Combine the Telephone and Selection overlay controllers, updating UI behavior.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Jul 2014 16:22:01 +0000 (16:22 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Jul 2014 16:22:01 +0000 (16:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134461

Reviewed by Tim Horton.

Source/WebCore:
* WebCore.exp.in:

* dom/Range.cpp:
(WebCore::Range::contains): Returns true if the Range completely contains the passed-in Range.
* dom/Range.h:

Source/WebKit2:
* WebKit2.xcodeproj/project.pbxproj:

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::selectedTelephoneNumberRangesChanged):
(WebKit::WebEditorClient::selectionRectsDidChange):

Remove the separate Selection overlay controller:
* WebProcess/WebPage/SelectionOverlayController.cpp: Removed.
* WebProcess/WebPage/ServicesOverlayController.h: Renamed from Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h.
(WebKit::ServicesOverlayController::create):
* WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm: Removed.

Remove the separate TelephoneNumber overlay controller:
* WebProcess/WebPage/TelephoneNumberOverlayController.cpp: Removed.
* WebProcess/WebPage/TelephoneNumberOverlayController.h: Removed.
* WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm: Removed.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::servicesOverlayController):
(WebKit::WebPage::telephoneNumberOverlayController): Deleted.
(WebKit::WebPage::selectionOverlayController): Deleted.
(WebKit::WebPage::didChangeScrollOffsetForFrame): Deleted.
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::serviceControlsEnabled): Deleted.

ServicesOverlayController is a combination of the old TelephoneNumber and Selection overlay controllers.
A lot of code duplication is resolved, and things are generally easier to follow.
It enforces displaying a telephone number highlight if precisely one telephone number is selected, or
the selection highlight if the selection contains more than a single phone number
* WebProcess/WebPage/mac/ServicesOverlayController.mm: Added.
(WebKit::textQuadsToBoundingRectForRange):
(WebKit::ServicesOverlayController::ServicesOverlayController):
(WebKit::ServicesOverlayController::destroyOverlay):
(WebKit::ServicesOverlayController::pageOverlayDestroyed):
(WebKit::ServicesOverlayController::willMoveToWebPage):
(WebKit::ServicesOverlayController::didMoveToWebPage):
(WebKit::ServicesOverlayController::createOverlayIfNeeded):
(WebKit::ServicesOverlayController::selectionRectsDidChange):
(WebKit::ServicesOverlayController::selectedTelephoneNumberRangesChanged):
(WebKit::ServicesOverlayController::clearHighlightState):
(WebKit::ServicesOverlayController::drawRect):
(WebKit::ServicesOverlayController::drawSelectionHighlight):
(WebKit::ServicesOverlayController::drawTelephoneNumberHighlight):
(WebKit::ServicesOverlayController::drawCurrentHighlight):
(WebKit::ServicesOverlayController::mouseEvent):
(WebKit::ServicesOverlayController::handleClick):

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/dom/Range.cpp
Source/WebCore/dom/Range.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp [deleted file]
Source/WebKit2/WebProcess/WebPage/ServicesOverlayController.h [moved from Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h with 71% similarity]
Source/WebKit2/WebProcess/WebPage/TelephoneNumberOverlayController.cpp [deleted file]
Source/WebKit2/WebProcess/WebPage/TelephoneNumberOverlayController.h [deleted file]
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm [deleted file]
Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm [new file with mode: 0644]
Source/WebKit2/WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm [deleted file]

index 7e930cca92ccdc7c1a7188bf253241468025c80b..a2aa8b62b21757a0402b73d29638f55af2ca2779 100644 (file)
@@ -1,3 +1,16 @@
+2014-07-01  Brady Eidson  <beidson@apple.com>
+
+        Combine the Telephone and Selection overlay controllers, updating UI behavior.
+        https://bugs.webkit.org/show_bug.cgi?id=134461
+
+        Reviewed by Tim Horton.
+
+        * WebCore.exp.in:
+
+        * dom/Range.cpp:
+        (WebCore::Range::contains): Returns true if the Range completely contains the passed-in Range.
+        * dom/Range.h:
+
 2014-07-01  Antti Koivisto  <antti@apple.com>
 
         REGRESSION(160908): vube.com video won't play after going into and out of fullscreen
index 3cc6cf300b88c9dd2d61cb115d614a2f0e41da52..ea15caff6fad8c02cc827b94f23d5f8b025ac61d 100644 (file)
@@ -1907,6 +1907,7 @@ __ZNK7WebCore5Range19boundaryPointsValidEv
 __ZNK7WebCore5Range21compareBoundaryPointsENS0_10CompareHowEPKS0_Ri
 __ZNK7WebCore5Range23commonAncestorContainerERi
 __ZNK7WebCore5Range4textEv
+__ZNK7WebCore5Range8containsERKS0_
 __ZNK7WebCore5Range9collapsedERi
 __ZNK7WebCore5Range9endOffsetERi
 __ZNK7WebCore5Range9firstNodeEv
index 64a72a8bae4ef7722406bb97905aedebd978ee27..9b2d4e9198105a0628ccab00a7389a6f91d38a76 100644 (file)
@@ -1967,6 +1967,19 @@ void Range::formatForDebugger(char* buffer, unsigned length) const
 }
 #endif
 
+bool Range::contains(const Range& other) const
+{
+    if (commonAncestorContainer(ASSERT_NO_EXCEPTION)->ownerDocument() != other.commonAncestorContainer(ASSERT_NO_EXCEPTION)->ownerDocument())
+        return false;
+
+    short startToStart = compareBoundaryPoints(Range::START_TO_START, &other, ASSERT_NO_EXCEPTION);
+    if (startToStart > 0)
+        return false;
+
+    short endToEnd = compareBoundaryPoints(Range::END_TO_END, &other, ASSERT_NO_EXCEPTION);
+    return endToEnd >= 0;
+}
+
 bool areRangesEqual(const Range* a, const Range* b)
 {
     if (a == b)
index c40ede3437d7646649a9f67f0b55dc23ae3ed339..ff37e714ba7afdb9df11e6b7f5e959ab9a64590a 100644 (file)
@@ -161,6 +161,8 @@ public:
     void formatForDebugger(char* buffer, unsigned length) const;
 #endif
 
+    bool contains(const Range&) const;
+
 private:
     explicit Range(Document&);
     Range(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
index 8ee46507497db67f0c1b7f4ce6ce9cc525f637ff..8f407535814107ec4c689bfd2ba260806219fbf8 100644 (file)
@@ -1,3 +1,57 @@
+2014-07-01  Brady Eidson  <beidson@apple.com>
+
+        Combine the Telephone and Selection overlay controllers, updating UI behavior.
+        https://bugs.webkit.org/show_bug.cgi?id=134461
+
+        Reviewed by Tim Horton.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::selectedTelephoneNumberRangesChanged):
+        (WebKit::WebEditorClient::selectionRectsDidChange):
+
+        Remove the separate Selection overlay controller:
+        * WebProcess/WebPage/SelectionOverlayController.cpp: Removed.
+        * WebProcess/WebPage/ServicesOverlayController.h: Renamed from Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h.
+        (WebKit::ServicesOverlayController::create):
+        * WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm: Removed.
+
+        Remove the separate TelephoneNumber overlay controller:
+        * WebProcess/WebPage/TelephoneNumberOverlayController.cpp: Removed.
+        * WebProcess/WebPage/TelephoneNumberOverlayController.h: Removed.
+        * WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm: Removed.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::servicesOverlayController):
+        (WebKit::WebPage::telephoneNumberOverlayController): Deleted.
+        (WebKit::WebPage::selectionOverlayController): Deleted.
+        (WebKit::WebPage::didChangeScrollOffsetForFrame): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::serviceControlsEnabled): Deleted.
+
+        ServicesOverlayController is a combination of the old TelephoneNumber and Selection overlay controllers.
+        A lot of code duplication is resolved, and things are generally easier to follow.
+        It enforces displaying a telephone number highlight if precisely one telephone number is selected, or
+        the selection highlight if the selection contains more than a single phone number
+        * WebProcess/WebPage/mac/ServicesOverlayController.mm: Added.
+        (WebKit::textQuadsToBoundingRectForRange):
+        (WebKit::ServicesOverlayController::ServicesOverlayController):
+        (WebKit::ServicesOverlayController::destroyOverlay):
+        (WebKit::ServicesOverlayController::pageOverlayDestroyed):
+        (WebKit::ServicesOverlayController::willMoveToWebPage):
+        (WebKit::ServicesOverlayController::didMoveToWebPage):
+        (WebKit::ServicesOverlayController::createOverlayIfNeeded):
+        (WebKit::ServicesOverlayController::selectionRectsDidChange):
+        (WebKit::ServicesOverlayController::selectedTelephoneNumberRangesChanged):
+        (WebKit::ServicesOverlayController::clearHighlightState):
+        (WebKit::ServicesOverlayController::drawRect):
+        (WebKit::ServicesOverlayController::drawSelectionHighlight):
+        (WebKit::ServicesOverlayController::drawTelephoneNumberHighlight):
+        (WebKit::ServicesOverlayController::drawCurrentHighlight):
+        (WebKit::ServicesOverlayController::mouseEvent):
+        (WebKit::ServicesOverlayController::handleClick):
+
 2014-07-01  Zan Dobersek  <zdobersek@igalia.com>
 
         [WK2] IPC messages' arguments() method returns const std::tuple<> copies
index 6f281725d3dd17144d121cd32a99588cec01059e..7be4ef0047eefabea874933203e23bdc1dd027d6 100644 (file)
                518E8F0B16B2093700E91429 /* DownloadManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 518E8F0216B2093700E91429 /* DownloadManager.cpp */; };
                518E8F0C16B2093700E91429 /* DownloadManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 518E8F0316B2093700E91429 /* DownloadManager.h */; };
                518E8F0D16B2093700E91429 /* DownloadMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 518E8F0516B2093700E91429 /* DownloadMac.mm */; };
-               519EF58E18EF770D0003B7F4 /* TelephoneNumberOverlayControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 519EF58D18EF770D0003B7F4 /* TelephoneNumberOverlayControllerMac.mm */; };
-               519EF59218EF80CE0003B7F4 /* TelephoneNumberOverlayController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 519EF58F18EF77210003B7F4 /* TelephoneNumberOverlayController.cpp */; };
+               5192D5761961FD0300CD19AA /* ServicesOverlayController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5192D5751961FD0300CD19AA /* ServicesOverlayController.mm */; };
                51A4D5A916CAC4FF000E615E /* StatisticsRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A4D5A816CAC4FF000E615E /* StatisticsRequest.cpp */; };
                51A555F5128C6C47009ABCEC /* WKContextMenuItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A555F3128C6C47009ABCEC /* WKContextMenuItem.cpp */; };
                51A555F6128C6C47009ABCEC /* WKContextMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A555F4128C6C47009ABCEC /* WKContextMenuItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51E35205180F5D4F00E53BE9 /* DatabaseProcessMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E35203180F5D4B00E53BE9 /* DatabaseProcessMain.mm */; };
                51E35209180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E35208180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm */; };
                51E3B67F16F266B3009968DC /* NetworkResourceLoaderMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E3B67E16F266B3009968DC /* NetworkResourceLoaderMac.mm */; };
-               51EF124E19098522008A6532 /* SelectionOverlayController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51EF124C19098522008A6532 /* SelectionOverlayController.cpp */; };
-               51EF124F19098523008A6532 /* SelectionOverlayController.h in Headers */ = {isa = PBXBuildFile; fileRef = 51EF124D19098522008A6532 /* SelectionOverlayController.h */; };
-               51EF125119098531008A6532 /* SelectionOverlayControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51EF125019098531008A6532 /* SelectionOverlayControllerMac.mm */; };
                51EFC1CF1524E62500C9A938 /* WKBundleDOMWindowExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FA2D541521118600C1BA0B /* WKBundleDOMWindowExtension.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51F060E01654317F00F3281B /* WebResourceLoaderMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */; };
                51F060E11654318500F3281B /* WebResourceLoaderMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */; };
                518E8F0216B2093700E91429 /* DownloadManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DownloadManager.cpp; path = Downloads/DownloadManager.cpp; sourceTree = "<group>"; };
                518E8F0316B2093700E91429 /* DownloadManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DownloadManager.h; path = Downloads/DownloadManager.h; sourceTree = "<group>"; };
                518E8F0516B2093700E91429 /* DownloadMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DownloadMac.mm; sourceTree = "<group>"; };
-               519EF58D18EF770D0003B7F4 /* TelephoneNumberOverlayControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TelephoneNumberOverlayControllerMac.mm; sourceTree = "<group>"; };
-               519EF58F18EF77210003B7F4 /* TelephoneNumberOverlayController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TelephoneNumberOverlayController.cpp; sourceTree = "<group>"; };
-               519EF59018EF77210003B7F4 /* TelephoneNumberOverlayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TelephoneNumberOverlayController.h; sourceTree = "<group>"; };
+               5192D5711961FA2F00CD19AA /* ServicesOverlayController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ServicesOverlayController.h; sourceTree = "<group>"; };
+               5192D5751961FD0300CD19AA /* ServicesOverlayController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ServicesOverlayController.mm; sourceTree = "<group>"; };
                51A4D5A816CAC4FF000E615E /* StatisticsRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StatisticsRequest.cpp; sourceTree = "<group>"; };
                51A555F3128C6C47009ABCEC /* WKContextMenuItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKContextMenuItem.cpp; sourceTree = "<group>"; };
                51A555F4128C6C47009ABCEC /* WKContextMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContextMenuItem.h; sourceTree = "<group>"; };
                51E35207180F5D6100E53BE9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
                51E35208180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseServiceEntryPoint.mm; sourceTree = "<group>"; };
                51E3B67E16F266B3009968DC /* NetworkResourceLoaderMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkResourceLoaderMac.mm; sourceTree = "<group>"; };
-               51EF124C19098522008A6532 /* SelectionOverlayController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectionOverlayController.cpp; sourceTree = "<group>"; };
-               51EF124D19098522008A6532 /* SelectionOverlayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectionOverlayController.h; sourceTree = "<group>"; };
-               51EF125019098531008A6532 /* SelectionOverlayControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SelectionOverlayControllerMac.mm; sourceTree = "<group>"; };
                51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceLoaderMessageReceiver.cpp; sourceTree = "<group>"; };
                51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebResourceLoaderMessages.h; sourceTree = "<group>"; };
                51F7DC4A180CC93600212CA3 /* com.apple.WebKit.Databases.xpc */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = com.apple.WebKit.Databases.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
                                1A90C23512650717003E44D4 /* PageOverlay.h */,
                                2D140EAD18F37BE0005E75A0 /* PageOverlayController.cpp */,
                                2D140EAE18F37BE0005E75A0 /* PageOverlayController.h */,
-                               51EF124C19098522008A6532 /* SelectionOverlayController.cpp */,
-                               51EF124D19098522008A6532 /* SelectionOverlayController.h */,
-                               519EF58F18EF77210003B7F4 /* TelephoneNumberOverlayController.cpp */,
-                               519EF59018EF77210003B7F4 /* TelephoneNumberOverlayController.h */,
+                               5192D5711961FA2F00CD19AA /* ServicesOverlayController.h */,
                                2D819B99186275B3001F03D1 /* ViewGestureGeometryCollector.cpp */,
                                2D819B9A186275B3001F03D1 /* ViewGestureGeometryCollector.h */,
                                2D819B9B186275B3001F03D1 /* ViewGestureGeometryCollector.messages.in */,
                                1AB16AE7164B3A8800290D62 /* RemoteLayerTreeContext.mm */,
                                1AB16ADC1648598400290D62 /* RemoteLayerTreeDrawingArea.h */,
                                1AB16ADB1648598400290D62 /* RemoteLayerTreeDrawingArea.mm */,
-                               51EF125019098531008A6532 /* SelectionOverlayControllerMac.mm */,
-                               519EF58D18EF770D0003B7F4 /* TelephoneNumberOverlayControllerMac.mm */,
+                               5192D5751961FD0300CD19AA /* ServicesOverlayController.mm */,
                                1AAF263714687C39004A1E8A /* TiledCoreAnimationDrawingArea.h */,
                                1AAF263614687C39004A1E8A /* TiledCoreAnimationDrawingArea.mm */,
                                1C8E2DAD1278C5B200BC7BD0 /* WebInspectorMac.mm */,
                                29501724162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h in Headers */,
                                1F7506B61859165700EC0FF7 /* WKWebProcessPlugInNodeHandleInternal.h in Headers */,
                                1F7506B51859165400EC0FF7 /* WKWebProcessPlugInScriptWorldInternal.h in Headers */,
-                               51EF124F19098523008A6532 /* SelectionOverlayController.h in Headers */,
                                373CEAD6185417AE008C363D /* WKNSData.h in Headers */,
                                1AB8A1F018400B0000E9AE69 /* WKPageFormClient.h in Headers */,
                                BC989D85161A9890000D46D3 /* WKWebProcessPlugInInternal.h in Headers */,
                                512F589612A8838800629530 /* AuthenticationChallengeProxy.cpp in Sources */,
                                1AE00D4C182D6EB000087DD7 /* WKBrowsingContextHandle.mm in Sources */,
                                512F589812A8838800629530 /* AuthenticationDecisionListener.cpp in Sources */,
+                               5192D5761961FD0300CD19AA /* ServicesOverlayController.mm in Sources */,
                                518E8EF816B2091C00E91429 /* AuthenticationManager.cpp in Sources */,
                                518E8EFB16B2091C00E91429 /* AuthenticationManager.mac.mm in Sources */,
                                512F58A212A883AD00629530 /* AuthenticationManagerMessageReceiver.cpp in Sources */,
                                BCAC112012C92C1F00B08EEE /* WebDatabaseManagerProxyClient.cpp in Sources */,
                                F62A76B812B1B25F0005F1B6 /* WebDatabaseManagerProxyMessageReceiver.cpp in Sources */,
                                517DD5C5180DC3E10081660B /* DatabaseProcessProxyMac.mm in Sources */,
-                               51EF125119098531008A6532 /* SelectionOverlayControllerMac.mm in Sources */,
                                BC111A5D112F4FBB00337BAB /* WebDragClient.cpp in Sources */,
                                C574A37712E6099D002DFE98 /* WebDragClientMac.mm in Sources */,
                                BCA0EFA012332642007D3CFB /* WebEditCommandProxy.cpp in Sources */,
                                33D3A3CA1339617900709BE4 /* WebMediaCacheManagerProxyMessageReceiver.cpp in Sources */,
                                E164A2F1191AF14E0010737D /* BlobDataFileReferenceWithSandboxExtension.cpp in Sources */,
                                0FCB4E4D18BBE044000FCFC9 /* WKContentView.mm in Sources */,
-                               519EF59218EF80CE0003B7F4 /* TelephoneNumberOverlayController.cpp in Sources */,
                                909854EC12BC4E17000AD080 /* WebMemorySampler.cpp in Sources */,
                                909854EE12BC4E18000AD080 /* WebMemorySampler.mac.mm in Sources */,
                                C0337DB0127A28D0008FF4F4 /* WebMouseEvent.cpp in Sources */,
-                               519EF58E18EF770D0003B7F4 /* TelephoneNumberOverlayControllerMac.mm in Sources */,
                                BCF69FA31176D01400471A52 /* APINavigationData.cpp in Sources */,
                                31A2EC48148997C200810D71 /* WebNotification.cpp in Sources */,
                                A115DC71191D82D700DA8072 /* _WKWebViewPrintFormatter.mm in Sources */,
                                E115C714190F89E400ECC516 /* DatabaseProcessIOS.mm in Sources */,
                                33F9D5B91312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp in Sources */,
                                33367655130C9ECA006C9DE2 /* WebResourceCacheManagerMessageReceiver.cpp in Sources */,
-                               51EF124E19098522008A6532 /* SelectionOverlayController.cpp in Sources */,
                                33367635130C99B2006C9DE2 /* WebResourceCacheManagerProxy.cpp in Sources */,
                                33367657130C9ECA006C9DE2 /* WebResourceCacheManagerProxyMessageReceiver.cpp in Sources */,
                                1A8E7D3C18C15149005A702A /* VisitedLinkTableControllerMessageReceiver.cpp in Sources */,
index 9df5925178f29184d8e286e2661737c149eba381..d9c000a6e763c0ec44480de0c0fd837c0c799b1c 100644 (file)
@@ -27,8 +27,7 @@
 #include "WebEditorClient.h"
 
 #include "EditorState.h"
-#include "SelectionOverlayController.h"
-#include "TelephoneNumberOverlayController.h"
+#include "ServicesOverlayController.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebFrame.h"
 #include "WebPage.h"
@@ -525,19 +524,16 @@ bool WebEditorClient::supportsGlobalSelection()
 #endif
 }
 
-#if ENABLE(TELEPHONE_NUMBER_DETECTION)
+#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
 void WebEditorClient::selectedTelephoneNumberRangesChanged(const Vector<RefPtr<Range>>& ranges)
 {
-    m_page->telephoneNumberOverlayController().selectedTelephoneNumberRangesChanged(ranges);
+    m_page->servicesOverlayController().selectedTelephoneNumberRangesChanged(ranges);
 }
-#endif
-
-#if ENABLE(SERVICE_CONTROLS)
 void WebEditorClient::selectionRectsDidChange(const Vector<LayoutRect>& rects)
 {
     if (m_page->serviceControlsEnabled())
-        m_page->selectionOverlayController().selectionRectsDidChange(rects);
+        m_page->servicesOverlayController().selectionRectsDidChange(rects);
 }
-#endif // ENABLE(SERVICE_CONTROLS)
+#endif // ENABLE(SERVICE_CONTROLS) && ENABLE(TELEPHONE_NUMBER_DETECTION)
 
 } // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp b/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp
deleted file mode 100644 (file)
index 120b926..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "SelectionOverlayController.h"
-
-#if ENABLE(SERVICE_CONTROLS)
-
-#include "WebPage.h"
-#include "WebProcess.h"
-#include <WebCore/NotImplemented.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-    
-SelectionOverlayController::SelectionOverlayController(WebPage* webPage)
-    : m_webPage(webPage)
-    , m_selectionOverlay(nullptr)
-    , m_mouseIsDownOnButton(false)
-    , m_mouseIsOverHighlight(false)
-    , m_visible(false)
-    , m_hoverTimer(RunLoop::main(), this, &SelectionOverlayController::hoverTimerFired)
-    , m_currentHighlightIsDirty(false)
-{
-}
-
-void SelectionOverlayController::createOverlayIfNeeded()
-{
-    if (m_selectionOverlay) {
-        m_selectionOverlay->setNeedsDisplay();
-        return;
-    }
-    
-    RefPtr<PageOverlay> overlay = PageOverlay::create(this, PageOverlay::OverlayType::Document);
-    m_selectionOverlay = overlay.get();
-    m_webPage->installPageOverlay(overlay.release(), PageOverlay::FadeMode::Fade);
-    m_selectionOverlay->setNeedsDisplay();
-}
-
-void SelectionOverlayController::destroyOverlay()
-{
-    if (!m_selectionOverlay)
-        return;
-
-    m_mouseIsOverHighlight = false;
-    mouseHoverStateChanged();
-
-    m_webPage->uninstallPageOverlay(m_selectionOverlay, PageOverlay::FadeMode::DoNotFade);
-}
-
-void SelectionOverlayController::pageOverlayDestroyed(PageOverlay*)
-{
-    // Before the overlay is destroyed, it should have moved out of the WebPage,
-    // at which point we already cleared our back pointer.
-    ASSERT(!m_selectionOverlay);
-}
-
-void SelectionOverlayController::willMoveToWebPage(PageOverlay*, WebPage* webPage)
-{
-    if (webPage)
-        return;
-
-    ASSERT(m_selectionOverlay);
-    m_selectionOverlay = nullptr;
-}
-
-void SelectionOverlayController::didMoveToWebPage(PageOverlay*, WebPage*)
-{
-}
-
-void SelectionOverlayController::selectionRectsDidChange(const Vector<LayoutRect>& rects)
-{
-#if __MAC_OS_X_VERSION_MIN_REQUIRED > 1090
-    m_currentHighlightIsDirty = true;
-    m_currentSelectionRects = rects;
-
-    if (WebProcess::shared().hasSelectionServices() && !m_currentSelectionRects.isEmpty())
-        createOverlayIfNeeded();
-    else
-        destroyOverlay();
-
-#else
-    UNUSED_PARAM(rects);
-#endif
-}
-
-void SelectionOverlayController::hoverTimerFired()
-{
-    if (!m_mouseIsOverHighlight)
-        return;
-
-    m_visible = true;
-
-    ASSERT(m_selectionOverlay);
-    m_selectionOverlay->setNeedsDisplay();
-}
-
-#if !PLATFORM(MAC)
-void SelectionOverlayController::drawRect(PageOverlay*, WebCore::GraphicsContext&, const WebCore::IntRect&)
-{
-    notImplemented();
-}
-
-bool SelectionOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent&)
-{
-    notImplemented();
-    return false;
-}
-#endif
-
-} // namespace WebKit
-
-#endif // ENABLE(SERVICE_CONTROLS)
similarity index 71%
rename from Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h
rename to Source/WebKit2/WebProcess/WebPage/ServicesOverlayController.h
index 589ac60bd00921f66f2058874dacac6c1a2b1a22..7b2dbf32d4673f9dfe779887f5f6dc026850c9c1 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef SelectionOverlayController_h
+#ifndef ServicesOverlayController_h
 
-#if ENABLE(SERVICE_CONTROLS)
+#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
 
 #include "PageOverlay.h"
-#include "WebPage.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RunLoop.h>
 
 typedef void* DDHighlightRef;
 
 namespace WebCore {
 class LayoutRect;
+class Range;
 }
 
 namespace WebKit {
-    
+
 class WebPage;
 
-class SelectionOverlayController : public RefCounted<SelectionOverlayController>, private PageOverlay::Client {
-public:
+typedef void* DDHighlightRef;
 
-    static PassRefPtr<SelectionOverlayController> create(WebPage* webPage)
-    {
-        return adoptRef(new SelectionOverlayController(webPage));
-    }
+class ServicesOverlayController : private PageOverlay::Client {
+public:
+    ServicesOverlayController(WebPage&);
+    ~ServicesOverlayController();
 
+    void selectedTelephoneNumberRangesChanged(const Vector<RefPtr<WebCore::Range>>&);
     void selectionRectsDidChange(const Vector<WebCore::LayoutRect>&);
-    void handleClick(const WebCore::IntPoint&);
-    
-private:
-    SelectionOverlayController(WebPage*);
 
+private:
     void createOverlayIfNeeded();
-    void destroyOverlay();
+    void handleClick(const WebCore::IntPoint&);
+    void clearHighlightState();
     
-    void handleSelectionOverlayClick(const WebCore::IntPoint&);
-
     virtual void pageOverlayDestroyed(PageOverlay*) override;
     virtual void willMoveToWebPage(PageOverlay*, WebPage*) override;
     virtual void didMoveToWebPage(PageOverlay*, WebPage*) override;
     virtual void drawRect(PageOverlay*, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) override;
     virtual bool mouseEvent(PageOverlay*, const WebMouseEvent&) override;
 
-    void mouseHoverStateChanged();
-    void hoverTimerFired();
+    void drawTelephoneNumberHighlight(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
+    void drawSelectionHighlight(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
+    void drawCurrentHighlight(WebCore::GraphicsContext&);
 
-    RefPtr<WebPage> m_webPage;
-    PageOverlay* m_selectionOverlay;
+    WebPage* m_webPage;
+    PageOverlay* m_servicesOverlay;
+    
     Vector<WebCore::LayoutRect> m_currentSelectionRects;
+    Vector<RefPtr<WebCore::Range>> m_currentTelephoneNumberRanges;
 
     WebCore::IntPoint m_mousePosition;
     bool m_mouseIsDownOnButton;
     bool m_mouseIsOverHighlight;
-    bool m_visible;
-
-    RunLoop::Timer<SelectionOverlayController> m_hoverTimer;
+    bool m_drawingTelephoneNumberHighlight;
 
     RetainPtr<DDHighlightRef> m_currentHighlight;
     bool m_currentHighlightIsDirty;
@@ -87,5 +82,5 @@ private:
 
 } // namespace WebKit
 
-#endif // ENABLE(SERVICE_CONTROLS)
-#endif // SelectionOverlayController_h
+#endif // ENABLE(SERVICE_CONTROLS) && ENABLE(TELEPHONE_NUMBER_DETECTION)
+#endif // ServicesOverlayController_h
diff --git a/Source/WebKit2/WebProcess/WebPage/TelephoneNumberOverlayController.cpp b/Source/WebKit2/WebProcess/WebPage/TelephoneNumberOverlayController.cpp
deleted file mode 100644 (file)
index 7f94bf8..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "TelephoneNumberOverlayController.h"
-
-#if ENABLE(TELEPHONE_NUMBER_DETECTION)
-
-#include "WebPage.h"
-#include <WebCore/NotImplemented.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-    
-TelephoneNumberOverlayController::TelephoneNumberOverlayController(WebPage* webPage)
-    : m_webPage(webPage)
-    , m_telephoneNumberOverlay(nullptr)
-{
-    ASSERT(m_webPage);
-}
-
-void TelephoneNumberOverlayController::createOverlayIfNeeded()
-{
-    if (m_telephoneNumberOverlay) {
-        m_telephoneNumberOverlay->setNeedsDisplay();
-        return;
-    }
-    
-    RefPtr<PageOverlay> overlay = PageOverlay::create(this, PageOverlay::OverlayType::Document);
-    m_telephoneNumberOverlay = overlay.get();
-    m_webPage->installPageOverlay(overlay.release(), PageOverlay::FadeMode::Fade);
-    m_telephoneNumberOverlay->setNeedsDisplay();
-}
-
-void TelephoneNumberOverlayController::destroyOverlay()
-{
-    if (!m_telephoneNumberOverlay)
-        return;
-
-    m_webPage->uninstallPageOverlay(m_telephoneNumberOverlay, PageOverlay::FadeMode::DoNotFade);
-}
-
-void TelephoneNumberOverlayController::pageOverlayDestroyed(PageOverlay*)
-{
-    // Before the overlay is destroyed, it should have moved out of the WebPage,
-    // at which point we already cleared our back pointer.
-    ASSERT(!m_telephoneNumberOverlay);
-}
-
-void TelephoneNumberOverlayController::willMoveToWebPage(PageOverlay*, WebPage* webPage)
-{
-    if (webPage)
-        return;
-
-    ASSERT(m_telephoneNumberOverlay);
-    m_telephoneNumberOverlay = 0;
-}
-
-void TelephoneNumberOverlayController::didMoveToWebPage(PageOverlay*, WebPage*)
-{
-}
-
-void TelephoneNumberOverlayController::selectedTelephoneNumberRangesChanged(const Vector<RefPtr<Range>>& ranges)
-{
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 1090
-    m_currentSelectionRanges = ranges;
-    
-    clearHighlights();
-    
-    if (m_currentSelectionRanges.isEmpty())
-        destroyOverlay();
-    else
-        createOverlayIfNeeded();
-#else
-    UNUSED_PARAM(ranges);
-#endif
-}
-
-#if !PLATFORM(MAC)
-void TelephoneNumberOverlayController::drawRect(PageOverlay*, WebCore::GraphicsContext&, const WebCore::IntRect&)
-{
-    notImplemented();
-}
-
-bool TelephoneNumberOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent&)
-{
-    notImplemented();
-    return false;
-}
-#endif
-
-} // namespace WebKit
-
-#endif // ENABLE(TELEPHONE_NUMBER_DETECTION)
diff --git a/Source/WebKit2/WebProcess/WebPage/TelephoneNumberOverlayController.h b/Source/WebKit2/WebProcess/WebPage/TelephoneNumberOverlayController.h
deleted file mode 100644 (file)
index c9587d2..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef TelephoneNumberOverlayController_h
-
-#if ENABLE(TELEPHONE_NUMBER_DETECTION)
-
-#include "PageOverlay.h"
-#include "WebPage.h"
-#include <WebCore/IntRect.h>
-#include <wtf/RefCounted.h>
-
-namespace WebCore {
-class Range;
-}
-
-namespace WebKit {
-    
-class WebPage;
-    
-#if PLATFORM(MAC)
-typedef void* DDHighlightRef;
-
-class TelephoneNumberData : public RefCounted<TelephoneNumberData> {
-public:
-    static PassRefPtr<TelephoneNumberData> create(WebCore::Range* range, DDHighlightRef highlight)
-    {
-        return adoptRef(new TelephoneNumberData(range, highlight));
-    }
-
-    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_hovered(false)
-        , m_range(range)
-        , m_highlight(highlight)
-    {
-    }
-
-    bool m_hovered;
-    RefPtr<WebCore::Range> m_range;
-    RetainPtr<DDHighlightRef> m_highlight;
-};
-#endif
-
-class TelephoneNumberOverlayController : public RefCounted<TelephoneNumberOverlayController>, private PageOverlay::Client {
-public:
-
-    static PassRefPtr<TelephoneNumberOverlayController> create(WebPage* webPage)
-    {
-        return adoptRef(new TelephoneNumberOverlayController(webPage));
-    }
-
-    void selectedTelephoneNumberRangesChanged(const Vector<RefPtr<WebCore::Range>>&);
-    
-private:
-    TelephoneNumberOverlayController(WebPage*);
-
-    void createOverlayIfNeeded();
-    void destroyOverlay();
-    
-    void clearHighlights();
-    void clearMouseDownInformation();
-
-#if PLATFORM(MAC)
-    void handleTelephoneClick(TelephoneNumberData*, const WebCore::IntPoint&);
-#endif
-    
-    virtual void pageOverlayDestroyed(PageOverlay*) override;
-    virtual void willMoveToWebPage(PageOverlay*, WebPage*) override;
-    virtual void didMoveToWebPage(PageOverlay*, WebPage*) override;
-    virtual void drawRect(PageOverlay*, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) override;
-    virtual bool mouseEvent(PageOverlay*, const WebMouseEvent&) override;
-
-    RefPtr<WebPage> m_webPage;
-    PageOverlay* m_telephoneNumberOverlay;
-    Vector<RefPtr<WebCore::Range>> m_currentSelectionRanges;
-    
-#if PLATFORM(MAC)
-    RefPtr<TelephoneNumberData> m_highlightedTelephoneNumberData;
-    RefPtr<TelephoneNumberData> m_currentMouseDownNumber;
-#endif
-
-    WebCore::IntPoint m_lastMouseMovePosition;
-    WebCore::IntPoint m_mouseDownPosition;
-};
-
-} // namespace WebKit
-
-#endif // ENABLE(TELEPHONE_NUMBER_DETECTION)
-#endif // TelephoneNumberOverlayController_h
index 969ed9a51de06c042767e7982158775c2f8a12dc..56dc080026b9a3a7cd059fa8b7052d8d7883258b 100644 (file)
 #include "PluginProxy.h"
 #include "PluginView.h"
 #include "PrintInfo.h"
-#include "SelectionOverlayController.h"
+#include "ServicesOverlayController.h"
 #include "SessionState.h"
 #include "SessionStateConversion.h"
 #include "SessionTracker.h"
 #include "ShareableBitmap.h"
-#include "TelephoneNumberOverlayController.h"
 #include "VisitedLinkTableController.h"
 #include "WKBundleAPICast.h"
 #include "WKRetainPtr.h"
@@ -4735,23 +4734,13 @@ bool WebPage::synchronousMessagesShouldSpinRunLoop()
     return false;
 }
     
-#if ENABLE(TELEPHONE_NUMBER_DETECTION)
-TelephoneNumberOverlayController& WebPage::telephoneNumberOverlayController()
+#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
+ServicesOverlayController& WebPage::servicesOverlayController()
 {
-    if (!m_telephoneNumberOverlayController)
-        m_telephoneNumberOverlayController = TelephoneNumberOverlayController::create(this);
+    if (!m_servicesOverlayController)
+        m_servicesOverlayController = std::make_unique<ServicesOverlayController>(this);
 
-    return *m_telephoneNumberOverlayController;
-}
-#endif
-
-#if ENABLE(SERVICE_CONTROLS)
-SelectionOverlayController& WebPage::selectionOverlayController()
-{
-    if (!m_selectionOverlayController)
-        m_selectionOverlayController = SelectionOverlayController::create(this);
-
-    return *m_selectionOverlayController;
+    return *m_servicesOverlayController;
 }
 #endif
 
index fa0bd4220a9d07746991028c62e771e40208a801..e0ee60b182300e9a80f12ec6ec74e9099f973e10 100644 (file)
@@ -140,12 +140,12 @@ namespace WebKit {
 
 class DrawingArea;
 class InjectedBundleBackForwardList;
+class LegacySessionState;
 class NotificationPermissionRequestManager;
 class PageBanner;
 class PageOverlay;
 class PluginView;
-class LegacySessionState;
-class SelectionOverlayController;
+class ServicesOverlayController;
 class VisibleContentRectUpdateInfo;
 class WebColorChooser;
 class WebContextMenu;
@@ -183,10 +183,6 @@ class RemoteLayerTreeTransaction;
 class WebTouchEvent;
 #endif
 
-#if ENABLE(TELEPHONE_NUMBER_DETECTION)
-class TelephoneNumberOverlayController;
-#endif
-
 class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IPC::MessageReceiver, public IPC::MessageSender {
 public:
     static PassRefPtr<WebPage> create(uint64_t pageID, const WebPageCreationParameters&);
@@ -827,13 +823,10 @@ public:
     // Some platforms require accessibility-enabled processes to spin the run loop so that the WebProcess doesn't hang.
     // While this is not ideal, it does not have to be applied to every platform at the moment.
     static bool synchronousMessagesShouldSpinRunLoop();
-    
-#if ENABLE(TELEPHONE_NUMBER_DETECTION)
-    TelephoneNumberOverlayController& telephoneNumberOverlayController();
+
+#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION) 
+    ServicesOverlayController& servicesOverlayController();
     void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&);
-#endif
-#if ENABLE(SERVICE_CONTROLS)
-    SelectionOverlayController& selectionOverlayController();
     void handleSelectionServiceClick(WebCore::FrameSelection&, const WebCore::IntPoint&);
     bool serviceControlsEnabled() const { return m_serviceControlsEnabled; }
 #endif
@@ -1271,11 +1264,8 @@ private:
     WebCore::WebGLLoadPolicy m_systemWebGLPolicy;
 #endif
 
-#if ENABLE(TELEPHONE_NUMBER_DETECTION)
-    RefPtr<TelephoneNumberOverlayController> m_telephoneNumberOverlayController;
-#endif
-#if ENABLE(SERVICE_CONTROLS)
-    RefPtr<SelectionOverlayController> m_selectionOverlayController;
+#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
+    std::unique_ptr<ServicesOverlayController> m_servicesOverlayController;
 #endif
 
     PageOverlayController m_pageOverlayController;
diff --git a/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm b/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm
deleted file mode 100644 (file)
index e156b78..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "SelectionOverlayController.h"
-
-#if ENABLE(SERVICE_CONTROLS)
-
-#import "WebProcess.h"
-#import <WebCore/FrameView.h>
-#import <WebCore/GraphicsContext.h>
-#import <WebCore/MainFrame.h>
-#import <WebCore/SoftLinking.h>
-
-#if __has_include(<DataDetectors/DDHighlightDrawing.h>)
-#import <DataDetectors/DDHighlightDrawing.h>
-#else
-typedef void* DDHighlightRef;
-#endif
-
-#if __has_include(<DataDetectors/DDHighlightDrawing_Private.h>)
-#import <DataDetectors/DDHighlightDrawing_Private.h>
-#endif
-
-SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(DataDetectors)
-SOFT_LINK(DataDetectors, DDHighlightCreateWithRectsInVisibleRect, DDHighlightRef, (CFAllocatorRef allocator, CGRect * rects, CFIndex count, CGRect globalVisibleRect, Boolean withArrow), (allocator, rects, count, globalVisibleRect, withArrow))
-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;
-
-namespace WebKit {
-
-static double hoverTimerInterval = 2.0;
-
-void SelectionOverlayController::drawRect(PageOverlay* overlay, WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& dirtyRect)
-{
-    if (m_currentSelectionRects.isEmpty())
-        return;
-
-    if (!WebProcess::shared().hasSelectionServices()) {
-        destroyOverlay();
-        return;
-    }
-
-    if (!m_currentHighlight || m_currentHighlightIsDirty) {
-        Vector<CGRect> cgRects;
-        cgRects.reserveCapacity(m_currentSelectionRects.size());
-
-        for (auto& rect : m_currentSelectionRects) {
-            IntRect selectionRect(rect.pixelSnappedLocation(), rect.pixelSnappedSize());
-
-            if (!selectionRect.intersects(dirtyRect))
-                continue;
-
-            cgRects.append((CGRect)pixelSnappedIntRect(rect));
-        }
-
-        if (!cgRects.isEmpty()) {
-            CGRect bounds = m_webPage->corePage()->mainFrame().view()->boundsRect();
-            m_currentHighlight = adoptCF(DDHighlightCreateWithRectsInVisibleRect(nullptr, cgRects.begin(), cgRects.size(), bounds, true));
-            m_currentHighlightIsDirty = false;
-
-            Boolean onButton;
-            m_mouseIsOverHighlight = DDHighlightPointIsOnHighlight(m_currentHighlight.get(), (CGPoint)m_mousePosition, &onButton);
-
-            mouseHoverStateChanged();
-        }
-    }
-
-    // If the UI is not visibile or if the mouse is not over the DDHighlight we have no drawing to do.
-    if (!m_mouseIsOverHighlight || !m_visible)
-        return;
-
-    CGContextRef cgContext = graphicsContext.platformContext();
-
-    CGLayerRef highlightLayer = DDHighlightGetLayerWithContext(m_currentHighlight.get(), cgContext);
-    CGRect highlightBoundingRect = DDHighlightGetBoundingRect(m_currentHighlight.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);
-}
-    
-bool SelectionOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent& event)
-{
-    m_mousePosition = m_webPage->corePage()->mainFrame().view()->rootViewToContents(event.position());
-
-    bool mouseWasOverHighlight = m_mouseIsOverHighlight;
-    Boolean onButton = false;
-    m_mouseIsOverHighlight = m_currentHighlight ? DDHighlightPointIsOnHighlight(m_currentHighlight.get(), (CGPoint)m_mousePosition, &onButton) : false;
-
-    if (mouseWasOverHighlight != m_mouseIsOverHighlight) {
-        m_selectionOverlay->setNeedsDisplay();
-        mouseHoverStateChanged();
-    }
-
-    // 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) {
-        m_mouseIsDownOnButton = false;
-        return false;
-    }
-
-    if (!m_currentHighlight)
-        return false;
-
-    // Check and see if the mouse went up and we have a current mouse down highlight button.
-    if (event.type() == WebEvent::MouseUp) {
-        bool mouseWasDownOnButton = m_mouseIsDownOnButton;
-        m_mouseIsDownOnButton = false;
-
-        // If the mouse lifted while still over the highlight button that it went down on, then that is a click.
-        if (m_mouseIsOverHighlight && onButton && mouseWasDownOnButton) {
-            handleClick(m_mousePosition);
-            return true;
-        }
-        
-        return false;
-    }
-    
-    // Check and see if the mouse moved within the confines of the DD highlight button.
-    if (event.type() == WebEvent::MouseMove) {
-        // Moving with the mouse button down is okay as long as the mouse never leaves the highlight button.
-        if (m_mouseIsOverHighlight && onButton)
-            return true;
-
-        m_mouseIsDownOnButton = false;
-        
-        return false;
-    }
-    
-    // Check and see if the mouse went down over a DD highlight button.
-    if (event.type() == WebEvent::MouseDown) {
-        if (m_mouseIsOverHighlight && onButton) {
-            m_mouseIsDownOnButton = true;
-
-            // FIXME: We need to do the following, but SOFT_LINK isn't working for this method.
-            // DDHighlightSetButtonPressed(m_currentHighlight.get(), true);
-            
-            m_selectionOverlay->setNeedsDisplay();
-            return true;
-        }
-
-        return false;
-    }
-        
-    return false;
-}
-
-void SelectionOverlayController::handleClick(const WebCore::IntPoint& point)
-{
-    m_webPage->handleSelectionServiceClick(m_webPage->corePage()->mainFrame().selection(), point);
-}
-
-void SelectionOverlayController::mouseHoverStateChanged()
-{
-    if (m_mouseIsOverHighlight) {
-        if (!m_hoverTimer.isActive())
-            m_hoverTimer.startOneShot(hoverTimerInterval);
-    } else {
-        m_visible = false;
-        m_hoverTimer.stop();
-    }
-}
-    
-} // namespace WebKit
-
-#endif // ENABLE(SERVICE_CONTROLS)
-
diff --git a/Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm b/Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm
new file mode 100644 (file)
index 0000000..24938a9
--- /dev/null
@@ -0,0 +1,350 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "ServicesOverlayController.h"
+
+#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
+
+#import "WebPage.h"
+#import "WebProcess.h"
+#import <WebCore/Document.h>
+#import <WebCore/FloatQuad.h>
+#import <WebCore/FrameView.h>
+#import <WebCore/GraphicsContext.h>
+#import <WebCore/MainFrame.h>
+#import <WebCore/SoftLinking.h>
+
+#if __has_include(<DataDetectors/DDHighlightDrawing.h>)
+#import <DataDetectors/DDHighlightDrawing.h>
+#else
+typedef void* DDHighlightRef;
+#endif
+
+#if __has_include(<DataDetectors/DDHighlightDrawing_Private.h>)
+#import <DataDetectors/DDHighlightDrawing_Private.h>
+#endif
+
+typedef NSUInteger DDHighlightStyle;
+static DDHighlightStyle DDHighlightNoOutlineWithArrow = 0;
+
+SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(DataDetectors)
+SOFT_LINK(DataDetectors, DDHighlightCreateWithRectsInVisibleRect, DDHighlightRef, (CFAllocatorRef allocator, CGRect * rects, CFIndex count, CGRect globalVisibleRect, Boolean withArrow), (allocator, rects, count, globalVisibleRect, withArrow))
+SOFT_LINK(DataDetectors, DDHighlightCreateWithRectsInVisibleRectWithStyle, DDHighlightRef, (CFAllocatorRef allocator, CGRect * rects, CFIndex count, CGRect globalVisibleRect, DDHighlightStyle style, Boolean withArrow), (allocator, rects, count, globalVisibleRect, style, withArrow))
+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))
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static IntRect textQuadsToBoundingRectForRange(Range& range)
+{
+    Vector<FloatQuad> textQuads;
+    range.textQuads(textQuads);
+    FloatRect boundingRect;
+    for (auto& quad : textQuads)
+        boundingRect.unite(quad.boundingBox());
+    return enclosingIntRect(boundingRect);
+}
+
+ServicesOverlayController::ServicesOverlayController(WebPage& webPage)
+    : m_webPage(&webPage)
+    , m_servicesOverlay(nullptr)
+    , m_mouseIsDownOnButton(false)
+    , m_mouseIsOverHighlight(false)
+    , m_drawingTelephoneNumberHighlight(false)
+    , m_currentHighlightIsDirty(false)
+{
+}
+
+ServicesOverlayController::~ServicesOverlayController()
+{
+    if (!m_servicesOverlay) {
+        ASSERT(m_webPage);
+        m_webPage->uninstallPageOverlay(m_servicesOverlay, PageOverlay::FadeMode::DoNotFade);
+    }
+}
+
+void ServicesOverlayController::pageOverlayDestroyed(PageOverlay*)
+{
+    // Before the overlay is destroyed, it should have moved out of the WebPage,
+    // at which point we already cleared our back pointer.
+    ASSERT(!m_servicesOverlay);
+}
+
+void ServicesOverlayController::willMoveToWebPage(PageOverlay*, WebPage* webPage)
+{
+    if (webPage)
+        return;
+
+    ASSERT(m_servicesOverlay);
+    m_servicesOverlay = nullptr;
+
+    ASSERT(m_webPage);
+    m_webPage = nullptr;
+}
+
+void ServicesOverlayController::didMoveToWebPage(PageOverlay*, WebPage*)
+{
+}
+
+void ServicesOverlayController::createOverlayIfNeeded()
+{
+    if (m_servicesOverlay) {
+        m_servicesOverlay->setNeedsDisplay();
+        return;
+    }
+
+    if (m_currentTelephoneNumberRanges.isEmpty() && (!WebProcess::shared().hasSelectionServices() || m_currentSelectionRects.isEmpty()))
+        return;
+
+    RefPtr<PageOverlay> overlay = PageOverlay::create(this, PageOverlay::OverlayType::Document);
+    m_servicesOverlay = overlay.get();
+    m_webPage->installPageOverlay(overlay.release(), PageOverlay::FadeMode::Fade);
+    m_servicesOverlay->setNeedsDisplay();
+}
+
+void ServicesOverlayController::selectionRectsDidChange(const Vector<LayoutRect>& rects)
+{
+#if __MAC_OS_X_VERSION_MIN_REQUIRED > 1090
+    m_currentHighlightIsDirty = true;
+    m_currentSelectionRects = rects;
+
+    createOverlayIfNeeded();
+#else
+    UNUSED_PARAM(rects);
+#endif
+}
+
+void ServicesOverlayController::selectedTelephoneNumberRangesChanged(const Vector<RefPtr<Range>>& ranges)
+{
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 1090
+    m_currentHighlightIsDirty = true;
+    m_currentTelephoneNumberRanges = ranges;
+    m_drawingTelephoneNumberHighlight = false;
+
+    if (ranges.size() == 1) {
+        RefPtr<Range> selectionRange = m_webPage->corePage()->mainFrame().selection().toNormalizedRange();
+        if (ranges[0]->contains(*selectionRange))
+            m_drawingTelephoneNumberHighlight = true;
+    }
+    
+    createOverlayIfNeeded();
+#else
+    UNUSED_PARAM(ranges);
+#endif
+}
+
+void ServicesOverlayController::clearHighlightState()
+{
+    m_mouseIsDownOnButton = false;
+    m_mouseIsOverHighlight = false;
+    m_drawingTelephoneNumberHighlight = false;
+
+    m_currentHighlight = nullptr;
+}
+
+void ServicesOverlayController::drawRect(PageOverlay* overlay, WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& dirtyRect)
+{
+    if (m_currentSelectionRects.isEmpty() && m_currentTelephoneNumberRanges.isEmpty()) {
+        clearHighlightState();
+        return;
+    }
+
+    if (m_drawingTelephoneNumberHighlight)
+        drawTelephoneNumberHighlight(graphicsContext, dirtyRect);
+    else
+        drawSelectionHighlight(graphicsContext, dirtyRect);
+}
+
+void ServicesOverlayController::drawSelectionHighlight(WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& dirtyRect)
+{
+    ASSERT(!m_drawingTelephoneNumberHighlight);
+    ASSERT(m_currentSelectionRects.size());
+
+    // If there are no installed selection services and we have no phone numbers detected, then we have nothing to draw.
+    if (!WebProcess::shared().hasSelectionServices() && m_currentTelephoneNumberRanges.isEmpty())
+        return;
+
+    if (!m_currentHighlight || m_currentHighlightIsDirty) {
+        Vector<CGRect> cgRects;
+        cgRects.reserveCapacity(m_currentSelectionRects.size());
+
+        for (auto& rect : m_currentSelectionRects) {
+            IntRect selectionRect(rect.pixelSnappedLocation(), rect.pixelSnappedSize());
+
+            if (!selectionRect.intersects(dirtyRect))
+                continue;
+
+            cgRects.append((CGRect)pixelSnappedIntRect(rect));
+        }
+
+        if (!cgRects.isEmpty()) {
+            CGRect bounds = m_webPage->corePage()->mainFrame().view()->boundsRect();
+            m_currentHighlight = adoptCF(DDHighlightCreateWithRectsInVisibleRectWithStyle(nullptr, cgRects.begin(), cgRects.size(), bounds, DDHighlightNoOutlineWithArrow, true));
+            m_currentHighlightIsDirty = false;
+        }
+    }
+
+    drawCurrentHighlight(graphicsContext);
+}
+
+void ServicesOverlayController::drawTelephoneNumberHighlight(WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& dirtyRect)
+{
+    ASSERT(m_drawingTelephoneNumberHighlight);
+    ASSERT(m_currentTelephoneNumberRanges.size() == 1);
+
+    auto& range = m_currentTelephoneNumberRanges[0];
+
+    // 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);
+
+    // 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())));
+
+    // If the selection rect is completely outside this drawing tile, don't process it further
+    if (!rect.intersects(dirtyRect))
+        return;
+
+    if (!m_currentHighlight || m_currentHighlightIsDirty) {
+        CGRect cgRect = (CGRect)rect;
+
+        m_currentHighlight = adoptCF(DDHighlightCreateWithRectsInVisibleRect(nullptr, &cgRect, 1, viewForRange->boundsRect(), true));
+        m_currentHighlightIsDirty = false;
+    }
+
+    drawCurrentHighlight(graphicsContext);
+}
+
+void ServicesOverlayController::drawCurrentHighlight(WebCore::GraphicsContext& graphicsContext)
+{
+    Boolean onButton;
+    m_mouseIsOverHighlight = DDHighlightPointIsOnHighlight(m_currentHighlight.get(), (CGPoint)m_mousePosition, &onButton);
+
+    // If the mouse is not over the DDHighlight we have no drawing to do.
+    if (!m_mouseIsOverHighlight)
+        return;
+
+    CGContextRef cgContext = graphicsContext.platformContext();
+    
+    CGLayerRef highlightLayer = DDHighlightGetLayerWithContext(m_currentHighlight.get(), cgContext);
+    CGRect highlightBoundingRect = DDHighlightGetBoundingRect(m_currentHighlight.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);
+}
+
+bool ServicesOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent& event)
+{
+    m_mousePosition = m_webPage->corePage()->mainFrame().view()->rootViewToContents(event.position());
+
+    bool mouseWasOverHighlight = m_mouseIsOverHighlight;
+    Boolean onButton = false;
+    m_mouseIsOverHighlight = m_currentHighlight ? DDHighlightPointIsOnHighlight(m_currentHighlight.get(), (CGPoint)m_mousePosition, &onButton) : false;
+
+    if (mouseWasOverHighlight != m_mouseIsOverHighlight)
+        m_servicesOverlay->setNeedsDisplay();
+
+    // 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) {
+        m_mouseIsDownOnButton = false;
+        return false;
+    }
+
+    if (!m_currentHighlight)
+        return false;
+
+    // Check and see if the mouse went up and we have a current mouse down highlight button.
+    if (event.type() == WebEvent::MouseUp) {
+        bool mouseWasDownOnButton = m_mouseIsDownOnButton;
+        m_mouseIsDownOnButton = false;
+
+        // If the mouse lifted while still over the highlight button that it went down on, then that is a click.
+        if (m_mouseIsOverHighlight && onButton && mouseWasDownOnButton) {
+            handleClick(m_mousePosition);
+            return true;
+        }
+        
+        return false;
+    }
+    
+    // Check and see if the mouse moved within the confines of the DD highlight button.
+    if (event.type() == WebEvent::MouseMove) {
+        // Moving with the mouse button down is okay as long as the mouse never leaves the highlight button.
+        if (m_mouseIsOverHighlight && onButton)
+            return true;
+
+        m_mouseIsDownOnButton = false;
+        
+        return false;
+    }
+    
+    // Check and see if the mouse went down over a DD highlight button.
+    if (event.type() == WebEvent::MouseDown) {
+        if (m_mouseIsOverHighlight && onButton) {
+            m_mouseIsDownOnButton = true;
+            m_servicesOverlay->setNeedsDisplay();
+            return true;
+        }
+
+        return false;
+    }
+        
+    return false;
+}
+
+void ServicesOverlayController::handleClick(const WebCore::IntPoint& point)
+{
+    if (m_drawingTelephoneNumberHighlight) {
+        ASSERT(m_currentTelephoneNumberRanges.size() == 1);
+        m_webPage->handleTelephoneNumberClick(m_currentTelephoneNumberRanges[0]->text(), point);
+    } else {
+        // FIXME: Include all selected telephone numbers so they can be added to the menu as well.
+        m_webPage->handleSelectionServiceClick(m_webPage->corePage()->mainFrame().selection(), point);
+    }
+}
+    
+} // namespace WebKit
+
+#endif // #if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
diff --git a/Source/WebKit2/WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm b/Source/WebKit2/WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm
deleted file mode 100644 (file)
index cc76d1a..0000000
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "TelephoneNumberOverlayController.h"
-
-#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>
-#import <WebCore/SoftLinking.h>
-
-#if __has_include(<DataDetectors/DDHighlightDrawing.h>)
-#import <DataDetectors/DDHighlightDrawing.h>
-#else
-typedef void* DDHighlightRef;
-#endif
-
-#if __has_include(<DataDetectors/DDHighlightDrawing_Private.h>)
-#import <DataDetectors/DDHighlightDrawing_Private.h>
-#endif
-
-SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(DataDetectors)
-SOFT_LINK(DataDetectors, DDHighlightCreateWithRectsInVisibleRect, DDHighlightRef, (CFAllocatorRef allocator, CGRect * rects, CFIndex count, CGRect globalVisibleRect, Boolean withArrow), (allocator, rects, count, globalVisibleRect, withArrow))
-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))
-
-using namespace WebCore;
-
-namespace WebKit {
-
-static IntRect textQuadsToBoundingRectForRange(Range& range)
-{
-    Vector<FloatQuad> textQuads;
-    range.textQuads(textQuads);
-    FloatRect boundingRect;
-    for (auto& quad : textQuads)
-        boundingRect.unite(quad.boundingBox());
-    return enclosingIntRect(boundingRect);
-}
-
-void TelephoneNumberOverlayController::drawRect(PageOverlay* overlay, WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& dirtyRect)
-{
-    // 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();
-    auto& range = m_currentSelectionRanges[0];
-
-    // 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);
-
-    // 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())));
-
-    // If the selection rect is completely outside this drawing tile, don't process it further
-    if (!rect.intersects(dirtyRect))
-        return;
-
-    CGRect cgRects[] = { (CGRect)rect };
-
-    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)
-{
-    ASSERT(number);
-
-    m_webPage->handleTelephoneNumberClick(number->range()->text(), point);
-}
-    
-bool TelephoneNumberOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent& event)
-{
-    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();
-        return false;
-    }
-    
-    RefPtr<TelephoneNumberData> currentNumber = m_currentMouseDownNumber;
-    
-    // Check and see if the mouse went up and we have a current mouse down highlight button.
-    if (event.type() == WebEvent::MouseUp && currentNumber) {
-        clearMouseDownInformation();
-        
-        // 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)m_lastMouseMovePosition, &onButton) && onButton) {
-            handleTelephoneClick(currentNumber.get(), m_webPage->corePage()->mainFrame().view()->contentsToWindow(m_lastMouseMovePosition));
-            
-            return true;
-        }
-        
-        return false;
-    }
-    
-    // Check and see if the mouse moved within the confines of the DD highlight button.
-    if (event.type() == WebEvent::MouseMove && currentNumber) {
-        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)m_lastMouseMovePosition, &onButton) && onButton)
-            return true;
-        
-        clearMouseDownInformation();
-        
-        return false;
-    }
-    
-    // Check and see if the mouse went down over a DD highlight button.
-    if (event.type() == WebEvent::MouseDown) {
-        ASSERT(!m_currentMouseDownNumber);
-        
-        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;
-    }
-        
-    return false;
-}
-    
-void TelephoneNumberOverlayController::clearMouseDownInformation()
-{
-    m_currentMouseDownNumber = nullptr;
-    m_mouseDownPosition = IntPoint();
-}
-    
-void TelephoneNumberOverlayController::clearHighlights()
-{
-    m_highlightedTelephoneNumberData = nullptr;
-    m_currentMouseDownNumber = nullptr;
-}
-    
-}
-
-#endif // ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)