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
+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.
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.
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
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());
return WebElement(m_private->rootEditableElement());
}
+bool WebNode::focused() const
+{
+ return m_private->focused();
+}
+
bool WebNode::hasNonEmptyBoundingBox() const
{
m_private->document()->updateLayoutIgnorePendingStylesheets();
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()
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();
+}
+
}
--- /dev/null
+<input id='field'/>
+<script>
+ var field = document.getElementById('field');
+ field.focus();
+ field.value = 'some text';
+</script>
--- /dev/null
+<input id='field'/>
+<script>
+ var field = document.getElementById('field');
+ field.value = 'some text';
+</script>