Title: [171159] trunk/Source/WebKit2
Revision
171159
Author
enr...@apple.com
Date
2014-07-16 17:00:34 -0700 (Wed, 16 Jul 2014)

Log Message

REGRESSION (iOS WebKit2): Cannot scroll while dragging a selection.
https://bugs.webkit.org/show_bug.cgi?id=134992
<rdar://problem/17528020>

Reviewed by Benjamin Poulain.

This patch exposes the scroller and the visible content rect so that
UIKit can implement autoscroll when dragging the selections.
It also changes that way we do hit testing to allow hit test outside
the clipping region and fixes the way we compute the selection rectangle
for the block selection, ensuring that we consider also non text elements
like images.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView scroller]):
(-[WKContentView visibleRect]):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::selectionBoxForRange):
(WebKit::WebPage::rangeForWebSelectionAtPosition):
(WebKit::WebPage::rangeForBlockAtPoint):
(WebKit::WebPage::expandedRangeFromHandle):
(WebKit::WebPage::contractedRangeFromHandle):
(WebKit::WebPage::computeExpandAndShrinkThresholdsForHandle):
(WebKit::WebPage::changeBlockSelection):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (171158 => 171159)


--- trunk/Source/WebKit2/ChangeLog	2014-07-16 23:34:23 UTC (rev 171158)
+++ trunk/Source/WebKit2/ChangeLog	2014-07-17 00:00:34 UTC (rev 171159)
@@ -1,3 +1,30 @@
+2014-07-16  Enrica Casucci  <enr...@apple.com>
+
+        REGRESSION (iOS WebKit2): Cannot scroll while dragging a selection.
+        https://bugs.webkit.org/show_bug.cgi?id=134992
+        <rdar://problem/17528020>
+
+        Reviewed by Benjamin Poulain.
+
+        This patch exposes the scroller and the visible content rect so that
+        UIKit can implement autoscroll when dragging the selections.
+        It also changes that way we do hit testing to allow hit test outside
+        the clipping region and fixes the way we compute the selection rectangle
+        for the block selection, ensuring that we consider also non text elements
+        like images.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView scroller]):
+        (-[WKContentView visibleRect]):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::selectionBoxForRange):
+        (WebKit::WebPage::rangeForWebSelectionAtPosition):
+        (WebKit::WebPage::rangeForBlockAtPoint):
+        (WebKit::WebPage::expandedRangeFromHandle):
+        (WebKit::WebPage::contractedRangeFromHandle):
+        (WebKit::WebPage::computeExpandAndShrinkThresholdsForHandle):
+        (WebKit::WebPage::changeBlockSelection):
+
 2014-07-16  Alexey Proskuryakov  <a...@apple.com>
 
         <rdar://problem/17669097> REGRESSION (r170155): Sandbox violations using a wrong

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (171158 => 171159)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2014-07-16 23:34:23 UTC (rev 171158)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2014-07-17 00:00:34 UTC (rev 171159)
@@ -349,6 +349,16 @@
     return 1 / [[self layer] transform].m11;
 }
 
+- (UIScrollView *)_scroller
+{
+    return [_webView scrollView];
+}
+
+- (CGRect)unobscuredContentRect
+{
+    return _page->unobscuredContentRect();
+}
+
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
 {
     ASSERT([keyPath isEqualToString:@"transform"]);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (171158 => 171159)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2014-07-16 23:34:23 UTC (rev 171158)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2014-07-17 00:00:34 UTC (rev 171159)
@@ -706,13 +706,32 @@
     return constrainedPoint;
 }
 
+static IntRect selectionBoxForRange(WebCore::Range* range)
+{
+    if (!range)
+        return IntRect();
+    
+    IntRect boundingRect;
+    Vector<SelectionRect> selectionRects;
+    range->collectSelectionRects(selectionRects);
+    unsigned size = selectionRects.size();
+    
+    for (unsigned i = 0; i < size; ++i) {
+        const IntRect &coreRect = selectionRects[i].rect();
+        if (!i)
+            boundingRect = coreRect;
+        else
+            boundingRect.unite(coreRect);
+    }
+    return boundingRect;
+}
+
 PassRefPtr<Range> WebPage::rangeForWebSelectionAtPosition(const IntPoint& point, const VisiblePosition& position, SelectionFlags& flags)
 {
     HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint((point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent | HitTestRequest::AllowChildFrameContent);
 
     Node* currentNode = result.innerNode();
     RefPtr<Range> range;
-    IntRect boundingRect;
     FloatRect boundingRectInScrollViewCoordinates;
 
     if (currentNode->isTextNode()) {
@@ -722,18 +741,7 @@
         if (!range)
             return nullptr;
 
-        Vector<SelectionRect> selectionRects;
-        range->collectSelectionRects(selectionRects);
-        unsigned size = selectionRects.size();
-
-        for (unsigned i = 0; i < size; i++) {
-            const IntRect &coreRect = selectionRects[i].rect();
-            if (i == 0)
-                boundingRect = coreRect;
-            else
-                boundingRect.unite(coreRect);
-        }
-        boundingRectInScrollViewCoordinates = boundingRect;
+        boundingRectInScrollViewCoordinates = selectionBoxForRange(range.get());
         boundingRectInScrollViewCoordinates.scale(m_page->pageScaleFactor());
         if (boundingRectInScrollViewCoordinates.width() > m_blockSelectionDesiredSize.width() && boundingRectInScrollViewCoordinates.height() > m_blockSelectionDesiredSize.height())
             return wordRangeFromPosition(position);
@@ -746,8 +754,7 @@
 
     Node* bestChoice = currentNode;
     while (currentNode) {
-        boundingRect = currentNode->renderer()->absoluteBoundingBoxRect(true);
-        boundingRectInScrollViewCoordinates = boundingRect;
+        boundingRectInScrollViewCoordinates = currentNode->renderer()->absoluteBoundingBoxRect(true);
         boundingRectInScrollViewCoordinates.scale(m_page->pageScaleFactor());
         if (boundingRectInScrollViewCoordinates.width() > m_blockSelectionDesiredSize.width() && boundingRectInScrollViewCoordinates.height() > m_blockSelectionDesiredSize.height())
             break;
@@ -784,7 +791,7 @@
 
 PassRefPtr<Range> WebPage::rangeForBlockAtPoint(const IntPoint& point)
 {
-    HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint((point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent);
+    HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint((point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent | HitTestRequest::IgnoreClipping);
 
     Node* currentNode = result.innerNode();
     RefPtr<Range> range;
@@ -1090,8 +1097,7 @@
 
 PassRefPtr<Range> WebPage::expandedRangeFromHandle(Range* currentRange, SelectionHandlePosition handlePosition)
 {
-    // FIXME: We should use boundingRect() instead of boundingBox() in this function when <rdar://problem/16063723> is fixed.
-    IntRect currentBox = currentRange->boundingBox();
+    IntRect currentBox = selectionBoxForRange(currentRange);
     IntPoint edgeCenter = computeEdgeCenter(currentBox, handlePosition);
     static const float maxDistance = 1000;
     const float multiple = powf(maxDistance, 1.0/(maxHitTests - 1));
@@ -1138,7 +1144,7 @@
         else
             newRange = unionDOMRanges(currentRange, rangeAtPosition.get());
 
-        IntRect copyRect = newRange->boundingBox();
+        IntRect copyRect = selectionBoxForRange(newRange.get());
 
         // Is it different and bigger than the current?
         bool isBetterChoice = !(rectsEssentiallyTheSame(copyRect, currentBox, .05));
@@ -1188,8 +1194,7 @@
     // see if we can break that down to a base and extent. Shrinking base and extent is comparatively straightforward.
     // Shrinking down to another element is unlikely to move just one edge, but we can try that as a fallback.
 
-    // FIXME: We should use boundingRect() instead of boundingBox() in this function when <rdar://problem/16063723> is fixed.
-    IntRect currentBox = currentRange->boundingBox();
+    IntRect currentBox = selectionBoxForRange(currentRange);
     IntPoint edgeCenter = computeEdgeCenter(currentBox, handlePosition);
     flags = IsBlockSelection;
 
@@ -1257,7 +1262,7 @@
         else
             newRange = Range::create(newRange->startContainer()->document(), currentRange->startPosition(), newRange->startPosition());
 
-        IntRect copyRect = newRange->boundingBox();
+        IntRect copyRect = selectionBoxForRange(newRange.get());
         if (copyRect.isEmpty()) {
             bestRange = rangeForBlockAtPoint(testPoint);
             break;
@@ -1322,10 +1327,9 @@
     SelectionFlags flags;
     RefPtr<Range> contractedRange = contractedRangeFromHandle(currentRange.get(), handlePosition, flags);
 
-    // FIXME: We should use boundingRect() instead of boundingBox() in this function when <rdar://problem/16063723> is fixed.
-    IntRect currentBounds = currentRange->boundingBox();
-    IntRect expandedBounds = expandedRange->boundingBox();
-    IntRect contractedBounds = contractedRange->boundingBox();
+    IntRect currentBounds = selectionBoxForRange(currentRange.get());
+    IntRect expandedBounds = selectionBoxForRange(expandedRange.get());
+    IntRect contractedBounds = selectionBoxForRange(contractedRange.get());
 
     float current;
     float expanded;
@@ -1397,11 +1401,8 @@
 {
     Frame& frame = m_page->focusController().focusedOrMainFrame();
     RefPtr<Range> currentRange = m_currentBlockSelection ? m_currentBlockSelection.get() : frame.selection().selection().toNormalizedRange();
-    // FIXME: We should use boundingRect() instead of boundingBox() in this function when <rdar://problem/16063723> is fixed.
-    IntRect currentRect = currentRange->boundingBox();
+    RefPtr<Range> newRange = shouldExpand(handlePosition, selectionBoxForRange(currentRange.get()), point) ? expandedRangeFromHandle(currentRange.get(), handlePosition) : contractedRangeFromHandle(currentRange.get(), handlePosition, flags);
 
-    RefPtr<Range> newRange = shouldExpand(handlePosition, currentRect, point) ? expandedRangeFromHandle(currentRange.get(), handlePosition) : contractedRangeFromHandle(currentRange.get(), handlePosition, flags);
-
     if (newRange) {
         m_currentBlockSelection = newRange;
         frame.selection().setSelectedRange(newRange.get(), VP_DEFAULT_AFFINITY, true);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to