Client may receive began editing callback for already focused text field
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Jun 2015 04:38:59 +0000 (04:38 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Jun 2015 04:38:59 +0000 (04:38 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185692 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/html/TextFieldInputType.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2/TextFieldDidBeginAndEndEditing.cpp

index db7410a..6b61d1f 100644 (file)
@@ -1,3 +1,22 @@
+2015-06-17  Daniel Bates  <dabates@apple.com>
+
+        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  <achristensen@webkit.org>
 
         [Content Extensions] Fail to parse invalid arrays
index d369daa..7d5b146 100644 (file)
@@ -206,17 +206,21 @@ void TextFieldInputType::forwardEvent(Event* event)
                 }
 
                 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();
index cb585ea..985c3ea 100644 (file)
@@ -64,6 +64,7 @@ protected:
     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;
index 95a3596..b8ca298 100644 (file)
@@ -1,3 +1,19 @@
+2015-06-17  Daniel Bates  <dabates@apple.com>
+
+        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  <hyungwook.lee@navercorp.com>
 
         [Win]Implement layoutTestController.dispatchPendingLoadRequests. 
index 71c887b..cfe0be2 100644 (file)
@@ -120,6 +120,12 @@ TEST_F(WebKit2TextFieldBeginAndEditEditingTest, TextFieldDidBeginAndEndEditingEv
     executeJavaScriptAndCheckDidReceiveMessage("blurTextField('readonly')", "DidReceiveTextFieldDidEndEditing");
 }
 
+TEST_F(WebKit2TextFieldBeginAndEditEditingTest, TextFieldDidBeginShouldNotBeDispatchedForAlreadyFocusedField)
+{
+    executeJavaScriptAndCheckDidReceiveMessage("focusTextField('input'); focusTextField('input')", "DidReceiveTextFieldDidBeginEditing");
+    executeJavaScriptAndCheckDidReceiveMessage("blurTextField('input')", "DidReceiveTextFieldDidEndEditing");
+}
+
 } // namespace TestWebKitAPI
 
 #endif