Title: [238057] trunk
Revision
238057
Author
[email protected]
Date
2018-11-09 14:50:47 -0800 (Fri, 09 Nov 2018)

Log Message

[Cocoa] Implement SPI on WKWebView to increase and decrease list levels
https://bugs.webkit.org/show_bug.cgi?id=191471
<rdar://problem/45952472>

Reviewed by Tim Horton.

Source/WebCore:

Add new method stubs for changing the list type for the current selection (to be implemented in a future patch).

* editing/Editor.cpp:
(WebCore::Editor::canChangeSelectionListType):
(WebCore::Editor::changeSelectionListType):
* editing/Editor.h:

Source/WebKit:

Implement these method stubs by calling into Editor.

Test: WKWebViewEditActions.ModifyListLevel

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::increaseListLevel):
(WebKit::WebPage::decreaseListLevel):
(WebKit::WebPage::changeListType):

Tools:

Add an API test to ensure that list levels can be incremented and decremented via WKWebView SPI.

* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm:
(TestWebKitAPI::webViewForEditActionTesting):
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (238056 => 238057)


--- trunk/Source/WebCore/ChangeLog	2018-11-09 22:34:47 UTC (rev 238056)
+++ trunk/Source/WebCore/ChangeLog	2018-11-09 22:50:47 UTC (rev 238057)
@@ -1,3 +1,18 @@
+2018-11-09  Wenson Hsieh  <[email protected]>
+
+        [Cocoa] Implement SPI on WKWebView to increase and decrease list levels
+        https://bugs.webkit.org/show_bug.cgi?id=191471
+        <rdar://problem/45952472>
+
+        Reviewed by Tim Horton.
+
+        Add new method stubs for changing the list type for the current selection (to be implemented in a future patch).
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::canChangeSelectionListType):
+        (WebCore::Editor::changeSelectionListType):
+        * editing/Editor.h:
+
 2018-11-09  Keith Rollin  <[email protected]>
 
         Unreviewed build fix after https://bugs.webkit.org/show_bug.cgi?id=191324

Modified: trunk/Source/WebCore/editing/Editor.cpp (238056 => 238057)


--- trunk/Source/WebCore/editing/Editor.cpp	2018-11-09 22:34:47 UTC (rev 238056)
+++ trunk/Source/WebCore/editing/Editor.cpp	2018-11-09 22:50:47 UTC (rev 238057)
@@ -1476,6 +1476,17 @@
     setStartNewKillRingSequence(false);
 }
 
+bool Editor::canChangeSelectionListType()
+{
+    // FIXME: Not implemented.
+    return false;
+}
+
+void Editor::changeSelectionListType()
+{
+    // FIXME: Not implemented.
+}
+
 void Editor::simplifyMarkup(Node* startNode, Node* endNode)
 {
     if (!startNode)

Modified: trunk/Source/WebCore/editing/Editor.h (238056 => 238057)


--- trunk/Source/WebCore/editing/Editor.h	2018-11-09 22:34:47 UTC (rev 238056)
+++ trunk/Source/WebCore/editing/Editor.h	2018-11-09 22:50:47 UTC (rev 238057)
@@ -206,6 +206,8 @@
     WEBCORE_EXPORT RefPtr<Node> increaseSelectionListLevelOrdered();
     WEBCORE_EXPORT RefPtr<Node> increaseSelectionListLevelUnordered();
     WEBCORE_EXPORT void decreaseSelectionListLevel();
+    WEBCORE_EXPORT bool canChangeSelectionListType();
+    WEBCORE_EXPORT void changeSelectionListType();
    
     void removeFormattingAndStyle();
 

Modified: trunk/Source/WebKit/ChangeLog (238056 => 238057)


--- trunk/Source/WebKit/ChangeLog	2018-11-09 22:34:47 UTC (rev 238056)
+++ trunk/Source/WebKit/ChangeLog	2018-11-09 22:50:47 UTC (rev 238057)
@@ -1,3 +1,20 @@
+2018-11-09  Wenson Hsieh  <[email protected]>
+
+        [Cocoa] Implement SPI on WKWebView to increase and decrease list levels
+        https://bugs.webkit.org/show_bug.cgi?id=191471
+        <rdar://problem/45952472>
+
+        Reviewed by Tim Horton.
+
+        Implement these method stubs by calling into Editor.
+
+        Test: WKWebViewEditActions.ModifyListLevel
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::increaseListLevel):
+        (WebKit::WebPage::decreaseListLevel):
+        (WebKit::WebPage::changeListType):
+
 2018-11-09  Keith Rollin  <[email protected]>
 
         Unreviewed build fix after https://bugs.webkit.org/show_bug.cgi?id=191324

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (238056 => 238057)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-11-09 22:34:47 UTC (rev 238056)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-11-09 22:50:47 UTC (rev 238057)
@@ -1152,17 +1152,23 @@
 
 void WebPage::increaseListLevel()
 {
-    // FIXME: Not implemented.
+    auto& editor = m_page->focusController().focusedOrMainFrame().editor();
+    if (editor.canIncreaseSelectionListLevel())
+        editor.increaseSelectionListLevel();
 }
 
 void WebPage::decreaseListLevel()
 {
-    // FIXME: Not implemented.
+    auto& editor = m_page->focusController().focusedOrMainFrame().editor();
+    if (editor.canDecreaseSelectionListLevel())
+        editor.decreaseSelectionListLevel();
 }
 
 void WebPage::changeListType()
 {
-    // FIXME: Not implemented.
+    auto& editor = m_page->focusController().focusedOrMainFrame().editor();
+    if (editor.canChangeSelectionListType())
+        editor.changeSelectionListType();
 }
 
 bool WebPage::isEditingCommandEnabled(const String& commandName)

Modified: trunk/Tools/ChangeLog (238056 => 238057)


--- trunk/Tools/ChangeLog	2018-11-09 22:34:47 UTC (rev 238056)
+++ trunk/Tools/ChangeLog	2018-11-09 22:50:47 UTC (rev 238057)
@@ -1,3 +1,17 @@
+2018-11-09  Wenson Hsieh  <[email protected]>
+
+        [Cocoa] Implement SPI on WKWebView to increase and decrease list levels
+        https://bugs.webkit.org/show_bug.cgi?id=191471
+        <rdar://problem/45952472>
+
+        Reviewed by Tim Horton.
+
+        Add an API test to ensure that list levels can be incremented and decremented via WKWebView SPI.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm:
+        (TestWebKitAPI::webViewForEditActionTesting):
+        (TestWebKitAPI::TEST):
+
 2018-11-09  Basuke Suzuki  <[email protected]>
 
         [Curl][WebKit] Implement Proxy configuration API.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm (238056 => 238057)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm	2018-11-09 22:34:47 UTC (rev 238056)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm	2018-11-09 22:50:47 UTC (rev 238057)
@@ -61,15 +61,44 @@
 
 namespace TestWebKitAPI {
 
-static RetainPtr<TestWKWebView> webViewForEditActionTesting()
+static RetainPtr<TestWKWebView> webViewForEditActionTesting(NSString *markup)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
-    [webView synchronouslyLoadHTMLString:@"<div>WebKit</div>"];
+    [webView synchronouslyLoadHTMLString:markup];
     [webView _setEditable:YES];
     [webView stringByEvaluatingJavaScript:@"getSelection().setPosition(document.body, 1)"];
     return webView;
 }
 
+static RetainPtr<TestWKWebView> webViewForEditActionTesting()
+{
+    return webViewForEditActionTesting(@"<div>WebKit</div>");
+}
+
+TEST(WKWebViewEditActions, ModifyListLevel)
+{
+    auto webView = webViewForEditActionTesting(@"<ol><li>Foo</li><ol><li id='bar'>Bar</li></ol><ul><li id='baz'>Baz</li></ul></ol>");
+
+    [webView evaluateJavaScript:@"getSelection().setPosition(bar, 0)" completionHandler:nil];
+    [webView _decreaseListLevel:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ol > li#bar"]);
+    EXPECT_TRUE([webView querySelectorExists:@"ol > ul > li#baz"]);
+
+    [webView evaluateJavaScript:@"getSelection().setPosition(baz, 0)" completionHandler:nil];
+    [webView _decreaseListLevel:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ol > li#bar"]);
+    EXPECT_TRUE([webView querySelectorExists:@"ol > li#baz"]);
+
+    [webView evaluateJavaScript:@"getSelection().setBaseAndExtent(bar, 0, baz, 1)" completionHandler:nil];
+    [webView _increaseListLevel:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ol > ol > li#bar"]);
+    EXPECT_TRUE([webView querySelectorExists:@"ol > ol > li#baz"]);
+
+    [webView _decreaseListLevel:nil];
+    EXPECT_TRUE([webView querySelectorExists:@"ol > li#bar"]);
+    EXPECT_TRUE([webView querySelectorExists:@"ol > li#baz"]);
+}
+
 TEST(WKWebViewEditActions, NestedListInsertion)
 {
     auto webView = webViewForEditActionTesting();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to