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

Unified Diff: content/renderer/render_widget.cc

Issue 2020973002: Reland: Fix setComposingText with empty text when newCursorPosition != 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: For multi-code text Created 4 years, 6 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_widget.cc
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index ee171f595d950efcb2d85b3a3de5361b38a6517a..187edac700de34a8a7379c5d3125d7a8e429f802 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -1508,6 +1508,32 @@ WebRect RenderWidget::windowResizerRect() {
return resizer_rect_;
}
+std::pair<int, int> RenderWidget::adjustSelectionForBoundary(
+ int selectionStart,
+ int selectionEnd,
+ const int textLength) const {
+ int compositionLength =
+ text_input_info_.compositionEnd - text_input_info_.compositionStart;
+ int beforeCompositionLength;
+ if (compositionLength != 0)
+ beforeCompositionLength = text_input_info_.compositionStart;
+ else
+ beforeCompositionLength = text_input_info_.selectionStart;
+ int afterCompositionLength =
+ static_cast<int>(text_input_info_.value.length()) - compositionLength -
+ beforeCompositionLength;
+
+ // In case of exceeding the left boundary.
+ selectionStart = std::max(selectionStart, -beforeCompositionLength);
+ selectionEnd = std::max(selectionEnd, selectionStart);
+
+ // In case of exceeding the right boundary.
+ selectionEnd = std::min(selectionEnd, textLength + afterCompositionLength);
+ selectionStart = std::min(selectionStart, selectionEnd);
+
+ return std::make_pair(selectionStart, selectionEnd);
+}
+
void RenderWidget::OnImeSetComposition(
const base::string16& text,
const std::vector<WebCompositionUnderline>& underlines,
@@ -1516,9 +1542,13 @@ void RenderWidget::OnImeSetComposition(
if (!ShouldHandleImeEvent())
return;
ImeEventGuard guard(this);
+
+ std::pair<int, int> selectionPair =
+ adjustSelectionForBoundary(selection_start, selection_end, text.length());
+
if (!webwidget_->setComposition(
text, WebVector<WebCompositionUnderline>(underlines),
- selection_start, selection_end)) {
+ selectionPair.first, selectionPair.second)) {
// If we failed to set the composition text, then we need to let the browser
// process to cancel the input method's ongoing composition session, to make
// sure we are in a consistent state.

Powered by Google App Engine
This is Rietveld 408576698