Title: [238186] trunk
Revision
238186
Author
wenson_hs...@apple.com
Date
2018-11-14 11:00:04 -0800 (Wed, 14 Nov 2018)

Log Message

Source/WebKit:
[Cocoa] [WebKit2] Hook up some more editing actions (-_pasteAndMatchStyle:, -makeTextWritingDirectionNatural:)
https://bugs.webkit.org/show_bug.cgi?id=191605
<rdar://problem/45813991>

Reviewed by Dean Jackson.

Hook up a couple of editing actions on iOS and macOS. The `-pasteAndMatchStyle:` selector is privately declared
in UIKit, but does not exist on macOS; as such, add `-_pasteAndMatchStyle:` as SPI on WKWebView, and
additionally implement the unprefixed version, `-pasteAndMatchStyle:`, on iOS.

Since `-makeTextWritingDirectionNatural:` is already declared on both iOS and macOS (SPI on UIResponder and API
on macOS, respectively) we simply implement the unprefixed variant on both platforms.

* Platform/spi/ios/UIKitSPI.h:
* UIProcess/API/Cocoa/WKWebView.mm:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView makeTextWritingDirectionNaturalForWebView:]):
(-[WKContentView canPerformActionForWebView:withSender:]):

Tools:
[Cocoa] [WebKit2] Hook up some more editing actions (-pasteAndMatchStyle:, -makeTextWritingDirectionNatural:)
https://bugs.webkit.org/show_bug.cgi?id=191605
<rdar://problem/45813991>

Reviewed by Dean Jackson.

Adds two new API tests to exercise -_pasteAndMatchStyle: and -makeTextWritingDirectionNatural:.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(-[TestWKWebView _synchronouslyExecuteEditCommand:argument:]): Deleted.
* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:

Pull `-_synchronouslyExecuteEditCommand:argument:` out of WKAttachmentTests and into shared code, in a new
category on WKWebView declared in TestWKWebView. Also, fix an unrelated typo in a nearby category.

(-[WKWebView _synchronouslyExecuteEditCommand:argument:]):
* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (238185 => 238186)


--- trunk/Source/WebKit/ChangeLog	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Source/WebKit/ChangeLog	2018-11-14 19:00:04 UTC (rev 238186)
@@ -1,3 +1,26 @@
+2018-11-14  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [Cocoa] [WebKit2] Hook up some more editing actions (-_pasteAndMatchStyle:, -makeTextWritingDirectionNatural:)
+        https://bugs.webkit.org/show_bug.cgi?id=191605
+        <rdar://problem/45813991>
+
+        Reviewed by Dean Jackson.
+
+        Hook up a couple of editing actions on iOS and macOS. The `-pasteAndMatchStyle:` selector is privately declared
+        in UIKit, but does not exist on macOS; as such, add `-_pasteAndMatchStyle:` as SPI on WKWebView, and
+        additionally implement the unprefixed version, `-pasteAndMatchStyle:`, on iOS.
+
+        Since `-makeTextWritingDirectionNatural:` is already declared on both iOS and macOS (SPI on UIResponder and API
+        on macOS, respectively) we simply implement the unprefixed variant on both platforms.
+
+        * Platform/spi/ios/UIKitSPI.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView makeTextWritingDirectionNaturalForWebView:]):
+        (-[WKContentView canPerformActionForWebView:withSender:]):
+
 2018-11-14  Per Arne Vollan  <pvol...@apple.com>
 
         REGRESSION (WEBPROCESS_WINDOWSERVER_BLOCKING): requestAnimationFrame Stops Completing

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (238185 => 238186)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2018-11-14 19:00:04 UTC (rev 238186)
@@ -1078,6 +1078,8 @@
 
 @interface UIResponder ()
 - (UIResponder *)firstResponder;
+- (void)pasteAndMatchStyle:(id)sender;
+- (void)makeTextWritingDirectionNatural:(id)sender;
 @end
 
 @interface _UINavigationInteractiveTransitionBase ()

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (238185 => 238186)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-11-14 19:00:04 UTC (rev 238186)
@@ -4331,7 +4331,8 @@
 WEBCORE_PRIVATE_COMMAND(insertNestedUnorderedList)
 WEBCORE_PRIVATE_COMMAND(indent)
 WEBCORE_PRIVATE_COMMAND(outdent)
-WEBCORE_PRIVATE_COMMAND(pasteAsQuotation);
+WEBCORE_PRIVATE_COMMAND(pasteAsQuotation)
+WEBCORE_PRIVATE_COMMAND(pasteAndMatchStyle)
 
 #undef WEBCORE_PRIVATE_COMMAND
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (238185 => 238186)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-11-14 19:00:04 UTC (rev 238186)
@@ -203,6 +203,7 @@
 - (IBAction)_decreaseListLevel:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (IBAction)_changeListType:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (IBAction)_pasteAsQuotation:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_pasteAndMatchStyle:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 #if TARGET_OS_IPHONE
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (238185 => 238186)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-11-14 19:00:04 UTC (rev 238186)
@@ -132,7 +132,9 @@
     M(alignLeft) \
     M(alignRight) \
     M(alignCenter) \
-    M(alignJustified)
+    M(alignJustified) \
+    M(pasteAndMatchStyle) \
+    M(makeTextWritingDirectionNatural)
 
 #define FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(M) \
     M(_alignCenter) \
@@ -149,7 +151,8 @@
     M(_increaseListLevel) \
     M(_decreaseListLevel) \
     M(_changeListType) \
-    M(_pasteAsQuotation)
+    M(_pasteAsQuotation) \
+    M(_pasteAndMatchStyle)
 
 namespace WebKit {
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (238185 => 238186)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-11-14 19:00:04 UTC (rev 238186)
@@ -2261,6 +2261,11 @@
     return (NSString *)_page->editorState().postLayoutData().wordAtSelection;
 }
 
+- (void)makeTextWritingDirectionNaturalForWebView:(id)sender
+{
+    _page->executeEditCommand("makeTextWritingDirectionNatural"_s);
+}
+
 - (BOOL)isReplaceAllowed
 {
     return _page->editorState().postLayoutData().isReplaceAllowed;
@@ -2308,6 +2313,7 @@
 WEBCORE_COMMAND_FOR_WEBVIEW(alignRight);
 WEBCORE_COMMAND_FOR_WEBVIEW(alignCenter);
 WEBCORE_COMMAND_FOR_WEBVIEW(alignJustified);
+WEBCORE_COMMAND_FOR_WEBVIEW(pasteAndMatchStyle);
 #undef WEBCORE_COMMAND_FOR_WEBVIEW
 
 - (void)_increaseListLevelForWebView:(id)sender
@@ -2448,7 +2454,8 @@
         || action == @selector(increaseSize:) || action == @selector(decreaseSize:)
         || action == @selector(toggleStrikeThrough:) || action == @selector(insertOrderedList:) || action == @selector(insertUnorderedList:) || action == @selector(indent:) || action == @selector(outdent:)
         || action == @selector(alignLeft:) || action == @selector(alignRight:) || action == @selector(alignCenter:) || action == @selector(alignJustified:)
-        || action == @selector(setTextColor:sender:) || action == @selector(setFont:sender:) || action == @selector(setFontSize:sender:)) {
+        || action == @selector(setTextColor:sender:) || action == @selector(setFont:sender:) || action == @selector(setFontSize:sender:)
+        || action == @selector(makeTextWritingDirectionNatural:)) {
         // FIXME: This should be more nuanced in the future, rather than returning YES for all richly editable areas. For instance, outdent: should be disabled when the selection is already
         // at the outermost indentation level.
         return editorState.isContentRichlyEditable;
@@ -2456,7 +2463,7 @@
     if (action == @selector(cut:))
         return !editorState.isInPasswordField && editorState.isContentEditable && editorState.selectionIsRange;
     
-    if (action == @selector(paste:) || action == @selector(_pasteAsQuotation:)) {
+    if (action == @selector(paste:) || action == @selector(_pasteAsQuotation:) || action == @selector(_pasteAndMatchStyle:) || action == @selector(pasteAndMatchStyle:)) {
         if (editorState.selectionIsNone || !editorState.isContentEditable)
             return NO;
         UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

Modified: trunk/Tools/ChangeLog (238185 => 238186)


--- trunk/Tools/ChangeLog	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Tools/ChangeLog	2018-11-14 19:00:04 UTC (rev 238186)
@@ -1,3 +1,26 @@
+2018-11-14  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [Cocoa] [WebKit2] Hook up some more editing actions (-pasteAndMatchStyle:, -makeTextWritingDirectionNatural:)
+        https://bugs.webkit.org/show_bug.cgi?id=191605
+        <rdar://problem/45813991>
+
+        Reviewed by Dean Jackson.
+
+        Adds two new API tests to exercise -_pasteAndMatchStyle: and -makeTextWritingDirectionNatural:.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (-[TestWKWebView _synchronouslyExecuteEditCommand:argument:]): Deleted.
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/cocoa/TestWKWebView.h:
+        * TestWebKitAPI/cocoa/TestWKWebView.mm:
+
+        Pull `-_synchronouslyExecuteEditCommand:argument:` out of WKAttachmentTests and into shared code, in a new
+        category on WKWebView declared in TestWKWebView. Also, fix an unrelated typo in a nearby category.
+
+        (-[WKWebView _synchronouslyExecuteEditCommand:argument:]):
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2018-11-14  Chris Dumez  <cdu...@apple.com>
 
         WebKit.ApplicationManifestBasic API test is failing when enabling PSON

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (238185 => 238186)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2018-11-14 19:00:04 UTC (rev 238186)
@@ -246,18 +246,6 @@
     [self expectElementTagsInOrder:@[tagName, otherTagName]];
 }
 
-- (BOOL)_synchronouslyExecuteEditCommand:(NSString *)command argument:(NSString *)argument
-{
-    __block bool done = false;
-    __block bool success;
-    [self _executeEditCommand:command argument:argument completion:^(BOOL completionSuccess) {
-        done = true;
-        success = completionSuccess;
-    }];
-    TestWebKitAPI::Util::run(&done);
-    return success;
-}
-
 - (_WKAttachment *)synchronouslyInsertAttachmentWithFileWrapper:(NSFileWrapper *)fileWrapper contentType:(NSString *)contentType
 {
     __block bool done = false;

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm (238185 => 238186)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm	2018-11-14 19:00:04 UTC (rev 238186)
@@ -240,6 +240,31 @@
     EXPECT_TRUE([webView querySelectorExists:@"blockquote"]);
 }
 
+TEST(WKWebViewEditActions, PasteAndMatchStyle)
+{
+    auto source = webViewForEditActionTesting();
+    auto destination = webViewForEditActionTesting(@"<div><br></div>");
+
+    [source selectAll:nil];
+    [source evaluateJavaScript:@"document.execCommand('bold'); document.execCommand('underline'); document.execCommand('italic')" completionHandler:nil];
+    [source _synchronouslyExecuteEditCommand:@"Copy" argument:nil];
+
+    [destination _pasteAndMatchStyle:nil];
+    [destination selectAll:nil];
+    EXPECT_FALSE([destination stringByEvaluatingJavaScript:@"document.queryCommandState('bold')"].boolValue);
+    EXPECT_FALSE([destination stringByEvaluatingJavaScript:@"document.queryCommandState('italic')"].boolValue);
+    EXPECT_FALSE([destination stringByEvaluatingJavaScript:@"document.queryCommandState('underline')"].boolValue);
+    EXPECT_WK_STREQ("WebKit", [destination stringByEvaluatingJavaScript:@"getSelection().toString()"]);
+}
+
+TEST(WKWebViewEditActions, ModifyTextWritingDirection)
+{
+    auto webView = webViewForEditActionTesting(@"<div id='text' style='direction: rtl; unicode-bidi: bidi-override;'>WebKit</div>");
+    [webView selectAll:nil];
+    [webView makeTextWritingDirectionNatural:nil];
+    EXPECT_WK_STREQ("normal", [webView stringByEvaluatingJavaScript:@"getComputedStyle(text).unicodeBidi"]);
+}
+
 #if PLATFORM(IOS_FAMILY)
 
 TEST(WKWebViewEditActions, ChangeFontSize)

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h (238185 => 238186)


--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h	2018-11-14 19:00:04 UTC (rev 238186)
@@ -46,6 +46,10 @@
 #endif
 @end
 
+@interface WKWebView (TestWebKitAPI)
+- (BOOL)_synchronouslyExecuteEditCommand:(NSString *)command argument:(NSString *)argument;
+@end
+
 @interface TestMessageHandler : NSObject <WKScriptMessageHandler>
 - (void)addMessage:(NSString *)message withHandler:(dispatch_block_t)handler;
 @end

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm (238185 => 238186)


--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm	2018-11-14 19:00:04 UTC (rev 238186)
@@ -50,7 +50,7 @@
 SOFT_LINK_FRAMEWORK(UIKit)
 SOFT_LINK_CLASS(UIKit, UIWindow)
 
-@implementation WKWebView (WKWebViewTestingQuicks)
+@implementation WKWebView (WKWebViewTestingQuirks)
 
 // TestWebKitAPI is currently not a UIApplication so we are unable to track if it is in
 // the background or not (https://bugs.webkit.org/show_bug.cgi?id=175204). This can
@@ -63,6 +63,22 @@
 @end
 #endif
 
+@implementation WKWebView (TestWebKitAPI)
+
+- (BOOL)_synchronouslyExecuteEditCommand:(NSString *)command argument:(NSString *)argument
+{
+    __block bool done = false;
+    __block bool success;
+    [self _executeEditCommand:command argument:argument completion:^(BOOL completionSuccess) {
+        done = true;
+        success = completionSuccess;
+    }];
+    TestWebKitAPI::Util::run(&done);
+    return success;
+}
+
+@end
+
 @implementation TestMessageHandler {
     NSMutableDictionary<NSString *, dispatch_block_t> *_messageHandlers;
 }

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (238185 => 238186)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2018-11-14 18:49:22 UTC (rev 238185)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2018-11-14 19:00:04 UTC (rev 238186)
@@ -162,6 +162,7 @@
 
 @interface UIResponder (UIKitSPI)
 - (UIResponder *)firstResponder;
+- (void)makeTextWritingDirectionNatural:(id)sender;
 @end
 
 @interface UIKeyboard ()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to