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