Title: [120985] trunk/Source
Revision
120985
Author
[email protected]
Date
2012-06-21 17:49:25 -0700 (Thu, 21 Jun 2012)

Log Message

Add methods to select between offsets in an editable field.
https://bugs.webkit.org/show_bug.cgi?id=89098

Patch by Oli Lan <[email protected]> on 2012-06-21
Reviewed by Ryosuke Niwa.

Reviewed by Ryosuke Niwa.

Source/WebCore:

Adds a new method setSelectionOffsets to Editor. This selects between
the two integer offsets provided in the node currently being edited,
assuming the offsets are given relative to the rootEditableElement.
If no node or field is currently being edited, the method returns false.

Test: a new test has been added to the chromium port's WebViewTest that
calls this via WebViewImpl::setSelectionEditableOffsets.

* editing/Editor.cpp:
(WebCore::Editor::setSelectionOffsets):
(WebCore):
* editing/Editor.h:
(Editor):

Source/WebKit/chromium:

This adds a new method WebViewImpl::setEditableSelectionOffsets, which
can be used to select between two character positions in the node
currently beign edited.

The offsets are assumed to be relative to the rootEditableElement.

This can be used for IME features that require the ability to manipulate
the selection, for example on Android where the method InputConnection#setSelection
is used.

This method calls a new method Editor::setSelectionOffsets.

The method works for inputs/textareas (i.e. text form controls) and
contenteditable nodes, and the new test in WebViewTest tests both these cases.

* public/WebView.h:
(WebView):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::setEditableSelectionOffsets):
(WebKit):
* src/WebViewImpl.h:
(WebViewImpl):
* tests/WebViewTest.cpp:
(WebKit::TEST_F):
(WebKit):
* tests/data/content_editable_populated.html: Added.
* tests/data/input_field_populated.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (120984 => 120985)


--- trunk/Source/WebCore/ChangeLog	2012-06-22 00:36:07 UTC (rev 120984)
+++ trunk/Source/WebCore/ChangeLog	2012-06-22 00:49:25 UTC (rev 120985)
@@ -1,3 +1,26 @@
+2012-06-21  Oli Lan  <[email protected]>
+
+        Add methods to select between offsets in an editable field.
+        https://bugs.webkit.org/show_bug.cgi?id=89098
+
+        Reviewed by Ryosuke Niwa.
+
+        Reviewed by Ryosuke Niwa.
+
+        Adds a new method setSelectionOffsets to Editor. This selects between
+        the two integer offsets provided in the node currently being edited,
+        assuming the offsets are given relative to the rootEditableElement.
+        If no node or field is currently being edited, the method returns false.
+        
+        Test: a new test has been added to the chromium port's WebViewTest that
+        calls this via WebViewImpl::setSelectionEditableOffsets.
+        
+        * editing/Editor.cpp:
+        (WebCore::Editor::setSelectionOffsets):
+        (WebCore):
+        * editing/Editor.h:
+        (Editor):
+
 2012-06-21  Julien Chaffraix  <[email protected]>
 
         Add support for the grid and inline-grid display types.

Modified: trunk/Source/WebCore/editing/Editor.cpp (120984 => 120985)


--- trunk/Source/WebCore/editing/Editor.cpp	2012-06-22 00:36:07 UTC (rev 120984)
+++ trunk/Source/WebCore/editing/Editor.cpp	2012-06-22 00:49:25 UTC (rev 120985)
@@ -2347,6 +2347,19 @@
     return true;
 }
 
+bool Editor::setSelectionOffsets(int selectionStart, int selectionEnd)
+{
+    Element* rootEditableElement = m_frame->selection()->rootEditableElement();
+    if (!rootEditableElement)
+        return false;
+
+    RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(rootEditableElement, selectionStart, selectionEnd - selectionStart);
+    if (!range)
+        return false;
+
+    return m_frame->selection()->setSelectedRange(range.get(), VP_DEFAULT_AFFINITY, false);
+}
+
 void Editor::transpose()
 {
     if (!canEdit())

Modified: trunk/Source/WebCore/editing/Editor.h (120984 => 120985)


--- trunk/Source/WebCore/editing/Editor.h	2012-06-22 00:36:07 UTC (rev 120984)
+++ trunk/Source/WebCore/editing/Editor.h	2012-06-22 00:49:25 UTC (rev 120985)
@@ -295,6 +295,7 @@
     void cancelComposition();
     PassRefPtr<Range> compositionRange() const;
     bool getCompositionSelection(unsigned& selectionStart, unsigned& selectionEnd) const;
+    bool setSelectionOffsets(int selectionStart, int selectionEnd);
 
     // getting international text input composition state (for use by InlineTextBox)
     Text* compositionNode() const { return m_compositionNode.get(); }

Modified: trunk/Source/WebKit/chromium/ChangeLog (120984 => 120985)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-06-22 00:36:07 UTC (rev 120984)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-06-22 00:49:25 UTC (rev 120985)
@@ -1,3 +1,40 @@
+2012-06-21  Oli Lan  <[email protected]>
+
+        Add methods to select between offsets in an editable field.
+        https://bugs.webkit.org/show_bug.cgi?id=89098
+
+        Reviewed by Ryosuke Niwa.
+
+        Reviewed by Ryosuke Niwa.
+
+        This adds a new method WebViewImpl::setEditableSelectionOffsets, which
+        can be used to select between two character positions in the node
+        currently beign edited.
+
+        The offsets are assumed to be relative to the rootEditableElement.
+        
+        This can be used for IME features that require the ability to manipulate
+        the selection, for example on Android where the method InputConnection#setSelection
+        is used.
+
+        This method calls a new method Editor::setSelectionOffsets.
+
+        The method works for inputs/textareas (i.e. text form controls) and
+        contenteditable nodes, and the new test in WebViewTest tests both these cases.
+
+        * public/WebView.h:
+        (WebView):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::setEditableSelectionOffsets):
+        (WebKit):
+        * src/WebViewImpl.h:
+        (WebViewImpl):
+        * tests/WebViewTest.cpp:
+        (WebKit::TEST_F):
+        (WebKit):
+        * tests/data/content_editable_populated.html: Added.
+        * tests/data/input_field_populated.html: Added.
+
 2012-06-19  James Robinson  <[email protected]>
 
         [chromium] LayerRendererChromium is not getting visibility messages in single threaded compositing mode.

Modified: trunk/Source/WebKit/chromium/public/WebView.h (120984 => 120985)


--- trunk/Source/WebKit/chromium/public/WebView.h	2012-06-22 00:36:07 UTC (rev 120984)
+++ trunk/Source/WebKit/chromium/public/WebView.h	2012-06-22 00:49:25 UTC (rev 120985)
@@ -453,6 +453,8 @@
     // by the compositor) but must be completed by the WebView.
     virtual void transferActiveWheelFlingAnimation(const WebActiveWheelFlingParameters&) = 0;
 
+    virtual bool setEditableSelectionOffsets(int start, int end) = 0;
+
     // Visibility -----------------------------------------------------------
 
     // Sets the visibility of the WebView.

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (120984 => 120985)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-06-22 00:36:07 UTC (rev 120984)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-06-22 00:49:25 UTC (rev 120985)
@@ -2131,6 +2131,19 @@
     return true;
 }
 
+bool WebViewImpl::setEditableSelectionOffsets(int start, int end)
+{
+    const Frame* focused = focusedWebCoreFrame();
+    if (!focused)
+        return false;
+
+    Editor* editor = focused->editor();
+    if (!editor || !editor->canEdit())
+        return false;
+
+    return editor->setSelectionOffsets(start, end);
+}
+
 bool WebViewImpl::caretOrSelectionRange(size_t* location, size_t* length)
 {
     const Frame* focused = focusedWebCoreFrame();

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (120984 => 120985)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.h	2012-06-22 00:36:07 UTC (rev 120984)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h	2012-06-22 00:49:25 UTC (rev 120985)
@@ -150,6 +150,7 @@
     virtual bool compositionRange(size_t* location, size_t* length);
     virtual WebTextInputInfo textInputInfo();
     virtual WebTextInputType textInputType();
+    virtual bool setEditableSelectionOffsets(int start, int end);
     virtual bool selectionBounds(WebRect& start, WebRect& end) const;
     virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const;
     virtual bool caretOrSelectionRange(size_t* location, size_t* length);

Modified: trunk/Source/WebKit/chromium/tests/WebViewTest.cpp (120984 => 120985)


--- trunk/Source/WebKit/chromium/tests/WebViewTest.cpp	2012-06-22 00:36:07 UTC (rev 120984)
+++ trunk/Source/WebKit/chromium/tests/WebViewTest.cpp	2012-06-22 00:49:25 UTC (rev 120985)
@@ -306,4 +306,23 @@
 
 }
 
+TEST_F(WebViewTest, SetEditableSelectionOffsets)
+{
+    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "input_field_populated.html");
+    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+    webView->setInitialFocus(false);
+    webView->setEditableSelectionOffsets(5, 13);
+    WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame());
+    EXPECT_EQ("56789abc", frame->selectionAsText());
+    webView->close();
+
+    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "content_editable_populated.html");
+    webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "content_editable_populated.html");
+    webView->setInitialFocus(false);
+    webView->setEditableSelectionOffsets(8, 19);
+    frame = static_cast<WebFrameImpl*>(webView->mainFrame());
+    EXPECT_EQ("89abcdefghi", frame->selectionAsText());
+    webView->close();
 }
+
+}

Added: trunk/Source/WebKit/chromium/tests/data/content_editable_populated.html (0 => 120985)


--- trunk/Source/WebKit/chromium/tests/data/content_editable_populated.html	                        (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/content_editable_populated.html	2012-06-22 00:49:25 UTC (rev 120985)
@@ -0,0 +1 @@
+<span contenteditable="true">0123456789abcdefghijklmnopqrstuvwxyz</span>

Added: trunk/Source/WebKit/chromium/tests/data/input_field_populated.html (0 => 120985)


--- trunk/Source/WebKit/chromium/tests/data/input_field_populated.html	                        (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/input_field_populated.html	2012-06-22 00:49:25 UTC (rev 120985)
@@ -0,0 +1 @@
+<input value='0123456789abcdefghijklmnopqrstuvwxyz'/>
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to