Diff
Modified: trunk/Source/WebKit2/ChangeLog (138460 => 138461)
--- trunk/Source/WebKit2/ChangeLog 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/ChangeLog 2012-12-25 11:08:22 UTC (rev 138461)
@@ -1,3 +1,44 @@
+2012-12-25 Tim Horton <[email protected]>
+
+ PDFPlugin: Find-in-page
+ https://bugs.webkit.org/show_bug.cgi?id=105710
+ <rdar://problem/12555331>
+
+ Reviewed by Alexey Proskuryakov.
+
+ Make use of PDFLayerController's find-in-page functionality to mimic WebKit's.
+ Add two Plugin methods, countFindMatches and findString, and make use of them
+ if attempting to find-in-page within a PluginDocument.
+
+ * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
+ (WebKit::NetscapePlugin::countFindMatches): Added. We don't support find-in-page for NetscapePlugin.
+ (WebKit::NetscapePlugin::findString): Added. We don't support find-in-page for NetscapePlugin.
+ * WebProcess/Plugins/Netscape/NetscapePlugin.h: Add countFindMatches and findString.
+ * WebProcess/Plugins/PDF/PDFLayerControllerDetails.h: Add requisite PDFLayerController interfaces.
+ * WebProcess/Plugins/PDF/PDFPlugin.h: Add countFindMatches, findString, and nextMatchForString,
+ as well as storage for the most-recently-searched string.
+ * WebProcess/Plugins/PDF/PDFPlugin.mm:
+ (WebKit::PDFPlugin::writeItemsToPasteboard):
+ (WebKit::PDFPlugin::countFindMatches):
+ (WebKit::PDFPlugin::nextMatchForString):
+ (WebKit::PDFPlugin::findString):
+ * WebProcess/Plugins/PDF/SimplePDFPlugin.h: Add countFindMatches and findString.
+ * WebProcess/Plugins/Plugin.h: Add countFindMatches and findString.
+ * WebProcess/Plugins/PluginProxy.h: Add countFindMatches and findString, but since PDFPlugin
+ is in-process, we don't need to forward these calls to the PluginProcess.
+ * WebProcess/Plugins/PluginView.cpp:
+ (WebKit::PluginView::countFindMatches): Forward countFindMatches to the plugin.
+ (WebKit::PluginView::findString): Forward findString to the plugin.
+ * WebProcess/Plugins/PluginView.h: Add countFindMatches and findString.
+ * WebProcess/WebPage/FindController.cpp:
+ (WebKit::pluginViewForFrame): If the given frame hosts a PluginDocument, grab its PluginView.
+ (WebKit::FindController::countStringMatches): Forward countStringMatches to PluginView if necessary.
+ (WebKit::FindController::updateFindUIAfterPageScroll): Only use unmarkAllTextMatches if we're using
+ ordinary find-in-page and don't have a plugin. If we have a plugin, disable our overlay, as it must
+ be handled by the plugin itself, and request the number of matches for the search from the plugin.
+ (WebKit::FindController::findString): If necessary, forward findString to the plugin.
+ (WebKit::FindController::hideFindUI): Hide the search highlight by searching for an empty string.
+
2012-12-24 Laszlo Gombos <[email protected]>
Remove wtf/Platform.h includes from {c|cpp} files
Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp 2012-12-25 11:08:22 UTC (rev 138461)
@@ -958,7 +958,17 @@
return scriptableNPObject;
}
+
+unsigned NetscapePlugin::countFindMatches(const String&, WebCore::FindOptions, unsigned)
+{
+ return 0;
+}
+bool NetscapePlugin::findString(const String&, WebCore::FindOptions, unsigned)
+{
+ return false;
+}
+
void NetscapePlugin::contentsScaleFactorChanged(float scaleFactor)
{
ASSERT(m_isStarted);
Modified: trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h 2012-12-25 11:08:22 UTC (rev 138461)
@@ -213,6 +213,9 @@
virtual bool handlesPageScaleFactor() OVERRIDE;
virtual NPObject* pluginScriptableNPObject();
+
+ virtual unsigned countFindMatches(const String&, WebCore::FindOptions, unsigned maxMatchCount) OVERRIDE;
+ virtual bool findString(const String&, WebCore::FindOptions, unsigned maxMatchCount) OVERRIDE;
#if PLATFORM(MAC)
virtual void windowFocusChanged(bool);
Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFLayerControllerDetails.h (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFLayerControllerDetails.h 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFLayerControllerDetails.h 2012-12-25 11:08:22 UTC (rev 138461)
@@ -83,7 +83,12 @@
- (NSArray *)findString:(NSString *)string caseSensitive:(BOOL)isCaseSensitive highlightMatches:(BOOL)shouldHighlightMatches;
-- (id)currentSelection;
+- (PDFSelection *)currentSelection;
+- (void)setCurrentSelection:(PDFSelection *)selection;
+- (PDFSelection *)searchSelection;
+- (void)setSearchSelection:(PDFSelection *)selection;
+- (void)gotoSelection:(PDFSelection *)selection;
+
- (void)copySelection;
- (void)selectAll;
Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h 2012-12-25 11:08:22 UTC (rev 138461)
@@ -32,6 +32,7 @@
#include "SimplePDFPlugin.h"
#include "WebEvent.h"
#include <WebCore/AffineTransform.h>
+#include <WebCore/FindOptions.h>
#include <WebCore/ScrollableArea.h>
#include <wtf/RetainPtr.h>
@@ -41,6 +42,7 @@
OBJC_CLASS PDFAnnotation;
OBJC_CLASS PDFLayerController;
+OBJC_CLASS PDFSelection;
OBJC_CLASS WKPDFLayerControllerDelegate;
namespace CoreIPC {
@@ -97,6 +99,11 @@
virtual bool isEditingCommandEnabled(const String&) OVERRIDE;
virtual bool handlesPageScaleFactor() OVERRIDE;
+ virtual unsigned countFindMatches(const String& target, WebCore::FindOptions, unsigned maxMatchCount) OVERRIDE;
+ virtual bool findString(const String& target, WebCore::FindOptions, unsigned maxMatchCount) OVERRIDE;
+
+ PDFSelection *nextMatchForString(const String& target, BOOL searchForward, BOOL caseSensitive, BOOL wrapSearch, PDFSelection *initialSelection, BOOL startInSelection);
+
// ScrollableArea functions.
virtual void setScrollOffset(const WebCore::IntPoint&) OVERRIDE;
virtual void invalidateScrollbarRect(WebCore::Scrollbar*, const WebCore::IntRect&) OVERRIDE;
@@ -129,6 +136,8 @@
WebCore::IntPoint m_lastMousePositionInPluginCoordinates;
String m_temporaryPDFUUID;
+
+ String m_lastFoundString;
RetainPtr<WKPDFLayerControllerDelegate> m_pdfLayerControllerDelegate;
};
Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm 2012-12-25 11:08:22 UTC (rev 138461)
@@ -828,7 +828,6 @@
WebProcess::shared().connection()->send(Messages::WebContext::SetPasteboardBufferForType(NSGeneralPboard, type, handle, buffer->size()), 0);
}
}
-
}
IntPoint PDFPlugin::convertFromPDFViewToRootView(const IntPoint& point) const
@@ -849,6 +848,97 @@
webFrame()->page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(attributedString, dictionaryPopupInfo));
}
+unsigned PDFPlugin::countFindMatches(const String& target, WebCore::FindOptions options, unsigned maxMatchCount)
+{
+ if (!target.length())
+ return 0;
+
+ int nsOptions = (options & FindOptionsCaseInsensitive) ? NSCaseInsensitiveSearch : 0;
+
+ return [[pdfDocument().get() findString:target withOptions:nsOptions] count];
+}
+
+PDFSelection *PDFPlugin::nextMatchForString(const String& target, BOOL searchForward, BOOL caseSensitive, BOOL wrapSearch, PDFSelection *initialSelection, BOOL startInSelection)
+{
+ if (!target.length())
+ return nil;
+
+ NSStringCompareOptions options = 0;
+ if (!searchForward)
+ options |= NSBackwardsSearch;
+
+ if (!caseSensitive)
+ options |= NSCaseInsensitiveSearch;
+
+ PDFDocument *document = pdfDocument().get();
+
+ PDFSelection *selectionForInitialSearch = [initialSelection copy];
+ if (startInSelection) {
+ // Initially we want to include the selected text in the search. So we must modify the starting search
+ // selection to fit PDFDocument's search requirements: selection must have a length >= 1, begin before
+ // the current selection (if searching forwards) or after (if searching backwards).
+ int initialSelectionLength = [[initialSelection string] length];
+ if (searchForward) {
+ [selectionForInitialSearch extendSelectionAtStart:1];
+ [selectionForInitialSearch extendSelectionAtEnd:-initialSelectionLength];
+ } else {
+ [selectionForInitialSearch extendSelectionAtEnd:1];
+ [selectionForInitialSearch extendSelectionAtStart:-initialSelectionLength];
+ }
+ }
+
+ PDFSelection *foundSelection = [document findString:target fromSelection:selectionForInitialSearch withOptions:options];
+ [selectionForInitialSearch release];
+
+ // If we first searched in the selection, and we found the selection, search again from just past the selection.
+ if (startInSelection && [foundSelection isEqual:initialSelection])
+ foundSelection = [document findString:target fromSelection:initialSelection withOptions:options];
+
+ if (!foundSelection && wrapSearch)
+ foundSelection = [document findString:target fromSelection:nil withOptions:options];
+
+ return foundSelection;
+}
+
+bool PDFPlugin::findString(const String& target, WebCore::FindOptions options, unsigned maxMatchCount)
+{
+ BOOL searchForward = !(options & FindOptionsBackwards);
+ BOOL caseSensitive = !(options & FindOptionsCaseInsensitive);
+ BOOL wrapSearch = options & FindOptionsWrapAround;
+
+ unsigned matchCount;
+ if (!maxMatchCount) {
+ // If the max was zero, any result means we exceeded the max. We can skip computing the actual count.
+ matchCount = static_cast<unsigned>(kWKMoreThanMaximumMatchCount);
+ } else {
+ matchCount = countFindMatches(target, options, maxMatchCount);
+ if (matchCount > maxMatchCount)
+ matchCount = static_cast<unsigned>(kWKMoreThanMaximumMatchCount);
+ }
+
+ if (target.isEmpty()) {
+ PDFSelection* searchSelection = [m_pdfLayerController.get() searchSelection];
+ [m_pdfLayerController.get() findString:target caseSensitive:caseSensitive highlightMatches:YES];
+ [m_pdfLayerController.get() setSearchSelection:searchSelection];
+ m_lastFoundString = emptyString();
+ return false;
+ }
+
+ if (m_lastFoundString == target) {
+ PDFSelection *selection = nextMatchForString(target, searchForward, caseSensitive, wrapSearch, [m_pdfLayerController.get() searchSelection], NO);
+ if (!selection)
+ return false;
+
+ [m_pdfLayerController.get() setSearchSelection:selection];
+ [m_pdfLayerController.get() gotoSelection:selection];
+ } else {
+ [m_pdfLayerController.get() findString:target caseSensitive:caseSensitive highlightMatches:YES];
+ m_lastFoundString = target;
+ }
+
+ return matchCount > 0;
+}
+
} // namespace WebKit
#endif // ENABLE(PDFKIT_PLUGIN)
Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/SimplePDFPlugin.h 2012-12-25 11:08:22 UTC (rev 138461)
@@ -174,6 +174,9 @@
virtual bool shouldAllowScripting() OVERRIDE { return false; }
virtual bool shouldAllowNavigationFromDrags() { return true; }
+ virtual unsigned countFindMatches(const String&, WebCore::FindOptions, unsigned) OVERRIDE { return 0; }
+ virtual bool findString(const String&, WebCore::FindOptions, unsigned) OVERRIDE { return false; }
+
WebCore::IntSize m_scrollOffset;
private:
Modified: trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h 2012-12-25 11:08:22 UTC (rev 138461)
@@ -26,6 +26,7 @@
#ifndef Plugin_h
#define Plugin_h
+#include <WebCore/FindOptions.h>
#include <WebCore/GraphicsLayer.h>
#include <WebCore/KURL.h>
#include <WebCore/ScrollTypes.h>
@@ -254,6 +255,10 @@
virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; }
#endif
+ virtual unsigned countFindMatches(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0;
+
+ virtual bool findString(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0;
+
virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint& pointInLocalCoordinates) const;
virtual bool shouldAlwaysAutoStart() const { return false; }
Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginProxy.h 2012-12-25 11:08:22 UTC (rev 138461)
@@ -32,6 +32,7 @@
#include "Plugin.h"
#include "PluginProcess.h"
#include <WebCore/AffineTransform.h>
+#include <WebCore/FindOptions.h>
#include <WebCore/IntRect.h>
#include <WebCore/SecurityOrigin.h>
@@ -127,6 +128,9 @@
virtual WebCore::Scrollbar* horizontalScrollbar();
virtual WebCore::Scrollbar* verticalScrollbar();
+ virtual unsigned countFindMatches(const String&, WebCore::FindOptions, unsigned) OVERRIDE { return 0; }
+ virtual bool findString(const String&, WebCore::FindOptions, unsigned) OVERRIDE { return false; }
+
virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint&) const OVERRIDE;
float contentsScaleFactor();
Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp 2012-12-25 11:08:22 UTC (rev 138461)
@@ -736,6 +736,16 @@
initializePlugin();
}
+unsigned PluginView::countFindMatches(const String& target, WebCore::FindOptions options, unsigned maxMatchCount)
+{
+ return m_plugin->countFindMatches(target, options, maxMatchCount);
+}
+
+bool PluginView::findString(const String& target, WebCore::FindOptions options, unsigned maxMatchCount)
+{
+ return m_plugin->findString(target, options, maxMatchCount);
+}
+
PassOwnPtr<WebEvent> PluginView::createWebEvent(MouseEvent* event) const
{
WebEvent::Type type = WebEvent::NoType;
Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h 2012-12-25 11:08:22 UTC (rev 138461)
@@ -30,6 +30,7 @@
#include "Plugin.h"
#include "PluginController.h"
#include "WebFrame.h"
+#include <WebCore/FindOptions.h>
#include <WebCore/Image.h>
#include <WebCore/MediaCanStartListener.h>
#include <WebCore/PluginViewBase.h>
@@ -90,8 +91,11 @@
void pageScaleFactorDidChange();
void webPageDestroyed();
- virtual bool handleEditingCommand(const String& commandName, const String& argument);
- virtual bool isEditingCommandEnabled(const String& commandName);
+ bool handleEditingCommand(const String& commandName, const String& argument);
+ bool isEditingCommandEnabled(const String& commandName);
+
+ unsigned countFindMatches(const String& target, WebCore::FindOptions, unsigned maxMatchCount);
+ bool findString(const String& target, WebCore::FindOptions, unsigned maxMatchCount);
bool shouldAllowScripting();
Modified: trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp (138460 => 138461)
--- trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp 2012-12-25 09:26:38 UTC (rev 138460)
+++ trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp 2012-12-25 11:08:22 UTC (rev 138461)
@@ -26,6 +26,7 @@
#include "config.h"
#include "FindController.h"
+#include "PluginView.h"
#include "ShareableBitmap.h"
#include "WKPage.h"
#include "WebCoreArgumentCoders.h"
@@ -39,6 +40,7 @@
#include <WebCore/FrameView.h>
#include <WebCore/GraphicsContext.h>
#include <WebCore/Page.h>
+#include <WebCore/PluginDocument.h>
using namespace std;
using namespace WebCore;
@@ -65,14 +67,31 @@
{
}
+static PluginView* pluginViewForFrame(Frame* frame)
+{
+ if (!frame->document()->isPluginDocument())
+ return 0;
+
+ PluginDocument* pluginDocument = static_cast<PluginDocument*>(frame->document());
+ return static_cast<PluginView*>(pluginDocument->pluginWidget());
+}
+
void FindController::countStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
{
if (maxMatchCount == numeric_limits<unsigned>::max())
--maxMatchCount;
- unsigned matchCount = m_webPage->corePage()->markAllMatchesForText(string, core(options), false, maxMatchCount + 1);
- m_webPage->corePage()->unmarkAllTextMatches();
+ PluginView* pluginView = pluginViewForFrame(m_webPage->mainFrame());
+
+ unsigned matchCount;
+ if (pluginView)
+ matchCount = pluginView->countFindMatches(string, core(options), maxMatchCount + 1);
+ else {
+ matchCount = m_webPage->corePage()->markAllMatchesForText(string, core(options), false, maxMatchCount + 1);
+ m_webPage->corePage()->unmarkAllTextMatches();
+ }
+
// Check if we have more matches than allowed.
if (matchCount > maxMatchCount)
matchCount = static_cast<unsigned>(kWKMoreThanMaximumMatchCount);
@@ -93,11 +112,14 @@
void FindController::updateFindUIAfterPageScroll(bool found, const String& string, FindOptions options, unsigned maxMatchCount)
{
Frame* selectedFrame = frameWithSelection(m_webPage->corePage());
+
+ PluginView* pluginView = pluginViewForFrame(m_webPage->mainFrame());
bool shouldShowOverlay = false;
if (!found) {
- m_webPage->corePage()->unmarkAllTextMatches();
+ if (!pluginView)
+ m_webPage->corePage()->unmarkAllTextMatches();
// Clear the selection.
if (selectedFrame)
@@ -116,8 +138,13 @@
if (maxMatchCount == numeric_limits<unsigned>::max())
--maxMatchCount;
- m_webPage->corePage()->unmarkAllTextMatches();
- matchCount = m_webPage->corePage()->markAllMatchesForText(string, core(options), shouldShowHighlight, maxMatchCount + 1);
+ if (pluginView) {
+ matchCount = pluginView->countFindMatches(string, core(options), maxMatchCount + 1);
+ shouldShowOverlay = false;
+ } else {
+ m_webPage->corePage()->unmarkAllTextMatches();
+ matchCount = m_webPage->corePage()->markAllMatchesForText(string, core(options), shouldShowHighlight, maxMatchCount + 1);
+ }
// Check if we have more matches than allowed.
if (matchCount > maxMatchCount) {
@@ -155,7 +182,14 @@
void FindController::findString(const String& string, FindOptions options, unsigned maxMatchCount)
{
- bool found = m_webPage->corePage()->findString(string, core(options));
+ PluginView* pluginView = pluginViewForFrame(m_webPage->mainFrame());
+
+ bool found;
+
+ if (pluginView)
+ found = pluginView->findString(string, core(options), maxMatchCount);
+ else
+ found = m_webPage->corePage()->findString(string, core(options));
m_webPage->drawingArea()->dispatchAfterEnsuringUpdatedScrollPosition(WTF::bind(&FindController::updateFindUIAfterPageScroll, this, found, string, options, maxMatchCount));
}
@@ -165,7 +199,13 @@
if (m_findPageOverlay)
m_webPage->uninstallPageOverlay(m_findPageOverlay, false);
- m_webPage->corePage()->unmarkAllTextMatches();
+ PluginView* pluginView = pluginViewForFrame(m_webPage->mainFrame());
+
+ if (pluginView)
+ pluginView->findString(emptyString(), 0, 0);
+ else
+ m_webPage->corePage()->unmarkAllTextMatches();
+
hideFindIndicator();
}