Changeset 121451 in webkit


Ignore:
Timestamp:
Jun 28, 2012, 12:35:39 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Change WebViewImpl::textInputInfo to use root editable element.
https://bugs.webkit.org/show_bug.cgi?id=90179

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

WebViewImpl::textInputInfo currently returns text value and offsets relative to the
focused node. For contenteditable nodes, this may not give the expected result.

This patch changes the method to return value and offsets for the root editable element.
This also allows the implementation to be simplified somewhat.

This also ensures that the offsets returned will use the same basis as the recently added
method Editor::setSelectionOffsets (and WebViewImpl::setEditableSelectionOffsets).

Testing for textInputInfo has been added to WebViewTest.

  • src/WebViewImpl.cpp:

(WebKit::WebViewImpl::textInputInfo):

  • tests/WebViewTest.cpp:

(WebKit::TEST_F):

Location:
trunk/Source/WebKit/chromium
Files:
3 edited

Legend:

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

    r121450 r121451  
     12012-06-28  Oli Lan  <olilan@chromium.org>
     2
     3        [chromium] Change WebViewImpl::textInputInfo to use root editable element.
     4        https://bugs.webkit.org/show_bug.cgi?id=90179
     5
     6        Reviewed by Adam Barth.
     7
     8        WebViewImpl::textInputInfo currently returns text value and offsets relative to the
     9        focused node. For contenteditable nodes, this may not give the expected result.
     10
     11        This patch changes the method to return value and offsets for the root editable element.
     12        This also allows the implementation to be simplified somewhat.
     13
     14        This also ensures that the offsets returned will use the same basis as the recently added
     15        method Editor::setSelectionOffsets (and WebViewImpl::setEditableSelectionOffsets).
     16
     17        Testing for textInputInfo has been added to WebViewTest.
     18
     19        * src/WebViewImpl.cpp:
     20        (WebKit::WebViewImpl::textInputInfo):
     21        * tests/WebViewTest.cpp:
     22        (WebKit::TEST_F):
     23
    1242012-06-28  James Robinson  <jamesr@chromium.org>
    225
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r121342 r121451  
    19881988        return info;
    19891989
    1990     Node* node = focusedWebCoreNode();
     1990    Node* node = selection->selection().rootEditableElement();
    19911991    if (!node)
    19921992        return info;
     
    19961996        return info;
    19971997
    1998     if (node->hasTagName(HTMLNames::textareaTag))
    1999         info.value = static_cast<HTMLTextAreaElement*>(node)->value();
    2000     else if (node->hasTagName(HTMLNames::inputTag))
    2001         info.value = static_cast<HTMLInputElement*>(node)->value();
    2002     else if (node->shouldUseInputMethod())
    2003         info.value = node->nodeValue();
    2004     else
    2005         return info;
     1998    info.value = plainText(rangeOfContents(node).get());
    20061999
    20072000    if (info.value.isEmpty())
    20082001        return info;
    20092002
    2010     if (node->hasTagName(HTMLNames::textareaTag) || node->hasTagName(HTMLNames::inputTag)) {
    2011         HTMLTextFormControlElement* formElement = static_cast<HTMLTextFormControlElement*>(node);
    2012         info.selectionStart = formElement->selectionStart();
    2013         info.selectionEnd = formElement->selectionEnd();
    2014         if (editor->hasComposition()) {
    2015             info.compositionStart = formElement->indexForVisiblePosition(Position(editor->compositionNode(), editor->compositionStart()));
    2016             info.compositionEnd = formElement->indexForVisiblePosition(Position(editor->compositionNode(), editor->compositionEnd()));
    2017         }
    2018     } else {
    2019         info.selectionStart = selection->start().computeOffsetInContainerNode();
    2020         info.selectionEnd = selection->end().computeOffsetInContainerNode();
    2021         if (editor->hasComposition()) {
    2022             info.compositionStart = static_cast<int>(editor->compositionStart());
    2023             info.compositionEnd = static_cast<int>(editor->compositionEnd());
    2024         }
     2003    size_t location;
     2004    size_t length;
     2005    RefPtr<Range> range = selection->selection().firstRange();
     2006    if (range && TextIterator::getLocationAndLengthFromRange(selection->rootEditableElement(), range.get(), location, length)) {
     2007        info.selectionStart = location;
     2008        info.selectionEnd = location + length;
     2009    }
     2010    range = editor->compositionRange();
     2011    if (range && TextIterator::getLocationAndLengthFromRange(selection->rootEditableElement(), range.get(), location, length)) {
     2012        info.compositionStart = location;
     2013        info.compositionEnd = location + length;
    20252014    }
    20262015
  • trunk/Source/WebKit/chromium/tests/WebViewTest.cpp

    r121408 r121451  
    307307}
    308308
    309 TEST_F(WebViewTest, SetEditableSelectionOffsets)
     309TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
    310310{
    311311    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "input_field_populated.html");
     
    315315    WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame());
    316316    EXPECT_EQ("56789abc", frame->selectionAsText());
     317    WebTextInputInfo info = webView->textInputInfo();
     318    EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value);
     319    EXPECT_EQ(5, info.selectionStart);
     320    EXPECT_EQ(13, info.selectionEnd);
     321    EXPECT_EQ(-1, info.compositionStart);
     322    EXPECT_EQ(-1, info.compositionEnd);
    317323    webView->close();
    318324
     
    323329    frame = static_cast<WebFrameImpl*>(webView->mainFrame());
    324330    EXPECT_EQ("89abcdefghi", frame->selectionAsText());
    325     webView->close();
    326 }
    327 
    328 }
     331    info = webView->textInputInfo();
     332    EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value);
     333    EXPECT_EQ(8, info.selectionStart);
     334    EXPECT_EQ(19, info.selectionEnd);
     335    EXPECT_EQ(-1, info.compositionStart);
     336    EXPECT_EQ(-1, info.compositionEnd);
     337    webView->close();
     338}
     339
     340}
Note: See TracChangeset for help on using the changeset viewer.