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

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: skip composition calculation when the focused not is not editable. Created 4 years, 4 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 display_mode_(blink::WebDisplayModeUndefined), 239 display_mode_(blink::WebDisplayModeUndefined),
240 ime_event_guard_(nullptr), 240 ime_event_guard_(nullptr),
241 closing_(false), 241 closing_(false),
242 host_closing_(false), 242 host_closing_(false),
243 is_swapped_out_(swapped_out), 243 is_swapped_out_(swapped_out),
244 for_oopif_(false), 244 for_oopif_(false),
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 composition_range_(gfx::Range::InvalidRange()),
249 popup_type_(popup_type), 250 popup_type_(popup_type),
250 pending_window_rect_count_(0), 251 pending_window_rect_count_(0),
251 screen_info_(screen_info), 252 screen_info_(screen_info),
252 device_scale_factor_(screen_info_.deviceScaleFactor), 253 device_scale_factor_(screen_info_.deviceScaleFactor),
253 #if defined(OS_ANDROID) 254 #if defined(OS_ANDROID)
254 text_field_is_dirty_(false), 255 text_field_is_dirty_(false),
255 #endif 256 #endif
257 monitor_composition_info_(false),
256 popup_origin_scale_for_emulation_(0.f), 258 popup_origin_scale_for_emulation_(0.f),
257 frame_swap_message_queue_(new FrameSwapMessageQueue()), 259 frame_swap_message_queue_(new FrameSwapMessageQueue()),
258 resizing_mode_selector_(new ResizingModeSelector()), 260 resizing_mode_selector_(new ResizingModeSelector()),
259 has_host_context_menu_location_(false), 261 has_host_context_menu_location_(false),
260 has_focus_(false), 262 has_focus_(false),
261 focused_pepper_plugin_(nullptr) { 263 focused_pepper_plugin_(nullptr) {
262 if (!swapped_out) 264 if (!swapped_out)
263 RenderProcess::current()->AddRefProcess(); 265 RenderProcess::current()->AddRefProcess();
264 DCHECK(RenderThread::Get()); 266 DCHECK(RenderThread::Get());
265 device_color_profile_.push_back('0'); 267 device_color_profile_.push_back('0');
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) 493 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
492 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) 494 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
493 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) 495 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
494 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceClientId, OnSetSurfaceClientId) 496 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceClientId, OnSetSurfaceClientId)
495 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, 497 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
496 OnWaitNextFrameForTests) 498 OnWaitNextFrameForTests)
497 #if defined(OS_ANDROID) 499 #if defined(OS_ANDROID)
498 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) 500 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
499 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, 501 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
500 OnRequestTextInputStateUpdate) 502 OnRequestTextInputStateUpdate)
503 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
504 OnRequestCompositionUpdate)
501 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) 505 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
502 #endif 506 #endif
503 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) 507 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
504 IPC_MESSAGE_UNHANDLED(handled = false) 508 IPC_MESSAGE_UNHANDLED(handled = false)
505 IPC_END_MESSAGE_MAP() 509 IPC_END_MESSAGE_MAP()
506 return handled; 510 return handled;
507 } 511 }
508 512
509 bool RenderWidget::Send(IPC::Message* message) { 513 bool RenderWidget::Send(IPC::Message* message) {
510 // Don't send any messages after the browser has told us to close, and filter 514 // Don't send any messages after the browser has told us to close, and filter
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 if (ime_event_guard_) { 896 if (ime_event_guard_) {
893 // show_ime should still be effective even if it was set inside the IME 897 // show_ime should still be effective even if it was set inside the IME
894 // event guard. 898 // event guard.
895 if (show_ime == ShowIme::IF_NEEDED) { 899 if (show_ime == ShowIme::IF_NEEDED) {
896 ime_event_guard_->set_show_ime(true); 900 ime_event_guard_->set_show_ime(true);
897 } 901 }
898 return; 902 return;
899 } 903 }
900 904
901 ui::TextInputType new_type = GetTextInputType(); 905 ui::TextInputType new_type = GetTextInputType();
906 #if !defined(OS_ANDROID)
aelias_OOO_until_Jul13 2016/07/26 19:26:02 Sorry, I realize you're just following the convent
Seigo Nonaka 2016/07/28 09:10:59 Sure, for Mac OSX, it is not a monitor implementat
907 // Monitor the composition information during the focused node is text input
908 // node. On Android, monitor_composition_info_ is controlled by
909 // RequestCompositionUpdate message.
910 monitor_composition_info_ = new_type != ui::TEXT_INPUT_TYPE_NONE;
911 #endif
912
902 if (IsDateTimeInput(new_type)) 913 if (IsDateTimeInput(new_type))
903 return; // Not considered as a text input field in WebKit/Chromium. 914 return; // Not considered as a text input field in WebKit/Chromium.
904 915
905 blink::WebTextInputInfo new_info; 916 blink::WebTextInputInfo new_info;
906 if (webwidget_) 917 if (webwidget_)
907 new_info = webwidget_->textInputInfo(); 918 new_info = webwidget_->textInputInfo();
908 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); 919 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
909 920
910 bool new_can_compose_inline = CanComposeInline(); 921 bool new_can_compose_inline = CanComposeInline();
911 922
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 return; 1362 return;
1352 ImeEventGuard guard(this); 1363 ImeEventGuard guard(this);
1353 if (!webwidget_->setComposition( 1364 if (!webwidget_->setComposition(
1354 text, WebVector<WebCompositionUnderline>(underlines), 1365 text, WebVector<WebCompositionUnderline>(underlines),
1355 selection_start, selection_end)) { 1366 selection_start, selection_end)) {
1356 // If we failed to set the composition text, then we need to let the browser 1367 // If we failed to set the composition text, then we need to let the browser
1357 // process to cancel the input method's ongoing composition session, to make 1368 // process to cancel the input method's ongoing composition session, to make
1358 // sure we are in a consistent state. 1369 // sure we are in a consistent state.
1359 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1370 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1360 } 1371 }
1361 UpdateCompositionInfo(true); 1372 UpdateCompositionInfo(false /* not an immediate request */);
1362 } 1373 }
1363 1374
1364 void RenderWidget::OnImeConfirmComposition(const base::string16& text, 1375 void RenderWidget::OnImeConfirmComposition(const base::string16& text,
1365 const gfx::Range& replacement_range, 1376 const gfx::Range& replacement_range,
1366 bool keep_selection) { 1377 bool keep_selection) {
1367 #if defined(ENABLE_PLUGINS) 1378 #if defined(ENABLE_PLUGINS)
1368 if (focused_pepper_plugin_) { 1379 if (focused_pepper_plugin_) {
1369 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( 1380 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition(
1370 text, replacement_range, keep_selection); 1381 text, replacement_range, keep_selection);
1371 return; 1382 return;
1372 } 1383 }
1373 #endif 1384 #endif
1374 if (replacement_range.IsValid()) { 1385 if (replacement_range.IsValid()) {
1375 webwidget_->applyReplacementRange(replacement_range.start(), 1386 webwidget_->applyReplacementRange(replacement_range.start(),
1376 replacement_range.length()); 1387 replacement_range.length());
1377 } 1388 }
1378 1389
1379 if (!ShouldHandleImeEvent()) 1390 if (!ShouldHandleImeEvent())
1380 return; 1391 return;
1381 ImeEventGuard guard(this); 1392 ImeEventGuard guard(this);
1382 input_handler_->set_handling_input_event(true); 1393 input_handler_->set_handling_input_event(true);
1383 if (text.length()) 1394 if (text.length())
1384 webwidget_->confirmComposition(text); 1395 webwidget_->confirmComposition(text);
1385 else if (keep_selection) 1396 else if (keep_selection)
1386 webwidget_->confirmComposition(WebWidget::KeepSelection); 1397 webwidget_->confirmComposition(WebWidget::KeepSelection);
1387 else 1398 else
1388 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); 1399 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
1389 input_handler_->set_handling_input_event(false); 1400 input_handler_->set_handling_input_event(false);
1390 UpdateCompositionInfo(true); 1401 UpdateCompositionInfo(false /* not an immediate request */);
1391 } 1402 }
1392 1403
1393 void RenderWidget::OnDeviceScaleFactorChanged() { 1404 void RenderWidget::OnDeviceScaleFactorChanged() {
1394 if (!compositor_) 1405 if (!compositor_)
1395 return; 1406 return;
1396 if (IsUseZoomForDSFEnabled()) 1407 if (IsUseZoomForDSFEnabled())
1397 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); 1408 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
1398 else 1409 else
1399 compositor_->setDeviceScaleFactor(device_scale_factor_); 1410 compositor_->setDeviceScaleFactor(device_scale_factor_);
1400 } 1411 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 ui::TextInputType RenderWidget::GetTextInputType() { 1476 ui::TextInputType RenderWidget::GetTextInputType() {
1466 #if defined(ENABLE_PLUGINS) 1477 #if defined(ENABLE_PLUGINS)
1467 if (focused_pepper_plugin_) 1478 if (focused_pepper_plugin_)
1468 return focused_pepper_plugin_->text_input_type(); 1479 return focused_pepper_plugin_->text_input_type();
1469 #endif 1480 #endif
1470 if (webwidget_) 1481 if (webwidget_)
1471 return WebKitToUiTextInputType(webwidget_->textInputType()); 1482 return WebKitToUiTextInputType(webwidget_->textInputType());
1472 return ui::TEXT_INPUT_TYPE_NONE; 1483 return ui::TEXT_INPUT_TYPE_NONE;
1473 } 1484 }
1474 1485
1475 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { 1486 void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1487 if (!monitor_composition_info_ && !immediate_request)
1488 return; // Do not calculate composition info if not requested.
1489
1476 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); 1490 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1477 gfx::Range range = gfx::Range(); 1491 gfx::Range range;
1478 if (should_update_range) { 1492 std::vector<gfx::Rect> character_bounds;
1493
1494 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1495 // Composition information is only available on editable node.
1496 range = gfx::Range::InvalidRange();
1497 } else {
1479 GetCompositionRange(&range); 1498 GetCompositionRange(&range);
1480 } else { 1499 GetCompositionCharacterBounds(&character_bounds);
1481 range = composition_range_;
1482 } 1500 }
1483 std::vector<gfx::Rect> character_bounds;
1484 GetCompositionCharacterBounds(&character_bounds);
1485 1501
1486 if (!ShouldUpdateCompositionInfo(range, character_bounds)) 1502 if (!immediate_request &&
1503 !ShouldUpdateCompositionInfo(range, character_bounds)) {
1487 return; 1504 return;
1505 }
1488 composition_character_bounds_ = character_bounds; 1506 composition_character_bounds_ = character_bounds;
1489 composition_range_ = range; 1507 composition_range_ = range;
1490 Send(new InputHostMsg_ImeCompositionRangeChanged( 1508 Send(new InputHostMsg_ImeCompositionRangeChanged(
1491 routing_id(), composition_range_, composition_character_bounds_)); 1509 routing_id(), composition_range_, composition_character_bounds_));
1492 } 1510 }
1493 1511
1494 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { 1512 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1495 if (IsUseZoomForDSFEnabled()) { 1513 if (IsUseZoomForDSFEnabled()) {
1496 float reverse = 1 / GetOriginalDeviceScaleFactor(); 1514 float reverse = 1 / GetOriginalDeviceScaleFactor();
1497 // TODO(oshima): We may need to allow pixel precision here as the the 1515 // TODO(oshima): We may need to allow pixel precision here as the the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 void RenderWidget::OnImeEventAck() { 1552 void RenderWidget::OnImeEventAck() {
1535 DCHECK_GE(text_input_info_history_.size(), 1u); 1553 DCHECK_GE(text_input_info_history_.size(), 1u);
1536 text_input_info_history_.pop_front(); 1554 text_input_info_history_.pop_front();
1537 } 1555 }
1538 1556
1539 void RenderWidget::OnRequestTextInputStateUpdate() { 1557 void RenderWidget::OnRequestTextInputStateUpdate() {
1540 DCHECK(!ime_event_guard_); 1558 DCHECK(!ime_event_guard_);
1541 UpdateSelectionBounds(); 1559 UpdateSelectionBounds();
1542 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); 1560 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1543 } 1561 }
1562
1563 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1564 bool monitor_request) {
1565 monitor_composition_info_ = monitor_request;
1566 if (!immediate_request)
1567 return;
1568 UpdateCompositionInfo(true /* immediate request */);
1569 }
1544 #endif 1570 #endif
1545 1571
1546 bool RenderWidget::ShouldHandleImeEvent() { 1572 bool RenderWidget::ShouldHandleImeEvent() {
1547 #if defined(OS_ANDROID) 1573 #if defined(OS_ANDROID)
1548 if (!webwidget_) 1574 if (!webwidget_)
1549 return false; 1575 return false;
1550 if (IsUsingImeThread()) 1576 if (IsUsingImeThread())
1551 return true; 1577 return true;
1552 1578
1553 // We cannot handle IME events if there is any chance that the event we are 1579 // We cannot handle IME events if there is any chance that the event we are
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 if (selection_anchor_rect_ != params.anchor_rect || 1753 if (selection_anchor_rect_ != params.anchor_rect ||
1728 selection_focus_rect_ != params.focus_rect) { 1754 selection_focus_rect_ != params.focus_rect) {
1729 selection_anchor_rect_ = params.anchor_rect; 1755 selection_anchor_rect_ = params.anchor_rect;
1730 selection_focus_rect_ = params.focus_rect; 1756 selection_focus_rect_ = params.focus_rect;
1731 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); 1757 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1732 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); 1758 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1733 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); 1759 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1734 } 1760 }
1735 } 1761 }
1736 1762
1737 UpdateCompositionInfo(false); 1763 UpdateCompositionInfo(false /* not an immediate request */);
1738 } 1764 }
1739 1765
1740 void RenderWidget::SetDeviceColorProfileForTesting( 1766 void RenderWidget::SetDeviceColorProfileForTesting(
1741 const std::vector<char>& color_profile) { 1767 const std::vector<char>& color_profile) {
1742 SetDeviceColorProfile(color_profile); 1768 SetDeviceColorProfile(color_profile);
1743 } 1769 }
1744 1770
1745 void RenderWidget::ResetDeviceColorProfileForTesting() { 1771 void RenderWidget::ResetDeviceColorProfileForTesting() {
1746 std::vector<char> color_profile; 1772 std::vector<char> color_profile;
1747 color_profile.push_back('0'); 1773 color_profile.push_back('0');
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1872 ImeEventGuard guard(this); 1898 ImeEventGuard guard(this);
1873 // If the last text input type is not None, then we should finish any 1899 // If the last text input type is not None, then we should finish any
1874 // ongoing composition regardless of the new text input type. 1900 // ongoing composition regardless of the new text input type.
1875 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 1901 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
1876 // If a composition text exists, then we need to let the browser process 1902 // If a composition text exists, then we need to let the browser process
1877 // to cancel the input method's ongoing composition session. 1903 // to cancel the input method's ongoing composition session.
1878 if (webwidget_->confirmComposition()) 1904 if (webwidget_->confirmComposition())
1879 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1905 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1880 } 1906 }
1881 1907
1882 UpdateCompositionInfo(true); 1908 UpdateCompositionInfo(false /* not an immediate request */);
1883 } 1909 }
1884 1910
1885 #if defined(OS_ANDROID) 1911 #if defined(OS_ANDROID)
1886 void RenderWidget::showUnhandledTapUIIfNeeded( 1912 void RenderWidget::showUnhandledTapUIIfNeeded(
1887 const WebPoint& tapped_position, 1913 const WebPoint& tapped_position,
1888 const WebNode& tapped_node, 1914 const WebNode& tapped_node,
1889 bool page_changed) { 1915 bool page_changed) {
1890 DCHECK(input_handler_->handling_input_event()); 1916 DCHECK(input_handler_->handling_input_event());
1891 bool should_trigger = !page_changed && tapped_node.isTextNode() && 1917 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
1892 !tapped_node.isContentEditable() && 1918 !tapped_node.isContentEditable() &&
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 void RenderWidget::requestPointerUnlock() { 2066 void RenderWidget::requestPointerUnlock() {
2041 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); 2067 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2042 } 2068 }
2043 2069
2044 bool RenderWidget::isPointerLocked() { 2070 bool RenderWidget::isPointerLocked() {
2045 return mouse_lock_dispatcher_->IsMouseLockedTo( 2071 return mouse_lock_dispatcher_->IsMouseLockedTo(
2046 webwidget_mouse_lock_target_.get()); 2072 webwidget_mouse_lock_target_.get());
2047 } 2073 }
2048 2074
2049 } // namespace content 2075 } // 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