Implement action menus for data detected items
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Oct 2014 18:48:23 +0000 (18:48 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Oct 2014 18:48:23 +0000 (18:48 +0000)
commit6dc8d825e63aa6d64ed1ba8607010bc1e02a882a
tree2cd52818bec54330a03e622a5c075769112ee520
parentfd2386a01611bdc76b19b90dd09e822db54a856e
Implement action menus for data detected items
https://bugs.webkit.org/show_bug.cgi?id=138178
<rdar://problem/18709436>

Reviewed by Anders Carlsson.

* WebCore.exp.in:
Export a symbol from Position that we need.

* WebCore.xcodeproj/project.pbxproj:
* platform/spi/mac/DataDetectorsSPI.h:
Add a combined SPI header for all of the random bits of DataDetectors that we use.

* Shared/API/c/WKActionMenuTypes.h:
Add a new type.

* Shared/WebHitTestResult.cpp:
(WebKit::WebHitTestResult::Data::Data):
(WebKit::WebHitTestResult::Data::encode):
(WebKit::WebHitTestResult::Data::decode):
* Shared/WebHitTestResult.h:
(WebKit::WebHitTestResult::isTextNode):
Determine, store, encode, and decode whether or not the hit node is a text node.

* Shared/mac/ActionMenuHitTestResult.h:
* Shared/mac/ActionMenuHitTestResult.mm: Renamed from Source/WebKit2/Shared/mac/ActionMenuHitTestResult.cpp.
(WebKit::ActionMenuHitTestResult::encode):
(WebKit::ActionMenuHitTestResult::decode):
Make ActionMenuHitTestResult an Obj-C++ file.
Store, encode, and decode (securely!) a DDActionContext and FloatRect
representing the bounding box of the data detected item, if any.

* UIProcess/API/mac/WKView.mm:
(-[WKView initWithFrame:context:configuration:webView:]):
(-[WKView willOpenMenu:withEvent:]): Deleted.
Stop using willOpenMenu; we'll use NSMenuDelegate's menuNeedsUpdate: instead.
Hook up WKActionMenuController as our action menu's delegate.

* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController prepareForMenu:withEvent:]):
Call _updateActionMenuItems *after* we've adjusted _state, so that it
can depend on the value being correct.

(-[WKActionMenuController willOpenMenu:withEvent:]):
(-[WKActionMenuController didPerformActionMenuHitTest:]):
Move menu updating to menuNeedsUpdate for more accurate timing.

(_updateActionMenuItems):
When building the menu, if we have a text node that is not a link,
and hit a data detected item, retrieve the menu from the DDActionContext.
If we have nothing, make sure to reset _type, and if the final hit-test
is still pending, build a menu with a dummy item.

* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::performActionMenuHitTestAtLocation): Moved to WebPageMac.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::rangeExpandedAroundPosition):
Factor this out of performDictionaryLookupAtLocation.

(WebKit::WebPage::performDictionaryLookupAtLocation):
Make use of rangeExpandedAroundPosition.

(WebKit::scanForDataDetectedItems):
Expand to four lines of context around the hit point.
Convert that range to plain text, and feed it to DataDetectors.
Find the result that intersects the hit point, and make a DDActionContext
for it. Also, store the bounding box of the first quad of the detected
text, to provide to Data Detectors as a hint for UI placement.

(WebKit::WebPage::performActionMenuHitTestAtLocation):
If the hit node is a text node, call scanForDataDetectedItems and
store the resultant DDActionContext and bounding rect on our
ActionMenuHitTestResult for transfer to the UI process.

* WebKitSystemInterface.h:
* libWebKitSystemInterfaceMavericks.a:
* libWebKitSystemInterfaceMountainLion.a:
* libWebKitSystemInterfaceYosemite.a:
Update WebKitSystemInterface.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175335 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/spi/mac/DataDetectorsSPI.h [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/c/WKActionMenuTypes.h
Source/WebKit2/Shared/WebHitTestResult.cpp
Source/WebKit2/Shared/WebHitTestResult.h
Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h
Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm [moved from Source/WebKit2/Shared/mac/ActionMenuHitTestResult.cpp with 55% similarity]
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/mac/WKActionMenuController.h
Source/WebKit2/UIProcess/mac/WKActionMenuController.mm
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
WebKitLibraries/ChangeLog
WebKitLibraries/WebKitSystemInterface.h
WebKitLibraries/libWebKitSystemInterfaceMavericks.a
WebKitLibraries/libWebKitSystemInterfaceMountainLion.a
WebKitLibraries/libWebKitSystemInterfaceYosemite.a