blob: ee171f595d950efcb2d85b3a3de5361b38a6517a [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"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.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"
[email protected]681ccff2013-03-18 06:13:5226#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3327#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3028#include "cc/output/output_surface.h"
dyenb52ecd962016-04-20 23:23:4429#include "cc/output/vulkan_in_process_context_provider.h"
fsamuel78f86e42016-01-20 04:10:2330#include "cc/scheduler/begin_frame_source.h"
[email protected]556fd292013-03-18 08:03:0431#include "cc/trees/layer_tree_host.h"
alexclarke7fa93942015-10-21 15:37:1132#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2133#include "components/scheduler/renderer/renderer_scheduler.h"
oshima750cb4342015-10-31 00:59:0134#include "content/common/content_switches_internal.h"
[email protected]0634cdd42013-08-16 00:46:0935#include "content/common/gpu/client/context_provider_command_buffer.h"
fsamuelc28d985e2016-03-22 23:05:0236#include "content/common/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3537#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4438#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1539#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1540#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3841#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5042#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1243#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2944#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4245#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4046#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3947#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
[email protected]b2e4c70132013-10-03 02:07:5148#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5949#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1150#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5951#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1152#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2853#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2954#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1355#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3256#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1657#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2758#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0559#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4460#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5561#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4462#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0963#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0464#include "content/renderer/resizing_mode_selector.h"
danakj6f4e1e22016-04-20 03:27:3465#include "gpu/command_buffer/client/shared_memory_limits.h"
[email protected]484955942010-08-19 16:13:1866#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4867#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1868#include "third_party/WebKit/public/platform/WebCursorInfo.h"
donnda070f3c2015-01-16 19:54:1169#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3070#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1871#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3072#include "third_party/WebKit/public/platform/WebSize.h"
73#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4374#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5975#include "third_party/WebKit/public/web/WebFrameWidget.h"
76#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1177#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3178#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3179#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
80#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3881#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5982#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0883#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4184#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1385#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5086#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0987#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3288#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4889#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2790#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4191#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4892
[email protected]eeb93112013-05-01 19:41:1093#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1594#include <android/keycodes.h>
boliubee541f42015-11-05 00:52:5395#include "content/renderer/android/synchronous_compositor_filter.h"
96#include "content/renderer/android/synchronous_compositor_output_surface.h"
[email protected]eeb93112013-05-01 19:41:1097#endif
98
[email protected]661eb9d2009-02-03 02:11:4899#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:49100#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:52101#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41102#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48103#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44104
penghuang28a5fa22015-12-02 17:58:19105#if defined(MOJO_SHELL_CLIENT)
106#include "content/public/common/mojo_shell_connection.h"
fsamuel2545ecc2015-12-05 00:44:46107#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:19108#endif
109
[email protected]180ef242013-11-07 06:50:46110using blink::WebCompositionUnderline;
111using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43112using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46113using blink::WebGestureEvent;
114using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49115using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46116using blink::WebKeyboardEvent;
117using 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;
124using blink::WebRange;
125using blink::WebRect;
126using blink::WebScreenInfo;
127using blink::WebSize;
128using blink::WebTextDirection;
129using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25130using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46131using blink::WebVector;
132using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26133
danakj365175c2016-02-06 00:37:37134#define STATIC_ASSERT_ENUM(a, b) \
135 static_assert(static_cast<int>(a) == static_cast<int>(b), \
136 "mismatching enums: " #a)
137
[email protected]6a4d7f62013-01-07 21:32:13138namespace {
[email protected]b256eca2013-07-11 10:57:40139
140typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
141
lfgbee1e0a2016-06-08 21:24:21142class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
143 public:
144 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
145 : webwidget_(webwidget) {}
146
147 void OnLockMouseACK(bool succeeded) override {
148 if (succeeded)
149 webwidget_->didAcquirePointerLock();
150 else
151 webwidget_->didNotAcquirePointerLock();
152 }
153
154 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
155
156 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
157 // The WebWidget handles mouse lock in Blink's handleInputEvent().
158 return false;
159 }
160
161 private:
162 blink::WebWidget* webwidget_;
163};
164
[email protected]b256eca2013-07-11 10:57:40165class TextInputModeMapSingleton {
166 public:
167 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22168 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40169 }
[email protected]dd705d4d2013-11-27 08:14:41170 TextInputModeMapSingleton() {
171 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
172 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
173 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
174 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
175 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
176 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
177 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
178 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
179 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
180 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
181 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40182 }
[email protected]dd705d4d2013-11-27 08:14:41183 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40184 private:
[email protected]dd705d4d2013-11-27 08:14:41185 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40186
olli.raula36aa8be2015-09-10 11:14:22187 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40188
189 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
190};
191
[email protected]dd705d4d2013-11-27 08:14:41192ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40193 static TextInputModeMapSingleton* singleton =
194 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41195 TextInputModeMap::const_iterator it =
196 singleton->map().find(input_mode.utf8());
197 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40198 return ui::TEXT_INPUT_MODE_DEFAULT;
199 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13200}
[email protected]b256eca2013-07-11 10:57:40201
fsamuel72464894f2015-12-15 06:59:31202bool IsDateTimeInput(ui::TextInputType type) {
203 return type == ui::TEXT_INPUT_TYPE_DATE ||
204 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
205 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
206 type == ui::TEXT_INPUT_TYPE_MONTH ||
207 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
dtapuskae7473612015-12-04 14:23:06208}
209
fsamuele8326c742016-01-12 00:49:39210content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
211 content::RenderWidget* widget) {
212#if defined(MOJO_SHELL_CLIENT)
penghuang639a1042016-01-14 21:25:29213 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
ben6c85c4492016-06-16 20:40:51214 if (content::MojoShellConnection::GetForProcess() &&
penghuang639a1042016-01-14 21:25:29215 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39216 return content::RenderWidgetMusConnection::GetOrCreate(
217 widget->routing_id());
218 }
219#endif
220 // If we don't have a connection to the Mojo shell, then we want to route IPCs
221 // back to the browser process rather than Mus so we use the |widget| as the
222 // RenderWidgetInputHandlerDelegate.
223 return widget;
224}
225
[email protected]b256eca2013-07-11 10:57:40226} // namespace
227
[email protected]e9ff79c2012-10-19 21:31:26228namespace content {
[email protected]62cb33cae2009-03-27 23:30:22229
[email protected]b2e4c70132013-10-03 02:07:51230// RenderWidget ---------------------------------------------------------------
231
dcheng35d31c112015-07-22 00:17:36232RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
233 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46234 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04235 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03236 bool hidden,
237 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29238 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36239 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53240 webwidget_(nullptr),
avi40b5be7a2016-03-03 21:13:44241 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29242 opener_id_(MSG_ROUTING_NONE),
initial.commit09911bf2008-07-26 23:55:29243 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51244 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09245 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29246 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04247 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39248 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12249 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12250 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16251 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48252 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22253 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44254 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20255 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45256 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40257 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20258 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53259 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12260 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48261 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04262 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52263 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30264 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13265#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36266 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13267#endif
[email protected]b2e4c70132013-10-03 02:07:51268 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11269 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42270 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08271 has_host_context_menu_location_(false),
272 has_focus_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05273 if (!swapped_out)
274 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27275 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53276 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37277#if defined(OS_ANDROID)
278 text_input_info_history_.push_back(blink::WebTextInputInfo());
279#endif
alexclarke7fa93942015-10-21 15:37:11280
281 // In tests there may not be a RenderThreadImpl.
282 if (RenderThreadImpl::current()) {
283 render_widget_scheduling_state_ = RenderThreadImpl::current()
284 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32285 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11286 render_widget_scheduling_state_->SetHidden(is_hidden_);
287 }
initial.commit09911bf2008-07-26 23:55:29288}
289
290RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11291 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16292
[email protected]992db4c2011-05-12 15:37:15293 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02294 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15295 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29296}
297
[email protected]484955942010-08-19 16:13:18298// static
avi1023d012015-12-25 02:39:14299RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53300 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46301 blink::WebPopupType popup_type,
302 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29303 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36304 scoped_refptr<RenderWidget> widget(new RenderWidget(
305 compositor_deps, popup_type, screen_info, false, false, false));
306 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46307 return widget.get();
[email protected]a635f942012-12-07 10:34:29308 }
309 return NULL;
initial.commit09911bf2008-07-26 23:55:29310}
311
[email protected]484955942010-08-19 16:13:18312// static
kenrba7199832015-01-22 23:44:59313RenderWidget* RenderWidget::CreateForFrame(
314 int routing_id,
kenrba7199832015-01-22 23:44:59315 bool hidden,
316 const blink::WebScreenInfo& screen_info,
317 CompositorDependencies* compositor_deps,
318 blink::WebLocalFrame* frame) {
319 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55320 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
321 // same routing ID for both the view routing ID and the main frame widget
322 // routing ID. https://crbug.com/545684
323 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
324 if (view) {
avi8a45c1092016-03-01 16:12:34325 view->AttachWebFrameWidget(
326 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
327 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55328 }
dcheng35d31c112015-07-22 00:17:36329 scoped_refptr<RenderWidget> widget(
330 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
331 false, hidden, false));
fsamuele8326c742016-01-12 00:49:39332 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20333 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59334 // DoInit increments the reference count on |widget|, keeping it alive after
335 // this function returns.
dcheng35d31c112015-07-22 00:17:36336 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59337 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
338 nullptr)) {
kenrba7199832015-01-22 23:44:59339 return widget.get();
340 }
341 return nullptr;
342}
343
344// static
lfgcaab5142016-02-26 19:06:52345blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08346 RenderWidget* render_widget,
347 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55348 if (!frame->parent()) {
349 // TODO(dcheng): The main frame widget currently has a special case.
350 // Eliminate this once WebView is no longer a WebWidget.
351 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
352 }
dchengda9b4bb2015-07-20 20:58:08353 return blink::WebFrameWidget::create(render_widget, frame);
354}
355
356// static
kenrba7199832015-01-22 23:44:59357blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18358 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46359 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18360 break;
[email protected]180ef242013-11-07 06:50:46361 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44362 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18363 default:
364 NOTREACHED();
365 }
366 return NULL;
367}
368
dchengda9b4bb2015-07-20 20:58:08369void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32370 OnClose();
kenrba7199832015-01-22 23:44:59371}
372
fsamuele8326c742016-01-12 00:49:39373void RenderWidget::SetRoutingID(int32_t routing_id) {
374 routing_id_ = routing_id;
375 input_handler_.reset(new RenderWidgetInputHandler(
376 GetRenderWidgetInputHandlerDelegate(this), this));
377}
378
avi1023d012015-12-25 02:39:14379bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39380 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05381 opener_id, RenderWidget::CreateWebWidget(this),
382 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39383 if (success) {
384 SetRoutingID(routing_id_);
385 return true;
386 }
387 return false;
[email protected]484955942010-08-19 16:13:18388}
389
avi1023d012015-12-25 02:39:14390bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06391 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18392 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29393 DCHECK(!webwidget_);
394
395 if (opener_id != MSG_ROUTING_NONE)
396 opener_id_ = opener_id;
397
[email protected]484955942010-08-19 16:13:18398 webwidget_ = web_widget;
lfgbee1e0a2016-06-08 21:24:21399 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
400 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29401
kenrba7199832015-01-22 23:44:59402 bool result = true;
403 if (create_widget_message)
404 result = RenderThread::Get()->Send(create_widget_message);
405
initial.commit09911bf2008-07-26 23:55:29406 if (result) {
[email protected]380244092011-10-07 17:26:27407 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29408 // Take a reference on behalf of the RenderThread. This will be balanced
409 // when we receive ViewMsg_Close.
410 AddRef();
[email protected]b2db9272014-01-10 17:42:00411 if (RenderThreadImpl::current()) {
412 RenderThreadImpl::current()->WidgetCreated();
413 if (is_hidden_)
414 RenderThreadImpl::current()->WidgetHidden();
415 }
fsamuele8326c742016-01-12 00:49:39416
[email protected]a635f942012-12-07 10:34:29417 return true;
initial.commit09911bf2008-07-26 23:55:29418 } else {
[email protected]a635f942012-12-07 10:34:29419 // The above Send can fail when the tab is closing.
420 return false;
initial.commit09911bf2008-07-26 23:55:29421 }
422}
423
[email protected]992db4c2011-05-12 15:37:15424void RenderWidget::SetSwappedOut(bool is_swapped_out) {
425 // We should only toggle between states.
426 DCHECK(is_swapped_out_ != is_swapped_out);
427 is_swapped_out_ = is_swapped_out;
428
429 // If we are swapping out, we will call ReleaseProcess, allowing the process
430 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52431 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15432 // If we are swapping in, we call AddRefProcess to prevent the process from
433 // exiting.
[email protected]949b6592014-08-20 13:17:52434 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15435 RenderProcess::current()->AddRefProcess();
436}
437
[email protected]949b6592014-08-20 13:17:52438void RenderWidget::WasSwappedOut() {
439 // If we have been swapped out and no one else is using this process,
440 // it's safe to exit now.
441 CHECK(is_swapped_out_);
442 RenderProcess::current()->ReleaseProcess();
443}
444
[email protected]b2e4c70132013-10-03 02:07:51445void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39446 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51447 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43448 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49449 popup_screen_origin_for_emulation_ = gfx::Point(
450 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
451 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56452 screen_info_ = emulator->original_screen_info();
453 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51454}
455
[email protected]2d6836f42014-07-02 17:25:31456gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
457 if (screen_metrics_emulator_)
458 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
459 return anchor;
460}
461
haibinluc643d33c2016-06-03 02:22:34462#if defined(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51463void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39464 ExternalPopupMenu* popup,
465 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49466 popup->SetOriginScaleAndOffsetForEmulation(
467 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51468}
[email protected]53907862014-03-25 15:42:40469#endif
[email protected]b2e4c70132013-10-03 02:07:51470
471void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
472 if (screen_metrics_emulator_)
473 screen_metrics_emulator_->OnShowContextMenu(params);
474}
475
[email protected]a95986a82010-12-24 06:19:28476bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
lfgbee1e0a2016-06-08 21:24:21477 if (mouse_lock_dispatcher_ &&
478 mouse_lock_dispatcher_->OnMessageReceived(message))
479 return true;
480
[email protected]a95986a82010-12-24 06:19:28481 bool handled = true;
482 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15483 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22484 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
485 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22486 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
487 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15488 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
489 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35490 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
491 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28492 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28493 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20494 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
495 OnEnableDeviceEmulation)
496 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
497 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41498 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54499 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28500 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41501 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25502 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28503 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
504 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03505 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05506 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
lfg43e08e62016-02-03 18:51:37507 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
508 OnWaitNextFrameForTests)
[email protected]105dffb42013-02-20 03:46:21509#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37510 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39511 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
512 OnRequestTextInputStateUpdate)
[email protected]2384b6c2013-02-28 23:58:51513 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21514#endif
dtrainor5ef644e2015-11-19 00:12:47515 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28516 IPC_MESSAGE_UNHANDLED(handled = false)
517 IPC_END_MESSAGE_MAP()
518 return handled;
519}
initial.commit09911bf2008-07-26 23:55:29520
521bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15522 // Don't send any messages after the browser has told us to close, and filter
523 // most outgoing messages while swapped out.
524 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26525 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11526 closing_) {
initial.commit09911bf2008-07-26 23:55:29527 delete message;
528 return false;
529 }
530
531 // If given a messsage without a routing ID, then assign our routing ID.
532 if (message->routing_id() == MSG_ROUTING_NONE)
533 message->set_routing_id(routing_id_);
534
[email protected]380244092011-10-07 17:26:27535 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44536}
537
bokanc007c3a2015-02-03 07:15:56538void RenderWidget::SetWindowRectSynchronously(
539 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39540 ResizeParams params;
541 params.screen_info = screen_info_;
542 params.new_size = new_window_rect.size();
543 params.physical_backing_size =
544 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39545 params.visible_viewport_size = new_window_rect.size();
546 params.resizer_rect = gfx::Rect();
547 params.is_fullscreen_granted = is_fullscreen_granted_;
548 params.display_mode = display_mode_;
549 params.needs_resize_ack = false;
550 Resize(params);
551
bokanc007c3a2015-02-03 07:15:56552 view_screen_rect_ = new_window_rect;
553 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02554 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56555 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02556}
557
initial.commit09911bf2008-07-26 23:55:29558void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32559 DCHECK(content::RenderThread::Get());
560 if (closing_)
561 return;
562 NotifyOnClose();
563 closing_ = true;
564
565 // Browser correspondence is no longer needed at this point.
566 if (routing_id_ != MSG_ROUTING_NONE) {
567 RenderThread::Get()->RemoveRoute(routing_id_);
568 SetHidden(false);
569 if (RenderThreadImpl::current())
570 RenderThreadImpl::current()->WidgetDestroyed();
571 }
572
573 if (for_oopif_) {
574 // Widgets for frames may be created and closed at any time while the frame
575 // is alive. However, the closing process must happen synchronously. Frame
576 // widget and frames hold pointers to each other. If Close() is deferred to
577 // the message loop like in the non-frame widget case, WebWidget::close()
578 // can end up accessing members of an already-deleted frame.
579 Close();
580 } else {
581 // If there is a Send call on the stack, then it could be dangerous to close
582 // now. Post a task that only gets invoked when there are no nested message
583 // loops.
584 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
585 FROM_HERE, base::Bind(&RenderWidget::Close, this));
586 }
587
588 // Balances the AddRef taken when we called AddRoute.
589 Release();
initial.commit09911bf2008-07-26 23:55:29590}
591
fsamuel664e8b62016-01-20 19:54:01592void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04593 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32594 return;
595
[email protected]b2e4c70132013-10-03 02:07:51596 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39597 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51598 return;
599 }
600
mfomitchev2600fd7c2016-02-17 20:53:39601 Resize(params);
initial.commit09911bf2008-07-26 23:55:29602}
603
dgozman9260b0a12015-03-16 13:45:20604void RenderWidget::OnEnableDeviceEmulation(
605 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39606 if (!screen_metrics_emulator_) {
607 ResizeParams resize_params;
608 resize_params.screen_info = screen_info_;
609 resize_params.new_size = size_;
610 resize_params.physical_backing_size = physical_backing_size_;
611 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39612 resize_params.resizer_rect = resizer_rect_;
613 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
614 resize_params.display_mode = display_mode_;
615 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
616 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18617 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39618 } else {
dgozman9260b0a12015-03-16 13:45:20619 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39620 }
dgozman9260b0a12015-03-16 13:45:20621}
622
623void RenderWidget::OnDisableDeviceEmulation() {
624 screen_metrics_emulator_.reset();
625}
626
noel89949e62014-09-30 01:12:41627void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
628 SetDeviceColorProfile(color_profile);
629}
630
[email protected]b5913d72012-02-07 22:26:54631void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01632 if (resizer_rect_ == resizer_rect)
633 return;
634 resizer_rect_ = resizer_rect;
635 if (webwidget_)
636 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54637}
638
initial.commit09911bf2008-07-26 23:55:29639void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31640 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29641 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03642 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59643 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
644 WasHidden());
initial.commit09911bf2008-07-26 23:55:29645}
646
[email protected]3399dd822014-08-09 11:14:24647void RenderWidget::OnWasShown(bool needs_repainting,
648 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41649 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29650 // During shutdown we can just ignore this message.
651 if (!webwidget_)
652 return;
653
654 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03655 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59656 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
657 WasShown());
initial.commit09911bf2008-07-26 23:55:29658
[email protected]8a23afb32014-04-30 22:40:23659 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29660 return;
initial.commit09911bf2008-07-26 23:55:29661
662 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24663 if (compositor_) {
664 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15665 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24666 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05667 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24668 }
jdduke491a3f0c2015-06-15 23:30:26669 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29670}
671
[email protected]53d3f302009-12-21 04:42:05672void RenderWidget::OnRequestMoveAck() {
673 DCHECK(pending_window_rect_count_);
674 pending_window_rect_count_--;
bokan71cb5b12016-04-27 03:45:22675 if (!pending_window_rect_count_)
676 view_screen_rect_ = pending_window_rect_;
[email protected]53d3f302009-12-21 04:42:05677}
678
[email protected]ed7defa2013-03-12 21:29:59679GURL RenderWidget::GetURLForGraphicsContext3D() {
680 return GURL();
[email protected]65225772011-05-12 21:10:24681}
682
fsamuel78f86e42016-01-20 04:10:23683void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10684 const ui::LatencyInfo& latency_info,
685 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23686 if (!input_event)
687 return;
dtapuska0bd451a2016-02-18 17:08:10688 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23689}
690
691void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
692 if (webwidget_)
693 webwidget_->setCursorVisibilityState(is_visible);
694}
695
696void RenderWidget::OnMouseCaptureLost() {
697 if (webwidget_)
698 webwidget_->mouseCaptureLost();
699}
700
701void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08702 has_focus_ = enable;
703
fsamuel78f86e42016-01-20 04:10:23704 if (webwidget_)
705 webwidget_->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08706
707 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
708 RenderWidgetSetFocus(enable));
fsamuel78f86e42016-01-20 04:10:23709}
710
711///////////////////////////////////////////////////////////////////////////////
712// RenderWidgetCompositorDelegate
713
714void RenderWidget::ApplyViewportDeltas(
715 const gfx::Vector2dF& inner_delta,
716 const gfx::Vector2dF& outer_delta,
717 const gfx::Vector2dF& elastic_overscroll_delta,
718 float page_scale,
719 float top_controls_delta) {
720 webwidget_->applyViewportDeltas(inner_delta, outer_delta,
721 elastic_overscroll_delta, page_scale,
722 top_controls_delta);
723}
724
725void RenderWidget::BeginMainFrame(double frame_time_sec) {
726 webwidget_->beginFrame(frame_time_sec);
727}
728
dchengcedca5612016-04-09 01:40:15729std::unique_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(
730 bool fallback) {
piman990d8ea2016-01-12 15:35:31731 DCHECK(webwidget_);
[email protected]7912e822014-04-16 02:37:03732 // For widgets that are never visible, we don't start the compositor, so we
733 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39734 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:19735
avi83883c82014-12-23 00:08:49736 const base::CommandLine& command_line =
737 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33738 bool use_software = fallback;
739 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
740 use_software = true;
741
penghuang28a5fa22015-12-02 17:58:19742#if defined(MOJO_SHELL_CLIENT)
ben6c85c4492016-06-16 20:40:51743 if (MojoShellConnection::GetForProcess() && !use_software &&
rockot19c030e862016-02-26 05:46:58744 command_line.HasSwitch(switches::kUseMusInRenderer)) {
penghuang28a5fa22015-12-02 17:58:19745 RenderWidgetMusConnection* connection =
746 RenderWidgetMusConnection::GetOrCreate(routing_id());
747 return connection->CreateOutputSurface();
748 }
749#endif
750
danakj3873e852016-05-05 00:46:07751 uint32_t output_surface_id = next_output_surface_id_++;
752
753 if (command_line.HasSwitch(switches::kEnableVulkan)) {
754 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider =
755 cc::VulkanInProcessContextProvider::Create();
756 if (vulkan_context_provider) {
hajimehoshiea85b9dc2016-05-25 09:52:31757 return base::WrapUnique(new CompositorOutputSurface(
758 routing_id(), output_surface_id, vulkan_context_provider,
759 frame_swap_message_queue_));
danakj3873e852016-05-05 00:46:07760 }
761 }
762
763 // Create a gpu process channel and verify we want to use GPU compositing
764 // before creating any context providers.
penghuang346a46f92016-03-31 21:37:52765 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host;
piman990d8ea2016-01-12 15:35:31766 if (!use_software) {
danakj3873e852016-05-05 00:46:07767 gpu_channel_host = RenderThreadImpl::current()->EstablishGpuChannelSync(
768 CAUSE_FOR_GPU_LAUNCH_RENDERER_VERIFY_GPU_COMPOSITING);
danakje8ec797e2016-04-19 04:08:43769 if (!gpu_channel_host) {
piman990d8ea2016-01-12 15:35:31770 // Cause the compositor to wait and try again.
771 return nullptr;
772 }
773 // We may get a valid channel, but with a software renderer. In that case,
774 // disable GPU compositing.
775 if (gpu_channel_host->gpu_info().software_rendering)
776 use_software = true;
777 }
778
danakj3873e852016-05-05 00:46:07779 if (use_software) {
hajimehoshiea85b9dc2016-05-25 09:52:31780 return base::WrapUnique(
781 new CompositorOutputSurface(routing_id(), output_surface_id, nullptr,
782 nullptr, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09783 }
piman8944e1c2015-09-22 21:10:34784
danakj3873e852016-05-05 00:46:07785 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider =
danakj0b4b94e32016-05-10 22:33:01786 RenderThreadImpl::current()->SharedCompositorWorkerContextProvider();
danakj3873e852016-05-05 00:46:07787 if (!worker_context_provider) {
788 // Cause the compositor to wait and try again.
789 return nullptr;
[email protected]ebc0e1df2013-08-01 02:46:22790 }
[email protected]ed7defa2013-03-12 21:29:59791
danakj3873e852016-05-05 00:46:07792 // The renderer compositor context doesn't do a lot of stuff, so we don't
793 // expect it to need a lot of space for commands or transfer. Raster and
794 // uploads happen on the worker context instead.
danakj0dd9e1e2016-05-11 22:15:09795 gpu::SharedMemoryLimits limits = gpu::SharedMemoryLimits::ForMailboxContext();
danakj3873e852016-05-05 00:46:07796
797 // This is for an offscreen context for the compositor. So the default
798 // framebuffer doesn't need alpha, depth, stencil, antialiasing.
799 gpu::gles2::ContextCreationAttribHelper attributes;
800 attributes.alpha_size = -1;
801 attributes.depth_size = 0;
802 attributes.stencil_size = 0;
803 attributes.samples = 0;
804 attributes.sample_buffers = 0;
805 attributes.bind_generates_resource = false;
806 attributes.lose_context_when_out_of_memory = true;
807
808 constexpr bool automatic_flushes = false;
danakj9a04adc2016-05-16 22:45:07809 constexpr bool support_locking = false;
danakj3873e852016-05-05 00:46:07810
danakj9a04adc2016-05-16 22:45:07811 // The compositor context shares resources with the worker context unless
812 // the worker is async.
813 ContextProviderCommandBuffer* share_context = worker_context_provider.get();
814 if (compositor_deps_->IsAsyncWorkerContextEnabled())
815 share_context = nullptr;
sunnypsd8ce1c22016-05-10 18:02:40816
danakj9a04adc2016-05-16 22:45:07817 scoped_refptr<ContextProviderCommandBuffer> context_provider(
818 new ContextProviderCommandBuffer(
819 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT,
820 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle,
kylechar7a463842016-05-26 14:46:12821 GetURLForGraphicsContext3D(), gl::PreferIntegratedGpu,
danakj9a04adc2016-05-16 22:45:07822 automatic_flushes, support_locking, limits, attributes, share_context,
823 command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT));
danakj3873e852016-05-05 00:46:07824
825#if defined(OS_ANDROID)
826 if (RenderThreadImpl::current()->sync_compositor_message_filter()) {
827 return base::WrapUnique(new SynchronousCompositorOutputSurface(
828 context_provider, worker_context_provider, routing_id(),
829 output_surface_id,
830 RenderThreadImpl::current()->sync_compositor_message_filter(),
831 frame_swap_message_queue_));
832 }
833#endif
834
835 // Composite-to-mailbox is currently used for layout tests in order to cause
836 // them to draw inside in the renderer to do the readback there. This should
837 // no longer be the case when crbug.com/311404 is fixed.
838 if (RenderThreadImpl::current()->layout_test_mode()) {
hajimehoshiea85b9dc2016-05-25 09:52:31839 return base::MakeUnique<MailboxOutputSurface>(
840 output_surface_id, std::move(context_provider),
841 std::move(worker_context_provider));
danakj3873e852016-05-05 00:46:07842 }
843
hajimehoshiea85b9dc2016-05-25 09:52:31844 return base::WrapUnique(new CompositorOutputSurface(
danakje8ec797e2016-04-19 04:08:43845 routing_id(), output_surface_id, std::move(context_provider),
hajimehoshiea85b9dc2016-05-25 09:52:31846 std::move(worker_context_provider), frame_swap_message_queue_));
[email protected]ba91a792013-02-06 09:48:28847}
848
dchengcedca5612016-04-09 01:40:15849std::unique_ptr<cc::BeginFrameSource>
fsamuel78f86e42016-01-20 04:10:23850RenderWidget::CreateExternalBeginFrameSource() {
851 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_);
852}
853
854void RenderWidget::DidCommitAndDrawCompositorFrame() {
855 // NOTE: Tests may break if this event is renamed or moved. See
856 // tab_capture_performancetest.cc.
857 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08858
859 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
860 DidCommitAndDrawCompositorFrame());
861
fsamuel78f86e42016-01-20 04:10:23862 // Notify subclasses that we initiated the paint operation.
863 DidInitiatePaint();
864}
865
866void RenderWidget::DidCommitCompositorFrame() {
867 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
868 DidCommitCompositorFrame());
869 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
870 DidCommitCompositorFrame());
871#if defined(VIDEO_HOLE)
872 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
873 DidCommitCompositorFrame());
874#endif // defined(VIDEO_HOLE)
875 input_handler_->FlushPendingInputEventAck();
876}
877
878void RenderWidget::DidCompletePageScaleAnimation() {}
879
880void RenderWidget::DidCompleteSwapBuffers() {
881 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
882
883 // Notify subclasses threaded composited rendering was flushed to the screen.
884 DidFlushPaint();
885
pimanbfb2ceb2016-03-18 21:32:58886 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23887 return;
888 }
889
890 ViewHostMsg_UpdateRect_Params params;
891 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23892 params.flags = next_paint_flags_;
893
894 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
895 next_paint_flags_ = 0;
896 need_update_rect_for_auto_resize_ = false;
897}
898
fsamuel78f86e42016-01-20 04:10:23899void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
900 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
901}
902
903bool RenderWidget::IsClosing() const {
904 return host_closing_;
905}
906
[email protected]4d7e46a2013-11-08 05:33:40907void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24908 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:24909 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:26910 ScheduleComposite();
[email protected]65225772011-05-12 21:10:24911}
912
[email protected]4d7e46a2013-11-08 05:33:40913void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24914 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16915
[email protected]404939f2012-06-01 04:06:18916 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16917 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:29918}
919
fsamuel78f86e42016-01-20 04:10:23920void RenderWidget::OnSwapBuffersPosted() {
921 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:29922}
923
danakj53eccbc2016-03-02 22:51:07924void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23925 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29926}
927
fsamuel78f86e42016-01-20 04:10:23928void RenderWidget::UpdateVisualState() {
929 webwidget_->updateAllLifecyclePhases();
930}
931
932void RenderWidget::WillBeginCompositorFrame() {
933 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
934
935 // The UpdateTextInputState can result in further layout and possibly
936 // enable GPU acceleration so they need to be called before any painting
937 // is done.
938 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
939 UpdateSelectionBounds();
lfge6119aac2016-01-27 02:14:31940
941 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
942 WillBeginCompositorFrame());
initial.commit09911bf2008-07-26 23:55:29943}
944
vmpstrd6dce2602016-05-18 20:19:04945void RenderWidget::ReportFixedRasterScaleUseCounters(
946 bool has_blurry_content,
947 bool has_potential_performance_regression) {
948 webwidget_->reportFixedRasterScaleUseCounters(
949 has_blurry_content, has_potential_performance_regression);
950}
951
fsamuel72464894f2015-12-15 06:59:31952///////////////////////////////////////////////////////////////////////////////
953// RenderWidgetInputHandlerDelegate
954
avid7d6b2e2016-03-04 19:41:17955void RenderWidget::FocusChangeComplete() {
956 if (owner_delegate_)
957 owner_delegate_->RenderWidgetFocusChangeComplete();
958}
fsamuel72464894f2015-12-15 06:59:31959
960bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17961 if (owner_delegate_)
962 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
963
fsamuel72464894f2015-12-15 06:59:31964 return true;
965}
966
967void RenderWidget::ObserveWheelEventAndResult(
968 const blink::WebMouseWheelEvent& wheel_event,
969 const gfx::Vector2dF& wheel_unused_delta,
970 bool event_processed) {
971 if (!compositor_deps_->IsElasticOverscrollEnabled())
972 return;
973
974 cc::InputHandlerScrollResult scroll_result;
975 scroll_result.did_scroll = event_processed;
976 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
977 scroll_result.unused_scroll_delta = wheel_unused_delta;
978
979 RenderThreadImpl* render_thread = RenderThreadImpl::current();
980 InputHandlerManager* input_handler_manager =
981 render_thread ? render_thread->input_handler_manager() : NULL;
982 if (input_handler_manager) {
983 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
984 routing_id_, wheel_event, scroll_result);
jddukefffb67c2015-01-07 22:32:29985 }
fsamuel72464894f2015-12-15 06:59:31986}
987
dtapuska1827dd22016-03-11 15:24:59988void RenderWidget::ObserveGestureEventAndResult(
989 const blink::WebGestureEvent& gesture_event,
990 const gfx::Vector2dF& unused_delta,
991 bool event_processed) {
992 if (!compositor_deps_->IsElasticOverscrollEnabled())
993 return;
994
995 cc::InputHandlerScrollResult scroll_result;
996 scroll_result.did_scroll = event_processed;
997 scroll_result.did_overscroll_root = !unused_delta.IsZero();
998 scroll_result.unused_scroll_delta = unused_delta;
999
1000 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1001 InputHandlerManager* input_handler_manager =
1002 render_thread ? render_thread->input_handler_manager() : NULL;
1003 if (input_handler_manager) {
1004 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1005 routing_id_, gesture_event, scroll_result);
1006 }
1007}
1008
avid7d6b2e2016-03-04 19:41:171009void RenderWidget::OnDidHandleKeyEvent() {
1010 if (owner_delegate_)
1011 owner_delegate_->RenderWidgetDidHandleKeyEvent();
1012}
fsamuel72464894f2015-12-15 06:59:311013
1014void RenderWidget::OnDidOverscroll(const DidOverscrollParams& params) {
1015 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1016}
1017
dchengcedca5612016-04-09 01:40:151018void RenderWidget::OnInputEventAck(
1019 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:311020 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
1021}
1022
dtapuska46616922016-03-17 22:52:011023void RenderWidget::NotifyInputEventHandled(
dtapuska0bd451a2016-02-18 17:08:101024 blink::WebInputEvent::Type handled_type) {
1025 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1026 InputHandlerManager* input_handler_manager =
1027 render_thread ? render_thread->input_handler_manager() : NULL;
1028 if (input_handler_manager) {
dtapuska46616922016-03-17 22:52:011029 input_handler_manager->NotifyInputEventHandledOnMainThread(routing_id_,
1030 handled_type);
dtapuska0bd451a2016-02-18 17:08:101031 }
1032}
1033
fsamuele8326c742016-01-12 00:49:391034void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1035 // Nothing to do here. RenderWidget created the |input_handler| and will take
1036 // ownership of it. We just verify here that we don't already have an input
1037 // handler.
1038 DCHECK(!input_handler_);
1039}
1040
fsamuel72464894f2015-12-15 06:59:311041void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1042 ChangeSource change_source) {
1043 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1044 if (ime_event_guard_) {
1045 // show_ime should still be effective even if it was set inside the IME
1046 // event guard.
1047 if (show_ime == ShowIme::IF_NEEDED) {
1048 ime_event_guard_->set_show_ime(true);
1049 }
1050 return;
1051 }
1052
1053 ui::TextInputType new_type = GetTextInputType();
1054 if (IsDateTimeInput(new_type))
1055 return; // Not considered as a text input field in WebKit/Chromium.
1056
1057 blink::WebTextInputInfo new_info;
1058 if (webwidget_)
1059 new_info = webwidget_->textInputInfo();
1060 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1061
1062 bool new_can_compose_inline = CanComposeInline();
1063
1064 // Only sends text input params if they are changed or if the ime should be
1065 // shown.
1066 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:391067 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
fsamuel72464894f2015-12-15 06:59:311068 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1069 text_input_info_ != new_info ||
1070 can_compose_inline_ != new_can_compose_inline)
1071#if defined(OS_ANDROID)
1072 || text_field_is_dirty_
1073#endif
1074 ) {
ekaramad9053e57b2016-04-26 20:00:381075 TextInputState params;
fsamuel72464894f2015-12-15 06:59:311076 params.type = new_type;
1077 params.mode = new_mode;
1078 params.flags = new_info.flags;
1079 params.value = new_info.value.utf8();
1080 params.selection_start = new_info.selectionStart;
1081 params.selection_end = new_info.selectionEnd;
1082 params.composition_start = new_info.compositionStart;
1083 params.composition_end = new_info.compositionEnd;
1084 params.can_compose_inline = new_can_compose_inline;
1085 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
1086#if defined(USE_AURA)
1087 params.is_non_ime_change = true;
1088#endif
1089#if defined(OS_ANDROID)
1090 params.is_non_ime_change =
1091 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
1092 if (params.is_non_ime_change)
1093 OnImeEventSentForAck(new_info);
1094 text_field_is_dirty_ = false;
1095#endif
1096 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1097
1098 text_input_info_ = new_info;
1099 text_input_type_ = new_type;
1100 text_input_mode_ = new_mode;
1101 can_compose_inline_ = new_can_compose_inline;
1102 text_input_flags_ = new_info.flags;
1103 }
1104}
1105
1106bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:171107 if (owner_delegate_)
1108 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
1109
fsamuel72464894f2015-12-15 06:59:311110 return false;
1111}
1112
1113bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
lfge0c2792ec2016-05-11 18:52:081114 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1115 RenderWidgetWillHandleMouseEvent());
1116
avid7d6b2e2016-03-04 19:41:171117 if (owner_delegate_)
1118 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1119
fsamuel72464894f2015-12-15 06:59:311120 return false;
[email protected]fd847792013-10-24 17:12:351121}
1122
initial.commit09911bf2008-07-26 23:55:291123///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391124// RenderWidgetScreenMetricsDelegate
1125
1126void RenderWidget::Redraw() {
1127 set_next_paint_is_resize_ack();
1128 if (compositor_)
1129 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1130}
1131
bokanc63441c2016-04-27 15:49:121132void RenderWidget::ResizeWebWidget() {
1133 webwidget_->resize(GetSizeForWebWidget());
1134}
1135
1136gfx::Size RenderWidget::GetSizeForWebWidget() const {
1137 if (IsUseZoomForDSFEnabled())
1138 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1139
1140 return size_;
1141}
1142
mfomitchev2600fd7c2016-02-17 20:53:391143void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581144 bool orientation_changed =
1145 screen_info_.orientationAngle != params.screen_info.orientationAngle ||
1146 screen_info_.orientationType != params.screen_info.orientationType;
1147
mfomitchev2600fd7c2016-02-17 20:53:391148 screen_info_ = params.screen_info;
1149 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
1150
1151 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1152 // A resize ack shouldn't be requested if we have not ACK'd the previous
1153 // one.
1154 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1155 }
1156
1157 // Ignore this during shutdown.
1158 if (!webwidget_)
1159 return;
1160
1161 if (compositor_)
1162 compositor_->setViewportSize(params.physical_backing_size);
1163
mfomitchev2600fd7c2016-02-17 20:53:391164 visible_viewport_size_ = params.visible_viewport_size;
1165 resizer_rect_ = params.resizer_rect;
1166
1167 // NOTE: We may have entered fullscreen mode without changing our size.
1168 bool fullscreen_change =
1169 is_fullscreen_granted_ != params.is_fullscreen_granted;
1170 is_fullscreen_granted_ = params.is_fullscreen_granted;
1171 display_mode_ = params.display_mode;
1172
bokanc63441c2016-04-27 15:49:121173 size_ = params.new_size;
1174 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391175
bokanc63441c2016-04-27 15:49:121176 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221177
mfomitchev2600fd7c2016-02-17 20:53:391178 WebSize visual_viewport_size;
1179
1180 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181181 visual_viewport_size = gfx::ScaleToCeiledSize(
1182 params.visible_viewport_size,
1183 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391184 } else {
1185 visual_viewport_size = visible_viewport_size_;
1186 }
1187
1188 webwidget()->resizeVisualViewport(visual_viewport_size);
1189
bokanc63441c2016-04-27 15:49:121190 // When resizing, we want to wait to paint before ACK'ing the resize. This
1191 // ensures that we only resize as fast as we can paint. We only need to
1192 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391193 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1194 // In this case there is no paint/composite and therefore no
1195 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1196 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1197 DCHECK(!params.needs_resize_ack);
1198 }
1199
1200 // Send the Resize_ACK flag once we paint again if requested.
1201 if (params.needs_resize_ack)
1202 set_next_paint_is_resize_ack();
1203
1204 if (fullscreen_change)
1205 DidToggleFullscreen();
1206
engedy6cb63c92016-02-23 14:14:581207 if (orientation_changed)
1208 OnOrientationChange();
1209
mfomitchev2600fd7c2016-02-17 20:53:391210 // If a resize ack is requested and it isn't set-up, then no more resizes will
1211 // come in and in general things will go wrong.
1212 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1213}
1214
1215void RenderWidget::SetScreenMetricsEmulationParameters(
1216 bool enabled,
1217 const blink::WebDeviceEmulationParams& params) {
1218 // This is only supported in RenderView.
1219 NOTREACHED();
1220}
1221
1222void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1223 const gfx::Rect& window_screen_rect) {
1224 view_screen_rect_ = view_screen_rect;
1225 window_screen_rect_ = window_screen_rect;
1226}
1227
1228///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461229// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291230
[email protected]244ac1892011-12-02 17:04:471231void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima33ec97cd2015-12-14 19:40:241232 WebRect new_size_in_window(0, 0, new_size.width, new_size.height);
1233 convertViewportToWindow(&new_size_in_window);
1234 if (size_.width() != new_size_in_window.width ||
1235 size_.height() != new_size_in_window.height) {
1236 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
[email protected]20fbfc22013-05-08 20:50:581237
[email protected]5b45ad42013-10-25 00:42:041238 if (resizing_mode_selector_->is_synchronous_mode()) {
oshima33ec97cd2015-12-14 19:40:241239 gfx::Rect new_pos(rootWindowRect().x,
1240 rootWindowRect().y,
1241 size_.width(),
1242 size_.height());
[email protected]eac2b362013-05-22 07:01:451243 view_screen_rect_ = new_pos;
1244 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031245 }
[email protected]20fbfc22013-05-08 20:50:581246
[email protected]eac2b362013-05-22 07:01:451247 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581248
[email protected]5b45ad42013-10-25 00:42:041249 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581250 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091251 }
[email protected]244ac1892011-12-02 17:04:471252}
1253
[email protected]3a1c8a8032013-03-18 22:35:321254void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401255 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051256 if (compositor_)
oshima750cb4342015-10-31 00:59:011257 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051258}
1259
[email protected]e195e582013-03-08 01:32:591260void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221261 DCHECK(!host_closing_);
1262
fsamuel78f86e42016-01-20 04:10:231263 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1264 compositor_deps_);
oshima750cb4342015-10-31 00:59:011265 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331266 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391267 // For background pages and certain tests, we don't want to trigger
1268 // OutputSurface creation.
1269 if (compositor_never_visible_ || !RenderThreadImpl::current())
1270 compositor_->SetNeverVisible();
1271
pimanc4af3072015-10-02 03:45:591272 StartCompositor();
[email protected]e195e582013-03-08 01:32:591273}
1274
ennef3c58142014-12-09 21:44:381275void RenderWidget::WillCloseLayerTreeView() {
1276 if (host_closing_)
1277 return;
1278
1279 // Prevent new compositors or output surfaces from being created.
1280 host_closing_ = true;
1281
[email protected]aeeedad2014-08-22 18:16:221282 // Always send this notification to prevent new layer tree views from
1283 // being created, even if one hasn't been created yet.
1284 if (webwidget_)
1285 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221286}
1287
[email protected]180ef242013-11-07 06:50:461288blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281289 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061290}
1291
dglazkovf0e1d6d2015-10-10 02:13:481292void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1293 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1294 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1295 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1296 }
dglazkov79c426102015-08-31 21:22:431297
dglazkovf0e1d6d2015-10-10 02:13:481298 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1299 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431300}
1301
jdduke491a3f0c2015-06-15 23:30:261302void RenderWidget::ScheduleComposite() {
1303 if (compositor_ &&
1304 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1305 compositor_->setNeedsAnimate();
1306 }
1307}
1308
1309void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1310 if (compositor_) {
1311 // Regardless of whether threaded compositing is enabled, always
1312 // use this mechanism to force the compositor to redraw. However,
1313 // the invalidation code path below is still needed for the
1314 // non-threaded case.
1315 compositor_->SetNeedsForcedRedraw();
1316 }
1317 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151318}
1319
[email protected]586871b2014-07-22 17:05:111320// static
dchengcedca5612016-04-09 01:40:151321std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111322 IPC::Message* msg,
1323 MessageDeliveryPolicy policy,
1324 FrameSwapMessageQueue* frame_swap_message_queue,
1325 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111326 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111327 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151328 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1329 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111330 &first_message_for_frame);
1331 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151332 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111333 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061334 return promise;
[email protected]586871b2014-07-22 17:05:111335 }
dcheng4b6b5ff2014-10-16 00:42:061336 return nullptr;
[email protected]586871b2014-07-22 17:05:111337}
1338
1339void RenderWidget::QueueMessage(IPC::Message* msg,
1340 MessageDeliveryPolicy policy) {
1341 // RenderThreadImpl::current() is NULL in some tests.
1342 if (!compositor_ || !RenderThreadImpl::current()) {
1343 Send(msg);
1344 return;
1345 }
1346
dchengcedca5612016-04-09 01:40:151347 std::unique_ptr<cc::SwapPromise> swap_promise =
1348 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111349 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111350 compositor_->GetSourceFrameNumber());
1351
1352 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321353 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351354 // Request a commit. This might either A) request a commit ahead of time
1355 // or B) request a commit which is not needed because there are not
1356 // pending updates. If B) then the commit will be skipped and the swap
1357 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1358 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1359 // can_cancel_commit is not unset.
1360 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111361 }
1362}
1363
[email protected]4873c7d2009-07-16 06:36:281364void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301365 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521366 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181367 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291368 // Only send a SetCursor message if we need to make a change.
1369 if (!current_cursor_.IsEqual(cursor)) {
1370 current_cursor_ = cursor;
1371 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1372 }
1373}
1374
1375// We are supposed to get a single call to Show for a newly created RenderWidget
1376// that was created via RenderWidget::CreateWebView. So, we wait until this
1377// point to dispatch the ShowWidget message.
1378//
1379// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281380// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291381//
[email protected]4873c7d2009-07-16 06:36:281382void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291383 DCHECK(!did_show_) << "received extraneous Show call";
1384 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1385 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1386
[email protected]8de12d942010-11-17 20:42:441387 if (did_show_)
1388 return;
1389
1390 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561391 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441392 // that's okay. It'll be ignored if as_popup is false, or the browser
1393 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561394 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1395 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291396}
1397
[email protected]4873c7d2009-07-16 06:36:281398void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291399}
1400
[email protected]2533ce12009-05-09 00:02:241401void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381402 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241403 Send(new ViewHostMsg_Close(routing_id_));
1404}
1405
dgozmancf9039cd2015-04-06 12:01:311406void RenderWidget::NotifyOnClose() {
1407 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1408}
1409
[email protected]4873c7d2009-07-16 06:36:281410void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081411 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321412 if (is_swapped_out_) {
1413 // This widget is currently swapped out, and the active widget is in a
1414 // different process. Have the browser route the close request to the
1415 // active widget instead, so that the correct unload handlers are run.
1416 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1417 return;
1418 }
1419
initial.commit09911bf2008-07-26 23:55:291420 // If a page calls window.close() twice, we'll end up here twice, but that's
1421 // OK. It is safe to send multiple Close messages.
1422
[email protected]2533ce12009-05-09 00:02:241423 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1424 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1425 // could be closed before the JS finishes executing. So instead, post a
1426 // message back to the message loop, which won't run until the JS is
1427 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081428 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211429 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291430}
1431
[email protected]9017d7852013-11-21 17:47:351432void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151433 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351434 const SyntheticGestureCompletionCallback& callback) {
1435 DCHECK(!callback.is_null());
1436
1437 pending_synthetic_gesture_callbacks_.push(callback);
1438
1439 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321440 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351441
1442 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1443}
1444
initial.commit09911bf2008-07-26 23:55:291445void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031446 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381447 WillCloseLayerTreeView();
1448 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291449 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281450 webwidget_->close();
lfg4fa48da2016-05-09 18:25:131451 webwidget_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291452 }
1453}
1454
[email protected]4873c7d2009-07-16 06:36:281455WebRect RenderWidget::windowRect() {
1456 if (pending_window_rect_count_)
1457 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241458
[email protected]80ad8622012-11-07 16:33:031459 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291460}
1461
[email protected]180ef242013-11-07 06:50:461462void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301463 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541464 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301465}
1466
oshima33ec97cd2015-12-14 19:40:241467void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1468 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511469 if (popup_origin_scale_for_emulation_) {
1470 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561471 window_rect.x = popup_screen_origin_for_emulation_.x() +
1472 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1473 window_rect.y = popup_screen_origin_for_emulation_.y() +
1474 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511475 }
1476
[email protected]5b45ad42013-10-25 00:42:041477 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201478 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561479 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1480 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031481 } else {
bokanc007c3a2015-02-03 07:15:561482 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031483 }
initial.commit09911bf2008-07-26 23:55:291484 } else {
bokanc007c3a2015-02-03 07:15:561485 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291486 }
1487}
1488
[email protected]2533ce12009-05-09 00:02:241489void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1490 pending_window_rect_ = rect;
1491 pending_window_rect_count_++;
1492}
1493
[email protected]4873c7d2009-07-16 06:36:281494WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241495 if (pending_window_rect_count_) {
1496 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1497 // the RootWindowRect is probably going to return wrong results since the
1498 // browser may not have processed the Move yet. There isn't really anything
1499 // good to do in this case, and it shouldn't happen - since this size is
1500 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281501 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241502 }
1503
[email protected]80ad8622012-11-07 16:33:031504 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371505}
1506
[email protected]4873c7d2009-07-16 06:36:281507WebRect RenderWidget::windowResizerRect() {
1508 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191509}
1510
[email protected]fa7b1dc2010-06-23 17:53:041511void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261512 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041513 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071514 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041515 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131516 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281517 return;
[email protected]66fca5bc2013-05-23 06:58:291518 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361519 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041520 text, WebVector<WebCompositionUnderline>(underlines),
1521 selection_start, selection_end)) {
1522 // If we failed to set the composition text, then we need to let the browser
1523 // process to cancel the input method's ongoing composition session, to make
1524 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221525 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261526 }
[email protected]88dbe32f2013-06-20 23:31:361527 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041528}
1529
[email protected]fcf75d42013-12-03 20:11:261530void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511531 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021532 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131533 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041534 return;
[email protected]66fca5bc2013-05-23 06:58:291535 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391536 input_handler_->set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021537 if (text.length())
1538 webwidget_->confirmComposition(text);
1539 else if (keep_selection)
1540 webwidget_->confirmComposition(WebWidget::KeepSelection);
1541 else
1542 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391543 input_handler_->set_handling_input_event(false);
[email protected]88dbe32f2013-06-20 23:31:361544 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291545}
1546
oshimad5279032015-12-16 18:22:331547void RenderWidget::OnDeviceScaleFactorChanged() {
1548 if (!compositor_)
1549 return;
oshimad5279032015-12-16 18:22:331550 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181551 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331552 else
1553 compositor_->setDeviceScaleFactor(device_scale_factor_);
1554}
1555
[email protected]0bc1f572013-04-17 01:46:311556void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121557 // During shutdown we can just ignore this message.
1558 if (!webwidget_)
1559 return;
1560
[email protected]0bc1f572013-04-17 01:46:311561 // Even if the browser provides an empty damage rect, it's still expecting to
1562 // receive a repaint ack so just damage the entire widget bounds.
1563 if (size_to_paint.IsEmpty()) {
1564 size_to_paint = size_;
1565 }
1566
[email protected]ec7dc112008-08-06 05:30:121567 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051568 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311569 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121570}
1571
[email protected]79fa22e2013-08-23 15:18:121572void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351573 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1574
1575 pending_synthetic_gesture_callbacks_.front().Run();
1576 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271577}
1578
[email protected]4873c7d2009-07-16 06:36:281579void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111580 if (!webwidget_)
1581 return;
[email protected]4873c7d2009-07-16 06:36:281582 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111583}
1584
[email protected]80ad8622012-11-07 16:33:031585void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1586 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511587 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391588 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1589 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511590 } else {
mfomitchev2600fd7c2016-02-17 20:53:391591 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511592 }
[email protected]80ad8622012-11-07 16:33:031593 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1594}
1595
lfgdb5c4ed2016-03-04 23:09:071596void RenderWidget::OnUpdateWindowScreenRect(
1597 const gfx::Rect& window_screen_rect) {
1598 if (screen_metrics_emulator_) {
1599 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
1600 } else {
1601 window_screen_rect_ = window_screen_rect;
1602 }
1603}
1604
kenrbb4e2a3b2015-05-14 15:05:051605void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1606 if (compositor_)
1607 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1608}
1609
dtrainor5ef644e2015-11-19 00:12:471610void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1611 if (compositor_)
1612 compositor_->OnHandleCompositorProto(proto);
1613}
1614
[email protected]adb362312014-06-28 06:04:241615void RenderWidget::showImeIfNeeded() {
1616 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131617}
1618
fsamuel72464894f2015-12-15 06:59:311619ui::TextInputType RenderWidget::GetTextInputType() {
1620 if (webwidget_)
1621 return WebKitToUiTextInputType(webwidget_->textInputType());
1622 return ui::TEXT_INPUT_TYPE_NONE;
1623}
1624
1625void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
fsamuel72464894f2015-12-15 06:59:311626 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1627 gfx::Range range = gfx::Range();
1628 if (should_update_range) {
1629 GetCompositionRange(&range);
1630 } else {
1631 range = composition_range_;
1632 }
1633 std::vector<gfx::Rect> character_bounds;
1634 GetCompositionCharacterBounds(&character_bounds);
1635
1636 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1637 return;
1638 composition_character_bounds_ = character_bounds;
1639 composition_range_ = range;
1640 Send(new InputHostMsg_ImeCompositionRangeChanged(
1641 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311642}
1643
oshimaf866dab2015-12-05 00:41:541644void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1645 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181646 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331647 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541648 // anchor element can be placed at half pixel.
1649 gfx::Rect window_rect =
1650 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1651 rect->x = window_rect.x();
1652 rect->y = window_rect.y();
1653 rect->width = window_rect.width();
1654 rect->height = window_rect.height();
1655 }
1656}
1657
oshimaa6985b62016-01-27 08:58:301658void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1659 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181660 rect->x *= GetOriginalDeviceScaleFactor();
1661 rect->y *= GetOriginalDeviceScaleFactor();
1662 rect->width *= GetOriginalDeviceScaleFactor();
1663 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301664 }
1665}
1666
[email protected]adb362312014-06-28 06:04:241667void RenderWidget::OnShowImeIfNeeded() {
1668#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311669 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241670#endif
rouslanf7ebd8832015-01-22 01:54:141671
1672// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1673// virtual keyboard.
1674#if !defined(OS_ANDROID)
1675 FocusChangeComplete();
1676#endif
[email protected]adb362312014-06-28 06:04:241677}
1678
1679#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371680void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1681 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131682}
1683
1684void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371685 DCHECK_GE(text_input_info_history_.size(), 1u);
1686 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511687}
changwan8c342742016-02-26 00:53:391688
1689void RenderWidget::OnRequestTextInputStateUpdate() {
1690 DCHECK(!ime_event_guard_);
1691 UpdateSelectionBounds();
1692 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1693}
[email protected]105dffb42013-02-20 03:46:211694#endif
1695
[email protected]0d1ebed12013-08-05 22:01:131696bool RenderWidget::ShouldHandleImeEvent() {
1697#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371698 if (!webwidget_)
1699 return false;
changwan8c342742016-02-26 00:53:391700 if (IsUsingImeThread())
1701 return true;
changwan3a841162015-08-11 02:53:371702
1703 // We cannot handle IME events if there is any chance that the event we are
1704 // receiving here from the browser is based on the state that is different
1705 // from our current one as indicated by |text_input_info_|.
1706 // The states the browser might be in are:
1707 // text_input_info_history_[0] - current state ack'd by browser
1708 // text_input_info_history_[1...N] - pending state changes
1709 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1710 if (text_input_info_history_[i] != text_input_info_)
1711 return false;
1712 }
1713 return true;
[email protected]0d1ebed12013-08-05 22:01:131714#else
1715 return !!webwidget_;
1716#endif
1717}
1718
[email protected]468ac582012-11-20 00:53:191719void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1720 if (device_scale_factor_ == device_scale_factor)
1721 return;
1722
1723 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331724
1725 OnDeviceScaleFactorChanged();
1726
jdduke491a3f0c2015-06-15 23:30:261727 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191728}
1729
[email protected]28ed6b32014-06-08 02:16:271730bool RenderWidget::SetDeviceColorProfile(
1731 const std::vector<char>& color_profile) {
1732 if (device_color_profile_ == color_profile)
1733 return false;
1734
1735 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271736
avi40b5be7a2016-03-03 21:13:441737 if (owner_delegate_)
1738 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1739
1740 return true;
noeldb4df152014-09-16 17:45:201741}
1742
[email protected]fcdc5642014-05-09 14:32:241743void RenderWidget::OnOrientationChange() {
1744}
1745
avib9dbd972016-03-08 18:19:321746void RenderWidget::DidFlushPaint() {
1747 if (owner_delegate_)
1748 owner_delegate_->RenderWidgetDidFlushPaint();
1749}
1750
[email protected]bee16aab2009-08-26 15:55:031751void RenderWidget::SetHidden(bool hidden) {
1752 if (is_hidden_ == hidden)
1753 return;
1754
jdduke8fac9d102014-12-20 02:40:131755 // The status has changed. Tell the RenderThread about it and ensure
1756 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031757 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391758 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131759
[email protected]bee16aab2009-08-26 15:55:031760 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001761 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031762 else
[email protected]b2db9272014-01-10 17:42:001763 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111764
1765 if (render_widget_scheduling_state_)
1766 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031767}
1768
[email protected]2b624c562011-10-27 22:58:261769void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261770 if (!webwidget_)
1771 return;
1772
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121773 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261774 webwidget_->didEnterFullScreen();
1775 } else {
1776 webwidget_->didExitFullScreen();
1777 }
[email protected]2b624c562011-10-27 22:58:261778}
1779
[email protected]674741932009-02-04 23:44:461780bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051781 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461782}
1783
[email protected]674741932009-02-04 23:44:461784void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051785 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461786}
1787
[email protected]674741932009-02-04 23:44:461788void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051789 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461790}
1791
changwan8c342742016-02-26 00:53:391792bool RenderWidget::IsUsingImeThread() {
1793#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121794 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391795#else
1796 return false;
1797#endif
1798}
1799
changwanf2a707b2015-10-30 08:22:161800void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1801 if (!ime_event_guard_)
1802 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291803}
1804
changwanf2a707b2015-10-30 08:22:161805void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1806 if (ime_event_guard_ != guard) {
1807#if defined(OS_ANDROID)
1808 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1809 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391810 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161811 // Therefore, we want to mark this text state update as 'from IME' only
1812 // when all the nested events are all originating from IME.
1813 ime_event_guard_->set_from_ime(
1814 ime_event_guard_->from_ime() && guard->from_ime());
1815#endif
1816 return;
1817 }
1818 ime_event_guard_ = nullptr;
1819
[email protected]66fca5bc2013-05-23 06:58:291820 // While handling an ime event, text input state and selection bounds updates
1821 // are ignored. These must explicitly be updated once finished handling the
1822 // ime event.
1823 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471824#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161825 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311826 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1827 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471828#endif
[email protected]66fca5bc2013-05-23 06:58:291829}
1830
[email protected]7c8873e2013-02-05 08:03:011831void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1832 WebRect focus_webrect;
1833 WebRect anchor_webrect;
1834 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241835 convertViewportToWindow(&focus_webrect);
1836 convertViewportToWindow(&anchor_webrect);
1837 *focus = focus_webrect;
1838 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321839}
1840
[email protected]e99ef6f2011-10-16 01:13:001841void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081842 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001843 if (!webwidget_)
1844 return;
changwanf2a707b2015-10-30 08:22:161845 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291846 return;
[email protected]e99ef6f2011-10-16 01:13:001847
mohsenb0eeba72015-08-09 06:20:081848#if defined(USE_AURA)
1849 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1850 // Aura beucause composited selection updates are not working for webview tags
1851 // which regresses IME inside webview. Remove this when composited selection
1852 // updates are fixed for webviews. See, http://crbug.com/510568.
1853 bool send_ipc = true;
1854#else
jddukeacf809e2014-09-23 20:38:381855 // With composited selection updates, the selection bounds will be reported
1856 // directly by the compositor, in which case explicit IPC selection
1857 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081858 bool send_ipc =
1859 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1860#endif
1861 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381862 ViewHostMsg_SelectionBounds_Params params;
1863 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1864 if (selection_anchor_rect_ != params.anchor_rect ||
1865 selection_focus_rect_ != params.focus_rect) {
1866 selection_anchor_rect_ = params.anchor_rect;
1867 selection_focus_rect_ = params.focus_rect;
1868 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1869 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1870 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1871 }
[email protected]58b48a0d2012-06-13 07:01:351872 }
jddukeacf809e2014-09-23 20:38:381873
[email protected]88dbe32f2013-06-20 23:31:361874 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001875}
1876
avi40b5be7a2016-03-03 21:13:441877void RenderWidget::SetDeviceColorProfileForTesting(
1878 const std::vector<char>& color_profile) {
1879 SetDeviceColorProfile(color_profile);
1880}
1881
1882void RenderWidget::ResetDeviceColorProfileForTesting() {
1883 std::vector<char> color_profile;
1884 color_profile.push_back('0');
1885 SetDeviceColorProfile(color_profile);
1886}
1887
[email protected]180ef242013-11-07 06:50:461888// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
danakj365175c2016-02-06 00:37:371889STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1890STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1891STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1892 ui::TEXT_INPUT_TYPE_PASSWORD);
1893STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1894STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1895STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1896STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1897 ui::TEXT_INPUT_TYPE_TELEPHONE);
1898STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1899STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1900STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1901 ui::TEXT_INPUT_TYPE_DATE_TIME);
1902STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1903 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1904STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1905STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1906STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1907STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1908 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1909STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1910 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1911STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1912 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451913
[email protected]5b739cb2012-08-21 20:35:211914ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461915 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211916 // Check the type is in the range representable by ui::TextInputType.
1917 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461918 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211919 return static_cast<ui::TextInputType>(type);
1920}
1921
[email protected]58b48a0d2012-06-13 07:01:351922void RenderWidget::GetCompositionCharacterBounds(
1923 std::vector<gfx::Rect>* bounds) {
1924 DCHECK(bounds);
1925 bounds->clear();
1926}
1927
[email protected]db4fc1e2013-09-06 20:01:511928void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:361929 size_t location, length;
1930 if (webwidget_->compositionRange(&location, &length)) {
1931 range->set_start(location);
1932 range->set_end(location + length);
1933 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1934 range->set_start(location);
1935 range->set_end(location + length);
1936 } else {
[email protected]db4fc1e2013-09-06 20:01:511937 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:361938 }
1939}
1940
[email protected]501ea13d2013-07-09 17:03:291941bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511942 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291943 const std::vector<gfx::Rect>& bounds) {
1944 if (composition_range_ != range)
1945 return true;
1946 if (bounds.size() != composition_character_bounds_.size())
1947 return true;
1948 for (size_t i = 0; i < bounds.size(); ++i) {
1949 if (bounds[i] != composition_character_bounds_[i])
1950 return true;
1951 }
1952 return false;
1953}
[email protected]501ea13d2013-07-09 17:03:291954
[email protected]ad26ef42011-06-17 07:59:451955bool RenderWidget::CanComposeInline() {
1956 return true;
[email protected]56ea1a62011-05-30 07:05:571957}
1958
[email protected]4873c7d2009-07-16 06:36:281959WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041960 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281961}
1962
[email protected]fa7b1dc2010-06-23 17:53:041963void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021964 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041965 // If the last text input type is not None, then we should finish any
1966 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451967 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041968 // If a composition text exists, then we need to let the browser process
1969 // to cancel the input method's ongoing composition session.
1970 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:221971 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041972 }
[email protected]d4cff272011-05-02 15:46:011973
[email protected]88dbe32f2013-06-20 23:31:361974 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041975}
1976
donnda070f3c2015-01-16 19:54:111977#if defined(OS_ANDROID)
1978void RenderWidget::showUnhandledTapUIIfNeeded(
1979 const WebPoint& tapped_position,
1980 const WebNode& tapped_node,
1981 bool page_changed) {
fsamuele8326c742016-01-12 00:49:391982 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:111983 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371984 !tapped_node.isContentEditable() &&
1985 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111986 if (should_trigger) {
1987 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1988 tapped_position.x, tapped_position.y));
1989 }
1990}
1991#endif
1992
[email protected]c68c3e4e2013-01-24 00:36:561993void RenderWidget::didHandleGestureEvent(
1994 const WebGestureEvent& event,
1995 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021996#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561997 if (event_cancelled)
1998 return;
[email protected]07c70d22014-08-21 08:33:461999 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:312000 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462001 } else if (event.type == WebInputEvent::GestureLongPress) {
2002 DCHECK(webwidget_);
2003 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:312004 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462005 else
fsamuel72464894f2015-12-15 06:59:312006 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562007 }
2008#endif
2009}
2010
sataya.m582c9ce2015-06-09 08:03:422011void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:312012 const blink::WebFloatSize& overscrollDelta,
2013 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422014 const blink::WebFloatPoint& position,
2015 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482016#if defined(OS_MACOSX)
2017 // On OSX the user can disable the elastic overscroll effect. If that's the
2018 // case, don't forward the overscroll notification.
2019 DCHECK(compositor_deps());
2020 if (!compositor_deps()->IsElasticOverscrollEnabled())
2021 return;
2022#endif
bokane53a10f2016-04-13 23:48:312023 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392024 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422025}
2026
[email protected]7912e822014-04-16 02:37:032027void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392028 if (!is_hidden())
2029 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032030}
2031
[email protected]24ed0432013-04-24 07:50:312032RenderWidgetCompositor* RenderWidget::compositor() const {
2033 return compositor_.get();
2034}
2035
fsamuel72464894f2015-12-15 06:59:312036void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392037 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372038}
[email protected]c3d45532011-10-07 19:20:402039
fsamuel72464894f2015-12-15 06:59:312040bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392041 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242042}
2043
fsamuel72464894f2015-12-15 06:59:312044void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392045 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312046}
2047
[email protected]ce6689f2013-03-29 12:52:552048void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112049 if (render_widget_scheduling_state_)
2050 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552051 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2052}
2053
danakj365175c2016-02-06 00:37:372054// Check blink::WebTouchAction and content::TouchAction is kept in sync.
2055STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
2056STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
2057STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
2058STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
2059STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
2060STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
2061STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
2062STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
2063STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
2064STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
2065 TOUCH_ACTION_MANIPULATION);
2066STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2067 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2068STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
mostynbe29b6882015-01-13 09:59:172069
[email protected]5d0bbdfa92013-12-10 00:35:512070void RenderWidget::setTouchAction(
2071 blink::WebTouchAction web_touch_action) {
2072
2073 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2074 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392075 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512076 return;
2077
[email protected]a18f67a2013-12-20 19:44:362078 content::TouchAction content_touch_action =
2079 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512080 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2081}
2082
[email protected]90f24152014-04-09 12:41:362083void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2084#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392085 if (!IsUsingImeThread())
2086 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362087#endif
2088}
2089
[email protected]e3244ed2014-06-20 20:04:272090void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2091 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162092}
2093
[email protected]e3244ed2014-06-20 20:04:272094void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2095 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162096}
2097
[email protected]de3c5d82014-05-28 22:12:592098void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2099 render_frames_.AddObserver(frame);
2100}
2101
2102void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2103 render_frames_.RemoveObserver(frame);
2104}
2105
[email protected]a017938b2014-05-27 21:17:172106#if defined(VIDEO_HOLE)
2107void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2108 video_hole_frames_.AddObserver(frame);
2109}
2110
2111void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2112 video_hole_frames_.RemoveObserver(frame);
2113}
2114#endif // defined(VIDEO_HOLE)
2115
lfg43e08e62016-02-03 18:51:372116void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2117 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2118 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2119}
2120
oshima50872a72016-03-04 13:26:182121float RenderWidget::GetOriginalDeviceScaleFactor() const {
2122 return
2123 screen_metrics_emulator_ ?
2124 screen_metrics_emulator_->original_screen_info().deviceScaleFactor :
2125 device_scale_factor_;
2126}
2127
lfgbee1e0a2016-06-08 21:24:212128bool RenderWidget::requestPointerLock() {
2129 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2130}
2131
2132void RenderWidget::requestPointerUnlock() {
2133 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2134}
2135
2136bool RenderWidget::isPointerLocked() {
2137 return mouse_lock_dispatcher_->IsMouseLockedTo(
2138 webwidget_mouse_lock_target_.get());
2139}
2140
[email protected]e9ff79c2012-10-19 21:31:262141} // namespace content