Modified: trunk/Source/WebKit/chromium/ChangeLog (142926 => 142927)
--- trunk/Source/WebKit/chromium/ChangeLog 2013-02-14 23:14:45 UTC (rev 142926)
+++ trunk/Source/WebKit/chromium/ChangeLog 2013-02-14 23:42:05 UTC (rev 142927)
@@ -1,3 +1,21 @@
+2013-02-14 David Trainor <[email protected]>
+
+ [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 <[email protected]>
[chromium] Fix scaling in WebViewImpl::handleGestureEvent, second try
Modified: trunk/Source/WebKit/chromium/public/WebAutofillClient.h (142926 => 142927)
--- trunk/Source/WebKit/chromium/public/WebAutofillClient.h 2013-02-14 23:14:45 UTC (rev 142926)
+++ trunk/Source/WebKit/chromium/public/WebAutofillClient.h 2013-02-14 23:42:05 UTC (rev 142927)
@@ -90,8 +90,11 @@
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
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (142926 => 142927)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2013-02-14 23:14:45 UTC (rev 142926)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2013-02-14 23:42:05 UTC (rev 142927)
@@ -2153,8 +2153,15 @@
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;
}
}
Modified: trunk/Source/WebKit/chromium/tests/WebViewTest.cpp (142926 => 142927)
--- trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2013-02-14 23:14:45 UTC (rev 142926)
+++ trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2013-02-14 23:42:05 UTC (rev 142927)
@@ -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 @@
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();
+}
+
+}