blob: 7a9920204a6ac5d184a089a19347b6d04a788b65 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
dchengcedca5612016-04-09 01:40:157#include <memory>
dcheng07945f632015-12-26 07:59:328#include <utility>
9
[email protected]c27dd4f2014-05-22 18:05:1910#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2111#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0012#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1213#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/logging.h"
avi1023d012015-12-25 02:39:1415#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1516#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4017#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3018#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2120#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0021#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2722#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0123#include "base/trace_event/trace_event.h"
24#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "build/build_config.h"
[email protected]7f0d825f2013-03-18 07:24:3026#include "cc/output/output_surface.h"
fsamuel78f86e42016-01-20 04:10:2327#include "cc/scheduler/begin_frame_source.h"
alexclarke7fa93942015-10-21 15:37:1128#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2129#include "components/scheduler/renderer/renderer_scheduler.h"
oshima750cb4342015-10-31 00:59:0130#include "content/common/content_switches_internal.h"
[email protected]9017d7852013-11-21 17:47:3531#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4432#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1533#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1534#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3835#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5036#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1237#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2938#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4239#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4040#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3941#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
[email protected]b2e4c70132013-10-03 02:07:5142#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1143#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1144#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2845#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2946#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1347#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3248#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1649#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2750#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0551#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4452#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5553#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4454#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0955#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0456#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1857#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4858#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1859#include "third_party/WebKit/public/platform/WebCursorInfo.h"
donnda070f3c2015-01-16 19:54:1160#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1862#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3063#include "third_party/WebKit/public/platform/WebSize.h"
64#include "third_party/WebKit/public/platform/WebString.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
penghuang28a5fa22015-12-02 17:58:1994#if defined(MOJO_SHELL_CLIENT)
95#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;
113using blink::WebRange;
114using blink::WebRect;
115using blink::WebScreenInfo;
116using blink::WebSize;
117using blink::WebTextDirection;
118using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25119using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46120using blink::WebVector;
121using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26122
danakj365175c2016-02-06 00:37:37123#define STATIC_ASSERT_ENUM(a, b) \
124 static_assert(static_cast<int>(a) == static_cast<int>(b), \
125 "mismatching enums: " #a)
126
[email protected]6a4d7f62013-01-07 21:32:13127namespace {
[email protected]b256eca2013-07-11 10:57:40128
129typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
130
lfgbee1e0a2016-06-08 21:24:21131class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
132 public:
133 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
134 : webwidget_(webwidget) {}
135
136 void OnLockMouseACK(bool succeeded) override {
137 if (succeeded)
138 webwidget_->didAcquirePointerLock();
139 else
140 webwidget_->didNotAcquirePointerLock();
141 }
142
143 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
144
145 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
146 // The WebWidget handles mouse lock in Blink's handleInputEvent().
147 return false;
148 }
149
150 private:
151 blink::WebWidget* webwidget_;
152};
153
[email protected]b256eca2013-07-11 10:57:40154class TextInputModeMapSingleton {
155 public:
156 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22157 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40158 }
[email protected]dd705d4d2013-11-27 08:14:41159 TextInputModeMapSingleton() {
160 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
161 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
162 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
163 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
164 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
165 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
166 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
167 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
168 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
169 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
170 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40171 }
[email protected]dd705d4d2013-11-27 08:14:41172 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40173 private:
[email protected]dd705d4d2013-11-27 08:14:41174 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40175
olli.raula36aa8be2015-09-10 11:14:22176 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40177
178 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
179};
180
[email protected]dd705d4d2013-11-27 08:14:41181ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40182 static TextInputModeMapSingleton* singleton =
183 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41184 TextInputModeMap::const_iterator it =
185 singleton->map().find(input_mode.utf8());
186 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40187 return ui::TEXT_INPUT_MODE_DEFAULT;
188 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13189}
[email protected]b256eca2013-07-11 10:57:40190
fsamuel72464894f2015-12-15 06:59:31191bool IsDateTimeInput(ui::TextInputType type) {
192 return type == ui::TEXT_INPUT_TYPE_DATE ||
193 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
194 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
195 type == ui::TEXT_INPUT_TYPE_MONTH ||
196 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
dtapuskae7473612015-12-04 14:23:06197}
198
fsamuele8326c742016-01-12 00:49:39199content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
200 content::RenderWidget* widget) {
201#if defined(MOJO_SHELL_CLIENT)
penghuang639a1042016-01-14 21:25:29202 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
ben6c85c4492016-06-16 20:40:51203 if (content::MojoShellConnection::GetForProcess() &&
penghuang639a1042016-01-14 21:25:29204 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39205 return content::RenderWidgetMusConnection::GetOrCreate(
206 widget->routing_id());
207 }
208#endif
209 // If we don't have a connection to the Mojo shell, then we want to route IPCs
210 // back to the browser process rather than Mus so we use the |widget| as the
211 // RenderWidgetInputHandlerDelegate.
212 return widget;
213}
214
[email protected]b256eca2013-07-11 10:57:40215} // namespace
216
[email protected]e9ff79c2012-10-19 21:31:26217namespace content {
[email protected]62cb33cae2009-03-27 23:30:22218
[email protected]b2e4c70132013-10-03 02:07:51219// RenderWidget ---------------------------------------------------------------
220
dcheng35d31c112015-07-22 00:17:36221RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
222 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46223 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04224 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03225 bool hidden,
226 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29227 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36228 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53229 webwidget_(nullptr),
avi40b5be7a2016-03-03 21:13:44230 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29231 opener_id_(MSG_ROUTING_NONE),
initial.commit09911bf2008-07-26 23:55:29232 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51233 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09234 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29235 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04236 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39237 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12238 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12239 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16240 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48241 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22242 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44243 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20244 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45245 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40246 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20247 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53248 can_compose_inline_(true),
[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
[email protected]b2e4c70132013-10-03 02:07:51256 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11257 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42258 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08259 has_host_context_menu_location_(false),
ekaramad2a46d632016-07-19 13:33:09260 has_focus_(false),
261 focused_pepper_plugin_(nullptr) {
[email protected]8b3f0eb2012-05-03 19:15:05262 if (!swapped_out)
263 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27264 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53265 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37266#if defined(OS_ANDROID)
267 text_input_info_history_.push_back(blink::WebTextInputInfo());
268#endif
alexclarke7fa93942015-10-21 15:37:11269
270 // In tests there may not be a RenderThreadImpl.
271 if (RenderThreadImpl::current()) {
272 render_widget_scheduling_state_ = RenderThreadImpl::current()
273 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32274 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11275 render_widget_scheduling_state_->SetHidden(is_hidden_);
276 }
initial.commit09911bf2008-07-26 23:55:29277}
278
279RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11280 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16281
[email protected]992db4c2011-05-12 15:37:15282 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02283 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15284 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29285}
286
[email protected]484955942010-08-19 16:13:18287// static
avi1023d012015-12-25 02:39:14288RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53289 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46290 blink::WebPopupType popup_type,
291 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29292 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36293 scoped_refptr<RenderWidget> widget(new RenderWidget(
294 compositor_deps, popup_type, screen_info, false, false, false));
295 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46296 return widget.get();
[email protected]a635f942012-12-07 10:34:29297 }
298 return NULL;
initial.commit09911bf2008-07-26 23:55:29299}
300
[email protected]484955942010-08-19 16:13:18301// static
kenrba7199832015-01-22 23:44:59302RenderWidget* RenderWidget::CreateForFrame(
303 int routing_id,
kenrba7199832015-01-22 23:44:59304 bool hidden,
305 const blink::WebScreenInfo& screen_info,
306 CompositorDependencies* compositor_deps,
307 blink::WebLocalFrame* frame) {
308 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55309 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
310 // same routing ID for both the view routing ID and the main frame widget
311 // routing ID. https://crbug.com/545684
312 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
313 if (view) {
avi8a45c1092016-03-01 16:12:34314 view->AttachWebFrameWidget(
315 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
316 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55317 }
dcheng35d31c112015-07-22 00:17:36318 scoped_refptr<RenderWidget> widget(
319 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
320 false, hidden, false));
fsamuele8326c742016-01-12 00:49:39321 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20322 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59323 // DoInit increments the reference count on |widget|, keeping it alive after
324 // this function returns.
dcheng35d31c112015-07-22 00:17:36325 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59326 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
327 nullptr)) {
kenrba7199832015-01-22 23:44:59328 return widget.get();
329 }
330 return nullptr;
331}
332
333// static
lfgcaab5142016-02-26 19:06:52334blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08335 RenderWidget* render_widget,
336 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55337 if (!frame->parent()) {
338 // TODO(dcheng): The main frame widget currently has a special case.
339 // Eliminate this once WebView is no longer a WebWidget.
340 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
341 }
dchengda9b4bb2015-07-20 20:58:08342 return blink::WebFrameWidget::create(render_widget, frame);
343}
344
345// static
kenrba7199832015-01-22 23:44:59346blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18347 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46348 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18349 break;
[email protected]180ef242013-11-07 06:50:46350 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44351 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18352 default:
353 NOTREACHED();
354 }
355 return NULL;
356}
357
dchengda9b4bb2015-07-20 20:58:08358void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32359 OnClose();
kenrba7199832015-01-22 23:44:59360}
361
fsamuele8326c742016-01-12 00:49:39362void RenderWidget::SetRoutingID(int32_t routing_id) {
363 routing_id_ = routing_id;
364 input_handler_.reset(new RenderWidgetInputHandler(
365 GetRenderWidgetInputHandlerDelegate(this), this));
366}
367
avi1023d012015-12-25 02:39:14368bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39369 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05370 opener_id, RenderWidget::CreateWebWidget(this),
371 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39372 if (success) {
373 SetRoutingID(routing_id_);
374 return true;
375 }
376 return false;
[email protected]484955942010-08-19 16:13:18377}
378
avi1023d012015-12-25 02:39:14379bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06380 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18381 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29382 DCHECK(!webwidget_);
383
384 if (opener_id != MSG_ROUTING_NONE)
385 opener_id_ = opener_id;
386
[email protected]484955942010-08-19 16:13:18387 webwidget_ = web_widget;
lfgbee1e0a2016-06-08 21:24:21388 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
389 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29390
kenrba7199832015-01-22 23:44:59391 bool result = true;
392 if (create_widget_message)
393 result = RenderThread::Get()->Send(create_widget_message);
394
initial.commit09911bf2008-07-26 23:55:29395 if (result) {
[email protected]380244092011-10-07 17:26:27396 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29397 // Take a reference on behalf of the RenderThread. This will be balanced
398 // when we receive ViewMsg_Close.
399 AddRef();
[email protected]b2db9272014-01-10 17:42:00400 if (RenderThreadImpl::current()) {
401 RenderThreadImpl::current()->WidgetCreated();
402 if (is_hidden_)
403 RenderThreadImpl::current()->WidgetHidden();
404 }
fsamuele8326c742016-01-12 00:49:39405
[email protected]a635f942012-12-07 10:34:29406 return true;
initial.commit09911bf2008-07-26 23:55:29407 } else {
[email protected]a635f942012-12-07 10:34:29408 // The above Send can fail when the tab is closing.
409 return false;
initial.commit09911bf2008-07-26 23:55:29410 }
411}
412
[email protected]992db4c2011-05-12 15:37:15413void RenderWidget::SetSwappedOut(bool is_swapped_out) {
414 // We should only toggle between states.
415 DCHECK(is_swapped_out_ != is_swapped_out);
416 is_swapped_out_ = is_swapped_out;
417
418 // If we are swapping out, we will call ReleaseProcess, allowing the process
419 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52420 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15421 // If we are swapping in, we call AddRefProcess to prevent the process from
422 // exiting.
[email protected]949b6592014-08-20 13:17:52423 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15424 RenderProcess::current()->AddRefProcess();
425}
426
[email protected]949b6592014-08-20 13:17:52427void RenderWidget::WasSwappedOut() {
428 // If we have been swapped out and no one else is using this process,
429 // it's safe to exit now.
430 CHECK(is_swapped_out_);
431 RenderProcess::current()->ReleaseProcess();
432}
433
[email protected]b2e4c70132013-10-03 02:07:51434void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39435 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51436 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43437 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49438 popup_screen_origin_for_emulation_ = gfx::Point(
439 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
440 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56441 screen_info_ = emulator->original_screen_info();
442 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51443}
444
[email protected]2d6836f42014-07-02 17:25:31445gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
446 if (screen_metrics_emulator_)
447 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
448 return anchor;
449}
450
haibinluc643d33c2016-06-03 02:22:34451#if defined(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51452void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39453 ExternalPopupMenu* popup,
454 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49455 popup->SetOriginScaleAndOffsetForEmulation(
456 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51457}
[email protected]53907862014-03-25 15:42:40458#endif
[email protected]b2e4c70132013-10-03 02:07:51459
460void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
461 if (screen_metrics_emulator_)
462 screen_metrics_emulator_->OnShowContextMenu(params);
463}
464
[email protected]a95986a82010-12-24 06:19:28465bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
lfgbee1e0a2016-06-08 21:24:21466 if (mouse_lock_dispatcher_ &&
467 mouse_lock_dispatcher_->OnMessageReceived(message))
468 return true;
469
[email protected]a95986a82010-12-24 06:19:28470 bool handled = true;
471 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15472 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22473 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
474 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22475 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
476 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15477 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
478 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35479 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
480 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28481 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28482 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20483 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
484 OnEnableDeviceEmulation)
485 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
486 OnDisableDeviceEmulation)
[email protected]b5913d72012-02-07 22:26:54487 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28488 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41489 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25490 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28491 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
492 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03493 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
fsamuel278664272016-07-13 04:06:59494 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceClientId, OnSetSurfaceClientId)
lfg43e08e62016-02-03 18:51:37495 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
496 OnWaitNextFrameForTests)
[email protected]105dffb42013-02-20 03:46:21497#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37498 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39499 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
500 OnRequestTextInputStateUpdate)
[email protected]2384b6c2013-02-28 23:58:51501 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21502#endif
dtrainor5ef644e2015-11-19 00:12:47503 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28504 IPC_MESSAGE_UNHANDLED(handled = false)
505 IPC_END_MESSAGE_MAP()
506 return handled;
507}
initial.commit09911bf2008-07-26 23:55:29508
509bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15510 // Don't send any messages after the browser has told us to close, and filter
511 // most outgoing messages while swapped out.
512 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26513 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11514 closing_) {
initial.commit09911bf2008-07-26 23:55:29515 delete message;
516 return false;
517 }
518
519 // If given a messsage without a routing ID, then assign our routing ID.
520 if (message->routing_id() == MSG_ROUTING_NONE)
521 message->set_routing_id(routing_id_);
522
[email protected]380244092011-10-07 17:26:27523 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44524}
525
bokanc007c3a2015-02-03 07:15:56526void RenderWidget::SetWindowRectSynchronously(
527 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39528 ResizeParams params;
529 params.screen_info = screen_info_;
530 params.new_size = new_window_rect.size();
531 params.physical_backing_size =
532 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39533 params.visible_viewport_size = new_window_rect.size();
534 params.resizer_rect = gfx::Rect();
535 params.is_fullscreen_granted = is_fullscreen_granted_;
536 params.display_mode = display_mode_;
537 params.needs_resize_ack = false;
538 Resize(params);
539
bokanc007c3a2015-02-03 07:15:56540 view_screen_rect_ = new_window_rect;
541 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02542 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56543 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02544}
545
initial.commit09911bf2008-07-26 23:55:29546void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32547 DCHECK(content::RenderThread::Get());
548 if (closing_)
549 return;
550 NotifyOnClose();
551 closing_ = true;
552
553 // Browser correspondence is no longer needed at this point.
554 if (routing_id_ != MSG_ROUTING_NONE) {
555 RenderThread::Get()->RemoveRoute(routing_id_);
556 SetHidden(false);
557 if (RenderThreadImpl::current())
558 RenderThreadImpl::current()->WidgetDestroyed();
559 }
560
561 if (for_oopif_) {
562 // Widgets for frames may be created and closed at any time while the frame
563 // is alive. However, the closing process must happen synchronously. Frame
564 // widget and frames hold pointers to each other. If Close() is deferred to
565 // the message loop like in the non-frame widget case, WebWidget::close()
566 // can end up accessing members of an already-deleted frame.
567 Close();
568 } else {
569 // If there is a Send call on the stack, then it could be dangerous to close
570 // now. Post a task that only gets invoked when there are no nested message
571 // loops.
572 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
573 FROM_HERE, base::Bind(&RenderWidget::Close, this));
574 }
575
576 // Balances the AddRef taken when we called AddRoute.
577 Release();
initial.commit09911bf2008-07-26 23:55:29578}
579
fsamuel664e8b62016-01-20 19:54:01580void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04581 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32582 return;
583
[email protected]b2e4c70132013-10-03 02:07:51584 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39585 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51586 return;
587 }
588
mfomitchev2600fd7c2016-02-17 20:53:39589 Resize(params);
initial.commit09911bf2008-07-26 23:55:29590}
591
dgozman9260b0a12015-03-16 13:45:20592void RenderWidget::OnEnableDeviceEmulation(
593 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39594 if (!screen_metrics_emulator_) {
595 ResizeParams resize_params;
596 resize_params.screen_info = screen_info_;
597 resize_params.new_size = size_;
598 resize_params.physical_backing_size = physical_backing_size_;
599 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39600 resize_params.resizer_rect = resizer_rect_;
601 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
602 resize_params.display_mode = display_mode_;
603 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
604 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18605 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39606 } else {
dgozman9260b0a12015-03-16 13:45:20607 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39608 }
dgozman9260b0a12015-03-16 13:45:20609}
610
611void RenderWidget::OnDisableDeviceEmulation() {
612 screen_metrics_emulator_.reset();
613}
614
[email protected]b5913d72012-02-07 22:26:54615void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01616 if (resizer_rect_ == resizer_rect)
617 return;
618 resizer_rect_ = resizer_rect;
619 if (webwidget_)
620 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54621}
622
initial.commit09911bf2008-07-26 23:55:29623void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31624 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29625 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03626 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59627 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
628 WasHidden());
initial.commit09911bf2008-07-26 23:55:29629}
630
[email protected]3399dd822014-08-09 11:14:24631void RenderWidget::OnWasShown(bool needs_repainting,
632 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41633 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29634 // During shutdown we can just ignore this message.
635 if (!webwidget_)
636 return;
637
638 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03639 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59640 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
641 WasShown());
initial.commit09911bf2008-07-26 23:55:29642
[email protected]8a23afb32014-04-30 22:40:23643 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29644 return;
initial.commit09911bf2008-07-26 23:55:29645
646 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24647 if (compositor_) {
648 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15649 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24650 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05651 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24652 }
jdduke491a3f0c2015-06-15 23:30:26653 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29654}
655
[email protected]53d3f302009-12-21 04:42:05656void RenderWidget::OnRequestMoveAck() {
657 DCHECK(pending_window_rect_count_);
658 pending_window_rect_count_--;
bokan71cb5b12016-04-27 03:45:22659 if (!pending_window_rect_count_)
660 view_screen_rect_ = pending_window_rect_;
[email protected]53d3f302009-12-21 04:42:05661}
662
[email protected]ed7defa2013-03-12 21:29:59663GURL RenderWidget::GetURLForGraphicsContext3D() {
664 return GURL();
[email protected]65225772011-05-12 21:10:24665}
666
fsamuel78f86e42016-01-20 04:10:23667void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10668 const ui::LatencyInfo& latency_info,
669 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23670 if (!input_event)
671 return;
dtapuska0bd451a2016-02-18 17:08:10672 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23673}
674
675void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
676 if (webwidget_)
677 webwidget_->setCursorVisibilityState(is_visible);
678}
679
680void RenderWidget::OnMouseCaptureLost() {
681 if (webwidget_)
682 webwidget_->mouseCaptureLost();
683}
684
685void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08686 has_focus_ = enable;
687
fsamuel78f86e42016-01-20 04:10:23688 if (webwidget_)
689 webwidget_->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08690
691 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
692 RenderWidgetSetFocus(enable));
fsamuel78f86e42016-01-20 04:10:23693}
694
695///////////////////////////////////////////////////////////////////////////////
696// RenderWidgetCompositorDelegate
697
698void RenderWidget::ApplyViewportDeltas(
699 const gfx::Vector2dF& inner_delta,
700 const gfx::Vector2dF& outer_delta,
701 const gfx::Vector2dF& elastic_overscroll_delta,
702 float page_scale,
703 float top_controls_delta) {
704 webwidget_->applyViewportDeltas(inner_delta, outer_delta,
705 elastic_overscroll_delta, page_scale,
706 top_controls_delta);
707}
708
709void RenderWidget::BeginMainFrame(double frame_time_sec) {
710 webwidget_->beginFrame(frame_time_sec);
711}
712
dchengcedca5612016-04-09 01:40:15713std::unique_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(
714 bool fallback) {
piman990d8ea2016-01-12 15:35:31715 DCHECK(webwidget_);
[email protected]7912e822014-04-16 02:37:03716 // For widgets that are never visible, we don't start the compositor, so we
717 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39718 DCHECK(!compositor_never_visible_);
danakj83066a32016-06-21 02:34:49719 return RenderThreadImpl::current()->CreateCompositorOutputSurface(
720 fallback, routing_id_, frame_swap_message_queue_,
721 GetURLForGraphicsContext3D());
[email protected]ba91a792013-02-06 09:48:28722}
723
dchengcedca5612016-04-09 01:40:15724std::unique_ptr<cc::BeginFrameSource>
fsamuel78f86e42016-01-20 04:10:23725RenderWidget::CreateExternalBeginFrameSource() {
726 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_);
727}
728
729void RenderWidget::DidCommitAndDrawCompositorFrame() {
730 // NOTE: Tests may break if this event is renamed or moved. See
731 // tab_capture_performancetest.cc.
732 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08733
734 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
735 DidCommitAndDrawCompositorFrame());
736
fsamuel78f86e42016-01-20 04:10:23737 // Notify subclasses that we initiated the paint operation.
738 DidInitiatePaint();
739}
740
741void RenderWidget::DidCommitCompositorFrame() {
742 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
743 DidCommitCompositorFrame());
744 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
745 DidCommitCompositorFrame());
746#if defined(VIDEO_HOLE)
747 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
748 DidCommitCompositorFrame());
749#endif // defined(VIDEO_HOLE)
750 input_handler_->FlushPendingInputEventAck();
751}
752
753void RenderWidget::DidCompletePageScaleAnimation() {}
754
755void RenderWidget::DidCompleteSwapBuffers() {
756 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
757
758 // Notify subclasses threaded composited rendering was flushed to the screen.
759 DidFlushPaint();
760
pimanbfb2ceb2016-03-18 21:32:58761 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23762 return;
763 }
764
765 ViewHostMsg_UpdateRect_Params params;
766 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23767 params.flags = next_paint_flags_;
768
769 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
770 next_paint_flags_ = 0;
771 need_update_rect_for_auto_resize_ = false;
772}
773
fsamuel78f86e42016-01-20 04:10:23774void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
775 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
776}
777
778bool RenderWidget::IsClosing() const {
779 return host_closing_;
780}
781
[email protected]4d7e46a2013-11-08 05:33:40782void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24783 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:24784 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:26785 ScheduleComposite();
[email protected]65225772011-05-12 21:10:24786}
787
[email protected]4d7e46a2013-11-08 05:33:40788void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24789 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16790
[email protected]404939f2012-06-01 04:06:18791 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16792 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:29793}
794
fsamuel78f86e42016-01-20 04:10:23795void RenderWidget::OnSwapBuffersPosted() {
796 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:29797}
798
danakj53eccbc2016-03-02 22:51:07799void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23800 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29801}
802
fsamuel78f86e42016-01-20 04:10:23803void RenderWidget::UpdateVisualState() {
804 webwidget_->updateAllLifecyclePhases();
805}
806
807void RenderWidget::WillBeginCompositorFrame() {
808 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
809
810 // The UpdateTextInputState can result in further layout and possibly
811 // enable GPU acceleration so they need to be called before any painting
812 // is done.
813 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
814 UpdateSelectionBounds();
lfge6119aac2016-01-27 02:14:31815
816 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
817 WillBeginCompositorFrame());
initial.commit09911bf2008-07-26 23:55:29818}
819
fsamuel72464894f2015-12-15 06:59:31820///////////////////////////////////////////////////////////////////////////////
821// RenderWidgetInputHandlerDelegate
822
avid7d6b2e2016-03-04 19:41:17823void RenderWidget::FocusChangeComplete() {
824 if (owner_delegate_)
825 owner_delegate_->RenderWidgetFocusChangeComplete();
826}
fsamuel72464894f2015-12-15 06:59:31827
828bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17829 if (owner_delegate_)
830 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
831
fsamuel72464894f2015-12-15 06:59:31832 return true;
833}
834
dtapuska1827dd22016-03-11 15:24:59835void RenderWidget::ObserveGestureEventAndResult(
836 const blink::WebGestureEvent& gesture_event,
837 const gfx::Vector2dF& unused_delta,
838 bool event_processed) {
839 if (!compositor_deps_->IsElasticOverscrollEnabled())
840 return;
841
842 cc::InputHandlerScrollResult scroll_result;
843 scroll_result.did_scroll = event_processed;
844 scroll_result.did_overscroll_root = !unused_delta.IsZero();
845 scroll_result.unused_scroll_delta = unused_delta;
846
847 RenderThreadImpl* render_thread = RenderThreadImpl::current();
848 InputHandlerManager* input_handler_manager =
849 render_thread ? render_thread->input_handler_manager() : NULL;
850 if (input_handler_manager) {
851 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
852 routing_id_, gesture_event, scroll_result);
853 }
854}
855
avid7d6b2e2016-03-04 19:41:17856void RenderWidget::OnDidHandleKeyEvent() {
857 if (owner_delegate_)
858 owner_delegate_->RenderWidgetDidHandleKeyEvent();
859}
fsamuel72464894f2015-12-15 06:59:31860
861void RenderWidget::OnDidOverscroll(const DidOverscrollParams& params) {
862 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
863}
864
dchengcedca5612016-04-09 01:40:15865void RenderWidget::OnInputEventAck(
866 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:31867 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
868}
869
dtapuska46616922016-03-17 22:52:01870void RenderWidget::NotifyInputEventHandled(
dtapuskab08721e62016-06-29 03:35:07871 blink::WebInputEvent::Type handled_type,
872 InputEventAckState ack_result) {
dtapuska0bd451a2016-02-18 17:08:10873 RenderThreadImpl* render_thread = RenderThreadImpl::current();
874 InputHandlerManager* input_handler_manager =
875 render_thread ? render_thread->input_handler_manager() : NULL;
876 if (input_handler_manager) {
dtapuskab08721e62016-06-29 03:35:07877 input_handler_manager->NotifyInputEventHandledOnMainThread(
878 routing_id_, handled_type, ack_result);
dtapuska0bd451a2016-02-18 17:08:10879 }
880}
881
fsamuele8326c742016-01-12 00:49:39882void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
883 // Nothing to do here. RenderWidget created the |input_handler| and will take
884 // ownership of it. We just verify here that we don't already have an input
885 // handler.
886 DCHECK(!input_handler_);
887}
888
fsamuel72464894f2015-12-15 06:59:31889void RenderWidget::UpdateTextInputState(ShowIme show_ime,
890 ChangeSource change_source) {
891 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
892 if (ime_event_guard_) {
893 // show_ime should still be effective even if it was set inside the IME
894 // event guard.
895 if (show_ime == ShowIme::IF_NEEDED) {
896 ime_event_guard_->set_show_ime(true);
897 }
898 return;
899 }
900
901 ui::TextInputType new_type = GetTextInputType();
902 if (IsDateTimeInput(new_type))
903 return; // Not considered as a text input field in WebKit/Chromium.
904
905 blink::WebTextInputInfo new_info;
906 if (webwidget_)
907 new_info = webwidget_->textInputInfo();
908 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
909
910 bool new_can_compose_inline = CanComposeInline();
911
912 // Only sends text input params if they are changed or if the ime should be
913 // shown.
914 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:39915 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
fsamuel72464894f2015-12-15 06:59:31916 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
917 text_input_info_ != new_info ||
918 can_compose_inline_ != new_can_compose_inline)
919#if defined(OS_ANDROID)
920 || text_field_is_dirty_
921#endif
922 ) {
ekaramad9053e57b2016-04-26 20:00:38923 TextInputState params;
fsamuel72464894f2015-12-15 06:59:31924 params.type = new_type;
925 params.mode = new_mode;
926 params.flags = new_info.flags;
927 params.value = new_info.value.utf8();
928 params.selection_start = new_info.selectionStart;
929 params.selection_end = new_info.selectionEnd;
930 params.composition_start = new_info.compositionStart;
931 params.composition_end = new_info.compositionEnd;
932 params.can_compose_inline = new_can_compose_inline;
933 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
934#if defined(USE_AURA)
935 params.is_non_ime_change = true;
936#endif
937#if defined(OS_ANDROID)
938 params.is_non_ime_change =
939 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
940 if (params.is_non_ime_change)
941 OnImeEventSentForAck(new_info);
942 text_field_is_dirty_ = false;
943#endif
944 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
945
946 text_input_info_ = new_info;
947 text_input_type_ = new_type;
948 text_input_mode_ = new_mode;
949 can_compose_inline_ = new_can_compose_inline;
950 text_input_flags_ = new_info.flags;
951 }
952}
953
954bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:17955 if (owner_delegate_)
956 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
957
fsamuel72464894f2015-12-15 06:59:31958 return false;
959}
960
961bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
lfge0c2792ec2016-05-11 18:52:08962 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
963 RenderWidgetWillHandleMouseEvent());
964
avid7d6b2e2016-03-04 19:41:17965 if (owner_delegate_)
966 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
967
fsamuel72464894f2015-12-15 06:59:31968 return false;
[email protected]fd847792013-10-24 17:12:35969}
970
initial.commit09911bf2008-07-26 23:55:29971///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:39972// RenderWidgetScreenMetricsDelegate
973
974void RenderWidget::Redraw() {
975 set_next_paint_is_resize_ack();
976 if (compositor_)
977 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
978}
979
bokanc63441c2016-04-27 15:49:12980void RenderWidget::ResizeWebWidget() {
981 webwidget_->resize(GetSizeForWebWidget());
982}
983
984gfx::Size RenderWidget::GetSizeForWebWidget() const {
985 if (IsUseZoomForDSFEnabled())
986 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
987
988 return size_;
989}
990
mfomitchev2600fd7c2016-02-17 20:53:39991void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:58992 bool orientation_changed =
993 screen_info_.orientationAngle != params.screen_info.orientationAngle ||
994 screen_info_.orientationType != params.screen_info.orientationType;
995
mfomitchev2600fd7c2016-02-17 20:53:39996 screen_info_ = params.screen_info;
997 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
998
999 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1000 // A resize ack shouldn't be requested if we have not ACK'd the previous
1001 // one.
1002 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1003 }
1004
1005 // Ignore this during shutdown.
1006 if (!webwidget_)
1007 return;
1008
1009 if (compositor_)
1010 compositor_->setViewportSize(params.physical_backing_size);
1011
mfomitchev2600fd7c2016-02-17 20:53:391012 visible_viewport_size_ = params.visible_viewport_size;
1013 resizer_rect_ = params.resizer_rect;
1014
1015 // NOTE: We may have entered fullscreen mode without changing our size.
1016 bool fullscreen_change =
1017 is_fullscreen_granted_ != params.is_fullscreen_granted;
1018 is_fullscreen_granted_ = params.is_fullscreen_granted;
1019 display_mode_ = params.display_mode;
1020
bokanc63441c2016-04-27 15:49:121021 size_ = params.new_size;
1022 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391023
bokanc63441c2016-04-27 15:49:121024 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221025
mfomitchev2600fd7c2016-02-17 20:53:391026 WebSize visual_viewport_size;
1027
1028 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181029 visual_viewport_size = gfx::ScaleToCeiledSize(
1030 params.visible_viewport_size,
1031 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391032 } else {
1033 visual_viewport_size = visible_viewport_size_;
1034 }
1035
1036 webwidget()->resizeVisualViewport(visual_viewport_size);
1037
bokanc63441c2016-04-27 15:49:121038 // When resizing, we want to wait to paint before ACK'ing the resize. This
1039 // ensures that we only resize as fast as we can paint. We only need to
1040 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391041 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1042 // In this case there is no paint/composite and therefore no
1043 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1044 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1045 DCHECK(!params.needs_resize_ack);
1046 }
1047
1048 // Send the Resize_ACK flag once we paint again if requested.
1049 if (params.needs_resize_ack)
1050 set_next_paint_is_resize_ack();
1051
1052 if (fullscreen_change)
1053 DidToggleFullscreen();
1054
engedy6cb63c92016-02-23 14:14:581055 if (orientation_changed)
1056 OnOrientationChange();
1057
mfomitchev2600fd7c2016-02-17 20:53:391058 // If a resize ack is requested and it isn't set-up, then no more resizes will
1059 // come in and in general things will go wrong.
1060 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1061}
1062
1063void RenderWidget::SetScreenMetricsEmulationParameters(
1064 bool enabled,
1065 const blink::WebDeviceEmulationParams& params) {
1066 // This is only supported in RenderView.
1067 NOTREACHED();
1068}
1069
1070void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1071 const gfx::Rect& window_screen_rect) {
1072 view_screen_rect_ = view_screen_rect;
1073 window_screen_rect_ = window_screen_rect;
1074}
1075
1076///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461077// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291078
[email protected]3a1c8a8032013-03-18 22:35:321079void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401080 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051081 if (compositor_)
oshima750cb4342015-10-31 00:59:011082 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051083}
1084
[email protected]e195e582013-03-08 01:32:591085void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221086 DCHECK(!host_closing_);
1087
fsamuel78f86e42016-01-20 04:10:231088 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1089 compositor_deps_);
oshima750cb4342015-10-31 00:59:011090 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331091 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391092 // For background pages and certain tests, we don't want to trigger
1093 // OutputSurface creation.
1094 if (compositor_never_visible_ || !RenderThreadImpl::current())
1095 compositor_->SetNeverVisible();
1096
pimanc4af3072015-10-02 03:45:591097 StartCompositor();
[email protected]e195e582013-03-08 01:32:591098}
1099
ennef3c58142014-12-09 21:44:381100void RenderWidget::WillCloseLayerTreeView() {
1101 if (host_closing_)
1102 return;
1103
1104 // Prevent new compositors or output surfaces from being created.
1105 host_closing_ = true;
1106
[email protected]aeeedad2014-08-22 18:16:221107 // Always send this notification to prevent new layer tree views from
1108 // being created, even if one hasn't been created yet.
1109 if (webwidget_)
1110 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221111}
1112
[email protected]180ef242013-11-07 06:50:461113blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281114 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061115}
1116
dglazkovf0e1d6d2015-10-10 02:13:481117void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1118 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1119 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1120 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1121 }
dglazkov79c426102015-08-31 21:22:431122
dglazkovf0e1d6d2015-10-10 02:13:481123 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1124 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431125}
1126
jdduke491a3f0c2015-06-15 23:30:261127void RenderWidget::ScheduleComposite() {
1128 if (compositor_ &&
1129 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1130 compositor_->setNeedsAnimate();
1131 }
1132}
1133
1134void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1135 if (compositor_) {
1136 // Regardless of whether threaded compositing is enabled, always
1137 // use this mechanism to force the compositor to redraw. However,
1138 // the invalidation code path below is still needed for the
1139 // non-threaded case.
1140 compositor_->SetNeedsForcedRedraw();
1141 }
1142 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151143}
1144
[email protected]586871b2014-07-22 17:05:111145// static
dchengcedca5612016-04-09 01:40:151146std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111147 IPC::Message* msg,
1148 MessageDeliveryPolicy policy,
1149 FrameSwapMessageQueue* frame_swap_message_queue,
1150 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111151 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111152 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151153 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1154 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111155 &first_message_for_frame);
1156 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151157 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111158 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061159 return promise;
[email protected]586871b2014-07-22 17:05:111160 }
dcheng4b6b5ff2014-10-16 00:42:061161 return nullptr;
[email protected]586871b2014-07-22 17:05:111162}
1163
1164void RenderWidget::QueueMessage(IPC::Message* msg,
1165 MessageDeliveryPolicy policy) {
1166 // RenderThreadImpl::current() is NULL in some tests.
1167 if (!compositor_ || !RenderThreadImpl::current()) {
1168 Send(msg);
1169 return;
1170 }
1171
dchengcedca5612016-04-09 01:40:151172 std::unique_ptr<cc::SwapPromise> swap_promise =
1173 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111174 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111175 compositor_->GetSourceFrameNumber());
1176
1177 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321178 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351179 // Request a commit. This might either A) request a commit ahead of time
1180 // or B) request a commit which is not needed because there are not
1181 // pending updates. If B) then the commit will be skipped and the swap
1182 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1183 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1184 // can_cancel_commit is not unset.
1185 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111186 }
1187}
1188
[email protected]4873c7d2009-07-16 06:36:281189void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301190 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521191 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181192 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291193 // Only send a SetCursor message if we need to make a change.
1194 if (!current_cursor_.IsEqual(cursor)) {
1195 current_cursor_ = cursor;
1196 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1197 }
1198}
1199
1200// We are supposed to get a single call to Show for a newly created RenderWidget
1201// that was created via RenderWidget::CreateWebView. So, we wait until this
1202// point to dispatch the ShowWidget message.
1203//
1204// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281205// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291206//
[email protected]4873c7d2009-07-16 06:36:281207void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291208 DCHECK(!did_show_) << "received extraneous Show call";
1209 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1210 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1211
[email protected]8de12d942010-11-17 20:42:441212 if (did_show_)
1213 return;
1214
1215 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561216 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441217 // that's okay. It'll be ignored if as_popup is false, or the browser
1218 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561219 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1220 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291221}
1222
[email protected]4873c7d2009-07-16 06:36:281223void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291224}
1225
[email protected]2533ce12009-05-09 00:02:241226void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381227 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241228 Send(new ViewHostMsg_Close(routing_id_));
1229}
1230
dgozmancf9039cd2015-04-06 12:01:311231void RenderWidget::NotifyOnClose() {
1232 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1233}
1234
[email protected]4873c7d2009-07-16 06:36:281235void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081236 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321237 if (is_swapped_out_) {
1238 // This widget is currently swapped out, and the active widget is in a
1239 // different process. Have the browser route the close request to the
1240 // active widget instead, so that the correct unload handlers are run.
1241 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1242 return;
1243 }
1244
initial.commit09911bf2008-07-26 23:55:291245 // If a page calls window.close() twice, we'll end up here twice, but that's
1246 // OK. It is safe to send multiple Close messages.
1247
[email protected]2533ce12009-05-09 00:02:241248 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1249 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1250 // could be closed before the JS finishes executing. So instead, post a
1251 // message back to the message loop, which won't run until the JS is
1252 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081253 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211254 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291255}
1256
[email protected]9017d7852013-11-21 17:47:351257void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151258 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351259 const SyntheticGestureCompletionCallback& callback) {
1260 DCHECK(!callback.is_null());
1261
1262 pending_synthetic_gesture_callbacks_.push(callback);
1263
1264 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321265 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351266
1267 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1268}
1269
initial.commit09911bf2008-07-26 23:55:291270void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031271 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381272 WillCloseLayerTreeView();
1273 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291274 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281275 webwidget_->close();
lfg4fa48da2016-05-09 18:25:131276 webwidget_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291277 }
1278}
1279
[email protected]4873c7d2009-07-16 06:36:281280WebRect RenderWidget::windowRect() {
1281 if (pending_window_rect_count_)
1282 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241283
[email protected]80ad8622012-11-07 16:33:031284 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291285}
1286
[email protected]180ef242013-11-07 06:50:461287void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301288 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541289 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301290}
1291
oshima33ec97cd2015-12-14 19:40:241292void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1293 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511294 if (popup_origin_scale_for_emulation_) {
1295 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561296 window_rect.x = popup_screen_origin_for_emulation_.x() +
1297 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1298 window_rect.y = popup_screen_origin_for_emulation_.y() +
1299 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511300 }
1301
[email protected]5b45ad42013-10-25 00:42:041302 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201303 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561304 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1305 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031306 } else {
bokanc007c3a2015-02-03 07:15:561307 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031308 }
initial.commit09911bf2008-07-26 23:55:291309 } else {
bokanc007c3a2015-02-03 07:15:561310 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291311 }
1312}
1313
[email protected]2533ce12009-05-09 00:02:241314void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1315 pending_window_rect_ = rect;
1316 pending_window_rect_count_++;
1317}
1318
[email protected]4873c7d2009-07-16 06:36:281319WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241320 if (pending_window_rect_count_) {
1321 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1322 // the RootWindowRect is probably going to return wrong results since the
1323 // browser may not have processed the Move yet. There isn't really anything
1324 // good to do in this case, and it shouldn't happen - since this size is
1325 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281326 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241327 }
1328
[email protected]80ad8622012-11-07 16:33:031329 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371330}
1331
[email protected]4873c7d2009-07-16 06:36:281332WebRect RenderWidget::windowResizerRect() {
1333 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191334}
1335
[email protected]fa7b1dc2010-06-23 17:53:041336void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261337 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041338 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071339 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041340 int selection_start, int selection_end) {
ekaramad2a46d632016-07-19 13:33:091341#if defined(ENABLE_PLUGINS)
1342 if (focused_pepper_plugin_) {
1343 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1344 text, underlines, selection_start, selection_end);
1345 return;
1346 }
1347#endif
1348 if (replacement_range.IsValid()) {
1349 webwidget_->applyReplacementRange(replacement_range.start(),
1350 replacement_range.length());
1351 }
1352
[email protected]0d1ebed12013-08-05 22:01:131353 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281354 return;
[email protected]66fca5bc2013-05-23 06:58:291355 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361356 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041357 text, WebVector<WebCompositionUnderline>(underlines),
1358 selection_start, selection_end)) {
1359 // If we failed to set the composition text, then we need to let the browser
1360 // process to cancel the input method's ongoing composition session, to make
1361 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221362 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261363 }
[email protected]88dbe32f2013-06-20 23:31:361364 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041365}
1366
[email protected]fcf75d42013-12-03 20:11:261367void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511368 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021369 bool keep_selection) {
ekaramad2a46d632016-07-19 13:33:091370#if defined(ENABLE_PLUGINS)
1371 if (focused_pepper_plugin_) {
1372 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition(
1373 text, replacement_range, keep_selection);
1374 return;
1375 }
1376#endif
1377 if (replacement_range.IsValid()) {
1378 webwidget_->applyReplacementRange(replacement_range.start(),
1379 replacement_range.length());
1380 }
1381
[email protected]0d1ebed12013-08-05 22:01:131382 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041383 return;
[email protected]66fca5bc2013-05-23 06:58:291384 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391385 input_handler_->set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021386 if (text.length())
1387 webwidget_->confirmComposition(text);
1388 else if (keep_selection)
1389 webwidget_->confirmComposition(WebWidget::KeepSelection);
1390 else
1391 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391392 input_handler_->set_handling_input_event(false);
[email protected]88dbe32f2013-06-20 23:31:361393 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291394}
1395
oshimad5279032015-12-16 18:22:331396void RenderWidget::OnDeviceScaleFactorChanged() {
1397 if (!compositor_)
1398 return;
oshimad5279032015-12-16 18:22:331399 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181400 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331401 else
1402 compositor_->setDeviceScaleFactor(device_scale_factor_);
1403}
1404
[email protected]0bc1f572013-04-17 01:46:311405void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121406 // During shutdown we can just ignore this message.
1407 if (!webwidget_)
1408 return;
1409
[email protected]0bc1f572013-04-17 01:46:311410 // Even if the browser provides an empty damage rect, it's still expecting to
1411 // receive a repaint ack so just damage the entire widget bounds.
1412 if (size_to_paint.IsEmpty()) {
1413 size_to_paint = size_;
1414 }
1415
[email protected]ec7dc112008-08-06 05:30:121416 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051417 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311418 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121419}
1420
[email protected]79fa22e2013-08-23 15:18:121421void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351422 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1423
1424 pending_synthetic_gesture_callbacks_.front().Run();
1425 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271426}
1427
[email protected]4873c7d2009-07-16 06:36:281428void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111429 if (!webwidget_)
1430 return;
[email protected]4873c7d2009-07-16 06:36:281431 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111432}
1433
[email protected]80ad8622012-11-07 16:33:031434void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1435 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511436 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391437 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1438 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511439 } else {
mfomitchev2600fd7c2016-02-17 20:53:391440 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511441 }
[email protected]80ad8622012-11-07 16:33:031442 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1443}
1444
lfgdb5c4ed2016-03-04 23:09:071445void RenderWidget::OnUpdateWindowScreenRect(
1446 const gfx::Rect& window_screen_rect) {
1447 if (screen_metrics_emulator_) {
1448 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
1449 } else {
1450 window_screen_rect_ = window_screen_rect;
1451 }
1452}
1453
fsamuel278664272016-07-13 04:06:591454void RenderWidget::OnSetSurfaceClientId(uint32_t surface_id_namespace) {
kenrbb4e2a3b2015-05-14 15:05:051455 if (compositor_)
fsamuel278664272016-07-13 04:06:591456 compositor_->SetSurfaceClientId(surface_id_namespace);
kenrbb4e2a3b2015-05-14 15:05:051457}
1458
dtrainor5ef644e2015-11-19 00:12:471459void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1460 if (compositor_)
1461 compositor_->OnHandleCompositorProto(proto);
1462}
1463
[email protected]adb362312014-06-28 06:04:241464void RenderWidget::showImeIfNeeded() {
1465 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131466}
1467
fsamuel72464894f2015-12-15 06:59:311468ui::TextInputType RenderWidget::GetTextInputType() {
ekaramad2a46d632016-07-19 13:33:091469#if defined(ENABLE_PLUGINS)
1470 if (focused_pepper_plugin_)
1471 return focused_pepper_plugin_->text_input_type();
1472#endif
fsamuel72464894f2015-12-15 06:59:311473 if (webwidget_)
1474 return WebKitToUiTextInputType(webwidget_->textInputType());
1475 return ui::TEXT_INPUT_TYPE_NONE;
1476}
1477
1478void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
fsamuel72464894f2015-12-15 06:59:311479 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1480 gfx::Range range = gfx::Range();
1481 if (should_update_range) {
1482 GetCompositionRange(&range);
1483 } else {
1484 range = composition_range_;
1485 }
1486 std::vector<gfx::Rect> character_bounds;
1487 GetCompositionCharacterBounds(&character_bounds);
1488
1489 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1490 return;
1491 composition_character_bounds_ = character_bounds;
1492 composition_range_ = range;
1493 Send(new InputHostMsg_ImeCompositionRangeChanged(
1494 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311495}
1496
oshimaf866dab2015-12-05 00:41:541497void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1498 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181499 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331500 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541501 // anchor element can be placed at half pixel.
1502 gfx::Rect window_rect =
1503 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1504 rect->x = window_rect.x();
1505 rect->y = window_rect.y();
1506 rect->width = window_rect.width();
1507 rect->height = window_rect.height();
1508 }
1509}
1510
oshimaa6985b62016-01-27 08:58:301511void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1512 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181513 rect->x *= GetOriginalDeviceScaleFactor();
1514 rect->y *= GetOriginalDeviceScaleFactor();
1515 rect->width *= GetOriginalDeviceScaleFactor();
1516 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301517 }
1518}
1519
[email protected]adb362312014-06-28 06:04:241520void RenderWidget::OnShowImeIfNeeded() {
1521#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311522 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241523#endif
rouslanf7ebd8832015-01-22 01:54:141524
1525// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1526// virtual keyboard.
1527#if !defined(OS_ANDROID)
1528 FocusChangeComplete();
1529#endif
[email protected]adb362312014-06-28 06:04:241530}
1531
1532#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371533void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1534 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131535}
1536
1537void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371538 DCHECK_GE(text_input_info_history_.size(), 1u);
1539 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511540}
changwan8c342742016-02-26 00:53:391541
1542void RenderWidget::OnRequestTextInputStateUpdate() {
1543 DCHECK(!ime_event_guard_);
1544 UpdateSelectionBounds();
1545 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1546}
[email protected]105dffb42013-02-20 03:46:211547#endif
1548
[email protected]0d1ebed12013-08-05 22:01:131549bool RenderWidget::ShouldHandleImeEvent() {
1550#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371551 if (!webwidget_)
1552 return false;
changwan8c342742016-02-26 00:53:391553 if (IsUsingImeThread())
1554 return true;
changwan3a841162015-08-11 02:53:371555
1556 // We cannot handle IME events if there is any chance that the event we are
1557 // receiving here from the browser is based on the state that is different
1558 // from our current one as indicated by |text_input_info_|.
1559 // The states the browser might be in are:
1560 // text_input_info_history_[0] - current state ack'd by browser
1561 // text_input_info_history_[1...N] - pending state changes
1562 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1563 if (text_input_info_history_[i] != text_input_info_)
1564 return false;
1565 }
1566 return true;
[email protected]0d1ebed12013-08-05 22:01:131567#else
1568 return !!webwidget_;
1569#endif
1570}
1571
[email protected]468ac582012-11-20 00:53:191572void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1573 if (device_scale_factor_ == device_scale_factor)
1574 return;
1575
1576 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331577
1578 OnDeviceScaleFactorChanged();
1579
jdduke491a3f0c2015-06-15 23:30:261580 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191581}
1582
[email protected]28ed6b32014-06-08 02:16:271583bool RenderWidget::SetDeviceColorProfile(
1584 const std::vector<char>& color_profile) {
1585 if (device_color_profile_ == color_profile)
1586 return false;
1587
1588 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271589
avi40b5be7a2016-03-03 21:13:441590 if (owner_delegate_)
1591 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1592
1593 return true;
noeldb4df152014-09-16 17:45:201594}
1595
[email protected]fcdc5642014-05-09 14:32:241596void RenderWidget::OnOrientationChange() {
1597}
1598
avib9dbd972016-03-08 18:19:321599void RenderWidget::DidFlushPaint() {
1600 if (owner_delegate_)
1601 owner_delegate_->RenderWidgetDidFlushPaint();
1602}
1603
[email protected]bee16aab2009-08-26 15:55:031604void RenderWidget::SetHidden(bool hidden) {
1605 if (is_hidden_ == hidden)
1606 return;
1607
jdduke8fac9d102014-12-20 02:40:131608 // The status has changed. Tell the RenderThread about it and ensure
1609 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031610 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391611 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131612
[email protected]bee16aab2009-08-26 15:55:031613 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001614 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031615 else
[email protected]b2db9272014-01-10 17:42:001616 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111617
1618 if (render_widget_scheduling_state_)
1619 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031620}
1621
[email protected]2b624c562011-10-27 22:58:261622void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261623 if (!webwidget_)
1624 return;
1625
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121626 if (is_fullscreen_granted_) {
foolip73101372016-07-13 08:19:221627 webwidget_->didEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261628 } else {
foolip73101372016-07-13 08:19:221629 webwidget_->didExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261630 }
[email protected]2b624c562011-10-27 22:58:261631}
1632
[email protected]674741932009-02-04 23:44:461633bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051634 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461635}
1636
[email protected]674741932009-02-04 23:44:461637void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051638 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461639}
1640
[email protected]674741932009-02-04 23:44:461641void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051642 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461643}
1644
changwan8c342742016-02-26 00:53:391645bool RenderWidget::IsUsingImeThread() {
1646#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121647 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391648#else
1649 return false;
1650#endif
1651}
1652
changwanf2a707b2015-10-30 08:22:161653void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1654 if (!ime_event_guard_)
1655 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291656}
1657
changwanf2a707b2015-10-30 08:22:161658void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1659 if (ime_event_guard_ != guard) {
1660#if defined(OS_ANDROID)
1661 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1662 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391663 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161664 // Therefore, we want to mark this text state update as 'from IME' only
1665 // when all the nested events are all originating from IME.
1666 ime_event_guard_->set_from_ime(
1667 ime_event_guard_->from_ime() && guard->from_ime());
1668#endif
1669 return;
1670 }
1671 ime_event_guard_ = nullptr;
1672
[email protected]66fca5bc2013-05-23 06:58:291673 // While handling an ime event, text input state and selection bounds updates
1674 // are ignored. These must explicitly be updated once finished handling the
1675 // ime event.
1676 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471677#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161678 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311679 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1680 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471681#endif
[email protected]66fca5bc2013-05-23 06:58:291682}
1683
[email protected]7c8873e2013-02-05 08:03:011684void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
ekaramad2a46d632016-07-19 13:33:091685#if defined(ENABLE_PLUGINS)
1686 if (focused_pepper_plugin_) {
1687 // TODO(kinaba) http://crbug.com/101101
1688 // Current Pepper IME API does not handle selection bounds. So we simply
1689 // use the caret position as an empty range for now. It will be updated
1690 // after Pepper API equips features related to surrounding text retrieval.
1691 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1692 convertViewportToWindow(&caret);
1693 *focus = caret;
1694 *anchor = caret;
1695 return;
1696 }
1697#endif
[email protected]7c8873e2013-02-05 08:03:011698 WebRect focus_webrect;
1699 WebRect anchor_webrect;
1700 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241701 convertViewportToWindow(&focus_webrect);
1702 convertViewportToWindow(&anchor_webrect);
1703 *focus = focus_webrect;
1704 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321705}
1706
[email protected]e99ef6f2011-10-16 01:13:001707void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081708 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001709 if (!webwidget_)
1710 return;
changwanf2a707b2015-10-30 08:22:161711 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291712 return;
[email protected]e99ef6f2011-10-16 01:13:001713
mohsenb0eeba72015-08-09 06:20:081714#if defined(USE_AURA)
1715 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1716 // Aura beucause composited selection updates are not working for webview tags
1717 // which regresses IME inside webview. Remove this when composited selection
1718 // updates are fixed for webviews. See, http://crbug.com/510568.
1719 bool send_ipc = true;
1720#else
jddukeacf809e2014-09-23 20:38:381721 // With composited selection updates, the selection bounds will be reported
1722 // directly by the compositor, in which case explicit IPC selection
1723 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081724 bool send_ipc =
1725 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1726#endif
1727 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381728 ViewHostMsg_SelectionBounds_Params params;
1729 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1730 if (selection_anchor_rect_ != params.anchor_rect ||
1731 selection_focus_rect_ != params.focus_rect) {
1732 selection_anchor_rect_ = params.anchor_rect;
1733 selection_focus_rect_ = params.focus_rect;
1734 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1735 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1736 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1737 }
[email protected]58b48a0d2012-06-13 07:01:351738 }
jddukeacf809e2014-09-23 20:38:381739
[email protected]88dbe32f2013-06-20 23:31:361740 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001741}
1742
avi40b5be7a2016-03-03 21:13:441743void RenderWidget::SetDeviceColorProfileForTesting(
1744 const std::vector<char>& color_profile) {
1745 SetDeviceColorProfile(color_profile);
1746}
1747
1748void RenderWidget::ResetDeviceColorProfileForTesting() {
1749 std::vector<char> color_profile;
1750 color_profile.push_back('0');
1751 SetDeviceColorProfile(color_profile);
1752}
1753
lfgb00fcad2016-07-14 14:16:331754void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
1755 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
1756 convertViewportToWindow(&new_size_in_window);
1757 if (size_.width() != new_size_in_window.width ||
1758 size_.height() != new_size_in_window.height) {
1759 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
1760
1761 if (resizing_mode_selector_->is_synchronous_mode()) {
1762 gfx::Rect new_pos(rootWindowRect().x, rootWindowRect().y, size_.width(),
1763 size_.height());
1764 view_screen_rect_ = new_pos;
1765 window_screen_rect_ = new_pos;
1766 }
1767
1768 AutoResizeCompositor();
1769
1770 if (!resizing_mode_selector_->is_synchronous_mode())
1771 need_update_rect_for_auto_resize_ = true;
1772 }
1773}
1774
[email protected]180ef242013-11-07 06:50:461775// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
danakj365175c2016-02-06 00:37:371776STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1777STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1778STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1779 ui::TEXT_INPUT_TYPE_PASSWORD);
1780STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1781STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1782STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1783STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1784 ui::TEXT_INPUT_TYPE_TELEPHONE);
1785STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1786STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1787STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1788 ui::TEXT_INPUT_TYPE_DATE_TIME);
1789STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1790 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1791STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1792STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1793STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1794STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1795 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1796STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1797 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1798STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1799 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451800
[email protected]5b739cb2012-08-21 20:35:211801ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461802 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211803 // Check the type is in the range representable by ui::TextInputType.
1804 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461805 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211806 return static_cast<ui::TextInputType>(type);
1807}
1808
[email protected]58b48a0d2012-06-13 07:01:351809void RenderWidget::GetCompositionCharacterBounds(
1810 std::vector<gfx::Rect>* bounds) {
1811 DCHECK(bounds);
1812 bounds->clear();
ekaramad2a46d632016-07-19 13:33:091813
1814#if defined(ENABLE_PLUGINS)
1815 if (focused_pepper_plugin_)
1816 return;
1817#endif
1818
1819 if (!webwidget_)
1820 return;
1821 blink::WebVector<blink::WebRect> bounds_from_blink;
1822 if (!webwidget_->getCompositionCharacterBounds(bounds_from_blink))
1823 return;
1824
1825 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
1826 convertViewportToWindow(&bounds_from_blink[i]);
1827 bounds->push_back(bounds_from_blink[i]);
1828 }
[email protected]58b48a0d2012-06-13 07:01:351829}
1830
[email protected]db4fc1e2013-09-06 20:01:511831void RenderWidget::GetCompositionRange(gfx::Range* range) {
ekaramad2a46d632016-07-19 13:33:091832#if defined(ENABLE_PLUGINS)
1833 if (focused_pepper_plugin_)
1834 return;
1835#endif
[email protected]88dbe32f2013-06-20 23:31:361836 size_t location, length;
1837 if (webwidget_->compositionRange(&location, &length)) {
1838 range->set_start(location);
1839 range->set_end(location + length);
1840 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1841 range->set_start(location);
1842 range->set_end(location + length);
1843 } else {
[email protected]db4fc1e2013-09-06 20:01:511844 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:361845 }
1846}
1847
[email protected]501ea13d2013-07-09 17:03:291848bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511849 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291850 const std::vector<gfx::Rect>& bounds) {
1851 if (composition_range_ != range)
1852 return true;
1853 if (bounds.size() != composition_character_bounds_.size())
1854 return true;
1855 for (size_t i = 0; i < bounds.size(); ++i) {
1856 if (bounds[i] != composition_character_bounds_[i])
1857 return true;
1858 }
1859 return false;
1860}
[email protected]501ea13d2013-07-09 17:03:291861
[email protected]ad26ef42011-06-17 07:59:451862bool RenderWidget::CanComposeInline() {
ekaramad2a46d632016-07-19 13:33:091863#if defined(ENABLE_PLUGINS)
1864 if (focused_pepper_plugin_)
1865 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
1866#endif
[email protected]ad26ef42011-06-17 07:59:451867 return true;
[email protected]56ea1a62011-05-30 07:05:571868}
1869
[email protected]4873c7d2009-07-16 06:36:281870WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041871 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281872}
1873
[email protected]fa7b1dc2010-06-23 17:53:041874void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021875 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041876 // If the last text input type is not None, then we should finish any
1877 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451878 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041879 // If a composition text exists, then we need to let the browser process
1880 // to cancel the input method's ongoing composition session.
1881 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:221882 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041883 }
[email protected]d4cff272011-05-02 15:46:011884
[email protected]88dbe32f2013-06-20 23:31:361885 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041886}
1887
donnda070f3c2015-01-16 19:54:111888#if defined(OS_ANDROID)
1889void RenderWidget::showUnhandledTapUIIfNeeded(
1890 const WebPoint& tapped_position,
1891 const WebNode& tapped_node,
1892 bool page_changed) {
fsamuele8326c742016-01-12 00:49:391893 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:111894 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371895 !tapped_node.isContentEditable() &&
1896 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111897 if (should_trigger) {
1898 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1899 tapped_position.x, tapped_position.y));
1900 }
1901}
1902#endif
1903
[email protected]c68c3e4e2013-01-24 00:36:561904void RenderWidget::didHandleGestureEvent(
1905 const WebGestureEvent& event,
1906 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021907#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561908 if (event_cancelled)
1909 return;
[email protected]07c70d22014-08-21 08:33:461910 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:311911 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461912 } else if (event.type == WebInputEvent::GestureLongPress) {
1913 DCHECK(webwidget_);
1914 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:311915 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461916 else
fsamuel72464894f2015-12-15 06:59:311917 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:561918 }
1919#endif
1920}
1921
sataya.m582c9ce2015-06-09 08:03:421922void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:311923 const blink::WebFloatSize& overscrollDelta,
1924 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:421925 const blink::WebFloatPoint& position,
1926 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:481927#if defined(OS_MACOSX)
1928 // On OSX the user can disable the elastic overscroll effect. If that's the
1929 // case, don't forward the overscroll notification.
1930 DCHECK(compositor_deps());
1931 if (!compositor_deps()->IsElasticOverscrollEnabled())
1932 return;
1933#endif
bokane53a10f2016-04-13 23:48:311934 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:391935 position, velocity);
sataya.m582c9ce2015-06-09 08:03:421936}
1937
[email protected]7912e822014-04-16 02:37:031938void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:391939 if (!is_hidden())
1940 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:031941}
1942
[email protected]24ed0432013-04-24 07:50:311943RenderWidgetCompositor* RenderWidget::compositor() const {
1944 return compositor_.get();
1945}
1946
fsamuel72464894f2015-12-15 06:59:311947void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:391948 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:371949}
[email protected]c3d45532011-10-07 19:20:401950
fsamuel72464894f2015-12-15 06:59:311951bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:391952 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:241953}
1954
fsamuel72464894f2015-12-15 06:59:311955void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:391956 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:311957}
1958
[email protected]ce6689f2013-03-29 12:52:551959void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:111960 if (render_widget_scheduling_state_)
1961 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:551962 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
1963}
1964
danakj365175c2016-02-06 00:37:371965// Check blink::WebTouchAction and content::TouchAction is kept in sync.
1966STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
1967STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
1968STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
1969STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
1970STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
1971STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
1972STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
1973STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
1974STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
1975STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
1976 TOUCH_ACTION_MANIPULATION);
1977STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
1978 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
1979STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
mostynbe29b6882015-01-13 09:59:171980
[email protected]5d0bbdfa92013-12-10 00:35:511981void RenderWidget::setTouchAction(
1982 blink::WebTouchAction web_touch_action) {
1983
1984 // Ignore setTouchAction calls that result from synthetic touch events (eg.
1985 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:391986 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:511987 return;
1988
[email protected]a18f67a2013-12-20 19:44:361989 content::TouchAction content_touch_action =
1990 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:511991 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
1992}
1993
[email protected]90f24152014-04-09 12:41:361994void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
1995#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:391996 if (!IsUsingImeThread())
1997 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:361998#endif
1999}
2000
[email protected]e3244ed2014-06-20 20:04:272001void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2002 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162003}
2004
[email protected]e3244ed2014-06-20 20:04:272005void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2006 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162007}
2008
[email protected]de3c5d82014-05-28 22:12:592009void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2010 render_frames_.AddObserver(frame);
2011}
2012
2013void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2014 render_frames_.RemoveObserver(frame);
2015}
2016
[email protected]a017938b2014-05-27 21:17:172017#if defined(VIDEO_HOLE)
2018void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2019 video_hole_frames_.AddObserver(frame);
2020}
2021
2022void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2023 video_hole_frames_.RemoveObserver(frame);
2024}
2025#endif // defined(VIDEO_HOLE)
2026
lfg43e08e62016-02-03 18:51:372027void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2028 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2029 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2030}
2031
oshima50872a72016-03-04 13:26:182032float RenderWidget::GetOriginalDeviceScaleFactor() const {
2033 return
2034 screen_metrics_emulator_ ?
2035 screen_metrics_emulator_->original_screen_info().deviceScaleFactor :
2036 device_scale_factor_;
2037}
2038
lfgbee1e0a2016-06-08 21:24:212039bool RenderWidget::requestPointerLock() {
2040 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2041}
2042
2043void RenderWidget::requestPointerUnlock() {
2044 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2045}
2046
2047bool RenderWidget::isPointerLocked() {
2048 return mouse_lock_dispatcher_->IsMouseLockedTo(
2049 webwidget_mouse_lock_target_.get());
2050}
2051
[email protected]e9ff79c2012-10-19 21:31:262052} // namespace content