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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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), |
256 // Disable monitoring composition info by default on Android for | |
257 // performance reasons. | |
258 monitor_composition_info_(false), | |
259 #else | |
260 monitor_composition_info_(true), | |
aelias_OOO_until_Jul13
2016/07/25 22:21:56
Hmm, it looks like this was the way of fixing non-
Seigo Nonaka
2016/07/26 01:08:14
This line is necessary not only for testing purpos
aelias_OOO_until_Jul13
2016/07/26 01:22:24
I agree tying this to render process creation woul
Seigo Nonaka
2016/07/26 01:30:54
Setting true on getting text input focus and false
| |
255 #endif | 261 #endif |
256 popup_origin_scale_for_emulation_(0.f), | 262 popup_origin_scale_for_emulation_(0.f), |
257 frame_swap_message_queue_(new FrameSwapMessageQueue()), | 263 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
258 resizing_mode_selector_(new ResizingModeSelector()), | 264 resizing_mode_selector_(new ResizingModeSelector()), |
259 has_host_context_menu_location_(false), | 265 has_host_context_menu_location_(false), |
260 has_focus_(false) { | 266 has_focus_(false) { |
261 if (!swapped_out) | 267 if (!swapped_out) |
262 RenderProcess::current()->AddRefProcess(); | 268 RenderProcess::current()->AddRefProcess(); |
263 DCHECK(RenderThread::Get()); | 269 DCHECK(RenderThread::Get()); |
264 device_color_profile_.push_back('0'); | 270 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) | 496 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
491 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 497 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
492 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) | 498 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
493 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceClientId, OnSetSurfaceClientId) | 499 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceClientId, OnSetSurfaceClientId) |
494 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, | 500 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, |
495 OnWaitNextFrameForTests) | 501 OnWaitNextFrameForTests) |
496 #if defined(OS_ANDROID) | 502 #if defined(OS_ANDROID) |
497 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) | 503 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) |
498 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, | 504 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, |
499 OnRequestTextInputStateUpdate) | 505 OnRequestTextInputStateUpdate) |
506 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate, | |
507 OnRequestCompositionUpdate) | |
500 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) | 508 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) |
501 #endif | 509 #endif |
502 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) | 510 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) |
503 IPC_MESSAGE_UNHANDLED(handled = false) | 511 IPC_MESSAGE_UNHANDLED(handled = false) |
504 IPC_END_MESSAGE_MAP() | 512 IPC_END_MESSAGE_MAP() |
505 return handled; | 513 return handled; |
506 } | 514 } |
507 | 515 |
508 bool RenderWidget::Send(IPC::Message* message) { | 516 bool RenderWidget::Send(IPC::Message* message) { |
509 // Don't send any messages after the browser has told us to close, and filter | 517 // Don't send any messages after the browser has told us to close, and filter |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1341 return; | 1349 return; |
1342 ImeEventGuard guard(this); | 1350 ImeEventGuard guard(this); |
1343 if (!webwidget_->setComposition( | 1351 if (!webwidget_->setComposition( |
1344 text, WebVector<WebCompositionUnderline>(underlines), | 1352 text, WebVector<WebCompositionUnderline>(underlines), |
1345 selection_start, selection_end)) { | 1353 selection_start, selection_end)) { |
1346 // If we failed to set the composition text, then we need to let the browser | 1354 // If we failed to set the composition text, then we need to let the browser |
1347 // process to cancel the input method's ongoing composition session, to make | 1355 // process to cancel the input method's ongoing composition session, to make |
1348 // sure we are in a consistent state. | 1356 // sure we are in a consistent state. |
1349 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1357 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1350 } | 1358 } |
1351 UpdateCompositionInfo(true); | 1359 UpdateCompositionInfo(false /* not an immediate request */); |
1352 } | 1360 } |
1353 | 1361 |
1354 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1362 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
1355 const gfx::Range& replacement_range, | 1363 const gfx::Range& replacement_range, |
1356 bool keep_selection) { | 1364 bool keep_selection) { |
1357 if (!ShouldHandleImeEvent()) | 1365 if (!ShouldHandleImeEvent()) |
1358 return; | 1366 return; |
1359 ImeEventGuard guard(this); | 1367 ImeEventGuard guard(this); |
1360 input_handler_->set_handling_input_event(true); | 1368 input_handler_->set_handling_input_event(true); |
1361 if (text.length()) | 1369 if (text.length()) |
1362 webwidget_->confirmComposition(text); | 1370 webwidget_->confirmComposition(text); |
1363 else if (keep_selection) | 1371 else if (keep_selection) |
1364 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1372 webwidget_->confirmComposition(WebWidget::KeepSelection); |
1365 else | 1373 else |
1366 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1374 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
1367 input_handler_->set_handling_input_event(false); | 1375 input_handler_->set_handling_input_event(false); |
1368 UpdateCompositionInfo(true); | 1376 UpdateCompositionInfo(false /* not an immediate request */); |
1369 } | 1377 } |
1370 | 1378 |
1371 void RenderWidget::OnDeviceScaleFactorChanged() { | 1379 void RenderWidget::OnDeviceScaleFactorChanged() { |
1372 if (!compositor_) | 1380 if (!compositor_) |
1373 return; | 1381 return; |
1374 if (IsUseZoomForDSFEnabled()) | 1382 if (IsUseZoomForDSFEnabled()) |
1375 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); | 1383 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); |
1376 else | 1384 else |
1377 compositor_->setDeviceScaleFactor(device_scale_factor_); | 1385 compositor_->setDeviceScaleFactor(device_scale_factor_); |
1378 } | 1386 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1439 void RenderWidget::showImeIfNeeded() { | 1447 void RenderWidget::showImeIfNeeded() { |
1440 OnShowImeIfNeeded(); | 1448 OnShowImeIfNeeded(); |
1441 } | 1449 } |
1442 | 1450 |
1443 ui::TextInputType RenderWidget::GetTextInputType() { | 1451 ui::TextInputType RenderWidget::GetTextInputType() { |
1444 if (webwidget_) | 1452 if (webwidget_) |
1445 return WebKitToUiTextInputType(webwidget_->textInputType()); | 1453 return WebKitToUiTextInputType(webwidget_->textInputType()); |
1446 return ui::TEXT_INPUT_TYPE_NONE; | 1454 return ui::TEXT_INPUT_TYPE_NONE; |
1447 } | 1455 } |
1448 | 1456 |
1449 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { | 1457 void RenderWidget::UpdateCompositionInfo(bool immediate_request) { |
1458 if (!monitor_composition_info_ && !immediate_request) | |
1459 return; // Do not calculate composition info if not requested. | |
1460 | |
1450 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); | 1461 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
1451 gfx::Range range = gfx::Range(); | 1462 gfx::Range range; |
1452 if (should_update_range) { | 1463 std::vector<gfx::Rect> character_bounds; |
1464 | |
1465 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { | |
1466 // Composition information is only available on editable node. | |
1467 range = gfx::Range::InvalidRange(); | |
1468 } else { | |
1453 GetCompositionRange(&range); | 1469 GetCompositionRange(&range); |
1454 } else { | 1470 GetCompositionCharacterBounds(&character_bounds); |
1455 range = composition_range_; | |
1456 } | 1471 } |
1457 std::vector<gfx::Rect> character_bounds; | |
1458 GetCompositionCharacterBounds(&character_bounds); | |
1459 | 1472 |
1460 if (!ShouldUpdateCompositionInfo(range, character_bounds)) | 1473 if (!immediate_request && |
1474 !ShouldUpdateCompositionInfo(range, character_bounds)) { | |
1461 return; | 1475 return; |
1476 } | |
1462 composition_character_bounds_ = character_bounds; | 1477 composition_character_bounds_ = character_bounds; |
1463 composition_range_ = range; | 1478 composition_range_ = range; |
1464 Send(new InputHostMsg_ImeCompositionRangeChanged( | 1479 Send(new InputHostMsg_ImeCompositionRangeChanged( |
1465 routing_id(), composition_range_, composition_character_bounds_)); | 1480 routing_id(), composition_range_, composition_character_bounds_)); |
1466 } | 1481 } |
1467 | 1482 |
1468 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { | 1483 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { |
1469 if (IsUseZoomForDSFEnabled()) { | 1484 if (IsUseZoomForDSFEnabled()) { |
1470 float reverse = 1 / GetOriginalDeviceScaleFactor(); | 1485 float reverse = 1 / GetOriginalDeviceScaleFactor(); |
1471 // TODO(oshima): We may need to allow pixel precision here as the the | 1486 // 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 Loading... | |
1508 void RenderWidget::OnImeEventAck() { | 1523 void RenderWidget::OnImeEventAck() { |
1509 DCHECK_GE(text_input_info_history_.size(), 1u); | 1524 DCHECK_GE(text_input_info_history_.size(), 1u); |
1510 text_input_info_history_.pop_front(); | 1525 text_input_info_history_.pop_front(); |
1511 } | 1526 } |
1512 | 1527 |
1513 void RenderWidget::OnRequestTextInputStateUpdate() { | 1528 void RenderWidget::OnRequestTextInputStateUpdate() { |
1514 DCHECK(!ime_event_guard_); | 1529 DCHECK(!ime_event_guard_); |
1515 UpdateSelectionBounds(); | 1530 UpdateSelectionBounds(); |
1516 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); | 1531 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); |
1517 } | 1532 } |
1533 | |
1534 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request, | |
1535 bool monitor_request) { | |
1536 monitor_composition_info_ = monitor_request; | |
1537 if (!immediate_request) | |
1538 return; | |
1539 UpdateCompositionInfo(true /* immediate request */); | |
1540 } | |
1518 #endif | 1541 #endif |
1519 | 1542 |
1520 bool RenderWidget::ShouldHandleImeEvent() { | 1543 bool RenderWidget::ShouldHandleImeEvent() { |
1521 #if defined(OS_ANDROID) | 1544 #if defined(OS_ANDROID) |
1522 if (!webwidget_) | 1545 if (!webwidget_) |
1523 return false; | 1546 return false; |
1524 if (IsUsingImeThread()) | 1547 if (IsUsingImeThread()) |
1525 return true; | 1548 return true; |
1526 | 1549 |
1527 // We cannot handle IME events if there is any chance that the event we are | 1550 // 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... | |
1688 if (selection_anchor_rect_ != params.anchor_rect || | 1711 if (selection_anchor_rect_ != params.anchor_rect || |
1689 selection_focus_rect_ != params.focus_rect) { | 1712 selection_focus_rect_ != params.focus_rect) { |
1690 selection_anchor_rect_ = params.anchor_rect; | 1713 selection_anchor_rect_ = params.anchor_rect; |
1691 selection_focus_rect_ = params.focus_rect; | 1714 selection_focus_rect_ = params.focus_rect; |
1692 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); | 1715 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); |
1693 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); | 1716 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); |
1694 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); | 1717 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); |
1695 } | 1718 } |
1696 } | 1719 } |
1697 | 1720 |
1698 UpdateCompositionInfo(false); | 1721 UpdateCompositionInfo(false /* not an immediate request */); |
1699 } | 1722 } |
1700 | 1723 |
1701 void RenderWidget::SetDeviceColorProfileForTesting( | 1724 void RenderWidget::SetDeviceColorProfileForTesting( |
1702 const std::vector<char>& color_profile) { | 1725 const std::vector<char>& color_profile) { |
1703 SetDeviceColorProfile(color_profile); | 1726 SetDeviceColorProfile(color_profile); |
1704 } | 1727 } |
1705 | 1728 |
1706 void RenderWidget::ResetDeviceColorProfileForTesting() { | 1729 void RenderWidget::ResetDeviceColorProfileForTesting() { |
1707 std::vector<char> color_profile; | 1730 std::vector<char> color_profile; |
1708 color_profile.push_back('0'); | 1731 color_profile.push_back('0'); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1809 ImeEventGuard guard(this); | 1832 ImeEventGuard guard(this); |
1810 // 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 |
1811 // ongoing composition regardless of the new text input type. | 1834 // ongoing composition regardless of the new text input type. |
1812 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { | 1835 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
1813 // 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 |
1814 // to cancel the input method's ongoing composition session. | 1837 // to cancel the input method's ongoing composition session. |
1815 if (webwidget_->confirmComposition()) | 1838 if (webwidget_->confirmComposition()) |
1816 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1839 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1817 } | 1840 } |
1818 | 1841 |
1819 UpdateCompositionInfo(true); | 1842 UpdateCompositionInfo(false /* not an immediate request */); |
1820 } | 1843 } |
1821 | 1844 |
1822 #if defined(OS_ANDROID) | 1845 #if defined(OS_ANDROID) |
1823 void RenderWidget::showUnhandledTapUIIfNeeded( | 1846 void RenderWidget::showUnhandledTapUIIfNeeded( |
1824 const WebPoint& tapped_position, | 1847 const WebPoint& tapped_position, |
1825 const WebNode& tapped_node, | 1848 const WebNode& tapped_node, |
1826 bool page_changed) { | 1849 bool page_changed) { |
1827 DCHECK(input_handler_->handling_input_event()); | 1850 DCHECK(input_handler_->handling_input_event()); |
1828 bool should_trigger = !page_changed && tapped_node.isTextNode() && | 1851 bool should_trigger = !page_changed && tapped_node.isTextNode() && |
1829 !tapped_node.isContentEditable() && | 1852 !tapped_node.isContentEditable() && |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1977 void RenderWidget::requestPointerUnlock() { | 2000 void RenderWidget::requestPointerUnlock() { |
1978 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); | 2001 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
1979 } | 2002 } |
1980 | 2003 |
1981 bool RenderWidget::isPointerLocked() { | 2004 bool RenderWidget::isPointerLocked() { |
1982 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2005 return mouse_lock_dispatcher_->IsMouseLockedTo( |
1983 webwidget_mouse_lock_target_.get()); | 2006 webwidget_mouse_lock_target_.get()); |
1984 } | 2007 } |
1985 | 2008 |
1986 } // namespace content | 2009 } // namespace content |
OLD | NEW |