blob: 9f897771f495ff5c8aab603d52546a42915d1bba [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
dchengcedca5612016-04-09 01:40:157#include <memory>
dcheng07945f632015-12-26 07:59:328#include <utility>
9
[email protected]c27dd4f2014-05-22 18:05:1910#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2111#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0012#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1213#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/logging.h"
avi1023d012015-12-25 02:39:1415#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1516#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4017#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3018#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2120#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0021#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2722#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0123#include "base/trace_event/trace_event.h"
24#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5226#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3327#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3028#include "cc/output/output_surface.h"
fsamuel78f86e42016-01-20 04:10:2329#include "cc/scheduler/begin_frame_source.h"
[email protected]556fd292013-03-18 08:03:0430#include "cc/trees/layer_tree_host.h"
alexclarke7fa93942015-10-21 15:37:1131#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2132#include "components/scheduler/renderer/renderer_scheduler.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"
fsamuelc28d985e2016-03-22 23:05:0236#include "content/common/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3537#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4438#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1539#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1540#include "content/common/swapped_out_messages.h"
ekaramad2bd4a2f2016-04-06 20:12:4641#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5042#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1243#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2944#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4245#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4046#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3947#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
[email protected]b2e4c70132013-10-03 02:07:5148#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5949#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2950#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1151#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5952#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1153#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2854#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2955#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1356#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3257#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1658#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2759#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0560#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4461#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5562#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4463#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0964#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0465#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1866#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4867#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1868#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3069#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1170#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3071#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1872#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3073#include "third_party/WebKit/public/platform/WebSize.h"
74#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4375#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5976#include "third_party/WebKit/public/web/WebFrameWidget.h"
77#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1178#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3179#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3180#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
81#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3882#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5983#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4184#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1385#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5086#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0987#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3288#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4889#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2790#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4191#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4892
[email protected]eeb93112013-05-01 19:41:1093#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1594#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0795#include "content/renderer/android/synchronous_compositor_factory.h"
boliubee541f42015-11-05 00:52:5396#include "content/renderer/android/synchronous_compositor_filter.h"
97#include "content/renderer/android/synchronous_compositor_output_surface.h"
[email protected]eeb93112013-05-01 19:41:1098#endif
99
[email protected]661eb9d2009-02-03 02:11:48100#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:49101#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:52102#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41103#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48104#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44105
penghuang28a5fa22015-12-02 17:58:19106#if defined(MOJO_SHELL_CLIENT)
107#include "content/public/common/mojo_shell_connection.h"
fsamuel2545ecc2015-12-05 00:44:46108#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:19109#endif
110
dyen136e05c2016-04-06 22:28:27111#if defined(ENABLE_VULKAN)
112#include "cc/output/vulkan_in_process_context_provider.h"
113#endif
114
[email protected]2255a9332013-06-17 05:12:31115#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:29116
[email protected]180ef242013-11-07 06:50:46117using blink::WebCompositionUnderline;
118using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43119using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46120using blink::WebGestureEvent;
121using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49122using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46123using blink::WebKeyboardEvent;
124using blink::WebMouseEvent;
125using blink::WebMouseWheelEvent;
126using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11127using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46128using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11129using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46130using blink::WebPopupType;
131using blink::WebRange;
132using blink::WebRect;
133using blink::WebScreenInfo;
134using blink::WebSize;
135using blink::WebTextDirection;
136using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25137using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46138using blink::WebVector;
139using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26140
danakj365175c2016-02-06 00:37:37141#define STATIC_ASSERT_ENUM(a, b) \
142 static_assert(static_cast<int>(a) == static_cast<int>(b), \
143 "mismatching enums: " #a)
144
[email protected]6a4d7f62013-01-07 21:32:13145namespace {
[email protected]b256eca2013-07-11 10:57:40146
147typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
148
149class TextInputModeMapSingleton {
150 public:
151 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22152 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40153 }
[email protected]dd705d4d2013-11-27 08:14:41154 TextInputModeMapSingleton() {
155 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
156 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
157 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
158 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
159 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
160 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
161 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
162 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
163 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
164 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
165 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40166 }
[email protected]dd705d4d2013-11-27 08:14:41167 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40168 private:
[email protected]dd705d4d2013-11-27 08:14:41169 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40170
olli.raula36aa8be2015-09-10 11:14:22171 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40172
173 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
174};
175
[email protected]dd705d4d2013-11-27 08:14:41176ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40177 static TextInputModeMapSingleton* singleton =
178 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41179 TextInputModeMap::const_iterator it =
180 singleton->map().find(input_mode.utf8());
181 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40182 return ui::TEXT_INPUT_MODE_DEFAULT;
183 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13184}
[email protected]b256eca2013-07-11 10:57:40185
fsamuel72464894f2015-12-15 06:59:31186bool IsDateTimeInput(ui::TextInputType type) {
187 return type == ui::TEXT_INPUT_TYPE_DATE ||
188 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
189 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
190 type == ui::TEXT_INPUT_TYPE_MONTH ||
191 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
dtapuskae7473612015-12-04 14:23:06192}
193
fsamuele8326c742016-01-12 00:49:39194content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
195 content::RenderWidget* widget) {
196#if defined(MOJO_SHELL_CLIENT)
penghuang639a1042016-01-14 21:25:29197 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
198 if (content::MojoShellConnection::Get() &&
199 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39200 return content::RenderWidgetMusConnection::GetOrCreate(
201 widget->routing_id());
202 }
203#endif
204 // If we don't have a connection to the Mojo shell, then we want to route IPCs
205 // back to the browser process rather than Mus so we use the |widget| as the
206 // RenderWidgetInputHandlerDelegate.
207 return widget;
208}
209
[email protected]b256eca2013-07-11 10:57:40210} // namespace
211
[email protected]e9ff79c2012-10-19 21:31:26212namespace content {
[email protected]62cb33cae2009-03-27 23:30:22213
[email protected]b2e4c70132013-10-03 02:07:51214// RenderWidget ---------------------------------------------------------------
215
dcheng35d31c112015-07-22 00:17:36216RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
217 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46218 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04219 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03220 bool hidden,
221 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29222 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36223 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53224 webwidget_(nullptr),
avi40b5be7a2016-03-03 21:13:44225 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29226 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02227 top_controls_shrink_blink_size_(false),
228 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29229 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51230 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09231 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29232 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04233 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39234 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12235 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12236 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16237 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48238 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22239 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44240 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20241 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45242 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40243 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20244 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53245 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12246 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48247 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04248 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52249 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30250 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13251#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36252 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13253#endif
[email protected]b2e4c70132013-10-03 02:07:51254 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11255 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42256 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51257 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05258 if (!swapped_out)
259 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27260 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53261 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37262#if defined(OS_ANDROID)
263 text_input_info_history_.push_back(blink::WebTextInputInfo());
264#endif
alexclarke7fa93942015-10-21 15:37:11265
266 // In tests there may not be a RenderThreadImpl.
267 if (RenderThreadImpl::current()) {
268 render_widget_scheduling_state_ = RenderThreadImpl::current()
269 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32270 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11271 render_widget_scheduling_state_->SetHidden(is_hidden_);
272 }
initial.commit09911bf2008-07-26 23:55:29273}
274
275RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11276 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16277
[email protected]992db4c2011-05-12 15:37:15278 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02279 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15280 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29281}
282
[email protected]484955942010-08-19 16:13:18283// static
avi1023d012015-12-25 02:39:14284RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53285 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46286 blink::WebPopupType popup_type,
287 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29288 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36289 scoped_refptr<RenderWidget> widget(new RenderWidget(
290 compositor_deps, popup_type, screen_info, false, false, false));
291 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46292 return widget.get();
[email protected]a635f942012-12-07 10:34:29293 }
294 return NULL;
initial.commit09911bf2008-07-26 23:55:29295}
296
[email protected]484955942010-08-19 16:13:18297// static
kenrba7199832015-01-22 23:44:59298RenderWidget* RenderWidget::CreateForFrame(
299 int routing_id,
kenrba7199832015-01-22 23:44:59300 bool hidden,
301 const blink::WebScreenInfo& screen_info,
302 CompositorDependencies* compositor_deps,
303 blink::WebLocalFrame* frame) {
304 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55305 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
306 // same routing ID for both the view routing ID and the main frame widget
307 // routing ID. https://crbug.com/545684
308 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
309 if (view) {
avi8a45c1092016-03-01 16:12:34310 view->AttachWebFrameWidget(
311 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
312 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55313 }
dcheng35d31c112015-07-22 00:17:36314 scoped_refptr<RenderWidget> widget(
315 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
316 false, hidden, false));
fsamuele8326c742016-01-12 00:49:39317 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20318 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59319 // DoInit increments the reference count on |widget|, keeping it alive after
320 // this function returns.
dcheng35d31c112015-07-22 00:17:36321 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59322 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
323 nullptr)) {
kenrba7199832015-01-22 23:44:59324 return widget.get();
325 }
326 return nullptr;
327}
328
329// static
lfgcaab5142016-02-26 19:06:52330blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08331 RenderWidget* render_widget,
332 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55333 if (!frame->parent()) {
334 // TODO(dcheng): The main frame widget currently has a special case.
335 // Eliminate this once WebView is no longer a WebWidget.
336 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
337 }
dchengda9b4bb2015-07-20 20:58:08338 return blink::WebFrameWidget::create(render_widget, frame);
339}
340
341// static
kenrba7199832015-01-22 23:44:59342blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18343 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46344 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18345 break;
[email protected]180ef242013-11-07 06:50:46346 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44347 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18348 default:
349 NOTREACHED();
350 }
351 return NULL;
352}
353
dchengda9b4bb2015-07-20 20:58:08354void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32355 OnClose();
kenrba7199832015-01-22 23:44:59356}
357
fsamuele8326c742016-01-12 00:49:39358void RenderWidget::SetRoutingID(int32_t routing_id) {
359 routing_id_ = routing_id;
360 input_handler_.reset(new RenderWidgetInputHandler(
361 GetRenderWidgetInputHandlerDelegate(this), this));
362}
363
avi1023d012015-12-25 02:39:14364bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39365 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05366 opener_id, RenderWidget::CreateWebWidget(this),
367 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39368 if (success) {
369 SetRoutingID(routing_id_);
370 return true;
371 }
372 return false;
[email protected]484955942010-08-19 16:13:18373}
374
avi1023d012015-12-25 02:39:14375bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06376 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18377 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29378 DCHECK(!webwidget_);
379
380 if (opener_id != MSG_ROUTING_NONE)
381 opener_id_ = opener_id;
382
[email protected]484955942010-08-19 16:13:18383 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29384
kenrba7199832015-01-22 23:44:59385 bool result = true;
386 if (create_widget_message)
387 result = RenderThread::Get()->Send(create_widget_message);
388
initial.commit09911bf2008-07-26 23:55:29389 if (result) {
[email protected]380244092011-10-07 17:26:27390 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29391 // Take a reference on behalf of the RenderThread. This will be balanced
392 // when we receive ViewMsg_Close.
393 AddRef();
[email protected]b2db9272014-01-10 17:42:00394 if (RenderThreadImpl::current()) {
395 RenderThreadImpl::current()->WidgetCreated();
396 if (is_hidden_)
397 RenderThreadImpl::current()->WidgetHidden();
398 }
fsamuele8326c742016-01-12 00:49:39399
[email protected]a635f942012-12-07 10:34:29400 return true;
initial.commit09911bf2008-07-26 23:55:29401 } else {
[email protected]a635f942012-12-07 10:34:29402 // The above Send can fail when the tab is closing.
403 return false;
initial.commit09911bf2008-07-26 23:55:29404 }
405}
406
[email protected]992db4c2011-05-12 15:37:15407void RenderWidget::SetSwappedOut(bool is_swapped_out) {
408 // We should only toggle between states.
409 DCHECK(is_swapped_out_ != is_swapped_out);
410 is_swapped_out_ = is_swapped_out;
411
412 // If we are swapping out, we will call ReleaseProcess, allowing the process
413 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52414 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15415 // If we are swapping in, we call AddRefProcess to prevent the process from
416 // exiting.
[email protected]949b6592014-08-20 13:17:52417 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15418 RenderProcess::current()->AddRefProcess();
419}
420
[email protected]949b6592014-08-20 13:17:52421void RenderWidget::WasSwappedOut() {
422 // If we have been swapped out and no one else is using this process,
423 // it's safe to exit now.
424 CHECK(is_swapped_out_);
425 RenderProcess::current()->ReleaseProcess();
426}
427
[email protected]b2e4c70132013-10-03 02:07:51428void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39429 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51430 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43431 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49432 popup_screen_origin_for_emulation_ = gfx::Point(
433 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
434 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56435 screen_info_ = emulator->original_screen_info();
436 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51437}
438
[email protected]2d6836f42014-07-02 17:25:31439gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
440 if (screen_metrics_emulator_)
441 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
442 return anchor;
443}
444
[email protected]53907862014-03-25 15:42:40445#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51446void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39447 ExternalPopupMenu* popup,
448 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49449 popup->SetOriginScaleAndOffsetForEmulation(
450 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51451}
[email protected]53907862014-03-25 15:42:40452#endif
[email protected]b2e4c70132013-10-03 02:07:51453
454void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
455 if (screen_metrics_emulator_)
456 screen_metrics_emulator_->OnShowContextMenu(params);
457}
458
[email protected]a95986a82010-12-24 06:19:28459bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
460 bool handled = true;
461 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15462 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22463 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
464 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22465 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
466 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15467 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
468 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35469 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
470 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28471 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28472 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20473 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
474 OnEnableDeviceEmulation)
475 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
476 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41477 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54478 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28479 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41480 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25481 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28482 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
483 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03484 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05485 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
lfg43e08e62016-02-03 18:51:37486 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
487 OnWaitNextFrameForTests)
[email protected]105dffb42013-02-20 03:46:21488#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37489 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39490 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
491 OnRequestTextInputStateUpdate)
[email protected]2384b6c2013-02-28 23:58:51492 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21493#endif
dtrainor5ef644e2015-11-19 00:12:47494 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28495 IPC_MESSAGE_UNHANDLED(handled = false)
496 IPC_END_MESSAGE_MAP()
497 return handled;
498}
initial.commit09911bf2008-07-26 23:55:29499
500bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15501 // Don't send any messages after the browser has told us to close, and filter
502 // most outgoing messages while swapped out.
503 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26504 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11505 closing_) {
initial.commit09911bf2008-07-26 23:55:29506 delete message;
507 return false;
508 }
509
510 // If given a messsage without a routing ID, then assign our routing ID.
511 if (message->routing_id() == MSG_ROUTING_NONE)
512 message->set_routing_id(routing_id_);
513
[email protected]380244092011-10-07 17:26:27514 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44515}
516
bokanc007c3a2015-02-03 07:15:56517void RenderWidget::SetWindowRectSynchronously(
518 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39519 ResizeParams params;
520 params.screen_info = screen_info_;
521 params.new_size = new_window_rect.size();
522 params.physical_backing_size =
523 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
524 params.top_controls_shrink_blink_size = top_controls_shrink_blink_size_;
525 params.top_controls_height = top_controls_height_;
526 params.visible_viewport_size = new_window_rect.size();
527 params.resizer_rect = gfx::Rect();
528 params.is_fullscreen_granted = is_fullscreen_granted_;
529 params.display_mode = display_mode_;
530 params.needs_resize_ack = false;
531 Resize(params);
532
bokanc007c3a2015-02-03 07:15:56533 view_screen_rect_ = new_window_rect;
534 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02535 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56536 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02537}
538
initial.commit09911bf2008-07-26 23:55:29539void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32540 DCHECK(content::RenderThread::Get());
541 if (closing_)
542 return;
543 NotifyOnClose();
544 closing_ = true;
545
546 // Browser correspondence is no longer needed at this point.
547 if (routing_id_ != MSG_ROUTING_NONE) {
548 RenderThread::Get()->RemoveRoute(routing_id_);
549 SetHidden(false);
550 if (RenderThreadImpl::current())
551 RenderThreadImpl::current()->WidgetDestroyed();
552 }
553
554 if (for_oopif_) {
555 // Widgets for frames may be created and closed at any time while the frame
556 // is alive. However, the closing process must happen synchronously. Frame
557 // widget and frames hold pointers to each other. If Close() is deferred to
558 // the message loop like in the non-frame widget case, WebWidget::close()
559 // can end up accessing members of an already-deleted frame.
560 Close();
561 } else {
562 // If there is a Send call on the stack, then it could be dangerous to close
563 // now. Post a task that only gets invoked when there are no nested message
564 // loops.
565 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
566 FROM_HERE, base::Bind(&RenderWidget::Close, this));
567 }
568
569 // Balances the AddRef taken when we called AddRoute.
570 Release();
initial.commit09911bf2008-07-26 23:55:29571}
572
fsamuel664e8b62016-01-20 19:54:01573void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04574 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32575 return;
576
[email protected]b2e4c70132013-10-03 02:07:51577 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39578 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51579 return;
580 }
581
mfomitchev2600fd7c2016-02-17 20:53:39582 Resize(params);
initial.commit09911bf2008-07-26 23:55:29583}
584
dgozman9260b0a12015-03-16 13:45:20585void RenderWidget::OnEnableDeviceEmulation(
586 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39587 if (!screen_metrics_emulator_) {
588 ResizeParams resize_params;
589 resize_params.screen_info = screen_info_;
590 resize_params.new_size = size_;
591 resize_params.physical_backing_size = physical_backing_size_;
592 resize_params.visible_viewport_size = visible_viewport_size_;
593 resize_params.top_controls_shrink_blink_size =
594 top_controls_shrink_blink_size_;
595 resize_params.top_controls_height = top_controls_height_;
596 resize_params.resizer_rect = resizer_rect_;
597 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
598 resize_params.display_mode = display_mode_;
599 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
600 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18601 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39602 } else {
dgozman9260b0a12015-03-16 13:45:20603 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39604 }
dgozman9260b0a12015-03-16 13:45:20605}
606
607void RenderWidget::OnDisableDeviceEmulation() {
608 screen_metrics_emulator_.reset();
609}
610
noel89949e62014-09-30 01:12:41611void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
612 SetDeviceColorProfile(color_profile);
613}
614
[email protected]b5913d72012-02-07 22:26:54615void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01616 if (resizer_rect_ == resizer_rect)
617 return;
618 resizer_rect_ = resizer_rect;
619 if (webwidget_)
620 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54621}
622
initial.commit09911bf2008-07-26 23:55:29623void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31624 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29625 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03626 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59627 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
628 WasHidden());
initial.commit09911bf2008-07-26 23:55:29629}
630
[email protected]3399dd822014-08-09 11:14:24631void RenderWidget::OnWasShown(bool needs_repainting,
632 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41633 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29634 // During shutdown we can just ignore this message.
635 if (!webwidget_)
636 return;
637
638 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03639 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59640 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
641 WasShown());
initial.commit09911bf2008-07-26 23:55:29642
[email protected]8a23afb32014-04-30 22:40:23643 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29644 return;
initial.commit09911bf2008-07-26 23:55:29645
646 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24647 if (compositor_) {
648 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15649 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24650 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05651 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24652 }
jdduke491a3f0c2015-06-15 23:30:26653 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29654}
655
[email protected]53d3f302009-12-21 04:42:05656void RenderWidget::OnRequestMoveAck() {
657 DCHECK(pending_window_rect_count_);
658 pending_window_rect_count_--;
659}
660
[email protected]ed7defa2013-03-12 21:29:59661GURL RenderWidget::GetURLForGraphicsContext3D() {
662 return GURL();
[email protected]65225772011-05-12 21:10:24663}
664
fsamuel78f86e42016-01-20 04:10:23665void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10666 const ui::LatencyInfo& latency_info,
667 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23668 if (!input_event)
669 return;
dtapuska0bd451a2016-02-18 17:08:10670 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23671}
672
673void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
674 if (webwidget_)
675 webwidget_->setCursorVisibilityState(is_visible);
676}
677
678void RenderWidget::OnMouseCaptureLost() {
679 if (webwidget_)
680 webwidget_->mouseCaptureLost();
681}
682
683void RenderWidget::OnSetFocus(bool enable) {
684 if (webwidget_)
685 webwidget_->setFocus(enable);
686}
687
688///////////////////////////////////////////////////////////////////////////////
689// RenderWidgetCompositorDelegate
690
691void RenderWidget::ApplyViewportDeltas(
692 const gfx::Vector2dF& inner_delta,
693 const gfx::Vector2dF& outer_delta,
694 const gfx::Vector2dF& elastic_overscroll_delta,
695 float page_scale,
696 float top_controls_delta) {
697 webwidget_->applyViewportDeltas(inner_delta, outer_delta,
698 elastic_overscroll_delta, page_scale,
699 top_controls_delta);
700}
701
702void RenderWidget::BeginMainFrame(double frame_time_sec) {
703 webwidget_->beginFrame(frame_time_sec);
704}
705
dchengcedca5612016-04-09 01:40:15706std::unique_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(
707 bool fallback) {
piman990d8ea2016-01-12 15:35:31708 DCHECK(webwidget_);
[email protected]7912e822014-04-16 02:37:03709 // For widgets that are never visible, we don't start the compositor, so we
710 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39711 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:19712
avi83883c82014-12-23 00:08:49713 const base::CommandLine& command_line =
714 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33715 bool use_software = fallback;
716 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
717 use_software = true;
718
penghuang28a5fa22015-12-02 17:58:19719#if defined(MOJO_SHELL_CLIENT)
rockot19c030e862016-02-26 05:46:58720 if (MojoShellConnection::Get() && !use_software &&
721 command_line.HasSwitch(switches::kUseMusInRenderer)) {
penghuang28a5fa22015-12-02 17:58:19722 RenderWidgetMusConnection* connection =
723 RenderWidgetMusConnection::GetOrCreate(routing_id());
724 return connection->CreateOutputSurface();
725 }
726#endif
727
penghuang346a46f92016-03-31 21:37:52728 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host;
piman990d8ea2016-01-12 15:35:31729 if (!use_software) {
730 CauseForGpuLaunch cause =
731 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
732 gpu_channel_host =
733 RenderThreadImpl::current()->EstablishGpuChannelSync(cause);
734 if (!gpu_channel_host.get()) {
735 // Cause the compositor to wait and try again.
736 return nullptr;
737 }
738 // We may get a valid channel, but with a software renderer. In that case,
739 // disable GPU compositing.
740 if (gpu_channel_host->gpu_info().software_rendering)
741 use_software = true;
742 }
743
dyen136e05c2016-04-06 22:28:27744#if defined(ENABLE_VULKAN)
745 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider;
746#endif
[email protected]0634cdd42013-08-16 00:46:09747 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17748 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:33749 if (!use_software) {
dyen136e05c2016-04-06 22:28:27750#if defined(ENABLE_VULKAN)
751 vulkan_context_provider = cc::VulkanInProcessContextProvider::Create();
752 if (vulkan_context_provider) {
753 uint32_t output_surface_id = next_output_surface_id_++;
dchengcedca5612016-04-09 01:40:15754 return std::unique_ptr<cc::OutputSurface>(
755 new DelegatedCompositorOutputSurface(
756 routing_id(), output_surface_id, context_provider,
757 worker_context_provider, vulkan_context_provider,
758 frame_swap_message_queue_));
dyen136e05c2016-04-06 22:28:27759 }
760#endif
761
[email protected]0634cdd42013-08-16 00:46:09762 context_provider = ContextProviderCommandBuffer::Create(
piman990d8ea2016-01-12 15:35:31763 CreateGraphicsContext3D(gpu_channel_host.get()),
764 RENDER_COMPOSITOR_CONTEXT);
765 DCHECK(context_provider);
revemand180dfc32015-09-24 00:19:43766 worker_context_provider =
767 RenderThreadImpl::current()->SharedWorkerContextProvider();
768 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:17769 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34770 return nullptr;
vmiura78b69282015-02-14 00:01:17771 }
boliu853d46052015-10-13 20:20:06772
773#if defined(OS_ANDROID)
774 if (SynchronousCompositorFactory* factory =
775 SynchronousCompositorFactory::GetInstance()) {
boliuf4e574852016-03-22 19:33:17776 uint32_t output_surface_id = next_output_surface_id_++;
boliu853d46052015-10-13 20:20:06777 return factory->CreateOutputSurface(
boliuf4e574852016-03-22 19:33:17778 routing_id(), output_surface_id, frame_swap_message_queue_,
779 context_provider, worker_context_provider);
boliubee541f42015-11-05 00:52:53780 } else if (RenderThreadImpl::current()->sync_compositor_message_filter()) {
boliuf4e574852016-03-22 19:33:17781 uint32_t output_surface_id = next_output_surface_id_++;
dchengcedca5612016-04-09 01:40:15782 return base::WrapUnique(new SynchronousCompositorOutputSurface(
boliubee541f42015-11-05 00:52:53783 context_provider, worker_context_provider, routing_id(),
boliuf4e574852016-03-22 19:33:17784 output_surface_id, content::RenderThreadImpl::current()
785 ->sync_compositor_message_filter(),
boliubee541f42015-11-05 00:52:53786 frame_swap_message_queue_));
boliu853d46052015-10-13 20:20:06787 }
788#endif
[email protected]0634cdd42013-08-16 00:46:09789 }
[email protected]ebc0e1df2013-08-01 02:46:22790
avi1023d012015-12-25 02:39:14791 uint32_t output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:34792 // Composite-to-mailbox is currently used for layout tests in order to cause
793 // them to draw inside in the renderer to do the readback there. This should
794 // no longer be the case when crbug.com/311404 is fixed.
795 if (!RenderThreadImpl::current() ||
796 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:53797 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
dchengcedca5612016-04-09 01:40:15798 return base::WrapUnique(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:17799 routing_id(), output_surface_id, context_provider,
dyen136e05c2016-04-06 22:28:27800 worker_context_provider,
801#if defined(ENABLE_VULKAN)
802 vulkan_context_provider,
803#endif
804 frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09805 }
piman8944e1c2015-09-22 21:10:34806
[email protected]0634cdd42013-08-16 00:46:09807 if (!context_provider.get()) {
dchengcedca5612016-04-09 01:40:15808 std::unique_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:12809 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:09810
dchengcedca5612016-04-09 01:40:15811 return base::WrapUnique(new CompositorOutputSurface(
caseqff9c74c2015-02-10 14:56:29812 routing_id(), output_surface_id, nullptr, nullptr,
dyen136e05c2016-04-06 22:28:27813#if defined(ENABLE_VULKAN)
814 nullptr,
815#endif
dcheng07945f632015-12-26 07:59:32816 std::move(software_device), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:22817 }
[email protected]ed7defa2013-03-12 21:29:59818
dchengcedca5612016-04-09 01:40:15819 return base::WrapUnique(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:17820 routing_id(), output_surface_id, context_provider,
piman8944e1c2015-09-22 21:10:34821 worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:28822}
823
dchengcedca5612016-04-09 01:40:15824std::unique_ptr<cc::BeginFrameSource>
fsamuel78f86e42016-01-20 04:10:23825RenderWidget::CreateExternalBeginFrameSource() {
826 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_);
827}
828
829void RenderWidget::DidCommitAndDrawCompositorFrame() {
830 // NOTE: Tests may break if this event is renamed or moved. See
831 // tab_capture_performancetest.cc.
832 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
833 // Notify subclasses that we initiated the paint operation.
834 DidInitiatePaint();
835}
836
837void RenderWidget::DidCommitCompositorFrame() {
838 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
839 DidCommitCompositorFrame());
840 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
841 DidCommitCompositorFrame());
842#if defined(VIDEO_HOLE)
843 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
844 DidCommitCompositorFrame());
845#endif // defined(VIDEO_HOLE)
846 input_handler_->FlushPendingInputEventAck();
847}
848
849void RenderWidget::DidCompletePageScaleAnimation() {}
850
851void RenderWidget::DidCompleteSwapBuffers() {
852 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
853
854 // Notify subclasses threaded composited rendering was flushed to the screen.
855 DidFlushPaint();
856
pimanbfb2ceb2016-03-18 21:32:58857 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23858 return;
859 }
860
861 ViewHostMsg_UpdateRect_Params params;
862 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23863 params.flags = next_paint_flags_;
864
865 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
866 next_paint_flags_ = 0;
867 need_update_rect_for_auto_resize_ = false;
868}
869
870bool RenderWidget::ForOOPIF() const {
871 // TODO(simonhong): Remove this when we enable BeginFrame scheduling for
872 // OOPIF(crbug.com/471411).
873 return for_oopif_;
874}
875
876void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
877 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
878}
879
880bool RenderWidget::IsClosing() const {
881 return host_closing_;
882}
883
[email protected]4d7e46a2013-11-08 05:33:40884void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24885 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:24886 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:26887 ScheduleComposite();
[email protected]65225772011-05-12 21:10:24888}
889
[email protected]4d7e46a2013-11-08 05:33:40890void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24891 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16892
[email protected]404939f2012-06-01 04:06:18893 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16894 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:29895}
896
fsamuel78f86e42016-01-20 04:10:23897void RenderWidget::OnSwapBuffersPosted() {
898 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:29899}
900
fsamuel78f86e42016-01-20 04:10:23901void RenderWidget::RecordFrameTimingEvents(
dchengcedca5612016-04-09 01:40:15902 std::unique_ptr<cc::FrameTimingTracker::CompositeTimingSet>
903 composite_events,
904 std::unique_ptr<cc::FrameTimingTracker::MainFrameTimingSet>
905 main_frame_events) {
fsamuel78f86e42016-01-20 04:10:23906 for (const auto& composite_event : *composite_events) {
907 int64_t frameId = composite_event.first;
908 const std::vector<cc::FrameTimingTracker::CompositeTimingEvent>& events =
909 composite_event.second;
910 std::vector<blink::WebFrameTimingEvent> webEvents;
911 for (size_t i = 0; i < events.size(); ++i) {
912 webEvents.push_back(blink::WebFrameTimingEvent(
913 events[i].frame_id,
914 (events[i].timestamp - base::TimeTicks()).InSecondsF()));
915 }
916 webwidget_->recordFrameTimingEvent(blink::WebWidget::CompositeEvent,
917 frameId, webEvents);
918 }
919 for (const auto& main_frame_event : *main_frame_events) {
920 int64_t frameId = main_frame_event.first;
921 const std::vector<cc::FrameTimingTracker::MainFrameTimingEvent>& events =
922 main_frame_event.second;
923 std::vector<blink::WebFrameTimingEvent> webEvents;
924 for (size_t i = 0; i < events.size(); ++i) {
925 webEvents.push_back(blink::WebFrameTimingEvent(
926 events[i].frame_id,
927 (events[i].timestamp - base::TimeTicks()).InSecondsF(),
928 (events[i].end_time - base::TimeTicks()).InSecondsF()));
929 }
930 webwidget_->recordFrameTimingEvent(blink::WebWidget::RenderEvent, frameId,
931 webEvents);
932 }
[email protected]34202de2013-05-06 23:36:22933}
934
danakj53eccbc2016-03-02 22:51:07935void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23936 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29937}
938
fsamuel78f86e42016-01-20 04:10:23939void RenderWidget::UpdateVisualState() {
940 webwidget_->updateAllLifecyclePhases();
941}
942
943void RenderWidget::WillBeginCompositorFrame() {
944 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
945
946 // The UpdateTextInputState can result in further layout and possibly
947 // enable GPU acceleration so they need to be called before any painting
948 // is done.
949 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
950 UpdateSelectionBounds();
lfge6119aac2016-01-27 02:14:31951
952 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
953 WillBeginCompositorFrame());
initial.commit09911bf2008-07-26 23:55:29954}
955
fsamuel72464894f2015-12-15 06:59:31956///////////////////////////////////////////////////////////////////////////////
957// RenderWidgetInputHandlerDelegate
958
avid7d6b2e2016-03-04 19:41:17959void RenderWidget::FocusChangeComplete() {
960 if (owner_delegate_)
961 owner_delegate_->RenderWidgetFocusChangeComplete();
962}
fsamuel72464894f2015-12-15 06:59:31963
964bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17965 if (owner_delegate_)
966 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
967
fsamuel72464894f2015-12-15 06:59:31968 return true;
969}
970
971void RenderWidget::ObserveWheelEventAndResult(
972 const blink::WebMouseWheelEvent& wheel_event,
973 const gfx::Vector2dF& wheel_unused_delta,
974 bool event_processed) {
975 if (!compositor_deps_->IsElasticOverscrollEnabled())
976 return;
977
978 cc::InputHandlerScrollResult scroll_result;
979 scroll_result.did_scroll = event_processed;
980 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
981 scroll_result.unused_scroll_delta = wheel_unused_delta;
982
983 RenderThreadImpl* render_thread = RenderThreadImpl::current();
984 InputHandlerManager* input_handler_manager =
985 render_thread ? render_thread->input_handler_manager() : NULL;
986 if (input_handler_manager) {
987 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
988 routing_id_, wheel_event, scroll_result);
jddukefffb67c2015-01-07 22:32:29989 }
fsamuel72464894f2015-12-15 06:59:31990}
991
dtapuska1827dd22016-03-11 15:24:59992void RenderWidget::ObserveGestureEventAndResult(
993 const blink::WebGestureEvent& gesture_event,
994 const gfx::Vector2dF& unused_delta,
995 bool event_processed) {
996 if (!compositor_deps_->IsElasticOverscrollEnabled())
997 return;
998
999 cc::InputHandlerScrollResult scroll_result;
1000 scroll_result.did_scroll = event_processed;
1001 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1002 scroll_result.unused_scroll_delta = unused_delta;
1003
1004 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1005 InputHandlerManager* input_handler_manager =
1006 render_thread ? render_thread->input_handler_manager() : NULL;
1007 if (input_handler_manager) {
1008 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1009 routing_id_, gesture_event, scroll_result);
1010 }
1011}
1012
avid7d6b2e2016-03-04 19:41:171013void RenderWidget::OnDidHandleKeyEvent() {
1014 if (owner_delegate_)
1015 owner_delegate_->RenderWidgetDidHandleKeyEvent();
1016}
fsamuel72464894f2015-12-15 06:59:311017
1018void RenderWidget::OnDidOverscroll(const DidOverscrollParams& params) {
1019 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1020}
1021
dchengcedca5612016-04-09 01:40:151022void RenderWidget::OnInputEventAck(
1023 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:311024 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
1025}
1026
dtapuska46616922016-03-17 22:52:011027void RenderWidget::NotifyInputEventHandled(
dtapuska0bd451a2016-02-18 17:08:101028 blink::WebInputEvent::Type handled_type) {
1029 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1030 InputHandlerManager* input_handler_manager =
1031 render_thread ? render_thread->input_handler_manager() : NULL;
1032 if (input_handler_manager) {
dtapuska46616922016-03-17 22:52:011033 input_handler_manager->NotifyInputEventHandledOnMainThread(routing_id_,
1034 handled_type);
dtapuska0bd451a2016-02-18 17:08:101035 }
1036}
1037
fsamuele8326c742016-01-12 00:49:391038void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1039 // Nothing to do here. RenderWidget created the |input_handler| and will take
1040 // ownership of it. We just verify here that we don't already have an input
1041 // handler.
1042 DCHECK(!input_handler_);
1043}
1044
fsamuel72464894f2015-12-15 06:59:311045void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1046 ChangeSource change_source) {
1047 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1048 if (ime_event_guard_) {
1049 // show_ime should still be effective even if it was set inside the IME
1050 // event guard.
1051 if (show_ime == ShowIme::IF_NEEDED) {
1052 ime_event_guard_->set_show_ime(true);
1053 }
1054 return;
1055 }
1056
1057 ui::TextInputType new_type = GetTextInputType();
1058 if (IsDateTimeInput(new_type))
1059 return; // Not considered as a text input field in WebKit/Chromium.
1060
1061 blink::WebTextInputInfo new_info;
1062 if (webwidget_)
1063 new_info = webwidget_->textInputInfo();
1064 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1065
1066 bool new_can_compose_inline = CanComposeInline();
1067
1068 // Only sends text input params if they are changed or if the ime should be
1069 // shown.
1070 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:391071 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
fsamuel72464894f2015-12-15 06:59:311072 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1073 text_input_info_ != new_info ||
1074 can_compose_inline_ != new_can_compose_inline)
1075#if defined(OS_ANDROID)
1076 || text_field_is_dirty_
1077#endif
1078 ) {
ekaramad2bd4a2f2016-04-06 20:12:461079 TextInputState params;
fsamuel72464894f2015-12-15 06:59:311080 params.type = new_type;
1081 params.mode = new_mode;
1082 params.flags = new_info.flags;
1083 params.value = new_info.value.utf8();
1084 params.selection_start = new_info.selectionStart;
1085 params.selection_end = new_info.selectionEnd;
1086 params.composition_start = new_info.compositionStart;
1087 params.composition_end = new_info.compositionEnd;
1088 params.can_compose_inline = new_can_compose_inline;
1089 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
1090#if defined(USE_AURA)
1091 params.is_non_ime_change = true;
1092#endif
1093#if defined(OS_ANDROID)
1094 params.is_non_ime_change =
1095 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
1096 if (params.is_non_ime_change)
1097 OnImeEventSentForAck(new_info);
1098 text_field_is_dirty_ = false;
1099#endif
1100 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1101
1102 text_input_info_ = new_info;
1103 text_input_type_ = new_type;
1104 text_input_mode_ = new_mode;
1105 can_compose_inline_ = new_can_compose_inline;
1106 text_input_flags_ = new_info.flags;
1107 }
1108}
1109
1110bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:171111 if (owner_delegate_)
1112 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
1113
fsamuel72464894f2015-12-15 06:59:311114 return false;
1115}
1116
1117bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
avid7d6b2e2016-03-04 19:41:171118 if (owner_delegate_)
1119 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1120
fsamuel72464894f2015-12-15 06:59:311121 return false;
[email protected]fd847792013-10-24 17:12:351122}
1123
initial.commit09911bf2008-07-26 23:55:291124///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391125// RenderWidgetScreenMetricsDelegate
1126
1127void RenderWidget::Redraw() {
1128 set_next_paint_is_resize_ack();
1129 if (compositor_)
1130 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1131}
1132
1133void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581134 bool orientation_changed =
1135 screen_info_.orientationAngle != params.screen_info.orientationAngle ||
1136 screen_info_.orientationType != params.screen_info.orientationType;
1137
mfomitchev2600fd7c2016-02-17 20:53:391138 screen_info_ = params.screen_info;
1139 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
1140
1141 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1142 // A resize ack shouldn't be requested if we have not ACK'd the previous
1143 // one.
1144 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1145 }
1146
1147 // Ignore this during shutdown.
1148 if (!webwidget_)
1149 return;
1150
1151 if (compositor_)
1152 compositor_->setViewportSize(params.physical_backing_size);
1153
1154 bool resized = size_ != params.new_size ||
1155 physical_backing_size_ != params.physical_backing_size;
1156
1157 size_ = params.new_size;
1158 physical_backing_size_ = params.physical_backing_size;
1159
1160 top_controls_shrink_blink_size_ = params.top_controls_shrink_blink_size;
1161 top_controls_height_ = params.top_controls_height;
1162 visible_viewport_size_ = params.visible_viewport_size;
1163 resizer_rect_ = params.resizer_rect;
1164
1165 // NOTE: We may have entered fullscreen mode without changing our size.
1166 bool fullscreen_change =
1167 is_fullscreen_granted_ != params.is_fullscreen_granted;
1168 is_fullscreen_granted_ = params.is_fullscreen_granted;
1169 display_mode_ = params.display_mode;
1170
1171 webwidget_->setTopControlsHeight(params.top_controls_height,
1172 top_controls_shrink_blink_size_);
1173
1174 if (resized) {
oshima50872a72016-03-04 13:26:181175 gfx::Size new_widget_size = size_;
1176 if (IsUseZoomForDSFEnabled()) {
1177 new_widget_size = gfx::ScaleToCeiledSize(new_widget_size,
1178 GetOriginalDeviceScaleFactor());
1179 }
mfomitchev2600fd7c2016-02-17 20:53:391180 // When resizing, we want to wait to paint before ACK'ing the resize. This
1181 // ensures that we only resize as fast as we can paint. We only need to
1182 // send an ACK if we are resized to a non-empty rect.
1183 webwidget_->resize(new_widget_size);
1184 }
1185 WebSize visual_viewport_size;
1186
1187 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181188 visual_viewport_size = gfx::ScaleToCeiledSize(
1189 params.visible_viewport_size,
1190 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391191 } else {
1192 visual_viewport_size = visible_viewport_size_;
1193 }
1194
1195 webwidget()->resizeVisualViewport(visual_viewport_size);
1196
1197 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1198 // In this case there is no paint/composite and therefore no
1199 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1200 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1201 DCHECK(!params.needs_resize_ack);
1202 }
1203
1204 // Send the Resize_ACK flag once we paint again if requested.
1205 if (params.needs_resize_ack)
1206 set_next_paint_is_resize_ack();
1207
1208 if (fullscreen_change)
1209 DidToggleFullscreen();
1210
engedy6cb63c92016-02-23 14:14:581211 if (orientation_changed)
1212 OnOrientationChange();
1213
mfomitchev2600fd7c2016-02-17 20:53:391214 // If a resize ack is requested and it isn't set-up, then no more resizes will
1215 // come in and in general things will go wrong.
1216 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1217}
1218
1219void RenderWidget::SetScreenMetricsEmulationParameters(
1220 bool enabled,
1221 const blink::WebDeviceEmulationParams& params) {
1222 // This is only supported in RenderView.
1223 NOTREACHED();
1224}
1225
1226void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1227 const gfx::Rect& window_screen_rect) {
1228 view_screen_rect_ = view_screen_rect;
1229 window_screen_rect_ = window_screen_rect;
1230}
1231
1232///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461233// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291234
[email protected]244ac1892011-12-02 17:04:471235void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima33ec97cd2015-12-14 19:40:241236 WebRect new_size_in_window(0, 0, new_size.width, new_size.height);
1237 convertViewportToWindow(&new_size_in_window);
1238 if (size_.width() != new_size_in_window.width ||
1239 size_.height() != new_size_in_window.height) {
1240 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
[email protected]20fbfc22013-05-08 20:50:581241
[email protected]5b45ad42013-10-25 00:42:041242 if (resizing_mode_selector_->is_synchronous_mode()) {
oshima33ec97cd2015-12-14 19:40:241243 gfx::Rect new_pos(rootWindowRect().x,
1244 rootWindowRect().y,
1245 size_.width(),
1246 size_.height());
[email protected]eac2b362013-05-22 07:01:451247 view_screen_rect_ = new_pos;
1248 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031249 }
[email protected]20fbfc22013-05-08 20:50:581250
[email protected]eac2b362013-05-22 07:01:451251 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581252
[email protected]5b45ad42013-10-25 00:42:041253 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581254 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091255 }
[email protected]244ac1892011-12-02 17:04:471256}
1257
[email protected]3a1c8a8032013-03-18 22:35:321258void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401259 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051260 if (compositor_)
oshima750cb4342015-10-31 00:59:011261 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051262}
1263
[email protected]e195e582013-03-08 01:32:591264void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221265 DCHECK(!host_closing_);
1266
fsamuel78f86e42016-01-20 04:10:231267 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1268 compositor_deps_);
oshima750cb4342015-10-31 00:59:011269 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331270 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391271 // For background pages and certain tests, we don't want to trigger
1272 // OutputSurface creation.
1273 if (compositor_never_visible_ || !RenderThreadImpl::current())
1274 compositor_->SetNeverVisible();
1275
pimanc4af3072015-10-02 03:45:591276 StartCompositor();
[email protected]e195e582013-03-08 01:32:591277}
1278
ennef3c58142014-12-09 21:44:381279void RenderWidget::WillCloseLayerTreeView() {
1280 if (host_closing_)
1281 return;
1282
1283 // Prevent new compositors or output surfaces from being created.
1284 host_closing_ = true;
1285
[email protected]aeeedad2014-08-22 18:16:221286 // Always send this notification to prevent new layer tree views from
1287 // being created, even if one hasn't been created yet.
1288 if (webwidget_)
1289 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221290}
1291
[email protected]180ef242013-11-07 06:50:461292blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281293 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061294}
1295
dglazkovf0e1d6d2015-10-10 02:13:481296void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1297 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1298 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1299 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1300 }
dglazkov79c426102015-08-31 21:22:431301
dglazkovf0e1d6d2015-10-10 02:13:481302 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1303 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431304}
1305
jdduke491a3f0c2015-06-15 23:30:261306void RenderWidget::ScheduleComposite() {
1307 if (compositor_ &&
1308 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1309 compositor_->setNeedsAnimate();
1310 }
1311}
1312
1313void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1314 if (compositor_) {
1315 // Regardless of whether threaded compositing is enabled, always
1316 // use this mechanism to force the compositor to redraw. However,
1317 // the invalidation code path below is still needed for the
1318 // non-threaded case.
1319 compositor_->SetNeedsForcedRedraw();
1320 }
1321 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151322}
1323
[email protected]586871b2014-07-22 17:05:111324// static
dchengcedca5612016-04-09 01:40:151325std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111326 IPC::Message* msg,
1327 MessageDeliveryPolicy policy,
1328 FrameSwapMessageQueue* frame_swap_message_queue,
1329 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111330 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111331 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151332 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1333 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111334 &first_message_for_frame);
1335 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151336 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111337 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061338 return promise;
[email protected]586871b2014-07-22 17:05:111339 }
dcheng4b6b5ff2014-10-16 00:42:061340 return nullptr;
[email protected]586871b2014-07-22 17:05:111341}
1342
1343void RenderWidget::QueueMessage(IPC::Message* msg,
1344 MessageDeliveryPolicy policy) {
1345 // RenderThreadImpl::current() is NULL in some tests.
1346 if (!compositor_ || !RenderThreadImpl::current()) {
1347 Send(msg);
1348 return;
1349 }
1350
dchengcedca5612016-04-09 01:40:151351 std::unique_ptr<cc::SwapPromise> swap_promise =
1352 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111353 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111354 compositor_->GetSourceFrameNumber());
1355
1356 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321357 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351358 // Request a commit. This might either A) request a commit ahead of time
1359 // or B) request a commit which is not needed because there are not
1360 // pending updates. If B) then the commit will be skipped and the swap
1361 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1362 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1363 // can_cancel_commit is not unset.
1364 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111365 }
1366}
1367
[email protected]4873c7d2009-07-16 06:36:281368void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301369 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521370 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181371 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291372 // Only send a SetCursor message if we need to make a change.
1373 if (!current_cursor_.IsEqual(cursor)) {
1374 current_cursor_ = cursor;
1375 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1376 }
1377}
1378
1379// We are supposed to get a single call to Show for a newly created RenderWidget
1380// that was created via RenderWidget::CreateWebView. So, we wait until this
1381// point to dispatch the ShowWidget message.
1382//
1383// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281384// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291385//
[email protected]4873c7d2009-07-16 06:36:281386void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291387 DCHECK(!did_show_) << "received extraneous Show call";
1388 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1389 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1390
[email protected]8de12d942010-11-17 20:42:441391 if (did_show_)
1392 return;
1393
1394 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561395 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441396 // that's okay. It'll be ignored if as_popup is false, or the browser
1397 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561398 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1399 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291400}
1401
[email protected]4873c7d2009-07-16 06:36:281402void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291403}
1404
[email protected]2533ce12009-05-09 00:02:241405void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381406 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241407 Send(new ViewHostMsg_Close(routing_id_));
1408}
1409
dgozmancf9039cd2015-04-06 12:01:311410void RenderWidget::NotifyOnClose() {
1411 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1412}
1413
[email protected]4873c7d2009-07-16 06:36:281414void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081415 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321416 if (is_swapped_out_) {
1417 // This widget is currently swapped out, and the active widget is in a
1418 // different process. Have the browser route the close request to the
1419 // active widget instead, so that the correct unload handlers are run.
1420 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1421 return;
1422 }
1423
initial.commit09911bf2008-07-26 23:55:291424 // If a page calls window.close() twice, we'll end up here twice, but that's
1425 // OK. It is safe to send multiple Close messages.
1426
[email protected]2533ce12009-05-09 00:02:241427 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1428 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1429 // could be closed before the JS finishes executing. So instead, post a
1430 // message back to the message loop, which won't run until the JS is
1431 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081432 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211433 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291434}
1435
[email protected]9017d7852013-11-21 17:47:351436void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151437 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351438 const SyntheticGestureCompletionCallback& callback) {
1439 DCHECK(!callback.is_null());
1440
1441 pending_synthetic_gesture_callbacks_.push(callback);
1442
1443 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321444 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351445
1446 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1447}
1448
initial.commit09911bf2008-07-26 23:55:291449void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031450 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381451 WillCloseLayerTreeView();
1452 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291453 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281454 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291455 webwidget_ = NULL;
1456 }
1457}
1458
[email protected]4873c7d2009-07-16 06:36:281459WebRect RenderWidget::windowRect() {
1460 if (pending_window_rect_count_)
1461 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241462
[email protected]80ad8622012-11-07 16:33:031463 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291464}
1465
[email protected]180ef242013-11-07 06:50:461466void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301467 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541468 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301469}
1470
oshima33ec97cd2015-12-14 19:40:241471void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1472 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511473 if (popup_origin_scale_for_emulation_) {
1474 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561475 window_rect.x = popup_screen_origin_for_emulation_.x() +
1476 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1477 window_rect.y = popup_screen_origin_for_emulation_.y() +
1478 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511479 }
1480
[email protected]5b45ad42013-10-25 00:42:041481 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201482 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561483 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1484 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031485 } else {
bokanc007c3a2015-02-03 07:15:561486 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031487 }
initial.commit09911bf2008-07-26 23:55:291488 } else {
bokanc007c3a2015-02-03 07:15:561489 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291490 }
1491}
1492
[email protected]2533ce12009-05-09 00:02:241493void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1494 pending_window_rect_ = rect;
1495 pending_window_rect_count_++;
1496}
1497
[email protected]4873c7d2009-07-16 06:36:281498WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241499 if (pending_window_rect_count_) {
1500 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1501 // the RootWindowRect is probably going to return wrong results since the
1502 // browser may not have processed the Move yet. There isn't really anything
1503 // good to do in this case, and it shouldn't happen - since this size is
1504 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281505 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241506 }
1507
[email protected]80ad8622012-11-07 16:33:031508 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371509}
1510
[email protected]4873c7d2009-07-16 06:36:281511WebRect RenderWidget::windowResizerRect() {
1512 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191513}
1514
[email protected]fa7b1dc2010-06-23 17:53:041515void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261516 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041517 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071518 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041519 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131520 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281521 return;
[email protected]66fca5bc2013-05-23 06:58:291522 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361523 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041524 text, WebVector<WebCompositionUnderline>(underlines),
1525 selection_start, selection_end)) {
1526 // If we failed to set the composition text, then we need to let the browser
1527 // process to cancel the input method's ongoing composition session, to make
1528 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221529 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261530 }
[email protected]88dbe32f2013-06-20 23:31:361531 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041532}
1533
[email protected]fcf75d42013-12-03 20:11:261534void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511535 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021536 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131537 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041538 return;
[email protected]66fca5bc2013-05-23 06:58:291539 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391540 input_handler_->set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021541 if (text.length())
1542 webwidget_->confirmComposition(text);
1543 else if (keep_selection)
1544 webwidget_->confirmComposition(WebWidget::KeepSelection);
1545 else
1546 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391547 input_handler_->set_handling_input_event(false);
[email protected]88dbe32f2013-06-20 23:31:361548 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291549}
1550
oshimad5279032015-12-16 18:22:331551void RenderWidget::OnDeviceScaleFactorChanged() {
1552 if (!compositor_)
1553 return;
oshimad5279032015-12-16 18:22:331554 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181555 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331556 else
1557 compositor_->setDeviceScaleFactor(device_scale_factor_);
1558}
1559
[email protected]0bc1f572013-04-17 01:46:311560void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121561 // During shutdown we can just ignore this message.
1562 if (!webwidget_)
1563 return;
1564
[email protected]0bc1f572013-04-17 01:46:311565 // Even if the browser provides an empty damage rect, it's still expecting to
1566 // receive a repaint ack so just damage the entire widget bounds.
1567 if (size_to_paint.IsEmpty()) {
1568 size_to_paint = size_;
1569 }
1570
[email protected]ec7dc112008-08-06 05:30:121571 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051572 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311573 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121574}
1575
[email protected]79fa22e2013-08-23 15:18:121576void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351577 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1578
1579 pending_synthetic_gesture_callbacks_.front().Run();
1580 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271581}
1582
[email protected]4873c7d2009-07-16 06:36:281583void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111584 if (!webwidget_)
1585 return;
[email protected]4873c7d2009-07-16 06:36:281586 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111587}
1588
[email protected]80ad8622012-11-07 16:33:031589void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1590 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511591 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391592 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1593 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511594 } else {
mfomitchev2600fd7c2016-02-17 20:53:391595 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511596 }
[email protected]80ad8622012-11-07 16:33:031597 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1598}
1599
lfgdb5c4ed2016-03-04 23:09:071600void RenderWidget::OnUpdateWindowScreenRect(
1601 const gfx::Rect& window_screen_rect) {
1602 if (screen_metrics_emulator_) {
1603 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
1604 } else {
1605 window_screen_rect_ = window_screen_rect;
1606 }
1607}
1608
kenrbb4e2a3b2015-05-14 15:05:051609void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1610 if (compositor_)
1611 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1612}
1613
dtrainor5ef644e2015-11-19 00:12:471614void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1615 if (compositor_)
1616 compositor_->OnHandleCompositorProto(proto);
1617}
1618
[email protected]adb362312014-06-28 06:04:241619void RenderWidget::showImeIfNeeded() {
1620 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131621}
1622
fsamuel72464894f2015-12-15 06:59:311623ui::TextInputType RenderWidget::GetTextInputType() {
1624 if (webwidget_)
1625 return WebKitToUiTextInputType(webwidget_->textInputType());
1626 return ui::TEXT_INPUT_TYPE_NONE;
1627}
1628
1629void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
fsamuel72464894f2015-12-15 06:59:311630 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1631 gfx::Range range = gfx::Range();
1632 if (should_update_range) {
1633 GetCompositionRange(&range);
1634 } else {
1635 range = composition_range_;
1636 }
1637 std::vector<gfx::Rect> character_bounds;
1638 GetCompositionCharacterBounds(&character_bounds);
1639
1640 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1641 return;
1642 composition_character_bounds_ = character_bounds;
1643 composition_range_ = range;
1644 Send(new InputHostMsg_ImeCompositionRangeChanged(
1645 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311646}
1647
oshimaf866dab2015-12-05 00:41:541648void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1649 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181650 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331651 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541652 // anchor element can be placed at half pixel.
1653 gfx::Rect window_rect =
1654 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1655 rect->x = window_rect.x();
1656 rect->y = window_rect.y();
1657 rect->width = window_rect.width();
1658 rect->height = window_rect.height();
1659 }
1660}
1661
oshimaa6985b62016-01-27 08:58:301662void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1663 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181664 rect->x *= GetOriginalDeviceScaleFactor();
1665 rect->y *= GetOriginalDeviceScaleFactor();
1666 rect->width *= GetOriginalDeviceScaleFactor();
1667 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301668 }
1669}
1670
[email protected]adb362312014-06-28 06:04:241671void RenderWidget::OnShowImeIfNeeded() {
1672#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311673 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241674#endif
rouslanf7ebd8832015-01-22 01:54:141675
1676// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1677// virtual keyboard.
1678#if !defined(OS_ANDROID)
1679 FocusChangeComplete();
1680#endif
[email protected]adb362312014-06-28 06:04:241681}
1682
1683#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371684void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1685 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131686}
1687
1688void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371689 DCHECK_GE(text_input_info_history_.size(), 1u);
1690 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511691}
changwan8c342742016-02-26 00:53:391692
1693void RenderWidget::OnRequestTextInputStateUpdate() {
1694 DCHECK(!ime_event_guard_);
1695 UpdateSelectionBounds();
1696 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1697}
[email protected]105dffb42013-02-20 03:46:211698#endif
1699
[email protected]0d1ebed12013-08-05 22:01:131700bool RenderWidget::ShouldHandleImeEvent() {
1701#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371702 if (!webwidget_)
1703 return false;
changwan8c342742016-02-26 00:53:391704 if (IsUsingImeThread())
1705 return true;
changwan3a841162015-08-11 02:53:371706
1707 // We cannot handle IME events if there is any chance that the event we are
1708 // receiving here from the browser is based on the state that is different
1709 // from our current one as indicated by |text_input_info_|.
1710 // The states the browser might be in are:
1711 // text_input_info_history_[0] - current state ack'd by browser
1712 // text_input_info_history_[1...N] - pending state changes
1713 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1714 if (text_input_info_history_[i] != text_input_info_)
1715 return false;
1716 }
1717 return true;
[email protected]0d1ebed12013-08-05 22:01:131718#else
1719 return !!webwidget_;
1720#endif
1721}
1722
[email protected]468ac582012-11-20 00:53:191723void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1724 if (device_scale_factor_ == device_scale_factor)
1725 return;
1726
1727 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331728
1729 OnDeviceScaleFactorChanged();
1730
jdduke491a3f0c2015-06-15 23:30:261731 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191732}
1733
[email protected]28ed6b32014-06-08 02:16:271734bool RenderWidget::SetDeviceColorProfile(
1735 const std::vector<char>& color_profile) {
1736 if (device_color_profile_ == color_profile)
1737 return false;
1738
1739 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271740
avi40b5be7a2016-03-03 21:13:441741 if (owner_delegate_)
1742 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1743
1744 return true;
noeldb4df152014-09-16 17:45:201745}
1746
[email protected]fcdc5642014-05-09 14:32:241747void RenderWidget::OnOrientationChange() {
1748}
1749
avib9dbd972016-03-08 18:19:321750void RenderWidget::DidInitiatePaint() {
1751 if (owner_delegate_)
1752 owner_delegate_->RenderWidgetDidCommitAndDrawCompositorFrame();
1753}
1754
1755void RenderWidget::DidFlushPaint() {
1756 if (owner_delegate_)
1757 owner_delegate_->RenderWidgetDidFlushPaint();
1758}
1759
[email protected]bee16aab2009-08-26 15:55:031760void RenderWidget::SetHidden(bool hidden) {
1761 if (is_hidden_ == hidden)
1762 return;
1763
jdduke8fac9d102014-12-20 02:40:131764 // The status has changed. Tell the RenderThread about it and ensure
1765 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031766 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391767 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131768
[email protected]bee16aab2009-08-26 15:55:031769 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001770 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031771 else
[email protected]b2db9272014-01-10 17:42:001772 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111773
1774 if (render_widget_scheduling_state_)
1775 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031776}
1777
[email protected]2b624c562011-10-27 22:58:261778void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261779 if (!webwidget_)
1780 return;
1781
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121782 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261783 webwidget_->didEnterFullScreen();
1784 } else {
1785 webwidget_->didExitFullScreen();
1786 }
[email protected]2b624c562011-10-27 22:58:261787}
1788
[email protected]674741932009-02-04 23:44:461789bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051790 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461791}
1792
[email protected]674741932009-02-04 23:44:461793void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051794 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461795}
1796
[email protected]674741932009-02-04 23:44:461797void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051798 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461799}
1800
changwan8c342742016-02-26 00:53:391801bool RenderWidget::IsUsingImeThread() {
1802#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121803 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391804#else
1805 return false;
1806#endif
1807}
1808
changwanf2a707b2015-10-30 08:22:161809void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1810 if (!ime_event_guard_)
1811 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291812}
1813
changwanf2a707b2015-10-30 08:22:161814void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1815 if (ime_event_guard_ != guard) {
1816#if defined(OS_ANDROID)
1817 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1818 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391819 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161820 // Therefore, we want to mark this text state update as 'from IME' only
1821 // when all the nested events are all originating from IME.
1822 ime_event_guard_->set_from_ime(
1823 ime_event_guard_->from_ime() && guard->from_ime());
1824#endif
1825 return;
1826 }
1827 ime_event_guard_ = nullptr;
1828
[email protected]66fca5bc2013-05-23 06:58:291829 // While handling an ime event, text input state and selection bounds updates
1830 // are ignored. These must explicitly be updated once finished handling the
1831 // ime event.
1832 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471833#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161834 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311835 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1836 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471837#endif
[email protected]66fca5bc2013-05-23 06:58:291838}
1839
[email protected]7c8873e2013-02-05 08:03:011840void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1841 WebRect focus_webrect;
1842 WebRect anchor_webrect;
1843 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241844 convertViewportToWindow(&focus_webrect);
1845 convertViewportToWindow(&anchor_webrect);
1846 *focus = focus_webrect;
1847 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321848}
1849
[email protected]e99ef6f2011-10-16 01:13:001850void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081851 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001852 if (!webwidget_)
1853 return;
changwanf2a707b2015-10-30 08:22:161854 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291855 return;
[email protected]e99ef6f2011-10-16 01:13:001856
mohsenb0eeba72015-08-09 06:20:081857#if defined(USE_AURA)
1858 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1859 // Aura beucause composited selection updates are not working for webview tags
1860 // which regresses IME inside webview. Remove this when composited selection
1861 // updates are fixed for webviews. See, http://crbug.com/510568.
1862 bool send_ipc = true;
1863#else
jddukeacf809e2014-09-23 20:38:381864 // With composited selection updates, the selection bounds will be reported
1865 // directly by the compositor, in which case explicit IPC selection
1866 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081867 bool send_ipc =
1868 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1869#endif
1870 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381871 ViewHostMsg_SelectionBounds_Params params;
1872 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1873 if (selection_anchor_rect_ != params.anchor_rect ||
1874 selection_focus_rect_ != params.focus_rect) {
1875 selection_anchor_rect_ = params.anchor_rect;
1876 selection_focus_rect_ = params.focus_rect;
1877 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1878 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1879 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1880 }
[email protected]58b48a0d2012-06-13 07:01:351881 }
jddukeacf809e2014-09-23 20:38:381882
[email protected]88dbe32f2013-06-20 23:31:361883 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001884}
1885
avi40b5be7a2016-03-03 21:13:441886void RenderWidget::SetDeviceColorProfileForTesting(
1887 const std::vector<char>& color_profile) {
1888 SetDeviceColorProfile(color_profile);
1889}
1890
1891void RenderWidget::ResetDeviceColorProfileForTesting() {
1892 std::vector<char> color_profile;
1893 color_profile.push_back('0');
1894 SetDeviceColorProfile(color_profile);
1895}
1896
[email protected]180ef242013-11-07 06:50:461897// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
danakj365175c2016-02-06 00:37:371898STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1899STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1900STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1901 ui::TEXT_INPUT_TYPE_PASSWORD);
1902STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1903STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1904STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1905STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1906 ui::TEXT_INPUT_TYPE_TELEPHONE);
1907STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1908STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1909STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1910 ui::TEXT_INPUT_TYPE_DATE_TIME);
1911STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1912 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1913STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1914STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1915STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1916STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1917 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1918STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1919 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1920STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1921 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451922
[email protected]5b739cb2012-08-21 20:35:211923ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461924 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211925 // Check the type is in the range representable by ui::TextInputType.
1926 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461927 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211928 return static_cast<ui::TextInputType>(type);
1929}
1930
[email protected]58b48a0d2012-06-13 07:01:351931void RenderWidget::GetCompositionCharacterBounds(
1932 std::vector<gfx::Rect>* bounds) {
1933 DCHECK(bounds);
1934 bounds->clear();
1935}
1936
[email protected]db4fc1e2013-09-06 20:01:511937void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:361938 size_t location, length;
1939 if (webwidget_->compositionRange(&location, &length)) {
1940 range->set_start(location);
1941 range->set_end(location + length);
1942 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1943 range->set_start(location);
1944 range->set_end(location + length);
1945 } else {
[email protected]db4fc1e2013-09-06 20:01:511946 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:361947 }
1948}
1949
[email protected]501ea13d2013-07-09 17:03:291950bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511951 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291952 const std::vector<gfx::Rect>& bounds) {
1953 if (composition_range_ != range)
1954 return true;
1955 if (bounds.size() != composition_character_bounds_.size())
1956 return true;
1957 for (size_t i = 0; i < bounds.size(); ++i) {
1958 if (bounds[i] != composition_character_bounds_[i])
1959 return true;
1960 }
1961 return false;
1962}
[email protected]501ea13d2013-07-09 17:03:291963
[email protected]ad26ef42011-06-17 07:59:451964bool RenderWidget::CanComposeInline() {
1965 return true;
[email protected]56ea1a62011-05-30 07:05:571966}
1967
[email protected]4873c7d2009-07-16 06:36:281968WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041969 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281970}
1971
[email protected]fa7b1dc2010-06-23 17:53:041972void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021973 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041974 // If the last text input type is not None, then we should finish any
1975 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451976 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041977 // If a composition text exists, then we need to let the browser process
1978 // to cancel the input method's ongoing composition session.
1979 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:221980 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041981 }
[email protected]d4cff272011-05-02 15:46:011982
[email protected]88dbe32f2013-06-20 23:31:361983 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041984}
1985
donnda070f3c2015-01-16 19:54:111986#if defined(OS_ANDROID)
1987void RenderWidget::showUnhandledTapUIIfNeeded(
1988 const WebPoint& tapped_position,
1989 const WebNode& tapped_node,
1990 bool page_changed) {
fsamuele8326c742016-01-12 00:49:391991 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:111992 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371993 !tapped_node.isContentEditable() &&
1994 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111995 if (should_trigger) {
1996 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1997 tapped_position.x, tapped_position.y));
1998 }
1999}
2000#endif
2001
[email protected]c68c3e4e2013-01-24 00:36:562002void RenderWidget::didHandleGestureEvent(
2003 const WebGestureEvent& event,
2004 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022005#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562006 if (event_cancelled)
2007 return;
[email protected]07c70d22014-08-21 08:33:462008 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:312009 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462010 } else if (event.type == WebInputEvent::GestureLongPress) {
2011 DCHECK(webwidget_);
2012 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:312013 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462014 else
fsamuel72464894f2015-12-15 06:59:312015 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562016 }
2017#endif
2018}
2019
sataya.m582c9ce2015-06-09 08:03:422020void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:312021 const blink::WebFloatSize& overscrollDelta,
2022 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422023 const blink::WebFloatPoint& position,
2024 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482025#if defined(OS_MACOSX)
2026 // On OSX the user can disable the elastic overscroll effect. If that's the
2027 // case, don't forward the overscroll notification.
2028 DCHECK(compositor_deps());
2029 if (!compositor_deps()->IsElasticOverscrollEnabled())
2030 return;
2031#endif
bokane53a10f2016-04-13 23:48:312032 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392033 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422034}
2035
[email protected]7912e822014-04-16 02:37:032036void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392037 if (!is_hidden())
2038 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032039}
2040
[email protected]24ed0432013-04-24 07:50:312041RenderWidgetCompositor* RenderWidget::compositor() const {
2042 return compositor_.get();
2043}
2044
fsamuel72464894f2015-12-15 06:59:312045void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392046 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372047}
[email protected]c3d45532011-10-07 19:20:402048
fsamuel72464894f2015-12-15 06:59:312049bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392050 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242051}
2052
fsamuel72464894f2015-12-15 06:59:312053void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392054 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312055}
2056
[email protected]ce6689f2013-03-29 12:52:552057void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112058 if (render_widget_scheduling_state_)
2059 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552060 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2061}
2062
danakj365175c2016-02-06 00:37:372063// Check blink::WebTouchAction and content::TouchAction is kept in sync.
2064STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
2065STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
2066STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
2067STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
2068STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
2069STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
2070STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
2071STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
2072STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
2073STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
2074 TOUCH_ACTION_MANIPULATION);
2075STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2076 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2077STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
mostynbe29b6882015-01-13 09:59:172078
[email protected]5d0bbdfa92013-12-10 00:35:512079void RenderWidget::setTouchAction(
2080 blink::WebTouchAction web_touch_action) {
2081
2082 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2083 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392084 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512085 return;
2086
[email protected]a18f67a2013-12-20 19:44:362087 content::TouchAction content_touch_action =
2088 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512089 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2090}
2091
[email protected]90f24152014-04-09 12:41:362092void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2093#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392094 if (!IsUsingImeThread())
2095 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362096#endif
2097}
2098
dchengcedca5612016-04-09 01:40:152099std::unique_ptr<WebGraphicsContext3DCommandBufferImpl>
penghuang346a46f92016-03-31 21:37:522100RenderWidget::CreateGraphicsContext3D(gpu::GpuChannelHost* gpu_channel_host) {
danakjd316e022016-03-31 01:07:592101 // This is for an offscreen context for raster in the compositor. So the
2102 // default framebuffer doesn't need alpha, depth, stencil, antialiasing.
2103 gpu::gles2::ContextCreationAttribHelper attributes;
2104 attributes.alpha_size = -1;
2105 attributes.depth_size = 0;
2106 attributes.stencil_size = 0;
2107 attributes.samples = 0;
2108 attributes.sample_buffers = 0;
2109 attributes.bind_generates_resource = false;
2110 attributes.lose_context_when_out_of_memory = true;
2111
[email protected]96ab016c2013-10-23 00:50:292112 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012113#if defined(OS_ANDROID)
boliu853d46052015-10-13 20:20:062114 bool using_synchronous_compositing =
boliubee541f42015-11-05 00:52:532115 SynchronousCompositorFactory::GetInstance() ||
2116 base::CommandLine::ForCurrentProcess()->HasSwitch(
2117 switches::kIPCSyncCompositing);
[email protected]b6eb8e332013-09-10 00:51:012118 // If we raster too fast we become upload bound, and pending
2119 // uploads consume memory. For maximum upload throughput, we would
2120 // want to allow for upload_throughput * pipeline_time of pending
2121 // uploads, after which we are just wasting memory. Since we don't
2122 // know our upload throughput yet, this just caps our memory usage.
boliu853d46052015-10-13 20:20:062123 // Synchronous compositor uses half because synchronous compositor
2124 // pipeline is only one frame deep. But twice of half for low end
2125 // because 16bit texture is not supported.
2126 size_t divider = using_synchronous_compositing ? 2 : 1;
[email protected]35b4f0c2014-06-26 16:55:272127 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032128 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012129 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032130 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012131 // Deadline to draw a frame to achieve 60 frames per second.
2132 const size_t kMillisecondsPerFrame = 16;
2133 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032134 size_t max_transfer_buffer_usage_mb =
2135 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2136 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012137 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2138 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292139 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032140 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012141#endif
piman990d8ea2016-01-12 15:35:312142 limits.command_buffer_size = 64 * 1024;
2143 limits.start_transfer_buffer_size = 64 * 1024;
2144 limits.min_transfer_buffer_size = 64 * 1024;
[email protected]96ab016c2013-10-23 00:50:292145
danakjd316e022016-03-31 01:07:592146 bool share_resources = true;
2147 bool automatic_flushes = false;
2148
dchengcedca5612016-04-09 01:40:152149 return base::WrapUnique(new WebGraphicsContext3DCommandBufferImpl(
piman934b1742016-03-11 17:11:182150 gpu::kNullSurfaceHandle, GetURLForGraphicsContext3D(), gpu_channel_host,
danakjd316e022016-03-31 01:07:592151 attributes, gfx::PreferIntegratedGpu, share_resources, automatic_flushes,
2152 limits, nullptr));
[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