OLD | NEW |
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 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 return pending_window_rect_; | 1348 return pending_window_rect_; |
1349 } | 1349 } |
1350 | 1350 |
1351 return window_screen_rect_; | 1351 return window_screen_rect_; |
1352 } | 1352 } |
1353 | 1353 |
1354 WebRect RenderWidget::windowResizerRect() { | 1354 WebRect RenderWidget::windowResizerRect() { |
1355 return resizer_rect_; | 1355 return resizer_rect_; |
1356 } | 1356 } |
1357 | 1357 |
| 1358 std::pair<int, int> RenderWidget::adjustSelectionForBoundary( |
| 1359 int selectionStart, |
| 1360 int selectionEnd, |
| 1361 const int textLength) const { |
| 1362 int compositionLength = |
| 1363 text_input_info_.compositionEnd - text_input_info_.compositionStart; |
| 1364 int beforeCompositionLength; |
| 1365 if (compositionLength != 0) |
| 1366 beforeCompositionLength = text_input_info_.compositionStart; |
| 1367 else |
| 1368 beforeCompositionLength = text_input_info_.selectionStart; |
| 1369 int afterCompositionLength = |
| 1370 static_cast<int>(text_input_info_.value.length()) - compositionLength - |
| 1371 beforeCompositionLength; |
| 1372 |
| 1373 // In case of exceeding the left boundary. |
| 1374 selectionStart = std::max(selectionStart, -beforeCompositionLength); |
| 1375 selectionEnd = std::max(selectionEnd, selectionStart); |
| 1376 |
| 1377 // In case of exceeding the right boundary. |
| 1378 selectionEnd = std::min(selectionEnd, textLength + afterCompositionLength); |
| 1379 selectionStart = std::min(selectionStart, selectionEnd); |
| 1380 |
| 1381 return std::make_pair(selectionStart, selectionEnd); |
| 1382 } |
| 1383 |
1358 void RenderWidget::OnImeSetComposition( | 1384 void RenderWidget::OnImeSetComposition( |
1359 const base::string16& text, | 1385 const base::string16& text, |
1360 const std::vector<WebCompositionUnderline>& underlines, | 1386 const std::vector<WebCompositionUnderline>& underlines, |
1361 const gfx::Range& replacement_range, | 1387 const gfx::Range& replacement_range, |
1362 int selection_start, int selection_end) { | 1388 int selection_start, int selection_end) { |
1363 if (!ShouldHandleImeEvent()) | 1389 if (!ShouldHandleImeEvent()) |
1364 return; | 1390 return; |
1365 ImeEventGuard guard(this); | 1391 ImeEventGuard guard(this); |
| 1392 |
| 1393 std::pair<int, int> selectionPair = |
| 1394 adjustSelectionForBoundary(selection_start, selection_end, text.length()); |
| 1395 |
1366 if (!webwidget_->setComposition( | 1396 if (!webwidget_->setComposition( |
1367 text, WebVector<WebCompositionUnderline>(underlines), | 1397 text, WebVector<WebCompositionUnderline>(underlines), |
1368 selection_start, selection_end)) { | 1398 selectionPair.first, selectionPair.second)) { |
1369 // If we failed to set the composition text, then we need to let the browser | 1399 // If we failed to set the composition text, then we need to let the browser |
1370 // process to cancel the input method's ongoing composition session, to make | 1400 // process to cancel the input method's ongoing composition session, to make |
1371 // sure we are in a consistent state. | 1401 // sure we are in a consistent state. |
1372 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1402 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1373 } | 1403 } |
1374 UpdateCompositionInfo(true); | 1404 UpdateCompositionInfo(true); |
1375 } | 1405 } |
1376 | 1406 |
1377 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1407 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
1378 const gfx::Range& replacement_range, | 1408 const gfx::Range& replacement_range, |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 void RenderWidget::requestPointerUnlock() { | 2009 void RenderWidget::requestPointerUnlock() { |
1980 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); | 2010 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
1981 } | 2011 } |
1982 | 2012 |
1983 bool RenderWidget::isPointerLocked() { | 2013 bool RenderWidget::isPointerLocked() { |
1984 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2014 return mouse_lock_dispatcher_->IsMouseLockedTo( |
1985 webwidget_mouse_lock_target_.get()); | 2015 webwidget_mouse_lock_target_.get()); |
1986 } | 2016 } |
1987 | 2017 |
1988 } // namespace content | 2018 } // namespace content |
OLD | NEW |