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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/render_widget.h" 5 #include "content/renderer/render_widget.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 return pending_window_rect_; 1501 return pending_window_rect_;
1502 } 1502 }
1503 1503
1504 return window_screen_rect_; 1504 return window_screen_rect_;
1505 } 1505 }
1506 1506
1507 WebRect RenderWidget::windowResizerRect() { 1507 WebRect RenderWidget::windowResizerRect() {
1508 return resizer_rect_; 1508 return resizer_rect_;
1509 } 1509 }
1510 1510
1511 void RenderWidget::adjustSelectionForBoundary(int& selectionStart,
yosin_UTC9 2016/06/15 05:34:41 Please follow Chromimum coding style: http://dev.c
1512 int& selectionEnd,
1513 const int textLength) const {
1514 int compositionLength =
1515 text_input_info_.compositionEnd - text_input_info_.compositionStart;
1516 int beforeCompositionLength;
1517 if (compositionLength != 0)
1518 beforeCompositionLength = text_input_info_.compositionStart;
1519 else
1520 beforeCompositionLength = text_input_info_.selectionStart;
1521 int afterCompositionLength =
1522 static_cast<int>(text_input_info_.value.length()) - compositionLength -
1523 beforeCompositionLength;
1524
1525 // In case of exceeding the left boundary.
1526 selectionStart = std::max(selectionStart, -beforeCompositionLength);
1527 selectionEnd = std::max(selectionEnd, selectionStart);
1528
1529 // In case of exceeding the right boundary.
1530 selectionEnd = std::min(selectionEnd, textLength + afterCompositionLength);
1531 selectionStart = std::min(selectionStart, selectionEnd);
1532 }
1533
1511 void RenderWidget::OnImeSetComposition( 1534 void RenderWidget::OnImeSetComposition(
1512 const base::string16& text, 1535 const base::string16& text,
1513 const std::vector<WebCompositionUnderline>& underlines, 1536 const std::vector<WebCompositionUnderline>& underlines,
1514 const gfx::Range& replacement_range, 1537 const gfx::Range& replacement_range,
1515 int selection_start, int selection_end) { 1538 int selection_start, int selection_end) {
1516 if (!ShouldHandleImeEvent()) 1539 if (!ShouldHandleImeEvent())
1517 return; 1540 return;
1518 ImeEventGuard guard(this); 1541 ImeEventGuard guard(this);
1542
1543 adjustSelectionForBoundary(selection_start, selection_end, text.length());
1544
1519 if (!webwidget_->setComposition( 1545 if (!webwidget_->setComposition(
1520 text, WebVector<WebCompositionUnderline>(underlines), 1546 text, WebVector<WebCompositionUnderline>(underlines),
1521 selection_start, selection_end)) { 1547 selection_start, selection_end)) {
1522 // If we failed to set the composition text, then we need to let the browser 1548 // If we failed to set the composition text, then we need to let the browser
1523 // process to cancel the input method's ongoing composition session, to make 1549 // process to cancel the input method's ongoing composition session, to make
1524 // sure we are in a consistent state. 1550 // sure we are in a consistent state.
1525 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1551 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1526 } 1552 }
1527 UpdateCompositionInfo(true); 1553 UpdateCompositionInfo(true);
1528 } 1554 }
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 void RenderWidget::requestPointerUnlock() { 2158 void RenderWidget::requestPointerUnlock() {
2133 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); 2159 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2134 } 2160 }
2135 2161
2136 bool RenderWidget::isPointerLocked() { 2162 bool RenderWidget::isPointerLocked() {
2137 return mouse_lock_dispatcher_->IsMouseLockedTo( 2163 return mouse_lock_dispatcher_->IsMouseLockedTo(
2138 webwidget_mouse_lock_target_.get()); 2164 webwidget_mouse_lock_target_.get());
2139 } 2165 }
2140 2166
2141 } // namespace content 2167 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698