Title: [168499] trunk/Source/WebKit2
Revision
168499
Author
bda...@apple.com
Date
2014-05-08 15:29:22 -0700 (Thu, 08 May 2014)

Log Message

REGRESSION (r168053): Phone number detection boxes are wrong when scrolled
https://bugs.webkit.org/show_bug.cgi?id=132706
-and corresponding-
<rdar://problem/16787957>

Reviewed by Tim Horton.

We need to paint the boxes in Document coordinates. Range::boundingRect() was 
giving us a point that took scroll position into account, and that’s not what we 
want. Here we use Range::textQuads() instead so that we can get something in 
Document coordinates, and then we need to convert that up to the main Document’s 
coordinates.
* WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm:
(WebKit::textQuadsToBoundingRectForRange):
(WebKit::TelephoneNumberOverlayController::drawRect):

The telephone click function wants a point in Window coordinates.
(WebKit::TelephoneNumberOverlayController::mouseEvent):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (168498 => 168499)


--- trunk/Source/WebKit2/ChangeLog	2014-05-08 22:03:33 UTC (rev 168498)
+++ trunk/Source/WebKit2/ChangeLog	2014-05-08 22:29:22 UTC (rev 168499)
@@ -1,3 +1,24 @@
+2014-05-08  Beth Dakin  <bda...@apple.com>
+
+        REGRESSION (r168053): Phone number detection boxes are wrong when scrolled
+        https://bugs.webkit.org/show_bug.cgi?id=132706
+        -and corresponding-
+        <rdar://problem/16787957>
+
+        Reviewed by Tim Horton.
+
+        We need to paint the boxes in Document coordinates. Range::boundingRect() was 
+        giving us a point that took scroll position into account, and that’s not what we 
+        want. Here we use Range::textQuads() instead so that we can get something in 
+        Document coordinates, and then we need to convert that up to the main Document’s 
+        coordinates.
+        * WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm:
+        (WebKit::textQuadsToBoundingRectForRange):
+        (WebKit::TelephoneNumberOverlayController::drawRect):
+
+        The telephone click function wants a point in Window coordinates.
+        (WebKit::TelephoneNumberOverlayController::mouseEvent):
+
 2014-05-08  Tim Horton  <timothy_hor...@apple.com>
 
         [iOS WebKit2] Flush RemoteLayerBackingStore contexts on a secondary queue

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm (168498 => 168499)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm	2014-05-08 22:03:33 UTC (rev 168498)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm	2014-05-08 22:29:22 UTC (rev 168499)
@@ -29,6 +29,7 @@
 #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
 
 #import <WebCore/Document.h>
+#import <WebCore/FloatQuad.h>
 #import <WebCore/FrameView.h>
 #import <WebCore/GraphicsContext.h>
 #import <WebCore/MainFrame.h>
@@ -55,6 +56,17 @@
 
 namespace WebKit {
 
+static IntRect textQuadsToBoundingRectForRange(Range& range)
+{
+    Vector<FloatQuad> textQuads;
+    range.textQuads(textQuads);
+    FloatRect boundingRect;
+    size_t size = textQuads.size();
+    for (size_t i = 0; i < size; ++i)
+        boundingRect.unite(textQuads[i].boundingBox());
+    return enclosingIntRect(boundingRect);
+}
+
 void TelephoneNumberOverlayController::drawRect(PageOverlay* overlay, WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& dirtyRect)
 {
     if (m_currentSelectionRanges.isEmpty())
@@ -67,14 +79,17 @@
     for (auto& range : m_currentSelectionRanges) {
         // FIXME: This will choke if the range wraps around the edge of the view.
         // What should we do in that case?
-        IntRect rect = enclosingIntRect(range->boundingRect());
+        IntRect rect = textQuadsToBoundingRectForRange(*range);
 
         // Convert to the main document's coordinate space.
+        // FIXME: It's a little crazy to call contentsToWindow and then windowToContents in order to get the right coordinate space.
+        // We should consider adding conversion functions to ScrollView for contentsToDocument(). Right now, contentsToRootView() is
+        // not equivalent to what we need when you have a topContentInset or a header banner.
         FrameView* viewForRange = range->ownerDocument().view();
         if (!viewForRange)
             return;
         FrameView& mainFrameView = *m_webPage->corePage()->mainFrame().view();
-        rect.setLocation(mainFrameView.convertChildToSelf(viewForRange, rect.location()));
+        rect.setLocation(mainFrameView.windowToContents(viewForRange->contentsToWindow(rect.location())));
 
         CGRect cgRects[] = { (CGRect)rect };
 
@@ -122,7 +137,7 @@
 bool TelephoneNumberOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent& event)
 {
     IntPoint mousePosition = m_webPage->corePage()->mainFrame().view()->rootViewToContents(event.position());
-    
+
     // If this event has nothing to do with the left button, it clears the current mouse down tracking and we're done processing it.
     if (event.button() != WebMouseEvent::LeftButton) {
         clearMouseDownInformation();
@@ -138,7 +153,7 @@
         // If the mouse lifted while still over the highlight button that it went down on, then that is a click.
         Boolean onButton;
         if (DDHighlightPointIsOnHighlight(currentNumber->highlight(), (CGPoint)mousePosition, &onButton) && onButton) {
-            handleTelephoneClick(currentNumber.get(), mousePosition);
+            handleTelephoneClick(currentNumber.get(), m_webPage->corePage()->mainFrame().view()->contentsToWindow(mousePosition));
             
             return true;
         }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to