[chromium] No triggering autofill on unfocus
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 23:42:05 +0000 (23:42 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 23:42:05 +0000 (23:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109735

Patch by David Trainor <dtrainor@chromium.org> on 2013-02-14
Reviewed by James Robinson.

Need to notify the autofill client to not process text changes when we're setting
focus to false and are trying to commit a composition.

* public/WebAutofillClient.h:
(WebAutofillClient):
(WebKit::WebAutofillClient::setIgnoreTextChanges):
(WebKit::WebAutofillClient::~WebAutofillClient):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::setFocus):
* tests/WebViewTest.cpp:

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

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebAutofillClient.h
Source/WebKit/chromium/src/WebViewImpl.cpp
Source/WebKit/chromium/tests/WebViewTest.cpp

index 9c0ff1b60df7cd8f0fcd32f87da7feb256bec20a..1e55bc4ea6c968e870e77225fb4258458616b4e3 100644 (file)
@@ -1,3 +1,21 @@
+2013-02-14  David Trainor  <dtrainor@chromium.org>
+
+        [chromium] No triggering autofill on unfocus
+        https://bugs.webkit.org/show_bug.cgi?id=109735
+
+        Reviewed by James Robinson.
+
+        Need to notify the autofill client to not process text changes when we're setting
+        focus to false and are trying to commit a composition.
+
+        * public/WebAutofillClient.h:
+        (WebAutofillClient):
+        (WebKit::WebAutofillClient::setIgnoreTextChanges):
+        (WebKit::WebAutofillClient::~WebAutofillClient):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::setFocus):
+        * tests/WebViewTest.cpp:
+
 2013-02-14  Alexandre Elias  <aelias@chromium.org>
 
         [chromium] Fix scaling in WebViewImpl::handleGestureEvent, second try
index 7424c3fecdba9ffa7286e1b7eef3df8c960bfd5d..aa4d0a3daedb1c7ecbf69d4cc4260226cd0638f0 100644 (file)
@@ -90,8 +90,11 @@ public:
     virtual void textFieldDidChange(const WebInputElement&) { }
     virtual void textFieldDidReceiveKeyDown(const WebInputElement&, const WebKeyboardEvent&) { }
 
+    // Informs the client whether or not any subsequent text changes should be ignored.
+    virtual void setIgnoreTextChanges(bool ignore) { }
+
 protected:
-    ~WebAutofillClient() { }
+    virtual ~WebAutofillClient() { }
 };
 
 } // namespace WebKit
index 5a5f113a38a8dd4a0f07a3cc96a9feb606318ec2..d7de869626dff7c6a7930aeae0d71217387dd51c 100644 (file)
@@ -2153,8 +2153,15 @@ void WebViewImpl::setFocus(bool enable)
         if (focusedFrame) {
             // Finish an ongoing composition to delete the composition node.
             Editor* editor = focusedFrame->editor();
-            if (editor && editor->hasComposition())
+            if (editor && editor->hasComposition()) {
+                if (m_autofillClient)
+                    m_autofillClient->setIgnoreTextChanges(true);
+
                 editor->confirmComposition();
+
+                if (m_autofillClient)
+                    m_autofillClient->setIgnoreTextChanges(false);
+            }
             m_imeAcceptEvents = false;
         }
     }
index 24fecf557f438ad49371f3f2cfe6da5fbd64fff2..46088e66b295a3f90a0f939ca85ee2b947d87078 100644 (file)
@@ -37,6 +37,7 @@
 #include "FrameView.h"
 #include "HTMLDocument.h"
 #include "URLTestHelpers.h"
+#include "WebAutofillClient.h"
 #include "WebContentDetectionResult.h"
 #include "WebDocument.h"
 #include "WebElement.h"
@@ -720,4 +721,96 @@ TEST_F(WebViewTest, SelectionOnReadOnlyInput)
     webView->close();
 }
 
+class MockAutofillClient : public WebAutofillClient {
+public:
+    MockAutofillClient()
+        : m_ignoreTextChanges(false)
+        , m_textChangesWhileIgnored(0)
+        , m_textChangesWhileNotIgnored(0) { }
+
+    virtual ~MockAutofillClient() { }
+
+    virtual void setIgnoreTextChanges(bool ignore) OVERRIDE { m_ignoreTextChanges = ignore; }
+    virtual void textFieldDidChange(const WebInputElement&) OVERRIDE
+    {
+        if (m_ignoreTextChanges)
+            ++m_textChangesWhileIgnored;
+        else
+            ++m_textChangesWhileNotIgnored;
+    }
+
+    void clearChangeCounts()
+    {
+        m_textChangesWhileIgnored = 0;
+        m_textChangesWhileNotIgnored = 0;
+    }
+
+    int textChangesWhileIgnored() { return m_textChangesWhileIgnored; }
+    int textChangesWhileNotIgnored() { return m_textChangesWhileNotIgnored; }
+
+private:
+    bool m_ignoreTextChanges;
+    int m_textChangesWhileIgnored;
+    int m_textChangesWhileNotIgnored;
+};
+
+
+TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange)
+{
+    URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
+    MockAutofillClient client;
+    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+    webView->setAutofillClient(&client);
+    webView->setInitialFocus(false);
+
+    // Set up a composition that needs to be committed.
+    WebVector<WebCompositionUnderline> emptyUnderlines;
+    webView->setEditableSelectionOffsets(4, 10);
+    webView->setCompositionFromExistingText(8, 12, emptyUnderlines);
+    WebTextInputInfo info = webView->textInputInfo();
+    EXPECT_EQ(4, info.selectionStart);
+    EXPECT_EQ(10, info.selectionEnd);
+    EXPECT_EQ(8, info.compositionStart);
+    EXPECT_EQ(12, info.compositionEnd);
+
+    // Clear the focus and track that the subsequent composition commit does not trigger a
+    // text changed notification for autofill.
+    client.clearChangeCounts();
+    webView->setFocus(false);
+    EXPECT_EQ(1, client.textChangesWhileIgnored());
+    EXPECT_EQ(0, client.textChangesWhileNotIgnored());
+
+    webView->setAutofillClient(0);
+    webView->close();
+}
+
+TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange)
+{
+    URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
+    MockAutofillClient client;
+    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+    webView->setAutofillClient(&client);
+    webView->setInitialFocus(false);
+
+    // Set up a composition that needs to be committed.
+    std::string compositionText("testingtext");
+
+    WebVector<WebCompositionUnderline> emptyUnderlines;
+    webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, compositionText.length());
+
+    WebTextInputInfo info = webView->textInputInfo();
+    EXPECT_EQ(0, info.selectionStart);
+    EXPECT_EQ((int) compositionText.length(), info.selectionEnd);
+    EXPECT_EQ(0, info.compositionStart);
+    EXPECT_EQ((int) compositionText.length(), info.compositionEnd);
+
+    client.clearChangeCounts();
+    webView->confirmComposition();
+    EXPECT_EQ(0, client.textChangesWhileIgnored());
+    EXPECT_EQ(1, client.textChangesWhileNotIgnored());
+
+    webView->setAutofillClient(0);
+    webView->close();
+}
+
 }