Title: [170782] trunk/Source
Revision
170782
Author
beid...@apple.com
Date
2014-07-03 17:39:41 -0700 (Thu, 03 Jul 2014)

Log Message

When showing the selection menu, include menu options for all selected phone numbers.
<rdar://problem/16983434>, <rdar://problem/16874568>, and https://bugs.webkit.org/show_bug.cgi?id=134613

Reviewed by Tim Horton.

Source/WebCore:
* English.lproj/Localizable.strings:

* dom/Range.cpp:
(WebCore::rangesOverlap): Fix reversed arguments that caused some types of overlaps to not be detected.

Source/WebKit2:
Move some telephone number menu logic from WebKitSystemInterface here.
Also provide utility to get just the one menu item relevant to a telephone number.
* Platform/mac/MenuUtilities.h:
* Platform/mac/MenuUtilities.mm: Added.
(WebKit::menuItemForTelephoneNumber):
(WebKit::menuItemsForTelephoneNumber):

* Platform/mac/StringUtilities.h:
* Platform/mac/StringUtilities.mm:
(WebKit::formattedPhoneNumberString): Return a localized formatted phone number.

Add a member to track the selected phone numbers:
* Shared/ContextMenuContextData.h:
(WebKit::ContextMenuContextData::ContextMenuContextData):
(WebKit::ContextMenuContextData::selectedTelephoneNumbers):

* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::setupServicesMenu): Also add menu items for each phone number that is
  in the selection.

Switch away from a WKSI method, and remove a lot of unneeded forward declarations and soft linking:
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::showTelephoneNumberMenu):
(WebKit::WebPageProxy::showSelectionServiceMenu):

* WebKit2.xcodeproj/project.pbxproj:

* WebProcess/WebPage/mac/ServicesOverlayController.mm:
(WebKit::ServicesOverlayController::drawSelectionHighlight):
(WebKit::ServicesOverlayController::handleClick): Pass the phone numbers along.

* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::handleSelectionServiceClick): Pass the phone numbers along.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (170781 => 170782)


--- trunk/Source/WebCore/ChangeLog	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebCore/ChangeLog	2014-07-04 00:39:41 UTC (rev 170782)
@@ -1,3 +1,15 @@
+2014-07-03  Brady Eidson  <beid...@apple.com>
+
+        When showing the selection menu, include menu options for all selected phone numbers.
+        <rdar://problem/16983434>, <rdar://problem/16874568>, and https://bugs.webkit.org/show_bug.cgi?id=134613
+
+        Reviewed by Tim Horton.
+
+        * English.lproj/Localizable.strings:
+
+        * dom/Range.cpp:
+        (WebCore::rangesOverlap): Fix reversed arguments that caused some types of overlaps to not be detected.
+
 2014-07-03  Daniel Bates  <daba...@apple.com>
 
         Add WTF::move()

Modified: trunk/Source/WebCore/English.lproj/Localizable.strings (170781 => 170782)


--- trunk/Source/WebCore/English.lproj/Localizable.strings	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebCore/English.lproj/Localizable.strings	2014-07-04 00:39:41 UTC (rev 170782)
@@ -118,6 +118,9 @@
 /* Undo action name */
 "Bold (Undo action name)" = "Bold";
 
+/* menu item for making a telephone call to a telephone number */
+"Call “%@” Using iPhone" = "Call “%@” Using iPhone";
+
 /* File Upload alert sheet button string to cancel */
 "Cancel (file upload action sheet)" = "Cancel";
 

Modified: trunk/Source/WebCore/dom/Range.cpp (170781 => 170782)


--- trunk/Source/WebCore/dom/Range.cpp	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebCore/dom/Range.cpp	2014-07-04 00:39:41 UTC (rev 170782)
@@ -2008,11 +2008,11 @@
         return true;
 
     // End of first range is inside second range.
-    if (a->compareBoundaryPoints(Range::END_TO_START, b, ASSERT_NO_EXCEPTION) >= 0 && endToEnd <= 0)
+    if (a->compareBoundaryPoints(Range::START_TO_END, b, ASSERT_NO_EXCEPTION) >= 0 && endToEnd <= 0)
         return true;
 
     // Start of first range is inside second range.
-    if (startToStart >= 0 && a->compareBoundaryPoints(Range::START_TO_END, b, ASSERT_NO_EXCEPTION) <= 0)
+    if (startToStart >= 0 && a->compareBoundaryPoints(Range::END_TO_START, b, ASSERT_NO_EXCEPTION) <= 0)
         return true;
 
     return false;

Modified: trunk/Source/WebKit2/ChangeLog (170781 => 170782)


--- trunk/Source/WebKit2/ChangeLog	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/ChangeLog	2014-07-04 00:39:41 UTC (rev 170782)
@@ -1,3 +1,48 @@
+2014-07-03  Brady Eidson  <beid...@apple.com>
+
+        When showing the selection menu, include menu options for all selected phone numbers.
+        <rdar://problem/16983434>, <rdar://problem/16874568>, and https://bugs.webkit.org/show_bug.cgi?id=134613
+
+        Reviewed by Tim Horton.
+
+        Move some telephone number menu logic from WebKitSystemInterface here.
+        Also provide utility to get just the one menu item relevant to a telephone number.
+        * Platform/mac/MenuUtilities.h:
+        * Platform/mac/MenuUtilities.mm: Added.
+        (WebKit::menuItemForTelephoneNumber):
+        (WebKit::menuItemsForTelephoneNumber):
+
+        * Platform/mac/StringUtilities.h:
+        * Platform/mac/StringUtilities.mm:
+        (WebKit::formattedPhoneNumberString): Return a localized formatted phone number.
+
+        Add a member to track the selected phone numbers:
+        * Shared/ContextMenuContextData.h:
+        (WebKit::ContextMenuContextData::ContextMenuContextData):
+        (WebKit::ContextMenuContextData::selectedTelephoneNumbers):
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::setupServicesMenu): Also add menu items for each phone number that is
+          in the selection.
+
+        Switch away from a WKSI method, and remove a lot of unneeded forward declarations and soft linking:
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::showTelephoneNumberMenu):
+        (WebKit::WebPageProxy::showSelectionServiceMenu):
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
+        * WebProcess/WebPage/mac/ServicesOverlayController.mm:
+        (WebKit::ServicesOverlayController::drawSelectionHighlight):
+        (WebKit::ServicesOverlayController::handleClick): Pass the phone numbers along.
+
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::handleSelectionServiceClick): Pass the phone numbers along.
+
 2014-07-03  Gavin Barraclough  <baraclo...@apple.com>
 
         WKProcessAssertionBackgroundTaskManager should clear member if task expires

Copied: trunk/Source/WebKit2/Platform/mac/MenuUtilities.h (from rev 170781, trunk/Source/WebKit2/Platform/mac/StringUtilities.mm) (0 => 170782)


--- trunk/Source/WebKit2/Platform/mac/MenuUtilities.h	                        (rev 0)
+++ trunk/Source/WebKit2/Platform/mac/MenuUtilities.h	2014-07-04 00:39:41 UTC (rev 170782)
@@ -0,0 +1,41 @@
+/*
+ * 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 MenuUtilities_h
+#define MenuUtilities_h
+
+#import <wtf/Vector.h>
+#import <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+#if ENABLE(TELEPHONE_NUMBER_DETECTION) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+NSMenuItem *menuItemForTelephoneNumber(const String& telephoneNumberString);
+NSArray *menuItemsForTelephoneNumber(const String& telephoneNumber);
+#endif
+
+} // namespace WebKit
+
+#endif // MenuUtilities_h

Added: trunk/Source/WebKit2/Platform/mac/MenuUtilities.mm (0 => 170782)


--- trunk/Source/WebKit2/Platform/mac/MenuUtilities.mm	                        (rev 0)
+++ trunk/Source/WebKit2/Platform/mac/MenuUtilities.mm	2014-07-04 00:39:41 UTC (rev 170782)
@@ -0,0 +1,121 @@
+/*
+ * 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 "MenuUtilities.h"
+
+#import "StringUtilities.h"
+#import <WebCore/LocalizedStrings.h>
+#import <WebCore/SoftLinking.h>
+#import <objc/runtime.h>
+
+#if ENABLE(TELEPHONE_NUMBER_DETECTION) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+SOFT_LINK_PRIVATE_FRAMEWORK(DataDetectors)
+SOFT_LINK_CLASS(DataDetectors, DDAction)
+SOFT_LINK_CLASS(DataDetectors, DDActionsManager)
+SOFT_LINK_CONSTANT(DataDetectors, DDBinderPhoneNumberKey, CFStringRef)
+
+@interface DDAction : NSObject
+@property (readonly) NSString *actionUTI;
+@end
+
+typedef void* DDActionContext;
+
+@interface DDActionsManager : NSObject
++ (DDActionsManager *)sharedManager;
+- (NSArray *)menuItemsForValue:(NSString *)value type:(CFStringRef)type service:(NSString *)service context:(DDActionContext *)context;
+@end
+#endif
+
+namespace WebKit {
+
+#if ENABLE(TELEPHONE_NUMBER_DETECTION) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+
+static NSString *menuItemTitleForTelephoneNumber(const String& telephoneNumber)
+{
+    return [NSString stringWithFormat:WEB_UI_STRING("Call “%@” Using iPhone", "menu item for making a telephone call to a telephone number"), formattedPhoneNumberString(telephoneNumber)];
+}
+
+NSMenuItem *menuItemForTelephoneNumber(const String& telephoneNumber)
+{
+    NSArray *proposedMenu = [[getDDActionsManagerClass() sharedManager] menuItemsForValue:(NSString *)telephoneNumber type:getDDBinderPhoneNumberKey() service:nil context:nil];
+    for (NSMenuItem *item in proposedMenu) {
+        NSDictionary *representedObject = item.representedObject;
+        if (![representedObject isKindOfClass:[NSDictionary class]])
+            continue;
+
+        DDAction *actionObject = [representedObject objectForKey:@"DDAction"];
+        if (![actionObject isKindOfClass:getDDActionClass()])
+            continue;
+
+        if ([actionObject.actionUTI hasPrefix:@"com.apple.dial"]) {
+            item.title = menuItemTitleForTelephoneNumber(telephoneNumber);
+            return item;
+        }
+    }
+
+    return nil;
+}
+
+NSArray *menuItemsForTelephoneNumber(const String& telephoneNumber)
+{
+    NSMutableArray *items = [NSMutableArray array];
+    NSMutableArray *faceTimeItems = [NSMutableArray array];
+    NSMenuItem *dialItem = nil;
+
+    NSArray *proposedMenu = [[getDDActionsManagerClass() sharedManager] menuItemsForValue:(NSString *)telephoneNumber type:getDDBinderPhoneNumberKey() service:nil context:nil];
+    for (NSMenuItem *item in proposedMenu) {
+        NSDictionary *representedObject = item.representedObject;
+        if (![representedObject isKindOfClass:[NSDictionary class]])
+            continue;
+
+        DDAction *actionObject = [representedObject objectForKey:@"DDAction"];
+        if (![actionObject isKindOfClass:getDDActionClass()])
+            continue;
+
+        if ([actionObject.actionUTI hasPrefix:@"com.apple.dial"]) {
+            item.title = menuItemTitleForTelephoneNumber(telephoneNumber);
+            dialItem = item;
+            continue;
+        }
+
+        if ([actionObject.actionUTI hasPrefix:@"com.apple.facetime"])
+            [faceTimeItems addObject:item];
+    }
+
+    if (dialItem)
+        [items addObject:dialItem];
+
+    if (faceTimeItems.count) {
+        if (items.count)
+            [items addObject:[NSMenuItem separatorItem]];
+        [items addObjectsFromArray:faceTimeItems];
+    }
+
+    return items.count ? items : nil;
+}
+#endif
+
+} // namespace WebKit

Modified: trunk/Source/WebKit2/Platform/mac/StringUtilities.h (170781 => 170782)


--- trunk/Source/WebKit2/Platform/mac/StringUtilities.h	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/Platform/mac/StringUtilities.h	2014-07-04 00:39:41 UTC (rev 170782)
@@ -32,8 +32,12 @@
 
 // NOTE: This does not use String::operator NSString*() since that function
 // expects to be called on the thread running WebCore.
-NSString* nsStringFromWebCoreString(const String&);
+NSString *nsStringFromWebCoreString(const String&);
 
+#if ENABLE(TELEPHONE_NUMBER_DETECTION) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+NSString *formattedPhoneNumberString(NSString *originalPhoneNumber);
+#endif
+
 }
 
 #endif // StringUtilities_h

Modified: trunk/Source/WebKit2/Platform/mac/StringUtilities.mm (170781 => 170782)


--- trunk/Source/WebKit2/Platform/mac/StringUtilities.mm	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/Platform/mac/StringUtilities.mm	2014-07-04 00:39:41 UTC (rev 170782)
@@ -28,6 +28,7 @@
 
 #import "WKSharedAPICast.h"
 #import "WKStringCF.h"
+#import <WebCore/SoftLinking.h>
 #import <wtf/ObjcRuntimeExtras.h>
 #import <wtf/text/WTFString.h>
 
@@ -38,4 +39,39 @@
     return string.isEmpty() ? @"" : CFBridgingRelease(WKStringCopyCFString(0, toAPI(string.impl())));
 }
 
+#if ENABLE(TELEPHONE_NUMBER_DETECTION) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+
+SOFT_LINK_PRIVATE_FRAMEWORK(PhoneNumbers);
+
+typedef struct __CFPhoneNumber* CFPhoneNumberRef;
+
+// These functions are declared with __attribute__((visibility ("default")))
+// We currently don't have a way to soft link such functions, so we forward declare them again here.
+CFPhoneNumberRef CFPhoneNumberCreate(CFAllocatorRef, CFStringRef, CFStringRef);
+SOFT_LINK(PhoneNumbers, CFPhoneNumberCreate, CFPhoneNumberRef, (CFAllocatorRef allocator, CFStringRef digits, CFStringRef countryCode), (allocator, digits, countryCode));
+
+CFStringRef CFPhoneNumberCopyFormattedRepresentation(CFPhoneNumberRef);
+SOFT_LINK(PhoneNumbers, CFPhoneNumberCopyFormattedRepresentation, CFStringRef, (CFPhoneNumberRef phoneNumber), (phoneNumber));
+
+CFStringRef CFPhoneNumberCopyUnformattedRepresentation(CFPhoneNumberRef);
+SOFT_LINK(PhoneNumbers, CFPhoneNumberCopyUnformattedRepresentation, CFStringRef, (CFPhoneNumberRef phoneNumber), (phoneNumber));
+
+
+NSString *formattedPhoneNumberString(NSString *originalPhoneNumber)
+{
+    NSString *countryCode = [[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode] lowercaseString];
+
+    RetainPtr<CFPhoneNumberRef> phoneNumber = adoptCF(CFPhoneNumberCreate(kCFAllocatorDefault, (CFStringRef)originalPhoneNumber, (CFStringRef)countryCode));
+    if (!phoneNumber)
+        return originalPhoneNumber;
+
+    CFStringRef phoneNumberString = CFPhoneNumberCopyFormattedRepresentation(phoneNumber.get());
+    if (!phoneNumberString)
+        phoneNumberString = CFPhoneNumberCopyUnformattedRepresentation(phoneNumber.get());
+
+    return [(NSString *)phoneNumberString autorelease];
 }
+
+#endif // ENABLE(TELEPHONE_NUMBER_DETECTION) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+
+}

Modified: trunk/Source/WebKit2/Shared/ContextMenuContextData.h (170781 => 170782)


--- trunk/Source/WebKit2/Shared/ContextMenuContextData.h	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/Shared/ContextMenuContextData.h	2014-07-04 00:39:41 UTC (rev 170782)
@@ -57,14 +57,16 @@
     const WebHitTestResult::Data& webHitTestResultData() const { return m_webHitTestResultData; }
 
 #if ENABLE(SERVICE_CONTROLS)
-    ContextMenuContextData(const Vector<uint8_t>& selectionData, bool isEditable)
+    ContextMenuContextData(const Vector<uint8_t>& selectionData, const Vector<String>& selectedTelephoneNumbers, bool isEditable)
         : m_isTelephoneNumberContext(false)
         , m_controlledSelectionData(selectionData)
+        , m_selectedTelephoneNumbers(selectedTelephoneNumbers)
         , m_selectionIsEditable(isEditable)
     { }
 
     const ShareableBitmap::Handle& controlledImageHandle() const { return m_controlledImageHandle; }
     const Vector<uint8_t>& controlledSelectionData() const { return m_controlledSelectionData; }
+    const Vector<String>& selectedTelephoneNumbers() const { return m_selectedTelephoneNumbers; }
 
     bool controlledDataIsEditable() const;
     bool needsServicesMenu() const { return !m_controlledImageHandle.isNull() || !m_controlledSelectionData.isEmpty(); }
@@ -85,6 +87,7 @@
 #if ENABLE(SERVICE_CONTROLS)
     ShareableBitmap::Handle m_controlledImageHandle;
     Vector<uint8_t> m_controlledSelectionData;
+    Vector<String> m_selectedTelephoneNumbers;
     bool m_selectionIsEditable;
 #endif
 };

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (170781 => 170782)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2014-07-04 00:39:41 UTC (rev 170782)
@@ -1099,7 +1099,7 @@
 #endif
 
 #if ENABLE(SERVICE_CONTROLS)
-    void showSelectionServiceMenu(const IPC::DataReference& selectionAsRTFD, bool isEditable, const WebCore::IntPoint&);
+    void showSelectionServiceMenu(const IPC::DataReference& selectionAsRTFD, const Vector<String>& telephoneNumbers, bool isEditable, const WebCore::IntPoint&);
 #endif
 
     // Search popup results

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (170781 => 170782)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2014-07-04 00:39:41 UTC (rev 170782)
@@ -396,7 +396,7 @@
 #endif
 
 #if ENABLE(SERVICE_CONTROLS)
-    ShowSelectionServiceMenu(IPC::DataReference selectionAsRTFD, bool isEditable, WebCore::IntPoint point)
+    ShowSelectionServiceMenu(IPC::DataReference selectionAsRTFD, Vector<String> telephoneNumbers, bool isEditable, WebCore::IntPoint point)
 #endif
 
 #if USE(QUICK_LOOK)

Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm (170781 => 170782)


--- trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm	2014-07-04 00:39:41 UTC (rev 170782)
@@ -29,6 +29,7 @@
 #if PLATFORM(MAC)
 
 #import "DataReference.h"
+#import "MenuUtilities.h"
 #import "PageClientImpl.h"
 #import "ShareableBitmap.h"
 #import "StringUtilities.h"
@@ -398,6 +399,16 @@
 
     m_servicesMenu = [picker menu];
 
+    // Explicitly add a menu item for each telephone number that is in the selection.
+    const Vector<String>& selectedTelephoneNumbers = context.selectedTelephoneNumbers();
+    if (!selectedTelephoneNumbers.isEmpty()) {
+        [m_servicesMenu.get() addItem:[NSMenuItem separatorItem]];
+        for (auto& telephoneNumber : selectedTelephoneNumbers) {
+            if (NSMenuItem *item = menuItemForTelephoneNumber(telephoneNumber))
+                [m_servicesMenu.get() addItem:item];
+        }
+    }
+
     // If there is no services menu, then the existing services on the system have changed.
     // Ask the UIProcess to refresh that list of services.
     // If <rdar://problem/16776831> is resolved then we can more accurately keep the list up to date without this call.

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (170781 => 170782)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2014-07-04 00:39:41 UTC (rev 170782)
@@ -35,6 +35,7 @@
 #import "DictionaryPopupInfo.h"
 #import "EditingRange.h"
 #import "EditorState.h"
+#import "MenuUtilities.h"
 #import "NativeWebKeyboardEvent.h"
 #import "PageClient.h"
 #import "PageClientImpl.h"
@@ -49,10 +50,8 @@
 #import <WebCore/GraphicsLayer.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SharedBuffer.h>
-#import <WebCore/SoftLinking.h>
 #import <WebCore/TextAlternativeWithRange.h>
 #import <WebCore/UserAgent.h>
-#import <WebKitSystemInterface.h>
 #import <mach-o/dyld.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/text/StringConcatenate.h>
@@ -61,17 +60,6 @@
 - (void)speakString:(NSString *)string;
 @end
 
-SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(DataDetectors)
-SOFT_LINK_CLASS(DataDetectors, DDActionsManager)
-SOFT_LINK_CONSTANT(DataDetectors, DDBinderPhoneNumberKey, CFStringRef)
-
-typedef void* DDActionContext;
-
-@interface DDActionsManager : NSObject
-+ (DDActionsManager *) sharedManager;
-- (NSArray *) menuItemsForValue:(NSString *)value type:(CFStringRef)type service:(NSString *)service context:(DDActionContext *)context;
-@end
-
 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, process().connection())
 
 using namespace WebCore;
@@ -647,8 +635,7 @@
 #if ENABLE(TELEPHONE_NUMBER_DETECTION)
 void WebPageProxy::showTelephoneNumberMenu(const String& telephoneNumber, const WebCore::IntPoint& point)
 {
-    NSArray *menuItems = [[getDDActionsManagerClass() sharedManager] menuItemsForValue:(NSString *)telephoneNumber type:getDDBinderPhoneNumberKey() service:nil context:nil];
-    menuItems = WKTelephoneNumberMenuFromProposedMenu(menuItems, telephoneNumber);
+    NSArray *menuItems = menuItemsForTelephoneNumber(telephoneNumber);
 
     Vector<WebContextMenuItemData> items;
     for (NSMenuItem *item in menuItems) {
@@ -667,10 +654,10 @@
 #endif
 
 #if ENABLE(SERVICE_CONTROLS)
-void WebPageProxy::showSelectionServiceMenu(const IPC::DataReference& selectionAsRTFD, bool isEditable, const IntPoint& point)
+void WebPageProxy::showSelectionServiceMenu(const IPC::DataReference& selectionAsRTFD, const Vector<String>& telephoneNumbers, bool isEditable, const IntPoint& point)
 {
     Vector<WebContextMenuItemData> items;
-    ContextMenuContextData contextData(selectionAsRTFD.vector(), isEditable);
+    ContextMenuContextData contextData(selectionAsRTFD.vector(), telephoneNumbers, isEditable);
 
     internalShowContextMenu(point, contextData, items, ContextMenuClientEligibility::NotEligibleForClient, nullptr);
 }

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (170781 => 170782)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2014-07-04 00:39:41 UTC (rev 170782)
@@ -915,6 +915,8 @@
 		518E8F0C16B2093700E91429 /* DownloadManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 518E8F0316B2093700E91429 /* DownloadManager.h */; };
 		518E8F0D16B2093700E91429 /* DownloadMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 518E8F0516B2093700E91429 /* DownloadMac.mm */; };
 		5192D5761961FD0300CD19AA /* ServicesOverlayController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5192D5751961FD0300CD19AA /* ServicesOverlayController.mm */; };
+		51933DEF1965EB31008AC3EA /* MenuUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 51933DEB1965EB24008AC3EA /* MenuUtilities.h */; };
+		51933DF01965EB31008AC3EA /* MenuUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51933DEC1965EB24008AC3EA /* MenuUtilities.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, ); }; };
@@ -2917,6 +2919,8 @@
 		518E8F0516B2093700E91429 /* DownloadMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DownloadMac.mm; 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>"; };
+		51933DEB1965EB24008AC3EA /* MenuUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuUtilities.h; sourceTree = "<group>"; };
+		51933DEC1965EB24008AC3EA /* MenuUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MenuUtilities.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>"; };
@@ -4256,6 +4260,8 @@
 				BCE0937514FB128B001138D9 /* LayerHostingContext.mm */,
 				1A24B5F011F531E800C38269 /* MachUtilities.cpp */,
 				1A24B5F111F531E800C38269 /* MachUtilities.h */,
+				51933DEB1965EB24008AC3EA /* MenuUtilities.h */,
+				51933DEC1965EB24008AC3EA /* MenuUtilities.mm */,
 				1A24BF39120896A600FBB059 /* SharedMemoryMac.cpp */,
 				296BD85B15019BC30071F424 /* StringUtilities.h */,
 				296BD85C15019BC30071F424 /* StringUtilities.mm */,
@@ -7624,6 +7630,7 @@
 				BC5C75C814954DA600BC4775 /* WKConnectionInternal.h in Headers */,
 				BC4A6297147313A0006C681A /* WKConnectionRef.h in Headers */,
 				BCB9E24B1120E15C00A137E0 /* WKContext.h in Headers */,
+				51933DEF1965EB31008AC3EA /* MenuUtilities.h in Headers */,
 				3795789C18AD4F1900B9ED2E /* WKWebProcessPlugInFormDelegatePrivate.h in Headers */,
 				51A555F6128C6C47009ABCEC /* WKContextMenuItem.h in Headers */,
 				51A55601128C6D92009ABCEC /* WKContextMenuItemTypes.h in Headers */,
@@ -9000,6 +9007,7 @@
 				51A4D5A916CAC4FF000E615E /* StatisticsRequest.cpp in Sources */,
 				1AD3306E16B1D991004F60E7 /* StorageAreaImpl.cpp in Sources */,
 				1ACECD2417162DB1001FC9EF /* StorageAreaMap.cpp in Sources */,
+				51933DF01965EB31008AC3EA /* MenuUtilities.mm in Sources */,
 				1A334DED16DE8F88006A8E38 /* StorageAreaMapMessageReceiver.cpp in Sources */,
 				1A44B95B16B73F9F00B7BBD8 /* StorageManager.cpp in Sources */,
 				1AB31A9616BC688100F6DBC9 /* StorageManagerMessageReceiver.cpp in Sources */,

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (170781 => 170782)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-07-04 00:39:41 UTC (rev 170782)
@@ -830,7 +830,7 @@
 #if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION) 
     ServicesOverlayController& servicesOverlayController();
     void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&);
-    void handleSelectionServiceClick(WebCore::FrameSelection&, const WebCore::IntPoint&);
+    void handleSelectionServiceClick(WebCore::FrameSelection&, const Vector<String>& telephoneNumbers, const WebCore::IntPoint&);
     bool serviceControlsEnabled() const { return m_serviceControlsEnabled; }
 #endif
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm (170781 => 170782)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm	2014-07-04 00:39:41 UTC (rev 170782)
@@ -278,8 +278,12 @@
 void ServicesOverlayController::drawSelectionHighlight(WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& dirtyRect)
 {
     ASSERT(!m_drawingTelephoneNumberHighlight);
-    ASSERT(m_currentSelectionRects.size());
 
+    // It's possible to end up drawing the selection highlight before we've actually received the selection rects.
+    // If that happens we'll end up here again once we have the rects.
+    if (m_currentSelectionRects.isEmpty())
+        return;
+
     // 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;
@@ -430,8 +434,12 @@
         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);
+        Vector<String> selectedTelephoneNumbers;
+        selectedTelephoneNumbers.reserveCapacity(m_currentTelephoneNumberRanges.size());
+        for (auto& range : m_currentTelephoneNumberRanges)
+            selectedTelephoneNumbers.append(range->text());
+
+        m_webPage->handleSelectionServiceClick(m_webPage->corePage()->mainFrame().selection(), selectedTelephoneNumbers, point);
     }
 }
     

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (170781 => 170782)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-07-04 00:36:07 UTC (rev 170781)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-07-04 00:39:41 UTC (rev 170782)
@@ -1022,7 +1022,7 @@
 #endif
 
 #if ENABLE(SERVICE_CONTROLS)
-void WebPage::handleSelectionServiceClick(FrameSelection& selection, const IntPoint& point)
+void WebPage::handleSelectionServiceClick(FrameSelection& selection, const Vector<String>& phoneNumbers, const IntPoint& point)
 {
     RefPtr<Range> range = selection.selection().firstRange();
     if (!range)
@@ -1036,7 +1036,7 @@
     IPC::DataReference data = "" uint8_t*>([selectionData bytes]), [selectionData length]);
     bool isEditable = selection.selection().isContentRichlyEditable();
 
-    send(Messages::WebPageProxy::ShowSelectionServiceMenu(data, isEditable, point));
+    send(Messages::WebPageProxy::ShowSelectionServiceMenu(data, phoneNumbers, isEditable, point));
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to