Title: [185692] trunk
Revision
185692
Author
[email protected]
Date
2015-06-17 21:38:59 -0700 (Wed, 17 Jun 2015)

Log Message

Client may receive began editing callback for already focused text field
https://bugs.webkit.org/show_bug.cgi?id=146074
<rdar://problem/21293562>

Reviewed by Darin Adler.

Source/WebCore:

Fixes an issue where the client would be notified that began editing in a text field
for each programmatic DOM focus event dispatched at the text field regardless of
whether the field was focused. The client should only be notified that began editing
exactly once when a text field becomes focused (either programmatically or by user interaction).

* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::forwardEvent): Move logic to dispatch editing began callback from here...
(WebCore::TextFieldInputType::handleFocusEvent): to here. This function is called when the
text field becomes newly focused.
* html/TextFieldInputType.h:

Tools:

Add a unit test to ensure that a client receives exactly one began editing
callback when a text field is newly focused. In particular, dispatching
a DOM focus event at an already focused text field does not dispatch a
began editing callback to the client.

* TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp:
(TestWebKitAPI::TEST_F):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (185691 => 185692)


--- trunk/Source/WebCore/ChangeLog	2015-06-18 04:11:05 UTC (rev 185691)
+++ trunk/Source/WebCore/ChangeLog	2015-06-18 04:38:59 UTC (rev 185692)
@@ -1,3 +1,22 @@
+2015-06-17  Daniel Bates  <[email protected]>
+
+        Client may receive began editing callback for already focused text field
+        https://bugs.webkit.org/show_bug.cgi?id=146074
+        <rdar://problem/21293562>
+
+        Reviewed by Darin Adler.
+
+        Fixes an issue where the client would be notified that began editing in a text field
+        for each programmatic DOM focus event dispatched at the text field regardless of
+        whether the field was focused. The client should only be notified that began editing
+        exactly once when a text field becomes focused (either programmatically or by user interaction).
+
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::forwardEvent): Move logic to dispatch editing began callback from here...
+        (WebCore::TextFieldInputType::handleFocusEvent): to here. This function is called when the
+        text field becomes newly focused.
+        * html/TextFieldInputType.h:
+
 2015-06-17  Alex Christensen  <[email protected]>
 
         [Content Extensions] Fail to parse invalid arrays

Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (185691 => 185692)


--- trunk/Source/WebCore/html/TextFieldInputType.cpp	2015-06-18 04:11:05 UTC (rev 185691)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp	2015-06-18 04:38:59 UTC (rev 185692)
@@ -206,17 +206,21 @@
                 }
 
                 capsLockStateMayHaveChanged();
-            } else if (event->type() == eventNames().focusEvent) {
-                if (Frame* frame = element().document().frame())
-                    frame->editor().textFieldDidBeginEditing(&element());
+            } else if (event->type() == eventNames().focusEvent)
                 capsLockStateMayHaveChanged();
-            }
 
             element().forwardEvent(event);
         }
     }
 }
 
+void TextFieldInputType::handleFocusEvent(Node* oldFocusedNode, FocusDirection)
+{
+    ASSERT_UNUSED(oldFocusedNode, oldFocusedNode != &element());
+    if (Frame* frame = element().document().frame())
+        frame->editor().textFieldDidBeginEditing(&element());
+}
+
 void TextFieldInputType::handleBlurEvent()
 {
     InputType::handleBlurEvent();

Modified: trunk/Source/WebCore/html/TextFieldInputType.h (185691 => 185692)


--- trunk/Source/WebCore/html/TextFieldInputType.h	2015-06-18 04:11:05 UTC (rev 185691)
+++ trunk/Source/WebCore/html/TextFieldInputType.h	2015-06-18 04:38:59 UTC (rev 185692)
@@ -64,6 +64,7 @@
     virtual void disabledAttributeChanged() override final;
     virtual void readonlyAttributeChanged() override final;
     virtual bool supportsReadOnly() const override final;
+    void handleFocusEvent(Node* oldFocusedNode, FocusDirection) override final;
     virtual void handleBlurEvent() override final;
     virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) override;
     virtual void updateInnerTextValue() override final;

Modified: trunk/Tools/ChangeLog (185691 => 185692)


--- trunk/Tools/ChangeLog	2015-06-18 04:11:05 UTC (rev 185691)
+++ trunk/Tools/ChangeLog	2015-06-18 04:38:59 UTC (rev 185692)
@@ -1,3 +1,19 @@
+2015-06-17  Daniel Bates  <[email protected]>
+
+        Client may receive began editing callback for already focused text field
+        https://bugs.webkit.org/show_bug.cgi?id=146074
+        <rdar://problem/21293562>
+
+        Reviewed by Darin Adler.
+
+        Add a unit test to ensure that a client receives exactly one began editing
+        callback when a text field is newly focused. In particular, dispatching
+        a DOM focus event at an already focused text field does not dispatch a
+        began editing callback to the client.
+
+        * TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2015-06-17  Hyungwook Lee  <[email protected]>
 
         [Win]Implement layoutTestController.dispatchPendingLoadRequests. 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp (185691 => 185692)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp	2015-06-18 04:11:05 UTC (rev 185691)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp	2015-06-18 04:38:59 UTC (rev 185692)
@@ -120,6 +120,12 @@
     executeJavaScriptAndCheckDidReceiveMessage("blurTextField('readonly')", "DidReceiveTextFieldDidEndEditing");
 }
 
+TEST_F(WebKit2TextFieldBeginAndEditEditingTest, TextFieldDidBeginShouldNotBeDispatchedForAlreadyFocusedField)
+{
+    executeJavaScriptAndCheckDidReceiveMessage("focusTextField('input'); focusTextField('input')", "DidReceiveTextFieldDidBeginEditing");
+    executeJavaScriptAndCheckDidReceiveMessage("blurTextField('input')", "DidReceiveTextFieldDidEndEditing");
+}
+
 } // namespace TestWebKitAPI
 
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to