Title: [288180] trunk
Revision
288180
Author
[email protected]
Date
2022-01-18 21:13:37 -0800 (Tue, 18 Jan 2022)

Log Message

Loupe sometimes flips to the bottom of the page when dragging the end of a selection to the top of a page with selection flipping.
https://bugs.webkit.org/show_bug.cgi?id=235220

Reviewed by Tim Horton.

Source/WebCore:

Test: fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html

When selecting on an EPUB in books, if you had a selection near the top of the page,
and you dragged the end of the selection past the start and into the upper margin, sometimes
this would result in the selection ending up on the previous page of content, which would result
in the loupe being pushed to the bottom of the page (because the selection was on the previous page
at the bottom), which is incorrect. The most solid way to keep this from happening is to clamp the selection
to the unobscured content rect, which will keep selection from reaching back to the previous page.

* platform/graphics/FloatPoint.cpp:
(WebCore::FloatPoint::constrainedWithin const):
* platform/graphics/FloatPoint.h:
* platform/graphics/IntPoint.cpp:
(WebCore::IntPoint::constrainedWithin const):
* platform/graphics/IntPoint.h:

Source/WebKit:

When selecting on an EPUB in books, if you had a selection near the top of the page,
and you dragged the end of the selection past the start and into the upper margin, sometimes
this would result in the selection ending up on the previous page of content, which would result
in the loupe being pushed to the bottom of the page (because the selection was on the previous page
at the bottom), which is incorrect. The most solid way to keep this from happening is to clamp the selection
to the unobscured content rect, which will keep selection from reaching back to the previous page.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::rangeForPointInRootViewCoordinates):

LayoutTests:

* fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow-expected.txt: Added.
* fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288179 => 288180)


--- trunk/LayoutTests/ChangeLog	2022-01-19 03:29:54 UTC (rev 288179)
+++ trunk/LayoutTests/ChangeLog	2022-01-19 05:13:37 UTC (rev 288180)
@@ -1,3 +1,13 @@
+2022-01-18  Megan Gardner  <[email protected]>
+
+        Loupe sometimes flips to the bottom of the page when dragging the end of a selection to the top of a page with selection flipping.
+        https://bugs.webkit.org/show_bug.cgi?id=235220
+
+        Reviewed by Tim Horton.
+
+        * fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow-expected.txt: Added.
+        * fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html: Added.
+
 2022-01-18  Wenson Hsieh  <[email protected]>
 
         REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus

Added: trunk/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow-expected.txt (0 => 288180)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow-expected.txt	2022-01-19 05:13:37 UTC (rev 288180)
@@ -0,0 +1,2 @@
+PASS: Has Selection
+PASS: Selection properly bounded

Added: trunk/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html (0 => 288180)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html	2022-01-19 05:13:37 UTC (rev 288180)
@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+
+        function rectToString(rect)
+        {
+            return `(left = ${Math.round(rect.left)}, top = ${Math.round(rect.top)}, width = ${Math.round(rect.width)}, height = ${Math.round(rect.height)})`;
+        }
+
+        async function runTest()
+        {
+            var fontHeight = 30;
+
+            if (!testRunner.runUIScript)
+                return;
+
+            window.scrollBy(0, window.innerHeight);
+
+            var output = '';
+            var targetRect = document.getElementById('target').getBoundingClientRect();
+
+            var pressPointX = window.screen.width / 2;
+            var pressPointY = fontHeight + window.innerHeight;
+            
+            var selectionChangedCount = 0;
+            document.addEventListener("selectionchange", () => {
+                selectionChangedCount++;
+            });
+
+            await longPressAtPoint(pressPointX, pressPointY);
+
+            await UIHelper.waitForSelectionToAppear();
+
+            if (document.getSelection().toString() != "")
+                output += 'PASS: Has Selection';
+            else
+                output += 'FAIL: failed to select a word as a result of a long press.';
+            output += '<br>';
+
+            lastSelectionChangeCount = selectionChangedCount;
+            var grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y , grabberMidpoint.x, grabberMidpoint.y - (fontHeight * 2));
+
+            if ((await UIHelper.getUISelectionRects()).length > 2)
+                output += 'FAIL: Selected outside of visible area.';
+            else
+                output += 'PASS: Selection properly bounded';
+
+            document.getElementById('target').innerHTML = output;
+            testRunner.notifyDone();
+        }
+
+        window.addEventListener('load', runTest, false);
+    </script>
+    <style>
+        #target {
+            height: 50px;
+            width: 300px;
+            background-color: silver;
+            font-family: monospace;
+            font-size: 18px;
+        }
+        body {
+            overflow: hidden;
+        }
+    </style>
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+    <div id="target">
+        <p>Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes. The ones who see things differently. They're not fond of rules. And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them. About the only thing you can't do is ignore them. Because they change things. They push the human race forward. And while some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they can change the world, are the ones who do.</p>
+        <p>Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes. The ones who see things differently. They're not fond of rules. And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them. About the only thing you can't do is ignore them. Because they change things. They push the human race forward. And while some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they can change the world, are the ones who do.</p>
+        <p>Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes. The ones who see things differently. They're not fond of rules. And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them. About the only thing you can't do is ignore them. Because they change things. They push the human race forward. And while some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they can change the world, are the ones who do.</p>
+        <p>This test requires UIScriptController to run.</p>
+    </div>
+</body>
+</html>
+

Modified: trunk/Source/WebCore/ChangeLog (288179 => 288180)


--- trunk/Source/WebCore/ChangeLog	2022-01-19 03:29:54 UTC (rev 288179)
+++ trunk/Source/WebCore/ChangeLog	2022-01-19 05:13:37 UTC (rev 288180)
@@ -1,3 +1,26 @@
+2022-01-18  Megan Gardner  <[email protected]>
+
+        Loupe sometimes flips to the bottom of the page when dragging the end of a selection to the top of a page with selection flipping.
+        https://bugs.webkit.org/show_bug.cgi?id=235220
+
+        Reviewed by Tim Horton.
+
+        Test: fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html
+
+        When selecting on an EPUB in books, if you had a selection near the top of the page,
+        and you dragged the end of the selection past the start and into the upper margin, sometimes
+        this would result in the selection ending up on the previous page of content, which would result
+        in the loupe being pushed to the bottom of the page (because the selection was on the previous page
+        at the bottom), which is incorrect. The most solid way to keep this from happening is to clamp the selection
+        to the unobscured content rect, which will keep selection from reaching back to the previous page.
+
+        * platform/graphics/FloatPoint.cpp:
+        (WebCore::FloatPoint::constrainedWithin const):
+        * platform/graphics/FloatPoint.h:
+        * platform/graphics/IntPoint.cpp:
+        (WebCore::IntPoint::constrainedWithin const):
+        * platform/graphics/IntPoint.h:
+
 2022-01-18  Chris Dumez  <[email protected]>
 
         When inserting a selected <option> in a <select> element, its selected state should remain

Modified: trunk/Source/WebCore/platform/graphics/FloatPoint.cpp (288179 => 288180)


--- trunk/Source/WebCore/platform/graphics/FloatPoint.cpp	2022-01-19 03:29:54 UTC (rev 288179)
+++ trunk/Source/WebCore/platform/graphics/FloatPoint.cpp	2022-01-19 05:13:37 UTC (rev 288180)
@@ -29,6 +29,7 @@
 
 #include "AffineTransform.h"
 #include "FloatConversion.h"
+#include "FloatRect.h"
 #include "IntPoint.h"
 #include "TransformationMatrix.h"
 #include <limits>
@@ -49,6 +50,11 @@
     };
 }
 
+FloatPoint FloatPoint::constrainedWithin(const FloatRect& rect) const
+{
+    return constrainedBetween(rect.minXMinYCorner(), rect.maxXMaxYCorner());
+}
+
 void FloatPoint::normalize()
 {
     float tempLength = length();

Modified: trunk/Source/WebCore/platform/graphics/FloatPoint.h (288179 => 288180)


--- trunk/Source/WebCore/platform/graphics/FloatPoint.h	2022-01-19 03:29:54 UTC (rev 288179)
+++ trunk/Source/WebCore/platform/graphics/FloatPoint.h	2022-01-19 05:13:37 UTC (rev 288180)
@@ -52,6 +52,7 @@
 class AffineTransform;
 class TransformationMatrix;
 class IntSize;
+class FloatRect;
 
 class FloatPoint {
     WTF_MAKE_FAST_ALLOCATED;
@@ -161,6 +162,8 @@
     }
 
     WEBCORE_EXPORT FloatPoint constrainedBetween(const FloatPoint& min, const FloatPoint& max) const;
+    
+    WEBCORE_EXPORT FloatPoint constrainedWithin(const FloatRect&) const;
 
     FloatPoint shrunkTo(const FloatPoint& other) const
     {

Modified: trunk/Source/WebCore/platform/graphics/IntPoint.cpp (288179 => 288180)


--- trunk/Source/WebCore/platform/graphics/IntPoint.cpp	2022-01-19 03:29:54 UTC (rev 288179)
+++ trunk/Source/WebCore/platform/graphics/IntPoint.cpp	2022-01-19 05:13:37 UTC (rev 288180)
@@ -27,6 +27,7 @@
 #include "IntPoint.h"
 
 #include "FloatPoint.h"
+#include "IntRect.h"
 #include <wtf/text/TextStream.h>
 
 namespace WebCore {
@@ -45,6 +46,11 @@
     };
 }
 
+IntPoint IntPoint::constrainedWithin(const IntRect& rect) const
+{
+    return constrainedBetween(rect.minXMinYCorner(), rect.maxXMaxYCorner());
+}
+
 TextStream& operator<<(TextStream& ts, const IntPoint& p)
 {
     return ts << "(" << p.x() << "," << p.y() << ")";

Modified: trunk/Source/WebCore/platform/graphics/IntPoint.h (288179 => 288180)


--- trunk/Source/WebCore/platform/graphics/IntPoint.h	2022-01-19 03:29:54 UTC (rev 288179)
+++ trunk/Source/WebCore/platform/graphics/IntPoint.h	2022-01-19 05:13:37 UTC (rev 288180)
@@ -54,6 +54,7 @@
 namespace WebCore {
 
 class FloatPoint;
+class IntRect;
 
 class IntPoint {
 public:
@@ -102,6 +103,8 @@
     }
 
     WEBCORE_EXPORT IntPoint constrainedBetween(const IntPoint& min, const IntPoint& max) const;
+    
+    WEBCORE_EXPORT IntPoint constrainedWithin(const IntRect&) const;
 
     int distanceSquaredToPoint(const IntPoint&) const;
 

Modified: trunk/Source/WebKit/ChangeLog (288179 => 288180)


--- trunk/Source/WebKit/ChangeLog	2022-01-19 03:29:54 UTC (rev 288179)
+++ trunk/Source/WebKit/ChangeLog	2022-01-19 05:13:37 UTC (rev 288180)
@@ -1,3 +1,20 @@
+2022-01-18  Megan Gardner  <[email protected]>
+
+        Loupe sometimes flips to the bottom of the page when dragging the end of a selection to the top of a page with selection flipping.
+        https://bugs.webkit.org/show_bug.cgi?id=235220
+
+        Reviewed by Tim Horton.
+
+        When selecting on an EPUB in books, if you had a selection near the top of the page,
+        and you dragged the end of the selection past the start and into the upper margin, sometimes
+        this would result in the selection ending up on the previous page of content, which would result
+        in the loupe being pushed to the bottom of the page (because the selection was on the previous page
+        at the bottom), which is incorrect. The most solid way to keep this from happening is to clamp the selection
+        to the unobscured content rect, which will keep selection from reaching back to the previous page.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::rangeForPointInRootViewCoordinates):
+
 2022-01-18  Wenson Hsieh  <[email protected]>
 
         REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (288179 => 288180)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-01-19 03:29:54 UTC (rev 288179)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-01-19 05:13:37 UTC (rev 288180)
@@ -1504,7 +1504,7 @@
     VisiblePosition selectionStart = existingSelection.visibleStart();
     VisiblePosition selectionEnd = existingSelection.visibleEnd();
 
-    auto pointInDocument = frame.view()->rootViewToContents(pointInRootViewCoordinates);
+    auto pointInDocument = frame.view()->rootViewToContents(pointInRootViewCoordinates.constrainedWithin(frame.mainFrame().view()->unobscuredContentRect()));
 
     if (!selectionFlippingEnabled) {
         auto node = selectionStart.deepEquivalent().containerNode();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to