| Index: content/renderer/render_widget.cc
|
| diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
|
| index 129ed07f6eb454e478f97327fc3e4969ea84065a..0b6007ae505049d68936c18c54250d5063e1a64d 100644
|
| --- a/content/renderer/render_widget.cc
|
| +++ b/content/renderer/render_widget.cc
|
| @@ -1355,6 +1355,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,
|
| @@ -1363,9 +1389,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.
|
|
|