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

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 tyrbot failure 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 cc25047179fdb7ca43ece0e0e0d8497929d995aa..cbe00003273845a2c5a1bb729a57340a52f4d745 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -1508,6 +1508,29 @@ WebRect RenderWidget::windowResizerRect() {
return resizer_rect_;
}
+void RenderWidget::adjustSelectionForBoundary(int& selectionStart,
yosin_UTC9 2016/06/15 05:34:41 Please follow Chromimum coding style: http://dev.c
+ 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);
+}
+
void RenderWidget::OnImeSetComposition(
const base::string16& text,
const std::vector<WebCompositionUnderline>& underlines,
@@ -1516,6 +1539,9 @@ void RenderWidget::OnImeSetComposition(
if (!ShouldHandleImeEvent())
return;
ImeEventGuard guard(this);
+
+ adjustSelectionForBoundary(selection_start, selection_end, text.length());
+
if (!webwidget_->setComposition(
text, WebVector<WebCompositionUnderline>(underlines),
selection_start, selection_end)) {

Powered by Google App Engine
This is Rietveld 408576698