blob: 50a882f9e828aeb273fde9ea48c7d7e9842b10f0 [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
dcheng07945f632015-12-26 07:59:327#include <utility>
8
[email protected]c27dd4f2014-05-22 18:05:199#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2110#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0011#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1212#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/logging.h"
avi1023d012015-12-25 02:39:1414#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4016#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3017#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2119#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0020#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2721#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0122#include "base/trace_event/trace_event.h"
23#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4824#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5225#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3326#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3027#include "cc/output/output_surface.h"
fsamuel78f86e42016-01-20 04:10:2328#include "cc/scheduler/begin_frame_source.h"
[email protected]556fd292013-03-18 08:03:0429#include "cc/trees/layer_tree_host.h"
alexclarke7fa93942015-10-21 15:37:1130#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2131#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]29e2fb42013-07-19 01:13:4732#include "content/child/npapi/webplugin.h"
oshima750cb4342015-10-31 00:59:0133#include "content/common/content_switches_internal.h"
[email protected]0634cdd42013-08-16 00:46:0934#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5935#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2936#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3537#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4438#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1539#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1540#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5041#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1242#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2943#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4244#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4045#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3946#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
[email protected]b2e4c70132013-10-03 02:07:5147#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5948#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2949#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1150#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5951#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1152#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2853#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2954#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1355#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3256#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1657#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2758#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0559#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4460#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5561#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4462#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0963#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0464#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1865#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4866#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1867#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3068#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1169#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3070#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1871#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3072#include "third_party/WebKit/public/platform/WebSize.h"
73#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4374#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5975#include "third_party/WebKit/public/web/WebFrameWidget.h"
76#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1177#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3178#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3179#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
80#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3881#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5982#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4183#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1384#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5085#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0986#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3287#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4888#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2789#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4190#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4891
[email protected]eeb93112013-05-01 19:41:1092#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1593#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0794#include "content/renderer/android/synchronous_compositor_factory.h"
boliubee541f42015-11-05 00:52:5395#include "content/renderer/android/synchronous_compositor_filter.h"
96#include "content/renderer/android/synchronous_compositor_output_surface.h"
[email protected]eeb93112013-05-01 19:41:1097#endif
98
[email protected]661eb9d2009-02-03 02:11:4899#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:49100#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:52101#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41102#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48103#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44104
penghuang28a5fa22015-12-02 17:58:19105#if defined(MOJO_SHELL_CLIENT)
106#include "content/public/common/mojo_shell_connection.h"
fsamuel2545ecc2015-12-05 00:44:46107#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:19108#endif
109
[email protected]2255a9332013-06-17 05:12:31110#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:29111
[email protected]180ef242013-11-07 06:50:46112using blink::WebCompositionUnderline;
113using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43114using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46115using blink::WebGestureEvent;
116using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49117using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46118using blink::WebKeyboardEvent;
119using blink::WebMouseEvent;
120using blink::WebMouseWheelEvent;
121using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11122using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46123using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11124using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46125using blink::WebPopupType;
126using blink::WebRange;
127using blink::WebRect;
128using blink::WebScreenInfo;
129using blink::WebSize;
130using blink::WebTextDirection;
131using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25132using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46133using blink::WebVector;
134using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26135
danakj365175c2016-02-06 00:37:37136#define STATIC_ASSERT_ENUM(a, b) \
137 static_assert(static_cast<int>(a) == static_cast<int>(b), \
138 "mismatching enums: " #a)
139
[email protected]6a4d7f62013-01-07 21:32:13140namespace {
[email protected]b256eca2013-07-11 10:57:40141
142typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
143
144class TextInputModeMapSingleton {
145 public:
146 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22147 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40148 }
[email protected]dd705d4d2013-11-27 08:14:41149 TextInputModeMapSingleton() {
150 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
151 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
152 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
153 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
154 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
155 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
156 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
157 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
158 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
159 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
160 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40161 }
[email protected]dd705d4d2013-11-27 08:14:41162 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40163 private:
[email protected]dd705d4d2013-11-27 08:14:41164 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40165
olli.raula36aa8be2015-09-10 11:14:22166 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40167
168 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
169};
170
[email protected]dd705d4d2013-11-27 08:14:41171ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40172 static TextInputModeMapSingleton* singleton =
173 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41174 TextInputModeMap::const_iterator it =
175 singleton->map().find(input_mode.utf8());
176 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40177 return ui::TEXT_INPUT_MODE_DEFAULT;
178 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13179}
[email protected]b256eca2013-07-11 10:57:40180
fsamuel72464894f2015-12-15 06:59:31181bool IsDateTimeInput(ui::TextInputType type) {
182 return type == ui::TEXT_INPUT_TYPE_DATE ||
183 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
184 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
185 type == ui::TEXT_INPUT_TYPE_MONTH ||
186 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
dtapuskae7473612015-12-04 14:23:06187}
188
fsamuele8326c742016-01-12 00:49:39189content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
190 content::RenderWidget* widget) {
191#if defined(MOJO_SHELL_CLIENT)
penghuang639a1042016-01-14 21:25:29192 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
193 if (content::MojoShellConnection::Get() &&
194 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
[email protected]b256eca2013-07-11 10:57:40205} // namespace
206
[email protected]e9ff79c2012-10-19 21:31:26207namespace content {
[email protected]62cb33cae2009-03-27 23:30:22208
[email protected]b2e4c70132013-10-03 02:07:51209// RenderWidget ---------------------------------------------------------------
210
dcheng35d31c112015-07-22 00:17:36211RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
212 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46213 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04214 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03215 bool hidden,
216 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29217 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36218 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53219 webwidget_(nullptr),
avi40b5be7a2016-03-03 21:13:44220 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29221 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02222 top_controls_shrink_blink_size_(false),
223 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29224 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51225 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09226 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29227 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04228 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39229 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12230 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12231 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16232 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48233 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22234 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44235 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20236 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45237 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40238 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20239 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53240 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12241 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48242 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04243 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52244 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30245 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13246#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36247 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13248#endif
[email protected]b2e4c70132013-10-03 02:07:51249 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11250 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42251 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51252 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05253 if (!swapped_out)
254 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27255 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53256 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37257#if defined(OS_ANDROID)
258 text_input_info_history_.push_back(blink::WebTextInputInfo());
259#endif
alexclarke7fa93942015-10-21 15:37:11260
261 // In tests there may not be a RenderThreadImpl.
262 if (RenderThreadImpl::current()) {
263 render_widget_scheduling_state_ = RenderThreadImpl::current()
264 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32265 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11266 render_widget_scheduling_state_->SetHidden(is_hidden_);
267 }
initial.commit09911bf2008-07-26 23:55:29268}
269
270RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11271 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16272
[email protected]992db4c2011-05-12 15:37:15273 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02274 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15275 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29276}
277
[email protected]484955942010-08-19 16:13:18278// static
avi1023d012015-12-25 02:39:14279RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53280 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46281 blink::WebPopupType popup_type,
282 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29283 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36284 scoped_refptr<RenderWidget> widget(new RenderWidget(
285 compositor_deps, popup_type, screen_info, false, false, false));
286 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46287 return widget.get();
[email protected]a635f942012-12-07 10:34:29288 }
289 return NULL;
initial.commit09911bf2008-07-26 23:55:29290}
291
[email protected]484955942010-08-19 16:13:18292// static
kenrba7199832015-01-22 23:44:59293RenderWidget* RenderWidget::CreateForFrame(
294 int routing_id,
kenrba7199832015-01-22 23:44:59295 bool hidden,
296 const blink::WebScreenInfo& screen_info,
297 CompositorDependencies* compositor_deps,
298 blink::WebLocalFrame* frame) {
299 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55300 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
301 // same routing ID for both the view routing ID and the main frame widget
302 // routing ID. https://crbug.com/545684
303 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
304 if (view) {
avi8a45c1092016-03-01 16:12:34305 view->AttachWebFrameWidget(
306 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
307 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55308 }
dcheng35d31c112015-07-22 00:17:36309 scoped_refptr<RenderWidget> widget(
310 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
311 false, hidden, false));
fsamuele8326c742016-01-12 00:49:39312 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20313 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59314 // DoInit increments the reference count on |widget|, keeping it alive after
315 // this function returns.
dcheng35d31c112015-07-22 00:17:36316 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59317 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
318 nullptr)) {
kenrba7199832015-01-22 23:44:59319 return widget.get();
320 }
321 return nullptr;
322}
323
324// static
lfgcaab5142016-02-26 19:06:52325blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08326 RenderWidget* render_widget,
327 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55328 if (!frame->parent()) {
329 // TODO(dcheng): The main frame widget currently has a special case.
330 // Eliminate this once WebView is no longer a WebWidget.
331 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
332 }
dchengda9b4bb2015-07-20 20:58:08333 return blink::WebFrameWidget::create(render_widget, frame);
334}
335
336// static
kenrba7199832015-01-22 23:44:59337blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18338 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46339 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18340 break;
[email protected]180ef242013-11-07 06:50:46341 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44342 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18343 default:
344 NOTREACHED();
345 }
346 return NULL;
347}
348
dchengda9b4bb2015-07-20 20:58:08349void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32350 OnClose();
kenrba7199832015-01-22 23:44:59351}
352
fsamuele8326c742016-01-12 00:49:39353void RenderWidget::SetRoutingID(int32_t routing_id) {
354 routing_id_ = routing_id;
355 input_handler_.reset(new RenderWidgetInputHandler(
356 GetRenderWidgetInputHandlerDelegate(this), this));
357}
358
avi1023d012015-12-25 02:39:14359bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39360 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05361 opener_id, RenderWidget::CreateWebWidget(this),
362 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39363 if (success) {
364 SetRoutingID(routing_id_);
365 return true;
366 }
367 return false;
[email protected]484955942010-08-19 16:13:18368}
369
avi1023d012015-12-25 02:39:14370bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06371 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18372 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29373 DCHECK(!webwidget_);
374
375 if (opener_id != MSG_ROUTING_NONE)
376 opener_id_ = opener_id;
377
[email protected]484955942010-08-19 16:13:18378 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29379
kenrba7199832015-01-22 23:44:59380 bool result = true;
381 if (create_widget_message)
382 result = RenderThread::Get()->Send(create_widget_message);
383
initial.commit09911bf2008-07-26 23:55:29384 if (result) {
[email protected]380244092011-10-07 17:26:27385 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29386 // Take a reference on behalf of the RenderThread. This will be balanced
387 // when we receive ViewMsg_Close.
388 AddRef();
[email protected]b2db9272014-01-10 17:42:00389 if (RenderThreadImpl::current()) {
390 RenderThreadImpl::current()->WidgetCreated();
391 if (is_hidden_)
392 RenderThreadImpl::current()->WidgetHidden();
393 }
fsamuele8326c742016-01-12 00:49:39394
[email protected]a635f942012-12-07 10:34:29395 return true;
initial.commit09911bf2008-07-26 23:55:29396 } else {
[email protected]a635f942012-12-07 10:34:29397 // The above Send can fail when the tab is closing.
398 return false;
initial.commit09911bf2008-07-26 23:55:29399 }
400}
401
[email protected]992db4c2011-05-12 15:37:15402void RenderWidget::SetSwappedOut(bool is_swapped_out) {
403 // We should only toggle between states.
404 DCHECK(is_swapped_out_ != is_swapped_out);
405 is_swapped_out_ = is_swapped_out;
406
407 // If we are swapping out, we will call ReleaseProcess, allowing the process
408 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52409 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15410 // If we are swapping in, we call AddRefProcess to prevent the process from
411 // exiting.
[email protected]949b6592014-08-20 13:17:52412 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15413 RenderProcess::current()->AddRefProcess();
414}
415
[email protected]949b6592014-08-20 13:17:52416void RenderWidget::WasSwappedOut() {
417 // If we have been swapped out and no one else is using this process,
418 // it's safe to exit now.
419 CHECK(is_swapped_out_);
420 RenderProcess::current()->ReleaseProcess();
421}
422
[email protected]b2e4c70132013-10-03 02:07:51423void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39424 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51425 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43426 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49427 popup_screen_origin_for_emulation_ = gfx::Point(
428 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
429 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56430 screen_info_ = emulator->original_screen_info();
431 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51432}
433
[email protected]2d6836f42014-07-02 17:25:31434gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
435 if (screen_metrics_emulator_)
436 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
437 return anchor;
438}
439
[email protected]53907862014-03-25 15:42:40440#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51441void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39442 ExternalPopupMenu* popup,
443 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49444 popup->SetOriginScaleAndOffsetForEmulation(
445 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51446}
[email protected]53907862014-03-25 15:42:40447#endif
[email protected]b2e4c70132013-10-03 02:07:51448
449void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
450 if (screen_metrics_emulator_)
451 screen_metrics_emulator_->OnShowContextMenu(params);
452}
453
[email protected]a95986a82010-12-24 06:19:28454bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
455 bool handled = true;
456 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15457 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22458 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
459 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22460 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
461 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15462 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
463 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35464 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
465 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28466 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28467 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20468 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
469 OnEnableDeviceEmulation)
470 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
471 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41472 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54473 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28474 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41475 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25476 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28477 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
478 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03479 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05480 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
lfg43e08e62016-02-03 18:51:37481 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
482 OnWaitNextFrameForTests)
[email protected]105dffb42013-02-20 03:46:21483#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37484 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39485 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
486 OnRequestTextInputStateUpdate)
[email protected]2384b6c2013-02-28 23:58:51487 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21488#endif
dtrainor5ef644e2015-11-19 00:12:47489 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28490 IPC_MESSAGE_UNHANDLED(handled = false)
491 IPC_END_MESSAGE_MAP()
492 return handled;
493}
initial.commit09911bf2008-07-26 23:55:29494
495bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15496 // Don't send any messages after the browser has told us to close, and filter
497 // most outgoing messages while swapped out.
498 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26499 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11500 closing_) {
initial.commit09911bf2008-07-26 23:55:29501 delete message;
502 return false;
503 }
504
505 // If given a messsage without a routing ID, then assign our routing ID.
506 if (message->routing_id() == MSG_ROUTING_NONE)
507 message->set_routing_id(routing_id_);
508
[email protected]380244092011-10-07 17:26:27509 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44510}
511
bokanc007c3a2015-02-03 07:15:56512void RenderWidget::SetWindowRectSynchronously(
513 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39514 ResizeParams params;
515 params.screen_info = screen_info_;
516 params.new_size = new_window_rect.size();
517 params.physical_backing_size =
518 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
519 params.top_controls_shrink_blink_size = top_controls_shrink_blink_size_;
520 params.top_controls_height = top_controls_height_;
521 params.visible_viewport_size = new_window_rect.size();
522 params.resizer_rect = gfx::Rect();
523 params.is_fullscreen_granted = is_fullscreen_granted_;
524 params.display_mode = display_mode_;
525 params.needs_resize_ack = false;
526 Resize(params);
527
bokanc007c3a2015-02-03 07:15:56528 view_screen_rect_ = new_window_rect;
529 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02530 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56531 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02532}
533
initial.commit09911bf2008-07-26 23:55:29534void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32535 DCHECK(content::RenderThread::Get());
536 if (closing_)
537 return;
538 NotifyOnClose();
539 closing_ = true;
540
541 // Browser correspondence is no longer needed at this point.
542 if (routing_id_ != MSG_ROUTING_NONE) {
543 RenderThread::Get()->RemoveRoute(routing_id_);
544 SetHidden(false);
545 if (RenderThreadImpl::current())
546 RenderThreadImpl::current()->WidgetDestroyed();
547 }
548
549 if (for_oopif_) {
550 // Widgets for frames may be created and closed at any time while the frame
551 // is alive. However, the closing process must happen synchronously. Frame
552 // widget and frames hold pointers to each other. If Close() is deferred to
553 // the message loop like in the non-frame widget case, WebWidget::close()
554 // can end up accessing members of an already-deleted frame.
555 Close();
556 } else {
557 // If there is a Send call on the stack, then it could be dangerous to close
558 // now. Post a task that only gets invoked when there are no nested message
559 // loops.
560 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
561 FROM_HERE, base::Bind(&RenderWidget::Close, this));
562 }
563
564 // Balances the AddRef taken when we called AddRoute.
565 Release();
initial.commit09911bf2008-07-26 23:55:29566}
567
fsamuel664e8b62016-01-20 19:54:01568void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04569 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32570 return;
571
[email protected]b2e4c70132013-10-03 02:07:51572 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39573 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51574 return;
575 }
576
mfomitchev2600fd7c2016-02-17 20:53:39577 Resize(params);
initial.commit09911bf2008-07-26 23:55:29578}
579
dgozman9260b0a12015-03-16 13:45:20580void RenderWidget::OnEnableDeviceEmulation(
581 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39582 if (!screen_metrics_emulator_) {
583 ResizeParams resize_params;
584 resize_params.screen_info = screen_info_;
585 resize_params.new_size = size_;
586 resize_params.physical_backing_size = physical_backing_size_;
587 resize_params.visible_viewport_size = visible_viewport_size_;
588 resize_params.top_controls_shrink_blink_size =
589 top_controls_shrink_blink_size_;
590 resize_params.top_controls_height = top_controls_height_;
591 resize_params.resizer_rect = resizer_rect_;
592 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
593 resize_params.display_mode = display_mode_;
594 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
595 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18596 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39597 } else {
dgozman9260b0a12015-03-16 13:45:20598 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39599 }
dgozman9260b0a12015-03-16 13:45:20600}
601
602void RenderWidget::OnDisableDeviceEmulation() {
603 screen_metrics_emulator_.reset();
604}
605
noel89949e62014-09-30 01:12:41606void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
607 SetDeviceColorProfile(color_profile);
608}
609
[email protected]b5913d72012-02-07 22:26:54610void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01611 if (resizer_rect_ == resizer_rect)
612 return;
613 resizer_rect_ = resizer_rect;
614 if (webwidget_)
615 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54616}
617
initial.commit09911bf2008-07-26 23:55:29618void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31619 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29620 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03621 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59622 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
623 WasHidden());
initial.commit09911bf2008-07-26 23:55:29624}
625
[email protected]3399dd822014-08-09 11:14:24626void RenderWidget::OnWasShown(bool needs_repainting,
627 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41628 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29629 // During shutdown we can just ignore this message.
630 if (!webwidget_)
631 return;
632
633 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03634 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59635 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
636 WasShown());
initial.commit09911bf2008-07-26 23:55:29637
[email protected]8a23afb32014-04-30 22:40:23638 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29639 return;
initial.commit09911bf2008-07-26 23:55:29640
641 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24642 if (compositor_) {
643 ui::LatencyInfo swap_latency_info(latency_info);
644 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
645 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05646 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24647 }
jdduke491a3f0c2015-06-15 23:30:26648 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29649}
650
[email protected]53d3f302009-12-21 04:42:05651void RenderWidget::OnRequestMoveAck() {
652 DCHECK(pending_window_rect_count_);
653 pending_window_rect_count_--;
654}
655
[email protected]ed7defa2013-03-12 21:29:59656GURL RenderWidget::GetURLForGraphicsContext3D() {
657 return GURL();
[email protected]65225772011-05-12 21:10:24658}
659
fsamuel78f86e42016-01-20 04:10:23660void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10661 const ui::LatencyInfo& latency_info,
662 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23663 if (!input_event)
664 return;
dtapuska0bd451a2016-02-18 17:08:10665 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23666}
667
668void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
669 if (webwidget_)
670 webwidget_->setCursorVisibilityState(is_visible);
671}
672
673void RenderWidget::OnMouseCaptureLost() {
674 if (webwidget_)
675 webwidget_->mouseCaptureLost();
676}
677
678void RenderWidget::OnSetFocus(bool enable) {
679 if (webwidget_)
680 webwidget_->setFocus(enable);
681}
682
683///////////////////////////////////////////////////////////////////////////////
684// RenderWidgetCompositorDelegate
685
686void RenderWidget::ApplyViewportDeltas(
687 const gfx::Vector2dF& inner_delta,
688 const gfx::Vector2dF& outer_delta,
689 const gfx::Vector2dF& elastic_overscroll_delta,
690 float page_scale,
691 float top_controls_delta) {
692 webwidget_->applyViewportDeltas(inner_delta, outer_delta,
693 elastic_overscroll_delta, page_scale,
694 top_controls_delta);
695}
696
697void RenderWidget::BeginMainFrame(double frame_time_sec) {
698 webwidget_->beginFrame(frame_time_sec);
699}
700
[email protected]ebc0e1df2013-08-01 02:46:22701scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
piman990d8ea2016-01-12 15:35:31702 DCHECK(webwidget_);
[email protected]7912e822014-04-16 02:37:03703 // For widgets that are never visible, we don't start the compositor, so we
704 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39705 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:19706
avi83883c82014-12-23 00:08:49707 const base::CommandLine& command_line =
708 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33709 bool use_software = fallback;
710 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
711 use_software = true;
712
penghuang28a5fa22015-12-02 17:58:19713#if defined(MOJO_SHELL_CLIENT)
rockot19c030e862016-02-26 05:46:58714 if (MojoShellConnection::Get() && !use_software &&
715 command_line.HasSwitch(switches::kUseMusInRenderer)) {
penghuang28a5fa22015-12-02 17:58:19716 RenderWidgetMusConnection* connection =
717 RenderWidgetMusConnection::GetOrCreate(routing_id());
718 return connection->CreateOutputSurface();
719 }
720#endif
721
piman990d8ea2016-01-12 15:35:31722 scoped_refptr<GpuChannelHost> gpu_channel_host;
723 if (!use_software) {
724 CauseForGpuLaunch cause =
725 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
726 gpu_channel_host =
727 RenderThreadImpl::current()->EstablishGpuChannelSync(cause);
728 if (!gpu_channel_host.get()) {
729 // Cause the compositor to wait and try again.
730 return nullptr;
731 }
732 // We may get a valid channel, but with a software renderer. In that case,
733 // disable GPU compositing.
734 if (gpu_channel_host->gpu_info().software_rendering)
735 use_software = true;
736 }
737
[email protected]0634cdd42013-08-16 00:46:09738 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17739 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:33740 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09741 context_provider = ContextProviderCommandBuffer::Create(
piman990d8ea2016-01-12 15:35:31742 CreateGraphicsContext3D(gpu_channel_host.get()),
743 RENDER_COMPOSITOR_CONTEXT);
744 DCHECK(context_provider);
revemand180dfc32015-09-24 00:19:43745 worker_context_provider =
746 RenderThreadImpl::current()->SharedWorkerContextProvider();
747 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:17748 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34749 return nullptr;
vmiura78b69282015-02-14 00:01:17750 }
boliu853d46052015-10-13 20:20:06751
752#if defined(OS_ANDROID)
753 if (SynchronousCompositorFactory* factory =
754 SynchronousCompositorFactory::GetInstance()) {
755 return factory->CreateOutputSurface(
756 routing_id(), frame_swap_message_queue_, context_provider,
757 worker_context_provider);
boliubee541f42015-11-05 00:52:53758 } else if (RenderThreadImpl::current()->sync_compositor_message_filter()) {
759 return make_scoped_ptr(new SynchronousCompositorOutputSurface(
760 context_provider, worker_context_provider, routing_id(),
761 content::RenderThreadImpl::current()
762 ->sync_compositor_message_filter(),
763 frame_swap_message_queue_));
boliu853d46052015-10-13 20:20:06764 }
765#endif
[email protected]0634cdd42013-08-16 00:46:09766 }
[email protected]ebc0e1df2013-08-01 02:46:22767
avi1023d012015-12-25 02:39:14768 uint32_t output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:34769 // Composite-to-mailbox is currently used for layout tests in order to cause
770 // them to draw inside in the renderer to do the readback there. This should
771 // no longer be the case when crbug.com/311404 is fixed.
772 if (!RenderThreadImpl::current() ||
773 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:53774 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
piman8944e1c2015-09-22 21:10:34775 return make_scoped_ptr(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:17776 routing_id(), output_surface_id, context_provider,
777 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09778 }
piman8944e1c2015-09-22 21:10:34779
[email protected]0634cdd42013-08-16 00:46:09780 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:09781 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:12782 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:09783
piman8944e1c2015-09-22 21:10:34784 return make_scoped_ptr(new CompositorOutputSurface(
caseqff9c74c2015-02-10 14:56:29785 routing_id(), output_surface_id, nullptr, nullptr,
dcheng07945f632015-12-26 07:59:32786 std::move(software_device), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:22787 }
[email protected]ed7defa2013-03-12 21:29:59788
piman8944e1c2015-09-22 21:10:34789 return make_scoped_ptr(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:17790 routing_id(), output_surface_id, context_provider,
piman8944e1c2015-09-22 21:10:34791 worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:28792}
793
fsamuel78f86e42016-01-20 04:10:23794scoped_ptr<cc::BeginFrameSource>
795RenderWidget::CreateExternalBeginFrameSource() {
796 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_);
797}
798
799void RenderWidget::DidCommitAndDrawCompositorFrame() {
800 // NOTE: Tests may break if this event is renamed or moved. See
801 // tab_capture_performancetest.cc.
802 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
803 // Notify subclasses that we initiated the paint operation.
804 DidInitiatePaint();
805}
806
807void RenderWidget::DidCommitCompositorFrame() {
808 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
809 DidCommitCompositorFrame());
810 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
811 DidCommitCompositorFrame());
812#if defined(VIDEO_HOLE)
813 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
814 DidCommitCompositorFrame());
815#endif // defined(VIDEO_HOLE)
816 input_handler_->FlushPendingInputEventAck();
817}
818
819void RenderWidget::DidCompletePageScaleAnimation() {}
820
821void RenderWidget::DidCompleteSwapBuffers() {
822 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
823
824 // Notify subclasses threaded composited rendering was flushed to the screen.
825 DidFlushPaint();
826
827 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_ &&
828 !plugin_window_moves_.size()) {
829 return;
830 }
831
832 ViewHostMsg_UpdateRect_Params params;
833 params.view_size = size_;
834 params.plugin_window_moves.swap(plugin_window_moves_);
835 params.flags = next_paint_flags_;
836
837 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
838 next_paint_flags_ = 0;
839 need_update_rect_for_auto_resize_ = false;
840}
841
842bool RenderWidget::ForOOPIF() const {
843 // TODO(simonhong): Remove this when we enable BeginFrame scheduling for
844 // OOPIF(crbug.com/471411).
845 return for_oopif_;
846}
847
848void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
849 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
850}
851
852bool RenderWidget::IsClosing() const {
853 return host_closing_;
854}
855
[email protected]4d7e46a2013-11-08 05:33:40856void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24857 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:24858 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:26859 ScheduleComposite();
[email protected]65225772011-05-12 21:10:24860}
861
[email protected]4d7e46a2013-11-08 05:33:40862void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24863 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16864
[email protected]404939f2012-06-01 04:06:18865 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16866 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:29867}
868
fsamuel78f86e42016-01-20 04:10:23869void RenderWidget::OnSwapBuffersPosted() {
870 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:29871}
872
fsamuel78f86e42016-01-20 04:10:23873void RenderWidget::RecordFrameTimingEvents(
874 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
875 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
876 for (const auto& composite_event : *composite_events) {
877 int64_t frameId = composite_event.first;
878 const std::vector<cc::FrameTimingTracker::CompositeTimingEvent>& events =
879 composite_event.second;
880 std::vector<blink::WebFrameTimingEvent> webEvents;
881 for (size_t i = 0; i < events.size(); ++i) {
882 webEvents.push_back(blink::WebFrameTimingEvent(
883 events[i].frame_id,
884 (events[i].timestamp - base::TimeTicks()).InSecondsF()));
885 }
886 webwidget_->recordFrameTimingEvent(blink::WebWidget::CompositeEvent,
887 frameId, webEvents);
888 }
889 for (const auto& main_frame_event : *main_frame_events) {
890 int64_t frameId = main_frame_event.first;
891 const std::vector<cc::FrameTimingTracker::MainFrameTimingEvent>& events =
892 main_frame_event.second;
893 std::vector<blink::WebFrameTimingEvent> webEvents;
894 for (size_t i = 0; i < events.size(); ++i) {
895 webEvents.push_back(blink::WebFrameTimingEvent(
896 events[i].frame_id,
897 (events[i].timestamp - base::TimeTicks()).InSecondsF(),
898 (events[i].end_time - base::TimeTicks()).InSecondsF()));
899 }
900 webwidget_->recordFrameTimingEvent(blink::WebWidget::RenderEvent, frameId,
901 webEvents);
902 }
[email protected]34202de2013-05-06 23:36:22903}
904
danakj53eccbc2016-03-02 22:51:07905void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23906 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29907}
908
fsamuel78f86e42016-01-20 04:10:23909void RenderWidget::UpdateVisualState() {
910 webwidget_->updateAllLifecyclePhases();
911}
912
913void RenderWidget::WillBeginCompositorFrame() {
914 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
915
916 // The UpdateTextInputState can result in further layout and possibly
917 // enable GPU acceleration so they need to be called before any painting
918 // is done.
919 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
920 UpdateSelectionBounds();
lfge6119aac2016-01-27 02:14:31921
922 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
923 WillBeginCompositorFrame());
initial.commit09911bf2008-07-26 23:55:29924}
925
fsamuel72464894f2015-12-15 06:59:31926///////////////////////////////////////////////////////////////////////////////
927// RenderWidgetInputHandlerDelegate
928
avid7d6b2e2016-03-04 19:41:17929void RenderWidget::FocusChangeComplete() {
930 if (owner_delegate_)
931 owner_delegate_->RenderWidgetFocusChangeComplete();
932}
fsamuel72464894f2015-12-15 06:59:31933
934bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17935 if (owner_delegate_)
936 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
937
fsamuel72464894f2015-12-15 06:59:31938 return true;
939}
940
941void RenderWidget::ObserveWheelEventAndResult(
942 const blink::WebMouseWheelEvent& wheel_event,
943 const gfx::Vector2dF& wheel_unused_delta,
944 bool event_processed) {
945 if (!compositor_deps_->IsElasticOverscrollEnabled())
946 return;
947
948 cc::InputHandlerScrollResult scroll_result;
949 scroll_result.did_scroll = event_processed;
950 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
951 scroll_result.unused_scroll_delta = wheel_unused_delta;
952
953 RenderThreadImpl* render_thread = RenderThreadImpl::current();
954 InputHandlerManager* input_handler_manager =
955 render_thread ? render_thread->input_handler_manager() : NULL;
956 if (input_handler_manager) {
957 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
958 routing_id_, wheel_event, scroll_result);
jddukefffb67c2015-01-07 22:32:29959 }
fsamuel72464894f2015-12-15 06:59:31960}
961
dtapuska1827dd22016-03-11 15:24:59962void RenderWidget::ObserveGestureEventAndResult(
963 const blink::WebGestureEvent& gesture_event,
964 const gfx::Vector2dF& unused_delta,
965 bool event_processed) {
966 if (!compositor_deps_->IsElasticOverscrollEnabled())
967 return;
968
969 cc::InputHandlerScrollResult scroll_result;
970 scroll_result.did_scroll = event_processed;
971 scroll_result.did_overscroll_root = !unused_delta.IsZero();
972 scroll_result.unused_scroll_delta = unused_delta;
973
974 RenderThreadImpl* render_thread = RenderThreadImpl::current();
975 InputHandlerManager* input_handler_manager =
976 render_thread ? render_thread->input_handler_manager() : NULL;
977 if (input_handler_manager) {
978 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
979 routing_id_, gesture_event, scroll_result);
980 }
981}
982
avid7d6b2e2016-03-04 19:41:17983void RenderWidget::OnDidHandleKeyEvent() {
984 if (owner_delegate_)
985 owner_delegate_->RenderWidgetDidHandleKeyEvent();
986}
fsamuel72464894f2015-12-15 06:59:31987
988void RenderWidget::OnDidOverscroll(const DidOverscrollParams& params) {
989 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
990}
991
992void RenderWidget::OnInputEventAck(scoped_ptr<InputEventAck> input_event_ack) {
993 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
994}
995
dtapuska0bd451a2016-02-18 17:08:10996void RenderWidget::NonBlockingInputEventHandled(
997 blink::WebInputEvent::Type handled_type) {
998 RenderThreadImpl* render_thread = RenderThreadImpl::current();
999 InputHandlerManager* input_handler_manager =
1000 render_thread ? render_thread->input_handler_manager() : NULL;
1001 if (input_handler_manager) {
1002 input_handler_manager->NonBlockingInputEventHandledOnMainThread(
1003 routing_id_, handled_type);
1004 }
1005}
1006
fsamuele8326c742016-01-12 00:49:391007void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1008 // Nothing to do here. RenderWidget created the |input_handler| and will take
1009 // ownership of it. We just verify here that we don't already have an input
1010 // handler.
1011 DCHECK(!input_handler_);
1012}
1013
fsamuel72464894f2015-12-15 06:59:311014void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1015 ChangeSource change_source) {
1016 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1017 if (ime_event_guard_) {
1018 // show_ime should still be effective even if it was set inside the IME
1019 // event guard.
1020 if (show_ime == ShowIme::IF_NEEDED) {
1021 ime_event_guard_->set_show_ime(true);
1022 }
1023 return;
1024 }
1025
1026 ui::TextInputType new_type = GetTextInputType();
1027 if (IsDateTimeInput(new_type))
1028 return; // Not considered as a text input field in WebKit/Chromium.
1029
1030 blink::WebTextInputInfo new_info;
1031 if (webwidget_)
1032 new_info = webwidget_->textInputInfo();
1033 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1034
1035 bool new_can_compose_inline = CanComposeInline();
1036
1037 // Only sends text input params if they are changed or if the ime should be
1038 // shown.
1039 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:391040 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
fsamuel72464894f2015-12-15 06:59:311041 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1042 text_input_info_ != new_info ||
1043 can_compose_inline_ != new_can_compose_inline)
1044#if defined(OS_ANDROID)
1045 || text_field_is_dirty_
1046#endif
1047 ) {
1048 ViewHostMsg_TextInputState_Params params;
1049 params.type = new_type;
1050 params.mode = new_mode;
1051 params.flags = new_info.flags;
1052 params.value = new_info.value.utf8();
1053 params.selection_start = new_info.selectionStart;
1054 params.selection_end = new_info.selectionEnd;
1055 params.composition_start = new_info.compositionStart;
1056 params.composition_end = new_info.compositionEnd;
1057 params.can_compose_inline = new_can_compose_inline;
1058 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
1059#if defined(USE_AURA)
1060 params.is_non_ime_change = true;
1061#endif
1062#if defined(OS_ANDROID)
1063 params.is_non_ime_change =
1064 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
1065 if (params.is_non_ime_change)
1066 OnImeEventSentForAck(new_info);
1067 text_field_is_dirty_ = false;
1068#endif
1069 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1070
1071 text_input_info_ = new_info;
1072 text_input_type_ = new_type;
1073 text_input_mode_ = new_mode;
1074 can_compose_inline_ = new_can_compose_inline;
1075 text_input_flags_ = new_info.flags;
1076 }
1077}
1078
1079bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:171080 if (owner_delegate_)
1081 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
1082
fsamuel72464894f2015-12-15 06:59:311083 return false;
1084}
1085
1086bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
avid7d6b2e2016-03-04 19:41:171087 if (owner_delegate_)
1088 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1089
fsamuel72464894f2015-12-15 06:59:311090 return false;
[email protected]fd847792013-10-24 17:12:351091}
1092
initial.commit09911bf2008-07-26 23:55:291093///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391094// RenderWidgetScreenMetricsDelegate
1095
1096void RenderWidget::Redraw() {
1097 set_next_paint_is_resize_ack();
1098 if (compositor_)
1099 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1100}
1101
1102void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581103 bool orientation_changed =
1104 screen_info_.orientationAngle != params.screen_info.orientationAngle ||
1105 screen_info_.orientationType != params.screen_info.orientationType;
1106
mfomitchev2600fd7c2016-02-17 20:53:391107 screen_info_ = params.screen_info;
1108 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
1109
1110 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1111 // A resize ack shouldn't be requested if we have not ACK'd the previous
1112 // one.
1113 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1114 }
1115
1116 // Ignore this during shutdown.
1117 if (!webwidget_)
1118 return;
1119
1120 if (compositor_)
1121 compositor_->setViewportSize(params.physical_backing_size);
1122
1123 bool resized = size_ != params.new_size ||
1124 physical_backing_size_ != params.physical_backing_size;
1125
1126 size_ = params.new_size;
1127 physical_backing_size_ = params.physical_backing_size;
1128
1129 top_controls_shrink_blink_size_ = params.top_controls_shrink_blink_size;
1130 top_controls_height_ = params.top_controls_height;
1131 visible_viewport_size_ = params.visible_viewport_size;
1132 resizer_rect_ = params.resizer_rect;
1133
1134 // NOTE: We may have entered fullscreen mode without changing our size.
1135 bool fullscreen_change =
1136 is_fullscreen_granted_ != params.is_fullscreen_granted;
1137 is_fullscreen_granted_ = params.is_fullscreen_granted;
1138 display_mode_ = params.display_mode;
1139
1140 webwidget_->setTopControlsHeight(params.top_controls_height,
1141 top_controls_shrink_blink_size_);
1142
1143 if (resized) {
oshima50872a72016-03-04 13:26:181144 gfx::Size new_widget_size = size_;
1145 if (IsUseZoomForDSFEnabled()) {
1146 new_widget_size = gfx::ScaleToCeiledSize(new_widget_size,
1147 GetOriginalDeviceScaleFactor());
1148 }
mfomitchev2600fd7c2016-02-17 20:53:391149 // When resizing, we want to wait to paint before ACK'ing the resize. This
1150 // ensures that we only resize as fast as we can paint. We only need to
1151 // send an ACK if we are resized to a non-empty rect.
1152 webwidget_->resize(new_widget_size);
1153 }
1154 WebSize visual_viewport_size;
1155
1156 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181157 visual_viewport_size = gfx::ScaleToCeiledSize(
1158 params.visible_viewport_size,
1159 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391160 } else {
1161 visual_viewport_size = visible_viewport_size_;
1162 }
1163
1164 webwidget()->resizeVisualViewport(visual_viewport_size);
1165
1166 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1167 // In this case there is no paint/composite and therefore no
1168 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1169 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1170 DCHECK(!params.needs_resize_ack);
1171 }
1172
1173 // Send the Resize_ACK flag once we paint again if requested.
1174 if (params.needs_resize_ack)
1175 set_next_paint_is_resize_ack();
1176
1177 if (fullscreen_change)
1178 DidToggleFullscreen();
1179
engedy6cb63c92016-02-23 14:14:581180 if (orientation_changed)
1181 OnOrientationChange();
1182
mfomitchev2600fd7c2016-02-17 20:53:391183 // If a resize ack is requested and it isn't set-up, then no more resizes will
1184 // come in and in general things will go wrong.
1185 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1186}
1187
1188void RenderWidget::SetScreenMetricsEmulationParameters(
1189 bool enabled,
1190 const blink::WebDeviceEmulationParams& params) {
1191 // This is only supported in RenderView.
1192 NOTREACHED();
1193}
1194
1195void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1196 const gfx::Rect& window_screen_rect) {
1197 view_screen_rect_ = view_screen_rect;
1198 window_screen_rect_ = window_screen_rect;
1199}
1200
1201///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461202// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291203
[email protected]244ac1892011-12-02 17:04:471204void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima33ec97cd2015-12-14 19:40:241205 WebRect new_size_in_window(0, 0, new_size.width, new_size.height);
1206 convertViewportToWindow(&new_size_in_window);
1207 if (size_.width() != new_size_in_window.width ||
1208 size_.height() != new_size_in_window.height) {
1209 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
[email protected]20fbfc22013-05-08 20:50:581210
[email protected]5b45ad42013-10-25 00:42:041211 if (resizing_mode_selector_->is_synchronous_mode()) {
oshima33ec97cd2015-12-14 19:40:241212 gfx::Rect new_pos(rootWindowRect().x,
1213 rootWindowRect().y,
1214 size_.width(),
1215 size_.height());
[email protected]eac2b362013-05-22 07:01:451216 view_screen_rect_ = new_pos;
1217 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031218 }
[email protected]20fbfc22013-05-08 20:50:581219
[email protected]eac2b362013-05-22 07:01:451220 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581221
[email protected]5b45ad42013-10-25 00:42:041222 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581223 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091224 }
[email protected]244ac1892011-12-02 17:04:471225}
1226
[email protected]3a1c8a8032013-03-18 22:35:321227void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401228 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051229 if (compositor_)
oshima750cb4342015-10-31 00:59:011230 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051231}
1232
[email protected]e195e582013-03-08 01:32:591233void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221234 DCHECK(!host_closing_);
1235
fsamuel78f86e42016-01-20 04:10:231236 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1237 compositor_deps_);
oshima750cb4342015-10-31 00:59:011238 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331239 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391240 // For background pages and certain tests, we don't want to trigger
1241 // OutputSurface creation.
1242 if (compositor_never_visible_ || !RenderThreadImpl::current())
1243 compositor_->SetNeverVisible();
1244
pimanc4af3072015-10-02 03:45:591245 StartCompositor();
[email protected]e195e582013-03-08 01:32:591246}
1247
ennef3c58142014-12-09 21:44:381248void RenderWidget::WillCloseLayerTreeView() {
1249 if (host_closing_)
1250 return;
1251
1252 // Prevent new compositors or output surfaces from being created.
1253 host_closing_ = true;
1254
[email protected]aeeedad2014-08-22 18:16:221255 // Always send this notification to prevent new layer tree views from
1256 // being created, even if one hasn't been created yet.
1257 if (webwidget_)
1258 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221259}
1260
[email protected]180ef242013-11-07 06:50:461261blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281262 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061263}
1264
dglazkovf0e1d6d2015-10-10 02:13:481265void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1266 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1267 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1268 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1269 }
dglazkov79c426102015-08-31 21:22:431270
dglazkovf0e1d6d2015-10-10 02:13:481271 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1272 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431273}
1274
jdduke491a3f0c2015-06-15 23:30:261275void RenderWidget::ScheduleComposite() {
1276 if (compositor_ &&
1277 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1278 compositor_->setNeedsAnimate();
1279 }
1280}
1281
1282void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1283 if (compositor_) {
1284 // Regardless of whether threaded compositing is enabled, always
1285 // use this mechanism to force the compositor to redraw. However,
1286 // the invalidation code path below is still needed for the
1287 // non-threaded case.
1288 compositor_->SetNeedsForcedRedraw();
1289 }
1290 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151291}
1292
[email protected]586871b2014-07-22 17:05:111293// static
1294scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1295 IPC::Message* msg,
1296 MessageDeliveryPolicy policy,
1297 FrameSwapMessageQueue* frame_swap_message_queue,
1298 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111299 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111300 bool first_message_for_frame = false;
1301 frame_swap_message_queue->QueueMessageForFrame(policy,
1302 source_frame_number,
1303 make_scoped_ptr(msg),
1304 &first_message_for_frame);
1305 if (first_message_for_frame) {
1306 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1307 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061308 return promise;
[email protected]586871b2014-07-22 17:05:111309 }
dcheng4b6b5ff2014-10-16 00:42:061310 return nullptr;
[email protected]586871b2014-07-22 17:05:111311}
1312
1313void RenderWidget::QueueMessage(IPC::Message* msg,
1314 MessageDeliveryPolicy policy) {
1315 // RenderThreadImpl::current() is NULL in some tests.
1316 if (!compositor_ || !RenderThreadImpl::current()) {
1317 Send(msg);
1318 return;
1319 }
1320
1321 scoped_ptr<cc::SwapPromise> swap_promise =
1322 QueueMessageImpl(msg,
1323 policy,
dcheng58867a92014-08-26 02:50:221324 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111325 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111326 compositor_->GetSourceFrameNumber());
1327
1328 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321329 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351330 // Request a commit. This might either A) request a commit ahead of time
1331 // or B) request a commit which is not needed because there are not
1332 // pending updates. If B) then the commit will be skipped and the swap
1333 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1334 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1335 // can_cancel_commit is not unset.
1336 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111337 }
1338}
1339
[email protected]4873c7d2009-07-16 06:36:281340void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301341 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521342 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181343 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291344 // Only send a SetCursor message if we need to make a change.
1345 if (!current_cursor_.IsEqual(cursor)) {
1346 current_cursor_ = cursor;
1347 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1348 }
1349}
1350
1351// We are supposed to get a single call to Show for a newly created RenderWidget
1352// that was created via RenderWidget::CreateWebView. So, we wait until this
1353// point to dispatch the ShowWidget message.
1354//
1355// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281356// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291357//
[email protected]4873c7d2009-07-16 06:36:281358void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291359 DCHECK(!did_show_) << "received extraneous Show call";
1360 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1361 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1362
[email protected]8de12d942010-11-17 20:42:441363 if (did_show_)
1364 return;
1365
1366 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561367 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441368 // that's okay. It'll be ignored if as_popup is false, or the browser
1369 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561370 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1371 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291372}
1373
[email protected]4873c7d2009-07-16 06:36:281374void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291375}
1376
[email protected]2533ce12009-05-09 00:02:241377void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381378 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241379 Send(new ViewHostMsg_Close(routing_id_));
1380}
1381
dgozmancf9039cd2015-04-06 12:01:311382void RenderWidget::NotifyOnClose() {
1383 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1384}
1385
[email protected]4873c7d2009-07-16 06:36:281386void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081387 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321388 if (is_swapped_out_) {
1389 // This widget is currently swapped out, and the active widget is in a
1390 // different process. Have the browser route the close request to the
1391 // active widget instead, so that the correct unload handlers are run.
1392 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1393 return;
1394 }
1395
initial.commit09911bf2008-07-26 23:55:291396 // If a page calls window.close() twice, we'll end up here twice, but that's
1397 // OK. It is safe to send multiple Close messages.
1398
[email protected]2533ce12009-05-09 00:02:241399 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1400 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1401 // could be closed before the JS finishes executing. So instead, post a
1402 // message back to the message loop, which won't run until the JS is
1403 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081404 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211405 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291406}
1407
[email protected]9017d7852013-11-21 17:47:351408void RenderWidget::QueueSyntheticGesture(
1409 scoped_ptr<SyntheticGestureParams> gesture_params,
1410 const SyntheticGestureCompletionCallback& callback) {
1411 DCHECK(!callback.is_null());
1412
1413 pending_synthetic_gesture_callbacks_.push(callback);
1414
1415 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321416 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351417
1418 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1419}
1420
initial.commit09911bf2008-07-26 23:55:291421void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031422 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381423 WillCloseLayerTreeView();
1424 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291425 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281426 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291427 webwidget_ = NULL;
1428 }
1429}
1430
[email protected]4873c7d2009-07-16 06:36:281431WebRect RenderWidget::windowRect() {
1432 if (pending_window_rect_count_)
1433 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241434
[email protected]80ad8622012-11-07 16:33:031435 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291436}
1437
[email protected]180ef242013-11-07 06:50:461438void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301439 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541440 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301441}
1442
oshima33ec97cd2015-12-14 19:40:241443void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1444 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511445 if (popup_origin_scale_for_emulation_) {
1446 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561447 window_rect.x = popup_screen_origin_for_emulation_.x() +
1448 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1449 window_rect.y = popup_screen_origin_for_emulation_.y() +
1450 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511451 }
1452
[email protected]5b45ad42013-10-25 00:42:041453 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201454 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561455 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1456 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031457 } else {
bokanc007c3a2015-02-03 07:15:561458 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031459 }
initial.commit09911bf2008-07-26 23:55:291460 } else {
bokanc007c3a2015-02-03 07:15:561461 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291462 }
1463}
1464
[email protected]2533ce12009-05-09 00:02:241465void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1466 pending_window_rect_ = rect;
1467 pending_window_rect_count_++;
1468}
1469
[email protected]4873c7d2009-07-16 06:36:281470WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241471 if (pending_window_rect_count_) {
1472 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1473 // the RootWindowRect is probably going to return wrong results since the
1474 // browser may not have processed the Move yet. There isn't really anything
1475 // good to do in this case, and it shouldn't happen - since this size is
1476 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281477 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241478 }
1479
[email protected]80ad8622012-11-07 16:33:031480 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371481}
1482
[email protected]4873c7d2009-07-16 06:36:281483WebRect RenderWidget::windowResizerRect() {
1484 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191485}
1486
[email protected]fa7b1dc2010-06-23 17:53:041487void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261488 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041489 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071490 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041491 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131492 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281493 return;
[email protected]66fca5bc2013-05-23 06:58:291494 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361495 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041496 text, WebVector<WebCompositionUnderline>(underlines),
1497 selection_start, selection_end)) {
1498 // If we failed to set the composition text, then we need to let the browser
1499 // process to cancel the input method's ongoing composition session, to make
1500 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221501 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261502 }
[email protected]88dbe32f2013-06-20 23:31:361503 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041504}
1505
[email protected]fcf75d42013-12-03 20:11:261506void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511507 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021508 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131509 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041510 return;
[email protected]66fca5bc2013-05-23 06:58:291511 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391512 input_handler_->set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021513 if (text.length())
1514 webwidget_->confirmComposition(text);
1515 else if (keep_selection)
1516 webwidget_->confirmComposition(WebWidget::KeepSelection);
1517 else
1518 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391519 input_handler_->set_handling_input_event(false);
[email protected]88dbe32f2013-06-20 23:31:361520 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291521}
1522
oshimad5279032015-12-16 18:22:331523void RenderWidget::OnDeviceScaleFactorChanged() {
1524 if (!compositor_)
1525 return;
oshimad5279032015-12-16 18:22:331526 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181527 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331528 else
1529 compositor_->setDeviceScaleFactor(device_scale_factor_);
1530}
1531
[email protected]0bc1f572013-04-17 01:46:311532void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121533 // During shutdown we can just ignore this message.
1534 if (!webwidget_)
1535 return;
1536
[email protected]0bc1f572013-04-17 01:46:311537 // Even if the browser provides an empty damage rect, it's still expecting to
1538 // receive a repaint ack so just damage the entire widget bounds.
1539 if (size_to_paint.IsEmpty()) {
1540 size_to_paint = size_;
1541 }
1542
[email protected]ec7dc112008-08-06 05:30:121543 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051544 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311545 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121546}
1547
[email protected]79fa22e2013-08-23 15:18:121548void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351549 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1550
1551 pending_synthetic_gesture_callbacks_.front().Run();
1552 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271553}
1554
[email protected]4873c7d2009-07-16 06:36:281555void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111556 if (!webwidget_)
1557 return;
[email protected]4873c7d2009-07-16 06:36:281558 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111559}
1560
[email protected]80ad8622012-11-07 16:33:031561void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1562 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511563 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391564 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1565 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511566 } else {
mfomitchev2600fd7c2016-02-17 20:53:391567 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511568 }
[email protected]80ad8622012-11-07 16:33:031569 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1570}
1571
lfgdb5c4ed2016-03-04 23:09:071572void RenderWidget::OnUpdateWindowScreenRect(
1573 const gfx::Rect& window_screen_rect) {
1574 if (screen_metrics_emulator_) {
1575 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
1576 } else {
1577 window_screen_rect_ = window_screen_rect;
1578 }
1579}
1580
kenrbb4e2a3b2015-05-14 15:05:051581void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1582 if (compositor_)
1583 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1584}
1585
dtrainor5ef644e2015-11-19 00:12:471586void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1587 if (compositor_)
1588 compositor_->OnHandleCompositorProto(proto);
1589}
1590
[email protected]adb362312014-06-28 06:04:241591void RenderWidget::showImeIfNeeded() {
1592 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131593}
1594
fsamuel72464894f2015-12-15 06:59:311595ui::TextInputType RenderWidget::GetTextInputType() {
1596 if (webwidget_)
1597 return WebKitToUiTextInputType(webwidget_->textInputType());
1598 return ui::TEXT_INPUT_TYPE_NONE;
1599}
1600
1601void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
fsamuel72464894f2015-12-15 06:59:311602 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1603 gfx::Range range = gfx::Range();
1604 if (should_update_range) {
1605 GetCompositionRange(&range);
1606 } else {
1607 range = composition_range_;
1608 }
1609 std::vector<gfx::Rect> character_bounds;
1610 GetCompositionCharacterBounds(&character_bounds);
1611
1612 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1613 return;
1614 composition_character_bounds_ = character_bounds;
1615 composition_range_ = range;
1616 Send(new InputHostMsg_ImeCompositionRangeChanged(
1617 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311618}
1619
oshimaf866dab2015-12-05 00:41:541620void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1621 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181622 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331623 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541624 // anchor element can be placed at half pixel.
1625 gfx::Rect window_rect =
1626 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1627 rect->x = window_rect.x();
1628 rect->y = window_rect.y();
1629 rect->width = window_rect.width();
1630 rect->height = window_rect.height();
1631 }
1632}
1633
oshimaa6985b62016-01-27 08:58:301634void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1635 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181636 rect->x *= GetOriginalDeviceScaleFactor();
1637 rect->y *= GetOriginalDeviceScaleFactor();
1638 rect->width *= GetOriginalDeviceScaleFactor();
1639 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301640 }
1641}
1642
[email protected]adb362312014-06-28 06:04:241643void RenderWidget::OnShowImeIfNeeded() {
1644#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311645 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241646#endif
rouslanf7ebd8832015-01-22 01:54:141647
1648// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1649// virtual keyboard.
1650#if !defined(OS_ANDROID)
1651 FocusChangeComplete();
1652#endif
[email protected]adb362312014-06-28 06:04:241653}
1654
1655#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371656void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1657 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131658}
1659
1660void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371661 DCHECK_GE(text_input_info_history_.size(), 1u);
1662 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511663}
changwan8c342742016-02-26 00:53:391664
1665void RenderWidget::OnRequestTextInputStateUpdate() {
1666 DCHECK(!ime_event_guard_);
1667 UpdateSelectionBounds();
1668 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1669}
[email protected]105dffb42013-02-20 03:46:211670#endif
1671
[email protected]0d1ebed12013-08-05 22:01:131672bool RenderWidget::ShouldHandleImeEvent() {
1673#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371674 if (!webwidget_)
1675 return false;
changwan8c342742016-02-26 00:53:391676 if (IsUsingImeThread())
1677 return true;
changwan3a841162015-08-11 02:53:371678
1679 // We cannot handle IME events if there is any chance that the event we are
1680 // receiving here from the browser is based on the state that is different
1681 // from our current one as indicated by |text_input_info_|.
1682 // The states the browser might be in are:
1683 // text_input_info_history_[0] - current state ack'd by browser
1684 // text_input_info_history_[1...N] - pending state changes
1685 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1686 if (text_input_info_history_[i] != text_input_info_)
1687 return false;
1688 }
1689 return true;
[email protected]0d1ebed12013-08-05 22:01:131690#else
1691 return !!webwidget_;
1692#endif
1693}
1694
[email protected]468ac582012-11-20 00:53:191695void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1696 if (device_scale_factor_ == device_scale_factor)
1697 return;
1698
1699 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331700
1701 OnDeviceScaleFactorChanged();
1702
jdduke491a3f0c2015-06-15 23:30:261703 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191704}
1705
[email protected]28ed6b32014-06-08 02:16:271706bool RenderWidget::SetDeviceColorProfile(
1707 const std::vector<char>& color_profile) {
1708 if (device_color_profile_ == color_profile)
1709 return false;
1710
1711 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271712
avi40b5be7a2016-03-03 21:13:441713 if (owner_delegate_)
1714 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1715
1716 return true;
noeldb4df152014-09-16 17:45:201717}
1718
[email protected]fcdc5642014-05-09 14:32:241719void RenderWidget::OnOrientationChange() {
1720}
1721
avib9dbd972016-03-08 18:19:321722void RenderWidget::DidInitiatePaint() {
1723 if (owner_delegate_)
1724 owner_delegate_->RenderWidgetDidCommitAndDrawCompositorFrame();
1725}
1726
1727void RenderWidget::DidFlushPaint() {
1728 if (owner_delegate_)
1729 owner_delegate_->RenderWidgetDidFlushPaint();
1730}
1731
[email protected]ceb36f7d2012-10-31 18:33:241732gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521733 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241734 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521735}
1736
[email protected]bee16aab2009-08-26 15:55:031737void RenderWidget::SetHidden(bool hidden) {
1738 if (is_hidden_ == hidden)
1739 return;
1740
jdduke8fac9d102014-12-20 02:40:131741 // The status has changed. Tell the RenderThread about it and ensure
1742 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031743 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391744 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131745
[email protected]bee16aab2009-08-26 15:55:031746 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001747 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031748 else
[email protected]b2db9272014-01-10 17:42:001749 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111750
1751 if (render_widget_scheduling_state_)
1752 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031753}
1754
[email protected]2b624c562011-10-27 22:58:261755void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261756 if (!webwidget_)
1757 return;
1758
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121759 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261760 webwidget_->didEnterFullScreen();
1761 } else {
1762 webwidget_->didExitFullScreen();
1763 }
[email protected]2b624c562011-10-27 22:58:261764}
1765
[email protected]674741932009-02-04 23:44:461766bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051767 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461768}
1769
[email protected]674741932009-02-04 23:44:461770void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051771 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461772}
1773
[email protected]674741932009-02-04 23:44:461774void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051775 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461776}
1777
changwan8c342742016-02-26 00:53:391778bool RenderWidget::IsUsingImeThread() {
1779#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121780 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391781#else
1782 return false;
1783#endif
1784}
1785
changwanf2a707b2015-10-30 08:22:161786void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1787 if (!ime_event_guard_)
1788 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291789}
1790
changwanf2a707b2015-10-30 08:22:161791void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1792 if (ime_event_guard_ != guard) {
1793#if defined(OS_ANDROID)
1794 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1795 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391796 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161797 // Therefore, we want to mark this text state update as 'from IME' only
1798 // when all the nested events are all originating from IME.
1799 ime_event_guard_->set_from_ime(
1800 ime_event_guard_->from_ime() && guard->from_ime());
1801#endif
1802 return;
1803 }
1804 ime_event_guard_ = nullptr;
1805
[email protected]66fca5bc2013-05-23 06:58:291806 // While handling an ime event, text input state and selection bounds updates
1807 // are ignored. These must explicitly be updated once finished handling the
1808 // ime event.
1809 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471810#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161811 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311812 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1813 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471814#endif
[email protected]66fca5bc2013-05-23 06:58:291815}
1816
[email protected]7c8873e2013-02-05 08:03:011817void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1818 WebRect focus_webrect;
1819 WebRect anchor_webrect;
1820 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241821 convertViewportToWindow(&focus_webrect);
1822 convertViewportToWindow(&anchor_webrect);
1823 *focus = focus_webrect;
1824 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321825}
1826
[email protected]e99ef6f2011-10-16 01:13:001827void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081828 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001829 if (!webwidget_)
1830 return;
changwanf2a707b2015-10-30 08:22:161831 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291832 return;
[email protected]e99ef6f2011-10-16 01:13:001833
mohsenb0eeba72015-08-09 06:20:081834#if defined(USE_AURA)
1835 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1836 // Aura beucause composited selection updates are not working for webview tags
1837 // which regresses IME inside webview. Remove this when composited selection
1838 // updates are fixed for webviews. See, http://crbug.com/510568.
1839 bool send_ipc = true;
1840#else
jddukeacf809e2014-09-23 20:38:381841 // With composited selection updates, the selection bounds will be reported
1842 // directly by the compositor, in which case explicit IPC selection
1843 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081844 bool send_ipc =
1845 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1846#endif
1847 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381848 ViewHostMsg_SelectionBounds_Params params;
1849 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1850 if (selection_anchor_rect_ != params.anchor_rect ||
1851 selection_focus_rect_ != params.focus_rect) {
1852 selection_anchor_rect_ = params.anchor_rect;
1853 selection_focus_rect_ = params.focus_rect;
1854 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1855 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1856 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1857 }
[email protected]58b48a0d2012-06-13 07:01:351858 }
jddukeacf809e2014-09-23 20:38:381859
[email protected]88dbe32f2013-06-20 23:31:361860 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001861}
1862
avi40b5be7a2016-03-03 21:13:441863void RenderWidget::SetDeviceColorProfileForTesting(
1864 const std::vector<char>& color_profile) {
1865 SetDeviceColorProfile(color_profile);
1866}
1867
1868void RenderWidget::ResetDeviceColorProfileForTesting() {
1869 std::vector<char> color_profile;
1870 color_profile.push_back('0');
1871 SetDeviceColorProfile(color_profile);
1872}
1873
[email protected]180ef242013-11-07 06:50:461874// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
danakj365175c2016-02-06 00:37:371875STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1876STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1877STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1878 ui::TEXT_INPUT_TYPE_PASSWORD);
1879STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1880STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1881STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1882STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1883 ui::TEXT_INPUT_TYPE_TELEPHONE);
1884STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1885STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1886STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1887 ui::TEXT_INPUT_TYPE_DATE_TIME);
1888STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1889 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1890STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1891STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1892STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1893STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1894 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1895STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1896 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1897STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1898 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451899
[email protected]5b739cb2012-08-21 20:35:211900ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461901 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211902 // Check the type is in the range representable by ui::TextInputType.
1903 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461904 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211905 return static_cast<ui::TextInputType>(type);
1906}
1907
[email protected]58b48a0d2012-06-13 07:01:351908void RenderWidget::GetCompositionCharacterBounds(
1909 std::vector<gfx::Rect>* bounds) {
1910 DCHECK(bounds);
1911 bounds->clear();
1912}
1913
[email protected]db4fc1e2013-09-06 20:01:511914void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:361915 size_t location, length;
1916 if (webwidget_->compositionRange(&location, &length)) {
1917 range->set_start(location);
1918 range->set_end(location + length);
1919 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1920 range->set_start(location);
1921 range->set_end(location + length);
1922 } else {
[email protected]db4fc1e2013-09-06 20:01:511923 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:361924 }
1925}
1926
[email protected]501ea13d2013-07-09 17:03:291927bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511928 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291929 const std::vector<gfx::Rect>& bounds) {
1930 if (composition_range_ != range)
1931 return true;
1932 if (bounds.size() != composition_character_bounds_.size())
1933 return true;
1934 for (size_t i = 0; i < bounds.size(); ++i) {
1935 if (bounds[i] != composition_character_bounds_[i])
1936 return true;
1937 }
1938 return false;
1939}
[email protected]501ea13d2013-07-09 17:03:291940
[email protected]ad26ef42011-06-17 07:59:451941bool RenderWidget::CanComposeInline() {
1942 return true;
[email protected]56ea1a62011-05-30 07:05:571943}
1944
[email protected]4873c7d2009-07-16 06:36:281945WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041946 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281947}
1948
[email protected]fa7b1dc2010-06-23 17:53:041949void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021950 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041951 // If the last text input type is not None, then we should finish any
1952 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451953 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041954 // If a composition text exists, then we need to let the browser process
1955 // to cancel the input method's ongoing composition session.
1956 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:221957 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041958 }
[email protected]d4cff272011-05-02 15:46:011959
[email protected]88dbe32f2013-06-20 23:31:361960 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041961}
1962
donnda070f3c2015-01-16 19:54:111963#if defined(OS_ANDROID)
1964void RenderWidget::showUnhandledTapUIIfNeeded(
1965 const WebPoint& tapped_position,
1966 const WebNode& tapped_node,
1967 bool page_changed) {
fsamuele8326c742016-01-12 00:49:391968 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:111969 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371970 !tapped_node.isContentEditable() &&
1971 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111972 if (should_trigger) {
1973 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1974 tapped_position.x, tapped_position.y));
1975 }
1976}
1977#endif
1978
[email protected]c68c3e4e2013-01-24 00:36:561979void RenderWidget::didHandleGestureEvent(
1980 const WebGestureEvent& event,
1981 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021982#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561983 if (event_cancelled)
1984 return;
[email protected]07c70d22014-08-21 08:33:461985 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:311986 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461987 } else if (event.type == WebInputEvent::GestureLongPress) {
1988 DCHECK(webwidget_);
1989 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:311990 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461991 else
fsamuel72464894f2015-12-15 06:59:311992 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:561993 }
1994#endif
1995}
1996
sataya.m582c9ce2015-06-09 08:03:421997void RenderWidget::didOverscroll(
1998 const blink::WebFloatSize& unusedDelta,
1999 const blink::WebFloatSize& accumulatedRootOverScroll,
2000 const blink::WebFloatPoint& position,
2001 const blink::WebFloatSize& velocity) {
fsamuele8326c742016-01-12 00:49:392002 input_handler_->DidOverscrollFromBlink(unusedDelta, accumulatedRootOverScroll,
2003 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422004}
2005
[email protected]7912e822014-04-16 02:37:032006void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392007 if (!is_hidden())
2008 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032009}
2010
[email protected]29e2fb42013-07-19 01:13:472011void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292012 size_t i = 0;
2013 for (; i < plugin_window_moves_.size(); ++i) {
2014 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582015 if (move.rects_valid) {
2016 plugin_window_moves_[i] = move;
2017 } else {
2018 plugin_window_moves_[i].visible = move.visible;
2019 }
initial.commit09911bf2008-07-26 23:55:292020 break;
2021 }
2022 }
2023
2024 if (i == plugin_window_moves_.size())
2025 plugin_window_moves_.push_back(move);
2026}
[email protected]268654772009-08-06 23:02:042027
2028void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2029 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2030 i != plugin_window_moves_.end(); ++i) {
2031 if (i->window == window) {
2032 plugin_window_moves_.erase(i);
2033 break;
2034 }
2035 }
2036}
[email protected]67bfb83f2011-09-22 03:36:372037
[email protected]63b465922012-09-06 02:04:522038
[email protected]24ed0432013-04-24 07:50:312039RenderWidgetCompositor* RenderWidget::compositor() const {
2040 return compositor_.get();
2041}
2042
fsamuel72464894f2015-12-15 06:59:312043void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392044 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372045}
[email protected]c3d45532011-10-07 19:20:402046
fsamuel72464894f2015-12-15 06:59:312047bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392048 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242049}
2050
fsamuel72464894f2015-12-15 06:59:312051void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392052 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312053}
2054
[email protected]ce6689f2013-03-29 12:52:552055void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112056 if (render_widget_scheduling_state_)
2057 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552058 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2059}
2060
danakj365175c2016-02-06 00:37:372061// Check blink::WebTouchAction and content::TouchAction is kept in sync.
2062STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
2063STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
2064STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
2065STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
2066STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
2067STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
2068STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
2069STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
2070STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
2071STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
2072 TOUCH_ACTION_MANIPULATION);
2073STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2074 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2075STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
mostynbe29b6882015-01-13 09:59:172076
[email protected]5d0bbdfa92013-12-10 00:35:512077void RenderWidget::setTouchAction(
2078 blink::WebTouchAction web_touch_action) {
2079
2080 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2081 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392082 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512083 return;
2084
[email protected]a18f67a2013-12-20 19:44:362085 content::TouchAction content_touch_action =
2086 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512087 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2088}
2089
[email protected]90f24152014-04-09 12:41:362090void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2091#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392092 if (!IsUsingImeThread())
2093 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362094#endif
2095}
2096
[email protected]0634cdd42013-08-16 00:46:092097scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
piman990d8ea2016-01-12 15:35:312098RenderWidget::CreateGraphicsContext3D(GpuChannelHost* gpu_channel_host) {
[email protected]828a3932014-04-02 14:43:132099 // Explicitly disable antialiasing for the compositor. As of the time of
2100 // this writing, the only platform that supported antialiasing for the
2101 // compositor was Mac OS X, because the on-screen OpenGL context creation
2102 // code paths on Windows and Linux didn't yet have multisampling support.
2103 // Mac OS X essentially always behaves as though it's rendering offscreen.
2104 // Multisampling has a heavy cost especially on devices with relatively low
2105 // fill rate like most notebooks, and the Mac implementation would need to
2106 // be optimized to resolve directly into the IOSurface shared between the
2107 // GPU and browser processes. For these reasons and to avoid platform
2108 // disparities we explicitly disable antialiasing.
2109 blink::WebGraphicsContext3D::Attributes attributes;
2110 attributes.antialias = false;
2111 attributes.shareResources = true;
2112 attributes.noAutomaticFlushes = true;
2113 attributes.depth = false;
2114 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132115 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292116 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012117#if defined(OS_ANDROID)
boliu853d46052015-10-13 20:20:062118 bool using_synchronous_compositing =
boliubee541f42015-11-05 00:52:532119 SynchronousCompositorFactory::GetInstance() ||
2120 base::CommandLine::ForCurrentProcess()->HasSwitch(
2121 switches::kIPCSyncCompositing);
[email protected]b6eb8e332013-09-10 00:51:012122 // If we raster too fast we become upload bound, and pending
2123 // uploads consume memory. For maximum upload throughput, we would
2124 // want to allow for upload_throughput * pipeline_time of pending
2125 // uploads, after which we are just wasting memory. Since we don't
2126 // know our upload throughput yet, this just caps our memory usage.
boliu853d46052015-10-13 20:20:062127 // Synchronous compositor uses half because synchronous compositor
2128 // pipeline is only one frame deep. But twice of half for low end
2129 // because 16bit texture is not supported.
2130 size_t divider = using_synchronous_compositing ? 2 : 1;
[email protected]35b4f0c2014-06-26 16:55:272131 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032132 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012133 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032134 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012135 // Deadline to draw a frame to achieve 60 frames per second.
2136 const size_t kMillisecondsPerFrame = 16;
2137 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032138 size_t max_transfer_buffer_usage_mb =
2139 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2140 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012141 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2142 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292143 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032144 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012145#endif
piman990d8ea2016-01-12 15:35:312146 limits.command_buffer_size = 64 * 1024;
2147 limits.start_transfer_buffer_size = 64 * 1024;
2148 limits.min_transfer_buffer_size = 64 * 1024;
[email protected]96ab016c2013-10-23 00:50:292149
piman990d8ea2016-01-12 15:35:312150 return make_scoped_ptr(new WebGraphicsContext3DCommandBufferImpl(
2151 0, GetURLForGraphicsContext3D(), gpu_channel_host, attributes,
piman08f75532015-10-05 18:58:012152 lose_context_when_out_of_memory, limits, NULL));
[email protected]ed7defa2013-03-12 21:29:592153}
2154
[email protected]e3244ed2014-06-20 20:04:272155void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2156 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162157}
2158
[email protected]e3244ed2014-06-20 20:04:272159void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2160 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162161}
2162
[email protected]de3c5d82014-05-28 22:12:592163void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2164 render_frames_.AddObserver(frame);
2165}
2166
2167void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2168 render_frames_.RemoveObserver(frame);
2169}
2170
[email protected]a017938b2014-05-27 21:17:172171#if defined(VIDEO_HOLE)
2172void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2173 video_hole_frames_.AddObserver(frame);
2174}
2175
2176void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2177 video_hole_frames_.RemoveObserver(frame);
2178}
2179#endif // defined(VIDEO_HOLE)
2180
lfg43e08e62016-02-03 18:51:372181void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2182 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2183 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2184}
2185
oshima50872a72016-03-04 13:26:182186float RenderWidget::GetOriginalDeviceScaleFactor() const {
2187 return
2188 screen_metrics_emulator_ ?
2189 screen_metrics_emulator_->original_screen_info().deviceScaleFactor :
2190 device_scale_factor_;
2191}
2192
[email protected]e9ff79c2012-10-19 21:31:262193} // namespace content