From: enrica@apple.com Date: Tue, 28 Apr 2015 20:18:36 +0000 (+0000) Subject: Add support for lookup on iOS. X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=311b3f3f763d58c7604db95916d30fe8a83c3c1c Add support for lookup on iOS. https://bugs.webkit.org/show_bug.cgi?id=144342 rdar://problem/19994090 Reviewed by Tim Horton. * UIProcess/WebPageProxy.h: * UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView _lookup:]): (-[WKContentView canPerformAction:withSender:]): * UIProcess/ios/WebPageProxyIOS.mm: (WebKit::WebPageProxy::getLookupContextAtPoint): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::getLookupContextAtPoint): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183503 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index 1396884..940a8a0 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,22 @@ +2015-04-28 Enrica Casucci + + Add support for lookup on iOS. + https://bugs.webkit.org/show_bug.cgi?id=144342 + rdar://problem/19994090 + + Reviewed by Tim Horton. + + * UIProcess/WebPageProxy.h: + * UIProcess/ios/WKContentViewInteraction.mm: + (-[WKContentView _lookup:]): + (-[WKContentView canPerformAction:withSender:]): + * UIProcess/ios/WebPageProxyIOS.mm: + (WebKit::WebPageProxy::getLookupContextAtPoint): + * WebProcess/WebPage/WebPage.h: + * WebProcess/WebPage/WebPage.messages.in: + * WebProcess/WebPage/ios/WebPageIOS.mm: + (WebKit::WebPage::getLookupContextAtPoint): + 2015-04-28 Brady Eidson Consolidate most "frame load" arguments into FrameLoadRequest. diff --git a/Source/WebKit2/UIProcess/WebPageProxy.h b/Source/WebKit2/UIProcess/WebPageProxy.h index 539603e..0102658 100644 --- a/Source/WebKit2/UIProcess/WebPageProxy.h +++ b/Source/WebKit2/UIProcess/WebPageProxy.h @@ -501,6 +501,7 @@ public: void viewportMetaTagWidthDidChange(float width); void didFinishDrawingPagesToPDF(const IPC::DataReference&); void contentSizeCategoryDidChange(const String& contentSizeCategory); + void getLookupContextAtPoint(const WebCore::IntPoint&, std::function); #endif void didCommitLayerTree(const WebKit::RemoteLayerTreeTransaction&); diff --git a/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm b/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm index 0aaa6d0..f958008 100644 --- a/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm +++ b/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm @@ -182,11 +182,13 @@ const CGFloat minimumTapHighlightRadius = 2.0; - (void)showTextServiceFor:(NSString *)selectedTerm fromRect:(CGRect)presentationRect; - (void)scheduleChineseTransliterationForText:(NSString *)text; - (void)showShareSheetFor:(NSString *)selectedTerm fromRect:(CGRect)presentationRect; +- (void)lookup:(NSString *)textWithContext fromRect:(CGRect)presentationRect; @end @interface UIWKSelectionAssistant (StagingToRemove) - (void)showTextServiceFor:(NSString *)selectedTerm fromRect:(CGRect)presentationRect; - (void)showShareSheetFor:(NSString *)selectedTerm fromRect:(CGRect)presentationRect; +- (void)lookup:(NSString *)textWithContext fromRect:(CGRect)presentationRect; @end @interface UIKeyboardImpl (StagingToRemove) @@ -1295,6 +1297,24 @@ static void cancelPotentialTapIfNecessary(WKContentView* contentView) return (_page->editorState().isContentRichlyEditable) ? richTypes : plainTextTypes; } +- (void)_lookup:(CGPoint)point +{ + RetainPtr view = self; + _page->getLookupContextAtPoint(WebCore::IntPoint(point), [view](const String& string, CallbackBase::Error error) { + if (error != CallbackBase::Error::None) + return; + if (!string) + return; + + CGRect presentationRect = view->_page->editorState().selectionIsRange ? view->_page->editorState().postLayoutData().selectionRects[0].rect() : view->_page->editorState().postLayoutData().caretRectAtStart; + + if (view->_textSelectionAssistant && [view->_textSelectionAssistant respondsToSelector:@selector(lookup:fromRect:)]) + [view->_textSelectionAssistant lookup:string fromRect:presentationRect]; + else if (view->_webSelectionAssistant && [view->_webSelectionAssistant respondsToSelector:@selector(lookup:fromRect:)]) + [view->_webSelectionAssistant lookup:string fromRect:presentationRect]; + }); +} + - (void)_share:(id)sender { RetainPtr view = self; @@ -1443,6 +1463,16 @@ static void cancelPotentialTapIfNecessary(WKContentView* contentView) return YES; } + if (action == @selector(_lookup:)) { + if (_page->editorState().isInPasswordField) + return NO; + + if ([[getMCProfileConnectionClass() sharedConnection] effectiveBoolValueForSetting:MCFeatureDefinitionLookupAllowed] == MCRestrictedBoolExplicitNo) + return NO; + + return YES; + } + if (action == @selector(_share:)) { if (_page->editorState().isInPasswordField || !(hasWebSelection || _page->editorState().selectionIsRange)) return NO; diff --git a/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm b/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm index 5cfe595..082127f 100644 --- a/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm +++ b/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm @@ -513,6 +513,17 @@ void WebPageProxy::getAutocorrectionContext(String& beforeContext, String& marke m_process->sendSync(Messages::WebPage::GetAutocorrectionContext(), Messages::WebPage::GetAutocorrectionContext::Reply(beforeContext, markedText, selectedText, afterContext, location, length), m_pageID); } +void WebPageProxy::getLookupContextAtPoint(const WebCore::IntPoint& point, std::function callbackFunction) +{ + if (!isValid()) { + callbackFunction(String(), CallbackBase::Error::Unknown); + return; + } + + uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken()); + m_process->send(Messages::WebPage::GetLookupContextAtPoint(point, callbackID), m_pageID); +} + void WebPageProxy::selectWithTwoTouches(const WebCore::IntPoint from, const WebCore::IntPoint to, uint32_t gestureType, uint32_t gestureState, std::function callbackFunction) { if (!isValid()) { diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.h b/Source/WebKit2/WebProcess/WebPage/WebPage.h index 8ffc130..05a4c67 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.h +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.h @@ -526,6 +526,7 @@ public: void resetAssistedNodeForFrame(WebFrame*); WebCore::IntRect rectForElementAtInteractionLocation(); void updateSelectionAppearance(); + void getLookupContextAtPoint(const WebCore::IntPoint, uint64_t callbackID); #if ENABLE(IOS_TOUCH_EVENTS) void dispatchAsynchronousTouchEvents(const Vector& queue); diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in index 852ead1..70e6c576 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in @@ -91,6 +91,7 @@ messages -> WebPage LegacyReceiver { ApplicationDidBecomeActive() ContentSizeCategoryDidChange(String contentSizeCategory) ExecuteEditCommandWithCallback(String name, uint64_t callbackID) + GetLookupContextAtPoint(WebCore::IntPoint point, uint64_t callbackID) #endif #if ENABLE(REMOTE_INSPECTOR) diff --git a/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm b/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm index f3cca5e..a886da1 100644 --- a/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm +++ b/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm @@ -406,6 +406,20 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent&) return false; } +void WebPage::getLookupContextAtPoint(const WebCore::IntPoint point, uint64_t callbackID) +{ + Frame& frame = m_page->focusController().focusedOrMainFrame(); + VisiblePosition position = frame.visiblePositionForPoint(point); + String resultString; + if (!position.isNull()) { + // As context, we are going to use 250 characters of text before and after the point. + RefPtr fullCharacterRange = rangeExpandedAroundPositionByCharacters(position, 250); + if (fullCharacterRange) + resultString = plainText(fullCharacterRange.get()); + } + send(Messages::WebPageProxy::StringCallback(resultString, callbackID)); +} + NSObject *WebPage::accessibilityObjectForMainFramePlugin() { if (!m_page)