- Revision
- 126200
- Author
- [email protected]
- Date
- 2012-08-21 15:49:58 -0700 (Tue, 21 Aug 2012)
Log Message
[chromium] Add WebView methods setCompositionFromExistingText and extendSelectionAndDelete.
https://bugs.webkit.org/show_bug.cgi?id=93724
Patch by Oli Lan <[email protected]> on 2012-08-21
Reviewed by Ryosuke Niwa.
This adds two new methods to WebViewImpl.
1) setCompositionFromExistingText creates a new composition from the existing text
in the currently focused input field. The new composition is between the two offsets
provided, relative to the rootEditableElement. The current selection is left unchanged.
2) extendSelectionAndDelete extends the selection by the specified number of characters
before and after, and then deletes the selection. If the selection is just a caret, the effect
is to delete the specified number of characters before and after the current editing point.
These methods will be used e.g. by the Android port to implement IME functionality.
New tests WebViewTest.ExtendSelectionAndDelete and WebViewTest.SetCompositionFromExistingText
test the two new methods.
* public/WebView.h:
(WebView):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::setComposingRegion):
(WebKit):
(WebKit::extendSelectionAndDelete):
* src/WebViewImpl.h:
(WebViewImpl):
* tests/WebViewTest.cpp:
Modified Paths
Diff
Modified: trunk/Source/WebKit/chromium/ChangeLog (126199 => 126200)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-08-21 22:41:32 UTC (rev 126199)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-08-21 22:49:58 UTC (rev 126200)
@@ -1,3 +1,35 @@
+2012-08-21 Oli Lan <[email protected]>
+
+ [chromium] Add WebView methods setCompositionFromExistingText and extendSelectionAndDelete.
+ https://bugs.webkit.org/show_bug.cgi?id=93724
+
+ Reviewed by Ryosuke Niwa.
+
+ This adds two new methods to WebViewImpl.
+
+ 1) setCompositionFromExistingText creates a new composition from the existing text
+ in the currently focused input field. The new composition is between the two offsets
+ provided, relative to the rootEditableElement. The current selection is left unchanged.
+
+ 2) extendSelectionAndDelete extends the selection by the specified number of characters
+ before and after, and then deletes the selection. If the selection is just a caret, the effect
+ is to delete the specified number of characters before and after the current editing point.
+
+ These methods will be used e.g. by the Android port to implement IME functionality.
+
+ New tests WebViewTest.ExtendSelectionAndDelete and WebViewTest.SetCompositionFromExistingText
+ test the two new methods.
+
+ * public/WebView.h:
+ (WebView):
+ * src/WebViewImpl.cpp:
+ (WebKit::WebViewImpl::setComposingRegion):
+ (WebKit):
+ (WebKit::extendSelectionAndDelete):
+ * src/WebViewImpl.h:
+ (WebViewImpl):
+ * tests/WebViewTest.cpp:
+
2012-08-21 Alec Flett <[email protected]>
IndexedDB: remove old update/openCursor glue
Modified: trunk/Source/WebKit/chromium/public/WebView.h (126199 => 126200)
--- trunk/Source/WebKit/chromium/public/WebView.h 2012-08-21 22:41:32 UTC (rev 126199)
+++ trunk/Source/WebKit/chromium/public/WebView.h 2012-08-21 22:49:58 UTC (rev 126200)
@@ -460,6 +460,8 @@
virtual void transferActiveWheelFlingAnimation(const WebActiveWheelFlingParameters&) = 0;
virtual bool setEditableSelectionOffsets(int start, int end) = 0;
+ virtual bool setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines) = 0;
+ virtual void extendSelectionAndDelete(int before, int after) = 0;
virtual bool isSelectionEditable() const = 0;
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (126199 => 126200)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-08-21 22:41:32 UTC (rev 126199)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-08-21 22:49:58 UTC (rev 126200)
@@ -2214,6 +2214,58 @@
return editor->setSelectionOffsets(start, end);
}
+bool WebViewImpl::setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines)
+{
+ const Frame* focused = focusedWebCoreFrame();
+ if (!focused)
+ return false;
+
+ Editor* editor = focused->editor();
+ if (!editor || !editor->canEdit())
+ return false;
+
+ editor->cancelComposition();
+
+ if (compositionStart == compositionEnd)
+ return true;
+
+ size_t location;
+ size_t length;
+ caretOrSelectionRange(&location, &length);
+ editor->setIgnoreCompositionSelectionChange(true);
+ editor->setSelectionOffsets(compositionStart, compositionEnd);
+ String text = editor->selectedText();
+ focused->document()->execCommand("delete", true);
+ editor->setComposition(text, CompositionUnderlineVectorBuilder(underlines), 0, 0);
+ editor->setSelectionOffsets(location, location + length);
+ editor->setIgnoreCompositionSelectionChange(false);
+
+ return true;
+}
+
+void WebViewImpl::extendSelectionAndDelete(int before, int after)
+{
+ const Frame* focused = focusedWebCoreFrame();
+ if (!focused)
+ return;
+
+ Editor* editor = focused->editor();
+ if (!editor || !editor->canEdit())
+ return;
+
+ FrameSelection* selection = focused->selection();
+ if (!selection)
+ return;
+
+ size_t location;
+ size_t length;
+ RefPtr<Range> range = selection->selection().firstRange();
+ if (range && TextIterator::getLocationAndLengthFromRange(selection->rootEditableElement(), range.get(), location, length)) {
+ editor->setSelectionOffsets(max(static_cast<int>(location) - before, 0), location + length + after);
+ focused->document()->execCommand("delete", true);
+ }
+}
+
bool WebViewImpl::isSelectionEditable() const
{
const Frame* frame = focusedWebCoreFrame();
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (126199 => 126200)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.h 2012-08-21 22:41:32 UTC (rev 126199)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h 2012-08-21 22:49:58 UTC (rev 126200)
@@ -162,6 +162,8 @@
virtual WebTextInputInfo textInputInfo();
virtual WebTextInputType textInputType();
virtual bool setEditableSelectionOffsets(int start, int end);
+ virtual bool setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines);
+ virtual void extendSelectionAndDelete(int before, int after);
virtual bool isSelectionEditable() const;
virtual WebColor backgroundColor() const;
virtual bool selectionBounds(WebRect& start, WebRect& end) const;
Modified: trunk/Source/WebKit/chromium/tests/WebViewTest.cpp (126199 => 126200)
--- trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2012-08-21 22:41:32 UTC (rev 126199)
+++ trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2012-08-21 22:49:58 UTC (rev 126200)
@@ -379,4 +379,43 @@
webView->close();
}
+TEST_F(WebViewTest, ExtendSelectionAndDelete)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
+ WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ webView->setInitialFocus(false);
+ webView->setEditableSelectionOffsets(10, 10);
+ webView->extendSelectionAndDelete(5, 8);
+ WebTextInputInfo info = webView->textInputInfo();
+ EXPECT_EQ("01234ijklmnopqrstuvwxyz", std::string(info.value.utf8().data()));
+ EXPECT_EQ(5, info.selectionStart);
+ EXPECT_EQ(5, info.selectionEnd);
+ webView->extendSelectionAndDelete(10, 0);
+ info = webView->textInputInfo();
+ EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data()));
+ webView->close();
}
+
+TEST_F(WebViewTest, SetCompositionFromExistingText)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
+ WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ webView->setInitialFocus(false);
+ WebVector<WebCompositionUnderline> emptyUnderlines;
+ webView->setEditableSelectionOffsets(4, 10);
+ webView->setCompositionFromExistingText(8, 12, emptyUnderlines);
+ WebTextInputInfo info = webView->textInputInfo();
+ EXPECT_EQ(4, info.selectionStart);
+ EXPECT_EQ(10, info.selectionEnd);
+ EXPECT_EQ(8, info.compositionStart);
+ EXPECT_EQ(12, info.compositionEnd);
+ webView->setCompositionFromExistingText(0, 0, emptyUnderlines);
+ info = webView->textInputInfo();
+ EXPECT_EQ(4, info.selectionStart);
+ EXPECT_EQ(10, info.selectionEnd);
+ EXPECT_EQ(-1, info.compositionStart);
+ EXPECT_EQ(-1, info.compositionEnd);
+ webView->close();
+}
+
+}