From 1a055fcb24a59b19c55eb64cc152bf4b3bc73f94 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 19 May 2025 11:04:13 +0200 Subject: [PATCH] LibWeb: Mark canvas element for relayout when width or height changes While width and height are presentational hints on canvas, they actually map to the CSS aspect-ratio attribute, not to CSS width and height. For this reason, we actually need to manually mark for relayout here. Also import a WPT test that was flaky before this change. --- Libraries/LibWeb/DOM/Node.h | 1 + Libraries/LibWeb/HTML/HTMLCanvasElement.cpp | 2 ++ ...t.size.attributes.setAttribute.decimal.txt | 6 ++++ ....size.attributes.setAttribute.decimal.html | 33 ++++++++++++++++++ ...t.size.attributes.setAttribute.decimal.png | Bin 0 -> 137 bytes 5 files changed, 42 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.html create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.png diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index ba97eb981e3..43b0531631c 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -93,6 +93,7 @@ enum class StyleInvalidationReason { #define ENUMERATE_SET_NEEDS_LAYOUT_REASONS(X) \ X(CharacterDataReplaceData) \ X(FinalizeACrossDocumentNavigation) \ + X(HTMLCanvasElementWidthOrHeightChange) \ X(HTMLImageElementReactToChangesInTheEnvironment) \ X(HTMLImageElementUpdateTheImageData) \ X(HTMLVideoElementSetVideoTrack) \ diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index e426899c8db..eb1212d5cf8 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -193,6 +193,8 @@ void HTMLCanvasElement::attribute_changed(FlyString const& local_name, Optional< if (local_name.equals_ignoring_ascii_case(HTML::AttributeNames::width) || local_name.equals_ignoring_ascii_case(HTML::AttributeNames::height)) { notify_context_about_canvas_size_change(); reset_context_to_default_state(); + if (auto layout_node = this->layout_node()) + layout_node->set_needs_layout_update(DOM::SetNeedsLayoutReason::HTMLCanvasElementWidthOrHeightChange); } } diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.txt new file mode 100644 index 00000000000..e9b811cbae3 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Parsing of non-negative integers in setAttribute \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.html b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.html new file mode 100644 index 00000000000..b30c440260d --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.html @@ -0,0 +1,33 @@ + + + +Canvas test: 2d.canvas.host.size.attributes.setAttribute.decimal + + + + + + +

2d.canvas.host.size.attributes.setAttribute.decimal

+

Parsing of non-negative integers in setAttribute

+ + +

Actual output:

+

FAIL (fallback content)

+

Expected output:

+

+ + diff --git a/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.png b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/canvas-host/2d.canvas.host.size.attributes.setAttribute.decimal.png new file mode 100644 index 0000000000000000000000000000000000000000..f8426733306293c70134e35f4704268b7a19a407 GIT binary patch literal 137 zcmeAS@N?(olHy`uVBq!ia0y~yU`PRB4mJh`hJr^^Ll_ts*pj^6T^Rm@;DWu&Co?cG z*m=4*hE&XXd(e=Pfq~)Bg0KF$-1-X`hyo4E8RslvU|d!@wGX7;)78&qol`;+0PUI_ An*aa+ literal 0 HcmV?d00001