| 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), |
| 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_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 Loading... |
| 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 /* update composition range */, |
| 1377 false /* force update */); |
| 1375 } | 1378 } |
| 1376 | 1379 |
| 1377 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1380 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
| 1378 const gfx::Range& replacement_range, | 1381 const gfx::Range& replacement_range, |
| 1379 bool keep_selection) { | 1382 bool keep_selection) { |
| 1380 if (!ShouldHandleImeEvent()) | 1383 if (!ShouldHandleImeEvent()) |
| 1381 return; | 1384 return; |
| 1382 ImeEventGuard guard(this); | 1385 ImeEventGuard guard(this); |
| 1383 input_handler_->set_handling_input_event(true); | 1386 input_handler_->set_handling_input_event(true); |
| 1384 if (text.length()) | 1387 if (text.length()) |
| 1385 webwidget_->confirmComposition(text); | 1388 webwidget_->confirmComposition(text); |
| 1386 else if (keep_selection) | 1389 else if (keep_selection) |
| 1387 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1390 webwidget_->confirmComposition(WebWidget::KeepSelection); |
| 1388 else | 1391 else |
| 1389 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1392 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
| 1390 input_handler_->set_handling_input_event(false); | 1393 input_handler_->set_handling_input_event(false); |
| 1391 UpdateCompositionInfo(true); | 1394 UpdateCompositionInfo(true /* update composition range */, |
| 1395 false /* force update */); |
| 1392 } | 1396 } |
| 1393 | 1397 |
| 1394 void RenderWidget::OnDeviceScaleFactorChanged() { | 1398 void RenderWidget::OnDeviceScaleFactorChanged() { |
| 1395 if (!compositor_) | 1399 if (!compositor_) |
| 1396 return; | 1400 return; |
| 1397 if (IsUseZoomForDSFEnabled()) | 1401 if (IsUseZoomForDSFEnabled()) |
| 1398 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); | 1402 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); |
| 1399 else | 1403 else |
| 1400 compositor_->setDeviceScaleFactor(device_scale_factor_); | 1404 compositor_->setDeviceScaleFactor(device_scale_factor_); |
| 1401 } | 1405 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 void RenderWidget::showImeIfNeeded() { | 1466 void RenderWidget::showImeIfNeeded() { |
| 1463 OnShowImeIfNeeded(); | 1467 OnShowImeIfNeeded(); |
| 1464 } | 1468 } |
| 1465 | 1469 |
| 1466 ui::TextInputType RenderWidget::GetTextInputType() { | 1470 ui::TextInputType RenderWidget::GetTextInputType() { |
| 1467 if (webwidget_) | 1471 if (webwidget_) |
| 1468 return WebKitToUiTextInputType(webwidget_->textInputType()); | 1472 return WebKitToUiTextInputType(webwidget_->textInputType()); |
| 1469 return ui::TEXT_INPUT_TYPE_NONE; | 1473 return ui::TEXT_INPUT_TYPE_NONE; |
| 1470 } | 1474 } |
| 1471 | 1475 |
| 1472 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { | 1476 void RenderWidget::UpdateCompositionInfo( |
| 1477 bool should_update_range, bool force_update) { |
| 1478 #if defined(OS_ANDROID) |
| 1479 if (!monitor_composition_info_) |
| 1480 return; // Do not calculate composition info if not requested. |
| 1481 #endif // OS_ANDROID |
| 1473 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); | 1482 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
| 1474 gfx::Range range = gfx::Range(); | 1483 gfx::Range range = gfx::Range(); |
| 1475 if (should_update_range) { | 1484 if (should_update_range) { |
| 1476 GetCompositionRange(&range); | 1485 GetCompositionRange(&range); |
| 1477 } else { | 1486 } else { |
| 1478 range = composition_range_; | 1487 range = composition_range_; |
| 1479 } | 1488 } |
| 1480 std::vector<gfx::Rect> character_bounds; | 1489 std::vector<gfx::Rect> character_bounds; |
| 1481 GetCompositionCharacterBounds(&character_bounds); | 1490 GetCompositionCharacterBounds(&character_bounds); |
| 1482 | 1491 |
| 1483 if (!ShouldUpdateCompositionInfo(range, character_bounds)) | 1492 if (!force_update && !ShouldUpdateCompositionInfo(range, character_bounds)) |
| 1484 return; | 1493 return; |
| 1485 composition_character_bounds_ = character_bounds; | 1494 composition_character_bounds_ = character_bounds; |
| 1486 composition_range_ = range; | 1495 composition_range_ = range; |
| 1487 Send(new InputHostMsg_ImeCompositionRangeChanged( | 1496 Send(new InputHostMsg_ImeCompositionRangeChanged( |
| 1488 routing_id(), composition_range_, composition_character_bounds_)); | 1497 routing_id(), composition_range_, composition_character_bounds_)); |
| 1489 } | 1498 } |
| 1490 | 1499 |
| 1491 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { | 1500 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { |
| 1492 if (IsUseZoomForDSFEnabled()) { | 1501 if (IsUseZoomForDSFEnabled()) { |
| 1493 float reverse = 1 / GetOriginalDeviceScaleFactor(); | 1502 float reverse = 1 / GetOriginalDeviceScaleFactor(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1531 void RenderWidget::OnImeEventAck() { | 1540 void RenderWidget::OnImeEventAck() { |
| 1532 DCHECK_GE(text_input_info_history_.size(), 1u); | 1541 DCHECK_GE(text_input_info_history_.size(), 1u); |
| 1533 text_input_info_history_.pop_front(); | 1542 text_input_info_history_.pop_front(); |
| 1534 } | 1543 } |
| 1535 | 1544 |
| 1536 void RenderWidget::OnRequestTextInputStateUpdate() { | 1545 void RenderWidget::OnRequestTextInputStateUpdate() { |
| 1537 DCHECK(!ime_event_guard_); | 1546 DCHECK(!ime_event_guard_); |
| 1538 UpdateSelectionBounds(); | 1547 UpdateSelectionBounds(); |
| 1539 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); | 1548 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); |
| 1540 } | 1549 } |
| 1550 |
| 1551 void RenderWidget::OnRequestCursorUpdate( |
| 1552 bool immediate_request, bool monitor_request) { |
| 1553 monitor_composition_info_ = monitor_request; |
| 1554 if (!immediate_request) |
| 1555 return; |
| 1556 UpdateCompositionInfo(true /* update composition range */, |
| 1557 true /* force update */); |
| 1558 } |
| 1541 #endif | 1559 #endif |
| 1542 | 1560 |
| 1543 bool RenderWidget::ShouldHandleImeEvent() { | 1561 bool RenderWidget::ShouldHandleImeEvent() { |
| 1544 #if defined(OS_ANDROID) | 1562 #if defined(OS_ANDROID) |
| 1545 if (!webwidget_) | 1563 if (!webwidget_) |
| 1546 return false; | 1564 return false; |
| 1547 if (IsUsingImeThread()) | 1565 if (IsUsingImeThread()) |
| 1548 return true; | 1566 return true; |
| 1549 | 1567 |
| 1550 // We cannot handle IME events if there is any chance that the event we are | 1568 // 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 || | 1729 if (selection_anchor_rect_ != params.anchor_rect || |
| 1712 selection_focus_rect_ != params.focus_rect) { | 1730 selection_focus_rect_ != params.focus_rect) { |
| 1713 selection_anchor_rect_ = params.anchor_rect; | 1731 selection_anchor_rect_ = params.anchor_rect; |
| 1714 selection_focus_rect_ = params.focus_rect; | 1732 selection_focus_rect_ = params.focus_rect; |
| 1715 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); | 1733 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); |
| 1716 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); | 1734 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); |
| 1717 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); | 1735 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); |
| 1718 } | 1736 } |
| 1719 } | 1737 } |
| 1720 | 1738 |
| 1721 UpdateCompositionInfo(false); | 1739 UpdateCompositionInfo(false /* update composition range */, |
| 1740 false /* force update */); |
| 1722 } | 1741 } |
| 1723 | 1742 |
| 1724 void RenderWidget::SetDeviceColorProfileForTesting( | 1743 void RenderWidget::SetDeviceColorProfileForTesting( |
| 1725 const std::vector<char>& color_profile) { | 1744 const std::vector<char>& color_profile) { |
| 1726 SetDeviceColorProfile(color_profile); | 1745 SetDeviceColorProfile(color_profile); |
| 1727 } | 1746 } |
| 1728 | 1747 |
| 1729 void RenderWidget::ResetDeviceColorProfileForTesting() { | 1748 void RenderWidget::ResetDeviceColorProfileForTesting() { |
| 1730 std::vector<char> color_profile; | 1749 std::vector<char> color_profile; |
| 1731 color_profile.push_back('0'); | 1750 color_profile.push_back('0'); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1811 ImeEventGuard guard(this); | 1830 ImeEventGuard guard(this); |
| 1812 // If the last text input type is not None, then we should finish any | 1831 // If the last text input type is not None, then we should finish any |
| 1813 // ongoing composition regardless of the new text input type. | 1832 // ongoing composition regardless of the new text input type. |
| 1814 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { | 1833 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
| 1815 // If a composition text exists, then we need to let the browser process | 1834 // If a composition text exists, then we need to let the browser process |
| 1816 // to cancel the input method's ongoing composition session. | 1835 // to cancel the input method's ongoing composition session. |
| 1817 if (webwidget_->confirmComposition()) | 1836 if (webwidget_->confirmComposition()) |
| 1818 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1837 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1819 } | 1838 } |
| 1820 | 1839 |
| 1821 UpdateCompositionInfo(true); | 1840 UpdateCompositionInfo(true /* update composition range */, |
| 1841 false /* force update */); |
| 1822 } | 1842 } |
| 1823 | 1843 |
| 1824 #if defined(OS_ANDROID) | 1844 #if defined(OS_ANDROID) |
| 1825 void RenderWidget::showUnhandledTapUIIfNeeded( | 1845 void RenderWidget::showUnhandledTapUIIfNeeded( |
| 1826 const WebPoint& tapped_position, | 1846 const WebPoint& tapped_position, |
| 1827 const WebNode& tapped_node, | 1847 const WebNode& tapped_node, |
| 1828 bool page_changed) { | 1848 bool page_changed) { |
| 1829 DCHECK(input_handler_->handling_input_event()); | 1849 DCHECK(input_handler_->handling_input_event()); |
| 1830 bool should_trigger = !page_changed && tapped_node.isTextNode() && | 1850 bool should_trigger = !page_changed && tapped_node.isTextNode() && |
| 1831 !tapped_node.isContentEditable() && | 1851 !tapped_node.isContentEditable() && |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 void RenderWidget::requestPointerUnlock() { | 1999 void RenderWidget::requestPointerUnlock() { |
| 1980 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); | 2000 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 1981 } | 2001 } |
| 1982 | 2002 |
| 1983 bool RenderWidget::isPointerLocked() { | 2003 bool RenderWidget::isPointerLocked() { |
| 1984 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2004 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 1985 webwidget_mouse_lock_target_.get()); | 2005 webwidget_mouse_lock_target_.get()); |
| 1986 } | 2006 } |
| 1987 | 2007 |
| 1988 } // namespace content | 2008 } // namespace content |
| OLD | NEW |