Use TextIndicator instead of the built in Lookup highlight
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Nov 2014 20:41:27 +0000 (20:41 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Nov 2014 20:41:27 +0000 (20:41 +0000)
commitbb6ac30c8f593461ec6432e07f73fea049482d69
tree83e4feabf0cf3b2d6e5aa23d036121d986ed2926
parent2abe0c25a4572df47676033ed6b2741328d96215
Use TextIndicator instead of the built in Lookup highlight
https://bugs.webkit.org/show_bug.cgi?id=138775
<rdar://problem/18953982>

Reviewed by Anders Carlsson.

In order to make the yellow highlight for Lookup more accurately match the
painted content of the web page (in light of e.g. Web fonts, and interesting
text features that only WebKit implements and cannot round-trip through
NSAttributedString), use a TextIndicator instead of the built-in Lookup
highlight where possible.

* Configurations/BaseTarget.xcconfig:
Make it possible to include headers from private frameworks. This matches WebCore.

* Shared/DictionaryPopupInfo.cpp:
(WebKit::DictionaryPopupInfo::encode):
(WebKit::DictionaryPopupInfo::decode):
* Shared/DictionaryPopupInfo.h:
Include the attributed string inside the DictionaryPopupInfo, instead of
as a secondary argument to DidPerformDictionaryLookup.
Add a TextIndicator to DictionaryPopupInfo, which can be used to highlight
the text in the UI process.

* UIProcess/API/mac/WKView.mm:
(-[WKView dealloc]):
(-[WKView viewDidMoveToWindow]):
(-[WKView _dictionaryLookupPopoverWillClose:]):
(-[WKView _setTextIndicator:fadeOut:animate:animationCompletionHandler:]):
(-[WKView _setTextIndicator:fadeOut:animate:]):
(-[WKView initWithFrame:context:configuration:webView:]):
(+[WKView hideWordDefinitionWindow]):
* UIProcess/API/mac/WKViewInternal.h:
Adopt the Lookup SPI header.
If we have the requisite API, register the notification that Lookup sends
when the popover closes, and hook that up to hide the text indicator.
Add a version of _setTextIndicator: that takes an animation completion handler.

* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::didPerformDictionaryLookup):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::didPerformDictionaryLookup):
Adjust to the new didPerformDictionaryLookup signature.

* WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
Remove a WKSI import.

* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::didPerformDictionaryLookup):
If we have the requisite API, disable Lookup's built-in highlight and
present a TextIndicator instead.
We currently have to run the animations serially (first bounce the TextIndicator,
then animate in the Lookup popover) because the act of adding the Lookup popover
blocks us from getting any animation events for the TextIndicator, and breaks
the bounce. We could also fix this by using a threaded animation for the TextIndicator,
but it's not clear that it's safe to do so.

(WebKit::PageClientImpl::dismissDictionaryLookupPanel):
When explicitly dismissing the Lookup panel, also hide the text indicator.

* UIProcess/mac/TextIndicatorWindow.h:
* UIProcess/mac/TextIndicatorWindow.mm:
(WebKit::TextIndicatorWindow::setTextIndicator):
Store the completion handler.

(WebKit::TextIndicatorWindow::bounceAnimationDidEnd):
Call the completion handler when the animation completes.

* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController _createActionMenuItemForTag:]):
Disable the Lookup item if lookup is not available.

* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::showDefinitionForAttributedString):
Adjust to the new didPerformDictionaryLookup signature.
Since PDFPlugin can't trivially repaint the required part of the PDF,
we don't build a TextIndicator. This will result in PDFPlugin continuing
to use Lookup's built-in highlight.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupForRange):
Build a TextIndicator from the Lookup range and pass it along with
the DictionaryPopupInfo.

* WebCore.exp.in:
* platform/mac/WebCoreSystemInterface.h:
* platform/mac/WebCoreSystemInterface.mm:
Remove a WKSI import/export that we don't need anymore.

* platform/spi/mac/LookupSPI.h: Added.
(WebCore::canDisableLookupIndicator):
Add Lookup SPI header.
Add a 'canDisableLookupIndicator', which must be called in any translation
unit that wants to use either of the soft-linked constants related to
that functionality, before calling the get* function.

* WebCore.xcodeproj/project.pbxproj:
* editing/mac/DictionaryLookup.mm:
(WebCore::rangeForDictionaryLookupForSelection):
(WebCore::rangeForDictionaryLookupAtHitTestResult):
Adopt the Lookup SPI header.

* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
Remove a WKSI import.

* WebView/WebActionMenuController.mm:
(-[WebActionMenuController _lookupText:]):
(-[WebActionMenuController _createActionMenuItemForTag:]):
Make use of the new Lookup SPI header.
Disable the Lookup item if lookup is not available.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176164 268f45cc-cd09-0410-ab3c-d52691b4dbfc
29 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/editing/mac/DictionaryLookup.mm
Source/WebCore/platform/mac/WebCoreSystemInterface.h
Source/WebCore/platform/mac/WebCoreSystemInterface.mm
Source/WebCore/platform/spi/mac/LookupSPI.h [new file with mode: 0644]
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm
Source/WebKit/mac/WebView/WebActionMenuController.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Configurations/BaseTarget.xcconfig
Source/WebKit2/Shared/DictionaryPopupInfo.cpp
Source/WebKit2/Shared/DictionaryPopupInfo.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit2/UIProcess/mac/PageClientImpl.h
Source/WebKit2/UIProcess/mac/PageClientImpl.mm
Source/WebKit2/UIProcess/mac/TextIndicatorWindow.h
Source/WebKit2/UIProcess/mac/TextIndicatorWindow.mm
Source/WebKit2/UIProcess/mac/WKActionMenuController.mm
Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm