Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1231)

Unified Diff: content/renderer/render_view_impl.cc

Issue 8769003: Pepper IME API for surrounding text retrieval. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sort. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/render_view_impl.cc
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 9f34b6c26bf5e60208b0c0051dc19894ed86fa6e..5506b448b2d9751caecc3d916fd38f7ce4b64b10 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -3606,34 +3606,42 @@ void RenderViewImpl::SyncSelectionIfRequired() {
if (!frame)
return;
- size_t location, length;
- if (!webview()->caretOrSelectionRange(&location, &length))
- return;
-
string16 text;
size_t offset;
- ui::Range range(location, location + length);
-
- if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
- // If current focused element is editable, we will send 100 more chars
- // before and after selection. It is for input method surrounding text
- // feature.
- if (location > kExtraCharsBeforeAndAfterSelection)
- offset = location - kExtraCharsBeforeAndAfterSelection;
- else
- offset = 0;
- length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
- WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
- if (!webrange.isNull())
- text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
+ ui::Range range;
+
+ if (pepper_delegate_.IsPluginFocused()) {
+ pepper_delegate_.GetSurroundingText(&text, &range);
+ offset = 0; // Pepper API does not support offset reporting.
+ // TODO(kinaba): cut as needed.
} else {
- offset = location;
- text = frame->selectionAsText();
- // http://crbug.com/101435
- // In some case, frame->selectionAsText() returned text's length is not
- // equal to the length returned from webview()->caretOrSelectionRange().
- // So we have to set the range according to text.length().
- range.set_end(range.start() + text.length());
+ size_t location, length;
+ if (!webview()->caretOrSelectionRange(&location, &length))
+ return;
+
+ range = ui::Range(location, location + length);
+
+ if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
+ // If current focused element is editable, we will send 100 more chars
+ // before and after selection. It is for input method surrounding text
+ // feature.
+ if (location > kExtraCharsBeforeAndAfterSelection)
+ offset = location - kExtraCharsBeforeAndAfterSelection;
+ else
+ offset = 0;
+ length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
+ WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
+ if (!webrange.isNull())
+ text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
+ } else {
+ offset = location;
+ text = frame->selectionAsText();
+ // http://crbug.com/101435
+ // In some case, frame->selectionAsText() returned text's length is not
+ // equal to the length returned from webview()->caretOrSelectionRange().
+ // So we have to set the range according to text.length().
+ range.set_end(range.start() + text.length());
+ }
}
// Sometimes we get repeated didChangeSelection calls from webkit when
@@ -4689,6 +4697,10 @@ void RenderViewImpl::PpapiPluginCancelComposition() {
Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
}
+void RenderViewImpl::PpapiPluginSelectionChanged() {
+ SyncSelectionIfRequired();
+}
+
void RenderViewImpl::OnImeSetComposition(
const string16& text,
const std::vector<WebKit::WebCompositionUnderline>& underlines,

Powered by Google App Engine
This is Rietveld 408576698