Title: [261042] trunk
Revision
261042
Author
wenson_hs...@apple.com
Date
2020-05-01 19:26:23 -0700 (Fri, 01 May 2020)

Log Message

Text manipulation should observe the value attribute of some input elements
https://bugs.webkit.org/show_bug.cgi?id=211307
<rdar://problem/61568528>

Reviewed by Darin Adler.

Source/WebCore:

Teach TextManipulationController to detect the `value` attribute in input elements of type "button" and
"submit". To do this, we plumb the element through to `isAttributeForTextManipulation` and check `isTextButton()`
if "value" attribute is being considered.

Test: TextManipulation.StartTextManipulationExtractsValuesFromButtonInputs

* editing/TextManipulationController.cpp:
(WebCore::isAttributeForTextManipulation):
(WebCore::TextManipulationController::observeParagraphs):

Tools:

Add a new API test that covers `<input type="submit">` and `<input type="button">`.

* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (261041 => 261042)


--- trunk/Source/WebCore/ChangeLog	2020-05-02 00:21:51 UTC (rev 261041)
+++ trunk/Source/WebCore/ChangeLog	2020-05-02 02:26:23 UTC (rev 261042)
@@ -1,3 +1,21 @@
+2020-05-01  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Text manipulation should observe the value attribute of some input elements
+        https://bugs.webkit.org/show_bug.cgi?id=211307
+        <rdar://problem/61568528>
+
+        Reviewed by Darin Adler.
+
+        Teach TextManipulationController to detect the `value` attribute in input elements of type "button" and
+        "submit". To do this, we plumb the element through to `isAttributeForTextManipulation` and check `isTextButton()`
+        if "value" attribute is being considered.
+
+        Test: TextManipulation.StartTextManipulationExtractsValuesFromButtonInputs
+
+        * editing/TextManipulationController.cpp:
+        (WebCore::isAttributeForTextManipulation):
+        (WebCore::TextManipulationController::observeParagraphs):
+
 2020-05-01  Chris Dumez  <cdu...@apple.com>
 
         Regression(r259036) Unable to post comments on Jira

Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (261041 => 261042)


--- trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-05-02 00:21:51 UTC (rev 261041)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-05-02 02:26:23 UTC (rev 261042)
@@ -33,6 +33,7 @@
 #include "EventLoop.h"
 #include "HTMLBRElement.h"
 #include "HTMLElement.h"
+#include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "HTMLParserIdioms.h"
 #include "NodeTraversal.h"
@@ -224,9 +225,13 @@
     RefPtr<Node> m_pastEndNode;
 };
 
-static bool isAttributeForTextManipulation(const QualifiedName& nameToCheck)
+static bool isAttributeForTextManipulation(const Element& element, const QualifiedName& nameToCheck)
 {
     using namespace HTMLNames;
+
+    if (nameToCheck == valueAttr)
+        return is<HTMLInputElement>(element) && downcast<HTMLInputElement>(element).isTextButton();
+
     static const QualifiedName* const attributeNames[] = {
         &titleAttr.get(),
         &altAttr.get(),
@@ -340,7 +345,7 @@
                 }
                 if (currentElement.hasAttributes()) {
                     for (auto& attribute : currentElement.attributesIterator()) {
-                        if (isAttributeForTextManipulation(attribute.name())) {
+                        if (isAttributeForTextManipulation(currentElement, attribute.name())) {
                             addItem(ManipulationItemData { Position(), Position(), makeWeakPtr(currentElement), attribute.name(),
                                 { ManipulationToken { m_tokenIdentifier.generate(), attribute.value(), tokenInfo(&currentElement) } } });
                         }

Modified: trunk/Tools/ChangeLog (261041 => 261042)


--- trunk/Tools/ChangeLog	2020-05-02 00:21:51 UTC (rev 261041)
+++ trunk/Tools/ChangeLog	2020-05-02 02:26:23 UTC (rev 261042)
@@ -1,3 +1,15 @@
+2020-05-01  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Text manipulation should observe the value attribute of some input elements
+        https://bugs.webkit.org/show_bug.cgi?id=211307
+        <rdar://problem/61568528>
+
+        Reviewed by Darin Adler.
+
+        Add a new API test that covers `<input type="submit">` and `<input type="button">`.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+
 2020-05-01  Alex Christensen  <achristen...@webkit.org>
 
         Add SPI to move localStorage to a different domain

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (261041 => 261042)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-05-02 00:21:51 UTC (rev 261041)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-05-02 02:26:23 UTC (rev 261042)
@@ -757,6 +757,35 @@
     }
 }
 
+TEST(TextManipulation, StartTextManipulationExtractsValuesFromButtonInputs)
+{
+    auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView _setTextManipulationDelegate:delegate.get()];
+
+    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html>"
+        "<body>"
+        "<input type='button' value='One'>"
+        "<input type='submit' value='Two'>"
+        "<input type='password' value='Three'>"
+        "<input type='range' value='4'>"
+        "<input type='date' value='2020-05-01'>"
+        "</body>"];
+
+    done = false;
+    [webView _startTextManipulationsWithConfiguration:nil completion:^{
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    auto items = [delegate items];
+    EXPECT_EQ(items.count, 2UL);
+    EXPECT_EQ(items[0].tokens.count, 1UL);
+    EXPECT_EQ(items[1].tokens.count, 1UL);
+    EXPECT_WK_STREQ("One", items[0].tokens[0].content);
+    EXPECT_WK_STREQ("Two", items[1].tokens[0].content);
+}
+
 struct Token {
     NSString *identifier;
     NSString *content;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to