diff options
-rw-r--r-- | components/layout/flow.rs | 17 | ||||
-rw-r--r-- | components/layout/generated_content.rs | 2 | ||||
-rw-r--r-- | components/layout/sequential.rs | 16 |
3 files changed, 19 insertions, 16 deletions
diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 3ce36ad1a7c..5bf08c2a92d 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -542,6 +542,9 @@ pub trait MutableFlowUtils { /// Traverses the tree in postorder. fn traverse_postorder<T: PostorderFlowTraversal>(self, traversal: &T); + /// Traverses the tree in-order. + fn traverse_inorder<T: InorderFlowTraversal>(self, traversal: &mut T, level: u32); + /// Traverse the Absolute flow tree in preorder. /// /// Traverse all your direct absolute descendants, who will then traverse @@ -643,7 +646,7 @@ pub trait InorderFlowTraversal { /// Returns true if this node should be processed and false if neither this node nor its /// descendants should be processed. - fn should_process(&mut self, flow: &mut Flow) -> bool; + fn should_process_subtree(&mut self, flow: &mut Flow) -> bool; } bitflags! { @@ -1378,6 +1381,18 @@ impl<'a> MutableFlowUtils for &'a mut Flow { } } + /// Traverses the tree in-order. + fn traverse_inorder<T: InorderFlowTraversal>(self, traversal: &mut T, level: u32) { + if !traversal.should_process_subtree(self) { + return; + } + + traversal.process(self, level); + + for kid in child_iter_mut(self) { + kid.traverse_inorder(traversal, level + 1); + } + } /// Calls `repair_style` and `bubble_inline_sizes`. You should use this method instead of /// calling them individually, since there is no reason not to perform both operations. diff --git a/components/layout/generated_content.rs b/components/layout/generated_content.rs index 21fce5a03c4..26e1754fad9 100644 --- a/components/layout/generated_content.rs +++ b/components/layout/generated_content.rs @@ -130,7 +130,7 @@ impl<'a> InorderFlowTraversal for ResolveGeneratedContent<'a> { } #[inline] - fn should_process(&mut self, flow: &mut Flow) -> bool { + fn should_process_subtree(&mut self, flow: &mut Flow) -> bool { flow::base(flow).restyle_damage.intersects(RESOLVE_GENERATED_CONTENT) || flow::base(flow).flags.intersects(AFFECTS_COUNTERS | HAS_COUNTER_AFFECTING_CHILDREN) } diff --git a/components/layout/sequential.rs b/components/layout/sequential.rs index f6f8ce429e4..b97f0a4d357 100644 --- a/components/layout/sequential.rs +++ b/components/layout/sequential.rs @@ -9,7 +9,7 @@ use context::LayoutContext; use display_list_builder::DisplayListBuildState; use euclid::{Point2D, Vector2D}; use floats::SpeculatedFloatPlacement; -use flow::{self, Flow, ImmutableFlowUtils, InorderFlowTraversal, MutableFlowUtils}; +use flow::{self, Flow, ImmutableFlowUtils, MutableFlowUtils}; use flow::{PostorderFlowTraversal, PreorderFlowTraversal}; use flow::IS_ABSOLUTELY_POSITIONED; use fragment::{FragmentBorderBoxIterator, CoordinateSystem}; @@ -22,20 +22,8 @@ use traversal::{AssignBSizes, AssignISizes, BubbleISizes, BuildDisplayList}; pub use style::sequential::traverse_dom; pub fn resolve_generated_content(root: &mut Flow, layout_context: &LayoutContext) { - fn doit(flow: &mut Flow, level: u32, traversal: &mut ResolveGeneratedContent) { - if !traversal.should_process(flow) { - return; - } - - traversal.process(flow, level); - - for kid in flow::mut_base(flow).children.iter_mut() { - doit(kid, level + 1, traversal) - } - } - let mut traversal = ResolveGeneratedContent::new(&layout_context); - doit(root, 0, &mut traversal) + root.traverse_inorder(&mut traversal, 0); } pub fn traverse_flow_tree_preorder(root: &mut Flow, layout_context: &LayoutContext, relayout_mode: RelayoutMode) { |