gecko-dev/servo/components/style/sequential.rs
Bobby Holley b0588eeb56 servo: Merge #14610 - Simplify style context architecture and make it safer (from bholley:style_context_refactor); r=emilio
See the discussion at https://bugzilla.mozilla.org/show_bug.cgi?id=1323372

Not done here, but want to get a try run in on the first patch.

Source-Repo: https://github.com/servo/servo
Source-Revision: a4ecdf2d5fda281f25e2689852bc2134429e07c6
2016-12-16 11:38:27 -08:00

59 lines
1.8 KiB
Rust

/* 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 http://mozilla.org/MPL/2.0/. */
//! Implements sequential traversal over the DOM tree.
use dom::{TElement, TNode};
use std::borrow::Borrow;
use traversal::{DomTraversal, PerLevelTraversalData, PreTraverseToken};
pub fn traverse_dom<N, D>(traversal: &D,
root: N::ConcreteElement,
token: PreTraverseToken)
where N: TNode,
D: DomTraversal<N>
{
debug_assert!(token.should_traverse());
fn doit<N, D>(traversal: &D, node: N, data: &mut PerLevelTraversalData)
where N: TNode,
D: DomTraversal<N>
{
traversal.process_preorder(node, data);
if let Some(el) = node.as_element() {
if let Some(ref mut depth) = data.current_dom_depth {
*depth += 1;
}
D::traverse_children(el, |kid| doit(traversal, kid, data));
if let Some(ref mut depth) = data.current_dom_depth {
*depth -= 1;
}
}
if D::needs_postorder_traversal() {
traversal.process_postorder(node);
}
}
let mut data = PerLevelTraversalData {
current_dom_depth: None,
};
if token.traverse_unstyled_children_only() {
for kid in root.as_node().children() {
if kid.as_element().map_or(false, |el| el.get_data().is_none()) {
doit(traversal, kid, &mut data);
}
}
} else {
doit(traversal, root.as_node(), &mut data);
}
// Clear the local LRU cache since we store stateful elements inside.
let tlc = traversal.create_or_get_thread_local_context();
(*tlc).borrow().style_sharing_candidate_cache.borrow_mut().clear();
}