blob: cb2afbcc623807384a97bb66e7a6fb376251af6d [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"
jbroman6ccbc7d472016-07-27 04:45:4126#include "cc/output/copy_output_request.h"
[email protected]7f0d825f2013-03-18 07:24:3027#include "cc/output/output_surface.h"
fsamuel78f86e42016-01-20 04:10:2328#include "cc/scheduler/begin_frame_source.h"
oshima750cb4342015-10-31 00:59:0129#include "content/common/content_switches_internal.h"
[email protected]9017d7852013-11-21 17:47:3530#include "content/common/input/synthetic_gesture_packet.h"
[email protected]c084330e02013-04-27 01:08:1531#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1532#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3833#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5034#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1235#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2936#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4237#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4038#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3939#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
[email protected]b2e4c70132013-10-03 02:07:5140#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1141#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1142#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2843#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2944#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1345#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3246#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1647#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2748#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0549#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4450#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5551#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4452#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0953#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0454#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1855#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4856#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1857#include "third_party/WebKit/public/platform/WebCursorInfo.h"
donnda070f3c2015-01-16 19:54:1158#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3059#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1860#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebSize.h"
62#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5163#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
64#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
[email protected]19193682014-04-03 15:01:4365#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5966#include "third_party/WebKit/public/web/WebFrameWidget.h"
67#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1168#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3169#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3170#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
71#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3872#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5973#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0874#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4175#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1376#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5077#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0978#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3279#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4880#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2781#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4883
[email protected]eeb93112013-05-01 19:41:1084#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1585#include <android/keycodes.h>
[email protected]eeb93112013-05-01 19:41:1086#endif
87
[email protected]661eb9d2009-02-03 02:11:4888#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4989#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5290#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4191#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4892#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4493
sadrul943e3b32016-08-04 18:22:5994#if defined(USE_AURA)
penghuang28a5fa22015-12-02 17:58:1995#include "content/public/common/mojo_shell_connection.h"
fsamuel2545ecc2015-12-05 00:44:4696#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:1997#endif
98
[email protected]180ef242013-11-07 06:50:4699using blink::WebCompositionUnderline;
100using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43101using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46102using blink::WebGestureEvent;
103using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49104using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46105using blink::WebKeyboardEvent;
106using blink::WebMouseEvent;
107using blink::WebMouseWheelEvent;
108using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11109using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46110using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11111using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46112using blink::WebPopupType;
[email protected]180ef242013-11-07 06:50:46113using blink::WebRect;
114using blink::WebScreenInfo;
115using blink::WebSize;
116using blink::WebTextDirection;
117using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25118using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46119using blink::WebVector;
120using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26121
danakj365175c2016-02-06 00:37:37122#define STATIC_ASSERT_ENUM(a, b) \
123 static_assert(static_cast<int>(a) == static_cast<int>(b), \
124 "mismatching enums: " #a)
125
[email protected]6a4d7f62013-01-07 21:32:13126namespace {
[email protected]b256eca2013-07-11 10:57:40127
128typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
129
lfgbee1e0a2016-06-08 21:24:21130class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
131 public:
132 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
133 : webwidget_(webwidget) {}
134
135 void OnLockMouseACK(bool succeeded) override {
136 if (succeeded)
137 webwidget_->didAcquirePointerLock();
138 else
139 webwidget_->didNotAcquirePointerLock();
140 }
141
142 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
143
144 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
145 // The WebWidget handles mouse lock in Blink's handleInputEvent().
146 return false;
147 }
148
149 private:
150 blink::WebWidget* webwidget_;
151};
152
[email protected]b256eca2013-07-11 10:57:40153class TextInputModeMapSingleton {
154 public:
155 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22156 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40157 }
[email protected]dd705d4d2013-11-27 08:14:41158 TextInputModeMapSingleton() {
159 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
160 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
161 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
162 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
163 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
164 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
165 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
166 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
167 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
168 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
169 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40170 }
[email protected]dd705d4d2013-11-27 08:14:41171 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40172 private:
[email protected]dd705d4d2013-11-27 08:14:41173 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40174
olli.raula36aa8be2015-09-10 11:14:22175 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40176
177 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
178};
179
[email protected]dd705d4d2013-11-27 08:14:41180ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40181 static TextInputModeMapSingleton* singleton =
182 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41183 TextInputModeMap::const_iterator it =
184 singleton->map().find(input_mode.utf8());
185 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40186 return ui::TEXT_INPUT_MODE_DEFAULT;
187 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13188}
[email protected]b256eca2013-07-11 10:57:40189
fsamuel72464894f2015-12-15 06:59:31190bool IsDateTimeInput(ui::TextInputType type) {
191 return type == ui::TEXT_INPUT_TYPE_DATE ||
192 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
193 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
194 type == ui::TEXT_INPUT_TYPE_MONTH ||
195 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
dtapuskae7473612015-12-04 14:23:06196}
197
fsamuele8326c742016-01-12 00:49:39198content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
199 content::RenderWidget* widget) {
sadrul943e3b32016-08-04 18:22:59200#if defined(USE_AURA)
penghuang639a1042016-01-14 21:25:29201 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
ben6c85c4492016-06-16 20:40:51202 if (content::MojoShellConnection::GetForProcess() &&
penghuang639a1042016-01-14 21:25:29203 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39204 return content::RenderWidgetMusConnection::GetOrCreate(
205 widget->routing_id());
206 }
207#endif
208 // If we don't have a connection to the Mojo shell, then we want to route IPCs
209 // back to the browser process rather than Mus so we use the |widget| as the
210 // RenderWidgetInputHandlerDelegate.
211 return widget;
212}
213
[email protected]b256eca2013-07-11 10:57:40214} // namespace
215
[email protected]e9ff79c2012-10-19 21:31:26216namespace content {
[email protected]62cb33cae2009-03-27 23:30:22217
[email protected]b2e4c70132013-10-03 02:07:51218// RenderWidget ---------------------------------------------------------------
219
dcheng35d31c112015-07-22 00:17:36220RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
221 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46222 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04223 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03224 bool hidden,
225 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29226 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36227 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53228 webwidget_(nullptr),
avi40b5be7a2016-03-03 21:13:44229 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29230 opener_id_(MSG_ROUTING_NONE),
initial.commit09911bf2008-07-26 23:55:29231 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51232 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09233 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29234 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04235 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39236 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12237 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12238 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16239 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48240 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22241 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44242 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20243 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45244 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40245 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20246 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53247 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18248 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12249 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48250 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04251 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52252 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0d1ebed12013-08-05 22:01:13253#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36254 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13255#endif
nonafa291792016-08-10 02:36:18256 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51257 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11258 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42259 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08260 has_host_context_menu_location_(false),
ekaramad2a46d632016-07-19 13:33:09261 has_focus_(false),
262 focused_pepper_plugin_(nullptr) {
[email protected]8b3f0eb2012-05-03 19:15:05263 if (!swapped_out)
264 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27265 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53266 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37267#if defined(OS_ANDROID)
268 text_input_info_history_.push_back(blink::WebTextInputInfo());
269#endif
alexclarke7fa93942015-10-21 15:37:11270
271 // In tests there may not be a RenderThreadImpl.
272 if (RenderThreadImpl::current()) {
273 render_widget_scheduling_state_ = RenderThreadImpl::current()
274 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32275 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11276 render_widget_scheduling_state_->SetHidden(is_hidden_);
277 }
initial.commit09911bf2008-07-26 23:55:29278}
279
280RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11281 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16282
[email protected]992db4c2011-05-12 15:37:15283 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02284 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15285 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29286}
287
[email protected]484955942010-08-19 16:13:18288// static
avi1023d012015-12-25 02:39:14289RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53290 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46291 blink::WebPopupType popup_type,
292 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29293 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36294 scoped_refptr<RenderWidget> widget(new RenderWidget(
295 compositor_deps, popup_type, screen_info, false, false, false));
296 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46297 return widget.get();
[email protected]a635f942012-12-07 10:34:29298 }
299 return NULL;
initial.commit09911bf2008-07-26 23:55:29300}
301
[email protected]484955942010-08-19 16:13:18302// static
kenrba7199832015-01-22 23:44:59303RenderWidget* RenderWidget::CreateForFrame(
304 int routing_id,
kenrba7199832015-01-22 23:44:59305 bool hidden,
306 const blink::WebScreenInfo& screen_info,
307 CompositorDependencies* compositor_deps,
308 blink::WebLocalFrame* frame) {
309 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55310 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
311 // same routing ID for both the view routing ID and the main frame widget
312 // routing ID. https://crbug.com/545684
313 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
314 if (view) {
avi8a45c1092016-03-01 16:12:34315 view->AttachWebFrameWidget(
316 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
317 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55318 }
dcheng35d31c112015-07-22 00:17:36319 scoped_refptr<RenderWidget> widget(
lfg465051d2016-08-04 00:16:35320 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
321 false, hidden, false));
fsamuele8326c742016-01-12 00:49:39322 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20323 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59324 // DoInit increments the reference count on |widget|, keeping it alive after
325 // this function returns.
dcheng35d31c112015-07-22 00:17:36326 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59327 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
328 nullptr)) {
kenrba7199832015-01-22 23:44:59329 return widget.get();
330 }
331 return nullptr;
332}
333
334// static
lfgcaab5142016-02-26 19:06:52335blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08336 RenderWidget* render_widget,
337 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55338 if (!frame->parent()) {
339 // TODO(dcheng): The main frame widget currently has a special case.
340 // Eliminate this once WebView is no longer a WebWidget.
341 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
342 }
dchengda9b4bb2015-07-20 20:58:08343 return blink::WebFrameWidget::create(render_widget, frame);
344}
345
346// static
kenrba7199832015-01-22 23:44:59347blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18348 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46349 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18350 break;
[email protected]180ef242013-11-07 06:50:46351 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44352 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18353 default:
354 NOTREACHED();
355 }
356 return NULL;
357}
358
dchengda9b4bb2015-07-20 20:58:08359void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32360 OnClose();
kenrba7199832015-01-22 23:44:59361}
362
fsamuele8326c742016-01-12 00:49:39363void RenderWidget::SetRoutingID(int32_t routing_id) {
364 routing_id_ = routing_id;
365 input_handler_.reset(new RenderWidgetInputHandler(
366 GetRenderWidgetInputHandlerDelegate(this), this));
367}
368
avi1023d012015-12-25 02:39:14369bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39370 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05371 opener_id, RenderWidget::CreateWebWidget(this),
372 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39373 if (success) {
374 SetRoutingID(routing_id_);
375 return true;
376 }
377 return false;
[email protected]484955942010-08-19 16:13:18378}
379
avi1023d012015-12-25 02:39:14380bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06381 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18382 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29383 DCHECK(!webwidget_);
384
385 if (opener_id != MSG_ROUTING_NONE)
386 opener_id_ = opener_id;
387
[email protected]484955942010-08-19 16:13:18388 webwidget_ = web_widget;
lfgbee1e0a2016-06-08 21:24:21389 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
390 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29391
kenrba7199832015-01-22 23:44:59392 bool result = true;
393 if (create_widget_message)
394 result = RenderThread::Get()->Send(create_widget_message);
395
initial.commit09911bf2008-07-26 23:55:29396 if (result) {
[email protected]380244092011-10-07 17:26:27397 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29398 // Take a reference on behalf of the RenderThread. This will be balanced
399 // when we receive ViewMsg_Close.
400 AddRef();
[email protected]b2db9272014-01-10 17:42:00401 if (RenderThreadImpl::current()) {
402 RenderThreadImpl::current()->WidgetCreated();
403 if (is_hidden_)
404 RenderThreadImpl::current()->WidgetHidden();
405 }
fsamuele8326c742016-01-12 00:49:39406
[email protected]a635f942012-12-07 10:34:29407 return true;
initial.commit09911bf2008-07-26 23:55:29408 } else {
[email protected]a635f942012-12-07 10:34:29409 // The above Send can fail when the tab is closing.
410 return false;
initial.commit09911bf2008-07-26 23:55:29411 }
412}
413
[email protected]992db4c2011-05-12 15:37:15414void RenderWidget::SetSwappedOut(bool is_swapped_out) {
415 // We should only toggle between states.
416 DCHECK(is_swapped_out_ != is_swapped_out);
417 is_swapped_out_ = is_swapped_out;
418
419 // If we are swapping out, we will call ReleaseProcess, allowing the process
420 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52421 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15422 // If we are swapping in, we call AddRefProcess to prevent the process from
423 // exiting.
[email protected]949b6592014-08-20 13:17:52424 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15425 RenderProcess::current()->AddRefProcess();
426}
427
[email protected]949b6592014-08-20 13:17:52428void RenderWidget::WasSwappedOut() {
429 // If we have been swapped out and no one else is using this process,
430 // it's safe to exit now.
431 CHECK(is_swapped_out_);
432 RenderProcess::current()->ReleaseProcess();
433}
434
[email protected]b2e4c70132013-10-03 02:07:51435void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39436 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51437 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43438 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49439 popup_screen_origin_for_emulation_ = gfx::Point(
440 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
441 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56442 screen_info_ = emulator->original_screen_info();
443 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51444}
445
[email protected]2d6836f42014-07-02 17:25:31446gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
447 if (screen_metrics_emulator_)
448 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
449 return anchor;
450}
451
haibinluc643d33c2016-06-03 02:22:34452#if defined(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51453void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39454 ExternalPopupMenu* popup,
455 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49456 popup->SetOriginScaleAndOffsetForEmulation(
457 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51458}
[email protected]53907862014-03-25 15:42:40459#endif
[email protected]b2e4c70132013-10-03 02:07:51460
461void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
462 if (screen_metrics_emulator_)
463 screen_metrics_emulator_->OnShowContextMenu(params);
464}
465
[email protected]a95986a82010-12-24 06:19:28466bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
lfgbee1e0a2016-06-08 21:24:21467 if (mouse_lock_dispatcher_ &&
468 mouse_lock_dispatcher_->OnMessageReceived(message))
469 return true;
470
[email protected]a95986a82010-12-24 06:19:28471 bool handled = true;
472 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15473 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22474 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
475 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22476 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
477 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15478 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
479 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35480 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
481 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28482 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28483 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20484 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
485 OnEnableDeviceEmulation)
486 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
487 OnDisableDeviceEmulation)
[email protected]b5913d72012-02-07 22:26:54488 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28489 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41490 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25491 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28492 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
493 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03494 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
fsamuel278664272016-07-13 04:06:59495 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceClientId, OnSetSurfaceClientId)
lfg43e08e62016-02-03 18:51:37496 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
497 OnWaitNextFrameForTests)
nonafa291792016-08-10 02:36:18498 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
499 OnRequestCompositionUpdate)
[email protected]105dffb42013-02-20 03:46:21500#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37501 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39502 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
503 OnRequestTextInputStateUpdate)
[email protected]2384b6c2013-02-28 23:58:51504 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21505#endif
dtrainor5ef644e2015-11-19 00:12:47506 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28507 IPC_MESSAGE_UNHANDLED(handled = false)
508 IPC_END_MESSAGE_MAP()
509 return handled;
510}
initial.commit09911bf2008-07-26 23:55:29511
512bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15513 // Don't send any messages after the browser has told us to close, and filter
514 // most outgoing messages while swapped out.
515 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26516 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11517 closing_) {
initial.commit09911bf2008-07-26 23:55:29518 delete message;
519 return false;
520 }
521
522 // If given a messsage without a routing ID, then assign our routing ID.
523 if (message->routing_id() == MSG_ROUTING_NONE)
524 message->set_routing_id(routing_id_);
525
[email protected]380244092011-10-07 17:26:27526 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44527}
528
bokanc007c3a2015-02-03 07:15:56529void RenderWidget::SetWindowRectSynchronously(
530 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39531 ResizeParams params;
532 params.screen_info = screen_info_;
533 params.new_size = new_window_rect.size();
534 params.physical_backing_size =
535 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39536 params.visible_viewport_size = new_window_rect.size();
537 params.resizer_rect = gfx::Rect();
538 params.is_fullscreen_granted = is_fullscreen_granted_;
539 params.display_mode = display_mode_;
540 params.needs_resize_ack = false;
541 Resize(params);
542
bokanc007c3a2015-02-03 07:15:56543 view_screen_rect_ = new_window_rect;
544 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02545 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56546 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02547}
548
initial.commit09911bf2008-07-26 23:55:29549void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32550 DCHECK(content::RenderThread::Get());
551 if (closing_)
552 return;
553 NotifyOnClose();
554 closing_ = true;
555
556 // Browser correspondence is no longer needed at this point.
557 if (routing_id_ != MSG_ROUTING_NONE) {
558 RenderThread::Get()->RemoveRoute(routing_id_);
559 SetHidden(false);
560 if (RenderThreadImpl::current())
561 RenderThreadImpl::current()->WidgetDestroyed();
562 }
563
564 if (for_oopif_) {
565 // Widgets for frames may be created and closed at any time while the frame
566 // is alive. However, the closing process must happen synchronously. Frame
567 // widget and frames hold pointers to each other. If Close() is deferred to
568 // the message loop like in the non-frame widget case, WebWidget::close()
569 // can end up accessing members of an already-deleted frame.
570 Close();
571 } else {
572 // If there is a Send call on the stack, then it could be dangerous to close
573 // now. Post a task that only gets invoked when there are no nested message
574 // loops.
575 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
576 FROM_HERE, base::Bind(&RenderWidget::Close, this));
577 }
578
579 // Balances the AddRef taken when we called AddRoute.
580 Release();
initial.commit09911bf2008-07-26 23:55:29581}
582
fsamuel664e8b62016-01-20 19:54:01583void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04584 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32585 return;
586
[email protected]b2e4c70132013-10-03 02:07:51587 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39588 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51589 return;
590 }
591
mfomitchev2600fd7c2016-02-17 20:53:39592 Resize(params);
initial.commit09911bf2008-07-26 23:55:29593}
594
dgozman9260b0a12015-03-16 13:45:20595void RenderWidget::OnEnableDeviceEmulation(
596 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39597 if (!screen_metrics_emulator_) {
598 ResizeParams resize_params;
599 resize_params.screen_info = screen_info_;
600 resize_params.new_size = size_;
601 resize_params.physical_backing_size = physical_backing_size_;
602 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39603 resize_params.resizer_rect = resizer_rect_;
604 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
605 resize_params.display_mode = display_mode_;
606 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
607 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18608 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39609 } else {
dgozman9260b0a12015-03-16 13:45:20610 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39611 }
dgozman9260b0a12015-03-16 13:45:20612}
613
614void RenderWidget::OnDisableDeviceEmulation() {
615 screen_metrics_emulator_.reset();
616}
617
[email protected]b5913d72012-02-07 22:26:54618void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01619 if (resizer_rect_ == resizer_rect)
620 return;
621 resizer_rect_ = resizer_rect;
622 if (webwidget_)
623 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54624}
625
initial.commit09911bf2008-07-26 23:55:29626void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31627 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29628 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03629 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59630 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
631 WasHidden());
initial.commit09911bf2008-07-26 23:55:29632}
633
[email protected]3399dd822014-08-09 11:14:24634void RenderWidget::OnWasShown(bool needs_repainting,
635 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41636 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29637 // During shutdown we can just ignore this message.
638 if (!webwidget_)
639 return;
640
641 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03642 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59643 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
644 WasShown());
initial.commit09911bf2008-07-26 23:55:29645
[email protected]8a23afb32014-04-30 22:40:23646 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29647 return;
initial.commit09911bf2008-07-26 23:55:29648
649 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24650 if (compositor_) {
651 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15652 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24653 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05654 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24655 }
jdduke491a3f0c2015-06-15 23:30:26656 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29657}
658
[email protected]53d3f302009-12-21 04:42:05659void RenderWidget::OnRequestMoveAck() {
660 DCHECK(pending_window_rect_count_);
661 pending_window_rect_count_--;
bokan71cb5b12016-04-27 03:45:22662 if (!pending_window_rect_count_)
663 view_screen_rect_ = pending_window_rect_;
[email protected]53d3f302009-12-21 04:42:05664}
665
[email protected]ed7defa2013-03-12 21:29:59666GURL RenderWidget::GetURLForGraphicsContext3D() {
667 return GURL();
[email protected]65225772011-05-12 21:10:24668}
669
fsamuel78f86e42016-01-20 04:10:23670void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10671 const ui::LatencyInfo& latency_info,
672 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23673 if (!input_event)
674 return;
dtapuska0bd451a2016-02-18 17:08:10675 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23676}
677
678void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
679 if (webwidget_)
680 webwidget_->setCursorVisibilityState(is_visible);
681}
682
683void RenderWidget::OnMouseCaptureLost() {
684 if (webwidget_)
685 webwidget_->mouseCaptureLost();
686}
687
688void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08689 has_focus_ = enable;
690
fsamuel78f86e42016-01-20 04:10:23691 if (webwidget_)
692 webwidget_->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08693
694 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
695 RenderWidgetSetFocus(enable));
fsamuel78f86e42016-01-20 04:10:23696}
697
698///////////////////////////////////////////////////////////////////////////////
699// RenderWidgetCompositorDelegate
700
701void RenderWidget::ApplyViewportDeltas(
702 const gfx::Vector2dF& inner_delta,
703 const gfx::Vector2dF& outer_delta,
704 const gfx::Vector2dF& elastic_overscroll_delta,
705 float page_scale,
706 float top_controls_delta) {
707 webwidget_->applyViewportDeltas(inner_delta, outer_delta,
708 elastic_overscroll_delta, page_scale,
709 top_controls_delta);
710}
711
712void RenderWidget::BeginMainFrame(double frame_time_sec) {
713 webwidget_->beginFrame(frame_time_sec);
714}
715
dchengcedca5612016-04-09 01:40:15716std::unique_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(
717 bool fallback) {
piman990d8ea2016-01-12 15:35:31718 DCHECK(webwidget_);
[email protected]7912e822014-04-16 02:37:03719 // For widgets that are never visible, we don't start the compositor, so we
720 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39721 DCHECK(!compositor_never_visible_);
danakj83066a32016-06-21 02:34:49722 return RenderThreadImpl::current()->CreateCompositorOutputSurface(
723 fallback, routing_id_, frame_swap_message_queue_,
724 GetURLForGraphicsContext3D());
[email protected]ba91a792013-02-06 09:48:28725}
726
dchengcedca5612016-04-09 01:40:15727std::unique_ptr<cc::BeginFrameSource>
fsamuel78f86e42016-01-20 04:10:23728RenderWidget::CreateExternalBeginFrameSource() {
729 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_);
730}
731
732void RenderWidget::DidCommitAndDrawCompositorFrame() {
733 // NOTE: Tests may break if this event is renamed or moved. See
734 // tab_capture_performancetest.cc.
735 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08736
737 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
738 DidCommitAndDrawCompositorFrame());
739
fsamuel78f86e42016-01-20 04:10:23740 // Notify subclasses that we initiated the paint operation.
741 DidInitiatePaint();
742}
743
744void RenderWidget::DidCommitCompositorFrame() {
745 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
746 DidCommitCompositorFrame());
747 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
748 DidCommitCompositorFrame());
749#if defined(VIDEO_HOLE)
750 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
751 DidCommitCompositorFrame());
752#endif // defined(VIDEO_HOLE)
753 input_handler_->FlushPendingInputEventAck();
754}
755
756void RenderWidget::DidCompletePageScaleAnimation() {}
757
758void RenderWidget::DidCompleteSwapBuffers() {
759 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
760
761 // Notify subclasses threaded composited rendering was flushed to the screen.
762 DidFlushPaint();
763
pimanbfb2ceb2016-03-18 21:32:58764 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23765 return;
766 }
767
768 ViewHostMsg_UpdateRect_Params params;
769 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23770 params.flags = next_paint_flags_;
771
772 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
773 next_paint_flags_ = 0;
774 need_update_rect_for_auto_resize_ = false;
775}
776
fsamuel78f86e42016-01-20 04:10:23777void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
778 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
779}
780
781bool RenderWidget::IsClosing() const {
782 return host_closing_;
783}
784
[email protected]4d7e46a2013-11-08 05:33:40785void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24786 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:24787 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:26788 ScheduleComposite();
[email protected]65225772011-05-12 21:10:24789}
790
[email protected]4d7e46a2013-11-08 05:33:40791void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24792 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16793
[email protected]404939f2012-06-01 04:06:18794 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16795 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:29796}
797
fsamuel78f86e42016-01-20 04:10:23798void RenderWidget::OnSwapBuffersPosted() {
799 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:29800}
801
danakj53eccbc2016-03-02 22:51:07802void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23803 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29804}
805
fsamuel78f86e42016-01-20 04:10:23806void RenderWidget::UpdateVisualState() {
807 webwidget_->updateAllLifecyclePhases();
808}
809
810void RenderWidget::WillBeginCompositorFrame() {
811 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
812
813 // The UpdateTextInputState can result in further layout and possibly
814 // enable GPU acceleration so they need to be called before any painting
815 // is done.
816 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
817 UpdateSelectionBounds();
lfge6119aac2016-01-27 02:14:31818
819 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
820 WillBeginCompositorFrame());
initial.commit09911bf2008-07-26 23:55:29821}
822
jbroman6ccbc7d472016-07-27 04:45:41823std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
824 std::unique_ptr<cc::CopyOutputRequest> request) {
825 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
826 routing_id_, std::move(request));
827}
828
fsamuel72464894f2015-12-15 06:59:31829///////////////////////////////////////////////////////////////////////////////
830// RenderWidgetInputHandlerDelegate
831
avid7d6b2e2016-03-04 19:41:17832void RenderWidget::FocusChangeComplete() {
833 if (owner_delegate_)
834 owner_delegate_->RenderWidgetFocusChangeComplete();
835}
fsamuel72464894f2015-12-15 06:59:31836
837bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17838 if (owner_delegate_)
839 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
840
fsamuel72464894f2015-12-15 06:59:31841 return true;
842}
843
dtapuska1827dd22016-03-11 15:24:59844void RenderWidget::ObserveGestureEventAndResult(
845 const blink::WebGestureEvent& gesture_event,
846 const gfx::Vector2dF& unused_delta,
847 bool event_processed) {
848 if (!compositor_deps_->IsElasticOverscrollEnabled())
849 return;
850
851 cc::InputHandlerScrollResult scroll_result;
852 scroll_result.did_scroll = event_processed;
853 scroll_result.did_overscroll_root = !unused_delta.IsZero();
854 scroll_result.unused_scroll_delta = unused_delta;
855
856 RenderThreadImpl* render_thread = RenderThreadImpl::current();
857 InputHandlerManager* input_handler_manager =
858 render_thread ? render_thread->input_handler_manager() : NULL;
859 if (input_handler_manager) {
860 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
861 routing_id_, gesture_event, scroll_result);
862 }
863}
864
avid7d6b2e2016-03-04 19:41:17865void RenderWidget::OnDidHandleKeyEvent() {
866 if (owner_delegate_)
867 owner_delegate_->RenderWidgetDidHandleKeyEvent();
868}
fsamuel72464894f2015-12-15 06:59:31869
chongza8ba91fc2016-08-16 21:39:17870void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:31871 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
872}
873
dchengcedca5612016-04-09 01:40:15874void RenderWidget::OnInputEventAck(
875 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:31876 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
877}
878
dtapuska46616922016-03-17 22:52:01879void RenderWidget::NotifyInputEventHandled(
dtapuskab08721e62016-06-29 03:35:07880 blink::WebInputEvent::Type handled_type,
881 InputEventAckState ack_result) {
dtapuska0bd451a2016-02-18 17:08:10882 RenderThreadImpl* render_thread = RenderThreadImpl::current();
883 InputHandlerManager* input_handler_manager =
884 render_thread ? render_thread->input_handler_manager() : NULL;
885 if (input_handler_manager) {
dtapuskab08721e62016-06-29 03:35:07886 input_handler_manager->NotifyInputEventHandledOnMainThread(
887 routing_id_, handled_type, ack_result);
dtapuska0bd451a2016-02-18 17:08:10888 }
889}
890
fsamuele8326c742016-01-12 00:49:39891void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
892 // Nothing to do here. RenderWidget created the |input_handler| and will take
893 // ownership of it. We just verify here that we don't already have an input
894 // handler.
895 DCHECK(!input_handler_);
896}
897
fsamuel72464894f2015-12-15 06:59:31898void RenderWidget::UpdateTextInputState(ShowIme show_ime,
899 ChangeSource change_source) {
900 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
901 if (ime_event_guard_) {
902 // show_ime should still be effective even if it was set inside the IME
903 // event guard.
904 if (show_ime == ShowIme::IF_NEEDED) {
905 ime_event_guard_->set_show_ime(true);
906 }
907 return;
908 }
909
910 ui::TextInputType new_type = GetTextInputType();
911 if (IsDateTimeInput(new_type))
912 return; // Not considered as a text input field in WebKit/Chromium.
913
914 blink::WebTextInputInfo new_info;
915 if (webwidget_)
916 new_info = webwidget_->textInputInfo();
917 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
918
919 bool new_can_compose_inline = CanComposeInline();
920
921 // Only sends text input params if they are changed or if the ime should be
922 // shown.
923 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:39924 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
fsamuel72464894f2015-12-15 06:59:31925 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
926 text_input_info_ != new_info ||
927 can_compose_inline_ != new_can_compose_inline)
928#if defined(OS_ANDROID)
929 || text_field_is_dirty_
930#endif
931 ) {
ekaramad9053e57b2016-04-26 20:00:38932 TextInputState params;
fsamuel72464894f2015-12-15 06:59:31933 params.type = new_type;
934 params.mode = new_mode;
935 params.flags = new_info.flags;
936 params.value = new_info.value.utf8();
937 params.selection_start = new_info.selectionStart;
938 params.selection_end = new_info.selectionEnd;
939 params.composition_start = new_info.compositionStart;
940 params.composition_end = new_info.compositionEnd;
941 params.can_compose_inline = new_can_compose_inline;
942 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
943#if defined(USE_AURA)
944 params.is_non_ime_change = true;
945#endif
946#if defined(OS_ANDROID)
947 params.is_non_ime_change =
948 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
949 if (params.is_non_ime_change)
950 OnImeEventSentForAck(new_info);
951 text_field_is_dirty_ = false;
952#endif
953 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
954
955 text_input_info_ = new_info;
956 text_input_type_ = new_type;
957 text_input_mode_ = new_mode;
958 can_compose_inline_ = new_can_compose_inline;
959 text_input_flags_ = new_info.flags;
960 }
961}
962
963bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:17964 if (owner_delegate_)
965 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
966
fsamuel72464894f2015-12-15 06:59:31967 return false;
968}
969
970bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
lfge0c2792ec2016-05-11 18:52:08971 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
972 RenderWidgetWillHandleMouseEvent());
973
avid7d6b2e2016-03-04 19:41:17974 if (owner_delegate_)
975 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
976
fsamuel72464894f2015-12-15 06:59:31977 return false;
[email protected]fd847792013-10-24 17:12:35978}
979
initial.commit09911bf2008-07-26 23:55:29980///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:39981// RenderWidgetScreenMetricsDelegate
982
983void RenderWidget::Redraw() {
984 set_next_paint_is_resize_ack();
985 if (compositor_)
986 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
987}
988
bokanc63441c2016-04-27 15:49:12989void RenderWidget::ResizeWebWidget() {
990 webwidget_->resize(GetSizeForWebWidget());
991}
992
993gfx::Size RenderWidget::GetSizeForWebWidget() const {
994 if (IsUseZoomForDSFEnabled())
995 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
996
997 return size_;
998}
999
mfomitchev2600fd7c2016-02-17 20:53:391000void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581001 bool orientation_changed =
1002 screen_info_.orientationAngle != params.screen_info.orientationAngle ||
1003 screen_info_.orientationType != params.screen_info.orientationType;
1004
mfomitchev2600fd7c2016-02-17 20:53:391005 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581006
1007 if (device_scale_factor_ != screen_info_.deviceScaleFactor) {
1008 device_scale_factor_ = screen_info_.deviceScaleFactor;
1009 OnDeviceScaleFactorChanged();
1010 ScheduleComposite();
1011 }
mfomitchev2600fd7c2016-02-17 20:53:391012
1013 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1014 // A resize ack shouldn't be requested if we have not ACK'd the previous
1015 // one.
1016 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1017 }
1018
1019 // Ignore this during shutdown.
1020 if (!webwidget_)
1021 return;
1022
ianwene5fc5782016-08-18 04:05:151023 if (compositor_) {
mfomitchev2600fd7c2016-02-17 20:53:391024 compositor_->setViewportSize(params.physical_backing_size);
ianwene5fc5782016-08-18 04:05:151025 compositor_->setBottomControlsHeight(params.bottom_controls_height);
1026 }
mfomitchev2600fd7c2016-02-17 20:53:391027
mfomitchev2600fd7c2016-02-17 20:53:391028 visible_viewport_size_ = params.visible_viewport_size;
1029 resizer_rect_ = params.resizer_rect;
1030
1031 // NOTE: We may have entered fullscreen mode without changing our size.
1032 bool fullscreen_change =
1033 is_fullscreen_granted_ != params.is_fullscreen_granted;
1034 is_fullscreen_granted_ = params.is_fullscreen_granted;
1035 display_mode_ = params.display_mode;
1036
bokanc63441c2016-04-27 15:49:121037 size_ = params.new_size;
1038 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391039
bokanc63441c2016-04-27 15:49:121040 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221041
mfomitchev2600fd7c2016-02-17 20:53:391042 WebSize visual_viewport_size;
1043
1044 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181045 visual_viewport_size = gfx::ScaleToCeiledSize(
1046 params.visible_viewport_size,
1047 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391048 } else {
1049 visual_viewport_size = visible_viewport_size_;
1050 }
1051
1052 webwidget()->resizeVisualViewport(visual_viewport_size);
1053
bokanc63441c2016-04-27 15:49:121054 // When resizing, we want to wait to paint before ACK'ing the resize. This
1055 // ensures that we only resize as fast as we can paint. We only need to
1056 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391057 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1058 // In this case there is no paint/composite and therefore no
1059 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1060 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1061 DCHECK(!params.needs_resize_ack);
1062 }
1063
1064 // Send the Resize_ACK flag once we paint again if requested.
1065 if (params.needs_resize_ack)
1066 set_next_paint_is_resize_ack();
1067
1068 if (fullscreen_change)
1069 DidToggleFullscreen();
1070
engedy6cb63c92016-02-23 14:14:581071 if (orientation_changed)
1072 OnOrientationChange();
1073
mfomitchev2600fd7c2016-02-17 20:53:391074 // If a resize ack is requested and it isn't set-up, then no more resizes will
1075 // come in and in general things will go wrong.
1076 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1077}
1078
1079void RenderWidget::SetScreenMetricsEmulationParameters(
1080 bool enabled,
1081 const blink::WebDeviceEmulationParams& params) {
1082 // This is only supported in RenderView.
1083 NOTREACHED();
1084}
1085
1086void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1087 const gfx::Rect& window_screen_rect) {
1088 view_screen_rect_ = view_screen_rect;
1089 window_screen_rect_ = window_screen_rect;
1090}
1091
1092///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461093// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291094
[email protected]3a1c8a8032013-03-18 22:35:321095void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401096 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051097 if (compositor_)
oshima750cb4342015-10-31 00:59:011098 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051099}
1100
[email protected]e195e582013-03-08 01:32:591101void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221102 DCHECK(!host_closing_);
1103
fsamuel78f86e42016-01-20 04:10:231104 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1105 compositor_deps_);
oshima750cb4342015-10-31 00:59:011106 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331107 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391108 // For background pages and certain tests, we don't want to trigger
1109 // OutputSurface creation.
1110 if (compositor_never_visible_ || !RenderThreadImpl::current())
1111 compositor_->SetNeverVisible();
1112
pimanc4af3072015-10-02 03:45:591113 StartCompositor();
[email protected]e195e582013-03-08 01:32:591114}
1115
ennef3c58142014-12-09 21:44:381116void RenderWidget::WillCloseLayerTreeView() {
1117 if (host_closing_)
1118 return;
1119
1120 // Prevent new compositors or output surfaces from being created.
1121 host_closing_ = true;
1122
[email protected]aeeedad2014-08-22 18:16:221123 // Always send this notification to prevent new layer tree views from
1124 // being created, even if one hasn't been created yet.
1125 if (webwidget_)
1126 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221127}
1128
[email protected]180ef242013-11-07 06:50:461129blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281130 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061131}
1132
dglazkovf0e1d6d2015-10-10 02:13:481133void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1134 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1135 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1136 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1137 }
dglazkov79c426102015-08-31 21:22:431138
dglazkovf0e1d6d2015-10-10 02:13:481139 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1140 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431141}
1142
jdduke491a3f0c2015-06-15 23:30:261143void RenderWidget::ScheduleComposite() {
1144 if (compositor_ &&
1145 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1146 compositor_->setNeedsAnimate();
1147 }
1148}
1149
1150void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1151 if (compositor_) {
1152 // Regardless of whether threaded compositing is enabled, always
1153 // use this mechanism to force the compositor to redraw. However,
1154 // the invalidation code path below is still needed for the
1155 // non-threaded case.
1156 compositor_->SetNeedsForcedRedraw();
1157 }
1158 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151159}
1160
[email protected]586871b2014-07-22 17:05:111161// static
dchengcedca5612016-04-09 01:40:151162std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111163 IPC::Message* msg,
1164 MessageDeliveryPolicy policy,
1165 FrameSwapMessageQueue* frame_swap_message_queue,
1166 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111167 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111168 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151169 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1170 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111171 &first_message_for_frame);
1172 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151173 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111174 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061175 return promise;
[email protected]586871b2014-07-22 17:05:111176 }
dcheng4b6b5ff2014-10-16 00:42:061177 return nullptr;
[email protected]586871b2014-07-22 17:05:111178}
1179
1180void RenderWidget::QueueMessage(IPC::Message* msg,
1181 MessageDeliveryPolicy policy) {
1182 // RenderThreadImpl::current() is NULL in some tests.
1183 if (!compositor_ || !RenderThreadImpl::current()) {
1184 Send(msg);
1185 return;
1186 }
1187
dchengcedca5612016-04-09 01:40:151188 std::unique_ptr<cc::SwapPromise> swap_promise =
1189 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111190 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111191 compositor_->GetSourceFrameNumber());
1192
1193 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321194 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351195 // Request a commit. This might either A) request a commit ahead of time
1196 // or B) request a commit which is not needed because there are not
1197 // pending updates. If B) then the commit will be skipped and the swap
1198 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1199 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1200 // can_cancel_commit is not unset.
1201 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111202 }
1203}
1204
[email protected]4873c7d2009-07-16 06:36:281205void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301206 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521207 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181208 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291209 // Only send a SetCursor message if we need to make a change.
1210 if (!current_cursor_.IsEqual(cursor)) {
1211 current_cursor_ = cursor;
1212 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1213 }
1214}
1215
1216// We are supposed to get a single call to Show for a newly created RenderWidget
1217// that was created via RenderWidget::CreateWebView. So, we wait until this
1218// point to dispatch the ShowWidget message.
1219//
1220// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281221// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291222//
[email protected]4873c7d2009-07-16 06:36:281223void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291224 DCHECK(!did_show_) << "received extraneous Show call";
1225 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1226 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1227
[email protected]8de12d942010-11-17 20:42:441228 if (did_show_)
1229 return;
1230
1231 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561232 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441233 // that's okay. It'll be ignored if as_popup is false, or the browser
1234 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561235 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1236 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291237}
1238
[email protected]2533ce12009-05-09 00:02:241239void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381240 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241241 Send(new ViewHostMsg_Close(routing_id_));
1242}
1243
dgozmancf9039cd2015-04-06 12:01:311244void RenderWidget::NotifyOnClose() {
1245 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1246}
1247
[email protected]4873c7d2009-07-16 06:36:281248void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081249 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321250 if (is_swapped_out_) {
1251 // This widget is currently swapped out, and the active widget is in a
1252 // different process. Have the browser route the close request to the
1253 // active widget instead, so that the correct unload handlers are run.
1254 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1255 return;
1256 }
1257
initial.commit09911bf2008-07-26 23:55:291258 // If a page calls window.close() twice, we'll end up here twice, but that's
1259 // OK. It is safe to send multiple Close messages.
1260
[email protected]2533ce12009-05-09 00:02:241261 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1262 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1263 // could be closed before the JS finishes executing. So instead, post a
1264 // message back to the message loop, which won't run until the JS is
1265 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081266 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211267 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291268}
1269
[email protected]9017d7852013-11-21 17:47:351270void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151271 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351272 const SyntheticGestureCompletionCallback& callback) {
1273 DCHECK(!callback.is_null());
1274
1275 pending_synthetic_gesture_callbacks_.push(callback);
1276
1277 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321278 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351279
1280 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1281}
1282
initial.commit09911bf2008-07-26 23:55:291283void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031284 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381285 WillCloseLayerTreeView();
1286 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291287 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281288 webwidget_->close();
lfg4fa48da2016-05-09 18:25:131289 webwidget_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291290 }
1291}
1292
[email protected]4873c7d2009-07-16 06:36:281293WebRect RenderWidget::windowRect() {
1294 if (pending_window_rect_count_)
1295 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241296
[email protected]80ad8622012-11-07 16:33:031297 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291298}
1299
[email protected]180ef242013-11-07 06:50:461300void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301301 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541302 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301303}
1304
oshima33ec97cd2015-12-14 19:40:241305void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1306 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511307 if (popup_origin_scale_for_emulation_) {
1308 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561309 window_rect.x = popup_screen_origin_for_emulation_.x() +
1310 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1311 window_rect.y = popup_screen_origin_for_emulation_.y() +
1312 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511313 }
1314
[email protected]5b45ad42013-10-25 00:42:041315 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201316 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561317 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1318 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031319 } else {
bokanc007c3a2015-02-03 07:15:561320 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031321 }
initial.commit09911bf2008-07-26 23:55:291322 } else {
bokanc007c3a2015-02-03 07:15:561323 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291324 }
1325}
1326
[email protected]2533ce12009-05-09 00:02:241327void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1328 pending_window_rect_ = rect;
1329 pending_window_rect_count_++;
1330}
1331
lfg0140a452016-07-19 19:15:051332gfx::Rect RenderWidget::RootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241333 if (pending_window_rect_count_) {
1334 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1335 // the RootWindowRect is probably going to return wrong results since the
1336 // browser may not have processed the Move yet. There isn't really anything
1337 // good to do in this case, and it shouldn't happen - since this size is
1338 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281339 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241340 }
1341
[email protected]80ad8622012-11-07 16:33:031342 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371343}
1344
[email protected]4873c7d2009-07-16 06:36:281345WebRect RenderWidget::windowResizerRect() {
1346 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191347}
1348
[email protected]fa7b1dc2010-06-23 17:53:041349void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261350 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041351 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071352 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041353 int selection_start, int selection_end) {
ekaramad2a46d632016-07-19 13:33:091354#if defined(ENABLE_PLUGINS)
1355 if (focused_pepper_plugin_) {
1356 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1357 text, underlines, selection_start, selection_end);
1358 return;
1359 }
1360#endif
1361 if (replacement_range.IsValid()) {
1362 webwidget_->applyReplacementRange(replacement_range.start(),
1363 replacement_range.length());
1364 }
1365
[email protected]0d1ebed12013-08-05 22:01:131366 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281367 return;
[email protected]66fca5bc2013-05-23 06:58:291368 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361369 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041370 text, WebVector<WebCompositionUnderline>(underlines),
1371 selection_start, selection_end)) {
1372 // If we failed to set the composition text, then we need to let the browser
1373 // process to cancel the input method's ongoing composition session, to make
1374 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221375 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261376 }
nonafa291792016-08-10 02:36:181377 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041378}
1379
[email protected]fcf75d42013-12-03 20:11:261380void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511381 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021382 bool keep_selection) {
ekaramad2a46d632016-07-19 13:33:091383#if defined(ENABLE_PLUGINS)
1384 if (focused_pepper_plugin_) {
1385 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition(
1386 text, replacement_range, keep_selection);
1387 return;
1388 }
1389#endif
1390 if (replacement_range.IsValid()) {
1391 webwidget_->applyReplacementRange(replacement_range.start(),
1392 replacement_range.length());
1393 }
1394
[email protected]0d1ebed12013-08-05 22:01:131395 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041396 return;
[email protected]66fca5bc2013-05-23 06:58:291397 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391398 input_handler_->set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021399 if (text.length())
1400 webwidget_->confirmComposition(text);
1401 else if (keep_selection)
1402 webwidget_->confirmComposition(WebWidget::KeepSelection);
1403 else
1404 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391405 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181406 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291407}
1408
oshimad5279032015-12-16 18:22:331409void RenderWidget::OnDeviceScaleFactorChanged() {
1410 if (!compositor_)
1411 return;
oshimad5279032015-12-16 18:22:331412 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181413 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331414 else
1415 compositor_->setDeviceScaleFactor(device_scale_factor_);
1416}
1417
[email protected]0bc1f572013-04-17 01:46:311418void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121419 // During shutdown we can just ignore this message.
1420 if (!webwidget_)
1421 return;
1422
[email protected]0bc1f572013-04-17 01:46:311423 // Even if the browser provides an empty damage rect, it's still expecting to
1424 // receive a repaint ack so just damage the entire widget bounds.
1425 if (size_to_paint.IsEmpty()) {
1426 size_to_paint = size_;
1427 }
1428
[email protected]ec7dc112008-08-06 05:30:121429 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051430 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311431 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121432}
1433
[email protected]79fa22e2013-08-23 15:18:121434void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351435 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1436
1437 pending_synthetic_gesture_callbacks_.front().Run();
1438 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271439}
1440
[email protected]4873c7d2009-07-16 06:36:281441void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111442 if (!webwidget_)
1443 return;
[email protected]4873c7d2009-07-16 06:36:281444 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111445}
1446
[email protected]80ad8622012-11-07 16:33:031447void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1448 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511449 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391450 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1451 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511452 } else {
mfomitchev2600fd7c2016-02-17 20:53:391453 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511454 }
[email protected]80ad8622012-11-07 16:33:031455 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1456}
1457
lfgdb5c4ed2016-03-04 23:09:071458void RenderWidget::OnUpdateWindowScreenRect(
1459 const gfx::Rect& window_screen_rect) {
1460 if (screen_metrics_emulator_) {
1461 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
1462 } else {
1463 window_screen_rect_ = window_screen_rect;
1464 }
1465}
1466
fsamuel278664272016-07-13 04:06:591467void RenderWidget::OnSetSurfaceClientId(uint32_t surface_id_namespace) {
kenrbb4e2a3b2015-05-14 15:05:051468 if (compositor_)
fsamuel278664272016-07-13 04:06:591469 compositor_->SetSurfaceClientId(surface_id_namespace);
kenrbb4e2a3b2015-05-14 15:05:051470}
1471
dtrainor5ef644e2015-11-19 00:12:471472void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1473 if (compositor_)
1474 compositor_->OnHandleCompositorProto(proto);
1475}
1476
[email protected]adb362312014-06-28 06:04:241477void RenderWidget::showImeIfNeeded() {
1478 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131479}
1480
fsamuel72464894f2015-12-15 06:59:311481ui::TextInputType RenderWidget::GetTextInputType() {
ekaramad2a46d632016-07-19 13:33:091482#if defined(ENABLE_PLUGINS)
1483 if (focused_pepper_plugin_)
1484 return focused_pepper_plugin_->text_input_type();
1485#endif
fsamuel72464894f2015-12-15 06:59:311486 if (webwidget_)
1487 return WebKitToUiTextInputType(webwidget_->textInputType());
1488 return ui::TEXT_INPUT_TYPE_NONE;
1489}
1490
nonafa291792016-08-10 02:36:181491void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1492 if (!monitor_composition_info_ && !immediate_request)
1493 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591494
nonafa291792016-08-10 02:36:181495 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1496 gfx::Range range;
1497 std::vector<gfx::Rect> character_bounds;
1498
1499 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1500 // Composition information is only available on editable node.
1501 range = gfx::Range::InvalidRange();
1502 } else {
1503 GetCompositionRange(&range);
1504 GetCompositionCharacterBounds(&character_bounds);
1505 }
1506
1507 if (!immediate_request &&
1508 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311509 return;
nonafa291792016-08-10 02:36:181510 }
fsamuel72464894f2015-12-15 06:59:311511 composition_character_bounds_ = character_bounds;
1512 composition_range_ = range;
1513 Send(new InputHostMsg_ImeCompositionRangeChanged(
1514 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311515}
1516
oshimaf866dab2015-12-05 00:41:541517void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1518 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181519 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331520 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541521 // anchor element can be placed at half pixel.
1522 gfx::Rect window_rect =
1523 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1524 rect->x = window_rect.x();
1525 rect->y = window_rect.y();
1526 rect->width = window_rect.width();
1527 rect->height = window_rect.height();
1528 }
1529}
1530
oshimaa6985b62016-01-27 08:58:301531void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1532 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181533 rect->x *= GetOriginalDeviceScaleFactor();
1534 rect->y *= GetOriginalDeviceScaleFactor();
1535 rect->width *= GetOriginalDeviceScaleFactor();
1536 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301537 }
1538}
1539
[email protected]adb362312014-06-28 06:04:241540void RenderWidget::OnShowImeIfNeeded() {
1541#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311542 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241543#endif
rouslanf7ebd8832015-01-22 01:54:141544
1545// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1546// virtual keyboard.
1547#if !defined(OS_ANDROID)
1548 FocusChangeComplete();
1549#endif
[email protected]adb362312014-06-28 06:04:241550}
1551
1552#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371553void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1554 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131555}
1556
1557void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371558 DCHECK_GE(text_input_info_history_.size(), 1u);
1559 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511560}
changwan8c342742016-02-26 00:53:391561
1562void RenderWidget::OnRequestTextInputStateUpdate() {
1563 DCHECK(!ime_event_guard_);
1564 UpdateSelectionBounds();
1565 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1566}
[email protected]105dffb42013-02-20 03:46:211567#endif
1568
nonafa291792016-08-10 02:36:181569void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1570 bool monitor_request) {
1571 monitor_composition_info_ = monitor_request;
1572 if (!immediate_request)
1573 return;
1574 UpdateCompositionInfo(true /* immediate request */);
1575}
1576
[email protected]0d1ebed12013-08-05 22:01:131577bool RenderWidget::ShouldHandleImeEvent() {
1578#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371579 if (!webwidget_)
1580 return false;
changwan8c342742016-02-26 00:53:391581 if (IsUsingImeThread())
1582 return true;
changwan3a841162015-08-11 02:53:371583
1584 // We cannot handle IME events if there is any chance that the event we are
1585 // receiving here from the browser is based on the state that is different
1586 // from our current one as indicated by |text_input_info_|.
1587 // The states the browser might be in are:
1588 // text_input_info_history_[0] - current state ack'd by browser
1589 // text_input_info_history_[1...N] - pending state changes
1590 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1591 if (text_input_info_history_[i] != text_input_info_)
1592 return false;
1593 }
1594 return true;
[email protected]0d1ebed12013-08-05 22:01:131595#else
1596 return !!webwidget_;
1597#endif
1598}
1599
wjmaclean8a795f32016-08-11 23:49:581600void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191601 if (device_scale_factor_ == device_scale_factor)
1602 return;
1603
1604 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331605
1606 OnDeviceScaleFactorChanged();
jdduke491a3f0c2015-06-15 23:30:261607 ScheduleComposite();
wjmaclean8a795f32016-08-11 23:49:581608
1609 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191610}
1611
[email protected]28ed6b32014-06-08 02:16:271612bool RenderWidget::SetDeviceColorProfile(
1613 const std::vector<char>& color_profile) {
1614 if (device_color_profile_ == color_profile)
1615 return false;
1616
1617 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271618
avi40b5be7a2016-03-03 21:13:441619 if (owner_delegate_)
1620 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1621
1622 return true;
noeldb4df152014-09-16 17:45:201623}
1624
[email protected]fcdc5642014-05-09 14:32:241625void RenderWidget::OnOrientationChange() {
1626}
1627
avib9dbd972016-03-08 18:19:321628void RenderWidget::DidFlushPaint() {
1629 if (owner_delegate_)
1630 owner_delegate_->RenderWidgetDidFlushPaint();
1631}
1632
[email protected]bee16aab2009-08-26 15:55:031633void RenderWidget::SetHidden(bool hidden) {
1634 if (is_hidden_ == hidden)
1635 return;
1636
jdduke8fac9d102014-12-20 02:40:131637 // The status has changed. Tell the RenderThread about it and ensure
1638 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031639 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391640 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131641
[email protected]bee16aab2009-08-26 15:55:031642 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001643 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031644 else
[email protected]b2db9272014-01-10 17:42:001645 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111646
1647 if (render_widget_scheduling_state_)
1648 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031649}
1650
[email protected]2b624c562011-10-27 22:58:261651void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261652 if (!webwidget_)
1653 return;
1654
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121655 if (is_fullscreen_granted_) {
foolip73101372016-07-13 08:19:221656 webwidget_->didEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261657 } else {
foolip73101372016-07-13 08:19:221658 webwidget_->didExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261659 }
[email protected]2b624c562011-10-27 22:58:261660}
1661
[email protected]674741932009-02-04 23:44:461662bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051663 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461664}
1665
[email protected]674741932009-02-04 23:44:461666void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051667 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461668}
1669
[email protected]674741932009-02-04 23:44:461670void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051671 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461672}
1673
changwan8c342742016-02-26 00:53:391674bool RenderWidget::IsUsingImeThread() {
1675#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121676 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391677#else
1678 return false;
1679#endif
1680}
1681
changwanf2a707b2015-10-30 08:22:161682void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1683 if (!ime_event_guard_)
1684 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291685}
1686
changwanf2a707b2015-10-30 08:22:161687void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1688 if (ime_event_guard_ != guard) {
1689#if defined(OS_ANDROID)
1690 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1691 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391692 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161693 // Therefore, we want to mark this text state update as 'from IME' only
1694 // when all the nested events are all originating from IME.
1695 ime_event_guard_->set_from_ime(
1696 ime_event_guard_->from_ime() && guard->from_ime());
1697#endif
1698 return;
1699 }
1700 ime_event_guard_ = nullptr;
1701
[email protected]66fca5bc2013-05-23 06:58:291702 // While handling an ime event, text input state and selection bounds updates
1703 // are ignored. These must explicitly be updated once finished handling the
1704 // ime event.
1705 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471706#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161707 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311708 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1709 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471710#endif
[email protected]66fca5bc2013-05-23 06:58:291711}
1712
[email protected]7c8873e2013-02-05 08:03:011713void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
ekaramad2a46d632016-07-19 13:33:091714#if defined(ENABLE_PLUGINS)
1715 if (focused_pepper_plugin_) {
1716 // TODO(kinaba) http://crbug.com/101101
1717 // Current Pepper IME API does not handle selection bounds. So we simply
1718 // use the caret position as an empty range for now. It will be updated
1719 // after Pepper API equips features related to surrounding text retrieval.
1720 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1721 convertViewportToWindow(&caret);
1722 *focus = caret;
1723 *anchor = caret;
1724 return;
1725 }
1726#endif
[email protected]7c8873e2013-02-05 08:03:011727 WebRect focus_webrect;
1728 WebRect anchor_webrect;
1729 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241730 convertViewportToWindow(&focus_webrect);
1731 convertViewportToWindow(&anchor_webrect);
1732 *focus = focus_webrect;
1733 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321734}
1735
[email protected]e99ef6f2011-10-16 01:13:001736void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081737 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001738 if (!webwidget_)
1739 return;
changwanf2a707b2015-10-30 08:22:161740 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291741 return;
[email protected]e99ef6f2011-10-16 01:13:001742
mohsenb0eeba72015-08-09 06:20:081743#if defined(USE_AURA)
1744 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1745 // Aura beucause composited selection updates are not working for webview tags
1746 // which regresses IME inside webview. Remove this when composited selection
1747 // updates are fixed for webviews. See, http://crbug.com/510568.
1748 bool send_ipc = true;
1749#else
jddukeacf809e2014-09-23 20:38:381750 // With composited selection updates, the selection bounds will be reported
1751 // directly by the compositor, in which case explicit IPC selection
1752 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081753 bool send_ipc =
1754 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1755#endif
1756 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381757 ViewHostMsg_SelectionBounds_Params params;
1758 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1759 if (selection_anchor_rect_ != params.anchor_rect ||
1760 selection_focus_rect_ != params.focus_rect) {
1761 selection_anchor_rect_ = params.anchor_rect;
1762 selection_focus_rect_ = params.focus_rect;
1763 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1764 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1765 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1766 }
[email protected]58b48a0d2012-06-13 07:01:351767 }
jddukeacf809e2014-09-23 20:38:381768
nonafa291792016-08-10 02:36:181769 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:001770}
1771
avi40b5be7a2016-03-03 21:13:441772void RenderWidget::SetDeviceColorProfileForTesting(
1773 const std::vector<char>& color_profile) {
1774 SetDeviceColorProfile(color_profile);
1775}
1776
lfgb00fcad2016-07-14 14:16:331777void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
1778 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
1779 convertViewportToWindow(&new_size_in_window);
1780 if (size_.width() != new_size_in_window.width ||
1781 size_.height() != new_size_in_window.height) {
1782 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
1783
1784 if (resizing_mode_selector_->is_synchronous_mode()) {
lfg0140a452016-07-19 19:15:051785 gfx::Rect new_pos(RootWindowRect().x(), RootWindowRect().y(),
1786 size_.width(), size_.height());
lfgb00fcad2016-07-14 14:16:331787 view_screen_rect_ = new_pos;
1788 window_screen_rect_ = new_pos;
1789 }
1790
1791 AutoResizeCompositor();
1792
1793 if (!resizing_mode_selector_->is_synchronous_mode())
1794 need_update_rect_for_auto_resize_ = true;
1795 }
1796}
1797
[email protected]180ef242013-11-07 06:50:461798// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
danakj365175c2016-02-06 00:37:371799STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1800STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1801STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1802 ui::TEXT_INPUT_TYPE_PASSWORD);
1803STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1804STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1805STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1806STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1807 ui::TEXT_INPUT_TYPE_TELEPHONE);
1808STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1809STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1810STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1811 ui::TEXT_INPUT_TYPE_DATE_TIME);
1812STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1813 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1814STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1815STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1816STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1817STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1818 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1819STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1820 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1821STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1822 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451823
[email protected]5b739cb2012-08-21 20:35:211824ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461825 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211826 // Check the type is in the range representable by ui::TextInputType.
1827 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461828 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211829 return static_cast<ui::TextInputType>(type);
1830}
1831
[email protected]58b48a0d2012-06-13 07:01:351832void RenderWidget::GetCompositionCharacterBounds(
1833 std::vector<gfx::Rect>* bounds) {
1834 DCHECK(bounds);
1835 bounds->clear();
ekaramad2a46d632016-07-19 13:33:091836
1837#if defined(ENABLE_PLUGINS)
1838 if (focused_pepper_plugin_)
1839 return;
1840#endif
1841
1842 if (!webwidget_)
1843 return;
1844 blink::WebVector<blink::WebRect> bounds_from_blink;
1845 if (!webwidget_->getCompositionCharacterBounds(bounds_from_blink))
1846 return;
1847
1848 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
1849 convertViewportToWindow(&bounds_from_blink[i]);
1850 bounds->push_back(bounds_from_blink[i]);
1851 }
[email protected]58b48a0d2012-06-13 07:01:351852}
1853
[email protected]db4fc1e2013-09-06 20:01:511854void RenderWidget::GetCompositionRange(gfx::Range* range) {
ekaramad2a46d632016-07-19 13:33:091855#if defined(ENABLE_PLUGINS)
1856 if (focused_pepper_plugin_)
1857 return;
1858#endif
[email protected]88dbe32f2013-06-20 23:31:361859 size_t location, length;
1860 if (webwidget_->compositionRange(&location, &length)) {
1861 range->set_start(location);
1862 range->set_end(location + length);
1863 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1864 range->set_start(location);
1865 range->set_end(location + length);
1866 } else {
[email protected]db4fc1e2013-09-06 20:01:511867 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:361868 }
1869}
1870
[email protected]501ea13d2013-07-09 17:03:291871bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511872 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291873 const std::vector<gfx::Rect>& bounds) {
1874 if (composition_range_ != range)
1875 return true;
1876 if (bounds.size() != composition_character_bounds_.size())
1877 return true;
1878 for (size_t i = 0; i < bounds.size(); ++i) {
1879 if (bounds[i] != composition_character_bounds_[i])
1880 return true;
1881 }
1882 return false;
1883}
[email protected]501ea13d2013-07-09 17:03:291884
[email protected]ad26ef42011-06-17 07:59:451885bool RenderWidget::CanComposeInline() {
ekaramad2a46d632016-07-19 13:33:091886#if defined(ENABLE_PLUGINS)
1887 if (focused_pepper_plugin_)
1888 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
1889#endif
[email protected]ad26ef42011-06-17 07:59:451890 return true;
[email protected]56ea1a62011-05-30 07:05:571891}
1892
[email protected]4873c7d2009-07-16 06:36:281893WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041894 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281895}
1896
[email protected]fa7b1dc2010-06-23 17:53:041897void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021898 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041899 // If the last text input type is not None, then we should finish any
1900 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451901 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041902 // If a composition text exists, then we need to let the browser process
1903 // to cancel the input method's ongoing composition session.
1904 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:221905 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041906 }
[email protected]d4cff272011-05-02 15:46:011907
nonafa291792016-08-10 02:36:181908 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041909}
1910
donnda070f3c2015-01-16 19:54:111911#if defined(OS_ANDROID)
1912void RenderWidget::showUnhandledTapUIIfNeeded(
1913 const WebPoint& tapped_position,
1914 const WebNode& tapped_node,
1915 bool page_changed) {
fsamuele8326c742016-01-12 00:49:391916 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:111917 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371918 !tapped_node.isContentEditable() &&
1919 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111920 if (should_trigger) {
1921 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1922 tapped_position.x, tapped_position.y));
1923 }
1924}
1925#endif
1926
[email protected]c68c3e4e2013-01-24 00:36:561927void RenderWidget::didHandleGestureEvent(
1928 const WebGestureEvent& event,
1929 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021930#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561931 if (event_cancelled)
1932 return;
[email protected]07c70d22014-08-21 08:33:461933 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:311934 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461935 } else if (event.type == WebInputEvent::GestureLongPress) {
1936 DCHECK(webwidget_);
1937 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:311938 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461939 else
fsamuel72464894f2015-12-15 06:59:311940 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:561941 }
1942#endif
1943}
1944
sataya.m582c9ce2015-06-09 08:03:421945void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:311946 const blink::WebFloatSize& overscrollDelta,
1947 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:421948 const blink::WebFloatPoint& position,
1949 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:481950#if defined(OS_MACOSX)
1951 // On OSX the user can disable the elastic overscroll effect. If that's the
1952 // case, don't forward the overscroll notification.
1953 DCHECK(compositor_deps());
1954 if (!compositor_deps()->IsElasticOverscrollEnabled())
1955 return;
1956#endif
bokane53a10f2016-04-13 23:48:311957 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:391958 position, velocity);
sataya.m582c9ce2015-06-09 08:03:421959}
1960
[email protected]7912e822014-04-16 02:37:031961void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:391962 if (!is_hidden())
1963 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:031964}
1965
[email protected]24ed0432013-04-24 07:50:311966RenderWidgetCompositor* RenderWidget::compositor() const {
1967 return compositor_.get();
1968}
1969
fsamuel72464894f2015-12-15 06:59:311970void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:391971 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:371972}
[email protected]c3d45532011-10-07 19:20:401973
fsamuel72464894f2015-12-15 06:59:311974bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:391975 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:241976}
1977
fsamuel72464894f2015-12-15 06:59:311978void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:391979 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:311980}
1981
[email protected]ce6689f2013-03-29 12:52:551982void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:111983 if (render_widget_scheduling_state_)
1984 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:551985 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
1986}
1987
danakj365175c2016-02-06 00:37:371988// Check blink::WebTouchAction and content::TouchAction is kept in sync.
1989STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
1990STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
1991STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
1992STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
1993STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
1994STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
1995STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
1996STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
1997STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
1998STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
1999 TOUCH_ACTION_MANIPULATION);
2000STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2001 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2002STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
mostynbe29b6882015-01-13 09:59:172003
[email protected]5d0bbdfa92013-12-10 00:35:512004void RenderWidget::setTouchAction(
2005 blink::WebTouchAction web_touch_action) {
2006
2007 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2008 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392009 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512010 return;
2011
[email protected]a18f67a2013-12-20 19:44:362012 content::TouchAction content_touch_action =
2013 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512014 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2015}
2016
[email protected]90f24152014-04-09 12:41:362017void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2018#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392019 if (!IsUsingImeThread())
2020 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362021#endif
2022}
2023
[email protected]e3244ed2014-06-20 20:04:272024void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2025 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162026}
2027
[email protected]e3244ed2014-06-20 20:04:272028void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2029 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162030}
2031
[email protected]de3c5d82014-05-28 22:12:592032void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2033 render_frames_.AddObserver(frame);
2034}
2035
2036void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2037 render_frames_.RemoveObserver(frame);
2038}
2039
[email protected]a017938b2014-05-27 21:17:172040#if defined(VIDEO_HOLE)
2041void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2042 video_hole_frames_.AddObserver(frame);
2043}
2044
2045void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2046 video_hole_frames_.RemoveObserver(frame);
2047}
2048#endif // defined(VIDEO_HOLE)
2049
lfg43e08e62016-02-03 18:51:372050void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2051 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2052 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2053}
2054
oshima50872a72016-03-04 13:26:182055float RenderWidget::GetOriginalDeviceScaleFactor() const {
2056 return
2057 screen_metrics_emulator_ ?
2058 screen_metrics_emulator_->original_screen_info().deviceScaleFactor :
2059 device_scale_factor_;
2060}
2061
lfgbee1e0a2016-06-08 21:24:212062bool RenderWidget::requestPointerLock() {
2063 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2064}
2065
2066void RenderWidget::requestPointerUnlock() {
2067 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2068}
2069
2070bool RenderWidget::isPointerLocked() {
2071 return mouse_lock_dispatcher_->IsMouseLockedTo(
2072 webwidget_mouse_lock_target_.get());
2073}
2074
[email protected]e9ff79c2012-10-19 21:31:262075} // namespace content