Changeset 106216 in webkit


Ignore:
Timestamp:
Jan 29, 2012 11:22:59 PM (12 years ago)
Author:
tkent@chromium.org
Message:

[Chromium] REGRESSION(r87067): WebFrame::setFindEndstateFocusAndSelection()
doesn't set the selection for <input> and <textarea>
https://bugs.webkit.org/show_bug.cgi?id=77186

Reviewed by Hajime Morita.

When the find-in-page box is closed, WebFrame::stopFinding(false) is
called. It calls setFindEndstateFocusAndSelection(). Before r87067,
m_activeMatch was stored as the normal selection in <input> or
<textarea> by accident. r87067 stopped this accidental behavior.

However the behavior of pre-r87067 is useful and we should support it
for contentEditable elements too.

  • src/WebFrameImpl.cpp:

(WebKit::WebFrameImpl::setFindEndstateFocusAndSelection):

  • Add special handing for <input> and <textarea> to find a focusable parent.
  • Sets the active match as the selection even if a focusable parent is found.
  • tests/WebFrameTest.cpp:

(WebKit::TEST_F): Add tests for find() and stopFinding().

  • tests/data/find.html: Added.
Location:
trunk/Source/WebKit/chromium
Files:
1 added
3 edited

Legend:

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

    r106214 r106216  
     12012-01-29  Kent Tamura  <tkent@chromium.org>
     2
     3        [Chromium] REGRESSION(r87067): WebFrame::setFindEndstateFocusAndSelection()
     4        doesn't set the selection for <input> and <textarea>
     5        https://bugs.webkit.org/show_bug.cgi?id=77186
     6
     7        Reviewed by Hajime Morita.
     8
     9        When the find-in-page box is closed, WebFrame::stopFinding(false) is
     10        called. It calls setFindEndstateFocusAndSelection(). Before r87067,
     11        m_activeMatch was stored as the normal selection in <input> or
     12        <textarea> by accident. r87067 stopped this accidental behavior.
     13
     14        However the behavior of pre-r87067 is useful and we should support it
     15        for contentEditable elements too.
     16
     17        * src/WebFrameImpl.cpp:
     18        (WebKit::WebFrameImpl::setFindEndstateFocusAndSelection):
     19        - Add special handing for <input> and <textarea> to find a focusable parent.
     20        - Sets the active match as the selection even if a focusable parent is found.
     21        * tests/WebFrameTest.cpp:
     22        (WebKit::TEST_F): Add tests for find() and stopFinding().
     23        * tests/data/find.html: Added.
     24
    1252012-01-29  Nico Weber  <nicolasweber@gmx.de>
    226
  • trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp

    r105489 r106216  
    21652165        // example, focus links if we have found text within the link.
    21662166        Node* node = m_activeMatch->firstNode();
     2167        if (node && node->isInShadowTree()) {
     2168            Node* host = node->shadowAncestorNode();
     2169            if (host->hasTagName(HTMLNames::inputTag) || host->hasTagName(HTMLNames::textareaTag))
     2170                node = host;
     2171        }
    21672172        while (node && !node->isFocusable() && node != frame()->document())
    21682173            node = node->parentNode();
    21692174
    21702175        if (node && node != frame()->document()) {
    2171             // Found a focusable parent node. Set focus to it.
     2176            // Found a focusable parent node. Set the active match as the
     2177            // selection and focus to the focusable node.
     2178            frame()->selection()->setSelection(m_activeMatch.get());
    21722179            frame()->document()->setFocusedNode(node);
    21732180            return;
  • trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp

    r99940 r106216  
    3434#include "ResourceError.h"
    3535#include "WebDocument.h"
     36#include "WebFindOptions.h"
    3637#include "WebFormElement.h"
    3738#include "WebFrame.h"
    3839#include "WebFrameClient.h"
     40#include "WebRange.h"
    3941#include "WebScriptSource.h"
    4042#include "WebSearchableFormData.h"
     
    380382}
    381383
     384TEST_F(WebFrameTest, FindInPage)
     385{
     386    registerMockedHttpURLLoad("find.html");
     387    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find.html");
     388    WebFrame* frame = webView->mainFrame();
     389    const int findIdentifier = 12345;
     390    WebFindOptions options;
     391
     392    // Find in a <div> element.
     393    EXPECT_TRUE(frame->find(findIdentifier, WebString::fromUTF8("bar1"), options, false, 0));
     394    frame->stopFinding(false);
     395    WebRange range = frame->selectionRange();
     396    EXPECT_EQ(5, range.startOffset());
     397    EXPECT_EQ(9, range.endOffset());
     398    EXPECT_TRUE(frame->document().focusedNode().isNull());
     399
     400    // Find in an <input> value.
     401    EXPECT_TRUE(frame->find(findIdentifier, WebString::fromUTF8("bar2"), options, false, 0));
     402    // Confirm stopFinding(false) sets the selection on the found text.
     403    frame->stopFinding(false);
     404    range = frame->selectionRange();
     405    ASSERT_FALSE(range.isNull());
     406    EXPECT_EQ(5, range.startOffset());
     407    EXPECT_EQ(9, range.endOffset());
     408    EXPECT_EQ(WebString::fromUTF8("INPUT"), frame->document().focusedNode().nodeName());
     409
     410    // Find in a <textarea> content.
     411    EXPECT_TRUE(frame->find(findIdentifier, WebString::fromUTF8("bar3"), options, false, 0));
     412    // Confirm stopFinding(false) sets the selection on the found text.
     413    frame->stopFinding(false);
     414    range = frame->selectionRange();
     415    ASSERT_FALSE(range.isNull());
     416    EXPECT_EQ(5, range.startOffset());
     417    EXPECT_EQ(9, range.endOffset());
     418    EXPECT_EQ(WebString::fromUTF8("TEXTAREA"), frame->document().focusedNode().nodeName());
     419
     420    // Find in a contentEditable element.
     421    EXPECT_TRUE(frame->find(findIdentifier, WebString::fromUTF8("bar4"), options, false, 0));
     422    // Confirm stopFinding(false) sets the selection on the found text.
     423    frame->stopFinding(false);
     424    range = frame->selectionRange();
     425    ASSERT_FALSE(range.isNull());
     426    EXPECT_EQ(0, range.startOffset());
     427    EXPECT_EQ(4, range.endOffset());
     428    // "bar4" is surrounded by <span>, but the focusable node should be the parent <div>.
     429    EXPECT_EQ(WebString::fromUTF8("DIV"), frame->document().focusedNode().nodeName());
     430
     431    webView->close();
     432}
     433
    382434} // namespace
Note: See TracChangeset for help on using the changeset viewer.