<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[169170] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/169170">169170</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2014-05-21 10:37:48 -0700 (Wed, 21 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Special handling of telephone number detection menu.
&lt;rdar://problem/16967971&gt; and https://bugs.webkit.org/show_bug.cgi?id=133143

Reviewed by Geoff Garen.

Add a bool to ContextMenuContextData to represent telephone number menus:
* Shared/ContextMenuContextData.cpp:
(WebKit::ContextMenuContextData::ContextMenuContextData):
(WebKit::ContextMenuContextData::operator=):
(WebKit::ContextMenuContextData::encode):
(WebKit::ContextMenuContextData::decode):
* Shared/ContextMenuContextData.h:
(WebKit::ContextMenuContextData::ContextMenuContextData):
(WebKit::ContextMenuContextData::isTelephoneNumberContext):

* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::showContextMenu): If the menu is a telephone
  number menu then display it using a specific AppKit API.

* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::showTelephoneNumberMenu): Filter the array of menu items
  through a new WKSI call, and then show it using a telephone number context.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedContextMenuContextDatacpp">trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedContextMenuContextDatah">trunk/Source/WebKit2/Shared/ContextMenuContextData.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebContextMenuProxyMacmm">trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebPageProxyMacmm">trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (169169 => 169170)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-05-21 17:30:33 UTC (rev 169169)
+++ trunk/Source/WebKit2/ChangeLog        2014-05-21 17:37:48 UTC (rev 169170)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2014-05-21  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Special handling of telephone number detection menu.
+        &lt;rdar://problem/16967971&gt; and https://bugs.webkit.org/show_bug.cgi?id=133143
+
+        Reviewed by Geoff Garen.
+
+        Add a bool to ContextMenuContextData to represent telephone number menus:
+        * Shared/ContextMenuContextData.cpp:
+        (WebKit::ContextMenuContextData::ContextMenuContextData):
+        (WebKit::ContextMenuContextData::operator=):
+        (WebKit::ContextMenuContextData::encode):
+        (WebKit::ContextMenuContextData::decode):
+        * Shared/ContextMenuContextData.h:
+        (WebKit::ContextMenuContextData::ContextMenuContextData):
+        (WebKit::ContextMenuContextData::isTelephoneNumberContext):
+
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::showContextMenu): If the menu is a telephone
+          number menu then display it using a specific AppKit API.
+
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::showTelephoneNumberMenu): Filter the array of menu items
+          through a new WKSI call, and then show it using a telephone number context.
+
</ins><span class="cx"> 2014-05-21  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Mac] REGRESSION (Async text input): Asian text input doesn't work in Flash
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedContextMenuContextDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp (169169 => 169170)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp        2014-05-21 17:30:33 UTC (rev 169169)
+++ trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp        2014-05-21 17:37:48 UTC (rev 169170)
</span><span class="lines">@@ -38,14 +38,24 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> ContextMenuContextData::ContextMenuContextData()
</span><ins>+    : m_isTelephoneNumberContext(false)
</ins><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><del>-    : m_selectionIsEditable(false)
</del><ins>+    , m_selectionIsEditable(false)
</ins><span class="cx"> #endif
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+ContextMenuContextData::ContextMenuContextData(TelephoneNumberContextTag)
+    : m_isTelephoneNumberContext(true)
+#if ENABLE(SERVICE_CONTROLS)
+    , m_selectionIsEditable(false)
+#endif
+{
+}
+
</ins><span class="cx"> ContextMenuContextData::ContextMenuContextData(const ContextMenuContext&amp; context)
</span><span class="cx">     : m_webHitTestResultData(WebHitTestResult::Data(context.hitTestResult()))
</span><ins>+    , m_isTelephoneNumberContext(false)
</ins><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     , m_selectionIsEditable(false)
</span><span class="cx"> #endif
</span><span class="lines">@@ -69,6 +79,8 @@
</span><span class="cx"> ContextMenuContextData&amp; ContextMenuContextData::operator=(const ContextMenuContextData&amp; other)
</span><span class="cx"> {
</span><span class="cx">     m_webHitTestResultData = other.m_webHitTestResultData;
</span><ins>+    m_isTelephoneNumberContext = other.m_isTelephoneNumberContext;
+
</ins><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     m_controlledImageHandle.clear();
</span><span class="cx"> 
</span><span class="lines">@@ -76,6 +88,8 @@
</span><span class="cx">         RefPtr&lt;ShareableBitmap&gt; bitmap = ShareableBitmap::create(other.m_controlledImageHandle);
</span><span class="cx">         bitmap-&gt;createHandle(m_controlledImageHandle);
</span><span class="cx">     }
</span><ins>+
+    m_selectionIsEditable = other.m_selectionIsEditable;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     return *this;
</span><span class="lines">@@ -84,6 +98,11 @@
</span><span class="cx"> void ContextMenuContextData::encode(IPC::ArgumentEncoder&amp; encoder) const
</span><span class="cx"> {
</span><span class="cx">     encoder &lt;&lt; m_webHitTestResultData;
</span><ins>+
+#if ENABLE(TELEPHONE_NUMBER_DETECTION)
+    encoder &lt;&lt; m_isTelephoneNumberContext;
+#endif
+
</ins><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     encoder &lt;&lt; m_controlledImageHandle;
</span><span class="cx"> #endif
</span><span class="lines">@@ -93,7 +112,12 @@
</span><span class="cx"> {
</span><span class="cx">     if (!decoder.decode(contextMenuContextData.m_webHitTestResultData))
</span><span class="cx">         return false;
</span><del>-        
</del><ins>+
+#if ENABLE(TELEPHONE_NUMBER_DETECTION)
+    if (!decoder.decode(contextMenuContextData.m_isTelephoneNumberContext))
+        return false;
+#endif
+
</ins><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     if (!decoder.decode(contextMenuContextData.m_controlledImageHandle))
</span><span class="cx">         return false;
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedContextMenuContextDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ContextMenuContextData.h (169169 => 169170)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ContextMenuContextData.h        2014-05-21 17:30:33 UTC (rev 169169)
+++ trunk/Source/WebKit2/Shared/ContextMenuContextData.h        2014-05-21 17:37:48 UTC (rev 169170)
</span><span class="lines">@@ -43,9 +43,12 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+enum TelephoneNumberContextTag { TelephoneNumberContext };
+
</ins><span class="cx"> class ContextMenuContextData {
</span><span class="cx"> public:
</span><span class="cx">     ContextMenuContextData();
</span><ins>+    ContextMenuContextData(TelephoneNumberContextTag);
</ins><span class="cx">     ContextMenuContextData(const WebCore::ContextMenuContext&amp;);
</span><span class="cx"> 
</span><span class="cx">     ContextMenuContextData(const ContextMenuContextData&amp;);
</span><span class="lines">@@ -55,7 +58,8 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     ContextMenuContextData(const Vector&lt;uint8_t&gt;&amp; selectionData, bool isEditable)
</span><del>-        : m_controlledSelectionData(selectionData)
</del><ins>+        : m_isTelephoneNumberContext(false)
+        , m_controlledSelectionData(selectionData)
</ins><span class="cx">         , m_selectionIsEditable(isEditable)
</span><span class="cx">     { }
</span><span class="cx"> 
</span><span class="lines">@@ -66,12 +70,17 @@
</span><span class="cx">     bool needsServicesMenu() const { return !m_controlledImageHandle.isNull() || !m_controlledSelectionData.isEmpty(); }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(TELEPHONE_NUMBER_DETECTION)
+    bool isTelephoneNumberContext() const { return m_isTelephoneNumberContext; }
+#endif
+
</ins><span class="cx">     void encode(IPC::ArgumentEncoder&amp;) const;
</span><span class="cx">     static bool decode(IPC::ArgumentDecoder&amp;, ContextMenuContextData&amp;);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx"> 
</span><span class="cx">     WebHitTestResult::Data m_webHitTestResultData;
</span><ins>+    bool m_isTelephoneNumberContext;
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     ShareableBitmap::Handle m_controlledImageHandle;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebContextMenuProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm (169169 => 169170)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm        2014-05-21 17:30:33 UTC (rev 169169)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm        2014-05-21 17:37:48 UTC (rev 169170)
</span><span class="lines">@@ -457,6 +457,17 @@
</span><span class="cx">         [m_popup attachPopUpWithFrame:menuRect inView:m_webView];
</span><span class="cx"> 
</span><span class="cx">     NSMenu *menu = m_servicesMenu ? m_servicesMenu.get() : [m_popup menu];
</span><ins>+
+    // Telephone number menus must use the [NSMenu popUpMenuPositioningItem:atLocation:inView:] API.
+    // FIXME: That API is better than WKPopupContextMenu. In the future all menus should use either it
+    // or the [NSMenu popUpContextMenu:withEvent:forView:] API, depending on the menu type.
+    // Then we could get rid of NSPopUpButtonCell, custom metrics, and WKPopupContextMenu.
+    if (context.isTelephoneNumberContext()) {
+        [menu popUpMenuPositioningItem:nil atLocation:menuLocation inView:m_webView];
+        hideContextMenu();
+        return;
+    }
+
</ins><span class="cx"> #else
</span><span class="cx">     [m_popup attachPopUpWithFrame:menuRect inView:m_webView];
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebPageProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (169169 => 169170)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm        2014-05-21 17:30:33 UTC (rev 169169)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm        2014-05-21 17:37:48 UTC (rev 169170)
</span><span class="lines">@@ -63,8 +63,6 @@
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(DataDetectors)
</span><span class="cx"> SOFT_LINK_CLASS(DataDetectors, DDActionsManager)
</span><del>-SOFT_LINK_CLASS(DataDetectors, DDAction)
-SOFT_LINK_CLASS(DataDetectors, DDSeparatorAction)
</del><span class="cx"> SOFT_LINK_CONSTANT(DataDetectors, DDBinderPhoneNumberKey, CFStringRef)
</span><span class="cx"> 
</span><span class="cx"> typedef void* DDActionContext;
</span><span class="lines">@@ -74,10 +72,6 @@
</span><span class="cx"> - (NSArray *) menuItemsForValue:(NSString *)value type:(CFStringRef)type service:(NSString *)service context:(DDActionContext *)context;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><del>-@interface DDAction : NSObject
-@property (readonly) NSString *actionUTI;
-@end
-
</del><span class="cx"> #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, process().connection())
</span><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="lines">@@ -663,25 +657,10 @@
</span><span class="cx"> void WebPageProxy::showTelephoneNumberMenu(const String&amp; telephoneNumber, const WebCore::IntPoint&amp; point)
</span><span class="cx"> {
</span><span class="cx">     NSArray *menuItems = [[getDDActionsManagerClass() sharedManager] menuItemsForValue:(NSString *)telephoneNumber type:getDDBinderPhoneNumberKey() service:nil context:nil];
</span><ins>+    menuItems = WKTelephoneNumberMenuFromProposedMenu(menuItems, telephoneNumber);
</ins><span class="cx"> 
</span><span class="cx">     Vector&lt;WebContextMenuItemData&gt; items;
</span><span class="cx">     for (NSMenuItem *item in menuItems) {
</span><del>-        NSDictionary *representedObject = [item representedObject];
-        if (![representedObject isKindOfClass:[NSDictionary class]])
-            continue;
-
-        DDAction *actionObject = [representedObject objectForKey:@&quot;DDAction&quot;];
-        if (![actionObject isKindOfClass:getDDActionClass()])
-            continue;
-
-        // Skip menu items whose actions have anything to do with contacts.
-        if ([[actionObject actionUTI] hasPrefix:@&quot;com.apple.contact.&quot;])
-            continue;
-
-        // Skip seperator items.
-        if ([actionObject isKindOfClass:getDDSeparatorActionClass()])
-            continue;
-
</del><span class="cx">         RetainPtr&lt;NSMenuItem&gt; retainedItem = item;
</span><span class="cx">         std::function&lt;void()&gt; handler = [retainedItem]() {
</span><span class="cx">             NSMenuItem *item = retainedItem.get();
</span><span class="lines">@@ -691,7 +670,7 @@
</span><span class="cx">         items.append(WebContextMenuItemData(ContextMenuItem(item), handler));
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    ContextMenuContextData contextData;
</del><ins>+    ContextMenuContextData contextData(TelephoneNumberContext);
</ins><span class="cx">     internalShowContextMenu(point, contextData, items, ContextMenuClientEligibility::NotEligibleForClient, nullptr);
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>