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

Side by Side Diff: content/renderer/render_widget.cc

Issue 2121953002: Do not calculate composition bounds until IME requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 5 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
« no previous file with comments | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 245 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
246 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), 246 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
247 text_input_flags_(0), 247 text_input_flags_(0),
248 can_compose_inline_(true), 248 can_compose_inline_(true),
249 popup_type_(popup_type), 249 popup_type_(popup_type),
250 pending_window_rect_count_(0), 250 pending_window_rect_count_(0),
251 screen_info_(screen_info), 251 screen_info_(screen_info),
252 device_scale_factor_(screen_info_.deviceScaleFactor), 252 device_scale_factor_(screen_info_.deviceScaleFactor),
253 #if defined(OS_ANDROID) 253 #if defined(OS_ANDROID)
254 text_field_is_dirty_(false), 254 text_field_is_dirty_(false),
255 monitor_composition_info_(false),
255 #endif 256 #endif
256 popup_origin_scale_for_emulation_(0.f), 257 popup_origin_scale_for_emulation_(0.f),
257 frame_swap_message_queue_(new FrameSwapMessageQueue()), 258 frame_swap_message_queue_(new FrameSwapMessageQueue()),
258 resizing_mode_selector_(new ResizingModeSelector()), 259 resizing_mode_selector_(new ResizingModeSelector()),
259 has_host_context_menu_location_(false), 260 has_host_context_menu_location_(false),
260 has_focus_(false) { 261 has_focus_(false) {
261 if (!swapped_out) 262 if (!swapped_out)
262 RenderProcess::current()->AddRefProcess(); 263 RenderProcess::current()->AddRefProcess();
263 DCHECK(RenderThread::Get()); 264 DCHECK(RenderThread::Get());
264 device_color_profile_.push_back('0'); 265 device_color_profile_.push_back('0');
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) 491 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
491 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) 492 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
492 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) 493 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
493 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace) 494 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
494 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, 495 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
495 OnWaitNextFrameForTests) 496 OnWaitNextFrameForTests)
496 #if defined(OS_ANDROID) 497 #if defined(OS_ANDROID)
497 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) 498 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
498 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, 499 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
499 OnRequestTextInputStateUpdate) 500 OnRequestTextInputStateUpdate)
501 IPC_MESSAGE_HANDLER(InputMsg_RequestCursorUpdate, OnRequestCursorUpdate)
500 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) 502 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
501 #endif 503 #endif
502 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) 504 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
503 IPC_MESSAGE_UNHANDLED(handled = false) 505 IPC_MESSAGE_UNHANDLED(handled = false)
504 IPC_END_MESSAGE_MAP() 506 IPC_END_MESSAGE_MAP()
505 return handled; 507 return handled;
506 } 508 }
507 509
508 bool RenderWidget::Send(IPC::Message* message) { 510 bool RenderWidget::Send(IPC::Message* message) {
509 // Don't send any messages after the browser has told us to close, and filter 511 // Don't send any messages after the browser has told us to close, and filter
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 return; 1366 return;
1365 ImeEventGuard guard(this); 1367 ImeEventGuard guard(this);
1366 if (!webwidget_->setComposition( 1368 if (!webwidget_->setComposition(
1367 text, WebVector<WebCompositionUnderline>(underlines), 1369 text, WebVector<WebCompositionUnderline>(underlines),
1368 selection_start, selection_end)) { 1370 selection_start, selection_end)) {
1369 // If we failed to set the composition text, then we need to let the browser 1371 // 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 1372 // process to cancel the input method's ongoing composition session, to make
1371 // sure we are in a consistent state. 1373 // sure we are in a consistent state.
1372 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1374 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1373 } 1375 }
1374 UpdateCompositionInfo(true); 1376 UpdateCompositionInfo(true, false /* force update */);
1375 } 1377 }
1376 1378
1377 void RenderWidget::OnImeConfirmComposition(const base::string16& text, 1379 void RenderWidget::OnImeConfirmComposition(const base::string16& text,
1378 const gfx::Range& replacement_range, 1380 const gfx::Range& replacement_range,
1379 bool keep_selection) { 1381 bool keep_selection) {
1380 if (!ShouldHandleImeEvent()) 1382 if (!ShouldHandleImeEvent())
1381 return; 1383 return;
1382 ImeEventGuard guard(this); 1384 ImeEventGuard guard(this);
1383 input_handler_->set_handling_input_event(true); 1385 input_handler_->set_handling_input_event(true);
1384 if (text.length()) 1386 if (text.length())
1385 webwidget_->confirmComposition(text); 1387 webwidget_->confirmComposition(text);
1386 else if (keep_selection) 1388 else if (keep_selection)
1387 webwidget_->confirmComposition(WebWidget::KeepSelection); 1389 webwidget_->confirmComposition(WebWidget::KeepSelection);
1388 else 1390 else
1389 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); 1391 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
1390 input_handler_->set_handling_input_event(false); 1392 input_handler_->set_handling_input_event(false);
1391 UpdateCompositionInfo(true); 1393 UpdateCompositionInfo(true, false /* force update */);
1392 } 1394 }
1393 1395
1394 void RenderWidget::OnDeviceScaleFactorChanged() { 1396 void RenderWidget::OnDeviceScaleFactorChanged() {
1395 if (!compositor_) 1397 if (!compositor_)
1396 return; 1398 return;
1397 if (IsUseZoomForDSFEnabled()) 1399 if (IsUseZoomForDSFEnabled())
1398 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); 1400 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
1399 else 1401 else
1400 compositor_->setDeviceScaleFactor(device_scale_factor_); 1402 compositor_->setDeviceScaleFactor(device_scale_factor_);
1401 } 1403 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 void RenderWidget::showImeIfNeeded() { 1464 void RenderWidget::showImeIfNeeded() {
1463 OnShowImeIfNeeded(); 1465 OnShowImeIfNeeded();
1464 } 1466 }
1465 1467
1466 ui::TextInputType RenderWidget::GetTextInputType() { 1468 ui::TextInputType RenderWidget::GetTextInputType() {
1467 if (webwidget_) 1469 if (webwidget_)
1468 return WebKitToUiTextInputType(webwidget_->textInputType()); 1470 return WebKitToUiTextInputType(webwidget_->textInputType());
1469 return ui::TEXT_INPUT_TYPE_NONE; 1471 return ui::TEXT_INPUT_TYPE_NONE;
1470 } 1472 }
1471 1473
1472 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { 1474 void RenderWidget::UpdateCompositionInfo(
1475 bool should_update_range, bool force_update) {
1476 #if defined(OS_ANDROID)
1477 if (!monitor_composition_info_)
1478 return; // Do not calculate composition info if not requested.
1479 #endif // OS_ANDROID
1473 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); 1480 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1474 gfx::Range range = gfx::Range(); 1481 gfx::Range range = gfx::Range();
1475 if (should_update_range) { 1482 if (should_update_range) {
1476 GetCompositionRange(&range); 1483 GetCompositionRange(&range);
1477 } else { 1484 } else {
1478 range = composition_range_; 1485 range = composition_range_;
1479 } 1486 }
1480 std::vector<gfx::Rect> character_bounds; 1487 std::vector<gfx::Rect> character_bounds;
1481 GetCompositionCharacterBounds(&character_bounds); 1488 GetCompositionCharacterBounds(&character_bounds);
1482 1489
1483 if (!ShouldUpdateCompositionInfo(range, character_bounds)) 1490 if (!force_update && !ShouldUpdateCompositionInfo(range, character_bounds))
1484 return; 1491 return;
1485 composition_character_bounds_ = character_bounds; 1492 composition_character_bounds_ = character_bounds;
1486 composition_range_ = range; 1493 composition_range_ = range;
1487 Send(new InputHostMsg_ImeCompositionRangeChanged( 1494 Send(new InputHostMsg_ImeCompositionRangeChanged(
1488 routing_id(), composition_range_, composition_character_bounds_)); 1495 routing_id(), composition_range_, composition_character_bounds_));
1489 } 1496 }
1490 1497
1491 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { 1498 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1492 if (IsUseZoomForDSFEnabled()) { 1499 if (IsUseZoomForDSFEnabled()) {
1493 float reverse = 1 / GetOriginalDeviceScaleFactor(); 1500 float reverse = 1 / GetOriginalDeviceScaleFactor();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 void RenderWidget::OnImeEventAck() { 1538 void RenderWidget::OnImeEventAck() {
1532 DCHECK_GE(text_input_info_history_.size(), 1u); 1539 DCHECK_GE(text_input_info_history_.size(), 1u);
1533 text_input_info_history_.pop_front(); 1540 text_input_info_history_.pop_front();
1534 } 1541 }
1535 1542
1536 void RenderWidget::OnRequestTextInputStateUpdate() { 1543 void RenderWidget::OnRequestTextInputStateUpdate() {
1537 DCHECK(!ime_event_guard_); 1544 DCHECK(!ime_event_guard_);
1538 UpdateSelectionBounds(); 1545 UpdateSelectionBounds();
1539 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); 1546 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1540 } 1547 }
1548 void RenderWidget::OnRequestCursorUpdate(int mode) {
yosin_UTC9 2016/07/06 03:33:08 How about using two bool parameters to match with
Seigo Nonaka 2016/07/06 05:46:04 Sure, personally, enum is rarely used for this cas
1549 // See
1550 // https://developer.android.com/reference/android/view/inputmethod/InputConne ction.html
1551 const int CURSOR_UPDATE_IMMEDIATE = 1;
1552 const int CURSOR_UPDATE_MONITOR = 1 << 1;
1553
1554 if (mode & CURSOR_UPDATE_MONITOR)
yosin_UTC9 2016/07/06 03:33:08 How about monitor_composition_info_ = mode & CURSO
Seigo Nonaka 2016/07/06 05:46:04 You are right, but I moved this calculation to Jav
1555 monitor_composition_info_ = true;
1556 else
1557 monitor_composition_info_ = false;
1558
1559 if (mode & CURSOR_UPDATE_IMMEDIATE)
yosin_UTC9 2016/07/06 03:33:08 How about if (!(mode & CURSOR_UPDATE_IMMEDIATE)
Seigo Nonaka 2016/07/06 05:46:04 Hmm, introducing const boolean sounds overkill to
1560 UpdateCompositionInfo(true, true /* force update */);
1561 }
1541 #endif 1562 #endif
1542 1563
1543 bool RenderWidget::ShouldHandleImeEvent() { 1564 bool RenderWidget::ShouldHandleImeEvent() {
1544 #if defined(OS_ANDROID) 1565 #if defined(OS_ANDROID)
1545 if (!webwidget_) 1566 if (!webwidget_)
1546 return false; 1567 return false;
1547 if (IsUsingImeThread()) 1568 if (IsUsingImeThread())
1548 return true; 1569 return true;
1549 1570
1550 // We cannot handle IME events if there is any chance that the event we are 1571 // We cannot handle IME events if there is any chance that the event we are
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 if (selection_anchor_rect_ != params.anchor_rect || 1732 if (selection_anchor_rect_ != params.anchor_rect ||
1712 selection_focus_rect_ != params.focus_rect) { 1733 selection_focus_rect_ != params.focus_rect) {
1713 selection_anchor_rect_ = params.anchor_rect; 1734 selection_anchor_rect_ = params.anchor_rect;
1714 selection_focus_rect_ = params.focus_rect; 1735 selection_focus_rect_ = params.focus_rect;
1715 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); 1736 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1716 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); 1737 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1717 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); 1738 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1718 } 1739 }
1719 } 1740 }
1720 1741
1721 UpdateCompositionInfo(false); 1742 UpdateCompositionInfo(false, false /* force update */);
1722 } 1743 }
1723 1744
1724 void RenderWidget::SetDeviceColorProfileForTesting( 1745 void RenderWidget::SetDeviceColorProfileForTesting(
1725 const std::vector<char>& color_profile) { 1746 const std::vector<char>& color_profile) {
1726 SetDeviceColorProfile(color_profile); 1747 SetDeviceColorProfile(color_profile);
1727 } 1748 }
1728 1749
1729 void RenderWidget::ResetDeviceColorProfileForTesting() { 1750 void RenderWidget::ResetDeviceColorProfileForTesting() {
1730 std::vector<char> color_profile; 1751 std::vector<char> color_profile;
1731 color_profile.push_back('0'); 1752 color_profile.push_back('0');
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 ImeEventGuard guard(this); 1832 ImeEventGuard guard(this);
1812 // If the last text input type is not None, then we should finish any 1833 // If the last text input type is not None, then we should finish any
1813 // ongoing composition regardless of the new text input type. 1834 // ongoing composition regardless of the new text input type.
1814 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 1835 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
1815 // If a composition text exists, then we need to let the browser process 1836 // If a composition text exists, then we need to let the browser process
1816 // to cancel the input method's ongoing composition session. 1837 // to cancel the input method's ongoing composition session.
1817 if (webwidget_->confirmComposition()) 1838 if (webwidget_->confirmComposition())
1818 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1839 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1819 } 1840 }
1820 1841
1821 UpdateCompositionInfo(true); 1842 UpdateCompositionInfo(true, false /* force update */);
1822 } 1843 }
1823 1844
1824 #if defined(OS_ANDROID) 1845 #if defined(OS_ANDROID)
1825 void RenderWidget::showUnhandledTapUIIfNeeded( 1846 void RenderWidget::showUnhandledTapUIIfNeeded(
1826 const WebPoint& tapped_position, 1847 const WebPoint& tapped_position,
1827 const WebNode& tapped_node, 1848 const WebNode& tapped_node,
1828 bool page_changed) { 1849 bool page_changed) {
1829 DCHECK(input_handler_->handling_input_event()); 1850 DCHECK(input_handler_->handling_input_event());
1830 bool should_trigger = !page_changed && tapped_node.isTextNode() && 1851 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
1831 !tapped_node.isContentEditable() && 1852 !tapped_node.isContentEditable() &&
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 void RenderWidget::requestPointerUnlock() { 2000 void RenderWidget::requestPointerUnlock() {
1980 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); 2001 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
1981 } 2002 }
1982 2003
1983 bool RenderWidget::isPointerLocked() { 2004 bool RenderWidget::isPointerLocked() {
1984 return mouse_lock_dispatcher_->IsMouseLockedTo( 2005 return mouse_lock_dispatcher_->IsMouseLockedTo(
1985 webwidget_mouse_lock_target_.get()); 2006 webwidget_mouse_lock_target_.get());
1986 } 2007 }
1987 2008
1988 } // namespace content 2009 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698