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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 #include "skia/ext/platform_canvas.h" | 57 #include "skia/ext/platform_canvas.h" |
58 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 58 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
59 #include "third_party/WebKit/public/platform/WebPoint.h" | 59 #include "third_party/WebKit/public/platform/WebPoint.h" |
60 #include "third_party/WebKit/public/platform/WebRect.h" | 60 #include "third_party/WebKit/public/platform/WebRect.h" |
61 #include "third_party/WebKit/public/platform/WebSize.h" | 61 #include "third_party/WebKit/public/platform/WebSize.h" |
62 #include "third_party/WebKit/public/platform/WebString.h" | 62 #include "third_party/WebKit/public/platform/WebString.h" |
63 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc heduling_state.h" | 63 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc heduling_state.h" |
64 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h" | 64 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h" |
65 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" | 65 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" |
66 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 66 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
67 #include "third_party/WebKit/public/web/WebInputMethodController.h" | |
67 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 68 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
68 #include "third_party/WebKit/public/web/WebNode.h" | 69 #include "third_party/WebKit/public/web/WebNode.h" |
69 #include "third_party/WebKit/public/web/WebPagePopup.h" | 70 #include "third_party/WebKit/public/web/WebPagePopup.h" |
70 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" | 71 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" |
71 #include "third_party/WebKit/public/web/WebRange.h" | 72 #include "third_party/WebKit/public/web/WebRange.h" |
72 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 73 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
73 #include "third_party/WebKit/public/web/WebView.h" | 74 #include "third_party/WebKit/public/web/WebView.h" |
74 #include "third_party/WebKit/public/web/WebWidget.h" | 75 #include "third_party/WebKit/public/web/WebWidget.h" |
75 #include "third_party/skia/include/core/SkShader.h" | 76 #include "third_party/skia/include/core/SkShader.h" |
76 #include "ui/base/ui_base_switches.h" | 77 #include "ui/base/ui_base_switches.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
99 #if defined(OS_MACOSX) | 100 #if defined(OS_MACOSX) |
100 #include "content/renderer/text_input_client_observer.h" | 101 #include "content/renderer/text_input_client_observer.h" |
101 #endif | 102 #endif |
102 | 103 |
103 using blink::WebCompositionUnderline; | 104 using blink::WebCompositionUnderline; |
104 using blink::WebCursorInfo; | 105 using blink::WebCursorInfo; |
105 using blink::WebDeviceEmulationParams; | 106 using blink::WebDeviceEmulationParams; |
106 using blink::WebGestureEvent; | 107 using blink::WebGestureEvent; |
107 using blink::WebInputEvent; | 108 using blink::WebInputEvent; |
108 using blink::WebInputEventResult; | 109 using blink::WebInputEventResult; |
110 using blink::WebInputMethodController; | |
109 using blink::WebKeyboardEvent; | 111 using blink::WebKeyboardEvent; |
110 using blink::WebMouseEvent; | 112 using blink::WebMouseEvent; |
111 using blink::WebMouseWheelEvent; | 113 using blink::WebMouseWheelEvent; |
112 using blink::WebNavigationPolicy; | 114 using blink::WebNavigationPolicy; |
113 using blink::WebNode; | 115 using blink::WebNode; |
114 using blink::WebPagePopup; | 116 using blink::WebPagePopup; |
115 using blink::WebPoint; | 117 using blink::WebPoint; |
116 using blink::WebPopupType; | 118 using blink::WebPopupType; |
117 using blink::WebRange; | 119 using blink::WebRange; |
118 using blink::WebRect; | 120 using blink::WebRect; |
(...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1389 } | 1391 } |
1390 #endif | 1392 #endif |
1391 if (replacement_range.IsValid()) { | 1393 if (replacement_range.IsValid()) { |
1392 GetWebWidget()->applyReplacementRange( | 1394 GetWebWidget()->applyReplacementRange( |
1393 WebRange(replacement_range.start(), replacement_range.length())); | 1395 WebRange(replacement_range.start(), replacement_range.length())); |
1394 } | 1396 } |
1395 | 1397 |
1396 if (!ShouldHandleImeEvent()) | 1398 if (!ShouldHandleImeEvent()) |
1397 return; | 1399 return; |
1398 ImeEventGuard guard(this); | 1400 ImeEventGuard guard(this); |
1399 if (!GetWebWidget()->setComposition( | 1401 auto* controller = GetInputMethodController(); |
Charlie Reis
2016/11/02 20:57:38
nit: Let's avoid auto here. It's helpful to know
EhsanK
2016/11/02 22:16:34
Acknowledged.
| |
1402 DCHECK(controller); | |
1403 if (!controller || | |
1404 !controller->setComposition( | |
1400 text, WebVector<WebCompositionUnderline>(underlines), selection_start, | 1405 text, WebVector<WebCompositionUnderline>(underlines), selection_start, |
1401 selection_end)) { | 1406 selection_end)) { |
1402 // If we failed to set the composition text, then we need to let the browser | 1407 // If we failed to set the composition text, then we need to let the browser |
1403 // process to cancel the input method's ongoing composition session, to make | 1408 // process to cancel the input method's ongoing composition session, to make |
1404 // sure we are in a consistent state. | 1409 // sure we are in a consistent state. |
1405 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1410 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1406 } | 1411 } |
1407 UpdateCompositionInfo(false /* not an immediate request */); | 1412 UpdateCompositionInfo(false /* not an immediate request */); |
1408 } | 1413 } |
1409 | 1414 |
1410 void RenderWidget::OnImeCommitText(const base::string16& text, | 1415 void RenderWidget::OnImeCommitText(const base::string16& text, |
1411 const gfx::Range& replacement_range, | 1416 const gfx::Range& replacement_range, |
1412 int relative_cursor_pos) { | 1417 int relative_cursor_pos) { |
1413 #if defined(ENABLE_PLUGINS) | 1418 #if defined(ENABLE_PLUGINS) |
1414 if (focused_pepper_plugin_) { | 1419 if (focused_pepper_plugin_) { |
1415 focused_pepper_plugin_->render_frame()->OnImeCommitText( | 1420 focused_pepper_plugin_->render_frame()->OnImeCommitText( |
1416 text, replacement_range, relative_cursor_pos); | 1421 text, replacement_range, relative_cursor_pos); |
1417 return; | 1422 return; |
1418 } | 1423 } |
1419 #endif | 1424 #endif |
1420 if (replacement_range.IsValid()) { | 1425 if (replacement_range.IsValid()) { |
1421 GetWebWidget()->applyReplacementRange( | 1426 GetWebWidget()->applyReplacementRange( |
1422 WebRange(replacement_range.start(), replacement_range.length())); | 1427 WebRange(replacement_range.start(), replacement_range.length())); |
1423 } | 1428 } |
1424 | 1429 |
1425 if (!ShouldHandleImeEvent()) | 1430 if (!ShouldHandleImeEvent()) |
1426 return; | 1431 return; |
1427 ImeEventGuard guard(this); | 1432 ImeEventGuard guard(this); |
1428 input_handler_->set_handling_input_event(true); | 1433 input_handler_->set_handling_input_event(true); |
1429 GetWebWidget()->commitText(text, relative_cursor_pos); | 1434 if (auto* controller = GetInputMethodController()) |
1435 controller->commitText(text, relative_cursor_pos); | |
1430 input_handler_->set_handling_input_event(false); | 1436 input_handler_->set_handling_input_event(false); |
1431 UpdateCompositionInfo(false /* not an immediate request */); | 1437 UpdateCompositionInfo(false /* not an immediate request */); |
1432 } | 1438 } |
1433 | 1439 |
1434 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { | 1440 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
1435 #if defined(ENABLE_PLUGINS) | 1441 #if defined(ENABLE_PLUGINS) |
1436 if (focused_pepper_plugin_) { | 1442 if (focused_pepper_plugin_) { |
1437 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( | 1443 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( |
1438 keep_selection); | 1444 keep_selection); |
1439 return; | 1445 return; |
1440 } | 1446 } |
1441 #endif | 1447 #endif |
1442 | 1448 |
1443 if (!ShouldHandleImeEvent()) | 1449 if (!ShouldHandleImeEvent()) |
1444 return; | 1450 return; |
1445 ImeEventGuard guard(this); | 1451 ImeEventGuard guard(this); |
1446 input_handler_->set_handling_input_event(true); | 1452 input_handler_->set_handling_input_event(true); |
1447 GetWebWidget()->finishComposingText(keep_selection | 1453 if (auto* controller = GetInputMethodController()) { |
1448 ? WebWidget::KeepSelection | 1454 controller->finishComposingText( |
1449 : WebWidget::DoNotKeepSelection); | 1455 keep_selection ? WebInputMethodController::KeepSelection |
1456 : WebInputMethodController::DoNotKeepSelection); | |
1457 } | |
1450 input_handler_->set_handling_input_event(false); | 1458 input_handler_->set_handling_input_event(false); |
1451 UpdateCompositionInfo(false /* not an immediate request */); | 1459 UpdateCompositionInfo(false /* not an immediate request */); |
1452 } | 1460 } |
1453 | 1461 |
1454 void RenderWidget::OnDeviceScaleFactorChanged() { | 1462 void RenderWidget::OnDeviceScaleFactorChanged() { |
1455 if (!compositor_) | 1463 if (!compositor_) |
1456 return; | 1464 return; |
1457 if (IsUseZoomForDSFEnabled()) | 1465 if (IsUseZoomForDSFEnabled()) |
1458 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); | 1466 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); |
1459 else | 1467 else |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1946 return web_screen_info; | 1954 return web_screen_info; |
1947 } | 1955 } |
1948 | 1956 |
1949 void RenderWidget::resetInputMethod() { | 1957 void RenderWidget::resetInputMethod() { |
1950 ImeEventGuard guard(this); | 1958 ImeEventGuard guard(this); |
1951 // If the last text input type is not None, then we should finish any | 1959 // If the last text input type is not None, then we should finish any |
1952 // ongoing composition regardless of the new text input type. | 1960 // ongoing composition regardless of the new text input type. |
1953 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { | 1961 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
1954 // If a composition text exists, then we need to let the browser process | 1962 // If a composition text exists, then we need to let the browser process |
1955 // to cancel the input method's ongoing composition session. | 1963 // to cancel the input method's ongoing composition session. |
1956 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) | 1964 auto* controller = GetInputMethodController(); |
1965 if (controller && | |
1966 controller->finishComposingText( | |
1967 WebInputMethodController::DoNotKeepSelection)) | |
1957 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1968 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
1958 } | 1969 } |
1959 | 1970 |
1960 UpdateCompositionInfo(false /* not an immediate request */); | 1971 UpdateCompositionInfo(false /* not an immediate request */); |
1961 } | 1972 } |
1962 | 1973 |
1963 #if defined(OS_ANDROID) | 1974 #if defined(OS_ANDROID) |
1964 void RenderWidget::showUnhandledTapUIIfNeeded( | 1975 void RenderWidget::showUnhandledTapUIIfNeeded( |
1965 const WebPoint& tapped_position, | 1976 const WebPoint& tapped_position, |
1966 const WebNode& tapped_node, | 1977 const WebNode& tapped_node, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2087 | 2098 |
2088 bool RenderWidget::isPointerLocked() { | 2099 bool RenderWidget::isPointerLocked() { |
2089 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2100 return mouse_lock_dispatcher_->IsMouseLockedTo( |
2090 webwidget_mouse_lock_target_.get()); | 2101 webwidget_mouse_lock_target_.get()); |
2091 } | 2102 } |
2092 | 2103 |
2093 blink::WebWidget* RenderWidget::GetWebWidget() const { | 2104 blink::WebWidget* RenderWidget::GetWebWidget() const { |
2094 return webwidget_internal_; | 2105 return webwidget_internal_; |
2095 } | 2106 } |
2096 | 2107 |
2108 blink::WebInputMethodController* RenderWidget::GetInputMethodController() | |
2109 const { | |
2110 // TODO(ekaramad): Will this DCHECK ever fire? Remove when GetWebWidget() is | |
2111 // always a WebFrameWidget. | |
2112 DCHECK(GetWebWidget()->isWebFrameWidget()); | |
Charlie Reis
2016/11/02 20:57:38
This can't be a DCHECK, since we'll get a potentia
EhsanK
2016/11/02 22:16:34
I see. Thanks! I don't think we can have a WebWidg
| |
2113 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | |
2114 ->getActiveWebInputMethodController(); | |
2115 } | |
2116 | |
2097 } // namespace content | 2117 } // namespace content |
OLD | NEW |