Skip to content

Truly independent web browser

LibWeb: Preserve the computed block display of buttons

sideshowbarkeracaafc5029a0
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs b/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs
index ffa1d8303fd..3a6c04ec26a 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs
@@ -193,6 +193,7 @@ pub(super) fn adjust_element_style(
new_display = FfiDisplay::inline_block();
}
if input.is_button_element
+ && new_display != FfiDisplay::block()
&& !(new_display.is_flex_inside()
|| new_display.is_grid_inside()
|| new_display.is_none()
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs b/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs
index 860939603de..fcfc763ea31 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute/tests.rs
@@ -229,8 +229,8 @@ fn element_style_adjustments_follow_box_type_transformation() {
let adjustments = compute_element_style_adjustments(&input, keyword::LEFT);
assert!(adjustments.box_type.changed_display);
assert!(adjustments.box_type.display.is_block_outside());
- assert!(adjustments.element_style.changed_display);
- assert!(adjustments.element_style.display.is_flow_root_inside());
+ assert!(!adjustments.element_style.changed_display);
+ assert_eq!(adjustments.element_style.display, FfiDisplay::block());
}
fn test_context() -> FfiLengthResolutionContext {
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index baf5433ed39..75f41bb05dd 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -8517,6 +8517,7 @@ impl<'pass> BlockFormattingContext<'pass> {
if facts.has_dom_node()
&& (facts.is_floating()
|| facts.is_absolutely_positioned()
+ || facts.uses_button_layout()
|| self.style(node).own_style_establishes_block_formatting_context()
|| !self.style(node).display().is_flow_inside())
{
diff --git a/Tests/LibWeb/Text/expected/css/block-button-computed-display.txt b/Tests/LibWeb/Text/expected/css/block-button-computed-display.txt
new file mode 100644
index 00000000000..1f2ba4f1c16
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/block-button-computed-display.txt
@@ -0,0 +1,5 @@
+block
+flow-root
+flex
+grid
+43
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-display/display-contents-blockify-dynamic.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-display/display-contents-blockify-dynamic.txt
index 9e0e5a72dcb..6660d0caccc 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-display/display-contents-blockify-dynamic.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-display/display-contents-blockify-dynamic.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 3 tests
-1 Pass
-2 Fail
+3 Pass
Pass Dynamic changes to `display` causing blockification of children are handled correctly
-Fail Dynamic changes to `display` from `grid` to `block` should cause children to get de-blockified despite being children of `display: contents` elements
-Fail Dynamic changes to `display` from `block` to `grid` should cause children to get blockified despite being children of `display: contents` elements
\ No newline at end of file
+Pass Dynamic changes to `display` from `grid` to `block` should cause children to get de-blockified despite being children of `display: contents` elements
+Pass Dynamic changes to `display` from `block` to `grid` should cause children to get blockified despite being children of `display: contents` elements
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/css/block-button-computed-display.html b/Tests/LibWeb/Text/input/css/block-button-computed-display.html
new file mode 100644
index 00000000000..2225d1859d5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/block-button-computed-display.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<script src="../include.js"></script>
+<button id="target">Button</button>
+<script>
+ test(() => {
+ for (const display of ["block", "flow-root", "flex", "grid"]) {
+ target.style.display = display;
+ println(getComputedStyle(target).display);
+ }
+ target.style.cssText = "display: block; border: 0; padding: 0";
+ target.innerHTML = '<span style="float: left; width: 15px; height: 43px"></span>';
+ println(target.offsetHeight);
+ });
+</script>