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()), | |
250 popup_type_(popup_type), | 249 popup_type_(popup_type), |
251 pending_window_rect_count_(0), | 250 pending_window_rect_count_(0), |
252 screen_info_(screen_info), | 251 screen_info_(screen_info), |
253 device_scale_factor_(screen_info_.deviceScaleFactor), | 252 device_scale_factor_(screen_info_.deviceScaleFactor), |
254 #if defined(OS_ANDROID) | 253 #if defined(OS_ANDROID) |
255 text_field_is_dirty_(false), | 254 text_field_is_dirty_(false), |
256 #endif | 255 #endif |
257 monitor_composition_info_(false), | |
258 popup_origin_scale_for_emulation_(0.f), | 256 popup_origin_scale_for_emulation_(0.f), |
259 frame_swap_message_queue_(new FrameSwapMessageQueue()), | 257 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
260 resizing_mode_selector_(new ResizingModeSelector()), | 258 resizing_mode_selector_(new ResizingModeSelector()), |
261 has_host_context_menu_location_(false), | 259 has_host_context_menu_location_(false), |
262 has_focus_(false), | 260 has_focus_(false), |
263 focused_pepper_plugin_(nullptr) { | 261 focused_pepper_plugin_(nullptr) { |
264 if (!swapped_out) | 262 if (!swapped_out) |
265 RenderProcess::current()->AddRefProcess(); | 263 RenderProcess::current()->AddRefProcess(); |
266 DCHECK(RenderThread::Get()); | 264 DCHECK(RenderThread::Get()); |
267 device_color_profile_.push_back('0'); | 265 device_color_profile_.push_back('0'); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect) | 487 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect) |
490 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) | 488 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
491 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) | 489 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) |
492 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) | 490 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) |
493 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 491 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
494 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 492 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
495 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) | 493 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
496 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceClientId, OnSetSurfaceClientId) | 494 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceClientId, OnSetSurfaceClientId) |
497 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, | 495 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, |
498 OnWaitNextFrameForTests) | 496 OnWaitNextFrameForTests) |
499 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate, | |
500 OnRequestCompositionUpdate) | |
501 #if defined(OS_ANDROID) | 497 #if defined(OS_ANDROID) |
502 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) | 498 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) |
503 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, | 499 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, |
504 OnRequestTextInputStateUpdate) | 500 OnRequestTextInputStateUpdate) |
505 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) | 501 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) |
506 #endif | 502 #endif |
507 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) | 503 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) |
508 IPC_MESSAGE_UNHANDLED(handled = false) | 504 IPC_MESSAGE_UNHANDLED(handled = false) |
509 IPC_END_MESSAGE_MAP() | 505 IPC_END_MESSAGE_MAP() |
510 return handled; | 506 return handled; |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 return; | 1351 return; |
1356 ImeEventGuard guard(this); | 1352 ImeEventGuard guard(this); |
1357 if (!webwidget_->setComposition( | 1353 if (!webwidget_->setComposition( |
1358 text, WebVector<WebCompositionUnderline>(underlines), | 1354 text, WebVector<WebCompositionUnderline>(underlines), |
1359 selection_start, selection_end)) { | 1355 selection_start, selection_end)) { |
1360 // If we failed to set the composition text, then we need to let the browser | 1356 // If we failed to set the composition text, then we need to let the browser |
1361 // process to cancel the input method's ongoing composition session, to make | 1357 // process to cancel the input method's ongoing composition session, to make |
1362 // sure we are in a consistent state. | 1358 // sure we are in a consistent state. |
1363 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1359 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1364 } | 1360 } |
1365 UpdateCompositionInfo(false /* not an immediate request */); | 1361 UpdateCompositionInfo(true); |
1366 } | 1362 } |
1367 | 1363 |
1368 void RenderWidget::OnImeConfirmComposition(const base::string16& text, | 1364 void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
1369 const gfx::Range& replacement_range, | 1365 const gfx::Range& replacement_range, |
1370 bool keep_selection) { | 1366 bool keep_selection) { |
1371 #if defined(ENABLE_PLUGINS) | 1367 #if defined(ENABLE_PLUGINS) |
1372 if (focused_pepper_plugin_) { | 1368 if (focused_pepper_plugin_) { |
1373 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( | 1369 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( |
1374 text, replacement_range, keep_selection); | 1370 text, replacement_range, keep_selection); |
1375 return; | 1371 return; |
1376 } | 1372 } |
1377 #endif | 1373 #endif |
1378 if (replacement_range.IsValid()) { | 1374 if (replacement_range.IsValid()) { |
1379 webwidget_->applyReplacementRange(replacement_range.start(), | 1375 webwidget_->applyReplacementRange(replacement_range.start(), |
1380 replacement_range.length()); | 1376 replacement_range.length()); |
1381 } | 1377 } |
1382 | 1378 |
1383 if (!ShouldHandleImeEvent()) | 1379 if (!ShouldHandleImeEvent()) |
1384 return; | 1380 return; |
1385 ImeEventGuard guard(this); | 1381 ImeEventGuard guard(this); |
1386 input_handler_->set_handling_input_event(true); | 1382 input_handler_->set_handling_input_event(true); |
1387 if (text.length()) | 1383 if (text.length()) |
1388 webwidget_->confirmComposition(text); | 1384 webwidget_->confirmComposition(text); |
1389 else if (keep_selection) | 1385 else if (keep_selection) |
1390 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1386 webwidget_->confirmComposition(WebWidget::KeepSelection); |
1391 else | 1387 else |
1392 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1388 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
1393 input_handler_->set_handling_input_event(false); | 1389 input_handler_->set_handling_input_event(false); |
1394 UpdateCompositionInfo(false /* not an immediate request */); | 1390 UpdateCompositionInfo(true); |
1395 } | 1391 } |
1396 | 1392 |
1397 void RenderWidget::OnDeviceScaleFactorChanged() { | 1393 void RenderWidget::OnDeviceScaleFactorChanged() { |
1398 if (!compositor_) | 1394 if (!compositor_) |
1399 return; | 1395 return; |
1400 if (IsUseZoomForDSFEnabled()) | 1396 if (IsUseZoomForDSFEnabled()) |
1401 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); | 1397 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); |
1402 else | 1398 else |
1403 compositor_->setDeviceScaleFactor(device_scale_factor_); | 1399 compositor_->setDeviceScaleFactor(device_scale_factor_); |
1404 } | 1400 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 ui::TextInputType RenderWidget::GetTextInputType() { | 1465 ui::TextInputType RenderWidget::GetTextInputType() { |
1470 #if defined(ENABLE_PLUGINS) | 1466 #if defined(ENABLE_PLUGINS) |
1471 if (focused_pepper_plugin_) | 1467 if (focused_pepper_plugin_) |
1472 return focused_pepper_plugin_->text_input_type(); | 1468 return focused_pepper_plugin_->text_input_type(); |
1473 #endif | 1469 #endif |
1474 if (webwidget_) | 1470 if (webwidget_) |
1475 return WebKitToUiTextInputType(webwidget_->textInputType()); | 1471 return WebKitToUiTextInputType(webwidget_->textInputType()); |
1476 return ui::TEXT_INPUT_TYPE_NONE; | 1472 return ui::TEXT_INPUT_TYPE_NONE; |
1477 } | 1473 } |
1478 | 1474 |
1479 void RenderWidget::UpdateCompositionInfo(bool immediate_request) { | 1475 void RenderWidget::UpdateCompositionInfo(bool should_update_range) { |
1480 if (!monitor_composition_info_ && !immediate_request) | 1476 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
1481 return; // Do not calculate composition info if not requested. | 1477 gfx::Range range = gfx::Range(); |
| 1478 if (should_update_range) { |
| 1479 GetCompositionRange(&range); |
| 1480 } else { |
| 1481 range = composition_range_; |
| 1482 } |
| 1483 std::vector<gfx::Rect> character_bounds; |
| 1484 GetCompositionCharacterBounds(&character_bounds); |
1482 | 1485 |
1483 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); | 1486 if (!ShouldUpdateCompositionInfo(range, character_bounds)) |
1484 gfx::Range range; | |
1485 std::vector<gfx::Rect> character_bounds; | |
1486 | |
1487 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { | |
1488 // Composition information is only available on editable node. | |
1489 range = gfx::Range::InvalidRange(); | |
1490 } else { | |
1491 GetCompositionRange(&range); | |
1492 GetCompositionCharacterBounds(&character_bounds); | |
1493 } | |
1494 | |
1495 if (!immediate_request && | |
1496 !ShouldUpdateCompositionInfo(range, character_bounds)) { | |
1497 return; | 1487 return; |
1498 } | |
1499 composition_character_bounds_ = character_bounds; | 1488 composition_character_bounds_ = character_bounds; |
1500 composition_range_ = range; | 1489 composition_range_ = range; |
1501 Send(new InputHostMsg_ImeCompositionRangeChanged( | 1490 Send(new InputHostMsg_ImeCompositionRangeChanged( |
1502 routing_id(), composition_range_, composition_character_bounds_)); | 1491 routing_id(), composition_range_, composition_character_bounds_)); |
1503 } | 1492 } |
1504 | 1493 |
1505 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { | 1494 void RenderWidget::convertViewportToWindow(blink::WebRect* rect) { |
1506 if (IsUseZoomForDSFEnabled()) { | 1495 if (IsUseZoomForDSFEnabled()) { |
1507 float reverse = 1 / GetOriginalDeviceScaleFactor(); | 1496 float reverse = 1 / GetOriginalDeviceScaleFactor(); |
1508 // TODO(oshima): We may need to allow pixel precision here as the the | 1497 // 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 Loading... |
1547 text_input_info_history_.pop_front(); | 1536 text_input_info_history_.pop_front(); |
1548 } | 1537 } |
1549 | 1538 |
1550 void RenderWidget::OnRequestTextInputStateUpdate() { | 1539 void RenderWidget::OnRequestTextInputStateUpdate() { |
1551 DCHECK(!ime_event_guard_); | 1540 DCHECK(!ime_event_guard_); |
1552 UpdateSelectionBounds(); | 1541 UpdateSelectionBounds(); |
1553 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); | 1542 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); |
1554 } | 1543 } |
1555 #endif | 1544 #endif |
1556 | 1545 |
1557 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request, | |
1558 bool monitor_request) { | |
1559 monitor_composition_info_ = monitor_request; | |
1560 if (!immediate_request) | |
1561 return; | |
1562 UpdateCompositionInfo(true /* immediate request */); | |
1563 } | |
1564 | |
1565 bool RenderWidget::ShouldHandleImeEvent() { | 1546 bool RenderWidget::ShouldHandleImeEvent() { |
1566 #if defined(OS_ANDROID) | 1547 #if defined(OS_ANDROID) |
1567 if (!webwidget_) | 1548 if (!webwidget_) |
1568 return false; | 1549 return false; |
1569 if (IsUsingImeThread()) | 1550 if (IsUsingImeThread()) |
1570 return true; | 1551 return true; |
1571 | 1552 |
1572 // We cannot handle IME events if there is any chance that the event we are | 1553 // We cannot handle IME events if there is any chance that the event we are |
1573 // receiving here from the browser is based on the state that is different | 1554 // receiving here from the browser is based on the state that is different |
1574 // from our current one as indicated by |text_input_info_|. | 1555 // from our current one as indicated by |text_input_info_|. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 if (selection_anchor_rect_ != params.anchor_rect || | 1727 if (selection_anchor_rect_ != params.anchor_rect || |
1747 selection_focus_rect_ != params.focus_rect) { | 1728 selection_focus_rect_ != params.focus_rect) { |
1748 selection_anchor_rect_ = params.anchor_rect; | 1729 selection_anchor_rect_ = params.anchor_rect; |
1749 selection_focus_rect_ = params.focus_rect; | 1730 selection_focus_rect_ = params.focus_rect; |
1750 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); | 1731 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); |
1751 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); | 1732 params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); |
1752 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); | 1733 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); |
1753 } | 1734 } |
1754 } | 1735 } |
1755 | 1736 |
1756 UpdateCompositionInfo(false /* not an immediate request */); | 1737 UpdateCompositionInfo(false); |
1757 } | 1738 } |
1758 | 1739 |
1759 void RenderWidget::SetDeviceColorProfileForTesting( | 1740 void RenderWidget::SetDeviceColorProfileForTesting( |
1760 const std::vector<char>& color_profile) { | 1741 const std::vector<char>& color_profile) { |
1761 SetDeviceColorProfile(color_profile); | 1742 SetDeviceColorProfile(color_profile); |
1762 } | 1743 } |
1763 | 1744 |
1764 void RenderWidget::ResetDeviceColorProfileForTesting() { | 1745 void RenderWidget::ResetDeviceColorProfileForTesting() { |
1765 std::vector<char> color_profile; | 1746 std::vector<char> color_profile; |
1766 color_profile.push_back('0'); | 1747 color_profile.push_back('0'); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1891 ImeEventGuard guard(this); | 1872 ImeEventGuard guard(this); |
1892 // If the last text input type is not None, then we should finish any | 1873 // If the last text input type is not None, then we should finish any |
1893 // ongoing composition regardless of the new text input type. | 1874 // ongoing composition regardless of the new text input type. |
1894 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { | 1875 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
1895 // If a composition text exists, then we need to let the browser process | 1876 // If a composition text exists, then we need to let the browser process |
1896 // to cancel the input method's ongoing composition session. | 1877 // to cancel the input method's ongoing composition session. |
1897 if (webwidget_->confirmComposition()) | 1878 if (webwidget_->confirmComposition()) |
1898 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1879 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1899 } | 1880 } |
1900 | 1881 |
1901 UpdateCompositionInfo(false /* not an immediate request */); | 1882 UpdateCompositionInfo(true); |
1902 } | 1883 } |
1903 | 1884 |
1904 #if defined(OS_ANDROID) | 1885 #if defined(OS_ANDROID) |
1905 void RenderWidget::showUnhandledTapUIIfNeeded( | 1886 void RenderWidget::showUnhandledTapUIIfNeeded( |
1906 const WebPoint& tapped_position, | 1887 const WebPoint& tapped_position, |
1907 const WebNode& tapped_node, | 1888 const WebNode& tapped_node, |
1908 bool page_changed) { | 1889 bool page_changed) { |
1909 DCHECK(input_handler_->handling_input_event()); | 1890 DCHECK(input_handler_->handling_input_event()); |
1910 bool should_trigger = !page_changed && tapped_node.isTextNode() && | 1891 bool should_trigger = !page_changed && tapped_node.isTextNode() && |
1911 !tapped_node.isContentEditable() && | 1892 !tapped_node.isContentEditable() && |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 void RenderWidget::requestPointerUnlock() { | 2040 void RenderWidget::requestPointerUnlock() { |
2060 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); | 2041 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
2061 } | 2042 } |
2062 | 2043 |
2063 bool RenderWidget::isPointerLocked() { | 2044 bool RenderWidget::isPointerLocked() { |
2064 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2045 return mouse_lock_dispatcher_->IsMouseLockedTo( |
2065 webwidget_mouse_lock_target_.get()); | 2046 webwidget_mouse_lock_target_.get()); |
2066 } | 2047 } |
2067 | 2048 |
2068 } // namespace content | 2049 } // namespace content |
OLD | NEW |