Skip to content

Truly independent web browser

LibWeb: Make position compute to absolute in the top layer

sideshowbarker9298770aa415
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs
index f6d0e3f46e7..1a23683c882 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs
@@ -804,9 +804,10 @@ impl RetainedState {
let box_type_input = self.box_type_transformation_input_with(
records,
facts,
- match is_pseudo_element {
- true => crate::css::style_compute::StyleAdjustmentTarget::PseudoElement,
- false => crate::css::style_compute::StyleAdjustmentTarget::Element,
+ match (is_pseudo_element, target_pseudo_kind) {
+ (true, pseudo_kind::BACKDROP) => crate::css::style_compute::StyleAdjustmentTarget::Backdrop,
+ (true, _) => crate::css::style_compute::StyleAdjustmentTarget::PseudoElement,
+ (false, _) => crate::css::style_compute::StyleAdjustmentTarget::Element,
},
parent.map(|(parent, _)| parent),
);
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs
index 1a166b537c9..d307f1902b0 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs
@@ -329,6 +329,8 @@ impl RetainedState {
StyleAdjustmentTarget::Element,
self.projection.inheritance_parent(node),
)
+ } else if pseudo_kind == pseudo_kind::BACKDROP {
+ self.box_type_transformation_input(facts, StyleAdjustmentTarget::Backdrop, Some(node))
} else {
self.box_type_transformation_input(facts, StyleAdjustmentTarget::PseudoElement, Some(node))
}
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 63d88483ad5..997353c6cfe 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -6071,6 +6071,7 @@ unsafe fn create_document_style_record(
force_position_static: false,
force_symbol_display_inline: false,
webkit_box_layout_transformation_applies: false,
+ in_top_layer: false,
},
color_scheme_input: input.color_scheme_input,
is_th_element: false,
@@ -7453,6 +7454,13 @@ fn post_compute_adjusted_values(
prop::FLOAT,
StyleValueData::Keyword { keyword: keyword::NONE },
);
+ adjust(
+ transformation.set_position_absolute,
+ prop::POSITION,
+ StyleValueData::Keyword {
+ keyword: keyword::ABSOLUTE,
+ },
+ );
adjust(
adjusted_display != adjustment.display_before,
prop::DISPLAY,
@@ -7484,6 +7492,7 @@ fn post_compute_adjusted_values(
);
for (changed, property_id) in [
(transformation.set_float_none, prop::FLOAT),
+ (transformation.set_position_absolute, prop::POSITION),
(
transformation.changed_display || element_adjustment.changed_display,
prop::DISPLAY,
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs b/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs
index e688604c840..8c4fc319a20 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs
@@ -43,6 +43,8 @@ pub struct FfiBoxTypeTransformationInput {
pub force_position_static: bool,
pub force_symbol_display_inline: bool,
pub webkit_box_layout_transformation_applies: bool,
+ /// The element is rendered in the top layer, and isn't the document element, or the subject is its ::backdrop.
+ pub in_top_layer: bool,
}
/// Whether element-specific adjustments apply to the subject being computed.
@@ -50,6 +52,8 @@ pub struct FfiBoxTypeTransformationInput {
pub enum StyleAdjustmentTarget {
Element,
PseudoElement,
+ /// A ::backdrop, which exists only for an element rendered in the top layer.
+ Backdrop,
}
/// Build the shared adjustment inputs from element facts. The caller supplies the first
@@ -91,6 +95,11 @@ pub(crate) fn rust_box_type_transformation_input(
force_position_static: adjust_element && has(fact::FORCE_POSITION_STATIC),
force_symbol_display_inline: adjust_element && has(fact::FORCE_SYMBOL_DISPLAY_INLINE),
webkit_box_layout_transformation_applies: false,
+ in_top_layer: match target {
+ StyleAdjustmentTarget::Element => has(fact::RENDERED_IN_TOP_LAYER) && !has(fact::IS_DOCUMENT_ELEMENT),
+ StyleAdjustmentTarget::PseudoElement => false,
+ StyleAdjustmentTarget::Backdrop => true,
+ },
}
}
@@ -126,6 +135,7 @@ pub extern "C" fn rust_animated_box_type_transformation_input(
#[derive(Clone, Copy)]
pub struct FfiBoxTypeTransformation {
pub set_float_none: bool,
+ pub set_position_absolute: bool,
pub changed_display: bool,
pub display: FfiDisplay,
}
@@ -286,6 +296,23 @@ pub(super) fn transform_box_type(input: &FfiBoxTypeTransformationInput) -> FfiBo
let display_before_transformation = input.display;
let mut display = display_before_transformation;
+ // https://drafts.csswg.org/css-position-4/#top-styling
+ // Every element rendered in the top layer, as well as its corresponding ::backdrop pseudo-element, are rendered
+ // with the following qualities:
+ // - If its specified 'display' property is 'display/contents', it computes to 'display/block'.
+ // - If its specified 'position' property is not 'position/absolute' or 'position/fixed', it computes to
+ // 'position/absolute'.
+ let set_position_absolute =
+ input.in_top_layer && input.position != keyword::ABSOLUTE && input.position != keyword::FIXED;
+ let mut adjusted_input = *input;
+ if set_position_absolute {
+ adjusted_input.position = keyword::ABSOLUTE;
+ }
+ let input = &adjusted_input;
+ if input.in_top_layer && display.is_contents() {
+ display = FfiDisplay::block();
+ }
+
// https://drafts.csswg.org/css-overflow-4/#webkit-line-clamp
// If the specified value of the 'display' property is '-webkit-box', the computed value becomes 'flow-root'
// and the box establishes a BFC.
@@ -298,6 +325,7 @@ pub(super) fn transform_box_type(input: &FfiBoxTypeTransformationInput) -> FfiBo
}
let unchanged = |set_float_none: bool| FfiBoxTypeTransformation {
set_float_none,
+ set_position_absolute,
changed_display: display != display_before_transformation,
display,
};
@@ -314,6 +342,7 @@ pub(super) fn transform_box_type(input: &FfiBoxTypeTransformationInput) -> FfiBo
if input.is_document_element && !display.is_block_outside() {
return FfiBoxTypeTransformation {
set_float_none: false,
+ set_position_absolute,
changed_display: true,
display: FfiDisplay::block(),
};
@@ -400,6 +429,7 @@ pub(super) fn transform_box_type(input: &FfiBoxTypeTransformationInput) -> FfiBo
FfiBoxTypeTransformation {
set_float_none,
+ set_position_absolute,
changed_display: new_display != display_before_transformation,
display: new_display,
}
@@ -633,6 +663,9 @@ pub(super) fn finalize_animated_box_type(
if adjustments.box_type.set_float_none {
adjust(prop::FLOAT, keyword(keyword::NONE));
}
+ if adjustments.box_type.set_position_absolute {
+ adjust(prop::POSITION, keyword(keyword::ABSOLUTE));
+ }
if adjustments.box_type.changed_display {
adjust(prop::DISPLAY, display(adjustments.box_type.display));
}
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs b/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs
index ee67d47c04a..7e15d593ec7 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs
@@ -177,6 +177,7 @@ fn element_adjustment_input() -> FfiBoxTypeTransformationInput {
force_position_static: false,
force_symbol_display_inline: false,
webkit_box_layout_transformation_applies: false,
+ in_top_layer: false,
}
}
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/backdrop-in-flow-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/backdrop-in-flow-ref.html
new file mode 100644
index 00000000000..4857557bf88
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/backdrop-in-flow-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<style>
+#backdrop {
+ position: absolute;
+ top: 100px;
+ left: 100px;
+ height: 100px;
+ width: 100px;
+ background: green;
+}
+</style>
+<body>
+Test that position 'static' or 'relative' for ::backdrop computes to 'absolute'.
+The test passes if there is a single green box.
+<div id="backdrop"></div>
+</body>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/dont-share-style-to-top-layer-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/dont-share-style-to-top-layer-ref.html
new file mode 100644
index 00000000000..7e6112b3cee
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/dont-share-style-to-top-layer-ref.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<style>
+dialog {
+ outline: none;
+}
+#non-modal {
+ position: static;
+}
+</style>
+<p>Test that a non-top layer element doesn't share style with a top layer
+element. The test passes if you see two boxes.</p>
+<dialog id="non-modal" open></dialog>
+<dialog id="modal"></dialog>
+<script>
+document.querySelector('#modal').showModal();
+</script>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/element-removed-from-top-layer-has-original-position-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/element-removed-from-top-layer-has-original-position-ref.html
new file mode 100644
index 00000000000..c0b64e68bd1
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/element-removed-from-top-layer-has-original-position-ref.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+.green {
+ color: green;
+}
+</style>
+</head>
+<body>
+<p>Bug <a href="http://webkit.org/b/106538">106538</a>: Top layer fails for inline elements</p>
+<p>This tests that position 'static' no longer computes to 'absolute' for an
+element that has been removed from the top layer. The test passes if you see
+a single line of text.</p>
+<span class="green">This is the span.</span>
+<span class="green">This is the dialog following it.</span>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-ref.html
new file mode 100644
index 00000000000..01eff8c4de5
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-ref.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+
+<style>
+dialog {
+ background-color: green;
+ height: 50px;
+ width: 50px;
+ border: none;
+ padding: 0;
+ margin: 0;
+
+ position: absolute;
+ top: 100px;
+ left: 100px;
+}
+</style>
+
+<dialog></dialog>
+
+<script>
+document.querySelector('dialog').showModal();
+</script>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/backdrop-in-flow.html b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/backdrop-in-flow.html
new file mode 100644
index 00000000000..d4061e531d1
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/backdrop-in-flow.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<link rel="match" href="../../../../../../expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/backdrop-in-flow-ref.html">
+<link rel="help" href="https://fullscreen.spec.whatwg.org/#new-stacking-layer">
+<style>
+dialog {
+ visibility: hidden;
+}
+
+dialog::backdrop {
+ visibility: visible;
+ height: 100px;
+ width: 50px;
+}
+
+#left::backdrop {
+ position: static;
+ top: 100px;
+ left: 100px;
+ background: green;
+}
+
+#right::backdrop {
+ position: relative;
+ background: green;
+ top: 100px;
+ left: 150px;
+}
+</style>
+<body>
+Test that position 'static' or 'relative' for ::backdrop computes to 'absolute'.
+The test passes if there is a single green box.
+<dialog id="left"></dialog>
+<dialog id="right"></dialog>
+<script>
+document.querySelector('#left').showModal();
+document.querySelector('#right').showModal();
+</script>
+</body>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/dont-share-style-to-top-layer.html b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/dont-share-style-to-top-layer.html
new file mode 100644
index 00000000000..667e6ec7279
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/dont-share-style-to-top-layer.html
@@ -0,0 +1,18 @@
+<!doctype html>
+<link rel="match" href="../../../../../../expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/dont-share-style-to-top-layer-ref.html">
+<link rel="help" href="https://fullscreen.spec.whatwg.org/#new-stacking-layer">
+<style>
+dialog {
+ position: static;
+}
+#modal {
+ outline: none;
+}
+</style>
+<p>Test that a non-top layer element doesn't share style with a top layer
+element. The test passes if you see two boxes.</p>
+<dialog open></dialog>
+<dialog id="modal"></dialog>
+<script>
+document.querySelector('#modal').showModal();
+</script>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/element-removed-from-top-layer-has-original-position.html b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/element-removed-from-top-layer-has-original-position.html
new file mode 100644
index 00000000000..d2c47a597b9
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/element-removed-from-top-layer-has-original-position.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="match" href="../../../../../../expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/element-removed-from-top-layer-has-original-position-ref.html">
+<link rel="help" href="https://fullscreen.spec.whatwg.org/#new-stacking-layer">
+<style>
+.green {
+ color: green;
+}
+
+#right-dialog {
+ display: inline;
+ position: static;
+ border: none;
+ padding: 0;
+ margin: 0;
+ outline: none;
+}
+</style>
+</head>
+<body>
+<p>Bug <a href="http://webkit.org/b/106538">106538</a>: Top layer fails for inline elements</p>
+<p>This tests that position 'static' no longer computes to 'absolute' for an
+element that has been removed from the top layer. The test passes if you see
+a single line of text.</p>
+<span class="green">This is the span.</span>
+<dialog class="green" id="right-dialog">This is the dialog following it.</dialog>
+<script>
+var dialog = document.getElementById('right-dialog');
+dialog.showModal();
+dialog.close();
+dialog.show();
+</script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-relative.html b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-relative.html
new file mode 100644
index 00000000000..66500894f13
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-relative.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<link rel=author href="mailto:[email protected]">
+<link rel=author href="mailto:[email protected]">
+<link rel=help href="https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element">
+<link rel=help href="https://bugs.webkit.org/show_bug.cgi?id=106538">
+<link rel=match href="../../../../../../expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-ref.html">
+<meta name=assert content="Position relative computes to absolute in the top layer for dialog elements.">
+
+<style>
+dialog {
+ background-color: green;
+ height: 50px;
+ width: 50px;
+ border: none;
+ padding: 0;
+ margin: 0;
+
+ position: relative;
+ top: 100px;
+ left: 100px;
+}
+</style>
+
+<dialog></dialog>
+
+<script>
+document.querySelector('dialog').showModal();
+</script>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-static.html b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-static.html
new file mode 100644
index 00000000000..ed2cd960db0
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-static.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<link rel=author href="mailto:[email protected]">
+<link rel=author href="mailto:[email protected]">
+<link rel=help href="https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element">
+<link rel=help href="https://bugs.webkit.org/show_bug.cgi?id=106538">
+<link rel=match href="../../../../../../expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position-ref.html">
+<meta name=assert content="Position static computes to absolute in the top layer for dialog elements.">
+
+<style>
+dialog {
+ background-color: green;
+ height: 50px;
+ width: 50px;
+ border: none;
+ padding: 0;
+ margin: 0;
+
+ position: static;
+ top: 100px;
+ left: 100px;
+}
+</style>
+
+<dialog></dialog>
+
+<script>
+document.querySelector('dialog').showModal();
+</script>
diff --git a/Tests/LibWeb/Text/expected/wpt-import/fullscreen/api/fullscreen-display-contents.txt b/Tests/LibWeb/Text/expected/wpt-import/fullscreen/api/fullscreen-display-contents.txt
index 530a9ce6e06..7c174dee2a2 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/fullscreen/api/fullscreen-display-contents.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/fullscreen/api/fullscreen-display-contents.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail
+1 Pass
+Pass
Test that display:contents on fullscreen elements acts like
display:block
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position.txt
new file mode 100644
index 00000000000..a0ee3ce3f42
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Verifies that position:static and position:relative computed to position:absolute in the top layer.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position.html
new file mode 100644
index 00000000000..6c0aaec9944
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/interactive-elements/the-dialog-element/top-layer-position.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<link rel=author href="mailto:[email protected]">
+<link rel=help href="https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element">
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+
+<body>
+<script>
+test(() => {
+ const dialog = document.createElement('dialog');
+ document.body.appendChild(dialog);
+
+ dialog.style = 'position:static';
+ assert_equals(getComputedStyle(dialog).position, 'static');
+ dialog.showModal();
+ assert_true(dialog.open);
+ assert_equals(getComputedStyle(dialog).position, 'absolute',
+ `dialog should be position:absolute when element.style has position:static.`);
+ dialog.close();
+ assert_false(dialog.open);
+
+ dialog.style = 'position:relative';
+ assert_equals(getComputedStyle(dialog).position, 'relative');
+ dialog.showModal();
+ assert_true(dialog.open);
+ assert_equals(getComputedStyle(dialog).position, 'absolute',
+ `dialog should be position:absolute when element.style has position:relative.`);
+ dialog.close();
+ assert_false(dialog.open);
+}, `Verifies that position:static and position:relative computed to position:absolute in the top layer.`);
+</script>