Title: [288513] branches/safari-613-branch
Revision
288513
Author
[email protected]
Date
2022-01-24 17:55:47 -0800 (Mon, 24 Jan 2022)

Log Message

Cherry-pick r288180. rdar://problem/84440841

    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.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288180 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (288512 => 288513)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-01-25 01:55:41 UTC (rev 288512)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-01-25 01:55:47 UTC (rev 288513)
@@ -1,5 +1,62 @@
 2022-01-24  Alan Coon  <[email protected]>
 
+        Cherry-pick r288180. rdar://problem/84440841
+
+    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.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-24  Alan Coon  <[email protected]>
+
         Cherry-pick r288099. rdar://problem/86586969
 
     Layered @import rules in <style> should be preloaded

Added: branches/safari-613-branch/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow-expected.txt (0 => 288513)


--- branches/safari-613-branch/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow-expected.txt	2022-01-25 01:55:47 UTC (rev 288513)
@@ -0,0 +1,2 @@
+PASS: Has Selection
+PASS: Selection properly bounded

Added: branches/safari-613-branch/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html (0 => 288513)


--- branches/safari-613-branch/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/fast/events/touch/ios/long-press-then-drag-up-to-change-selected-text-overflow.html	2022-01-25 01:55:47 UTC (rev 288513)
@@ -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: branches/safari-613-branch/Source/WebCore/ChangeLog (288512 => 288513)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-01-25 01:55:41 UTC (rev 288512)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-01-25 01:55:47 UTC (rev 288513)
@@ -1,5 +1,75 @@
 2022-01-24  Alan Coon  <[email protected]>
 
+        Cherry-pick r288180. rdar://problem/84440841
+
+    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.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-24  Alan Coon  <[email protected]>
+
         Cherry-pick r288111. rdar://problem/87699260
 
     [:has() pseudo-class] Disallow nested :has()

Modified: branches/safari-613-branch/Source/WebCore/platform/graphics/FloatPoint.cpp (288512 => 288513)


--- branches/safari-613-branch/Source/WebCore/platform/graphics/FloatPoint.cpp	2022-01-25 01:55:41 UTC (rev 288512)
+++ branches/safari-613-branch/Source/WebCore/platform/graphics/FloatPoint.cpp	2022-01-25 01:55:47 UTC (rev 288513)
@@ -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: branches/safari-613-branch/Source/WebCore/platform/graphics/FloatPoint.h (288512 => 288513)


--- branches/safari-613-branch/Source/WebCore/platform/graphics/FloatPoint.h	2022-01-25 01:55:41 UTC (rev 288512)
+++ branches/safari-613-branch/Source/WebCore/platform/graphics/FloatPoint.h	2022-01-25 01:55:47 UTC (rev 288513)
@@ -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: branches/safari-613-branch/Source/WebCore/platform/graphics/IntPoint.cpp (288512 => 288513)


--- branches/safari-613-branch/Source/WebCore/platform/graphics/IntPoint.cpp	2022-01-25 01:55:41 UTC (rev 288512)
+++ branches/safari-613-branch/Source/WebCore/platform/graphics/IntPoint.cpp	2022-01-25 01:55:47 UTC (rev 288513)
@@ -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: branches/safari-613-branch/Source/WebCore/platform/graphics/IntPoint.h (288512 => 288513)


--- branches/safari-613-branch/Source/WebCore/platform/graphics/IntPoint.h	2022-01-25 01:55:41 UTC (rev 288512)
+++ branches/safari-613-branch/Source/WebCore/platform/graphics/IntPoint.h	2022-01-25 01:55:47 UTC (rev 288513)
@@ -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: branches/safari-613-branch/Source/WebKit/ChangeLog (288512 => 288513)


--- branches/safari-613-branch/Source/WebKit/ChangeLog	2022-01-25 01:55:41 UTC (rev 288512)
+++ branches/safari-613-branch/Source/WebKit/ChangeLog	2022-01-25 01:55:47 UTC (rev 288513)
@@ -1,5 +1,69 @@
 2022-01-24  Alan Coon  <[email protected]>
 
+        Cherry-pick r288180. rdar://problem/84440841
+
+    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.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-24  Alan Coon  <[email protected]>
+
         Cherry-pick r288039. rdar://problem/79220540
 
     [iOS] Occasional crash under -[UITargetedPreview initWithView:parameters:target:] when focusing form controls

Modified: branches/safari-613-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (288512 => 288513)


--- branches/safari-613-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-01-25 01:55:41 UTC (rev 288512)
+++ branches/safari-613-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-01-25 01:55:47 UTC (rev 288513)
@@ -1509,7 +1509,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