[chromium] Add a method didChangeFormState to WebViewClient.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2012 14:23:45 +0000 (14:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2012 14:23:45 +0000 (14:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90563

Patch by Oli Lan <olilan@chromium.org> on 2012-07-05
Reviewed by Adam Barth.

This patch adds a new method didChangeFormState to WebViewClient,
and calls it from ChromeClientImpl::formStateDidChange with the changed node.

This new method can be used for example by the Android port to update the browser's
IME when the state of the currently focused text node has changed. To facilitate this
usage, a focused() method has been added to WebNode.

A new test has been added to WebViewTest. This test checks that didChangeFormState
is called when an input's value is changed, and also checks that WebNode::focused() returns
the correct value for the provided node, in both the focused and non-focused cases.

* public/WebNode.h:
* public/WebViewClient.h:
(WebKit::WebViewClient::didChangeFormState):
* src/ChromeClientImpl.cpp:
(WebKit::ChromeClientImpl::formStateDidChange):
* src/WebNode.cpp:
(WebKit::WebNode::focused):
(WebKit):
* tests/WebViewTest.cpp:
(FormChangeWebViewClient):
(WebKit::FormChangeWebViewClient::didChangeFormState):
(WebKit::FormChangeWebViewClient::reset):
(WebKit::FormChangeWebViewClient::called):
(WebKit::FormChangeWebViewClient::focused):
(WebKit):
(WebKit::TEST_F):
* tests/data/input_field_set_value_while_focused.html: Added.
* tests/data/input_field_set_value_while_not_focused.html: Added.

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

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebNode.h
Source/WebKit/chromium/public/WebViewClient.h
Source/WebKit/chromium/src/ChromeClientImpl.cpp
Source/WebKit/chromium/src/WebNode.cpp
Source/WebKit/chromium/tests/WebViewTest.cpp
Source/WebKit/chromium/tests/data/input_field_set_value_while_focused.html [new file with mode: 0644]
Source/WebKit/chromium/tests/data/input_field_set_value_while_not_focused.html [new file with mode: 0644]

index 75eefb3..fa93b68 100644 (file)
@@ -1,3 +1,40 @@
+2012-07-05  Oli Lan  <olilan@chromium.org>
+
+        [chromium] Add a method didChangeFormState to WebViewClient.
+        https://bugs.webkit.org/show_bug.cgi?id=90563
+
+        Reviewed by Adam Barth.
+
+        This patch adds a new method didChangeFormState to WebViewClient,
+        and calls it from ChromeClientImpl::formStateDidChange with the changed node.
+
+        This new method can be used for example by the Android port to update the browser's
+        IME when the state of the currently focused text node has changed. To facilitate this
+        usage, a focused() method has been added to WebNode.
+
+        A new test has been added to WebViewTest. This test checks that didChangeFormState
+        is called when an input's value is changed, and also checks that WebNode::focused() returns
+        the correct value for the provided node, in both the focused and non-focused cases.
+
+        * public/WebNode.h:
+        * public/WebViewClient.h:
+        (WebKit::WebViewClient::didChangeFormState):
+        * src/ChromeClientImpl.cpp:
+        (WebKit::ChromeClientImpl::formStateDidChange):
+        * src/WebNode.cpp:
+        (WebKit::WebNode::focused):
+        (WebKit):
+        * tests/WebViewTest.cpp:
+        (FormChangeWebViewClient):
+        (WebKit::FormChangeWebViewClient::didChangeFormState):
+        (WebKit::FormChangeWebViewClient::reset):
+        (WebKit::FormChangeWebViewClient::called):
+        (WebKit::FormChangeWebViewClient::focused):
+        (WebKit):
+        (WebKit::TEST_F):
+        * tests/data/input_field_set_value_while_focused.html: Added.
+        * tests/data/input_field_set_value_while_not_focused.html: Added.
+
 2012-07-04  Yoshifumi Inoue  <yosin@chromium.org>
 
         Unreviewed, Chromium gardening. Roll Chromium DEPS.
index d4ee874..5281db1 100644 (file)
@@ -111,6 +111,7 @@ public:
     WEBKIT_EXPORT void simulateClick();
     WEBKIT_EXPORT WebNodeList getElementsByTagName(const WebString&) const;
     WEBKIT_EXPORT WebElement rootEditableElement() const;
+    WEBKIT_EXPORT bool focused() const;
 
     // Returns true if the node has a non-empty bounding box in layout.
     // This does not 100% guarantee the user can see it, but is pretty close.
index 6393a07..662409f 100644 (file)
@@ -187,6 +187,7 @@ public:
     virtual void didChangeContents() { }
     virtual void didExecuteCommand(const WebString& commandName) { }
     virtual void didEndEditing() { }
+    virtual void didChangeFormState(const WebNode&) { }
 
     // This method is called in response to WebView's handleInputEvent()
     // when the default action for the current keyboard event is not
index 60314d2..3497339 100644 (file)
@@ -841,6 +841,9 @@ void ChromeClientImpl::setNewWindowNavigationPolicy(WebNavigationPolicy policy)
 
 void ChromeClientImpl::formStateDidChange(const Node* node)
 {
+    if (m_webView->client())
+        m_webView->client()->didChangeFormState(WebNode(const_cast<Node*>(node)));
+
     // The current history item is not updated yet.  That happens lazily when
     // WebFrame::currentHistoryItem is requested.
     WebFrameImpl* webframe = WebFrameImpl::fromFrame(node->document()->frame());
index 49dcdd9..14da1d5 100644 (file)
@@ -213,6 +213,11 @@ WebElement WebNode::rootEditableElement() const
     return WebElement(m_private->rootEditableElement());
 }
 
+bool WebNode::focused() const
+{
+    return m_private->focused();
+}
+
 bool WebNode::hasNonEmptyBoundingBox() const
 {
     m_private->document()->updateLayoutIgnorePendingStylesheets();
index 8eccf2c..7903721 100644 (file)
@@ -92,6 +92,29 @@ private:
     TestData m_testData;
 };
 
+class FormChangeWebViewClient : public WebViewClient {
+public:
+    // WebViewClient methods
+    virtual void didChangeFormState(const WebNode& node)
+    {
+        m_focused = node.focused();
+        m_called = true;
+    }
+
+    // Local methods
+    void reset()
+    {
+        m_called = false;
+        m_focused = false;
+    }
+    bool called() { return m_called; }
+    bool focused() { return m_focused; }
+
+private:
+    bool m_called;
+    bool m_focused;
+};
+
 class WebViewTest : public testing::Test {
 public:
     WebViewTest()
@@ -337,4 +360,20 @@ TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
     webView->close();
 }
 
+TEST_F(WebViewTest, FormChange)
+{
+    FormChangeWebViewClient client;
+    client.reset();
+    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "input_field_set_value_while_focused.html");
+    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_set_value_while_focused.html", true, 0, &client);
+    EXPECT_TRUE(client.called());
+    EXPECT_TRUE(client.focused());
+    client.reset();
+    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "input_field_set_value_while_not_focused.html");
+    webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_set_value_while_not_focused.html", true, 0, &client);
+    EXPECT_TRUE(client.called());
+    EXPECT_FALSE(client.focused());
+    webView->close();
+}
+
 }
diff --git a/Source/WebKit/chromium/tests/data/input_field_set_value_while_focused.html b/Source/WebKit/chromium/tests/data/input_field_set_value_while_focused.html
new file mode 100644 (file)
index 0000000..e6c73ea
--- /dev/null
@@ -0,0 +1,6 @@
+<input id='field'/>
+<script>
+  var field = document.getElementById('field');
+  field.focus();
+  field.value = 'some text';
+</script>
diff --git a/Source/WebKit/chromium/tests/data/input_field_set_value_while_not_focused.html b/Source/WebKit/chromium/tests/data/input_field_set_value_while_not_focused.html
new file mode 100644 (file)
index 0000000..4e578d4
--- /dev/null
@@ -0,0 +1,5 @@
+<input id='field'/>
+<script>
+  var field = document.getElementById('field');
+  field.value = 'some text';
+</script>