Title: [183208] trunk/Source/WebKit2
Revision
183208
Author
enr...@apple.com
Date
2015-04-23 14:03:46 -0700 (Thu, 23 Apr 2015)

Log Message

Support share button.
https://bugs.webkit.org/show_bug.cgi?id=144077
rdar://problem/19772892

Reviewed by Darin Adler.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _share:]):
(-[WKContentView canPerformAction:withSender:]):
(-[WKContentView _define:]):
(-[WKContentView accessibilityRetrieveSpeakSelectionContent]):
(-[WKContentView moveByOffset:]):
(-[WKContentView requestAutocorrectionRectsForString:withCompletionHandler:]):
(-[WKContentView applyAutocorrection:toString:withCompletionHandler:]):
(-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):
(-[WKContentView accessoryTab:]):
(-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]):
(-[WKContentView executeEditCommandWithCallback:]):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (183207 => 183208)


--- trunk/Source/WebKit2/ChangeLog	2015-04-23 20:47:31 UTC (rev 183207)
+++ trunk/Source/WebKit2/ChangeLog	2015-04-23 21:03:46 UTC (rev 183208)
@@ -1,3 +1,24 @@
+2015-04-23  Enrica Casucci  <enr...@apple.com>
+
+        Support share button.
+        https://bugs.webkit.org/show_bug.cgi?id=144077
+        rdar://problem/19772892
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _share:]):
+        (-[WKContentView canPerformAction:withSender:]):
+        (-[WKContentView _define:]):
+        (-[WKContentView accessibilityRetrieveSpeakSelectionContent]):
+        (-[WKContentView moveByOffset:]):
+        (-[WKContentView requestAutocorrectionRectsForString:withCompletionHandler:]):
+        (-[WKContentView applyAutocorrection:toString:withCompletionHandler:]):
+        (-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):
+        (-[WKContentView accessoryTab:]):
+        (-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]):
+        (-[WKContentView executeEditCommandWithCallback:]):
+
 2015-04-23  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [UNIX] Do not allow copies of IPC::Attachment

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (183207 => 183208)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2015-04-23 20:47:31 UTC (rev 183207)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2015-04-23 21:03:46 UTC (rev 183208)
@@ -181,6 +181,7 @@
 - (void)scheduleReplacementsForText:(NSString *)text;
 - (void)showTextServiceFor:(NSString *)selectedTerm fromRect:(CGRect)presentationRect;
 - (void)scheduleChineseTransliterationForText:(NSString *)text;
+- (void)showShareSheetFor:(NSString *)selectedTerm fromRect:(CGRect)presentationRect;
 @end
 
 @interface UIWKSelectionAssistant (StagingToRemove)
@@ -1293,6 +1294,24 @@
     return (_page->editorState().isContentRichlyEditable) ? richTypes : plainTextTypes;
 }
 
+- (void)_share:(id)sender
+{
+    RetainPtr<WKContentView> view = self;
+    _page->getSelectionOrContentsAsString([view](const String& string, CallbackBase::Error error) {
+        if (error != CallbackBase::Error::None)
+            return;
+        if (!string)
+            return;
+
+        CGRect presentationRect = view->_page->editorState().postLayoutData().selectionRects[0].rect();
+
+        if (view->_textSelectionAssistant && [view->_textSelectionAssistant respondsToSelector:@selector(showShareSheetFor:fromRect:)])
+            [view->_textSelectionAssistant showShareSheetFor:string fromRect:presentationRect];
+        else if (view->_webSelectionAssistant && [view->_webSelectionAssistant respondsToSelector:@selector(showShareSheetFor:fromRect:)])
+            [view->_webSelectionAssistant showShareSheetFor:string fromRect:presentationRect];
+    });
+}
+
 - (void)_addShortcut:(id)sender
 {
     if (_textSelectionAssistant && [_textSelectionAssistant respondsToSelector:@selector(showTextServiceFor:fromRect:)])
@@ -1423,6 +1442,18 @@
         return YES;
     }
 
+    if (action == @selector(_share:)) {
+        if (_page->editorState().isInPasswordField || !(hasWebSelection || _page->editorState().selectionIsRange))
+            return NO;
+
+        NSUInteger textLength = _page->editorState().postLayoutData().selectedTextLength;
+        // See FIXME above for _define.
+        if (!textLength || textLength > 200)
+            return NO;
+        
+        return YES;
+    }
+
     if (action == @selector(_addShortcut:)) {
         if (_page->editorState().isInPasswordField || !(hasWebSelection || _page->editorState().selectionIsRange))
             return NO;
@@ -1563,23 +1594,25 @@
     if ([[getMCProfileConnectionClass() sharedConnection] effectiveBoolValueForSetting:MCFeatureDefinitionLookupAllowed] == MCRestrictedBoolExplicitNo)
         return;
 
-    _page->getSelectionOrContentsAsString([self](const String& string, WebKit::CallbackBase::Error error) {
+    RetainPtr<WKContentView> view = self;
+    _page->getSelectionOrContentsAsString([view](const String& string, WebKit::CallbackBase::Error error) {
         if (error != WebKit::CallbackBase::Error::None)
             return;
         if (!string)
             return;
 
-        [self _showDictionary:string];
+        [view _showDictionary:string];
     });
 }
 
 - (void)accessibilityRetrieveSpeakSelectionContent
 {
-    _page->getSelectionOrContentsAsString([self](const String& string, WebKit::CallbackBase::Error error) {
+    RetainPtr<WKContentView> view = self;
+    _page->getSelectionOrContentsAsString([view](const String& string, WebKit::CallbackBase::Error error) {
         if (error != WebKit::CallbackBase::Error::None)
             return;
-        if ([self respondsToSelector:@selector(accessibilitySpeakSelectionSetContent:)])
-            [self accessibilitySpeakSelectionSetContent:string];
+        if ([view respondsToSelector:@selector(accessibilitySpeakSelectionSetContent:)])
+            [view accessibilitySpeakSelectionSetContent:string];
     });
 }
 
@@ -1867,8 +1900,9 @@
         return;
     
     [self beginSelectionChange];
-    _page->moveSelectionByOffset(offset, [self](WebKit::CallbackBase::Error) {
-        [self endSelectionChange];
+    RetainPtr<WKContentView> view = self;
+    _page->moveSelectionByOffset(offset, [view](WebKit::CallbackBase::Error) {
+        [view endSelectionChange];
     });
 }
 
@@ -1885,8 +1919,9 @@
         return;
     }
 
+    RetainPtr<WKContentView> view = self;
     _autocorrectionData.autocorrectionHandler = [completionHandler copy];
-    _page->requestAutocorrectionData(input, [self](const Vector<FloatRect>& rects, const String& fontName, double fontSize, uint64_t traits, WebKit::CallbackBase::Error) {
+    _page->requestAutocorrectionData(input, [view](const Vector<FloatRect>& rects, const String& fontName, double fontSize, uint64_t traits, WebKit::CallbackBase::Error) {
         CGRect firstRect = CGRectZero;
         CGRect lastRect = CGRectZero;
         if (rects.size()) {
@@ -1894,15 +1929,15 @@
             lastRect = rects[rects.size() - 1];
         }
         
-        _autocorrectionData.fontName = fontName;
-        _autocorrectionData.fontSize = fontSize;
-        _autocorrectionData.fontTraits = traits;
-        _autocorrectionData.textFirstRect = firstRect;
-        _autocorrectionData.textLastRect = lastRect;
+        view->_autocorrectionData.fontName = fontName;
+        view->_autocorrectionData.fontSize = fontSize;
+        view->_autocorrectionData.fontTraits = traits;
+        view->_autocorrectionData.textFirstRect = firstRect;
+        view->_autocorrectionData.textLastRect = lastRect;
 
-        _autocorrectionData.autocorrectionHandler(rects.size() ? [WKAutocorrectionRects autocorrectionRectsWithRects:firstRect lastRect:lastRect] : nil);
-        [_autocorrectionData.autocorrectionHandler release];
-        _autocorrectionData.autocorrectionHandler = nil;
+        view->_autocorrectionData.autocorrectionHandler(rects.size() ? [WKAutocorrectionRects autocorrectionRectsWithRects:firstRect lastRect:lastRect] : nil);
+        [view->_autocorrectionData.autocorrectionHandler release];
+        view->_autocorrectionData.autocorrectionHandler = nil;
     });
 }
 
@@ -2016,10 +2051,11 @@
         return;
     }
     _autocorrectionData.autocorrectionHandler = [completionHandler copy];
-    _page->applyAutocorrection(correction, input, [self](const String& string, WebKit::CallbackBase::Error error) {
-        _autocorrectionData.autocorrectionHandler(!string.isNull() ? [WKAutocorrectionRects autocorrectionRectsWithRects:_autocorrectionData.textFirstRect lastRect:_autocorrectionData.textLastRect] : nil);
-        [_autocorrectionData.autocorrectionHandler release];
-        _autocorrectionData.autocorrectionHandler = nil;
+    RetainPtr<WKContentView> view = self;
+    _page->applyAutocorrection(correction, input, [view](const String& string, WebKit::CallbackBase::Error error) {
+        view->_autocorrectionData.autocorrectionHandler(!string.isNull() ? [WKAutocorrectionRects autocorrectionRectsWithRects:view->_autocorrectionData.textFirstRect lastRect:view->_autocorrectionData.textLastRect] : nil);
+        [view->_autocorrectionData.autocorrectionHandler release];
+        view->_autocorrectionData.autocorrectionHandler = nil;
     });
 }
 
@@ -2039,8 +2075,9 @@
         completionHandler([WKAutocorrectionContext autocorrectionContextWithData:beforeText markedText:markedText selectedText:selectedText afterText:afterText selectedRangeInMarkedText:NSMakeRange(location, length)]);
     } else {
         _autocorrectionData.autocorrectionContextHandler = [completionHandler copy];
-        _page->requestAutocorrectionContext([self](const String& beforeText, const String& markedText, const String& selectedText, const String& afterText, uint64_t location, uint64_t length, WebKit::CallbackBase::Error) {
-            _autocorrectionData.autocorrectionContextHandler([WKAutocorrectionContext autocorrectionContextWithData:beforeText markedText:markedText selectedText:selectedText afterText:afterText selectedRangeInMarkedText:NSMakeRange(location, length)]);
+        RetainPtr<WKContentView> view = self;
+        _page->requestAutocorrectionContext([view](const String& beforeText, const String& markedText, const String& selectedText, const String& afterText, uint64_t location, uint64_t length, WebKit::CallbackBase::Error) {
+            view->_autocorrectionData.autocorrectionContextHandler([WKAutocorrectionContext autocorrectionContextWithData:beforeText markedText:markedText selectedText:selectedText afterText:afterText selectedRangeInMarkedText:NSMakeRange(location, length)]);
         });
     }
 }
@@ -2074,9 +2111,10 @@
 
     _didAccessoryTabInitiateFocus = YES; // Will be cleared in either -_displayFormNodeInputView or -cleanupInteraction.
     [self beginSelectionChange];
-    _page->focusNextAssistedNode(isNext, [self](WebKit::CallbackBase::Error) {
-        [self endSelectionChange];
-        [self reloadInputViews];
+    RetainPtr<WKContentView> view = self;
+    _page->focusNextAssistedNode(isNext, [view](WebKit::CallbackBase::Error) {
+        [view endSelectionChange];
+        [view reloadInputViews];
     });
 
 }
@@ -2084,8 +2122,9 @@
 - (void)_becomeFirstResponderWithSelectionMovingForward:(BOOL)selectingForward completionHandler:(void (^)(BOOL didBecomeFirstResponder))completionHandler
 {
     auto completionHandlerCopy = Block_copy(completionHandler);
-    _page->setInitialFocus(selectingForward, false, WebKit::WebKeyboardEvent(), [self, completionHandlerCopy](WebKit::CallbackBase::Error) {
-        BOOL didBecomeFirstResponder = _assistedNodeInformation.elementType != InputType::None && [self becomeFirstResponder];
+    RetainPtr<WKContentView> view = self;
+    _page->setInitialFocus(selectingForward, false, WebKit::WebKeyboardEvent(), [view, completionHandlerCopy](WebKit::CallbackBase::Error) {
+        BOOL didBecomeFirstResponder = view->_assistedNodeInformation.elementType != InputType::None && [view becomeFirstResponder];
         completionHandlerCopy(didBecomeFirstResponder);
         Block_release(completionHandlerCopy);
     });
@@ -2561,8 +2600,9 @@
 - (void)executeEditCommandWithCallback:(NSString *)commandName
 {
     [self beginSelectionChange];
-    _page->executeEditCommand(commandName, [self](WebKit::CallbackBase::Error) {
-        [self endSelectionChange];
+    RetainPtr<WKContentView> view = self;
+    _page->executeEditCommand(commandName, [view](WebKit::CallbackBase::Error) {
+        [view endSelectionChange];
     });
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to