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)) { |