Skip to content

Make RestyleDamage an associated type and make embedder responsible for all damage computation #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nicoburns
Copy link
Collaborator

@nicoburns nicoburns commented Aug 5, 2025

Draft for design review: does the key idea here (pushing the top-level compute_style_difference up to the embedder) seem like a good idea?

(includes the changes from #222 which is a much more surface-level change)

Servo PR: servo/servo#38479


Objective

  • Give embedder full control over restyle damage computation (functionality built-in to Stylo (e.g. generated restyle_damage_* functions) is exposed as public library functions that the embedded can call into).
  • Remove the need for a separate LayoutDamage type.
  • Make interface/contract of the RestyleDamage type more explicit (by making it a trait)

Changes Made

  • Create TRestyleDamage trait to represent restyle damage
  • Add RestyleDamage associated type to TElement trait
  • Move the top-level compute_style_difference function from the (private) MatchMethods trait to the (public) TElement trait (so that the embedder can implement it).
  • Remove the TElement::compute_layout_damage method (embedders should now use compute_style_difference instead).
  • Make ElementData struct generic over TElement
  • Rename RestyleDamage::reconstruct to ::set_rebuild_pseudos
    (because that is the scenario in which it's called, and pseudos having changed doesn't necessarily imply that the entire box needs to be reconstructed (although Servo will presumably continue to do that for now))

Notes

There are a few places where Servo does different things to Gecko around RestyleDamage:

A key one is that in Gecko RestyleDamage::is_empty() will be false (triggering a StyleChange::Changed to be returned to Stylo) if any style property has changed. Whereas in Servo this only happens if one of the properties we check for damage has changed.

We should check what the correct semantics are here and whether Servo's implementation is correct/valid.

@nicoburns nicoburns force-pushed the associated-damage-type branch 3 times, most recently from 0b1623f to 4fe9a9a Compare August 5, 2025 15:20
Signed-off-by: Nico Burns <[email protected]>
@nicoburns nicoburns force-pushed the associated-damage-type branch from 4fe9a9a to ef96559 Compare August 7, 2025 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant