| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 #include "skia/ext/platform_canvas.h" | 61 #include "skia/ext/platform_canvas.h" |
| 62 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 62 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| 63 #include "third_party/WebKit/public/platform/WebPoint.h" | 63 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 64 #include "third_party/WebKit/public/platform/WebRect.h" | 64 #include "third_party/WebKit/public/platform/WebRect.h" |
| 65 #include "third_party/WebKit/public/platform/WebSize.h" | 65 #include "third_party/WebKit/public/platform/WebSize.h" |
| 66 #include "third_party/WebKit/public/platform/WebString.h" | 66 #include "third_party/WebKit/public/platform/WebString.h" |
| 67 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc
heduling_state.h" | 67 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc
heduling_state.h" |
| 68 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" | 68 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" |
| 69 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" | 69 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" |
| 70 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 70 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
| 71 #include "third_party/WebKit/public/web/WebInputMethodController.h" |
| 71 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 72 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 72 #include "third_party/WebKit/public/web/WebNode.h" | 73 #include "third_party/WebKit/public/web/WebNode.h" |
| 73 #include "third_party/WebKit/public/web/WebPagePopup.h" | 74 #include "third_party/WebKit/public/web/WebPagePopup.h" |
| 74 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" | 75 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" |
| 75 #include "third_party/WebKit/public/web/WebRange.h" | 76 #include "third_party/WebKit/public/web/WebRange.h" |
| 76 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 77 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 77 #include "third_party/WebKit/public/web/WebView.h" | 78 #include "third_party/WebKit/public/web/WebView.h" |
| 78 #include "third_party/WebKit/public/web/WebWidget.h" | 79 #include "third_party/WebKit/public/web/WebWidget.h" |
| 79 #include "third_party/skia/include/core/SkShader.h" | 80 #include "third_party/skia/include/core/SkShader.h" |
| 80 #include "ui/base/ui_base_switches.h" | 81 #include "ui/base/ui_base_switches.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 105 | 106 |
| 106 using blink::WebCompositionUnderline; | 107 using blink::WebCompositionUnderline; |
| 107 using blink::WebCursorInfo; | 108 using blink::WebCursorInfo; |
| 108 using blink::WebDeviceEmulationParams; | 109 using blink::WebDeviceEmulationParams; |
| 109 using blink::WebDragOperationsMask; | 110 using blink::WebDragOperationsMask; |
| 110 using blink::WebDragData; | 111 using blink::WebDragData; |
| 111 using blink::WebGestureEvent; | 112 using blink::WebGestureEvent; |
| 112 using blink::WebImage; | 113 using blink::WebImage; |
| 113 using blink::WebInputEvent; | 114 using blink::WebInputEvent; |
| 114 using blink::WebInputEventResult; | 115 using blink::WebInputEventResult; |
| 116 using blink::WebInputMethodController; |
| 115 using blink::WebKeyboardEvent; | 117 using blink::WebKeyboardEvent; |
| 116 using blink::WebLocalFrame; | 118 using blink::WebLocalFrame; |
| 117 using blink::WebMouseEvent; | 119 using blink::WebMouseEvent; |
| 118 using blink::WebMouseWheelEvent; | 120 using blink::WebMouseWheelEvent; |
| 119 using blink::WebNavigationPolicy; | 121 using blink::WebNavigationPolicy; |
| 120 using blink::WebNode; | 122 using blink::WebNode; |
| 121 using blink::WebPagePopup; | 123 using blink::WebPagePopup; |
| 122 using blink::WebPoint; | 124 using blink::WebPoint; |
| 123 using blink::WebPopupType; | 125 using blink::WebPopupType; |
| 124 using blink::WebRange; | 126 using blink::WebRange; |
| (...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 } | 1407 } |
| 1406 #endif | 1408 #endif |
| 1407 if (replacement_range.IsValid()) { | 1409 if (replacement_range.IsValid()) { |
| 1408 GetWebWidget()->applyReplacementRange( | 1410 GetWebWidget()->applyReplacementRange( |
| 1409 WebRange(replacement_range.start(), replacement_range.length())); | 1411 WebRange(replacement_range.start(), replacement_range.length())); |
| 1410 } | 1412 } |
| 1411 | 1413 |
| 1412 if (!ShouldHandleImeEvent()) | 1414 if (!ShouldHandleImeEvent()) |
| 1413 return; | 1415 return; |
| 1414 ImeEventGuard guard(this); | 1416 ImeEventGuard guard(this); |
| 1415 if (!GetWebWidget()->setComposition( | 1417 blink::WebInputMethodController* controller = GetInputMethodController(); |
| 1418 DCHECK(controller); |
| 1419 if (!controller || |
| 1420 !controller->setComposition( |
| 1416 text, WebVector<WebCompositionUnderline>(underlines), selection_start, | 1421 text, WebVector<WebCompositionUnderline>(underlines), selection_start, |
| 1417 selection_end)) { | 1422 selection_end)) { |
| 1418 // If we failed to set the composition text, then we need to let the browser | 1423 // If we failed to set the composition text, then we need to let the browser |
| 1419 // process to cancel the input method's ongoing composition session, to make | 1424 // process to cancel the input method's ongoing composition session, to make |
| 1420 // sure we are in a consistent state. | 1425 // sure we are in a consistent state. |
| 1421 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1426 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1422 } | 1427 } |
| 1423 UpdateCompositionInfo(false /* not an immediate request */); | 1428 UpdateCompositionInfo(false /* not an immediate request */); |
| 1424 } | 1429 } |
| 1425 | 1430 |
| 1426 void RenderWidget::OnImeCommitText(const base::string16& text, | 1431 void RenderWidget::OnImeCommitText(const base::string16& text, |
| 1427 const gfx::Range& replacement_range, | 1432 const gfx::Range& replacement_range, |
| 1428 int relative_cursor_pos) { | 1433 int relative_cursor_pos) { |
| 1429 #if defined(ENABLE_PLUGINS) | 1434 #if defined(ENABLE_PLUGINS) |
| 1430 if (focused_pepper_plugin_) { | 1435 if (focused_pepper_plugin_) { |
| 1431 focused_pepper_plugin_->render_frame()->OnImeCommitText( | 1436 focused_pepper_plugin_->render_frame()->OnImeCommitText( |
| 1432 text, replacement_range, relative_cursor_pos); | 1437 text, replacement_range, relative_cursor_pos); |
| 1433 return; | 1438 return; |
| 1434 } | 1439 } |
| 1435 #endif | 1440 #endif |
| 1436 if (replacement_range.IsValid()) { | 1441 if (replacement_range.IsValid()) { |
| 1437 GetWebWidget()->applyReplacementRange( | 1442 GetWebWidget()->applyReplacementRange( |
| 1438 WebRange(replacement_range.start(), replacement_range.length())); | 1443 WebRange(replacement_range.start(), replacement_range.length())); |
| 1439 } | 1444 } |
| 1440 | 1445 |
| 1441 if (!ShouldHandleImeEvent()) | 1446 if (!ShouldHandleImeEvent()) |
| 1442 return; | 1447 return; |
| 1443 ImeEventGuard guard(this); | 1448 ImeEventGuard guard(this); |
| 1444 input_handler_->set_handling_input_event(true); | 1449 input_handler_->set_handling_input_event(true); |
| 1445 GetWebWidget()->commitText(text, relative_cursor_pos); | 1450 if (auto* controller = GetInputMethodController()) |
| 1451 controller->commitText(text, relative_cursor_pos); |
| 1446 input_handler_->set_handling_input_event(false); | 1452 input_handler_->set_handling_input_event(false); |
| 1447 UpdateCompositionInfo(false /* not an immediate request */); | 1453 UpdateCompositionInfo(false /* not an immediate request */); |
| 1448 } | 1454 } |
| 1449 | 1455 |
| 1450 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { | 1456 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
| 1451 #if defined(ENABLE_PLUGINS) | 1457 #if defined(ENABLE_PLUGINS) |
| 1452 if (focused_pepper_plugin_) { | 1458 if (focused_pepper_plugin_) { |
| 1453 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( | 1459 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( |
| 1454 keep_selection); | 1460 keep_selection); |
| 1455 return; | 1461 return; |
| 1456 } | 1462 } |
| 1457 #endif | 1463 #endif |
| 1458 | 1464 |
| 1459 if (!ShouldHandleImeEvent()) | 1465 if (!ShouldHandleImeEvent()) |
| 1460 return; | 1466 return; |
| 1461 ImeEventGuard guard(this); | 1467 ImeEventGuard guard(this); |
| 1462 input_handler_->set_handling_input_event(true); | 1468 input_handler_->set_handling_input_event(true); |
| 1463 GetWebWidget()->finishComposingText(keep_selection | 1469 if (auto* controller = GetInputMethodController()) { |
| 1464 ? WebWidget::KeepSelection | 1470 controller->finishComposingText( |
| 1465 : WebWidget::DoNotKeepSelection); | 1471 keep_selection ? WebInputMethodController::KeepSelection |
| 1472 : WebInputMethodController::DoNotKeepSelection); |
| 1473 } |
| 1466 input_handler_->set_handling_input_event(false); | 1474 input_handler_->set_handling_input_event(false); |
| 1467 UpdateCompositionInfo(false /* not an immediate request */); | 1475 UpdateCompositionInfo(false /* not an immediate request */); |
| 1468 } | 1476 } |
| 1469 | 1477 |
| 1470 void RenderWidget::OnDeviceScaleFactorChanged() { | 1478 void RenderWidget::OnDeviceScaleFactorChanged() { |
| 1471 if (!compositor_) | 1479 if (!compositor_) |
| 1472 return; | 1480 return; |
| 1473 if (IsUseZoomForDSFEnabled()) | 1481 if (IsUseZoomForDSFEnabled()) |
| 1474 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); | 1482 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor()); |
| 1475 else | 1483 else |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1933 return web_screen_info; | 1941 return web_screen_info; |
| 1934 } | 1942 } |
| 1935 | 1943 |
| 1936 void RenderWidget::resetInputMethod() { | 1944 void RenderWidget::resetInputMethod() { |
| 1937 ImeEventGuard guard(this); | 1945 ImeEventGuard guard(this); |
| 1938 // If the last text input type is not None, then we should finish any | 1946 // If the last text input type is not None, then we should finish any |
| 1939 // ongoing composition regardless of the new text input type. | 1947 // ongoing composition regardless of the new text input type. |
| 1940 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { | 1948 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
| 1941 // If a composition text exists, then we need to let the browser process | 1949 // If a composition text exists, then we need to let the browser process |
| 1942 // to cancel the input method's ongoing composition session. | 1950 // to cancel the input method's ongoing composition session. |
| 1943 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection)) | 1951 blink::WebInputMethodController* controller = GetInputMethodController(); |
| 1952 if (controller && |
| 1953 controller->finishComposingText( |
| 1954 WebInputMethodController::DoNotKeepSelection)) |
| 1944 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1955 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1945 } | 1956 } |
| 1946 | 1957 |
| 1947 UpdateCompositionInfo(false /* not an immediate request */); | 1958 UpdateCompositionInfo(false /* not an immediate request */); |
| 1948 } | 1959 } |
| 1949 | 1960 |
| 1950 #if defined(OS_ANDROID) | 1961 #if defined(OS_ANDROID) |
| 1951 void RenderWidget::showUnhandledTapUIIfNeeded( | 1962 void RenderWidget::showUnhandledTapUIIfNeeded( |
| 1952 const WebPoint& tapped_position, | 1963 const WebPoint& tapped_position, |
| 1953 const WebNode& tapped_node, | 1964 const WebNode& tapped_node, |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2089 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y); | 2100 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y); |
| 2090 Send(new DragHostMsg_StartDragging(routing_id_, drop_data, mask, | 2101 Send(new DragHostMsg_StartDragging(routing_id_, drop_data, mask, |
| 2091 image.getSkBitmap(), imageOffset, | 2102 image.getSkBitmap(), imageOffset, |
| 2092 possible_drag_event_info_)); | 2103 possible_drag_event_info_)); |
| 2093 } | 2104 } |
| 2094 | 2105 |
| 2095 blink::WebWidget* RenderWidget::GetWebWidget() const { | 2106 blink::WebWidget* RenderWidget::GetWebWidget() const { |
| 2096 return webwidget_internal_; | 2107 return webwidget_internal_; |
| 2097 } | 2108 } |
| 2098 | 2109 |
| 2110 blink::WebInputMethodController* RenderWidget::GetInputMethodController() |
| 2111 const { |
| 2112 // TODO(ekaramad): Remove this CHECK when GetWebWidget() is |
| 2113 // always a WebFrameWidget. |
| 2114 CHECK(GetWebWidget()->isWebFrameWidget()); |
| 2115 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
| 2116 ->getActiveWebInputMethodController(); |
| 2117 } |
| 2118 |
| 2099 } // namespace content | 2119 } // namespace content |
| OLD | NEW |