"Use Selection for Find" doesn't work in PDF viewed in Safari
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Dec 2013 22:30:40 +0000 (22:30 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Dec 2013 22:30:40 +0000 (22:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=125319
<rdar://problem/15486983>

Reviewed by Tim Horton.

* WebProcess/Plugins/PDF/PDFPlugin.h:
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(-[WKPDFLayerControllerDelegate writeItemsToPasteboard:withTypes:]):
Pass NSGeneralPboard to writeItemsToPasteboard.

(WebKit::PDFPlugin::handleEditingCommand):
Handle takeFindStringFromSelection by getting the current selection string and writing it to the find pasteboard.

(WebKit::PDFPlugin::isEditingCommandEnabled):
Handle takeFindStringFromSelection.

(WebKit::PDFPlugin::writeItemsToPasteboard):
Update this to take a pasteboard name.

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm

index d939451..1f9e89f 100644 (file)
@@ -1,5 +1,27 @@
 2013-12-05  Anders Carlsson  <andersca@apple.com>
 
+        "Use Selection for Find" doesn't work in PDF viewed in Safari
+        https://bugs.webkit.org/show_bug.cgi?id=125319
+        <rdar://problem/15486983>
+
+        Reviewed by Tim Horton.
+
+        * WebProcess/Plugins/PDF/PDFPlugin.h:
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (-[WKPDFLayerControllerDelegate writeItemsToPasteboard:withTypes:]):
+        Pass NSGeneralPboard to writeItemsToPasteboard.
+
+        (WebKit::PDFPlugin::handleEditingCommand):
+        Handle takeFindStringFromSelection by getting the current selection string and writing it to the find pasteboard.
+
+        (WebKit::PDFPlugin::isEditingCommandEnabled):
+        Handle takeFindStringFromSelection.
+
+        (WebKit::PDFPlugin::writeItemsToPasteboard):
+        Update this to take a pasteboard name.
+
+2013-12-05  Anders Carlsson  <andersca@apple.com>
+
         WebKit2 API should use weak ownership for delegate properties rather than assign
         https://bugs.webkit.org/show_bug.cgi?id=125316
         <rdar://problem/15560614>
index 724a213..3d292c5 100644 (file)
@@ -88,7 +88,7 @@ public:
     void clickedLink(NSURL *);
     void saveToPDF();
     void openWithNativeApplication();
-    void writeItemsToPasteboard(NSArray *items, NSArray *types);
+    void writeItemsToPasteboard(NSString *pasteboardName, NSArray *items, NSArray *types);
     void showDefinitionForAttributedString(NSAttributedString *, CGPoint);
     void performWebSearch(NSString *);
     void performSpotlightSearch(NSString *);
index 2b0b234..89ee89f 100644 (file)
@@ -335,7 +335,7 @@ static const int defaultScrollMagnitudeThresholdForPageFlip = 20;
 
 - (void)writeItemsToPasteboard:(NSArray *)items withTypes:(NSArray *)types
 {
-    _pdfPlugin->writeItemsToPasteboard(items, types);
+    _pdfPlugin->writeItemsToPasteboard(NSGeneralPboard, items, types);
 }
 
 - (void)showDefinitionForAttributedString:(NSAttributedString *)string atPoint:(CGPoint)point
@@ -1480,17 +1480,22 @@ bool PDFPlugin::handleKeyboardEvent(const WebKeyboardEvent& event)
 bool PDFPlugin::handleEditingCommand(const String& commandName, const String& argument)
 {
     if (commandName == "copy")
-        [m_pdfLayerController.get() copySelection];
+        [m_pdfLayerController copySelection];
     else if (commandName == "selectAll")
-        [m_pdfLayerController.get() selectAll];
-    
+        [m_pdfLayerController selectAll];
+    else if (commandName == "takeFindStringFromSelection") {
+        NSString *string = [m_pdfLayerController currentSelection].string;
+        if (string.length)
+            writeItemsToPasteboard(NSFindPboard, @[ [string dataUsingEncoding:NSUTF8StringEncoding] ], @[ NSPasteboardTypeString ]);
+    }
+
     return true;
 }
 
 bool PDFPlugin::isEditingCommandEnabled(const String& commandName)
 {
-    if (commandName == "copy")
-        return [m_pdfLayerController.get() currentSelection];
+    if (commandName == "copy" || commandName == "takeFindStringFromSelection")
+        return [m_pdfLayerController currentSelection];
         
     if (commandName == "selectAll")
         return true;
@@ -1630,7 +1635,7 @@ void PDFPlugin::openWithNativeApplication()
     webFrame()->page()->send(Messages::WebPageProxy::OpenPDFFromTemporaryFolderWithNativeApplication(m_temporaryPDFUUID));
 }
 
-void PDFPlugin::writeItemsToPasteboard(NSArray *items, NSArray *types)
+void PDFPlugin::writeItemsToPasteboard(NSString *pasteboardName, NSArray *items, NSArray *types)
 {
     Vector<String> pasteboardTypes;
 
@@ -1638,7 +1643,7 @@ void PDFPlugin::writeItemsToPasteboard(NSArray *items, NSArray *types)
         pasteboardTypes.append(type);
 
     uint64_t newChangeCount;
-    WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardTypes(NSGeneralPboard, pasteboardTypes),
+    WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardTypes(pasteboardName, pasteboardTypes),
         Messages::WebContext::SetPasteboardTypes::Reply(newChangeCount), 0);
 
     for (NSUInteger i = 0, count = items.count; i < count; ++i) {
@@ -1653,7 +1658,7 @@ void PDFPlugin::writeItemsToPasteboard(NSArray *items, NSArray *types)
 
         if ([type isEqualToString:NSStringPboardType] || [type isEqualToString:NSPasteboardTypeString]) {
             RetainPtr<NSString> plainTextString = adoptNS([[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
-            WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardStringForType(NSGeneralPboard, type, plainTextString.get()),
+            WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardStringForType(pasteboardName, type, plainTextString.get()),
                 Messages::WebContext::SetPasteboardStringForType::Reply(newChangeCount), 0);
         } else {
             RefPtr<SharedBuffer> buffer = SharedBuffer::wrapNSData(data);
@@ -1665,7 +1670,7 @@ void PDFPlugin::writeItemsToPasteboard(NSArray *items, NSArray *types)
             RefPtr<SharedMemory> sharedMemory = SharedMemory::create(buffer->size());
             memcpy(sharedMemory->data(), buffer->data(), buffer->size());
             sharedMemory->createHandle(handle, SharedMemory::ReadOnly);
-            WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardBufferForType(NSGeneralPboard, type, handle, buffer->size()),
+            WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardBufferForType(pasteboardName, type, handle, buffer->size()),
                 Messages::WebContext::SetPasteboardBufferForType::Reply(newChangeCount), 0);
         }
     }