Title: [189052] trunk/Source
Revision
189052
Author
timothy_hor...@apple.com
Date
2015-08-27 14:24:27 -0700 (Thu, 27 Aug 2015)

Log Message

Factor out Lookup invocation
https://bugs.webkit.org/show_bug.cgi?id=148509

Reviewed by Anders Carlsson.

There's a ton of duplicated code in legacy and modern WebKit to talk to
Lookup. And, it's pretty messy. As a first step to making it less messy,
make it so we only have it in one place instead of four (or two).

* editing/DictionaryPopupInfo.h:
Move DictionaryPopupInfo into WebCore. This was duplicated
in both legacy and modern WebKit.

* editing/mac/DictionaryLookup.h:
* editing/mac/DictionaryLookup.mm:
(WebCore::DictionaryLookup::rangeForSelection):
(WebCore::DictionaryLookup::rangeAtHitTestResult):
(WebCore::DictionaryLookup::stringForPDFSelection):
(WebCore::showPopupOrCreateAnimationController):
(WebCore::DictionaryLookup::showPopup):
(WebCore::DictionaryLookup::hidePopup):
(WebCore::DictionaryLookup::animationControllerForPopup):
(WebCore::rangeForDictionaryLookupForSelection): Deleted.
(WebCore::rangeForDictionaryLookupAtHitTestResult): Deleted.
(WebCore::dictionaryLookupForPDFSelection): Deleted.
Move DictionaryLookup stuff into a class for better names.

Move showPopup, hidePopup, and animationControllerForPopup here.
showPopup and animationControllerForPopup both bottleneck through
a single function, where previously we duplicated all of the code
for both of them, and in both legacy and modern WebKit.

showPopup and animationControllerForPopup take a block that they *may*
call if we have support for overriding Lookup's indicator with TextIndicator,
because the installation process is different per WebKit.

* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::selectClosestWordFromHitTestResultBasedOnLookup):
* testing/Internals.cpp:
(WebCore::Internals::rangeForDictionaryLookupAtLocation):
Adjust to the new naming.

* Shared/DictionaryPopupInfo.cpp: Removed.
* Shared/DictionaryPopupInfo.h: Removed.
Moved to WebCore.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<DictionaryPopupInfo>::encode):
(IPC::ArgumentCoder<DictionaryPopupInfo>::decode):
Add encode/decoders for DictionaryPopupInfo now that it's in WebCore.

* Shared/WebCoreArgumentCoders.h:
* Shared/WebHitTestResult.h:
* Shared/mac/ArgumentCodersMac.h:
* UIProcess/API/mac/WKView.mm:
(+[WKView hideWordDefinitionWindow]):
(-[WKView _dismissContentRelativeChildWindows]):
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::didPerformDictionaryLookup):
* UIProcess/mac/WKImmediateActionController.mm:
(-[WKImmediateActionController _animationControllerForText]):
* UIProcess/mac/WebPageProxyMac.mm:
* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::showDefinitionForAttributedString):
(WebKit::PDFPlugin::lookupTextAtLocation):
* WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation):
(WebKit::WebPage::performDictionaryLookupForSelection):
(WebKit::WebPage::dictionaryPopupInfoForRange):
(WebKit::WebPage::dictionaryPopupInfoForSelectionInPDFPlugin):
(WebKit::WebPage::lookupTextAtLocation):
Adjust to new names and move stuff to WebCore.

* WebKit.xcodeproj/project.pbxproj:

* WebView/DictionaryPopupInfo.h: Removed.
Move to WebCore.

* WebView/WebHTMLView.mm:
(-[WebHTMLView _lookUpInDictionaryFromMenu:]):
DictionaryPopupInfo keeps a TextIndicatorData, not a TextIndicator.

* WebView/WebImmediateActionController.mm:
(-[WebImmediateActionController _animationControllerForDataDetectedLink]):
(dictionaryPopupInfoForRange):
(-[WebImmediateActionController _animationControllerForText]):
* WebView/WebView.mm:
(-[WebView _prepareForDictionaryLookup]):
(-[WebView _animationControllerForDictionaryLookupPopupInfo:]):
(-[WebView _setTextIndicator:withLifetime:]):
(-[WebView _showDictionaryLookupPopup:]):
* WebView/WebViewInternal.h:
Move a bunch of code to WebCore.
Factor some that has to stay out into _prepareForDictionaryLookup.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (189051 => 189052)


--- trunk/Source/WebCore/ChangeLog	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebCore/ChangeLog	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1,3 +1,47 @@
+2015-08-27  Timothy Horton  <timothy_hor...@apple.com>
+
+        Factor out Lookup invocation
+        https://bugs.webkit.org/show_bug.cgi?id=148509
+
+        Reviewed by Anders Carlsson.
+
+        There's a ton of duplicated code in legacy and modern WebKit to talk to
+        Lookup. And, it's pretty messy. As a first step to making it less messy,
+        make it so we only have it in one place instead of four (or two).
+
+        * editing/DictionaryPopupInfo.h:
+        Move DictionaryPopupInfo into WebCore. This was duplicated
+        in both legacy and modern WebKit.
+
+        * editing/mac/DictionaryLookup.h:
+        * editing/mac/DictionaryLookup.mm:
+        (WebCore::DictionaryLookup::rangeForSelection):
+        (WebCore::DictionaryLookup::rangeAtHitTestResult):
+        (WebCore::DictionaryLookup::stringForPDFSelection):
+        (WebCore::showPopupOrCreateAnimationController):
+        (WebCore::DictionaryLookup::showPopup):
+        (WebCore::DictionaryLookup::hidePopup):
+        (WebCore::DictionaryLookup::animationControllerForPopup):
+        (WebCore::rangeForDictionaryLookupForSelection): Deleted.
+        (WebCore::rangeForDictionaryLookupAtHitTestResult): Deleted.
+        (WebCore::dictionaryLookupForPDFSelection): Deleted.
+        Move DictionaryLookup stuff into a class for better names.
+
+        Move showPopup, hidePopup, and animationControllerForPopup here.
+        showPopup and animationControllerForPopup both bottleneck through
+        a single function, where previously we duplicated all of the code
+        for both of them, and in both legacy and modern WebKit.
+
+        showPopup and animationControllerForPopup take a block that they *may*
+        call if we have support for overriding Lookup's indicator with TextIndicator,
+        because the installation process is different per WebKit.
+
+        * page/mac/EventHandlerMac.mm:
+        (WebCore::EventHandler::selectClosestWordFromHitTestResultBasedOnLookup):
+        * testing/Internals.cpp:
+        (WebCore::Internals::rangeForDictionaryLookupAtLocation):
+        Adjust to the new naming.
+
 2015-08-27  Jon Davis  <j...@apple.com>
 
         Add IndexedDB to the feature status page.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (189051 => 189052)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1139,6 +1139,7 @@
 		2D5002F81B56D7810020AAF7 /* DOMPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D5002F71B56D7810020AAF7 /* DOMPath.cpp */; };
 		2D5002FB1B56D7990020AAF7 /* PathUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D5002F91B56D7990020AAF7 /* PathUtilities.cpp */; };
 		2D5002FC1B56D7990020AAF7 /* PathUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5002FA1B56D7990020AAF7 /* PathUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		2D5646B01B8F8493003C4994 /* DictionaryPopupInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5646AF1B8F8493003C4994 /* DictionaryPopupInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2D58D8551A15F65F00A5F726 /* DataDetection.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D58D8531A15F65F00A5F726 /* DataDetection.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2D58D8561A15F65F00A5F726 /* DataDetection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D58D8541A15F65F00A5F726 /* DataDetection.mm */; };
 		2D59F1BF1A0044C6001F3D29 /* DataDetectorsSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -8351,6 +8352,7 @@
 		2D5002F71B56D7810020AAF7 /* DOMPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMPath.cpp; sourceTree = "<group>"; };
 		2D5002F91B56D7990020AAF7 /* PathUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PathUtilities.cpp; sourceTree = "<group>"; };
 		2D5002FA1B56D7990020AAF7 /* PathUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PathUtilities.h; sourceTree = "<group>"; };
+		2D5646AF1B8F8493003C4994 /* DictionaryPopupInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictionaryPopupInfo.h; sourceTree = "<group>"; };
 		2D58D8531A15F65F00A5F726 /* DataDetection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetection.h; sourceTree = "<group>"; };
 		2D58D8541A15F65F00A5F726 /* DataDetection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetection.mm; sourceTree = "<group>"; };
 		2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetectorsSPI.h; sourceTree = "<group>"; };
@@ -17977,6 +17979,7 @@
 				CECADFC3153778FF00E37068 /* DictationAlternative.h */,
 				CECADFC4153778FF00E37068 /* DictationCommand.cpp */,
 				CECADFC5153778FF00E37068 /* DictationCommand.h */,
+				2D5646AF1B8F8493003C4994 /* DictionaryPopupInfo.h */,
 				93309D93099E64910056E581 /* EditAction.h */,
 				93309D94099E64910056E581 /* EditCommand.cpp */,
 				93309D95099E64910056E581 /* EditCommand.h */,
@@ -24374,6 +24377,7 @@
 				31288E750E3005D6003619AE /* CSSKeyframesRule.h in Headers */,
 				BC772E131331620C001EC9CE /* CSSLineBoxContainValue.h in Headers */,
 				A80E6D030A1989CA007FB8C5 /* CSSMediaRule.h in Headers */,
+				2D5646B01B8F8493003C4994 /* DictionaryPopupInfo.h in Headers */,
 				F98FFF4511A2676200F548E8 /* CSSOMUtils.h in Headers */,
 				A80E6D000A1989CA007FB8C5 /* CSSPageRule.h in Headers */,
 				BC772B3E0C4EA91E0083285F /* CSSParser.h in Headers */,

Added: trunk/Source/WebCore/editing/DictionaryPopupInfo.h (0 => 189052)


--- trunk/Source/WebCore/editing/DictionaryPopupInfo.h	                        (rev 0)
+++ trunk/Source/WebCore/editing/DictionaryPopupInfo.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2014-2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DictionaryPopupInfo_h
+#define DictionaryPopupInfo_h
+
+#include "FloatPoint.h"
+#include "TextIndicator.h"
+#include <wtf/RetainPtr.h>
+
+OBJC_CLASS NSAttributedString;
+OBJC_CLASS NSDictionary;
+
+namespace WebCore {
+
+struct DictionaryPopupInfo {
+    FloatPoint origin;
+    TextIndicatorData textIndicator;
+#if PLATFORM(COCOA)
+    RetainPtr<NSDictionary> options;
+    RetainPtr<NSAttributedString> attributedString;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // DictionaryPopupInfo_h

Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.h (189051 => 189052)


--- trunk/Source/WebCore/editing/mac/DictionaryLookup.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -28,21 +28,42 @@
 
 #if PLATFORM(MAC)
 
+#include "DictionaryPopupInfo.h"
+#include <functional>
 #include <wtf/PassRefPtr.h>
 
-OBJC_CLASS NSDictionary;
+OBJC_CLASS NSString;
+OBJC_CLASS NSView;
 OBJC_CLASS PDFSelection;
 
+// This file is included in Internals.cpp, so we can't use ObjC outright.
+#if defined(__OBJC__) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+#include "NSImmediateActionGestureRecognizerSPI.h"
+#define PlatformAnimationController id<NSImmediateActionAnimationController>
+#else
+#define PlatformAnimationController void*
+#endif
+
 namespace WebCore {
 
 class HitTestResult;
 class Range;
 class VisibleSelection;
 
-WEBCORE_EXPORT PassRefPtr<Range> rangeForDictionaryLookupForSelection(const VisibleSelection&, NSDictionary **options);
-WEBCORE_EXPORT PassRefPtr<Range> rangeForDictionaryLookupAtHitTestResult(const HitTestResult&, NSDictionary **options);
-WEBCORE_EXPORT NSString *dictionaryLookupForPDFSelection(PDFSelection *, NSDictionary **options);
+class DictionaryLookup {
+public:
+    WEBCORE_EXPORT static PassRefPtr<Range> rangeForSelection(const VisibleSelection&, NSDictionary **options);
+    WEBCORE_EXPORT static PassRefPtr<Range> rangeAtHitTestResult(const HitTestResult&, NSDictionary **options);
+    WEBCORE_EXPORT static NSString *stringForPDFSelection(PDFSelection *, NSDictionary **options);
 
+    // FIXME: Should move/unify dictionaryPopupInfoForRange here too.
+
+    WEBCORE_EXPORT static void showPopup(const DictionaryPopupInfo&, NSView *, std::function<void(TextIndicator&)> textIndicatorInstallationCallback);
+    WEBCORE_EXPORT static void hidePopup();
+
+    WEBCORE_EXPORT static PlatformAnimationController animationControllerForPopup(const DictionaryPopupInfo&, NSView *, std::function<void(TextIndicator&)> textIndicatorInstallationCallback);
+};
+
 } // namespace WebCore
 
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.mm (189051 => 189052)


--- trunk/Source/WebCore/editing/mac/DictionaryLookup.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -35,6 +35,7 @@
 #import "HTMLConverter.h"
 #import "HitTestResult.h"
 #import "LookupSPI.h"
+#import "NSImmediateActionGestureRecognizerSPI.h"
 #import "Page.h"
 #import "Range.h"
 #import "RenderObject.h"
@@ -47,6 +48,8 @@
 #import <PDFKit/PDFKit.h>
 #import <wtf/RefPtr.h>
 
+SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUTermOptionDisableSearchTermIndicator, NSString *)
+
 namespace WebCore {
 
 static bool selectionContainsPosition(const VisiblePosition& position, const VisibleSelection& selection)
@@ -61,7 +64,7 @@
     return selectedRange->contains(position);
 }
 
-PassRefPtr<Range> rangeForDictionaryLookupForSelection(const VisibleSelection& selection, NSDictionary **options)
+PassRefPtr<Range> DictionaryLookup::rangeForSelection(const VisibleSelection& selection, NSDictionary **options)
 {
     RefPtr<Range> selectedRange = selection.toNormalizedRange();
     if (!selectedRange)
@@ -87,7 +90,7 @@
     return selectedRange.release();
 }
 
-PassRefPtr<Range> rangeForDictionaryLookupAtHitTestResult(const HitTestResult& hitTestResult, NSDictionary **options)
+PassRefPtr<Range> DictionaryLookup::rangeAtHitTestResult(const HitTestResult& hitTestResult, NSDictionary **options)
 {
     Node* node = hitTestResult.innerNonSharedNode();
     if (!node)
@@ -113,7 +116,7 @@
     // If we hit the selection, use that instead of letting Lookup decide the range.
     VisibleSelection selection = frame->page()->focusController().focusedOrMainFrame().selection().selection();
     if (selectionContainsPosition(position, selection))
-        return rangeForDictionaryLookupForSelection(selection, options);
+        return DictionaryLookup::rangeForSelection(selection, options);
 
     VisibleSelection selectionAccountingForLineRules = VisibleSelection(position);
     selectionAccountingForLineRules.expandUsingGranularity(WordGranularity);
@@ -150,7 +153,7 @@
     charactersAddedAfterEnd = selection.string.length - originalLength - charactersAddedBeforeStart;
 }
 
-NSString *dictionaryLookupForPDFSelection(PDFSelection *selection, NSDictionary **options)
+NSString *DictionaryLookup::stringForPDFSelection(PDFSelection *selection, NSDictionary **options)
 {
     // Don't do anything if there is no character at the point.
     if (!selection || !selection.string.length)
@@ -185,6 +188,69 @@
     return selection.string;
 }
 
+static PlatformAnimationController showPopupOrCreateAnimationController(bool createAnimationController, const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, std::function<void(TextIndicator&)> textIndicatorInstallationCallback)
+{
+    if (!getLULookupDefinitionModuleClass())
+        return nil;
+
+    RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([(NSDictionary *)dictionaryPopupInfo.options.get() mutableCopy]);
+
+    auto textIndicator = TextIndicator::create(dictionaryPopupInfo.textIndicator);
+
+    if (canLoadLUTermOptionDisableSearchTermIndicator() && textIndicator.get().contentImage()) {
+        textIndicatorInstallationCallback(textIndicator.get());
+        [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
+
+        if ([getLULookupDefinitionModuleClass() respondsToSelector:@selector(showDefinitionForTerm:relativeToRect:ofView:options:)]) {
+            FloatRect firstTextRectInViewCoordinates = textIndicator.get().textRectsInBoundingRectCoordinates()[0];
+            firstTextRectInViewCoordinates.moveBy(textIndicator.get().textBoundingRectInRootViewCoordinates().location());
+            if (createAnimationController) {
+#if  __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+                return [getLULookupDefinitionModuleClass() lookupAnimationControllerForTerm:dictionaryPopupInfo.attributedString.get() relativeToRect:firstTextRectInViewCoordinates ofView:view options:mutableOptions.get()];
+#else
+                return nil;
+#endif
+            }
+            [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.get() relativeToRect:firstTextRectInViewCoordinates ofView:view options:mutableOptions.get()];
+            return nil;
+        }
+    }
+
+    NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
+
+    // Convert to screen coordinates.
+    textBaselineOrigin = [view convertPoint:textBaselineOrigin toView:nil];
+    textBaselineOrigin = [view.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
+
+    if (createAnimationController) {
+#if  __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+        return [getLULookupDefinitionModuleClass() lookupAnimationControllerForTerm:dictionaryPopupInfo.attributedString.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
+#else
+        return nil;
+#endif
+    }
+
+    [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
+    return nil;
+}
+
+void DictionaryLookup::showPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, std::function<void(TextIndicator&)> textIndicatorInstallationCallback)
+{
+    showPopupOrCreateAnimationController(false, dictionaryPopupInfo, view, textIndicatorInstallationCallback);
+}
+
+void DictionaryLookup::hidePopup()
+{
+    if (!getLULookupDefinitionModuleClass())
+        return;
+    [getLULookupDefinitionModuleClass() hideDefinition];
+}
+
+PlatformAnimationController DictionaryLookup::animationControllerForPopup(const DictionaryPopupInfo& dictionaryPopupInfo, NSView *view, std::function<void(TextIndicator&)> textIndicatorInstallationCallback)
+{
+    return showPopupOrCreateAnimationController(true, dictionaryPopupInfo, view, textIndicatorInstallationCallback);
+}
+
 } // namespace WebCore
 
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebCore/page/mac/EventHandlerMac.mm (189051 => 189052)


--- trunk/Source/WebCore/page/mac/EventHandlerMac.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebCore/page/mac/EventHandlerMac.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1079,7 +1079,7 @@
         return VisibleSelection();
 
     NSDictionary *options = nil;
-    if (RefPtr<Range> range = rangeForDictionaryLookupAtHitTestResult(result, &options))
+    if (RefPtr<Range> range = DictionaryLookup::rangeAtHitTestResult(result, &options))
         return VisibleSelection(*range);
 
     return VisibleSelection();

Modified: trunk/Source/WebCore/testing/Internals.cpp (189051 => 189052)


--- trunk/Source/WebCore/testing/Internals.cpp	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebCore/testing/Internals.cpp	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1269,7 +1269,7 @@
     
     HitTestResult result = document->frame()->mainFrame().eventHandler().hitTestResultAtPoint(IntPoint(x, y));
     NSDictionary *options = nullptr;
-    return rangeForDictionaryLookupAtHitTestResult(result, &options);
+    return DictionaryLookup::rangeAtHitTestResult(result, &options);
 #else
     UNUSED_PARAM(x);
     UNUSED_PARAM(y);

Modified: trunk/Source/WebKit/ChangeLog (189051 => 189052)


--- trunk/Source/WebKit/ChangeLog	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit/ChangeLog	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1,3 +1,12 @@
+2015-08-27  Timothy Horton  <timothy_hor...@apple.com>
+
+        Factor out Lookup invocation
+        https://bugs.webkit.org/show_bug.cgi?id=148509
+
+        Reviewed by Anders Carlsson.
+
+        * WebKit.xcodeproj/project.pbxproj:
+
 2015-08-26  Brent Fulgham  <bfulg...@apple.com>
 
         Correct build after r188982.

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (189051 => 189052)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2015-08-27 21:24:27 UTC (rev 189052)
@@ -101,7 +101,6 @@
 		2D25396718CE85C200270222 /* WebSharingServicePickerController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D25396518CE85C200270222 /* WebSharingServicePickerController.mm */; };
 		2DD632C219E5D1F0002E9C7B /* WebSelectionServiceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DD632C019E5D1F0002E9C7B /* WebSelectionServiceController.h */; };
 		2DD632C319E5D1F0002E9C7B /* WebSelectionServiceController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DD632C119E5D1F0002E9C7B /* WebSelectionServiceController.mm */; };
-		2DF064A91A2DD53C00DBB354 /* DictionaryPopupInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DF064A81A2DD53C00DBB354 /* DictionaryPopupInfo.h */; };
 		312E2FE514E48182007CCA18 /* WebNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 312E2FE314E48182007CCA18 /* WebNotification.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		312E2FE614E48182007CCA18 /* WebNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = 312E2FE414E48182007CCA18 /* WebNotification.mm */; };
 		312E2FE914E48215007CCA18 /* WebNotificationInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 312E2FE814E48215007CCA18 /* WebNotificationInternal.h */; };
@@ -563,7 +562,6 @@
 		2D81DAB303EB0B2D00A80166 /* WebFormDelegate.m */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebFormDelegate.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		2DD632C019E5D1F0002E9C7B /* WebSelectionServiceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSelectionServiceController.h; sourceTree = "<group>"; };
 		2DD632C119E5D1F0002E9C7B /* WebSelectionServiceController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSelectionServiceController.mm; sourceTree = "<group>"; };
-		2DF064A81A2DD53C00DBB354 /* DictionaryPopupInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictionaryPopupInfo.h; sourceTree = "<group>"; };
 		312E2FE314E48182007CCA18 /* WebNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNotification.h; sourceTree = "<group>"; };
 		312E2FE414E48182007CCA18 /* WebNotification.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNotification.mm; sourceTree = "<group>"; };
 		312E2FE814E48215007CCA18 /* WebNotificationInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNotificationInternal.h; sourceTree = "<group>"; };
@@ -1321,7 +1319,6 @@
 				F52CA6BD02DF9D0F018635CA /* HTML */,
 				51E94C0706C02CA300A9B09E /* PDF */,
 				A10C1D79182030190036883A /* ios */,
-				2DF064A81A2DD53C00DBB354 /* DictionaryPopupInfo.h */,
 				8373435A0624EE0D00F3B289 /* WebArchive.h */,
 				8373435B0624EE0D00F3B289 /* WebArchive.mm */,
 				44BB8B131241A022001E3A22 /* WebArchiveInternal.h */,
@@ -1840,7 +1837,6 @@
 				A10C1D8C1820305E0036883A /* WebPDFViewIPhone.h in Headers */,
 				9398106D0824BF01008DF038 /* WebKitErrorsPrivate.h in Headers */,
 				CD8BFCE815531224005AFB25 /* WebKitFullScreenListener.h in Headers */,
-				2DF064A91A2DD53C00DBB354 /* DictionaryPopupInfo.h in Headers */,
 				9398101D0824BF01008DF038 /* WebKitLogging.h in Headers */,
 				9398101E0824BF01008DF038 /* WebKitNSStringExtras.h in Headers */,
 				1AAF58940EDCCF15008D883D /* WebKitPluginAgent.defs in Headers */,

Modified: trunk/Source/WebKit/mac/ChangeLog (189051 => 189052)


--- trunk/Source/WebKit/mac/ChangeLog	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit/mac/ChangeLog	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1,3 +1,30 @@
+2015-08-27  Timothy Horton  <timothy_hor...@apple.com>
+
+        Factor out Lookup invocation
+        https://bugs.webkit.org/show_bug.cgi?id=148509
+
+        Reviewed by Anders Carlsson.
+
+        * WebView/DictionaryPopupInfo.h: Removed.
+        Move to WebCore.
+
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView _lookUpInDictionaryFromMenu:]):
+        DictionaryPopupInfo keeps a TextIndicatorData, not a TextIndicator.
+
+        * WebView/WebImmediateActionController.mm:
+        (-[WebImmediateActionController _animationControllerForDataDetectedLink]):
+        (dictionaryPopupInfoForRange):
+        (-[WebImmediateActionController _animationControllerForText]):
+        * WebView/WebView.mm:
+        (-[WebView _prepareForDictionaryLookup]):
+        (-[WebView _animationControllerForDictionaryLookupPopupInfo:]):
+        (-[WebView _setTextIndicator:withLifetime:]):
+        (-[WebView _showDictionaryLookupPopup:]):
+        * WebView/WebViewInternal.h:
+        Move a bunch of code to WebCore.
+        Factor some that has to stay out into _prepareForDictionaryLookup.
+
 2015-08-27  Brian Burg  <bb...@apple.com>
 
         Web Inspector: FrontendChannel should know its own connection type

Deleted: trunk/Source/WebKit/mac/WebView/DictionaryPopupInfo.h (189051 => 189052)


--- trunk/Source/WebKit/mac/WebView/DictionaryPopupInfo.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit/mac/WebView/DictionaryPopupInfo.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#if PLATFORM(MAC)
-
-#import <WebCore/FloatPoint.h>
-#import <wtf/RetainPtr.h>
-
-@class NSAttributedString;
-@class NSDictionary;
-
-namespace WebCore {
-class TextIndicator;
-};
-
-struct DictionaryPopupInfo {
-    NSPoint origin;
-    RetainPtr<NSDictionary> options;
-    RetainPtr<NSAttributedString> attributedString;
-    RefPtr<WebCore::TextIndicator> textIndicator;
-};
-
-#endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit/mac/WebView/WebHTMLView.mm (189051 => 189052)


--- trunk/Source/WebKit/mac/WebView/WebHTMLView.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLView.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -34,7 +34,6 @@
 #import "DOMDocumentInternal.h"
 #import "DOMNodeInternal.h"
 #import "DOMRangeInternal.h"
-#import "DictionaryPopupInfo.h"
 #import "WebArchive.h"
 #import "WebClipView.h"
 #import "WebContextMenuClient.h"
@@ -82,6 +81,7 @@
 #import <WebCore/ColorMac.h>
 #import <WebCore/ContextMenu.h>
 #import <WebCore/ContextMenuController.h>
+#import <WebCore/DictionaryLookup.h>
 #import <WebCore/Document.h>
 #import <WebCore/DocumentFragment.h>
 #import <WebCore/DocumentMarkerController.h>
@@ -5689,7 +5689,8 @@
     DictionaryPopupInfo info;
     info.attributedString = attrString;
     info.origin = coreFrame->view()->contentsToWindow(enclosingIntRect(rect)).location();
-    info.textIndicator = TextIndicator::createWithSelectionInFrame(*coreFrame, TextIndicatorOptionIncludeSnapshotWithSelectionHighlight, TextIndicatorPresentationTransition::BounceAndCrossfade);
+    if (auto textIndicator = TextIndicator::createWithSelectionInFrame(*coreFrame, TextIndicatorOptionIncludeSnapshotWithSelectionHighlight, TextIndicatorPresentationTransition::BounceAndCrossfade))
+        info.textIndicator = textIndicator->data();
     [[self _webView] _showDictionaryLookupPopup:info];
 }
 

Modified: trunk/Source/WebKit/mac/WebView/WebImmediateActionController.mm (189051 => 189052)


--- trunk/Source/WebKit/mac/WebView/WebImmediateActionController.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit/mac/WebView/WebImmediateActionController.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -30,7 +30,6 @@
 #import "DOMElementInternal.h"
 #import "DOMNodeInternal.h"
 #import "DOMRangeInternal.h"
-#import "DictionaryPopupInfo.h"
 #import "WebElementDictionary.h"
 #import "WebFrameInternal.h"
 #import "WebHTMLView.h"
@@ -454,6 +453,7 @@
     if (!linkRange)
         return nullptr;
     RefPtr<TextIndicator> indicator = TextIndicator::createWithRange(*linkRange, TextIndicatorOptionDefault, TextIndicatorPresentationTransition::FadeIn);
+    indicator->data().textBoundingRectInRootViewCoordinates = [_webView _convertRectFromRootView:indicator->textBoundingRectInRootViewCoordinates()];
 
     _currentActionContext = [actionContext contextForView:_webView altMode:YES interactionStartedHandler:^() {
     } interactionChangedHandler:^() {
@@ -510,7 +510,9 @@
     }];
 
     popupInfo.attributedString = scaledNSAttributedString.get();
-    popupInfo.textIndicator = TextIndicator::createWithRange(range, TextIndicatorOptionDefault, presentationTransition);
+
+    if (auto textIndicator = TextIndicator::createWithRange(range, TextIndicatorOptionDefault, presentationTransition))
+        popupInfo.textIndicator = textIndicator->data();
     return popupInfo;
 }
 
@@ -528,7 +530,7 @@
         return nil;
 
     NSDictionary *options = nil;
-    RefPtr<Range> dictionaryRange = rangeForDictionaryLookupAtHitTestResult(_hitTestResult, &options);
+    RefPtr<Range> dictionaryRange = DictionaryLookup::rangeAtHitTestResult(_hitTestResult, &options);
     if (!dictionaryRange)
         return nil;
 

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (189051 => 189052)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -35,7 +35,6 @@
 #import "DOMDocumentInternal.h"
 #import "DOMNodeInternal.h"
 #import "DOMRangeInternal.h"
-#import "DictionaryPopupInfo.h"
 #import "StorageThread.h"
 #import "WebAlternativeTextClient.h"
 #import "WebApplicationCacheInternal.h"
@@ -123,6 +122,7 @@
 #import <WebCore/Chrome.h>
 #import <WebCore/ColorMac.h>
 #import <WebCore/DatabaseManager.h>
+#import <WebCore/DictionaryLookup.h>
 #import <WebCore/Document.h>
 #import <WebCore/DocumentLoader.h>
 #import <WebCore/DragController.h>
@@ -295,7 +295,6 @@
 
 #if PLATFORM(MAC)
 SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUNotificationPopoverWillClose, NSString *)
-SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUTermOptionDisableSearchTermIndicator, NSString *)
 #endif
 
 #if !PLATFORM(IOS)
@@ -8551,29 +8550,14 @@
     if (!dictionaryPopupInfo.attributedString)
         return nil;
 
-    if (canLoadLUTermOptionDisableSearchTermIndicator() && canLoadLUNotificationPopoverWillClose() && dictionaryPopupInfo.textIndicator) {
-        if (!_private->hasInitializedLookupObserver) {
-            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_dictionaryLookupPopoverWillClose:) name:getLUNotificationPopoverWillClose() object:nil];
-            _private->hasInitializedLookupObserver = YES;
-        }
+    [self _prepareForDictionaryLookup];
 
-        RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([dictionaryPopupInfo.options mutableCopy]);
-        if (!mutableOptions)
-            mutableOptions = adoptNS([[NSMutableDictionary alloc] init]);
-        [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
-        [self _setTextIndicator:*dictionaryPopupInfo.textIndicator withLifetime:TextIndicatorWindowLifetime::Permanent];
+    DictionaryPopupInfo adjustedPopupInfo = dictionaryPopupInfo;
+    adjustedPopupInfo.textIndicator.textBoundingRectInRootViewCoordinates = [self _convertRectFromRootView:adjustedPopupInfo.textIndicator.textBoundingRectInRootViewCoordinates];
 
-        if ([getLULookupDefinitionModuleClass() respondsToSelector:@selector(lookupAnimationControllerForTerm:relativeToRect:ofView:options:)]) {
-            FloatRect firstTextRectInViewCoordinates = dictionaryPopupInfo.textIndicator->textRectsInBoundingRectCoordinates()[0];
-            firstTextRectInViewCoordinates.moveBy(dictionaryPopupInfo.textIndicator->textBoundingRectInRootViewCoordinates().location());
-            return [getLULookupDefinitionModuleClass() lookupAnimationControllerForTerm:dictionaryPopupInfo.attributedString.get() relativeToRect:[self _convertRectFromRootView:firstTextRectInViewCoordinates] ofView:self options:mutableOptions.get()];
-        }
-    }
-
-    // Convert to screen coordinates.
-    NSPoint textBaselineOrigin = [self.window convertRectToScreen:NSMakeRect(dictionaryPopupInfo.origin.x, dictionaryPopupInfo.origin.y, 0, 0)].origin;
-
-    return [getLULookupDefinitionModuleClass() lookupAnimationControllerForTerm:dictionaryPopupInfo.attributedString.get() atLocation:textBaselineOrigin options:dictionaryPopupInfo.options.get()];
+    return DictionaryLookup::animationControllerForPopup(adjustedPopupInfo, self, [self](TextIndicator& textIndicator) {
+        [self _setTextIndicator:textIndicator withLifetime:TextIndicatorWindowLifetime::Permanent];
+    });
 }
 #endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
 
@@ -8597,7 +8581,7 @@
     if (!_private->textIndicatorWindow)
         _private->textIndicatorWindow = std::make_unique<TextIndicatorWindow>(self);
 
-    NSRect textBoundingRectInWindowCoordinates = [self convertRect:[self _convertRectFromRootView:textIndicator.textBoundingRectInRootViewCoordinates()] toView:nil];
+    NSRect textBoundingRectInWindowCoordinates = [self convertRect:textIndicator.textBoundingRectInRootViewCoordinates() toView:nil];
     NSRect textBoundingRectInScreenCoordinates = [self.window convertRectToScreen:textBoundingRectInWindowCoordinates];
     _private->textIndicatorWindow->setTextIndicator(textIndicator, NSRectToCGRect(textBoundingRectInScreenCoordinates), lifetime);
 }
@@ -8615,35 +8599,30 @@
         _private->textIndicatorWindow->setAnimationProgress(progress);
 }
 
-- (void)_showDictionaryLookupPopup:(const DictionaryPopupInfo&)dictionaryPopupInfo
+- (void)_prepareForDictionaryLookup
 {
-    if (!dictionaryPopupInfo.attributedString)
+    if (_private->hasInitializedLookupObserver)
         return;
 
-    if (canLoadLUTermOptionDisableSearchTermIndicator() && canLoadLUNotificationPopoverWillClose() && dictionaryPopupInfo.textIndicator) {
-        if (!_private->hasInitializedLookupObserver) {
-            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_dictionaryLookupPopoverWillClose:) name:getLUNotificationPopoverWillClose() object:nil];
-            _private->hasInitializedLookupObserver = YES;
-        }
+    _private->hasInitializedLookupObserver = YES;
 
-        RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([dictionaryPopupInfo.options mutableCopy]);
-        if (!mutableOptions)
-            mutableOptions = adoptNS([[NSMutableDictionary alloc] init]);
-        [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
-        [self _setTextIndicator:*dictionaryPopupInfo.textIndicator withLifetime:TextIndicatorWindowLifetime::Permanent];
+    if (canLoadLUNotificationPopoverWillClose())
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_dictionaryLookupPopoverWillClose:) name:getLUNotificationPopoverWillClose() object:nil];
+}
 
-        if ([getLULookupDefinitionModuleClass() respondsToSelector:@selector(showDefinitionForTerm:relativeToRect:ofView:options:)]) {
-            FloatRect firstTextRectInViewCoordinates = dictionaryPopupInfo.textIndicator->textRectsInBoundingRectCoordinates()[0];
-            firstTextRectInViewCoordinates.moveBy(dictionaryPopupInfo.textIndicator->textBoundingRectInRootViewCoordinates().location());
-            [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.get() relativeToRect:[self _convertRectFromRootView:firstTextRectInViewCoordinates] ofView:self options:mutableOptions.get()];
-            return;
-        }
-    }
+- (void)_showDictionaryLookupPopup:(const DictionaryPopupInfo&)dictionaryPopupInfo
+{
+    if (!dictionaryPopupInfo.attributedString)
+        return;
 
-    // Convert to screen coordinates.
-    NSPoint textBaselineOrigin = [self.window convertRectToScreen:NSMakeRect(dictionaryPopupInfo.origin.x, dictionaryPopupInfo.origin.y, 0, 0)].origin;
+    [self _prepareForDictionaryLookup];
 
-    [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.get() atLocation:textBaselineOrigin options:dictionaryPopupInfo.options.get()];
+    DictionaryPopupInfo adjustedPopupInfo = dictionaryPopupInfo;
+    adjustedPopupInfo.textIndicator.textBoundingRectInRootViewCoordinates = [self _convertRectFromRootView:adjustedPopupInfo.textIndicator.textBoundingRectInRootViewCoordinates];
+
+    DictionaryLookup::showPopup(adjustedPopupInfo, self, [self](TextIndicator& textIndicator) {
+        [self _setTextIndicator:textIndicator withLifetime:TextIndicatorWindowLifetime::Permanent];
+    });
 }
 
 - (void)_dictionaryLookupPopoverWillClose:(NSNotification *)notification

Modified: trunk/Source/WebKit/mac/WebView/WebViewInternal.h (189051 => 189052)


--- trunk/Source/WebKit/mac/WebView/WebViewInternal.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit/mac/WebView/WebViewInternal.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -58,9 +58,9 @@
 class TextIndicator;
 class URL;
 struct DictationAlternative;
+struct DictionaryPopupInfo;
 }
 
-struct DictionaryPopupInfo;
 class WebMediaPlaybackTargetPicker;
 class WebSelectionServiceController;
 
@@ -269,9 +269,9 @@
 - (void)_setTextIndicator:(WebCore::TextIndicator&)textIndicator withLifetime:(WebCore::TextIndicatorWindowLifetime)lifetime;
 - (void)_clearTextIndicatorWithAnimation:(WebCore::TextIndicatorWindowDismissalAnimation)animation;
 - (void)_setTextIndicatorAnimationProgress:(float)progress;
-- (void)_showDictionaryLookupPopup:(const DictionaryPopupInfo&)dictionaryPopupInfo;
+- (void)_showDictionaryLookupPopup:(const WebCore::DictionaryPopupInfo&)dictionaryPopupInfo;
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
-- (id)_animationControllerForDictionaryLookupPopupInfo:(const DictionaryPopupInfo&)dictionaryPopupInfo;
+- (id)_animationControllerForDictionaryLookupPopupInfo:(const WebCore::DictionaryPopupInfo&)dictionaryPopupInfo;
 - (WebImmediateActionController *)_immediateActionController;
 #endif
 - (NSEvent *)_pressureEvent;

Modified: trunk/Source/WebKit2/CMakeLists.txt (189051 => 189052)


--- trunk/Source/WebKit2/CMakeLists.txt	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/CMakeLists.txt	2015-08-27 21:24:27 UTC (rev 189052)
@@ -217,7 +217,6 @@
     Shared/ChildProcess.cpp
     Shared/ChildProcessProxy.cpp
     Shared/ContextMenuContextData.cpp
-    Shared/DictionaryPopupInfo.cpp
     Shared/EditorState.cpp
     Shared/FontInfo.cpp
     Shared/LayerTreeContext.cpp

Modified: trunk/Source/WebKit2/ChangeLog (189051 => 189052)


--- trunk/Source/WebKit2/ChangeLog	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/ChangeLog	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1,3 +1,48 @@
+2015-08-27  Timothy Horton  <timothy_hor...@apple.com>
+
+        Factor out Lookup invocation
+        https://bugs.webkit.org/show_bug.cgi?id=148509
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/DictionaryPopupInfo.cpp: Removed.
+        * Shared/DictionaryPopupInfo.h: Removed.
+        Moved to WebCore.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<DictionaryPopupInfo>::encode):
+        (IPC::ArgumentCoder<DictionaryPopupInfo>::decode):
+        Add encode/decoders for DictionaryPopupInfo now that it's in WebCore.
+
+        * Shared/WebCoreArgumentCoders.h:
+        * Shared/WebHitTestResult.h:
+        * Shared/mac/ArgumentCodersMac.h:
+        * UIProcess/API/mac/WKView.mm:
+        (+[WKView hideWordDefinitionWindow]):
+        (-[WKView _dismissContentRelativeChildWindows]):
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::didPerformDictionaryLookup):
+        * UIProcess/mac/WKImmediateActionController.mm:
+        (-[WKImmediateActionController _animationControllerForText]):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        * WebKit2.xcodeproj/project.pbxproj:
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::showDefinitionForAttributedString):
+        (WebKit::PDFPlugin::lookupTextAtLocation):
+        * WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performDictionaryLookupAtLocation):
+        (WebKit::WebPage::performDictionaryLookupForSelection):
+        (WebKit::WebPage::dictionaryPopupInfoForRange):
+        (WebKit::WebPage::dictionaryPopupInfoForSelectionInPDFPlugin):
+        (WebKit::WebPage::lookupTextAtLocation):
+        Adjust to new names and move stuff to WebCore.
+
 2015-08-27  Brian Burg  <bb...@apple.com>
 
         Web Inspector: FrontendChannel should know its own connection type

Deleted: trunk/Source/WebKit2/Shared/DictionaryPopupInfo.cpp (189051 => 189052)


--- trunk/Source/WebKit2/Shared/DictionaryPopupInfo.cpp	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/Shared/DictionaryPopupInfo.cpp	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "DictionaryPopupInfo.h"
-
-#include "WebCoreArgumentCoders.h"
-
-#if PLATFORM(COCOA)
-#include "ArgumentCodersCF.h"
-#endif
-
-namespace WebKit {
-
-void DictionaryPopupInfo::encode(IPC::ArgumentEncoder& encoder) const
-{
-    encoder << origin;
-    encoder << textIndicator;
-
-#if PLATFORM(COCOA)
-    bool hadOptions = options;
-    encoder << hadOptions;
-    if (hadOptions)
-        IPC::encode(encoder, options.get());
-
-    encoder << attributedString;
-#endif
-}
-
-bool DictionaryPopupInfo::decode(IPC::ArgumentDecoder& decoder, DictionaryPopupInfo& result)
-{
-    if (!decoder.decode(result.origin))
-        return false;
-
-    if (!decoder.decode(result.textIndicator))
-        return false;
-
-#if PLATFORM(COCOA)
-    bool hadOptions;
-    if (!decoder.decode(hadOptions))
-        return false;
-    if (hadOptions) {
-        if (!IPC::decode(decoder, result.options))
-            return false;
-    }
-
-    if (!decoder.decode(result.attributedString))
-        return false;
-#endif
-    return true;
-}
-
-} // namespace WebKit

Deleted: trunk/Source/WebKit2/Shared/DictionaryPopupInfo.h (189051 => 189052)


--- trunk/Source/WebKit2/Shared/DictionaryPopupInfo.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/Shared/DictionaryPopupInfo.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef DictionaryPopupInfo_h
-#define DictionaryPopupInfo_h
-
-#include <WebCore/FloatPoint.h>
-#include <WebCore/TextIndicator.h>
-
-#if PLATFORM(COCOA)
-#include "AttributedString.h"
-#include <wtf/RetainPtr.h>
-#endif
-
-namespace IPC {
-class ArgumentDecoder;
-class ArgumentEncoder;
-}
-
-namespace WebKit {
-
-struct DictionaryPopupInfo {
-    void encode(IPC::ArgumentEncoder&) const;
-    static bool decode(IPC::ArgumentDecoder&, DictionaryPopupInfo&);
-
-    WebCore::FloatPoint origin;
-    WebCore::TextIndicatorData textIndicator;
-#if PLATFORM(COCOA)
-    RetainPtr<CFDictionaryRef> options;
-    AttributedString attributedString;
-#endif
-};
-
-} // namespace WebKit
-
-#endif // DictionaryPopupInfo_h

Modified: trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp (189051 => 189052)


--- trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp	2015-08-27 21:24:27 UTC (rev 189052)
@@ -36,6 +36,7 @@
 #include <WebCore/Cursor.h>
 #include <WebCore/DatabaseDetails.h>
 #include <WebCore/DictationAlternative.h>
+#include <WebCore/DictionaryPopupInfo.h>
 #include <WebCore/Editor.h>
 #include <WebCore/FileChooser.h>
 #include <WebCore/FilterOperation.h>
@@ -73,6 +74,7 @@
 
 #if PLATFORM(COCOA)
 #include "ArgumentCodersCF.h"
+#include "ArgumentCodersMac.h"
 #endif
 
 #if PLATFORM(IOS)
@@ -2203,4 +2205,52 @@
 }
 #endif
 
+void ArgumentCoder<DictionaryPopupInfo>::encode(IPC::ArgumentEncoder& encoder, const DictionaryPopupInfo& info)
+{
+    encoder << info.origin;
+    encoder << info.textIndicator;
+
+#if PLATFORM(COCOA)
+    bool hadOptions = info.options;
+    encoder << hadOptions;
+    if (hadOptions)
+        IPC::encode(encoder, info.options.get());
+
+    bool hadAttributedString = info.attributedString;
+    encoder << hadAttributedString;
+    if (hadAttributedString)
+        IPC::encode(encoder, info.attributedString.get());
+#endif
+}
+
+bool ArgumentCoder<DictionaryPopupInfo>::decode(IPC::ArgumentDecoder& decoder, DictionaryPopupInfo& result)
+{
+    if (!decoder.decode(result.origin))
+        return false;
+
+    if (!decoder.decode(result.textIndicator))
+        return false;
+
+#if PLATFORM(COCOA)
+    bool hadOptions;
+    if (!decoder.decode(hadOptions))
+        return false;
+    if (hadOptions) {
+        if (!IPC::decode(decoder, result.options))
+            return false;
+    } else
+        result.options = nullptr;
+
+    bool hadAttributedString;
+    if (!decoder.decode(hadAttributedString))
+        return false;
+    if (hadAttributedString) {
+        if (!IPC::decode(decoder, result.attributedString))
+            return false;
+    } else
+        result.attributedString = nullptr;
+#endif
+    return true;
+}
+
 } // namespace IPC

Modified: trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h (189051 => 189052)


--- trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -71,6 +71,7 @@
 struct CompositionUnderline;
 struct Cookie;
 struct DictationAlternative;
+struct DictionaryPopupInfo;
 struct FileChooserSettings;
 struct IDBDatabaseMetadata;
 struct IDBGetResult;
@@ -473,6 +474,11 @@
     static bool decode(ArgumentDecoder&, WebCore::TextIndicatorData&);
 };
 
+template<> struct ArgumentCoder<WebCore::DictionaryPopupInfo> {
+    static void encode(ArgumentEncoder&, const WebCore::DictionaryPopupInfo&);
+    static bool decode(ArgumentDecoder&, WebCore::DictionaryPopupInfo&);
+};
+
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
 template<> struct ArgumentCoder<WebCore::MediaPlaybackTargetContext> {
     static void encode(ArgumentEncoder&, const WebCore::MediaPlaybackTargetContext&);

Modified: trunk/Source/WebKit2/Shared/WebHitTestResult.h (189051 => 189052)


--- trunk/Source/WebKit2/Shared/WebHitTestResult.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/Shared/WebHitTestResult.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -21,8 +21,8 @@
 #define WebHitTestResult_h
 
 #include "APIObject.h"
-#include "DictionaryPopupInfo.h"
 #include "SharedMemory.h"
+#include <WebCore/DictionaryPopupInfo.h>
 #include <WebCore/FloatPoint.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/PageOverlay.h>
@@ -75,7 +75,7 @@
         RefPtr<WebCore::TextIndicator> detectedDataTextIndicator;
         WebCore::PageOverlay::PageOverlayID detectedDataOriginatingPageOverlay;
 
-        DictionaryPopupInfo dictionaryPopupInfo;
+        WebCore::DictionaryPopupInfo dictionaryPopupInfo;
 
         RefPtr<WebCore::TextIndicator> linkTextIndicator;
 

Modified: trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.h (189051 => 189052)


--- trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -28,6 +28,16 @@
 
 #include <wtf/RetainPtr.h>
 
+OBJC_CLASS NSArray;
+OBJC_CLASS NSAttributedString;
+OBJC_CLASS NSColor;
+OBJC_CLASS NSData;
+OBJC_CLASS NSDate;
+OBJC_CLASS NSDictionary;
+OBJC_CLASS NSFont;
+OBJC_CLASS NSNumber;
+OBJC_CLASS NSString;
+
 namespace IPC {
 
 class ArgumentEncoder;

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (189051 => 189052)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -83,6 +83,7 @@
 #import <WebCore/AXObjectCache.h>
 #import <WebCore/ColorMac.h>
 #import <WebCore/DataDetectorsSPI.h>
+#import <WebCore/DictionaryLookup.h>
 #import <WebCore/DragController.h>
 #import <WebCore/DragData.h>
 #import <WebCore/FloatRect.h>
@@ -4083,9 +4084,7 @@
 
 + (void)hideWordDefinitionWindow
 {
-    if (!getLULookupDefinitionModuleClass())
-        return;
-    [getLULookupDefinitionModuleClass() hideDefinition];
+    DictionaryLookup::hidePopup();
 }
 
 - (NSSize)minimumSizeForAutoLayout
@@ -4676,8 +4675,7 @@
         || [_data->_immediateActionController hasActiveImmediateAction]
 #endif
         ) {
-        if (Class lookupDefinitionModuleClass = getLULookupDefinitionModuleClass())
-            [lookupDefinitionModuleClass hideDefinition];
+        DictionaryLookup::hidePopup();
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
         DDActionsManager *actionsManager = [getDDActionsManagerClass() sharedManager];

Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (189051 => 189052)


--- trunk/Source/WebKit2/UIProcess/PageClient.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -239,7 +239,7 @@
 #if PLATFORM(MAC)
     virtual void pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus) = 0;
     virtual void setPluginComplexTextInputState(uint64_t pluginComplexTextInputIdentifier, PluginComplexTextInputState) = 0;
-    virtual void didPerformDictionaryLookup(const DictionaryPopupInfo&) = 0;
+    virtual void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&) = 0;
     virtual void dismissContentRelativeChildWindows(bool withAnimation = true) = 0;
     virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) = 0;
     virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeText) = 0;

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (189051 => 189052)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -155,6 +155,7 @@
 class RunLoopObserver;
 class SharedBuffer;
 class TextIndicator;
+struct DictionaryPopupInfo;
 struct FileChooserSettings;
 struct TextAlternativeWithRange;
 struct TextCheckingResult;
@@ -201,7 +202,6 @@
 class WebsiteDataStore;
 struct AttributedString;
 struct ColorSpaceData;
-struct DictionaryPopupInfo;
 struct EditingRange;
 struct EditorState;
 struct PlatformPopupMenuData;
@@ -1295,7 +1295,7 @@
     void searchTheWeb(const String&);
 
     // Dictionary.
-    void didPerformDictionaryLookup(const DictionaryPopupInfo&);
+    void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&);
 #endif
 
 #if PLATFORM(MAC)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (189051 => 189052)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2015-08-27 21:24:27 UTC (rev 189052)
@@ -308,7 +308,7 @@
 
 #if PLATFORM(COCOA)
     # Dictionary support.
-    DidPerformDictionaryLookup(struct WebKit::DictionaryPopupInfo dictionaryPopupInfo)
+    DidPerformDictionaryLookup(struct WebCore::DictionaryPopupInfo dictionaryPopupInfo)
 
     # Keyboard input support messages
     ExecuteSavedCommandBySelector(String selector) -> (bool handled)

Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h (189051 => 189052)


--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -145,7 +145,7 @@
 
     virtual void makeFirstResponder() override;
     
-    virtual void didPerformDictionaryLookup(const DictionaryPopupInfo&) override;
+    virtual void didPerformDictionaryLookup(const WebCore::DictionaryPopupInfo&) override;
     virtual void dismissContentRelativeChildWindows(bool withAnimation = true) override;
 
     virtual void showCorrectionPanel(WebCore::AlternativeTextType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings) override;

Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (189051 => 189052)


--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -28,10 +28,8 @@
 
 #if PLATFORM(MAC)
 
-#import "AttributedString.h"
 #import "ColorSpaceData.h"
 #import "DataReference.h"
-#import "DictionaryPopupInfo.h"
 #import "DownloadProxy.h"
 #import "NativeWebKeyboardEvent.h"
 #import "NativeWebWheelEvent.h"
@@ -53,11 +51,11 @@
 #import <WebCore/AlternativeTextUIController.h>
 #import <WebCore/BitmapImage.h>
 #import <WebCore/Cursor.h>
+#import <WebCore/DictionaryLookup.h>
 #import <WebCore/FloatRect.h>
 #import <WebCore/GraphicsContext.h>
 #import <WebCore/Image.h>
 #import <WebCore/KeyboardEvent.h>
-#import <WebCore/LookupSPI.h>
 #import <WebCore/NotImplemented.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/TextIndicator.h>
@@ -85,8 +83,6 @@
 @end
 #endif
 
-SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUTermOptionDisableSearchTermIndicator, NSString *)
-
 using namespace WebCore;
 using namespace WebKit;
 
@@ -585,32 +581,11 @@
 
 void PageClientImpl::didPerformDictionaryLookup(const DictionaryPopupInfo& dictionaryPopupInfo)
 {
-    if (!getLULookupDefinitionModuleClass())
-        return;
-
-    RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([(NSDictionary *)dictionaryPopupInfo.options.get() mutableCopy]);
-
     [m_wkView _prepareForDictionaryLookup];
 
-    if (canLoadLUTermOptionDisableSearchTermIndicator() && dictionaryPopupInfo.textIndicator.contentImage) {
-        [m_wkView _setTextIndicator:TextIndicator::create(dictionaryPopupInfo.textIndicator) withLifetime:TextIndicatorWindowLifetime::Permanent];
-        [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
-
-        if ([getLULookupDefinitionModuleClass() respondsToSelector:@selector(showDefinitionForTerm:relativeToRect:ofView:options:)]) {
-            FloatRect firstTextRectInViewCoordinates = dictionaryPopupInfo.textIndicator.textRectsInBoundingRectCoordinates[0];
-            firstTextRectInViewCoordinates.moveBy(dictionaryPopupInfo.textIndicator.textBoundingRectInRootViewCoordinates.location());
-            [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.string.get() relativeToRect:firstTextRectInViewCoordinates ofView:m_wkView options:mutableOptions.get()];
-            return;
-        }
-    }
-
-    NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
-
-    // Convert to screen coordinates.
-    textBaselineOrigin = [m_wkView convertPoint:textBaselineOrigin toView:nil];
-    textBaselineOrigin = [m_wkView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
-
-    [getLULookupDefinitionModuleClass() showDefinitionForTerm:dictionaryPopupInfo.attributedString.string.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
+    DictionaryLookup::showPopup(dictionaryPopupInfo, m_wkView, [this](TextIndicator& textIndicator) {
+        [m_wkView _setTextIndicator:textIndicator withLifetime:TextIndicatorWindowLifetime::Permanent];
+    });
 }
 
 void PageClientImpl::dismissContentRelativeChildWindows(bool withAnimation)

Modified: trunk/Source/WebKit2/UIProcess/mac/WKImmediateActionController.mm (189051 => 189052)


--- trunk/Source/WebKit2/UIProcess/mac/WKImmediateActionController.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/UIProcess/mac/WKImmediateActionController.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -35,6 +35,7 @@
 #import "WebPageProxyMessages.h"
 #import "WebProcessProxy.h"
 #import <WebCore/DataDetectorsSPI.h>
+#import <WebCore/DictionaryLookup.h>
 #import <WebCore/GeometryUtilities.h>
 #import <WebCore/LookupSPI.h>
 #import <WebCore/NSMenuSPI.h>
@@ -46,7 +47,6 @@
 
 SOFT_LINK_FRAMEWORK_IN_UMBRELLA(Quartz, QuickLookUI)
 SOFT_LINK_CLASS(QuickLookUI, QLPreviewMenuItem)
-SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUTermOptionDisableSearchTermIndicator, NSString *)
 
 using namespace WebCore;
 using namespace WebKit;
@@ -461,33 +461,15 @@
     if (_state != ImmediateActionState::Ready)
         return nil;
 
-    if (!getLULookupDefinitionModuleClass())
-        return nil;
-
     DictionaryPopupInfo dictionaryPopupInfo = _hitTestResultData.dictionaryPopupInfo;
-    if (!dictionaryPopupInfo.attributedString.string)
+    if (!dictionaryPopupInfo.attributedString)
         return nil;
 
     [_wkView _prepareForDictionaryLookup];
 
-    RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([(NSDictionary *)dictionaryPopupInfo.options.get() mutableCopy]);
-    if (canLoadLUTermOptionDisableSearchTermIndicator() && dictionaryPopupInfo.textIndicator.contentImage) {
-        [_wkView _setTextIndicator:TextIndicator::create(dictionaryPopupInfo.textIndicator) withLifetime:TextIndicatorWindowLifetime::Permanent];
-        [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
-
-        if ([getLULookupDefinitionModuleClass() respondsToSelector:@selector(lookupAnimationControllerForTerm:relativeToRect:ofView:options:)]) {
-            FloatRect firstTextRectInViewCoordinates = dictionaryPopupInfo.textIndicator.textRectsInBoundingRectCoordinates[0];
-            firstTextRectInViewCoordinates.moveBy(dictionaryPopupInfo.textIndicator.textBoundingRectInRootViewCoordinates.location());
-            return [getLULookupDefinitionModuleClass() lookupAnimationControllerForTerm:dictionaryPopupInfo.attributedString.string.get() relativeToRect:firstTextRectInViewCoordinates ofView:_wkView options:mutableOptions.get()];
-        }
-    }
-
-    // Convert baseline to screen coordinates.
-    NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
-    textBaselineOrigin = [_wkView convertPoint:textBaselineOrigin toView:nil];
-    textBaselineOrigin = [_wkView.window convertRectToScreen:NSMakeRect(textBaselineOrigin.x, textBaselineOrigin.y, 0, 0)].origin;
-
-    return [getLULookupDefinitionModuleClass() lookupAnimationControllerForTerm:dictionaryPopupInfo.attributedString.string.get() atLocation:textBaselineOrigin options:mutableOptions.get()];
+    return DictionaryLookup::animationControllerForPopup(dictionaryPopupInfo, _wkView, [self](TextIndicator& textIndicator) {
+        [_wkView _setTextIndicator:textIndicator withLifetime:TextIndicatorWindowLifetime::Permanent];
+    });
 }
 
 @end

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (189051 => 189052)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -32,7 +32,6 @@
 #import "AttributedString.h"
 #import "ColorSpaceData.h"
 #import "DataReference.h"
-#import "DictionaryPopupInfo.h"
 #import "EditingRange.h"
 #import "EditorState.h"
 #import "MenuUtilities.h"
@@ -48,6 +47,7 @@
 #import "WebPageMessages.h"
 #import "WebProcessProxy.h"
 #import <WebCore/DictationAlternative.h>
+#import <WebCore/DictionaryLookup.h>
 #import <WebCore/GraphicsLayer.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SharedBuffer.h>

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (189051 => 189052)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2015-08-27 21:24:27 UTC (rev 189052)
@@ -1594,8 +1594,6 @@
 		BCE469791214F2B4000B98EB /* WebFrameListenerProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE469781214F2B4000B98EB /* WebFrameListenerProxy.cpp */; };
 		BCE81D8C1319F7EF00241910 /* FontInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE81D8A1319F7EF00241910 /* FontInfo.cpp */; };
 		BCE81D8D1319F7EF00241910 /* FontInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE81D8B1319F7EF00241910 /* FontInfo.h */; };
-		BCE81D98131AE02100241910 /* DictionaryPopupInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCE81D96131AE02000241910 /* DictionaryPopupInfo.cpp */; };
-		BCE81D99131AE02100241910 /* DictionaryPopupInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = BCE81D97131AE02100241910 /* DictionaryPopupInfo.h */; };
 		BCEE7AD012817988009827DA /* WebProcessProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEE7ACC12817988009827DA /* WebProcessProxyMessageReceiver.cpp */; };
 		BCEE7AD112817988009827DA /* WebProcessProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEE7ACD12817988009827DA /* WebProcessProxyMessages.h */; };
 		BCEE7DC5128B645D009827DA /* InjectedBundleClient.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEE7DC3128B645D009827DA /* InjectedBundleClient.h */; };
@@ -3821,8 +3819,6 @@
 		BCE469781214F2B4000B98EB /* WebFrameListenerProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebFrameListenerProxy.cpp; sourceTree = "<group>"; };
 		BCE81D8A1319F7EF00241910 /* FontInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontInfo.cpp; sourceTree = "<group>"; };
 		BCE81D8B1319F7EF00241910 /* FontInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontInfo.h; sourceTree = "<group>"; };
-		BCE81D96131AE02000241910 /* DictionaryPopupInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DictionaryPopupInfo.cpp; sourceTree = "<group>"; };
-		BCE81D97131AE02100241910 /* DictionaryPopupInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictionaryPopupInfo.h; sourceTree = "<group>"; };
 		BCE9C0CF1485965D00E33D61 /* WebConnectionToUIProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebConnectionToUIProcess.cpp; sourceTree = "<group>"; };
 		BCE9C0D01485965D00E33D61 /* WebConnectionToUIProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebConnectionToUIProcess.h; sourceTree = "<group>"; };
 		BCEE7AB312817095009827DA /* WebProcessProxy.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebProcessProxy.messages.in; sourceTree = "<group>"; };
@@ -4700,8 +4696,6 @@
 				1A6F9F8E11E13EFC00DB1371 /* CommandLine.h */,
 				5106D7BF18BDBE73000AB166 /* ContextMenuContextData.cpp */,
 				5106D7C018BDBE73000AB166 /* ContextMenuContextData.h */,
-				BCE81D96131AE02000241910 /* DictionaryPopupInfo.cpp */,
-				BCE81D97131AE02100241910 /* DictionaryPopupInfo.h */,
 				C517388012DF8F4F00EE3F47 /* DragControllerAction.h */,
 				0FB659221208B4DB0044816C /* DrawingAreaInfo.h */,
 				E105FE5318D7B9DE008F57A8 /* EditingRange.h */,
@@ -7637,7 +7631,6 @@
 				CE1A0BD41A48E6C60054EF74 /* DataDetectorsUISPI.h in Headers */,
 				1AC75380183BE50F0072CB15 /* DataReference.h in Headers */,
 				83891B6C1A68C30B0030F386 /* DiagnosticLoggingClient.h in Headers */,
-				BCE81D99131AE02100241910 /* DictionaryPopupInfo.h in Headers */,
 				518E8F0816B2093700E91429 /* Download.h in Headers */,
 				518E8F0A16B2093700E91429 /* DownloadAuthenticationClient.h in Headers */,
 				A1DF631318E0B7C8003A3E2A /* DownloadClient.h in Headers */,
@@ -9440,7 +9433,6 @@
 				51032F1D180F791700961BB7 /* DatabaseToWebProcessConnectionMessageReceiver.cpp in Sources */,
 				1AC7537F183BE50F0072CB15 /* DataReference.cpp in Sources */,
 				83891B6D1A68C30B0030F386 /* DiagnosticLoggingClient.mm in Sources */,
-				BCE81D98131AE02100241910 /* DictionaryPopupInfo.cpp in Sources */,
 				518E8F0716B2093700E91429 /* Download.cpp in Sources */,
 				518E8F0916B2093700E91429 /* DownloadAuthenticationClient.cpp in Sources */,
 				A1DF631218E0B7C8003A3E2A /* DownloadClient.mm in Sources */,

Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm (189051 => 189052)


--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -29,9 +29,7 @@
 #if ENABLE(PDFKIT_PLUGIN)
 
 #import "ArgumentCoders.h"
-#import "AttributedString.h"
 #import "DataReference.h"
-#import "DictionaryPopupInfo.h"
 #import "PDFAnnotationTextWidgetDetails.h"
 #import "PDFKitImports.h"
 #import "PDFLayerControllerDetails.h"
@@ -1720,7 +1718,7 @@
 {
     DictionaryPopupInfo dictionaryPopupInfo;
     dictionaryPopupInfo.origin = convertFromPDFViewToRootView(IntPoint(point));
-    dictionaryPopupInfo.attributedString.string = string;
+    dictionaryPopupInfo.attributedString = string;
 
     webFrame()->page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfo));
 }
@@ -1937,7 +1935,7 @@
         return selection.string;
     }
     
-    NSString *lookupText = dictionaryLookupForPDFSelection(selection, options);
+    NSString *lookupText = DictionaryLookup::stringForPDFSelection(selection, options);
     if (!lookupText || !lookupText.length)
         return @"";
 

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm (189051 => 189052)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -28,10 +28,10 @@
 
 #if ENABLE(CONTEXT_MENUS)
 
-#import "DictionaryPopupInfo.h"
 #import "WebCoreArgumentCoders.h"
 #import "WebPage.h"
 #import "WebPageProxyMessages.h"
+#import <WebCore/DictionaryLookup.h>
 #import <WebCore/FrameView.h>
 #import <WebCore/MainFrame.h>
 #import <WebCore/Page.h>

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (189051 => 189052)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-08-27 21:24:27 UTC (rev 189052)
@@ -30,7 +30,6 @@
 #include "APIInjectedBundlePageContextMenuClient.h"
 #include "APIInjectedBundlePageUIClient.h"
 #include "APIObject.h"
-#include "DictionaryPopupInfo.h"
 #include "FindController.h"
 #include "GeolocationPermissionRequestManager.h"
 #include "ImageOptions.h"
@@ -49,6 +48,7 @@
 #include "UserData.h"
 #include "UserMediaPermissionRequestManager.h"
 #include <WebCore/DictationAlternative.h>
+#include <WebCore/DictionaryPopupInfo.h>
 #include <WebCore/DragData.h>
 #include <WebCore/Editor.h>
 #include <WebCore/FrameLoaderTypes.h>
@@ -1055,9 +1055,9 @@
     void performDictionaryLookupAtLocation(const WebCore::FloatPoint&);
     void performDictionaryLookupOfCurrentSelection();
     void performDictionaryLookupForRange(WebCore::Frame*, WebCore::Range&, NSDictionary *options, WebCore::TextIndicatorPresentationTransition);
-    DictionaryPopupInfo dictionaryPopupInfoForRange(WebCore::Frame* frame, WebCore::Range& range, NSDictionary **options, WebCore::TextIndicatorPresentationTransition presentationTransition);
+    WebCore::DictionaryPopupInfo dictionaryPopupInfoForRange(WebCore::Frame*, WebCore::Range&, NSDictionary **options, WebCore::TextIndicatorPresentationTransition);
 #if ENABLE(PDFKIT_PLUGIN)
-    DictionaryPopupInfo dictionaryPopupInfoForSelectionInPDFPlugin(PDFSelection *, PDFPlugin&, NSDictionary **options, WebCore::TextIndicatorPresentationTransition);
+    WebCore::DictionaryPopupInfo dictionaryPopupInfoForSelectionInPDFPlugin(PDFSelection *, PDFPlugin&, NSDictionary **options, WebCore::TextIndicatorPresentationTransition);
 #endif
 
     void windowAndViewFramesChanged(const WebCore::FloatRect& windowFrameInScreenCoordinates, const WebCore::FloatRect& windowFrameInUnflippedScreenCoordinates, const WebCore::FloatRect& viewFrameInWindowCoordinates, const WebCore::FloatPoint& accessibilityViewCoordinates);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (189051 => 189052)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2015-08-27 21:23:49 UTC (rev 189051)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2015-08-27 21:24:27 UTC (rev 189052)
@@ -30,7 +30,6 @@
 
 #import "AttributedString.h"
 #import "DataReference.h"
-#import "DictionaryPopupInfo.h"
 #import "EditingRange.h"
 #import "EditorState.h"
 #import "InjectedBundleHitTestResult.h"
@@ -518,7 +517,7 @@
     HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(point));
     Frame* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
     NSDictionary *options = nil;
-    RefPtr<Range> range = rangeForDictionaryLookupAtHitTestResult(result, &options);
+    RefPtr<Range> range = DictionaryLookup::rangeAtHitTestResult(result, &options);
     if (!range)
         return;
 
@@ -528,7 +527,7 @@
 void WebPage::performDictionaryLookupForSelection(Frame* frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition)
 {
     NSDictionary *options = nil;
-    RefPtr<Range> selectedRange = rangeForDictionaryLookupForSelection(selection, &options);
+    RefPtr<Range> selectedRange = DictionaryLookup::rangeForSelection(selection, &options);
     if (selectedRange)
         performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition);
 }
@@ -556,7 +555,7 @@
     IntRect rangeRect = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
 
     dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y() + (style.fontMetrics().ascent() * pageScaleFactor()));
-    dictionaryPopupInfo.options = (CFDictionaryRef)*options;
+    dictionaryPopupInfo.options = *options;
 
     NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range, IncludeImagesInAttributedString::No);
 
@@ -585,7 +584,7 @@
         return dictionaryPopupInfo;
 
     dictionaryPopupInfo.textIndicator = textIndicator->data();
-    dictionaryPopupInfo.attributedString.string = scaledNSAttributedString;
+    dictionaryPopupInfo.attributedString = scaledNSAttributedString;
 
     return dictionaryPopupInfo;
 }
@@ -638,9 +637,9 @@
     dataForSelection.presentationTransition = presentationTransition;
     
     dictionaryPopupInfo.origin = rangeRect.origin;
-    dictionaryPopupInfo.options = (CFDictionaryRef)*options;
+    dictionaryPopupInfo.options = *options;
     dictionaryPopupInfo.textIndicator = dataForSelection;
-    dictionaryPopupInfo.attributedString.string = scaledNSAttributedString;
+    dictionaryPopupInfo.attributedString = scaledNSAttributedString;
     
     return dictionaryPopupInfo;
 }
@@ -1198,7 +1197,7 @@
 
     IntPoint point = roundedIntPoint(locationInViewCoordinates);
     HitTestResult result = mainFrame.eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(point));
-    return rangeForDictionaryLookupAtHitTestResult(result, options);
+    return DictionaryLookup::rangeAtHitTestResult(result, options);
 }
 
 void WebPage::immediateActionDidUpdate()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to