diff options
author | Martin Robinson <mrobinson@igalia.com> | 2025-04-19 12:17:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-19 10:17:03 +0000 |
commit | 7787cab521ccc6b4d8533ebe9b45563046e0463d (patch) | |
tree | d1277fa3846f24cc99859310da3d7f099c73bfc5 /components/layout/traversal.rs | |
parent | 3ab5b8c4472129798b63cfb40b63ae672763b653 (diff) | |
download | servo-7787cab521ccc6b4d8533ebe9b45563046e0463d.tar.gz servo-7787cab521ccc6b4d8533ebe9b45563046e0463d.zip |
layout: Combine `layout_2020` and `layout_thread_2020` into a crate called `layout` (#36613)
Now that legacy layout has been removed, the name `layout_2020` doesn't
make much sense any longer, also it's 2025 now for better or worse. The
split between the "layout thread" and "layout" also doesn't make as much
sense since layout doesn't run on it's own thread. There's a possibility
that it will in the future, but that should be something that the user
of the crate controls rather than layout iself.
This is part of the larger layout interface cleanup and optimization
that
@Looriool and I are doing.
Testing: Covered by existing tests as this is just code movement.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/layout/traversal.rs')
-rw-r--r-- | components/layout/traversal.rs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs new file mode 100644 index 00000000000..40281b640c9 --- /dev/null +++ b/components/layout/traversal.rs @@ -0,0 +1,74 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use script_layout_interface::wrapper_traits::LayoutNode; +use style::context::{SharedStyleContext, StyleContext}; +use style::data::ElementData; +use style::dom::{NodeInfo, TElement, TNode}; +use style::traversal::{DomTraversal, PerLevelTraversalData, recalc_style_at}; + +use crate::context::LayoutContext; +use crate::dom::DOMLayoutData; + +pub struct RecalcStyle<'a> { + context: LayoutContext<'a>, +} + +impl<'a> RecalcStyle<'a> { + pub fn new(context: LayoutContext<'a>) -> Self { + RecalcStyle { context } + } + + pub fn context(&self) -> &LayoutContext<'a> { + &self.context + } + + pub fn destroy(self) -> LayoutContext<'a> { + self.context + } +} + +#[allow(unsafe_code)] +impl<'dom, E> DomTraversal<E> for RecalcStyle<'_> +where + E: TElement, + E::ConcreteNode: 'dom + LayoutNode<'dom>, +{ + fn process_preorder<F>( + &self, + traversal_data: &PerLevelTraversalData, + context: &mut StyleContext<E>, + node: E::ConcreteNode, + note_child: F, + ) where + F: FnMut(E::ConcreteNode), + { + unsafe { + node.initialize_style_and_layout_data::<DOMLayoutData>(); + if !node.is_text_node() { + let el = node.as_element().unwrap(); + let mut data = el.mutate_data().unwrap(); + recalc_style_at(self, traversal_data, context, el, &mut data, note_child); + el.unset_dirty_descendants(); + } + } + } + + #[inline] + fn needs_postorder_traversal() -> bool { + false + } + + fn process_postorder(&self, _style_context: &mut StyleContext<E>, _node: E::ConcreteNode) { + panic!("this should never be called") + } + + fn text_node_needs_traversal(node: E::ConcreteNode, parent_data: &ElementData) -> bool { + node.layout_data().is_none() || !parent_data.damage.is_empty() + } + + fn shared_context(&self) -> &SharedStyleContext { + &self.context.style_context + } +} |