<!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>[183136] trunk</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/183136">183136</a></dd>
<dt>Author</dt> <dd>bfulgham@apple.com</dd>
<dt>Date</dt> <dd>2015-04-22 14:23:54 -0700 (Wed, 22 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Source/WebCore:
[Mac] Extend action menus to support PDF
https://bugs.webkit.org/show_bug.cgi?id=143895
&lt;rdar://problem/19003333&gt;

Reviewed by Tim Horton.

Tested by TestWebKitAPI ActionMenus.mm.

Add a new dictionary lookup method to support PDF Selections. This code replicates the
DOM Range-based logic used for HTML documents, but does so using the PDFKit API and
its support types.

* Configurations/Base.xcconfig: Add PDFKit include path for build.
* editing/mac/DictionaryLookup.h:
* editing/mac/DictionaryLookup.mm:
(WebCore::expandSelectionByCharacters): Helper function for PDF support.
(WebCore::dictionaryLookupForPDFSelection): Added.

Source/WebKit/mac:
Extend action menus to support PDF
https://bugs.webkit.org/show_bug.cgi?id=143895
&lt;rdar://problem/19003333&gt;

Reviewed by Tim Horton.

Prevent a crash when someone attempts to invoke an action menu on a PDF hosted
in a WK1 view.

* WebView/WebActionMenuController.mm:
(-[WebActionMenuController performHitTestAtPoint:]): Handle WebPDFView as well as
the WebHTMLView case.
* WebView/WebDocument.h:
* WebView/WebHTMLView.h:
* WebView/WebHTMLView.mm:
(-[WebHTMLView _frame]):
* WebView/WebHTMLViewInternal.h:
* WebView/WebPDFView.h:
* WebView/WebPDFView.mm:
(-[WebPDFView _frame]): Added.

Source/WebKit2:
Extend action menus to support PDF
https://bugs.webkit.org/show_bug.cgi?id=143895
&lt;rdar://problem/19003333&gt;

Reviewed by Tim Horton.

If the mouse pointer is over a PDF, try to provide a relevant action menu for whatever
content is under the mouse. For now, we only support copying text and handling URLs.

If no text is selected, use the dictionary lookup service to find a semantically appropriate
selection underneath the mouse. This is consistent with how normal text is treated in pure HTML
views. If some text is already selected, and the mouse is over the existing selection, continue
using the selected text. Otherwise, discard the old selection and select the most appropriate
region under the mouse pointer.

* Shared/API/c/WKActionMenuTypes.h: Add PDF menu option.
* Shared/WebMouseEvent.cpp: Recognize mouse force events as valid mouse events.
* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController _defaultMenuItemsForPDF]): Add simply copy text option.
(-[WKActionMenuController _defaultMenuItems]): Recognize PDFs and add relevant action
menu entries.
* WebProcess/Plugins/Netscape/NetscapePlugin.h: Provide stub for new method.
* WebProcess/Plugins/PDF/PDFLayerControllerDetails.h: Expose 'rectsForSelectionInLayerSpace',
'rectsForAnnotationInLayoutSpace', 'layout', and 'currentPage'.
* WebProcess/Plugins/PDF/PDFPlugin.h:
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::getSelectionForWordAtPoint): Added.
(WebKit::PDFPlugin::existingSelectionContainsPoint): Added.
(WebKit::PDFPlugin::lookupTextAtLocation): Added.
* WebProcess/Plugins/Plugin.h: Add declaration for new 'getSelectionForWordAtPoint' method.
* WebProcess/Plugins/PluginProxy.h: Provide stub for new method.
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::getSelectionForWordAtPoint): Added.
(WebKit::PluginView::existingSelectionContainsPoint): Added.
(WebKit::PluginView::lookupTextAtLocation): Added.
* WebProcess/Plugins/PluginView.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performActionMenuHitTestAtLocation): Update to support PDF documents and retrieve
relevant content to support later action menu handling.

Tools:
[Mac] Extend action menus to support PDF
https://bugs.webkit.org/show_bug.cgi?id=143895
&lt;rdar://problem/19003333&gt;

Reviewed by Tim Horton.

Reactivate the action menu tests, and add a new PDF-based test to make sure that selection
of PDF content works.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add new 'test.pdf' resource to bundle.
* TestWebKitAPI/Tests/WebKit2/action-menu-targets.html: Update with a new PDF pane.
* TestWebKitAPI/Tests/WebKit2/test.pdf: Added.
* TestWebKitAPI/Tests/WebKit2ObjC/ActionMenus.mm:
(-[ActionMenusTestWKView _actionMenuItemsForHitTestResult:withType:defaultActionMenuItems:userData:]):
Update to support PDF tests.
(TestWebKitAPI::windowPointForTarget): Add new target for PDF test.
(TestWebKitAPI::waitForPDFToLoad): New helper function to avoid starting test before the PDF is available.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreConfigurationsWebCorexcconfig">trunk/Source/WebCore/Configurations/WebCore.xcconfig</a></li>
<li><a href="#trunkSourceWebCoreeditingmacDictionaryLookuph">trunk/Source/WebCore/editing/mac/DictionaryLookup.h</a></li>
<li><a href="#trunkSourceWebCoreeditingmacDictionaryLookupmm">trunk/Source/WebCore/editing/mac/DictionaryLookup.mm</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebActionMenuControllermm">trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedWebHitTestResulth">trunk/Source/WebKit2/Shared/WebHitTestResult.h</a></li>
<li><a href="#trunkSourceWebKit2SharedWebMouseEventcpp">trunk/Source/WebKit2/Shared/WebMouseEvent.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKHitTestResultcpp">trunk/Source/WebKit2/UIProcess/API/C/WKHitTestResult.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKHitTestResulth">trunk/Source/WebKit2/UIProcess/API/C/WKHitTestResult.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsNetscapeNetscapePluginh">trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPDFPDFLayerControllerDetailsh">trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFLayerControllerDetails.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPDFPDFPluginh">trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPDFPDFPluginmm">trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPluginh">trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPluginProxyh">trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPluginViewcpp">trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPluginViewh">trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagemacWebPageMacmm">trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2actionmenutargetshtml">trunk/Tools/TestWebKitAPI/Tests/WebKit2/action-menu-targets.html</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2ObjCActionMenusmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/ActionMenus.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2actionmenutargetpdf">trunk/Tools/TestWebKitAPI/Tests/WebKit2/action-menu-target.pdf</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2testpdf">trunk/Tools/TestWebKitAPI/Tests/WebKit2/test.pdf</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebCore/ChangeLog        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2015-04-21  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        [Mac] Extend action menus to support PDF
+        https://bugs.webkit.org/show_bug.cgi?id=143895
+        &lt;rdar://problem/19003333&gt;
+
+        Reviewed by Tim Horton.
+
+        Tested by TestWebKitAPI ActionMenus.mm.
+
+        Add a new dictionary lookup method to support PDF Selections. This code replicates the
+        DOM Range-based logic used for HTML documents, but does so using the PDFKit API and
+        its support types.
+
+        * Configurations/Base.xcconfig: Add PDFKit include path for build.
+        * editing/mac/DictionaryLookup.h:
+        * editing/mac/DictionaryLookup.mm:
+        (WebCore::expandSelectionByCharacters): Helper function for PDF support.
+        (WebCore::dictionaryLookupForPDFSelection): Added.
+
</ins><span class="cx"> 2015-04-22  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Move render ruby initialization logic from RenderElement::createFor() to *::createElementRenderer()
</span></span></pre></div>
<a id="trunkSourceWebCoreConfigurationsWebCorexcconfig"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Configurations/WebCore.xcconfig (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Configurations/WebCore.xcconfig        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebCore/Configurations/WebCore.xcconfig        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -32,7 +32,7 @@
</span><span class="cx"> FRAMEWORK_SEARCH_PATHS_ios_Production = $(PRODUCTION_FRAMEWORKS_DIR);
</span><span class="cx"> FRAMEWORK_SEARCH_PATHS[sdk=macosx*] = $(STAGED_FRAMEWORKS_SEARCH_PATH) $(FRAMEWORK_SEARCH_PATHS);
</span><span class="cx"> 
</span><del>-OTHER_CFLAGS = $(inherited) -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/CoreServices.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks;
</del><ins>+OTHER_CFLAGS = $(inherited) -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/CoreServices.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/Frameworks/Quartz.framework/Frameworks -iframework $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks;
</ins><span class="cx"> OTHER_CPLUSPLUSFLAGS = $(OTHER_CFLAGS);
</span><span class="cx"> 
</span><span class="cx"> STAGED_FRAMEWORKS_SEARCH_PATH = $(STAGED_FRAMEWORKS_SEARCH_PATH_$(USE_STAGING_INSTALL_PATH));
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingmacDictionaryLookuph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.h (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/mac/DictionaryLookup.h        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.h        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &lt;wtf/PassRefPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> OBJC_CLASS NSDictionary;
</span><ins>+OBJC_CLASS PDFSelection;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -47,6 +48,7 @@
</span><span class="cx"> PassRefPtr&lt;Range&gt; rangeExpandedAroundPositionByCharacters(const VisiblePosition&amp;, int numberOfCharactersToExpand);
</span><span class="cx"> WEBCORE_EXPORT PassRefPtr&lt;Range&gt; rangeForDictionaryLookupForSelection(const VisibleSelection&amp;, NSDictionary **options);
</span><span class="cx"> WEBCORE_EXPORT PassRefPtr&lt;Range&gt; rangeForDictionaryLookupAtHitTestResult(const HitTestResult&amp;, NSDictionary **options);
</span><ins>+WEBCORE_EXPORT NSString *dictionaryLookupForPDFSelection(PDFSelection *, NSDictionary **options);
</ins><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingmacDictionaryLookupmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.mm (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/mac/DictionaryLookup.mm        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.mm        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> #import &quot;VisibleUnits.h&quot;
</span><span class="cx"> #import &quot;WebCoreSystemInterface.h&quot;
</span><span class="cx"> #import &quot;htmlediting.h&quot;
</span><ins>+#import &lt;PDFKit/PDFKit.h&gt;
</ins><span class="cx"> #import &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -162,6 +163,54 @@
</span><span class="cx">     return TextIterator::subrange(fullCharacterRange.get(), extractedRange.location, extractedRange.length);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void expandSelectionByCharacters(PDFSelection *selection, NSInteger numberOfCharactersToExpand, NSInteger&amp; charactersAddedBeforeStart, NSInteger&amp; charactersAddedAfterEnd)
+{
+    size_t originalLength = selection.string.length;
+    [selection extendSelectionAtStart:numberOfCharactersToExpand];
+    
+    charactersAddedBeforeStart = selection.string.length - originalLength;
+    
+    [selection extendSelectionAtEnd:numberOfCharactersToExpand];
+    charactersAddedAfterEnd = selection.string.length - originalLength - charactersAddedBeforeStart;
+}
+
+NSString *dictionaryLookupForPDFSelection(PDFSelection *selection, NSDictionary **options)
+{
+    // Don't do anything if there is no character at the point.
+    if (!selection || !selection.string.length)
+        return @&quot;&quot;;
+    
+    RetainPtr&lt;PDFSelection&gt; selectionForLookup = adoptNS([selection copy]);
+    
+    // As context, we are going to use 250 characters of text before and after the point.
+    NSInteger originalLength = [selectionForLookup string].length;
+    NSInteger charactersAddedBeforeStart = 0;
+    NSInteger charactersAddedAfterEnd = 0;
+    expandSelectionByCharacters(selectionForLookup.get(), 250, charactersAddedBeforeStart, charactersAddedAfterEnd);
+    
+    NSString *fullPlainTextString = [selectionForLookup string];
+    NSRange rangeToPass = NSMakeRange(charactersAddedBeforeStart, 0);
+    
+    NSRange extractedRange = NSMakeRange(rangeToPass.location, 0);
+    if (Class luLookupDefinitionModule = getLULookupDefinitionModuleClass())
+        extractedRange = [luLookupDefinitionModule tokenRangeForString:fullPlainTextString range:rangeToPass options:options];
+    
+    // This function sometimes returns {NSNotFound, 0} if it was unable to determine a good string.
+    if (extractedRange.location == NSNotFound)
+        return selection.string;
+    
+    NSInteger lookupAddedBefore = (extractedRange.location &lt; rangeToPass.location) ? rangeToPass.location - extractedRange.location : 0;
+    NSInteger lookupAddedAfter = 0;
+    if ((extractedRange.location + extractedRange.length) &gt; (rangeToPass.location + originalLength))
+        lookupAddedAfter = (extractedRange.location + extractedRange.length) - (rangeToPass.location + originalLength);
+    
+    [selection extendSelectionAtStart:lookupAddedBefore];
+    [selection extendSelectionAtEnd:lookupAddedAfter];
+    
+    ASSERT([selection.string isEqualToString:[fullPlainTextString substringWithRange:extractedRange]]);
+    return selection.string;
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit/mac/ChangeLog        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2015-04-21  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        Extend action menus to support PDF
+        https://bugs.webkit.org/show_bug.cgi?id=143895
+        &lt;rdar://problem/19003333&gt;
+
+        Reviewed by Tim Horton.
+
+        Prevent a crash when someone attempts to invoke an action menu on a PDF hosted
+        in a WK1 view.
+
+        * WebView/WebActionMenuController.mm:
+        (-[WebActionMenuController performHitTestAtPoint:]): Handle WebPDFView as well as
+        the WebHTMLView case.
+        * WebView/WebDocument.h:
+        * WebView/WebHTMLView.h:
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView _frame]):
+        * WebView/WebHTMLViewInternal.h:
+        * WebView/WebPDFView.h:
+        * WebView/WebPDFView.mm:
+        (-[WebPDFView _frame]): Added.
+
</ins><span class="cx"> 2015-04-22  Eric Carlson  &lt;eric.carlson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed post-review clean up after r183096.
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebActionMenuControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -30,11 +30,13 @@
</span><span class="cx"> #import &quot;DOMElementInternal.h&quot;
</span><span class="cx"> #import &quot;DOMNodeInternal.h&quot;
</span><span class="cx"> #import &quot;DOMRangeInternal.h&quot;
</span><ins>+#import &quot;WebDataSource.h&quot;
</ins><span class="cx"> #import &quot;WebDocumentInternal.h&quot;
</span><span class="cx"> #import &quot;WebElementDictionary.h&quot;
</span><span class="cx"> #import &quot;WebFrameInternal.h&quot;
</span><span class="cx"> #import &quot;WebHTMLView.h&quot;
</span><span class="cx"> #import &quot;WebHTMLViewInternal.h&quot;
</span><ins>+#import &quot;WebPDFView.h&quot;
</ins><span class="cx"> #import &quot;WebSystemInterface.h&quot;
</span><span class="cx"> #import &quot;WebUIDelegatePrivate.h&quot;
</span><span class="cx"> #import &quot;WebViewInternal.h&quot;
</span><span class="lines">@@ -94,12 +96,15 @@
</span><span class="cx"> 
</span><span class="cx"> - (WebElementDictionary *)performHitTestAtPoint:(NSPoint)windowPoint
</span><span class="cx"> {
</span><del>-    WebHTMLView *documentView = [[[_webView _selectedOrMainFrame] frameView] documentView];
-    NSPoint point = [documentView convertPoint:windowPoint fromView:nil];
-
-    Frame* coreFrame = core([documentView _frame]);
</del><ins>+    NSView&lt;WebDocumentView&gt; *documentView = [[[_webView _selectedOrMainFrame] frameView] documentView];
+    if (![documentView isKindOfClass:[WebHTMLView class]])
+        return nil;
+        
+    Frame* coreFrame = core([(WebHTMLView *)documentView _frame]);
</ins><span class="cx">     if (!coreFrame)
</span><span class="cx">         return nil;
</span><ins>+
+    NSPoint point = [documentView convertPoint:windowPoint fromView:nil];
</ins><span class="cx">     _hitTestResult = coreFrame-&gt;eventHandler().hitTestResultAtPoint(IntPoint(point));
</span><span class="cx"> 
</span><span class="cx">     return [[[WebElementDictionary alloc] initWithHitTestResult:_hitTestResult] autorelease];
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/ChangeLog        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,3 +1,45 @@
</span><ins>+2015-04-21  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        Extend action menus to support PDF
+        https://bugs.webkit.org/show_bug.cgi?id=143895
+        &lt;rdar://problem/19003333&gt;
+
+        Reviewed by Tim Horton.
+
+        If the mouse pointer is over a PDF, try to provide a relevant action menu for whatever
+        content is under the mouse. For now, we only support copying text and handling URLs.
+
+        If no text is selected, use the dictionary lookup service to find a semantically appropriate
+        selection underneath the mouse. This is consistent with how normal text is treated in pure HTML
+        views. If some text is already selected, and the mouse is over the existing selection, continue
+        using the selected text. Otherwise, discard the old selection and select the most appropriate
+        region under the mouse pointer.
+
+        * Shared/API/c/WKActionMenuTypes.h: Add PDF menu option.
+        * Shared/WebMouseEvent.cpp: Recognize mouse force events as valid mouse events.
+        * UIProcess/mac/WKActionMenuController.mm:
+        (-[WKActionMenuController _defaultMenuItemsForPDF]): Add simply copy text option.
+        (-[WKActionMenuController _defaultMenuItems]): Recognize PDFs and add relevant action
+        menu entries.
+        * WebProcess/Plugins/Netscape/NetscapePlugin.h: Provide stub for new method.
+        * WebProcess/Plugins/PDF/PDFLayerControllerDetails.h: Expose 'rectsForSelectionInLayerSpace',
+        'rectsForAnnotationInLayoutSpace', 'layout', and 'currentPage'.
+        * WebProcess/Plugins/PDF/PDFPlugin.h:
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::getSelectionForWordAtPoint): Added.
+        (WebKit::PDFPlugin::existingSelectionContainsPoint): Added.
+        (WebKit::PDFPlugin::lookupTextAtLocation): Added.
+        * WebProcess/Plugins/Plugin.h: Add declaration for new 'getSelectionForWordAtPoint' method.
+        * WebProcess/Plugins/PluginProxy.h: Provide stub for new method.
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::getSelectionForWordAtPoint): Added.
+        (WebKit::PluginView::existingSelectionContainsPoint): Added.
+        (WebKit::PluginView::lookupTextAtLocation): Added.
+        * WebProcess/Plugins/PluginView.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performActionMenuHitTestAtLocation): Update to support PDF documents and retrieve
+        relevant content to support later action menu handling.
+
</ins><span class="cx"> 2015-04-22  Eric Carlson  &lt;eric.carlson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Update AirPlay sandbox rules
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedWebHitTestResulth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/WebHitTestResult.h (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/WebHitTestResult.h        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/Shared/WebHitTestResult.h        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -104,6 +104,7 @@
</span><span class="cx"> 
</span><span class="cx">     String linkLabel() const { return m_data.linkLabel; }
</span><span class="cx">     String linkTitle() const { return m_data.linkTitle; }
</span><ins>+    String lookupText() const { return m_data.lookupText; }
</ins><span class="cx"> 
</span><span class="cx">     bool isContentEditable() const { return m_data.isContentEditable; }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedWebMouseEventcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/WebMouseEvent.cpp (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/WebMouseEvent.cpp        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/Shared/WebMouseEvent.cpp        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -120,7 +120,7 @@
</span><span class="cx"> 
</span><span class="cx"> bool WebMouseEvent::isMouseEventType(Type type)
</span><span class="cx"> {
</span><del>-    return type == MouseDown || type == MouseUp || type == MouseMove;
</del><ins>+    return type == MouseDown || type == MouseUp || type == MouseMove || type == MouseForceUp || type == MouseForceDown || type == MouseForceChanged;
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKHitTestResultcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKHitTestResult.cpp (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKHitTestResult.cpp        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKHitTestResult.cpp        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -67,6 +67,11 @@
</span><span class="cx">     return toCopiedAPI(toImpl(hitTestResultRef)-&gt;linkTitle());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+WKStringRef WKHitTestResultCopyLookupText(WKHitTestResultRef hitTestResult)
+{
+    return toCopiedAPI(toImpl(hitTestResult)-&gt;lookupText());
+}
+
</ins><span class="cx"> bool WKHitTestResultIsContentEditable(WKHitTestResultRef hitTestResultRef)
</span><span class="cx"> {
</span><span class="cx">     return toImpl(hitTestResultRef)-&gt;isContentEditable();
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKHitTestResulth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKHitTestResult.h (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKHitTestResult.h        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKHitTestResult.h        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx"> 
</span><span class="cx"> WK_EXPORT WKStringRef WKHitTestResultCopyLinkLabel(WKHitTestResultRef hitTestResult);
</span><span class="cx"> WK_EXPORT WKStringRef WKHitTestResultCopyLinkTitle(WKHitTestResultRef hitTestResult);
</span><ins>+WK_EXPORT WKStringRef WKHitTestResultCopyLookupText(WKHitTestResultRef hitTestResult);
</ins><span class="cx"> 
</span><span class="cx"> WK_EXPORT bool WKHitTestResultIsContentEditable(WKHitTestResultRef hitTestResult);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsNetscapeNetscapePluginh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -38,6 +38,10 @@
</span><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><span class="cx"> #include &lt;wtf/text/StringHash.h&gt;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(COCOA)
+#include &quot;WebHitTestResult.h&quot;
+#endif
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> class MachSendRight;
</span><span class="cx"> class HTTPHeaderMap;
</span><span class="lines">@@ -237,6 +241,7 @@
</span><span class="cx">     void setComplexTextInputEnabled(bool);
</span><span class="cx"> 
</span><span class="cx">     void updatePluginLayer();
</span><ins>+    String lookupTextAtLocation(const WebCore::FloatPoint&amp;, WebHitTestResult::Data&amp;, PDFSelection** selection, NSDictionary**) const override { return String(); }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     virtual void contentsScaleFactorChanged(float) override;
</span><span class="lines">@@ -260,7 +265,9 @@
</span><span class="cx"> 
</span><span class="cx">     virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&amp;) override { return false; }
</span><span class="cx"> 
</span><del>-    virtual String getSelectionString() const override { return String(); }
</del><ins>+    String getSelectionString() const override { return String(); }
+    String getSelectionForWordAtPoint(const WebCore::FloatPoint&amp;) const override { return String(); }
+    bool existingSelectionContainsPoint(const WebCore::FloatPoint&amp;) const override { return false; }
</ins><span class="cx"> 
</span><span class="cx">     virtual void mutedStateChanged(bool) override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPDFPDFLayerControllerDetailsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFLayerControllerDetails.h (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFLayerControllerDetails.h        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFLayerControllerDetails.h        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #import &lt;PDFKit/PDFKit.h&gt;
</span><span class="cx"> 
</span><span class="cx"> @class CPReadingModel;
</span><ins>+@class PDFViewLayout;
</ins><span class="cx"> 
</span><span class="cx"> @protocol PDFLayerControllerDelegate &lt;NSObject&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -95,7 +96,12 @@
</span><span class="cx"> - (void)setSearchSelection:(PDFSelection *)selection;
</span><span class="cx"> - (void)gotoSelection:(PDFSelection *)selection;
</span><span class="cx"> - (PDFSelection *)getSelectionForWordAtPoint:(CGPoint)point;
</span><ins>+- (NSArray *)rectsForSelectionInLayoutSpace:(PDFSelection *)selection;
+- (NSArray *)rectsForAnnotationInLayoutSpace:(PDFAnnotation *)annotation;
+- (PDFViewLayout *)layout;
+- (NSRect)frame;
</ins><span class="cx"> 
</span><ins>+- (PDFPage *)currentPage;
</ins><span class="cx"> - (NSUInteger)lastPageIndex;
</span><span class="cx"> - (NSUInteger)currentPageIndex;
</span><span class="cx"> - (void)gotoNextPage;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPDFPDFPluginh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2011, 2012, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;Plugin.h&quot;
</span><span class="cx"> #include &quot;WebEvent.h&quot;
</span><ins>+#include &quot;WebHitTestResult.h&quot;
</ins><span class="cx"> #include &lt;WebCore/AffineTransform.h&gt;
</span><span class="cx"> #include &lt;WebCore/FindOptions.h&gt;
</span><span class="cx"> #include &lt;WebCore/ScrollableArea.h&gt;
</span><span class="lines">@@ -165,8 +166,11 @@
</span><span class="cx"> 
</span><span class="cx">     PDFSelection *nextMatchForString(const String&amp; target, BOOL searchForward, BOOL caseSensitive, BOOL wrapSearch, PDFSelection *initialSelection, BOOL startInSelection);
</span><span class="cx"> 
</span><del>-    virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&amp;) override;
-    virtual String getSelectionString() const override;
</del><ins>+    bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&amp;) override;
+    String getSelectionString() const override;
+    String getSelectionForWordAtPoint(const WebCore::FloatPoint&amp;) const override;
+    bool existingSelectionContainsPoint(const WebCore::FloatPoint&amp;) const override;
+    String lookupTextAtLocation(const WebCore::FloatPoint&amp;, WebHitTestResult::Data&amp;, PDFSelection **, NSDictionary **) const override;
</ins><span class="cx"> 
</span><span class="cx">     virtual bool shouldAllowScripting() override { return false; }
</span><span class="cx">     virtual bool shouldAllowNavigationFromDrags() override { return true; }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPDFPDFPluginmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -56,6 +56,7 @@
</span><span class="cx"> #import &lt;WebCore/ArchiveResource.h&gt;
</span><span class="cx"> #import &lt;WebCore/Chrome.h&gt;
</span><span class="cx"> #import &lt;WebCore/Cursor.h&gt;
</span><ins>+#import &lt;WebCore/DictionaryLookup.h&gt;
</ins><span class="cx"> #import &lt;WebCore/DocumentLoader.h&gt;
</span><span class="cx"> #import &lt;WebCore/FocusController.h&gt;
</span><span class="cx"> #import &lt;WebCore/FormState.h&gt;
</span><span class="lines">@@ -392,6 +393,11 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+@interface PDFViewLayout
+- (NSPoint)convertPoint:(NSPoint)point toPage:(PDFPage *)page forScaleFactor:(CGFloat)scaleFactor;
+- (PDFPage *)pageNearestPoint:(NSPoint)point currentPage:(PDFPage *)currentPage;
+@end
+
</ins><span class="cx"> static const char* postScriptMIMEType = &quot;application/postscript&quot;;
</span><span class="cx"> const uint64_t pdfDocumentRequestID = 1; // PluginController supports loading multiple streams, but we only need one for PDF.
</span><span class="cx"> 
</span><span class="lines">@@ -1829,6 +1835,104 @@
</span><span class="cx">     return [[m_pdfLayerController currentSelection] string];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String PDFPlugin::getSelectionForWordAtPoint(const WebCore::FloatPoint&amp; point) const
+{
+    IntPoint pointInView = convertFromPluginToPDFView(convertFromRootViewToPlugin(roundedIntPoint(point)));
+    PDFSelection *selectionForWord = [m_pdfLayerController getSelectionForWordAtPoint:pointInView];
+    [m_pdfLayerController setCurrentSelection:selectionForWord];
+    
+    return [selectionForWord string];
+}
+
+bool PDFPlugin::existingSelectionContainsPoint(const WebCore::FloatPoint&amp; point) const
+{
+    PDFSelection *currentSelection = [m_pdfLayerController currentSelection];
+    if (!currentSelection)
+        return false;
+    
+    IntPoint pointInView = convertFromPluginToPDFView(roundedIntPoint(point));
+    PDFSelection *selectionForWord = [m_pdfLayerController getSelectionForWordAtPoint:pointInView];
+
+    NSUInteger currentPageIndex = [m_pdfLayerController currentPageIndex];
+    
+    NSArray *selectionRects = [m_pdfLayerController rectsForSelectionInLayoutSpace:currentSelection];
+    if (!selectionRects || !selectionRects.count)
+        return false;
+    
+    if (currentPageIndex &gt;= selectionRects.count)
+        currentPageIndex = selectionRects.count - 1;
+
+    NSArray *wordSelectionRects = [m_pdfLayerController rectsForSelectionInLayoutSpace:selectionForWord];
+    if (!wordSelectionRects || !wordSelectionRects.count)
+        return false;
+
+    NSValue *selectionBounds = [selectionRects objectAtIndex:currentPageIndex];
+    NSValue *wordSelectionBounds = [wordSelectionRects objectAtIndex:0];
+
+    NSRect selectionBoundsRect = selectionBounds.rectValue;
+    NSRect wordSelectionBoundsRect = wordSelectionBounds.rectValue;
+    return NSIntersectsRect(wordSelectionBoundsRect, selectionBoundsRect);
+}
+
+static NSPoint pointInLayoutSpaceForPointInWindowSpace(PDFLayerController* pdfLayerController, NSPoint pointInView)
+{
+    CGPoint point = NSPointToCGPoint(pointInView);
+    CGPoint scrollOffset = [pdfLayerController scrollPosition];
+    CGFloat scaleFactor = [pdfLayerController contentScaleFactor];
+
+    scrollOffset.y = [pdfLayerController contentSizeRespectingZoom].height - NSRectToCGRect([pdfLayerController frame]).size.height - scrollOffset.y;
+    
+    CGPoint newPoint = CGPointMake(scrollOffset.x + point.x, scrollOffset.y + point.y);
+    newPoint.x /= scaleFactor;
+    newPoint.y /= scaleFactor;
+    return NSPointFromCGPoint(newPoint);
+}
+
+String PDFPlugin::lookupTextAtLocation(const WebCore::FloatPoint&amp; locationInViewCoordinates, WebHitTestResult::Data&amp; data, PDFSelection **selectionPtr, NSDictionary **options) const
+{
+    PDFSelection*&amp; selection = *selectionPtr;
+
+    selection = [m_pdfLayerController currentSelection];
+    if (existingSelectionContainsPoint(locationInViewCoordinates))
+        return [selection string];
+        
+    IntPoint pointInView = convertFromPluginToPDFView(roundedIntPoint(locationInViewCoordinates));
+    selection = [m_pdfLayerController getSelectionForWordAtPoint:pointInView];
+    if (!selection)
+        return @&quot;&quot;;
+
+    NSPoint pointInLayoutSpace = pointInLayoutSpaceForPointInWindowSpace(m_pdfLayerController.get(), pointInView);
+
+    PDFPage *currentPage = [[m_pdfLayerController layout] pageNearestPoint:pointInLayoutSpace currentPage:[m_pdfLayerController currentPage]];
+    
+    NSPoint pointInPageSpace = [[m_pdfLayerController layout] convertPoint:pointInLayoutSpace toPage:currentPage forScaleFactor:1.0];
+    
+    for (PDFAnnotation *annotation in [currentPage annotations]) {
+        if (![annotation isKindOfClass:pdfAnnotationLinkClass()])
+            continue;
+    
+        NSRect bounds = [annotation bounds];
+        if (!NSPointInRect(pointInPageSpace, bounds))
+            continue;
+        
+        PDFAnnotationLink *linkAnnotation = (PDFAnnotationLink *)annotation;
+        NSURL *url = [linkAnnotation URL];
+        if (!url)
+            continue;
+        
+        data.absoluteLinkURL = [url absoluteString];
+        data.linkLabel = [selection string];
+        return [selection string];
+    }
+    
+    NSString *lookupText = dictionaryLookupForPDFSelection(selection, options);
+    if (!lookupText || !lookupText.length)
+        return @&quot;&quot;;
+
+    [m_pdfLayerController setCurrentSelection:selection];
+    return lookupText;
+}
+
</ins><span class="cx"> void PDFPlugin::performWebSearch(NSString *string)
</span><span class="cx"> {
</span><span class="cx">     webFrame()-&gt;page()-&gt;send(Messages::WebPageProxy::SearchTheWeb(string));
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPluginh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -38,9 +38,12 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx"> #include &quot;LayerHostingContext.h&quot;
</span><ins>+#include &quot;WebHitTestResult.h&quot;
</ins><span class="cx"> 
</span><ins>+OBJC_CLASS NSDictionary;
</ins><span class="cx"> OBJC_CLASS NSObject;
</span><span class="cx"> OBJC_CLASS PDFDocument;
</span><ins>+OBJC_CLASS PDFSelection;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> struct NPObject;
</span><span class="lines">@@ -277,7 +280,12 @@
</span><span class="cx">     virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&amp;) = 0;
</span><span class="cx"> 
</span><span class="cx">     virtual String getSelectionString() const = 0;
</span><del>-    
</del><ins>+    virtual String getSelectionForWordAtPoint(const WebCore::FloatPoint&amp;) const = 0;
+    virtual bool existingSelectionContainsPoint(const WebCore::FloatPoint&amp;) const = 0;
+#if PLATFORM(COCOA)
+    virtual String lookupTextAtLocation(const WebCore::FloatPoint&amp;, WebHitTestResult::Data&amp;, PDFSelection**, NSDictionary**) const = 0;
+#endif
+
</ins><span class="cx">     virtual WebCore::AudioHardwareActivityType audioHardwareActivity() const { return WebCore::AudioHardwareActivityType::Unknown; }
</span><span class="cx"> 
</span><span class="cx">     virtual void mutedStateChanged(bool) { }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPluginProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> #include &lt;memory&gt;
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><ins>+#include &quot;WebHitTestResult.h&quot;
</ins><span class="cx"> #include &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> OBJC_CLASS CALayer;
</span><span class="cx"> #endif
</span><span class="lines">@@ -122,6 +123,7 @@
</span><span class="cx">     virtual uint64_t pluginComplexTextInputIdentifier() const override;
</span><span class="cx">     virtual void sendComplexTextInput(const String&amp; textInput) override;
</span><span class="cx">     virtual void setLayerHostingMode(LayerHostingMode) override;
</span><ins>+    String lookupTextAtLocation(const WebCore::FloatPoint&amp;, WebHitTestResult::Data&amp;, PDFSelection**, NSDictionary**) const override { return String(); }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     virtual void contentsScaleFactorChanged(float) override;
</span><span class="lines">@@ -141,7 +143,9 @@
</span><span class="cx">     virtual PassRefPtr&lt;WebCore::SharedBuffer&gt; liveResourceData() const override;
</span><span class="cx">     virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&amp;) override { return false; }
</span><span class="cx"> 
</span><del>-    virtual String getSelectionString() const override { return String(); }
</del><ins>+    String getSelectionString() const override { return String(); }
+    String getSelectionForWordAtPoint(const WebCore::FloatPoint&amp;) const override { return String(); }
+    bool existingSelectionContainsPoint(const WebCore::FloatPoint&amp;) const override { return false; }
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     virtual WebCore::AudioHardwareActivityType audioHardwareActivity() const override;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPluginViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010, 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2012, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -993,6 +993,32 @@
</span><span class="cx">     return m_plugin-&gt;performDictionaryLookupAtLocation(point);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String PluginView::getSelectionForWordAtPoint(const WebCore::FloatPoint&amp; point) const
+{
+    if (!m_isInitialized || !m_plugin)
+        return String();
+    
+    return m_plugin-&gt;getSelectionForWordAtPoint(point);
+}
+
+bool PluginView::existingSelectionContainsPoint(const WebCore::FloatPoint&amp; point) const
+{
+    if (!m_isInitialized || !m_plugin)
+        return false;
+    
+    return m_plugin-&gt;existingSelectionContainsPoint(point);
+}
+
+#if PLATFORM(COCOA)
+String PluginView::lookupTextAtLocation(const WebCore::FloatPoint&amp; point, WebHitTestResult::Data&amp; data, PDFSelection **selection, NSDictionary **options) const
+{
+    if (!m_isInitialized || !m_plugin)
+        return String();
+
+    return m_plugin-&gt;lookupTextAtLocation(point, data, selection, options);
+}
+#endif
+
</ins><span class="cx"> void PluginView::notifyWidget(WidgetNotification notification)
</span><span class="cx"> {
</span><span class="cx">     switch (notification) {
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPluginViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010, 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2012, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -46,6 +46,13 @@
</span><span class="cx"> 
</span><span class="cx"> // FIXME: Eventually this should move to WebCore.
</span><span class="cx"> 
</span><ins>+#if PLATFORM(COCOA)
+#include &quot;WebHitTestResult.h&quot;
+
+OBJC_CLASS NSDictionary;
+OBJC_CLASS PDFSelection;
+#endif
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> class Frame;
</span><span class="cx"> class HTMLPlugInElement;
</span><span class="lines">@@ -82,6 +89,7 @@
</span><span class="cx">     bool sendComplexTextInput(uint64_t pluginComplexTextInputIdentifier, const String&amp; textInput);
</span><span class="cx">     RetainPtr&lt;PDFDocument&gt; pdfDocumentForPrinting() const { return m_plugin-&gt;pdfDocumentForPrinting(); }
</span><span class="cx">     NSObject *accessibilityObject() const;
</span><ins>+    String lookupTextAtLocation(const WebCore::FloatPoint&amp;, WebHitTestResult::Data&amp;, PDFSelection**, NSDictionary**) const;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     WebCore::HTMLPlugInElement* pluginElement() const { return m_pluginElement.get(); }
</span><span class="lines">@@ -111,6 +119,8 @@
</span><span class="cx"> 
</span><span class="cx">     PassRefPtr&lt;WebCore::SharedBuffer&gt; liveResourceData() const;
</span><span class="cx">     bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&amp;);
</span><ins>+    String getSelectionForWordAtPoint(const WebCore::FloatPoint&amp;) const;
+    bool existingSelectionContainsPoint(const WebCore::FloatPoint&amp;) const;
</ins><span class="cx">     virtual WebCore::AudioHardwareActivityType audioHardwareActivity() const override;
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagemacWebPageMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010, 2011, 2012, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -65,6 +65,7 @@
</span><span class="cx"> #import &lt;WebCore/FrameView.h&gt;
</span><span class="cx"> #import &lt;WebCore/GraphicsContext.h&gt;
</span><span class="cx"> #import &lt;WebCore/HTMLConverter.h&gt;
</span><ins>+#import &lt;WebCore/HTMLPluginImageElement.h&gt;
</ins><span class="cx"> #import &lt;WebCore/HitTestResult.h&gt;
</span><span class="cx"> #import &lt;WebCore/KeyboardEvent.h&gt;
</span><span class="cx"> #import &lt;WebCore/MIMETypeRegistry.h&gt;
</span><span class="lines">@@ -1100,6 +1101,30 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+#if ENABLE(PDFKIT_PLUGIN)
+    // See if we have a PDF
+    if (element &amp;&amp; is&lt;HTMLPlugInImageElement&gt;(*element)) {
+        HTMLPlugInImageElement&amp; pluginImageElement = downcast&lt;HTMLPlugInImageElement&gt;(*element);
+        if (PluginView* pluginView = reinterpret_cast&lt;PluginView*&gt;(pluginImageElement.pluginWidget())) {
+            // FIXME: We don't have API to identify images inside PDFs based on position.
+            NSDictionary *options = nil;
+            PDFSelection *selection = nil;
+            String selectedText = pluginView-&gt;lookupTextAtLocation(locationInContentCoordinates, actionMenuResult, &amp;selection, &amp;options);
+            if (!selectedText.isEmpty()) {
+                if (element-&gt;document().isPluginDocument()) {
+                    // FIXME(144030): Focus does not seem to get set to the PDF when invoking the menu.
+                    PluginDocument&amp; pluginDocument = static_cast&lt;PluginDocument&amp;&gt;(element-&gt;document());
+                    pluginDocument.setFocusedElement(element);
+                }
+
+                actionMenuResult.lookupText = selectedText;
+                actionMenuResult.isSelected = true;
+                actionMenuResult.allowsCopy = true;
+            }
+        }
+    }
+#endif
+
</ins><span class="cx">     RefPtr&lt;API::Object&gt; userData;
</span><span class="cx">     injectedBundleContextMenuClient().prepareForActionMenu(*this, hitTestResult, userData);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Tools/ChangeLog        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2015-04-21  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        [Mac] Extend action menus to support PDF
+        https://bugs.webkit.org/show_bug.cgi?id=143895
+        &lt;rdar://problem/19003333&gt;
+
+        Reviewed by Tim Horton.
+
+        Reactivate the action menu tests, and add a new PDF-based test to make sure that selection
+        of PDF content works.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add new 'test.pdf' resource to bundle.
+        * TestWebKitAPI/Tests/WebKit2/action-menu-targets.html: Update with a new PDF pane.
+        * TestWebKitAPI/Tests/WebKit2/test.pdf: Added.
+        * TestWebKitAPI/Tests/WebKit2ObjC/ActionMenus.mm:
+        (-[ActionMenusTestWKView _actionMenuItemsForHitTestResult:withType:defaultActionMenuItems:userData:]):
+        Update to support PDF tests.
+        (TestWebKitAPI::windowPointForTarget): Add new target for PDF test.
+        (TestWebKitAPI::waitForPDFToLoad): New helper function to avoid starting test before the PDF is available.
+
</ins><span class="cx"> 2015-04-22  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Do not run GTK+ user media unit tests when ENABLE_MEDIA_STREAM is disabled.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -63,6 +63,8 @@
</span><span class="cx">                 7A99D9941AD4A29D00373141 /* MenuTypesForMouseEvents.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */; };
</span><span class="cx">                 7AA021BB1AB09EA70052953F /* DateMath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AA021BA1AB09EA70052953F /* DateMath.cpp */; };
</span><span class="cx">                 7AA6A1521AAC0B31002B2ED3 /* WorkQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AA6A1511AAC0B31002B2ED3 /* WorkQueue.cpp */; };
</span><ins>+                7AE9E5091AE5AE8B00CF874B /* test.pdf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7AE9E5081AE5AE8B00CF874B /* test.pdf */; };
+                7AE9E50B1AE5F97000CF874B /* action-menu-target.pdf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7AE9E50A1AE5F91300CF874B /* action-menu-target.pdf */; };
</ins><span class="cx">                 7C486BA11AA12567003F6F9B /* bundle-file.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7C486BA01AA1254B003F6F9B /* bundle-file.html */; };
</span><span class="cx">                 7C54A4BE1AA11CCA00380F78 /* WKBundleFileHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C54A4BC1AA11CCA00380F78 /* WKBundleFileHandle.cpp */; };
</span><span class="cx">                 7C54A4C11AA11CE400380F78 /* WKBundleFileHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C54A4BF1AA11CE400380F78 /* WKBundleFileHandle_Bundle.cpp */; };
</span><span class="lines">@@ -328,6 +330,8 @@
</span><span class="cx">                         dstPath = TestWebKitAPI.resources;
</span><span class="cx">                         dstSubfolderSpec = 7;
</span><span class="cx">                         files = (
</span><ins>+                                7AE9E50B1AE5F97000CF874B /* action-menu-target.pdf in Copy Resources */,
+                                7AE9E5091AE5AE8B00CF874B /* test.pdf in Copy Resources */,
</ins><span class="cx">                                 7A1458FC1AD5C07000E06772 /* mouse-button-listener.html in Copy Resources */,
</span><span class="cx">                                 7C486BA11AA12567003F6F9B /* bundle-file.html in Copy Resources */,
</span><span class="cx">                                 1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
</span><span class="lines">@@ -531,6 +535,8 @@
</span><span class="cx">                 7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MenuTypesForMouseEvents.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7AA021BA1AB09EA70052953F /* DateMath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DateMath.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7AA6A1511AAC0B31002B2ED3 /* WorkQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueue.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                7AE9E5081AE5AE8B00CF874B /* test.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = test.pdf; sourceTree = &quot;&lt;group&gt;&quot;; };
+                7AE9E50A1AE5F91300CF874B /* action-menu-target.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = &quot;action-menu-target.pdf&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 7C486BA01AA1254B003F6F9B /* bundle-file.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = &quot;bundle-file.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7C54A4BC1AA11CCA00380F78 /* WKBundleFileHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundleFileHandle.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7C54A4BF1AA11CE400380F78 /* WKBundleFileHandle_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundleFileHandle_Bundle.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1077,6 +1083,8 @@
</span><span class="cx">                 BC90977B125571AE00083756 /* Resources */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                7AE9E50A1AE5F91300CF874B /* action-menu-target.pdf */,
+                                7AE9E5081AE5AE8B00CF874B /* test.pdf */,
</ins><span class="cx">                                 7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */,
</span><span class="cx">                                 C045F9461385C2F800C0F3CD /* 18-characters.html */,
</span><span class="cx">                                 2D950FBF1A230C1E00012434 /* action-menu-targets.html */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2actionmenutargetpdf"></a>
<div class="binary"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/action-menu-target.pdf</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/Tools/TestWebKitAPI/Tests/WebKit2/action-menu-target.pdf
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2actionmenutargetshtml"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/action-menu-targets.html (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/action-menu-targets.html        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/action-menu-targets.html        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -5,6 +5,14 @@
</span><span class="cx">     overflow: hidden;
</span><span class="cx">     border: 1px solid black;
</span><span class="cx"> }
</span><ins>+
+embed {
+    position: absolute;
+    width: 100%; height: 100%;
+    overflow: hidden;
+    padding: 0;
+    margin: 0;
+}
</ins><span class="cx"> &lt;/style&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;script&gt;
</span><span class="lines">@@ -102,6 +110,8 @@
</span><span class="cx"> &lt;div style=&quot;top: 250px; left: 0px;&quot;&gt;&lt;img src=&quot;icon.png&quot; height=&quot;100%&quot;&gt;&lt;/div&gt;&lt;br/&gt;
</span><span class="cx"> &lt;div style=&quot;top: 250px; left: 200px;&quot;&gt;&lt;a href=&quot;http://example.org/&quot;&gt;&lt;img src=&quot;icon.png&quot; height=&quot;100%&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;br/&gt;
</span><span class="cx"> 
</span><ins>+&lt;div style=&quot;top: 250px; left: 400px; height: 350px&quot;&gt;&lt;embed src=&quot;test.pdf&quot;&gt;&lt;/embed&gt;&lt;/div&gt;&lt;br/&gt;
+
</ins><span class="cx"> &lt;div style=&quot;top: 300px; left: 0px; width: 95px;&quot;&gt;&lt;a href=&quot;http://example.org/&quot;&gt;http&lt;/a&gt;&lt;/div&gt;&lt;br/&gt;
</span><span class="cx"> &lt;div style=&quot;top: 300px; left: 100px; width: 95px;&quot;&gt;&lt;a href=&quot;ftp://example.org/&quot;&gt;ftp&lt;/a&gt;&lt;/div&gt;&lt;br/&gt;
</span><span class="cx"> &lt;div style=&quot;top: 300px; left: 200px; width: 95px;&quot;&gt;&lt;a href=&quot;mailto:example@example.org&quot;&gt;mailto link&lt;/a&gt;&lt;/div&gt;&lt;br/&gt;
</span><span class="lines">@@ -110,5 +120,4 @@
</span><span class="cx"> &lt;div style=&quot;top: 350px; left: 0px;&quot;&gt;&lt;video src=&quot;test.mp4&quot;&gt;&lt;/video&gt;&lt;/div&gt;&lt;br/&gt;
</span><span class="cx"> &lt;div style=&quot;top: 350px; left: 200px;&quot;&gt;&lt;video id=&quot;mse-video&quot;&gt;&lt;/video&gt;&lt;/div&gt;&lt;br/&gt;
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> &lt;div style=&quot;top: 0px; left: 750px; height: 600px;&quot;&gt;data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text data detectors menu text &lt;/div&gt;&lt;br/&gt;
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2testpdf"></a>
<div class="binary"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/test.pdf</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/Tools/TestWebKitAPI/Tests/WebKit2/test.pdf
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2ObjCActionMenusmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/ActionMenus.mm (183135 => 183136)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/ActionMenus.mm        2015-04-22 21:22:02 UTC (rev 183135)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/ActionMenus.mm        2015-04-22 21:23:54 UTC (rev 183136)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2014-2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -82,6 +82,9 @@
</span><span class="cx">     if (type != kWKActionMenuNone)
</span><span class="cx">         EXPECT_GT(defaultMenuItems.count, (NSUInteger)0);
</span><span class="cx"> 
</span><ins>+    if (!hitTestResult)
+        return defaultMenuItems;
+
</ins><span class="cx">     // Clients should be able to pass userData from the Web to UI process, between
</span><span class="cx">     // the WKBundlePageContextMenuClient's prepareForActionMenu, and here.
</span><span class="cx">     // http://trac.webkit.org/changeset/175444
</span><span class="lines">@@ -363,6 +366,8 @@
</span><span class="cx">     PageWhitespace,
</span><span class="cx">     Video,
</span><span class="cx">     MSEVideo,
</span><ins>+    PDFEmbed,
+    PDFDocument
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> static NSPoint windowPointForTarget(TargetType target)
</span><span class="lines">@@ -432,15 +437,29 @@
</span><span class="cx">     case TargetType::MSEVideo:
</span><span class="cx">         contentPoint = NSMakePoint(200, 350);
</span><span class="cx">         break;
</span><ins>+    case TargetType::PDFEmbed:
+        contentPoint = NSMakePoint(410, 420);
+        break;
+    case TargetType::PDFDocument:
+        contentPoint = NSMakePoint(141, 374);
+        break;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return NSMakePoint(contentPoint.x + 8, 600 - contentPoint.y - 8);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void waitForPDFToLoad(ActionMenusTestWKView* wkView)
+{
+    __block bool pdfSeemsLoaded = false;
+    [wkView runMenuSequenceAtPoint:windowPointForTarget(TargetType::PDFEmbed) preDidCloseMenuHandler:^() {
+        pdfSeemsLoaded = kWKActionMenuReadOnlyText == [wkView _actionMenuResult].type;
+    }];
+    Util::run(&amp;didFinishLoad);
+}
+
</ins><span class="cx"> // FIXME: Ideally, each of these would be able to run as its own subtest in a suite, sharing a WKView (for performance reasons),
</span><span class="cx"> // but we cannot because run-api-tests explicitly runs each test in a separate process. So, we use a single test for many tests instead.
</span><del>-// FIXME: Temporarily disabled.
-TEST(WebKit2, DISABLED_ActionMenusTest)
</del><ins>+TEST(WebKit2, ActionMenusTest)
</ins><span class="cx"> {
</span><span class="cx">     WKRetainPtr&lt;WKContextRef&gt; context = adoptWK(Util::createContextForInjectedBundleTest(&quot;ActionMenusTest&quot;));
</span><span class="cx"> 
</span><span class="lines">@@ -452,7 +471,7 @@
</span><span class="cx">     PlatformWebView platformWebView(context.get(), pageGroup.get(), [ActionMenusTestWKView class]);
</span><span class="cx">     RetainPtr&lt;ActionMenusTestWKView&gt; wkView = (ActionMenusTestWKView *)platformWebView.platformView();
</span><span class="cx"> 
</span><del>-    if (![wkView respondsToSelector:@selector(setActionMenu:)])
</del><ins>+    if (![wkView respondsToSelector:@selector(_setActionMenu:)])
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     WKPageLoaderClientV0 loaderClient;
</span><span class="lines">@@ -476,6 +495,11 @@
</span><span class="cx"> 
</span><span class="cx">     Util::run(&amp;didFinishLoad);
</span><span class="cx"> 
</span><ins>+    waitForVideoReady([wkView pageRef]);
+
+    // PDF embeds should have selectable/copyable text.
+    waitForPDFToLoad(wkView.get());
+
</ins><span class="cx">     // Read-only text.
</span><span class="cx">     [wkView runMenuSequenceAtPoint:windowPointForTarget(TargetType::Word) preDidCloseMenuHandler:^() {
</span><span class="cx">         EXPECT_EQ(kWKActionMenuReadOnlyText, [wkView _actionMenuResult].type);
</span><span class="lines">@@ -494,18 +518,14 @@
</span><span class="cx"> 
</span><span class="cx">     // Read-only text, on an address.
</span><span class="cx">     [wkView runMenuSequenceAtPoint:windowPointForTarget(TargetType::Address) preDidCloseMenuHandler:^() {
</span><del>-        EXPECT_EQ(kWKActionMenuDataDetectedItem, [wkView _actionMenuResult].type);
-
-        // Addresses don't get selected, because they immediately show a TextIndicator.
-        EXPECT_WK_STREQ(@&quot;&lt;no selection&gt;&quot;, retrieveSelection([wkView pageRef]));
</del><ins>+        EXPECT_EQ(kWKActionMenuReadOnlyText, [wkView _actionMenuResult].type);
+        EXPECT_WK_STREQ(@&quot;1 Infinite Loop, Cupertino, CA 95014&quot;, retrieveSelection([wkView pageRef]));
</ins><span class="cx">     }];
</span><span class="cx"> 
</span><span class="cx">     // Read-only text, on a date.
</span><span class="cx">     [wkView runMenuSequenceAtPoint:windowPointForTarget(TargetType::Date) preDidCloseMenuHandler:^() {
</span><del>-        EXPECT_EQ(kWKActionMenuDataDetectedItem, [wkView _actionMenuResult].type);
-
-        // Dates don't get selected, because they immediately show a TextIndicator.
-        EXPECT_WK_STREQ(@&quot;&lt;no selection&gt;&quot;, retrieveSelection([wkView pageRef]));
</del><ins>+        EXPECT_EQ(kWKActionMenuReadOnlyText, [wkView _actionMenuResult].type);
+        EXPECT_WK_STREQ(@&quot;May 17th, 2012&quot;, retrieveSelection([wkView pageRef]));
</ins><span class="cx">     }];
</span><span class="cx"> 
</span><span class="cx">     // Read-only text, on a phone number.
</span><span class="lines">@@ -662,8 +682,6 @@
</span><span class="cx">         EXPECT_EQ(kWKActionMenuLink, [wkView _actionMenuResult].type);
</span><span class="cx">     }];
</span><span class="cx"> 
</span><del>-    waitForVideoReady([wkView pageRef]);
-
</del><span class="cx">     // Copy a video URL.
</span><span class="cx">     [wkView runMenuSequenceAtPoint:windowPointForTarget(TargetType::Video) preDidCloseMenuHandler:^() {
</span><span class="cx">         EXPECT_EQ(kWKActionMenuVideo, [wkView _actionMenuResult].type);
</span><span class="lines">@@ -716,6 +734,14 @@
</span><span class="cx">         EXPECT_FALSE(callJavaScriptReturningBool([wkView pageRef], &quot;wasFailCalled()&quot;));
</span><span class="cx">     }];
</span><span class="cx"> 
</span><ins>+    // PDF text content
+    [wkView runMenuSequenceAtPoint:windowPointForTarget(TargetType::PDFEmbed) preDidCloseMenuHandler:^() {
+        EXPECT_EQ(kWKActionMenuReadOnlyText, [wkView _actionMenuResult].type);
+        EXPECT_WK_STREQ(&quot;Test&quot;, WKHitTestResultCopyLookupText([wkView _actionMenuResult].hitTestResult.get()));
+
+        // FIXME(14408): You cannot copy from PDFs hosted in &lt;embed&gt; tags. When this is fixed, we should test it works here.
+    }];
+
</ins><span class="cx">     // Clients should be able to customize the menu by overriding WKView's _actionMenuItemsForHitTestResult.
</span><span class="cx">     // http://trac.webkit.org/changeset/174908
</span><span class="cx">     RetainPtr&lt;NSMenuItem&gt; item = adoptNS([[NSMenuItem alloc] initWithTitle:@&quot;Some Action&quot; action:@selector(copy:) keyEquivalent:@&quot;&quot;]);
</span><span class="lines">@@ -740,6 +766,42 @@
</span><span class="cx">     }];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(WebKit2, ActionMenusPDFTest)
+{
+    WKRetainPtr&lt;WKContextRef&gt; context = adoptWK(Util::createContextForInjectedBundleTest(&quot;ActionMenusTest&quot;));
+    
+    WKRetainPtr&lt;WKPageGroupRef&gt; pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(Util::toWK(&quot;ActionMenusPDFTestGroup&quot;).get()));
+    WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup.get());
+    WKPreferencesSetMediaSourceEnabled(preferences, true);
+    WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true);
+    
+    PlatformWebView platformWebView(context.get(), pageGroup.get(), [ActionMenusTestWKView class]);
+    RetainPtr&lt;ActionMenusTestWKView&gt; wkView = (ActionMenusTestWKView *)platformWebView.platformView();
+    
+    if (![wkView respondsToSelector:@selector(_setActionMenu:)])
+        return;
+    
+    WKPageLoaderClientV0 loaderClient;
+    memset(&amp;loaderClient, 0, sizeof(loaderClient));
+    loaderClient.base.version = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrameCallback;
+    WKPageSetPageLoaderClient([wkView pageRef], &amp;loaderClient.base);
+    
+    ActiveDownloadContext activeDownloadContext;
+    
+    WKRetainPtr&lt;WKURLRef&gt; url(AdoptWK, Util::createURLForResource(&quot;action-menu-target&quot;, &quot;pdf&quot;));
+    WKPageLoadURL([wkView pageRef], url.get());
+    
+    Util::run(&amp;didFinishLoad);
+
+    [wkView runMenuSequenceAtPoint:windowPointForTarget(TargetType::PDFDocument) preDidCloseMenuHandler:^() {
+        EXPECT_EQ(kWKActionMenuReadOnlyText, [wkView _actionMenuResult].type);
+        EXPECT_WK_STREQ(&quot;Happiness&quot;, WKHitTestResultCopyLookupText([wkView _actionMenuResult].hitTestResult.get()));
+        performMenuItemAtIndexOfTypeAsync([wkView _actionMenu], 0, kWKContextActionItemTagCopyText);
+        EXPECT_WK_STREQ(@&quot;Happiness&quot;, watchPasteboardForString());
+    }];
+}
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>