Skip to content

Truly independent web browser

LibWeb: Make an important author revert skip normal author declarations

Andreas Klingc06587f6aab6
diff --git a/Libraries/LibWeb/Rust/src/css/style/cascade.rs b/Libraries/LibWeb/Rust/src/css/style/cascade.rs
index f165bc78ba4..438fe65f2b2 100644
--- a/Libraries/LibWeb/Rust/src/css/style/cascade.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/cascade.rs
@@ -268,7 +268,6 @@ pub enum CascadeAttachment {
pub enum CascadeContinuationCeiling {
Origin {
origin_group: u8,
- important: bool,
},
Layer {
origin: u8,
@@ -329,7 +328,6 @@ impl CascadeStratum {
match operator {
CascadeOperator::Revert => Some(CascadeContinuationCeiling::Origin {
origin_group: self.origin_group,
- important: self.important,
}),
CascadeOperator::RevertLayer => Some(CascadeContinuationCeiling::Layer {
origin: self.origin,
@@ -345,10 +343,10 @@ impl CascadeStratum {
pub(crate) fn is_below(self, ceiling: CascadeContinuationCeiling) -> bool {
match ceiling {
- CascadeContinuationCeiling::Origin {
- origin_group,
- important,
- } => self.origin_group != origin_group || self.important != important,
+ // https://drafts.csswg.org/css-cascade-5/#valdef-all-revert
+ // The cascaded value rolls back as if no rules of the reverting declaration's origin were
+ // specified, important or not, and a user declaration also rolls back past the author's.
+ CascadeContinuationCeiling::Origin { origin_group } => self.origin_group < origin_group,
CascadeContinuationCeiling::Layer {
origin,
important: _,
diff --git a/Tests/LibWeb/Text/expected/css/revert-important-skips-normal-author-declarations.txt b/Tests/LibWeb/Text/expected/css/revert-important-skips-normal-author-declarations.txt
new file mode 100644
index 00000000000..240fae99eee
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/revert-important-skips-normal-author-declarations.txt
@@ -0,0 +1,3 @@
+important: max-width=none color=rgb(0, 128, 0)
+normal: max-width=none color=rgb(0, 128, 0)
+important-color: max-width=100% color=rgb(0, 0, 0)
diff --git a/Tests/LibWeb/Text/input/css/revert-important-skips-normal-author-declarations.html b/Tests/LibWeb/Text/input/css/revert-important-skips-normal-author-declarations.html
new file mode 100644
index 00000000000..c329bdc929b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/revert-important-skips-normal-author-declarations.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ div { max-width: 100%; color: green; }
+ .important { max-width: revert !important; }
+ .normal { max-width: 50px; }
+ .normal { max-width: revert; }
+ .important-color { color: revert !important; }
+</style>
+<!-- An important author `revert` rolls back past every author declaration, normal ones included. -->
+<div class="important"></div>
+<div class="normal"></div>
+<div class="important-color"></div>
+<script>
+ test(() => {
+ for (const div of document.querySelectorAll("div")) {
+ const style = getComputedStyle(div);
+ println(`${div.className}: max-width=${style.maxWidth} color=${style.color}`);
+ }
+ });
+</script>