Title: [238050] trunk
Revision
238050
Author
wenson_hs...@apple.com
Date
2018-11-09 12:16:32 -0800 (Fri, 09 Nov 2018)

Log Message

[Cocoa] Introduce WKWebView SPI to insert nested ordered and unordered lists
https://bugs.webkit.org/show_bug.cgi?id=191410
<rdar://problem/45898610>

Reviewed by Dean Jackson.

Source/WebKit:

Prefixes a few iOS-only SPI methods declared on WKWebView in r236867 with underscores, and also exposes some
more cross-platform Cocoa editing SPI. Once the unprefixed SPI methods are no longer used by internal clients,
these will need to be removed (see followup bug: webkit.org/b/191450). See below for more details.

Covered by new and existing API tests in WKWebViewEditActions.

* UIProcess/API/Cocoa/WKWebView.mm:

Hoist the definition (and undefinition) of `FORWARD_ACTION_TO_WKCONTENTVIEW` to encompass both the WKWebView
implementation and the WKWebView (WKPrivate) implementation. This allows us to use this macro when implementing
SPI methods in the WKPrivate category, as well as methods that are part of the main WKWebView implementation.

(-[WKWebView canPerformAction:withSender:]):
(-[WKWebView targetForAction:withSender:]):

Add forwarding for the new editing commands in -canPerformAction: and -targetForAction:.

(-[WKWebView _toggleStrikeThrough:]):
(-[WKWebView _increaseListLevel:]):
(-[WKWebView _decreaseListLevel:]):
(-[WKWebView _changeListType:]):
(-[WKWebView _setFont:sender:]):
(-[WKWebView _setFontSize:sender:]):
(-[WKWebView _setTextColor:sender:]):

Add definitions for the new editing methods on WKWebView, using macros (`WEBCORE_PRIVATE_COMMAND` on macOS and
`FORWARD_ACTION_TO_WKCONTENTVIEW` on iOS) to help reduce the code duplication.

(-[WKWebView _pasteAsQuotation:]): Deleted.

Remove this method definition, which is now replaced by macros on iOS and macOS.

* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Introduce the new SPI to WKWebView (WKPrivate), and add FIXMEs to remove old, unprefixed variants of the SPI.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::increaseListLevel):
(WebKit::WebPageProxy::decreaseListLevel):
(WebKit::WebPageProxy::changeListType):

Add plumbing for these list editing commands.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _increaseListLevelForWebView:]):
(-[WKContentView _decreaseListLevelForWebView:]):
(-[WKContentView _changeListTypeForWebView:]):
(-[WKContentView _toggleStrikeThroughForWebView:]):
(-[WKContentView _setFontForWebView:sender:]):
(-[WKContentView _setFontSizeForWebView:sender:]):
(-[WKContentView _setTextColorForWebView:sender:]):
(-[WKContentView toggleStrikeThroughForWebView:]):
(-[WKContentView setFontForWebView:sender:]):
(-[WKContentView setFontSizeForWebView:sender:]):
(-[WKContentView setTextColorForWebView:sender:]):
(-[WKContentView canPerformActionForWebView:withSender:]):

Check for the new action selectors here, and additionally add validation for `_pasteAsQuotation:`. Let the
unprefixed versions of these methods simply call the prefixed versions (these method implementations will be
removed in a followup once doing so would not affect any clients of WebKit).

* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::increaseListLevel):
(WebKit::WebPage::decreaseListLevel):
(WebKit::WebPage::changeListType):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Add stubs for several list editing commands that are yet to be hooked up to WebCore. These will be implemented
in a future patch.

Tools:

Move WKWebViewEditActions from iOS to WebKitCocoa, and enable the relevant WKWebViewEditActions tests on macOS.
Additionally, add new API tests to verify that `-_pasteAsQuotation:` and `-_insertNested(Un)OrderedList:` are
hooked up to their respective editing commands.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm: Renamed from Tools/TestWebKitAPI/Tests/ios/WKWebViewEditActions.mm.
(-[TestWKWebView querySelectorExists:]):
(-[TestWKWebView insertString:]):

Add a helper method to insert a piece of text. This abstracts platform differences between iOS and macOS, by
invoking the WKWebView directly on macOS and calling on the content view on iOS.

(TestWebKitAPI::webViewForEditActionTesting):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (238049 => 238050)


--- trunk/Source/WebKit/ChangeLog	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/ChangeLog	2018-11-09 20:16:32 UTC (rev 238050)
@@ -1,3 +1,85 @@
+2018-11-09  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [Cocoa] Introduce WKWebView SPI to insert nested ordered and unordered lists
+        https://bugs.webkit.org/show_bug.cgi?id=191410
+        <rdar://problem/45898610>
+
+        Reviewed by Dean Jackson.
+
+        Prefixes a few iOS-only SPI methods declared on WKWebView in r236867 with underscores, and also exposes some
+        more cross-platform Cocoa editing SPI. Once the unprefixed SPI methods are no longer used by internal clients,
+        these will need to be removed (see followup bug: webkit.org/b/191450). See below for more details.
+
+        Covered by new and existing API tests in WKWebViewEditActions.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+
+        Hoist the definition (and undefinition) of `FORWARD_ACTION_TO_WKCONTENTVIEW` to encompass both the WKWebView
+        implementation and the WKWebView (WKPrivate) implementation. This allows us to use this macro when implementing
+        SPI methods in the WKPrivate category, as well as methods that are part of the main WKWebView implementation.
+
+        (-[WKWebView canPerformAction:withSender:]):
+        (-[WKWebView targetForAction:withSender:]):
+
+        Add forwarding for the new editing commands in -canPerformAction: and -targetForAction:.
+
+        (-[WKWebView _toggleStrikeThrough:]):
+        (-[WKWebView _increaseListLevel:]):
+        (-[WKWebView _decreaseListLevel:]):
+        (-[WKWebView _changeListType:]):
+        (-[WKWebView _setFont:sender:]):
+        (-[WKWebView _setFontSize:sender:]):
+        (-[WKWebView _setTextColor:sender:]):
+
+        Add definitions for the new editing methods on WKWebView, using macros (`WEBCORE_PRIVATE_COMMAND` on macOS and
+        `FORWARD_ACTION_TO_WKCONTENTVIEW` on iOS) to help reduce the code duplication.
+
+        (-[WKWebView _pasteAsQuotation:]): Deleted.
+
+        Remove this method definition, which is now replaced by macros on iOS and macOS.
+
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
+        Introduce the new SPI to WKWebView (WKPrivate), and add FIXMEs to remove old, unprefixed variants of the SPI.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::increaseListLevel):
+        (WebKit::WebPageProxy::decreaseListLevel):
+        (WebKit::WebPageProxy::changeListType):
+
+        Add plumbing for these list editing commands.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _increaseListLevelForWebView:]):
+        (-[WKContentView _decreaseListLevelForWebView:]):
+        (-[WKContentView _changeListTypeForWebView:]):
+        (-[WKContentView _toggleStrikeThroughForWebView:]):
+        (-[WKContentView _setFontForWebView:sender:]):
+        (-[WKContentView _setFontSizeForWebView:sender:]):
+        (-[WKContentView _setTextColorForWebView:sender:]):
+        (-[WKContentView toggleStrikeThroughForWebView:]):
+        (-[WKContentView setFontForWebView:sender:]):
+        (-[WKContentView setFontSizeForWebView:sender:]):
+        (-[WKContentView setTextColorForWebView:sender:]):
+        (-[WKContentView canPerformActionForWebView:withSender:]):
+
+        Check for the new action selectors here, and additionally add validation for `_pasteAsQuotation:`. Let the
+        unprefixed versions of these methods simply call the prefixed versions (these method implementations will be
+        removed in a followup once doing so would not affect any clients of WebKit).
+
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::increaseListLevel):
+        (WebKit::WebPage::decreaseListLevel):
+        (WebKit::WebPage::changeListType):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
+        Add stubs for several list editing commands that are yet to be hooked up to WebCore. These will be implemented
+        in a future patch.
+
 2018-11-09  Antti Koivisto  <an...@apple.com>
 
         Use OptionSet for layout milestones

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


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-11-09 20:16:32 UTC (rev 238050)
@@ -257,6 +257,13 @@
 }
 #endif
 
+#define FORWARD_ACTION_TO_WKCONTENTVIEW(_action) \
+    - (void)_action:(id)sender \
+    { \
+        if (self.usesStandardContentView) \
+            [_contentView _action ## ForWebView:sender]; \
+    }
+
 @implementation WKWebView {
     std::unique_ptr<WebKit::NavigationState> _navigationState;
     std::unique_ptr<WebKit::UIDelegate> _uiDelegate;
@@ -1384,17 +1391,8 @@
     return [super resignFirstResponder];
 }
 
-#define FORWARD_ACTION_TO_WKCONTENTVIEW(_action) \
-    - (void)_action:(id)sender \
-    { \
-        if (self.usesStandardContentView) \
-            [_contentView _action ## ForWebView:sender]; \
-    }
-
 FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
 
-#undef FORWARD_ACTION_TO_WKCONTENTVIEW
-
 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
 {
     #define FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_action) \
@@ -1402,14 +1400,16 @@
             return self.usesStandardContentView && [_contentView canPerformActionForWebView:action withSender:sender];
 
     FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW)
+    FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW)
+    FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(setTextColor:sender)
+    FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(setFontSize:sender)
+    FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(setFont:sender)
+    FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_setTextColor:sender)
+    FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_setFontSize:sender)
+    FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_setFont:sender)
 
-    FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_pasteAsQuotation)
-
     #undef FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW
 
-    if (action == @selector(setTextColor:sender:) || action == @selector(setFontSize:sender:) || action == @selector(setFont:sender:))
-        return self.usesStandardContentView && [_contentView canPerformActionForWebView:action withSender:sender];
-
     return [super canPerformAction:action withSender:sender];
 }
 
@@ -1420,9 +1420,14 @@
             return [_contentView targetForActionForWebView:action withSender:sender];
 
     FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW)
+    FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW)
+    FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(setTextColor:sender)
+    FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(setFontSize:sender)
+    FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(setFont:sender)
+    FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_setTextColor:sender)
+    FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_setFontSize:sender)
+    FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_setFont:sender)
 
-    FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_pasteAsQuotation)
-
     #undef FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW
 
     return [super targetForAction:action withSender:sender];
@@ -4292,6 +4297,70 @@
 
 @implementation WKWebView (WKPrivate)
 
+#if PLATFORM(MAC)
+
+#define WEBCORE_PRIVATE_COMMAND(command) - (void)_##command:(id)sender { _page->executeEditCommand(#command ## _s); }
+
+WEBCORE_PRIVATE_COMMAND(alignCenter)
+WEBCORE_PRIVATE_COMMAND(alignJustified)
+WEBCORE_PRIVATE_COMMAND(alignLeft)
+WEBCORE_PRIVATE_COMMAND(alignRight)
+WEBCORE_PRIVATE_COMMAND(insertOrderedList)
+WEBCORE_PRIVATE_COMMAND(insertUnorderedList)
+WEBCORE_PRIVATE_COMMAND(insertNestedOrderedList)
+WEBCORE_PRIVATE_COMMAND(insertNestedUnorderedList)
+WEBCORE_PRIVATE_COMMAND(indent)
+WEBCORE_PRIVATE_COMMAND(outdent)
+WEBCORE_PRIVATE_COMMAND(pasteAsQuotation);
+
+#undef WEBCORE_PRIVATE_COMMAND
+
+- (void)_toggleStrikeThrough:(id)sender
+{
+    _page->executeEditCommand("strikethrough"_s);
+}
+
+- (void)_increaseListLevel:(id)sender
+{
+    _page->increaseListLevel();
+}
+
+- (void)_decreaseListLevel:(id)sender
+{
+    _page->decreaseListLevel();
+}
+
+- (void)_changeListType:(id)sender
+{
+    _page->changeListType();
+}
+
+#endif // PLATFORM(MAC)
+
+#if PLATFORM(IOS_FAMILY)
+
+FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
+
+- (void)_setFont:(UIFont *)font sender:(id)sender
+{
+    if (self.usesStandardContentView)
+        [_contentView setFontForWebView:font sender:sender];
+}
+
+- (void)_setFontSize:(CGFloat)fontSize sender:(id)sender
+{
+    if (self.usesStandardContentView)
+        [_contentView setFontSizeForWebView:fontSize sender:sender];
+}
+
+- (void)_setTextColor:(UIColor *)color sender:(id)sender
+{
+    if (self.usesStandardContentView)
+        [_contentView setTextColorForWebView:color sender:sender];
+}
+
+#endif // PLATFORM(IOS_FAMILY)
+
 - (BOOL)_isEditable
 {
     return _page->isEditable();
@@ -4638,16 +4707,6 @@
     return nil;
 }
 
-- (void)_pasteAsQuotation:(id)sender
-{
-#if PLATFORM(MAC)
-    _impl->executeEditCommandForSelector(_cmd);
-#else
-    if (self.usesStandardContentView)
-        [_contentView _pasteAsQuotationForWebView:sender];
-#endif
-}
-
 + (BOOL)_handlesSafeBrowsing
 {
     return DEFAULT_SAFE_BROWSING_ENABLED;
@@ -6026,6 +6085,7 @@
 
 @end
 
+#undef FORWARD_ACTION_TO_WKCONTENTVIEW
 
 @implementation WKWebView (WKTesting)
 

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


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-11-09 20:16:32 UTC (rev 238050)
@@ -186,11 +186,30 @@
 - (_WKAttachment *)_insertAttachmentWithFileWrapper:(NSFileWrapper *)fileWrapper contentType:(NSString *)contentType completion:(void(^)(BOOL success))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (_WKAttachment *)_attachmentForIdentifier:(NSString *)identifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
++ (BOOL)_handlesSafeBrowsing WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
+- (IBAction)_alignCenter:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_alignJustified:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_alignLeft:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_alignRight:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_indent:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_outdent:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_toggleStrikeThrough:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_insertOrderedList:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_insertUnorderedList:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_insertNestedOrderedList:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_insertNestedUnorderedList:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (IBAction)_increaseListLevel:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (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));
 
-+ (BOOL)_handlesSafeBrowsing WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+#if TARGET_OS_IPHONE
 
-#if TARGET_OS_IPHONE
+- (void)_setFont:(UIFont *)font sender:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_setFontSize:(CGFloat)fontSize sender:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_setTextColor:(UIColor *)color sender:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
 // DERECATED: The setters of the three following function are deprecated, please use overrideLayoutParameters.
 // Define the smallest size a page take with a regular viewport.
 @property (nonatomic, readonly) CGSize _minimumLayoutSizeOverride;
@@ -371,6 +390,7 @@
 #if TARGET_OS_IPHONE
 
 @interface WKWebView () <UIResponderStandardEditActions>
+// FIXME: Remove these once internal clients have moved to the underscore-prefixed versions.
 - (void)alignCenter:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA));
 - (void)alignJustified:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA));
 - (void)alignLeft:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA));

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (238049 => 238050)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2018-11-09 20:16:32 UTC (rev 238050)
@@ -1756,6 +1756,24 @@
     m_process->send(Messages::WebPage::ValidateCommand(commandName, callbackID), m_pageID);
 }
 
+void WebPageProxy::increaseListLevel()
+{
+    if (isValid())
+        m_process->send(Messages::WebPage::IncreaseListLevel(), m_pageID);
+}
+
+void WebPageProxy::decreaseListLevel()
+{
+    if (isValid())
+        m_process->send(Messages::WebPage::DecreaseListLevel(), m_pageID);
+}
+
+void WebPageProxy::changeListType()
+{
+    if (isValid())
+        m_process->send(Messages::WebPage::ChangeListType(), m_pageID);
+}
+
 void WebPageProxy::updateFontAttributesAfterEditorStateChange()
 {
     m_cachedFontAttributesAtSelectionStart.reset();

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (238049 => 238050)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-11-09 20:16:32 UTC (rev 238050)
@@ -545,6 +545,10 @@
     bool hasSelectedRange() const { return m_editorState.selectionIsRange; }
     bool isContentEditable() const { return m_editorState.isContentEditable; }
 
+    void increaseListLevel();
+    void decreaseListLevel();
+    void changeListType();
+
     std::optional<WebCore::FontAttributes> cachedFontAttributesAtSelectionStart() const { return m_cachedFontAttributesAtSelectionStart; }
 
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (238049 => 238050)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-11-09 20:16:32 UTC (rev 238050)
@@ -134,6 +134,23 @@
     M(alignCenter) \
     M(alignJustified)
 
+#define FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(M) \
+    M(_alignCenter) \
+    M(_alignJustified) \
+    M(_alignLeft) \
+    M(_alignRight) \
+    M(_indent) \
+    M(_outdent) \
+    M(_toggleStrikeThrough) \
+    M(_insertOrderedList) \
+    M(_insertUnorderedList) \
+    M(_insertNestedOrderedList) \
+    M(_insertNestedUnorderedList) \
+    M(_increaseListLevel) \
+    M(_decreaseListLevel) \
+    M(_changeListType) \
+    M(_pasteAsQuotation)
+
 namespace WebKit {
 
 struct WKSelectionDrawingInfo {
@@ -339,7 +356,7 @@
 #define DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW(_action) \
     - (void)_action ## ForWebView:(id)sender;
 FOR_EACH_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
-DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW(_pasteAsQuotation)
+FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
 #undef DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW
 
 - (void)setFontForWebView:(UIFont *)fontFamily sender:(id)sender;

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (238049 => 238050)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-11-09 20:16:32 UTC (rev 238050)
@@ -2194,9 +2194,8 @@
     }
 
 FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKWEBVIEW)
+FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKWEBVIEW)
 
-FORWARD_ACTION_TO_WKWEBVIEW(_pasteAsQuotation)
-
 #undef FORWARD_ACTION_TO_WKWEBVIEW
 
 - (void)_lookupForWebView:(id)sender
@@ -2285,10 +2284,13 @@
     [[UIKeyboardImpl sharedInstance] replaceText:sender];
 }
 
-#define WEBCORE_COMMAND_FOR_WEBVIEW(command) - (void)command ## ForWebView:(id)sender { _page->executeEditCommand(#command ## _s); }
-
+#define WEBCORE_COMMAND_FOR_WEBVIEW(command) \
+    - (void)_ ## command ## ForWebView:(id)sender { _page->executeEditCommand(#command ## _s); } \
+    - (void)command ## ForWebView:(id)sender { [self _ ## command ## ForWebView:sender]; }
 WEBCORE_COMMAND_FOR_WEBVIEW(insertOrderedList);
 WEBCORE_COMMAND_FOR_WEBVIEW(insertUnorderedList);
+WEBCORE_COMMAND_FOR_WEBVIEW(insertNestedOrderedList);
+WEBCORE_COMMAND_FOR_WEBVIEW(insertNestedUnorderedList);
 WEBCORE_COMMAND_FOR_WEBVIEW(indent);
 WEBCORE_COMMAND_FOR_WEBVIEW(outdent);
 WEBCORE_COMMAND_FOR_WEBVIEW(alignLeft);
@@ -2295,9 +2297,25 @@
 WEBCORE_COMMAND_FOR_WEBVIEW(alignRight);
 WEBCORE_COMMAND_FOR_WEBVIEW(alignCenter);
 WEBCORE_COMMAND_FOR_WEBVIEW(alignJustified);
+#undef WEBCORE_COMMAND_FOR_WEBVIEW
 
-- (void)toggleStrikeThroughForWebView:(id)sender
+- (void)_increaseListLevelForWebView:(id)sender
 {
+    _page->increaseListLevel();
+}
+
+- (void)_decreaseListLevelForWebView:(id)sender
+{
+    _page->decreaseListLevel();
+}
+
+- (void)_changeListTypeForWebView:(id)sender
+{
+    _page->changeListType();
+}
+
+- (void)_toggleStrikeThroughForWebView:(id)sender
+{
     _page->executeEditCommand("StrikeThrough"_s);
 }
 
@@ -2311,7 +2329,7 @@
     _page->executeEditCommand("FontSizeDelta"_s, "-1"_s);
 }
 
-- (void)setFontForWebView:(UIFont *)font sender:(id)sender
+- (void)_setFontForWebView:(UIFont *)font sender:(id)sender
 {
     WebCore::FontChanges changes;
     changes.setFontFamily(font.familyName);
@@ -2322,7 +2340,7 @@
     _page->changeFont(WTFMove(changes));
 }
 
-- (void)setFontSizeForWebView:(CGFloat)fontSize sender:(id)sender
+- (void)_setFontSizeForWebView:(CGFloat)fontSize sender:(id)sender
 {
     WebCore::FontChanges changes;
     changes.setFontSize(fontSize);
@@ -2329,13 +2347,31 @@
     _page->changeFont(WTFMove(changes));
 }
 
-- (void)setTextColorForWebView:(UIColor *)color sender:(id)sender
+- (void)_setTextColorForWebView:(UIColor *)color sender:(id)sender
 {
     _page->executeEditCommand("ForeColor"_s, WebCore::Color(color.CGColor).serialized());
 }
 
-#undef WEBCORE_COMMAND_FOR_WEBVIEW
+- (void)toggleStrikeThroughForWebView:(id)sender
+{
+    [self _toggleStrikeThroughForWebView:sender];
+}
 
+- (void)setFontForWebView:(UIFont *)font sender:(id)sender
+{
+    [self _setFontForWebView:font sender:sender];
+}
+
+- (void)setFontSizeForWebView:(CGFloat)fontSize sender:(id)sender
+{
+    [self _setFontSizeForWebView:fontSize sender:sender];
+}
+
+- (void)setTextColorForWebView:(UIColor *)color sender:(id)sender
+{
+    [self _setTextColorForWebView:color sender:sender];
+}
+
 - (NSDictionary *)textStylingAtPosition:(UITextPosition *)position inDirection:(UITextStorageDirection)direction
 {
     if (!position || !_page->editorState().isContentRichlyEditable)
@@ -2392,11 +2428,16 @@
         return editorState.isContentRichlyEditable && editorState.selectionIsRange && !_showingTextStyleOptions;
     if (_showingTextStyleOptions)
         return (action == @selector(toggleBoldface:) || action == @selector(toggleItalics:) || action == @selector(toggleUnderline:));
-    if (action == @selector(toggleBoldface:) || action == @selector(toggleItalics:) || action == @selector(toggleUnderline:) || action == @selector(toggleStrikeThrough:)
-        || action == @selector(insertOrderedList:) || action == @selector(insertUnorderedList:) || action == @selector(indent:) || action == @selector(outdent:)
+    // FIXME: Some of the following checks should be removed once internal clients move to the underscore-prefixed versions.
+    if (action == @selector(toggleBoldface:) || action == @selector(toggleItalics:) || action == @selector(toggleUnderline:) || action == @selector(_toggleStrikeThrough:)
+        || 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(_insertOrderedList:) || action == @selector(_insertUnorderedList:) || action == @selector(_insertNestedOrderedList:) || action == @selector(_insertNestedUnorderedList:)
+        || action == @selector(_increaseListLevel:) || action == @selector(_decreaseListLevel:) || action == @selector(_changeListType:) || action == @selector(_indent:) || action == @selector(_outdent:)
+        || 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(increaseSize:) || action == @selector(decreaseSize:) || action == @selector(setTextColor:sender:)
-        || action == @selector(setFont:sender:) || action == @selector(setFontSize:sender:)) {
+        || action == @selector(setTextColor:sender:) || action == @selector(setFont:sender:) || action == @selector(setFontSize:sender:)) {
         // 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;
@@ -2404,7 +2445,7 @@
     if (action == @selector(cut:))
         return !editorState.isInPasswordField && editorState.isContentEditable && editorState.selectionIsRange;
     
-    if (action == @selector(paste:)) {
+    if (action == @selector(paste:) || action == @selector(_pasteAsQuotation:)) {
         if (editorState.selectionIsNone || !editorState.isContentEditable)
             return NO;
         UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (238049 => 238050)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-11-09 20:16:32 UTC (rev 238050)
@@ -1150,6 +1150,21 @@
     }
 }
 
+void WebPage::increaseListLevel()
+{
+    // FIXME: Not implemented.
+}
+
+void WebPage::decreaseListLevel()
+{
+    // FIXME: Not implemented.
+}
+
+void WebPage::changeListType()
+{
+    // FIXME: Not implemented.
+}
+
 bool WebPage::isEditingCommandEnabled(const String& commandName)
 {
     Frame& frame = m_page->focusController().focusedOrMainFrame();

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (238049 => 238050)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-11-09 20:16:32 UTC (rev 238050)
@@ -1186,6 +1186,10 @@
     void executeEditCommand(const String&, const String&);
     void setEditable(bool);
 
+    void increaseListLevel();
+    void decreaseListLevel();
+    void changeListType();
+
     void setNeedsFontAttributes(bool);
 
     void mouseEvent(const WebMouseEvent&);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (238049 => 238050)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2018-11-09 20:16:32 UTC (rev 238050)
@@ -212,6 +212,10 @@
     ValidateCommand(String name, WebKit::CallbackID callbackID)
     ExecuteEditCommand(String name, String argument)
 
+    IncreaseListLevel()
+    DecreaseListLevel()
+    ChangeListType()
+
     SetNeedsFontAttributes(bool needsFontAttributes)
 
     RequestFontAttributesAtSelectionStart(WebKit::CallbackID callbackID)

Modified: trunk/Tools/ChangeLog (238049 => 238050)


--- trunk/Tools/ChangeLog	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Tools/ChangeLog	2018-11-09 20:16:32 UTC (rev 238050)
@@ -1,3 +1,26 @@
+2018-11-09  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [Cocoa] Introduce WKWebView SPI to insert nested ordered and unordered lists
+        https://bugs.webkit.org/show_bug.cgi?id=191410
+        <rdar://problem/45898610>
+
+        Reviewed by Dean Jackson.
+
+        Move WKWebViewEditActions from iOS to WebKitCocoa, and enable the relevant WKWebViewEditActions tests on macOS.
+        Additionally, add new API tests to verify that `-_pasteAsQuotation:` and `-_insertNested(Un)OrderedList:` are
+        hooked up to their respective editing commands.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm: Renamed from Tools/TestWebKitAPI/Tests/ios/WKWebViewEditActions.mm.
+        (-[TestWKWebView querySelectorExists:]):
+        (-[TestWKWebView insertString:]):
+
+        Add a helper method to insert a piece of text. This abstracts platform differences between iOS and macOS, by
+        invoking the WKWebView directly on macOS and calling on the content view on iOS.
+
+        (TestWebKitAPI::webViewForEditActionTesting):
+        (TestWebKitAPI::TEST):
+
 2018-11-09  Philippe Normand  <pnorm...@igalia.com>
 
         [Flatpak] Refactoring and drive-by fixes

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (238049 => 238050)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-11-09 20:16:32 UTC (rev 238050)
@@ -846,6 +846,7 @@
 		F46A095A1ED8A6E600D4AA55 /* apple.gif in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47D30EB1ED28619000482E1 /* apple.gif */; };
 		F46A095B1ED8A6E600D4AA55 /* gif-and-file-input.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47D30ED1ED28A6C000482E1 /* gif-and-file-input.html */; };
 		F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */; };
+		F4811E5921940BDE00A5E0FD /* WKWebViewEditActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */; };
 		F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4856CA21E6498A8009D7EE7 /* attachment-element.html */; };
 		F486B1D01F67952300F34BDD /* DataTransfer-setDragImage.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */; };
 		F4A32EC41F05F3850047C544 /* dragstart-change-selection-offscreen.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4A32EC31F05F3780047C544 /* dragstart-change-selection-offscreen.html */; };
@@ -878,7 +879,6 @@
 		F4F5BB5221667BAA002D06B9 /* TestFontOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4F5BB5121667BAA002D06B9 /* TestFontOptions.mm */; };
 		F4FA91811E61849B007B8C1D /* WKWebViewMacEditingTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FA917F1E61849B007B8C1D /* WKWebViewMacEditingTests.mm */; };
 		F4FA91831E61857B007B8C1D /* double-click-does-not-select-trailing-space.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4FA91821E618566007B8C1D /* double-click-does-not-select-trailing-space.html */; };
-		F4FB682521643EFC0034607A /* WKWebViewEditActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FB682421643EFC0034607A /* WKWebViewEditActions.mm */; };
 		F4FC077720F013B600CA043C /* significant-text-milestone.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4FC077620F0108100CA043C /* significant-text-milestone.html */; };
 		F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; };
 		F660AA1515A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA1415A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp */; };
@@ -2131,6 +2131,7 @@
 		F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-page-contenteditable.html"; sourceTree = "<group>"; };
 		F47D30EB1ED28619000482E1 /* apple.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = apple.gif; sourceTree = "<group>"; };
 		F47D30ED1ED28A6C000482E1 /* gif-and-file-input.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "gif-and-file-input.html"; sourceTree = "<group>"; };
+		F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewEditActions.mm; sourceTree = "<group>"; };
 		F4856CA21E6498A8009D7EE7 /* attachment-element.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "attachment-element.html"; sourceTree = "<group>"; };
 		F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "DataTransfer-setDragImage.html"; sourceTree = "<group>"; };
 		F493247C1F44DF8D006F4336 /* UIKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIKitSPI.h; sourceTree = "<group>"; };
@@ -2166,7 +2167,6 @@
 		F4F5BB5121667BAA002D06B9 /* TestFontOptions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TestFontOptions.mm; sourceTree = "<group>"; };
 		F4FA917F1E61849B007B8C1D /* WKWebViewMacEditingTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewMacEditingTests.mm; sourceTree = "<group>"; };
 		F4FA91821E618566007B8C1D /* double-click-does-not-select-trailing-space.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "double-click-does-not-select-trailing-space.html"; path = "Tests/WebKitCocoa/double-click-does-not-select-trailing-space.html"; sourceTree = SOURCE_ROOT; };
-		F4FB682421643EFC0034607A /* WKWebViewEditActions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewEditActions.mm; sourceTree = "<group>"; };
 		F4FC077620F0108100CA043C /* significant-text-milestone.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "significant-text-milestone.html"; sourceTree = "<group>"; };
 		F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; };
 		F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback_Bundle.cpp; sourceTree = "<group>"; };
@@ -2514,6 +2514,7 @@
 				7C417F311D19E14800B8EF53 /* WKWebViewDefaultNavigationDelegate.mm */,
 				46E66A8F1F0D75590026D83C /* WKWebViewDiagnosticLogging.mm */,
 				2DB647871F4161F70051A89E /* WKWebViewDoesNotLogDuringInitialization.mm */,
+				F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */,
 				0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
 				D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */,
 				37A9DBE7213B4C9300D261A2 /* WKWebViewServerTrustKVC.mm */,
@@ -2632,7 +2633,6 @@
 				F46849BD1EEF58E400B937FE /* UIPasteboardTests.mm */,
 				F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */,
 				514958BD1F7427AC00E87BAD /* WKWebViewAutofillTests.mm */,
-				F4FB682421643EFC0034607A /* WKWebViewEditActions.mm */,
 			);
 			path = ios;
 			sourceTree = "<group>";
@@ -4175,7 +4175,7 @@
 				7C417F331D19E14800B8EF53 /* WKWebViewDefaultNavigationDelegate.mm in Sources */,
 				46E66A901F0D75590026D83C /* WKWebViewDiagnosticLogging.mm in Sources */,
 				2DB647881F4163D60051A89E /* WKWebViewDoesNotLogDuringInitialization.mm in Sources */,
-				F4FB682521643EFC0034607A /* WKWebViewEditActions.mm in Sources */,
+				F4811E5921940BDE00A5E0FD /* WKWebViewEditActions.mm in Sources */,
 				0F3B94A71A77267400DE3272 /* WKWebViewEvaluateJavaScript.mm in Sources */,
 				D34E08761E4E42E1005FF14A /* WKWebViewGetContents.mm in Sources */,
 				F4FA91811E61849B007B8C1D /* WKWebViewMacEditingTests.mm in Sources */,

Copied: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm (from rev 238049, trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewEditActions.mm) (0 => 238050)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm	2018-11-09 20:16:32 UTC (rev 238050)
@@ -0,0 +1,242 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if WK_API_ENABLED
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKWebViewPrivate.h>
+
+#if PLATFORM(IOS_FAMILY)
+#import "UIKitSPI.h"
+#import <UIKit/UIFontDescriptor.h>
+#endif
+
+@interface TestWKWebView (EditActionTesting)
+- (BOOL)querySelectorExists:(NSString *)querySelector;
+- (void)insertString:(NSString *)string;
+@end
+
+@implementation TestWKWebView (EditActionTesting)
+
+- (BOOL)querySelectorExists:(NSString *)querySelector
+{
+    return [[self objectByEvaluatingJavaScript:[NSString stringWithFormat:@"!!document.querySelector(`%@`)", querySelector]] boolValue];
+}
+
+- (void)insertString:(NSString *)string
+{
+#if PLATFORM(IOS_FAMILY)
+    [[self textInputContentView] insertText:string];
+#else
+    [self insertText:string];
+#endif
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+static RetainPtr<TestWKWebView> webViewForEditActionTesting()
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView synchronouslyLoadHTMLString:@"<div>WebKit</div>"];
+    [webView _setEditable:YES];
+    [webView stringByEvaluatingJavaScript:@"getSelection().setPosition(document.body, 1)"];
+    return webView;
+}
+
+TEST(WKWebViewEditActions, NestedListInsertion)
+{
+    auto webView = webViewForEditActionTesting();
+
+    [webView _insertNestedOrderedList:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ol"]);
+    EXPECT_TRUE([webView querySelectorExists:@"ol > li"]);
+
+    [webView _insertNestedOrderedList:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ol > ol"]);
+    EXPECT_TRUE([webView querySelectorExists:@"ol > ol > li"]);
+
+    [webView _insertNestedUnorderedList:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ol > ol > ul"]);
+    EXPECT_TRUE([webView querySelectorExists:@"ol > ol > ul > li"]);
+
+    [webView _insertNestedUnorderedList:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ol > ol > ul > ul"]);
+    EXPECT_TRUE([webView querySelectorExists:@"ol > ol > ul > ul > li"]);
+}
+
+TEST(WKWebViewEditActions, ListInsertion)
+{
+    auto webView = webViewForEditActionTesting();
+
+    [webView _insertOrderedList:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ol"]);
+    [webView _insertOrderedList:nil];
+    EXPECT_FALSE([webView querySelectorExists:@"ol"]);
+
+    [webView _insertUnorderedList:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ul"]);
+    [webView _insertUnorderedList:nil];
+    EXPECT_FALSE([webView querySelectorExists:@"ul"]);
+}
+
+TEST(WKWebViewEditActions, ChangeIndentation)
+{
+    auto webView = webViewForEditActionTesting();
+
+    [webView _indent:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"blockquote"]);
+    [webView _indent:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"blockquote > blockquote"]);
+
+    [webView _outdent:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"blockquote"]);
+    [webView _outdent:nil];
+    EXPECT_FALSE([webView querySelectorExists:@"blockquote"]);
+}
+
+TEST(WKWebViewEditActions, SetAlignment)
+{
+    auto webView = webViewForEditActionTesting();
+    auto runTest = [webView] {
+        [webView _alignCenter:nil];
+        EXPECT_WK_STREQ("center", [webView stylePropertyAtSelectionStart:@"text-align"]);
+        [webView _alignLeft:nil];
+        EXPECT_WK_STREQ("left", [webView stylePropertyAtSelectionStart:@"text-align"]);
+        [webView _alignRight:nil];
+        EXPECT_WK_STREQ("right", [webView stylePropertyAtSelectionStart:@"text-align"]);
+        [webView _alignJustified:nil];
+        EXPECT_WK_STREQ("justify", [webView stylePropertyAtSelectionStart:@"text-align"]);
+    };
+
+    [webView evaluateJavaScript:@"document.body.dir = 'rtl'" completionHandler:nil];
+    runTest();
+
+    [webView evaluateJavaScript:@"document.body.dir = 'ltr'" completionHandler:nil];
+    runTest();
+}
+
+TEST(WKWebViewEditActions, ToggleStrikeThrough)
+{
+    auto webView = webViewForEditActionTesting();
+    [webView selectAll:nil];
+    [webView _toggleStrikeThrough:nil];
+    EXPECT_WK_STREQ("line-through", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]);
+    EXPECT_WK_STREQ("line-through", [webView stylePropertyAtSelectionEnd:@"-webkit-text-decorations-in-effect"]);
+
+    [webView _toggleStrikeThrough:nil];
+    EXPECT_WK_STREQ("none", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]);
+    EXPECT_WK_STREQ("none", [webView stylePropertyAtSelectionEnd:@"-webkit-text-decorations-in-effect"]);
+
+    [webView collapseToEnd];
+    [webView _toggleStrikeThrough:nil];
+    [webView insertString:@"Hello"];
+    EXPECT_WK_STREQ("line-through", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]);
+
+    [webView _toggleStrikeThrough:nil];
+    [webView insertString:@"Hello"];
+    EXPECT_WK_STREQ("none", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]);
+}
+
+TEST(WKWebViewEditActions, PasteAsQuotation)
+{
+    auto webView = webViewForEditActionTesting();
+    [webView selectAll:nil];
+    [webView _executeEditCommand:@"cut" argument:nil completion:nil];
+    [webView _pasteAsQuotation:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"blockquote"]);
+}
+
+#if PLATFORM(IOS_FAMILY)
+
+TEST(WKWebViewEditActions, ChangeFontSize)
+{
+    auto webView = webViewForEditActionTesting();
+    [webView selectAll:nil];
+    EXPECT_EQ(16, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
+
+    [webView increaseSize:nil];
+    EXPECT_EQ(17, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
+    [webView increaseSize:nil];
+    EXPECT_EQ(18, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
+
+    [webView decreaseSize:nil];
+    EXPECT_EQ(17, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
+    [webView decreaseSize:nil];
+    EXPECT_EQ(16, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
+
+    [webView _setFontSize:20 sender:nil];
+    EXPECT_EQ(20, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
+}
+
+TEST(WKWebViewEditActions, SetTextColor)
+{
+    auto webView = webViewForEditActionTesting();
+    [webView selectAll:nil];
+
+    [webView _setTextColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:1] sender:nil];
+    EXPECT_WK_STREQ("rgb(255, 0, 0)", [webView stylePropertyAtSelectionStart:@"color"]);
+    EXPECT_TRUE([webView querySelectorExists:@"font"]);
+
+    [webView _setTextColor:[UIColor colorWithRed:0 green:1 blue:0 alpha:0.2] sender:nil];
+    EXPECT_WK_STREQ("rgba(0, 255, 0, 0.2)", [webView stylePropertyAtSelectionStart:@"color"]);
+    EXPECT_FALSE([webView querySelectorExists:@"font"]);
+}
+
+TEST(WKWebViewEditActions, SetFontFamily)
+{
+    auto webView = webViewForEditActionTesting();
+    [webView selectAll:nil];
+
+    UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:@{ UIFontDescriptorFamilyAttribute: @"Helvetica" }];
+    [webView _setFont:[UIFont fontWithDescriptor:fontDescriptor size:24] sender:nil];
+    EXPECT_WK_STREQ("Helvetica", [webView stylePropertyAtSelectionStart:@"font-family"]);
+    EXPECT_WK_STREQ("24px", [webView stylePropertyAtSelectionStart:@"font-size"]);
+    EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-weight"]);
+    EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-style"]);
+
+    [webView _setFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:12] sender:nil];
+    EXPECT_WK_STREQ("\"Times New Roman\"", [webView stylePropertyAtSelectionStart:@"font-family"]);
+    EXPECT_WK_STREQ("12px", [webView stylePropertyAtSelectionStart:@"font-size"]);
+    EXPECT_WK_STREQ("bold", [webView stylePropertyAtSelectionStart:@"font-weight"]);
+    EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-style"]);
+
+    fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic | UIFontDescriptorTraitBold];
+    [webView _setFont:[UIFont fontWithDescriptor:fontDescriptor size:20] sender:nil];
+    EXPECT_WK_STREQ("Helvetica", [webView stylePropertyAtSelectionStart:@"font-family"]);
+    EXPECT_WK_STREQ("20px", [webView stylePropertyAtSelectionStart:@"font-size"]);
+    EXPECT_WK_STREQ("bold", [webView stylePropertyAtSelectionStart:@"font-weight"]);
+    EXPECT_WK_STREQ("italic", [webView stylePropertyAtSelectionStart:@"font-style"]);
+}
+
+#endif // PLATFORM(IOS_FAMILY)
+
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED

Deleted: trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewEditActions.mm (238049 => 238050)


--- trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewEditActions.mm	2018-11-09 19:47:15 UTC (rev 238049)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewEditActions.mm	2018-11-09 20:16:32 UTC (rev 238050)
@@ -1,195 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-
-#if PLATFORM(IOS_FAMILY) && WK_API_ENABLED
-
-#import "PlatformUtilities.h"
-#import "TestWKWebView.h"
-#import "UIKitSPI.h"
-#import <UIKit/UIFontDescriptor.h>
-#import <WebKit/WKWebViewPrivate.h>
-
-@interface TestWKWebView (EditActionTesting)
-- (BOOL)querySelectorExists:(NSString *)querySelector;
-@end
-
-@implementation TestWKWebView (EditActionTesting)
-
-- (BOOL)querySelectorExists:(NSString *)querySelector
-{
-    return [[self objectByEvaluatingJavaScript:[NSString stringWithFormat:@"!!document.querySelector(`%@`)", querySelector]] boolValue];
-}
-
-@end
-
-namespace TestWebKitAPI {
-
-static RetainPtr<TestWKWebView> webViewForEditActionTesting()
-{
-    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
-    [webView synchronouslyLoadHTMLString:@"<div>WebKit</div>"];
-    [webView _setEditable:YES];
-    [webView stringByEvaluatingJavaScript:@"getSelection().setPosition(document.body, 1)"];
-    return webView;
-}
-
-TEST(WKWebViewEditActions, ListInsertion)
-{
-    auto webView = webViewForEditActionTesting();
-
-    [webView insertOrderedList:nil];
-    EXPECT_TRUE([webView querySelectorExists:@"ol"]);
-    [webView insertOrderedList:nil];
-    EXPECT_FALSE([webView querySelectorExists:@"ol"]);
-
-    [webView insertUnorderedList:nil];
-    EXPECT_TRUE([webView querySelectorExists:@"ul"]);
-    [webView insertUnorderedList:nil];
-    EXPECT_FALSE([webView querySelectorExists:@"ul"]);
-}
-
-TEST(WKWebViewEditActions, ChangeIndentation)
-{
-    auto webView = webViewForEditActionTesting();
-
-    [webView indent:nil];
-    EXPECT_TRUE([webView querySelectorExists:@"blockquote"]);
-    [webView indent:nil];
-    EXPECT_TRUE([webView querySelectorExists:@"blockquote > blockquote"]);
-
-    [webView outdent:nil];
-    EXPECT_TRUE([webView querySelectorExists:@"blockquote"]);
-    [webView outdent:nil];
-    EXPECT_FALSE([webView querySelectorExists:@"blockquote"]);
-}
-
-TEST(WKWebViewEditActions, SetAlignment)
-{
-    auto webView = webViewForEditActionTesting();
-    auto runTest = [webView] {
-        [webView alignCenter:nil];
-        EXPECT_WK_STREQ("center", [webView stylePropertyAtSelectionStart:@"text-align"]);
-        [webView alignLeft:nil];
-        EXPECT_WK_STREQ("left", [webView stylePropertyAtSelectionStart:@"text-align"]);
-        [webView alignRight:nil];
-        EXPECT_WK_STREQ("right", [webView stylePropertyAtSelectionStart:@"text-align"]);
-        [webView alignJustified:nil];
-        EXPECT_WK_STREQ("justify", [webView stylePropertyAtSelectionStart:@"text-align"]);
-    };
-
-    [webView evaluateJavaScript:@"document.body.dir = 'rtl'" completionHandler:nil];
-    runTest();
-
-    [webView evaluateJavaScript:@"document.body.dir = 'ltr'" completionHandler:nil];
-    runTest();
-}
-
-TEST(WKWebViewEditActions, ToggleStrikeThrough)
-{
-    auto webView = webViewForEditActionTesting();
-    [webView selectAll:nil];
-    [webView toggleStrikeThrough:nil];
-    EXPECT_WK_STREQ("line-through", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]);
-    EXPECT_WK_STREQ("line-through", [webView stylePropertyAtSelectionEnd:@"-webkit-text-decorations-in-effect"]);
-
-    [webView toggleStrikeThrough:nil];
-    EXPECT_WK_STREQ("none", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]);
-    EXPECT_WK_STREQ("none", [webView stylePropertyAtSelectionEnd:@"-webkit-text-decorations-in-effect"]);
-
-    [webView collapseToEnd];
-    [webView toggleStrikeThrough:nil];
-    [[webView textInputContentView] insertText:@"Hello"];
-    EXPECT_WK_STREQ("line-through", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]);
-
-    [webView toggleStrikeThrough:nil];
-    [[webView textInputContentView] insertText:@"Hello"];
-    EXPECT_WK_STREQ("none", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]);
-}
-
-TEST(WKWebViewEditActions, ChangeFontSize)
-{
-    auto webView = webViewForEditActionTesting();
-    [webView selectAll:nil];
-    EXPECT_EQ(16, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
-
-    [webView increaseSize:nil];
-    EXPECT_EQ(17, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
-    [webView increaseSize:nil];
-    EXPECT_EQ(18, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
-
-    [webView decreaseSize:nil];
-    EXPECT_EQ(17, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
-    [webView decreaseSize:nil];
-    EXPECT_EQ(16, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
-
-    [webView setFontSize:20 sender:nil];
-    EXPECT_EQ(20, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]);
-}
-
-TEST(WKWebViewEditActions, SetTextColor)
-{
-    auto webView = webViewForEditActionTesting();
-    [webView selectAll:nil];
-
-    [webView setTextColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:1] sender:nil];
-    EXPECT_WK_STREQ("rgb(255, 0, 0)", [webView stylePropertyAtSelectionStart:@"color"]);
-    EXPECT_TRUE([webView querySelectorExists:@"font"]);
-
-    [webView setTextColor:[UIColor colorWithRed:0 green:1 blue:0 alpha:0.2] sender:nil];
-    EXPECT_WK_STREQ("rgba(0, 255, 0, 0.2)", [webView stylePropertyAtSelectionStart:@"color"]);
-    EXPECT_FALSE([webView querySelectorExists:@"font"]);
-}
-
-TEST(WKWebViewEditActions, SetFontFamily)
-{
-    auto webView = webViewForEditActionTesting();
-    [webView selectAll:nil];
-
-    UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:@{ UIFontDescriptorFamilyAttribute: @"Helvetica" }];
-    [webView setFont:[UIFont fontWithDescriptor:fontDescriptor size:24] sender:nil];
-    EXPECT_WK_STREQ("Helvetica", [webView stylePropertyAtSelectionStart:@"font-family"]);
-    EXPECT_WK_STREQ("24px", [webView stylePropertyAtSelectionStart:@"font-size"]);
-    EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-weight"]);
-    EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-style"]);
-
-    [webView setFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:12] sender:nil];
-    EXPECT_WK_STREQ("\"Times New Roman\"", [webView stylePropertyAtSelectionStart:@"font-family"]);
-    EXPECT_WK_STREQ("12px", [webView stylePropertyAtSelectionStart:@"font-size"]);
-    EXPECT_WK_STREQ("bold", [webView stylePropertyAtSelectionStart:@"font-weight"]);
-    EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-style"]);
-
-    fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic | UIFontDescriptorTraitBold];
-    [webView setFont:[UIFont fontWithDescriptor:fontDescriptor size:20] sender:nil];
-    EXPECT_WK_STREQ("Helvetica", [webView stylePropertyAtSelectionStart:@"font-family"]);
-    EXPECT_WK_STREQ("20px", [webView stylePropertyAtSelectionStart:@"font-size"]);
-    EXPECT_WK_STREQ("bold", [webView stylePropertyAtSelectionStart:@"font-weight"]);
-    EXPECT_WK_STREQ("italic", [webView stylePropertyAtSelectionStart:@"font-style"]);
-}
-
-} // namespace TestWebKitAPI
-
-#endif // PLATFORM(IOS_FAMILY) && WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to