Changeset 121451 in webkit
- Timestamp:
- Jun 28, 2012, 12:35:39 PM (13 years ago)
- Location:
- trunk/Source/WebKit/chromium
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/chromium/ChangeLog
r121450 r121451 1 2012-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 1 24 2012-06-28 James Robinson <jamesr@chromium.org> 2 25 -
trunk/Source/WebKit/chromium/src/WebViewImpl.cpp
r121342 r121451 1988 1988 return info; 1989 1989 1990 Node* node = focusedWebCoreNode();1990 Node* node = selection->selection().rootEditableElement(); 1991 1991 if (!node) 1992 1992 return info; … … 1996 1996 return info; 1997 1997 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()); 2006 1999 2007 2000 if (info.value.isEmpty()) 2008 2001 return info; 2009 2002 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; 2025 2014 } 2026 2015 -
trunk/Source/WebKit/chromium/tests/WebViewTest.cpp
r121408 r121451 307 307 } 308 308 309 TEST_F(WebViewTest, SetEditableSelectionOffsets )309 TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo) 310 310 { 311 311 FrameTestHelpers::registerMockedURLLoad(m_baseURL, "input_field_populated.html"); … … 315 315 WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 316 316 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); 317 323 webView->close(); 318 324 … … 323 329 frame = static_cast<WebFrameImpl*>(webView->mainFrame()); 324 330 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.