Title: [121451] trunk/Source/WebKit/chromium
- Revision
- 121451
- Author
- [email protected]
- Date
- 2012-06-28 12:35:39 -0700 (Thu, 28 Jun 2012)
Log Message
[chromium] Change WebViewImpl::textInputInfo to use root editable element.
https://bugs.webkit.org/show_bug.cgi?id=90179
Patch by Oli Lan <[email protected]> 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):
Modified Paths
Diff
Modified: trunk/Source/WebKit/chromium/ChangeLog (121450 => 121451)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-06-28 19:27:47 UTC (rev 121450)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-06-28 19:35:39 UTC (rev 121451)
@@ -1,3 +1,26 @@
+2012-06-28 Oli Lan <[email protected]>
+
+ [chromium] Change WebViewImpl::textInputInfo to use root editable element.
+ https://bugs.webkit.org/show_bug.cgi?id=90179
+
+ 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):
+
2012-06-28 James Robinson <[email protected]>
[chromium] Should schedule a commit when dropping contents textures
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (121450 => 121451)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-06-28 19:27:47 UTC (rev 121450)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-06-28 19:35:39 UTC (rev 121451)
@@ -1987,7 +1987,7 @@
if (!selection)
return info;
- Node* node = focusedWebCoreNode();
+ Node* node = selection->selection().rootEditableElement();
if (!node)
return info;
@@ -1995,34 +1995,23 @@
if (info.type == WebTextInputTypeNone)
return info;
- if (node->hasTagName(HTMLNames::textareaTag))
- info.value = static_cast<HTMLTextAreaElement*>(node)->value();
- else if (node->hasTagName(HTMLNames::inputTag))
- info.value = static_cast<HTMLInputElement*>(node)->value();
- else if (node->shouldUseInputMethod())
- info.value = node->nodeValue();
- else
- return info;
+ info.value = plainText(rangeOfContents(node).get());
if (info.value.isEmpty())
return info;
- if (node->hasTagName(HTMLNames::textareaTag) || node->hasTagName(HTMLNames::inputTag)) {
- HTMLTextFormControlElement* formElement = static_cast<HTMLTextFormControlElement*>(node);
- info.selectionStart = formElement->selectionStart();
- info.selectionEnd = formElement->selectionEnd();
- if (editor->hasComposition()) {
- info.compositionStart = formElement->indexForVisiblePosition(Position(editor->compositionNode(), editor->compositionStart()));
- info.compositionEnd = formElement->indexForVisiblePosition(Position(editor->compositionNode(), editor->compositionEnd()));
- }
- } else {
- info.selectionStart = selection->start().computeOffsetInContainerNode();
- info.selectionEnd = selection->end().computeOffsetInContainerNode();
- if (editor->hasComposition()) {
- info.compositionStart = static_cast<int>(editor->compositionStart());
- info.compositionEnd = static_cast<int>(editor->compositionEnd());
- }
+ size_t location;
+ size_t length;
+ RefPtr<Range> range = selection->selection().firstRange();
+ if (range && TextIterator::getLocationAndLengthFromRange(selection->rootEditableElement(), range.get(), location, length)) {
+ info.selectionStart = location;
+ info.selectionEnd = location + length;
}
+ range = editor->compositionRange();
+ if (range && TextIterator::getLocationAndLengthFromRange(selection->rootEditableElement(), range.get(), location, length)) {
+ info.compositionStart = location;
+ info.compositionEnd = location + length;
+ }
return info;
}
Modified: trunk/Source/WebKit/chromium/tests/WebViewTest.cpp (121450 => 121451)
--- trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2012-06-28 19:27:47 UTC (rev 121450)
+++ trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2012-06-28 19:35:39 UTC (rev 121451)
@@ -306,7 +306,7 @@
}
-TEST_F(WebViewTest, SetEditableSelectionOffsets)
+TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
{
FrameTestHelpers::registerMockedURLLoad(m_baseURL, "input_field_populated.html");
WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
@@ -314,6 +314,12 @@
webView->setEditableSelectionOffsets(5, 13);
WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame());
EXPECT_EQ("56789abc", frame->selectionAsText());
+ WebTextInputInfo info = webView->textInputInfo();
+ EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value);
+ EXPECT_EQ(5, info.selectionStart);
+ EXPECT_EQ(13, info.selectionEnd);
+ EXPECT_EQ(-1, info.compositionStart);
+ EXPECT_EQ(-1, info.compositionEnd);
webView->close();
FrameTestHelpers::registerMockedURLLoad(m_baseURL, "content_editable_populated.html");
@@ -322,6 +328,12 @@
webView->setEditableSelectionOffsets(8, 19);
frame = static_cast<WebFrameImpl*>(webView->mainFrame());
EXPECT_EQ("89abcdefghi", frame->selectionAsText());
+ info = webView->textInputInfo();
+ EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value);
+ EXPECT_EQ(8, info.selectionStart);
+ EXPECT_EQ(19, info.selectionEnd);
+ EXPECT_EQ(-1, info.compositionStart);
+ EXPECT_EQ(-1, info.compositionEnd);
webView->close();
}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes