blob: 8f6ffdb2189c598c6079f455a214ab1456329318 [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"
paulmeyer6ef5a792016-11-08 20:33:5830#include "content/common/drag_event_source_info.h"
31#include "content/common/drag_messages.h"
[email protected]9017d7852013-11-21 17:47:3532#include "content/common/input/synthetic_gesture_packet.h"
[email protected]c084330e02013-04-27 01:08:1533#include "content/common/input_messages.h"
jcivelliae1560a2016-11-01 22:40:2334#include "content/common/render_message_filter.mojom.h"
[email protected]992db4c2011-05-12 15:37:1535#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3836#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5037#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1238#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2939#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4240#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4041#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3942#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5843#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5144#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1145#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1146#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2847#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2948#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1349#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3250#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1651#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2752#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0553#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4454#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5555#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4456#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0957#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0458#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4759#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1860#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4861#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1862#include "third_party/WebKit/public/platform/WebCursorInfo.h"
donnda070f3c2015-01-16 19:54:1163#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3064#include "third_party/WebKit/public/platform/WebRect.h"
65#include "third_party/WebKit/public/platform/WebSize.h"
66#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5167#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
68#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
[email protected]19193682014-04-03 15:01:4369#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5970#include "third_party/WebKit/public/web/WebFrameWidget.h"
71#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1172#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3173#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3174#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
75#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3876#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5977#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0878#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4179#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1380#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5081#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0982#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3283#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4884#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2785#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4186#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4887
[email protected]eeb93112013-05-01 19:41:1088#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1589#include <android/keycodes.h>
[email protected]eeb93112013-05-01 19:41:1090#endif
91
[email protected]661eb9d2009-02-03 02:11:4892#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:5293#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4194#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4895#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4496
sadrul943e3b32016-08-04 18:22:5997#if defined(USE_AURA)
bend32292b2016-10-07 00:21:5898#include "content/public/common/service_manager_connection.h"
fsamuel2545ecc2015-12-05 00:44:4699#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:19100#endif
101
ekaramad330ba4232016-09-23 17:57:47102#if defined(OS_MACOSX)
103#include "content/renderer/text_input_client_observer.h"
104#endif
105
[email protected]180ef242013-11-07 06:50:46106using blink::WebCompositionUnderline;
107using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43108using blink::WebDeviceEmulationParams;
paulmeyer6ef5a792016-11-08 20:33:58109using blink::WebDragOperationsMask;
110using blink::WebDragData;
[email protected]180ef242013-11-07 06:50:46111using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58112using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46113using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49114using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46115using blink::WebKeyboardEvent;
paulmeyer6ef5a792016-11-08 20:33:58116using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46117using blink::WebMouseEvent;
118using blink::WebMouseWheelEvent;
119using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11120using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46121using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11122using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46123using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48124using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46125using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46126using blink::WebSize;
127using blink::WebTextDirection;
128using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25129using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46130using blink::WebVector;
131using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26132
[email protected]6a4d7f62013-01-07 21:32:13133namespace {
[email protected]b256eca2013-07-11 10:57:40134
135typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
136
lfgbee1e0a2016-06-08 21:24:21137class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
138 public:
139 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
140 : webwidget_(webwidget) {}
141
142 void OnLockMouseACK(bool succeeded) override {
143 if (succeeded)
144 webwidget_->didAcquirePointerLock();
145 else
146 webwidget_->didNotAcquirePointerLock();
147 }
148
149 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
150
151 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
152 // The WebWidget handles mouse lock in Blink's handleInputEvent().
153 return false;
154 }
155
156 private:
157 blink::WebWidget* webwidget_;
158};
159
dglazkov97b6c2b2016-10-25 17:35:55160bool IsDateTimeInput(ui::TextInputType type) {
161 return type == ui::TEXT_INPUT_TYPE_DATE ||
162 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
163 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
164 type == ui::TEXT_INPUT_TYPE_MONTH ||
165 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
166}
167
fsamuele8326c742016-01-12 00:49:39168content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
169 content::RenderWidget* widget) {
sadrul943e3b32016-08-04 18:22:59170#if defined(USE_AURA)
penghuang639a1042016-01-14 21:25:29171 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
bend32292b2016-10-07 00:21:58172 if (content::ServiceManagerConnection::GetForProcess() &&
penghuang639a1042016-01-14 21:25:29173 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39174 return content::RenderWidgetMusConnection::GetOrCreate(
175 widget->routing_id());
176 }
177#endif
bend32292b2016-10-07 00:21:58178 // If we don't have a connection to the Service Manager, then we want to route
179 // IPCs back to the browser process rather than Mus so we use the |widget| as
180 // the RenderWidgetInputHandlerDelegate.
fsamuele8326c742016-01-12 00:49:39181 return widget;
182}
183
lfg1568d112016-08-30 16:06:29184content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
185 nullptr;
186
187content::RenderWidget::RenderWidgetInitializedCallback
188 g_render_widget_initialized = nullptr;
189
dtapuskac4dd5be2016-10-25 15:11:10190ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
191 // Check the type is in the range representable by ui::TextInputType.
192 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
193 << "blink::WebTextInputType and ui::TextInputType not synchronized";
194 return static_cast<ui::TextInputType>(type);
195}
196
197ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
198 // Check the mode is in the range representable by ui::TextInputMode.
199 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
200 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
201 return static_cast<ui::TextInputMode>(mode);
202}
203
[email protected]b256eca2013-07-11 10:57:40204} // namespace
205
[email protected]e9ff79c2012-10-19 21:31:26206namespace content {
[email protected]62cb33cae2009-03-27 23:30:22207
[email protected]b2e4c70132013-10-03 02:07:51208// RenderWidget ---------------------------------------------------------------
209
dcheng35d31c112015-07-22 00:17:36210RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
211 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27212 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04213 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03214 bool hidden,
215 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29216 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36217 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21218 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44219 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29220 opener_id_(MSG_ROUTING_NONE),
initial.commit09911bf2008-07-26 23:55:29221 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51222 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09223 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29224 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04225 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39226 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12227 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12228 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16229 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48230 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22231 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44232 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20233 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55234 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40235 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20236 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53237 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18238 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12239 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48240 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04241 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27242 device_scale_factor_(screen_info_.device_scale_factor),
[email protected]0d1ebed12013-08-05 22:01:13243#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36244 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13245#endif
nonafa291792016-08-10 02:36:18246 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51247 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11248 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42249 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08250 has_host_context_menu_location_(false),
ekaramad2a46d632016-07-19 13:33:09251 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47252#if defined(OS_MACOSX)
253 text_input_client_observer_(new TextInputClientObserver(this)),
254#endif
ekaramad2a46d632016-07-19 13:33:09255 focused_pepper_plugin_(nullptr) {
[email protected]8b3f0eb2012-05-03 19:15:05256 if (!swapped_out)
257 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27258 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53259 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37260#if defined(OS_ANDROID)
261 text_input_info_history_.push_back(blink::WebTextInputInfo());
262#endif
alexclarke7fa93942015-10-21 15:37:11263
264 // In tests there may not be a RenderThreadImpl.
265 if (RenderThreadImpl::current()) {
266 render_widget_scheduling_state_ = RenderThreadImpl::current()
267 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32268 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11269 render_widget_scheduling_state_->SetHidden(is_hidden_);
270 }
initial.commit09911bf2008-07-26 23:55:29271}
272
273RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21274 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16275
[email protected]992db4c2011-05-12 15:37:15276 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02277 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15278 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29279}
280
[email protected]484955942010-08-19 16:13:18281// static
lfg1568d112016-08-30 16:06:29282void RenderWidget::InstallCreateHook(
283 CreateRenderWidgetFunction create_render_widget,
284 RenderWidgetInitializedCallback render_widget_initialized) {
285 CHECK(!g_create_render_widget && !g_render_widget_initialized);
286 g_create_render_widget = create_render_widget;
287 g_render_widget_initialized = render_widget_initialized;
288}
289
290// static
avi1023d012015-12-25 02:39:14291RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53292 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46293 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27294 const ScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29295 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36296 scoped_refptr<RenderWidget> widget(new RenderWidget(
297 compositor_deps, popup_type, screen_info, false, false, false));
298 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46299 return widget.get();
[email protected]a635f942012-12-07 10:34:29300 }
301 return NULL;
initial.commit09911bf2008-07-26 23:55:29302}
303
[email protected]484955942010-08-19 16:13:18304// static
kenrba7199832015-01-22 23:44:59305RenderWidget* RenderWidget::CreateForFrame(
306 int routing_id,
kenrba7199832015-01-22 23:44:59307 bool hidden,
ccameron2f451532016-09-07 21:49:27308 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59309 CompositorDependencies* compositor_deps,
310 blink::WebLocalFrame* frame) {
311 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55312 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
313 // same routing ID for both the view routing ID and the main frame widget
314 // routing ID. https://crbug.com/545684
315 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
316 if (view) {
avi8a45c1092016-03-01 16:12:34317 view->AttachWebFrameWidget(
318 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
319 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55320 }
dcheng35d31c112015-07-22 00:17:36321 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29322 g_create_render_widget
323 ? g_create_render_widget(compositor_deps, blink::WebPopupTypeNone,
324 screen_info, false, hidden, false)
325 : new RenderWidget(compositor_deps, blink::WebPopupTypeNone,
326 screen_info, false, hidden, false));
fsamuele8326c742016-01-12 00:49:39327 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20328 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59329 // DoInit increments the reference count on |widget|, keeping it alive after
330 // this function returns.
dcheng35d31c112015-07-22 00:17:36331 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59332 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
jcivelliae1560a2016-11-01 22:40:23333 CreateWidgetCallback())) {
lfg1568d112016-08-30 16:06:29334 if (g_render_widget_initialized)
335 g_render_widget_initialized(widget.get());
kenrba7199832015-01-22 23:44:59336 return widget.get();
337 }
338 return nullptr;
339}
340
341// static
lfgcaab5142016-02-26 19:06:52342blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08343 RenderWidget* render_widget,
344 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55345 if (!frame->parent()) {
346 // TODO(dcheng): The main frame widget currently has a special case.
347 // Eliminate this once WebView is no longer a WebWidget.
348 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
349 }
dchengda9b4bb2015-07-20 20:58:08350 return blink::WebFrameWidget::create(render_widget, frame);
351}
352
353// static
kenrba7199832015-01-22 23:44:59354blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18355 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46356 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18357 break;
[email protected]180ef242013-11-07 06:50:46358 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44359 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18360 default:
361 NOTREACHED();
362 }
363 return NULL;
364}
365
dchengda9b4bb2015-07-20 20:58:08366void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32367 OnClose();
kenrba7199832015-01-22 23:44:59368}
369
fsamuele8326c742016-01-12 00:49:39370void RenderWidget::SetRoutingID(int32_t routing_id) {
371 routing_id_ = routing_id;
372 input_handler_.reset(new RenderWidgetInputHandler(
373 GetRenderWidgetInputHandlerDelegate(this), this));
374}
375
alexmos78c9c0d2016-10-14 18:57:03376void RenderWidget::SetSwappedOut(bool is_swapped_out) {
377 // We should only toggle between states.
378 DCHECK(is_swapped_out_ != is_swapped_out);
379 is_swapped_out_ = is_swapped_out;
380
381 // If we are swapping out, we will call ReleaseProcess, allowing the process
382 // to exit if all of its RenderViews are swapped out. We wait until the
383 // WasSwappedOut call to do this, to allow the unload handler to finish.
384 // If we are swapping in, we call AddRefProcess to prevent the process from
385 // exiting.
386 if (!is_swapped_out_)
387 RenderProcess::current()->AddRefProcess();
388}
389
jcivelliae1560a2016-11-01 22:40:23390bool RenderWidget::CreateWidget(int32_t opener_id,
391 blink::WebPopupType popup_type,
392 int32_t* routing_id) {
393 RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
394 opener_id, popup_type, routing_id);
395 return true;
396}
397
avi1023d012015-12-25 02:39:14398bool RenderWidget::Init(int32_t opener_id) {
jcivelliae1560a2016-11-01 22:40:23399 bool success = DoInit(opener_id, RenderWidget::CreateWebWidget(this),
400 base::Bind(&RenderWidget::CreateWidget, base::Unretained(this),
401 opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39402 if (success) {
403 SetRoutingID(routing_id_);
404 return true;
405 }
406 return false;
[email protected]484955942010-08-19 16:13:18407}
408
avi1023d012015-12-25 02:39:14409bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06410 WebWidget* web_widget,
jcivelliae1560a2016-11-01 22:40:23411 CreateWidgetCallback create_widget_callback) {
lfg8ff33912016-09-13 20:59:21412 DCHECK(!webwidget_internal_);
initial.commit09911bf2008-07-26 23:55:29413
414 if (opener_id != MSG_ROUTING_NONE)
415 opener_id_ = opener_id;
416
lfg8ff33912016-09-13 20:59:21417 webwidget_internal_ = web_widget;
418 webwidget_mouse_lock_target_.reset(
419 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21420 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29421
kenrba7199832015-01-22 23:44:59422 bool result = true;
jcivelliae1560a2016-11-01 22:40:23423 if (!create_widget_callback.is_null())
424 result = std::move(create_widget_callback).Run();
kenrba7199832015-01-22 23:44:59425
initial.commit09911bf2008-07-26 23:55:29426 if (result) {
[email protected]380244092011-10-07 17:26:27427 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29428 // Take a reference on behalf of the RenderThread. This will be balanced
429 // when we receive ViewMsg_Close.
430 AddRef();
[email protected]b2db9272014-01-10 17:42:00431 if (RenderThreadImpl::current()) {
432 RenderThreadImpl::current()->WidgetCreated();
433 if (is_hidden_)
434 RenderThreadImpl::current()->WidgetHidden();
435 }
fsamuele8326c742016-01-12 00:49:39436
[email protected]a635f942012-12-07 10:34:29437 return true;
initial.commit09911bf2008-07-26 23:55:29438 } else {
[email protected]a635f942012-12-07 10:34:29439 // The above Send can fail when the tab is closing.
440 return false;
initial.commit09911bf2008-07-26 23:55:29441 }
442}
443
[email protected]949b6592014-08-20 13:17:52444void RenderWidget::WasSwappedOut() {
445 // If we have been swapped out and no one else is using this process,
446 // it's safe to exit now.
447 CHECK(is_swapped_out_);
448 RenderProcess::current()->ReleaseProcess();
449}
450
[email protected]b2e4c70132013-10-03 02:07:51451void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39452 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51453 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43454 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49455 popup_screen_origin_for_emulation_ = gfx::Point(
456 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
457 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56458 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27459 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51460}
461
[email protected]2d6836f42014-07-02 17:25:31462gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
463 if (screen_metrics_emulator_)
464 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
465 return anchor;
466}
467
haibinluc643d33c2016-06-03 02:22:34468#if defined(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51469void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39470 ExternalPopupMenu* popup,
471 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49472 popup->SetOriginScaleAndOffsetForEmulation(
473 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51474}
[email protected]53907862014-03-25 15:42:40475#endif
[email protected]b2e4c70132013-10-03 02:07:51476
477void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
478 if (screen_metrics_emulator_)
479 screen_metrics_emulator_->OnShowContextMenu(params);
480}
481
[email protected]a95986a82010-12-24 06:19:28482bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47483#if defined(OS_MACOSX)
484 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
485 return text_input_client_observer_->OnMessageReceived(message);
486#endif
lfgbee1e0a2016-06-08 21:24:21487 if (mouse_lock_dispatcher_ &&
488 mouse_lock_dispatcher_->OnMessageReceived(message))
489 return true;
490
[email protected]a95986a82010-12-24 06:19:28491 bool handled = true;
492 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15493 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22494 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
495 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22496 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29497 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
498 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
499 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15500 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46501 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
502 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15503 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35504 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
505 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28506 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28507 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20508 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
509 OnEnableDeviceEmulation)
510 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
511 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28512 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41513 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25514 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28515 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
516 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03517 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
lfg43e08e62016-02-03 18:51:37518 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
519 OnWaitNextFrameForTests)
nonafa291792016-08-10 02:36:18520 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
521 OnRequestCompositionUpdate)
[email protected]105dffb42013-02-20 03:46:21522#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37523 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39524 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
525 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21526#endif
dtrainor5ef644e2015-11-19 00:12:47527 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28528 IPC_MESSAGE_UNHANDLED(handled = false)
529 IPC_END_MESSAGE_MAP()
530 return handled;
531}
initial.commit09911bf2008-07-26 23:55:29532
533bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15534 // Don't send any messages after the browser has told us to close, and filter
535 // most outgoing messages while swapped out.
536 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26537 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11538 closing_) {
initial.commit09911bf2008-07-26 23:55:29539 delete message;
540 return false;
541 }
542
543 // If given a messsage without a routing ID, then assign our routing ID.
544 if (message->routing_id() == MSG_ROUTING_NONE)
545 message->set_routing_id(routing_id_);
546
[email protected]380244092011-10-07 17:26:27547 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44548}
549
bokanc007c3a2015-02-03 07:15:56550void RenderWidget::SetWindowRectSynchronously(
551 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39552 ResizeParams params;
553 params.screen_info = screen_info_;
554 params.new_size = new_window_rect.size();
555 params.physical_backing_size =
556 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39557 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39558 params.is_fullscreen_granted = is_fullscreen_granted_;
559 params.display_mode = display_mode_;
560 params.needs_resize_ack = false;
561 Resize(params);
562
bokanc007c3a2015-02-03 07:15:56563 view_screen_rect_ = new_window_rect;
564 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02565 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56566 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02567}
568
initial.commit09911bf2008-07-26 23:55:29569void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32570 DCHECK(content::RenderThread::Get());
571 if (closing_)
572 return;
573 NotifyOnClose();
574 closing_ = true;
575
576 // Browser correspondence is no longer needed at this point.
577 if (routing_id_ != MSG_ROUTING_NONE) {
578 RenderThread::Get()->RemoveRoute(routing_id_);
579 SetHidden(false);
580 if (RenderThreadImpl::current())
581 RenderThreadImpl::current()->WidgetDestroyed();
582 }
583
584 if (for_oopif_) {
585 // Widgets for frames may be created and closed at any time while the frame
586 // is alive. However, the closing process must happen synchronously. Frame
587 // widget and frames hold pointers to each other. If Close() is deferred to
588 // the message loop like in the non-frame widget case, WebWidget::close()
589 // can end up accessing members of an already-deleted frame.
590 Close();
591 } else {
592 // If there is a Send call on the stack, then it could be dangerous to close
593 // now. Post a task that only gets invoked when there are no nested message
594 // loops.
595 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
596 FROM_HERE, base::Bind(&RenderWidget::Close, this));
597 }
598
599 // Balances the AddRef taken when we called AddRoute.
600 Release();
initial.commit09911bf2008-07-26 23:55:29601}
602
fsamuel664e8b62016-01-20 19:54:01603void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04604 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32605 return;
606
[email protected]b2e4c70132013-10-03 02:07:51607 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39608 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51609 return;
610 }
611
mfomitchev2600fd7c2016-02-17 20:53:39612 Resize(params);
initial.commit09911bf2008-07-26 23:55:29613}
614
dgozman9260b0a12015-03-16 13:45:20615void RenderWidget::OnEnableDeviceEmulation(
616 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39617 if (!screen_metrics_emulator_) {
618 ResizeParams resize_params;
619 resize_params.screen_info = screen_info_;
620 resize_params.new_size = size_;
621 resize_params.physical_backing_size = physical_backing_size_;
622 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39623 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
624 resize_params.display_mode = display_mode_;
625 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
626 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18627 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39628 } else {
dgozman9260b0a12015-03-16 13:45:20629 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39630 }
dgozman9260b0a12015-03-16 13:45:20631}
632
633void RenderWidget::OnDisableDeviceEmulation() {
634 screen_metrics_emulator_.reset();
635}
636
initial.commit09911bf2008-07-26 23:55:29637void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31638 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29639 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03640 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55641 for (auto& observer : render_frames_)
642 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29643}
644
[email protected]3399dd822014-08-09 11:14:24645void RenderWidget::OnWasShown(bool needs_repainting,
646 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41647 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29648 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21649 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29650 return;
651
652 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03653 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55654 for (auto& observer : render_frames_)
655 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29656
[email protected]8a23afb32014-04-30 22:40:23657 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29658 return;
initial.commit09911bf2008-07-26 23:55:29659
660 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24661 if (compositor_) {
662 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15663 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24664 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05665 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24666 }
jdduke491a3f0c2015-06-15 23:30:26667 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29668}
669
[email protected]53d3f302009-12-21 04:42:05670void RenderWidget::OnRequestMoveAck() {
671 DCHECK(pending_window_rect_count_);
672 pending_window_rect_count_--;
673}
674
[email protected]ed7defa2013-03-12 21:29:59675GURL RenderWidget::GetURLForGraphicsContext3D() {
676 return GURL();
[email protected]65225772011-05-12 21:10:24677}
678
fsamuel78f86e42016-01-20 04:10:23679void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10680 const ui::LatencyInfo& latency_info,
681 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23682 if (!input_event)
683 return;
dtapuska0bd451a2016-02-18 17:08:10684 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23685}
686
687void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21688 if (GetWebWidget())
689 GetWebWidget()->setCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23690}
691
692void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21693 if (GetWebWidget())
694 GetWebWidget()->mouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23695}
696
alexmos56567492016-09-13 00:52:46697void RenderWidget::OnSetEditCommandsForNextKeyEvent(
698 const EditCommands& edit_commands) {
699 edit_commands_ = edit_commands;
700}
701
fsamuel78f86e42016-01-20 04:10:23702void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08703 has_focus_ = enable;
704
lfg8ff33912016-09-13 20:59:21705 if (GetWebWidget())
706 GetWebWidget()->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08707
ericwilligers88e69742016-10-17 19:29:55708 for (auto& observer : render_frames_)
709 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23710}
711
dtapuska3d5624d32016-08-30 04:34:00712void RenderWidget::SetNeedsMainFrame() {
713 RenderWidgetCompositor* rwc = compositor();
714 if (!rwc)
715 return;
716 rwc->setNeedsBeginFrame();
717}
718
fsamuel78f86e42016-01-20 04:10:23719///////////////////////////////////////////////////////////////////////////////
720// RenderWidgetCompositorDelegate
721
722void RenderWidget::ApplyViewportDeltas(
723 const gfx::Vector2dF& inner_delta,
724 const gfx::Vector2dF& outer_delta,
725 const gfx::Vector2dF& elastic_overscroll_delta,
726 float page_scale,
727 float top_controls_delta) {
lfg8ff33912016-09-13 20:59:21728 GetWebWidget()->applyViewportDeltas(inner_delta, outer_delta,
729 elastic_overscroll_delta, page_scale,
730 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23731}
732
733void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska3d5624d32016-08-30 04:34:00734 RenderThreadImpl* render_thread = RenderThreadImpl::current();
735 // render_thread may be NULL in tests.
736 InputHandlerManager* input_handler_manager =
737 render_thread ? render_thread->input_handler_manager() : NULL;
738 if (input_handler_manager)
739 input_handler_manager->ProcessRafAlignedInputOnMainThread(routing_id_);
740
lfg8ff33912016-09-13 20:59:21741 GetWebWidget()->beginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23742}
743
danakj1120f4c2016-09-15 02:05:32744std::unique_ptr<cc::CompositorFrameSink>
745RenderWidget::CreateCompositorFrameSink(bool fallback) {
lfg8ff33912016-09-13 20:59:21746 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03747 // For widgets that are never visible, we don't start the compositor, so we
danakj1120f4c2016-09-15 02:05:32748 // never get a request for a cc::CompositorFrameSink.
sievers71c62dd52015-10-07 01:44:39749 DCHECK(!compositor_never_visible_);
danakj1120f4c2016-09-15 02:05:32750 return RenderThreadImpl::current()->CreateCompositorFrameSink(
danakj83066a32016-06-21 02:34:49751 fallback, routing_id_, frame_swap_message_queue_,
752 GetURLForGraphicsContext3D());
[email protected]ba91a792013-02-06 09:48:28753}
754
fsamuel78f86e42016-01-20 04:10:23755void RenderWidget::DidCommitAndDrawCompositorFrame() {
756 // NOTE: Tests may break if this event is renamed or moved. See
757 // tab_capture_performancetest.cc.
758 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08759
ericwilligers88e69742016-10-17 19:29:55760 for (auto& observer : render_frames_)
761 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08762
fsamuel78f86e42016-01-20 04:10:23763 // Notify subclasses that we initiated the paint operation.
764 DidInitiatePaint();
765}
766
767void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:55768 for (auto& observer : render_frames_)
769 observer.DidCommitCompositorFrame();
770 for (auto& observer : render_frame_proxies_)
771 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:23772}
773
774void RenderWidget::DidCompletePageScaleAnimation() {}
775
danakj6c872fc02016-10-22 04:29:49776void RenderWidget::DidReceiveCompositorFrameAck() {
777 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
fsamuel78f86e42016-01-20 04:10:23778
pimanbfb2ceb2016-03-18 21:32:58779 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23780 return;
781 }
782
783 ViewHostMsg_UpdateRect_Params params;
784 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23785 params.flags = next_paint_flags_;
786
787 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
788 next_paint_flags_ = 0;
789 need_update_rect_for_auto_resize_ = false;
790}
791
fsamuel78f86e42016-01-20 04:10:23792void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
793 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
794}
795
796bool RenderWidget::IsClosing() const {
797 return host_closing_;
798}
799
danakj53eccbc2016-03-02 22:51:07800void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23801 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29802}
803
fsamuel78f86e42016-01-20 04:10:23804void RenderWidget::UpdateVisualState() {
lfg8ff33912016-09-13 20:59:21805 GetWebWidget()->updateAllLifecyclePhases();
fsamuel78f86e42016-01-20 04:10:23806}
807
808void RenderWidget::WillBeginCompositorFrame() {
809 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
810
dglazkov06854c5c2016-08-31 00:19:59811 // The UpdateTextInputState can result in further layout and possibly
812 // enable GPU acceleration so they need to be called before any painting
813 // is done.
814 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
815 UpdateSelectionBounds();
816
ericwilligers88e69742016-10-17 19:29:55817 for (auto& observer : render_frame_proxies_)
818 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:29819}
820
jbroman6ccbc7d472016-07-27 04:45:41821std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
822 std::unique_ptr<cc::CopyOutputRequest> request) {
823 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
824 routing_id_, std::move(request));
825}
826
fsamuel72464894f2015-12-15 06:59:31827///////////////////////////////////////////////////////////////////////////////
828// RenderWidgetInputHandlerDelegate
829
avid7d6b2e2016-03-04 19:41:17830void RenderWidget::FocusChangeComplete() {
831 if (owner_delegate_)
832 owner_delegate_->RenderWidgetFocusChangeComplete();
833}
fsamuel72464894f2015-12-15 06:59:31834
835bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17836 if (owner_delegate_)
837 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
838
fsamuel72464894f2015-12-15 06:59:31839 return true;
840}
841
dtapuska1827dd22016-03-11 15:24:59842void RenderWidget::ObserveGestureEventAndResult(
843 const blink::WebGestureEvent& gesture_event,
844 const gfx::Vector2dF& unused_delta,
845 bool event_processed) {
846 if (!compositor_deps_->IsElasticOverscrollEnabled())
847 return;
848
849 cc::InputHandlerScrollResult scroll_result;
850 scroll_result.did_scroll = event_processed;
851 scroll_result.did_overscroll_root = !unused_delta.IsZero();
852 scroll_result.unused_scroll_delta = unused_delta;
853
854 RenderThreadImpl* render_thread = RenderThreadImpl::current();
855 InputHandlerManager* input_handler_manager =
856 render_thread ? render_thread->input_handler_manager() : NULL;
857 if (input_handler_manager) {
858 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
859 routing_id_, gesture_event, scroll_result);
860 }
861}
862
avid7d6b2e2016-03-04 19:41:17863void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:46864 ClearEditCommands();
865}
866
867void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
868 const std::string& value) {
869 ClearEditCommands();
870 edit_commands_.emplace_back(name, value);
871}
872
873void RenderWidget::ClearEditCommands() {
874 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:17875}
fsamuel72464894f2015-12-15 06:59:31876
chongza8ba91fc2016-08-16 21:39:17877void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:31878 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
879}
880
dchengcedca5612016-04-09 01:40:15881void RenderWidget::OnInputEventAck(
882 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:31883 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
884}
885
dtapuska46616922016-03-17 22:52:01886void RenderWidget::NotifyInputEventHandled(
dtapuskab08721e62016-06-29 03:35:07887 blink::WebInputEvent::Type handled_type,
888 InputEventAckState ack_result) {
dtapuska0bd451a2016-02-18 17:08:10889 RenderThreadImpl* render_thread = RenderThreadImpl::current();
890 InputHandlerManager* input_handler_manager =
891 render_thread ? render_thread->input_handler_manager() : NULL;
892 if (input_handler_manager) {
dtapuskab08721e62016-06-29 03:35:07893 input_handler_manager->NotifyInputEventHandledOnMainThread(
894 routing_id_, handled_type, ack_result);
dtapuska0bd451a2016-02-18 17:08:10895 }
896}
897
fsamuele8326c742016-01-12 00:49:39898void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
899 // Nothing to do here. RenderWidget created the |input_handler| and will take
900 // ownership of it. We just verify here that we don't already have an input
901 // handler.
902 DCHECK(!input_handler_);
903}
904
fsamuel72464894f2015-12-15 06:59:31905void RenderWidget::UpdateTextInputState(ShowIme show_ime,
906 ChangeSource change_source) {
907 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
908 if (ime_event_guard_) {
909 // show_ime should still be effective even if it was set inside the IME
910 // event guard.
911 if (show_ime == ShowIme::IF_NEEDED) {
912 ime_event_guard_->set_show_ime(true);
913 }
914 return;
915 }
916
dglazkov97b6c2b2016-10-25 17:35:55917 ui::TextInputType new_type = GetTextInputType();
918 if (IsDateTimeInput(new_type))
919 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:31920
dglazkov97b6c2b2016-10-25 17:35:55921 blink::WebTextInputInfo new_info;
922 if (GetWebWidget())
923 new_info = GetWebWidget()->textInputInfo();
dtapuskac4dd5be2016-10-25 15:11:10924 const ui::TextInputMode new_mode =
925 ConvertWebTextInputMode(new_info.inputMode);
fsamuel72464894f2015-12-15 06:59:31926
927 bool new_can_compose_inline = CanComposeInline();
928
929 // Only sends text input params if they are changed or if the ime should be
930 // shown.
931 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:39932 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
dglazkov97b6c2b2016-10-25 17:35:55933 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
934 text_input_info_ != new_info ||
fsamuel72464894f2015-12-15 06:59:31935 can_compose_inline_ != new_can_compose_inline)
936#if defined(OS_ANDROID)
937 || text_field_is_dirty_
938#endif
939 ) {
ekaramad9053e57b2016-04-26 20:00:38940 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:55941 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:31942 params.mode = new_mode;
943 params.flags = new_info.flags;
944 params.value = new_info.value.utf8();
945 params.selection_start = new_info.selectionStart;
946 params.selection_end = new_info.selectionEnd;
947 params.composition_start = new_info.compositionStart;
948 params.composition_end = new_info.compositionEnd;
949 params.can_compose_inline = new_can_compose_inline;
950 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
951#if defined(USE_AURA)
952 params.is_non_ime_change = true;
953#endif
954#if defined(OS_ANDROID)
955 params.is_non_ime_change =
956 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
fsamuel72464894f2015-12-15 06:59:31957 if (params.is_non_ime_change)
958 OnImeEventSentForAck(new_info);
959 text_field_is_dirty_ = false;
960#endif
961 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
962
963 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:55964 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:31965 text_input_mode_ = new_mode;
966 can_compose_inline_ = new_can_compose_inline;
967 text_input_flags_ = new_info.flags;
968 }
969}
970
971bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:58972 possible_drag_event_info_.event_source =
973 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
974 possible_drag_event_info_.event_location =
975 gfx::Point(event.globalX, event.globalY);
avid7d6b2e2016-03-04 19:41:17976
fsamuel72464894f2015-12-15 06:59:31977 return false;
978}
979
980bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:55981 for (auto& observer : render_frames_)
982 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:08983
paulmeyer6ef5a792016-11-08 20:33:58984 possible_drag_event_info_.event_source =
985 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
986 possible_drag_event_info_.event_location =
987 gfx::Point(event.globalX, event.globalY);
988
avid7d6b2e2016-03-04 19:41:17989 if (owner_delegate_)
990 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
991
fsamuel72464894f2015-12-15 06:59:31992 return false;
[email protected]fd847792013-10-24 17:12:35993}
994
initial.commit09911bf2008-07-26 23:55:29995///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:39996// RenderWidgetScreenMetricsDelegate
997
998void RenderWidget::Redraw() {
999 set_next_paint_is_resize_ack();
1000 if (compositor_)
1001 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1002}
1003
bokanc63441c2016-04-27 15:49:121004void RenderWidget::ResizeWebWidget() {
lfg8ff33912016-09-13 20:59:211005 GetWebWidget()->resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121006}
1007
1008gfx::Size RenderWidget::GetSizeForWebWidget() const {
1009 if (IsUseZoomForDSFEnabled())
1010 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1011
1012 return size_;
1013}
1014
mfomitchev2600fd7c2016-02-17 20:53:391015void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581016 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271017 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1018 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581019
mfomitchev2600fd7c2016-02-17 20:53:391020 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581021
ccameron2f451532016-09-07 21:49:271022 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1023 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581024 OnDeviceScaleFactorChanged();
1025 ScheduleComposite();
1026 }
mfomitchev2600fd7c2016-02-17 20:53:391027
1028 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1029 // A resize ack shouldn't be requested if we have not ACK'd the previous
1030 // one.
1031 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1032 }
1033
1034 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211035 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391036 return;
1037
ianwene5fc5782016-08-18 04:05:151038 if (compositor_) {
mfomitchev2600fd7c2016-02-17 20:53:391039 compositor_->setViewportSize(params.physical_backing_size);
ianwene5fc5782016-08-18 04:05:151040 compositor_->setBottomControlsHeight(params.bottom_controls_height);
ccameronf408cab2016-09-14 16:54:421041 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
ianwene5fc5782016-08-18 04:05:151042 }
mfomitchev2600fd7c2016-02-17 20:53:391043
mfomitchev2600fd7c2016-02-17 20:53:391044 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391045
1046 // NOTE: We may have entered fullscreen mode without changing our size.
1047 bool fullscreen_change =
1048 is_fullscreen_granted_ != params.is_fullscreen_granted;
1049 is_fullscreen_granted_ = params.is_fullscreen_granted;
1050 display_mode_ = params.display_mode;
1051
bokanc63441c2016-04-27 15:49:121052 size_ = params.new_size;
1053 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391054
bokanc63441c2016-04-27 15:49:121055 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221056
mfomitchev2600fd7c2016-02-17 20:53:391057 WebSize visual_viewport_size;
1058
1059 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181060 visual_viewport_size = gfx::ScaleToCeiledSize(
1061 params.visible_viewport_size,
1062 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391063 } else {
1064 visual_viewport_size = visible_viewport_size_;
1065 }
1066
lfg8ff33912016-09-13 20:59:211067 GetWebWidget()->resizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391068
bokanc63441c2016-04-27 15:49:121069 // When resizing, we want to wait to paint before ACK'ing the resize. This
1070 // ensures that we only resize as fast as we can paint. We only need to
1071 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391072 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1073 // In this case there is no paint/composite and therefore no
1074 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1075 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1076 DCHECK(!params.needs_resize_ack);
1077 }
1078
1079 // Send the Resize_ACK flag once we paint again if requested.
1080 if (params.needs_resize_ack)
1081 set_next_paint_is_resize_ack();
1082
1083 if (fullscreen_change)
1084 DidToggleFullscreen();
1085
engedy6cb63c92016-02-23 14:14:581086 if (orientation_changed)
1087 OnOrientationChange();
1088
mfomitchev2600fd7c2016-02-17 20:53:391089 // If a resize ack is requested and it isn't set-up, then no more resizes will
1090 // come in and in general things will go wrong.
1091 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1092}
1093
1094void RenderWidget::SetScreenMetricsEmulationParameters(
1095 bool enabled,
1096 const blink::WebDeviceEmulationParams& params) {
1097 // This is only supported in RenderView.
1098 NOTREACHED();
1099}
1100
1101void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1102 const gfx::Rect& window_screen_rect) {
1103 view_screen_rect_ = view_screen_rect;
1104 window_screen_rect_ = window_screen_rect;
1105}
1106
1107///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461108// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291109
[email protected]3a1c8a8032013-03-18 22:35:321110void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401111 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051112 if (compositor_)
oshima750cb4342015-10-31 00:59:011113 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051114}
1115
[email protected]e195e582013-03-08 01:32:591116void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221117 DCHECK(!host_closing_);
1118
fsamuel78f86e42016-01-20 04:10:231119 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1120 compositor_deps_);
oshima750cb4342015-10-31 00:59:011121 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331122 OnDeviceScaleFactorChanged();
ccameronf408cab2016-09-14 16:54:421123 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
sievers71c62dd52015-10-07 01:44:391124 // For background pages and certain tests, we don't want to trigger
danakj1120f4c2016-09-15 02:05:321125 // CompositorFrameSink creation.
sievers71c62dd52015-10-07 01:44:391126 if (compositor_never_visible_ || !RenderThreadImpl::current())
1127 compositor_->SetNeverVisible();
1128
pimanc4af3072015-10-02 03:45:591129 StartCompositor();
staraz067f58242016-11-07 21:06:411130 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1131 compositor_->SetFrameSinkId(
1132 cc::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
[email protected]e195e582013-03-08 01:32:591133}
1134
ennef3c58142014-12-09 21:44:381135void RenderWidget::WillCloseLayerTreeView() {
1136 if (host_closing_)
1137 return;
1138
1139 // Prevent new compositors or output surfaces from being created.
1140 host_closing_ = true;
1141
[email protected]aeeedad2014-08-22 18:16:221142 // Always send this notification to prevent new layer tree views from
1143 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211144 if (blink::WebWidget* widget = GetWebWidget())
1145 widget->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221146}
1147
[email protected]180ef242013-11-07 06:50:461148blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281149 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061150}
1151
dglazkovf0e1d6d2015-10-10 02:13:481152void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1153 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1154 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1155 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1156 }
dglazkov79c426102015-08-31 21:22:431157
ericwilligers88e69742016-10-17 19:29:551158 for (auto& observer : render_frames_)
1159 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431160}
1161
jdduke491a3f0c2015-06-15 23:30:261162void RenderWidget::ScheduleComposite() {
1163 if (compositor_ &&
1164 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
skyostil32650d22016-09-26 16:58:231165 compositor_->setNeedsCompositorUpdate();
jdduke491a3f0c2015-06-15 23:30:261166 }
1167}
1168
1169void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1170 if (compositor_) {
1171 // Regardless of whether threaded compositing is enabled, always
1172 // use this mechanism to force the compositor to redraw. However,
1173 // the invalidation code path below is still needed for the
1174 // non-threaded case.
1175 compositor_->SetNeedsForcedRedraw();
1176 }
1177 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151178}
1179
[email protected]586871b2014-07-22 17:05:111180// static
dchengcedca5612016-04-09 01:40:151181std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111182 IPC::Message* msg,
1183 MessageDeliveryPolicy policy,
1184 FrameSwapMessageQueue* frame_swap_message_queue,
1185 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111186 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111187 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151188 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1189 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111190 &first_message_for_frame);
1191 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151192 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111193 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061194 return promise;
[email protected]586871b2014-07-22 17:05:111195 }
dcheng4b6b5ff2014-10-16 00:42:061196 return nullptr;
[email protected]586871b2014-07-22 17:05:111197}
1198
1199void RenderWidget::QueueMessage(IPC::Message* msg,
1200 MessageDeliveryPolicy policy) {
1201 // RenderThreadImpl::current() is NULL in some tests.
1202 if (!compositor_ || !RenderThreadImpl::current()) {
1203 Send(msg);
1204 return;
1205 }
1206
dchengcedca5612016-04-09 01:40:151207 std::unique_ptr<cc::SwapPromise> swap_promise =
1208 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111209 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111210 compositor_->GetSourceFrameNumber());
1211
1212 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321213 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351214 // Request a commit. This might either A) request a commit ahead of time
1215 // or B) request a commit which is not needed because there are not
1216 // pending updates. If B) then the commit will be skipped and the swap
1217 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1218 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1219 // can_cancel_commit is not unset.
1220 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111221 }
1222}
1223
[email protected]4873c7d2009-07-16 06:36:281224void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301225 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521226 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181227 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291228 // Only send a SetCursor message if we need to make a change.
1229 if (!current_cursor_.IsEqual(cursor)) {
1230 current_cursor_ = cursor;
1231 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1232 }
1233}
1234
1235// We are supposed to get a single call to Show for a newly created RenderWidget
1236// that was created via RenderWidget::CreateWebView. So, we wait until this
1237// point to dispatch the ShowWidget message.
1238//
1239// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281240// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291241//
[email protected]4873c7d2009-07-16 06:36:281242void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291243 DCHECK(!did_show_) << "received extraneous Show call";
1244 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1245 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1246
[email protected]8de12d942010-11-17 20:42:441247 if (did_show_)
1248 return;
1249
1250 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561251 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441252 // that's okay. It'll be ignored if as_popup is false, or the browser
1253 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561254 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1255 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291256}
1257
[email protected]2533ce12009-05-09 00:02:241258void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381259 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241260 Send(new ViewHostMsg_Close(routing_id_));
1261}
1262
dgozmancf9039cd2015-04-06 12:01:311263void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551264 for (auto& observer : render_frames_)
1265 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311266}
1267
[email protected]4873c7d2009-07-16 06:36:281268void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081269 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321270 if (is_swapped_out_) {
1271 // This widget is currently swapped out, and the active widget is in a
1272 // different process. Have the browser route the close request to the
1273 // active widget instead, so that the correct unload handlers are run.
1274 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1275 return;
1276 }
1277
initial.commit09911bf2008-07-26 23:55:291278 // If a page calls window.close() twice, we'll end up here twice, but that's
1279 // OK. It is safe to send multiple Close messages.
1280
[email protected]2533ce12009-05-09 00:02:241281 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1282 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1283 // could be closed before the JS finishes executing. So instead, post a
1284 // message back to the message loop, which won't run until the JS is
1285 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081286 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211287 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291288}
1289
[email protected]9017d7852013-11-21 17:47:351290void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151291 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351292 const SyntheticGestureCompletionCallback& callback) {
1293 DCHECK(!callback.is_null());
1294
1295 pending_synthetic_gesture_callbacks_.push(callback);
1296
1297 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321298 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351299
1300 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1301}
1302
initial.commit09911bf2008-07-26 23:55:291303void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031304 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381305 WillCloseLayerTreeView();
1306 compositor_.reset();
lfg8ff33912016-09-13 20:59:211307 if (webwidget_internal_) {
1308 webwidget_internal_->close();
1309 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291310 }
1311}
1312
bokan841fdc72016-10-06 00:16:351313void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1314 DCHECK(window_rect);
1315 float scale = popup_origin_scale_for_emulation_;
1316 if (!scale)
1317 return;
1318 window_rect->x =
1319 popup_view_origin_for_emulation_.x() +
1320 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1321 window_rect->y =
1322 popup_view_origin_for_emulation_.y() +
1323 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1324}
1325
1326void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1327 DCHECK(window_rect);
1328 float scale = popup_origin_scale_for_emulation_;
1329 if (!scale)
1330 return;
1331 window_rect->x =
1332 popup_screen_origin_for_emulation_.x() +
1333 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1334 window_rect->y =
1335 popup_screen_origin_for_emulation_.y() +
1336 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1337}
1338
[email protected]4873c7d2009-07-16 06:36:281339WebRect RenderWidget::windowRect() {
bokan841fdc72016-10-06 00:16:351340 WebRect rect;
bokan6b08cd22016-10-05 00:55:211341 if (pending_window_rect_count_) {
1342 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1343 // the RootWindowRect is probably going to return wrong results since the
1344 // browser may not have processed the Move yet. There isn't really anything
1345 // good to do in this case, and it shouldn't happen - since this size is
1346 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351347 rect = pending_window_rect_;
1348 } else {
1349 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211350 }
[email protected]2533ce12009-05-09 00:02:241351
bokan841fdc72016-10-06 00:16:351352 ScreenRectToEmulatedIfNeeded(&rect);
1353 return rect;
bokan6b08cd22016-10-05 00:55:211354}
1355
1356WebRect RenderWidget::viewRect() {
bokan841fdc72016-10-06 00:16:351357 WebRect rect = view_screen_rect_;
1358 ScreenRectToEmulatedIfNeeded(&rect);
1359 return rect;
initial.commit09911bf2008-07-26 23:55:291360}
1361
[email protected]180ef242013-11-07 06:50:461362void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301363 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541364 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301365}
1366
oshima33ec97cd2015-12-14 19:40:241367void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1368 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351369 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511370
[email protected]5b45ad42013-10-25 00:42:041371 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201372 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561373 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1374 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031375 } else {
bokanc007c3a2015-02-03 07:15:561376 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031377 }
initial.commit09911bf2008-07-26 23:55:291378 } else {
bokanc007c3a2015-02-03 07:15:561379 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291380 }
1381}
1382
[email protected]2533ce12009-05-09 00:02:241383void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1384 pending_window_rect_ = rect;
1385 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241386
bokan6b08cd22016-10-05 00:55:211387 // Popups don't get size updates back from the browser so just store the set
1388 // values.
1389 if (popup_type_ != blink::WebPopupTypeNone) {
1390 window_screen_rect_ = rect;
1391 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241392 }
[email protected]d4547452008-08-28 18:36:371393}
1394
[email protected]fa7b1dc2010-06-23 17:53:041395void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261396 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041397 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071398 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041399 int selection_start, int selection_end) {
ekaramad2a46d632016-07-19 13:33:091400#if defined(ENABLE_PLUGINS)
1401 if (focused_pepper_plugin_) {
1402 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1403 text, underlines, selection_start, selection_end);
1404 return;
1405 }
1406#endif
1407 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211408 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031409 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091410 }
1411
[email protected]0d1ebed12013-08-05 22:01:131412 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281413 return;
[email protected]66fca5bc2013-05-23 06:58:291414 ImeEventGuard guard(this);
lfg8ff33912016-09-13 20:59:211415 if (!GetWebWidget()->setComposition(
1416 text, WebVector<WebCompositionUnderline>(underlines), selection_start,
1417 selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041418 // If we failed to set the composition text, then we need to let the browser
1419 // process to cancel the input method's ongoing composition session, to make
1420 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221421 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261422 }
nonafa291792016-08-10 02:36:181423 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041424}
1425
aelias87b8f7c2016-09-14 03:19:291426void RenderWidget::OnImeCommitText(const base::string16& text,
1427 const gfx::Range& replacement_range,
1428 int relative_cursor_pos) {
ekaramad2a46d632016-07-19 13:33:091429#if defined(ENABLE_PLUGINS)
1430 if (focused_pepper_plugin_) {
aelias87b8f7c2016-09-14 03:19:291431 focused_pepper_plugin_->render_frame()->OnImeCommitText(
1432 text, replacement_range, relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091433 return;
1434 }
1435#endif
1436 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211437 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031438 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091439 }
1440
[email protected]0d1ebed12013-08-05 22:01:131441 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041442 return;
[email protected]66fca5bc2013-05-23 06:58:291443 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391444 input_handler_->set_handling_input_event(true);
aelias87b8f7c2016-09-14 03:19:291445 GetWebWidget()->commitText(text, relative_cursor_pos);
1446 input_handler_->set_handling_input_event(false);
1447 UpdateCompositionInfo(false /* not an immediate request */);
1448}
1449
1450void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
1451#if defined(ENABLE_PLUGINS)
1452 if (focused_pepper_plugin_) {
1453 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText(
1454 keep_selection);
1455 return;
1456 }
1457#endif
1458
1459 if (!ShouldHandleImeEvent())
1460 return;
1461 ImeEventGuard guard(this);
1462 input_handler_->set_handling_input_event(true);
1463 GetWebWidget()->finishComposingText(keep_selection
1464 ? WebWidget::KeepSelection
1465 : WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391466 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181467 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291468}
1469
oshimad5279032015-12-16 18:22:331470void RenderWidget::OnDeviceScaleFactorChanged() {
1471 if (!compositor_)
1472 return;
oshimad5279032015-12-16 18:22:331473 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181474 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331475 else
1476 compositor_->setDeviceScaleFactor(device_scale_factor_);
1477}
1478
[email protected]0bc1f572013-04-17 01:46:311479void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121480 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211481 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121482 return;
1483
[email protected]0bc1f572013-04-17 01:46:311484 // Even if the browser provides an empty damage rect, it's still expecting to
1485 // receive a repaint ack so just damage the entire widget bounds.
1486 if (size_to_paint.IsEmpty()) {
1487 size_to_paint = size_;
1488 }
1489
[email protected]ec7dc112008-08-06 05:30:121490 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051491 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311492 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121493}
1494
[email protected]79fa22e2013-08-23 15:18:121495void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351496 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1497
1498 pending_synthetic_gesture_callbacks_.front().Run();
1499 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271500}
1501
[email protected]4873c7d2009-07-16 06:36:281502void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211503 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111504 return;
lfg8ff33912016-09-13 20:59:211505 GetWebWidget()->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111506}
1507
[email protected]80ad8622012-11-07 16:33:031508void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1509 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511510 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391511 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1512 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511513 } else {
mfomitchev2600fd7c2016-02-17 20:53:391514 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511515 }
[email protected]80ad8622012-11-07 16:33:031516 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1517}
1518
lfgdb5c4ed2016-03-04 23:09:071519void RenderWidget::OnUpdateWindowScreenRect(
1520 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211521 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071522 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211523 else
lfgdb5c4ed2016-03-04 23:09:071524 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071525}
1526
dtrainor5ef644e2015-11-19 00:12:471527void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1528 if (compositor_)
1529 compositor_->OnHandleCompositorProto(proto);
1530}
1531
[email protected]adb362312014-06-28 06:04:241532void RenderWidget::showImeIfNeeded() {
boliu7b2be2f2016-11-04 04:58:311533#if defined(OS_ANDROID) || defined(USE_AURA)
1534 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
1535#endif
1536
1537// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1538// virtual keyboard.
1539#if !defined(OS_ANDROID)
1540 FocusChangeComplete();
1541#endif
[email protected]0d1ebed12013-08-05 22:01:131542}
1543
fsamuel72464894f2015-12-15 06:59:311544ui::TextInputType RenderWidget::GetTextInputType() {
ekaramad2a46d632016-07-19 13:33:091545#if defined(ENABLE_PLUGINS)
1546 if (focused_pepper_plugin_)
1547 return focused_pepper_plugin_->text_input_type();
1548#endif
lfg8ff33912016-09-13 20:59:211549 if (GetWebWidget())
dtapuskac4dd5be2016-10-25 15:11:101550 return ConvertWebTextInputType(GetWebWidget()->textInputType());
fsamuel72464894f2015-12-15 06:59:311551 return ui::TEXT_INPUT_TYPE_NONE;
1552}
1553
nonafa291792016-08-10 02:36:181554void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1555 if (!monitor_composition_info_ && !immediate_request)
1556 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591557
nonafa291792016-08-10 02:36:181558 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1559 gfx::Range range;
1560 std::vector<gfx::Rect> character_bounds;
1561
1562 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1563 // Composition information is only available on editable node.
1564 range = gfx::Range::InvalidRange();
1565 } else {
1566 GetCompositionRange(&range);
1567 GetCompositionCharacterBounds(&character_bounds);
1568 }
1569
1570 if (!immediate_request &&
1571 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311572 return;
nonafa291792016-08-10 02:36:181573 }
fsamuel72464894f2015-12-15 06:59:311574 composition_character_bounds_ = character_bounds;
1575 composition_range_ = range;
1576 Send(new InputHostMsg_ImeCompositionRangeChanged(
1577 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311578}
1579
oshimaf866dab2015-12-05 00:41:541580void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1581 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461582 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331583 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541584 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461585 gfx::Rect window_rect =
1586 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1587 rect->x = window_rect.x();
1588 rect->y = window_rect.y();
1589 rect->width = window_rect.width();
1590 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541591 }
1592}
1593
oshimaa6985b62016-01-27 08:58:301594void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1595 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181596 rect->x *= GetOriginalDeviceScaleFactor();
1597 rect->y *= GetOriginalDeviceScaleFactor();
1598 rect->width *= GetOriginalDeviceScaleFactor();
1599 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301600 }
1601}
1602
[email protected]adb362312014-06-28 06:04:241603#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371604void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1605 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131606}
1607
1608void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371609 DCHECK_GE(text_input_info_history_.size(), 1u);
1610 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511611}
changwan8c342742016-02-26 00:53:391612
1613void RenderWidget::OnRequestTextInputStateUpdate() {
1614 DCHECK(!ime_event_guard_);
1615 UpdateSelectionBounds();
1616 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1617}
[email protected]105dffb42013-02-20 03:46:211618#endif
1619
nonafa291792016-08-10 02:36:181620void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1621 bool monitor_request) {
1622 monitor_composition_info_ = monitor_request;
1623 if (!immediate_request)
1624 return;
1625 UpdateCompositionInfo(true /* immediate request */);
1626}
1627
[email protected]0d1ebed12013-08-05 22:01:131628bool RenderWidget::ShouldHandleImeEvent() {
1629#if defined(OS_ANDROID)
lfg8ff33912016-09-13 20:59:211630 if (!GetWebWidget())
changwan3a841162015-08-11 02:53:371631 return false;
changwan8c342742016-02-26 00:53:391632 if (IsUsingImeThread())
1633 return true;
changwan3a841162015-08-11 02:53:371634
1635 // We cannot handle IME events if there is any chance that the event we are
1636 // receiving here from the browser is based on the state that is different
1637 // from our current one as indicated by |text_input_info_|.
1638 // The states the browser might be in are:
1639 // text_input_info_history_[0] - current state ack'd by browser
1640 // text_input_info_history_[1...N] - pending state changes
1641 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1642 if (text_input_info_history_[i] != text_input_info_)
1643 return false;
1644 }
1645 return true;
[email protected]0d1ebed12013-08-05 22:01:131646#else
lfg8ff33912016-09-13 20:59:211647 return !!GetWebWidget();
[email protected]0d1ebed12013-08-05 22:01:131648#endif
1649}
1650
wjmaclean8a795f32016-08-11 23:49:581651void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191652 if (device_scale_factor_ == device_scale_factor)
1653 return;
1654
1655 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331656
1657 OnDeviceScaleFactorChanged();
jdduke491a3f0c2015-06-15 23:30:261658 ScheduleComposite();
wjmaclean8a795f32016-08-11 23:49:581659
1660 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191661}
1662
[email protected]28ed6b32014-06-08 02:16:271663bool RenderWidget::SetDeviceColorProfile(
1664 const std::vector<char>& color_profile) {
1665 if (device_color_profile_ == color_profile)
1666 return false;
1667
1668 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271669
avi40b5be7a2016-03-03 21:13:441670 if (owner_delegate_)
1671 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1672
1673 return true;
noeldb4df152014-09-16 17:45:201674}
1675
[email protected]fcdc5642014-05-09 14:32:241676void RenderWidget::OnOrientationChange() {
1677}
1678
[email protected]bee16aab2009-08-26 15:55:031679void RenderWidget::SetHidden(bool hidden) {
1680 if (is_hidden_ == hidden)
1681 return;
1682
jdduke8fac9d102014-12-20 02:40:131683 // The status has changed. Tell the RenderThread about it and ensure
1684 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031685 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131686
[email protected]bee16aab2009-08-26 15:55:031687 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001688 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031689 else
[email protected]b2db9272014-01-10 17:42:001690 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111691
1692 if (render_widget_scheduling_state_)
1693 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031694}
1695
[email protected]2b624c562011-10-27 22:58:261696void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:211697 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:261698 return;
1699
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121700 if (is_fullscreen_granted_) {
lfg8ff33912016-09-13 20:59:211701 GetWebWidget()->didEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261702 } else {
lfg8ff33912016-09-13 20:59:211703 GetWebWidget()->didExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261704 }
[email protected]2b624c562011-10-27 22:58:261705}
1706
[email protected]674741932009-02-04 23:44:461707bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051708 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461709}
1710
[email protected]674741932009-02-04 23:44:461711void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051712 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461713}
1714
[email protected]674741932009-02-04 23:44:461715void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051716 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461717}
1718
changwan8c342742016-02-26 00:53:391719bool RenderWidget::IsUsingImeThread() {
1720#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121721 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391722#else
1723 return false;
1724#endif
1725}
1726
changwanf2a707b2015-10-30 08:22:161727void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1728 if (!ime_event_guard_)
1729 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291730}
1731
changwanf2a707b2015-10-30 08:22:161732void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1733 if (ime_event_guard_ != guard) {
1734#if defined(OS_ANDROID)
1735 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1736 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391737 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161738 // Therefore, we want to mark this text state update as 'from IME' only
1739 // when all the nested events are all originating from IME.
1740 ime_event_guard_->set_from_ime(
1741 ime_event_guard_->from_ime() && guard->from_ime());
1742#endif
1743 return;
1744 }
1745 ime_event_guard_ = nullptr;
1746
[email protected]66fca5bc2013-05-23 06:58:291747 // While handling an ime event, text input state and selection bounds updates
1748 // are ignored. These must explicitly be updated once finished handling the
1749 // ime event.
1750 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471751#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161752 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311753 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1754 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471755#endif
[email protected]66fca5bc2013-05-23 06:58:291756}
1757
[email protected]7c8873e2013-02-05 08:03:011758void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
ekaramad2a46d632016-07-19 13:33:091759#if defined(ENABLE_PLUGINS)
1760 if (focused_pepper_plugin_) {
1761 // TODO(kinaba) http://crbug.com/101101
1762 // Current Pepper IME API does not handle selection bounds. So we simply
1763 // use the caret position as an empty range for now. It will be updated
1764 // after Pepper API equips features related to surrounding text retrieval.
1765 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1766 convertViewportToWindow(&caret);
1767 *focus = caret;
1768 *anchor = caret;
1769 return;
1770 }
1771#endif
[email protected]7c8873e2013-02-05 08:03:011772 WebRect focus_webrect;
1773 WebRect anchor_webrect;
lfg8ff33912016-09-13 20:59:211774 GetWebWidget()->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241775 convertViewportToWindow(&focus_webrect);
1776 convertViewportToWindow(&anchor_webrect);
1777 *focus = focus_webrect;
1778 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321779}
1780
[email protected]e99ef6f2011-10-16 01:13:001781void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081782 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:211783 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:001784 return;
changwanf2a707b2015-10-30 08:22:161785 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291786 return;
[email protected]e99ef6f2011-10-16 01:13:001787
mohsenb0eeba72015-08-09 06:20:081788#if defined(USE_AURA)
1789 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1790 // Aura beucause composited selection updates are not working for webview tags
1791 // which regresses IME inside webview. Remove this when composited selection
1792 // updates are fixed for webviews. See, http://crbug.com/510568.
1793 bool send_ipc = true;
1794#else
jddukeacf809e2014-09-23 20:38:381795 // With composited selection updates, the selection bounds will be reported
1796 // directly by the compositor, in which case explicit IPC selection
1797 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081798 bool send_ipc =
1799 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1800#endif
1801 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381802 ViewHostMsg_SelectionBounds_Params params;
1803 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1804 if (selection_anchor_rect_ != params.anchor_rect ||
1805 selection_focus_rect_ != params.focus_rect) {
1806 selection_anchor_rect_ = params.anchor_rect;
1807 selection_focus_rect_ = params.focus_rect;
lfg8ff33912016-09-13 20:59:211808 GetWebWidget()->selectionTextDirection(params.focus_dir,
1809 params.anchor_dir);
1810 params.is_anchor_first = GetWebWidget()->isSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:381811 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1812 }
[email protected]58b48a0d2012-06-13 07:01:351813 }
jddukeacf809e2014-09-23 20:38:381814
nonafa291792016-08-10 02:36:181815 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:001816}
1817
avi40b5be7a2016-03-03 21:13:441818void RenderWidget::SetDeviceColorProfileForTesting(
1819 const std::vector<char>& color_profile) {
1820 SetDeviceColorProfile(color_profile);
1821}
1822
lfgb00fcad2016-07-14 14:16:331823void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
1824 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
1825 convertViewportToWindow(&new_size_in_window);
1826 if (size_.width() != new_size_in_window.width ||
1827 size_.height() != new_size_in_window.height) {
1828 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
1829
1830 if (resizing_mode_selector_->is_synchronous_mode()) {
bokan6b08cd22016-10-05 00:55:211831 gfx::Rect new_pos(windowRect().x, windowRect().y,
lfg0140a452016-07-19 19:15:051832 size_.width(), size_.height());
lfgb00fcad2016-07-14 14:16:331833 view_screen_rect_ = new_pos;
1834 window_screen_rect_ = new_pos;
1835 }
1836
1837 AutoResizeCompositor();
1838
1839 if (!resizing_mode_selector_->is_synchronous_mode())
1840 need_update_rect_for_auto_resize_ = true;
1841 }
1842}
1843
[email protected]58b48a0d2012-06-13 07:01:351844void RenderWidget::GetCompositionCharacterBounds(
1845 std::vector<gfx::Rect>* bounds) {
1846 DCHECK(bounds);
1847 bounds->clear();
ekaramad2a46d632016-07-19 13:33:091848
1849#if defined(ENABLE_PLUGINS)
1850 if (focused_pepper_plugin_)
1851 return;
1852#endif
1853
lfg8ff33912016-09-13 20:59:211854 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:091855 return;
1856 blink::WebVector<blink::WebRect> bounds_from_blink;
lfg8ff33912016-09-13 20:59:211857 if (!GetWebWidget()->getCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:091858 return;
1859
1860 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
1861 convertViewportToWindow(&bounds_from_blink[i]);
1862 bounds->push_back(bounds_from_blink[i]);
1863 }
[email protected]58b48a0d2012-06-13 07:01:351864}
1865
[email protected]db4fc1e2013-09-06 20:01:511866void RenderWidget::GetCompositionRange(gfx::Range* range) {
ekaramad2a46d632016-07-19 13:33:091867#if defined(ENABLE_PLUGINS)
1868 if (focused_pepper_plugin_)
1869 return;
1870#endif
lfg8ff33912016-09-13 20:59:211871 WebRange web_range = GetWebWidget()->compositionRange();
nona2363a3d2016-11-09 03:26:211872 if (web_range.isNull()) {
1873 *range = gfx::Range::InvalidRange();
1874 return;
[email protected]88dbe32f2013-06-20 23:31:361875 }
nona2363a3d2016-11-09 03:26:211876 range->set_start(web_range.startOffset());
1877 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:361878}
1879
[email protected]501ea13d2013-07-09 17:03:291880bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511881 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291882 const std::vector<gfx::Rect>& bounds) {
1883 if (composition_range_ != range)
1884 return true;
1885 if (bounds.size() != composition_character_bounds_.size())
1886 return true;
1887 for (size_t i = 0; i < bounds.size(); ++i) {
1888 if (bounds[i] != composition_character_bounds_[i])
1889 return true;
1890 }
1891 return false;
1892}
[email protected]501ea13d2013-07-09 17:03:291893
[email protected]ad26ef42011-06-17 07:59:451894bool RenderWidget::CanComposeInline() {
ekaramad2a46d632016-07-19 13:33:091895#if defined(ENABLE_PLUGINS)
1896 if (focused_pepper_plugin_)
1897 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
1898#endif
[email protected]ad26ef42011-06-17 07:59:451899 return true;
[email protected]56ea1a62011-05-30 07:05:571900}
1901
ccameron2f451532016-09-07 21:49:271902blink::WebScreenInfo RenderWidget::screenInfo() {
1903 blink::WebScreenInfo web_screen_info;
1904 web_screen_info.deviceScaleFactor = screen_info_.device_scale_factor;
1905 web_screen_info.depth = screen_info_.depth;
1906 web_screen_info.depthPerComponent = screen_info_.depth_per_component;
1907 web_screen_info.isMonochrome = screen_info_.is_monochrome;
1908 web_screen_info.rect = blink::WebRect(screen_info_.rect);
1909 web_screen_info.availableRect = blink::WebRect(screen_info_.available_rect);
1910 switch (screen_info_.orientation_type) {
1911 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
1912 web_screen_info.orientationType =
1913 blink::WebScreenOrientationPortraitPrimary;
1914 break;
1915 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
1916 web_screen_info.orientationType =
1917 blink::WebScreenOrientationPortraitSecondary;
1918 break;
1919 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
1920 web_screen_info.orientationType =
1921 blink::WebScreenOrientationLandscapePrimary;
1922 break;
1923 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
1924 web_screen_info.orientationType =
1925 blink::WebScreenOrientationLandscapeSecondary;
1926 break;
1927 default:
1928 web_screen_info.orientationType =
1929 blink::WebScreenOrientationUndefined;
1930 break;
1931 }
1932 web_screen_info.orientationAngle = screen_info_.orientation_angle;
1933 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:281934}
1935
[email protected]fa7b1dc2010-06-23 17:53:041936void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021937 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041938 // If the last text input type is not None, then we should finish any
1939 // ongoing composition regardless of the new text input type.
dglazkov97b6c2b2016-10-25 17:35:551940 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041941 // If a composition text exists, then we need to let the browser process
1942 // to cancel the input method's ongoing composition session.
aelias87b8f7c2016-09-14 03:19:291943 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection))
[email protected]a2214eb2014-06-23 18:31:221944 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041945 }
[email protected]d4cff272011-05-02 15:46:011946
nonafa291792016-08-10 02:36:181947 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041948}
1949
donnda070f3c2015-01-16 19:54:111950#if defined(OS_ANDROID)
1951void RenderWidget::showUnhandledTapUIIfNeeded(
1952 const WebPoint& tapped_position,
1953 const WebNode& tapped_node,
1954 bool page_changed) {
fsamuele8326c742016-01-12 00:49:391955 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:111956 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371957 !tapped_node.isContentEditable() &&
1958 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111959 if (should_trigger) {
1960 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1961 tapped_position.x, tapped_position.y));
1962 }
1963}
1964#endif
1965
[email protected]c68c3e4e2013-01-24 00:36:561966void RenderWidget::didHandleGestureEvent(
1967 const WebGestureEvent& event,
1968 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021969#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561970 if (event_cancelled)
1971 return;
[email protected]07c70d22014-08-21 08:33:461972 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:311973 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461974 } else if (event.type == WebInputEvent::GestureLongPress) {
lfg8ff33912016-09-13 20:59:211975 DCHECK(GetWebWidget());
1976 if (GetWebWidget()->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:311977 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461978 else
fsamuel72464894f2015-12-15 06:59:311979 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:561980 }
1981#endif
1982}
1983
sataya.m582c9ce2015-06-09 08:03:421984void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:311985 const blink::WebFloatSize& overscrollDelta,
1986 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:421987 const blink::WebFloatPoint& position,
1988 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:481989#if defined(OS_MACOSX)
1990 // On OSX the user can disable the elastic overscroll effect. If that's the
1991 // case, don't forward the overscroll notification.
1992 DCHECK(compositor_deps());
1993 if (!compositor_deps()->IsElasticOverscrollEnabled())
1994 return;
1995#endif
bokane53a10f2016-04-13 23:48:311996 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:391997 position, velocity);
sataya.m582c9ce2015-06-09 08:03:421998}
1999
[email protected]7912e822014-04-16 02:37:032000void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392001 if (!is_hidden())
2002 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032003}
2004
[email protected]24ed0432013-04-24 07:50:312005RenderWidgetCompositor* RenderWidget::compositor() const {
2006 return compositor_.get();
2007}
2008
fsamuel72464894f2015-12-15 06:59:312009void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392010 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372011}
[email protected]c3d45532011-10-07 19:20:402012
[email protected]ce6689f2013-03-29 12:52:552013void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112014 if (render_widget_scheduling_state_)
2015 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552016 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2017}
2018
[email protected]5d0bbdfa92013-12-10 00:35:512019void RenderWidget::setTouchAction(
2020 blink::WebTouchAction web_touch_action) {
2021
2022 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2023 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392024 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512025 return;
2026
[email protected]a18f67a2013-12-20 19:44:362027 content::TouchAction content_touch_action =
2028 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512029 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2030}
2031
[email protected]90f24152014-04-09 12:41:362032void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2033#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392034 if (!IsUsingImeThread())
2035 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362036#endif
2037}
2038
[email protected]e3244ed2014-06-20 20:04:272039void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2040 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162041}
2042
[email protected]e3244ed2014-06-20 20:04:272043void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2044 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162045}
2046
[email protected]de3c5d82014-05-28 22:12:592047void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2048 render_frames_.AddObserver(frame);
2049}
2050
2051void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2052 render_frames_.RemoveObserver(frame);
2053}
2054
lfg43e08e62016-02-03 18:51:372055void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2056 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2057 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2058}
2059
oshima50872a72016-03-04 13:26:182060float RenderWidget::GetOriginalDeviceScaleFactor() const {
2061 return
2062 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272063 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182064 device_scale_factor_;
2065}
2066
lfgbee1e0a2016-06-08 21:24:212067bool RenderWidget::requestPointerLock() {
2068 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2069}
2070
2071void RenderWidget::requestPointerUnlock() {
2072 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2073}
2074
2075bool RenderWidget::isPointerLocked() {
2076 return mouse_lock_dispatcher_->IsMouseLockedTo(
2077 webwidget_mouse_lock_target_.get());
2078}
2079
paulmeyer6ef5a792016-11-08 20:33:582080void RenderWidget::startDragging(blink::WebReferrerPolicy policy,
2081 const WebDragData& data,
2082 WebDragOperationsMask mask,
2083 const WebImage& image,
2084 const WebPoint& webImageOffset) {
2085 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
2086 convertViewportToWindow(&offset_in_window);
2087 DropData drop_data(DropDataBuilder::Build(data));
2088 drop_data.referrer_policy = policy;
2089 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
2090 Send(new DragHostMsg_StartDragging(routing_id_, drop_data, mask,
2091 image.getSkBitmap(), imageOffset,
2092 possible_drag_event_info_));
2093}
2094
lfg8ff33912016-09-13 20:59:212095blink::WebWidget* RenderWidget::GetWebWidget() const {
2096 return webwidget_internal_;
2097}
2098
[email protected]e9ff79c2012-10-19 21:31:262099} // namespace content