traversal.rs (1749B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 4 5 //! Gecko-specific bits for the styling DOM traversal. 6 7 use crate::context::{SharedStyleContext, StyleContext}; 8 use crate::dom::{TElement, TNode}; 9 use crate::gecko::wrapper::{GeckoElement, GeckoNode}; 10 use crate::traversal::{recalc_style_at, DomTraversal, PerLevelTraversalData}; 11 12 /// This is the simple struct that Gecko uses to encapsulate a DOM traversal for 13 /// styling. 14 pub struct RecalcStyleOnly<'a> { 15 shared: SharedStyleContext<'a>, 16 } 17 18 impl<'a> RecalcStyleOnly<'a> { 19 /// Create a `RecalcStyleOnly` traversal from a `SharedStyleContext`. 20 pub fn new(shared: SharedStyleContext<'a>) -> Self { 21 RecalcStyleOnly { shared: shared } 22 } 23 } 24 25 impl<'recalc, 'le> DomTraversal<GeckoElement<'le>> for RecalcStyleOnly<'recalc> { 26 fn process_preorder<F>( 27 &self, 28 traversal_data: &PerLevelTraversalData, 29 context: &mut StyleContext<GeckoElement<'le>>, 30 node: GeckoNode<'le>, 31 note_child: F, 32 ) where 33 F: FnMut(GeckoNode<'le>), 34 { 35 if let Some(el) = node.as_element() { 36 let mut data = unsafe { el.ensure_data() }; 37 recalc_style_at(self, traversal_data, context, el, &mut data, note_child); 38 } 39 } 40 41 fn process_postorder(&self, _: &mut StyleContext<GeckoElement<'le>>, _: GeckoNode<'le>) { 42 unreachable!(); 43 } 44 45 /// We don't use the post-order traversal for anything. 46 fn needs_postorder_traversal() -> bool { 47 false 48 } 49 50 fn shared_context(&self) -> &SharedStyleContext<'recalc> { 51 &self.shared 52 } 53 }