Title: [170067] trunk/Source/WebKit2
Revision
170067
Author
beid...@apple.com
Date
2014-06-17 12:17:32 -0700 (Tue, 17 Jun 2014)

Log Message

Only show telephone number highlights if only one number is selected
<rdar://problem/16874568> and https://bugs.webkit.org/show_bug.cgi?id=133989

Reviewed by Tim Horton.

Add a flag to TelephoneNumberData to remember if it was hovered over:
* WebProcess/WebPage/TelephoneNumberOverlayController.h:
(WebKit::TelephoneNumberData::hovered):
(WebKit::TelephoneNumberData::setHovered):
(WebKit::TelephoneNumberData::TelephoneNumberData):

* WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm:
(WebKit::TelephoneNumberOverlayController::drawRect): Only draw the highlight if one
  phone number is selected.
(WebKit::TelephoneNumberOverlayController::mouseEvent): Update the hover state of the
  current phone number, and setNeedsDisplay if the hover state changes.
(WebKit::TelephoneNumberOverlayController::clearHighlights):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (170066 => 170067)


--- trunk/Source/WebKit2/ChangeLog	2014-06-17 19:04:40 UTC (rev 170066)
+++ trunk/Source/WebKit2/ChangeLog	2014-06-17 19:17:32 UTC (rev 170067)
@@ -1,3 +1,23 @@
+2014-06-17  Brady Eidson  <beid...@apple.com>
+
+        Only show telephone number highlights if only one number is selected
+        <rdar://problem/16874568> and https://bugs.webkit.org/show_bug.cgi?id=133989
+
+        Reviewed by Tim Horton.
+
+        Add a flag to TelephoneNumberData to remember if it was hovered over:
+        * WebProcess/WebPage/TelephoneNumberOverlayController.h:
+        (WebKit::TelephoneNumberData::hovered):
+        (WebKit::TelephoneNumberData::setHovered):
+        (WebKit::TelephoneNumberData::TelephoneNumberData):
+
+        * WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm:
+        (WebKit::TelephoneNumberOverlayController::drawRect): Only draw the highlight if one
+          phone number is selected.
+        (WebKit::TelephoneNumberOverlayController::mouseEvent): Update the hover state of the
+          current phone number, and setNeedsDisplay if the hover state changes.
+        (WebKit::TelephoneNumberOverlayController::clearHighlights):
+
 2014-06-17  Tim Horton  <timothy_hor...@apple.com>
 
         Remove WKContentView _setFindIndicator:fadeOut:animate:

Modified: trunk/Source/WebKit2/WebProcess/WebPage/TelephoneNumberOverlayController.h (170066 => 170067)


--- trunk/Source/WebKit2/WebProcess/WebPage/TelephoneNumberOverlayController.h	2014-06-17 19:04:40 UTC (rev 170066)
+++ trunk/Source/WebKit2/WebProcess/WebPage/TelephoneNumberOverlayController.h	2014-06-17 19:17:32 UTC (rev 170067)
@@ -53,13 +53,18 @@
     WebCore::Range* range() const { return m_range.get(); }
     DDHighlightRef highlight() const { return m_highlight.get(); }
 
+    bool isHovered() const { return m_hovered; }
+    void setHovered(bool hovered) { m_hovered = hovered; }
+
 private:
     TelephoneNumberData(WebCore::Range* range, DDHighlightRef highlight)
-        : m_range(range)
+        : m_hovered(false)
+        , m_range(range)
         , m_highlight(highlight)
     {
     }
 
+    bool m_hovered;
     RefPtr<WebCore::Range> m_range;
     RetainPtr<DDHighlightRef> m_highlight;
 };
@@ -99,10 +104,11 @@
     Vector<RefPtr<WebCore::Range>> m_currentSelectionRanges;
     
 #if PLATFORM(MAC)
-    Vector<RefPtr<TelephoneNumberData>> m_telephoneNumberDatas;
+    RefPtr<TelephoneNumberData> m_highlightedTelephoneNumberData;
     RefPtr<TelephoneNumberData> m_currentMouseDownNumber;
 #endif
-    
+
+    WebCore::IntPoint m_lastMouseMovePosition;
     WebCore::IntPoint m_mouseDownPosition;
 };
 

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


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm	2014-06-17 19:04:40 UTC (rev 170066)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm	2014-06-17 19:17:32 UTC (rev 170067)
@@ -50,7 +50,6 @@
 SOFT_LINK(DataDetectors, DDHighlightGetLayerWithContext, CGLayerRef, (DDHighlightRef highlight, CGContextRef context), (highlight, context))
 SOFT_LINK(DataDetectors, DDHighlightGetBoundingRect, CGRect, (DDHighlightRef highlight), (highlight))
 SOFT_LINK(DataDetectors, DDHighlightPointIsOnHighlight, Boolean, (DDHighlightRef highlight, CGPoint point, Boolean* onButton), (highlight, point, onButton))
-SOFT_LINK(DataDetectors, DDHighlightSetButtonPressed, void, (DDHighlightRef highlight, Boolean buttonPressed), (highlight, buttonPressed))
 
 using namespace WebCore;
 
@@ -68,66 +67,65 @@
 
 void TelephoneNumberOverlayController::drawRect(PageOverlay* overlay, WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& dirtyRect)
 {
-    if (m_currentSelectionRanges.isEmpty()) {
+    // Only draw an individual telephone number highlight if there is precisely one telephone number selected.
+    if (m_currentSelectionRanges.isEmpty() || m_currentSelectionRanges.size() > 1) {
         clearHighlights();
         return;
     }
 
     CGContextRef cgContext = graphicsContext.platformContext();
-    
-    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 = textQuadsToBoundingRectForRange(*range);
+    auto& range = m_currentSelectionRanges[0];
 
-        // 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.windowToContents(viewForRange->contentsToWindow(rect.location())));
+    // FIXME: This will choke if the range wraps around the edge of the view.
+    // What should we do in that case?
+    IntRect rect = textQuadsToBoundingRectForRange(*range);
 
-        // If the selection rect is completely outside this drawing tile, don't process it further
-        if (!rect.intersects(dirtyRect))
-            continue;
+    // 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.windowToContents(viewForRange->contentsToWindow(rect.location())));
 
-        CGRect cgRects[] = { (CGRect)rect };
+    // If the selection rect is completely outside this drawing tile, don't process it further
+    if (!rect.intersects(dirtyRect))
+        return;
 
-        RetainPtr<DDHighlightRef> highlight = adoptCF(DDHighlightCreateWithRectsInVisibleRect(nullptr, cgRects, 1, viewForRange->boundsRect(), true));
-        RefPtr<TelephoneNumberData> telephoneNumberData = TelephoneNumberData::create(range.get(), highlight.get());
-        m_telephoneNumberDatas.append(telephoneNumberData);
-        
-        // Check and see if the mouse is currently down inside this highlight's button.
-        if (m_mouseDownPosition != IntPoint()) {
-            Boolean onButton;
-            if (DDHighlightPointIsOnHighlight(highlight.get(), (CGPoint)m_mouseDownPosition, &onButton)) {
-                if (onButton) {
-                    m_currentMouseDownNumber = telephoneNumberData;
-                    
-                    // FIXME: We need to do the following, but SOFT_LINK isn't working for this method.
-                    // DDHighlightSetButtonPressed(highlight, true);
-                }
-            }
-        }
-        
-        CGLayerRef highlightLayer = DDHighlightGetLayerWithContext(highlight.get(), cgContext);
-        CGRect highlightBoundingRect = DDHighlightGetBoundingRect(highlight.get());
-        
-        GraphicsContextStateSaver stateSaver(graphicsContext);
+    CGRect cgRects[] = { (CGRect)rect };
 
-        graphicsContext.translate(toFloatSize(highlightBoundingRect.origin));
-        graphicsContext.scale(FloatSize(1, -1));
-        graphicsContext.translate(FloatSize(0, -highlightBoundingRect.size.height));
-        
-        CGRect highlightDrawRect = highlightBoundingRect;
-        highlightDrawRect.origin.x = 0;
-        highlightDrawRect.origin.y = 0;
-        
-        CGContextDrawLayerInRect(cgContext, highlightDrawRect, highlightLayer);
-    }
+    RetainPtr<DDHighlightRef> highlight = adoptCF(DDHighlightCreateWithRectsInVisibleRect(nullptr, cgRects, 1, viewForRange->boundsRect(), true));
+    m_highlightedTelephoneNumberData = TelephoneNumberData::create(range.get(), highlight.get());
+
+    Boolean onButton;
+    bool _onHighlight_ = DDHighlightPointIsOnHighlight(highlight.get(), (CGPoint)m_lastMouseMovePosition, &onButton);
+
+    m_highlightedTelephoneNumberData->setHovered(onHighlight);
+
+    // Don't draw the highlight if the mouse is not hovered over it.
+    if (!onHighlight)
+        return;
+
+    // Check and see if the mouse is currently down inside this highlight's button.
+    if (m_mouseDownPosition != IntPoint() && onButton)
+        m_currentMouseDownNumber = m_highlightedTelephoneNumberData;
+    
+    CGLayerRef highlightLayer = DDHighlightGetLayerWithContext(highlight.get(), cgContext);
+    CGRect highlightBoundingRect = DDHighlightGetBoundingRect(highlight.get());
+    
+    GraphicsContextStateSaver stateSaver(graphicsContext);
+
+    graphicsContext.translate(toFloatSize(highlightBoundingRect.origin));
+    graphicsContext.scale(FloatSize(1, -1));
+    graphicsContext.translate(FloatSize(0, -highlightBoundingRect.size.height));
+    
+    CGRect highlightDrawRect = highlightBoundingRect;
+    highlightDrawRect.origin.x = 0;
+    highlightDrawRect.origin.y = 0;
+    
+    CGContextDrawLayerInRect(cgContext, highlightDrawRect, highlightLayer);
 }
     
 void TelephoneNumberOverlayController::handleTelephoneClick(TelephoneNumberData* number, const IntPoint& point)
@@ -139,8 +137,18 @@
     
 bool TelephoneNumberOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent& event)
 {
-    IntPoint mousePosition = m_webPage->corePage()->mainFrame().view()->rootViewToContents(event.position());
+    m_lastMouseMovePosition = m_webPage->corePage()->mainFrame().view()->rootViewToContents(event.position());
 
+    if (m_highlightedTelephoneNumberData) {
+        Boolean onButton;
+        bool hovered = DDHighlightPointIsOnHighlight(m_highlightedTelephoneNumberData->highlight(), (CGPoint)m_lastMouseMovePosition, &onButton);
+
+        if (hovered != m_highlightedTelephoneNumberData->isHovered())
+            m_telephoneNumberOverlay->setNeedsDisplay();
+
+        m_highlightedTelephoneNumberData->setHovered(hovered);
+    }
+
     // 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();
@@ -155,8 +163,8 @@
         
         // 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(), m_webPage->corePage()->mainFrame().view()->contentsToWindow(mousePosition));
+        if (DDHighlightPointIsOnHighlight(currentNumber->highlight(), (CGPoint)m_lastMouseMovePosition, &onButton) && onButton) {
+            handleTelephoneClick(currentNumber.get(), m_webPage->corePage()->mainFrame().view()->contentsToWindow(m_lastMouseMovePosition));
             
             return true;
         }
@@ -169,7 +177,7 @@
         Boolean onButton;
         
         // Moving with the mouse button down is okay as long as the mouse never leaves the highlight button.
-        if (DDHighlightPointIsOnHighlight(currentNumber->highlight(), (CGPoint)mousePosition, &onButton) && onButton)
+        if (DDHighlightPointIsOnHighlight(currentNumber->highlight(), (CGPoint)m_lastMouseMovePosition, &onButton) && onButton)
             return true;
         
         clearMouseDownInformation();
@@ -181,20 +189,15 @@
     if (event.type() == WebEvent::MouseDown) {
         ASSERT(!m_currentMouseDownNumber);
         
-        for (auto& telephoneNumberData : m_telephoneNumberDatas) {
-            Boolean onButton;
-            if (DDHighlightPointIsOnHighlight(telephoneNumberData->highlight(), (CGPoint)mousePosition, &onButton) && onButton) {
-                m_mouseDownPosition = mousePosition;
-                m_currentMouseDownNumber = telephoneNumberData;
-                
-                // FIXME: We need to do the following, but SOFT_LINK isn't working for this method.
-                // DDHighlightSetButtonPressed(highlight.get(), true);
-                
-                m_telephoneNumberOverlay->setNeedsDisplay();
-                return true;
-            }
+        Boolean onButton;
+        if (DDHighlightPointIsOnHighlight(m_highlightedTelephoneNumberData->highlight(), (CGPoint)m_lastMouseMovePosition, &onButton) && onButton) {
+            m_mouseDownPosition = m_lastMouseMovePosition;
+            m_currentMouseDownNumber = m_highlightedTelephoneNumberData;
+            
+            m_telephoneNumberOverlay->setNeedsDisplay();
+            return true;
         }
-        
+
         return false;
     }
         
@@ -209,7 +212,7 @@
     
 void TelephoneNumberOverlayController::clearHighlights()
 {
-    m_telephoneNumberDatas.clear();
+    m_highlightedTelephoneNumberData = nullptr;
     m_currentMouseDownNumber = nullptr;
 }
     
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to