blob: f88c5fdaac32cf02da7d5aa660230a4a79096c7f [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]c27dd4f2014-05-22 18:05:197#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:218#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:009#include "base/command_line.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4012#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3013#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3814#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2115#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0016#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2717#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0118#include "base/trace_event/trace_event.h"
19#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4820#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5221#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3322#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3023#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0424#include "cc/trees/layer_tree_host.h"
alexclarke7819e2552015-06-03 11:17:2125#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]29e2fb42013-07-19 01:13:4726#include "content/child/npapi/webplugin.h"
[email protected]0634cdd42013-08-16 00:46:0927#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5928#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2929#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3530#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4431#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1532#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1533#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5034#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2935#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4236#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4037#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5138#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5939#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2940#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1141#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5942#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1143#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2844#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2945#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1346#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3247#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1648#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2749#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0550#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4451#include "content/renderer/render_thread_impl.h"
tfarina556a7232014-10-05 01:02:0952#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0453#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1854#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4855#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1856#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3057#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1158#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3059#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1860#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebSize.h"
62#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4363#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5964#include "third_party/WebKit/public/web/WebFrameWidget.h"
65#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1166#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3167#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3168#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
69#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3870#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5971#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4172#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1373#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5074#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0975#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3276#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4877#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2778#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4179#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4880
[email protected]eeb93112013-05-01 19:41:1081#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1582#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0783#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1084#endif
85
[email protected]661eb9d2009-02-03 02:11:4886#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4987#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5288#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4189#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4890#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4491
[email protected]2255a9332013-06-17 05:12:3192#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2993
[email protected]180ef242013-11-07 06:50:4694using blink::WebCompositionUnderline;
95using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4396using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4697using blink::WebGestureEvent;
98using blink::WebInputEvent;
99using blink::WebKeyboardEvent;
100using blink::WebMouseEvent;
101using blink::WebMouseWheelEvent;
102using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11103using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46104using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11105using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46106using blink::WebPopupType;
107using blink::WebRange;
108using blink::WebRect;
109using blink::WebScreenInfo;
110using blink::WebSize;
111using blink::WebTextDirection;
112using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25113using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46114using blink::WebVector;
115using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26116
[email protected]6a4d7f62013-01-07 21:32:13117namespace {
[email protected]b256eca2013-07-11 10:57:40118
119typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
120
121class TextInputModeMapSingleton {
122 public:
123 static TextInputModeMapSingleton* GetInstance() {
124 return Singleton<TextInputModeMapSingleton>::get();
125 }
[email protected]dd705d4d2013-11-27 08:14:41126 TextInputModeMapSingleton() {
127 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
128 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
129 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
130 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
131 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
132 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
133 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
134 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
135 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
136 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
137 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40138 }
[email protected]dd705d4d2013-11-27 08:14:41139 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40140 private:
[email protected]dd705d4d2013-11-27 08:14:41141 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40142
143 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
144
145 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
146};
147
[email protected]dd705d4d2013-11-27 08:14:41148ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40149 static TextInputModeMapSingleton* singleton =
150 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41151 TextInputModeMap::const_iterator it =
152 singleton->map().find(input_mode.utf8());
153 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40154 return ui::TEXT_INPUT_MODE_DEFAULT;
155 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13156}
[email protected]b256eca2013-07-11 10:57:40157
[email protected]fd847792013-10-24 17:12:35158// TODO(brianderson): Replace the hard-coded threshold with a fraction of
159// the BeginMainFrame interval.
160// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
161// be spent in input hanlders before input starts getting throttled.
162const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
163
jdduke07788062014-12-05 03:16:30164int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) {
165 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds))
166 .ToInternalValue();
167}
168
169void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now) {
170 UMA_HISTOGRAM_CUSTOM_COUNTS(
171 "Event.AggregatedLatency.Renderer2",
172 GetEventLatencyMicros(event, now),
173 1,
174 10000000,
175 100);
176
177#define CASE_TYPE(t) \
178 case WebInputEvent::t: \
179 UMA_HISTOGRAM_CUSTOM_COUNTS( \
180 "Event.Latency.Renderer2." #t, \
181 GetEventLatencyMicros(event, now), \
182 1, \
183 10000000, \
184 100); \
185 break;
186
187 switch(event.type) {
188 CASE_TYPE(Undefined);
189 CASE_TYPE(MouseDown);
190 CASE_TYPE(MouseUp);
191 CASE_TYPE(MouseMove);
192 CASE_TYPE(MouseEnter);
193 CASE_TYPE(MouseLeave);
194 CASE_TYPE(ContextMenu);
195 CASE_TYPE(MouseWheel);
196 CASE_TYPE(RawKeyDown);
197 CASE_TYPE(KeyDown);
198 CASE_TYPE(KeyUp);
199 CASE_TYPE(Char);
200 CASE_TYPE(GestureScrollBegin);
201 CASE_TYPE(GestureScrollEnd);
202 CASE_TYPE(GestureScrollUpdate);
203 CASE_TYPE(GestureFlingStart);
204 CASE_TYPE(GestureFlingCancel);
205 CASE_TYPE(GestureShowPress);
206 CASE_TYPE(GestureTap);
207 CASE_TYPE(GestureTapUnconfirmed);
208 CASE_TYPE(GestureTapDown);
209 CASE_TYPE(GestureTapCancel);
210 CASE_TYPE(GestureDoubleTap);
211 CASE_TYPE(GestureTwoFingerTap);
212 CASE_TYPE(GestureLongPress);
213 CASE_TYPE(GestureLongTap);
214 CASE_TYPE(GesturePinchBegin);
215 CASE_TYPE(GesturePinchEnd);
216 CASE_TYPE(GesturePinchUpdate);
217 CASE_TYPE(TouchStart);
218 CASE_TYPE(TouchMove);
219 CASE_TYPE(TouchEnd);
220 CASE_TYPE(TouchCancel);
221 default:
222 // Must include default to let blink::WebInputEvent add new event types
223 // before they're added here.
224 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event.type;
225 break;
226 }
227
228#undef CASE_TYPE
229}
230
[email protected]b256eca2013-07-11 10:57:40231} // namespace
232
[email protected]e9ff79c2012-10-19 21:31:26233namespace content {
[email protected]62cb33cae2009-03-27 23:30:22234
[email protected]b2e4c70132013-10-03 02:07:51235// RenderWidget::ScreenMetricsEmulator ----------------------------------------
236
237class RenderWidget::ScreenMetricsEmulator {
238 public:
239 ScreenMetricsEmulator(
240 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43241 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51242 virtual ~ScreenMetricsEmulator();
243
[email protected]19193682014-04-03 15:01:43244 // Scale and offset used to convert between host coordinates
245 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51246 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20247 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43248 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51249 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56250 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51251
252 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43253 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51254
255 // The following methods alter handlers' behavior for messages related to
256 // widget size and position.
257 void OnResizeMessage(const ViewMsg_Resize_Params& params);
258 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
259 const gfx::Rect& window_screen_rect);
260 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31261 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51262
263 private:
[email protected]19193682014-04-03 15:01:43264 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02265 void Apply(bool top_controls_shrink_blink_size,
266 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44267 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12268 bool is_fullscreen_granted,
269 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51270
271 RenderWidget* widget_;
272
[email protected]7f99fc22013-11-08 14:05:58273 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43274 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51275
[email protected]a179d3962013-11-12 14:44:40276 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51277 float scale_;
dgozman9260b0a12015-03-16 13:45:20278 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51279
[email protected]19193682014-04-03 15:01:43280 // Widget rect as passed to webwidget.
281 gfx::Rect applied_widget_rect_;
282
[email protected]b2e4c70132013-10-03 02:07:51283 // Original values to restore back after emulation ends.
284 gfx::Size original_size_;
285 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28286 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46287 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51288 gfx::Rect original_view_screen_rect_;
289 gfx::Rect original_window_screen_rect_;
290};
291
292RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
293 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43294 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51295 : widget_(widget),
[email protected]19193682014-04-03 15:01:43296 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51297 scale_(1.f) {
298 original_size_ = widget_->size_;
299 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28300 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51301 original_screen_info_ = widget_->screen_info_;
302 original_view_screen_rect_ = widget_->view_screen_rect_;
303 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02304 Apply(widget_->top_controls_shrink_blink_size_,
305 widget_->top_controls_height_,
306 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12307 widget_->is_fullscreen_granted_,
308 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51309}
310
311RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
312 widget_->screen_info_ = original_screen_info_;
313
314 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20315 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51316 widget_->view_screen_rect_ = original_view_screen_rect_;
317 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01318 widget_->Resize(original_size_,
319 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02320 widget_->top_controls_shrink_blink_size_,
321 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01322 original_visible_viewport_size_,
323 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12324 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12325 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01326 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51327}
328
329void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43330 const WebDeviceEmulationParams& params) {
331 params_ = params;
332 Reapply();
333}
334
335void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02336 Apply(widget_->top_controls_shrink_blink_size_,
337 widget_->top_controls_height_,
338 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12339 widget_->is_fullscreen_granted_,
340 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51341}
342
[email protected]19193682014-04-03 15:01:43343void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02344 bool top_controls_shrink_blink_size,
345 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44346 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12347 bool is_fullscreen_granted,
348 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31349 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
350 if (!applied_widget_rect_.width())
351 applied_widget_rect_.set_width(original_size_.width());
352 if (!applied_widget_rect_.height())
353 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43354
[email protected]f442ee42014-05-14 11:53:12355 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02356 int original_width = std::max(original_size_.width(), 1);
357 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51358 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02359 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51360 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02361 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51362 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
363 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01364
365 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43366 offset_.set_x(
367 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01368 offset_.set_y(
[email protected]19193682014-04-03 15:01:43369 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51370 } else {
[email protected]0b3578c2014-06-20 18:29:02371 scale_ = params_.scale;
372 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01373 }
[email protected]7f0e8fa2014-03-26 12:32:01374
[email protected]19193682014-04-03 15:01:43375 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
376 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01377 widget_->screen_info_.rect = original_screen_info_.rect;
378 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
379 widget_->window_screen_rect_ = original_window_screen_rect_;
380 } else {
dgozmanf28ccbe2015-06-24 08:50:49381 applied_widget_rect_.set_origin(params_.viewPosition);
382 gfx::Rect screen_rect = applied_widget_rect_;
383 if (!params_.screenSize.isEmpty()) {
384 screen_rect =
385 gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height);
386 }
387 widget_->screen_info_.rect = screen_rect;
388 widget_->screen_info_.availableRect = screen_rect;
[email protected]19193682014-04-03 15:01:43389 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01390 }
[email protected]a179d3962013-11-12 14:44:40391
[email protected]19193682014-04-03 15:01:43392 float applied_device_scale_factor = params_.deviceScaleFactor ?
393 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01394 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51395
[email protected]7f99fc22013-11-08 14:05:58396 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51397 // - we keep the real device scale factor in compositor to produce sharp image
398 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58399 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51400 // root layer.
dgozman9260b0a12015-03-16 13:45:20401 blink::WebDeviceEmulationParams modified_params = params_;
402 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
403 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
404 modified_params.scale = scale_;
405 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51406
[email protected]7f0e8fa2014-03-26 12:32:01407 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43408 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51409
410 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
411 original_size_, original_screen_info_.deviceScaleFactor));
dtrainorcb7779b82014-12-04 01:08:02412 widget_->Resize(applied_widget_rect_.size(),
413 physical_backing_size,
414 top_controls_shrink_blink_size,
415 top_controls_height,
416 applied_widget_rect_.size(),
417 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12418 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12419 display_mode,
dtrainorcb7779b82014-12-04 01:08:02420 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51421}
422
423void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
424 const ViewMsg_Resize_Params& params) {
425 bool need_ack = params.new_size != original_size_ &&
426 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
427 original_size_ = params.new_size;
428 original_physical_backing_size_ = params.physical_backing_size;
429 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28430 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02431 Apply(params.top_controls_shrink_blink_size,
432 params.top_controls_height,
433 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12434 params.is_fullscreen_granted,
435 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51436
437 if (need_ack) {
438 widget_->set_next_paint_is_resize_ack();
439 if (widget_->compositor_)
440 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
441 }
442}
443
444void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
445 const gfx::Rect& view_screen_rect,
446 const gfx::Rect& window_screen_rect) {
447 original_view_screen_rect_ = view_screen_rect;
448 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43449 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
450 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51451}
452
453void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
454 ContextMenuParams* params) {
455 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40456 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51457 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40458 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51459}
460
[email protected]2d6836f42014-07-02 17:25:31461gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
462 const gfx::Rect& anchor) {
463 gfx::Rect scaled = gfx::ToEnclosedRect(gfx::ScaleRect(anchor, scale_));
464 scaled.set_x(scaled.x() + offset_.x());
465 scaled.set_y(scaled.y() + offset_.y());
466 return scaled;
467}
468
[email protected]b2e4c70132013-10-03 02:07:51469// RenderWidget ---------------------------------------------------------------
470
dcheng35d31c112015-07-22 00:17:36471RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
472 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46473 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04474 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03475 bool hidden,
476 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29477 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56478 surface_id_(0),
dcheng35d31c112015-07-22 00:17:36479 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53480 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29481 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30482 init_complete_(false),
dtrainorcb7779b82014-12-04 01:08:02483 top_controls_shrink_blink_size_(false),
484 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29485 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51486 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09487 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29488 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04489 is_hidden_(hidden),
[email protected]7912e822014-04-16 02:37:03490 never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12491 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12492 display_mode_(blink::WebDisplayModeUndefined),
initial.commit09911bf2008-07-26 23:55:29493 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49494 handling_input_event_(false),
jddukec05612b2015-06-25 23:13:18495 handling_event_overscroll_(nullptr),
[email protected]e8f775f2013-02-14 21:00:50496 handling_ime_event_(false),
[email protected]c27dd4f2014-05-22 18:05:19497 handling_event_type_(WebInputEvent::Undefined),
498 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48499 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22500 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44501 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20502 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45503 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40504 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20505 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53506 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12507 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48508 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12509 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04510 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52511 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]8062ab262014-05-27 16:56:43512 current_event_latency_info_(NULL),
[email protected]53b4cc12013-07-18 23:02:30513 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13514#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36515 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13516 outstanding_ime_acks_(0),
[email protected]a4f0d882014-05-01 23:48:10517 body_background_color_(SK_ColorWHITE),
[email protected]0d1ebed12013-08-05 22:01:13518#endif
[email protected]b2e4c70132013-10-03 02:07:51519 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11520 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42521 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51522 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
523 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05524 if (!swapped_out)
525 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27526 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53527 device_color_profile_.push_back('0');
initial.commit09911bf2008-07-26 23:55:29528}
529
530RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11531 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16532
[email protected]992db4c2011-05-12 15:37:15533 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02534 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15535 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29536}
537
[email protected]484955942010-08-19 16:13:18538// static
[email protected]8085dbc82008-09-26 22:53:44539RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53540 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46541 blink::WebPopupType popup_type,
542 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29543 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36544 scoped_refptr<RenderWidget> widget(new RenderWidget(
545 compositor_deps, popup_type, screen_info, false, false, false));
546 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46547 return widget.get();
[email protected]a635f942012-12-07 10:34:29548 }
549 return NULL;
initial.commit09911bf2008-07-26 23:55:29550}
551
[email protected]484955942010-08-19 16:13:18552// static
kenrba7199832015-01-22 23:44:59553RenderWidget* RenderWidget::CreateForFrame(
554 int routing_id,
555 int surface_id,
556 bool hidden,
557 const blink::WebScreenInfo& screen_info,
558 CompositorDependencies* compositor_deps,
559 blink::WebLocalFrame* frame) {
560 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36561 scoped_refptr<RenderWidget> widget(
562 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
563 false, hidden, false));
kenrba7199832015-01-22 23:44:59564 widget->routing_id_ = routing_id;
565 widget->surface_id_ = surface_id;
simonhong628f9812015-04-27 23:13:20566 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59567 // DoInit increments the reference count on |widget|, keeping it alive after
568 // this function returns.
dcheng35d31c112015-07-22 00:17:36569 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59570 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
571 nullptr)) {
572 widget->CompleteInit();
573 return widget.get();
574 }
575 return nullptr;
576}
577
578// static
dchengda9b4bb2015-07-20 20:58:08579blink::WebWidget* RenderWidget::CreateWebFrameWidget(
580 RenderWidget* render_widget,
581 blink::WebLocalFrame* frame) {
582 return blink::WebFrameWidget::create(render_widget, frame);
583}
584
585// static
kenrba7199832015-01-22 23:44:59586blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18587 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46588 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18589 break;
[email protected]180ef242013-11-07 06:50:46590 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44591 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18592 default:
593 NOTREACHED();
594 }
595 return NULL;
596}
597
dchengda9b4bb2015-07-20 20:58:08598void RenderWidget::CloseForFrame() {
599 // Close() must be called synchronously, since Blink objects are already in
600 // the process of being torn down. Deferring Close() to the message loop like
601 // the normal case means that Close() will end up getting called when various
602 // pointers, etc. are already nulled out or freed.
603 CloseInternal(true);
kenrba7199832015-01-22 23:44:59604}
605
dcheng35d31c112015-07-22 00:17:36606bool RenderWidget::Init(int32 opener_id) {
607 return DoInit(opener_id, RenderWidget::CreateWebWidget(this),
[email protected]a635f942012-12-07 10:34:29608 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
609 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18610}
611
[email protected]a635f942012-12-07 10:34:29612bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06613 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18614 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29615 DCHECK(!webwidget_);
616
617 if (opener_id != MSG_ROUTING_NONE)
618 opener_id_ = opener_id;
619
[email protected]484955942010-08-19 16:13:18620 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29621
kenrba7199832015-01-22 23:44:59622 bool result = true;
623 if (create_widget_message)
624 result = RenderThread::Get()->Send(create_widget_message);
625
initial.commit09911bf2008-07-26 23:55:29626 if (result) {
[email protected]380244092011-10-07 17:26:27627 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29628 // Take a reference on behalf of the RenderThread. This will be balanced
629 // when we receive ViewMsg_Close.
630 AddRef();
[email protected]b2db9272014-01-10 17:42:00631 if (RenderThreadImpl::current()) {
632 RenderThreadImpl::current()->WidgetCreated();
633 if (is_hidden_)
634 RenderThreadImpl::current()->WidgetHidden();
635 }
[email protected]a635f942012-12-07 10:34:29636 return true;
initial.commit09911bf2008-07-26 23:55:29637 } else {
[email protected]a635f942012-12-07 10:34:29638 // The above Send can fail when the tab is closing.
639 return false;
initial.commit09911bf2008-07-26 23:55:29640 }
641}
642
[email protected]fc4404d2012-11-07 19:53:30643// This is used to complete pending inits and non-pending inits.
644void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29645 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29646
[email protected]fc4404d2012-11-07 19:53:30647 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42648
[email protected]7912e822014-04-16 02:37:03649 if (compositor_)
650 StartCompositor();
initial.commit09911bf2008-07-26 23:55:29651
[email protected]6de74452009-02-25 18:04:59652 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29653}
654
[email protected]992db4c2011-05-12 15:37:15655void RenderWidget::SetSwappedOut(bool is_swapped_out) {
656 // We should only toggle between states.
657 DCHECK(is_swapped_out_ != is_swapped_out);
658 is_swapped_out_ = is_swapped_out;
659
660 // If we are swapping out, we will call ReleaseProcess, allowing the process
661 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52662 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15663 // If we are swapping in, we call AddRefProcess to prevent the process from
664 // exiting.
[email protected]949b6592014-08-20 13:17:52665 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15666 RenderProcess::current()->AddRefProcess();
667}
668
[email protected]949b6592014-08-20 13:17:52669void RenderWidget::WasSwappedOut() {
670 // If we have been swapped out and no one else is using this process,
671 // it's safe to exit now.
672 CHECK(is_swapped_out_);
673 RenderProcess::current()->ReleaseProcess();
674}
675
[email protected]b2e4c70132013-10-03 02:07:51676void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
677 ScreenMetricsEmulator* emulator) {
678 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43679 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49680 popup_screen_origin_for_emulation_ = gfx::Point(
681 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
682 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56683 screen_info_ = emulator->original_screen_info();
684 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51685}
686
[email protected]2d6836f42014-07-02 17:25:31687gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
688 if (screen_metrics_emulator_)
689 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
690 return anchor;
691}
692
[email protected]b2e4c70132013-10-03 02:07:51693void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20694 bool enabled,
695 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51696 // This is only supported in RenderView.
697 NOTREACHED();
698}
699
[email protected]53907862014-03-25 15:42:40700#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51701void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
702 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49703 popup->SetOriginScaleAndOffsetForEmulation(
704 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51705}
[email protected]53907862014-03-25 15:42:40706#endif
[email protected]b2e4c70132013-10-03 02:07:51707
708void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
709 if (screen_metrics_emulator_)
710 screen_metrics_emulator_->OnShowContextMenu(params);
711}
712
[email protected]a95986a82010-12-24 06:19:28713bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
714 bool handled = true;
715 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15716 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22717 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
718 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22719 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
720 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15721 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
722 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35723 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
724 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28725 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
726 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
727 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20728 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
729 OnEnableDeviceEmulation)
730 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
731 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41732 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54733 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28734 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41735 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25736 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28737 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
738 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03739 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05740 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21741#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51742 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13743 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21744#endif
[email protected]a95986a82010-12-24 06:19:28745 IPC_MESSAGE_UNHANDLED(handled = false)
746 IPC_END_MESSAGE_MAP()
747 return handled;
748}
initial.commit09911bf2008-07-26 23:55:29749
750bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15751 // Don't send any messages after the browser has told us to close, and filter
752 // most outgoing messages while swapped out.
753 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26754 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11755 closing_) {
initial.commit09911bf2008-07-26 23:55:29756 delete message;
757 return false;
758 }
759
760 // If given a messsage without a routing ID, then assign our routing ID.
761 if (message->routing_id() == MSG_ROUTING_NONE)
762 message->set_routing_id(routing_id_);
763
[email protected]380244092011-10-07 17:26:27764 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44765}
766
[email protected]61e2b3cc2012-03-02 16:13:34767void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44768 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02769 bool top_controls_shrink_blink_size,
770 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44771 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34772 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12773 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12774 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58775 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56776 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48777 // A resize ack shouldn't be requested if we have not ACK'd the previous
778 // one.
779 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
780 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
781 }
initial.commit09911bf2008-07-26 23:55:29782
[email protected]61e2b3cc2012-03-02 16:13:34783 // Ignore this during shutdown.
784 if (!webwidget_)
785 return;
786
[email protected]d9083762013-03-24 01:36:40787 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44788 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40789 }
[email protected]60d47ac2013-03-01 23:42:44790
[email protected]dade8992013-03-04 07:34:34791 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02792 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
793 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28794 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34795 resizer_rect_ = resizer_rect;
796
797 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12798 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
[email protected]61e2b3cc2012-03-02 16:13:34799 if (fullscreen_change)
800 WillToggleFullscreen();
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12801 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12802 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34803
aelias6004fe02015-02-07 21:43:01804 webwidget_->setTopControlsHeight(top_controls_height,
805 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43806
[email protected]61e2b3cc2012-03-02 16:13:34807 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34808 size_ = new_size;
809
[email protected]61e2b3cc2012-03-02 16:13:34810 // When resizing, we want to wait to paint before ACK'ing the resize. This
811 // ensures that we only resize as fast as we can paint. We only need to
812 // send an ACK if we are resized to a non-empty rect.
813 webwidget_->resize(new_size);
[email protected]632c4382013-05-15 08:58:45814 }
815
[email protected]bb6378fe2014-04-28 21:19:44816 webwidget()->resizePinchViewport(gfx::Size(
817 visible_viewport_size.width(),
818 visible_viewport_size.height()));
819
[email protected]632c4382013-05-15 08:58:45820 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58821 // In this case there is no paint/composite and therefore no
822 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
823 // ack through a fake ViewHostMsg_UpdateRect or a different message.
824 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34825 }
826
[email protected]20fbfc22013-05-08 20:50:58827 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45828 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58829 set_next_paint_is_resize_ack();
830
[email protected]61e2b3cc2012-03-02 16:13:34831 if (fullscreen_change)
832 DidToggleFullscreen();
833
834 // If a resize ack is requested and it isn't set-up, then no more resizes will
835 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45836 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29837}
838
bokanc007c3a2015-02-03 07:15:56839void RenderWidget::SetWindowRectSynchronously(
840 const gfx::Rect& new_window_rect) {
841 Resize(new_window_rect.size(),
842 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02843 top_controls_shrink_blink_size_,
844 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56845 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01846 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12847 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12848 display_mode_,
[email protected]587941d2014-08-22 01:40:01849 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56850 view_screen_rect_ = new_window_rect;
851 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02852 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56853 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02854}
855
initial.commit09911bf2008-07-26 23:55:29856void RenderWidget::OnClose() {
dchengda9b4bb2015-07-20 20:58:08857 CloseInternal(false);
initial.commit09911bf2008-07-26 23:55:29858}
859
[email protected]61e2b3cc2012-03-02 16:13:34860// Got a response from the browser after the renderer decided to create a new
861// view.
[email protected]fc4404d2012-11-07 19:53:30862void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34863 DCHECK(routing_id_ != MSG_ROUTING_NONE);
864
[email protected]fc4404d2012-11-07 19:53:30865 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34866}
867
[email protected]0fdd5012013-05-29 08:05:56868void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04869 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32870 return;
871
[email protected]b2e4c70132013-10-03 02:07:51872 if (screen_metrics_emulator_) {
873 screen_metrics_emulator_->OnResizeMessage(params);
874 return;
875 }
876
[email protected]fcdc5642014-05-09 14:32:24877 bool orientation_changed =
878 screen_info_.orientationAngle != params.screen_info.orientationAngle;
879
[email protected]0fdd5012013-05-29 08:05:56880 screen_info_ = params.screen_info;
881 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02882 Resize(params.new_size,
883 params.physical_backing_size,
884 params.top_controls_shrink_blink_size,
885 params.top_controls_height,
886 params.visible_viewport_size,
887 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12888 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12889 params.display_mode,
sievers4e33dae2015-02-25 20:43:58890 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24891
892 if (orientation_changed)
893 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29894}
895
dgozman9260b0a12015-03-16 13:45:20896void RenderWidget::OnEnableDeviceEmulation(
897 const blink::WebDeviceEmulationParams& params) {
898 if (!screen_metrics_emulator_)
899 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
900 else
901 screen_metrics_emulator_->ChangeEmulationParams(params);
902}
903
904void RenderWidget::OnDisableDeviceEmulation() {
905 screen_metrics_emulator_.reset();
906}
907
noel89949e62014-09-30 01:12:41908void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
909 SetDeviceColorProfile(color_profile);
910}
911
[email protected]b5913d72012-02-07 22:26:54912void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01913 if (resizer_rect_ == resizer_rect)
914 return;
915 resizer_rect_ = resizer_rect;
916 if (webwidget_)
917 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54918}
919
initial.commit09911bf2008-07-26 23:55:29920void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31921 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29922 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03923 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59924 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
925 WasHidden());
initial.commit09911bf2008-07-26 23:55:29926}
927
[email protected]3399dd822014-08-09 11:14:24928void RenderWidget::OnWasShown(bool needs_repainting,
929 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41930 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29931 // During shutdown we can just ignore this message.
932 if (!webwidget_)
933 return;
934
935 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03936 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59937 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
938 WasShown());
initial.commit09911bf2008-07-26 23:55:29939
[email protected]8a23afb32014-04-30 22:40:23940 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29941 return;
initial.commit09911bf2008-07-26 23:55:29942
943 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24944 if (compositor_) {
945 ui::LatencyInfo swap_latency_info(latency_info);
946 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
947 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05948 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24949 }
jdduke491a3f0c2015-06-15 23:30:26950 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29951}
952
[email protected]53d3f302009-12-21 04:42:05953void RenderWidget::OnRequestMoveAck() {
954 DCHECK(pending_window_rect_count_);
955 pending_window_rect_count_--;
956}
957
[email protected]ed7defa2013-03-12 21:29:59958GURL RenderWidget::GetURLForGraphicsContext3D() {
959 return GURL();
[email protected]65225772011-05-12 21:10:24960}
961
[email protected]ebc0e1df2013-08-01 02:46:22962scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03963 // For widgets that are never visible, we don't start the compositor, so we
964 // never get a request for a cc::OutputSurface.
965 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19966
967#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01968 if (SynchronousCompositorFactory* factory =
969 SynchronousCompositorFactory::GetInstance()) {
[email protected]586871b2014-07-22 17:05:11970 return factory->CreateOutputSurface(routing_id(),
971 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:19972 }
973#endif
974
avi83883c82014-12-23 00:08:49975 const base::CommandLine& command_line =
976 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33977 bool use_software = fallback;
978 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
979 use_software = true;
980
[email protected]0634cdd42013-08-16 00:46:09981 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17982 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:33983 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09984 context_provider = ContextProviderCommandBuffer::Create(
sieversfbaa5dc2015-04-28 00:45:31985 CreateGraphicsContext3D(), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:33986 if (!context_provider.get()) {
987 // Cause the compositor to wait and try again.
988 return scoped_ptr<cc::OutputSurface>();
989 }
vmiura78b69282015-02-14 00:01:17990
991 worker_context_provider = ContextProviderCommandBuffer::Create(
sieversfbaa5dc2015-04-28 00:45:31992 CreateGraphicsContext3D(), RENDER_WORKER_CONTEXT);
vmiura78b69282015-02-14 00:01:17993 if (!worker_context_provider.get()) {
994 // Cause the compositor to wait and try again.
995 return scoped_ptr<cc::OutputSurface>();
996 }
[email protected]0634cdd42013-08-16 00:46:09997 }
[email protected]ebc0e1df2013-08-01 02:46:22998
[email protected]b6eb8e332013-09-10 00:51:01999 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:001000 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:531001 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
caseqff9c74c2015-02-10 14:56:291002 return scoped_ptr<cc::OutputSurface>(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171003 routing_id(), output_surface_id, context_provider,
1004 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091005 }
[email protected]0634cdd42013-08-16 00:46:091006 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091007 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121008 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091009
caseqff9c74c2015-02-10 14:56:291010 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
1011 routing_id(), output_surface_id, nullptr, nullptr,
1012 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221013 }
[email protected]ed7defa2013-03-12 21:29:591014
[email protected]36e5ff12013-06-11 12:19:291015 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:451016 // Composite-to-mailbox is currently used for layout tests in order to cause
1017 // them to draw inside in the renderer to do the readback there. This should
1018 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:531019 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:161020 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:271021 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:161022 format = cc::RGB_565;
caseqff9c74c2015-02-10 14:56:291023 return scoped_ptr<cc::OutputSurface>(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171024 routing_id(), output_surface_id, context_provider,
1025 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1026 frame_swap_message_queue_, format));
[email protected]36e5ff12013-06-11 12:19:291027 }
[email protected]0634cdd42013-08-16 00:46:091028 bool use_swap_compositor_frame_message = false;
caseqff9c74c2015-02-10 14:56:291029 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171030 routing_id(), output_surface_id, context_provider,
1031 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1032 frame_swap_message_queue_, use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281033}
1034
[email protected]4d7e46a2013-11-08 05:33:401035void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241036 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241037 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:261038 ScheduleComposite();
[email protected]65225772011-05-12 21:10:241039}
1040
[email protected]4d7e46a2013-11-08 05:33:401041void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081042 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081043}
1044
[email protected]4d7e46a2013-11-08 05:33:401045void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241046 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161047
[email protected]404939f2012-06-01 04:06:181048 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161049 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291050}
1051
[email protected]180ef242013-11-07 06:50:461052void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351053 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091054 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191055 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291056 return;
jddukec05612b2015-06-25 23:13:181057 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_,
1058 true);
[email protected]c27dd4f2014-05-22 18:05:191059 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1060 &handling_event_type_, input_event->type);
jddukec05612b2015-06-25 23:13:181061
1062 // Calls into |didOverscroll()| while handling this event will populate
1063 // |event_overscroll|, which in turn will be bundled with the event ack.
1064 scoped_ptr<DidOverscrollParams> event_overscroll;
1065 base::AutoReset<scoped_ptr<DidOverscrollParams>*>
1066 handling_event_overscroll_resetter(&handling_event_overscroll_,
1067 &event_overscroll);
1068
[email protected]25402eb2014-07-18 03:09:521069#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541070 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521071 // |AdapterInputConnection| generates input key events to make sure all JS
1072 // listeners that monitor KeyUp and KeyDown events receive the proper key
1073 // code. Since this input key event comes from IME, we need to set the
1074 // IME event guard here to make sure it does not interfere with other IME
1075 // events.
1076 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1077 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1078 const WebKeyboardEvent& key_event =
1079 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541080 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171081 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091082 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1083 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1084 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1085 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1086 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521087 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521088 }
1089#endif
initial.commit09911bf2008-07-26 23:55:291090
[email protected]8062ab262014-05-27 16:56:431091 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1092 &latency_info);
1093
[email protected]fd847792013-10-24 17:12:351094 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411095 if (base::TimeTicks::IsHighResolution())
1096 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351097
miletusfed8c43b2015-01-26 20:04:521098 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301099 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151100 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131101 TRACE_EVENT_FLOW_STEP0(
miletusfed8c43b2015-01-26 20:04:521102 "input,benchmark",
[email protected]15ba6dea2014-04-02 01:44:131103 "LatencyInfo.Flow",
1104 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1105 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101106
jdduke07788062014-12-05 03:16:301107 // If we don't have a high res timer, these metrics won't be accurate enough
1108 // to be worth collecting. Note that this does introduce some sampling bias.
1109 if (!start_time.is_null())
1110 LogInputEventLatencyUma(*input_event, start_time);
1111
[email protected]6be422b2013-12-08 06:47:311112 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351113 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311114 if (compositor_) {
1115 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351116 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1117 .Pass();
[email protected]6be422b2013-12-08 06:47:311118 }
[email protected]c2eaa8f2013-05-10 02:41:551119
[email protected]67bfb83f2011-09-22 03:36:371120 bool prevent_default = false;
1121 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261122 const WebMouseEvent& mouse_event =
1123 *static_cast<const WebMouseEvent*>(input_event);
1124 TRACE_EVENT2("renderer", "HandleMouseMove",
1125 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421126 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261127 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371128 }
1129
[email protected]cefe9b152014-03-27 18:16:151130 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421131 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151132#if defined(OS_ANDROID)
1133 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1134 // case it should behave like a select key (i.e. causing a click if a button
1135 // is focused). However, if a text field is focused (2), its intended
1136 // behavior is to just show the IME and don't propagate the key.
1137 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1138 // when clicked on an input text field and cause the form submit if clicked
1139 // when the submit button is focused, but not vice-versa.
1140 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1141 // but at this point we have to swallow the event for the scenario (2).
1142 const WebKeyboardEvent& key_event =
1143 *static_cast<const WebKeyboardEvent*>(input_event);
1144 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1145 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1146 OnShowImeIfNeeded();
1147 prevent_default = true;
1148 }
1149#endif
1150 }
[email protected]f56c7872013-06-18 12:31:571151
[email protected]41d86852012-11-07 12:23:241152 if (WebInputEvent::isGestureEventType(input_event->type)) {
1153 const WebGestureEvent& gesture_event =
1154 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421155 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241156 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1157 }
1158
[email protected]67bfb83f2011-09-22 03:36:371159 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121160 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1161 suppress_next_char_events_ = false;
1162 if (!processed && webwidget_)
1163 processed = webwidget_->handleInputEvent(*input_event);
1164 }
1165
1166 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1167 // it's not processed by webkit, then we need to suppress the upcoming Char
1168 // events.
1169 if (!processed && is_keyboard_shortcut)
1170 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291171
[email protected]3d5c243b2012-11-30 00:26:011172 InputEventAckState ack_result = processed ?
1173 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1174 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1175 const WebTouchEvent& touch_event =
1176 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251177 // Hit-test for all the pressed touch points. If there is a touch-handler
1178 // for any of the touch points, then the renderer should continue to receive
1179 // touch events.
1180 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1181 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1182 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271183 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391184 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251185 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1186 break;
1187 }
1188 }
[email protected]3d5c243b2012-11-30 00:26:011189 }
1190
ccamerond4ba47902014-12-17 07:20:311191 // Send mouse wheel events and their disposition to the compositor thread, so
1192 // that they can be used to produce the elastic overscroll effect on Mac.
1193 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311194 ObserveWheelEventAndResult(
sataya.mf405d0e2015-07-07 16:51:111195 static_cast<const WebMouseWheelEvent&>(*input_event),
1196 event_overscroll ? event_overscroll->latest_overscroll_delta
1197 : gfx::Vector2dF(),
1198 processed);
ccamerond4ba47902014-12-17 07:20:311199 }
1200
[email protected]721e2302014-04-30 23:42:011201 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061202
charliea3be839702015-01-26 17:35:411203 // If we don't have a fast and accurate Now(), we assume the input handlers
1204 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301205 bool rate_limiting_wanted =
1206 input_event->type == WebInputEvent::MouseMove ||
1207 input_event->type == WebInputEvent::MouseWheel;
1208 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411209 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351210 total_input_handling_time_this_frame_ += (end_time - start_time);
1211 rate_limiting_wanted =
1212 total_input_handling_time_this_frame_.InMicroseconds() >
1213 kInputHandlingTimeThrottlingThresholdMicroseconds;
1214 }
1215
[email protected]7f19e9d2014-05-09 15:16:291216 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1217
[email protected]c27dd4f2014-05-22 18:05:191218 // Note that we can't use handling_event_type_ here since it will be overriden
1219 // by reentrant calls for events after the paused one.
1220 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1221 input_event->type == WebInputEvent::MouseMove;
lanweif1a22832015-05-19 17:24:101222 if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) &&
1223 !no_ack) {
1224 InputEventAck ack(input_event->type, ack_result, swap_latency_info,
jddukec05612b2015-06-25 23:13:181225 event_overscroll.Pass(),
lanweif1a22832015-05-19 17:24:101226 WebInputEventTraits::GetUniqueTouchEventId(*input_event));
[email protected]34afe102013-12-13 17:24:551227 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561228 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301229 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551230 // We want to rate limit the input events in this case, so we'll wait for
1231 // painting to finish before ACKing this message.
1232 TRACE_EVENT_INSTANT0("renderer",
1233 "RenderWidget::OnHandleInputEvent ack throttled",
1234 TRACE_EVENT_SCOPE_THREAD);
1235 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291236 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1237 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551238 // As two different kinds of events could cause us to postpone an ack
1239 // we send it now, if we have one pending. The Browser should never
1240 // send us the same kind of event we are delaying the ack for.
1241 Send(pending_input_event_ack_.release());
1242 }
1243 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291244 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1245 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551246 if (compositor_)
1247 compositor_->NotifyInputThrottledUntilCommit();
1248 } else {
1249 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171250 }
jddukec05612b2015-06-25 23:13:181251 } else {
1252 DCHECK(!event_overscroll) << "Unexpected overscroll for un-acked event";
[email protected]12fbad812009-09-01 18:21:241253 }
alexclarke7819e2552015-06-03 11:17:211254 if (!no_ack && RenderThreadImpl::current()) {
1255 RenderThreadImpl::current()
1256 ->GetRendererScheduler()
1257 ->DidHandleInputEventOnMainThread(*input_event);
1258 }
[email protected]5fea4a52014-05-27 00:17:521259 if (input_event->type == WebInputEvent::MouseMove)
1260 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241261
[email protected]3306f262012-09-21 19:20:421262#if defined(OS_ANDROID)
1263 // Allow the IME to be shown when the focus changes as a consequence
1264 // of a processed touch end event.
1265 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361266 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021267#elif defined(USE_AURA)
1268 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1269 // change.
1270 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141271 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361272 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141273 }
[email protected]3306f262012-09-21 19:20:421274#endif
1275
[email protected]67bfb83f2011-09-22 03:36:371276 if (!prevent_default) {
1277 if (WebInputEvent::isKeyboardEventType(input_event->type))
1278 DidHandleKeyEvent();
[email protected]67bfb83f2011-09-22 03:36:371279 }
rouslanf7ebd8832015-01-22 01:54:141280
1281// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1282// virtual keyboard.
1283#if !defined(OS_ANDROID)
1284 // Virtual keyboard is not supported, so react to focus change immediately.
1285 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1286 input_event->type == WebInputEvent::MouseUp)) {
1287 FocusChangeComplete();
1288 }
1289#endif
initial.commit09911bf2008-07-26 23:55:291290}
1291
[email protected]34202de2013-05-06 23:36:221292void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1293 if (webwidget_)
1294 webwidget_->setCursorVisibilityState(is_visible);
1295}
1296
initial.commit09911bf2008-07-26 23:55:291297void RenderWidget::OnMouseCaptureLost() {
1298 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281299 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291300}
1301
1302void RenderWidget::OnSetFocus(bool enable) {
1303 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331304 if (webwidget_)
1305 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291306}
1307
1308void RenderWidget::ClearFocus() {
1309 // We may have got the focus from the browser before this gets processed, in
1310 // which case we do not want to unfocus ourself.
1311 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281312 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291313}
1314
[email protected]fd847792013-10-24 17:12:351315void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291316 if (pending_input_event_ack_) {
1317 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1318 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071319 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291320 }
[email protected]fd847792013-10-24 17:12:351321 total_input_handling_time_this_frame_ = base::TimeDelta();
1322}
1323
initial.commit09911bf2008-07-26 23:55:291324///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461325// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291326
[email protected]244ac1892011-12-02 17:04:471327void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091328 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451329 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581330
[email protected]5b45ad42013-10-25 00:42:041331 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451332 WebRect new_pos(rootWindowRect().x,
1333 rootWindowRect().y,
1334 new_size.width,
1335 new_size.height);
1336 view_screen_rect_ = new_pos;
1337 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031338 }
[email protected]20fbfc22013-05-08 20:50:581339
[email protected]eac2b362013-05-22 07:01:451340 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581341
[email protected]5b45ad42013-10-25 00:42:041342 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581343 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091344 }
[email protected]244ac1892011-12-02 17:04:471345}
1346
[email protected]3a1c8a8032013-03-18 22:35:321347void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051348 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1349 device_scale_factor_));
1350 if (compositor_)
1351 compositor_->setViewportSize(size_, physical_backing_size_);
1352}
1353
[email protected]e195e582013-03-08 01:32:591354void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221355 DCHECK(!host_closing_);
1356
danakj6e3bf8012014-12-16 18:27:531357 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591358 compositor_->setViewportSize(size_, physical_backing_size_);
1359 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031360 StartCompositor();
[email protected]e195e582013-03-08 01:32:591361}
1362
ennef3c58142014-12-09 21:44:381363void RenderWidget::WillCloseLayerTreeView() {
1364 if (host_closing_)
1365 return;
1366
1367 // Prevent new compositors or output surfaces from being created.
1368 host_closing_ = true;
1369
[email protected]aeeedad2014-08-22 18:16:221370 // Always send this notification to prevent new layer tree views from
1371 // being created, even if one hasn't been created yet.
1372 if (webwidget_)
1373 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221374}
1375
[email protected]180ef242013-11-07 06:50:461376blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281377 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061378}
1379
jdduke491a3f0c2015-06-15 23:30:261380void RenderWidget::WillBeginCompositorFrame() {
[email protected]9cd43a62012-03-26 08:03:561381 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371382
[email protected]abe8b3a2012-03-28 21:19:371383 // The following two can result in further layout and possibly
1384 // enable GPU acceleration so they need to be called before any painting
1385 // is done.
shuchen3517bb62014-10-15 03:55:571386 UpdateTextInputType();
1387#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361388 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571389#endif
[email protected]abe8b3a2012-03-28 21:19:371390 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561391}
1392
[email protected]6fceb912013-02-15 06:24:151393void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441394 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1395 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271396 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161397 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171398#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271399 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1400 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171401#endif // defined(VIDEO_HOLE)
jdduke491a3f0c2015-06-15 23:30:261402 FlushPendingInputEventAck();
1403}
1404
1405void RenderWidget::DidCommitAndDrawCompositorFrame() {
1406 // NOTE: Tests may break if this event is renamed or moved. See
1407 // tab_capture_performancetest.cc.
1408 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
1409 // Notify subclasses that we initiated the paint operation.
1410 DidInitiatePaint();
1411}
1412
1413void RenderWidget::DidCompleteSwapBuffers() {
1414 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
1415
1416 // Notify subclasses threaded composited rendering was flushed to the screen.
1417 DidFlushPaint();
1418
1419 if (!next_paint_flags_ &&
1420 !need_update_rect_for_auto_resize_ &&
1421 !plugin_window_moves_.size()) {
1422 return;
1423 }
1424
1425 ViewHostMsg_UpdateRect_Params params;
1426 params.view_size = size_;
1427 params.plugin_window_moves.swap(plugin_window_moves_);
1428 params.flags = next_paint_flags_;
1429
1430 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1431 next_paint_flags_ = 0;
1432 need_update_rect_for_auto_resize_ = false;
1433}
1434
1435void RenderWidget::ScheduleComposite() {
1436 if (compositor_ &&
1437 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1438 compositor_->setNeedsAnimate();
1439 }
1440}
1441
1442void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1443 if (compositor_) {
1444 // Regardless of whether threaded compositing is enabled, always
1445 // use this mechanism to force the compositor to redraw. However,
1446 // the invalidation code path below is still needed for the
1447 // non-threaded case.
1448 compositor_->SetNeedsForcedRedraw();
1449 }
1450 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151451}
1452
[email protected]586871b2014-07-22 17:05:111453// static
1454scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1455 IPC::Message* msg,
1456 MessageDeliveryPolicy policy,
1457 FrameSwapMessageQueue* frame_swap_message_queue,
1458 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111459 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111460 bool first_message_for_frame = false;
1461 frame_swap_message_queue->QueueMessageForFrame(policy,
1462 source_frame_number,
1463 make_scoped_ptr(msg),
1464 &first_message_for_frame);
1465 if (first_message_for_frame) {
1466 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1467 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061468 return promise;
[email protected]586871b2014-07-22 17:05:111469 }
dcheng4b6b5ff2014-10-16 00:42:061470 return nullptr;
[email protected]586871b2014-07-22 17:05:111471}
1472
1473void RenderWidget::QueueMessage(IPC::Message* msg,
1474 MessageDeliveryPolicy policy) {
1475 // RenderThreadImpl::current() is NULL in some tests.
1476 if (!compositor_ || !RenderThreadImpl::current()) {
1477 Send(msg);
1478 return;
1479 }
1480
1481 scoped_ptr<cc::SwapPromise> swap_promise =
1482 QueueMessageImpl(msg,
1483 policy,
dcheng58867a92014-08-26 02:50:221484 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111485 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111486 compositor_->GetSourceFrameNumber());
1487
1488 if (swap_promise) {
1489 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351490 // Request a commit. This might either A) request a commit ahead of time
1491 // or B) request a commit which is not needed because there are not
1492 // pending updates. If B) then the commit will be skipped and the swap
1493 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1494 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1495 // can_cancel_commit is not unset.
1496 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111497 }
1498}
1499
[email protected]4873c7d2009-07-16 06:36:281500void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301501 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521502 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401503 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291504 // Only send a SetCursor message if we need to make a change.
1505 if (!current_cursor_.IsEqual(cursor)) {
1506 current_cursor_ = cursor;
1507 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1508 }
1509}
1510
1511// We are supposed to get a single call to Show for a newly created RenderWidget
1512// that was created via RenderWidget::CreateWebView. So, we wait until this
1513// point to dispatch the ShowWidget message.
1514//
1515// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281516// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291517//
[email protected]4873c7d2009-07-16 06:36:281518void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291519 DCHECK(!did_show_) << "received extraneous Show call";
1520 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1521 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1522
[email protected]8de12d942010-11-17 20:42:441523 if (did_show_)
1524 return;
1525
1526 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561527 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441528 // that's okay. It'll be ignored if as_popup is false, or the browser
1529 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561530 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1531 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291532}
1533
[email protected]4873c7d2009-07-16 06:36:281534void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291535}
1536
[email protected]4873c7d2009-07-16 06:36:281537void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291538}
1539
[email protected]2533ce12009-05-09 00:02:241540void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381541 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241542 Send(new ViewHostMsg_Close(routing_id_));
1543}
1544
dgozmancf9039cd2015-04-06 12:01:311545void RenderWidget::NotifyOnClose() {
1546 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1547}
1548
dchengda9b4bb2015-07-20 20:58:081549void RenderWidget::CloseInternal(bool close_synchronously) {
1550 DCHECK(content::RenderThread::Get());
1551 if (closing_)
1552 return;
1553 NotifyOnClose();
1554 closing_ = true;
1555
1556 // Browser correspondence is no longer needed at this point.
1557 if (routing_id_ != MSG_ROUTING_NONE) {
1558 RenderThread::Get()->RemoveRoute(routing_id_);
1559 SetHidden(false);
1560 if (RenderThreadImpl::current())
1561 RenderThreadImpl::current()->WidgetDestroyed();
1562 }
1563
1564 if (close_synchronously) {
1565 Close();
1566 } else {
1567 // If there is a Send call on the stack, then it could be dangerous to close
1568 // now. Post a task that only gets invoked when there are no nested message
1569 // loops.
1570 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
1571 FROM_HERE, base::Bind(&RenderWidget::Close, this));
1572 }
1573
1574 // Balances the AddRef taken when we called AddRoute.
1575 Release();
1576}
1577
[email protected]4873c7d2009-07-16 06:36:281578void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081579 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321580 if (is_swapped_out_) {
1581 // This widget is currently swapped out, and the active widget is in a
1582 // different process. Have the browser route the close request to the
1583 // active widget instead, so that the correct unload handlers are run.
1584 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1585 return;
1586 }
1587
initial.commit09911bf2008-07-26 23:55:291588 // If a page calls window.close() twice, we'll end up here twice, but that's
1589 // OK. It is safe to send multiple Close messages.
1590
[email protected]2533ce12009-05-09 00:02:241591 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1592 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1593 // could be closed before the JS finishes executing. So instead, post a
1594 // message back to the message loop, which won't run until the JS is
1595 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081596 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211597 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291598}
1599
[email protected]9017d7852013-11-21 17:47:351600void RenderWidget::QueueSyntheticGesture(
1601 scoped_ptr<SyntheticGestureParams> gesture_params,
1602 const SyntheticGestureCompletionCallback& callback) {
1603 DCHECK(!callback.is_null());
1604
1605 pending_synthetic_gesture_callbacks_.push(callback);
1606
1607 SyntheticGesturePacket gesture_packet;
1608 gesture_packet.set_gesture_params(gesture_params.Pass());
1609
1610 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1611}
1612
initial.commit09911bf2008-07-26 23:55:291613void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031614 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381615 WillCloseLayerTreeView();
1616 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291617 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281618 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291619 webwidget_ = NULL;
1620 }
1621}
1622
[email protected]4873c7d2009-07-16 06:36:281623WebRect RenderWidget::windowRect() {
1624 if (pending_window_rect_count_)
1625 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241626
[email protected]80ad8622012-11-07 16:33:031627 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291628}
1629
[email protected]180ef242013-11-07 06:50:461630void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301631 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541632 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301633}
1634
[email protected]b2e4c70132013-10-03 02:07:511635void RenderWidget::setWindowRect(const WebRect& rect) {
bokanc007c3a2015-02-03 07:15:561636 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511637 if (popup_origin_scale_for_emulation_) {
1638 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561639 window_rect.x = popup_screen_origin_for_emulation_.x() +
1640 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1641 window_rect.y = popup_screen_origin_for_emulation_.y() +
1642 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511643 }
1644
[email protected]5b45ad42013-10-25 00:42:041645 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201646 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561647 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1648 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031649 } else {
bokanc007c3a2015-02-03 07:15:561650 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031651 }
initial.commit09911bf2008-07-26 23:55:291652 } else {
bokanc007c3a2015-02-03 07:15:561653 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291654 }
1655}
1656
[email protected]2533ce12009-05-09 00:02:241657void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1658 pending_window_rect_ = rect;
1659 pending_window_rect_count_++;
1660}
1661
[email protected]4873c7d2009-07-16 06:36:281662WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241663 if (pending_window_rect_count_) {
1664 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1665 // the RootWindowRect is probably going to return wrong results since the
1666 // browser may not have processed the Move yet. There isn't really anything
1667 // good to do in this case, and it shouldn't happen - since this size is
1668 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281669 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241670 }
1671
[email protected]80ad8622012-11-07 16:33:031672 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371673}
1674
[email protected]4873c7d2009-07-16 06:36:281675WebRect RenderWidget::windowResizerRect() {
1676 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191677}
1678
[email protected]fa7b1dc2010-06-23 17:53:041679void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261680 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041681 const std::vector<WebCompositionUnderline>& underlines,
1682 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131683 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281684 return;
[email protected]66fca5bc2013-05-23 06:58:291685 ImeEventGuard guard(this);
andresantoso28025f2c02015-07-21 21:46:111686 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_,
1687 true);
[email protected]88dbe32f2013-06-20 23:31:361688 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041689 text, WebVector<WebCompositionUnderline>(underlines),
1690 selection_start, selection_end)) {
1691 // If we failed to set the composition text, then we need to let the browser
1692 // process to cancel the input method's ongoing composition session, to make
1693 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221694 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261695 }
[email protected]88dbe32f2013-06-20 23:31:361696 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041697}
1698
[email protected]fcf75d42013-12-03 20:11:261699void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511700 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021701 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131702 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041703 return;
[email protected]66fca5bc2013-05-23 06:58:291704 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041705 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021706 if (text.length())
1707 webwidget_->confirmComposition(text);
1708 else if (keep_selection)
1709 webwidget_->confirmComposition(WebWidget::KeepSelection);
1710 else
1711 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041712 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361713 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291714}
1715
[email protected]0bc1f572013-04-17 01:46:311716void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121717 // During shutdown we can just ignore this message.
1718 if (!webwidget_)
1719 return;
1720
[email protected]0bc1f572013-04-17 01:46:311721 // Even if the browser provides an empty damage rect, it's still expecting to
1722 // receive a repaint ack so just damage the entire widget bounds.
1723 if (size_to_paint.IsEmpty()) {
1724 size_to_paint = size_;
1725 }
1726
[email protected]ec7dc112008-08-06 05:30:121727 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051728 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311729 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121730}
1731
[email protected]79fa22e2013-08-23 15:18:121732void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351733 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1734
1735 pending_synthetic_gesture_callbacks_.front().Run();
1736 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271737}
1738
[email protected]4873c7d2009-07-16 06:36:281739void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111740 if (!webwidget_)
1741 return;
[email protected]4873c7d2009-07-16 06:36:281742 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111743}
1744
[email protected]80ad8622012-11-07 16:33:031745void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1746 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511747 if (screen_metrics_emulator_) {
1748 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1749 view_screen_rect, window_screen_rect);
1750 } else {
1751 view_screen_rect_ = view_screen_rect;
1752 window_screen_rect_ = window_screen_rect;
1753 }
[email protected]80ad8622012-11-07 16:33:031754 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1755}
1756
kenrbb4e2a3b2015-05-14 15:05:051757void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1758 if (compositor_)
1759 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1760}
1761
[email protected]adb362312014-06-28 06:04:241762void RenderWidget::showImeIfNeeded() {
1763 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131764}
1765
[email protected]adb362312014-06-28 06:04:241766void RenderWidget::OnShowImeIfNeeded() {
1767#if defined(OS_ANDROID) || defined(USE_AURA)
1768 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1769#endif
rouslanf7ebd8832015-01-22 01:54:141770
1771// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1772// virtual keyboard.
1773#if !defined(OS_ANDROID)
1774 FocusChangeComplete();
1775#endif
[email protected]adb362312014-06-28 06:04:241776}
1777
1778#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131779void RenderWidget::IncrementOutstandingImeEventAcks() {
1780 ++outstanding_ime_acks_;
1781}
1782
1783void RenderWidget::OnImeEventAck() {
1784 --outstanding_ime_acks_;
1785 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511786}
[email protected]105dffb42013-02-20 03:46:211787#endif
1788
[email protected]0d1ebed12013-08-05 22:01:131789bool RenderWidget::ShouldHandleImeEvent() {
1790#if defined(OS_ANDROID)
1791 return !!webwidget_ && outstanding_ime_acks_ == 0;
1792#else
1793 return !!webwidget_;
1794#endif
1795}
1796
[email protected]c27dd4f2014-05-22 18:05:191797bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1798 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521799 // If we pause multiple times during a single mouse move event, we should
1800 // only send ACK once.
1801 if (!ignore_ack_for_mouse_move_from_debugger_) {
lanweif1a22832015-05-19 17:24:101802 InputEventAck ack(handling_event_type_, INPUT_EVENT_ACK_STATE_CONSUMED);
[email protected]5fea4a52014-05-27 00:17:521803 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dgozmanb739185d2015-04-10 15:04:021804 return true;
[email protected]5fea4a52014-05-27 00:17:521805 }
[email protected]c27dd4f2014-05-22 18:05:191806 }
1807 return false;
1808}
1809
1810void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1811 ignore_ack_for_mouse_move_from_debugger_ = true;
1812}
1813
[email protected]468ac582012-11-20 00:53:191814void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1815 if (device_scale_factor_ == device_scale_factor)
1816 return;
1817
1818 device_scale_factor_ = device_scale_factor;
jdduke491a3f0c2015-06-15 23:30:261819 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191820}
1821
[email protected]28ed6b32014-06-08 02:16:271822bool RenderWidget::SetDeviceColorProfile(
1823 const std::vector<char>& color_profile) {
1824 if (device_color_profile_ == color_profile)
1825 return false;
1826
1827 device_color_profile_ = color_profile;
1828 return true;
1829}
1830
noeldb4df152014-09-16 17:45:201831void RenderWidget::ResetDeviceColorProfileForTesting() {
1832 if (!device_color_profile_.empty())
1833 device_color_profile_.clear();
1834 device_color_profile_.push_back('0');
1835}
1836
[email protected]fcdc5642014-05-09 14:32:241837void RenderWidget::OnOrientationChange() {
1838}
1839
[email protected]ceb36f7d2012-10-31 18:33:241840gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521841 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241842 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521843}
1844
[email protected]bee16aab2009-08-26 15:55:031845void RenderWidget::SetHidden(bool hidden) {
1846 if (is_hidden_ == hidden)
1847 return;
1848
jdduke8fac9d102014-12-20 02:40:131849 // The status has changed. Tell the RenderThread about it and ensure
1850 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031851 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131852 FlushPendingInputEventAck();
1853
[email protected]bee16aab2009-08-26 15:55:031854 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001855 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031856 else
[email protected]b2db9272014-01-10 17:42:001857 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031858}
1859
[email protected]2b624c562011-10-27 22:58:261860void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261861 if (!webwidget_)
1862 return;
1863
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121864 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261865 webwidget_->willExitFullScreen();
1866 } else {
1867 webwidget_->willEnterFullScreen();
1868 }
[email protected]2b624c562011-10-27 22:58:261869}
1870
1871void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261872 if (!webwidget_)
1873 return;
1874
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121875 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261876 webwidget_->didEnterFullScreen();
1877 } else {
1878 webwidget_->didExitFullScreen();
1879 }
[email protected]2b624c562011-10-27 22:58:261880}
1881
[email protected]674741932009-02-04 23:44:461882bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051883 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461884}
1885
[email protected]674741932009-02-04 23:44:461886void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051887 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461888}
1889
[email protected]674741932009-02-04 23:44:461890void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051891 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461892}
1893
[email protected]b18583c2012-12-18 06:55:271894static bool IsDateTimeInput(ui::TextInputType type) {
1895 return type == ui::TEXT_INPUT_TYPE_DATE ||
1896 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1897 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1898 type == ui::TEXT_INPUT_TYPE_MONTH ||
1899 type == ui::TEXT_INPUT_TYPE_TIME ||
1900 type == ui::TEXT_INPUT_TYPE_WEEK;
1901}
1902
[email protected]66fca5bc2013-05-23 06:58:291903
1904void RenderWidget::StartHandlingImeEvent() {
1905 DCHECK(!handling_ime_event_);
1906 handling_ime_event_ = true;
1907}
1908
1909void RenderWidget::FinishHandlingImeEvent() {
1910 DCHECK(handling_ime_event_);
1911 handling_ime_event_ = false;
1912 // While handling an ime event, text input state and selection bounds updates
1913 // are ignored. These must explicitly be updated once finished handling the
1914 // ime event.
1915 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471916#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361917 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471918#endif
[email protected]66fca5bc2013-05-23 06:58:291919}
1920
shuchen3517bb62014-10-15 03:55:571921void RenderWidget::UpdateTextInputType() {
shuchen3517bb62014-10-15 03:55:571922 ui::TextInputType new_type = GetTextInputType();
1923 if (IsDateTimeInput(new_type))
1924 return; // Not considered as a text input field in WebKit/Chromium.
1925
1926 bool new_can_compose_inline = CanComposeInline();
1927
1928 blink::WebTextInputInfo new_info;
1929 if (webwidget_)
1930 new_info = webwidget_->textInputInfo();
1931 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201932 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571933
1934 if (text_input_type_ != new_type
1935 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201936 || text_input_mode_ != new_mode
1937 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571938 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1939 new_type,
1940 new_mode,
shuchen82ce8c52014-10-23 01:55:201941 new_can_compose_inline,
1942 new_flags));
shuchen3517bb62014-10-15 03:55:571943 text_input_type_ = new_type;
1944 can_compose_inline_ = new_can_compose_inline;
1945 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201946 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571947 }
1948}
1949
1950#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361951void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1952 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501953 if (handling_ime_event_)
1954 return;
[email protected]ad26ef42011-06-17 07:59:451955 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271956 if (IsDateTimeInput(new_type))
1957 return; // Not considered as a text input field in WebKit/Chromium.
1958
[email protected]180ef242013-11-07 06:50:461959 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211960 if (webwidget_)
1961 new_info = webwidget_->textInputInfo();
1962
[email protected]ad26ef42011-06-17 07:59:451963 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211964
[email protected]3306f262012-09-21 19:20:421965 // Only sends text input params if they are changed or if the ime should be
1966 // shown.
[email protected]90f24152014-04-09 12:41:361967 if (show_ime == SHOW_IME_IF_NEEDED ||
1968 (text_input_type_ != new_type ||
1969 text_input_info_ != new_info ||
1970 can_compose_inline_ != new_can_compose_inline)
1971#if defined(OS_ANDROID)
1972 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021973#endif
[email protected]90f24152014-04-09 12:41:361974 ) {
1975 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211976 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401977 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211978 p.value = new_info.value.utf8();
1979 p.selection_start = new_info.selectionStart;
1980 p.selection_end = new_info.selectionEnd;
1981 p.composition_start = new_info.compositionStart;
1982 p.composition_end = new_info.compositionEnd;
1983 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361984 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1985#if defined(USE_AURA)
1986 p.is_non_ime_change = true;
1987#endif
[email protected]183e28d2014-01-20 18:18:021988#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361989 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1990 text_field_is_dirty_;
1991 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131992 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361993 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021994#endif
shuchen3517bb62014-10-15 03:55:571995#if defined(USE_AURA)
1996 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1997 new_type,
1998 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:201999 new_can_compose_inline,
2000 new_info.flags));
shuchen3517bb62014-10-15 03:55:572001#endif
[email protected]5b739cb2012-08-21 20:35:212002 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2003
2004 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042005 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452006 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:202007 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:292008 }
initial.commit09911bf2008-07-26 23:55:292009}
shuchen3517bb62014-10-15 03:55:572010#endif
initial.commit09911bf2008-07-26 23:55:292011
[email protected]7c8873e2013-02-05 08:03:012012void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2013 WebRect focus_webrect;
2014 WebRect anchor_webrect;
2015 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2016 *focus = focus_webrect;
2017 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322018}
2019
[email protected]e99ef6f2011-10-16 01:13:002020void RenderWidget::UpdateSelectionBounds() {
2021 if (!webwidget_)
2022 return;
[email protected]66fca5bc2013-05-23 06:58:292023 if (handling_ime_event_)
2024 return;
[email protected]e99ef6f2011-10-16 01:13:002025
jddukeacf809e2014-09-23 20:38:382026 // With composited selection updates, the selection bounds will be reported
2027 // directly by the compositor, in which case explicit IPC selection
2028 // notifications should be suppressed.
2029 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
2030 ViewHostMsg_SelectionBounds_Params params;
2031 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2032 if (selection_anchor_rect_ != params.anchor_rect ||
2033 selection_focus_rect_ != params.focus_rect) {
2034 selection_anchor_rect_ = params.anchor_rect;
2035 selection_focus_rect_ = params.focus_rect;
2036 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2037 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2038 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2039 }
[email protected]58b48a0d2012-06-13 07:01:352040 }
jddukeacf809e2014-09-23 20:38:382041
[email protected]88dbe32f2013-06-20 23:31:362042 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002043}
2044
[email protected]180ef242013-11-07 06:50:462045// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172046#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2047 static_assert(int(blink::WebTextInputType##a) \
2048 == int(ui::TEXT_INPUT_TYPE_##b), \
2049 "mismatching enums: " #a)
2050
2051STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2052STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2053STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2054STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2055STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2056STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2057STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2058STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2059STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2060STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2061STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2062STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2063STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2064STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2065STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2066STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2067STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452068
[email protected]5b739cb2012-08-21 20:35:212069ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462070 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212071 // Check the type is in the range representable by ui::TextInputType.
2072 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462073 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212074 return static_cast<ui::TextInputType>(type);
2075}
2076
[email protected]ad26ef42011-06-17 07:59:452077ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272078 if (webwidget_)
2079 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452080 return ui::TEXT_INPUT_TYPE_NONE;
2081}
2082
[email protected]501ea13d2013-07-09 17:03:292083void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302084#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112085 // TODO(yukawa): Start sending character bounds when the browser side
2086 // implementation becomes ready (crbug.com/424866).
2087#else
[email protected]db4fc1e2013-09-06 20:01:512088 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292089 if (should_update_range) {
2090 GetCompositionRange(&range);
2091 } else {
2092 range = composition_range_;
2093 }
2094 std::vector<gfx::Rect> character_bounds;
2095 GetCompositionCharacterBounds(&character_bounds);
2096
2097 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2098 return;
2099 composition_character_bounds_ = character_bounds;
2100 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222101 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292102 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112103#endif
[email protected]501ea13d2013-07-09 17:03:292104}
2105
[email protected]58b48a0d2012-06-13 07:01:352106void RenderWidget::GetCompositionCharacterBounds(
2107 std::vector<gfx::Rect>* bounds) {
2108 DCHECK(bounds);
2109 bounds->clear();
2110}
2111
[email protected]db4fc1e2013-09-06 20:01:512112void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362113 size_t location, length;
2114 if (webwidget_->compositionRange(&location, &length)) {
2115 range->set_start(location);
2116 range->set_end(location + length);
2117 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2118 range->set_start(location);
2119 range->set_end(location + length);
2120 } else {
[email protected]db4fc1e2013-09-06 20:01:512121 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362122 }
2123}
2124
[email protected]501ea13d2013-07-09 17:03:292125bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512126 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292127 const std::vector<gfx::Rect>& bounds) {
2128 if (composition_range_ != range)
2129 return true;
2130 if (bounds.size() != composition_character_bounds_.size())
2131 return true;
2132 for (size_t i = 0; i < bounds.size(); ++i) {
2133 if (bounds[i] != composition_character_bounds_[i])
2134 return true;
2135 }
2136 return false;
2137}
[email protected]501ea13d2013-07-09 17:03:292138
[email protected]a4f0d882014-05-01 23:48:102139#if defined(OS_ANDROID)
2140void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2141 // If not initialized, default to white. Note that 0 is different from black
2142 // as black still has alpha 0xFF.
2143 if (!bg_color)
2144 bg_color = SK_ColorWHITE;
2145
2146 if (bg_color != body_background_color_) {
2147 body_background_color_ = bg_color;
2148 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2149 }
2150}
timav7a5032e2014-12-05 01:59:432151
2152bool RenderWidget::DoesRecordFullLayer() const {
2153 SynchronousCompositorFactory* synchronous_compositor_factory =
2154 SynchronousCompositorFactory::GetInstance();
2155
2156 // We assume that the absence of synchronous_compositor_factory
2157 // means we are in Chrome. In chrome, we want to clip, i.e.
2158 // *not* to record the full layer.
2159 if (!synchronous_compositor_factory)
2160 return false;
2161
2162 return synchronous_compositor_factory->RecordFullLayer();
2163}
[email protected]a4f0d882014-05-01 23:48:102164#endif
2165
[email protected]ad26ef42011-06-17 07:59:452166bool RenderWidget::CanComposeInline() {
2167 return true;
[email protected]56ea1a62011-05-30 07:05:572168}
2169
[email protected]4873c7d2009-07-16 06:36:282170WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042171 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282172}
2173
[email protected]f660d9c2012-06-06 18:31:212174float RenderWidget::deviceScaleFactor() {
2175 return device_scale_factor_;
2176}
2177
[email protected]fa7b1dc2010-06-23 17:53:042178void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022179 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042180 // If the last text input type is not None, then we should finish any
2181 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452182 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042183 // If a composition text exists, then we need to let the browser process
2184 // to cancel the input method's ongoing composition session.
2185 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222186 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042187 }
[email protected]d4cff272011-05-02 15:46:012188
[email protected]88dbe32f2013-06-20 23:31:362189 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042190}
2191
donnda070f3c2015-01-16 19:54:112192#if defined(OS_ANDROID)
2193void RenderWidget::showUnhandledTapUIIfNeeded(
2194 const WebPoint& tapped_position,
2195 const WebNode& tapped_node,
2196 bool page_changed) {
2197 DCHECK(handling_input_event_);
2198 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372199 !tapped_node.isContentEditable() &&
2200 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112201 if (should_trigger) {
2202 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2203 tapped_position.x, tapped_position.y));
2204 }
2205}
2206#endif
2207
[email protected]c68c3e4e2013-01-24 00:36:562208void RenderWidget::didHandleGestureEvent(
2209 const WebGestureEvent& event,
2210 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022211#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562212 if (event_cancelled)
2213 return;
[email protected]07c70d22014-08-21 08:33:462214 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362215 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462216 } else if (event.type == WebInputEvent::GestureLongPress) {
2217 DCHECK(webwidget_);
2218 if (webwidget_->textInputInfo().value.isEmpty())
2219 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2220 else
2221 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562222 }
2223#endif
2224}
2225
sataya.m582c9ce2015-06-09 08:03:422226void RenderWidget::didOverscroll(
2227 const blink::WebFloatSize& unusedDelta,
2228 const blink::WebFloatSize& accumulatedRootOverScroll,
2229 const blink::WebFloatPoint& position,
2230 const blink::WebFloatSize& velocity) {
2231 DidOverscrollParams params;
sataya.m582c9ce2015-06-09 08:03:422232 params.accumulated_overscroll = gfx::Vector2dF(
2233 accumulatedRootOverScroll.width, accumulatedRootOverScroll.height);
2234 params.latest_overscroll_delta =
2235 gfx::Vector2dF(unusedDelta.width, unusedDelta.height);
sataya.ma5cc13a2015-06-13 11:06:022236 // TODO(sataya.m): don't negate velocity once http://crbug.com/499743 is
2237 // fixed.
sataya.m582c9ce2015-06-09 08:03:422238 params.current_fling_velocity =
sataya.ma5cc13a2015-06-13 11:06:022239 gfx::Vector2dF(-velocity.width, -velocity.height);
sataya.m582c9ce2015-06-09 08:03:422240 params.causal_event_viewport_point = gfx::PointF(position.x, position.y);
jddukec05612b2015-06-25 23:13:182241
2242 // If we're currently handling an event, stash the overscroll data such that
2243 // it can be bundled in the event ack.
2244 if (handling_event_overscroll_) {
2245 handling_event_overscroll_->reset(new DidOverscrollParams(params));
2246 return;
2247 }
2248
sataya.m582c9ce2015-06-09 08:03:422249 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
2250}
2251
[email protected]7912e822014-04-16 02:37:032252void RenderWidget::StartCompositor() {
2253 // For widgets that are never visible, we don't need the compositor to run
2254 // at all.
2255 if (never_visible_)
2256 return;
danakj6e3bf8012014-12-16 18:27:532257 // In tests without a RenderThreadImpl, don't set ready as this kicks
2258 // off creating output surfaces that the test can't create.
2259 if (!RenderThreadImpl::current())
2260 return;
danakj018271e32014-12-16 21:17:262261 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032262}
2263
[email protected]29e2fb42013-07-19 01:13:472264void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292265 size_t i = 0;
2266 for (; i < plugin_window_moves_.size(); ++i) {
2267 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582268 if (move.rects_valid) {
2269 plugin_window_moves_[i] = move;
2270 } else {
2271 plugin_window_moves_[i].visible = move.visible;
2272 }
initial.commit09911bf2008-07-26 23:55:292273 break;
2274 }
2275 }
2276
2277 if (i == plugin_window_moves_.size())
2278 plugin_window_moves_.push_back(move);
2279}
[email protected]268654772009-08-06 23:02:042280
2281void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2282 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2283 i != plugin_window_moves_.end(); ++i) {
2284 if (i->window == window) {
2285 plugin_window_moves_.erase(i);
2286 break;
2287 }
2288 }
2289}
[email protected]67bfb83f2011-09-22 03:36:372290
[email protected]63b465922012-09-06 02:04:522291
[email protected]24ed0432013-04-24 07:50:312292RenderWidgetCompositor* RenderWidget::compositor() const {
2293 return compositor_.get();
2294}
2295
[email protected]180ef242013-11-07 06:50:462296bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372297 return false;
2298}
[email protected]c3d45532011-10-07 19:20:402299
[email protected]41d86852012-11-07 12:23:242300bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462301 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242302 return false;
2303}
2304
ccamerona7644752014-12-30 01:16:312305void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312306 const blink::WebMouseWheelEvent& wheel_event,
sataya.mf405d0e2015-07-07 16:51:112307 const gfx::Vector2dF& wheel_unused_delta,
ccamerond4ba47902014-12-17 07:20:312308 bool event_processed) {
ccamerona7644752014-12-30 01:16:312309 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312310 return;
2311
ccamerond4ba47902014-12-17 07:20:312312 cc::InputHandlerScrollResult scroll_result;
sataya.mf405d0e2015-07-07 16:51:112313 scroll_result.did_scroll = event_processed;
2314 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
2315 scroll_result.unused_scroll_delta = wheel_unused_delta;
ccamerond4ba47902014-12-17 07:20:312316
2317 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2318 InputHandlerManager* input_handler_manager =
2319 render_thread ? render_thread->input_handler_manager() : NULL;
2320 if (input_handler_manager) {
2321 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2322 routing_id_, wheel_event, scroll_result);
2323 }
2324}
2325
[email protected]ce6689f2013-03-29 12:52:552326void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2327 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2328}
2329
mostynbe29b6882015-01-13 09:59:172330// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2331#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2332 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2333 "mismatching enums: " #a)
2334
dtapuskaa98ac8d72015-05-08 19:29:092335inline content::TouchAction& operator|=(content::TouchAction& a,
2336 content::TouchAction b) {
2337 a = static_cast<content::TouchAction>(static_cast<int>(a) |
2338 static_cast<int>(b));
2339 return a;
2340}
2341
[email protected]5d0bbdfa92013-12-10 00:35:512342void RenderWidget::setTouchAction(
2343 blink::WebTouchAction web_touch_action) {
2344
2345 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2346 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192347 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512348 return;
2349
dtapuskaa98ac8d72015-05-08 19:29:092350 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172351 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2352 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092353 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2354 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172355 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092356 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2357 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172358 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2359 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362360
2361 content::TouchAction content_touch_action =
2362 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512363 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2364}
2365
[email protected]90f24152014-04-09 12:41:362366void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2367#if defined(OS_ANDROID)
2368 text_field_is_dirty_ = true;
2369#endif
2370}
2371
[email protected]3d5c243b2012-11-30 00:26:012372bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2373 return true;
2374}
2375
[email protected]0634cdd42013-08-16 00:46:092376scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132377RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592378 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092379 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492380 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222381 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092382 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292383 if (!RenderThreadImpl::current())
2384 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402385 CauseForGpuLaunch cause =
2386 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292387 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402388 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222389 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292390 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592391
[email protected]828a3932014-04-02 14:43:132392 // Explicitly disable antialiasing for the compositor. As of the time of
2393 // this writing, the only platform that supported antialiasing for the
2394 // compositor was Mac OS X, because the on-screen OpenGL context creation
2395 // code paths on Windows and Linux didn't yet have multisampling support.
2396 // Mac OS X essentially always behaves as though it's rendering offscreen.
2397 // Multisampling has a heavy cost especially on devices with relatively low
2398 // fill rate like most notebooks, and the Mac implementation would need to
2399 // be optimized to resolve directly into the IOSurface shared between the
2400 // GPU and browser processes. For these reasons and to avoid platform
2401 // disparities we explicitly disable antialiasing.
2402 blink::WebGraphicsContext3D::Attributes attributes;
2403 attributes.antialias = false;
2404 attributes.shareResources = true;
2405 attributes.noAutomaticFlushes = true;
2406 attributes.depth = false;
2407 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132408 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292409 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012410#if defined(OS_ANDROID)
2411 // If we raster too fast we become upload bound, and pending
2412 // uploads consume memory. For maximum upload throughput, we would
2413 // want to allow for upload_throughput * pipeline_time of pending
2414 // uploads, after which we are just wasting memory. Since we don't
2415 // know our upload throughput yet, this just caps our memory usage.
2416 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272417 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032418 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012419 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032420 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012421 // Deadline to draw a frame to achieve 60 frames per second.
2422 const size_t kMillisecondsPerFrame = 16;
2423 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032424 size_t max_transfer_buffer_usage_mb =
2425 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2426 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012427 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2428 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292429 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032430 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012431#endif
[email protected]96ab016c2013-10-23 00:50:292432
[email protected]96ab016c2013-10-23 00:50:292433 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132434 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2435 GetURLForGraphicsContext3D(),
2436 gpu_channel_host.get(),
2437 attributes,
[email protected]828a3932014-04-02 14:43:132438 lose_context_when_out_of_memory,
2439 limits,
2440 NULL));
[email protected]0634cdd42013-08-16 00:46:092441 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592442}
2443
[email protected]e3244ed2014-06-20 20:04:272444void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2445 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162446}
2447
[email protected]e3244ed2014-06-20 20:04:272448void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2449 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162450}
2451
[email protected]de3c5d82014-05-28 22:12:592452void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2453 render_frames_.AddObserver(frame);
2454}
2455
2456void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2457 render_frames_.RemoveObserver(frame);
2458}
2459
[email protected]a017938b2014-05-27 21:17:172460#if defined(VIDEO_HOLE)
2461void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2462 video_hole_frames_.AddObserver(frame);
2463}
2464
2465void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2466 video_hole_frames_.RemoveObserver(frame);
2467}
2468#endif // defined(VIDEO_HOLE)
2469
[email protected]e9ff79c2012-10-19 21:31:262470} // namespace content