Skip to content

Commit

Permalink
chore(innate): add tree leaf building children
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 7, 2023
1 parent 451612b commit 14fe6b0
Showing 1 changed file with 92 additions and 42 deletions.
134 changes: 92 additions & 42 deletions kayle_innate/kayle_innate/src/engine/audit/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ use victor_tree::style::values::Direction;
use victor_tree::style::values::WritingMode;
use victor_tree::style::StyleSet;

use crate::console_log;

lazy_static! {
static ref NODE_IGNORE: HashSet<&'static str> =
HashSet::from(["meta", "style", "link", "script", "head", "html"]);
HashSet::from(["meta", "style", "link", "script", "head", "html", "body"]);
}

/// try to fix all possible issues using a spec against the tree.
Expand Down Expand Up @@ -69,47 +71,96 @@ pub fn parse_accessibility_tree<'a, 'b, 'c>(
Some(element) => {
let name = element.value().name();
// TODO: determine if children are found to get entire layout of children to vector first
let layout_leaf = taffy
.new_leaf(Style {
// make nodes optional but, for now max out perf drawbacks
size: if NODE_IGNORE.contains(name) {
Size {
width: points(0.0),
height: points(0.0),
}
let layout_leaf = {
if NODE_IGNORE.contains(name) {
taffy.new_leaf(Default::default())
} else {
// all leafs created must be put into the body node at the end
console_log!("{name}");
// Non children elements
if name == "img" || name == "input" {
taffy.new_leaf(Default::default())
} else {
let style = victor_tree::style::cascade::style_for_element_ref(
&element,
&author,
&document,
&mut matching_context,
);
let style = style.as_ref();
let _physical_size =
style.box_size().size_to_physical(writing_direction);
// TODO: Build physical styles of each element as needed
// crate::console_log!("{name} {:?}", physical_size);
// crate::console_log!("{name} Margin {:?}", style.margin());
// crate::console_log!("{name} Padding {:?}", style.padding());
let padding_insent = style.padding().block_start;
// todo: make method to get entire size
let _padding_pxs = padding_insent.inner_px();
// crate::console_log!("{name} Padding Top {:?}", padding_pxs);
// IF the x and y is empty get the height based on the padding.
// If img has no height get the inherited from style width
// We may have to build the width/height if empty from paddings and margins
// TODO: use flex if element has a x or y but, not both to flex out entire layout.

Size {
width: points(800.0),
height: points(100.0),
let mut l_leafs: Vec<Node> = vec![];

for child in element.children() {
match scraper_forky::element_ref::ElementRef::wrap(child) {
Some(element) => {
let style =
victor_tree::style::cascade::style_for_element_ref(
&element,
&author,
&document,
&mut matching_context,
);
let style = style.as_ref();
let _physical_size =
style.box_size().size_to_physical(writing_direction);

let child_leaf = taffy.new_leaf(Default::default());

l_leafs.push(child_leaf.unwrap())
}
_ => (),
}
}
},
// todo: get entire styles up front
flex_grow: if name == "body" { 1.0 } else { 0.0 },
..Default::default()
})
.unwrap();

// TODO: get the style of each leaf
let leaf_style = Style {
flex_direction: FlexDirection::Column,
// compute the default layout from CDP
size: Size {
width: points(800.0),
height: points(600.0),
},
..Default::default()
};

// build leaf with children
if l_leafs.len() > 0 {
taffy.new_with_children(leaf_style, &l_leafs)
} else {
taffy.new_leaf(leaf_style)
}
}

// taffy.new_leaf(Style {
// // make nodes optional but, for now max out perf drawbacks
// size: {
// let style = victor_tree::style::cascade::style_for_element_ref(
// &element,
// &author,
// &document,
// &mut matching_context,
// );
// let style = style.as_ref();
// let _physical_size =
// style.box_size().size_to_physical(writing_direction);
// // TODO: Build physical styles of each element as needed
// // crate::console_log!("{name} {:?}", physical_size);
// // crate::console_log!("{name} Margin {:?}", style.margin());
// // crate::console_log!("{name} Padding {:?}", style.padding());
// let padding_insent = style.padding().block_start;
// // todo: make method to get entire size
// let _padding_pxs = padding_insent.inner_px();
// // crate::console_log!("{name} Padding Top {:?}", padding_pxs);
// // IF the x and y is empty get the height based on the padding.
// // If img has no height get the inherited from style width
// // We may have to build the width/height if empty from paddings and margins
// // TODO: use flex if element has a x or y but, not both to flex out entire layout.

// Size {
// width: points(800.0),
// height: points(100.0),
// }
// },
// // todo: get entire styles up front
// flex_grow: if name == "body" { 1.0 } else { 0.0 },
// ..Default::default()
// })
}
.unwrap()
};

layout_leafs.push(layout_leaf.clone());

Expand All @@ -122,7 +173,6 @@ pub fn parse_accessibility_tree<'a, 'b, 'c>(
};
}

// this is slow at the moment for large leafs being mocked
let root_node = taffy
.new_with_children(
Style {
Expand All @@ -137,7 +187,7 @@ pub fn parse_accessibility_tree<'a, 'b, 'c>(
&layout_leafs,
)
.unwrap();

// TODO: set the root node to html, body in the accessibility_tree
taffy.compute_layout(root_node, Size::MAX_CONTENT).unwrap();
// crate::console_log!("Last Element Position {:?}", taffy.layout(layout_leafs[layout_leafs.len() - 1]).unwrap());
// console_log!("Getting tree links {:?}", accessibility_tree.get("a"));
Expand Down

0 comments on commit 14fe6b0

Please sign in to comment.