[Services with UI] Selection services don't work inside <iframes>.
authorenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Aug 2014 18:36:10 +0000 (18:36 +0000)
committerenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Aug 2014 18:36:10 +0000 (18:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135941
<rdar://problem/17957690>

Reviewed by Tim Horton.

Need to map the selection rectangles using the correct FrameView.
When handling the click, we must use the selection from the focused frame.

* WebProcess/WebPage/mac/ServicesOverlayController.mm:
(WebKit::ServicesOverlayController::buildSelectionHighlight):
(WebKit::ServicesOverlayController::handleClick):

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm

index 8f20cc2..7f71a2a 100644 (file)
@@ -1,3 +1,18 @@
+2014-08-14  Enrica Casucci  <enrica@apple.com>
+
+        [Services with UI] Selection services don't work inside <iframes>.
+        https://bugs.webkit.org/show_bug.cgi?id=135941
+        <rdar://problem/17957690>
+
+        Reviewed by Tim Horton.
+
+        Need to map the selection rectangles using the correct FrameView.
+        When handling the click, we must use the selection from the focused frame.
+
+        * WebProcess/WebPage/mac/ServicesOverlayController.mm:
+        (WebKit::ServicesOverlayController::buildSelectionHighlight):
+        (WebKit::ServicesOverlayController::handleClick):
+
 2014-08-13  Mark Rowe  <mrowe@apple.com>
 
         <https://webkit.org/b/135909> Move helper applications out of the root of the framework.
index a7897b9..257beef 100644 (file)
@@ -518,14 +518,24 @@ void ServicesOverlayController::buildSelectionHighlight()
     Vector<CGRect> cgRects;
     cgRects.reserveCapacity(m_currentSelectionRects.size());
 
-    for (auto& rect : m_currentSelectionRects)
-        cgRects.append((CGRect)pixelSnappedIntRect(rect));
+    RefPtr<Range> selectionRange = m_webPage.corePage()->selection().firstRange();
+    if (selectionRange) {
+        Frame* mainFrame = m_webPage.mainFrame();
+        FrameView& mainFrameView = *mainFrame->view();
+        FrameView* viewForRange = selectionRange->ownerDocument().view();
+
+        for (auto& rect : m_currentSelectionRects) {
+            IntRect currentRect = pixelSnappedIntRect(rect);
+            currentRect.setLocation(mainFrameView.windowToContents(viewForRange->contentsToWindow(currentRect.location())));
+            cgRects.append((CGRect)currentRect);
+        }
 
-    if (!cgRects.isEmpty()) {
-        CGRect visibleRect = m_webPage.corePage()->mainFrame().view()->visibleContentRect();
-        RetainPtr<DDHighlightRef> ddHighlight = adoptCF(DDHighlightCreateWithRectsInVisibleRectWithStyleAndDirection(nullptr, cgRects.begin(), cgRects.size(), visibleRect, DDHighlightNoOutlineWithArrow, YES, NSWritingDirectionNatural, NO, YES));
-        
-        m_potentialHighlights.add(Highlight::createForSelection(*this, ddHighlight));
+        if (!cgRects.isEmpty()) {
+            CGRect visibleRect = m_webPage.corePage()->mainFrame().view()->visibleContentRect();
+            RetainPtr<DDHighlightRef> ddHighlight = adoptCF(DDHighlightCreateWithRectsInVisibleRectWithStyleAndDirection(nullptr, cgRects.begin(), cgRects.size(), visibleRect, DDHighlightNoOutlineWithArrow, YES, NSWritingDirectionNatural, NO, YES));
+            
+            m_potentialHighlights.add(Highlight::createForSelection(*this, ddHighlight));
+        }
     }
 
     didRebuildPotentialHighlights();
@@ -745,7 +755,7 @@ void ServicesOverlayController::handleClick(const IntPoint& clickPoint, Highligh
         for (auto& range : telephoneNumberRanges)
             selectedTelephoneNumbers.append(range->text());
 
-        m_webPage.handleSelectionServiceClick(m_webPage.corePage()->mainFrame().selection(), selectedTelephoneNumbers, windowPoint);
+        m_webPage.handleSelectionServiceClick(m_webPage.corePage()->focusController().focusedOrMainFrame().selection(), selectedTelephoneNumbers, windowPoint);
     } else if (highlight.type() == Highlight::Type::TelephoneNumber)
         m_webPage.handleTelephoneNumberClick(highlight.range()->text(), windowPoint);
 }