Skip to content

Truly independent web browser

LibWeb: Inherit currentcolor text shadows with absolute lengths

sideshowbarker41c4cbb16fe1
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index da403cbe4e4..585391858da 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -3531,11 +3531,23 @@ fn needs_computed_style_sheet_context(value: &RetainedStyleValueData) -> bool {
}
}
-/// Store what a drive found for one longhand: its computed value, and the specified value its
-/// inheritance depends on, if it does.
+/// Store what a drive found for one longhand: its computed value, and the value its inheritance depends on, if it
+/// does. That's the specified value, except for a value that reads currentcolor: An inheriting element takes its
+/// computed value, which keeps currentcolor to resolve against that element's own color, and whose lengths are
+/// absolute (resolved against this element's font, as inheritance requires).
fn store_driven_value(longhand_table: &mut ComputedLonghandTable, entry: ComputedStoreEntry) {
- let specified_value = entry.inheritance_dependent.then(|| entry.data.clone());
- longhand_table.set_drive_inheritance_dependent_value(entry.property_id, specified_value);
+ use crate::css::property_metadata::property_id as prop;
+ let inheritance_dependent_value = entry.inheritance_dependent.then(|| {
+ let inherits_computed_value = entry.computed_kind == COMPUTED_KIND_STYLE_VALUE
+ && entry.property_id != prop::COLOR
+ && crate::css::style_value::retained_value_depends_on_current_color(entry.data)
+ && !value_depends_on_inherited_info_for_property(entry.data.data(), entry.property_id);
+ match &entry.computed_data {
+ Some(computed_data) if inherits_computed_value => computed_data.clone(),
+ _ => entry.data.clone(),
+ }
+ });
+ longhand_table.set_drive_inheritance_dependent_value(entry.property_id, inheritance_dependent_value);
store_computed_value(longhand_table, entry);
}
diff --git a/Tests/LibWeb/Crash/CSS/inherited-text-shadow-currentcolor-relative-lengths.html b/Tests/LibWeb/Crash/CSS/inherited-text-shadow-currentcolor-relative-lengths.html
new file mode 100644
index 00000000000..8d5a876b5d3
--- /dev/null
+++ b/Tests/LibWeb/Crash/CSS/inherited-text-shadow-currentcolor-relative-lengths.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+ .rem { text-shadow: 0 1rem currentColor; }
+ .em { text-shadow: 0 1em currentColor, 1px 1px red; }
+ .vw { text-shadow: 0 1vw 2em currentColor; }
+ .calc { text-shadow: 0 calc(1px + 1rem) currentColor; }
+</style>
+<div class="rem"><span>rem</span></div>
+<div class="em"><span>em</span></div>
+<div class="vw"><span>vw</span></div>
+<div class="calc"><span>calc</span></div>
diff --git a/Tests/LibWeb/Ref/expected/inherited-text-shadow-currentcolor-and-em-ref.html b/Tests/LibWeb/Ref/expected/inherited-text-shadow-currentcolor-and-em-ref.html
new file mode 100644
index 00000000000..3e30ab2ee84
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/inherited-text-shadow-currentcolor-and-em-ref.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<style>
+ * { margin: 0; }
+ div { font: 20px/1 serif; }
+ span { font-size: 40px; color: green; text-shadow: 0 20px green; }
+</style>
+<div><span>X</span></div>
diff --git a/Tests/LibWeb/Ref/input/inherited-text-shadow-currentcolor-and-em.html b/Tests/LibWeb/Ref/input/inherited-text-shadow-currentcolor-and-em.html
new file mode 100644
index 00000000000..4d76a11d64c
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/inherited-text-shadow-currentcolor-and-em.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/inherited-text-shadow-currentcolor-and-em-ref.html" />
+<style>
+ * { margin: 0; }
+ div { font: 20px/1 serif; color: red; text-shadow: 0 1em currentColor; }
+ span { font-size: 40px; color: green; }
+</style>
+<div><span>X</span></div>