Skip to content

Truly independent web browser

LibWeb: Let Range client rects take the identity shortcut

Aliaksandr Kalenik3deac56543da
diff --git a/Libraries/LibWeb/DOM/Range.cpp b/Libraries/LibWeb/DOM/Range.cpp
index 40cae6bf905..68a2b47c364 100644
--- a/Libraries/LibWeb/DOM/Range.cpp
+++ b/Libraries/LibWeb/DOM/Range.cpp
@@ -1305,7 +1305,6 @@ Vector<Gfx::DoubleRect> Range::client_rects()
auto& document = start_container()->document();
document.update_layout(DOM::UpdateLayoutReason::RangeGetClientRects);
- document.update_paint_and_hit_testing_properties_if_needed();
Layout::ForcedReadScope read { document };
Vector<Gfx::DoubleRect> rects;
Optional<Compositing::AccumulatedVisualContextTree> visual_context_tree;
diff --git a/Tests/LibWeb/Text/expected/range-client-rects-lazy-visual-context-update.txt b/Tests/LibWeb/Text/expected/range-client-rects-lazy-visual-context-update.txt
new file mode 100644
index 00000000000..f95e9768eaf
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/range-client-rects-lazy-visual-context-update.txt
@@ -0,0 +1,2 @@
+rects: 1, at the origin of the text: true
+visual context updates: 0
diff --git a/Tests/LibWeb/Text/input/range-client-rects-lazy-visual-context-update.html b/Tests/LibWeb/Text/input/range-client-rects-lazy-visual-context-update.html
new file mode 100644
index 00000000000..bf0b1929a00
--- /dev/null
+++ b/Tests/LibWeb/Text/input/range-client-rects-lazy-visual-context-update.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<div id="target" style="width: 100px">hello</div>
+<script>
+ // The client rects of a range over text that no box transforms or scrolls are its absolute rects, which spares the
+ // visual context update a layout left pending. Printing lays the document out, so the lines are printed last.
+ test(() => {
+ const visualContextUpdateCount = () =>
+ internals.accumulatedVisualContextTreeBuildCount() + internals.accumulatedVisualContextIncrementalUpdateCount();
+ const range = document.createRange();
+ range.selectNodeContents(target.firstChild);
+ range.getClientRects();
+ const lines = [];
+ target.style.width = "120px";
+ const before = visualContextUpdateCount();
+ const rects = range.getClientRects();
+ const updates = visualContextUpdateCount() - before;
+ lines.push(`rects: ${rects.length}, at the origin of the text: ${rects[0].left === target.getBoundingClientRect().left}`);
+ lines.push(`visual context updates: ${updates}`);
+ for (const line of lines)
+ println(line);
+ });
+</script>