Trait style::traversal::DomTraversal

source ·
pub trait DomTraversal<E: TElement>: Sync {
    // Required methods
    fn process_preorder<F>(
        &self,
        data: &PerLevelTraversalData,
        context: &mut StyleContext<'_, E>,
        node: E::ConcreteNode,
        note_child: F,
    )
       where F: FnMut(E::ConcreteNode);
    fn process_postorder(
        &self,
        contect: &mut StyleContext<'_, E>,
        node: E::ConcreteNode,
    );
    fn shared_context(&self) -> &SharedStyleContext<'_>;

    // Provided methods
    fn needs_postorder_traversal() -> bool { ... }
    fn handle_postorder_traversal(
        &self,
        context: &mut StyleContext<'_, E>,
        root: OpaqueNode,
        node: E::ConcreteNode,
        children_to_process: isize,
    ) { ... }
    fn pre_traverse(
        root: E,
        shared_context: &SharedStyleContext<'_>,
    ) -> PreTraverseToken<E> { ... }
    fn text_node_needs_traversal(
        node: E::ConcreteNode,
        _parent_data: &ElementData,
    ) -> bool { ... }
    fn element_needs_traversal(
        el: E,
        traversal_flags: TraversalFlags,
        data: Option<&ElementData>,
    ) -> bool { ... }
}
Expand description

A DOM Traversal trait, that is used to generically implement styling for Gecko and Servo.

Required Methods§

source

fn process_preorder<F>( &self, data: &PerLevelTraversalData, context: &mut StyleContext<'_, E>, node: E::ConcreteNode, note_child: F, )
where F: FnMut(E::ConcreteNode),

Process node on the way down, before its children have been processed.

The callback is invoked for each child node that should be processed by the traversal.

source

fn process_postorder( &self, contect: &mut StyleContext<'_, E>, node: E::ConcreteNode, )

Process node on the way up, after its children have been processed.

This is only executed if needs_postorder_traversal returns true.

source

fn shared_context(&self) -> &SharedStyleContext<'_>

Return the shared style context common to all worker threads.

Provided Methods§

source

fn needs_postorder_traversal() -> bool

Boolean that specifies whether a bottom up traversal should be performed.

If it’s false, then process_postorder has no effect at all.

source

fn handle_postorder_traversal( &self, context: &mut StyleContext<'_, E>, root: OpaqueNode, node: E::ConcreteNode, children_to_process: isize, )

Handles the postorder step of the traversal, if it exists, by bubbling up the parent chain.

If we are the last child that finished processing, recursively process our parent. Else, stop. Also, stop at the root.

Thus, if we start with all the leaves of a tree, we end up traversing the whole tree bottom-up because each parent will be processed exactly once (by the last child that finishes processing).

The only communication between siblings is that they both fetch-and-subtract the parent’s children count. This makes it safe to call durign the parallel traversal.

source

fn pre_traverse( root: E, shared_context: &SharedStyleContext<'_>, ) -> PreTraverseToken<E>

Style invalidations happen when traversing from a parent to its children. However, this mechanism can’t handle style invalidations on the root. As such, we have a pre-traversal step to handle that part and determine whether a full traversal is needed.

source

fn text_node_needs_traversal( node: E::ConcreteNode, _parent_data: &ElementData, ) -> bool

Returns true if traversal should visit a text node. The style system never processes text nodes, but Servo overrides this to visit them for flow construction when necessary.

source

fn element_needs_traversal( el: E, traversal_flags: TraversalFlags, data: Option<&ElementData>, ) -> bool

Returns true if traversal is needed for the given element and subtree.

Object Safety§

This trait is not object safe.

Implementors§