Changeset 121904 in webkit


Ignore:
Timestamp:
Jul 5, 2012 7:23:45 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Add a method didChangeFormState to WebViewClient.
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.
Location:
trunk/Source/WebKit/chromium
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r121880 r121904  
     12012-07-05  Oli Lan  <olilan@chromium.org>
     2
     3        [chromium] Add a method didChangeFormState to WebViewClient.
     4        https://bugs.webkit.org/show_bug.cgi?id=90563
     5
     6        Reviewed by Adam Barth.
     7
     8        This patch adds a new method didChangeFormState to WebViewClient,
     9        and calls it from ChromeClientImpl::formStateDidChange with the changed node.
     10
     11        This new method can be used for example by the Android port to update the browser's
     12        IME when the state of the currently focused text node has changed. To facilitate this
     13        usage, a focused() method has been added to WebNode.
     14
     15        A new test has been added to WebViewTest. This test checks that didChangeFormState
     16        is called when an input's value is changed, and also checks that WebNode::focused() returns
     17        the correct value for the provided node, in both the focused and non-focused cases.
     18
     19        * public/WebNode.h:
     20        * public/WebViewClient.h:
     21        (WebKit::WebViewClient::didChangeFormState):
     22        * src/ChromeClientImpl.cpp:
     23        (WebKit::ChromeClientImpl::formStateDidChange):
     24        * src/WebNode.cpp:
     25        (WebKit::WebNode::focused):
     26        (WebKit):
     27        * tests/WebViewTest.cpp:
     28        (FormChangeWebViewClient):
     29        (WebKit::FormChangeWebViewClient::didChangeFormState):
     30        (WebKit::FormChangeWebViewClient::reset):
     31        (WebKit::FormChangeWebViewClient::called):
     32        (WebKit::FormChangeWebViewClient::focused):
     33        (WebKit):
     34        (WebKit::TEST_F):
     35        * tests/data/input_field_set_value_while_focused.html: Added.
     36        * tests/data/input_field_set_value_while_not_focused.html: Added.
     37
    1382012-07-04  Yoshifumi Inoue  <yosin@chromium.org>
    239
  • trunk/Source/WebKit/chromium/public/WebNode.h

    r105489 r121904  
    112112    WEBKIT_EXPORT WebNodeList getElementsByTagName(const WebString&) const;
    113113    WEBKIT_EXPORT WebElement rootEditableElement() const;
     114    WEBKIT_EXPORT bool focused() const;
    114115
    115116    // Returns true if the node has a non-empty bounding box in layout.
  • trunk/Source/WebKit/chromium/public/WebViewClient.h

    r121483 r121904  
    188188    virtual void didExecuteCommand(const WebString& commandName) { }
    189189    virtual void didEndEditing() { }
     190    virtual void didChangeFormState(const WebNode&) { }
    190191
    191192    // This method is called in response to WebView's handleInputEvent()
  • trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp

    r121555 r121904  
    842842void ChromeClientImpl::formStateDidChange(const Node* node)
    843843{
     844    if (m_webView->client())
     845        m_webView->client()->didChangeFormState(WebNode(const_cast<Node*>(node)));
     846
    844847    // The current history item is not updated yet.  That happens lazily when
    845848    // WebFrame::currentHistoryItem is requested.
  • trunk/Source/WebKit/chromium/src/WebNode.cpp

    r120637 r121904  
    214214}
    215215
     216bool WebNode::focused() const
     217{
     218    return m_private->focused();
     219}
     220
    216221bool WebNode::hasNonEmptyBoundingBox() const
    217222{
  • trunk/Source/WebKit/chromium/tests/WebViewTest.cpp

    r121469 r121904  
    9393};
    9494
     95class FormChangeWebViewClient : public WebViewClient {
     96public:
     97    // WebViewClient methods
     98    virtual void didChangeFormState(const WebNode& node)
     99    {
     100        m_focused = node.focused();
     101        m_called = true;
     102    }
     103
     104    // Local methods
     105    void reset()
     106    {
     107        m_called = false;
     108        m_focused = false;
     109    }
     110    bool called() { return m_called; }
     111    bool focused() { return m_focused; }
     112
     113private:
     114    bool m_called;
     115    bool m_focused;
     116};
     117
    95118class WebViewTest : public testing::Test {
    96119public:
     
    338361}
    339362
    340 }
     363TEST_F(WebViewTest, FormChange)
     364{
     365    FormChangeWebViewClient client;
     366    client.reset();
     367    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "input_field_set_value_while_focused.html");
     368    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_set_value_while_focused.html", true, 0, &client);
     369    EXPECT_TRUE(client.called());
     370    EXPECT_TRUE(client.focused());
     371    client.reset();
     372    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "input_field_set_value_while_not_focused.html");
     373    webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_set_value_while_not_focused.html", true, 0, &client);
     374    EXPECT_TRUE(client.called());
     375    EXPECT_FALSE(client.focused());
     376    webView->close();
     377}
     378
     379}
Note: See TracChangeset for help on using the changeset viewer.