blob: 71831f671e0a01183537dfb26ba38e6d6ccc1731 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
dchengcedca5612016-04-09 01:40:157#include <memory>
dcheng07945f632015-12-26 07:59:328#include <utility>
9
[email protected]c27dd4f2014-05-22 18:05:1910#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2111#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0012#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1213#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/logging.h"
avi1023d012015-12-25 02:39:1415#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1516#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4017#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3018#include "base/message_loop/message_loop.h"
asvitkine8d51e9d2016-09-02 23:55:4319#include "base/metrics/histogram_macros.h"
[email protected]aa4117f2011-12-09 22:19:2120#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0021#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2722#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0123#include "base/trace_event/trace_event.h"
24#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "build/build_config.h"
danakj1120f4c2016-09-15 02:05:3226#include "cc/output/compositor_frame_sink.h"
jbroman6ccbc7d472016-07-27 04:45:4127#include "cc/output/copy_output_request.h"
fsamuel78f86e42016-01-20 04:10:2328#include "cc/scheduler/begin_frame_source.h"
oshima750cb4342015-10-31 00:59:0129#include "content/common/content_switches_internal.h"
[email protected]9017d7852013-11-21 17:47:3530#include "content/common/input/synthetic_gesture_packet.h"
[email protected]c084330e02013-04-27 01:08:1531#include "content/common/input_messages.h"
jcivelliae1560a2016-11-01 22:40:2332#include "content/common/render_message_filter.mojom.h"
[email protected]992db4c2011-05-12 15:37:1533#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3834#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5035#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1236#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2937#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4238#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4039#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3940#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
[email protected]b2e4c70132013-10-03 02:07:5141#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1142#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1143#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2844#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2945#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1346#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3247#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1648#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2749#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0550#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4451#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5552#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4453#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0954#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0455#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4756#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1857#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4858#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1859#include "third_party/WebKit/public/platform/WebCursorInfo.h"
donnda070f3c2015-01-16 19:54:1160#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]aaf68892013-07-18 00:11:3062#include "third_party/WebKit/public/platform/WebSize.h"
63#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5164#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
65#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
[email protected]19193682014-04-03 15:01:4366#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5967#include "third_party/WebKit/public/web/WebFrameWidget.h"
68#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1169#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3170#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3171#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
72#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3873#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5974#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0875#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4176#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1377#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5078#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0979#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3280#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4881#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2782#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4183#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4884
[email protected]eeb93112013-05-01 19:41:1085#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1586#include <android/keycodes.h>
[email protected]eeb93112013-05-01 19:41:1087#endif
88
[email protected]661eb9d2009-02-03 02:11:4889#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4990#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5291#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4192#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4893#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4494
sadrul943e3b32016-08-04 18:22:5995#if defined(USE_AURA)
bend32292b2016-10-07 00:21:5896#include "content/public/common/service_manager_connection.h"
fsamuel2545ecc2015-12-05 00:44:4697#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:1998#endif
99
ekaramad330ba4232016-09-23 17:57:47100#if defined(OS_MACOSX)
101#include "content/renderer/text_input_client_observer.h"
102#endif
103
[email protected]180ef242013-11-07 06:50:46104using blink::WebCompositionUnderline;
105using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43106using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46107using blink::WebGestureEvent;
108using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49109using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46110using blink::WebKeyboardEvent;
111using blink::WebMouseEvent;
112using blink::WebMouseWheelEvent;
113using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11114using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46115using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11116using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46117using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48118using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46119using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46120using blink::WebSize;
121using blink::WebTextDirection;
122using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25123using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46124using blink::WebVector;
125using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26126
[email protected]6a4d7f62013-01-07 21:32:13127namespace {
[email protected]b256eca2013-07-11 10:57:40128
129typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
130
lfgbee1e0a2016-06-08 21:24:21131class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
132 public:
133 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
134 : webwidget_(webwidget) {}
135
136 void OnLockMouseACK(bool succeeded) override {
137 if (succeeded)
138 webwidget_->didAcquirePointerLock();
139 else
140 webwidget_->didNotAcquirePointerLock();
141 }
142
143 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
144
145 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
146 // The WebWidget handles mouse lock in Blink's handleInputEvent().
147 return false;
148 }
149
150 private:
151 blink::WebWidget* webwidget_;
152};
153
dglazkov97b6c2b2016-10-25 17:35:55154bool IsDateTimeInput(ui::TextInputType type) {
155 return type == ui::TEXT_INPUT_TYPE_DATE ||
156 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
157 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
158 type == ui::TEXT_INPUT_TYPE_MONTH ||
159 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
160}
161
fsamuele8326c742016-01-12 00:49:39162content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
163 content::RenderWidget* widget) {
sadrul943e3b32016-08-04 18:22:59164#if defined(USE_AURA)
penghuang639a1042016-01-14 21:25:29165 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
bend32292b2016-10-07 00:21:58166 if (content::ServiceManagerConnection::GetForProcess() &&
penghuang639a1042016-01-14 21:25:29167 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39168 return content::RenderWidgetMusConnection::GetOrCreate(
169 widget->routing_id());
170 }
171#endif
bend32292b2016-10-07 00:21:58172 // If we don't have a connection to the Service Manager, then we want to route
173 // IPCs back to the browser process rather than Mus so we use the |widget| as
174 // the RenderWidgetInputHandlerDelegate.
fsamuele8326c742016-01-12 00:49:39175 return widget;
176}
177
lfg1568d112016-08-30 16:06:29178content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
179 nullptr;
180
181content::RenderWidget::RenderWidgetInitializedCallback
182 g_render_widget_initialized = nullptr;
183
dtapuskac4dd5be2016-10-25 15:11:10184ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
185 // Check the type is in the range representable by ui::TextInputType.
186 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
187 << "blink::WebTextInputType and ui::TextInputType not synchronized";
188 return static_cast<ui::TextInputType>(type);
189}
190
191ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
192 // Check the mode is in the range representable by ui::TextInputMode.
193 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
194 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
195 return static_cast<ui::TextInputMode>(mode);
196}
197
[email protected]b256eca2013-07-11 10:57:40198} // namespace
199
[email protected]e9ff79c2012-10-19 21:31:26200namespace content {
[email protected]62cb33cae2009-03-27 23:30:22201
[email protected]b2e4c70132013-10-03 02:07:51202// RenderWidget ---------------------------------------------------------------
203
dcheng35d31c112015-07-22 00:17:36204RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
205 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27206 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04207 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03208 bool hidden,
209 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29210 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36211 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21212 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44213 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29214 opener_id_(MSG_ROUTING_NONE),
initial.commit09911bf2008-07-26 23:55:29215 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51216 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09217 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29218 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04219 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39220 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12221 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12222 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16223 ime_event_guard_(nullptr),
changwan46620072016-09-21 03:05:41224 ime_in_batch_edit_(false),
[email protected]661eb9d2009-02-03 02:11:48225 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22226 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44227 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20228 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55229 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40230 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20231 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53232 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18233 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12234 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48235 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04236 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27237 device_scale_factor_(screen_info_.device_scale_factor),
[email protected]0d1ebed12013-08-05 22:01:13238#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36239 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13240#endif
nonafa291792016-08-10 02:36:18241 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51242 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11243 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42244 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08245 has_host_context_menu_location_(false),
ekaramad2a46d632016-07-19 13:33:09246 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47247#if defined(OS_MACOSX)
248 text_input_client_observer_(new TextInputClientObserver(this)),
249#endif
ekaramad2a46d632016-07-19 13:33:09250 focused_pepper_plugin_(nullptr) {
[email protected]8b3f0eb2012-05-03 19:15:05251 if (!swapped_out)
252 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27253 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53254 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37255#if defined(OS_ANDROID)
256 text_input_info_history_.push_back(blink::WebTextInputInfo());
257#endif
alexclarke7fa93942015-10-21 15:37:11258
259 // In tests there may not be a RenderThreadImpl.
260 if (RenderThreadImpl::current()) {
261 render_widget_scheduling_state_ = RenderThreadImpl::current()
262 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32263 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11264 render_widget_scheduling_state_->SetHidden(is_hidden_);
265 }
initial.commit09911bf2008-07-26 23:55:29266}
267
268RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21269 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16270
[email protected]992db4c2011-05-12 15:37:15271 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02272 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15273 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29274}
275
[email protected]484955942010-08-19 16:13:18276// static
lfg1568d112016-08-30 16:06:29277void RenderWidget::InstallCreateHook(
278 CreateRenderWidgetFunction create_render_widget,
279 RenderWidgetInitializedCallback render_widget_initialized) {
280 CHECK(!g_create_render_widget && !g_render_widget_initialized);
281 g_create_render_widget = create_render_widget;
282 g_render_widget_initialized = render_widget_initialized;
283}
284
285// static
avi1023d012015-12-25 02:39:14286RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53287 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46288 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27289 const ScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29290 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36291 scoped_refptr<RenderWidget> widget(new RenderWidget(
292 compositor_deps, popup_type, screen_info, false, false, false));
293 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46294 return widget.get();
[email protected]a635f942012-12-07 10:34:29295 }
296 return NULL;
initial.commit09911bf2008-07-26 23:55:29297}
298
[email protected]484955942010-08-19 16:13:18299// static
kenrba7199832015-01-22 23:44:59300RenderWidget* RenderWidget::CreateForFrame(
301 int routing_id,
kenrba7199832015-01-22 23:44:59302 bool hidden,
ccameron2f451532016-09-07 21:49:27303 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59304 CompositorDependencies* compositor_deps,
305 blink::WebLocalFrame* frame) {
306 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55307 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
308 // same routing ID for both the view routing ID and the main frame widget
309 // routing ID. https://crbug.com/545684
310 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
311 if (view) {
avi8a45c1092016-03-01 16:12:34312 view->AttachWebFrameWidget(
313 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
314 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55315 }
dcheng35d31c112015-07-22 00:17:36316 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29317 g_create_render_widget
318 ? g_create_render_widget(compositor_deps, blink::WebPopupTypeNone,
319 screen_info, false, hidden, false)
320 : new RenderWidget(compositor_deps, blink::WebPopupTypeNone,
321 screen_info, false, hidden, false));
fsamuele8326c742016-01-12 00:49:39322 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20323 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59324 // DoInit increments the reference count on |widget|, keeping it alive after
325 // this function returns.
dcheng35d31c112015-07-22 00:17:36326 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59327 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
jcivelliae1560a2016-11-01 22:40:23328 CreateWidgetCallback())) {
lfg1568d112016-08-30 16:06:29329 if (g_render_widget_initialized)
330 g_render_widget_initialized(widget.get());
kenrba7199832015-01-22 23:44:59331 return widget.get();
332 }
333 return nullptr;
334}
335
336// static
lfgcaab5142016-02-26 19:06:52337blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08338 RenderWidget* render_widget,
339 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55340 if (!frame->parent()) {
341 // TODO(dcheng): The main frame widget currently has a special case.
342 // Eliminate this once WebView is no longer a WebWidget.
343 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
344 }
dchengda9b4bb2015-07-20 20:58:08345 return blink::WebFrameWidget::create(render_widget, frame);
346}
347
348// static
kenrba7199832015-01-22 23:44:59349blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18350 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46351 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18352 break;
[email protected]180ef242013-11-07 06:50:46353 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44354 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18355 default:
356 NOTREACHED();
357 }
358 return NULL;
359}
360
dchengda9b4bb2015-07-20 20:58:08361void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32362 OnClose();
kenrba7199832015-01-22 23:44:59363}
364
fsamuele8326c742016-01-12 00:49:39365void RenderWidget::SetRoutingID(int32_t routing_id) {
366 routing_id_ = routing_id;
367 input_handler_.reset(new RenderWidgetInputHandler(
368 GetRenderWidgetInputHandlerDelegate(this), this));
369}
370
alexmos78c9c0d2016-10-14 18:57:03371void RenderWidget::SetSwappedOut(bool is_swapped_out) {
372 // We should only toggle between states.
373 DCHECK(is_swapped_out_ != is_swapped_out);
374 is_swapped_out_ = is_swapped_out;
375
376 // If we are swapping out, we will call ReleaseProcess, allowing the process
377 // to exit if all of its RenderViews are swapped out. We wait until the
378 // WasSwappedOut call to do this, to allow the unload handler to finish.
379 // If we are swapping in, we call AddRefProcess to prevent the process from
380 // exiting.
381 if (!is_swapped_out_)
382 RenderProcess::current()->AddRefProcess();
383}
384
jcivelliae1560a2016-11-01 22:40:23385bool RenderWidget::CreateWidget(int32_t opener_id,
386 blink::WebPopupType popup_type,
387 int32_t* routing_id) {
388 RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
389 opener_id, popup_type, routing_id);
390 return true;
391}
392
avi1023d012015-12-25 02:39:14393bool RenderWidget::Init(int32_t opener_id) {
jcivelliae1560a2016-11-01 22:40:23394 bool success = DoInit(opener_id, RenderWidget::CreateWebWidget(this),
395 base::Bind(&RenderWidget::CreateWidget, base::Unretained(this),
396 opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39397 if (success) {
398 SetRoutingID(routing_id_);
399 return true;
400 }
401 return false;
[email protected]484955942010-08-19 16:13:18402}
403
avi1023d012015-12-25 02:39:14404bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06405 WebWidget* web_widget,
jcivelliae1560a2016-11-01 22:40:23406 CreateWidgetCallback create_widget_callback) {
lfg8ff33912016-09-13 20:59:21407 DCHECK(!webwidget_internal_);
initial.commit09911bf2008-07-26 23:55:29408
409 if (opener_id != MSG_ROUTING_NONE)
410 opener_id_ = opener_id;
411
lfg8ff33912016-09-13 20:59:21412 webwidget_internal_ = web_widget;
413 webwidget_mouse_lock_target_.reset(
414 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21415 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29416
kenrba7199832015-01-22 23:44:59417 bool result = true;
jcivelliae1560a2016-11-01 22:40:23418 if (!create_widget_callback.is_null())
419 result = std::move(create_widget_callback).Run();
kenrba7199832015-01-22 23:44:59420
initial.commit09911bf2008-07-26 23:55:29421 if (result) {
[email protected]380244092011-10-07 17:26:27422 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29423 // Take a reference on behalf of the RenderThread. This will be balanced
424 // when we receive ViewMsg_Close.
425 AddRef();
[email protected]b2db9272014-01-10 17:42:00426 if (RenderThreadImpl::current()) {
427 RenderThreadImpl::current()->WidgetCreated();
428 if (is_hidden_)
429 RenderThreadImpl::current()->WidgetHidden();
430 }
fsamuele8326c742016-01-12 00:49:39431
[email protected]a635f942012-12-07 10:34:29432 return true;
initial.commit09911bf2008-07-26 23:55:29433 } else {
[email protected]a635f942012-12-07 10:34:29434 // The above Send can fail when the tab is closing.
435 return false;
initial.commit09911bf2008-07-26 23:55:29436 }
437}
438
[email protected]949b6592014-08-20 13:17:52439void RenderWidget::WasSwappedOut() {
440 // If we have been swapped out and no one else is using this process,
441 // it's safe to exit now.
442 CHECK(is_swapped_out_);
443 RenderProcess::current()->ReleaseProcess();
444}
445
[email protected]b2e4c70132013-10-03 02:07:51446void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39447 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51448 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43449 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49450 popup_screen_origin_for_emulation_ = gfx::Point(
451 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
452 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56453 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27454 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51455}
456
[email protected]2d6836f42014-07-02 17:25:31457gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
458 if (screen_metrics_emulator_)
459 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
460 return anchor;
461}
462
haibinluc643d33c2016-06-03 02:22:34463#if defined(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51464void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39465 ExternalPopupMenu* popup,
466 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49467 popup->SetOriginScaleAndOffsetForEmulation(
468 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51469}
[email protected]53907862014-03-25 15:42:40470#endif
[email protected]b2e4c70132013-10-03 02:07:51471
472void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
473 if (screen_metrics_emulator_)
474 screen_metrics_emulator_->OnShowContextMenu(params);
475}
476
[email protected]a95986a82010-12-24 06:19:28477bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47478#if defined(OS_MACOSX)
479 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
480 return text_input_client_observer_->OnMessageReceived(message);
481#endif
lfgbee1e0a2016-06-08 21:24:21482 if (mouse_lock_dispatcher_ &&
483 mouse_lock_dispatcher_->OnMessageReceived(message))
484 return true;
485
[email protected]a95986a82010-12-24 06:19:28486 bool handled = true;
487 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15488 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22489 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
490 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22491 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29492 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
493 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
494 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15495 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46496 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
497 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15498 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35499 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
500 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28501 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28502 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20503 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
504 OnEnableDeviceEmulation)
505 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
506 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28507 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41508 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25509 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28510 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
511 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03512 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
fsamuele0f705b2016-10-01 14:07:14513 IPC_MESSAGE_HANDLER(ViewMsg_SetFrameSinkId, OnSetFrameSinkId)
lfg43e08e62016-02-03 18:51:37514 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
515 OnWaitNextFrameForTests)
nonafa291792016-08-10 02:36:18516 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
517 OnRequestCompositionUpdate)
[email protected]105dffb42013-02-20 03:46:21518#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37519 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39520 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
521 OnRequestTextInputStateUpdate)
changwan46620072016-09-21 03:05:41522 IPC_MESSAGE_HANDLER(InputMsg_ImeBatchEdit,
523 OnImeBatchEdit)
[email protected]2384b6c2013-02-28 23:58:51524 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21525#endif
dtrainor5ef644e2015-11-19 00:12:47526 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28527 IPC_MESSAGE_UNHANDLED(handled = false)
528 IPC_END_MESSAGE_MAP()
529 return handled;
530}
initial.commit09911bf2008-07-26 23:55:29531
532bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15533 // Don't send any messages after the browser has told us to close, and filter
534 // most outgoing messages while swapped out.
535 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26536 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11537 closing_) {
initial.commit09911bf2008-07-26 23:55:29538 delete message;
539 return false;
540 }
541
542 // If given a messsage without a routing ID, then assign our routing ID.
543 if (message->routing_id() == MSG_ROUTING_NONE)
544 message->set_routing_id(routing_id_);
545
[email protected]380244092011-10-07 17:26:27546 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44547}
548
bokanc007c3a2015-02-03 07:15:56549void RenderWidget::SetWindowRectSynchronously(
550 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39551 ResizeParams params;
552 params.screen_info = screen_info_;
553 params.new_size = new_window_rect.size();
554 params.physical_backing_size =
555 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39556 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39557 params.is_fullscreen_granted = is_fullscreen_granted_;
558 params.display_mode = display_mode_;
559 params.needs_resize_ack = false;
560 Resize(params);
561
bokanc007c3a2015-02-03 07:15:56562 view_screen_rect_ = new_window_rect;
563 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02564 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56565 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02566}
567
initial.commit09911bf2008-07-26 23:55:29568void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32569 DCHECK(content::RenderThread::Get());
570 if (closing_)
571 return;
572 NotifyOnClose();
573 closing_ = true;
574
575 // Browser correspondence is no longer needed at this point.
576 if (routing_id_ != MSG_ROUTING_NONE) {
577 RenderThread::Get()->RemoveRoute(routing_id_);
578 SetHidden(false);
579 if (RenderThreadImpl::current())
580 RenderThreadImpl::current()->WidgetDestroyed();
581 }
582
583 if (for_oopif_) {
584 // Widgets for frames may be created and closed at any time while the frame
585 // is alive. However, the closing process must happen synchronously. Frame
586 // widget and frames hold pointers to each other. If Close() is deferred to
587 // the message loop like in the non-frame widget case, WebWidget::close()
588 // can end up accessing members of an already-deleted frame.
589 Close();
590 } else {
591 // If there is a Send call on the stack, then it could be dangerous to close
592 // now. Post a task that only gets invoked when there are no nested message
593 // loops.
594 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
595 FROM_HERE, base::Bind(&RenderWidget::Close, this));
596 }
597
598 // Balances the AddRef taken when we called AddRoute.
599 Release();
initial.commit09911bf2008-07-26 23:55:29600}
601
fsamuel664e8b62016-01-20 19:54:01602void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04603 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32604 return;
605
[email protected]b2e4c70132013-10-03 02:07:51606 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39607 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51608 return;
609 }
610
mfomitchev2600fd7c2016-02-17 20:53:39611 Resize(params);
initial.commit09911bf2008-07-26 23:55:29612}
613
dgozman9260b0a12015-03-16 13:45:20614void RenderWidget::OnEnableDeviceEmulation(
615 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39616 if (!screen_metrics_emulator_) {
617 ResizeParams resize_params;
618 resize_params.screen_info = screen_info_;
619 resize_params.new_size = size_;
620 resize_params.physical_backing_size = physical_backing_size_;
621 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39622 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
623 resize_params.display_mode = display_mode_;
624 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
625 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18626 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39627 } else {
dgozman9260b0a12015-03-16 13:45:20628 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39629 }
dgozman9260b0a12015-03-16 13:45:20630}
631
632void RenderWidget::OnDisableDeviceEmulation() {
633 screen_metrics_emulator_.reset();
634}
635
initial.commit09911bf2008-07-26 23:55:29636void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31637 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29638 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03639 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55640 for (auto& observer : render_frames_)
641 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29642}
643
[email protected]3399dd822014-08-09 11:14:24644void RenderWidget::OnWasShown(bool needs_repainting,
645 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41646 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29647 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21648 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29649 return;
650
651 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03652 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55653 for (auto& observer : render_frames_)
654 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29655
[email protected]8a23afb32014-04-30 22:40:23656 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29657 return;
initial.commit09911bf2008-07-26 23:55:29658
659 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24660 if (compositor_) {
661 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15662 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24663 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05664 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24665 }
jdduke491a3f0c2015-06-15 23:30:26666 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29667}
668
[email protected]53d3f302009-12-21 04:42:05669void RenderWidget::OnRequestMoveAck() {
670 DCHECK(pending_window_rect_count_);
671 pending_window_rect_count_--;
[email protected]53d3f302009-12-21 04:42:05672}
673
[email protected]ed7defa2013-03-12 21:29:59674GURL RenderWidget::GetURLForGraphicsContext3D() {
675 return GURL();
[email protected]65225772011-05-12 21:10:24676}
677
fsamuel78f86e42016-01-20 04:10:23678void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10679 const ui::LatencyInfo& latency_info,
680 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23681 if (!input_event)
682 return;
dtapuska0bd451a2016-02-18 17:08:10683 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23684}
685
686void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21687 if (GetWebWidget())
688 GetWebWidget()->setCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23689}
690
691void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21692 if (GetWebWidget())
693 GetWebWidget()->mouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23694}
695
alexmos56567492016-09-13 00:52:46696void RenderWidget::OnSetEditCommandsForNextKeyEvent(
697 const EditCommands& edit_commands) {
698 edit_commands_ = edit_commands;
699}
700
fsamuel78f86e42016-01-20 04:10:23701void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08702 has_focus_ = enable;
703
lfg8ff33912016-09-13 20:59:21704 if (GetWebWidget())
705 GetWebWidget()->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08706
ericwilligers88e69742016-10-17 19:29:55707 for (auto& observer : render_frames_)
708 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23709}
710
dtapuska3d5624d32016-08-30 04:34:00711void RenderWidget::SetNeedsMainFrame() {
712 RenderWidgetCompositor* rwc = compositor();
713 if (!rwc)
714 return;
715 rwc->setNeedsBeginFrame();
716}
717
fsamuel78f86e42016-01-20 04:10:23718///////////////////////////////////////////////////////////////////////////////
719// RenderWidgetCompositorDelegate
720
721void RenderWidget::ApplyViewportDeltas(
722 const gfx::Vector2dF& inner_delta,
723 const gfx::Vector2dF& outer_delta,
724 const gfx::Vector2dF& elastic_overscroll_delta,
725 float page_scale,
726 float top_controls_delta) {
lfg8ff33912016-09-13 20:59:21727 GetWebWidget()->applyViewportDeltas(inner_delta, outer_delta,
728 elastic_overscroll_delta, page_scale,
729 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23730}
731
732void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska3d5624d32016-08-30 04:34:00733 RenderThreadImpl* render_thread = RenderThreadImpl::current();
734 // render_thread may be NULL in tests.
735 InputHandlerManager* input_handler_manager =
736 render_thread ? render_thread->input_handler_manager() : NULL;
737 if (input_handler_manager)
738 input_handler_manager->ProcessRafAlignedInputOnMainThread(routing_id_);
739
lfg8ff33912016-09-13 20:59:21740 GetWebWidget()->beginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23741}
742
danakj1120f4c2016-09-15 02:05:32743std::unique_ptr<cc::CompositorFrameSink>
744RenderWidget::CreateCompositorFrameSink(bool fallback) {
lfg8ff33912016-09-13 20:59:21745 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03746 // For widgets that are never visible, we don't start the compositor, so we
danakj1120f4c2016-09-15 02:05:32747 // never get a request for a cc::CompositorFrameSink.
sievers71c62dd52015-10-07 01:44:39748 DCHECK(!compositor_never_visible_);
danakj1120f4c2016-09-15 02:05:32749 return RenderThreadImpl::current()->CreateCompositorFrameSink(
danakj83066a32016-06-21 02:34:49750 fallback, routing_id_, frame_swap_message_queue_,
751 GetURLForGraphicsContext3D());
[email protected]ba91a792013-02-06 09:48:28752}
753
fsamuel78f86e42016-01-20 04:10:23754void RenderWidget::DidCommitAndDrawCompositorFrame() {
755 // NOTE: Tests may break if this event is renamed or moved. See
756 // tab_capture_performancetest.cc.
757 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08758
ericwilligers88e69742016-10-17 19:29:55759 for (auto& observer : render_frames_)
760 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08761
fsamuel78f86e42016-01-20 04:10:23762 // Notify subclasses that we initiated the paint operation.
763 DidInitiatePaint();
764}
765
766void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:55767 for (auto& observer : render_frames_)
768 observer.DidCommitCompositorFrame();
769 for (auto& observer : render_frame_proxies_)
770 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:23771}
772
773void RenderWidget::DidCompletePageScaleAnimation() {}
774
danakj6c872fc02016-10-22 04:29:49775void RenderWidget::DidReceiveCompositorFrameAck() {
776 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
fsamuel78f86e42016-01-20 04:10:23777
778 // Notify subclasses threaded composited rendering was flushed to the screen.
779 DidFlushPaint();
780
pimanbfb2ceb2016-03-18 21:32:58781 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23782 return;
783 }
784
785 ViewHostMsg_UpdateRect_Params params;
786 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23787 params.flags = next_paint_flags_;
788
789 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
790 next_paint_flags_ = 0;
791 need_update_rect_for_auto_resize_ = false;
792}
793
fsamuel78f86e42016-01-20 04:10:23794void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
795 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
796}
797
798bool RenderWidget::IsClosing() const {
799 return host_closing_;
800}
801
danakj53eccbc2016-03-02 22:51:07802void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23803 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29804}
805
fsamuel78f86e42016-01-20 04:10:23806void RenderWidget::UpdateVisualState() {
lfg8ff33912016-09-13 20:59:21807 GetWebWidget()->updateAllLifecyclePhases();
fsamuel78f86e42016-01-20 04:10:23808}
809
810void RenderWidget::WillBeginCompositorFrame() {
811 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
812
dglazkov06854c5c2016-08-31 00:19:59813 // The UpdateTextInputState can result in further layout and possibly
814 // enable GPU acceleration so they need to be called before any painting
815 // is done.
816 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
817 UpdateSelectionBounds();
818
ericwilligers88e69742016-10-17 19:29:55819 for (auto& observer : render_frame_proxies_)
820 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:29821}
822
jbroman6ccbc7d472016-07-27 04:45:41823std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
824 std::unique_ptr<cc::CopyOutputRequest> request) {
825 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
826 routing_id_, std::move(request));
827}
828
fsamuel72464894f2015-12-15 06:59:31829///////////////////////////////////////////////////////////////////////////////
830// RenderWidgetInputHandlerDelegate
831
avid7d6b2e2016-03-04 19:41:17832void RenderWidget::FocusChangeComplete() {
833 if (owner_delegate_)
834 owner_delegate_->RenderWidgetFocusChangeComplete();
835}
fsamuel72464894f2015-12-15 06:59:31836
837bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17838 if (owner_delegate_)
839 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
840
fsamuel72464894f2015-12-15 06:59:31841 return true;
842}
843
dtapuska1827dd22016-03-11 15:24:59844void RenderWidget::ObserveGestureEventAndResult(
845 const blink::WebGestureEvent& gesture_event,
846 const gfx::Vector2dF& unused_delta,
847 bool event_processed) {
848 if (!compositor_deps_->IsElasticOverscrollEnabled())
849 return;
850
851 cc::InputHandlerScrollResult scroll_result;
852 scroll_result.did_scroll = event_processed;
853 scroll_result.did_overscroll_root = !unused_delta.IsZero();
854 scroll_result.unused_scroll_delta = unused_delta;
855
856 RenderThreadImpl* render_thread = RenderThreadImpl::current();
857 InputHandlerManager* input_handler_manager =
858 render_thread ? render_thread->input_handler_manager() : NULL;
859 if (input_handler_manager) {
860 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
861 routing_id_, gesture_event, scroll_result);
862 }
863}
864
avid7d6b2e2016-03-04 19:41:17865void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:46866 ClearEditCommands();
867}
868
869void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
870 const std::string& value) {
871 ClearEditCommands();
872 edit_commands_.emplace_back(name, value);
873}
874
875void RenderWidget::ClearEditCommands() {
876 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:17877}
fsamuel72464894f2015-12-15 06:59:31878
chongza8ba91fc2016-08-16 21:39:17879void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:31880 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
881}
882
dchengcedca5612016-04-09 01:40:15883void RenderWidget::OnInputEventAck(
884 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:31885 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
886}
887
dtapuska46616922016-03-17 22:52:01888void RenderWidget::NotifyInputEventHandled(
dtapuskab08721e62016-06-29 03:35:07889 blink::WebInputEvent::Type handled_type,
890 InputEventAckState ack_result) {
dtapuska0bd451a2016-02-18 17:08:10891 RenderThreadImpl* render_thread = RenderThreadImpl::current();
892 InputHandlerManager* input_handler_manager =
893 render_thread ? render_thread->input_handler_manager() : NULL;
894 if (input_handler_manager) {
dtapuskab08721e62016-06-29 03:35:07895 input_handler_manager->NotifyInputEventHandledOnMainThread(
896 routing_id_, handled_type, ack_result);
dtapuska0bd451a2016-02-18 17:08:10897 }
898}
899
fsamuele8326c742016-01-12 00:49:39900void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
901 // Nothing to do here. RenderWidget created the |input_handler| and will take
902 // ownership of it. We just verify here that we don't already have an input
903 // handler.
904 DCHECK(!input_handler_);
905}
906
fsamuel72464894f2015-12-15 06:59:31907void RenderWidget::UpdateTextInputState(ShowIme show_ime,
908 ChangeSource change_source) {
909 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
910 if (ime_event_guard_) {
911 // show_ime should still be effective even if it was set inside the IME
912 // event guard.
913 if (show_ime == ShowIme::IF_NEEDED) {
914 ime_event_guard_->set_show_ime(true);
915 }
916 return;
917 }
918
dglazkov97b6c2b2016-10-25 17:35:55919 ui::TextInputType new_type = GetTextInputType();
920 if (IsDateTimeInput(new_type))
921 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:31922
dglazkov97b6c2b2016-10-25 17:35:55923 blink::WebTextInputInfo new_info;
924 if (GetWebWidget())
925 new_info = GetWebWidget()->textInputInfo();
dtapuskac4dd5be2016-10-25 15:11:10926 const ui::TextInputMode new_mode =
927 ConvertWebTextInputMode(new_info.inputMode);
fsamuel72464894f2015-12-15 06:59:31928
929 bool new_can_compose_inline = CanComposeInline();
930
931 // Only sends text input params if they are changed or if the ime should be
932 // shown.
933 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:39934 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
dglazkov97b6c2b2016-10-25 17:35:55935 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
936 text_input_info_ != new_info ||
fsamuel72464894f2015-12-15 06:59:31937 can_compose_inline_ != new_can_compose_inline)
938#if defined(OS_ANDROID)
939 || text_field_is_dirty_
940#endif
941 ) {
ekaramad9053e57b2016-04-26 20:00:38942 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:55943 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:31944 params.mode = new_mode;
945 params.flags = new_info.flags;
946 params.value = new_info.value.utf8();
947 params.selection_start = new_info.selectionStart;
948 params.selection_end = new_info.selectionEnd;
949 params.composition_start = new_info.compositionStart;
950 params.composition_end = new_info.compositionEnd;
951 params.can_compose_inline = new_can_compose_inline;
952 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
953#if defined(USE_AURA)
954 params.is_non_ime_change = true;
955#endif
956#if defined(OS_ANDROID)
957 params.is_non_ime_change =
958 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
changwan46620072016-09-21 03:05:41959 params.batch_edit = ime_in_batch_edit_;
fsamuel72464894f2015-12-15 06:59:31960 if (params.is_non_ime_change)
961 OnImeEventSentForAck(new_info);
962 text_field_is_dirty_ = false;
963#endif
964 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
965
966 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:55967 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:31968 text_input_mode_ = new_mode;
969 can_compose_inline_ = new_can_compose_inline;
970 text_input_flags_ = new_info.flags;
971 }
972}
973
974bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:17975 if (owner_delegate_)
976 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
977
fsamuel72464894f2015-12-15 06:59:31978 return false;
979}
980
981bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:55982 for (auto& observer : render_frames_)
983 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:08984
avid7d6b2e2016-03-04 19:41:17985 if (owner_delegate_)
986 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
987
fsamuel72464894f2015-12-15 06:59:31988 return false;
[email protected]fd847792013-10-24 17:12:35989}
990
initial.commit09911bf2008-07-26 23:55:29991///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:39992// RenderWidgetScreenMetricsDelegate
993
994void RenderWidget::Redraw() {
995 set_next_paint_is_resize_ack();
996 if (compositor_)
997 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
998}
999
bokanc63441c2016-04-27 15:49:121000void RenderWidget::ResizeWebWidget() {
lfg8ff33912016-09-13 20:59:211001 GetWebWidget()->resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121002}
1003
1004gfx::Size RenderWidget::GetSizeForWebWidget() const {
1005 if (IsUseZoomForDSFEnabled())
1006 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1007
1008 return size_;
1009}
1010
mfomitchev2600fd7c2016-02-17 20:53:391011void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581012 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271013 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1014 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581015
mfomitchev2600fd7c2016-02-17 20:53:391016 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581017
ccameron2f451532016-09-07 21:49:271018 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1019 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581020 OnDeviceScaleFactorChanged();
1021 ScheduleComposite();
1022 }
mfomitchev2600fd7c2016-02-17 20:53:391023
1024 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1025 // A resize ack shouldn't be requested if we have not ACK'd the previous
1026 // one.
1027 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1028 }
1029
1030 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211031 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391032 return;
1033
ianwene5fc5782016-08-18 04:05:151034 if (compositor_) {
mfomitchev2600fd7c2016-02-17 20:53:391035 compositor_->setViewportSize(params.physical_backing_size);
ianwene5fc5782016-08-18 04:05:151036 compositor_->setBottomControlsHeight(params.bottom_controls_height);
ccameronf408cab2016-09-14 16:54:421037 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
ianwene5fc5782016-08-18 04:05:151038 }
mfomitchev2600fd7c2016-02-17 20:53:391039
mfomitchev2600fd7c2016-02-17 20:53:391040 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391041
1042 // NOTE: We may have entered fullscreen mode without changing our size.
1043 bool fullscreen_change =
1044 is_fullscreen_granted_ != params.is_fullscreen_granted;
1045 is_fullscreen_granted_ = params.is_fullscreen_granted;
1046 display_mode_ = params.display_mode;
1047
bokanc63441c2016-04-27 15:49:121048 size_ = params.new_size;
1049 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391050
bokanc63441c2016-04-27 15:49:121051 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221052
mfomitchev2600fd7c2016-02-17 20:53:391053 WebSize visual_viewport_size;
1054
1055 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181056 visual_viewport_size = gfx::ScaleToCeiledSize(
1057 params.visible_viewport_size,
1058 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391059 } else {
1060 visual_viewport_size = visible_viewport_size_;
1061 }
1062
lfg8ff33912016-09-13 20:59:211063 GetWebWidget()->resizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391064
bokanc63441c2016-04-27 15:49:121065 // When resizing, we want to wait to paint before ACK'ing the resize. This
1066 // ensures that we only resize as fast as we can paint. We only need to
1067 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391068 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1069 // In this case there is no paint/composite and therefore no
1070 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1071 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1072 DCHECK(!params.needs_resize_ack);
1073 }
1074
1075 // Send the Resize_ACK flag once we paint again if requested.
1076 if (params.needs_resize_ack)
1077 set_next_paint_is_resize_ack();
1078
1079 if (fullscreen_change)
1080 DidToggleFullscreen();
1081
engedy6cb63c92016-02-23 14:14:581082 if (orientation_changed)
1083 OnOrientationChange();
1084
mfomitchev2600fd7c2016-02-17 20:53:391085 // If a resize ack is requested and it isn't set-up, then no more resizes will
1086 // come in and in general things will go wrong.
1087 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1088}
1089
1090void RenderWidget::SetScreenMetricsEmulationParameters(
1091 bool enabled,
1092 const blink::WebDeviceEmulationParams& params) {
1093 // This is only supported in RenderView.
1094 NOTREACHED();
1095}
1096
1097void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1098 const gfx::Rect& window_screen_rect) {
1099 view_screen_rect_ = view_screen_rect;
1100 window_screen_rect_ = window_screen_rect;
1101}
1102
1103///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461104// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291105
[email protected]3a1c8a8032013-03-18 22:35:321106void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401107 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051108 if (compositor_)
oshima750cb4342015-10-31 00:59:011109 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051110}
1111
[email protected]e195e582013-03-08 01:32:591112void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221113 DCHECK(!host_closing_);
1114
fsamuel78f86e42016-01-20 04:10:231115 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1116 compositor_deps_);
oshima750cb4342015-10-31 00:59:011117 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331118 OnDeviceScaleFactorChanged();
ccameronf408cab2016-09-14 16:54:421119 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
sievers71c62dd52015-10-07 01:44:391120 // For background pages and certain tests, we don't want to trigger
danakj1120f4c2016-09-15 02:05:321121 // CompositorFrameSink creation.
sievers71c62dd52015-10-07 01:44:391122 if (compositor_never_visible_ || !RenderThreadImpl::current())
1123 compositor_->SetNeverVisible();
1124
pimanc4af3072015-10-02 03:45:591125 StartCompositor();
[email protected]e195e582013-03-08 01:32:591126}
1127
ennef3c58142014-12-09 21:44:381128void RenderWidget::WillCloseLayerTreeView() {
1129 if (host_closing_)
1130 return;
1131
1132 // Prevent new compositors or output surfaces from being created.
1133 host_closing_ = true;
1134
[email protected]aeeedad2014-08-22 18:16:221135 // Always send this notification to prevent new layer tree views from
1136 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211137 if (blink::WebWidget* widget = GetWebWidget())
1138 widget->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221139}
1140
[email protected]180ef242013-11-07 06:50:461141blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281142 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061143}
1144
dglazkovf0e1d6d2015-10-10 02:13:481145void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1146 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1147 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1148 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1149 }
dglazkov79c426102015-08-31 21:22:431150
ericwilligers88e69742016-10-17 19:29:551151 for (auto& observer : render_frames_)
1152 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431153}
1154
jdduke491a3f0c2015-06-15 23:30:261155void RenderWidget::ScheduleComposite() {
1156 if (compositor_ &&
1157 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
skyostil32650d22016-09-26 16:58:231158 compositor_->setNeedsCompositorUpdate();
jdduke491a3f0c2015-06-15 23:30:261159 }
1160}
1161
1162void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1163 if (compositor_) {
1164 // Regardless of whether threaded compositing is enabled, always
1165 // use this mechanism to force the compositor to redraw. However,
1166 // the invalidation code path below is still needed for the
1167 // non-threaded case.
1168 compositor_->SetNeedsForcedRedraw();
1169 }
1170 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151171}
1172
[email protected]586871b2014-07-22 17:05:111173// static
dchengcedca5612016-04-09 01:40:151174std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111175 IPC::Message* msg,
1176 MessageDeliveryPolicy policy,
1177 FrameSwapMessageQueue* frame_swap_message_queue,
1178 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111179 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111180 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151181 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1182 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111183 &first_message_for_frame);
1184 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151185 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111186 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061187 return promise;
[email protected]586871b2014-07-22 17:05:111188 }
dcheng4b6b5ff2014-10-16 00:42:061189 return nullptr;
[email protected]586871b2014-07-22 17:05:111190}
1191
1192void RenderWidget::QueueMessage(IPC::Message* msg,
1193 MessageDeliveryPolicy policy) {
1194 // RenderThreadImpl::current() is NULL in some tests.
1195 if (!compositor_ || !RenderThreadImpl::current()) {
1196 Send(msg);
1197 return;
1198 }
1199
dchengcedca5612016-04-09 01:40:151200 std::unique_ptr<cc::SwapPromise> swap_promise =
1201 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111202 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111203 compositor_->GetSourceFrameNumber());
1204
1205 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321206 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351207 // Request a commit. This might either A) request a commit ahead of time
1208 // or B) request a commit which is not needed because there are not
1209 // pending updates. If B) then the commit will be skipped and the swap
1210 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1211 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1212 // can_cancel_commit is not unset.
1213 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111214 }
1215}
1216
[email protected]4873c7d2009-07-16 06:36:281217void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301218 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521219 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181220 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291221 // Only send a SetCursor message if we need to make a change.
1222 if (!current_cursor_.IsEqual(cursor)) {
1223 current_cursor_ = cursor;
1224 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1225 }
1226}
1227
1228// We are supposed to get a single call to Show for a newly created RenderWidget
1229// that was created via RenderWidget::CreateWebView. So, we wait until this
1230// point to dispatch the ShowWidget message.
1231//
1232// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281233// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291234//
[email protected]4873c7d2009-07-16 06:36:281235void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291236 DCHECK(!did_show_) << "received extraneous Show call";
1237 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1238 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1239
[email protected]8de12d942010-11-17 20:42:441240 if (did_show_)
1241 return;
1242
1243 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561244 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441245 // that's okay. It'll be ignored if as_popup is false, or the browser
1246 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561247 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1248 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291249}
1250
[email protected]2533ce12009-05-09 00:02:241251void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381252 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241253 Send(new ViewHostMsg_Close(routing_id_));
1254}
1255
dgozmancf9039cd2015-04-06 12:01:311256void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551257 for (auto& observer : render_frames_)
1258 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311259}
1260
[email protected]4873c7d2009-07-16 06:36:281261void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081262 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321263 if (is_swapped_out_) {
1264 // This widget is currently swapped out, and the active widget is in a
1265 // different process. Have the browser route the close request to the
1266 // active widget instead, so that the correct unload handlers are run.
1267 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1268 return;
1269 }
1270
initial.commit09911bf2008-07-26 23:55:291271 // If a page calls window.close() twice, we'll end up here twice, but that's
1272 // OK. It is safe to send multiple Close messages.
1273
[email protected]2533ce12009-05-09 00:02:241274 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1275 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1276 // could be closed before the JS finishes executing. So instead, post a
1277 // message back to the message loop, which won't run until the JS is
1278 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081279 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211280 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291281}
1282
[email protected]9017d7852013-11-21 17:47:351283void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151284 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351285 const SyntheticGestureCompletionCallback& callback) {
1286 DCHECK(!callback.is_null());
1287
1288 pending_synthetic_gesture_callbacks_.push(callback);
1289
1290 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321291 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351292
1293 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1294}
1295
initial.commit09911bf2008-07-26 23:55:291296void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031297 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381298 WillCloseLayerTreeView();
1299 compositor_.reset();
lfg8ff33912016-09-13 20:59:211300 if (webwidget_internal_) {
1301 webwidget_internal_->close();
1302 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291303 }
1304}
1305
bokan841fdc72016-10-06 00:16:351306void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1307 DCHECK(window_rect);
1308 float scale = popup_origin_scale_for_emulation_;
1309 if (!scale)
1310 return;
1311 window_rect->x =
1312 popup_view_origin_for_emulation_.x() +
1313 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1314 window_rect->y =
1315 popup_view_origin_for_emulation_.y() +
1316 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1317}
1318
1319void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1320 DCHECK(window_rect);
1321 float scale = popup_origin_scale_for_emulation_;
1322 if (!scale)
1323 return;
1324 window_rect->x =
1325 popup_screen_origin_for_emulation_.x() +
1326 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1327 window_rect->y =
1328 popup_screen_origin_for_emulation_.y() +
1329 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1330}
1331
[email protected]4873c7d2009-07-16 06:36:281332WebRect RenderWidget::windowRect() {
bokan841fdc72016-10-06 00:16:351333 WebRect rect;
bokan6b08cd22016-10-05 00:55:211334 if (pending_window_rect_count_) {
1335 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1336 // the RootWindowRect is probably going to return wrong results since the
1337 // browser may not have processed the Move yet. There isn't really anything
1338 // good to do in this case, and it shouldn't happen - since this size is
1339 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351340 rect = pending_window_rect_;
1341 } else {
1342 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211343 }
[email protected]2533ce12009-05-09 00:02:241344
bokan841fdc72016-10-06 00:16:351345 ScreenRectToEmulatedIfNeeded(&rect);
1346 return rect;
bokan6b08cd22016-10-05 00:55:211347}
1348
1349WebRect RenderWidget::viewRect() {
bokan841fdc72016-10-06 00:16:351350 WebRect rect = view_screen_rect_;
1351 ScreenRectToEmulatedIfNeeded(&rect);
1352 return rect;
initial.commit09911bf2008-07-26 23:55:291353}
1354
[email protected]180ef242013-11-07 06:50:461355void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301356 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541357 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301358}
1359
oshima33ec97cd2015-12-14 19:40:241360void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1361 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351362 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511363
[email protected]5b45ad42013-10-25 00:42:041364 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201365 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561366 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1367 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031368 } else {
bokanc007c3a2015-02-03 07:15:561369 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031370 }
initial.commit09911bf2008-07-26 23:55:291371 } else {
bokanc007c3a2015-02-03 07:15:561372 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291373 }
1374}
1375
[email protected]2533ce12009-05-09 00:02:241376void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1377 pending_window_rect_ = rect;
1378 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241379
bokan6b08cd22016-10-05 00:55:211380 // Popups don't get size updates back from the browser so just store the set
1381 // values.
1382 if (popup_type_ != blink::WebPopupTypeNone) {
1383 window_screen_rect_ = rect;
1384 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241385 }
[email protected]d4547452008-08-28 18:36:371386}
1387
[email protected]fa7b1dc2010-06-23 17:53:041388void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261389 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041390 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071391 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041392 int selection_start, int selection_end) {
ekaramad2a46d632016-07-19 13:33:091393#if defined(ENABLE_PLUGINS)
1394 if (focused_pepper_plugin_) {
1395 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1396 text, underlines, selection_start, selection_end);
1397 return;
1398 }
1399#endif
1400 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211401 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031402 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091403 }
1404
[email protected]0d1ebed12013-08-05 22:01:131405 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281406 return;
[email protected]66fca5bc2013-05-23 06:58:291407 ImeEventGuard guard(this);
lfg8ff33912016-09-13 20:59:211408 if (!GetWebWidget()->setComposition(
1409 text, WebVector<WebCompositionUnderline>(underlines), selection_start,
1410 selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041411 // If we failed to set the composition text, then we need to let the browser
1412 // process to cancel the input method's ongoing composition session, to make
1413 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221414 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261415 }
nonafa291792016-08-10 02:36:181416 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041417}
1418
aelias87b8f7c2016-09-14 03:19:291419void RenderWidget::OnImeCommitText(const base::string16& text,
1420 const gfx::Range& replacement_range,
1421 int relative_cursor_pos) {
ekaramad2a46d632016-07-19 13:33:091422#if defined(ENABLE_PLUGINS)
1423 if (focused_pepper_plugin_) {
aelias87b8f7c2016-09-14 03:19:291424 focused_pepper_plugin_->render_frame()->OnImeCommitText(
1425 text, replacement_range, relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091426 return;
1427 }
1428#endif
1429 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211430 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031431 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091432 }
1433
[email protected]0d1ebed12013-08-05 22:01:131434 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041435 return;
[email protected]66fca5bc2013-05-23 06:58:291436 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391437 input_handler_->set_handling_input_event(true);
aelias87b8f7c2016-09-14 03:19:291438 GetWebWidget()->commitText(text, relative_cursor_pos);
1439 input_handler_->set_handling_input_event(false);
1440 UpdateCompositionInfo(false /* not an immediate request */);
1441}
1442
1443void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
1444#if defined(ENABLE_PLUGINS)
1445 if (focused_pepper_plugin_) {
1446 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText(
1447 keep_selection);
1448 return;
1449 }
1450#endif
1451
1452 if (!ShouldHandleImeEvent())
1453 return;
1454 ImeEventGuard guard(this);
1455 input_handler_->set_handling_input_event(true);
1456 GetWebWidget()->finishComposingText(keep_selection
1457 ? WebWidget::KeepSelection
1458 : WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391459 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181460 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291461}
1462
oshimad5279032015-12-16 18:22:331463void RenderWidget::OnDeviceScaleFactorChanged() {
1464 if (!compositor_)
1465 return;
oshimad5279032015-12-16 18:22:331466 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181467 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331468 else
1469 compositor_->setDeviceScaleFactor(device_scale_factor_);
1470}
1471
[email protected]0bc1f572013-04-17 01:46:311472void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121473 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211474 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121475 return;
1476
[email protected]0bc1f572013-04-17 01:46:311477 // Even if the browser provides an empty damage rect, it's still expecting to
1478 // receive a repaint ack so just damage the entire widget bounds.
1479 if (size_to_paint.IsEmpty()) {
1480 size_to_paint = size_;
1481 }
1482
[email protected]ec7dc112008-08-06 05:30:121483 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051484 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311485 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121486}
1487
[email protected]79fa22e2013-08-23 15:18:121488void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351489 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1490
1491 pending_synthetic_gesture_callbacks_.front().Run();
1492 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271493}
1494
[email protected]4873c7d2009-07-16 06:36:281495void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211496 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111497 return;
lfg8ff33912016-09-13 20:59:211498 GetWebWidget()->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111499}
1500
[email protected]80ad8622012-11-07 16:33:031501void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1502 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511503 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391504 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1505 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511506 } else {
mfomitchev2600fd7c2016-02-17 20:53:391507 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511508 }
[email protected]80ad8622012-11-07 16:33:031509 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1510}
1511
lfgdb5c4ed2016-03-04 23:09:071512void RenderWidget::OnUpdateWindowScreenRect(
1513 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211514 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071515 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211516 else
lfgdb5c4ed2016-03-04 23:09:071517 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071518}
1519
fsamuele0f705b2016-10-01 14:07:141520void RenderWidget::OnSetFrameSinkId(const cc::FrameSinkId& frame_sink_id) {
kenrbb4e2a3b2015-05-14 15:05:051521 if (compositor_)
fsamuele0f705b2016-10-01 14:07:141522 compositor_->SetFrameSinkId(frame_sink_id);
kenrbb4e2a3b2015-05-14 15:05:051523}
1524
dtrainor5ef644e2015-11-19 00:12:471525void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1526 if (compositor_)
1527 compositor_->OnHandleCompositorProto(proto);
1528}
1529
[email protected]adb362312014-06-28 06:04:241530void RenderWidget::showImeIfNeeded() {
1531 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131532}
1533
fsamuel72464894f2015-12-15 06:59:311534ui::TextInputType RenderWidget::GetTextInputType() {
ekaramad2a46d632016-07-19 13:33:091535#if defined(ENABLE_PLUGINS)
1536 if (focused_pepper_plugin_)
1537 return focused_pepper_plugin_->text_input_type();
1538#endif
lfg8ff33912016-09-13 20:59:211539 if (GetWebWidget())
dtapuskac4dd5be2016-10-25 15:11:101540 return ConvertWebTextInputType(GetWebWidget()->textInputType());
fsamuel72464894f2015-12-15 06:59:311541 return ui::TEXT_INPUT_TYPE_NONE;
1542}
1543
nonafa291792016-08-10 02:36:181544void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1545 if (!monitor_composition_info_ && !immediate_request)
1546 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591547
nonafa291792016-08-10 02:36:181548 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1549 gfx::Range range;
1550 std::vector<gfx::Rect> character_bounds;
1551
1552 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1553 // Composition information is only available on editable node.
1554 range = gfx::Range::InvalidRange();
1555 } else {
1556 GetCompositionRange(&range);
1557 GetCompositionCharacterBounds(&character_bounds);
1558 }
1559
1560 if (!immediate_request &&
1561 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311562 return;
nonafa291792016-08-10 02:36:181563 }
fsamuel72464894f2015-12-15 06:59:311564 composition_character_bounds_ = character_bounds;
1565 composition_range_ = range;
1566 Send(new InputHostMsg_ImeCompositionRangeChanged(
1567 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311568}
1569
oshimaf866dab2015-12-05 00:41:541570void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1571 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461572 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331573 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541574 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461575 gfx::Rect window_rect =
1576 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1577 rect->x = window_rect.x();
1578 rect->y = window_rect.y();
1579 rect->width = window_rect.width();
1580 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541581 }
1582}
1583
oshimaa6985b62016-01-27 08:58:301584void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1585 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181586 rect->x *= GetOriginalDeviceScaleFactor();
1587 rect->y *= GetOriginalDeviceScaleFactor();
1588 rect->width *= GetOriginalDeviceScaleFactor();
1589 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301590 }
1591}
1592
[email protected]adb362312014-06-28 06:04:241593void RenderWidget::OnShowImeIfNeeded() {
1594#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311595 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241596#endif
rouslanf7ebd8832015-01-22 01:54:141597
1598// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1599// virtual keyboard.
1600#if !defined(OS_ANDROID)
1601 FocusChangeComplete();
1602#endif
[email protected]adb362312014-06-28 06:04:241603}
1604
1605#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371606void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1607 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131608}
1609
1610void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371611 DCHECK_GE(text_input_info_history_.size(), 1u);
1612 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511613}
changwan8c342742016-02-26 00:53:391614
1615void RenderWidget::OnRequestTextInputStateUpdate() {
1616 DCHECK(!ime_event_guard_);
1617 UpdateSelectionBounds();
1618 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1619}
changwan46620072016-09-21 03:05:411620
1621void RenderWidget::OnImeBatchEdit(bool begin) {
1622 if (begin) {
1623 ime_in_batch_edit_ = true;
1624 return;
1625 }
1626 if (!ime_in_batch_edit_)
1627 return;
1628 ime_in_batch_edit_ = false;
1629 DCHECK(!ime_event_guard_);
1630 UpdateSelectionBounds();
changwan872c3c422016-10-29 16:32:301631 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
changwan46620072016-09-21 03:05:411632}
[email protected]105dffb42013-02-20 03:46:211633#endif
1634
nonafa291792016-08-10 02:36:181635void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1636 bool monitor_request) {
1637 monitor_composition_info_ = monitor_request;
1638 if (!immediate_request)
1639 return;
1640 UpdateCompositionInfo(true /* immediate request */);
1641}
1642
[email protected]0d1ebed12013-08-05 22:01:131643bool RenderWidget::ShouldHandleImeEvent() {
1644#if defined(OS_ANDROID)
lfg8ff33912016-09-13 20:59:211645 if (!GetWebWidget())
changwan3a841162015-08-11 02:53:371646 return false;
changwan8c342742016-02-26 00:53:391647 if (IsUsingImeThread())
1648 return true;
changwan3a841162015-08-11 02:53:371649
1650 // We cannot handle IME events if there is any chance that the event we are
1651 // receiving here from the browser is based on the state that is different
1652 // from our current one as indicated by |text_input_info_|.
1653 // The states the browser might be in are:
1654 // text_input_info_history_[0] - current state ack'd by browser
1655 // text_input_info_history_[1...N] - pending state changes
1656 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1657 if (text_input_info_history_[i] != text_input_info_)
1658 return false;
1659 }
1660 return true;
[email protected]0d1ebed12013-08-05 22:01:131661#else
lfg8ff33912016-09-13 20:59:211662 return !!GetWebWidget();
[email protected]0d1ebed12013-08-05 22:01:131663#endif
1664}
1665
wjmaclean8a795f32016-08-11 23:49:581666void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191667 if (device_scale_factor_ == device_scale_factor)
1668 return;
1669
1670 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331671
1672 OnDeviceScaleFactorChanged();
jdduke491a3f0c2015-06-15 23:30:261673 ScheduleComposite();
wjmaclean8a795f32016-08-11 23:49:581674
1675 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191676}
1677
[email protected]28ed6b32014-06-08 02:16:271678bool RenderWidget::SetDeviceColorProfile(
1679 const std::vector<char>& color_profile) {
1680 if (device_color_profile_ == color_profile)
1681 return false;
1682
1683 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271684
avi40b5be7a2016-03-03 21:13:441685 if (owner_delegate_)
1686 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1687
1688 return true;
noeldb4df152014-09-16 17:45:201689}
1690
[email protected]fcdc5642014-05-09 14:32:241691void RenderWidget::OnOrientationChange() {
1692}
1693
avib9dbd972016-03-08 18:19:321694void RenderWidget::DidFlushPaint() {
1695 if (owner_delegate_)
1696 owner_delegate_->RenderWidgetDidFlushPaint();
1697}
1698
[email protected]bee16aab2009-08-26 15:55:031699void RenderWidget::SetHidden(bool hidden) {
1700 if (is_hidden_ == hidden)
1701 return;
1702
jdduke8fac9d102014-12-20 02:40:131703 // The status has changed. Tell the RenderThread about it and ensure
1704 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031705 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131706
[email protected]bee16aab2009-08-26 15:55:031707 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001708 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031709 else
[email protected]b2db9272014-01-10 17:42:001710 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111711
1712 if (render_widget_scheduling_state_)
1713 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031714}
1715
[email protected]2b624c562011-10-27 22:58:261716void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:211717 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:261718 return;
1719
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121720 if (is_fullscreen_granted_) {
lfg8ff33912016-09-13 20:59:211721 GetWebWidget()->didEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261722 } else {
lfg8ff33912016-09-13 20:59:211723 GetWebWidget()->didExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261724 }
[email protected]2b624c562011-10-27 22:58:261725}
1726
[email protected]674741932009-02-04 23:44:461727bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051728 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461729}
1730
[email protected]674741932009-02-04 23:44:461731void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051732 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461733}
1734
[email protected]674741932009-02-04 23:44:461735void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051736 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461737}
1738
changwan8c342742016-02-26 00:53:391739bool RenderWidget::IsUsingImeThread() {
1740#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121741 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391742#else
1743 return false;
1744#endif
1745}
1746
changwanf2a707b2015-10-30 08:22:161747void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1748 if (!ime_event_guard_)
1749 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291750}
1751
changwanf2a707b2015-10-30 08:22:161752void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1753 if (ime_event_guard_ != guard) {
1754#if defined(OS_ANDROID)
1755 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1756 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391757 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161758 // Therefore, we want to mark this text state update as 'from IME' only
1759 // when all the nested events are all originating from IME.
1760 ime_event_guard_->set_from_ime(
1761 ime_event_guard_->from_ime() && guard->from_ime());
1762#endif
1763 return;
1764 }
1765 ime_event_guard_ = nullptr;
1766
[email protected]66fca5bc2013-05-23 06:58:291767 // While handling an ime event, text input state and selection bounds updates
1768 // are ignored. These must explicitly be updated once finished handling the
1769 // ime event.
1770 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471771#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161772 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311773 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1774 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471775#endif
[email protected]66fca5bc2013-05-23 06:58:291776}
1777
[email protected]7c8873e2013-02-05 08:03:011778void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
ekaramad2a46d632016-07-19 13:33:091779#if defined(ENABLE_PLUGINS)
1780 if (focused_pepper_plugin_) {
1781 // TODO(kinaba) http://crbug.com/101101
1782 // Current Pepper IME API does not handle selection bounds. So we simply
1783 // use the caret position as an empty range for now. It will be updated
1784 // after Pepper API equips features related to surrounding text retrieval.
1785 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1786 convertViewportToWindow(&caret);
1787 *focus = caret;
1788 *anchor = caret;
1789 return;
1790 }
1791#endif
[email protected]7c8873e2013-02-05 08:03:011792 WebRect focus_webrect;
1793 WebRect anchor_webrect;
lfg8ff33912016-09-13 20:59:211794 GetWebWidget()->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241795 convertViewportToWindow(&focus_webrect);
1796 convertViewportToWindow(&anchor_webrect);
1797 *focus = focus_webrect;
1798 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321799}
1800
[email protected]e99ef6f2011-10-16 01:13:001801void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081802 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:211803 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:001804 return;
changwanf2a707b2015-10-30 08:22:161805 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291806 return;
[email protected]e99ef6f2011-10-16 01:13:001807
mohsenb0eeba72015-08-09 06:20:081808#if defined(USE_AURA)
1809 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1810 // Aura beucause composited selection updates are not working for webview tags
1811 // which regresses IME inside webview. Remove this when composited selection
1812 // updates are fixed for webviews. See, http://crbug.com/510568.
1813 bool send_ipc = true;
1814#else
jddukeacf809e2014-09-23 20:38:381815 // With composited selection updates, the selection bounds will be reported
1816 // directly by the compositor, in which case explicit IPC selection
1817 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081818 bool send_ipc =
1819 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1820#endif
1821 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381822 ViewHostMsg_SelectionBounds_Params params;
1823 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1824 if (selection_anchor_rect_ != params.anchor_rect ||
1825 selection_focus_rect_ != params.focus_rect) {
1826 selection_anchor_rect_ = params.anchor_rect;
1827 selection_focus_rect_ = params.focus_rect;
lfg8ff33912016-09-13 20:59:211828 GetWebWidget()->selectionTextDirection(params.focus_dir,
1829 params.anchor_dir);
1830 params.is_anchor_first = GetWebWidget()->isSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:381831 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1832 }
[email protected]58b48a0d2012-06-13 07:01:351833 }
jddukeacf809e2014-09-23 20:38:381834
nonafa291792016-08-10 02:36:181835 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:001836}
1837
avi40b5be7a2016-03-03 21:13:441838void RenderWidget::SetDeviceColorProfileForTesting(
1839 const std::vector<char>& color_profile) {
1840 SetDeviceColorProfile(color_profile);
1841}
1842
lfgb00fcad2016-07-14 14:16:331843void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
1844 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
1845 convertViewportToWindow(&new_size_in_window);
1846 if (size_.width() != new_size_in_window.width ||
1847 size_.height() != new_size_in_window.height) {
1848 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
1849
1850 if (resizing_mode_selector_->is_synchronous_mode()) {
bokan6b08cd22016-10-05 00:55:211851 gfx::Rect new_pos(windowRect().x, windowRect().y,
lfg0140a452016-07-19 19:15:051852 size_.width(), size_.height());
lfgb00fcad2016-07-14 14:16:331853 view_screen_rect_ = new_pos;
1854 window_screen_rect_ = new_pos;
1855 }
1856
1857 AutoResizeCompositor();
1858
1859 if (!resizing_mode_selector_->is_synchronous_mode())
1860 need_update_rect_for_auto_resize_ = true;
1861 }
1862}
1863
[email protected]58b48a0d2012-06-13 07:01:351864void RenderWidget::GetCompositionCharacterBounds(
1865 std::vector<gfx::Rect>* bounds) {
1866 DCHECK(bounds);
1867 bounds->clear();
ekaramad2a46d632016-07-19 13:33:091868
1869#if defined(ENABLE_PLUGINS)
1870 if (focused_pepper_plugin_)
1871 return;
1872#endif
1873
lfg8ff33912016-09-13 20:59:211874 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:091875 return;
1876 blink::WebVector<blink::WebRect> bounds_from_blink;
lfg8ff33912016-09-13 20:59:211877 if (!GetWebWidget()->getCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:091878 return;
1879
1880 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
1881 convertViewportToWindow(&bounds_from_blink[i]);
1882 bounds->push_back(bounds_from_blink[i]);
1883 }
[email protected]58b48a0d2012-06-13 07:01:351884}
1885
[email protected]db4fc1e2013-09-06 20:01:511886void RenderWidget::GetCompositionRange(gfx::Range* range) {
ekaramad2a46d632016-07-19 13:33:091887#if defined(ENABLE_PLUGINS)
1888 if (focused_pepper_plugin_)
1889 return;
1890#endif
lfg8ff33912016-09-13 20:59:211891 WebRange web_range = GetWebWidget()->compositionRange();
dglazkov78a24b62016-09-02 21:34:531892 if (!web_range.isNull()) {
1893 range->set_start(web_range.startOffset());
1894 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:361895 } else {
lfg8ff33912016-09-13 20:59:211896 web_range = GetWebWidget()->caretOrSelectionRange();
dglazkove353a372016-09-01 01:33:481897 range->set_start(web_range.startOffset());
1898 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:361899 }
1900}
1901
[email protected]501ea13d2013-07-09 17:03:291902bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511903 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291904 const std::vector<gfx::Rect>& bounds) {
1905 if (composition_range_ != range)
1906 return true;
1907 if (bounds.size() != composition_character_bounds_.size())
1908 return true;
1909 for (size_t i = 0; i < bounds.size(); ++i) {
1910 if (bounds[i] != composition_character_bounds_[i])
1911 return true;
1912 }
1913 return false;
1914}
[email protected]501ea13d2013-07-09 17:03:291915
[email protected]ad26ef42011-06-17 07:59:451916bool RenderWidget::CanComposeInline() {
ekaramad2a46d632016-07-19 13:33:091917#if defined(ENABLE_PLUGINS)
1918 if (focused_pepper_plugin_)
1919 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
1920#endif
[email protected]ad26ef42011-06-17 07:59:451921 return true;
[email protected]56ea1a62011-05-30 07:05:571922}
1923
ccameron2f451532016-09-07 21:49:271924blink::WebScreenInfo RenderWidget::screenInfo() {
1925 blink::WebScreenInfo web_screen_info;
1926 web_screen_info.deviceScaleFactor = screen_info_.device_scale_factor;
1927 web_screen_info.depth = screen_info_.depth;
1928 web_screen_info.depthPerComponent = screen_info_.depth_per_component;
1929 web_screen_info.isMonochrome = screen_info_.is_monochrome;
1930 web_screen_info.rect = blink::WebRect(screen_info_.rect);
1931 web_screen_info.availableRect = blink::WebRect(screen_info_.available_rect);
1932 switch (screen_info_.orientation_type) {
1933 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
1934 web_screen_info.orientationType =
1935 blink::WebScreenOrientationPortraitPrimary;
1936 break;
1937 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
1938 web_screen_info.orientationType =
1939 blink::WebScreenOrientationPortraitSecondary;
1940 break;
1941 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
1942 web_screen_info.orientationType =
1943 blink::WebScreenOrientationLandscapePrimary;
1944 break;
1945 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
1946 web_screen_info.orientationType =
1947 blink::WebScreenOrientationLandscapeSecondary;
1948 break;
1949 default:
1950 web_screen_info.orientationType =
1951 blink::WebScreenOrientationUndefined;
1952 break;
1953 }
1954 web_screen_info.orientationAngle = screen_info_.orientation_angle;
1955 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:281956}
1957
[email protected]fa7b1dc2010-06-23 17:53:041958void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021959 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041960 // If the last text input type is not None, then we should finish any
1961 // ongoing composition regardless of the new text input type.
dglazkov97b6c2b2016-10-25 17:35:551962 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041963 // If a composition text exists, then we need to let the browser process
1964 // to cancel the input method's ongoing composition session.
aelias87b8f7c2016-09-14 03:19:291965 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection))
[email protected]a2214eb2014-06-23 18:31:221966 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041967 }
[email protected]d4cff272011-05-02 15:46:011968
nonafa291792016-08-10 02:36:181969 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041970}
1971
donnda070f3c2015-01-16 19:54:111972#if defined(OS_ANDROID)
1973void RenderWidget::showUnhandledTapUIIfNeeded(
1974 const WebPoint& tapped_position,
1975 const WebNode& tapped_node,
1976 bool page_changed) {
fsamuele8326c742016-01-12 00:49:391977 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:111978 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371979 !tapped_node.isContentEditable() &&
1980 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111981 if (should_trigger) {
1982 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1983 tapped_position.x, tapped_position.y));
1984 }
1985}
1986#endif
1987
[email protected]c68c3e4e2013-01-24 00:36:561988void RenderWidget::didHandleGestureEvent(
1989 const WebGestureEvent& event,
1990 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021991#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561992 if (event_cancelled)
1993 return;
[email protected]07c70d22014-08-21 08:33:461994 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:311995 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461996 } else if (event.type == WebInputEvent::GestureLongPress) {
lfg8ff33912016-09-13 20:59:211997 DCHECK(GetWebWidget());
1998 if (GetWebWidget()->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:311999 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462000 else
fsamuel72464894f2015-12-15 06:59:312001 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562002 }
2003#endif
2004}
2005
sataya.m582c9ce2015-06-09 08:03:422006void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:312007 const blink::WebFloatSize& overscrollDelta,
2008 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422009 const blink::WebFloatPoint& position,
2010 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482011#if defined(OS_MACOSX)
2012 // On OSX the user can disable the elastic overscroll effect. If that's the
2013 // case, don't forward the overscroll notification.
2014 DCHECK(compositor_deps());
2015 if (!compositor_deps()->IsElasticOverscrollEnabled())
2016 return;
2017#endif
bokane53a10f2016-04-13 23:48:312018 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392019 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422020}
2021
[email protected]7912e822014-04-16 02:37:032022void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392023 if (!is_hidden())
2024 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032025}
2026
[email protected]24ed0432013-04-24 07:50:312027RenderWidgetCompositor* RenderWidget::compositor() const {
2028 return compositor_.get();
2029}
2030
fsamuel72464894f2015-12-15 06:59:312031void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392032 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372033}
[email protected]c3d45532011-10-07 19:20:402034
[email protected]ce6689f2013-03-29 12:52:552035void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112036 if (render_widget_scheduling_state_)
2037 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552038 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2039}
2040
[email protected]5d0bbdfa92013-12-10 00:35:512041void RenderWidget::setTouchAction(
2042 blink::WebTouchAction web_touch_action) {
2043
2044 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2045 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392046 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512047 return;
2048
[email protected]a18f67a2013-12-20 19:44:362049 content::TouchAction content_touch_action =
2050 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512051 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2052}
2053
[email protected]90f24152014-04-09 12:41:362054void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2055#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392056 if (!IsUsingImeThread())
2057 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362058#endif
2059}
2060
[email protected]e3244ed2014-06-20 20:04:272061void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2062 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162063}
2064
[email protected]e3244ed2014-06-20 20:04:272065void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2066 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162067}
2068
[email protected]de3c5d82014-05-28 22:12:592069void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2070 render_frames_.AddObserver(frame);
2071}
2072
2073void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2074 render_frames_.RemoveObserver(frame);
2075}
2076
lfg43e08e62016-02-03 18:51:372077void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2078 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2079 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2080}
2081
oshima50872a72016-03-04 13:26:182082float RenderWidget::GetOriginalDeviceScaleFactor() const {
2083 return
2084 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272085 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182086 device_scale_factor_;
2087}
2088
lfgbee1e0a2016-06-08 21:24:212089bool RenderWidget::requestPointerLock() {
2090 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2091}
2092
2093void RenderWidget::requestPointerUnlock() {
2094 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2095}
2096
2097bool RenderWidget::isPointerLocked() {
2098 return mouse_lock_dispatcher_->IsMouseLockedTo(
2099 webwidget_mouse_lock_target_.get());
2100}
2101
lfg8ff33912016-09-13 20:59:212102blink::WebWidget* RenderWidget::GetWebWidget() const {
2103 return webwidget_internal_;
2104}
2105
[email protected]e9ff79c2012-10-19 21:31:262106} // namespace content