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

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 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 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 std::pair<int, int> RenderWidget::adjustSelectionForBoundary(
1512 int selectionStart,
1513 int selectionEnd,
1514 const int textLength) const {
1515 int compositionLength =
1516 text_input_info_.compositionEnd - text_input_info_.compositionStart;
1517 int beforeCompositionLength;
1518 if (compositionLength != 0)
1519 beforeCompositionLength = text_input_info_.compositionStart;
1520 else
1521 beforeCompositionLength = text_input_info_.selectionStart;
1522 int afterCompositionLength =
1523 static_cast<int>(text_input_info_.value.length()) - compositionLength -
1524 beforeCompositionLength;
1525
1526 // In case of exceeding the left boundary.
1527 selectionStart = std::max(selectionStart, -beforeCompositionLength);
1528 selectionEnd = std::max(selectionEnd, selectionStart);
1529
1530 // In case of exceeding the right boundary.
1531 selectionEnd = std::min(selectionEnd, textLength + afterCompositionLength);
1532 selectionStart = std::min(selectionStart, selectionEnd);
1533
1534 return std::make_pair(selectionStart, selectionEnd);
1535 }
1536
1511 void RenderWidget::OnImeSetComposition( 1537 void RenderWidget::OnImeSetComposition(
1512 const base::string16& text, 1538 const base::string16& text,
1513 const std::vector<WebCompositionUnderline>& underlines, 1539 const std::vector<WebCompositionUnderline>& underlines,
1514 const gfx::Range& replacement_range, 1540 const gfx::Range& replacement_range,
1515 int selection_start, int selection_end) { 1541 int selection_start, int selection_end) {
1516 if (!ShouldHandleImeEvent()) 1542 if (!ShouldHandleImeEvent())
1517 return; 1543 return;
1518 ImeEventGuard guard(this); 1544 ImeEventGuard guard(this);
1545
1546 std::pair<int, int> selectionPair =
1547 adjustSelectionForBoundary(selection_start, selection_end, text.length());
1548
1519 if (!webwidget_->setComposition( 1549 if (!webwidget_->setComposition(
1520 text, WebVector<WebCompositionUnderline>(underlines), 1550 text, WebVector<WebCompositionUnderline>(underlines),
1521 selection_start, selection_end)) { 1551 selectionPair.first, selectionPair.second)) {
1522 // If we failed to set the composition text, then we need to let the browser 1552 // 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 1553 // process to cancel the input method's ongoing composition session, to make
1524 // sure we are in a consistent state. 1554 // sure we are in a consistent state.
1525 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1555 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1526 } 1556 }
1527 UpdateCompositionInfo(true); 1557 UpdateCompositionInfo(true);
1528 } 1558 }
1529 1559
1530 void RenderWidget::OnImeConfirmComposition(const base::string16& text, 1560 void RenderWidget::OnImeConfirmComposition(const base::string16& text,
1531 const gfx::Range& replacement_range, 1561 const gfx::Range& replacement_range,
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 void RenderWidget::requestPointerUnlock() { 2162 void RenderWidget::requestPointerUnlock() {
2133 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); 2163 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2134 } 2164 }
2135 2165
2136 bool RenderWidget::isPointerLocked() { 2166 bool RenderWidget::isPointerLocked() {
2137 return mouse_lock_dispatcher_->IsMouseLockedTo( 2167 return mouse_lock_dispatcher_->IsMouseLockedTo(
2138 webwidget_mouse_lock_target_.get()); 2168 webwidget_mouse_lock_target_.get());
2139 } 2169 }
2140 2170
2141 } // namespace content 2171 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698