Truly independent web browser
LibWeb: Skip redundant registered custom property resolution
Callum Lawf94965fea82e
diff --git a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rsindex 0a14ce7fcf1..5bacec550fa 100644--- a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs+++ b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs@@ -340,7 +340,7 @@ pub(super) struct PreparedCustomFunctions<'a> {/// What a registered custom property's value computes against: the element's lengths as its style/// computes them after line-height, and the color scheme its colors resolve with (a/// PreferredColorScheme code). The length context lends no output flag.-#[derive(Clone, Copy)]+#[derive(Clone, Copy, PartialEq)]pub(super) struct RegisteredValueContext {pub length: crate::css::style_compute::FfiLengthResolutionContext,pub color_scheme: u8,@@ -1257,8 +1257,8 @@ impl RetainedState {}/// Whether the custom declarations of a node, or of one of its pseudo-elements, name a- /// registered custom property: its drive then waits for the font it settles before resolving- /// them, as `FullDrive::AwaitsRegisteredContext` says.+ /// registered custom property: its drive may need to resolve them again against the font it+ /// settles, as `FullDrive::AwaitsRegisteredContext` says.pub(super) fn declares_registered_custom_property(&self,node: StyleNodeID,diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/drive.rs b/Libraries/LibWeb/Rust/src/css/style/publication/drive.rsindex 683ccef6a28..4e188d7cca8 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication/drive.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication/drive.rs@@ -649,7 +649,7 @@ impl RetainedState {/// against that font, and the remaining phase with the element facts the box-type/// transformation reads. Root-input preparation finishes only the font and line-height/// phases and preserves them for completion, and a drive with an `initial_registered_context`- /// stops after the color-scheme phase with the context the registered custom properties it+ /// may stop after the color-scheme phase with the context the registered custom properties it/// declares compute against, which it preserves likewise. Monospace default-size recascade/// stays in C++.#[allow(clippy::too_many_arguments, clippy::too_many_lines)]@@ -1122,7 +1122,7 @@ impl RetainedState {// A registered custom property computes against the font and color scheme settled now, as// the host finalizes one after the line-height phase; the winners the remaining phase reads// substitute what it computes to.- if initial_registered_context.is_some() {+ if let Some(initial_context) = initial_registered_context {let context = self.registered_value_context(target.node(),FfiLengthResolutionContext {@@ -1131,19 +1131,24 @@ impl RetainedState {},u8::try_from(effective_color_scheme).unwrap_or(inputs.preferred_color_scheme),);- font_scratch.pending = Some(PendingFontDrive {- target,- progress: Some(DriveProgress {- root_font_complete: true,- color_scheme_complete: true,- recascaded_font_size,- table,- results,- effective_color_scheme,- resolved_viewport_relative_length,- }),- });- return Ok(FullDrive::AwaitsRegisteredContext(context));++ // The initial environment already used this context. Resolve again only if+ // computing the font, line-height, or color scheme changed it.+ if context != *initial_context {+ font_scratch.pending = Some(PendingFontDrive {+ target,+ progress: Some(DriveProgress {+ root_font_complete: true,+ color_scheme_complete: true,+ recascaded_font_size,+ table,+ results,+ effective_color_scheme,+ resolved_viewport_relative_length,+ }),+ });+ return Ok(FullDrive::AwaitsRegisteredContext(context));+ }}let input_line_height_metrics = if has(fact::CHECK_INPUT_LINE_HEIGHT) {FfiInputLineHeightMetrics {diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex 4696742b610..47afd20f64c 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -44,7 +44,7 @@ include!(concat!(env!("OUT_DIR"), "/length_units_generated.rs"));/// The font metrics needed for font-relative length resolution, as unrounded/// CSS pixel values.#[repr(C)]-#[derive(Clone, Copy, Default)]+#[derive(Clone, Copy, Default, PartialEq)]pub struct FfiFontMetrics {pub font_size: f64,pub x_height: f64,@@ -55,7 +55,7 @@ pub struct FfiFontMetrics {/// Mirror of the length resolution parts of Length::ResolutionContext.#[repr(C)]-#[derive(Clone, Copy)]+#[derive(Clone, Copy, PartialEq)]pub struct FfiLengthResolutionContext {pub viewport_width: f64,pub viewport_height: f64,diff --git a/Tests/LibWeb/Text/expected/css/style-engine/custom-property-environment-beside-non-inheriting-registration.txt b/Tests/LibWeb/Text/expected/css/style-engine/custom-property-environment-beside-non-inheriting-registration.txtindex f89b3caca79..efbcca2216a 100644--- a/Tests/LibWeb/Text/expected/css/style-engine/custom-property-environment-beside-non-inheriting-registration.txt+++ b/Tests/LibWeb/Text/expected/css/style-engine/custom-property-environment-beside-non-inheriting-registration.txt@@ -1,5 +1,5 @@environment refusals: 0-environments the engine resolved: 5+environments the engine resolved: 3parent: --local 40px, --shared 6px, width 40px, height 42px, margin-left 0pxchild: --local 1px, --shared 6px, width 34px, height 1px, margin-left 6pxdeclaring: --local 1px, --shared 6px, width 40px, height 1px, margin-left 0pxdiff --git a/Tests/LibWeb/Text/expected/css/style-engine/registered-custom-property-backing-element-context.txt b/Tests/LibWeb/Text/expected/css/style-engine/registered-custom-property-backing-element-context.txtnew file mode 100644index 00000000000..37b5a26f846--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/style-engine/registered-custom-property-backing-element-context.txt@@ -0,0 +1,4 @@+input initial: font-size 20px, letter-spacing 20px+textarea initial: font-size 20px, letter-spacing 20px+input after rule changed: font-size 20px, letter-spacing 21px+textarea after rule changed: font-size 20px, letter-spacing 21pxdiff --git a/Tests/LibWeb/Text/expected/css/style-engine/registered-custom-property-external-inputs.txt b/Tests/LibWeb/Text/expected/css/style-engine/registered-custom-property-external-inputs.txtindex 0474931bf6c..3cf7a1ea2cc 100644--- a/Tests/LibWeb/Text/expected/css/style-engine/registered-custom-property-external-inputs.txt+++ b/Tests/LibWeb/Text/expected/css/style-engine/registered-custom-property-external-inputs.txt@@ -1,5 +1,5 @@environment refusals: 0-environments the engine resolved: 4+environments the engine resolved: 2--drawn in range: true--drawn shared between elements: trueopacity reads --drawn: truediff --git a/Tests/LibWeb/Text/input/css/style-engine/registered-custom-property-backing-element-context.html b/Tests/LibWeb/Text/input/css/style-engine/registered-custom-property-backing-element-context.htmlnew file mode 100644index 00000000000..69fbb15fa99--- /dev/null+++ b/Tests/LibWeb/Text/input/css/style-engine/registered-custom-property-backing-element-context.html@@ -0,0 +1,25 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<style>+ @property --length { syntax: "<length>"; inherits: false; initial-value: 0px; }+ input, textarea { font-size: 40px; }+ ::placeholder { font-size: 20px; --length: 1em; letter-spacing: var(--length); }+</style>+<input id="input" placeholder="p">+<textarea id="textarea" placeholder="p"></textarea>+<script>+ // The backing element keeps its font while its originating element has a different font.+ // Recomputing a longhand must still resolve the registered length against the backing font.+ test(() => {+ function report(label) {+ internals.updateStyle();+ for (const host of [input, textarea]) {+ const style = getComputedStyle(host, "::placeholder");+ println(`${host.localName} ${label}: font-size ${style.fontSize}, letter-spacing ${style.letterSpacing}`);+ }+ }+ report("initial");+ document.styleSheets[0].cssRules[2].style.letterSpacing = "calc(var(--length) + 1px)";+ report("after rule changed");+ });+</script>