Skip to content

Truly independent web browser

LibWeb: Round client and scroll sizes to the nearest integer

Andreas Klingc85bb17dea47
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index d9f1a81bebf..9c8f33d6555 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -3244,7 +3244,8 @@ int Element::client_width() const
// 3. Return the width of the padding edge excluding the width of any rendered scrollbar between the padding edge and the border edge,
// ignoring any transforms that apply to the element and its ancestors.
- return Painting::absolute_padding_box_rect(*layout_node).width().to_int();
+ // INTEROP: The result is rounded to the nearest integer rather than truncated, as browsers do.
+ return round(Painting::absolute_padding_box_rect(*layout_node).width()).to_int();
}
// https://drafts.csswg.org/cssom-view/#dom-element-clientheight
@@ -3271,7 +3272,8 @@ int Element::client_height() const
// 3. Return the height of the padding edge excluding the height of any rendered scrollbar between the padding edge and the border edge,
// ignoring any transforms that apply to the element and its ancestors.
- return Painting::absolute_padding_box_rect(*layout_node).height().to_int();
+ // INTEROP: The result is rounded to the nearest integer rather than truncated, as browsers do.
+ return round(Painting::absolute_padding_box_rect(*layout_node).height()).to_int();
}
// https://drafts.csswg.org/cssom-view/#dom-element-currentcsszoom
@@ -4033,7 +4035,8 @@ int Element::scroll_width()
// 3. Let viewport width be the width of the viewport excluding the width of the scroll bar, if any,
// or zero if there is no viewport.
auto viewport_width = document.viewport_rect().width().to_int();
- auto viewport_scrolling_area_width = viewport_scrollable_overflow_rect->width().to_int();
+ // INTEROP: The scrolling area width is rounded to the nearest integer rather than truncated, as browsers do.
+ auto viewport_scrolling_area_width = round(viewport_scrollable_overflow_rect->width()).to_int();
// 4. If the element is the root element and document is not in quirks mode
// return max(viewport scrolling area width, viewport width).
@@ -4051,8 +4054,9 @@ int Element::scroll_width()
return 0;
// 7. Return the width of the element’s scrolling area.
+ // INTEROP: The result is rounded to the nearest integer rather than truncated, as browsers do.
if (auto scrollable_overflow_rect = Painting::scrollable_overflow_rect(*layout_node); scrollable_overflow_rect.has_value())
- return scrollable_overflow_rect->width().to_int();
+ return round(scrollable_overflow_rect->width()).to_int();
return 0;
}
@@ -4078,7 +4082,8 @@ int Element::scroll_height()
// 3. Let viewport height be the height of the viewport excluding the height of the scroll bar, if any,
// or zero if there is no viewport.
auto viewport_height = document.viewport_rect().height().to_int();
- auto viewport_scrolling_area_height = viewport_scrollable_overflow_rect->height().to_int();
+ // INTEROP: The scrolling area height is rounded to the nearest integer rather than truncated, as browsers do.
+ auto viewport_scrolling_area_height = round(viewport_scrollable_overflow_rect->height()).to_int();
// 4. If the element is the root element and document is not in quirks mode
// return max(viewport scrolling area height, viewport height).
@@ -4096,8 +4101,9 @@ int Element::scroll_height()
return 0;
// 7. Return the height of the element’s scrolling area.
+ // INTEROP: The result is rounded to the nearest integer rather than truncated, as browsers do.
if (auto scrollable_overflow_rect = Painting::scrollable_overflow_rect(*layout_node); scrollable_overflow_rect.has_value()) {
- return scrollable_overflow_rect->height().to_int();
+ return round(scrollable_overflow_rect->height()).to_int();
}
return 0;
}
diff --git a/Tests/LibWeb/Text/expected/CSSOMView/root-scroll-size-rounds-fractional-scrolling-area.txt b/Tests/LibWeb/Text/expected/CSSOMView/root-scroll-size-rounds-fractional-scrolling-area.txt
new file mode 100644
index 00000000000..b0bbef8395c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/CSSOMView/root-scroll-size-rounds-fractional-scrolling-area.txt
@@ -0,0 +1,3 @@
+viewport: 800x600
+root scrollWidth: 801
+root scrollHeight: 1001
diff --git a/Tests/LibWeb/Text/expected/css/pseudo-elements-on-hover.txt b/Tests/LibWeb/Text/expected/css/pseudo-elements-on-hover.txt
index 2d3541b604b..9d952a3819f 100644
--- a/Tests/LibWeb/Text/expected/css/pseudo-elements-on-hover.txt
+++ b/Tests/LibWeb/Text/expected/css/pseudo-elements-on-hover.txt
@@ -1,3 +1,3 @@
-update: 16 create: 0
-update: 78 create: 33
-update: 16 create: 0
+update: 17 create: 0
+update: 79 create: 34
+update: 17 create: 0
diff --git a/Tests/LibWeb/Text/expected/css/scrollable-overflow-recalc-property-matrix.txt b/Tests/LibWeb/Text/expected/css/scrollable-overflow-recalc-property-matrix.txt
index 6fd5db4cdd2..8b6fdf5adca 100644
--- a/Tests/LibWeb/Text/expected/css/scrollable-overflow-recalc-property-matrix.txt
+++ b/Tests/LibWeb/Text/expected/css/scrollable-overflow-recalc-property-matrix.txt
@@ -1,7 +1,7 @@
initial: scrollWidth=100 scrollHeight=100 relayouts=1
translate: scrollWidth=100 scrollHeight=390 relayouts=0
-rotate: scrollWidth=108 scrollHeight=108 relayouts=0
+rotate: scrollWidth=109 scrollHeight=109 relayouts=0
scale: scrollWidth=270 scrollHeight=270 relayouts=0
-transform: scrollWidth=108 scrollHeight=108 relayouts=0
+transform: scrollWidth=109 scrollHeight=109 relayouts=0
transform-origin: scrollWidth=100 scrollHeight=127 relayouts=0
transform-box: scrollWidth=100 scrollHeight=123 relayouts=0
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-transform-008.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-transform-008.txt
index 2214f9b03ef..e6a5c7e1958 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-transform-008.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-transform-008.txt
@@ -2,6 +2,6 @@ Harness status: OK
Found 2 tests
-2 Fail
-Fail .container 1
-Fail .container 2
\ No newline at end of file
+2 Pass
+Pass .container 1
+Pass .container 2
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/fractional-percent-width.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/fractional-percent-width.txt
index d5d8a7cb37d..8d944e02b7f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/fractional-percent-width.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-tables/fractional-percent-width.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 3 tests
-1 Pass
-2 Fail
+3 Pass
Pass .cell 1
-Fail .cell 2
-Fail .cell 3
\ No newline at end of file
+Pass .cell 2
+Pass .cell 3
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/CSSOMView/root-scroll-size-rounds-fractional-scrolling-area.html b/Tests/LibWeb/Text/input/CSSOMView/root-scroll-size-rounds-fractional-scrolling-area.html
new file mode 100644
index 00000000000..e8c2930dcd9
--- /dev/null
+++ b/Tests/LibWeb/Text/input/CSSOMView/root-scroll-size-rounds-fractional-scrolling-area.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<style>
+ body { margin: 0; }
+ #content { position: absolute; top: 0; left: 0; width: 800.75px; height: 1000.75px; }
+</style>
+<script src="../include.js"></script>
+<div id="content"></div>
+<script>
+ test(() => {
+ const root = document.documentElement;
+ println(`viewport: ${window.innerWidth}x${window.innerHeight}`);
+ println(`root scrollWidth: ${root.scrollWidth}`);
+ println(`root scrollHeight: ${root.scrollHeight}`);
+ });
+</script>