Title: [279463] trunk
Revision
279463
Author
za...@apple.com
Date
2021-07-01 06:29:07 -0700 (Thu, 01 Jul 2021)

Log Message

VisiblePosition::absoluteSelectionBoundsForLine fails on multiline vertical-rl content
https://bugs.webkit.org/show_bug.cgi?id=227543
<rdar://79887141>

Reviewed by Simon Fraser.

Source/WebCore:

absoluteSelectionBoundsForLine flips the line's logical rect for the writing mode (horizontal vs. vertical)
but not for the block flow direction (ltr vs. rtl).
This adjustment is very similar to what we do in absoluteCaretBounds (see absoluteBoundsForLocalCaretRect).

* editing/VisiblePosition.cpp:
(WebCore::VisiblePosition::absoluteSelectionBoundsForLine const):
* testing/Internals.cpp:
(WebCore::Internals::absoluteLineRectFromPoint):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* fast/inline/line-rect-from-point-expected.txt: Added.
* fast/inline/line-rect-from-point.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (279462 => 279463)


--- trunk/LayoutTests/ChangeLog	2021-07-01 11:20:43 UTC (rev 279462)
+++ trunk/LayoutTests/ChangeLog	2021-07-01 13:29:07 UTC (rev 279463)
@@ -1,3 +1,14 @@
+2021-07-01  Alan Bujtas  <za...@apple.com>
+
+        VisiblePosition::absoluteSelectionBoundsForLine fails on multiline vertical-rl content
+        https://bugs.webkit.org/show_bug.cgi?id=227543
+        <rdar://79887141>
+
+        Reviewed by Simon Fraser.
+
+        * fast/inline/line-rect-from-point-expected.txt: Added.
+        * fast/inline/line-rect-from-point.html: Added.
+
 2021-07-01  Youenn Fablet  <you...@apple.com>
 
         [Cocoa] Migrate WebRTC UDP socket handling to NW API

Added: trunk/LayoutTests/fast/inline/line-rect-from-point-expected.txt (0 => 279463)


--- trunk/LayoutTests/fast/inline/line-rect-from-point-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/inline/line-rect-from-point-expected.txt	2021-07-01 13:29:07 UTC (rev 279463)
@@ -0,0 +1,12 @@
+short text
+long enough to wrap to next line
+short text
+short text
+long enough to wrap to next line
+short text
+short text
+long enough to wrap to next line
+short text
+[1x11][190x10]
+[11x203][10x190]
+[181x405][10x190]

Added: trunk/LayoutTests/fast/inline/line-rect-from-point.html (0 => 279463)


--- trunk/LayoutTests/fast/inline/line-rect-from-point.html	                        (rev 0)
+++ trunk/LayoutTests/fast/inline/line-rect-from-point.html	2021-07-01 13:29:07 UTC (rev 279463)
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+body {
+  font-family: Ahem;
+  font-size: 10px;
+  margin: 0px;
+}
+.container {
+  border: 1px solid green;
+  width: 200px;
+  height: 200px;
+}
+</style>
+</head>
+<body>
+<div id=first class=container style="writing-mode: horizontal-tb;">
+  <div>short text</div>
+  <div>long enough to wrap to next line</div>
+  <div>short text</div>
+</div>
+<div id=second class=container style="writing-mode: vertical-lr;">
+  <div>short text</div>
+  <div>long enough to wrap to next line</div>
+  <div>short text</div>
+</div>
+<div id=third class=container style="writing-mode: vertical-rl;">
+  <div>short text</div>
+  <div>long enough to wrap to next line</div>
+  <div>short text</div>
+</div>
+<pre id=result></pre>
+</body>
+<script>
+  document.body.offsetHeight;
+  if (window.internals) {
+    testRunner.dumpAsText();
+    let line1 = internals.absoluteLineRectFromPoint(first.offsetLeft + 5, first.offsetTop + 15);
+    let line2 = internals.absoluteLineRectFromPoint(second.offsetLeft + 15, second.offsetTop + 5);
+    let line3 = internals.absoluteLineRectFromPoint(third.offsetWidth - 15, third.offsetTop + 5);
+    result.innerHTML= "[" + line1.x + "x" + line1.y + "]" + "[" + line1.width + "x" + line1.height + "]"
+      + "<br>[" + line2.x + "x" + line2.y + "]" + "[" + line2.width + "x" + line2.height + "]"
+      + "<br>[" + line3.x + "x" + line3.y + "]" + "[" + line3.width + "x" + line3.height + "]";
+}
+</script>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (279462 => 279463)


--- trunk/Source/WebCore/ChangeLog	2021-07-01 11:20:43 UTC (rev 279462)
+++ trunk/Source/WebCore/ChangeLog	2021-07-01 13:29:07 UTC (rev 279463)
@@ -1,3 +1,22 @@
+2021-07-01  Alan Bujtas  <za...@apple.com>
+
+        VisiblePosition::absoluteSelectionBoundsForLine fails on multiline vertical-rl content
+        https://bugs.webkit.org/show_bug.cgi?id=227543
+        <rdar://79887141>
+
+        Reviewed by Simon Fraser.
+
+        absoluteSelectionBoundsForLine flips the line's logical rect for the writing mode (horizontal vs. vertical)
+        but not for the block flow direction (ltr vs. rtl).
+        This adjustment is very similar to what we do in absoluteCaretBounds (see absoluteBoundsForLocalCaretRect).
+
+        * editing/VisiblePosition.cpp:
+        (WebCore::VisiblePosition::absoluteSelectionBoundsForLine const):
+        * testing/Internals.cpp:
+        (WebCore::Internals::absoluteLineRectFromPoint):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2021-07-01  Carlos Garcia Campos  <cgar...@igalia.com>
 
         REGRESSION(r278062): [Nicosia] Threaded rendering is broken since r278062

Modified: trunk/Source/WebCore/editing/VisiblePosition.cpp (279462 => 279463)


--- trunk/Source/WebCore/editing/VisiblePosition.cpp	2021-07-01 11:20:43 UTC (rev 279462)
+++ trunk/Source/WebCore/editing/VisiblePosition.cpp	2021-07-01 13:29:07 UTC (rev 279463)
@@ -663,7 +663,7 @@
     auto localRect = FloatRect { FloatPoint { line->contentLogicalLeft(), line->selectionTop() }, FloatPoint { line->contentLogicalRight(), line->selectionBottom() } };
     if (!line->isHorizontal())
         localRect = localRect.transposedRect();
-
+    line->containingBlock().flipForWritingMode(localRect);
     return line->containingBlock().localToAbsoluteQuad(localRect).boundingBox();
 }
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (279462 => 279463)


--- trunk/Source/WebCore/testing/Internals.cpp	2021-07-01 11:20:43 UTC (rev 279462)
+++ trunk/Source/WebCore/testing/Internals.cpp	2021-07-01 13:29:07 UTC (rev 279463)
@@ -1658,6 +1658,23 @@
 }
 #endif // ENABLE(MEDIA_STREAM)
 
+ExceptionOr<Ref<DOMRect>> Internals::absoluteLineRectFromPoint(int x, int y)
+{
+    if (!contextDocument() || !contextDocument()->page())
+        return Exception { InvalidAccessError };
+
+    auto& document = *contextDocument();
+    if (!document.frame() || !document.view())
+        return Exception { InvalidAccessError };
+
+    auto& frame = *document.frame();
+    auto& view = *document.view();
+    document.updateLayoutIgnorePendingStylesheets();
+
+    auto position = frame.visiblePositionForPoint(view.rootViewToContents(IntPoint { x, y }));
+    return DOMRect::create(position.absoluteSelectionBoundsForLine());
+}
+
 ExceptionOr<Ref<DOMRect>> Internals::absoluteCaretBounds()
 {
     Document* document = contextDocument();

Modified: trunk/Source/WebCore/testing/Internals.h (279462 => 279463)


--- trunk/Source/WebCore/testing/Internals.h	2021-07-01 11:20:43 UTC (rev 279462)
+++ trunk/Source/WebCore/testing/Internals.h	2021-07-01 13:29:07 UTC (rev 279463)
@@ -272,6 +272,8 @@
     ExceptionOr<Vector<String>> formControlStateOfPreviousHistoryItem();
     ExceptionOr<void> setFormControlStateOfPreviousHistoryItem(const Vector<String>&);
 
+    ExceptionOr<Ref<DOMRect>> absoluteLineRectFromPoint(int x, int y);
+
     ExceptionOr<Ref<DOMRect>> absoluteCaretBounds();
     ExceptionOr<bool> isCaretBlinkingSuspended();
 

Modified: trunk/Source/WebCore/testing/Internals.idl (279462 => 279463)


--- trunk/Source/WebCore/testing/Internals.idl	2021-07-01 11:20:43 UTC (rev 279462)
+++ trunk/Source/WebCore/testing/Internals.idl	2021-07-01 13:29:07 UTC (rev 279463)
@@ -350,6 +350,8 @@
     sequence<DOMString> formControlStateOfPreviousHistoryItem();
     undefined setFormControlStateOfPreviousHistoryItem(sequence<DOMString> values);
 
+    DOMRect absoluteLineRectFromPoint(long x, long y);
+
     DOMRect absoluteCaretBounds();
     boolean isCaretBlinkingSuspended();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to