blob: daaf9e43083b35360b2650e0b5d690fb09e26ee9 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
dchengcedca5612016-04-09 01:40:157#include <memory>
dcheng07945f632015-12-26 07:59:328#include <utility>
9
[email protected]c27dd4f2014-05-22 18:05:1910#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2111#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0012#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1213#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/logging.h"
avi1023d012015-12-25 02:39:1415#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1516#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4017#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3018#include "base/message_loop/message_loop.h"
asvitkine8d51e9d2016-09-02 23:55:4319#include "base/metrics/histogram_macros.h"
[email protected]aa4117f2011-12-09 22:19:2120#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0021#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2722#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0123#include "base/trace_event/trace_event.h"
24#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "build/build_config.h"
danakj1120f4c2016-09-15 02:05:3226#include "cc/output/compositor_frame_sink.h"
jbroman6ccbc7d472016-07-27 04:45:4127#include "cc/output/copy_output_request.h"
fsamuel78f86e42016-01-20 04:10:2328#include "cc/scheduler/begin_frame_source.h"
oshima750cb4342015-10-31 00:59:0129#include "content/common/content_switches_internal.h"
[email protected]9017d7852013-11-21 17:47:3530#include "content/common/input/synthetic_gesture_packet.h"
[email protected]c084330e02013-04-27 01:08:1531#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1532#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3833#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5034#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1235#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2936#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4237#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4038#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3939#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
[email protected]b2e4c70132013-10-03 02:07:5140#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1141#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1142#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2843#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2944#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1345#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3246#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1647#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2748#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0549#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4450#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5551#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4452#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0953#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0454#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1855#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4856#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1857#include "third_party/WebKit/public/platform/WebCursorInfo.h"
donnda070f3c2015-01-16 19:54:1158#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3059#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]aaf68892013-07-18 00:11:3060#include "third_party/WebKit/public/platform/WebSize.h"
61#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5162#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
63#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
[email protected]19193682014-04-03 15:01:4364#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5965#include "third_party/WebKit/public/web/WebFrameWidget.h"
66#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1167#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3168#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3169#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
70#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3871#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5972#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0873#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4174#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1375#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5076#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0977#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3278#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4879#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2780#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4181#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4882
[email protected]eeb93112013-05-01 19:41:1083#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1584#include <android/keycodes.h>
[email protected]eeb93112013-05-01 19:41:1085#endif
86
[email protected]661eb9d2009-02-03 02:11:4887#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4988#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5289#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4190#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4891#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4492
sadrul943e3b32016-08-04 18:22:5993#if defined(USE_AURA)
penghuang28a5fa22015-12-02 17:58:1994#include "content/public/common/mojo_shell_connection.h"
fsamuel2545ecc2015-12-05 00:44:4695#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:1996#endif
97
[email protected]180ef242013-11-07 06:50:4698using blink::WebCompositionUnderline;
99using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43100using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46101using blink::WebGestureEvent;
102using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49103using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46104using blink::WebKeyboardEvent;
105using blink::WebMouseEvent;
106using blink::WebMouseWheelEvent;
107using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11108using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46109using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11110using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46111using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48112using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46113using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46114using blink::WebSize;
115using blink::WebTextDirection;
116using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25117using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46118using blink::WebVector;
119using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26120
danakj365175c2016-02-06 00:37:37121#define STATIC_ASSERT_ENUM(a, b) \
122 static_assert(static_cast<int>(a) == static_cast<int>(b), \
123 "mismatching enums: " #a)
124
[email protected]6a4d7f62013-01-07 21:32:13125namespace {
[email protected]b256eca2013-07-11 10:57:40126
127typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
128
lfgbee1e0a2016-06-08 21:24:21129class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
130 public:
131 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
132 : webwidget_(webwidget) {}
133
134 void OnLockMouseACK(bool succeeded) override {
135 if (succeeded)
136 webwidget_->didAcquirePointerLock();
137 else
138 webwidget_->didNotAcquirePointerLock();
139 }
140
141 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
142
143 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
144 // The WebWidget handles mouse lock in Blink's handleInputEvent().
145 return false;
146 }
147
148 private:
149 blink::WebWidget* webwidget_;
150};
151
[email protected]b256eca2013-07-11 10:57:40152class TextInputModeMapSingleton {
153 public:
154 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22155 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40156 }
[email protected]dd705d4d2013-11-27 08:14:41157 TextInputModeMapSingleton() {
158 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
159 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
160 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
161 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
162 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
163 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
164 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
165 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
166 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
167 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
168 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40169 }
[email protected]dd705d4d2013-11-27 08:14:41170 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40171 private:
[email protected]dd705d4d2013-11-27 08:14:41172 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40173
olli.raula36aa8be2015-09-10 11:14:22174 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40175
176 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
177};
178
[email protected]dd705d4d2013-11-27 08:14:41179ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40180 static TextInputModeMapSingleton* singleton =
181 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41182 TextInputModeMap::const_iterator it =
183 singleton->map().find(input_mode.utf8());
184 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40185 return ui::TEXT_INPUT_MODE_DEFAULT;
186 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13187}
[email protected]b256eca2013-07-11 10:57:40188
fsamuele8326c742016-01-12 00:49:39189content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
190 content::RenderWidget* widget) {
sadrul943e3b32016-08-04 18:22:59191#if defined(USE_AURA)
penghuang639a1042016-01-14 21:25:29192 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
ben6c85c4492016-06-16 20:40:51193 if (content::MojoShellConnection::GetForProcess() &&
penghuang639a1042016-01-14 21:25:29194 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39195 return content::RenderWidgetMusConnection::GetOrCreate(
196 widget->routing_id());
197 }
198#endif
199 // If we don't have a connection to the Mojo shell, then we want to route IPCs
200 // back to the browser process rather than Mus so we use the |widget| as the
201 // RenderWidgetInputHandlerDelegate.
202 return widget;
203}
204
lfg1568d112016-08-30 16:06:29205content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
206 nullptr;
207
208content::RenderWidget::RenderWidgetInitializedCallback
209 g_render_widget_initialized = nullptr;
210
[email protected]b256eca2013-07-11 10:57:40211} // namespace
212
[email protected]e9ff79c2012-10-19 21:31:26213namespace content {
[email protected]62cb33cae2009-03-27 23:30:22214
[email protected]b2e4c70132013-10-03 02:07:51215// RenderWidget ---------------------------------------------------------------
216
dcheng35d31c112015-07-22 00:17:36217RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
218 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27219 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04220 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03221 bool hidden,
222 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29223 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36224 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21225 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44226 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29227 opener_id_(MSG_ROUTING_NONE),
initial.commit09911bf2008-07-26 23:55:29228 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51229 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09230 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29231 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04232 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39233 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12234 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12235 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16236 ime_event_guard_(nullptr),
changwan46620072016-09-21 03:05:41237 ime_in_batch_edit_(false),
[email protected]661eb9d2009-02-03 02:11:48238 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22239 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44240 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20241 for_oopif_(false),
[email protected]b256eca2013-07-11 10:57:40242 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20243 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53244 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18245 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12246 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48247 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04248 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27249 device_scale_factor_(screen_info_.device_scale_factor),
[email protected]0d1ebed12013-08-05 22:01:13250#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36251 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13252#endif
nonafa291792016-08-10 02:36:18253 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51254 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11255 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42256 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08257 has_host_context_menu_location_(false),
ekaramad2a46d632016-07-19 13:33:09258 has_focus_(false),
259 focused_pepper_plugin_(nullptr) {
[email protected]8b3f0eb2012-05-03 19:15:05260 if (!swapped_out)
261 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27262 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53263 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37264#if defined(OS_ANDROID)
265 text_input_info_history_.push_back(blink::WebTextInputInfo());
266#endif
alexclarke7fa93942015-10-21 15:37:11267
268 // In tests there may not be a RenderThreadImpl.
269 if (RenderThreadImpl::current()) {
270 render_widget_scheduling_state_ = RenderThreadImpl::current()
271 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32272 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11273 render_widget_scheduling_state_->SetHidden(is_hidden_);
274 }
initial.commit09911bf2008-07-26 23:55:29275}
276
277RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21278 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16279
[email protected]992db4c2011-05-12 15:37:15280 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02281 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15282 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29283}
284
[email protected]484955942010-08-19 16:13:18285// static
lfg1568d112016-08-30 16:06:29286void RenderWidget::InstallCreateHook(
287 CreateRenderWidgetFunction create_render_widget,
288 RenderWidgetInitializedCallback render_widget_initialized) {
289 CHECK(!g_create_render_widget && !g_render_widget_initialized);
290 g_create_render_widget = create_render_widget;
291 g_render_widget_initialized = render_widget_initialized;
292}
293
294// static
avi1023d012015-12-25 02:39:14295RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53296 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46297 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27298 const ScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29299 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36300 scoped_refptr<RenderWidget> widget(new RenderWidget(
301 compositor_deps, popup_type, screen_info, false, false, false));
302 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46303 return widget.get();
[email protected]a635f942012-12-07 10:34:29304 }
305 return NULL;
initial.commit09911bf2008-07-26 23:55:29306}
307
[email protected]484955942010-08-19 16:13:18308// static
kenrba7199832015-01-22 23:44:59309RenderWidget* RenderWidget::CreateForFrame(
310 int routing_id,
kenrba7199832015-01-22 23:44:59311 bool hidden,
ccameron2f451532016-09-07 21:49:27312 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59313 CompositorDependencies* compositor_deps,
314 blink::WebLocalFrame* frame) {
315 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55316 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
317 // same routing ID for both the view routing ID and the main frame widget
318 // routing ID. https://crbug.com/545684
319 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
320 if (view) {
avi8a45c1092016-03-01 16:12:34321 view->AttachWebFrameWidget(
322 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
323 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55324 }
dcheng35d31c112015-07-22 00:17:36325 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29326 g_create_render_widget
327 ? g_create_render_widget(compositor_deps, blink::WebPopupTypeNone,
328 screen_info, false, hidden, false)
329 : new RenderWidget(compositor_deps, blink::WebPopupTypeNone,
330 screen_info, false, hidden, false));
fsamuele8326c742016-01-12 00:49:39331 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20332 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59333 // DoInit increments the reference count on |widget|, keeping it alive after
334 // this function returns.
dcheng35d31c112015-07-22 00:17:36335 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59336 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
337 nullptr)) {
lfg1568d112016-08-30 16:06:29338 if (g_render_widget_initialized)
339 g_render_widget_initialized(widget.get());
kenrba7199832015-01-22 23:44:59340 return widget.get();
341 }
342 return nullptr;
343}
344
345// static
lfgcaab5142016-02-26 19:06:52346blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08347 RenderWidget* render_widget,
348 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55349 if (!frame->parent()) {
350 // TODO(dcheng): The main frame widget currently has a special case.
351 // Eliminate this once WebView is no longer a WebWidget.
352 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
353 }
dchengda9b4bb2015-07-20 20:58:08354 return blink::WebFrameWidget::create(render_widget, frame);
355}
356
357// static
kenrba7199832015-01-22 23:44:59358blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18359 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46360 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18361 break;
[email protected]180ef242013-11-07 06:50:46362 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44363 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18364 default:
365 NOTREACHED();
366 }
367 return NULL;
368}
369
dchengda9b4bb2015-07-20 20:58:08370void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32371 OnClose();
kenrba7199832015-01-22 23:44:59372}
373
fsamuele8326c742016-01-12 00:49:39374void RenderWidget::SetRoutingID(int32_t routing_id) {
375 routing_id_ = routing_id;
376 input_handler_.reset(new RenderWidgetInputHandler(
377 GetRenderWidgetInputHandlerDelegate(this), this));
378}
379
avi1023d012015-12-25 02:39:14380bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39381 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05382 opener_id, RenderWidget::CreateWebWidget(this),
383 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39384 if (success) {
385 SetRoutingID(routing_id_);
386 return true;
387 }
388 return false;
[email protected]484955942010-08-19 16:13:18389}
390
avi1023d012015-12-25 02:39:14391bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06392 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18393 IPC::SyncMessage* create_widget_message) {
lfg8ff33912016-09-13 20:59:21394 DCHECK(!webwidget_internal_);
initial.commit09911bf2008-07-26 23:55:29395
396 if (opener_id != MSG_ROUTING_NONE)
397 opener_id_ = opener_id;
398
lfg8ff33912016-09-13 20:59:21399 webwidget_internal_ = web_widget;
400 webwidget_mouse_lock_target_.reset(
401 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21402 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29403
kenrba7199832015-01-22 23:44:59404 bool result = true;
405 if (create_widget_message)
406 result = RenderThread::Get()->Send(create_widget_message);
407
initial.commit09911bf2008-07-26 23:55:29408 if (result) {
[email protected]380244092011-10-07 17:26:27409 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29410 // Take a reference on behalf of the RenderThread. This will be balanced
411 // when we receive ViewMsg_Close.
412 AddRef();
[email protected]b2db9272014-01-10 17:42:00413 if (RenderThreadImpl::current()) {
414 RenderThreadImpl::current()->WidgetCreated();
415 if (is_hidden_)
416 RenderThreadImpl::current()->WidgetHidden();
417 }
fsamuele8326c742016-01-12 00:49:39418
[email protected]a635f942012-12-07 10:34:29419 return true;
initial.commit09911bf2008-07-26 23:55:29420 } else {
[email protected]a635f942012-12-07 10:34:29421 // The above Send can fail when the tab is closing.
422 return false;
initial.commit09911bf2008-07-26 23:55:29423 }
424}
425
[email protected]992db4c2011-05-12 15:37:15426void RenderWidget::SetSwappedOut(bool is_swapped_out) {
427 // We should only toggle between states.
428 DCHECK(is_swapped_out_ != is_swapped_out);
429 is_swapped_out_ = is_swapped_out;
430
431 // If we are swapping out, we will call ReleaseProcess, allowing the process
432 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52433 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15434 // If we are swapping in, we call AddRefProcess to prevent the process from
435 // exiting.
[email protected]949b6592014-08-20 13:17:52436 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15437 RenderProcess::current()->AddRefProcess();
438}
439
[email protected]949b6592014-08-20 13:17:52440void RenderWidget::WasSwappedOut() {
441 // If we have been swapped out and no one else is using this process,
442 // it's safe to exit now.
443 CHECK(is_swapped_out_);
444 RenderProcess::current()->ReleaseProcess();
445}
446
[email protected]b2e4c70132013-10-03 02:07:51447void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39448 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51449 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43450 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49451 popup_screen_origin_for_emulation_ = gfx::Point(
452 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
453 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56454 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27455 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51456}
457
[email protected]2d6836f42014-07-02 17:25:31458gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
459 if (screen_metrics_emulator_)
460 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
461 return anchor;
462}
463
haibinluc643d33c2016-06-03 02:22:34464#if defined(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51465void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39466 ExternalPopupMenu* popup,
467 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49468 popup->SetOriginScaleAndOffsetForEmulation(
469 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51470}
[email protected]53907862014-03-25 15:42:40471#endif
[email protected]b2e4c70132013-10-03 02:07:51472
473void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
474 if (screen_metrics_emulator_)
475 screen_metrics_emulator_->OnShowContextMenu(params);
476}
477
[email protected]a95986a82010-12-24 06:19:28478bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
lfgbee1e0a2016-06-08 21:24:21479 if (mouse_lock_dispatcher_ &&
480 mouse_lock_dispatcher_->OnMessageReceived(message))
481 return true;
482
[email protected]a95986a82010-12-24 06:19:28483 bool handled = true;
484 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15485 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22486 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
487 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22488 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29489 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
490 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
491 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15492 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46493 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
494 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15495 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35496 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
497 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28498 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28499 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20500 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
501 OnEnableDeviceEmulation)
502 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
503 OnDisableDeviceEmulation)
[email protected]b5913d72012-02-07 22:26:54504 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28505 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41506 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25507 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28508 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
509 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03510 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
fsamuel278664272016-07-13 04:06:59511 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceClientId, OnSetSurfaceClientId)
lfg43e08e62016-02-03 18:51:37512 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
513 OnWaitNextFrameForTests)
nonafa291792016-08-10 02:36:18514 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
515 OnRequestCompositionUpdate)
[email protected]105dffb42013-02-20 03:46:21516#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37517 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39518 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
519 OnRequestTextInputStateUpdate)
changwan46620072016-09-21 03:05:41520 IPC_MESSAGE_HANDLER(InputMsg_ImeBatchEdit,
521 OnImeBatchEdit)
[email protected]2384b6c2013-02-28 23:58:51522 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21523#endif
dtrainor5ef644e2015-11-19 00:12:47524 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28525 IPC_MESSAGE_UNHANDLED(handled = false)
526 IPC_END_MESSAGE_MAP()
527 return handled;
528}
initial.commit09911bf2008-07-26 23:55:29529
530bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15531 // Don't send any messages after the browser has told us to close, and filter
532 // most outgoing messages while swapped out.
533 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26534 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11535 closing_) {
initial.commit09911bf2008-07-26 23:55:29536 delete message;
537 return false;
538 }
539
540 // If given a messsage without a routing ID, then assign our routing ID.
541 if (message->routing_id() == MSG_ROUTING_NONE)
542 message->set_routing_id(routing_id_);
543
[email protected]380244092011-10-07 17:26:27544 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44545}
546
bokanc007c3a2015-02-03 07:15:56547void RenderWidget::SetWindowRectSynchronously(
548 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39549 ResizeParams params;
550 params.screen_info = screen_info_;
551 params.new_size = new_window_rect.size();
552 params.physical_backing_size =
553 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39554 params.visible_viewport_size = new_window_rect.size();
555 params.resizer_rect = gfx::Rect();
556 params.is_fullscreen_granted = is_fullscreen_granted_;
557 params.display_mode = display_mode_;
558 params.needs_resize_ack = false;
559 Resize(params);
560
bokanc007c3a2015-02-03 07:15:56561 view_screen_rect_ = new_window_rect;
562 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02563 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56564 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02565}
566
initial.commit09911bf2008-07-26 23:55:29567void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32568 DCHECK(content::RenderThread::Get());
569 if (closing_)
570 return;
571 NotifyOnClose();
572 closing_ = true;
573
574 // Browser correspondence is no longer needed at this point.
575 if (routing_id_ != MSG_ROUTING_NONE) {
576 RenderThread::Get()->RemoveRoute(routing_id_);
577 SetHidden(false);
578 if (RenderThreadImpl::current())
579 RenderThreadImpl::current()->WidgetDestroyed();
580 }
581
582 if (for_oopif_) {
583 // Widgets for frames may be created and closed at any time while the frame
584 // is alive. However, the closing process must happen synchronously. Frame
585 // widget and frames hold pointers to each other. If Close() is deferred to
586 // the message loop like in the non-frame widget case, WebWidget::close()
587 // can end up accessing members of an already-deleted frame.
588 Close();
589 } else {
590 // If there is a Send call on the stack, then it could be dangerous to close
591 // now. Post a task that only gets invoked when there are no nested message
592 // loops.
593 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
594 FROM_HERE, base::Bind(&RenderWidget::Close, this));
595 }
596
597 // Balances the AddRef taken when we called AddRoute.
598 Release();
initial.commit09911bf2008-07-26 23:55:29599}
600
fsamuel664e8b62016-01-20 19:54:01601void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04602 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32603 return;
604
[email protected]b2e4c70132013-10-03 02:07:51605 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39606 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51607 return;
608 }
609
mfomitchev2600fd7c2016-02-17 20:53:39610 Resize(params);
initial.commit09911bf2008-07-26 23:55:29611}
612
dgozman9260b0a12015-03-16 13:45:20613void RenderWidget::OnEnableDeviceEmulation(
614 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39615 if (!screen_metrics_emulator_) {
616 ResizeParams resize_params;
617 resize_params.screen_info = screen_info_;
618 resize_params.new_size = size_;
619 resize_params.physical_backing_size = physical_backing_size_;
620 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39621 resize_params.resizer_rect = resizer_rect_;
622 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
623 resize_params.display_mode = display_mode_;
624 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
625 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18626 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39627 } else {
dgozman9260b0a12015-03-16 13:45:20628 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39629 }
dgozman9260b0a12015-03-16 13:45:20630}
631
632void RenderWidget::OnDisableDeviceEmulation() {
633 screen_metrics_emulator_.reset();
634}
635
[email protected]b5913d72012-02-07 22:26:54636void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01637 if (resizer_rect_ == resizer_rect)
638 return;
639 resizer_rect_ = resizer_rect;
lfg8ff33912016-09-13 20:59:21640 if (GetWebWidget())
641 GetWebWidget()->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54642}
643
initial.commit09911bf2008-07-26 23:55:29644void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31645 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29646 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03647 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59648 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
649 WasHidden());
initial.commit09911bf2008-07-26 23:55:29650}
651
[email protected]3399dd822014-08-09 11:14:24652void RenderWidget::OnWasShown(bool needs_repainting,
653 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41654 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29655 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21656 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29657 return;
658
659 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03660 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59661 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
662 WasShown());
initial.commit09911bf2008-07-26 23:55:29663
[email protected]8a23afb32014-04-30 22:40:23664 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29665 return;
initial.commit09911bf2008-07-26 23:55:29666
667 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24668 if (compositor_) {
669 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15670 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24671 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05672 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24673 }
jdduke491a3f0c2015-06-15 23:30:26674 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29675}
676
[email protected]53d3f302009-12-21 04:42:05677void RenderWidget::OnRequestMoveAck() {
678 DCHECK(pending_window_rect_count_);
679 pending_window_rect_count_--;
bokan71cb5b12016-04-27 03:45:22680 if (!pending_window_rect_count_)
681 view_screen_rect_ = pending_window_rect_;
[email protected]53d3f302009-12-21 04:42:05682}
683
[email protected]ed7defa2013-03-12 21:29:59684GURL RenderWidget::GetURLForGraphicsContext3D() {
685 return GURL();
[email protected]65225772011-05-12 21:10:24686}
687
fsamuel78f86e42016-01-20 04:10:23688void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10689 const ui::LatencyInfo& latency_info,
690 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23691 if (!input_event)
692 return;
dtapuska0bd451a2016-02-18 17:08:10693 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23694}
695
696void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21697 if (GetWebWidget())
698 GetWebWidget()->setCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23699}
700
701void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21702 if (GetWebWidget())
703 GetWebWidget()->mouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23704}
705
alexmos56567492016-09-13 00:52:46706void RenderWidget::OnSetEditCommandsForNextKeyEvent(
707 const EditCommands& edit_commands) {
708 edit_commands_ = edit_commands;
709}
710
fsamuel78f86e42016-01-20 04:10:23711void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08712 has_focus_ = enable;
713
lfg8ff33912016-09-13 20:59:21714 if (GetWebWidget())
715 GetWebWidget()->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08716
717 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
718 RenderWidgetSetFocus(enable));
fsamuel78f86e42016-01-20 04:10:23719}
720
dtapuska3d5624d32016-08-30 04:34:00721void RenderWidget::SetNeedsMainFrame() {
722 RenderWidgetCompositor* rwc = compositor();
723 if (!rwc)
724 return;
725 rwc->setNeedsBeginFrame();
726}
727
fsamuel78f86e42016-01-20 04:10:23728///////////////////////////////////////////////////////////////////////////////
729// RenderWidgetCompositorDelegate
730
731void RenderWidget::ApplyViewportDeltas(
732 const gfx::Vector2dF& inner_delta,
733 const gfx::Vector2dF& outer_delta,
734 const gfx::Vector2dF& elastic_overscroll_delta,
735 float page_scale,
736 float top_controls_delta) {
lfg8ff33912016-09-13 20:59:21737 GetWebWidget()->applyViewportDeltas(inner_delta, outer_delta,
738 elastic_overscroll_delta, page_scale,
739 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23740}
741
742void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska3d5624d32016-08-30 04:34:00743 RenderThreadImpl* render_thread = RenderThreadImpl::current();
744 // render_thread may be NULL in tests.
745 InputHandlerManager* input_handler_manager =
746 render_thread ? render_thread->input_handler_manager() : NULL;
747 if (input_handler_manager)
748 input_handler_manager->ProcessRafAlignedInputOnMainThread(routing_id_);
749
lfg8ff33912016-09-13 20:59:21750 GetWebWidget()->beginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23751}
752
danakj1120f4c2016-09-15 02:05:32753std::unique_ptr<cc::CompositorFrameSink>
754RenderWidget::CreateCompositorFrameSink(bool fallback) {
lfg8ff33912016-09-13 20:59:21755 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03756 // For widgets that are never visible, we don't start the compositor, so we
danakj1120f4c2016-09-15 02:05:32757 // never get a request for a cc::CompositorFrameSink.
sievers71c62dd52015-10-07 01:44:39758 DCHECK(!compositor_never_visible_);
danakj1120f4c2016-09-15 02:05:32759 return RenderThreadImpl::current()->CreateCompositorFrameSink(
danakj83066a32016-06-21 02:34:49760 fallback, routing_id_, frame_swap_message_queue_,
761 GetURLForGraphicsContext3D());
[email protected]ba91a792013-02-06 09:48:28762}
763
fsamuel78f86e42016-01-20 04:10:23764void RenderWidget::DidCommitAndDrawCompositorFrame() {
765 // NOTE: Tests may break if this event is renamed or moved. See
766 // tab_capture_performancetest.cc.
767 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08768
769 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
770 DidCommitAndDrawCompositorFrame());
771
fsamuel78f86e42016-01-20 04:10:23772 // Notify subclasses that we initiated the paint operation.
773 DidInitiatePaint();
774}
775
776void RenderWidget::DidCommitCompositorFrame() {
777 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
778 DidCommitCompositorFrame());
779 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
780 DidCommitCompositorFrame());
fsamuel78f86e42016-01-20 04:10:23781 input_handler_->FlushPendingInputEventAck();
782}
783
784void RenderWidget::DidCompletePageScaleAnimation() {}
785
786void RenderWidget::DidCompleteSwapBuffers() {
787 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
788
789 // Notify subclasses threaded composited rendering was flushed to the screen.
790 DidFlushPaint();
791
pimanbfb2ceb2016-03-18 21:32:58792 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23793 return;
794 }
795
796 ViewHostMsg_UpdateRect_Params params;
797 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23798 params.flags = next_paint_flags_;
799
800 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
801 next_paint_flags_ = 0;
802 need_update_rect_for_auto_resize_ = false;
803}
804
fsamuel78f86e42016-01-20 04:10:23805void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
806 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
807}
808
809bool RenderWidget::IsClosing() const {
810 return host_closing_;
811}
812
[email protected]4d7e46a2013-11-08 05:33:40813void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24814 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:24815 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:26816 ScheduleComposite();
[email protected]65225772011-05-12 21:10:24817}
818
[email protected]4d7e46a2013-11-08 05:33:40819void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24820 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16821
[email protected]404939f2012-06-01 04:06:18822 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16823 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:29824}
825
fsamuel78f86e42016-01-20 04:10:23826void RenderWidget::OnSwapBuffersPosted() {
827 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:29828}
829
danakj53eccbc2016-03-02 22:51:07830void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23831 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29832}
833
fsamuel78f86e42016-01-20 04:10:23834void RenderWidget::UpdateVisualState() {
lfg8ff33912016-09-13 20:59:21835 GetWebWidget()->updateAllLifecyclePhases();
fsamuel78f86e42016-01-20 04:10:23836}
837
838void RenderWidget::WillBeginCompositorFrame() {
839 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
840
dglazkov06854c5c2016-08-31 00:19:59841 // The UpdateTextInputState can result in further layout and possibly
842 // enable GPU acceleration so they need to be called before any painting
843 // is done.
844 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
845 UpdateSelectionBounds();
846
lfge6119aac2016-01-27 02:14:31847 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
848 WillBeginCompositorFrame());
initial.commit09911bf2008-07-26 23:55:29849}
850
jbroman6ccbc7d472016-07-27 04:45:41851std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
852 std::unique_ptr<cc::CopyOutputRequest> request) {
853 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
854 routing_id_, std::move(request));
855}
856
fsamuel72464894f2015-12-15 06:59:31857///////////////////////////////////////////////////////////////////////////////
858// RenderWidgetInputHandlerDelegate
859
avid7d6b2e2016-03-04 19:41:17860void RenderWidget::FocusChangeComplete() {
861 if (owner_delegate_)
862 owner_delegate_->RenderWidgetFocusChangeComplete();
863}
fsamuel72464894f2015-12-15 06:59:31864
865bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17866 if (owner_delegate_)
867 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
868
fsamuel72464894f2015-12-15 06:59:31869 return true;
870}
871
dtapuska1827dd22016-03-11 15:24:59872void RenderWidget::ObserveGestureEventAndResult(
873 const blink::WebGestureEvent& gesture_event,
874 const gfx::Vector2dF& unused_delta,
875 bool event_processed) {
876 if (!compositor_deps_->IsElasticOverscrollEnabled())
877 return;
878
879 cc::InputHandlerScrollResult scroll_result;
880 scroll_result.did_scroll = event_processed;
881 scroll_result.did_overscroll_root = !unused_delta.IsZero();
882 scroll_result.unused_scroll_delta = unused_delta;
883
884 RenderThreadImpl* render_thread = RenderThreadImpl::current();
885 InputHandlerManager* input_handler_manager =
886 render_thread ? render_thread->input_handler_manager() : NULL;
887 if (input_handler_manager) {
888 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
889 routing_id_, gesture_event, scroll_result);
890 }
891}
892
avid7d6b2e2016-03-04 19:41:17893void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:46894 ClearEditCommands();
895}
896
897void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
898 const std::string& value) {
899 ClearEditCommands();
900 edit_commands_.emplace_back(name, value);
901}
902
903void RenderWidget::ClearEditCommands() {
904 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:17905}
fsamuel72464894f2015-12-15 06:59:31906
chongza8ba91fc2016-08-16 21:39:17907void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:31908 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
909}
910
dchengcedca5612016-04-09 01:40:15911void RenderWidget::OnInputEventAck(
912 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:31913 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
914}
915
dtapuska46616922016-03-17 22:52:01916void RenderWidget::NotifyInputEventHandled(
dtapuskab08721e62016-06-29 03:35:07917 blink::WebInputEvent::Type handled_type,
918 InputEventAckState ack_result) {
dtapuska0bd451a2016-02-18 17:08:10919 RenderThreadImpl* render_thread = RenderThreadImpl::current();
920 InputHandlerManager* input_handler_manager =
921 render_thread ? render_thread->input_handler_manager() : NULL;
922 if (input_handler_manager) {
dtapuskab08721e62016-06-29 03:35:07923 input_handler_manager->NotifyInputEventHandledOnMainThread(
924 routing_id_, handled_type, ack_result);
dtapuska0bd451a2016-02-18 17:08:10925 }
926}
927
fsamuele8326c742016-01-12 00:49:39928void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
929 // Nothing to do here. RenderWidget created the |input_handler| and will take
930 // ownership of it. We just verify here that we don't already have an input
931 // handler.
932 DCHECK(!input_handler_);
933}
934
fsamuel72464894f2015-12-15 06:59:31935void RenderWidget::UpdateTextInputState(ShowIme show_ime,
936 ChangeSource change_source) {
937 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
938 if (ime_event_guard_) {
939 // show_ime should still be effective even if it was set inside the IME
940 // event guard.
941 if (show_ime == ShowIme::IF_NEEDED) {
942 ime_event_guard_->set_show_ime(true);
943 }
944 return;
945 }
946
lfg8ff33912016-09-13 20:59:21947 if (!GetWebWidget())
dglazkov03c1f672016-08-30 23:18:28948 return;
fsamuel72464894f2015-12-15 06:59:31949
lfg8ff33912016-09-13 20:59:21950 blink::WebTextInputInfo new_info = GetWebWidget()->textInputInfo();
dglazkov03c1f672016-08-30 23:18:28951
fsamuel72464894f2015-12-15 06:59:31952 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
953
954 bool new_can_compose_inline = CanComposeInline();
955
956 // Only sends text input params if they are changed or if the ime should be
957 // shown.
958 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:39959 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
dglazkov03c1f672016-08-30 23:18:28960 (text_input_mode_ != new_mode || text_input_info_ != new_info ||
fsamuel72464894f2015-12-15 06:59:31961 can_compose_inline_ != new_can_compose_inline)
962#if defined(OS_ANDROID)
963 || text_field_is_dirty_
964#endif
965 ) {
ekaramad9053e57b2016-04-26 20:00:38966 TextInputState params;
dglazkov03c1f672016-08-30 23:18:28967 params.type = WebKitToUiTextInputType(new_info.type);
fsamuel72464894f2015-12-15 06:59:31968 params.mode = new_mode;
969 params.flags = new_info.flags;
970 params.value = new_info.value.utf8();
971 params.selection_start = new_info.selectionStart;
972 params.selection_end = new_info.selectionEnd;
973 params.composition_start = new_info.compositionStart;
974 params.composition_end = new_info.compositionEnd;
975 params.can_compose_inline = new_can_compose_inline;
976 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
977#if defined(USE_AURA)
978 params.is_non_ime_change = true;
979#endif
980#if defined(OS_ANDROID)
981 params.is_non_ime_change =
982 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
changwan46620072016-09-21 03:05:41983 params.batch_edit = ime_in_batch_edit_;
fsamuel72464894f2015-12-15 06:59:31984 if (params.is_non_ime_change)
985 OnImeEventSentForAck(new_info);
986 text_field_is_dirty_ = false;
987#endif
988 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
989
990 text_input_info_ = new_info;
fsamuel72464894f2015-12-15 06:59:31991 text_input_mode_ = new_mode;
992 can_compose_inline_ = new_can_compose_inline;
993 text_input_flags_ = new_info.flags;
994 }
995}
996
997bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:17998 if (owner_delegate_)
999 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
1000
fsamuel72464894f2015-12-15 06:59:311001 return false;
1002}
1003
1004bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
lfge0c2792ec2016-05-11 18:52:081005 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1006 RenderWidgetWillHandleMouseEvent());
1007
avid7d6b2e2016-03-04 19:41:171008 if (owner_delegate_)
1009 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1010
fsamuel72464894f2015-12-15 06:59:311011 return false;
[email protected]fd847792013-10-24 17:12:351012}
1013
initial.commit09911bf2008-07-26 23:55:291014///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391015// RenderWidgetScreenMetricsDelegate
1016
1017void RenderWidget::Redraw() {
1018 set_next_paint_is_resize_ack();
1019 if (compositor_)
1020 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1021}
1022
bokanc63441c2016-04-27 15:49:121023void RenderWidget::ResizeWebWidget() {
lfg8ff33912016-09-13 20:59:211024 GetWebWidget()->resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121025}
1026
1027gfx::Size RenderWidget::GetSizeForWebWidget() const {
1028 if (IsUseZoomForDSFEnabled())
1029 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1030
1031 return size_;
1032}
1033
mfomitchev2600fd7c2016-02-17 20:53:391034void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581035 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271036 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1037 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581038
mfomitchev2600fd7c2016-02-17 20:53:391039 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581040
ccameron2f451532016-09-07 21:49:271041 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1042 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581043 OnDeviceScaleFactorChanged();
1044 ScheduleComposite();
1045 }
mfomitchev2600fd7c2016-02-17 20:53:391046
1047 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1048 // A resize ack shouldn't be requested if we have not ACK'd the previous
1049 // one.
1050 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1051 }
1052
1053 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211054 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391055 return;
1056
ianwene5fc5782016-08-18 04:05:151057 if (compositor_) {
mfomitchev2600fd7c2016-02-17 20:53:391058 compositor_->setViewportSize(params.physical_backing_size);
ianwene5fc5782016-08-18 04:05:151059 compositor_->setBottomControlsHeight(params.bottom_controls_height);
ccameronf408cab2016-09-14 16:54:421060 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
ianwene5fc5782016-08-18 04:05:151061 }
mfomitchev2600fd7c2016-02-17 20:53:391062
mfomitchev2600fd7c2016-02-17 20:53:391063 visible_viewport_size_ = params.visible_viewport_size;
1064 resizer_rect_ = params.resizer_rect;
1065
1066 // NOTE: We may have entered fullscreen mode without changing our size.
1067 bool fullscreen_change =
1068 is_fullscreen_granted_ != params.is_fullscreen_granted;
1069 is_fullscreen_granted_ = params.is_fullscreen_granted;
1070 display_mode_ = params.display_mode;
1071
bokanc63441c2016-04-27 15:49:121072 size_ = params.new_size;
1073 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391074
bokanc63441c2016-04-27 15:49:121075 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221076
mfomitchev2600fd7c2016-02-17 20:53:391077 WebSize visual_viewport_size;
1078
1079 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181080 visual_viewport_size = gfx::ScaleToCeiledSize(
1081 params.visible_viewport_size,
1082 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391083 } else {
1084 visual_viewport_size = visible_viewport_size_;
1085 }
1086
lfg8ff33912016-09-13 20:59:211087 GetWebWidget()->resizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391088
bokanc63441c2016-04-27 15:49:121089 // When resizing, we want to wait to paint before ACK'ing the resize. This
1090 // ensures that we only resize as fast as we can paint. We only need to
1091 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391092 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1093 // In this case there is no paint/composite and therefore no
1094 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1095 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1096 DCHECK(!params.needs_resize_ack);
1097 }
1098
1099 // Send the Resize_ACK flag once we paint again if requested.
1100 if (params.needs_resize_ack)
1101 set_next_paint_is_resize_ack();
1102
1103 if (fullscreen_change)
1104 DidToggleFullscreen();
1105
engedy6cb63c92016-02-23 14:14:581106 if (orientation_changed)
1107 OnOrientationChange();
1108
mfomitchev2600fd7c2016-02-17 20:53:391109 // If a resize ack is requested and it isn't set-up, then no more resizes will
1110 // come in and in general things will go wrong.
1111 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1112}
1113
1114void RenderWidget::SetScreenMetricsEmulationParameters(
1115 bool enabled,
1116 const blink::WebDeviceEmulationParams& params) {
1117 // This is only supported in RenderView.
1118 NOTREACHED();
1119}
1120
1121void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1122 const gfx::Rect& window_screen_rect) {
1123 view_screen_rect_ = view_screen_rect;
1124 window_screen_rect_ = window_screen_rect;
1125}
1126
1127///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461128// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291129
[email protected]3a1c8a8032013-03-18 22:35:321130void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401131 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051132 if (compositor_)
oshima750cb4342015-10-31 00:59:011133 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051134}
1135
[email protected]e195e582013-03-08 01:32:591136void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221137 DCHECK(!host_closing_);
1138
fsamuel78f86e42016-01-20 04:10:231139 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1140 compositor_deps_);
oshima750cb4342015-10-31 00:59:011141 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331142 OnDeviceScaleFactorChanged();
ccameronf408cab2016-09-14 16:54:421143 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
sievers71c62dd52015-10-07 01:44:391144 // For background pages and certain tests, we don't want to trigger
danakj1120f4c2016-09-15 02:05:321145 // CompositorFrameSink creation.
sievers71c62dd52015-10-07 01:44:391146 if (compositor_never_visible_ || !RenderThreadImpl::current())
1147 compositor_->SetNeverVisible();
1148
pimanc4af3072015-10-02 03:45:591149 StartCompositor();
[email protected]e195e582013-03-08 01:32:591150}
1151
ennef3c58142014-12-09 21:44:381152void RenderWidget::WillCloseLayerTreeView() {
1153 if (host_closing_)
1154 return;
1155
1156 // Prevent new compositors or output surfaces from being created.
1157 host_closing_ = true;
1158
[email protected]aeeedad2014-08-22 18:16:221159 // Always send this notification to prevent new layer tree views from
1160 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211161 if (blink::WebWidget* widget = GetWebWidget())
1162 widget->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221163}
1164
[email protected]180ef242013-11-07 06:50:461165blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281166 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061167}
1168
dglazkovf0e1d6d2015-10-10 02:13:481169void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1170 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1171 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1172 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1173 }
dglazkov79c426102015-08-31 21:22:431174
dglazkovf0e1d6d2015-10-10 02:13:481175 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1176 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431177}
1178
jdduke491a3f0c2015-06-15 23:30:261179void RenderWidget::ScheduleComposite() {
1180 if (compositor_ &&
1181 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1182 compositor_->setNeedsAnimate();
1183 }
1184}
1185
1186void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1187 if (compositor_) {
1188 // Regardless of whether threaded compositing is enabled, always
1189 // use this mechanism to force the compositor to redraw. However,
1190 // the invalidation code path below is still needed for the
1191 // non-threaded case.
1192 compositor_->SetNeedsForcedRedraw();
1193 }
1194 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151195}
1196
[email protected]586871b2014-07-22 17:05:111197// static
dchengcedca5612016-04-09 01:40:151198std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111199 IPC::Message* msg,
1200 MessageDeliveryPolicy policy,
1201 FrameSwapMessageQueue* frame_swap_message_queue,
1202 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111203 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111204 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151205 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1206 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111207 &first_message_for_frame);
1208 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151209 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111210 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061211 return promise;
[email protected]586871b2014-07-22 17:05:111212 }
dcheng4b6b5ff2014-10-16 00:42:061213 return nullptr;
[email protected]586871b2014-07-22 17:05:111214}
1215
1216void RenderWidget::QueueMessage(IPC::Message* msg,
1217 MessageDeliveryPolicy policy) {
1218 // RenderThreadImpl::current() is NULL in some tests.
1219 if (!compositor_ || !RenderThreadImpl::current()) {
1220 Send(msg);
1221 return;
1222 }
1223
dchengcedca5612016-04-09 01:40:151224 std::unique_ptr<cc::SwapPromise> swap_promise =
1225 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111226 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111227 compositor_->GetSourceFrameNumber());
1228
1229 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321230 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351231 // Request a commit. This might either A) request a commit ahead of time
1232 // or B) request a commit which is not needed because there are not
1233 // pending updates. If B) then the commit will be skipped and the swap
1234 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1235 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1236 // can_cancel_commit is not unset.
1237 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111238 }
1239}
1240
[email protected]4873c7d2009-07-16 06:36:281241void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301242 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521243 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181244 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291245 // Only send a SetCursor message if we need to make a change.
1246 if (!current_cursor_.IsEqual(cursor)) {
1247 current_cursor_ = cursor;
1248 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1249 }
1250}
1251
1252// We are supposed to get a single call to Show for a newly created RenderWidget
1253// that was created via RenderWidget::CreateWebView. So, we wait until this
1254// point to dispatch the ShowWidget message.
1255//
1256// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281257// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291258//
[email protected]4873c7d2009-07-16 06:36:281259void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291260 DCHECK(!did_show_) << "received extraneous Show call";
1261 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1262 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1263
[email protected]8de12d942010-11-17 20:42:441264 if (did_show_)
1265 return;
1266
1267 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561268 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441269 // that's okay. It'll be ignored if as_popup is false, or the browser
1270 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561271 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1272 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291273}
1274
[email protected]2533ce12009-05-09 00:02:241275void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381276 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241277 Send(new ViewHostMsg_Close(routing_id_));
1278}
1279
dgozmancf9039cd2015-04-06 12:01:311280void RenderWidget::NotifyOnClose() {
1281 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1282}
1283
[email protected]4873c7d2009-07-16 06:36:281284void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081285 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321286 if (is_swapped_out_) {
1287 // This widget is currently swapped out, and the active widget is in a
1288 // different process. Have the browser route the close request to the
1289 // active widget instead, so that the correct unload handlers are run.
1290 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1291 return;
1292 }
1293
initial.commit09911bf2008-07-26 23:55:291294 // If a page calls window.close() twice, we'll end up here twice, but that's
1295 // OK. It is safe to send multiple Close messages.
1296
[email protected]2533ce12009-05-09 00:02:241297 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1298 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1299 // could be closed before the JS finishes executing. So instead, post a
1300 // message back to the message loop, which won't run until the JS is
1301 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081302 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211303 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291304}
1305
[email protected]9017d7852013-11-21 17:47:351306void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151307 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351308 const SyntheticGestureCompletionCallback& callback) {
1309 DCHECK(!callback.is_null());
1310
1311 pending_synthetic_gesture_callbacks_.push(callback);
1312
1313 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321314 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351315
1316 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1317}
1318
initial.commit09911bf2008-07-26 23:55:291319void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031320 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381321 WillCloseLayerTreeView();
1322 compositor_.reset();
lfg8ff33912016-09-13 20:59:211323 if (webwidget_internal_) {
1324 webwidget_internal_->close();
1325 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291326 }
1327}
1328
[email protected]4873c7d2009-07-16 06:36:281329WebRect RenderWidget::windowRect() {
1330 if (pending_window_rect_count_)
1331 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241332
[email protected]80ad8622012-11-07 16:33:031333 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291334}
1335
[email protected]180ef242013-11-07 06:50:461336void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301337 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541338 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301339}
1340
oshima33ec97cd2015-12-14 19:40:241341void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1342 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511343 if (popup_origin_scale_for_emulation_) {
1344 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561345 window_rect.x = popup_screen_origin_for_emulation_.x() +
1346 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1347 window_rect.y = popup_screen_origin_for_emulation_.y() +
1348 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511349 }
1350
[email protected]5b45ad42013-10-25 00:42:041351 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201352 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561353 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1354 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031355 } else {
bokanc007c3a2015-02-03 07:15:561356 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031357 }
initial.commit09911bf2008-07-26 23:55:291358 } else {
bokanc007c3a2015-02-03 07:15:561359 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291360 }
1361}
1362
[email protected]2533ce12009-05-09 00:02:241363void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1364 pending_window_rect_ = rect;
1365 pending_window_rect_count_++;
1366}
1367
lfg0140a452016-07-19 19:15:051368gfx::Rect RenderWidget::RootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241369 if (pending_window_rect_count_) {
1370 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1371 // the RootWindowRect is probably going to return wrong results since the
1372 // browser may not have processed the Move yet. There isn't really anything
1373 // good to do in this case, and it shouldn't happen - since this size is
1374 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281375 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241376 }
1377
[email protected]80ad8622012-11-07 16:33:031378 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371379}
1380
[email protected]4873c7d2009-07-16 06:36:281381WebRect RenderWidget::windowResizerRect() {
1382 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191383}
1384
[email protected]fa7b1dc2010-06-23 17:53:041385void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261386 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041387 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071388 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041389 int selection_start, int selection_end) {
ekaramad2a46d632016-07-19 13:33:091390#if defined(ENABLE_PLUGINS)
1391 if (focused_pepper_plugin_) {
1392 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1393 text, underlines, selection_start, selection_end);
1394 return;
1395 }
1396#endif
1397 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211398 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031399 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091400 }
1401
[email protected]0d1ebed12013-08-05 22:01:131402 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281403 return;
[email protected]66fca5bc2013-05-23 06:58:291404 ImeEventGuard guard(this);
lfg8ff33912016-09-13 20:59:211405 if (!GetWebWidget()->setComposition(
1406 text, WebVector<WebCompositionUnderline>(underlines), selection_start,
1407 selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041408 // If we failed to set the composition text, then we need to let the browser
1409 // process to cancel the input method's ongoing composition session, to make
1410 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221411 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261412 }
nonafa291792016-08-10 02:36:181413 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041414}
1415
aelias87b8f7c2016-09-14 03:19:291416void RenderWidget::OnImeCommitText(const base::string16& text,
1417 const gfx::Range& replacement_range,
1418 int relative_cursor_pos) {
ekaramad2a46d632016-07-19 13:33:091419#if defined(ENABLE_PLUGINS)
1420 if (focused_pepper_plugin_) {
aelias87b8f7c2016-09-14 03:19:291421 focused_pepper_plugin_->render_frame()->OnImeCommitText(
1422 text, replacement_range, relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091423 return;
1424 }
1425#endif
1426 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211427 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031428 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091429 }
1430
[email protected]0d1ebed12013-08-05 22:01:131431 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041432 return;
[email protected]66fca5bc2013-05-23 06:58:291433 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391434 input_handler_->set_handling_input_event(true);
aelias87b8f7c2016-09-14 03:19:291435 GetWebWidget()->commitText(text, relative_cursor_pos);
1436 input_handler_->set_handling_input_event(false);
1437 UpdateCompositionInfo(false /* not an immediate request */);
1438}
1439
1440void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
1441#if defined(ENABLE_PLUGINS)
1442 if (focused_pepper_plugin_) {
1443 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText(
1444 keep_selection);
1445 return;
1446 }
1447#endif
1448
1449 if (!ShouldHandleImeEvent())
1450 return;
1451 ImeEventGuard guard(this);
1452 input_handler_->set_handling_input_event(true);
1453 GetWebWidget()->finishComposingText(keep_selection
1454 ? WebWidget::KeepSelection
1455 : WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391456 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181457 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291458}
1459
oshimad5279032015-12-16 18:22:331460void RenderWidget::OnDeviceScaleFactorChanged() {
1461 if (!compositor_)
1462 return;
oshimad5279032015-12-16 18:22:331463 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181464 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331465 else
1466 compositor_->setDeviceScaleFactor(device_scale_factor_);
1467}
1468
[email protected]0bc1f572013-04-17 01:46:311469void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121470 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211471 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121472 return;
1473
[email protected]0bc1f572013-04-17 01:46:311474 // Even if the browser provides an empty damage rect, it's still expecting to
1475 // receive a repaint ack so just damage the entire widget bounds.
1476 if (size_to_paint.IsEmpty()) {
1477 size_to_paint = size_;
1478 }
1479
[email protected]ec7dc112008-08-06 05:30:121480 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051481 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311482 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121483}
1484
[email protected]79fa22e2013-08-23 15:18:121485void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351486 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1487
1488 pending_synthetic_gesture_callbacks_.front().Run();
1489 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271490}
1491
[email protected]4873c7d2009-07-16 06:36:281492void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211493 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111494 return;
lfg8ff33912016-09-13 20:59:211495 GetWebWidget()->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111496}
1497
[email protected]80ad8622012-11-07 16:33:031498void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1499 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511500 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391501 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1502 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511503 } else {
mfomitchev2600fd7c2016-02-17 20:53:391504 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511505 }
[email protected]80ad8622012-11-07 16:33:031506 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1507}
1508
lfgdb5c4ed2016-03-04 23:09:071509void RenderWidget::OnUpdateWindowScreenRect(
1510 const gfx::Rect& window_screen_rect) {
1511 if (screen_metrics_emulator_) {
1512 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
1513 } else {
1514 window_screen_rect_ = window_screen_rect;
1515 }
1516}
1517
fsamuel278664272016-07-13 04:06:591518void RenderWidget::OnSetSurfaceClientId(uint32_t surface_id_namespace) {
kenrbb4e2a3b2015-05-14 15:05:051519 if (compositor_)
fsamuel278664272016-07-13 04:06:591520 compositor_->SetSurfaceClientId(surface_id_namespace);
kenrbb4e2a3b2015-05-14 15:05:051521}
1522
dtrainor5ef644e2015-11-19 00:12:471523void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1524 if (compositor_)
1525 compositor_->OnHandleCompositorProto(proto);
1526}
1527
[email protected]adb362312014-06-28 06:04:241528void RenderWidget::showImeIfNeeded() {
1529 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131530}
1531
fsamuel72464894f2015-12-15 06:59:311532ui::TextInputType RenderWidget::GetTextInputType() {
ekaramad2a46d632016-07-19 13:33:091533#if defined(ENABLE_PLUGINS)
1534 if (focused_pepper_plugin_)
1535 return focused_pepper_plugin_->text_input_type();
1536#endif
lfg8ff33912016-09-13 20:59:211537 if (GetWebWidget())
1538 return WebKitToUiTextInputType(GetWebWidget()->textInputType());
fsamuel72464894f2015-12-15 06:59:311539 return ui::TEXT_INPUT_TYPE_NONE;
1540}
1541
nonafa291792016-08-10 02:36:181542void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1543 if (!monitor_composition_info_ && !immediate_request)
1544 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591545
nonafa291792016-08-10 02:36:181546 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1547 gfx::Range range;
1548 std::vector<gfx::Rect> character_bounds;
1549
1550 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1551 // Composition information is only available on editable node.
1552 range = gfx::Range::InvalidRange();
1553 } else {
1554 GetCompositionRange(&range);
1555 GetCompositionCharacterBounds(&character_bounds);
1556 }
1557
1558 if (!immediate_request &&
1559 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311560 return;
nonafa291792016-08-10 02:36:181561 }
fsamuel72464894f2015-12-15 06:59:311562 composition_character_bounds_ = character_bounds;
1563 composition_range_ = range;
1564 Send(new InputHostMsg_ImeCompositionRangeChanged(
1565 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311566}
1567
oshimaf866dab2015-12-05 00:41:541568void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1569 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461570 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331571 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541572 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461573 gfx::Rect window_rect =
1574 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1575 rect->x = window_rect.x();
1576 rect->y = window_rect.y();
1577 rect->width = window_rect.width();
1578 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541579 }
1580}
1581
oshimaa6985b62016-01-27 08:58:301582void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1583 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181584 rect->x *= GetOriginalDeviceScaleFactor();
1585 rect->y *= GetOriginalDeviceScaleFactor();
1586 rect->width *= GetOriginalDeviceScaleFactor();
1587 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301588 }
1589}
1590
[email protected]adb362312014-06-28 06:04:241591void RenderWidget::OnShowImeIfNeeded() {
1592#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311593 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241594#endif
rouslanf7ebd8832015-01-22 01:54:141595
1596// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1597// virtual keyboard.
1598#if !defined(OS_ANDROID)
1599 FocusChangeComplete();
1600#endif
[email protected]adb362312014-06-28 06:04:241601}
1602
1603#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371604void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1605 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131606}
1607
1608void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371609 DCHECK_GE(text_input_info_history_.size(), 1u);
1610 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511611}
changwan8c342742016-02-26 00:53:391612
1613void RenderWidget::OnRequestTextInputStateUpdate() {
1614 DCHECK(!ime_event_guard_);
1615 UpdateSelectionBounds();
1616 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1617}
changwan46620072016-09-21 03:05:411618
1619void RenderWidget::OnImeBatchEdit(bool begin) {
1620 if (begin) {
1621 ime_in_batch_edit_ = true;
1622 return;
1623 }
1624 if (!ime_in_batch_edit_)
1625 return;
1626 ime_in_batch_edit_ = false;
1627 DCHECK(!ime_event_guard_);
1628 UpdateSelectionBounds();
1629 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1630}
[email protected]105dffb42013-02-20 03:46:211631#endif
1632
nonafa291792016-08-10 02:36:181633void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1634 bool monitor_request) {
1635 monitor_composition_info_ = monitor_request;
1636 if (!immediate_request)
1637 return;
1638 UpdateCompositionInfo(true /* immediate request */);
1639}
1640
[email protected]0d1ebed12013-08-05 22:01:131641bool RenderWidget::ShouldHandleImeEvent() {
1642#if defined(OS_ANDROID)
lfg8ff33912016-09-13 20:59:211643 if (!GetWebWidget())
changwan3a841162015-08-11 02:53:371644 return false;
changwan8c342742016-02-26 00:53:391645 if (IsUsingImeThread())
1646 return true;
changwan3a841162015-08-11 02:53:371647
1648 // We cannot handle IME events if there is any chance that the event we are
1649 // receiving here from the browser is based on the state that is different
1650 // from our current one as indicated by |text_input_info_|.
1651 // The states the browser might be in are:
1652 // text_input_info_history_[0] - current state ack'd by browser
1653 // text_input_info_history_[1...N] - pending state changes
1654 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1655 if (text_input_info_history_[i] != text_input_info_)
1656 return false;
1657 }
1658 return true;
[email protected]0d1ebed12013-08-05 22:01:131659#else
lfg8ff33912016-09-13 20:59:211660 return !!GetWebWidget();
[email protected]0d1ebed12013-08-05 22:01:131661#endif
1662}
1663
wjmaclean8a795f32016-08-11 23:49:581664void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191665 if (device_scale_factor_ == device_scale_factor)
1666 return;
1667
1668 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331669
1670 OnDeviceScaleFactorChanged();
jdduke491a3f0c2015-06-15 23:30:261671 ScheduleComposite();
wjmaclean8a795f32016-08-11 23:49:581672
1673 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191674}
1675
[email protected]28ed6b32014-06-08 02:16:271676bool RenderWidget::SetDeviceColorProfile(
1677 const std::vector<char>& color_profile) {
1678 if (device_color_profile_ == color_profile)
1679 return false;
1680
1681 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271682
avi40b5be7a2016-03-03 21:13:441683 if (owner_delegate_)
1684 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1685
1686 return true;
noeldb4df152014-09-16 17:45:201687}
1688
[email protected]fcdc5642014-05-09 14:32:241689void RenderWidget::OnOrientationChange() {
1690}
1691
avib9dbd972016-03-08 18:19:321692void RenderWidget::DidFlushPaint() {
1693 if (owner_delegate_)
1694 owner_delegate_->RenderWidgetDidFlushPaint();
1695}
1696
[email protected]bee16aab2009-08-26 15:55:031697void RenderWidget::SetHidden(bool hidden) {
1698 if (is_hidden_ == hidden)
1699 return;
1700
jdduke8fac9d102014-12-20 02:40:131701 // The status has changed. Tell the RenderThread about it and ensure
1702 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031703 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391704 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131705
[email protected]bee16aab2009-08-26 15:55:031706 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001707 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031708 else
[email protected]b2db9272014-01-10 17:42:001709 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111710
1711 if (render_widget_scheduling_state_)
1712 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031713}
1714
[email protected]2b624c562011-10-27 22:58:261715void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:211716 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:261717 return;
1718
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121719 if (is_fullscreen_granted_) {
lfg8ff33912016-09-13 20:59:211720 GetWebWidget()->didEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261721 } else {
lfg8ff33912016-09-13 20:59:211722 GetWebWidget()->didExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261723 }
[email protected]2b624c562011-10-27 22:58:261724}
1725
[email protected]674741932009-02-04 23:44:461726bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051727 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461728}
1729
[email protected]674741932009-02-04 23:44:461730void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051731 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461732}
1733
[email protected]674741932009-02-04 23:44:461734void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051735 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461736}
1737
changwan8c342742016-02-26 00:53:391738bool RenderWidget::IsUsingImeThread() {
1739#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121740 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391741#else
1742 return false;
1743#endif
1744}
1745
changwanf2a707b2015-10-30 08:22:161746void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1747 if (!ime_event_guard_)
1748 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291749}
1750
changwanf2a707b2015-10-30 08:22:161751void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1752 if (ime_event_guard_ != guard) {
1753#if defined(OS_ANDROID)
1754 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1755 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391756 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161757 // Therefore, we want to mark this text state update as 'from IME' only
1758 // when all the nested events are all originating from IME.
1759 ime_event_guard_->set_from_ime(
1760 ime_event_guard_->from_ime() && guard->from_ime());
1761#endif
1762 return;
1763 }
1764 ime_event_guard_ = nullptr;
1765
[email protected]66fca5bc2013-05-23 06:58:291766 // While handling an ime event, text input state and selection bounds updates
1767 // are ignored. These must explicitly be updated once finished handling the
1768 // ime event.
1769 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471770#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161771 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311772 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1773 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471774#endif
[email protected]66fca5bc2013-05-23 06:58:291775}
1776
[email protected]7c8873e2013-02-05 08:03:011777void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
ekaramad2a46d632016-07-19 13:33:091778#if defined(ENABLE_PLUGINS)
1779 if (focused_pepper_plugin_) {
1780 // TODO(kinaba) http://crbug.com/101101
1781 // Current Pepper IME API does not handle selection bounds. So we simply
1782 // use the caret position as an empty range for now. It will be updated
1783 // after Pepper API equips features related to surrounding text retrieval.
1784 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1785 convertViewportToWindow(&caret);
1786 *focus = caret;
1787 *anchor = caret;
1788 return;
1789 }
1790#endif
[email protected]7c8873e2013-02-05 08:03:011791 WebRect focus_webrect;
1792 WebRect anchor_webrect;
lfg8ff33912016-09-13 20:59:211793 GetWebWidget()->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241794 convertViewportToWindow(&focus_webrect);
1795 convertViewportToWindow(&anchor_webrect);
1796 *focus = focus_webrect;
1797 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321798}
1799
[email protected]e99ef6f2011-10-16 01:13:001800void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081801 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:211802 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:001803 return;
changwanf2a707b2015-10-30 08:22:161804 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291805 return;
[email protected]e99ef6f2011-10-16 01:13:001806
mohsenb0eeba72015-08-09 06:20:081807#if defined(USE_AURA)
1808 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1809 // Aura beucause composited selection updates are not working for webview tags
1810 // which regresses IME inside webview. Remove this when composited selection
1811 // updates are fixed for webviews. See, http://crbug.com/510568.
1812 bool send_ipc = true;
1813#else
jddukeacf809e2014-09-23 20:38:381814 // With composited selection updates, the selection bounds will be reported
1815 // directly by the compositor, in which case explicit IPC selection
1816 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081817 bool send_ipc =
1818 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1819#endif
1820 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381821 ViewHostMsg_SelectionBounds_Params params;
1822 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1823 if (selection_anchor_rect_ != params.anchor_rect ||
1824 selection_focus_rect_ != params.focus_rect) {
1825 selection_anchor_rect_ = params.anchor_rect;
1826 selection_focus_rect_ = params.focus_rect;
lfg8ff33912016-09-13 20:59:211827 GetWebWidget()->selectionTextDirection(params.focus_dir,
1828 params.anchor_dir);
1829 params.is_anchor_first = GetWebWidget()->isSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:381830 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1831 }
[email protected]58b48a0d2012-06-13 07:01:351832 }
jddukeacf809e2014-09-23 20:38:381833
nonafa291792016-08-10 02:36:181834 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:001835}
1836
avi40b5be7a2016-03-03 21:13:441837void RenderWidget::SetDeviceColorProfileForTesting(
1838 const std::vector<char>& color_profile) {
1839 SetDeviceColorProfile(color_profile);
1840}
1841
lfgb00fcad2016-07-14 14:16:331842void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
1843 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
1844 convertViewportToWindow(&new_size_in_window);
1845 if (size_.width() != new_size_in_window.width ||
1846 size_.height() != new_size_in_window.height) {
1847 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
1848
1849 if (resizing_mode_selector_->is_synchronous_mode()) {
lfg0140a452016-07-19 19:15:051850 gfx::Rect new_pos(RootWindowRect().x(), RootWindowRect().y(),
1851 size_.width(), size_.height());
lfgb00fcad2016-07-14 14:16:331852 view_screen_rect_ = new_pos;
1853 window_screen_rect_ = new_pos;
1854 }
1855
1856 AutoResizeCompositor();
1857
1858 if (!resizing_mode_selector_->is_synchronous_mode())
1859 need_update_rect_for_auto_resize_ = true;
1860 }
1861}
1862
[email protected]180ef242013-11-07 06:50:461863// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
danakj365175c2016-02-06 00:37:371864STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1865STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1866STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1867 ui::TEXT_INPUT_TYPE_PASSWORD);
1868STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1869STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1870STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1871STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1872 ui::TEXT_INPUT_TYPE_TELEPHONE);
1873STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1874STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1875STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1876 ui::TEXT_INPUT_TYPE_DATE_TIME);
1877STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1878 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1879STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1880STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1881STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1882STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1883 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1884STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1885 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1886STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1887 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451888
[email protected]5b739cb2012-08-21 20:35:211889ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461890 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211891 // Check the type is in the range representable by ui::TextInputType.
1892 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461893 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211894 return static_cast<ui::TextInputType>(type);
1895}
1896
[email protected]58b48a0d2012-06-13 07:01:351897void RenderWidget::GetCompositionCharacterBounds(
1898 std::vector<gfx::Rect>* bounds) {
1899 DCHECK(bounds);
1900 bounds->clear();
ekaramad2a46d632016-07-19 13:33:091901
1902#if defined(ENABLE_PLUGINS)
1903 if (focused_pepper_plugin_)
1904 return;
1905#endif
1906
lfg8ff33912016-09-13 20:59:211907 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:091908 return;
1909 blink::WebVector<blink::WebRect> bounds_from_blink;
lfg8ff33912016-09-13 20:59:211910 if (!GetWebWidget()->getCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:091911 return;
1912
1913 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
1914 convertViewportToWindow(&bounds_from_blink[i]);
1915 bounds->push_back(bounds_from_blink[i]);
1916 }
[email protected]58b48a0d2012-06-13 07:01:351917}
1918
[email protected]db4fc1e2013-09-06 20:01:511919void RenderWidget::GetCompositionRange(gfx::Range* range) {
ekaramad2a46d632016-07-19 13:33:091920#if defined(ENABLE_PLUGINS)
1921 if (focused_pepper_plugin_)
1922 return;
1923#endif
lfg8ff33912016-09-13 20:59:211924 WebRange web_range = GetWebWidget()->compositionRange();
dglazkov78a24b62016-09-02 21:34:531925 if (!web_range.isNull()) {
1926 range->set_start(web_range.startOffset());
1927 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:361928 } else {
lfg8ff33912016-09-13 20:59:211929 web_range = GetWebWidget()->caretOrSelectionRange();
dglazkove353a372016-09-01 01:33:481930 range->set_start(web_range.startOffset());
1931 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:361932 }
1933}
1934
[email protected]501ea13d2013-07-09 17:03:291935bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511936 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291937 const std::vector<gfx::Rect>& bounds) {
1938 if (composition_range_ != range)
1939 return true;
1940 if (bounds.size() != composition_character_bounds_.size())
1941 return true;
1942 for (size_t i = 0; i < bounds.size(); ++i) {
1943 if (bounds[i] != composition_character_bounds_[i])
1944 return true;
1945 }
1946 return false;
1947}
[email protected]501ea13d2013-07-09 17:03:291948
[email protected]ad26ef42011-06-17 07:59:451949bool RenderWidget::CanComposeInline() {
ekaramad2a46d632016-07-19 13:33:091950#if defined(ENABLE_PLUGINS)
1951 if (focused_pepper_plugin_)
1952 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
1953#endif
[email protected]ad26ef42011-06-17 07:59:451954 return true;
[email protected]56ea1a62011-05-30 07:05:571955}
1956
ccameron2f451532016-09-07 21:49:271957blink::WebScreenInfo RenderWidget::screenInfo() {
1958 blink::WebScreenInfo web_screen_info;
1959 web_screen_info.deviceScaleFactor = screen_info_.device_scale_factor;
1960 web_screen_info.depth = screen_info_.depth;
1961 web_screen_info.depthPerComponent = screen_info_.depth_per_component;
1962 web_screen_info.isMonochrome = screen_info_.is_monochrome;
1963 web_screen_info.rect = blink::WebRect(screen_info_.rect);
1964 web_screen_info.availableRect = blink::WebRect(screen_info_.available_rect);
1965 switch (screen_info_.orientation_type) {
1966 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
1967 web_screen_info.orientationType =
1968 blink::WebScreenOrientationPortraitPrimary;
1969 break;
1970 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
1971 web_screen_info.orientationType =
1972 blink::WebScreenOrientationPortraitSecondary;
1973 break;
1974 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
1975 web_screen_info.orientationType =
1976 blink::WebScreenOrientationLandscapePrimary;
1977 break;
1978 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
1979 web_screen_info.orientationType =
1980 blink::WebScreenOrientationLandscapeSecondary;
1981 break;
1982 default:
1983 web_screen_info.orientationType =
1984 blink::WebScreenOrientationUndefined;
1985 break;
1986 }
1987 web_screen_info.orientationAngle = screen_info_.orientation_angle;
1988 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:281989}
1990
[email protected]fa7b1dc2010-06-23 17:53:041991void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021992 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041993 // If the last text input type is not None, then we should finish any
1994 // ongoing composition regardless of the new text input type.
dglazkov03c1f672016-08-30 23:18:281995 if (text_input_info_.type != blink::WebTextInputTypeNone) {
[email protected]fa7b1dc2010-06-23 17:53:041996 // If a composition text exists, then we need to let the browser process
1997 // to cancel the input method's ongoing composition session.
aelias87b8f7c2016-09-14 03:19:291998 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection))
[email protected]a2214eb2014-06-23 18:31:221999 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042000 }
[email protected]d4cff272011-05-02 15:46:012001
nonafa291792016-08-10 02:36:182002 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:042003}
2004
donnda070f3c2015-01-16 19:54:112005#if defined(OS_ANDROID)
2006void RenderWidget::showUnhandledTapUIIfNeeded(
2007 const WebPoint& tapped_position,
2008 const WebNode& tapped_node,
2009 bool page_changed) {
fsamuele8326c742016-01-12 00:49:392010 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:112011 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372012 !tapped_node.isContentEditable() &&
2013 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112014 if (should_trigger) {
2015 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2016 tapped_position.x, tapped_position.y));
2017 }
2018}
2019#endif
2020
[email protected]c68c3e4e2013-01-24 00:36:562021void RenderWidget::didHandleGestureEvent(
2022 const WebGestureEvent& event,
2023 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022024#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562025 if (event_cancelled)
2026 return;
[email protected]07c70d22014-08-21 08:33:462027 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:312028 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462029 } else if (event.type == WebInputEvent::GestureLongPress) {
lfg8ff33912016-09-13 20:59:212030 DCHECK(GetWebWidget());
2031 if (GetWebWidget()->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:312032 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462033 else
fsamuel72464894f2015-12-15 06:59:312034 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562035 }
2036#endif
2037}
2038
sataya.m582c9ce2015-06-09 08:03:422039void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:312040 const blink::WebFloatSize& overscrollDelta,
2041 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422042 const blink::WebFloatPoint& position,
2043 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482044#if defined(OS_MACOSX)
2045 // On OSX the user can disable the elastic overscroll effect. If that's the
2046 // case, don't forward the overscroll notification.
2047 DCHECK(compositor_deps());
2048 if (!compositor_deps()->IsElasticOverscrollEnabled())
2049 return;
2050#endif
bokane53a10f2016-04-13 23:48:312051 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392052 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422053}
2054
[email protected]7912e822014-04-16 02:37:032055void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392056 if (!is_hidden())
2057 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032058}
2059
[email protected]24ed0432013-04-24 07:50:312060RenderWidgetCompositor* RenderWidget::compositor() const {
2061 return compositor_.get();
2062}
2063
fsamuel72464894f2015-12-15 06:59:312064void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392065 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372066}
[email protected]c3d45532011-10-07 19:20:402067
fsamuel72464894f2015-12-15 06:59:312068bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392069 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242070}
2071
fsamuel72464894f2015-12-15 06:59:312072void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392073 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312074}
2075
[email protected]ce6689f2013-03-29 12:52:552076void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112077 if (render_widget_scheduling_state_)
2078 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552079 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2080}
2081
danakj365175c2016-02-06 00:37:372082// Check blink::WebTouchAction and content::TouchAction is kept in sync.
2083STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
2084STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
2085STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
2086STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
2087STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
2088STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
2089STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
2090STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
2091STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
2092STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
2093 TOUCH_ACTION_MANIPULATION);
2094STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2095 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2096STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
mostynbe29b6882015-01-13 09:59:172097
[email protected]5d0bbdfa92013-12-10 00:35:512098void RenderWidget::setTouchAction(
2099 blink::WebTouchAction web_touch_action) {
2100
2101 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2102 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392103 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512104 return;
2105
[email protected]a18f67a2013-12-20 19:44:362106 content::TouchAction content_touch_action =
2107 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512108 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2109}
2110
[email protected]90f24152014-04-09 12:41:362111void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2112#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392113 if (!IsUsingImeThread())
2114 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362115#endif
2116}
2117
[email protected]e3244ed2014-06-20 20:04:272118void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2119 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162120}
2121
[email protected]e3244ed2014-06-20 20:04:272122void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2123 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162124}
2125
[email protected]de3c5d82014-05-28 22:12:592126void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2127 render_frames_.AddObserver(frame);
2128}
2129
2130void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2131 render_frames_.RemoveObserver(frame);
2132}
2133
lfg43e08e62016-02-03 18:51:372134void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2135 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2136 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2137}
2138
oshima50872a72016-03-04 13:26:182139float RenderWidget::GetOriginalDeviceScaleFactor() const {
2140 return
2141 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272142 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182143 device_scale_factor_;
2144}
2145
lfgbee1e0a2016-06-08 21:24:212146bool RenderWidget::requestPointerLock() {
2147 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2148}
2149
2150void RenderWidget::requestPointerUnlock() {
2151 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2152}
2153
2154bool RenderWidget::isPointerLocked() {
2155 return mouse_lock_dispatcher_->IsMouseLockedTo(
2156 webwidget_mouse_lock_target_.get());
2157}
2158
lfg8ff33912016-09-13 20:59:212159blink::WebWidget* RenderWidget::GetWebWidget() const {
2160 return webwidget_internal_;
2161}
2162
[email protected]e9ff79c2012-10-19 21:31:262163} // namespace content