66
77use crate :: computed_value_flags:: ComputedValueFlags ;
88use crate :: context:: { SharedStyleContext , StackLimitChecker } ;
9- use crate :: dom:: TElement ;
9+ use crate :: dom:: { TElement , TRestyleDamage } ;
1010use crate :: invalidation:: element:: invalidator:: InvalidationResult ;
1111use crate :: invalidation:: element:: restyle_hints:: RestyleHint ;
1212use crate :: properties:: ComputedValues ;
13- use crate :: selector_parser:: { PseudoElement , RestyleDamage , EAGER_PSEUDO_COUNT } ;
13+ use crate :: selector_parser:: { PseudoElement , EAGER_PSEUDO_COUNT } ;
1414use crate :: style_resolver:: { PrimaryStyle , ResolvedElementStyles , ResolvedStyle } ;
1515#[ cfg( feature = "gecko" ) ]
1616use malloc_size_of:: MallocSizeOfOps ;
@@ -249,13 +249,13 @@ impl fmt::Debug for ElementStyles {
249249/// inside of layout data, which itself hangs directly off the Element. In
250250/// both cases, it is wrapped inside an AtomicRefCell to ensure thread safety.
251251#[ derive( Debug , Default ) ]
252- pub struct ElementData {
252+ pub struct ElementData < E : TElement > {
253253 /// The styles for the element and its pseudo-elements.
254254 pub styles : ElementStyles ,
255255
256256 /// The restyle damage, indicating what kind of layout changes are required
257257 /// afte restyling.
258- pub damage : RestyleDamage ,
258+ pub damage : E :: RestyleDamage ,
259259
260260 /// The restyle hint, which indicates whether selectors need to be rematched
261261 /// for this element, its children, and its descendants.
@@ -266,7 +266,14 @@ pub struct ElementData {
266266}
267267
268268// There's one of these per rendered elements so it better be small.
269- size_of_test ! ( ElementData , 24 ) ;
269+ // mod element_data_test {
270+ // use crate::dom::TRestyleDamage;
271+ // use super::ElementData;
272+ // #[derive(Debug, Copy, Clone, Default)]
273+ // struct SizeOfRestyleDamage(u32);
274+ // impl TRestyleDamage for SizeOfRestyleDamage {}
275+ // size_of_test!(ElementData<SizeOfRestyleDamage>, 24);
276+ // }
270277
271278/// The kind of restyle that a single element should do.
272279#[ derive( Debug ) ]
@@ -282,11 +289,11 @@ pub enum RestyleKind {
282289 CascadeOnly ,
283290}
284291
285- impl ElementData {
292+ impl < E : TElement > ElementData < E > {
286293 /// Invalidates style for this element, its descendants, and later siblings,
287294 /// based on the snapshot of the element that we took when attributes or
288295 /// state changed.
289- pub fn invalidate_style_if_needed < ' a , E : TElement > (
296+ pub fn invalidate_style_if_needed < ' a > (
290297 & mut self ,
291298 element : E ,
292299 shared_context : & SharedStyleContext ,
@@ -389,8 +396,8 @@ impl ElementData {
389396 return None ;
390397 }
391398
392- let needs_to_match_self = hint. intersects ( RestyleHint :: RESTYLE_SELF ) ||
393- ( hint. intersects ( RestyleHint :: RESTYLE_SELF_IF_PSEUDO ) && style. is_pseudo_style ( ) ) ;
399+ let needs_to_match_self = hint. intersects ( RestyleHint :: RESTYLE_SELF )
400+ || ( hint. intersects ( RestyleHint :: RESTYLE_SELF_IF_PSEUDO ) && style. is_pseudo_style ( ) ) ;
394401 if needs_to_match_self {
395402 return Some ( RestyleKind :: MatchAndCascade ) ;
396403 }
@@ -405,9 +412,9 @@ impl ElementData {
405412 ) ) ;
406413 }
407414
408- let needs_to_recascade_self = hint. intersects ( RestyleHint :: RECASCADE_SELF ) ||
409- ( hint. intersects ( RestyleHint :: RECASCADE_SELF_IF_INHERIT_RESET_STYLE ) &&
410- style
415+ let needs_to_recascade_self = hint. intersects ( RestyleHint :: RECASCADE_SELF )
416+ || ( hint. intersects ( RestyleHint :: RECASCADE_SELF_IF_INHERIT_RESET_STYLE )
417+ && style
411418 . flags
412419 . contains ( ComputedValueFlags :: INHERITS_RESET_STYLE ) ) ;
413420 if needs_to_recascade_self {
@@ -447,9 +454,9 @@ impl ElementData {
447454 ) ) ;
448455 }
449456
450- let needs_to_recascade_self = hint. intersects ( RestyleHint :: RECASCADE_SELF ) ||
451- ( hint. intersects ( RestyleHint :: RECASCADE_SELF_IF_INHERIT_RESET_STYLE ) &&
452- style
457+ let needs_to_recascade_self = hint. intersects ( RestyleHint :: RECASCADE_SELF )
458+ || ( hint. intersects ( RestyleHint :: RECASCADE_SELF_IF_INHERIT_RESET_STYLE )
459+ && style
453460 . flags
454461 . contains ( ComputedValueFlags :: INHERITS_RESET_STYLE ) ) ;
455462 if needs_to_recascade_self {
@@ -471,7 +478,7 @@ impl ElementData {
471478 /// Drops restyle flags and damage from the element.
472479 #[ inline]
473480 pub fn clear_restyle_flags_and_damage ( & mut self ) {
474- self . damage = RestyleDamage :: empty ( ) ;
481+ self . damage . clear ( ) ;
475482 self . flags . remove ( ElementDataFlags :: WAS_RESTYLED ) ;
476483 }
477484
@@ -521,8 +528,8 @@ impl ElementData {
521528 /// we need for style sharing, the latter does not.
522529 pub fn safe_for_cousin_sharing ( & self ) -> bool {
523530 if self . flags . intersects (
524- ElementDataFlags :: TRAVERSED_WITHOUT_STYLING |
525- ElementDataFlags :: PRIMARY_STYLE_REUSED_VIA_RULE_NODE ,
531+ ElementDataFlags :: TRAVERSED_WITHOUT_STYLING
532+ | ElementDataFlags :: PRIMARY_STYLE_REUSED_VIA_RULE_NODE ,
526533 ) {
527534 return false ;
528535 }
0 commit comments