| 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 DCHECK(GetInputMethodController()); |
| 1406 if (!GetInputMethodController() || |
| 1407 !GetInputMethodController()->setComposition( |
| 1404 text, WebVector<WebCompositionUnderline>(underlines), selection_start, | 1408 text, WebVector<WebCompositionUnderline>(underlines), selection_start, |
| 1405 selection_end)) { | 1409 selection_end)) { |
| 1406 // If we failed to set the composition text, then we need to let the browser | 1410 // 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 | 1411 // process to cancel the input method's ongoing composition session, to make |
| 1408 // sure we are in a consistent state. | 1412 // sure we are in a consistent state. |
| 1409 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1413 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1410 } | 1414 } |
| 1411 UpdateCompositionInfo(false /* not an immediate request */); | 1415 UpdateCompositionInfo(false /* not an immediate request */); |
| 1412 } | 1416 } |
| 1413 | 1417 |
| 1414 void RenderWidget::OnImeCommitText(const base::string16& text, | 1418 void RenderWidget::OnImeCommitText(const base::string16& text, |
| 1415 const gfx::Range& replacement_range, | 1419 const gfx::Range& replacement_range, |
| 1416 int relative_cursor_pos) { | 1420 int relative_cursor_pos) { |
| 1417 #if defined(ENABLE_PLUGINS) | 1421 #if defined(ENABLE_PLUGINS) |
| 1418 if (focused_pepper_plugin_) { | 1422 if (focused_pepper_plugin_) { |
| 1419 focused_pepper_plugin_->render_frame()->OnImeCommitText( | 1423 focused_pepper_plugin_->render_frame()->OnImeCommitText( |
| 1420 text, replacement_range, relative_cursor_pos); | 1424 text, replacement_range, relative_cursor_pos); |
| 1421 return; | 1425 return; |
| 1422 } | 1426 } |
| 1423 #endif | 1427 #endif |
| 1424 if (replacement_range.IsValid()) { | 1428 if (replacement_range.IsValid()) { |
| 1425 GetWebWidget()->applyReplacementRange( | 1429 GetWebWidget()->applyReplacementRange( |
| 1426 WebRange(replacement_range.start(), replacement_range.length())); | 1430 WebRange(replacement_range.start(), replacement_range.length())); |
| 1427 } | 1431 } |
| 1428 | 1432 |
| 1429 if (!ShouldHandleImeEvent()) | 1433 if (!ShouldHandleImeEvent()) |
| 1430 return; | 1434 return; |
| 1431 ImeEventGuard guard(this); | 1435 ImeEventGuard guard(this); |
| 1432 input_handler_->set_handling_input_event(true); | 1436 input_handler_->set_handling_input_event(true); |
| 1433 GetWebWidget()->commitText(text, relative_cursor_pos); | 1437 if (GetInputMethodController()) |
| 1438 GetInputMethodController()->commitText(text, relative_cursor_pos); |
| 1434 input_handler_->set_handling_input_event(false); | 1439 input_handler_->set_handling_input_event(false); |
| 1435 UpdateCompositionInfo(false /* not an immediate request */); | 1440 UpdateCompositionInfo(false /* not an immediate request */); |
| 1436 } | 1441 } |
| 1437 | 1442 |
| 1438 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { | 1443 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
| 1439 #if defined(ENABLE_PLUGINS) | 1444 #if defined(ENABLE_PLUGINS) |
| 1440 if (focused_pepper_plugin_) { | 1445 if (focused_pepper_plugin_) { |
| 1441 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( | 1446 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( |
| 1442 keep_selection); | 1447 keep_selection); |
| 1443 return; | 1448 return; |
| 1444 } | 1449 } |
| 1445 #endif | 1450 #endif |
| 1446 | 1451 |
| 1447 if (!ShouldHandleImeEvent()) | 1452 if (!ShouldHandleImeEvent()) |
| 1448 return; | 1453 return; |
| 1449 ImeEventGuard guard(this); | 1454 ImeEventGuard guard(this); |
| 1450 input_handler_->set_handling_input_event(true); | 1455 input_handler_->set_handling_input_event(true); |
| 1451 GetWebWidget()->finishComposingText(keep_selection | 1456 if (GetInputMethodController()) { |
| 1452 ? WebWidget::KeepSelection | 1457 GetInputMethodController()->finishComposingText( |
| 1453 : WebWidget::DoNotKeepSelection); | 1458 keep_selection ? WebInputMethodController::KeepSelection |
| 1459 : WebInputMethodController::DoNotKeepSelection); |
| 1460 } |
| 1454 input_handler_->set_handling_input_event(false); | 1461 input_handler_->set_handling_input_event(false); |
| 1455 UpdateCompositionInfo(false /* not an immediate request */); | 1462 UpdateCompositionInfo(false /* not an immediate request */); |
| 1456 } | 1463 } |
| 1457 | 1464 |
| 1458 void RenderWidget::OnDeviceScaleFactorChanged() { | 1465 void RenderWidget::OnDeviceScaleFactorChanged() { |
| 1459 if (!compositor_) | 1466 if (!compositor_) |
| 1460 return; | 1467 return; |
| 1461 if (IsUseZoomForDSFEnabled()) | 1468 if (IsUseZoomForDSFEnabled()) |
| 1462 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); | 1469 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); |
| 1463 else | 1470 else |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 return web_screen_info; | 1980 return web_screen_info; |
| 1974 } | 1981 } |
| 1975 | 1982 |
| 1976 void RenderWidget::resetInputMethod() { | 1983 void RenderWidget::resetInputMethod() { |
| 1977 ImeEventGuard guard(this); | 1984 ImeEventGuard guard(this); |
| 1978 // If the last text input type is not None, then we should finish any | 1985 // If the last text input type is not None, then we should finish any |
| 1979 // ongoing composition regardless of the new text input type. | 1986 // ongoing composition regardless of the new text input type. |
| 1980 if (text_input_info_.type != blink::WebTextInputTypeNone) { | 1987 if (text_input_info_.type != blink::WebTextInputTypeNone) { |
| 1981 // If a composition text exists, then we need to let the browser process | 1988 // If a composition text exists, then we need to let the browser process |
| 1982 // to cancel the input method's ongoing composition session. | 1989 // to cancel the input method's ongoing composition session. |
| 1983 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) | 1990 if (GetInputMethodController() && |
| 1991 GetInputMethodController()->finishComposingText( |
| 1992 WebInputMethodController::DoNotKeepSelection)) |
| 1984 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1993 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1985 } | 1994 } |
| 1986 | 1995 |
| 1987 UpdateCompositionInfo(false /* not an immediate request */); | 1996 UpdateCompositionInfo(false /* not an immediate request */); |
| 1988 } | 1997 } |
| 1989 | 1998 |
| 1990 #if defined(OS_ANDROID) | 1999 #if defined(OS_ANDROID) |
| 1991 void RenderWidget::showUnhandledTapUIIfNeeded( | 2000 void RenderWidget::showUnhandledTapUIIfNeeded( |
| 1992 const WebPoint& tapped_position, | 2001 const WebPoint& tapped_position, |
| 1993 const WebNode& tapped_node, | 2002 const WebNode& tapped_node, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 | 2157 |
| 2149 bool RenderWidget::isPointerLocked() { | 2158 bool RenderWidget::isPointerLocked() { |
| 2150 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2159 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2151 webwidget_mouse_lock_target_.get()); | 2160 webwidget_mouse_lock_target_.get()); |
| 2152 } | 2161 } |
| 2153 | 2162 |
| 2154 blink::WebWidget* RenderWidget::GetWebWidget() const { | 2163 blink::WebWidget* RenderWidget::GetWebWidget() const { |
| 2155 return webwidget_internal_; | 2164 return webwidget_internal_; |
| 2156 } | 2165 } |
| 2157 | 2166 |
| 2167 blink::WebInputMethodController* RenderWidget::GetInputMethodController() |
| 2168 const { |
| 2169 // TODO(ekaramad): Will this DCHECK ever fire? Remove when GetWebWidget() is |
| 2170 // always a WebFrameWidget. |
| 2171 DCHECK(GetWebWidget()->isWebFrameWidget()); |
| 2172 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
| 2173 ->getActiveWebInputMethodController(); |
| 2174 } |
| 2175 |
| 2158 } // namespace content | 2176 } // namespace content |
| OLD | NEW |