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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 #include "skia/ext/platform_canvas.h" | 56 #include "skia/ext/platform_canvas.h" |
57 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 57 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
58 #include "third_party/WebKit/public/platform/WebPoint.h" | 58 #include "third_party/WebKit/public/platform/WebPoint.h" |
59 #include "third_party/WebKit/public/platform/WebRect.h" | 59 #include "third_party/WebKit/public/platform/WebRect.h" |
60 #include "third_party/WebKit/public/platform/WebSize.h" | 60 #include "third_party/WebKit/public/platform/WebSize.h" |
61 #include "third_party/WebKit/public/platform/WebString.h" | 61 #include "third_party/WebKit/public/platform/WebString.h" |
62 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc heduling_state.h" | 62 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc heduling_state.h" |
63 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h" | 63 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h" |
64 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" | 64 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" |
65 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 65 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
66 #include "third_party/WebKit/public/web/WebInputMethodController.h" | |
66 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 67 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
67 #include "third_party/WebKit/public/web/WebNode.h" | 68 #include "third_party/WebKit/public/web/WebNode.h" |
68 #include "third_party/WebKit/public/web/WebPagePopup.h" | 69 #include "third_party/WebKit/public/web/WebPagePopup.h" |
69 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" | 70 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" |
70 #include "third_party/WebKit/public/web/WebRange.h" | 71 #include "third_party/WebKit/public/web/WebRange.h" |
71 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 72 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
72 #include "third_party/WebKit/public/web/WebView.h" | 73 #include "third_party/WebKit/public/web/WebView.h" |
73 #include "third_party/WebKit/public/web/WebWidget.h" | 74 #include "third_party/WebKit/public/web/WebWidget.h" |
74 #include "third_party/skia/include/core/SkShader.h" | 75 #include "third_party/skia/include/core/SkShader.h" |
75 #include "ui/base/ui_base_switches.h" | 76 #include "ui/base/ui_base_switches.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
94 #include "content/public/common/mojo_shell_connection.h" | 95 #include "content/public/common/mojo_shell_connection.h" |
95 #include "content/renderer/mus/render_widget_mus_connection.h" | 96 #include "content/renderer/mus/render_widget_mus_connection.h" |
96 #endif | 97 #endif |
97 | 98 |
98 using blink::WebCompositionUnderline; | 99 using blink::WebCompositionUnderline; |
99 using blink::WebCursorInfo; | 100 using blink::WebCursorInfo; |
100 using blink::WebDeviceEmulationParams; | 101 using blink::WebDeviceEmulationParams; |
101 using blink::WebGestureEvent; | 102 using blink::WebGestureEvent; |
102 using blink::WebInputEvent; | 103 using blink::WebInputEvent; |
103 using blink::WebInputEventResult; | 104 using blink::WebInputEventResult; |
105 using blink::WebInputMethodController; | |
104 using blink::WebKeyboardEvent; | 106 using blink::WebKeyboardEvent; |
105 using blink::WebMouseEvent; | 107 using blink::WebMouseEvent; |
106 using blink::WebMouseWheelEvent; | 108 using blink::WebMouseWheelEvent; |
107 using blink::WebNavigationPolicy; | 109 using blink::WebNavigationPolicy; |
108 using blink::WebNode; | 110 using blink::WebNode; |
109 using blink::WebPagePopup; | 111 using blink::WebPagePopup; |
110 using blink::WebPoint; | 112 using blink::WebPoint; |
111 using blink::WebPopupType; | 113 using blink::WebPopupType; |
112 using blink::WebRange; | 114 using blink::WebRange; |
113 using blink::WebRect; | 115 using blink::WebRect; |
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1393 } | 1395 } |
1394 #endif | 1396 #endif |
1395 if (replacement_range.IsValid()) { | 1397 if (replacement_range.IsValid()) { |
1396 GetWebWidget()->applyReplacementRange( | 1398 GetWebWidget()->applyReplacementRange( |
1397 WebRange(replacement_range.start(), replacement_range.length())); | 1399 WebRange(replacement_range.start(), replacement_range.length())); |
1398 } | 1400 } |
1399 | 1401 |
1400 if (!ShouldHandleImeEvent()) | 1402 if (!ShouldHandleImeEvent()) |
1401 return; | 1403 return; |
1402 ImeEventGuard guard(this); | 1404 ImeEventGuard guard(this); |
1403 if (!GetWebWidget()->setComposition( | 1405 if (!GetInputMethodController() || |
lfg
2016/09/16 20:17:09
Why do we need these guards? When do we call this
EhsanK
2016/09/20 15:38:29
It will return nullptr if the focused frame is NOT
| |
1406 !GetInputMethodController()->setComposition( | |
1404 text, WebVector<WebCompositionUnderline>(underlines), selection_start, | 1407 text, WebVector<WebCompositionUnderline>(underlines), selection_start, |
1405 selection_end)) { | 1408 selection_end)) { |
1406 // If we failed to set the composition text, then we need to let the browser | 1409 // If we failed to set the composition text, then we need to let the browser |
1407 // process to cancel the input method's ongoing composition session, to make | 1410 // process to cancel the input method's ongoing composition session, to make |
1408 // sure we are in a consistent state. | 1411 // sure we are in a consistent state. |
1409 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1412 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1410 } | 1413 } |
1411 UpdateCompositionInfo(false /* not an immediate request */); | 1414 UpdateCompositionInfo(false /* not an immediate request */); |
1412 } | 1415 } |
1413 | 1416 |
1414 void RenderWidget::OnImeCommitText(const base::string16& text, | 1417 void RenderWidget::OnImeCommitText(const base::string16& text, |
1415 const gfx::Range& replacement_range, | 1418 const gfx::Range& replacement_range, |
1416 int relative_cursor_pos) { | 1419 int relative_cursor_pos) { |
1417 #if defined(ENABLE_PLUGINS) | 1420 #if defined(ENABLE_PLUGINS) |
1418 if (focused_pepper_plugin_) { | 1421 if (focused_pepper_plugin_) { |
1419 focused_pepper_plugin_->render_frame()->OnImeCommitText( | 1422 focused_pepper_plugin_->render_frame()->OnImeCommitText( |
1420 text, replacement_range, relative_cursor_pos); | 1423 text, replacement_range, relative_cursor_pos); |
1421 return; | 1424 return; |
1422 } | 1425 } |
1423 #endif | 1426 #endif |
1424 if (replacement_range.IsValid()) { | 1427 if (replacement_range.IsValid()) { |
1425 GetWebWidget()->applyReplacementRange( | 1428 GetWebWidget()->applyReplacementRange( |
1426 WebRange(replacement_range.start(), replacement_range.length())); | 1429 WebRange(replacement_range.start(), replacement_range.length())); |
1427 } | 1430 } |
1428 | 1431 |
1429 if (!ShouldHandleImeEvent()) | 1432 if (!ShouldHandleImeEvent()) |
1430 return; | 1433 return; |
1431 ImeEventGuard guard(this); | 1434 ImeEventGuard guard(this); |
1432 input_handler_->set_handling_input_event(true); | 1435 input_handler_->set_handling_input_event(true); |
1433 GetWebWidget()->commitText(text, relative_cursor_pos); | 1436 if (GetInputMethodController()) |
1437 GetInputMethodController()->commitText(text, relative_cursor_pos); | |
1434 input_handler_->set_handling_input_event(false); | 1438 input_handler_->set_handling_input_event(false); |
1435 UpdateCompositionInfo(false /* not an immediate request */); | 1439 UpdateCompositionInfo(false /* not an immediate request */); |
1436 } | 1440 } |
1437 | 1441 |
1438 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { | 1442 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
1439 #if defined(ENABLE_PLUGINS) | 1443 #if defined(ENABLE_PLUGINS) |
1440 if (focused_pepper_plugin_) { | 1444 if (focused_pepper_plugin_) { |
1441 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( | 1445 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( |
1442 keep_selection); | 1446 keep_selection); |
1443 return; | 1447 return; |
1444 } | 1448 } |
1445 #endif | 1449 #endif |
1446 | 1450 |
1447 if (!ShouldHandleImeEvent()) | 1451 if (!ShouldHandleImeEvent()) |
1448 return; | 1452 return; |
1449 ImeEventGuard guard(this); | 1453 ImeEventGuard guard(this); |
1450 input_handler_->set_handling_input_event(true); | 1454 input_handler_->set_handling_input_event(true); |
1451 GetWebWidget()->finishComposingText(keep_selection | 1455 if (GetInputMethodController()) { |
1452 ? WebWidget::KeepSelection | 1456 GetInputMethodController()->finishComposingText( |
1453 : WebWidget::DoNotKeepSelection); | 1457 keep_selection ? WebInputMethodController::KeepSelection |
1458 : WebInputMethodController::DoNotKeepSelection); | |
1459 } | |
1454 input_handler_->set_handling_input_event(false); | 1460 input_handler_->set_handling_input_event(false); |
1455 UpdateCompositionInfo(false /* not an immediate request */); | 1461 UpdateCompositionInfo(false /* not an immediate request */); |
1456 } | 1462 } |
1457 | 1463 |
1458 void RenderWidget::OnDeviceScaleFactorChanged() { | 1464 void RenderWidget::OnDeviceScaleFactorChanged() { |
1459 if (!compositor_) | 1465 if (!compositor_) |
1460 return; | 1466 return; |
1461 if (IsUseZoomForDSFEnabled()) | 1467 if (IsUseZoomForDSFEnabled()) |
1462 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); | 1468 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); |
1463 else | 1469 else |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1973 return web_screen_info; | 1979 return web_screen_info; |
1974 } | 1980 } |
1975 | 1981 |
1976 void RenderWidget::resetInputMethod() { | 1982 void RenderWidget::resetInputMethod() { |
1977 ImeEventGuard guard(this); | 1983 ImeEventGuard guard(this); |
1978 // If the last text input type is not None, then we should finish any | 1984 // If the last text input type is not None, then we should finish any |
1979 // ongoing composition regardless of the new text input type. | 1985 // ongoing composition regardless of the new text input type. |
1980 if (text_input_info_.type != blink::WebTextInputTypeNone) { | 1986 if (text_input_info_.type != blink::WebTextInputTypeNone) { |
1981 // If a composition text exists, then we need to let the browser process | 1987 // If a composition text exists, then we need to let the browser process |
1982 // to cancel the input method's ongoing composition session. | 1988 // to cancel the input method's ongoing composition session. |
1983 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) | 1989 if (GetInputMethodController() && |
1990 GetInputMethodController()->finishComposingText( | |
1991 WebInputMethodController::DoNotKeepSelection)) | |
1984 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1992 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1985 } | 1993 } |
1986 | 1994 |
1987 UpdateCompositionInfo(false /* not an immediate request */); | 1995 UpdateCompositionInfo(false /* not an immediate request */); |
1988 } | 1996 } |
1989 | 1997 |
1990 #if defined(OS_ANDROID) | 1998 #if defined(OS_ANDROID) |
1991 void RenderWidget::showUnhandledTapUIIfNeeded( | 1999 void RenderWidget::showUnhandledTapUIIfNeeded( |
1992 const WebPoint& tapped_position, | 2000 const WebPoint& tapped_position, |
1993 const WebNode& tapped_node, | 2001 const WebNode& tapped_node, |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2148 | 2156 |
2149 bool RenderWidget::isPointerLocked() { | 2157 bool RenderWidget::isPointerLocked() { |
2150 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2158 return mouse_lock_dispatcher_->IsMouseLockedTo( |
2151 webwidget_mouse_lock_target_.get()); | 2159 webwidget_mouse_lock_target_.get()); |
2152 } | 2160 } |
2153 | 2161 |
2154 blink::WebWidget* RenderWidget::GetWebWidget() const { | 2162 blink::WebWidget* RenderWidget::GetWebWidget() const { |
2155 return webwidget_internal_; | 2163 return webwidget_internal_; |
2156 } | 2164 } |
2157 | 2165 |
2166 blink::WebInputMethodController* RenderWidget::GetInputMethodController() | |
2167 const { | |
2168 return GetWebWidget()->isWebFrameWidget() | |
lfg
2016/09/16 20:17:09
Should these be a DCHECK instead of returning null
EhsanK
2016/09/20 15:38:29
I think for now that we only use WebInputMethodCon
| |
2169 ? static_cast<blink::WebFrameWidget*>(GetWebWidget()) | |
2170 ->getActiveWebInputMethodController() | |
2171 : nullptr; | |
2172 } | |
2173 | |
2158 } // namespace content | 2174 } // namespace content |
OLD | NEW |