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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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), | |
aelias_OOO_until_Jul13
2016/07/07 00:13:35
Please move this out of OS_ANDROID, as I don't see
Seigo Nonaka
2016/07/07 13:38:26
I don't have strong opinion to this, but this flag
aelias_OOO_until_Jul13
2016/07/07 21:15:41
Well, I think this file in general greatly overuse
| |
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 Loading... | |
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_RequestCompositionUpdate, | |
502 OnRequestCompositionUpdate) | |
500 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) | 503 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) |
501 #endif | 504 #endif |
502 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) | 505 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) |
503 IPC_MESSAGE_UNHANDLED(handled = false) | 506 IPC_MESSAGE_UNHANDLED(handled = false) |
504 IPC_END_MESSAGE_MAP() | 507 IPC_END_MESSAGE_MAP() |
505 return handled; | 508 return handled; |
506 } | 509 } |
507 | 510 |
508 bool RenderWidget::Send(IPC::Message* message) { | 511 bool RenderWidget::Send(IPC::Message* message) { |
509 // Don't send any messages after the browser has told us to close, and filter | 512 // 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 Loading... | |
1364 return; | 1367 return; |
1365 ImeEventGuard guard(this); | 1368 ImeEventGuard guard(this); |
1366 if (!webwidget_->setComposition( | 1369 if (!webwidget_->setComposition( |
1367 text, WebVector<WebCompositionUnderline>(underlines), | 1370 text, WebVector<WebCompositionUnderline>(underlines), |
1368 selection_start, selection_end)) { | 1371 selection_start, selection_end)) { |
1369 // If we failed to set the composition text, then we need to let the browser | 1372 // 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 | 1373 // process to cancel the input method's ongoing composition session, to make |
1371 // sure we are in a consistent state. | 1374 // sure we are in a consistent state. |
1372 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1375 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1373 } | 1376 } |
1374 UpdateCompositionInfo(true); | 1377 UpdateCompositionInfo(true /* update composition range */, |
1378 false /* force update */); | |
1375 } | 1379 } |
1376 | 1380 |
1377 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1381 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
1378 const gfx::Range& replacement_range, | 1382 const gfx::Range& replacement_range, |
1379 bool keep_selection) { | 1383 bool keep_selection) { |
1380 if (!ShouldHandleImeEvent()) | 1384 if (!ShouldHandleImeEvent()) |
1381 return; | 1385 return; |
1382 ImeEventGuard guard(this); | 1386 ImeEventGuard guard(this); |
1383 input_handler_->set_handling_input_event(true); | 1387 input_handler_->set_handling_input_event(true); |
1384 if (text.length()) | 1388 if (text.length()) |
1385 webwidget_->confirmComposition(text); | 1389 webwidget_->confirmComposition(text); |
1386 else if (keep_selection) | 1390 else if (keep_selection) |
1387 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1391 webwidget_->confirmComposition(WebWidget::KeepSelection); |
1388 else | 1392 else |
1389 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1393 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
1390 input_handler_->set_handling_input_event(false); | 1394 input_handler_->set_handling_input_event(false); |
1391 UpdateCompositionInfo(true); | 1395 UpdateCompositionInfo(true /* update composition range */, |
1396 false /* force update */); | |
1392 } | 1397 } |
1393 | 1398 |
1394 void RenderWidget::OnDeviceScaleFactorChanged() { | 1399 void RenderWidget::OnDeviceScaleFactorChanged() { |
1395 if (!compositor_) | 1400 if (!compositor_) |
1396 return; | 1401 return; |
1397 if (IsUseZoomForDSFEnabled()) | 1402 if (IsUseZoomForDSFEnabled()) |
1398 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); | 1403 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); |
1399 else | 1404 else |
1400 compositor_->setDeviceScaleFactor(device_scale_factor_); | 1405 compositor_->setDeviceScaleFactor(device_scale_factor_); |
1401 } | 1406 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 void RenderWidget::showImeIfNeeded() { | 1467 void RenderWidget::showImeIfNeeded() { |
1463 OnShowImeIfNeeded(); | 1468 OnShowImeIfNeeded(); |
1464 } | 1469 } |
1465 | 1470 |
1466 ui::TextInputType RenderWidget::GetTextInputType() { | 1471 ui::TextInputType RenderWidget::GetTextInputType() { |
1467 if (webwidget_) | 1472 if (webwidget_) |
1468 return WebKitToUiTextInputType(webwidget_->textInputType()); | 1473 return WebKitToUiTextInputType(webwidget_->textInputType()); |
1469 return ui::TEXT_INPUT_TYPE_NONE; | 1474 return ui::TEXT_INPUT_TYPE_NONE; |
1470 } | 1475 } |
1471 | 1476 |
1472 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { | 1477 void RenderWidget::UpdateCompositionInfo( |
1478 bool should_update_range, bool force_update) { | |
aelias_OOO_until_Jul13
2016/07/07 00:13:36
Could you rename "force_update" to "immediate_requ
Seigo Nonaka
2016/07/07 13:38:26
Done.
| |
1479 #if defined(OS_ANDROID) | |
1480 if (!monitor_composition_info_) | |
1481 return; // Do not calculate composition info if not requested. | |
aelias_OOO_until_Jul13
2016/07/07 00:13:36
I don't think it's correct to early-exit here if "
Seigo Nonaka
2016/07/07 13:38:26
Good catch! Yes, you are right!
Fixed. Thank you.
aelias_OOO_until_Jul13
2016/07/07 21:15:41
Hmm, I'm concerned that no trybot caught this bug.
Seigo Nonaka
2016/07/13 07:12:07
Sure added into ImeLolipopTest.java
| |
1482 #endif // OS_ANDROID | |
1473 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); | 1483 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
1474 gfx::Range range = gfx::Range(); | 1484 gfx::Range range = gfx::Range(); |
1475 if (should_update_range) { | 1485 if (should_update_range) { |
1476 GetCompositionRange(&range); | 1486 GetCompositionRange(&range); |
1477 } else { | 1487 } else { |
1478 range = composition_range_; | 1488 range = composition_range_; |
1479 } | 1489 } |
1480 std::vector<gfx::Rect> character_bounds; | 1490 std::vector<gfx::Rect> character_bounds; |
1481 GetCompositionCharacterBounds(&character_bounds); | 1491 GetCompositionCharacterBounds(&character_bounds); |
1482 | 1492 |
1483 if (!ShouldUpdateCompositionInfo(range, character_bounds)) | 1493 if (!force_update && !ShouldUpdateCompositionInfo(range, character_bounds)) |
1484 return; | 1494 return; |
1485 composition_character_bounds_ = character_bounds; | 1495 composition_character_bounds_ = character_bounds; |
1486 composition_range_ = range; | 1496 composition_range_ = range; |
1487 Send(new InputHostMsg_ImeCompositionRangeChanged( | 1497 Send(new InputHostMsg_ImeCompositionRangeChanged( |
1488 routing_id(), composition_range_, composition_character_bounds_)); | 1498 routing_id(), composition_range_, composition_character_bounds_)); |
1489 } | 1499 } |
1490 | 1500 |
1491 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { | 1501 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { |
1492 if (IsUseZoomForDSFEnabled()) { | 1502 if (IsUseZoomForDSFEnabled()) { |
1493 float reverse = 1 / GetOriginalDeviceScaleFactor(); | 1503 float reverse = 1 / GetOriginalDeviceScaleFactor(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1531 void RenderWidget::OnImeEventAck() { | 1541 void RenderWidget::OnImeEventAck() { |
1532 DCHECK_GE(text_input_info_history_.size(), 1u); | 1542 DCHECK_GE(text_input_info_history_.size(), 1u); |
1533 text_input_info_history_.pop_front(); | 1543 text_input_info_history_.pop_front(); |
1534 } | 1544 } |
1535 | 1545 |
1536 void RenderWidget::OnRequestTextInputStateUpdate() { | 1546 void RenderWidget::OnRequestTextInputStateUpdate() { |
1537 DCHECK(!ime_event_guard_); | 1547 DCHECK(!ime_event_guard_); |
1538 UpdateSelectionBounds(); | 1548 UpdateSelectionBounds(); |
1539 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); | 1549 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); |
1540 } | 1550 } |
1551 | |
1552 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request, | |
1553 bool monitor_request) { | |
1554 monitor_composition_info_ = monitor_request; | |
1555 if (!immediate_request) | |
1556 return; | |
1557 UpdateCompositionInfo(true /* update composition range */, | |
1558 true /* force update */); | |
1559 } | |
1541 #endif | 1560 #endif |
1542 | 1561 |
1543 bool RenderWidget::ShouldHandleImeEvent() { | 1562 bool RenderWidget::ShouldHandleImeEvent() { |
1544 #if defined(OS_ANDROID) | 1563 #if defined(OS_ANDROID) |
1545 if (!webwidget_) | 1564 if (!webwidget_) |
1546 return false; | 1565 return false; |
1547 if (IsUsingImeThread()) | 1566 if (IsUsingImeThread()) |
1548 return true; | 1567 return true; |
1549 | 1568 |
1550 // We cannot handle IME events if there is any chance that the event we are | 1569 // 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 Loading... | |
1711 if (selection_anchor_rect_ != params.anchor_rect || | 1730 if (selection_anchor_rect_ != params.anchor_rect || |
1712 selection_focus_rect_ != params.focus_rect) { | 1731 selection_focus_rect_ != params.focus_rect) { |
1713 selection_anchor_rect_ = params.anchor_rect; | 1732 selection_anchor_rect_ = params.anchor_rect; |
1714 selection_focus_rect_ = params.focus_rect; | 1733 selection_focus_rect_ = params.focus_rect; |
1715 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); | 1734 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); |
1716 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); | 1735 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); |
1717 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); | 1736 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); |
1718 } | 1737 } |
1719 } | 1738 } |
1720 | 1739 |
1721 UpdateCompositionInfo(false); | 1740 UpdateCompositionInfo(false /* update composition range */, |
aelias_OOO_until_Jul13
2016/07/07 00:13:35
This scenario of setting update_range to false whe
Seigo Nonaka
2016/07/07 13:38:26
SelectionBoundsChanged is called when the bounding
aelias_OOO_until_Jul13
2016/07/07 21:15:41
So the caching is a pure performance optimization?
Seigo Nonaka
2016/07/13 07:12:07
Sure, I'm happy to remove this flag, but can I do
aelias_OOO_until_Jul13
2016/07/15 01:58:48
I'd ask you to do it as part this CL; the risk of
Seigo Nonaka
2016/07/20 05:42:12
Sure, finally I could make all test passing with r
| |
1741 false /* force update */); | |
1722 } | 1742 } |
1723 | 1743 |
1724 void RenderWidget::SetDeviceColorProfileForTesting( | 1744 void RenderWidget::SetDeviceColorProfileForTesting( |
1725 const std::vector<char>& color_profile) { | 1745 const std::vector<char>& color_profile) { |
1726 SetDeviceColorProfile(color_profile); | 1746 SetDeviceColorProfile(color_profile); |
1727 } | 1747 } |
1728 | 1748 |
1729 void RenderWidget::ResetDeviceColorProfileForTesting() { | 1749 void RenderWidget::ResetDeviceColorProfileForTesting() { |
1730 std::vector<char> color_profile; | 1750 std::vector<char> color_profile; |
1731 color_profile.push_back('0'); | 1751 color_profile.push_back('0'); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1811 ImeEventGuard guard(this); | 1831 ImeEventGuard guard(this); |
1812 // If the last text input type is not None, then we should finish any | 1832 // If the last text input type is not None, then we should finish any |
1813 // ongoing composition regardless of the new text input type. | 1833 // ongoing composition regardless of the new text input type. |
1814 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { | 1834 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
1815 // If a composition text exists, then we need to let the browser process | 1835 // If a composition text exists, then we need to let the browser process |
1816 // to cancel the input method's ongoing composition session. | 1836 // to cancel the input method's ongoing composition session. |
1817 if (webwidget_->confirmComposition()) | 1837 if (webwidget_->confirmComposition()) |
1818 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1838 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1819 } | 1839 } |
1820 | 1840 |
1821 UpdateCompositionInfo(true); | 1841 UpdateCompositionInfo(true /* update composition range */, |
1842 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 Loading... | |
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 |
OLD | NEW |