Skip to content

Truly independent web browser

LibWeb: Skip auto scrolling in scrollports smaller than a pixel

Jelle Raaijmakers0091d3229147
diff --git a/Libraries/LibWeb/Page/AutoScrollHandler.cpp b/Libraries/LibWeb/Page/AutoScrollHandler.cpp
index f64ea713642..f2157f6deb8 100644
--- a/Libraries/LibWeb/Page/AutoScrollHandler.cpp
+++ b/Libraries/LibWeb/Page/AutoScrollHandler.cpp
@@ -41,10 +41,14 @@ static Optional<CSSPixelRect> scrollport_rect_in_viewport(Layout::Node const& la
auto scrollport = Painting::absolute_padding_box_rect(layout_node);
// The viewport's scrollport is already in viewport coordinates.
- if (Painting::is_viewport_paintable(layout_node))
- return scrollport;
+ if (!Painting::is_viewport_paintable(layout_node))
+ scrollport = Painting::transform_rect_to_viewport(layout_node, scrollport);
- return Painting::transform_rect_to_viewport(layout_node, scrollport);
+ // A scrollport smaller than a pixel has no point the mouse can be constrained to.
+ if (scrollport.width() < 1 || scrollport.height() < 1)
+ return {};
+
+ return scrollport;
}
// Returns scroll speed in CSS pixels per second for each axis, based on how far the mouse is past the auto scroll edge.
diff --git a/Tests/LibWeb/Crash/UIEvents/selection-auto-scroll-collapsed-scrollport.html b/Tests/LibWeb/Crash/UIEvents/selection-auto-scroll-collapsed-scrollport.html
new file mode 100644
index 00000000000..8002c5c8d0c
--- /dev/null
+++ b/Tests/LibWeb/Crash/UIEvents/selection-auto-scroll-collapsed-scrollport.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<div id="container" style="overflow: auto; width: 200px; height: 100px">line1<br>line2<br>line3<br>line4<br>line5<br>line6<br>line7<br>line8<br>line9<br>line10</div>
+<script>
+ const rect = container.getBoundingClientRect();
+ internals.mouseDown(rect.x + 10, rect.y + 10);
+
+ container.style.width = "0";
+ container.style.height = "0";
+ container.style.padding = "0";
+ document.body.offsetWidth;
+
+ internals.mouseMove(rect.x + 50, rect.y + 50);
+ internals.mouseUp(rect.x + 50, rect.y + 50);
+</script>