@@ -14,7 +14,7 @@ use crate::context::UpdateAnimationsTasks;
1414use crate :: data:: ElementData ;
1515use crate :: media_queries:: Device ;
1616use crate :: properties:: { AnimationDeclarations , ComputedValues , PropertyDeclarationBlock } ;
17- use crate :: selector_parser:: { AttrValue , Lang , PseudoElement , RestyleDamage , SelectorImpl } ;
17+ use crate :: selector_parser:: { AttrValue , Lang , PseudoElement , SelectorImpl } ;
1818use crate :: shared_lock:: { Locked , SharedRwLock } ;
1919use crate :: stylesheets:: scope_rule:: ImplicitScopeRoot ;
2020use crate :: stylist:: CascadeData ;
@@ -30,7 +30,7 @@ use servo_arc::{Arc, ArcBorrow};
3030use std:: fmt;
3131use std:: fmt:: Debug ;
3232use std:: hash:: Hash ;
33- use std:: ops:: Deref ;
33+ use std:: ops:: { BitOrAssign , Deref } ;
3434
3535pub use style_traits:: dom:: OpaqueNode ;
3636
@@ -383,13 +383,51 @@ pub trait TShadowRoot: Sized + Copy + Clone + Debug + PartialEq {
383383 }
384384}
385385
386+ /// Represents restyle damage (whether to repaint, relayout, etc based on changed styles)
387+ ///
388+ /// Stylo is mostly agnostic to this type which is used by the embedder. This trait represents the
389+ /// minimal interface that Stylo does need to the type.
390+ pub trait TRestyleDamage : Copy + Clone + Default + Debug + BitOrAssign {
391+ /// Clear/reset all damage flags
392+ fn clear ( & mut self ) ;
393+ /// Whether the damage is empty ("no styles changed")
394+ fn is_empty ( & self ) -> bool ;
395+ /// Mark the element as needing it's (eager) pseudo-elements rebuilt
396+ fn set_rebuild_pseudos ( & mut self ) ;
397+ }
398+
399+ /// Represents the result of comparing an element's old and new style.
400+ #[ derive( Debug ) ]
401+ pub struct StyleDifference < RestyleDamage : TRestyleDamage > {
402+ /// The resulting damage.
403+ pub damage : RestyleDamage ,
404+
405+ /// Whether any styles changed.
406+ pub change : StyleChange ,
407+ }
408+
409+ /// Represents whether or not the style of an element has changed.
410+ #[ derive( Clone , Copy , Debug ) ]
411+ pub enum StyleChange {
412+ /// The style hasn't changed.
413+ Unchanged ,
414+ /// The style has changed.
415+ Changed {
416+ /// Whether only reset structs changed.
417+ reset_only : bool ,
418+ } ,
419+ }
420+
386421/// The element trait, the main abstraction the style crate acts over.
387422pub trait TElement :
388423 Eq + PartialEq + Debug + Hash + Sized + Copy + Clone + SelectorsElement < Impl = SelectorImpl >
389424{
390425 /// The concrete node type.
391426 type ConcreteNode : TNode < ConcreteElement = Self > ;
392427
428+ /// The type representing restyle damage flags
429+ type RestyleDamage : TRestyleDamage ;
430+
393431 /// A concrete children iterator type in order to iterate over the `Node`s.
394432 ///
395433 /// TODO(emilio): We should eventually replace this with the `impl Trait`
@@ -583,7 +621,7 @@ pub trait TElement:
583621
584622 /// Returns whether the element's styles are up-to-date after traversal
585623 /// (i.e. in post traversal).
586- fn has_current_styles ( & self , data : & ElementData ) -> bool {
624+ fn has_current_styles ( & self , data : & ElementData < Self :: RestyleDamage > ) -> bool {
587625 if self . has_snapshot ( ) && !self . handled_snapshot ( ) {
588626 return false ;
589627 }
@@ -670,7 +708,7 @@ pub trait TElement:
670708 ///
671709 /// Unsafe because it can race to allocate and leak if not used with
672710 /// exclusive access to the element.
673- unsafe fn ensure_data ( & self ) -> AtomicRefMut < ElementData > ;
711+ unsafe fn ensure_data ( & self ) -> AtomicRefMut < ElementData < Self :: RestyleDamage > > ;
674712
675713 /// Clears the element data reference, if any.
676714 ///
@@ -681,10 +719,10 @@ pub trait TElement:
681719 fn has_data ( & self ) -> bool ;
682720
683721 /// Immutably borrows the ElementData.
684- fn borrow_data ( & self ) -> Option < AtomicRef < ElementData > > ;
722+ fn borrow_data ( & self ) -> Option < AtomicRef < ElementData < Self :: RestyleDamage > > > ;
685723
686724 /// Mutably borrows the ElementData.
687- fn mutate_data ( & self ) -> Option < AtomicRefMut < ElementData > > ;
725+ fn mutate_data ( & self ) -> Option < AtomicRefMut < ElementData < Self :: RestyleDamage > > > ;
688726
689727 /// Whether we should skip any root- or item-based display property
690728 /// blockification on this element. (This function exists so that Gecko
@@ -909,9 +947,20 @@ pub trait TElement:
909947 None
910948 }
911949
912- /// Compute the damage incurred by the change from the `_old` to `_new`.
913- fn compute_layout_damage ( _old : & ComputedValues , _new : & ComputedValues ) -> RestyleDamage {
914- Default :: default ( )
950+ /// Given the old and new style of this element, and whether it's a
951+ /// pseudo-element, compute the restyle damage used to determine which
952+ /// kind of layout or painting operations we'll need.
953+ fn compute_style_difference (
954+ & self ,
955+ _old : & ComputedValues ,
956+ _new : & ComputedValues ,
957+ pseudo : Option < & PseudoElement > ,
958+ ) -> StyleDifference < Self :: RestyleDamage > {
959+ debug_assert ! ( pseudo. map_or( true , |p| p. is_eager( ) ) ) ;
960+ StyleDifference {
961+ damage : Default :: default ( ) ,
962+ change : StyleChange :: Unchanged ,
963+ }
915964 }
916965}
917966
0 commit comments