Title: [94459] trunk/Source/WebKit/chromium
- Revision
- 94459
- Author
- [email protected]
- Date
- 2011-09-02 16:07:29 -0700 (Fri, 02 Sep 2011)
Log Message
Need API for getting surrounding text from webkit in chromium
https://bugs.webkit.org/show_bug.cgi?id=66681
Patch by Peng Huang <[email protected]> on 2011-09-02
Reviewed by Ryosuke Niwa.
Add getSelectionOffsetsAndTextInEditableContent() to Chromium's
WebViewImpl. This function is for supporting some input methods which
need input context around the edit caret.
* public/WebWidget.h:
(WebKit::WebWidget::getSelectionOffsetsAndTextInEditableContent):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::getSelectionOffsetsAndTextInEditableContent):
* src/WebViewImpl.h:
Modified Paths
Diff
Modified: trunk/Source/WebKit/chromium/ChangeLog (94458 => 94459)
--- trunk/Source/WebKit/chromium/ChangeLog 2011-09-02 22:33:59 UTC (rev 94458)
+++ trunk/Source/WebKit/chromium/ChangeLog 2011-09-02 23:07:29 UTC (rev 94459)
@@ -1,3 +1,20 @@
+2011-09-02 Peng Huang <[email protected]>
+
+ Need API for getting surrounding text from webkit in chromium
+ https://bugs.webkit.org/show_bug.cgi?id=66681
+
+ Reviewed by Ryosuke Niwa.
+
+ Add getSelectionOffsetsAndTextInEditableContent() to Chromium's
+ WebViewImpl. This function is for supporting some input methods which
+ need input context around the edit caret.
+
+ * public/WebWidget.h:
+ (WebKit::WebWidget::getSelectionOffsetsAndTextInEditableContent):
+ * src/WebViewImpl.cpp:
+ (WebKit::WebViewImpl::getSelectionOffsetsAndTextInEditableContent):
+ * src/WebViewImpl.h:
+
2011-09-02 Sheriff Bot <[email protected]>
Unreviewed. Rolled DEPS.
Modified: trunk/Source/WebKit/chromium/public/WebWidget.h (94458 => 94459)
--- trunk/Source/WebKit/chromium/public/WebWidget.h 2011-09-02 22:33:59 UTC (rev 94458)
+++ trunk/Source/WebKit/chromium/public/WebWidget.h 2011-09-02 23:07:29 UTC (rev 94459)
@@ -147,6 +147,11 @@
// Returns the current text input type of this WebWidget.
virtual WebTextInputType textInputType() { return WebKit::WebTextInputTypeNone; }
+ // Returns the plain text around the edit caret and the focus index in the
+ // text. If selection exists, it will return the anchor index as well,
+ // otherwise the anchor index will be the same value of the focus index.
+ virtual bool getSelectionOffsetsAndTextInEditableContent(WebString&, size_t& focus, size_t& anchor) const { return false; }
+
// Returns the current caret bounds of this WebWidget. The selection bounds
// will be returned if a selection range is available.
virtual WebRect caretOrSelectionBounds() { return WebRect(); }
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (94458 => 94459)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2011-09-02 22:33:59 UTC (rev 94458)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2011-09-02 23:07:29 UTC (rev 94459)
@@ -1508,6 +1508,36 @@
return WebTextInputTypeNone;
}
+bool WebViewImpl::getSelectionOffsetsAndTextInEditableContent(WebString& text, size_t& focus, size_t& anchor) const
+{
+ const Frame* frame = focusedWebCoreFrame();
+ if (!frame)
+ return false;
+
+ const FrameSelection* selection = frame->selection();
+ Element* element = selection->rootEditableElement();
+ if (!element)
+ return false;
+
+ size_t location;
+ size_t length;
+ RefPtr<Range> range = selection->selection().firstRange();
+ if (!range || !TextIterator::locationAndLengthFromRange(range.get(), location, length))
+ return false;
+
+ if (selection->selection().isBaseFirst()) {
+ anchor = location;
+ focus = location + length;
+ } else {
+ anchor = location;
+ focus = location + length;
+ }
+
+ text = element->innerText();
+
+ return true;
+}
+
WebRect WebViewImpl::caretOrSelectionBounds()
{
WebRect rect;
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (94458 => 94459)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.h 2011-09-02 22:33:59 UTC (rev 94458)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h 2011-09-02 23:07:29 UTC (rev 94459)
@@ -117,6 +117,7 @@
virtual bool confirmComposition(const WebString& text);
virtual bool compositionRange(size_t* location, size_t* length);
virtual WebTextInputType textInputType();
+ virtual bool getSelectionOffsetsAndTextInEditableContent(WebString&, size_t& focus, size_t& anchor) const;
virtual WebRect caretOrSelectionBounds();
virtual bool selectionRange(WebPoint& start, WebPoint& end) const;
virtual bool caretOrSelectionRange(size_t* location, size_t* length);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes