blob: 405b64e0c33c8270e4f77a7a1df0e219e1b61cb6 [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
[email protected]c27dd4f2014-05-22 18:05:197#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:218#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:009#include "base/command_line.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
avi1023d012015-12-25 02:39:1411#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4013#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3014#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3815#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2116#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0017#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2718#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0119#include "base/trace_event/trace_event.h"
20#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4821#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5222#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3323#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3024#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0425#include "cc/trees/layer_tree_host.h"
alexclarke7fa93942015-10-21 15:37:1126#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2127#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]29e2fb42013-07-19 01:13:4728#include "content/child/npapi/webplugin.h"
oshima750cb4342015-10-31 00:59:0129#include "content/common/content_switches_internal.h"
[email protected]0634cdd42013-08-16 00:46:0930#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5931#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2932#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3533#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4434#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1535#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1536#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5037#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2938#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4239#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4040#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5141#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5942#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2943#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1144#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5945#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1146#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2847#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2948#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1349#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3250#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1651#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2752#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0553#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4454#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5555#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:0956#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0457#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1858#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4859#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1860#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1162#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3063#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1864#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3065#include "third_party/WebKit/public/platform/WebSize.h"
66#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4367#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5968#include "third_party/WebKit/public/web/WebFrameWidget.h"
69#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1170#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3171#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3172#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
73#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3874#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5975#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4176#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1377#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5078#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0979#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3280#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4881#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2782#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4183#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4884
[email protected]eeb93112013-05-01 19:41:1085#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1586#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0787#include "content/renderer/android/synchronous_compositor_factory.h"
boliubee541f42015-11-05 00:52:5388#include "content/renderer/android/synchronous_compositor_filter.h"
89#include "content/renderer/android/synchronous_compositor_output_surface.h"
[email protected]eeb93112013-05-01 19:41:1090#endif
91
[email protected]661eb9d2009-02-03 02:11:4892#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4993#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5294#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4195#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4896#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4497
penghuang28a5fa22015-12-02 17:58:1998#if defined(MOJO_SHELL_CLIENT)
99#include "content/public/common/mojo_shell_connection.h"
fsamuel2545ecc2015-12-05 00:44:46100#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:19101#endif
102
[email protected]2255a9332013-06-17 05:12:31103#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:29104
[email protected]180ef242013-11-07 06:50:46105using blink::WebCompositionUnderline;
106using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43107using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46108using blink::WebGestureEvent;
109using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49110using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46111using blink::WebKeyboardEvent;
112using blink::WebMouseEvent;
113using blink::WebMouseWheelEvent;
114using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11115using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46116using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11117using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46118using blink::WebPopupType;
119using blink::WebRange;
120using blink::WebRect;
121using blink::WebScreenInfo;
122using blink::WebSize;
123using blink::WebTextDirection;
124using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25125using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46126using blink::WebVector;
127using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26128
[email protected]6a4d7f62013-01-07 21:32:13129namespace {
[email protected]b256eca2013-07-11 10:57:40130
131typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
132
133class TextInputModeMapSingleton {
134 public:
135 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22136 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40137 }
[email protected]dd705d4d2013-11-27 08:14:41138 TextInputModeMapSingleton() {
139 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
140 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
141 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
142 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
143 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
144 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
145 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
146 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
147 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
148 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
149 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40150 }
[email protected]dd705d4d2013-11-27 08:14:41151 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40152 private:
[email protected]dd705d4d2013-11-27 08:14:41153 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40154
olli.raula36aa8be2015-09-10 11:14:22155 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40156
157 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
158};
159
[email protected]dd705d4d2013-11-27 08:14:41160ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40161 static TextInputModeMapSingleton* singleton =
162 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41163 TextInputModeMap::const_iterator it =
164 singleton->map().find(input_mode.utf8());
165 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40166 return ui::TEXT_INPUT_MODE_DEFAULT;
167 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13168}
[email protected]b256eca2013-07-11 10:57:40169
fsamuel72464894f2015-12-15 06:59:31170bool IsDateTimeInput(ui::TextInputType type) {
171 return type == ui::TEXT_INPUT_TYPE_DATE ||
172 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
173 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
174 type == ui::TEXT_INPUT_TYPE_MONTH ||
175 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
dtapuskae7473612015-12-04 14:23:06176}
177
[email protected]b256eca2013-07-11 10:57:40178} // namespace
179
[email protected]e9ff79c2012-10-19 21:31:26180namespace content {
[email protected]62cb33cae2009-03-27 23:30:22181
[email protected]b2e4c70132013-10-03 02:07:51182// RenderWidget::ScreenMetricsEmulator ----------------------------------------
183
184class RenderWidget::ScreenMetricsEmulator {
185 public:
186 ScreenMetricsEmulator(
187 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43188 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51189 virtual ~ScreenMetricsEmulator();
190
[email protected]19193682014-04-03 15:01:43191 // Scale and offset used to convert between host coordinates
192 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51193 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20194 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43195 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51196 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56197 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51198
199 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43200 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51201
202 // The following methods alter handlers' behavior for messages related to
203 // widget size and position.
204 void OnResizeMessage(const ViewMsg_Resize_Params& params);
205 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
206 const gfx::Rect& window_screen_rect);
207 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31208 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51209
210 private:
[email protected]19193682014-04-03 15:01:43211 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02212 void Apply(bool top_controls_shrink_blink_size,
213 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44214 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12215 bool is_fullscreen_granted,
216 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51217
218 RenderWidget* widget_;
219
[email protected]7f99fc22013-11-08 14:05:58220 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43221 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51222
[email protected]a179d3962013-11-12 14:44:40223 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51224 float scale_;
dgozman9260b0a12015-03-16 13:45:20225 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51226
[email protected]19193682014-04-03 15:01:43227 // Widget rect as passed to webwidget.
228 gfx::Rect applied_widget_rect_;
229
[email protected]b2e4c70132013-10-03 02:07:51230 // Original values to restore back after emulation ends.
231 gfx::Size original_size_;
232 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28233 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46234 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51235 gfx::Rect original_view_screen_rect_;
236 gfx::Rect original_window_screen_rect_;
237};
238
239RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
240 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43241 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51242 : widget_(widget),
[email protected]19193682014-04-03 15:01:43243 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51244 scale_(1.f) {
245 original_size_ = widget_->size_;
246 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28247 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51248 original_screen_info_ = widget_->screen_info_;
249 original_view_screen_rect_ = widget_->view_screen_rect_;
250 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02251 Apply(widget_->top_controls_shrink_blink_size_,
252 widget_->top_controls_height_,
253 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12254 widget_->is_fullscreen_granted_,
255 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51256}
257
258RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
259 widget_->screen_info_ = original_screen_info_;
260
261 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20262 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51263 widget_->view_screen_rect_ = original_view_screen_rect_;
264 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01265 widget_->Resize(original_size_,
266 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02267 widget_->top_controls_shrink_blink_size_,
268 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01269 original_visible_viewport_size_,
270 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12271 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12272 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01273 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51274}
275
276void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43277 const WebDeviceEmulationParams& params) {
278 params_ = params;
279 Reapply();
280}
281
282void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02283 Apply(widget_->top_controls_shrink_blink_size_,
284 widget_->top_controls_height_,
285 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12286 widget_->is_fullscreen_granted_,
287 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51288}
289
[email protected]19193682014-04-03 15:01:43290void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02291 bool top_controls_shrink_blink_size,
292 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44293 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12294 bool is_fullscreen_granted,
295 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31296 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
297 if (!applied_widget_rect_.width())
298 applied_widget_rect_.set_width(original_size_.width());
299 if (!applied_widget_rect_.height())
300 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43301
[email protected]f442ee42014-05-14 11:53:12302 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02303 int original_width = std::max(original_size_.width(), 1);
304 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51305 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02306 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51307 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02308 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51309 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
310 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01311
312 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43313 offset_.set_x(
314 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01315 offset_.set_y(
[email protected]19193682014-04-03 15:01:43316 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51317 } else {
[email protected]0b3578c2014-06-20 18:29:02318 scale_ = params_.scale;
319 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01320 }
[email protected]7f0e8fa2014-03-26 12:32:01321
[email protected]19193682014-04-03 15:01:43322 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
323 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01324 widget_->screen_info_.rect = original_screen_info_.rect;
325 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
326 widget_->window_screen_rect_ = original_window_screen_rect_;
327 } else {
dgozmanf28ccbe2015-06-24 08:50:49328 applied_widget_rect_.set_origin(params_.viewPosition);
329 gfx::Rect screen_rect = applied_widget_rect_;
330 if (!params_.screenSize.isEmpty()) {
331 screen_rect =
332 gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height);
333 }
334 widget_->screen_info_.rect = screen_rect;
335 widget_->screen_info_.availableRect = screen_rect;
[email protected]19193682014-04-03 15:01:43336 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01337 }
[email protected]a179d3962013-11-12 14:44:40338
[email protected]19193682014-04-03 15:01:43339 float applied_device_scale_factor = params_.deviceScaleFactor ?
340 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01341 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51342
[email protected]7f99fc22013-11-08 14:05:58343 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51344 // - we keep the real device scale factor in compositor to produce sharp image
345 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58346 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51347 // root layer.
dgozman9260b0a12015-03-16 13:45:20348 blink::WebDeviceEmulationParams modified_params = params_;
349 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
350 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
351 modified_params.scale = scale_;
352 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51353
[email protected]7f0e8fa2014-03-26 12:32:01354 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43355 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51356
danakjddaec912015-09-25 19:38:40357 gfx::Size physical_backing_size = gfx::ScaleToCeiledSize(
358 original_size_, original_screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02359 widget_->Resize(applied_widget_rect_.size(),
360 physical_backing_size,
361 top_controls_shrink_blink_size,
362 top_controls_height,
363 applied_widget_rect_.size(),
364 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12365 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12366 display_mode,
dtrainorcb7779b82014-12-04 01:08:02367 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51368}
369
370void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
371 const ViewMsg_Resize_Params& params) {
372 bool need_ack = params.new_size != original_size_ &&
373 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
374 original_size_ = params.new_size;
375 original_physical_backing_size_ = params.physical_backing_size;
376 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28377 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02378 Apply(params.top_controls_shrink_blink_size,
379 params.top_controls_height,
380 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12381 params.is_fullscreen_granted,
382 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51383
384 if (need_ack) {
385 widget_->set_next_paint_is_resize_ack();
386 if (widget_->compositor_)
387 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
388 }
389}
390
391void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
392 const gfx::Rect& view_screen_rect,
393 const gfx::Rect& window_screen_rect) {
394 original_view_screen_rect_ = view_screen_rect;
395 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43396 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
397 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51398}
399
400void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
401 ContextMenuParams* params) {
402 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40403 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51404 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40405 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51406}
407
[email protected]2d6836f42014-07-02 17:25:31408gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
409 const gfx::Rect& anchor) {
danakj4606f6332015-08-31 23:56:56410 gfx::Rect scaled = gfx::ScaleToEnclosedRect(anchor, scale_);
[email protected]2d6836f42014-07-02 17:25:31411 scaled.set_x(scaled.x() + offset_.x());
412 scaled.set_y(scaled.y() + offset_.y());
413 return scaled;
414}
415
[email protected]b2e4c70132013-10-03 02:07:51416// RenderWidget ---------------------------------------------------------------
417
dcheng35d31c112015-07-22 00:17:36418RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
419 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46420 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04421 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03422 bool hidden,
423 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29424 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36425 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53426 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29427 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02428 top_controls_shrink_blink_size_(false),
429 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29430 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51431 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09432 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29433 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04434 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39435 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12436 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12437 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16438 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48439 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22440 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44441 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20442 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45443 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40444 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20445 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53446 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12447 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48448 pending_window_rect_count_(0),
fsamuel72464894f2015-12-15 06:59:31449 input_handler_(this, this),
[email protected]842f10652012-06-06 01:54:04450 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52451 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30452 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13453#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36454 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13455#endif
[email protected]b2e4c70132013-10-03 02:07:51456 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11457 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42458 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51459 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05460 if (!swapped_out)
461 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27462 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53463 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37464#if defined(OS_ANDROID)
465 text_input_info_history_.push_back(blink::WebTextInputInfo());
466#endif
alexclarke7fa93942015-10-21 15:37:11467
468 // In tests there may not be a RenderThreadImpl.
469 if (RenderThreadImpl::current()) {
470 render_widget_scheduling_state_ = RenderThreadImpl::current()
471 ->GetRendererScheduler()
472 ->NewRenderWidgetSchedulingState()
473 .Pass();
474 render_widget_scheduling_state_->SetHidden(is_hidden_);
475 }
initial.commit09911bf2008-07-26 23:55:29476}
477
478RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11479 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16480
[email protected]992db4c2011-05-12 15:37:15481 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02482 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15483 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29484}
485
[email protected]484955942010-08-19 16:13:18486// static
avi1023d012015-12-25 02:39:14487RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53488 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46489 blink::WebPopupType popup_type,
490 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29491 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36492 scoped_refptr<RenderWidget> widget(new RenderWidget(
493 compositor_deps, popup_type, screen_info, false, false, false));
494 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46495 return widget.get();
[email protected]a635f942012-12-07 10:34:29496 }
497 return NULL;
initial.commit09911bf2008-07-26 23:55:29498}
499
[email protected]484955942010-08-19 16:13:18500// static
kenrba7199832015-01-22 23:44:59501RenderWidget* RenderWidget::CreateForFrame(
502 int routing_id,
kenrba7199832015-01-22 23:44:59503 bool hidden,
504 const blink::WebScreenInfo& screen_info,
505 CompositorDependencies* compositor_deps,
506 blink::WebLocalFrame* frame) {
507 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55508 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
509 // same routing ID for both the view routing ID and the main frame widget
510 // routing ID. https://crbug.com/545684
511 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
512 if (view) {
513 view->AttachWebFrameWidget(RenderWidget::CreateWebFrameWidget(view, frame));
514 return view;
515 }
dcheng35d31c112015-07-22 00:17:36516 scoped_refptr<RenderWidget> widget(
517 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
518 false, hidden, false));
kenrba7199832015-01-22 23:44:59519 widget->routing_id_ = routing_id;
simonhong628f9812015-04-27 23:13:20520 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59521 // DoInit increments the reference count on |widget|, keeping it alive after
522 // this function returns.
dcheng35d31c112015-07-22 00:17:36523 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59524 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
525 nullptr)) {
kenrba7199832015-01-22 23:44:59526 return widget.get();
527 }
528 return nullptr;
529}
530
531// static
dchengda9b4bb2015-07-20 20:58:08532blink::WebWidget* RenderWidget::CreateWebFrameWidget(
533 RenderWidget* render_widget,
534 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55535 if (!frame->parent()) {
536 // TODO(dcheng): The main frame widget currently has a special case.
537 // Eliminate this once WebView is no longer a WebWidget.
538 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
539 }
dchengda9b4bb2015-07-20 20:58:08540 return blink::WebFrameWidget::create(render_widget, frame);
541}
542
543// static
kenrba7199832015-01-22 23:44:59544blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18545 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46546 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18547 break;
[email protected]180ef242013-11-07 06:50:46548 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44549 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18550 default:
551 NOTREACHED();
552 }
553 return NULL;
554}
555
dchengda9b4bb2015-07-20 20:58:08556void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32557 OnClose();
kenrba7199832015-01-22 23:44:59558}
559
avi1023d012015-12-25 02:39:14560bool RenderWidget::Init(int32_t opener_id) {
piman5d36dae2015-09-24 22:47:05561 return DoInit(
562 opener_id, RenderWidget::CreateWebWidget(this),
563 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
[email protected]484955942010-08-19 16:13:18564}
565
avi1023d012015-12-25 02:39:14566bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06567 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18568 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29569 DCHECK(!webwidget_);
570
571 if (opener_id != MSG_ROUTING_NONE)
572 opener_id_ = opener_id;
573
[email protected]484955942010-08-19 16:13:18574 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29575
kenrba7199832015-01-22 23:44:59576 bool result = true;
577 if (create_widget_message)
578 result = RenderThread::Get()->Send(create_widget_message);
579
initial.commit09911bf2008-07-26 23:55:29580 if (result) {
[email protected]380244092011-10-07 17:26:27581 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29582 // Take a reference on behalf of the RenderThread. This will be balanced
583 // when we receive ViewMsg_Close.
584 AddRef();
[email protected]b2db9272014-01-10 17:42:00585 if (RenderThreadImpl::current()) {
586 RenderThreadImpl::current()->WidgetCreated();
587 if (is_hidden_)
588 RenderThreadImpl::current()->WidgetHidden();
589 }
[email protected]a635f942012-12-07 10:34:29590 return true;
initial.commit09911bf2008-07-26 23:55:29591 } else {
[email protected]a635f942012-12-07 10:34:29592 // The above Send can fail when the tab is closing.
593 return false;
initial.commit09911bf2008-07-26 23:55:29594 }
595}
596
[email protected]992db4c2011-05-12 15:37:15597void RenderWidget::SetSwappedOut(bool is_swapped_out) {
598 // We should only toggle between states.
599 DCHECK(is_swapped_out_ != is_swapped_out);
600 is_swapped_out_ = is_swapped_out;
601
602 // If we are swapping out, we will call ReleaseProcess, allowing the process
603 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52604 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15605 // If we are swapping in, we call AddRefProcess to prevent the process from
606 // exiting.
[email protected]949b6592014-08-20 13:17:52607 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15608 RenderProcess::current()->AddRefProcess();
609}
610
[email protected]949b6592014-08-20 13:17:52611void RenderWidget::WasSwappedOut() {
612 // If we have been swapped out and no one else is using this process,
613 // it's safe to exit now.
614 CHECK(is_swapped_out_);
615 RenderProcess::current()->ReleaseProcess();
616}
617
[email protected]b2e4c70132013-10-03 02:07:51618void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
619 ScreenMetricsEmulator* emulator) {
620 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43621 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49622 popup_screen_origin_for_emulation_ = gfx::Point(
623 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
624 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56625 screen_info_ = emulator->original_screen_info();
626 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51627}
628
[email protected]2d6836f42014-07-02 17:25:31629gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
630 if (screen_metrics_emulator_)
631 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
632 return anchor;
633}
634
[email protected]b2e4c70132013-10-03 02:07:51635void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20636 bool enabled,
637 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51638 // This is only supported in RenderView.
639 NOTREACHED();
640}
641
[email protected]53907862014-03-25 15:42:40642#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51643void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
644 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49645 popup->SetOriginScaleAndOffsetForEmulation(
646 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51647}
[email protected]53907862014-03-25 15:42:40648#endif
[email protected]b2e4c70132013-10-03 02:07:51649
650void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
651 if (screen_metrics_emulator_)
652 screen_metrics_emulator_->OnShowContextMenu(params);
653}
654
[email protected]a95986a82010-12-24 06:19:28655bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
656 bool handled = true;
657 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15658 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22659 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
660 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22661 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
662 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15663 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
664 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35665 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
666 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28667 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28668 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20669 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
670 OnEnableDeviceEmulation)
671 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
672 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41673 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54674 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28675 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41676 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25677 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28678 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
679 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03680 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05681 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21682#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37683 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
[email protected]2384b6c2013-02-28 23:58:51684 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21685#endif
dtrainor5ef644e2015-11-19 00:12:47686 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28687 IPC_MESSAGE_UNHANDLED(handled = false)
688 IPC_END_MESSAGE_MAP()
689 return handled;
690}
initial.commit09911bf2008-07-26 23:55:29691
692bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15693 // Don't send any messages after the browser has told us to close, and filter
694 // most outgoing messages while swapped out.
695 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26696 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11697 closing_) {
initial.commit09911bf2008-07-26 23:55:29698 delete message;
699 return false;
700 }
701
702 // If given a messsage without a routing ID, then assign our routing ID.
703 if (message->routing_id() == MSG_ROUTING_NONE)
704 message->set_routing_id(routing_id_);
705
[email protected]380244092011-10-07 17:26:27706 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44707}
708
[email protected]61e2b3cc2012-03-02 16:13:34709void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44710 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02711 bool top_controls_shrink_blink_size,
712 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44713 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34714 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12715 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12716 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58717 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56718 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48719 // A resize ack shouldn't be requested if we have not ACK'd the previous
720 // one.
721 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
722 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
723 }
initial.commit09911bf2008-07-26 23:55:29724
[email protected]61e2b3cc2012-03-02 16:13:34725 // Ignore this during shutdown.
726 if (!webwidget_)
727 return;
728
oshima750cb4342015-10-31 00:59:01729 if (compositor_)
730 compositor_->setViewportSize(physical_backing_size);
[email protected]60d47ac2013-03-01 23:42:44731
oshima750cb4342015-10-31 00:59:01732 bool resized = size_ != new_size ||
733 physical_backing_size_ != physical_backing_size;
734
735 size_ = new_size;
[email protected]dade8992013-03-04 07:34:34736 physical_backing_size_ = physical_backing_size;
oshima750cb4342015-10-31 00:59:01737
dtrainorcb7779b82014-12-04 01:08:02738 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
739 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28740 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34741 resizer_rect_ = resizer_rect;
742
743 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12744 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12745 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12746 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34747
aelias6004fe02015-02-07 21:43:01748 webwidget_->setTopControlsHeight(top_controls_height,
749 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43750
oshima750cb4342015-10-31 00:59:01751 if (resized) {
752 gfx::Size new_widget_size =
753 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_;
[email protected]61e2b3cc2012-03-02 16:13:34754 // When resizing, we want to wait to paint before ACK'ing the resize. This
755 // ensures that we only resize as fast as we can paint. We only need to
756 // send an ACK if we are resized to a non-empty rect.
oshima750cb4342015-10-31 00:59:01757 webwidget_->resize(new_widget_size);
758 }
jbroman304f01a2015-11-05 17:04:21759 WebSize visual_viewport_size;
oshima750cb4342015-10-31 00:59:01760
761 if (IsUseZoomForDSFEnabled()) {
oshimad5279032015-12-16 18:22:33762 visual_viewport_size =
763 gfx::ScaleToCeiledSize(visible_viewport_size, device_scale_factor_);
oshima750cb4342015-10-31 00:59:01764 } else {
jbroman304f01a2015-11-05 17:04:21765 visual_viewport_size = visible_viewport_size_;
[email protected]632c4382013-05-15 08:58:45766 }
767
jbroman304f01a2015-11-05 17:04:21768 webwidget()->resizeVisualViewport(visual_viewport_size);
[email protected]bb6378fe2014-04-28 21:19:44769
[email protected]632c4382013-05-15 08:58:45770 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58771 // In this case there is no paint/composite and therefore no
772 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
773 // ack through a fake ViewHostMsg_UpdateRect or a different message.
774 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34775 }
776
[email protected]20fbfc22013-05-08 20:50:58777 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45778 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58779 set_next_paint_is_resize_ack();
780
[email protected]61e2b3cc2012-03-02 16:13:34781 if (fullscreen_change)
782 DidToggleFullscreen();
783
784 // If a resize ack is requested and it isn't set-up, then no more resizes will
785 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45786 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29787}
788
bokanc007c3a2015-02-03 07:15:56789void RenderWidget::SetWindowRectSynchronously(
790 const gfx::Rect& new_window_rect) {
791 Resize(new_window_rect.size(),
792 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02793 top_controls_shrink_blink_size_,
794 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56795 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01796 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12797 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12798 display_mode_,
[email protected]587941d2014-08-22 01:40:01799 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56800 view_screen_rect_ = new_window_rect;
801 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02802 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56803 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02804}
805
initial.commit09911bf2008-07-26 23:55:29806void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32807 DCHECK(content::RenderThread::Get());
808 if (closing_)
809 return;
810 NotifyOnClose();
811 closing_ = true;
812
813 // Browser correspondence is no longer needed at this point.
814 if (routing_id_ != MSG_ROUTING_NONE) {
815 RenderThread::Get()->RemoveRoute(routing_id_);
816 SetHidden(false);
817 if (RenderThreadImpl::current())
818 RenderThreadImpl::current()->WidgetDestroyed();
819 }
820
821 if (for_oopif_) {
822 // Widgets for frames may be created and closed at any time while the frame
823 // is alive. However, the closing process must happen synchronously. Frame
824 // widget and frames hold pointers to each other. If Close() is deferred to
825 // the message loop like in the non-frame widget case, WebWidget::close()
826 // can end up accessing members of an already-deleted frame.
827 Close();
828 } else {
829 // If there is a Send call on the stack, then it could be dangerous to close
830 // now. Post a task that only gets invoked when there are no nested message
831 // loops.
832 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
833 FROM_HERE, base::Bind(&RenderWidget::Close, this));
834 }
835
836 // Balances the AddRef taken when we called AddRoute.
837 Release();
initial.commit09911bf2008-07-26 23:55:29838}
839
[email protected]0fdd5012013-05-29 08:05:56840void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04841 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32842 return;
843
[email protected]b2e4c70132013-10-03 02:07:51844 if (screen_metrics_emulator_) {
845 screen_metrics_emulator_->OnResizeMessage(params);
846 return;
847 }
848
[email protected]fcdc5642014-05-09 14:32:24849 bool orientation_changed =
850 screen_info_.orientationAngle != params.screen_info.orientationAngle;
851
[email protected]0fdd5012013-05-29 08:05:56852 screen_info_ = params.screen_info;
853 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02854 Resize(params.new_size,
855 params.physical_backing_size,
856 params.top_controls_shrink_blink_size,
857 params.top_controls_height,
858 params.visible_viewport_size,
859 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12860 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12861 params.display_mode,
sievers4e33dae2015-02-25 20:43:58862 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24863
864 if (orientation_changed)
865 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29866}
867
dgozman9260b0a12015-03-16 13:45:20868void RenderWidget::OnEnableDeviceEmulation(
869 const blink::WebDeviceEmulationParams& params) {
870 if (!screen_metrics_emulator_)
871 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
872 else
873 screen_metrics_emulator_->ChangeEmulationParams(params);
874}
875
876void RenderWidget::OnDisableDeviceEmulation() {
877 screen_metrics_emulator_.reset();
878}
879
noel89949e62014-09-30 01:12:41880void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
881 SetDeviceColorProfile(color_profile);
882}
883
[email protected]b5913d72012-02-07 22:26:54884void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01885 if (resizer_rect_ == resizer_rect)
886 return;
887 resizer_rect_ = resizer_rect;
888 if (webwidget_)
889 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54890}
891
initial.commit09911bf2008-07-26 23:55:29892void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31893 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29894 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03895 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59896 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
897 WasHidden());
initial.commit09911bf2008-07-26 23:55:29898}
899
[email protected]3399dd822014-08-09 11:14:24900void RenderWidget::OnWasShown(bool needs_repainting,
901 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41902 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29903 // During shutdown we can just ignore this message.
904 if (!webwidget_)
905 return;
906
907 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03908 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59909 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
910 WasShown());
initial.commit09911bf2008-07-26 23:55:29911
[email protected]8a23afb32014-04-30 22:40:23912 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29913 return;
initial.commit09911bf2008-07-26 23:55:29914
915 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24916 if (compositor_) {
917 ui::LatencyInfo swap_latency_info(latency_info);
918 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
919 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05920 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24921 }
jdduke491a3f0c2015-06-15 23:30:26922 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29923}
924
[email protected]53d3f302009-12-21 04:42:05925void RenderWidget::OnRequestMoveAck() {
926 DCHECK(pending_window_rect_count_);
927 pending_window_rect_count_--;
928}
929
[email protected]ed7defa2013-03-12 21:29:59930GURL RenderWidget::GetURLForGraphicsContext3D() {
931 return GURL();
[email protected]65225772011-05-12 21:10:24932}
933
[email protected]ebc0e1df2013-08-01 02:46:22934scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03935 // For widgets that are never visible, we don't start the compositor, so we
936 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39937 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:19938
avi83883c82014-12-23 00:08:49939 const base::CommandLine& command_line =
940 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33941 bool use_software = fallback;
942 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
943 use_software = true;
944
penghuang28a5fa22015-12-02 17:58:19945#if defined(MOJO_SHELL_CLIENT)
946 if (MojoShellConnection::Get() && !use_software) {
947 RenderWidgetMusConnection* connection =
948 RenderWidgetMusConnection::GetOrCreate(routing_id());
949 return connection->CreateOutputSurface();
950 }
951#endif
952
[email protected]0634cdd42013-08-16 00:46:09953 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17954 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:33955 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09956 context_provider = ContextProviderCommandBuffer::Create(
jbauman5e420d32015-08-05 09:33:01957 CreateGraphicsContext3D(true), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:33958 if (!context_provider.get()) {
959 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34960 return nullptr;
[email protected]e09994a2014-03-26 19:59:33961 }
revemand180dfc32015-09-24 00:19:43962 worker_context_provider =
963 RenderThreadImpl::current()->SharedWorkerContextProvider();
964 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:17965 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34966 return nullptr;
vmiura78b69282015-02-14 00:01:17967 }
boliu853d46052015-10-13 20:20:06968
969#if defined(OS_ANDROID)
970 if (SynchronousCompositorFactory* factory =
971 SynchronousCompositorFactory::GetInstance()) {
972 return factory->CreateOutputSurface(
973 routing_id(), frame_swap_message_queue_, context_provider,
974 worker_context_provider);
boliubee541f42015-11-05 00:52:53975 } else if (RenderThreadImpl::current()->sync_compositor_message_filter()) {
976 return make_scoped_ptr(new SynchronousCompositorOutputSurface(
977 context_provider, worker_context_provider, routing_id(),
978 content::RenderThreadImpl::current()
979 ->sync_compositor_message_filter(),
980 frame_swap_message_queue_));
boliu853d46052015-10-13 20:20:06981 }
982#endif
[email protected]0634cdd42013-08-16 00:46:09983 }
[email protected]ebc0e1df2013-08-01 02:46:22984
avi1023d012015-12-25 02:39:14985 uint32_t output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:34986 // Composite-to-mailbox is currently used for layout tests in order to cause
987 // them to draw inside in the renderer to do the readback there. This should
988 // no longer be the case when crbug.com/311404 is fixed.
989 if (!RenderThreadImpl::current() ||
990 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:53991 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
piman8944e1c2015-09-22 21:10:34992 return make_scoped_ptr(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:17993 routing_id(), output_surface_id, context_provider,
994 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09995 }
piman8944e1c2015-09-22 21:10:34996
[email protected]0634cdd42013-08-16 00:46:09997 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:09998 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:12999 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091000
piman8944e1c2015-09-22 21:10:341001 return make_scoped_ptr(new CompositorOutputSurface(
caseqff9c74c2015-02-10 14:56:291002 routing_id(), output_surface_id, nullptr, nullptr,
1003 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221004 }
[email protected]ed7defa2013-03-12 21:29:591005
piman8944e1c2015-09-22 21:10:341006 return make_scoped_ptr(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171007 routing_id(), output_surface_id, context_provider,
piman8944e1c2015-09-22 21:10:341008 worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:281009}
1010
[email protected]4d7e46a2013-11-08 05:33:401011void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241012 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241013 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:261014 ScheduleComposite();
[email protected]65225772011-05-12 21:10:241015}
1016
[email protected]4d7e46a2013-11-08 05:33:401017void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081018 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081019}
1020
[email protected]4d7e46a2013-11-08 05:33:401021void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241022 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161023
[email protected]404939f2012-06-01 04:06:181024 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161025 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291026}
1027
[email protected]180ef242013-11-07 06:50:461028void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
jdduke0cf1e662015-10-15 22:43:281029 const ui::LatencyInfo& latency_info) {
[email protected]c27dd4f2014-05-22 18:05:191030 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291031 return;
fsamuel72464894f2015-12-15 06:59:311032 input_handler_.HandleInputEvent(*input_event, latency_info);
initial.commit09911bf2008-07-26 23:55:291033}
1034
[email protected]34202de2013-05-06 23:36:221035void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1036 if (webwidget_)
1037 webwidget_->setCursorVisibilityState(is_visible);
1038}
1039
initial.commit09911bf2008-07-26 23:55:291040void RenderWidget::OnMouseCaptureLost() {
1041 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281042 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291043}
1044
1045void RenderWidget::OnSetFocus(bool enable) {
[email protected]9d166af2010-03-02 22:04:331046 if (webwidget_)
1047 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291048}
1049
fsamuel72464894f2015-12-15 06:59:311050///////////////////////////////////////////////////////////////////////////////
1051// RenderWidgetInputHandlerDelegate
1052
1053void RenderWidget::FocusChangeComplete() {}
1054
1055bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
1056 return true;
1057}
1058
1059void RenderWidget::ObserveWheelEventAndResult(
1060 const blink::WebMouseWheelEvent& wheel_event,
1061 const gfx::Vector2dF& wheel_unused_delta,
1062 bool event_processed) {
1063 if (!compositor_deps_->IsElasticOverscrollEnabled())
1064 return;
1065
1066 cc::InputHandlerScrollResult scroll_result;
1067 scroll_result.did_scroll = event_processed;
1068 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
1069 scroll_result.unused_scroll_delta = wheel_unused_delta;
1070
1071 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1072 InputHandlerManager* input_handler_manager =
1073 render_thread ? render_thread->input_handler_manager() : NULL;
1074 if (input_handler_manager) {
1075 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
1076 routing_id_, wheel_event, scroll_result);
jddukefffb67c2015-01-07 22:32:291077 }
fsamuel72464894f2015-12-15 06:59:311078}
1079
1080void RenderWidget::OnDidHandleKeyEvent() {}
1081
1082void RenderWidget::OnDidOverscroll(const DidOverscrollParams& params) {
1083 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1084}
1085
1086void RenderWidget::OnInputEventAck(scoped_ptr<InputEventAck> input_event_ack) {
1087 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
1088}
1089
1090void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1091 ChangeSource change_source) {
1092 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1093 if (ime_event_guard_) {
1094 // show_ime should still be effective even if it was set inside the IME
1095 // event guard.
1096 if (show_ime == ShowIme::IF_NEEDED) {
1097 ime_event_guard_->set_show_ime(true);
1098 }
1099 return;
1100 }
1101
1102 ui::TextInputType new_type = GetTextInputType();
1103 if (IsDateTimeInput(new_type))
1104 return; // Not considered as a text input field in WebKit/Chromium.
1105
1106 blink::WebTextInputInfo new_info;
1107 if (webwidget_)
1108 new_info = webwidget_->textInputInfo();
1109 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1110
1111 bool new_can_compose_inline = CanComposeInline();
1112
1113 // Only sends text input params if they are changed or if the ime should be
1114 // shown.
1115 if (show_ime == ShowIme::IF_NEEDED ||
1116 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1117 text_input_info_ != new_info ||
1118 can_compose_inline_ != new_can_compose_inline)
1119#if defined(OS_ANDROID)
1120 || text_field_is_dirty_
1121#endif
1122 ) {
1123 ViewHostMsg_TextInputState_Params params;
1124 params.type = new_type;
1125 params.mode = new_mode;
1126 params.flags = new_info.flags;
1127 params.value = new_info.value.utf8();
1128 params.selection_start = new_info.selectionStart;
1129 params.selection_end = new_info.selectionEnd;
1130 params.composition_start = new_info.compositionStart;
1131 params.composition_end = new_info.compositionEnd;
1132 params.can_compose_inline = new_can_compose_inline;
1133 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
1134#if defined(USE_AURA)
1135 params.is_non_ime_change = true;
1136#endif
1137#if defined(OS_ANDROID)
1138 params.is_non_ime_change =
1139 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
1140 if (params.is_non_ime_change)
1141 OnImeEventSentForAck(new_info);
1142 text_field_is_dirty_ = false;
1143#endif
1144 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1145
1146 text_input_info_ = new_info;
1147 text_input_type_ = new_type;
1148 text_input_mode_ = new_mode;
1149 can_compose_inline_ = new_can_compose_inline;
1150 text_input_flags_ = new_info.flags;
1151 }
1152}
1153
1154bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
1155 return false;
1156}
1157
1158bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
1159 return false;
[email protected]fd847792013-10-24 17:12:351160}
1161
initial.commit09911bf2008-07-26 23:55:291162///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461163// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291164
[email protected]244ac1892011-12-02 17:04:471165void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima33ec97cd2015-12-14 19:40:241166 WebRect new_size_in_window(0, 0, new_size.width, new_size.height);
1167 convertViewportToWindow(&new_size_in_window);
1168 if (size_.width() != new_size_in_window.width ||
1169 size_.height() != new_size_in_window.height) {
1170 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
[email protected]20fbfc22013-05-08 20:50:581171
[email protected]5b45ad42013-10-25 00:42:041172 if (resizing_mode_selector_->is_synchronous_mode()) {
oshima33ec97cd2015-12-14 19:40:241173 gfx::Rect new_pos(rootWindowRect().x,
1174 rootWindowRect().y,
1175 size_.width(),
1176 size_.height());
[email protected]eac2b362013-05-22 07:01:451177 view_screen_rect_ = new_pos;
1178 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031179 }
[email protected]20fbfc22013-05-08 20:50:581180
[email protected]eac2b362013-05-22 07:01:451181 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581182
[email protected]5b45ad42013-10-25 00:42:041183 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581184 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091185 }
[email protected]244ac1892011-12-02 17:04:471186}
1187
[email protected]3a1c8a8032013-03-18 22:35:321188void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401189 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051190 if (compositor_)
oshima750cb4342015-10-31 00:59:011191 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051192}
1193
[email protected]e195e582013-03-08 01:32:591194void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221195 DCHECK(!host_closing_);
1196
danakj6e3bf8012014-12-16 18:27:531197 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
oshima750cb4342015-10-31 00:59:011198 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331199 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391200 // For background pages and certain tests, we don't want to trigger
1201 // OutputSurface creation.
1202 if (compositor_never_visible_ || !RenderThreadImpl::current())
1203 compositor_->SetNeverVisible();
1204
pimanc4af3072015-10-02 03:45:591205 StartCompositor();
[email protected]e195e582013-03-08 01:32:591206}
1207
ennef3c58142014-12-09 21:44:381208void RenderWidget::WillCloseLayerTreeView() {
1209 if (host_closing_)
1210 return;
1211
1212 // Prevent new compositors or output surfaces from being created.
1213 host_closing_ = true;
1214
[email protected]aeeedad2014-08-22 18:16:221215 // Always send this notification to prevent new layer tree views from
1216 // being created, even if one hasn't been created yet.
1217 if (webwidget_)
1218 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221219}
1220
[email protected]180ef242013-11-07 06:50:461221blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281222 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061223}
1224
dglazkovf0e1d6d2015-10-10 02:13:481225void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1226 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1227 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1228 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1229 }
dglazkov79c426102015-08-31 21:22:431230
dglazkovf0e1d6d2015-10-10 02:13:481231 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1232 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431233}
1234
jdduke491a3f0c2015-06-15 23:30:261235void RenderWidget::WillBeginCompositorFrame() {
[email protected]9cd43a62012-03-26 08:03:561236 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371237
shuchen913f8b622015-07-31 13:22:431238 // The UpdateTextInputState can result in further layout and possibly
[email protected]abe8b3a2012-03-28 21:19:371239 // enable GPU acceleration so they need to be called before any painting
1240 // is done.
fsamuel72464894f2015-12-15 06:59:311241 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]abe8b3a2012-03-28 21:19:371242 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561243}
1244
[email protected]6fceb912013-02-15 06:24:151245void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441246 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1247 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271248 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161249 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171250#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271251 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1252 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171253#endif // defined(VIDEO_HOLE)
fsamuel72464894f2015-12-15 06:59:311254 input_handler_.FlushPendingInputEventAck();
jdduke491a3f0c2015-06-15 23:30:261255}
1256
1257void RenderWidget::DidCommitAndDrawCompositorFrame() {
1258 // NOTE: Tests may break if this event is renamed or moved. See
1259 // tab_capture_performancetest.cc.
1260 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
1261 // Notify subclasses that we initiated the paint operation.
1262 DidInitiatePaint();
1263}
1264
1265void RenderWidget::DidCompleteSwapBuffers() {
1266 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
1267
1268 // Notify subclasses threaded composited rendering was flushed to the screen.
1269 DidFlushPaint();
1270
1271 if (!next_paint_flags_ &&
1272 !need_update_rect_for_auto_resize_ &&
1273 !plugin_window_moves_.size()) {
1274 return;
1275 }
1276
1277 ViewHostMsg_UpdateRect_Params params;
1278 params.view_size = size_;
1279 params.plugin_window_moves.swap(plugin_window_moves_);
1280 params.flags = next_paint_flags_;
1281
1282 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1283 next_paint_flags_ = 0;
1284 need_update_rect_for_auto_resize_ = false;
1285}
1286
1287void RenderWidget::ScheduleComposite() {
1288 if (compositor_ &&
1289 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1290 compositor_->setNeedsAnimate();
1291 }
1292}
1293
1294void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1295 if (compositor_) {
1296 // Regardless of whether threaded compositing is enabled, always
1297 // use this mechanism to force the compositor to redraw. However,
1298 // the invalidation code path below is still needed for the
1299 // non-threaded case.
1300 compositor_->SetNeedsForcedRedraw();
1301 }
1302 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151303}
1304
[email protected]586871b2014-07-22 17:05:111305// static
1306scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1307 IPC::Message* msg,
1308 MessageDeliveryPolicy policy,
1309 FrameSwapMessageQueue* frame_swap_message_queue,
1310 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111311 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111312 bool first_message_for_frame = false;
1313 frame_swap_message_queue->QueueMessageForFrame(policy,
1314 source_frame_number,
1315 make_scoped_ptr(msg),
1316 &first_message_for_frame);
1317 if (first_message_for_frame) {
1318 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1319 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061320 return promise;
[email protected]586871b2014-07-22 17:05:111321 }
dcheng4b6b5ff2014-10-16 00:42:061322 return nullptr;
[email protected]586871b2014-07-22 17:05:111323}
1324
1325void RenderWidget::QueueMessage(IPC::Message* msg,
1326 MessageDeliveryPolicy policy) {
1327 // RenderThreadImpl::current() is NULL in some tests.
1328 if (!compositor_ || !RenderThreadImpl::current()) {
1329 Send(msg);
1330 return;
1331 }
1332
1333 scoped_ptr<cc::SwapPromise> swap_promise =
1334 QueueMessageImpl(msg,
1335 policy,
dcheng58867a92014-08-26 02:50:221336 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111337 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111338 compositor_->GetSourceFrameNumber());
1339
1340 if (swap_promise) {
1341 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351342 // Request a commit. This might either A) request a commit ahead of time
1343 // or B) request a commit which is not needed because there are not
1344 // pending updates. If B) then the commit will be skipped and the swap
1345 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1346 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1347 // can_cancel_commit is not unset.
1348 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111349 }
1350}
1351
[email protected]4873c7d2009-07-16 06:36:281352void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301353 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521354 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181355 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291356 // Only send a SetCursor message if we need to make a change.
1357 if (!current_cursor_.IsEqual(cursor)) {
1358 current_cursor_ = cursor;
1359 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1360 }
1361}
1362
1363// We are supposed to get a single call to Show for a newly created RenderWidget
1364// that was created via RenderWidget::CreateWebView. So, we wait until this
1365// point to dispatch the ShowWidget message.
1366//
1367// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281368// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291369//
[email protected]4873c7d2009-07-16 06:36:281370void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291371 DCHECK(!did_show_) << "received extraneous Show call";
1372 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1373 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1374
[email protected]8de12d942010-11-17 20:42:441375 if (did_show_)
1376 return;
1377
1378 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561379 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441380 // that's okay. It'll be ignored if as_popup is false, or the browser
1381 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561382 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1383 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291384}
1385
[email protected]4873c7d2009-07-16 06:36:281386void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291387}
1388
[email protected]2533ce12009-05-09 00:02:241389void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381390 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241391 Send(new ViewHostMsg_Close(routing_id_));
1392}
1393
dgozmancf9039cd2015-04-06 12:01:311394void RenderWidget::NotifyOnClose() {
1395 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1396}
1397
[email protected]4873c7d2009-07-16 06:36:281398void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081399 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321400 if (is_swapped_out_) {
1401 // This widget is currently swapped out, and the active widget is in a
1402 // different process. Have the browser route the close request to the
1403 // active widget instead, so that the correct unload handlers are run.
1404 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1405 return;
1406 }
1407
initial.commit09911bf2008-07-26 23:55:291408 // If a page calls window.close() twice, we'll end up here twice, but that's
1409 // OK. It is safe to send multiple Close messages.
1410
[email protected]2533ce12009-05-09 00:02:241411 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1412 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1413 // could be closed before the JS finishes executing. So instead, post a
1414 // message back to the message loop, which won't run until the JS is
1415 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081416 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211417 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291418}
1419
[email protected]9017d7852013-11-21 17:47:351420void RenderWidget::QueueSyntheticGesture(
1421 scoped_ptr<SyntheticGestureParams> gesture_params,
1422 const SyntheticGestureCompletionCallback& callback) {
1423 DCHECK(!callback.is_null());
1424
1425 pending_synthetic_gesture_callbacks_.push(callback);
1426
1427 SyntheticGesturePacket gesture_packet;
1428 gesture_packet.set_gesture_params(gesture_params.Pass());
1429
1430 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1431}
1432
initial.commit09911bf2008-07-26 23:55:291433void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031434 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381435 WillCloseLayerTreeView();
1436 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291437 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281438 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291439 webwidget_ = NULL;
1440 }
1441}
1442
[email protected]4873c7d2009-07-16 06:36:281443WebRect RenderWidget::windowRect() {
1444 if (pending_window_rect_count_)
1445 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241446
[email protected]80ad8622012-11-07 16:33:031447 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291448}
1449
[email protected]180ef242013-11-07 06:50:461450void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301451 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541452 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301453}
1454
oshima33ec97cd2015-12-14 19:40:241455void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1456 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511457 if (popup_origin_scale_for_emulation_) {
1458 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561459 window_rect.x = popup_screen_origin_for_emulation_.x() +
1460 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1461 window_rect.y = popup_screen_origin_for_emulation_.y() +
1462 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511463 }
1464
[email protected]5b45ad42013-10-25 00:42:041465 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201466 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561467 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1468 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031469 } else {
bokanc007c3a2015-02-03 07:15:561470 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031471 }
initial.commit09911bf2008-07-26 23:55:291472 } else {
bokanc007c3a2015-02-03 07:15:561473 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291474 }
1475}
1476
[email protected]2533ce12009-05-09 00:02:241477void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1478 pending_window_rect_ = rect;
1479 pending_window_rect_count_++;
1480}
1481
[email protected]4873c7d2009-07-16 06:36:281482WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241483 if (pending_window_rect_count_) {
1484 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1485 // the RootWindowRect is probably going to return wrong results since the
1486 // browser may not have processed the Move yet. There isn't really anything
1487 // good to do in this case, and it shouldn't happen - since this size is
1488 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281489 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241490 }
1491
[email protected]80ad8622012-11-07 16:33:031492 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371493}
1494
[email protected]4873c7d2009-07-16 06:36:281495WebRect RenderWidget::windowResizerRect() {
1496 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191497}
1498
[email protected]fa7b1dc2010-06-23 17:53:041499void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261500 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041501 const std::vector<WebCompositionUnderline>& underlines,
1502 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131503 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281504 return;
[email protected]66fca5bc2013-05-23 06:58:291505 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361506 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041507 text, WebVector<WebCompositionUnderline>(underlines),
1508 selection_start, selection_end)) {
1509 // If we failed to set the composition text, then we need to let the browser
1510 // process to cancel the input method's ongoing composition session, to make
1511 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221512 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261513 }
[email protected]88dbe32f2013-06-20 23:31:361514 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041515}
1516
[email protected]fcf75d42013-12-03 20:11:261517void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511518 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021519 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131520 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041521 return;
[email protected]66fca5bc2013-05-23 06:58:291522 ImeEventGuard guard(this);
fsamuel72464894f2015-12-15 06:59:311523 input_handler_.set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021524 if (text.length())
1525 webwidget_->confirmComposition(text);
1526 else if (keep_selection)
1527 webwidget_->confirmComposition(WebWidget::KeepSelection);
1528 else
1529 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuel72464894f2015-12-15 06:59:311530 input_handler_.set_handling_input_event(false);
[email protected]88dbe32f2013-06-20 23:31:361531 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291532}
1533
oshimad5279032015-12-16 18:22:331534void RenderWidget::OnDeviceScaleFactorChanged() {
1535 if (!compositor_)
1536 return;
1537
1538 if (IsUseZoomForDSFEnabled())
1539 compositor_->SetPaintedDeviceScaleFactor(device_scale_factor_);
1540 else
1541 compositor_->setDeviceScaleFactor(device_scale_factor_);
1542}
1543
[email protected]0bc1f572013-04-17 01:46:311544void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121545 // During shutdown we can just ignore this message.
1546 if (!webwidget_)
1547 return;
1548
[email protected]0bc1f572013-04-17 01:46:311549 // Even if the browser provides an empty damage rect, it's still expecting to
1550 // receive a repaint ack so just damage the entire widget bounds.
1551 if (size_to_paint.IsEmpty()) {
1552 size_to_paint = size_;
1553 }
1554
[email protected]ec7dc112008-08-06 05:30:121555 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051556 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311557 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121558}
1559
[email protected]79fa22e2013-08-23 15:18:121560void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351561 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1562
1563 pending_synthetic_gesture_callbacks_.front().Run();
1564 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271565}
1566
[email protected]4873c7d2009-07-16 06:36:281567void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111568 if (!webwidget_)
1569 return;
[email protected]4873c7d2009-07-16 06:36:281570 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111571}
1572
[email protected]80ad8622012-11-07 16:33:031573void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1574 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511575 if (screen_metrics_emulator_) {
1576 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1577 view_screen_rect, window_screen_rect);
1578 } else {
1579 view_screen_rect_ = view_screen_rect;
1580 window_screen_rect_ = window_screen_rect;
1581 }
[email protected]80ad8622012-11-07 16:33:031582 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1583}
1584
kenrbb4e2a3b2015-05-14 15:05:051585void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1586 if (compositor_)
1587 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1588}
1589
dtrainor5ef644e2015-11-19 00:12:471590void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1591 if (compositor_)
1592 compositor_->OnHandleCompositorProto(proto);
1593}
1594
[email protected]adb362312014-06-28 06:04:241595void RenderWidget::showImeIfNeeded() {
1596 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131597}
1598
fsamuel72464894f2015-12-15 06:59:311599ui::TextInputType RenderWidget::GetTextInputType() {
1600 if (webwidget_)
1601 return WebKitToUiTextInputType(webwidget_->textInputType());
1602 return ui::TEXT_INPUT_TYPE_NONE;
1603}
1604
1605void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
1606#if defined(OS_ANDROID)
1607// TODO(yukawa): Start sending character bounds when the browser side
1608// implementation becomes ready (crbug.com/424866).
1609#else
1610 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1611 gfx::Range range = gfx::Range();
1612 if (should_update_range) {
1613 GetCompositionRange(&range);
1614 } else {
1615 range = composition_range_;
1616 }
1617 std::vector<gfx::Rect> character_bounds;
1618 GetCompositionCharacterBounds(&character_bounds);
1619
1620 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1621 return;
1622 composition_character_bounds_ = character_bounds;
1623 composition_range_ = range;
1624 Send(new InputHostMsg_ImeCompositionRangeChanged(
1625 routing_id(), composition_range_, composition_character_bounds_));
1626#endif
1627}
1628
oshimaf866dab2015-12-05 00:41:541629void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1630 if (IsUseZoomForDSFEnabled()) {
1631 float reverse = 1 / device_scale_factor_;
oshimad5279032015-12-16 18:22:331632 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541633 // anchor element can be placed at half pixel.
1634 gfx::Rect window_rect =
1635 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1636 rect->x = window_rect.x();
1637 rect->y = window_rect.y();
1638 rect->width = window_rect.width();
1639 rect->height = window_rect.height();
1640 }
1641}
1642
[email protected]adb362312014-06-28 06:04:241643void RenderWidget::OnShowImeIfNeeded() {
1644#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311645 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241646#endif
rouslanf7ebd8832015-01-22 01:54:141647
1648// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1649// virtual keyboard.
1650#if !defined(OS_ANDROID)
1651 FocusChangeComplete();
1652#endif
[email protected]adb362312014-06-28 06:04:241653}
1654
1655#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371656void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1657 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131658}
1659
1660void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371661 DCHECK_GE(text_input_info_history_.size(), 1u);
1662 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511663}
[email protected]105dffb42013-02-20 03:46:211664#endif
1665
[email protected]0d1ebed12013-08-05 22:01:131666bool RenderWidget::ShouldHandleImeEvent() {
1667#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371668 if (!webwidget_)
1669 return false;
1670
1671 // We cannot handle IME events if there is any chance that the event we are
1672 // receiving here from the browser is based on the state that is different
1673 // from our current one as indicated by |text_input_info_|.
1674 // The states the browser might be in are:
1675 // text_input_info_history_[0] - current state ack'd by browser
1676 // text_input_info_history_[1...N] - pending state changes
1677 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1678 if (text_input_info_history_[i] != text_input_info_)
1679 return false;
1680 }
1681 return true;
[email protected]0d1ebed12013-08-05 22:01:131682#else
1683 return !!webwidget_;
1684#endif
1685}
1686
[email protected]468ac582012-11-20 00:53:191687void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1688 if (device_scale_factor_ == device_scale_factor)
1689 return;
1690
1691 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331692
1693 OnDeviceScaleFactorChanged();
1694
jdduke491a3f0c2015-06-15 23:30:261695 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191696}
1697
[email protected]28ed6b32014-06-08 02:16:271698bool RenderWidget::SetDeviceColorProfile(
1699 const std::vector<char>& color_profile) {
1700 if (device_color_profile_ == color_profile)
1701 return false;
1702
1703 device_color_profile_ = color_profile;
1704 return true;
1705}
1706
noeldb4df152014-09-16 17:45:201707void RenderWidget::ResetDeviceColorProfileForTesting() {
1708 if (!device_color_profile_.empty())
1709 device_color_profile_.clear();
1710 device_color_profile_.push_back('0');
1711}
1712
[email protected]fcdc5642014-05-09 14:32:241713void RenderWidget::OnOrientationChange() {
1714}
1715
[email protected]ceb36f7d2012-10-31 18:33:241716gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521717 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241718 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521719}
1720
[email protected]bee16aab2009-08-26 15:55:031721void RenderWidget::SetHidden(bool hidden) {
1722 if (is_hidden_ == hidden)
1723 return;
1724
jdduke8fac9d102014-12-20 02:40:131725 // The status has changed. Tell the RenderThread about it and ensure
1726 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031727 is_hidden_ = hidden;
fsamuel72464894f2015-12-15 06:59:311728 input_handler_.FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131729
[email protected]bee16aab2009-08-26 15:55:031730 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001731 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031732 else
[email protected]b2db9272014-01-10 17:42:001733 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111734
1735 if (render_widget_scheduling_state_)
1736 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031737}
1738
[email protected]2b624c562011-10-27 22:58:261739void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261740 if (!webwidget_)
1741 return;
1742
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121743 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261744 webwidget_->didEnterFullScreen();
1745 } else {
1746 webwidget_->didExitFullScreen();
1747 }
[email protected]2b624c562011-10-27 22:58:261748}
1749
[email protected]674741932009-02-04 23:44:461750bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051751 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461752}
1753
[email protected]674741932009-02-04 23:44:461754void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051755 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461756}
1757
[email protected]674741932009-02-04 23:44:461758void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051759 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461760}
1761
changwanf2a707b2015-10-30 08:22:161762void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1763 if (!ime_event_guard_)
1764 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291765}
1766
changwanf2a707b2015-10-30 08:22:161767void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1768 if (ime_event_guard_ != guard) {
1769#if defined(OS_ANDROID)
1770 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1771 // (e.g. long press gesture), we want to treat it as not-from-IME event
1772 // so that AdapterInputConnection can make changes to its Editable model.
1773 // Therefore, we want to mark this text state update as 'from IME' only
1774 // when all the nested events are all originating from IME.
1775 ime_event_guard_->set_from_ime(
1776 ime_event_guard_->from_ime() && guard->from_ime());
1777#endif
1778 return;
1779 }
1780 ime_event_guard_ = nullptr;
1781
[email protected]66fca5bc2013-05-23 06:58:291782 // While handling an ime event, text input state and selection bounds updates
1783 // are ignored. These must explicitly be updated once finished handling the
1784 // ime event.
1785 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471786#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161787 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311788 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1789 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471790#endif
[email protected]66fca5bc2013-05-23 06:58:291791}
1792
[email protected]7c8873e2013-02-05 08:03:011793void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1794 WebRect focus_webrect;
1795 WebRect anchor_webrect;
1796 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241797 convertViewportToWindow(&focus_webrect);
1798 convertViewportToWindow(&anchor_webrect);
1799 *focus = focus_webrect;
1800 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321801}
1802
[email protected]e99ef6f2011-10-16 01:13:001803void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081804 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001805 if (!webwidget_)
1806 return;
changwanf2a707b2015-10-30 08:22:161807 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291808 return;
[email protected]e99ef6f2011-10-16 01:13:001809
mohsenb0eeba72015-08-09 06:20:081810#if defined(USE_AURA)
1811 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1812 // Aura beucause composited selection updates are not working for webview tags
1813 // which regresses IME inside webview. Remove this when composited selection
1814 // updates are fixed for webviews. See, http://crbug.com/510568.
1815 bool send_ipc = true;
1816#else
jddukeacf809e2014-09-23 20:38:381817 // With composited selection updates, the selection bounds will be reported
1818 // directly by the compositor, in which case explicit IPC selection
1819 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081820 bool send_ipc =
1821 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1822#endif
1823 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381824 ViewHostMsg_SelectionBounds_Params params;
1825 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1826 if (selection_anchor_rect_ != params.anchor_rect ||
1827 selection_focus_rect_ != params.focus_rect) {
1828 selection_anchor_rect_ = params.anchor_rect;
1829 selection_focus_rect_ = params.focus_rect;
1830 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1831 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1832 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1833 }
[email protected]58b48a0d2012-06-13 07:01:351834 }
jddukeacf809e2014-09-23 20:38:381835
[email protected]88dbe32f2013-06-20 23:31:361836 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001837}
1838
dtrainor5ef644e2015-11-19 00:12:471839void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
1840 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
1841}
1842
[email protected]180ef242013-11-07 06:50:461843// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:171844#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
1845 static_assert(int(blink::WebTextInputType##a) \
1846 == int(ui::TEXT_INPUT_TYPE_##b), \
1847 "mismatching enums: " #a)
1848
1849STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
1850STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
1851STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
1852STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
1853STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
1854STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
1855STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
1856STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
1857STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
1858STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
1859STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
1860STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
1861STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
1862STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
1863STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
1864STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
1865STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451866
[email protected]5b739cb2012-08-21 20:35:211867ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461868 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211869 // Check the type is in the range representable by ui::TextInputType.
1870 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461871 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211872 return static_cast<ui::TextInputType>(type);
1873}
1874
[email protected]58b48a0d2012-06-13 07:01:351875void RenderWidget::GetCompositionCharacterBounds(
1876 std::vector<gfx::Rect>* bounds) {
1877 DCHECK(bounds);
1878 bounds->clear();
1879}
1880
[email protected]db4fc1e2013-09-06 20:01:511881void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:361882 size_t location, length;
1883 if (webwidget_->compositionRange(&location, &length)) {
1884 range->set_start(location);
1885 range->set_end(location + length);
1886 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1887 range->set_start(location);
1888 range->set_end(location + length);
1889 } else {
[email protected]db4fc1e2013-09-06 20:01:511890 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:361891 }
1892}
1893
[email protected]501ea13d2013-07-09 17:03:291894bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511895 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291896 const std::vector<gfx::Rect>& bounds) {
1897 if (composition_range_ != range)
1898 return true;
1899 if (bounds.size() != composition_character_bounds_.size())
1900 return true;
1901 for (size_t i = 0; i < bounds.size(); ++i) {
1902 if (bounds[i] != composition_character_bounds_[i])
1903 return true;
1904 }
1905 return false;
1906}
[email protected]501ea13d2013-07-09 17:03:291907
[email protected]ad26ef42011-06-17 07:59:451908bool RenderWidget::CanComposeInline() {
1909 return true;
[email protected]56ea1a62011-05-30 07:05:571910}
1911
[email protected]4873c7d2009-07-16 06:36:281912WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041913 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281914}
1915
[email protected]fa7b1dc2010-06-23 17:53:041916void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021917 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041918 // If the last text input type is not None, then we should finish any
1919 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451920 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041921 // If a composition text exists, then we need to let the browser process
1922 // to cancel the input method's ongoing composition session.
1923 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:221924 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041925 }
[email protected]d4cff272011-05-02 15:46:011926
[email protected]88dbe32f2013-06-20 23:31:361927 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041928}
1929
donnda070f3c2015-01-16 19:54:111930#if defined(OS_ANDROID)
1931void RenderWidget::showUnhandledTapUIIfNeeded(
1932 const WebPoint& tapped_position,
1933 const WebNode& tapped_node,
1934 bool page_changed) {
fsamuel72464894f2015-12-15 06:59:311935 DCHECK(input_handler_.handling_input_event());
donnda070f3c2015-01-16 19:54:111936 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371937 !tapped_node.isContentEditable() &&
1938 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111939 if (should_trigger) {
1940 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1941 tapped_position.x, tapped_position.y));
1942 }
1943}
1944#endif
1945
[email protected]c68c3e4e2013-01-24 00:36:561946void RenderWidget::didHandleGestureEvent(
1947 const WebGestureEvent& event,
1948 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021949#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561950 if (event_cancelled)
1951 return;
[email protected]07c70d22014-08-21 08:33:461952 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:311953 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461954 } else if (event.type == WebInputEvent::GestureLongPress) {
1955 DCHECK(webwidget_);
1956 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:311957 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461958 else
fsamuel72464894f2015-12-15 06:59:311959 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:561960 }
1961#endif
1962}
1963
sataya.m582c9ce2015-06-09 08:03:421964void RenderWidget::didOverscroll(
1965 const blink::WebFloatSize& unusedDelta,
1966 const blink::WebFloatSize& accumulatedRootOverScroll,
1967 const blink::WebFloatPoint& position,
1968 const blink::WebFloatSize& velocity) {
fsamuel72464894f2015-12-15 06:59:311969 input_handler_.DidOverscrollFromBlink(unusedDelta, accumulatedRootOverScroll,
1970 position, velocity);
sataya.m582c9ce2015-06-09 08:03:421971}
1972
[email protected]7912e822014-04-16 02:37:031973void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:391974 if (!is_hidden())
1975 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:031976}
1977
[email protected]29e2fb42013-07-19 01:13:471978void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291979 size_t i = 0;
1980 for (; i < plugin_window_moves_.size(); ++i) {
1981 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581982 if (move.rects_valid) {
1983 plugin_window_moves_[i] = move;
1984 } else {
1985 plugin_window_moves_[i].visible = move.visible;
1986 }
initial.commit09911bf2008-07-26 23:55:291987 break;
1988 }
1989 }
1990
1991 if (i == plugin_window_moves_.size())
1992 plugin_window_moves_.push_back(move);
1993}
[email protected]268654772009-08-06 23:02:041994
1995void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1996 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1997 i != plugin_window_moves_.end(); ++i) {
1998 if (i->window == window) {
1999 plugin_window_moves_.erase(i);
2000 break;
2001 }
2002 }
2003}
[email protected]67bfb83f2011-09-22 03:36:372004
[email protected]63b465922012-09-06 02:04:522005
[email protected]24ed0432013-04-24 07:50:312006RenderWidgetCompositor* RenderWidget::compositor() const {
2007 return compositor_.get();
2008}
2009
fsamuel72464894f2015-12-15 06:59:312010void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
2011 input_handler_.set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372012}
[email protected]c3d45532011-10-07 19:20:402013
fsamuel72464894f2015-12-15 06:59:312014bool RenderWidget::SendAckForMouseMoveFromDebugger() {
2015 return input_handler_.SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242016}
2017
fsamuel72464894f2015-12-15 06:59:312018void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
2019 input_handler_.IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312020}
2021
[email protected]ce6689f2013-03-29 12:52:552022void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112023 if (render_widget_scheduling_state_)
2024 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552025 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2026}
2027
mostynbe29b6882015-01-13 09:59:172028// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2029#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2030 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2031 "mismatching enums: " #a)
2032
[email protected]5d0bbdfa92013-12-10 00:35:512033void RenderWidget::setTouchAction(
2034 blink::WebTouchAction web_touch_action) {
2035
2036 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2037 // when blink is emulating touch with mouse).
fsamuel72464894f2015-12-15 06:59:312038 if (input_handler_.handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512039 return;
2040
dtapuskaa98ac8d72015-05-08 19:29:092041 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172042 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092043 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2044 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172045 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092046 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2047 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172048 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
rbyersa8b478d2015-10-30 15:49:102049 STATIC_ASSERT_WTI_ENUM_MATCH(Pan, PAN);
mostynbe29b6882015-01-13 09:59:172050 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
rbyersa8b478d2015-10-30 15:49:102051 STATIC_ASSERT_WTI_ENUM_MATCH(Manipulation, MANIPULATION);
2052 STATIC_ASSERT_WTI_ENUM_MATCH(DoubleTapZoom, DOUBLE_TAP_ZOOM);
2053 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
[email protected]a18f67a2013-12-20 19:44:362054
2055 content::TouchAction content_touch_action =
2056 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512057 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2058}
2059
[email protected]90f24152014-04-09 12:41:362060void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2061#if defined(OS_ANDROID)
2062 text_field_is_dirty_ = true;
2063#endif
2064}
2065
[email protected]0634cdd42013-08-16 00:46:092066scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
jbauman5e420d32015-08-05 09:33:012067RenderWidget::CreateGraphicsContext3D(bool compositor) {
[email protected]ed7defa2013-03-12 21:29:592068 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092069 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492070 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222071 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092072 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292073 if (!RenderThreadImpl::current())
2074 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402075 CauseForGpuLaunch cause =
2076 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292077 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402078 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222079 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292080 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592081
[email protected]828a3932014-04-02 14:43:132082 // Explicitly disable antialiasing for the compositor. As of the time of
2083 // this writing, the only platform that supported antialiasing for the
2084 // compositor was Mac OS X, because the on-screen OpenGL context creation
2085 // code paths on Windows and Linux didn't yet have multisampling support.
2086 // Mac OS X essentially always behaves as though it's rendering offscreen.
2087 // Multisampling has a heavy cost especially on devices with relatively low
2088 // fill rate like most notebooks, and the Mac implementation would need to
2089 // be optimized to resolve directly into the IOSurface shared between the
2090 // GPU and browser processes. For these reasons and to avoid platform
2091 // disparities we explicitly disable antialiasing.
2092 blink::WebGraphicsContext3D::Attributes attributes;
2093 attributes.antialias = false;
2094 attributes.shareResources = true;
2095 attributes.noAutomaticFlushes = true;
2096 attributes.depth = false;
2097 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132098 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292099 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012100#if defined(OS_ANDROID)
boliu853d46052015-10-13 20:20:062101 bool using_synchronous_compositing =
boliubee541f42015-11-05 00:52:532102 SynchronousCompositorFactory::GetInstance() ||
2103 base::CommandLine::ForCurrentProcess()->HasSwitch(
2104 switches::kIPCSyncCompositing);
[email protected]b6eb8e332013-09-10 00:51:012105 // If we raster too fast we become upload bound, and pending
2106 // uploads consume memory. For maximum upload throughput, we would
2107 // want to allow for upload_throughput * pipeline_time of pending
2108 // uploads, after which we are just wasting memory. Since we don't
2109 // know our upload throughput yet, this just caps our memory usage.
boliu853d46052015-10-13 20:20:062110 // Synchronous compositor uses half because synchronous compositor
2111 // pipeline is only one frame deep. But twice of half for low end
2112 // because 16bit texture is not supported.
2113 size_t divider = using_synchronous_compositing ? 2 : 1;
[email protected]35b4f0c2014-06-26 16:55:272114 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032115 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012116 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032117 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012118 // Deadline to draw a frame to achieve 60 frames per second.
2119 const size_t kMillisecondsPerFrame = 16;
2120 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032121 size_t max_transfer_buffer_usage_mb =
2122 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2123 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012124 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2125 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292126 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032127 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012128#endif
jbauman00ca2dc2015-08-10 23:21:152129 if (compositor) {
jbauman5e420d32015-08-05 09:33:012130 limits.command_buffer_size = 64 * 1024;
jbauman00ca2dc2015-08-10 23:21:152131 limits.start_transfer_buffer_size = 64 * 1024;
2132 limits.min_transfer_buffer_size = 64 * 1024;
2133 }
[email protected]96ab016c2013-10-23 00:50:292134
[email protected]96ab016c2013-10-23 00:50:292135 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
piman5d36dae2015-09-24 22:47:052136 new WebGraphicsContext3DCommandBufferImpl(
piman08f75532015-10-05 18:58:012137 0, GetURLForGraphicsContext3D(), gpu_channel_host.get(), attributes,
2138 lose_context_when_out_of_memory, limits, NULL));
[email protected]0634cdd42013-08-16 00:46:092139 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592140}
2141
[email protected]e3244ed2014-06-20 20:04:272142void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2143 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162144}
2145
[email protected]e3244ed2014-06-20 20:04:272146void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2147 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162148}
2149
[email protected]de3c5d82014-05-28 22:12:592150void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2151 render_frames_.AddObserver(frame);
2152}
2153
2154void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2155 render_frames_.RemoveObserver(frame);
2156}
2157
[email protected]a017938b2014-05-27 21:17:172158#if defined(VIDEO_HOLE)
2159void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2160 video_hole_frames_.AddObserver(frame);
2161}
2162
2163void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2164 video_hole_frames_.RemoveObserver(frame);
2165}
2166#endif // defined(VIDEO_HOLE)
2167
[email protected]e9ff79c2012-10-19 21:31:262168} // namespace content