blob: b0a74d63d62d6cdd93e6baf4bb4c405049701049 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
dcheng07945f632015-12-26 07:59:327#include <utility>
8
[email protected]c27dd4f2014-05-22 18:05:199#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2110#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0011#include "base/command_line.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/logging.h"
avi1023d012015-12-25 02:39:1413#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4015#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3016#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2118#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2720#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0121#include "base/trace_event/trace_event.h"
22#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4823#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5224#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3325#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3026#include "cc/output/output_surface.h"
fsamuel78f86e42016-01-20 04:10:2327#include "cc/scheduler/begin_frame_source.h"
[email protected]556fd292013-03-18 08:03:0428#include "cc/trees/layer_tree_host.h"
alexclarke7fa93942015-10-21 15:37:1129#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2130#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]29e2fb42013-07-19 01:13:4731#include "content/child/npapi/webplugin.h"
oshima750cb4342015-10-31 00:59:0132#include "content/common/content_switches_internal.h"
[email protected]0634cdd42013-08-16 00:46:0933#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5934#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2935#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3536#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4437#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1538#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1539#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5040#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2941#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4242#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4043#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5144#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5945#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2946#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1147#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5948#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1149#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2850#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2951#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1352#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3253#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1654#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2755#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0556#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4457#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5558#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:0959#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0460#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1861#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4862#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1863#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3064#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1165#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3066#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1867#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3068#include "third_party/WebKit/public/platform/WebSize.h"
69#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4370#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5971#include "third_party/WebKit/public/web/WebFrameWidget.h"
72#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1173#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3174#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3175#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
76#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3877#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5978#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4179#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1380#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5081#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0982#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3283#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4884#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2785#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4186#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4887
[email protected]eeb93112013-05-01 19:41:1088#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1589#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0790#include "content/renderer/android/synchronous_compositor_factory.h"
boliubee541f42015-11-05 00:52:5391#include "content/renderer/android/synchronous_compositor_filter.h"
92#include "content/renderer/android/synchronous_compositor_output_surface.h"
[email protected]eeb93112013-05-01 19:41:1093#endif
94
[email protected]661eb9d2009-02-03 02:11:4895#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4996#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5297#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4198#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4899#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44100
penghuang28a5fa22015-12-02 17:58:19101#if defined(MOJO_SHELL_CLIENT)
102#include "content/public/common/mojo_shell_connection.h"
fsamuel2545ecc2015-12-05 00:44:46103#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:19104#endif
105
[email protected]2255a9332013-06-17 05:12:31106#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:29107
[email protected]180ef242013-11-07 06:50:46108using blink::WebCompositionUnderline;
109using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43110using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46111using blink::WebGestureEvent;
112using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49113using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46114using blink::WebKeyboardEvent;
115using blink::WebMouseEvent;
116using blink::WebMouseWheelEvent;
117using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11118using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46119using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11120using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46121using blink::WebPopupType;
122using blink::WebRange;
123using blink::WebRect;
124using blink::WebScreenInfo;
125using blink::WebSize;
126using blink::WebTextDirection;
127using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25128using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46129using blink::WebVector;
130using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26131
[email protected]6a4d7f62013-01-07 21:32:13132namespace {
[email protected]b256eca2013-07-11 10:57:40133
134typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
135
136class TextInputModeMapSingleton {
137 public:
138 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22139 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40140 }
[email protected]dd705d4d2013-11-27 08:14:41141 TextInputModeMapSingleton() {
142 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
143 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
144 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
145 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
146 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
147 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
148 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
149 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
150 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
151 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
152 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40153 }
[email protected]dd705d4d2013-11-27 08:14:41154 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40155 private:
[email protected]dd705d4d2013-11-27 08:14:41156 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40157
olli.raula36aa8be2015-09-10 11:14:22158 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40159
160 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
161};
162
[email protected]dd705d4d2013-11-27 08:14:41163ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40164 static TextInputModeMapSingleton* singleton =
165 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41166 TextInputModeMap::const_iterator it =
167 singleton->map().find(input_mode.utf8());
168 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40169 return ui::TEXT_INPUT_MODE_DEFAULT;
170 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13171}
[email protected]b256eca2013-07-11 10:57:40172
fsamuel72464894f2015-12-15 06:59:31173bool IsDateTimeInput(ui::TextInputType type) {
174 return type == ui::TEXT_INPUT_TYPE_DATE ||
175 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
176 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
177 type == ui::TEXT_INPUT_TYPE_MONTH ||
178 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
dtapuskae7473612015-12-04 14:23:06179}
180
fsamuele8326c742016-01-12 00:49:39181content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
182 content::RenderWidget* widget) {
183#if defined(MOJO_SHELL_CLIENT)
penghuang639a1042016-01-14 21:25:29184 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
185 if (content::MojoShellConnection::Get() &&
186 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39187 return content::RenderWidgetMusConnection::GetOrCreate(
188 widget->routing_id());
189 }
190#endif
191 // If we don't have a connection to the Mojo shell, then we want to route IPCs
192 // back to the browser process rather than Mus so we use the |widget| as the
193 // RenderWidgetInputHandlerDelegate.
194 return widget;
195}
196
[email protected]b256eca2013-07-11 10:57:40197} // namespace
198
[email protected]e9ff79c2012-10-19 21:31:26199namespace content {
[email protected]62cb33cae2009-03-27 23:30:22200
[email protected]b2e4c70132013-10-03 02:07:51201// RenderWidget::ScreenMetricsEmulator ----------------------------------------
202
203class RenderWidget::ScreenMetricsEmulator {
204 public:
205 ScreenMetricsEmulator(
206 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43207 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51208 virtual ~ScreenMetricsEmulator();
209
[email protected]19193682014-04-03 15:01:43210 // Scale and offset used to convert between host coordinates
211 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51212 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20213 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43214 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51215 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56216 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51217
218 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43219 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51220
221 // The following methods alter handlers' behavior for messages related to
222 // widget size and position.
fsamuel664e8b62016-01-20 19:54:01223 void OnResizeMessage(const ResizeParams& params);
[email protected]b2e4c70132013-10-03 02:07:51224 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
225 const gfx::Rect& window_screen_rect);
226 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31227 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51228
229 private:
[email protected]19193682014-04-03 15:01:43230 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02231 void Apply(bool top_controls_shrink_blink_size,
232 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44233 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12234 bool is_fullscreen_granted,
235 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51236
237 RenderWidget* widget_;
238
[email protected]7f99fc22013-11-08 14:05:58239 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43240 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51241
[email protected]a179d3962013-11-12 14:44:40242 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51243 float scale_;
dgozman9260b0a12015-03-16 13:45:20244 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51245
[email protected]19193682014-04-03 15:01:43246 // Widget rect as passed to webwidget.
247 gfx::Rect applied_widget_rect_;
248
[email protected]b2e4c70132013-10-03 02:07:51249 // Original values to restore back after emulation ends.
250 gfx::Size original_size_;
251 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28252 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46253 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51254 gfx::Rect original_view_screen_rect_;
255 gfx::Rect original_window_screen_rect_;
256};
257
258RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
259 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43260 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51261 : widget_(widget),
[email protected]19193682014-04-03 15:01:43262 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51263 scale_(1.f) {
264 original_size_ = widget_->size_;
265 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28266 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51267 original_screen_info_ = widget_->screen_info_;
268 original_view_screen_rect_ = widget_->view_screen_rect_;
269 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02270 Apply(widget_->top_controls_shrink_blink_size_,
271 widget_->top_controls_height_,
272 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12273 widget_->is_fullscreen_granted_,
274 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51275}
276
277RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
278 widget_->screen_info_ = original_screen_info_;
279
280 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20281 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51282 widget_->view_screen_rect_ = original_view_screen_rect_;
283 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01284 widget_->Resize(original_size_,
285 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02286 widget_->top_controls_shrink_blink_size_,
287 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01288 original_visible_viewport_size_,
289 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12290 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12291 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01292 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51293}
294
295void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43296 const WebDeviceEmulationParams& params) {
297 params_ = params;
298 Reapply();
299}
300
301void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02302 Apply(widget_->top_controls_shrink_blink_size_,
303 widget_->top_controls_height_,
304 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12305 widget_->is_fullscreen_granted_,
306 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51307}
308
[email protected]19193682014-04-03 15:01:43309void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02310 bool top_controls_shrink_blink_size,
311 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44312 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12313 bool is_fullscreen_granted,
314 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31315 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
316 if (!applied_widget_rect_.width())
317 applied_widget_rect_.set_width(original_size_.width());
318 if (!applied_widget_rect_.height())
319 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43320
[email protected]f442ee42014-05-14 11:53:12321 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02322 int original_width = std::max(original_size_.width(), 1);
323 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51324 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02325 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51326 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02327 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51328 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
329 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01330
331 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43332 offset_.set_x(
333 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01334 offset_.set_y(
[email protected]19193682014-04-03 15:01:43335 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51336 } else {
[email protected]0b3578c2014-06-20 18:29:02337 scale_ = params_.scale;
338 offset_.SetPoint(params_.offset.x, params_.offset.y);
dgozman9f441e72016-01-14 23:06:11339 if (!params_.viewSize.width && !params_.viewSize.height && scale_) {
340 applied_widget_rect_.set_size(gfx::ScaleToRoundedSize(
341 original_size_, 1.f / scale_));
342 }
[email protected]7f0e8fa2014-03-26 12:32:01343 }
[email protected]7f0e8fa2014-03-26 12:32:01344
[email protected]19193682014-04-03 15:01:43345 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
346 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01347 widget_->screen_info_.rect = original_screen_info_.rect;
348 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
349 widget_->window_screen_rect_ = original_window_screen_rect_;
350 } else {
dgozmanf28ccbe2015-06-24 08:50:49351 applied_widget_rect_.set_origin(params_.viewPosition);
352 gfx::Rect screen_rect = applied_widget_rect_;
353 if (!params_.screenSize.isEmpty()) {
354 screen_rect =
355 gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height);
356 }
357 widget_->screen_info_.rect = screen_rect;
358 widget_->screen_info_.availableRect = screen_rect;
[email protected]19193682014-04-03 15:01:43359 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01360 }
[email protected]a179d3962013-11-12 14:44:40361
[email protected]19193682014-04-03 15:01:43362 float applied_device_scale_factor = params_.deviceScaleFactor ?
363 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01364 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51365
[email protected]7f99fc22013-11-08 14:05:58366 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51367 // - we keep the real device scale factor in compositor to produce sharp image
368 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58369 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51370 // root layer.
dgozman9260b0a12015-03-16 13:45:20371 blink::WebDeviceEmulationParams modified_params = params_;
372 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
373 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
374 modified_params.scale = scale_;
375 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51376
[email protected]7f0e8fa2014-03-26 12:32:01377 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43378 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51379
danakjddaec912015-09-25 19:38:40380 gfx::Size physical_backing_size = gfx::ScaleToCeiledSize(
381 original_size_, original_screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02382 widget_->Resize(applied_widget_rect_.size(),
383 physical_backing_size,
384 top_controls_shrink_blink_size,
385 top_controls_height,
386 applied_widget_rect_.size(),
387 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12388 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12389 display_mode,
dtrainorcb7779b82014-12-04 01:08:02390 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51391}
392
393void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
fsamuel664e8b62016-01-20 19:54:01394 const ResizeParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51395 bool need_ack = params.new_size != original_size_ &&
396 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
397 original_size_ = params.new_size;
398 original_physical_backing_size_ = params.physical_backing_size;
399 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28400 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02401 Apply(params.top_controls_shrink_blink_size,
402 params.top_controls_height,
403 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12404 params.is_fullscreen_granted,
405 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51406
407 if (need_ack) {
408 widget_->set_next_paint_is_resize_ack();
409 if (widget_->compositor_)
410 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
411 }
412}
413
414void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
415 const gfx::Rect& view_screen_rect,
416 const gfx::Rect& window_screen_rect) {
417 original_view_screen_rect_ = view_screen_rect;
418 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43419 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
420 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51421}
422
423void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
424 ContextMenuParams* params) {
425 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40426 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51427 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40428 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51429}
430
[email protected]2d6836f42014-07-02 17:25:31431gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
432 const gfx::Rect& anchor) {
danakj4606f6332015-08-31 23:56:56433 gfx::Rect scaled = gfx::ScaleToEnclosedRect(anchor, scale_);
[email protected]2d6836f42014-07-02 17:25:31434 scaled.set_x(scaled.x() + offset_.x());
435 scaled.set_y(scaled.y() + offset_.y());
436 return scaled;
437}
438
[email protected]b2e4c70132013-10-03 02:07:51439// RenderWidget ---------------------------------------------------------------
440
dcheng35d31c112015-07-22 00:17:36441RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
442 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46443 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04444 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03445 bool hidden,
446 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29447 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36448 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53449 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29450 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02451 top_controls_shrink_blink_size_(false),
452 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29453 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51454 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09455 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29456 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04457 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39458 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12459 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12460 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16461 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48462 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22463 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44464 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20465 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45466 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40467 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20468 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53469 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12470 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48471 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04472 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52473 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30474 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13475#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36476 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13477#endif
[email protected]b2e4c70132013-10-03 02:07:51478 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11479 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42480 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51481 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05482 if (!swapped_out)
483 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27484 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53485 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37486#if defined(OS_ANDROID)
487 text_input_info_history_.push_back(blink::WebTextInputInfo());
488#endif
alexclarke7fa93942015-10-21 15:37:11489
490 // In tests there may not be a RenderThreadImpl.
491 if (RenderThreadImpl::current()) {
492 render_widget_scheduling_state_ = RenderThreadImpl::current()
493 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32494 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11495 render_widget_scheduling_state_->SetHidden(is_hidden_);
496 }
initial.commit09911bf2008-07-26 23:55:29497}
498
499RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11500 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16501
[email protected]992db4c2011-05-12 15:37:15502 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02503 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15504 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29505}
506
[email protected]484955942010-08-19 16:13:18507// static
avi1023d012015-12-25 02:39:14508RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53509 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46510 blink::WebPopupType popup_type,
511 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29512 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36513 scoped_refptr<RenderWidget> widget(new RenderWidget(
514 compositor_deps, popup_type, screen_info, false, false, false));
515 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46516 return widget.get();
[email protected]a635f942012-12-07 10:34:29517 }
518 return NULL;
initial.commit09911bf2008-07-26 23:55:29519}
520
[email protected]484955942010-08-19 16:13:18521// static
kenrba7199832015-01-22 23:44:59522RenderWidget* RenderWidget::CreateForFrame(
523 int routing_id,
kenrba7199832015-01-22 23:44:59524 bool hidden,
525 const blink::WebScreenInfo& screen_info,
526 CompositorDependencies* compositor_deps,
527 blink::WebLocalFrame* frame) {
528 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55529 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
530 // same routing ID for both the view routing ID and the main frame widget
531 // routing ID. https://crbug.com/545684
532 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
533 if (view) {
534 view->AttachWebFrameWidget(RenderWidget::CreateWebFrameWidget(view, frame));
535 return view;
536 }
dcheng35d31c112015-07-22 00:17:36537 scoped_refptr<RenderWidget> widget(
538 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
539 false, hidden, false));
fsamuele8326c742016-01-12 00:49:39540 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20541 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59542 // DoInit increments the reference count on |widget|, keeping it alive after
543 // this function returns.
dcheng35d31c112015-07-22 00:17:36544 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59545 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
546 nullptr)) {
kenrba7199832015-01-22 23:44:59547 return widget.get();
548 }
549 return nullptr;
550}
551
552// static
dchengda9b4bb2015-07-20 20:58:08553blink::WebWidget* RenderWidget::CreateWebFrameWidget(
554 RenderWidget* render_widget,
555 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55556 if (!frame->parent()) {
557 // TODO(dcheng): The main frame widget currently has a special case.
558 // Eliminate this once WebView is no longer a WebWidget.
559 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
560 }
dchengda9b4bb2015-07-20 20:58:08561 return blink::WebFrameWidget::create(render_widget, frame);
562}
563
564// static
kenrba7199832015-01-22 23:44:59565blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18566 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46567 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18568 break;
[email protected]180ef242013-11-07 06:50:46569 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44570 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18571 default:
572 NOTREACHED();
573 }
574 return NULL;
575}
576
dchengda9b4bb2015-07-20 20:58:08577void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32578 OnClose();
kenrba7199832015-01-22 23:44:59579}
580
fsamuele8326c742016-01-12 00:49:39581void RenderWidget::SetRoutingID(int32_t routing_id) {
582 routing_id_ = routing_id;
583 input_handler_.reset(new RenderWidgetInputHandler(
584 GetRenderWidgetInputHandlerDelegate(this), this));
585}
586
avi1023d012015-12-25 02:39:14587bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39588 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05589 opener_id, RenderWidget::CreateWebWidget(this),
590 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39591 if (success) {
592 SetRoutingID(routing_id_);
593 return true;
594 }
595 return false;
[email protected]484955942010-08-19 16:13:18596}
597
avi1023d012015-12-25 02:39:14598bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06599 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18600 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29601 DCHECK(!webwidget_);
602
603 if (opener_id != MSG_ROUTING_NONE)
604 opener_id_ = opener_id;
605
[email protected]484955942010-08-19 16:13:18606 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29607
kenrba7199832015-01-22 23:44:59608 bool result = true;
609 if (create_widget_message)
610 result = RenderThread::Get()->Send(create_widget_message);
611
initial.commit09911bf2008-07-26 23:55:29612 if (result) {
[email protected]380244092011-10-07 17:26:27613 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29614 // Take a reference on behalf of the RenderThread. This will be balanced
615 // when we receive ViewMsg_Close.
616 AddRef();
[email protected]b2db9272014-01-10 17:42:00617 if (RenderThreadImpl::current()) {
618 RenderThreadImpl::current()->WidgetCreated();
619 if (is_hidden_)
620 RenderThreadImpl::current()->WidgetHidden();
621 }
fsamuele8326c742016-01-12 00:49:39622
[email protected]a635f942012-12-07 10:34:29623 return true;
initial.commit09911bf2008-07-26 23:55:29624 } else {
[email protected]a635f942012-12-07 10:34:29625 // The above Send can fail when the tab is closing.
626 return false;
initial.commit09911bf2008-07-26 23:55:29627 }
628}
629
[email protected]992db4c2011-05-12 15:37:15630void RenderWidget::SetSwappedOut(bool is_swapped_out) {
631 // We should only toggle between states.
632 DCHECK(is_swapped_out_ != is_swapped_out);
633 is_swapped_out_ = is_swapped_out;
634
635 // If we are swapping out, we will call ReleaseProcess, allowing the process
636 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52637 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15638 // If we are swapping in, we call AddRefProcess to prevent the process from
639 // exiting.
[email protected]949b6592014-08-20 13:17:52640 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15641 RenderProcess::current()->AddRefProcess();
642}
643
[email protected]949b6592014-08-20 13:17:52644void RenderWidget::WasSwappedOut() {
645 // If we have been swapped out and no one else is using this process,
646 // it's safe to exit now.
647 CHECK(is_swapped_out_);
648 RenderProcess::current()->ReleaseProcess();
649}
650
[email protected]b2e4c70132013-10-03 02:07:51651void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
652 ScreenMetricsEmulator* emulator) {
653 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43654 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49655 popup_screen_origin_for_emulation_ = gfx::Point(
656 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
657 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56658 screen_info_ = emulator->original_screen_info();
659 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51660}
661
[email protected]2d6836f42014-07-02 17:25:31662gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
663 if (screen_metrics_emulator_)
664 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
665 return anchor;
666}
667
[email protected]b2e4c70132013-10-03 02:07:51668void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20669 bool enabled,
670 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51671 // This is only supported in RenderView.
672 NOTREACHED();
673}
674
[email protected]53907862014-03-25 15:42:40675#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51676void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
677 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49678 popup->SetOriginScaleAndOffsetForEmulation(
679 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51680}
[email protected]53907862014-03-25 15:42:40681#endif
[email protected]b2e4c70132013-10-03 02:07:51682
683void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
684 if (screen_metrics_emulator_)
685 screen_metrics_emulator_->OnShowContextMenu(params);
686}
687
[email protected]a95986a82010-12-24 06:19:28688bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
689 bool handled = true;
690 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15691 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22692 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
693 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22694 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
695 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15696 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
697 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35698 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
699 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28700 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28701 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20702 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
703 OnEnableDeviceEmulation)
704 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
705 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41706 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54707 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28708 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41709 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25710 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28711 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
712 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03713 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05714 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21715#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37716 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
[email protected]2384b6c2013-02-28 23:58:51717 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21718#endif
dtrainor5ef644e2015-11-19 00:12:47719 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28720 IPC_MESSAGE_UNHANDLED(handled = false)
721 IPC_END_MESSAGE_MAP()
722 return handled;
723}
initial.commit09911bf2008-07-26 23:55:29724
725bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15726 // Don't send any messages after the browser has told us to close, and filter
727 // most outgoing messages while swapped out.
728 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26729 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11730 closing_) {
initial.commit09911bf2008-07-26 23:55:29731 delete message;
732 return false;
733 }
734
735 // If given a messsage without a routing ID, then assign our routing ID.
736 if (message->routing_id() == MSG_ROUTING_NONE)
737 message->set_routing_id(routing_id_);
738
[email protected]380244092011-10-07 17:26:27739 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44740}
741
[email protected]61e2b3cc2012-03-02 16:13:34742void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44743 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02744 bool top_controls_shrink_blink_size,
745 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44746 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34747 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12748 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12749 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58750 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56751 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48752 // A resize ack shouldn't be requested if we have not ACK'd the previous
753 // one.
754 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
755 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
756 }
initial.commit09911bf2008-07-26 23:55:29757
[email protected]61e2b3cc2012-03-02 16:13:34758 // Ignore this during shutdown.
759 if (!webwidget_)
760 return;
761
oshima750cb4342015-10-31 00:59:01762 if (compositor_)
763 compositor_->setViewportSize(physical_backing_size);
[email protected]60d47ac2013-03-01 23:42:44764
oshima750cb4342015-10-31 00:59:01765 bool resized = size_ != new_size ||
766 physical_backing_size_ != physical_backing_size;
767
768 size_ = new_size;
[email protected]dade8992013-03-04 07:34:34769 physical_backing_size_ = physical_backing_size;
oshima750cb4342015-10-31 00:59:01770
dtrainorcb7779b82014-12-04 01:08:02771 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
772 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28773 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34774 resizer_rect_ = resizer_rect;
775
776 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12777 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12778 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12779 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34780
aelias6004fe02015-02-07 21:43:01781 webwidget_->setTopControlsHeight(top_controls_height,
782 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43783
oshima750cb4342015-10-31 00:59:01784 if (resized) {
785 gfx::Size new_widget_size =
786 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_;
[email protected]61e2b3cc2012-03-02 16:13:34787 // When resizing, we want to wait to paint before ACK'ing the resize. This
788 // ensures that we only resize as fast as we can paint. We only need to
789 // send an ACK if we are resized to a non-empty rect.
oshima750cb4342015-10-31 00:59:01790 webwidget_->resize(new_widget_size);
791 }
jbroman304f01a2015-11-05 17:04:21792 WebSize visual_viewport_size;
oshima750cb4342015-10-31 00:59:01793
794 if (IsUseZoomForDSFEnabled()) {
oshimad5279032015-12-16 18:22:33795 visual_viewport_size =
796 gfx::ScaleToCeiledSize(visible_viewport_size, device_scale_factor_);
oshima750cb4342015-10-31 00:59:01797 } else {
jbroman304f01a2015-11-05 17:04:21798 visual_viewport_size = visible_viewport_size_;
[email protected]632c4382013-05-15 08:58:45799 }
800
jbroman304f01a2015-11-05 17:04:21801 webwidget()->resizeVisualViewport(visual_viewport_size);
[email protected]bb6378fe2014-04-28 21:19:44802
[email protected]632c4382013-05-15 08:58:45803 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58804 // In this case there is no paint/composite and therefore no
805 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
806 // ack through a fake ViewHostMsg_UpdateRect or a different message.
807 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34808 }
809
[email protected]20fbfc22013-05-08 20:50:58810 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45811 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58812 set_next_paint_is_resize_ack();
813
[email protected]61e2b3cc2012-03-02 16:13:34814 if (fullscreen_change)
815 DidToggleFullscreen();
816
817 // If a resize ack is requested and it isn't set-up, then no more resizes will
818 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45819 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29820}
821
bokanc007c3a2015-02-03 07:15:56822void RenderWidget::SetWindowRectSynchronously(
823 const gfx::Rect& new_window_rect) {
824 Resize(new_window_rect.size(),
oshimac059194c2016-01-12 19:40:15825 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_),
dtrainorcb7779b82014-12-04 01:08:02826 top_controls_shrink_blink_size_,
827 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56828 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01829 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12830 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12831 display_mode_,
[email protected]587941d2014-08-22 01:40:01832 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56833 view_screen_rect_ = new_window_rect;
834 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02835 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56836 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02837}
838
initial.commit09911bf2008-07-26 23:55:29839void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32840 DCHECK(content::RenderThread::Get());
841 if (closing_)
842 return;
843 NotifyOnClose();
844 closing_ = true;
845
846 // Browser correspondence is no longer needed at this point.
847 if (routing_id_ != MSG_ROUTING_NONE) {
848 RenderThread::Get()->RemoveRoute(routing_id_);
849 SetHidden(false);
850 if (RenderThreadImpl::current())
851 RenderThreadImpl::current()->WidgetDestroyed();
852 }
853
854 if (for_oopif_) {
855 // Widgets for frames may be created and closed at any time while the frame
856 // is alive. However, the closing process must happen synchronously. Frame
857 // widget and frames hold pointers to each other. If Close() is deferred to
858 // the message loop like in the non-frame widget case, WebWidget::close()
859 // can end up accessing members of an already-deleted frame.
860 Close();
861 } else {
862 // If there is a Send call on the stack, then it could be dangerous to close
863 // now. Post a task that only gets invoked when there are no nested message
864 // loops.
865 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
866 FROM_HERE, base::Bind(&RenderWidget::Close, this));
867 }
868
869 // Balances the AddRef taken when we called AddRoute.
870 Release();
initial.commit09911bf2008-07-26 23:55:29871}
872
fsamuel664e8b62016-01-20 19:54:01873void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04874 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32875 return;
876
[email protected]b2e4c70132013-10-03 02:07:51877 if (screen_metrics_emulator_) {
878 screen_metrics_emulator_->OnResizeMessage(params);
879 return;
880 }
881
[email protected]fcdc5642014-05-09 14:32:24882 bool orientation_changed =
883 screen_info_.orientationAngle != params.screen_info.orientationAngle;
884
[email protected]0fdd5012013-05-29 08:05:56885 screen_info_ = params.screen_info;
886 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02887 Resize(params.new_size,
888 params.physical_backing_size,
889 params.top_controls_shrink_blink_size,
890 params.top_controls_height,
891 params.visible_viewport_size,
892 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12893 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12894 params.display_mode,
sievers4e33dae2015-02-25 20:43:58895 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24896
897 if (orientation_changed)
898 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29899}
900
dgozman9260b0a12015-03-16 13:45:20901void RenderWidget::OnEnableDeviceEmulation(
902 const blink::WebDeviceEmulationParams& params) {
903 if (!screen_metrics_emulator_)
904 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
905 else
906 screen_metrics_emulator_->ChangeEmulationParams(params);
907}
908
909void RenderWidget::OnDisableDeviceEmulation() {
910 screen_metrics_emulator_.reset();
911}
912
noel89949e62014-09-30 01:12:41913void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
914 SetDeviceColorProfile(color_profile);
915}
916
[email protected]b5913d72012-02-07 22:26:54917void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01918 if (resizer_rect_ == resizer_rect)
919 return;
920 resizer_rect_ = resizer_rect;
921 if (webwidget_)
922 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54923}
924
initial.commit09911bf2008-07-26 23:55:29925void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31926 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29927 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03928 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59929 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
930 WasHidden());
initial.commit09911bf2008-07-26 23:55:29931}
932
[email protected]3399dd822014-08-09 11:14:24933void RenderWidget::OnWasShown(bool needs_repainting,
934 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41935 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29936 // During shutdown we can just ignore this message.
937 if (!webwidget_)
938 return;
939
940 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03941 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59942 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
943 WasShown());
initial.commit09911bf2008-07-26 23:55:29944
[email protected]8a23afb32014-04-30 22:40:23945 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29946 return;
initial.commit09911bf2008-07-26 23:55:29947
948 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24949 if (compositor_) {
950 ui::LatencyInfo swap_latency_info(latency_info);
951 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
952 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05953 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24954 }
jdduke491a3f0c2015-06-15 23:30:26955 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29956}
957
[email protected]53d3f302009-12-21 04:42:05958void RenderWidget::OnRequestMoveAck() {
959 DCHECK(pending_window_rect_count_);
960 pending_window_rect_count_--;
961}
962
[email protected]ed7defa2013-03-12 21:29:59963GURL RenderWidget::GetURLForGraphicsContext3D() {
964 return GURL();
[email protected]65225772011-05-12 21:10:24965}
966
fsamuel78f86e42016-01-20 04:10:23967void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
968 const ui::LatencyInfo& latency_info) {
969 if (!input_event)
970 return;
971 input_handler_->HandleInputEvent(*input_event, latency_info);
972}
973
974void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
975 if (webwidget_)
976 webwidget_->setCursorVisibilityState(is_visible);
977}
978
979void RenderWidget::OnMouseCaptureLost() {
980 if (webwidget_)
981 webwidget_->mouseCaptureLost();
982}
983
984void RenderWidget::OnSetFocus(bool enable) {
985 if (webwidget_)
986 webwidget_->setFocus(enable);
987}
988
989///////////////////////////////////////////////////////////////////////////////
990// RenderWidgetCompositorDelegate
991
992void RenderWidget::ApplyViewportDeltas(
993 const gfx::Vector2dF& inner_delta,
994 const gfx::Vector2dF& outer_delta,
995 const gfx::Vector2dF& elastic_overscroll_delta,
996 float page_scale,
997 float top_controls_delta) {
998 webwidget_->applyViewportDeltas(inner_delta, outer_delta,
999 elastic_overscroll_delta, page_scale,
1000 top_controls_delta);
1001}
1002
1003void RenderWidget::BeginMainFrame(double frame_time_sec) {
1004 webwidget_->beginFrame(frame_time_sec);
1005}
1006
[email protected]ebc0e1df2013-08-01 02:46:221007scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
piman990d8ea2016-01-12 15:35:311008 DCHECK(webwidget_);
[email protected]7912e822014-04-16 02:37:031009 // For widgets that are never visible, we don't start the compositor, so we
1010 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:391011 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:191012
avi83883c82014-12-23 00:08:491013 const base::CommandLine& command_line =
1014 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:331015 bool use_software = fallback;
1016 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
1017 use_software = true;
1018
penghuang28a5fa22015-12-02 17:58:191019#if defined(MOJO_SHELL_CLIENT)
1020 if (MojoShellConnection::Get() && !use_software) {
1021 RenderWidgetMusConnection* connection =
1022 RenderWidgetMusConnection::GetOrCreate(routing_id());
1023 return connection->CreateOutputSurface();
1024 }
1025#endif
1026
piman990d8ea2016-01-12 15:35:311027 scoped_refptr<GpuChannelHost> gpu_channel_host;
1028 if (!use_software) {
1029 CauseForGpuLaunch cause =
1030 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
1031 gpu_channel_host =
1032 RenderThreadImpl::current()->EstablishGpuChannelSync(cause);
1033 if (!gpu_channel_host.get()) {
1034 // Cause the compositor to wait and try again.
1035 return nullptr;
1036 }
1037 // We may get a valid channel, but with a software renderer. In that case,
1038 // disable GPU compositing.
1039 if (gpu_channel_host->gpu_info().software_rendering)
1040 use_software = true;
1041 }
1042
[email protected]0634cdd42013-08-16 00:46:091043 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:171044 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:331045 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:091046 context_provider = ContextProviderCommandBuffer::Create(
piman990d8ea2016-01-12 15:35:311047 CreateGraphicsContext3D(gpu_channel_host.get()),
1048 RENDER_COMPOSITOR_CONTEXT);
1049 DCHECK(context_provider);
revemand180dfc32015-09-24 00:19:431050 worker_context_provider =
1051 RenderThreadImpl::current()->SharedWorkerContextProvider();
1052 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:171053 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:341054 return nullptr;
vmiura78b69282015-02-14 00:01:171055 }
boliu853d46052015-10-13 20:20:061056
1057#if defined(OS_ANDROID)
1058 if (SynchronousCompositorFactory* factory =
1059 SynchronousCompositorFactory::GetInstance()) {
1060 return factory->CreateOutputSurface(
1061 routing_id(), frame_swap_message_queue_, context_provider,
1062 worker_context_provider);
boliubee541f42015-11-05 00:52:531063 } else if (RenderThreadImpl::current()->sync_compositor_message_filter()) {
1064 return make_scoped_ptr(new SynchronousCompositorOutputSurface(
1065 context_provider, worker_context_provider, routing_id(),
1066 content::RenderThreadImpl::current()
1067 ->sync_compositor_message_filter(),
1068 frame_swap_message_queue_));
boliu853d46052015-10-13 20:20:061069 }
1070#endif
[email protected]0634cdd42013-08-16 00:46:091071 }
[email protected]ebc0e1df2013-08-01 02:46:221072
avi1023d012015-12-25 02:39:141073 uint32_t output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:341074 // Composite-to-mailbox is currently used for layout tests in order to cause
1075 // them to draw inside in the renderer to do the readback there. This should
1076 // no longer be the case when crbug.com/311404 is fixed.
1077 if (!RenderThreadImpl::current() ||
1078 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:531079 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
piman8944e1c2015-09-22 21:10:341080 return make_scoped_ptr(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171081 routing_id(), output_surface_id, context_provider,
1082 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091083 }
piman8944e1c2015-09-22 21:10:341084
[email protected]0634cdd42013-08-16 00:46:091085 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091086 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121087 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091088
piman8944e1c2015-09-22 21:10:341089 return make_scoped_ptr(new CompositorOutputSurface(
caseqff9c74c2015-02-10 14:56:291090 routing_id(), output_surface_id, nullptr, nullptr,
dcheng07945f632015-12-26 07:59:321091 std::move(software_device), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221092 }
[email protected]ed7defa2013-03-12 21:29:591093
piman8944e1c2015-09-22 21:10:341094 return make_scoped_ptr(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171095 routing_id(), output_surface_id, context_provider,
piman8944e1c2015-09-22 21:10:341096 worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:281097}
1098
fsamuel78f86e42016-01-20 04:10:231099scoped_ptr<cc::BeginFrameSource>
1100RenderWidget::CreateExternalBeginFrameSource() {
1101 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_);
1102}
1103
1104void RenderWidget::DidCommitAndDrawCompositorFrame() {
1105 // NOTE: Tests may break if this event is renamed or moved. See
1106 // tab_capture_performancetest.cc.
1107 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
1108 // Notify subclasses that we initiated the paint operation.
1109 DidInitiatePaint();
1110}
1111
1112void RenderWidget::DidCommitCompositorFrame() {
1113 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1114 DidCommitCompositorFrame());
1115 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
1116 DidCommitCompositorFrame());
1117#if defined(VIDEO_HOLE)
1118 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1119 DidCommitCompositorFrame());
1120#endif // defined(VIDEO_HOLE)
1121 input_handler_->FlushPendingInputEventAck();
1122}
1123
1124void RenderWidget::DidCompletePageScaleAnimation() {}
1125
1126void RenderWidget::DidCompleteSwapBuffers() {
1127 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
1128
1129 // Notify subclasses threaded composited rendering was flushed to the screen.
1130 DidFlushPaint();
1131
1132 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_ &&
1133 !plugin_window_moves_.size()) {
1134 return;
1135 }
1136
1137 ViewHostMsg_UpdateRect_Params params;
1138 params.view_size = size_;
1139 params.plugin_window_moves.swap(plugin_window_moves_);
1140 params.flags = next_paint_flags_;
1141
1142 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1143 next_paint_flags_ = 0;
1144 need_update_rect_for_auto_resize_ = false;
1145}
1146
1147bool RenderWidget::ForOOPIF() const {
1148 // TODO(simonhong): Remove this when we enable BeginFrame scheduling for
1149 // OOPIF(crbug.com/471411).
1150 return for_oopif_;
1151}
1152
1153void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
1154 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
1155}
1156
1157bool RenderWidget::IsClosing() const {
1158 return host_closing_;
1159}
1160
[email protected]4d7e46a2013-11-08 05:33:401161void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241162 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241163 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:261164 ScheduleComposite();
[email protected]65225772011-05-12 21:10:241165}
1166
[email protected]4d7e46a2013-11-08 05:33:401167void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241168 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161169
[email protected]404939f2012-06-01 04:06:181170 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161171 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291172}
1173
fsamuel78f86e42016-01-20 04:10:231174void RenderWidget::OnSwapBuffersPosted() {
1175 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:291176}
1177
fsamuel78f86e42016-01-20 04:10:231178void RenderWidget::RecordFrameTimingEvents(
1179 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events,
1180 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) {
1181 for (const auto& composite_event : *composite_events) {
1182 int64_t frameId = composite_event.first;
1183 const std::vector<cc::FrameTimingTracker::CompositeTimingEvent>& events =
1184 composite_event.second;
1185 std::vector<blink::WebFrameTimingEvent> webEvents;
1186 for (size_t i = 0; i < events.size(); ++i) {
1187 webEvents.push_back(blink::WebFrameTimingEvent(
1188 events[i].frame_id,
1189 (events[i].timestamp - base::TimeTicks()).InSecondsF()));
1190 }
1191 webwidget_->recordFrameTimingEvent(blink::WebWidget::CompositeEvent,
1192 frameId, webEvents);
1193 }
1194 for (const auto& main_frame_event : *main_frame_events) {
1195 int64_t frameId = main_frame_event.first;
1196 const std::vector<cc::FrameTimingTracker::MainFrameTimingEvent>& events =
1197 main_frame_event.second;
1198 std::vector<blink::WebFrameTimingEvent> webEvents;
1199 for (size_t i = 0; i < events.size(); ++i) {
1200 webEvents.push_back(blink::WebFrameTimingEvent(
1201 events[i].frame_id,
1202 (events[i].timestamp - base::TimeTicks()).InSecondsF(),
1203 (events[i].end_time - base::TimeTicks()).InSecondsF()));
1204 }
1205 webwidget_->recordFrameTimingEvent(blink::WebWidget::RenderEvent, frameId,
1206 webEvents);
1207 }
[email protected]34202de2013-05-06 23:36:221208}
1209
fsamuel78f86e42016-01-20 04:10:231210void RenderWidget::ScheduleAnimation() {
1211 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:291212}
1213
fsamuel78f86e42016-01-20 04:10:231214void RenderWidget::UpdateVisualState() {
1215 webwidget_->updateAllLifecyclePhases();
1216}
1217
1218void RenderWidget::WillBeginCompositorFrame() {
1219 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1220
1221 // The UpdateTextInputState can result in further layout and possibly
1222 // enable GPU acceleration so they need to be called before any painting
1223 // is done.
1224 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
1225 UpdateSelectionBounds();
lfge6119aac2016-01-27 02:14:311226
1227 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
1228 WillBeginCompositorFrame());
initial.commit09911bf2008-07-26 23:55:291229}
1230
fsamuel72464894f2015-12-15 06:59:311231///////////////////////////////////////////////////////////////////////////////
1232// RenderWidgetInputHandlerDelegate
1233
1234void RenderWidget::FocusChangeComplete() {}
1235
1236bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
1237 return true;
1238}
1239
1240void RenderWidget::ObserveWheelEventAndResult(
1241 const blink::WebMouseWheelEvent& wheel_event,
1242 const gfx::Vector2dF& wheel_unused_delta,
1243 bool event_processed) {
1244 if (!compositor_deps_->IsElasticOverscrollEnabled())
1245 return;
1246
1247 cc::InputHandlerScrollResult scroll_result;
1248 scroll_result.did_scroll = event_processed;
1249 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
1250 scroll_result.unused_scroll_delta = wheel_unused_delta;
1251
1252 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1253 InputHandlerManager* input_handler_manager =
1254 render_thread ? render_thread->input_handler_manager() : NULL;
1255 if (input_handler_manager) {
1256 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
1257 routing_id_, wheel_event, scroll_result);
jddukefffb67c2015-01-07 22:32:291258 }
fsamuel72464894f2015-12-15 06:59:311259}
1260
1261void RenderWidget::OnDidHandleKeyEvent() {}
1262
1263void RenderWidget::OnDidOverscroll(const DidOverscrollParams& params) {
1264 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1265}
1266
1267void RenderWidget::OnInputEventAck(scoped_ptr<InputEventAck> input_event_ack) {
1268 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
1269}
1270
fsamuele8326c742016-01-12 00:49:391271void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1272 // Nothing to do here. RenderWidget created the |input_handler| and will take
1273 // ownership of it. We just verify here that we don't already have an input
1274 // handler.
1275 DCHECK(!input_handler_);
1276}
1277
fsamuel72464894f2015-12-15 06:59:311278void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1279 ChangeSource change_source) {
1280 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1281 if (ime_event_guard_) {
1282 // show_ime should still be effective even if it was set inside the IME
1283 // event guard.
1284 if (show_ime == ShowIme::IF_NEEDED) {
1285 ime_event_guard_->set_show_ime(true);
1286 }
1287 return;
1288 }
1289
1290 ui::TextInputType new_type = GetTextInputType();
1291 if (IsDateTimeInput(new_type))
1292 return; // Not considered as a text input field in WebKit/Chromium.
1293
1294 blink::WebTextInputInfo new_info;
1295 if (webwidget_)
1296 new_info = webwidget_->textInputInfo();
1297 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1298
1299 bool new_can_compose_inline = CanComposeInline();
1300
1301 // Only sends text input params if they are changed or if the ime should be
1302 // shown.
1303 if (show_ime == ShowIme::IF_NEEDED ||
1304 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1305 text_input_info_ != new_info ||
1306 can_compose_inline_ != new_can_compose_inline)
1307#if defined(OS_ANDROID)
1308 || text_field_is_dirty_
1309#endif
1310 ) {
1311 ViewHostMsg_TextInputState_Params params;
1312 params.type = new_type;
1313 params.mode = new_mode;
1314 params.flags = new_info.flags;
1315 params.value = new_info.value.utf8();
1316 params.selection_start = new_info.selectionStart;
1317 params.selection_end = new_info.selectionEnd;
1318 params.composition_start = new_info.compositionStart;
1319 params.composition_end = new_info.compositionEnd;
1320 params.can_compose_inline = new_can_compose_inline;
1321 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
1322#if defined(USE_AURA)
1323 params.is_non_ime_change = true;
1324#endif
1325#if defined(OS_ANDROID)
1326 params.is_non_ime_change =
1327 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
1328 if (params.is_non_ime_change)
1329 OnImeEventSentForAck(new_info);
1330 text_field_is_dirty_ = false;
1331#endif
1332 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1333
1334 text_input_info_ = new_info;
1335 text_input_type_ = new_type;
1336 text_input_mode_ = new_mode;
1337 can_compose_inline_ = new_can_compose_inline;
1338 text_input_flags_ = new_info.flags;
1339 }
1340}
1341
1342bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
1343 return false;
1344}
1345
1346bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
1347 return false;
[email protected]fd847792013-10-24 17:12:351348}
1349
initial.commit09911bf2008-07-26 23:55:291350///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461351// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291352
[email protected]244ac1892011-12-02 17:04:471353void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima33ec97cd2015-12-14 19:40:241354 WebRect new_size_in_window(0, 0, new_size.width, new_size.height);
1355 convertViewportToWindow(&new_size_in_window);
1356 if (size_.width() != new_size_in_window.width ||
1357 size_.height() != new_size_in_window.height) {
1358 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
[email protected]20fbfc22013-05-08 20:50:581359
[email protected]5b45ad42013-10-25 00:42:041360 if (resizing_mode_selector_->is_synchronous_mode()) {
oshima33ec97cd2015-12-14 19:40:241361 gfx::Rect new_pos(rootWindowRect().x,
1362 rootWindowRect().y,
1363 size_.width(),
1364 size_.height());
[email protected]eac2b362013-05-22 07:01:451365 view_screen_rect_ = new_pos;
1366 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031367 }
[email protected]20fbfc22013-05-08 20:50:581368
[email protected]eac2b362013-05-22 07:01:451369 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581370
[email protected]5b45ad42013-10-25 00:42:041371 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581372 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091373 }
[email protected]244ac1892011-12-02 17:04:471374}
1375
[email protected]3a1c8a8032013-03-18 22:35:321376void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401377 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051378 if (compositor_)
oshima750cb4342015-10-31 00:59:011379 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051380}
1381
[email protected]e195e582013-03-08 01:32:591382void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221383 DCHECK(!host_closing_);
1384
fsamuel78f86e42016-01-20 04:10:231385 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1386 compositor_deps_);
oshima750cb4342015-10-31 00:59:011387 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331388 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391389 // For background pages and certain tests, we don't want to trigger
1390 // OutputSurface creation.
1391 if (compositor_never_visible_ || !RenderThreadImpl::current())
1392 compositor_->SetNeverVisible();
1393
pimanc4af3072015-10-02 03:45:591394 StartCompositor();
[email protected]e195e582013-03-08 01:32:591395}
1396
ennef3c58142014-12-09 21:44:381397void RenderWidget::WillCloseLayerTreeView() {
1398 if (host_closing_)
1399 return;
1400
1401 // Prevent new compositors or output surfaces from being created.
1402 host_closing_ = true;
1403
[email protected]aeeedad2014-08-22 18:16:221404 // Always send this notification to prevent new layer tree views from
1405 // being created, even if one hasn't been created yet.
1406 if (webwidget_)
1407 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221408}
1409
[email protected]180ef242013-11-07 06:50:461410blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281411 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061412}
1413
dglazkovf0e1d6d2015-10-10 02:13:481414void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1415 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1416 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1417 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1418 }
dglazkov79c426102015-08-31 21:22:431419
dglazkovf0e1d6d2015-10-10 02:13:481420 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1421 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431422}
1423
jdduke491a3f0c2015-06-15 23:30:261424void RenderWidget::ScheduleComposite() {
1425 if (compositor_ &&
1426 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1427 compositor_->setNeedsAnimate();
1428 }
1429}
1430
1431void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1432 if (compositor_) {
1433 // Regardless of whether threaded compositing is enabled, always
1434 // use this mechanism to force the compositor to redraw. However,
1435 // the invalidation code path below is still needed for the
1436 // non-threaded case.
1437 compositor_->SetNeedsForcedRedraw();
1438 }
1439 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151440}
1441
[email protected]586871b2014-07-22 17:05:111442// static
1443scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1444 IPC::Message* msg,
1445 MessageDeliveryPolicy policy,
1446 FrameSwapMessageQueue* frame_swap_message_queue,
1447 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111448 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111449 bool first_message_for_frame = false;
1450 frame_swap_message_queue->QueueMessageForFrame(policy,
1451 source_frame_number,
1452 make_scoped_ptr(msg),
1453 &first_message_for_frame);
1454 if (first_message_for_frame) {
1455 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1456 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061457 return promise;
[email protected]586871b2014-07-22 17:05:111458 }
dcheng4b6b5ff2014-10-16 00:42:061459 return nullptr;
[email protected]586871b2014-07-22 17:05:111460}
1461
1462void RenderWidget::QueueMessage(IPC::Message* msg,
1463 MessageDeliveryPolicy policy) {
1464 // RenderThreadImpl::current() is NULL in some tests.
1465 if (!compositor_ || !RenderThreadImpl::current()) {
1466 Send(msg);
1467 return;
1468 }
1469
1470 scoped_ptr<cc::SwapPromise> swap_promise =
1471 QueueMessageImpl(msg,
1472 policy,
dcheng58867a92014-08-26 02:50:221473 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111474 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111475 compositor_->GetSourceFrameNumber());
1476
1477 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321478 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351479 // Request a commit. This might either A) request a commit ahead of time
1480 // or B) request a commit which is not needed because there are not
1481 // pending updates. If B) then the commit will be skipped and the swap
1482 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1483 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1484 // can_cancel_commit is not unset.
1485 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111486 }
1487}
1488
[email protected]4873c7d2009-07-16 06:36:281489void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301490 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521491 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181492 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291493 // Only send a SetCursor message if we need to make a change.
1494 if (!current_cursor_.IsEqual(cursor)) {
1495 current_cursor_ = cursor;
1496 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1497 }
1498}
1499
1500// We are supposed to get a single call to Show for a newly created RenderWidget
1501// that was created via RenderWidget::CreateWebView. So, we wait until this
1502// point to dispatch the ShowWidget message.
1503//
1504// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281505// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291506//
[email protected]4873c7d2009-07-16 06:36:281507void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291508 DCHECK(!did_show_) << "received extraneous Show call";
1509 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1510 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1511
[email protected]8de12d942010-11-17 20:42:441512 if (did_show_)
1513 return;
1514
1515 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561516 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441517 // that's okay. It'll be ignored if as_popup is false, or the browser
1518 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561519 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1520 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291521}
1522
[email protected]4873c7d2009-07-16 06:36:281523void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291524}
1525
[email protected]2533ce12009-05-09 00:02:241526void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381527 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241528 Send(new ViewHostMsg_Close(routing_id_));
1529}
1530
dgozmancf9039cd2015-04-06 12:01:311531void RenderWidget::NotifyOnClose() {
1532 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1533}
1534
[email protected]4873c7d2009-07-16 06:36:281535void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081536 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321537 if (is_swapped_out_) {
1538 // This widget is currently swapped out, and the active widget is in a
1539 // different process. Have the browser route the close request to the
1540 // active widget instead, so that the correct unload handlers are run.
1541 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1542 return;
1543 }
1544
initial.commit09911bf2008-07-26 23:55:291545 // If a page calls window.close() twice, we'll end up here twice, but that's
1546 // OK. It is safe to send multiple Close messages.
1547
[email protected]2533ce12009-05-09 00:02:241548 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1549 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1550 // could be closed before the JS finishes executing. So instead, post a
1551 // message back to the message loop, which won't run until the JS is
1552 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081553 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211554 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291555}
1556
[email protected]9017d7852013-11-21 17:47:351557void RenderWidget::QueueSyntheticGesture(
1558 scoped_ptr<SyntheticGestureParams> gesture_params,
1559 const SyntheticGestureCompletionCallback& callback) {
1560 DCHECK(!callback.is_null());
1561
1562 pending_synthetic_gesture_callbacks_.push(callback);
1563
1564 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321565 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351566
1567 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1568}
1569
initial.commit09911bf2008-07-26 23:55:291570void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031571 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381572 WillCloseLayerTreeView();
1573 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291574 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281575 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291576 webwidget_ = NULL;
1577 }
1578}
1579
[email protected]4873c7d2009-07-16 06:36:281580WebRect RenderWidget::windowRect() {
1581 if (pending_window_rect_count_)
1582 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241583
[email protected]80ad8622012-11-07 16:33:031584 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291585}
1586
[email protected]180ef242013-11-07 06:50:461587void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301588 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541589 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301590}
1591
oshima33ec97cd2015-12-14 19:40:241592void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1593 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511594 if (popup_origin_scale_for_emulation_) {
1595 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561596 window_rect.x = popup_screen_origin_for_emulation_.x() +
1597 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1598 window_rect.y = popup_screen_origin_for_emulation_.y() +
1599 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511600 }
1601
[email protected]5b45ad42013-10-25 00:42:041602 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201603 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561604 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1605 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031606 } else {
bokanc007c3a2015-02-03 07:15:561607 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031608 }
initial.commit09911bf2008-07-26 23:55:291609 } else {
bokanc007c3a2015-02-03 07:15:561610 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291611 }
1612}
1613
[email protected]2533ce12009-05-09 00:02:241614void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1615 pending_window_rect_ = rect;
1616 pending_window_rect_count_++;
1617}
1618
[email protected]4873c7d2009-07-16 06:36:281619WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241620 if (pending_window_rect_count_) {
1621 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1622 // the RootWindowRect is probably going to return wrong results since the
1623 // browser may not have processed the Move yet. There isn't really anything
1624 // good to do in this case, and it shouldn't happen - since this size is
1625 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281626 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241627 }
1628
[email protected]80ad8622012-11-07 16:33:031629 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371630}
1631
[email protected]4873c7d2009-07-16 06:36:281632WebRect RenderWidget::windowResizerRect() {
1633 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191634}
1635
[email protected]fa7b1dc2010-06-23 17:53:041636void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261637 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041638 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071639 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041640 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131641 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281642 return;
[email protected]66fca5bc2013-05-23 06:58:291643 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361644 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041645 text, WebVector<WebCompositionUnderline>(underlines),
1646 selection_start, selection_end)) {
1647 // If we failed to set the composition text, then we need to let the browser
1648 // process to cancel the input method's ongoing composition session, to make
1649 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221650 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261651 }
[email protected]88dbe32f2013-06-20 23:31:361652 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041653}
1654
[email protected]fcf75d42013-12-03 20:11:261655void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511656 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021657 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131658 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041659 return;
[email protected]66fca5bc2013-05-23 06:58:291660 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391661 input_handler_->set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021662 if (text.length())
1663 webwidget_->confirmComposition(text);
1664 else if (keep_selection)
1665 webwidget_->confirmComposition(WebWidget::KeepSelection);
1666 else
1667 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391668 input_handler_->set_handling_input_event(false);
[email protected]88dbe32f2013-06-20 23:31:361669 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291670}
1671
oshimad5279032015-12-16 18:22:331672void RenderWidget::OnDeviceScaleFactorChanged() {
1673 if (!compositor_)
1674 return;
1675
1676 if (IsUseZoomForDSFEnabled())
1677 compositor_->SetPaintedDeviceScaleFactor(device_scale_factor_);
1678 else
1679 compositor_->setDeviceScaleFactor(device_scale_factor_);
1680}
1681
[email protected]0bc1f572013-04-17 01:46:311682void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121683 // During shutdown we can just ignore this message.
1684 if (!webwidget_)
1685 return;
1686
[email protected]0bc1f572013-04-17 01:46:311687 // Even if the browser provides an empty damage rect, it's still expecting to
1688 // receive a repaint ack so just damage the entire widget bounds.
1689 if (size_to_paint.IsEmpty()) {
1690 size_to_paint = size_;
1691 }
1692
[email protected]ec7dc112008-08-06 05:30:121693 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051694 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311695 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121696}
1697
[email protected]79fa22e2013-08-23 15:18:121698void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351699 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1700
1701 pending_synthetic_gesture_callbacks_.front().Run();
1702 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271703}
1704
[email protected]4873c7d2009-07-16 06:36:281705void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111706 if (!webwidget_)
1707 return;
[email protected]4873c7d2009-07-16 06:36:281708 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111709}
1710
[email protected]80ad8622012-11-07 16:33:031711void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1712 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511713 if (screen_metrics_emulator_) {
1714 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1715 view_screen_rect, window_screen_rect);
1716 } else {
1717 view_screen_rect_ = view_screen_rect;
1718 window_screen_rect_ = window_screen_rect;
1719 }
[email protected]80ad8622012-11-07 16:33:031720 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1721}
1722
kenrbb4e2a3b2015-05-14 15:05:051723void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1724 if (compositor_)
1725 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1726}
1727
dtrainor5ef644e2015-11-19 00:12:471728void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1729 if (compositor_)
1730 compositor_->OnHandleCompositorProto(proto);
1731}
1732
[email protected]adb362312014-06-28 06:04:241733void RenderWidget::showImeIfNeeded() {
1734 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131735}
1736
fsamuel72464894f2015-12-15 06:59:311737ui::TextInputType RenderWidget::GetTextInputType() {
1738 if (webwidget_)
1739 return WebKitToUiTextInputType(webwidget_->textInputType());
1740 return ui::TEXT_INPUT_TYPE_NONE;
1741}
1742
1743void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
1744#if defined(OS_ANDROID)
1745// TODO(yukawa): Start sending character bounds when the browser side
1746// implementation becomes ready (crbug.com/424866).
1747#else
1748 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1749 gfx::Range range = gfx::Range();
1750 if (should_update_range) {
1751 GetCompositionRange(&range);
1752 } else {
1753 range = composition_range_;
1754 }
1755 std::vector<gfx::Rect> character_bounds;
1756 GetCompositionCharacterBounds(&character_bounds);
1757
1758 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1759 return;
1760 composition_character_bounds_ = character_bounds;
1761 composition_range_ = range;
1762 Send(new InputHostMsg_ImeCompositionRangeChanged(
1763 routing_id(), composition_range_, composition_character_bounds_));
1764#endif
1765}
1766
oshimaf866dab2015-12-05 00:41:541767void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1768 if (IsUseZoomForDSFEnabled()) {
1769 float reverse = 1 / device_scale_factor_;
oshimad5279032015-12-16 18:22:331770 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541771 // anchor element can be placed at half pixel.
1772 gfx::Rect window_rect =
1773 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1774 rect->x = window_rect.x();
1775 rect->y = window_rect.y();
1776 rect->width = window_rect.width();
1777 rect->height = window_rect.height();
1778 }
1779}
1780
oshimaa6985b62016-01-27 08:58:301781void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1782 if (IsUseZoomForDSFEnabled()) {
1783 rect->x *= device_scale_factor_;
1784 rect->y *= device_scale_factor_;
1785 rect->width *= device_scale_factor_;
1786 rect->height *= device_scale_factor_;
1787 }
1788}
1789
[email protected]adb362312014-06-28 06:04:241790void RenderWidget::OnShowImeIfNeeded() {
1791#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311792 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241793#endif
rouslanf7ebd8832015-01-22 01:54:141794
1795// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1796// virtual keyboard.
1797#if !defined(OS_ANDROID)
1798 FocusChangeComplete();
1799#endif
[email protected]adb362312014-06-28 06:04:241800}
1801
1802#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371803void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1804 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131805}
1806
1807void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371808 DCHECK_GE(text_input_info_history_.size(), 1u);
1809 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511810}
[email protected]105dffb42013-02-20 03:46:211811#endif
1812
[email protected]0d1ebed12013-08-05 22:01:131813bool RenderWidget::ShouldHandleImeEvent() {
1814#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371815 if (!webwidget_)
1816 return false;
1817
1818 // We cannot handle IME events if there is any chance that the event we are
1819 // receiving here from the browser is based on the state that is different
1820 // from our current one as indicated by |text_input_info_|.
1821 // The states the browser might be in are:
1822 // text_input_info_history_[0] - current state ack'd by browser
1823 // text_input_info_history_[1...N] - pending state changes
1824 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1825 if (text_input_info_history_[i] != text_input_info_)
1826 return false;
1827 }
1828 return true;
[email protected]0d1ebed12013-08-05 22:01:131829#else
1830 return !!webwidget_;
1831#endif
1832}
1833
[email protected]468ac582012-11-20 00:53:191834void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1835 if (device_scale_factor_ == device_scale_factor)
1836 return;
1837
1838 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331839
1840 OnDeviceScaleFactorChanged();
1841
jdduke491a3f0c2015-06-15 23:30:261842 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191843}
1844
[email protected]28ed6b32014-06-08 02:16:271845bool RenderWidget::SetDeviceColorProfile(
1846 const std::vector<char>& color_profile) {
1847 if (device_color_profile_ == color_profile)
1848 return false;
1849
1850 device_color_profile_ = color_profile;
1851 return true;
1852}
1853
noeldb4df152014-09-16 17:45:201854void RenderWidget::ResetDeviceColorProfileForTesting() {
1855 if (!device_color_profile_.empty())
1856 device_color_profile_.clear();
1857 device_color_profile_.push_back('0');
1858}
1859
[email protected]fcdc5642014-05-09 14:32:241860void RenderWidget::OnOrientationChange() {
1861}
1862
[email protected]ceb36f7d2012-10-31 18:33:241863gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521864 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241865 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521866}
1867
[email protected]bee16aab2009-08-26 15:55:031868void RenderWidget::SetHidden(bool hidden) {
1869 if (is_hidden_ == hidden)
1870 return;
1871
jdduke8fac9d102014-12-20 02:40:131872 // The status has changed. Tell the RenderThread about it and ensure
1873 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031874 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391875 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131876
[email protected]bee16aab2009-08-26 15:55:031877 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001878 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031879 else
[email protected]b2db9272014-01-10 17:42:001880 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111881
1882 if (render_widget_scheduling_state_)
1883 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031884}
1885
[email protected]2b624c562011-10-27 22:58:261886void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261887 if (!webwidget_)
1888 return;
1889
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121890 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261891 webwidget_->didEnterFullScreen();
1892 } else {
1893 webwidget_->didExitFullScreen();
1894 }
[email protected]2b624c562011-10-27 22:58:261895}
1896
[email protected]674741932009-02-04 23:44:461897bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051898 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461899}
1900
[email protected]674741932009-02-04 23:44:461901void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051902 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461903}
1904
[email protected]674741932009-02-04 23:44:461905void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051906 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461907}
1908
changwanf2a707b2015-10-30 08:22:161909void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1910 if (!ime_event_guard_)
1911 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291912}
1913
changwanf2a707b2015-10-30 08:22:161914void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1915 if (ime_event_guard_ != guard) {
1916#if defined(OS_ANDROID)
1917 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1918 // (e.g. long press gesture), we want to treat it as not-from-IME event
1919 // so that AdapterInputConnection can make changes to its Editable model.
1920 // Therefore, we want to mark this text state update as 'from IME' only
1921 // when all the nested events are all originating from IME.
1922 ime_event_guard_->set_from_ime(
1923 ime_event_guard_->from_ime() && guard->from_ime());
1924#endif
1925 return;
1926 }
1927 ime_event_guard_ = nullptr;
1928
[email protected]66fca5bc2013-05-23 06:58:291929 // While handling an ime event, text input state and selection bounds updates
1930 // are ignored. These must explicitly be updated once finished handling the
1931 // ime event.
1932 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471933#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161934 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311935 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1936 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471937#endif
[email protected]66fca5bc2013-05-23 06:58:291938}
1939
[email protected]7c8873e2013-02-05 08:03:011940void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1941 WebRect focus_webrect;
1942 WebRect anchor_webrect;
1943 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241944 convertViewportToWindow(&focus_webrect);
1945 convertViewportToWindow(&anchor_webrect);
1946 *focus = focus_webrect;
1947 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321948}
1949
[email protected]e99ef6f2011-10-16 01:13:001950void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081951 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001952 if (!webwidget_)
1953 return;
changwanf2a707b2015-10-30 08:22:161954 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291955 return;
[email protected]e99ef6f2011-10-16 01:13:001956
mohsenb0eeba72015-08-09 06:20:081957#if defined(USE_AURA)
1958 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1959 // Aura beucause composited selection updates are not working for webview tags
1960 // which regresses IME inside webview. Remove this when composited selection
1961 // updates are fixed for webviews. See, http://crbug.com/510568.
1962 bool send_ipc = true;
1963#else
jddukeacf809e2014-09-23 20:38:381964 // With composited selection updates, the selection bounds will be reported
1965 // directly by the compositor, in which case explicit IPC selection
1966 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081967 bool send_ipc =
1968 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1969#endif
1970 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381971 ViewHostMsg_SelectionBounds_Params params;
1972 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1973 if (selection_anchor_rect_ != params.anchor_rect ||
1974 selection_focus_rect_ != params.focus_rect) {
1975 selection_anchor_rect_ = params.anchor_rect;
1976 selection_focus_rect_ = params.focus_rect;
1977 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1978 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1979 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1980 }
[email protected]58b48a0d2012-06-13 07:01:351981 }
jddukeacf809e2014-09-23 20:38:381982
[email protected]88dbe32f2013-06-20 23:31:361983 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001984}
1985
[email protected]180ef242013-11-07 06:50:461986// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:171987#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
1988 static_assert(int(blink::WebTextInputType##a) \
1989 == int(ui::TEXT_INPUT_TYPE_##b), \
1990 "mismatching enums: " #a)
1991
1992STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
1993STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
1994STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
1995STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
1996STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
1997STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
1998STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
1999STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2000STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2001STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2002STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2003STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2004STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2005STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2006STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2007STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2008STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452009
[email protected]5b739cb2012-08-21 20:35:212010ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462011 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212012 // Check the type is in the range representable by ui::TextInputType.
2013 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462014 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212015 return static_cast<ui::TextInputType>(type);
2016}
2017
[email protected]58b48a0d2012-06-13 07:01:352018void RenderWidget::GetCompositionCharacterBounds(
2019 std::vector<gfx::Rect>* bounds) {
2020 DCHECK(bounds);
2021 bounds->clear();
2022}
2023
[email protected]db4fc1e2013-09-06 20:01:512024void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362025 size_t location, length;
2026 if (webwidget_->compositionRange(&location, &length)) {
2027 range->set_start(location);
2028 range->set_end(location + length);
2029 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2030 range->set_start(location);
2031 range->set_end(location + length);
2032 } else {
[email protected]db4fc1e2013-09-06 20:01:512033 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362034 }
2035}
2036
[email protected]501ea13d2013-07-09 17:03:292037bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512038 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292039 const std::vector<gfx::Rect>& bounds) {
2040 if (composition_range_ != range)
2041 return true;
2042 if (bounds.size() != composition_character_bounds_.size())
2043 return true;
2044 for (size_t i = 0; i < bounds.size(); ++i) {
2045 if (bounds[i] != composition_character_bounds_[i])
2046 return true;
2047 }
2048 return false;
2049}
[email protected]501ea13d2013-07-09 17:03:292050
[email protected]ad26ef42011-06-17 07:59:452051bool RenderWidget::CanComposeInline() {
2052 return true;
[email protected]56ea1a62011-05-30 07:05:572053}
2054
[email protected]4873c7d2009-07-16 06:36:282055WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042056 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282057}
2058
[email protected]fa7b1dc2010-06-23 17:53:042059void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022060 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042061 // If the last text input type is not None, then we should finish any
2062 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452063 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042064 // If a composition text exists, then we need to let the browser process
2065 // to cancel the input method's ongoing composition session.
2066 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222067 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042068 }
[email protected]d4cff272011-05-02 15:46:012069
[email protected]88dbe32f2013-06-20 23:31:362070 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042071}
2072
donnda070f3c2015-01-16 19:54:112073#if defined(OS_ANDROID)
2074void RenderWidget::showUnhandledTapUIIfNeeded(
2075 const WebPoint& tapped_position,
2076 const WebNode& tapped_node,
2077 bool page_changed) {
fsamuele8326c742016-01-12 00:49:392078 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:112079 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372080 !tapped_node.isContentEditable() &&
2081 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112082 if (should_trigger) {
2083 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2084 tapped_position.x, tapped_position.y));
2085 }
2086}
2087#endif
2088
[email protected]c68c3e4e2013-01-24 00:36:562089void RenderWidget::didHandleGestureEvent(
2090 const WebGestureEvent& event,
2091 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022092#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562093 if (event_cancelled)
2094 return;
[email protected]07c70d22014-08-21 08:33:462095 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:312096 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462097 } else if (event.type == WebInputEvent::GestureLongPress) {
2098 DCHECK(webwidget_);
2099 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:312100 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462101 else
fsamuel72464894f2015-12-15 06:59:312102 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562103 }
2104#endif
2105}
2106
sataya.m582c9ce2015-06-09 08:03:422107void RenderWidget::didOverscroll(
2108 const blink::WebFloatSize& unusedDelta,
2109 const blink::WebFloatSize& accumulatedRootOverScroll,
2110 const blink::WebFloatPoint& position,
2111 const blink::WebFloatSize& velocity) {
fsamuele8326c742016-01-12 00:49:392112 input_handler_->DidOverscrollFromBlink(unusedDelta, accumulatedRootOverScroll,
2113 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422114}
2115
[email protected]7912e822014-04-16 02:37:032116void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392117 if (!is_hidden())
2118 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032119}
2120
[email protected]29e2fb42013-07-19 01:13:472121void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292122 size_t i = 0;
2123 for (; i < plugin_window_moves_.size(); ++i) {
2124 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582125 if (move.rects_valid) {
2126 plugin_window_moves_[i] = move;
2127 } else {
2128 plugin_window_moves_[i].visible = move.visible;
2129 }
initial.commit09911bf2008-07-26 23:55:292130 break;
2131 }
2132 }
2133
2134 if (i == plugin_window_moves_.size())
2135 plugin_window_moves_.push_back(move);
2136}
[email protected]268654772009-08-06 23:02:042137
2138void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2139 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2140 i != plugin_window_moves_.end(); ++i) {
2141 if (i->window == window) {
2142 plugin_window_moves_.erase(i);
2143 break;
2144 }
2145 }
2146}
[email protected]67bfb83f2011-09-22 03:36:372147
[email protected]63b465922012-09-06 02:04:522148
[email protected]24ed0432013-04-24 07:50:312149RenderWidgetCompositor* RenderWidget::compositor() const {
2150 return compositor_.get();
2151}
2152
fsamuel72464894f2015-12-15 06:59:312153void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392154 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372155}
[email protected]c3d45532011-10-07 19:20:402156
fsamuel72464894f2015-12-15 06:59:312157bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392158 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242159}
2160
fsamuel72464894f2015-12-15 06:59:312161void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392162 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312163}
2164
[email protected]ce6689f2013-03-29 12:52:552165void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112166 if (render_widget_scheduling_state_)
2167 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552168 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2169}
2170
mostynbe29b6882015-01-13 09:59:172171// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2172#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2173 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2174 "mismatching enums: " #a)
2175
[email protected]5d0bbdfa92013-12-10 00:35:512176void RenderWidget::setTouchAction(
2177 blink::WebTouchAction web_touch_action) {
2178
2179 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2180 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392181 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512182 return;
2183
dtapuskaa98ac8d72015-05-08 19:29:092184 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172185 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092186 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2187 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172188 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092189 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2190 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172191 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
rbyersa8b478d2015-10-30 15:49:102192 STATIC_ASSERT_WTI_ENUM_MATCH(Pan, PAN);
mostynbe29b6882015-01-13 09:59:172193 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
rbyersa8b478d2015-10-30 15:49:102194 STATIC_ASSERT_WTI_ENUM_MATCH(Manipulation, MANIPULATION);
2195 STATIC_ASSERT_WTI_ENUM_MATCH(DoubleTapZoom, DOUBLE_TAP_ZOOM);
2196 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
[email protected]a18f67a2013-12-20 19:44:362197
2198 content::TouchAction content_touch_action =
2199 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512200 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2201}
2202
[email protected]90f24152014-04-09 12:41:362203void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2204#if defined(OS_ANDROID)
2205 text_field_is_dirty_ = true;
2206#endif
2207}
2208
[email protected]0634cdd42013-08-16 00:46:092209scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
piman990d8ea2016-01-12 15:35:312210RenderWidget::CreateGraphicsContext3D(GpuChannelHost* gpu_channel_host) {
[email protected]828a3932014-04-02 14:43:132211 // Explicitly disable antialiasing for the compositor. As of the time of
2212 // this writing, the only platform that supported antialiasing for the
2213 // compositor was Mac OS X, because the on-screen OpenGL context creation
2214 // code paths on Windows and Linux didn't yet have multisampling support.
2215 // Mac OS X essentially always behaves as though it's rendering offscreen.
2216 // Multisampling has a heavy cost especially on devices with relatively low
2217 // fill rate like most notebooks, and the Mac implementation would need to
2218 // be optimized to resolve directly into the IOSurface shared between the
2219 // GPU and browser processes. For these reasons and to avoid platform
2220 // disparities we explicitly disable antialiasing.
2221 blink::WebGraphicsContext3D::Attributes attributes;
2222 attributes.antialias = false;
2223 attributes.shareResources = true;
2224 attributes.noAutomaticFlushes = true;
2225 attributes.depth = false;
2226 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132227 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292228 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012229#if defined(OS_ANDROID)
boliu853d46052015-10-13 20:20:062230 bool using_synchronous_compositing =
boliubee541f42015-11-05 00:52:532231 SynchronousCompositorFactory::GetInstance() ||
2232 base::CommandLine::ForCurrentProcess()->HasSwitch(
2233 switches::kIPCSyncCompositing);
[email protected]b6eb8e332013-09-10 00:51:012234 // If we raster too fast we become upload bound, and pending
2235 // uploads consume memory. For maximum upload throughput, we would
2236 // want to allow for upload_throughput * pipeline_time of pending
2237 // uploads, after which we are just wasting memory. Since we don't
2238 // know our upload throughput yet, this just caps our memory usage.
boliu853d46052015-10-13 20:20:062239 // Synchronous compositor uses half because synchronous compositor
2240 // pipeline is only one frame deep. But twice of half for low end
2241 // because 16bit texture is not supported.
2242 size_t divider = using_synchronous_compositing ? 2 : 1;
[email protected]35b4f0c2014-06-26 16:55:272243 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032244 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012245 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032246 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012247 // Deadline to draw a frame to achieve 60 frames per second.
2248 const size_t kMillisecondsPerFrame = 16;
2249 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032250 size_t max_transfer_buffer_usage_mb =
2251 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2252 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012253 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2254 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292255 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032256 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012257#endif
piman990d8ea2016-01-12 15:35:312258 limits.command_buffer_size = 64 * 1024;
2259 limits.start_transfer_buffer_size = 64 * 1024;
2260 limits.min_transfer_buffer_size = 64 * 1024;
[email protected]96ab016c2013-10-23 00:50:292261
piman990d8ea2016-01-12 15:35:312262 return make_scoped_ptr(new WebGraphicsContext3DCommandBufferImpl(
2263 0, GetURLForGraphicsContext3D(), gpu_channel_host, attributes,
piman08f75532015-10-05 18:58:012264 lose_context_when_out_of_memory, limits, NULL));
[email protected]ed7defa2013-03-12 21:29:592265}
2266
[email protected]e3244ed2014-06-20 20:04:272267void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2268 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162269}
2270
[email protected]e3244ed2014-06-20 20:04:272271void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2272 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162273}
2274
[email protected]de3c5d82014-05-28 22:12:592275void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2276 render_frames_.AddObserver(frame);
2277}
2278
2279void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2280 render_frames_.RemoveObserver(frame);
2281}
2282
[email protected]a017938b2014-05-27 21:17:172283#if defined(VIDEO_HOLE)
2284void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2285 video_hole_frames_.AddObserver(frame);
2286}
2287
2288void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2289 video_hole_frames_.RemoveObserver(frame);
2290}
2291#endif // defined(VIDEO_HOLE)
2292
[email protected]e9ff79c2012-10-19 21:31:262293} // namespace content