- Revision
- 121904
- Author
- [email protected]
- Date
- 2012-07-05 07:23:45 -0700 (Thu, 05 Jul 2012)
Log Message
[chromium] Add a method didChangeFormState to WebViewClient.
https://bugs.webkit.org/show_bug.cgi?id=90563
Patch by Oli Lan <[email protected]> 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.
Modified Paths
Added Paths
Diff
Modified: trunk/Source/WebKit/chromium/ChangeLog (121903 => 121904)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-07-05 14:20:53 UTC (rev 121903)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-07-05 14:23:45 UTC (rev 121904)
@@ -1,3 +1,40 @@
+2012-07-05 Oli Lan <[email protected]>
+
+ [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 <[email protected]>
Unreviewed, Chromium gardening. Roll Chromium DEPS.
Modified: trunk/Source/WebKit/chromium/public/WebNode.h (121903 => 121904)
--- trunk/Source/WebKit/chromium/public/WebNode.h 2012-07-05 14:20:53 UTC (rev 121903)
+++ trunk/Source/WebKit/chromium/public/WebNode.h 2012-07-05 14:23:45 UTC (rev 121904)
@@ -111,6 +111,7 @@
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.
Modified: trunk/Source/WebKit/chromium/public/WebViewClient.h (121903 => 121904)
--- trunk/Source/WebKit/chromium/public/WebViewClient.h 2012-07-05 14:20:53 UTC (rev 121903)
+++ trunk/Source/WebKit/chromium/public/WebViewClient.h 2012-07-05 14:23:45 UTC (rev 121904)
@@ -187,6 +187,7 @@
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
Modified: trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp (121903 => 121904)
--- trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp 2012-07-05 14:20:53 UTC (rev 121903)
+++ trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp 2012-07-05 14:23:45 UTC (rev 121904)
@@ -841,6 +841,9 @@
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());
Modified: trunk/Source/WebKit/chromium/src/WebNode.cpp (121903 => 121904)
--- trunk/Source/WebKit/chromium/src/WebNode.cpp 2012-07-05 14:20:53 UTC (rev 121903)
+++ trunk/Source/WebKit/chromium/src/WebNode.cpp 2012-07-05 14:23:45 UTC (rev 121904)
@@ -213,6 +213,11 @@
return WebElement(m_private->rootEditableElement());
}
+bool WebNode::focused() const
+{
+ return m_private->focused();
+}
+
bool WebNode::hasNonEmptyBoundingBox() const
{
m_private->document()->updateLayoutIgnorePendingStylesheets();
Modified: trunk/Source/WebKit/chromium/tests/WebViewTest.cpp (121903 => 121904)
--- trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2012-07-05 14:20:53 UTC (rev 121903)
+++ trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2012-07-05 14:23:45 UTC (rev 121904)
@@ -92,6 +92,29 @@
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 @@
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();
}
+
+}
Added: trunk/Source/WebKit/chromium/tests/data/input_field_set_value_while_focused.html (0 => 121904)
--- trunk/Source/WebKit/chromium/tests/data/input_field_set_value_while_focused.html (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/input_field_set_value_while_focused.html 2012-07-05 14:23:45 UTC (rev 121904)
@@ -0,0 +1,6 @@
+<input id='field'/>
+<script>
+ var field = document.getElementById('field');
+ field.focus();
+ field.value = 'some text';
+</script>
Added: trunk/Source/WebKit/chromium/tests/data/input_field_set_value_while_not_focused.html (0 => 121904)
--- trunk/Source/WebKit/chromium/tests/data/input_field_set_value_while_not_focused.html (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/input_field_set_value_while_not_focused.html 2012-07-05 14:23:45 UTC (rev 121904)
@@ -0,0 +1,5 @@
+<input id='field'/>
+<script>
+ var field = document.getElementById('field');
+ field.value = 'some text';
+</script>