<!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>[175376] 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/175376">175376</a></dd>
<dt>Author</dt> <dd>bdakin@apple.com</dd>
<dt>Date</dt> <dd>2014-10-30 12:38:27 -0700 (Thu, 30 Oct 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement action menus for text
https://bugs.webkit.org/show_bug.cgi?id=138220
-and corresponding-
rdar://problem/18742297

Reviewed by Tim Horton.

Two new types of actions for the two text actions.
* Shared/API/c/WKActionMenuItemTypes.h:

One new type of menu.
* Shared/API/c/WKActionMenuTypes.h:

Pass willOpenMenu on to the WKActionMenuController.
* UIProcess/API/mac/WKView.mm:
(-[WKView willOpenMenu:withEvent:]):

Two new WebPageProxy functions that will pass messages along to the web process.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::selectLookupTextAtLocation):
* UIProcess/WebPageProxy.h:

At willOpenMenu time, text menus should select text so that it is clear what the 
menu actions will apply to.
* UIProcess/mac/WKActionMenuController.h:
* UIProcess/mac/WKActionMenuController.mm:

Menu items for text menus.
(-[WKActionMenuController willOpenMenu:withEvent:]):
(-[WKActionMenuController _defaultMenuItemsForText]):
(-[WKActionMenuController _copyText:]):
(-[WKActionMenuController _lookupText:]):
(-[WKActionMenuController _createActionMenuItemForTag:]):
(imageForResource:name::if):

New messages to the web process.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Re-factor performDictionaryLookupAtLocation() to re-use the code that finds the 
Range for the dictionary lookup. That code now lives in 
rangeForDictionaryLookupAtHitTestResult() and can be used by 
performDictionaryLookupAtLocation() and our new function 
selectLookupTextAtLocation().
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::rangeForDictionaryLookupAtHitTestResult):
(WebKit::WebPage::performDictionaryLookupAtLocation):

Since the action menu text is always selected, when the lookup action is chosen, 
we can just lookup the current selection.
(WebKit::WebPage::performDictionaryLookupOfCurrentSelection):

Uses the new function rangeForDictionaryLookupAtHitTestResult() to get a lookup 
range and then select it.
(WebKit::WebPage::selectLookupTextAtLocation):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedAPIcWKActionMenuItemTypesh">trunk/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h</a></li>
<li><a href="#trunkSourceWebKit2SharedAPIcWKActionMenuTypesh">trunk/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPImacWKViewmm">trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWKActionMenuControllerh">trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWKActionMenuControllermm">trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebPageProxyMacmm">trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagemessagesin">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagemacWebPageMacmm">trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/ChangeLog        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -1,3 +1,63 @@
</span><ins>+2014-10-30  Beth Dakin  &lt;bdakin@apple.com&gt;
+
+        Implement action menus for text
+        https://bugs.webkit.org/show_bug.cgi?id=138220
+        -and corresponding-
+        rdar://problem/18742297
+
+        Reviewed by Tim Horton.
+
+        Two new types of actions for the two text actions.
+        * Shared/API/c/WKActionMenuItemTypes.h:
+
+        One new type of menu.
+        * Shared/API/c/WKActionMenuTypes.h:
+
+        Pass willOpenMenu on to the WKActionMenuController.
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView willOpenMenu:withEvent:]):
+
+        Two new WebPageProxy functions that will pass messages along to the web process.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::selectLookupTextAtLocation):
+        * UIProcess/WebPageProxy.h:
+
+        At willOpenMenu time, text menus should select text so that it is clear what the 
+        menu actions will apply to.
+        * UIProcess/mac/WKActionMenuController.h:
+        * UIProcess/mac/WKActionMenuController.mm:
+
+        Menu items for text menus.
+        (-[WKActionMenuController willOpenMenu:withEvent:]):
+        (-[WKActionMenuController _defaultMenuItemsForText]):
+        (-[WKActionMenuController _copyText:]):
+        (-[WKActionMenuController _lookupText:]):
+        (-[WKActionMenuController _createActionMenuItemForTag:]):
+        (imageForResource:name::if):
+
+        New messages to the web process.
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::performDictionaryLookupOfCurrentSelection):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
+        Re-factor performDictionaryLookupAtLocation() to re-use the code that finds the 
+        Range for the dictionary lookup. That code now lives in 
+        rangeForDictionaryLookupAtHitTestResult() and can be used by 
+        performDictionaryLookupAtLocation() and our new function 
+        selectLookupTextAtLocation().
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::rangeForDictionaryLookupAtHitTestResult):
+        (WebKit::WebPage::performDictionaryLookupAtLocation):
+
+        Since the action menu text is always selected, when the lookup action is chosen, 
+        we can just lookup the current selection.
+        (WebKit::WebPage::performDictionaryLookupOfCurrentSelection):
+
+        Uses the new function rangeForDictionaryLookupAtHitTestResult() to get a lookup 
+        range and then select it.
+        (WebKit::WebPage::selectLookupTextAtLocation):
+
</ins><span class="cx"> 2014-10-30  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         When a client certificate is rejected, Safari says the website didn’t accept the certificate “unknown” instead of naming the certificate
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPIcWKActionMenuItemTypesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -40,7 +40,9 @@
</span><span class="cx">     kWKContextActionItemTagCopyImage,
</span><span class="cx">     kWKContextActionItemTagAddImageToPhotos,
</span><span class="cx">     kWKContextActionItemTagSaveImageToDownloads,
</span><del>-    kWKContextActionItemTagShareImage
</del><ins>+    kWKContextActionItemTagShareImage,
+    kWKContextActionItemTagCopyText,
+    kWKContextActionItemTagLookupText
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> #ifdef __cplusplus
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPIcWKActionMenuTypesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -36,7 +36,8 @@
</span><span class="cx">     kWKActionMenuNone = 0,
</span><span class="cx">     kWKActionMenuLink,
</span><span class="cx">     kWKActionMenuImage,
</span><del>-    kWKActionMenuDataDetectedItem
</del><ins>+    kWKActionMenuDataDetectedItem,
+    kWKActionMenuReadOnlyText
</ins><span class="cx"> };
</span><span class="cx"> typedef uint32_t _WKActionMenuType;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPImacWKViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -3643,6 +3643,11 @@
</span><span class="cx">     [_data-&gt;_actionMenuController prepareForMenu:menu withEvent:event];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event
+{
+    [_data-&gt;_actionMenuController willOpenMenu:menu withEvent:event];
+}
+
</ins><span class="cx"> - (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event
</span><span class="cx"> {
</span><span class="cx">     [_data-&gt;_actionMenuController didCloseMenu:menu withEvent:event];
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -5274,6 +5274,11 @@
</span><span class="cx">     m_process-&gt;send(Messages::WebPage::PerformActionMenuHitTestAtLocation(point), m_pageID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::selectLookupTextAtLocation(FloatPoint point)
+{
+    m_process-&gt;send(Messages::WebPage::SelectLookupTextAtLocation(point), m_pageID);
+}
+
</ins><span class="cx"> void WebPageProxy::didPerformActionMenuHitTest(const ActionMenuHitTestResult&amp; result)
</span><span class="cx"> {
</span><span class="cx">     m_pageClient.didPerformActionMenuHitTest(result);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -690,6 +690,7 @@
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     // Dictionary.
</span><span class="cx">     void performDictionaryLookupAtLocation(const WebCore::FloatPoint&amp;);
</span><ins>+    void performDictionaryLookupOfCurrentSelection();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void receivedPolicyDecision(WebCore::PolicyAction, WebFrameProxy*, uint64_t listenerID, uint64_t navigationID);
</span><span class="lines">@@ -925,6 +926,7 @@
</span><span class="cx"> 
</span><span class="cx">     WebHitTestResult* lastMouseMoveHitTestResult() const { return m_lastMouseMoveHitTestResult.get(); }
</span><span class="cx">     void performActionMenuHitTestAtLocation(WebCore::FloatPoint);
</span><ins>+    void selectLookupTextAtLocation(WebCore::FloatPoint);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(EFL) &amp;&amp; HAVE(ACCESSIBILITY) &amp;&amp; defined(HAVE_ECORE_X)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWKActionMenuControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.h (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.h        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.h        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx"> - (void)willDestroyView:(WKView *)view;
</span><span class="cx"> 
</span><span class="cx"> - (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
</span><ins>+- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
</ins><span class="cx"> - (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event;
</span><span class="cx"> 
</span><span class="cx"> - (void)didPerformActionMenuHitTest:(const WebKit::ActionMenuHitTestResult&amp;)hitTestResult;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWKActionMenuControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -104,6 +104,21 @@
</span><span class="cx">     [self _updateActionMenuItems];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event
+{
+    if (menu != _wkView.actionMenu)
+        return;
+
+    if (_type != kWKActionMenuReadOnlyText)
+        return;
+
+    // Action menus for text should highlight the text so that it is clear what the action menu actions
+    // will apply to. If the text is already selected, the menu will use the existing selection.
+    WebHitTestResult* hitTestResult = _page-&gt;lastMouseMoveHitTestResult();
+    if (!hitTestResult-&gt;isSelected())
+        _page-&gt;selectLookupTextAtLocation([_wkView convertPoint:event.locationInWindow fromView:nil]);
+}
+
</ins><span class="cx"> - (void)didCloseMenu:(NSMenu *)menu withEvent:(NSEvent *)event
</span><span class="cx"> {
</span><span class="cx">     if (menu != _wkView.actionMenu)
</span><span class="lines">@@ -290,6 +305,26 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#pragma mark Text actions
+
+- (NSArray *)_defaultMenuItemsForText
+{
+    RetainPtr&lt;NSMenuItem&gt; copyTextItem = [self _createActionMenuItemForTag:kWKContextActionItemTagCopyText];
+    RetainPtr&lt;NSMenuItem&gt; lookupTextItem = [self _createActionMenuItemForTag:kWKContextActionItemTagLookupText];
+
+    return @[ copyTextItem.get(), lookupTextItem.get() ];
+}
+
+-(void)_copyText:(id)sender
+{
+    _page-&gt;executeEditCommand(&quot;copy&quot;);
+}
+
+-(void)_lookupText:(id)sender
+{
+    _page-&gt;performDictionaryLookupOfCurrentSelection();
+}
+
</ins><span class="cx"> #pragma mark NSMenuDelegate implementation
</span><span class="cx"> 
</span><span class="cx"> - (void)menuNeedsUpdate:(NSMenu *)menu
</span><span class="lines">@@ -374,6 +409,18 @@
</span><span class="cx">         image = webKitBundleImageNamed(@&quot;ShareImageTemplate&quot;);
</span><span class="cx">         break;
</span><span class="cx"> 
</span><ins>+    case kWKContextActionItemTagCopyText:
+        selector = @selector(_copyText:);
+        title = @&quot;Copy&quot;;
+        image = [NSImage imageNamed:@&quot;NSActionMenuCopy&quot;];
+        break;
+
+    case kWKContextActionItemTagLookupText:
+        selector = @selector(_lookupText:);
+        title = @&quot;Lookup&quot;;
+        image = [NSImage imageNamed:@&quot;NSActionMenuLookup&quot;];
+        break;
+
</ins><span class="cx">     default:
</span><span class="cx">         ASSERT_NOT_REACHED();
</span><span class="cx">         return nil;
</span><span class="lines">@@ -414,6 +461,8 @@
</span><span class="cx">                     return dataDetectorMenuItems;
</span><span class="cx">                 }
</span><span class="cx">             }
</span><ins>+            _type = kWKActionMenuReadOnlyText;
+            return [self _defaultMenuItemsForText];
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebPageProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -408,6 +408,14 @@
</span><span class="cx">     process().send(Messages::WebPage::PerformDictionaryLookupAtLocation(point), m_pageID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::performDictionaryLookupOfCurrentSelection()
+{
+    if (!isValid())
+        return;
+
+    process().send(Messages::WebPage::PerformDictionaryLookupOfCurrentSelection(), m_pageID);
+}
+
</ins><span class="cx"> // Complex text input support for plug-ins.
</span><span class="cx"> void WebPageProxy::sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String&amp; textInput)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -973,6 +973,8 @@
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     void performDictionaryLookupAtLocation(const WebCore::FloatPoint&amp;);
</span><span class="cx">     void performDictionaryLookupForRange(WebCore::Frame*, WebCore::Range&amp;, NSDictionary *options);
</span><ins>+    PassRefPtr&lt;WebCore::Range&gt; rangeForDictionaryLookupAtHitTestResult(const WebCore::HitTestResult&amp;, NSDictionary **);
+    void performDictionaryLookupOfCurrentSelection();
</ins><span class="cx"> 
</span><span class="cx">     void windowAndViewFramesChanged(const WebCore::FloatRect&amp; windowFrameInScreenCoordinates, const WebCore::FloatRect&amp; windowFrameInUnflippedScreenCoordinates, const WebCore::FloatRect&amp; viewFrameInWindowCoordinates, const WebCore::FloatPoint&amp; accessibilityViewCoordinates);
</span><span class="cx"> 
</span><span class="lines">@@ -1047,6 +1049,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     void performActionMenuHitTestAtLocation(WebCore::FloatPoint);
</span><ins>+    void selectLookupTextAtLocation(WebCore::FloatPoint);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     uint64_t m_pageID;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -158,6 +158,7 @@
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     # Dictionary support.
</span><span class="cx">     PerformDictionaryLookupAtLocation(WebCore::FloatPoint point)
</span><ins>+    PerformDictionaryLookupOfCurrentSelection()
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     PreferencesDidChange(WebKit::WebPreferencesStore store)
</span><span class="lines">@@ -390,5 +391,6 @@
</span><span class="cx">     TakeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, uint64_t callbackID)
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     PerformActionMenuHitTestAtLocation(WebCore::FloatPoint location)
</span><ins>+    SelectLookupTextAtLocation(WebCore::FloatPoint location)
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagemacWebPageMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (175375 => 175376)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2014-10-30 19:04:29 UTC (rev 175375)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2014-10-30 19:38:27 UTC (rev 175376)
</span><span class="lines">@@ -529,50 +529,63 @@
</span><span class="cx">     return makeRange(contextStart, contextEnd);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPage::performDictionaryLookupAtLocation(const FloatPoint&amp; floatPoint)
</del><ins>+PassRefPtr&lt;Range&gt; WebPage::rangeForDictionaryLookupAtHitTestResult(const WebCore::HitTestResult&amp; hitTestResult, NSDictionary **options)
</ins><span class="cx"> {
</span><del>-    if (PluginView* pluginView = pluginViewForFrame(&amp;m_page-&gt;mainFrame())) {
-        if (pluginView-&gt;performDictionaryLookupAtLocation(floatPoint))
-            return;
-    }
</del><ins>+    Node* node = hitTestResult.innerNonSharedNode();
+    if (!node)
+        return nullptr;
</ins><span class="cx"> 
</span><del>-    // Find the frame the point is over.
-    IntPoint point = roundedIntPoint(floatPoint);
-    HitTestResult result = m_page-&gt;mainFrame().eventHandler().hitTestResultAtPoint(m_page-&gt;mainFrame().view()-&gt;windowToContents(point));
-    Frame* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()-&gt;document().frame() : &amp;m_page-&gt;focusController().focusedOrMainFrame();
</del><ins>+    auto renderer = node-&gt;renderer();
+    if (!renderer)
+        return nullptr;
</ins><span class="cx"> 
</span><del>-    IntPoint translatedPoint = frame-&gt;view()-&gt;windowToContents(point);
</del><ins>+    Frame* frame = node-&gt;document().frame();
+    if (!frame)
+        return nullptr;
</ins><span class="cx"> 
</span><span class="cx">     // Don't do anything if there is no character at the point.
</span><del>-    if (!frame-&gt;rangeForPoint(translatedPoint))
-        return;
</del><ins>+    if (!frame-&gt;rangeForPoint(hitTestResult.roundedPointInInnerNodeFrame()))
+        return nullptr;
</ins><span class="cx"> 
</span><del>-    VisiblePosition position = frame-&gt;visiblePositionForPoint(translatedPoint);
</del><ins>+    VisiblePosition position = renderer-&gt;positionForPoint(hitTestResult.localPoint(), nullptr);
+    if (position.isNull())
+        position = firstPositionInOrBeforeNode(node);
+
</ins><span class="cx">     VisibleSelection selection = m_page-&gt;focusController().focusedOrMainFrame().selection().selection();
</span><span class="cx">     if (shouldUseSelection(position, selection)) {
</span><span class="cx">         performDictionaryLookupForSelection(frame, selection);
</span><del>-        return;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    NSDictionary *options = nil;
-
</del><span class="cx">     // As context, we are going to use four lines of text before and after the point. (Dictionary can sometimes look up things that are four lines long)
</span><span class="cx">     RefPtr&lt;Range&gt; fullCharacterRange = rangeExpandedAroundPosition(position, 4);
</span><span class="cx">     NSRange rangeToPass = NSMakeRange(TextIterator::rangeLength(makeRange(fullCharacterRange-&gt;startPosition(), position).get()), 0);
</span><span class="cx"> 
</span><span class="cx">     String fullPlainTextString = plainText(fullCharacterRange.get());
</span><span class="cx"> 
</span><del>-    NSRange extractedRange = WKExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, &amp;options);
</del><ins>+    NSRange extractedRange = WKExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, options);
</ins><span class="cx"> 
</span><span class="cx">     // This function sometimes returns {NSNotFound, 0} if it was unable to determine a good string.
</span><span class="cx">     if (extractedRange.location == NSNotFound)
</span><del>-        return;
</del><ins>+        return nullptr;
</ins><span class="cx"> 
</span><del>-    RefPtr&lt;Range&gt; finalRange = TextIterator::subrange(fullCharacterRange.get(), extractedRange.location, extractedRange.length);
-    if (!finalRange)
-        return;
</del><ins>+    return TextIterator::subrange(fullCharacterRange.get(), extractedRange.location, extractedRange.length);
+}
</ins><span class="cx"> 
</span><del>-    performDictionaryLookupForRange(frame, *finalRange, options);
</del><ins>+void WebPage::performDictionaryLookupAtLocation(const FloatPoint&amp; floatPoint)
+{
+    if (PluginView* pluginView = pluginViewForFrame(&amp;m_page-&gt;mainFrame())) {
+        if (pluginView-&gt;performDictionaryLookupAtLocation(floatPoint))
+            return;
+    }
+
+    // Find the frame the point is over.
+    IntPoint point = roundedIntPoint(floatPoint);
+    HitTestResult result = m_page-&gt;mainFrame().eventHandler().hitTestResultAtPoint(m_page-&gt;mainFrame().view()-&gt;windowToContents(point));
+    Frame* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()-&gt;document().frame() : &amp;m_page-&gt;focusController().focusedOrMainFrame();
+    NSDictionary *options = nil;
+    RefPtr&lt;Range&gt; range = rangeForDictionaryLookupAtHitTestResult(result, &amp;options);
+    performDictionaryLookupForRange(frame, *range, options);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPage::performDictionaryLookupForSelection(Frame* frame, const VisibleSelection&amp; selection)
</span><span class="lines">@@ -602,6 +615,12 @@
</span><span class="cx">     performDictionaryLookupForRange(frame, *selectedRange, options);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::performDictionaryLookupOfCurrentSelection()
+{
+    Frame* frame = &amp;m_page-&gt;focusController().focusedOrMainFrame();
+    performDictionaryLookupForSelection(frame, frame-&gt;selection().selection());
+}
+
</ins><span class="cx"> void WebPage::performDictionaryLookupForRange(Frame* frame, Range&amp; range, NSDictionary *options)
</span><span class="cx"> {
</span><span class="cx">     if (range.text().stripWhiteSpace().isEmpty())
</span><span class="lines">@@ -1151,6 +1170,21 @@
</span><span class="cx">     send(Messages::WebPageProxy::DidPerformActionMenuHitTest(actionMenuResult));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::selectLookupTextAtLocation(FloatPoint locationInWindowCooordinates)
+{
+    MainFrame&amp; mainFrame = corePage()-&gt;mainFrame();
+    if (!mainFrame.view() || !mainFrame.view()-&gt;renderView())
+        return;
+
+    IntPoint point = roundedIntPoint(locationInWindowCooordinates);
+    HitTestResult result = m_page-&gt;mainFrame().eventHandler().hitTestResultAtPoint(m_page-&gt;mainFrame().view()-&gt;windowToContents(point));
+    Frame* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()-&gt;document().frame() : &amp;m_page-&gt;focusController().focusedOrMainFrame();
+    NSDictionary *options = nil;
+    RefPtr&lt;Range&gt; lookupRange = rangeForDictionaryLookupAtHitTestResult(result, &amp;options);
+    if (lookupRange)
+        frame-&gt;selection().setSelectedRange(lookupRange.get(), DOWNSTREAM, true);
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(MAC)
</span></span></pre>
</div>
</div>

</body>
</html>