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
+2015-04-28 Enrica Casucci <enrica@apple.com>
+
+ 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 <beidson@apple.com>
Consolidate most "frame load" arguments into FrameLoadRequest.
void viewportMetaTagWidthDidChange(float width);
void didFinishDrawingPagesToPDF(const IPC::DataReference&);
void contentSizeCategoryDidChange(const String& contentSizeCategory);
+ void getLookupContextAtPoint(const WebCore::IntPoint&, std::function<void(const String&, CallbackBase::Error)>);
#endif
void didCommitLayerTree(const WebKit::RemoteLayerTreeTransaction&);
- (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)
return (_page->editorState().isContentRichlyEditable) ? richTypes : plainTextTypes;
}
+- (void)_lookup:(CGPoint)point
+{
+ RetainPtr<WKContentView> 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<WKContentView> view = self;
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;
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<void(const String&, CallbackBase::Error)> 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<void (const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, CallbackBase::Error)> callbackFunction)
{
if (!isValid()) {
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<WebTouchEvent, 1>& queue);
ApplicationDidBecomeActive()
ContentSizeCategoryDidChange(String contentSizeCategory)
ExecuteEditCommandWithCallback(String name, uint64_t callbackID)
+ GetLookupContextAtPoint(WebCore::IntPoint point, uint64_t callbackID)
#endif
#if ENABLE(REMOTE_INSPECTOR)
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<Range> fullCharacterRange = rangeExpandedAroundPositionByCharacters(position, 250);
+ if (fullCharacterRange)
+ resultString = plainText(fullCharacterRange.get());
+ }
+ send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
+}
+
NSObject *WebPage::accessibilityObjectForMainFramePlugin()
{
if (!m_page)