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

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: remove OS_ANDROID from render_widget.cc 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
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
501 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) 503 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
502 #endif 504 #endif
505 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
506 OnRequestCompositionUpdate)
nasko 2016/07/29 16:26:10 nit: This should move before the #if defined(OS_AN
Seigo Nonaka 2016/08/01 02:27:35 Done.
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
511 // most outgoing messages while swapped out. 515 // most outgoing messages while swapped out.
512 if ((is_swapped_out_ && 516 if ((is_swapped_out_ &&
(...skipping 379 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
nasko 2016/07/29 16:26:10 Was this new empty line intentional?
Seigo Nonaka 2016/08/01 02:27:35 No, removed.
902 if (IsDateTimeInput(new_type)) 907 if (IsDateTimeInput(new_type))
903 return; // Not considered as a text input field in WebKit/Chromium. 908 return; // Not considered as a text input field in WebKit/Chromium.
904 909
905 blink::WebTextInputInfo new_info; 910 blink::WebTextInputInfo new_info;
906 if (webwidget_) 911 if (webwidget_)
907 new_info = webwidget_->textInputInfo(); 912 new_info = webwidget_->textInputInfo();
908 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); 913 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
909 914
910 bool new_can_compose_inline = CanComposeInline(); 915 bool new_can_compose_inline = CanComposeInline();
911 916
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 return; 1356 return;
1352 ImeEventGuard guard(this); 1357 ImeEventGuard guard(this);
1353 if (!webwidget_->setComposition( 1358 if (!webwidget_->setComposition(
1354 text, WebVector<WebCompositionUnderline>(underlines), 1359 text, WebVector<WebCompositionUnderline>(underlines),
1355 selection_start, selection_end)) { 1360 selection_start, selection_end)) {
1356 // If we failed to set the composition text, then we need to let the browser 1361 // 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 1362 // process to cancel the input method's ongoing composition session, to make
1358 // sure we are in a consistent state. 1363 // sure we are in a consistent state.
1359 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1364 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1360 } 1365 }
1361 UpdateCompositionInfo(true); 1366 UpdateCompositionInfo(false /* not an immediate request */);
1362 } 1367 }
1363 1368
1364 void RenderWidget::OnImeConfirmComposition(const base::string16& text, 1369 void RenderWidget::OnImeConfirmComposition(const base::string16& text,
1365 const gfx::Range& replacement_range, 1370 const gfx::Range& replacement_range,
1366 bool keep_selection) { 1371 bool keep_selection) {
1367 #if defined(ENABLE_PLUGINS) 1372 #if defined(ENABLE_PLUGINS)
1368 if (focused_pepper_plugin_) { 1373 if (focused_pepper_plugin_) {
1369 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( 1374 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition(
1370 text, replacement_range, keep_selection); 1375 text, replacement_range, keep_selection);
1371 return; 1376 return;
1372 } 1377 }
1373 #endif 1378 #endif
1374 if (replacement_range.IsValid()) { 1379 if (replacement_range.IsValid()) {
1375 webwidget_->applyReplacementRange(replacement_range.start(), 1380 webwidget_->applyReplacementRange(replacement_range.start(),
1376 replacement_range.length()); 1381 replacement_range.length());
1377 } 1382 }
1378 1383
1379 if (!ShouldHandleImeEvent()) 1384 if (!ShouldHandleImeEvent())
1380 return; 1385 return;
1381 ImeEventGuard guard(this); 1386 ImeEventGuard guard(this);
1382 input_handler_->set_handling_input_event(true); 1387 input_handler_->set_handling_input_event(true);
1383 if (text.length()) 1388 if (text.length())
1384 webwidget_->confirmComposition(text); 1389 webwidget_->confirmComposition(text);
1385 else if (keep_selection) 1390 else if (keep_selection)
1386 webwidget_->confirmComposition(WebWidget::KeepSelection); 1391 webwidget_->confirmComposition(WebWidget::KeepSelection);
1387 else 1392 else
1388 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); 1393 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
1389 input_handler_->set_handling_input_event(false); 1394 input_handler_->set_handling_input_event(false);
1390 UpdateCompositionInfo(true); 1395 UpdateCompositionInfo(false /* not an immediate request */);
1391 } 1396 }
1392 1397
1393 void RenderWidget::OnDeviceScaleFactorChanged() { 1398 void RenderWidget::OnDeviceScaleFactorChanged() {
1394 if (!compositor_) 1399 if (!compositor_)
1395 return; 1400 return;
1396 if (IsUseZoomForDSFEnabled()) 1401 if (IsUseZoomForDSFEnabled())
1397 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); 1402 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
1398 else 1403 else
1399 compositor_->setDeviceScaleFactor(device_scale_factor_); 1404 compositor_->setDeviceScaleFactor(device_scale_factor_);
1400 } 1405 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 ui::TextInputType RenderWidget::GetTextInputType() { 1470 ui::TextInputType RenderWidget::GetTextInputType() {
1466 #if defined(ENABLE_PLUGINS) 1471 #if defined(ENABLE_PLUGINS)
1467 if (focused_pepper_plugin_) 1472 if (focused_pepper_plugin_)
1468 return focused_pepper_plugin_->text_input_type(); 1473 return focused_pepper_plugin_->text_input_type();
1469 #endif 1474 #endif
1470 if (webwidget_) 1475 if (webwidget_)
1471 return WebKitToUiTextInputType(webwidget_->textInputType()); 1476 return WebKitToUiTextInputType(webwidget_->textInputType());
1472 return ui::TEXT_INPUT_TYPE_NONE; 1477 return ui::TEXT_INPUT_TYPE_NONE;
1473 } 1478 }
1474 1479
1475 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { 1480 void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1481 if (!monitor_composition_info_ && !immediate_request)
1482 return; // Do not calculate composition info if not requested.
1483
1476 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); 1484 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1477 gfx::Range range = gfx::Range(); 1485 gfx::Range range;
1478 if (should_update_range) { 1486 std::vector<gfx::Rect> character_bounds;
1487
1488 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1489 // Composition information is only available on editable node.
1490 range = gfx::Range::InvalidRange();
1491 } else {
1479 GetCompositionRange(&range); 1492 GetCompositionRange(&range);
1480 } else { 1493 GetCompositionCharacterBounds(&character_bounds);
1481 range = composition_range_;
1482 } 1494 }
1483 std::vector<gfx::Rect> character_bounds;
1484 GetCompositionCharacterBounds(&character_bounds);
1485 1495
1486 if (!ShouldUpdateCompositionInfo(range, character_bounds)) 1496 if (!immediate_request &&
1497 !ShouldUpdateCompositionInfo(range, character_bounds)) {
1487 return; 1498 return;
1499 }
1488 composition_character_bounds_ = character_bounds; 1500 composition_character_bounds_ = character_bounds;
1489 composition_range_ = range; 1501 composition_range_ = range;
1490 Send(new InputHostMsg_ImeCompositionRangeChanged( 1502 Send(new InputHostMsg_ImeCompositionRangeChanged(
1491 routing_id(), composition_range_, composition_character_bounds_)); 1503 routing_id(), composition_range_, composition_character_bounds_));
1492 } 1504 }
1493 1505
1494 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { 1506 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1495 if (IsUseZoomForDSFEnabled()) { 1507 if (IsUseZoomForDSFEnabled()) {
1496 float reverse = 1 / GetOriginalDeviceScaleFactor(); 1508 float reverse = 1 / GetOriginalDeviceScaleFactor();
1497 // TODO(oshima): We may need to allow pixel precision here as the the 1509 // TODO(oshima): We may need to allow pixel precision here as the the
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 text_input_info_history_.pop_front(); 1548 text_input_info_history_.pop_front();
1537 } 1549 }
1538 1550
1539 void RenderWidget::OnRequestTextInputStateUpdate() { 1551 void RenderWidget::OnRequestTextInputStateUpdate() {
1540 DCHECK(!ime_event_guard_); 1552 DCHECK(!ime_event_guard_);
1541 UpdateSelectionBounds(); 1553 UpdateSelectionBounds();
1542 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); 1554 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1543 } 1555 }
1544 #endif 1556 #endif
1545 1557
1558 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1559 bool monitor_request) {
1560 monitor_composition_info_ = monitor_request;
1561 if (!immediate_request)
1562 return;
1563 UpdateCompositionInfo(true /* immediate request */);
1564 }
1565
1546 bool RenderWidget::ShouldHandleImeEvent() { 1566 bool RenderWidget::ShouldHandleImeEvent() {
1547 #if defined(OS_ANDROID) 1567 #if defined(OS_ANDROID)
1548 if (!webwidget_) 1568 if (!webwidget_)
1549 return false; 1569 return false;
1550 if (IsUsingImeThread()) 1570 if (IsUsingImeThread())
1551 return true; 1571 return true;
1552 1572
1553 // We cannot handle IME events if there is any chance that the event we are 1573 // We cannot handle IME events if there is any chance that the event we are
1554 // receiving here from the browser is based on the state that is different 1574 // receiving here from the browser is based on the state that is different
1555 // from our current one as indicated by |text_input_info_|. 1575 // from our current one as indicated by |text_input_info_|.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 if (selection_anchor_rect_ != params.anchor_rect || 1747 if (selection_anchor_rect_ != params.anchor_rect ||
1728 selection_focus_rect_ != params.focus_rect) { 1748 selection_focus_rect_ != params.focus_rect) {
1729 selection_anchor_rect_ = params.anchor_rect; 1749 selection_anchor_rect_ = params.anchor_rect;
1730 selection_focus_rect_ = params.focus_rect; 1750 selection_focus_rect_ = params.focus_rect;
1731 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); 1751 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1732 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); 1752 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1733 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); 1753 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1734 } 1754 }
1735 } 1755 }
1736 1756
1737 UpdateCompositionInfo(false); 1757 UpdateCompositionInfo(false /* not an immediate request */);
1738 } 1758 }
1739 1759
1740 void RenderWidget::SetDeviceColorProfileForTesting( 1760 void RenderWidget::SetDeviceColorProfileForTesting(
1741 const std::vector<char>& color_profile) { 1761 const std::vector<char>& color_profile) {
1742 SetDeviceColorProfile(color_profile); 1762 SetDeviceColorProfile(color_profile);
1743 } 1763 }
1744 1764
1745 void RenderWidget::ResetDeviceColorProfileForTesting() { 1765 void RenderWidget::ResetDeviceColorProfileForTesting() {
1746 std::vector<char> color_profile; 1766 std::vector<char> color_profile;
1747 color_profile.push_back('0'); 1767 color_profile.push_back('0');
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1872 ImeEventGuard guard(this); 1892 ImeEventGuard guard(this);
1873 // If the last text input type is not None, then we should finish any 1893 // If the last text input type is not None, then we should finish any
1874 // ongoing composition regardless of the new text input type. 1894 // ongoing composition regardless of the new text input type.
1875 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { 1895 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
1876 // If a composition text exists, then we need to let the browser process 1896 // If a composition text exists, then we need to let the browser process
1877 // to cancel the input method's ongoing composition session. 1897 // to cancel the input method's ongoing composition session.
1878 if (webwidget_->confirmComposition()) 1898 if (webwidget_->confirmComposition())
1879 Send(new InputHostMsg_ImeCancelComposition(routing_id())); 1899 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1880 } 1900 }
1881 1901
1882 UpdateCompositionInfo(true); 1902 UpdateCompositionInfo(false /* not an immediate request */);
1883 } 1903 }
1884 1904
1885 #if defined(OS_ANDROID) 1905 #if defined(OS_ANDROID)
1886 void RenderWidget::showUnhandledTapUIIfNeeded( 1906 void RenderWidget::showUnhandledTapUIIfNeeded(
1887 const WebPoint& tapped_position, 1907 const WebPoint& tapped_position,
1888 const WebNode& tapped_node, 1908 const WebNode& tapped_node,
1889 bool page_changed) { 1909 bool page_changed) {
1890 DCHECK(input_handler_->handling_input_event()); 1910 DCHECK(input_handler_->handling_input_event());
1891 bool should_trigger = !page_changed && tapped_node.isTextNode() && 1911 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
1892 !tapped_node.isContentEditable() && 1912 !tapped_node.isContentEditable() &&
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 void RenderWidget::requestPointerUnlock() { 2060 void RenderWidget::requestPointerUnlock() {
2041 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); 2061 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2042 } 2062 }
2043 2063
2044 bool RenderWidget::isPointerLocked() { 2064 bool RenderWidget::isPointerLocked() {
2045 return mouse_lock_dispatcher_->IsMouseLockedTo( 2065 return mouse_lock_dispatcher_->IsMouseLockedTo(
2046 webwidget_mouse_lock_target_.get()); 2066 webwidget_mouse_lock_target_.get());
2047 } 2067 }
2048 2068
2049 } // namespace content 2069 } // namespace content
OLDNEW
« content/browser/renderer_host/ime_adapter_android.cc ('K') | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698