blob: 8366d6cf948971d6302feaf06e2cc55893dfc713 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
dcheng07945f632015-12-26 07:59:327#include <utility>
8
[email protected]c27dd4f2014-05-22 18:05:199#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2110#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0011#include "base/command_line.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/logging.h"
avi1023d012015-12-25 02:39:1413#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4015#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3016#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2118#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2720#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0121#include "base/trace_event/trace_event.h"
22#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4823#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5224#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3325#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3026#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0427#include "cc/trees/layer_tree_host.h"
alexclarke7fa93942015-10-21 15:37:1128#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2129#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]29e2fb42013-07-19 01:13:4730#include "content/child/npapi/webplugin.h"
oshima750cb4342015-10-31 00:59:0131#include "content/common/content_switches_internal.h"
[email protected]0634cdd42013-08-16 00:46:0932#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5933#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2934#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3535#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4436#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1537#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1538#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5039#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2940#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4241#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4042#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5143#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5944#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2945#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1146#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5947#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1148#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2849#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2950#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1351#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3252#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1653#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2754#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0555#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4456#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5557#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:0958#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0459#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1860#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4861#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1862#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3063#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1164#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3065#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1866#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3067#include "third_party/WebKit/public/platform/WebSize.h"
68#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4369#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5970#include "third_party/WebKit/public/web/WebFrameWidget.h"
71#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1172#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3173#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3174#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
75#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3876#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5977#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4178#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1379#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5080#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0981#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3282#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4883#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2784#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4185#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4886
[email protected]eeb93112013-05-01 19:41:1087#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1588#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0789#include "content/renderer/android/synchronous_compositor_factory.h"
boliubee541f42015-11-05 00:52:5390#include "content/renderer/android/synchronous_compositor_filter.h"
91#include "content/renderer/android/synchronous_compositor_output_surface.h"
[email protected]eeb93112013-05-01 19:41:1092#endif
93
[email protected]661eb9d2009-02-03 02:11:4894#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4995#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5296#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4197#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4898#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4499
penghuang28a5fa22015-12-02 17:58:19100#if defined(MOJO_SHELL_CLIENT)
101#include "content/public/common/mojo_shell_connection.h"
fsamuel2545ecc2015-12-05 00:44:46102#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:19103#endif
104
[email protected]2255a9332013-06-17 05:12:31105#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:29106
[email protected]180ef242013-11-07 06:50:46107using blink::WebCompositionUnderline;
108using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43109using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46110using blink::WebGestureEvent;
111using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49112using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46113using blink::WebKeyboardEvent;
114using blink::WebMouseEvent;
115using blink::WebMouseWheelEvent;
116using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11117using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46118using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11119using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46120using blink::WebPopupType;
121using blink::WebRange;
122using blink::WebRect;
123using blink::WebScreenInfo;
124using blink::WebSize;
125using blink::WebTextDirection;
126using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25127using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46128using blink::WebVector;
129using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26130
[email protected]6a4d7f62013-01-07 21:32:13131namespace {
[email protected]b256eca2013-07-11 10:57:40132
133typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
134
135class TextInputModeMapSingleton {
136 public:
137 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22138 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40139 }
[email protected]dd705d4d2013-11-27 08:14:41140 TextInputModeMapSingleton() {
141 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
142 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
143 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
144 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
145 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
146 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
147 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
148 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
149 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
150 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
151 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40152 }
[email protected]dd705d4d2013-11-27 08:14:41153 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40154 private:
[email protected]dd705d4d2013-11-27 08:14:41155 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40156
olli.raula36aa8be2015-09-10 11:14:22157 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40158
159 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
160};
161
[email protected]dd705d4d2013-11-27 08:14:41162ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40163 static TextInputModeMapSingleton* singleton =
164 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41165 TextInputModeMap::const_iterator it =
166 singleton->map().find(input_mode.utf8());
167 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40168 return ui::TEXT_INPUT_MODE_DEFAULT;
169 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13170}
[email protected]b256eca2013-07-11 10:57:40171
fsamuel72464894f2015-12-15 06:59:31172bool IsDateTimeInput(ui::TextInputType type) {
173 return type == ui::TEXT_INPUT_TYPE_DATE ||
174 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
175 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
176 type == ui::TEXT_INPUT_TYPE_MONTH ||
177 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
dtapuskae7473612015-12-04 14:23:06178}
179
[email protected]b256eca2013-07-11 10:57:40180} // namespace
181
[email protected]e9ff79c2012-10-19 21:31:26182namespace content {
[email protected]62cb33cae2009-03-27 23:30:22183
[email protected]b2e4c70132013-10-03 02:07:51184// RenderWidget::ScreenMetricsEmulator ----------------------------------------
185
186class RenderWidget::ScreenMetricsEmulator {
187 public:
188 ScreenMetricsEmulator(
189 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43190 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51191 virtual ~ScreenMetricsEmulator();
192
[email protected]19193682014-04-03 15:01:43193 // Scale and offset used to convert between host coordinates
194 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51195 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20196 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43197 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51198 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56199 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51200
201 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43202 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51203
204 // The following methods alter handlers' behavior for messages related to
205 // widget size and position.
206 void OnResizeMessage(const ViewMsg_Resize_Params& params);
207 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
208 const gfx::Rect& window_screen_rect);
209 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31210 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51211
212 private:
[email protected]19193682014-04-03 15:01:43213 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02214 void Apply(bool top_controls_shrink_blink_size,
215 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44216 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12217 bool is_fullscreen_granted,
218 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51219
220 RenderWidget* widget_;
221
[email protected]7f99fc22013-11-08 14:05:58222 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43223 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51224
[email protected]a179d3962013-11-12 14:44:40225 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51226 float scale_;
dgozman9260b0a12015-03-16 13:45:20227 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51228
[email protected]19193682014-04-03 15:01:43229 // Widget rect as passed to webwidget.
230 gfx::Rect applied_widget_rect_;
231
[email protected]b2e4c70132013-10-03 02:07:51232 // Original values to restore back after emulation ends.
233 gfx::Size original_size_;
234 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28235 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46236 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51237 gfx::Rect original_view_screen_rect_;
238 gfx::Rect original_window_screen_rect_;
239};
240
241RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
242 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43243 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51244 : widget_(widget),
[email protected]19193682014-04-03 15:01:43245 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51246 scale_(1.f) {
247 original_size_ = widget_->size_;
248 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28249 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51250 original_screen_info_ = widget_->screen_info_;
251 original_view_screen_rect_ = widget_->view_screen_rect_;
252 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02253 Apply(widget_->top_controls_shrink_blink_size_,
254 widget_->top_controls_height_,
255 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12256 widget_->is_fullscreen_granted_,
257 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51258}
259
260RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
261 widget_->screen_info_ = original_screen_info_;
262
263 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20264 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51265 widget_->view_screen_rect_ = original_view_screen_rect_;
266 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01267 widget_->Resize(original_size_,
268 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02269 widget_->top_controls_shrink_blink_size_,
270 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01271 original_visible_viewport_size_,
272 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12273 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12274 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01275 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51276}
277
278void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43279 const WebDeviceEmulationParams& params) {
280 params_ = params;
281 Reapply();
282}
283
284void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02285 Apply(widget_->top_controls_shrink_blink_size_,
286 widget_->top_controls_height_,
287 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12288 widget_->is_fullscreen_granted_,
289 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51290}
291
[email protected]19193682014-04-03 15:01:43292void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02293 bool top_controls_shrink_blink_size,
294 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44295 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12296 bool is_fullscreen_granted,
297 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31298 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
299 if (!applied_widget_rect_.width())
300 applied_widget_rect_.set_width(original_size_.width());
301 if (!applied_widget_rect_.height())
302 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43303
[email protected]f442ee42014-05-14 11:53:12304 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02305 int original_width = std::max(original_size_.width(), 1);
306 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51307 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02308 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51309 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02310 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51311 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
312 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01313
314 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43315 offset_.set_x(
316 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01317 offset_.set_y(
[email protected]19193682014-04-03 15:01:43318 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51319 } else {
[email protected]0b3578c2014-06-20 18:29:02320 scale_ = params_.scale;
321 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01322 }
[email protected]7f0e8fa2014-03-26 12:32:01323
[email protected]19193682014-04-03 15:01:43324 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
325 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01326 widget_->screen_info_.rect = original_screen_info_.rect;
327 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
328 widget_->window_screen_rect_ = original_window_screen_rect_;
329 } else {
dgozmanf28ccbe2015-06-24 08:50:49330 applied_widget_rect_.set_origin(params_.viewPosition);
331 gfx::Rect screen_rect = applied_widget_rect_;
332 if (!params_.screenSize.isEmpty()) {
333 screen_rect =
334 gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height);
335 }
336 widget_->screen_info_.rect = screen_rect;
337 widget_->screen_info_.availableRect = screen_rect;
[email protected]19193682014-04-03 15:01:43338 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01339 }
[email protected]a179d3962013-11-12 14:44:40340
[email protected]19193682014-04-03 15:01:43341 float applied_device_scale_factor = params_.deviceScaleFactor ?
342 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01343 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51344
[email protected]7f99fc22013-11-08 14:05:58345 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51346 // - we keep the real device scale factor in compositor to produce sharp image
347 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58348 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51349 // root layer.
dgozman9260b0a12015-03-16 13:45:20350 blink::WebDeviceEmulationParams modified_params = params_;
351 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
352 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
353 modified_params.scale = scale_;
354 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51355
[email protected]7f0e8fa2014-03-26 12:32:01356 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43357 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51358
danakjddaec912015-09-25 19:38:40359 gfx::Size physical_backing_size = gfx::ScaleToCeiledSize(
360 original_size_, original_screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02361 widget_->Resize(applied_widget_rect_.size(),
362 physical_backing_size,
363 top_controls_shrink_blink_size,
364 top_controls_height,
365 applied_widget_rect_.size(),
366 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12367 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12368 display_mode,
dtrainorcb7779b82014-12-04 01:08:02369 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51370}
371
372void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
373 const ViewMsg_Resize_Params& params) {
374 bool need_ack = params.new_size != original_size_ &&
375 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
376 original_size_ = params.new_size;
377 original_physical_backing_size_ = params.physical_backing_size;
378 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28379 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02380 Apply(params.top_controls_shrink_blink_size,
381 params.top_controls_height,
382 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12383 params.is_fullscreen_granted,
384 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51385
386 if (need_ack) {
387 widget_->set_next_paint_is_resize_ack();
388 if (widget_->compositor_)
389 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
390 }
391}
392
393void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
394 const gfx::Rect& view_screen_rect,
395 const gfx::Rect& window_screen_rect) {
396 original_view_screen_rect_ = view_screen_rect;
397 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43398 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
399 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51400}
401
402void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
403 ContextMenuParams* params) {
404 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40405 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51406 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40407 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51408}
409
[email protected]2d6836f42014-07-02 17:25:31410gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
411 const gfx::Rect& anchor) {
danakj4606f6332015-08-31 23:56:56412 gfx::Rect scaled = gfx::ScaleToEnclosedRect(anchor, scale_);
[email protected]2d6836f42014-07-02 17:25:31413 scaled.set_x(scaled.x() + offset_.x());
414 scaled.set_y(scaled.y() + offset_.y());
415 return scaled;
416}
417
[email protected]b2e4c70132013-10-03 02:07:51418// RenderWidget ---------------------------------------------------------------
419
dcheng35d31c112015-07-22 00:17:36420RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
421 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46422 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04423 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03424 bool hidden,
425 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29426 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36427 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53428 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29429 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02430 top_controls_shrink_blink_size_(false),
431 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29432 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51433 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09434 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29435 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04436 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39437 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12438 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12439 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16440 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48441 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22442 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44443 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20444 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45445 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40446 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20447 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53448 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12449 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48450 pending_window_rect_count_(0),
fsamuel72464894f2015-12-15 06:59:31451 input_handler_(this, this),
[email protected]842f10652012-06-06 01:54:04452 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52453 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30454 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13455#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36456 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13457#endif
[email protected]b2e4c70132013-10-03 02:07:51458 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11459 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42460 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51461 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05462 if (!swapped_out)
463 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27464 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53465 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37466#if defined(OS_ANDROID)
467 text_input_info_history_.push_back(blink::WebTextInputInfo());
468#endif
alexclarke7fa93942015-10-21 15:37:11469
470 // In tests there may not be a RenderThreadImpl.
471 if (RenderThreadImpl::current()) {
472 render_widget_scheduling_state_ = RenderThreadImpl::current()
473 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32474 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11475 render_widget_scheduling_state_->SetHidden(is_hidden_);
476 }
initial.commit09911bf2008-07-26 23:55:29477}
478
479RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11480 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16481
[email protected]992db4c2011-05-12 15:37:15482 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02483 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15484 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29485}
486
[email protected]484955942010-08-19 16:13:18487// static
avi1023d012015-12-25 02:39:14488RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53489 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46490 blink::WebPopupType popup_type,
491 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29492 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36493 scoped_refptr<RenderWidget> widget(new RenderWidget(
494 compositor_deps, popup_type, screen_info, false, false, false));
495 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46496 return widget.get();
[email protected]a635f942012-12-07 10:34:29497 }
498 return NULL;
initial.commit09911bf2008-07-26 23:55:29499}
500
[email protected]484955942010-08-19 16:13:18501// static
kenrba7199832015-01-22 23:44:59502RenderWidget* RenderWidget::CreateForFrame(
503 int routing_id,
kenrba7199832015-01-22 23:44:59504 bool hidden,
505 const blink::WebScreenInfo& screen_info,
506 CompositorDependencies* compositor_deps,
507 blink::WebLocalFrame* frame) {
508 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55509 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
510 // same routing ID for both the view routing ID and the main frame widget
511 // routing ID. https://crbug.com/545684
512 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
513 if (view) {
514 view->AttachWebFrameWidget(RenderWidget::CreateWebFrameWidget(view, frame));
515 return view;
516 }
dcheng35d31c112015-07-22 00:17:36517 scoped_refptr<RenderWidget> widget(
518 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
519 false, hidden, false));
kenrba7199832015-01-22 23:44:59520 widget->routing_id_ = routing_id;
simonhong628f9812015-04-27 23:13:20521 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59522 // DoInit increments the reference count on |widget|, keeping it alive after
523 // this function returns.
dcheng35d31c112015-07-22 00:17:36524 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59525 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
526 nullptr)) {
kenrba7199832015-01-22 23:44:59527 return widget.get();
528 }
529 return nullptr;
530}
531
532// static
dchengda9b4bb2015-07-20 20:58:08533blink::WebWidget* RenderWidget::CreateWebFrameWidget(
534 RenderWidget* render_widget,
535 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55536 if (!frame->parent()) {
537 // TODO(dcheng): The main frame widget currently has a special case.
538 // Eliminate this once WebView is no longer a WebWidget.
539 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
540 }
dchengda9b4bb2015-07-20 20:58:08541 return blink::WebFrameWidget::create(render_widget, frame);
542}
543
544// static
kenrba7199832015-01-22 23:44:59545blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18546 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46547 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18548 break;
[email protected]180ef242013-11-07 06:50:46549 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44550 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18551 default:
552 NOTREACHED();
553 }
554 return NULL;
555}
556
dchengda9b4bb2015-07-20 20:58:08557void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32558 OnClose();
kenrba7199832015-01-22 23:44:59559}
560
avi1023d012015-12-25 02:39:14561bool RenderWidget::Init(int32_t opener_id) {
piman5d36dae2015-09-24 22:47:05562 return DoInit(
563 opener_id, RenderWidget::CreateWebWidget(this),
564 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
[email protected]484955942010-08-19 16:13:18565}
566
avi1023d012015-12-25 02:39:14567bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06568 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18569 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29570 DCHECK(!webwidget_);
571
572 if (opener_id != MSG_ROUTING_NONE)
573 opener_id_ = opener_id;
574
[email protected]484955942010-08-19 16:13:18575 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29576
kenrba7199832015-01-22 23:44:59577 bool result = true;
578 if (create_widget_message)
579 result = RenderThread::Get()->Send(create_widget_message);
580
initial.commit09911bf2008-07-26 23:55:29581 if (result) {
[email protected]380244092011-10-07 17:26:27582 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29583 // Take a reference on behalf of the RenderThread. This will be balanced
584 // when we receive ViewMsg_Close.
585 AddRef();
[email protected]b2db9272014-01-10 17:42:00586 if (RenderThreadImpl::current()) {
587 RenderThreadImpl::current()->WidgetCreated();
588 if (is_hidden_)
589 RenderThreadImpl::current()->WidgetHidden();
590 }
[email protected]a635f942012-12-07 10:34:29591 return true;
initial.commit09911bf2008-07-26 23:55:29592 } else {
[email protected]a635f942012-12-07 10:34:29593 // The above Send can fail when the tab is closing.
594 return false;
initial.commit09911bf2008-07-26 23:55:29595 }
596}
597
[email protected]992db4c2011-05-12 15:37:15598void RenderWidget::SetSwappedOut(bool is_swapped_out) {
599 // We should only toggle between states.
600 DCHECK(is_swapped_out_ != is_swapped_out);
601 is_swapped_out_ = is_swapped_out;
602
603 // If we are swapping out, we will call ReleaseProcess, allowing the process
604 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52605 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15606 // If we are swapping in, we call AddRefProcess to prevent the process from
607 // exiting.
[email protected]949b6592014-08-20 13:17:52608 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15609 RenderProcess::current()->AddRefProcess();
610}
611
[email protected]949b6592014-08-20 13:17:52612void RenderWidget::WasSwappedOut() {
613 // If we have been swapped out and no one else is using this process,
614 // it's safe to exit now.
615 CHECK(is_swapped_out_);
616 RenderProcess::current()->ReleaseProcess();
617}
618
[email protected]b2e4c70132013-10-03 02:07:51619void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
620 ScreenMetricsEmulator* emulator) {
621 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43622 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49623 popup_screen_origin_for_emulation_ = gfx::Point(
624 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
625 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56626 screen_info_ = emulator->original_screen_info();
627 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51628}
629
[email protected]2d6836f42014-07-02 17:25:31630gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
631 if (screen_metrics_emulator_)
632 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
633 return anchor;
634}
635
[email protected]b2e4c70132013-10-03 02:07:51636void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20637 bool enabled,
638 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51639 // This is only supported in RenderView.
640 NOTREACHED();
641}
642
[email protected]53907862014-03-25 15:42:40643#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51644void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
645 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49646 popup->SetOriginScaleAndOffsetForEmulation(
647 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51648}
[email protected]53907862014-03-25 15:42:40649#endif
[email protected]b2e4c70132013-10-03 02:07:51650
651void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
652 if (screen_metrics_emulator_)
653 screen_metrics_emulator_->OnShowContextMenu(params);
654}
655
[email protected]a95986a82010-12-24 06:19:28656bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
657 bool handled = true;
658 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15659 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22660 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
661 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22662 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
663 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15664 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
665 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35666 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
667 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28668 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28669 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20670 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
671 OnEnableDeviceEmulation)
672 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
673 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41674 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54675 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28676 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41677 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25678 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28679 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
680 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03681 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05682 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21683#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37684 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
[email protected]2384b6c2013-02-28 23:58:51685 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21686#endif
dtrainor5ef644e2015-11-19 00:12:47687 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28688 IPC_MESSAGE_UNHANDLED(handled = false)
689 IPC_END_MESSAGE_MAP()
690 return handled;
691}
initial.commit09911bf2008-07-26 23:55:29692
693bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15694 // Don't send any messages after the browser has told us to close, and filter
695 // most outgoing messages while swapped out.
696 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26697 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11698 closing_) {
initial.commit09911bf2008-07-26 23:55:29699 delete message;
700 return false;
701 }
702
703 // If given a messsage without a routing ID, then assign our routing ID.
704 if (message->routing_id() == MSG_ROUTING_NONE)
705 message->set_routing_id(routing_id_);
706
[email protected]380244092011-10-07 17:26:27707 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44708}
709
[email protected]61e2b3cc2012-03-02 16:13:34710void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44711 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02712 bool top_controls_shrink_blink_size,
713 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44714 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34715 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12716 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12717 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58718 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56719 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48720 // A resize ack shouldn't be requested if we have not ACK'd the previous
721 // one.
722 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
723 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
724 }
initial.commit09911bf2008-07-26 23:55:29725
[email protected]61e2b3cc2012-03-02 16:13:34726 // Ignore this during shutdown.
727 if (!webwidget_)
728 return;
729
oshima750cb4342015-10-31 00:59:01730 if (compositor_)
731 compositor_->setViewportSize(physical_backing_size);
[email protected]60d47ac2013-03-01 23:42:44732
oshima750cb4342015-10-31 00:59:01733 bool resized = size_ != new_size ||
734 physical_backing_size_ != physical_backing_size;
735
736 size_ = new_size;
[email protected]dade8992013-03-04 07:34:34737 physical_backing_size_ = physical_backing_size;
oshima750cb4342015-10-31 00:59:01738
dtrainorcb7779b82014-12-04 01:08:02739 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
740 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28741 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34742 resizer_rect_ = resizer_rect;
743
744 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12745 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12746 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12747 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34748
aelias6004fe02015-02-07 21:43:01749 webwidget_->setTopControlsHeight(top_controls_height,
750 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43751
oshima750cb4342015-10-31 00:59:01752 if (resized) {
753 gfx::Size new_widget_size =
754 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_;
[email protected]61e2b3cc2012-03-02 16:13:34755 // When resizing, we want to wait to paint before ACK'ing the resize. This
756 // ensures that we only resize as fast as we can paint. We only need to
757 // send an ACK if we are resized to a non-empty rect.
oshima750cb4342015-10-31 00:59:01758 webwidget_->resize(new_widget_size);
759 }
jbroman304f01a2015-11-05 17:04:21760 WebSize visual_viewport_size;
oshima750cb4342015-10-31 00:59:01761
762 if (IsUseZoomForDSFEnabled()) {
oshimad5279032015-12-16 18:22:33763 visual_viewport_size =
764 gfx::ScaleToCeiledSize(visible_viewport_size, device_scale_factor_);
oshima750cb4342015-10-31 00:59:01765 } else {
jbroman304f01a2015-11-05 17:04:21766 visual_viewport_size = visible_viewport_size_;
[email protected]632c4382013-05-15 08:58:45767 }
768
jbroman304f01a2015-11-05 17:04:21769 webwidget()->resizeVisualViewport(visual_viewport_size);
[email protected]bb6378fe2014-04-28 21:19:44770
[email protected]632c4382013-05-15 08:58:45771 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58772 // In this case there is no paint/composite and therefore no
773 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
774 // ack through a fake ViewHostMsg_UpdateRect or a different message.
775 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34776 }
777
[email protected]20fbfc22013-05-08 20:50:58778 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45779 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58780 set_next_paint_is_resize_ack();
781
[email protected]61e2b3cc2012-03-02 16:13:34782 if (fullscreen_change)
783 DidToggleFullscreen();
784
785 // If a resize ack is requested and it isn't set-up, then no more resizes will
786 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45787 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29788}
789
bokanc007c3a2015-02-03 07:15:56790void RenderWidget::SetWindowRectSynchronously(
791 const gfx::Rect& new_window_rect) {
792 Resize(new_window_rect.size(),
793 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02794 top_controls_shrink_blink_size_,
795 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56796 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01797 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12798 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12799 display_mode_,
[email protected]587941d2014-08-22 01:40:01800 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56801 view_screen_rect_ = new_window_rect;
802 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02803 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56804 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02805}
806
initial.commit09911bf2008-07-26 23:55:29807void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32808 DCHECK(content::RenderThread::Get());
809 if (closing_)
810 return;
811 NotifyOnClose();
812 closing_ = true;
813
814 // Browser correspondence is no longer needed at this point.
815 if (routing_id_ != MSG_ROUTING_NONE) {
816 RenderThread::Get()->RemoveRoute(routing_id_);
817 SetHidden(false);
818 if (RenderThreadImpl::current())
819 RenderThreadImpl::current()->WidgetDestroyed();
820 }
821
822 if (for_oopif_) {
823 // Widgets for frames may be created and closed at any time while the frame
824 // is alive. However, the closing process must happen synchronously. Frame
825 // widget and frames hold pointers to each other. If Close() is deferred to
826 // the message loop like in the non-frame widget case, WebWidget::close()
827 // can end up accessing members of an already-deleted frame.
828 Close();
829 } else {
830 // If there is a Send call on the stack, then it could be dangerous to close
831 // now. Post a task that only gets invoked when there are no nested message
832 // loops.
833 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
834 FROM_HERE, base::Bind(&RenderWidget::Close, this));
835 }
836
837 // Balances the AddRef taken when we called AddRoute.
838 Release();
initial.commit09911bf2008-07-26 23:55:29839}
840
[email protected]0fdd5012013-05-29 08:05:56841void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04842 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32843 return;
844
[email protected]b2e4c70132013-10-03 02:07:51845 if (screen_metrics_emulator_) {
846 screen_metrics_emulator_->OnResizeMessage(params);
847 return;
848 }
849
[email protected]fcdc5642014-05-09 14:32:24850 bool orientation_changed =
851 screen_info_.orientationAngle != params.screen_info.orientationAngle;
852
[email protected]0fdd5012013-05-29 08:05:56853 screen_info_ = params.screen_info;
854 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02855 Resize(params.new_size,
856 params.physical_backing_size,
857 params.top_controls_shrink_blink_size,
858 params.top_controls_height,
859 params.visible_viewport_size,
860 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12861 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12862 params.display_mode,
sievers4e33dae2015-02-25 20:43:58863 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24864
865 if (orientation_changed)
866 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29867}
868
dgozman9260b0a12015-03-16 13:45:20869void RenderWidget::OnEnableDeviceEmulation(
870 const blink::WebDeviceEmulationParams& params) {
871 if (!screen_metrics_emulator_)
872 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
873 else
874 screen_metrics_emulator_->ChangeEmulationParams(params);
875}
876
877void RenderWidget::OnDisableDeviceEmulation() {
878 screen_metrics_emulator_.reset();
879}
880
noel89949e62014-09-30 01:12:41881void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
882 SetDeviceColorProfile(color_profile);
883}
884
[email protected]b5913d72012-02-07 22:26:54885void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01886 if (resizer_rect_ == resizer_rect)
887 return;
888 resizer_rect_ = resizer_rect;
889 if (webwidget_)
890 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54891}
892
initial.commit09911bf2008-07-26 23:55:29893void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31894 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29895 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03896 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59897 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
898 WasHidden());
initial.commit09911bf2008-07-26 23:55:29899}
900
[email protected]3399dd822014-08-09 11:14:24901void RenderWidget::OnWasShown(bool needs_repainting,
902 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41903 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29904 // During shutdown we can just ignore this message.
905 if (!webwidget_)
906 return;
907
908 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03909 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59910 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
911 WasShown());
initial.commit09911bf2008-07-26 23:55:29912
[email protected]8a23afb32014-04-30 22:40:23913 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29914 return;
initial.commit09911bf2008-07-26 23:55:29915
916 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24917 if (compositor_) {
918 ui::LatencyInfo swap_latency_info(latency_info);
919 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
920 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05921 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24922 }
jdduke491a3f0c2015-06-15 23:30:26923 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29924}
925
[email protected]53d3f302009-12-21 04:42:05926void RenderWidget::OnRequestMoveAck() {
927 DCHECK(pending_window_rect_count_);
928 pending_window_rect_count_--;
929}
930
[email protected]ed7defa2013-03-12 21:29:59931GURL RenderWidget::GetURLForGraphicsContext3D() {
932 return GURL();
[email protected]65225772011-05-12 21:10:24933}
934
[email protected]ebc0e1df2013-08-01 02:46:22935scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03936 // For widgets that are never visible, we don't start the compositor, so we
937 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39938 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:19939
avi83883c82014-12-23 00:08:49940 const base::CommandLine& command_line =
941 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33942 bool use_software = fallback;
943 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
944 use_software = true;
945
penghuang28a5fa22015-12-02 17:58:19946#if defined(MOJO_SHELL_CLIENT)
947 if (MojoShellConnection::Get() && !use_software) {
948 RenderWidgetMusConnection* connection =
949 RenderWidgetMusConnection::GetOrCreate(routing_id());
950 return connection->CreateOutputSurface();
951 }
952#endif
953
[email protected]0634cdd42013-08-16 00:46:09954 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17955 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:33956 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09957 context_provider = ContextProviderCommandBuffer::Create(
jbauman5e420d32015-08-05 09:33:01958 CreateGraphicsContext3D(true), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:33959 if (!context_provider.get()) {
960 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34961 return nullptr;
[email protected]e09994a2014-03-26 19:59:33962 }
revemand180dfc32015-09-24 00:19:43963 worker_context_provider =
964 RenderThreadImpl::current()->SharedWorkerContextProvider();
965 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:17966 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34967 return nullptr;
vmiura78b69282015-02-14 00:01:17968 }
boliu853d46052015-10-13 20:20:06969
970#if defined(OS_ANDROID)
971 if (SynchronousCompositorFactory* factory =
972 SynchronousCompositorFactory::GetInstance()) {
973 return factory->CreateOutputSurface(
974 routing_id(), frame_swap_message_queue_, context_provider,
975 worker_context_provider);
boliubee541f42015-11-05 00:52:53976 } else if (RenderThreadImpl::current()->sync_compositor_message_filter()) {
977 return make_scoped_ptr(new SynchronousCompositorOutputSurface(
978 context_provider, worker_context_provider, routing_id(),
979 content::RenderThreadImpl::current()
980 ->sync_compositor_message_filter(),
981 frame_swap_message_queue_));
boliu853d46052015-10-13 20:20:06982 }
983#endif
[email protected]0634cdd42013-08-16 00:46:09984 }
[email protected]ebc0e1df2013-08-01 02:46:22985
avi1023d012015-12-25 02:39:14986 uint32_t output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:34987 // Composite-to-mailbox is currently used for layout tests in order to cause
988 // them to draw inside in the renderer to do the readback there. This should
989 // no longer be the case when crbug.com/311404 is fixed.
990 if (!RenderThreadImpl::current() ||
991 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:53992 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
piman8944e1c2015-09-22 21:10:34993 return make_scoped_ptr(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:17994 routing_id(), output_surface_id, context_provider,
995 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09996 }
piman8944e1c2015-09-22 21:10:34997
[email protected]0634cdd42013-08-16 00:46:09998 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:09999 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121000 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091001
piman8944e1c2015-09-22 21:10:341002 return make_scoped_ptr(new CompositorOutputSurface(
caseqff9c74c2015-02-10 14:56:291003 routing_id(), output_surface_id, nullptr, nullptr,
dcheng07945f632015-12-26 07:59:321004 std::move(software_device), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221005 }
[email protected]ed7defa2013-03-12 21:29:591006
piman8944e1c2015-09-22 21:10:341007 return make_scoped_ptr(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171008 routing_id(), output_surface_id, context_provider,
piman8944e1c2015-09-22 21:10:341009 worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:281010}
1011
[email protected]4d7e46a2013-11-08 05:33:401012void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241013 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241014 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:261015 ScheduleComposite();
[email protected]65225772011-05-12 21:10:241016}
1017
[email protected]4d7e46a2013-11-08 05:33:401018void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081019 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081020}
1021
[email protected]4d7e46a2013-11-08 05:33:401022void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241023 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161024
[email protected]404939f2012-06-01 04:06:181025 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161026 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291027}
1028
[email protected]180ef242013-11-07 06:50:461029void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
jdduke0cf1e662015-10-15 22:43:281030 const ui::LatencyInfo& latency_info) {
[email protected]c27dd4f2014-05-22 18:05:191031 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291032 return;
fsamuel72464894f2015-12-15 06:59:311033 input_handler_.HandleInputEvent(*input_event, latency_info);
initial.commit09911bf2008-07-26 23:55:291034}
1035
[email protected]34202de2013-05-06 23:36:221036void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1037 if (webwidget_)
1038 webwidget_->setCursorVisibilityState(is_visible);
1039}
1040
initial.commit09911bf2008-07-26 23:55:291041void RenderWidget::OnMouseCaptureLost() {
1042 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281043 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291044}
1045
1046void RenderWidget::OnSetFocus(bool enable) {
[email protected]9d166af2010-03-02 22:04:331047 if (webwidget_)
1048 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291049}
1050
fsamuel72464894f2015-12-15 06:59:311051///////////////////////////////////////////////////////////////////////////////
1052// RenderWidgetInputHandlerDelegate
1053
1054void RenderWidget::FocusChangeComplete() {}
1055
1056bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
1057 return true;
1058}
1059
1060void RenderWidget::ObserveWheelEventAndResult(
1061 const blink::WebMouseWheelEvent& wheel_event,
1062 const gfx::Vector2dF& wheel_unused_delta,
1063 bool event_processed) {
1064 if (!compositor_deps_->IsElasticOverscrollEnabled())
1065 return;
1066
1067 cc::InputHandlerScrollResult scroll_result;
1068 scroll_result.did_scroll = event_processed;
1069 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
1070 scroll_result.unused_scroll_delta = wheel_unused_delta;
1071
1072 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1073 InputHandlerManager* input_handler_manager =
1074 render_thread ? render_thread->input_handler_manager() : NULL;
1075 if (input_handler_manager) {
1076 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
1077 routing_id_, wheel_event, scroll_result);
jddukefffb67c2015-01-07 22:32:291078 }
fsamuel72464894f2015-12-15 06:59:311079}
1080
1081void RenderWidget::OnDidHandleKeyEvent() {}
1082
1083void RenderWidget::OnDidOverscroll(const DidOverscrollParams& params) {
1084 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1085}
1086
1087void RenderWidget::OnInputEventAck(scoped_ptr<InputEventAck> input_event_ack) {
1088 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
1089}
1090
1091void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1092 ChangeSource change_source) {
1093 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1094 if (ime_event_guard_) {
1095 // show_ime should still be effective even if it was set inside the IME
1096 // event guard.
1097 if (show_ime == ShowIme::IF_NEEDED) {
1098 ime_event_guard_->set_show_ime(true);
1099 }
1100 return;
1101 }
1102
1103 ui::TextInputType new_type = GetTextInputType();
1104 if (IsDateTimeInput(new_type))
1105 return; // Not considered as a text input field in WebKit/Chromium.
1106
1107 blink::WebTextInputInfo new_info;
1108 if (webwidget_)
1109 new_info = webwidget_->textInputInfo();
1110 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1111
1112 bool new_can_compose_inline = CanComposeInline();
1113
1114 // Only sends text input params if they are changed or if the ime should be
1115 // shown.
1116 if (show_ime == ShowIme::IF_NEEDED ||
1117 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1118 text_input_info_ != new_info ||
1119 can_compose_inline_ != new_can_compose_inline)
1120#if defined(OS_ANDROID)
1121 || text_field_is_dirty_
1122#endif
1123 ) {
1124 ViewHostMsg_TextInputState_Params params;
1125 params.type = new_type;
1126 params.mode = new_mode;
1127 params.flags = new_info.flags;
1128 params.value = new_info.value.utf8();
1129 params.selection_start = new_info.selectionStart;
1130 params.selection_end = new_info.selectionEnd;
1131 params.composition_start = new_info.compositionStart;
1132 params.composition_end = new_info.compositionEnd;
1133 params.can_compose_inline = new_can_compose_inline;
1134 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
1135#if defined(USE_AURA)
1136 params.is_non_ime_change = true;
1137#endif
1138#if defined(OS_ANDROID)
1139 params.is_non_ime_change =
1140 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
1141 if (params.is_non_ime_change)
1142 OnImeEventSentForAck(new_info);
1143 text_field_is_dirty_ = false;
1144#endif
1145 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1146
1147 text_input_info_ = new_info;
1148 text_input_type_ = new_type;
1149 text_input_mode_ = new_mode;
1150 can_compose_inline_ = new_can_compose_inline;
1151 text_input_flags_ = new_info.flags;
1152 }
1153}
1154
1155bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
1156 return false;
1157}
1158
1159bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
1160 return false;
[email protected]fd847792013-10-24 17:12:351161}
1162
initial.commit09911bf2008-07-26 23:55:291163///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461164// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291165
[email protected]244ac1892011-12-02 17:04:471166void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima33ec97cd2015-12-14 19:40:241167 WebRect new_size_in_window(0, 0, new_size.width, new_size.height);
1168 convertViewportToWindow(&new_size_in_window);
1169 if (size_.width() != new_size_in_window.width ||
1170 size_.height() != new_size_in_window.height) {
1171 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
[email protected]20fbfc22013-05-08 20:50:581172
[email protected]5b45ad42013-10-25 00:42:041173 if (resizing_mode_selector_->is_synchronous_mode()) {
oshima33ec97cd2015-12-14 19:40:241174 gfx::Rect new_pos(rootWindowRect().x,
1175 rootWindowRect().y,
1176 size_.width(),
1177 size_.height());
[email protected]eac2b362013-05-22 07:01:451178 view_screen_rect_ = new_pos;
1179 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031180 }
[email protected]20fbfc22013-05-08 20:50:581181
[email protected]eac2b362013-05-22 07:01:451182 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581183
[email protected]5b45ad42013-10-25 00:42:041184 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581185 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091186 }
[email protected]244ac1892011-12-02 17:04:471187}
1188
[email protected]3a1c8a8032013-03-18 22:35:321189void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401190 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051191 if (compositor_)
oshima750cb4342015-10-31 00:59:011192 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051193}
1194
[email protected]e195e582013-03-08 01:32:591195void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221196 DCHECK(!host_closing_);
1197
danakj6e3bf8012014-12-16 18:27:531198 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
oshima750cb4342015-10-31 00:59:011199 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331200 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391201 // For background pages and certain tests, we don't want to trigger
1202 // OutputSurface creation.
1203 if (compositor_never_visible_ || !RenderThreadImpl::current())
1204 compositor_->SetNeverVisible();
1205
pimanc4af3072015-10-02 03:45:591206 StartCompositor();
[email protected]e195e582013-03-08 01:32:591207}
1208
ennef3c58142014-12-09 21:44:381209void RenderWidget::WillCloseLayerTreeView() {
1210 if (host_closing_)
1211 return;
1212
1213 // Prevent new compositors or output surfaces from being created.
1214 host_closing_ = true;
1215
[email protected]aeeedad2014-08-22 18:16:221216 // Always send this notification to prevent new layer tree views from
1217 // being created, even if one hasn't been created yet.
1218 if (webwidget_)
1219 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221220}
1221
[email protected]180ef242013-11-07 06:50:461222blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281223 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061224}
1225
dglazkovf0e1d6d2015-10-10 02:13:481226void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1227 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1228 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1229 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1230 }
dglazkov79c426102015-08-31 21:22:431231
dglazkovf0e1d6d2015-10-10 02:13:481232 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1233 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431234}
1235
jdduke491a3f0c2015-06-15 23:30:261236void RenderWidget::WillBeginCompositorFrame() {
[email protected]9cd43a62012-03-26 08:03:561237 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371238
shuchen913f8b622015-07-31 13:22:431239 // The UpdateTextInputState can result in further layout and possibly
[email protected]abe8b3a2012-03-28 21:19:371240 // enable GPU acceleration so they need to be called before any painting
1241 // is done.
fsamuel72464894f2015-12-15 06:59:311242 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]abe8b3a2012-03-28 21:19:371243 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561244}
1245
[email protected]6fceb912013-02-15 06:24:151246void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441247 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1248 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271249 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161250 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171251#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271252 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1253 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171254#endif // defined(VIDEO_HOLE)
fsamuel72464894f2015-12-15 06:59:311255 input_handler_.FlushPendingInputEventAck();
jdduke491a3f0c2015-06-15 23:30:261256}
1257
1258void RenderWidget::DidCommitAndDrawCompositorFrame() {
1259 // NOTE: Tests may break if this event is renamed or moved. See
1260 // tab_capture_performancetest.cc.
1261 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
1262 // Notify subclasses that we initiated the paint operation.
1263 DidInitiatePaint();
1264}
1265
1266void RenderWidget::DidCompleteSwapBuffers() {
1267 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
1268
1269 // Notify subclasses threaded composited rendering was flushed to the screen.
1270 DidFlushPaint();
1271
1272 if (!next_paint_flags_ &&
1273 !need_update_rect_for_auto_resize_ &&
1274 !plugin_window_moves_.size()) {
1275 return;
1276 }
1277
1278 ViewHostMsg_UpdateRect_Params params;
1279 params.view_size = size_;
1280 params.plugin_window_moves.swap(plugin_window_moves_);
1281 params.flags = next_paint_flags_;
1282
1283 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1284 next_paint_flags_ = 0;
1285 need_update_rect_for_auto_resize_ = false;
1286}
1287
1288void RenderWidget::ScheduleComposite() {
1289 if (compositor_ &&
1290 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1291 compositor_->setNeedsAnimate();
1292 }
1293}
1294
1295void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1296 if (compositor_) {
1297 // Regardless of whether threaded compositing is enabled, always
1298 // use this mechanism to force the compositor to redraw. However,
1299 // the invalidation code path below is still needed for the
1300 // non-threaded case.
1301 compositor_->SetNeedsForcedRedraw();
1302 }
1303 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151304}
1305
[email protected]586871b2014-07-22 17:05:111306// static
1307scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1308 IPC::Message* msg,
1309 MessageDeliveryPolicy policy,
1310 FrameSwapMessageQueue* frame_swap_message_queue,
1311 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111312 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111313 bool first_message_for_frame = false;
1314 frame_swap_message_queue->QueueMessageForFrame(policy,
1315 source_frame_number,
1316 make_scoped_ptr(msg),
1317 &first_message_for_frame);
1318 if (first_message_for_frame) {
1319 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1320 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061321 return promise;
[email protected]586871b2014-07-22 17:05:111322 }
dcheng4b6b5ff2014-10-16 00:42:061323 return nullptr;
[email protected]586871b2014-07-22 17:05:111324}
1325
1326void RenderWidget::QueueMessage(IPC::Message* msg,
1327 MessageDeliveryPolicy policy) {
1328 // RenderThreadImpl::current() is NULL in some tests.
1329 if (!compositor_ || !RenderThreadImpl::current()) {
1330 Send(msg);
1331 return;
1332 }
1333
1334 scoped_ptr<cc::SwapPromise> swap_promise =
1335 QueueMessageImpl(msg,
1336 policy,
dcheng58867a92014-08-26 02:50:221337 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111338 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111339 compositor_->GetSourceFrameNumber());
1340
1341 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321342 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351343 // Request a commit. This might either A) request a commit ahead of time
1344 // or B) request a commit which is not needed because there are not
1345 // pending updates. If B) then the commit will be skipped and the swap
1346 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1347 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1348 // can_cancel_commit is not unset.
1349 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111350 }
1351}
1352
[email protected]4873c7d2009-07-16 06:36:281353void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301354 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521355 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181356 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291357 // Only send a SetCursor message if we need to make a change.
1358 if (!current_cursor_.IsEqual(cursor)) {
1359 current_cursor_ = cursor;
1360 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1361 }
1362}
1363
1364// We are supposed to get a single call to Show for a newly created RenderWidget
1365// that was created via RenderWidget::CreateWebView. So, we wait until this
1366// point to dispatch the ShowWidget message.
1367//
1368// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281369// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291370//
[email protected]4873c7d2009-07-16 06:36:281371void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291372 DCHECK(!did_show_) << "received extraneous Show call";
1373 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1374 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1375
[email protected]8de12d942010-11-17 20:42:441376 if (did_show_)
1377 return;
1378
1379 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561380 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441381 // that's okay. It'll be ignored if as_popup is false, or the browser
1382 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561383 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1384 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291385}
1386
[email protected]4873c7d2009-07-16 06:36:281387void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291388}
1389
[email protected]2533ce12009-05-09 00:02:241390void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381391 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241392 Send(new ViewHostMsg_Close(routing_id_));
1393}
1394
dgozmancf9039cd2015-04-06 12:01:311395void RenderWidget::NotifyOnClose() {
1396 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1397}
1398
[email protected]4873c7d2009-07-16 06:36:281399void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081400 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321401 if (is_swapped_out_) {
1402 // This widget is currently swapped out, and the active widget is in a
1403 // different process. Have the browser route the close request to the
1404 // active widget instead, so that the correct unload handlers are run.
1405 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1406 return;
1407 }
1408
initial.commit09911bf2008-07-26 23:55:291409 // If a page calls window.close() twice, we'll end up here twice, but that's
1410 // OK. It is safe to send multiple Close messages.
1411
[email protected]2533ce12009-05-09 00:02:241412 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1413 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1414 // could be closed before the JS finishes executing. So instead, post a
1415 // message back to the message loop, which won't run until the JS is
1416 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081417 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211418 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291419}
1420
[email protected]9017d7852013-11-21 17:47:351421void RenderWidget::QueueSyntheticGesture(
1422 scoped_ptr<SyntheticGestureParams> gesture_params,
1423 const SyntheticGestureCompletionCallback& callback) {
1424 DCHECK(!callback.is_null());
1425
1426 pending_synthetic_gesture_callbacks_.push(callback);
1427
1428 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321429 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351430
1431 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1432}
1433
initial.commit09911bf2008-07-26 23:55:291434void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031435 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381436 WillCloseLayerTreeView();
1437 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291438 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281439 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291440 webwidget_ = NULL;
1441 }
1442}
1443
[email protected]4873c7d2009-07-16 06:36:281444WebRect RenderWidget::windowRect() {
1445 if (pending_window_rect_count_)
1446 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241447
[email protected]80ad8622012-11-07 16:33:031448 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291449}
1450
[email protected]180ef242013-11-07 06:50:461451void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301452 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541453 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301454}
1455
oshima33ec97cd2015-12-14 19:40:241456void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1457 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511458 if (popup_origin_scale_for_emulation_) {
1459 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561460 window_rect.x = popup_screen_origin_for_emulation_.x() +
1461 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1462 window_rect.y = popup_screen_origin_for_emulation_.y() +
1463 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511464 }
1465
[email protected]5b45ad42013-10-25 00:42:041466 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201467 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561468 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1469 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031470 } else {
bokanc007c3a2015-02-03 07:15:561471 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031472 }
initial.commit09911bf2008-07-26 23:55:291473 } else {
bokanc007c3a2015-02-03 07:15:561474 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291475 }
1476}
1477
[email protected]2533ce12009-05-09 00:02:241478void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1479 pending_window_rect_ = rect;
1480 pending_window_rect_count_++;
1481}
1482
[email protected]4873c7d2009-07-16 06:36:281483WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241484 if (pending_window_rect_count_) {
1485 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1486 // the RootWindowRect is probably going to return wrong results since the
1487 // browser may not have processed the Move yet. There isn't really anything
1488 // good to do in this case, and it shouldn't happen - since this size is
1489 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281490 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241491 }
1492
[email protected]80ad8622012-11-07 16:33:031493 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371494}
1495
[email protected]4873c7d2009-07-16 06:36:281496WebRect RenderWidget::windowResizerRect() {
1497 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191498}
1499
[email protected]fa7b1dc2010-06-23 17:53:041500void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261501 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041502 const std::vector<WebCompositionUnderline>& underlines,
1503 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131504 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281505 return;
[email protected]66fca5bc2013-05-23 06:58:291506 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361507 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041508 text, WebVector<WebCompositionUnderline>(underlines),
1509 selection_start, selection_end)) {
1510 // If we failed to set the composition text, then we need to let the browser
1511 // process to cancel the input method's ongoing composition session, to make
1512 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221513 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261514 }
[email protected]88dbe32f2013-06-20 23:31:361515 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041516}
1517
[email protected]fcf75d42013-12-03 20:11:261518void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511519 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021520 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131521 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041522 return;
[email protected]66fca5bc2013-05-23 06:58:291523 ImeEventGuard guard(this);
fsamuel72464894f2015-12-15 06:59:311524 input_handler_.set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021525 if (text.length())
1526 webwidget_->confirmComposition(text);
1527 else if (keep_selection)
1528 webwidget_->confirmComposition(WebWidget::KeepSelection);
1529 else
1530 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuel72464894f2015-12-15 06:59:311531 input_handler_.set_handling_input_event(false);
[email protected]88dbe32f2013-06-20 23:31:361532 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291533}
1534
oshimad5279032015-12-16 18:22:331535void RenderWidget::OnDeviceScaleFactorChanged() {
1536 if (!compositor_)
1537 return;
1538
1539 if (IsUseZoomForDSFEnabled())
1540 compositor_->SetPaintedDeviceScaleFactor(device_scale_factor_);
1541 else
1542 compositor_->setDeviceScaleFactor(device_scale_factor_);
1543}
1544
[email protected]0bc1f572013-04-17 01:46:311545void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121546 // During shutdown we can just ignore this message.
1547 if (!webwidget_)
1548 return;
1549
[email protected]0bc1f572013-04-17 01:46:311550 // Even if the browser provides an empty damage rect, it's still expecting to
1551 // receive a repaint ack so just damage the entire widget bounds.
1552 if (size_to_paint.IsEmpty()) {
1553 size_to_paint = size_;
1554 }
1555
[email protected]ec7dc112008-08-06 05:30:121556 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051557 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311558 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121559}
1560
[email protected]79fa22e2013-08-23 15:18:121561void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351562 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1563
1564 pending_synthetic_gesture_callbacks_.front().Run();
1565 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271566}
1567
[email protected]4873c7d2009-07-16 06:36:281568void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111569 if (!webwidget_)
1570 return;
[email protected]4873c7d2009-07-16 06:36:281571 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111572}
1573
[email protected]80ad8622012-11-07 16:33:031574void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1575 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511576 if (screen_metrics_emulator_) {
1577 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1578 view_screen_rect, window_screen_rect);
1579 } else {
1580 view_screen_rect_ = view_screen_rect;
1581 window_screen_rect_ = window_screen_rect;
1582 }
[email protected]80ad8622012-11-07 16:33:031583 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1584}
1585
kenrbb4e2a3b2015-05-14 15:05:051586void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1587 if (compositor_)
1588 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1589}
1590
dtrainor5ef644e2015-11-19 00:12:471591void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1592 if (compositor_)
1593 compositor_->OnHandleCompositorProto(proto);
1594}
1595
[email protected]adb362312014-06-28 06:04:241596void RenderWidget::showImeIfNeeded() {
1597 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131598}
1599
fsamuel72464894f2015-12-15 06:59:311600ui::TextInputType RenderWidget::GetTextInputType() {
1601 if (webwidget_)
1602 return WebKitToUiTextInputType(webwidget_->textInputType());
1603 return ui::TEXT_INPUT_TYPE_NONE;
1604}
1605
1606void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
1607#if defined(OS_ANDROID)
1608// TODO(yukawa): Start sending character bounds when the browser side
1609// implementation becomes ready (crbug.com/424866).
1610#else
1611 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1612 gfx::Range range = gfx::Range();
1613 if (should_update_range) {
1614 GetCompositionRange(&range);
1615 } else {
1616 range = composition_range_;
1617 }
1618 std::vector<gfx::Rect> character_bounds;
1619 GetCompositionCharacterBounds(&character_bounds);
1620
1621 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1622 return;
1623 composition_character_bounds_ = character_bounds;
1624 composition_range_ = range;
1625 Send(new InputHostMsg_ImeCompositionRangeChanged(
1626 routing_id(), composition_range_, composition_character_bounds_));
1627#endif
1628}
1629
oshimaf866dab2015-12-05 00:41:541630void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1631 if (IsUseZoomForDSFEnabled()) {
1632 float reverse = 1 / device_scale_factor_;
oshimad5279032015-12-16 18:22:331633 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541634 // anchor element can be placed at half pixel.
1635 gfx::Rect window_rect =
1636 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1637 rect->x = window_rect.x();
1638 rect->y = window_rect.y();
1639 rect->width = window_rect.width();
1640 rect->height = window_rect.height();
1641 }
1642}
1643
[email protected]adb362312014-06-28 06:04:241644void RenderWidget::OnShowImeIfNeeded() {
1645#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311646 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241647#endif
rouslanf7ebd8832015-01-22 01:54:141648
1649// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1650// virtual keyboard.
1651#if !defined(OS_ANDROID)
1652 FocusChangeComplete();
1653#endif
[email protected]adb362312014-06-28 06:04:241654}
1655
1656#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371657void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1658 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131659}
1660
1661void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371662 DCHECK_GE(text_input_info_history_.size(), 1u);
1663 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511664}
[email protected]105dffb42013-02-20 03:46:211665#endif
1666
[email protected]0d1ebed12013-08-05 22:01:131667bool RenderWidget::ShouldHandleImeEvent() {
1668#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371669 if (!webwidget_)
1670 return false;
1671
1672 // We cannot handle IME events if there is any chance that the event we are
1673 // receiving here from the browser is based on the state that is different
1674 // from our current one as indicated by |text_input_info_|.
1675 // The states the browser might be in are:
1676 // text_input_info_history_[0] - current state ack'd by browser
1677 // text_input_info_history_[1...N] - pending state changes
1678 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1679 if (text_input_info_history_[i] != text_input_info_)
1680 return false;
1681 }
1682 return true;
[email protected]0d1ebed12013-08-05 22:01:131683#else
1684 return !!webwidget_;
1685#endif
1686}
1687
[email protected]468ac582012-11-20 00:53:191688void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1689 if (device_scale_factor_ == device_scale_factor)
1690 return;
1691
1692 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331693
1694 OnDeviceScaleFactorChanged();
1695
jdduke491a3f0c2015-06-15 23:30:261696 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191697}
1698
[email protected]28ed6b32014-06-08 02:16:271699bool RenderWidget::SetDeviceColorProfile(
1700 const std::vector<char>& color_profile) {
1701 if (device_color_profile_ == color_profile)
1702 return false;
1703
1704 device_color_profile_ = color_profile;
1705 return true;
1706}
1707
noeldb4df152014-09-16 17:45:201708void RenderWidget::ResetDeviceColorProfileForTesting() {
1709 if (!device_color_profile_.empty())
1710 device_color_profile_.clear();
1711 device_color_profile_.push_back('0');
1712}
1713
[email protected]fcdc5642014-05-09 14:32:241714void RenderWidget::OnOrientationChange() {
1715}
1716
[email protected]ceb36f7d2012-10-31 18:33:241717gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521718 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241719 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521720}
1721
[email protected]bee16aab2009-08-26 15:55:031722void RenderWidget::SetHidden(bool hidden) {
1723 if (is_hidden_ == hidden)
1724 return;
1725
jdduke8fac9d102014-12-20 02:40:131726 // The status has changed. Tell the RenderThread about it and ensure
1727 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031728 is_hidden_ = hidden;
fsamuel72464894f2015-12-15 06:59:311729 input_handler_.FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131730
[email protected]bee16aab2009-08-26 15:55:031731 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001732 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031733 else
[email protected]b2db9272014-01-10 17:42:001734 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111735
1736 if (render_widget_scheduling_state_)
1737 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031738}
1739
[email protected]2b624c562011-10-27 22:58:261740void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261741 if (!webwidget_)
1742 return;
1743
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121744 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261745 webwidget_->didEnterFullScreen();
1746 } else {
1747 webwidget_->didExitFullScreen();
1748 }
[email protected]2b624c562011-10-27 22:58:261749}
1750
[email protected]674741932009-02-04 23:44:461751bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051752 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461753}
1754
[email protected]674741932009-02-04 23:44:461755void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051756 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461757}
1758
[email protected]674741932009-02-04 23:44:461759void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051760 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461761}
1762
changwanf2a707b2015-10-30 08:22:161763void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1764 if (!ime_event_guard_)
1765 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291766}
1767
changwanf2a707b2015-10-30 08:22:161768void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1769 if (ime_event_guard_ != guard) {
1770#if defined(OS_ANDROID)
1771 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1772 // (e.g. long press gesture), we want to treat it as not-from-IME event
1773 // so that AdapterInputConnection can make changes to its Editable model.
1774 // Therefore, we want to mark this text state update as 'from IME' only
1775 // when all the nested events are all originating from IME.
1776 ime_event_guard_->set_from_ime(
1777 ime_event_guard_->from_ime() && guard->from_ime());
1778#endif
1779 return;
1780 }
1781 ime_event_guard_ = nullptr;
1782
[email protected]66fca5bc2013-05-23 06:58:291783 // While handling an ime event, text input state and selection bounds updates
1784 // are ignored. These must explicitly be updated once finished handling the
1785 // ime event.
1786 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471787#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161788 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311789 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1790 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471791#endif
[email protected]66fca5bc2013-05-23 06:58:291792}
1793
[email protected]7c8873e2013-02-05 08:03:011794void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1795 WebRect focus_webrect;
1796 WebRect anchor_webrect;
1797 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241798 convertViewportToWindow(&focus_webrect);
1799 convertViewportToWindow(&anchor_webrect);
1800 *focus = focus_webrect;
1801 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321802}
1803
[email protected]e99ef6f2011-10-16 01:13:001804void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081805 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001806 if (!webwidget_)
1807 return;
changwanf2a707b2015-10-30 08:22:161808 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291809 return;
[email protected]e99ef6f2011-10-16 01:13:001810
mohsenb0eeba72015-08-09 06:20:081811#if defined(USE_AURA)
1812 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1813 // Aura beucause composited selection updates are not working for webview tags
1814 // which regresses IME inside webview. Remove this when composited selection
1815 // updates are fixed for webviews. See, http://crbug.com/510568.
1816 bool send_ipc = true;
1817#else
jddukeacf809e2014-09-23 20:38:381818 // With composited selection updates, the selection bounds will be reported
1819 // directly by the compositor, in which case explicit IPC selection
1820 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081821 bool send_ipc =
1822 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1823#endif
1824 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381825 ViewHostMsg_SelectionBounds_Params params;
1826 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1827 if (selection_anchor_rect_ != params.anchor_rect ||
1828 selection_focus_rect_ != params.focus_rect) {
1829 selection_anchor_rect_ = params.anchor_rect;
1830 selection_focus_rect_ = params.focus_rect;
1831 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1832 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1833 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1834 }
[email protected]58b48a0d2012-06-13 07:01:351835 }
jddukeacf809e2014-09-23 20:38:381836
[email protected]88dbe32f2013-06-20 23:31:361837 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001838}
1839
dtrainor5ef644e2015-11-19 00:12:471840void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
1841 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
1842}
1843
[email protected]180ef242013-11-07 06:50:461844// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:171845#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
1846 static_assert(int(blink::WebTextInputType##a) \
1847 == int(ui::TEXT_INPUT_TYPE_##b), \
1848 "mismatching enums: " #a)
1849
1850STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
1851STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
1852STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
1853STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
1854STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
1855STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
1856STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
1857STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
1858STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
1859STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
1860STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
1861STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
1862STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
1863STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
1864STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
1865STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
1866STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451867
[email protected]5b739cb2012-08-21 20:35:211868ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461869 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211870 // Check the type is in the range representable by ui::TextInputType.
1871 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461872 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211873 return static_cast<ui::TextInputType>(type);
1874}
1875
[email protected]58b48a0d2012-06-13 07:01:351876void RenderWidget::GetCompositionCharacterBounds(
1877 std::vector<gfx::Rect>* bounds) {
1878 DCHECK(bounds);
1879 bounds->clear();
1880}
1881
[email protected]db4fc1e2013-09-06 20:01:511882void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:361883 size_t location, length;
1884 if (webwidget_->compositionRange(&location, &length)) {
1885 range->set_start(location);
1886 range->set_end(location + length);
1887 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1888 range->set_start(location);
1889 range->set_end(location + length);
1890 } else {
[email protected]db4fc1e2013-09-06 20:01:511891 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:361892 }
1893}
1894
[email protected]501ea13d2013-07-09 17:03:291895bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511896 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291897 const std::vector<gfx::Rect>& bounds) {
1898 if (composition_range_ != range)
1899 return true;
1900 if (bounds.size() != composition_character_bounds_.size())
1901 return true;
1902 for (size_t i = 0; i < bounds.size(); ++i) {
1903 if (bounds[i] != composition_character_bounds_[i])
1904 return true;
1905 }
1906 return false;
1907}
[email protected]501ea13d2013-07-09 17:03:291908
[email protected]ad26ef42011-06-17 07:59:451909bool RenderWidget::CanComposeInline() {
1910 return true;
[email protected]56ea1a62011-05-30 07:05:571911}
1912
[email protected]4873c7d2009-07-16 06:36:281913WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041914 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281915}
1916
[email protected]fa7b1dc2010-06-23 17:53:041917void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021918 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041919 // If the last text input type is not None, then we should finish any
1920 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451921 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041922 // If a composition text exists, then we need to let the browser process
1923 // to cancel the input method's ongoing composition session.
1924 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:221925 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041926 }
[email protected]d4cff272011-05-02 15:46:011927
[email protected]88dbe32f2013-06-20 23:31:361928 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041929}
1930
donnda070f3c2015-01-16 19:54:111931#if defined(OS_ANDROID)
1932void RenderWidget::showUnhandledTapUIIfNeeded(
1933 const WebPoint& tapped_position,
1934 const WebNode& tapped_node,
1935 bool page_changed) {
fsamuel72464894f2015-12-15 06:59:311936 DCHECK(input_handler_.handling_input_event());
donnda070f3c2015-01-16 19:54:111937 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371938 !tapped_node.isContentEditable() &&
1939 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111940 if (should_trigger) {
1941 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1942 tapped_position.x, tapped_position.y));
1943 }
1944}
1945#endif
1946
[email protected]c68c3e4e2013-01-24 00:36:561947void RenderWidget::didHandleGestureEvent(
1948 const WebGestureEvent& event,
1949 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021950#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561951 if (event_cancelled)
1952 return;
[email protected]07c70d22014-08-21 08:33:461953 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:311954 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461955 } else if (event.type == WebInputEvent::GestureLongPress) {
1956 DCHECK(webwidget_);
1957 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:311958 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461959 else
fsamuel72464894f2015-12-15 06:59:311960 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:561961 }
1962#endif
1963}
1964
sataya.m582c9ce2015-06-09 08:03:421965void RenderWidget::didOverscroll(
1966 const blink::WebFloatSize& unusedDelta,
1967 const blink::WebFloatSize& accumulatedRootOverScroll,
1968 const blink::WebFloatPoint& position,
1969 const blink::WebFloatSize& velocity) {
fsamuel72464894f2015-12-15 06:59:311970 input_handler_.DidOverscrollFromBlink(unusedDelta, accumulatedRootOverScroll,
1971 position, velocity);
sataya.m582c9ce2015-06-09 08:03:421972}
1973
[email protected]7912e822014-04-16 02:37:031974void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:391975 if (!is_hidden())
1976 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:031977}
1978
[email protected]29e2fb42013-07-19 01:13:471979void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291980 size_t i = 0;
1981 for (; i < plugin_window_moves_.size(); ++i) {
1982 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581983 if (move.rects_valid) {
1984 plugin_window_moves_[i] = move;
1985 } else {
1986 plugin_window_moves_[i].visible = move.visible;
1987 }
initial.commit09911bf2008-07-26 23:55:291988 break;
1989 }
1990 }
1991
1992 if (i == plugin_window_moves_.size())
1993 plugin_window_moves_.push_back(move);
1994}
[email protected]268654772009-08-06 23:02:041995
1996void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1997 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1998 i != plugin_window_moves_.end(); ++i) {
1999 if (i->window == window) {
2000 plugin_window_moves_.erase(i);
2001 break;
2002 }
2003 }
2004}
[email protected]67bfb83f2011-09-22 03:36:372005
[email protected]63b465922012-09-06 02:04:522006
[email protected]24ed0432013-04-24 07:50:312007RenderWidgetCompositor* RenderWidget::compositor() const {
2008 return compositor_.get();
2009}
2010
fsamuel72464894f2015-12-15 06:59:312011void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
2012 input_handler_.set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372013}
[email protected]c3d45532011-10-07 19:20:402014
fsamuel72464894f2015-12-15 06:59:312015bool RenderWidget::SendAckForMouseMoveFromDebugger() {
2016 return input_handler_.SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242017}
2018
fsamuel72464894f2015-12-15 06:59:312019void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
2020 input_handler_.IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312021}
2022
[email protected]ce6689f2013-03-29 12:52:552023void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112024 if (render_widget_scheduling_state_)
2025 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552026 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2027}
2028
mostynbe29b6882015-01-13 09:59:172029// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2030#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2031 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2032 "mismatching enums: " #a)
2033
[email protected]5d0bbdfa92013-12-10 00:35:512034void RenderWidget::setTouchAction(
2035 blink::WebTouchAction web_touch_action) {
2036
2037 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2038 // when blink is emulating touch with mouse).
fsamuel72464894f2015-12-15 06:59:312039 if (input_handler_.handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512040 return;
2041
dtapuskaa98ac8d72015-05-08 19:29:092042 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172043 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092044 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2045 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172046 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092047 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2048 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172049 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
rbyersa8b478d2015-10-30 15:49:102050 STATIC_ASSERT_WTI_ENUM_MATCH(Pan, PAN);
mostynbe29b6882015-01-13 09:59:172051 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
rbyersa8b478d2015-10-30 15:49:102052 STATIC_ASSERT_WTI_ENUM_MATCH(Manipulation, MANIPULATION);
2053 STATIC_ASSERT_WTI_ENUM_MATCH(DoubleTapZoom, DOUBLE_TAP_ZOOM);
2054 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
[email protected]a18f67a2013-12-20 19:44:362055
2056 content::TouchAction content_touch_action =
2057 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512058 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2059}
2060
[email protected]90f24152014-04-09 12:41:362061void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2062#if defined(OS_ANDROID)
2063 text_field_is_dirty_ = true;
2064#endif
2065}
2066
[email protected]0634cdd42013-08-16 00:46:092067scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
jbauman5e420d32015-08-05 09:33:012068RenderWidget::CreateGraphicsContext3D(bool compositor) {
[email protected]ed7defa2013-03-12 21:29:592069 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092070 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492071 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222072 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092073 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292074 if (!RenderThreadImpl::current())
2075 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402076 CauseForGpuLaunch cause =
2077 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292078 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402079 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222080 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292081 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592082
[email protected]828a3932014-04-02 14:43:132083 // Explicitly disable antialiasing for the compositor. As of the time of
2084 // this writing, the only platform that supported antialiasing for the
2085 // compositor was Mac OS X, because the on-screen OpenGL context creation
2086 // code paths on Windows and Linux didn't yet have multisampling support.
2087 // Mac OS X essentially always behaves as though it's rendering offscreen.
2088 // Multisampling has a heavy cost especially on devices with relatively low
2089 // fill rate like most notebooks, and the Mac implementation would need to
2090 // be optimized to resolve directly into the IOSurface shared between the
2091 // GPU and browser processes. For these reasons and to avoid platform
2092 // disparities we explicitly disable antialiasing.
2093 blink::WebGraphicsContext3D::Attributes attributes;
2094 attributes.antialias = false;
2095 attributes.shareResources = true;
2096 attributes.noAutomaticFlushes = true;
2097 attributes.depth = false;
2098 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132099 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292100 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012101#if defined(OS_ANDROID)
boliu853d46052015-10-13 20:20:062102 bool using_synchronous_compositing =
boliubee541f42015-11-05 00:52:532103 SynchronousCompositorFactory::GetInstance() ||
2104 base::CommandLine::ForCurrentProcess()->HasSwitch(
2105 switches::kIPCSyncCompositing);
[email protected]b6eb8e332013-09-10 00:51:012106 // If we raster too fast we become upload bound, and pending
2107 // uploads consume memory. For maximum upload throughput, we would
2108 // want to allow for upload_throughput * pipeline_time of pending
2109 // uploads, after which we are just wasting memory. Since we don't
2110 // know our upload throughput yet, this just caps our memory usage.
boliu853d46052015-10-13 20:20:062111 // Synchronous compositor uses half because synchronous compositor
2112 // pipeline is only one frame deep. But twice of half for low end
2113 // because 16bit texture is not supported.
2114 size_t divider = using_synchronous_compositing ? 2 : 1;
[email protected]35b4f0c2014-06-26 16:55:272115 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032116 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012117 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032118 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012119 // Deadline to draw a frame to achieve 60 frames per second.
2120 const size_t kMillisecondsPerFrame = 16;
2121 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032122 size_t max_transfer_buffer_usage_mb =
2123 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2124 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012125 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2126 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292127 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032128 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012129#endif
jbauman00ca2dc2015-08-10 23:21:152130 if (compositor) {
jbauman5e420d32015-08-05 09:33:012131 limits.command_buffer_size = 64 * 1024;
jbauman00ca2dc2015-08-10 23:21:152132 limits.start_transfer_buffer_size = 64 * 1024;
2133 limits.min_transfer_buffer_size = 64 * 1024;
2134 }
[email protected]96ab016c2013-10-23 00:50:292135
[email protected]96ab016c2013-10-23 00:50:292136 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
piman5d36dae2015-09-24 22:47:052137 new WebGraphicsContext3DCommandBufferImpl(
piman08f75532015-10-05 18:58:012138 0, GetURLForGraphicsContext3D(), gpu_channel_host.get(), attributes,
2139 lose_context_when_out_of_memory, limits, NULL));
dcheng07945f632015-12-26 07:59:322140 return context;
[email protected]ed7defa2013-03-12 21:29:592141}
2142
[email protected]e3244ed2014-06-20 20:04:272143void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2144 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162145}
2146
[email protected]e3244ed2014-06-20 20:04:272147void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2148 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162149}
2150
[email protected]de3c5d82014-05-28 22:12:592151void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2152 render_frames_.AddObserver(frame);
2153}
2154
2155void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2156 render_frames_.RemoveObserver(frame);
2157}
2158
[email protected]a017938b2014-05-27 21:17:172159#if defined(VIDEO_HOLE)
2160void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2161 video_hole_frames_.AddObserver(frame);
2162}
2163
2164void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2165 video_hole_frames_.RemoveObserver(frame);
2166}
2167#endif // defined(VIDEO_HOLE)
2168
[email protected]e9ff79c2012-10-19 21:31:262169} // namespace content