blob: d2d1e7d6590071b6445c9c06aaef5818353b27bb [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"
68#include "third_party/WebKit/public/web/WebPopupMenu.h"
69#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
70#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3871#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5972#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4173#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1374#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5075#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0976#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3277#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4878#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2779#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4180#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4881
[email protected]eeb93112013-05-01 19:41:1082#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1583#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0784#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1085#endif
86
[email protected]661eb9d2009-02-03 02:11:4887#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4988#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5289#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4190#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4891#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4492
[email protected]2255a9332013-06-17 05:12:3193#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2994
[email protected]180ef242013-11-07 06:50:4695using blink::WebCompositionUnderline;
96using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4397using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4698using blink::WebGestureEvent;
99using blink::WebInputEvent;
100using blink::WebKeyboardEvent;
101using blink::WebMouseEvent;
102using blink::WebMouseWheelEvent;
103using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11104using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46105using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11106using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46107using blink::WebPopupMenu;
108using blink::WebPopupMenuInfo;
109using blink::WebPopupType;
110using blink::WebRange;
111using blink::WebRect;
112using blink::WebScreenInfo;
113using blink::WebSize;
114using blink::WebTextDirection;
115using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25116using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46117using blink::WebVector;
118using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26119
[email protected]6a4d7f62013-01-07 21:32:13120namespace {
[email protected]b256eca2013-07-11 10:57:40121
122typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
123
124class TextInputModeMapSingleton {
125 public:
126 static TextInputModeMapSingleton* GetInstance() {
127 return Singleton<TextInputModeMapSingleton>::get();
128 }
[email protected]dd705d4d2013-11-27 08:14:41129 TextInputModeMapSingleton() {
130 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
131 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
132 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
133 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
134 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
135 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
136 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
137 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
138 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
139 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
140 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40141 }
[email protected]dd705d4d2013-11-27 08:14:41142 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40143 private:
[email protected]dd705d4d2013-11-27 08:14:41144 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40145
146 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
147
148 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
149};
150
[email protected]dd705d4d2013-11-27 08:14:41151ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40152 static TextInputModeMapSingleton* singleton =
153 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41154 TextInputModeMap::const_iterator it =
155 singleton->map().find(input_mode.utf8());
156 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40157 return ui::TEXT_INPUT_MODE_DEFAULT;
158 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13159}
[email protected]b256eca2013-07-11 10:57:40160
[email protected]fd847792013-10-24 17:12:35161// TODO(brianderson): Replace the hard-coded threshold with a fraction of
162// the BeginMainFrame interval.
163// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
164// be spent in input hanlders before input starts getting throttled.
165const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
166
jdduke07788062014-12-05 03:16:30167int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) {
168 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds))
169 .ToInternalValue();
170}
171
172void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now) {
173 UMA_HISTOGRAM_CUSTOM_COUNTS(
174 "Event.AggregatedLatency.Renderer2",
175 GetEventLatencyMicros(event, now),
176 1,
177 10000000,
178 100);
179
180#define CASE_TYPE(t) \
181 case WebInputEvent::t: \
182 UMA_HISTOGRAM_CUSTOM_COUNTS( \
183 "Event.Latency.Renderer2." #t, \
184 GetEventLatencyMicros(event, now), \
185 1, \
186 10000000, \
187 100); \
188 break;
189
190 switch(event.type) {
191 CASE_TYPE(Undefined);
192 CASE_TYPE(MouseDown);
193 CASE_TYPE(MouseUp);
194 CASE_TYPE(MouseMove);
195 CASE_TYPE(MouseEnter);
196 CASE_TYPE(MouseLeave);
197 CASE_TYPE(ContextMenu);
198 CASE_TYPE(MouseWheel);
199 CASE_TYPE(RawKeyDown);
200 CASE_TYPE(KeyDown);
201 CASE_TYPE(KeyUp);
202 CASE_TYPE(Char);
203 CASE_TYPE(GestureScrollBegin);
204 CASE_TYPE(GestureScrollEnd);
205 CASE_TYPE(GestureScrollUpdate);
206 CASE_TYPE(GestureFlingStart);
207 CASE_TYPE(GestureFlingCancel);
208 CASE_TYPE(GestureShowPress);
209 CASE_TYPE(GestureTap);
210 CASE_TYPE(GestureTapUnconfirmed);
211 CASE_TYPE(GestureTapDown);
212 CASE_TYPE(GestureTapCancel);
213 CASE_TYPE(GestureDoubleTap);
214 CASE_TYPE(GestureTwoFingerTap);
215 CASE_TYPE(GestureLongPress);
216 CASE_TYPE(GestureLongTap);
217 CASE_TYPE(GesturePinchBegin);
218 CASE_TYPE(GesturePinchEnd);
219 CASE_TYPE(GesturePinchUpdate);
220 CASE_TYPE(TouchStart);
221 CASE_TYPE(TouchMove);
222 CASE_TYPE(TouchEnd);
223 CASE_TYPE(TouchCancel);
224 default:
225 // Must include default to let blink::WebInputEvent add new event types
226 // before they're added here.
227 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event.type;
228 break;
229 }
230
231#undef CASE_TYPE
232}
233
[email protected]b256eca2013-07-11 10:57:40234} // namespace
235
[email protected]e9ff79c2012-10-19 21:31:26236namespace content {
[email protected]62cb33cae2009-03-27 23:30:22237
[email protected]b2e4c70132013-10-03 02:07:51238// RenderWidget::ScreenMetricsEmulator ----------------------------------------
239
240class RenderWidget::ScreenMetricsEmulator {
241 public:
242 ScreenMetricsEmulator(
243 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43244 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51245 virtual ~ScreenMetricsEmulator();
246
[email protected]19193682014-04-03 15:01:43247 // Scale and offset used to convert between host coordinates
248 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51249 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20250 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43251 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51252 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56253 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51254
255 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43256 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51257
258 // The following methods alter handlers' behavior for messages related to
259 // widget size and position.
260 void OnResizeMessage(const ViewMsg_Resize_Params& params);
261 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
262 const gfx::Rect& window_screen_rect);
263 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31264 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51265
266 private:
[email protected]19193682014-04-03 15:01:43267 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02268 void Apply(bool top_controls_shrink_blink_size,
269 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44270 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12271 bool is_fullscreen_granted,
272 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51273
274 RenderWidget* widget_;
275
[email protected]7f99fc22013-11-08 14:05:58276 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43277 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51278
[email protected]a179d3962013-11-12 14:44:40279 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51280 float scale_;
dgozman9260b0a12015-03-16 13:45:20281 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51282
[email protected]19193682014-04-03 15:01:43283 // Widget rect as passed to webwidget.
284 gfx::Rect applied_widget_rect_;
285
[email protected]b2e4c70132013-10-03 02:07:51286 // Original values to restore back after emulation ends.
287 gfx::Size original_size_;
288 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28289 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46290 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51291 gfx::Rect original_view_screen_rect_;
292 gfx::Rect original_window_screen_rect_;
293};
294
295RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
296 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43297 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51298 : widget_(widget),
[email protected]19193682014-04-03 15:01:43299 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51300 scale_(1.f) {
301 original_size_ = widget_->size_;
302 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28303 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51304 original_screen_info_ = widget_->screen_info_;
305 original_view_screen_rect_ = widget_->view_screen_rect_;
306 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02307 Apply(widget_->top_controls_shrink_blink_size_,
308 widget_->top_controls_height_,
309 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12310 widget_->is_fullscreen_granted_,
311 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51312}
313
314RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
315 widget_->screen_info_ = original_screen_info_;
316
317 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20318 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51319 widget_->view_screen_rect_ = original_view_screen_rect_;
320 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01321 widget_->Resize(original_size_,
322 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02323 widget_->top_controls_shrink_blink_size_,
324 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01325 original_visible_viewport_size_,
326 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12327 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12328 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01329 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51330}
331
332void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43333 const WebDeviceEmulationParams& params) {
334 params_ = params;
335 Reapply();
336}
337
338void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02339 Apply(widget_->top_controls_shrink_blink_size_,
340 widget_->top_controls_height_,
341 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12342 widget_->is_fullscreen_granted_,
343 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51344}
345
[email protected]19193682014-04-03 15:01:43346void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02347 bool top_controls_shrink_blink_size,
348 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44349 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12350 bool is_fullscreen_granted,
351 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31352 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
353 if (!applied_widget_rect_.width())
354 applied_widget_rect_.set_width(original_size_.width());
355 if (!applied_widget_rect_.height())
356 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43357
[email protected]f442ee42014-05-14 11:53:12358 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02359 int original_width = std::max(original_size_.width(), 1);
360 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51361 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02362 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51363 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02364 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51365 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
366 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01367
368 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43369 offset_.set_x(
370 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01371 offset_.set_y(
[email protected]19193682014-04-03 15:01:43372 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51373 } else {
[email protected]0b3578c2014-06-20 18:29:02374 scale_ = params_.scale;
375 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01376 }
[email protected]7f0e8fa2014-03-26 12:32:01377
[email protected]19193682014-04-03 15:01:43378 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
379 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01380 widget_->screen_info_.rect = original_screen_info_.rect;
381 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
382 widget_->window_screen_rect_ = original_window_screen_rect_;
383 } else {
[email protected]19193682014-04-03 15:01:43384 applied_widget_rect_.set_origin(gfx::Point(0, 0));
385 widget_->screen_info_.rect = applied_widget_rect_;
386 widget_->screen_info_.availableRect = applied_widget_rect_;
387 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01388 }
[email protected]a179d3962013-11-12 14:44:40389
[email protected]19193682014-04-03 15:01:43390 float applied_device_scale_factor = params_.deviceScaleFactor ?
391 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01392 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51393
[email protected]7f99fc22013-11-08 14:05:58394 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51395 // - we keep the real device scale factor in compositor to produce sharp image
396 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58397 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51398 // root layer.
dgozman9260b0a12015-03-16 13:45:20399 blink::WebDeviceEmulationParams modified_params = params_;
400 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
401 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
402 modified_params.scale = scale_;
403 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51404
[email protected]7f0e8fa2014-03-26 12:32:01405 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43406 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51407
408 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
409 original_size_, original_screen_info_.deviceScaleFactor));
dtrainorcb7779b82014-12-04 01:08:02410 widget_->Resize(applied_widget_rect_.size(),
411 physical_backing_size,
412 top_controls_shrink_blink_size,
413 top_controls_height,
414 applied_widget_rect_.size(),
415 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12416 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12417 display_mode,
dtrainorcb7779b82014-12-04 01:08:02418 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51419}
420
421void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
422 const ViewMsg_Resize_Params& params) {
423 bool need_ack = params.new_size != original_size_ &&
424 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
425 original_size_ = params.new_size;
426 original_physical_backing_size_ = params.physical_backing_size;
427 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28428 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02429 Apply(params.top_controls_shrink_blink_size,
430 params.top_controls_height,
431 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12432 params.is_fullscreen_granted,
433 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51434
435 if (need_ack) {
436 widget_->set_next_paint_is_resize_ack();
437 if (widget_->compositor_)
438 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
439 }
440}
441
442void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
443 const gfx::Rect& view_screen_rect,
444 const gfx::Rect& window_screen_rect) {
445 original_view_screen_rect_ = view_screen_rect;
446 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43447 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
448 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51449}
450
451void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
452 ContextMenuParams* params) {
453 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40454 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51455 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40456 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51457}
458
[email protected]2d6836f42014-07-02 17:25:31459gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
460 const gfx::Rect& anchor) {
461 gfx::Rect scaled = gfx::ToEnclosedRect(gfx::ScaleRect(anchor, scale_));
462 scaled.set_x(scaled.x() + offset_.x());
463 scaled.set_y(scaled.y() + offset_.y());
464 return scaled;
465}
466
[email protected]b2e4c70132013-10-03 02:07:51467// RenderWidget ---------------------------------------------------------------
468
[email protected]180ef242013-11-07 06:50:46469RenderWidget::RenderWidget(blink::WebPopupType popup_type,
470 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04471 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03472 bool hidden,
473 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29474 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56475 surface_id_(0),
danakj6e3bf8012014-12-16 18:27:53476 compositor_deps_(nullptr),
477 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29478 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30479 init_complete_(false),
dtrainorcb7779b82014-12-04 01:08:02480 top_controls_shrink_blink_size_(false),
481 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29482 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51483 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09484 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29485 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04486 is_hidden_(hidden),
[email protected]7912e822014-04-16 02:37:03487 never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12488 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12489 display_mode_(blink::WebDisplayModeUndefined),
initial.commit09911bf2008-07-26 23:55:29490 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49491 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50492 handling_ime_event_(false),
[email protected]c27dd4f2014-05-22 18:05:19493 handling_event_type_(WebInputEvent::Undefined),
494 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48495 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22496 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44497 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20498 for_oopif_(false),
[email protected]fa7b1dc2010-06-23 17:53:04499 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45500 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40501 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20502 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53503 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12504 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48505 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12506 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04507 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52508 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]8062ab262014-05-27 16:56:43509 current_event_latency_info_(NULL),
[email protected]53b4cc12013-07-18 23:02:30510 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13511#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36512 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13513 outstanding_ime_acks_(0),
[email protected]a4f0d882014-05-01 23:48:10514 body_background_color_(SK_ColorWHITE),
[email protected]0d1ebed12013-08-05 22:01:13515#endif
[email protected]b2e4c70132013-10-03 02:07:51516 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11517 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42518 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51519 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
520 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05521 if (!swapped_out)
522 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27523 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53524 device_color_profile_.push_back('0');
initial.commit09911bf2008-07-26 23:55:29525}
526
527RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11528 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16529
[email protected]992db4c2011-05-12 15:37:15530 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02531 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15532 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29533}
534
[email protected]484955942010-08-19 16:13:18535// static
[email protected]8085dbc82008-09-26 22:53:44536RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53537 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46538 blink::WebPopupType popup_type,
539 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29540 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41541 scoped_refptr<RenderWidget> widget(
[email protected]7912e822014-04-16 02:37:03542 new RenderWidget(popup_type, screen_info, false, false, false));
danakj6e3bf8012014-12-16 18:27:53543 if (widget->Init(opener_id, compositor_deps)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46544 return widget.get();
[email protected]a635f942012-12-07 10:34:29545 }
546 return NULL;
initial.commit09911bf2008-07-26 23:55:29547}
548
[email protected]484955942010-08-19 16:13:18549// static
kenrba7199832015-01-22 23:44:59550RenderWidget* RenderWidget::CreateForFrame(
551 int routing_id,
552 int surface_id,
553 bool hidden,
554 const blink::WebScreenInfo& screen_info,
555 CompositorDependencies* compositor_deps,
556 blink::WebLocalFrame* frame) {
557 CHECK_NE(routing_id, MSG_ROUTING_NONE);
558 scoped_refptr<RenderWidget> widget(new RenderWidget(
559 blink::WebPopupTypeNone, screen_info, false, hidden, false));
560 widget->routing_id_ = routing_id;
561 widget->surface_id_ = surface_id;
562 widget->compositor_deps_ = compositor_deps;
simonhong628f9812015-04-27 23:13:20563 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59564 // DoInit increments the reference count on |widget|, keeping it alive after
565 // this function returns.
566 if (widget->DoInit(MSG_ROUTING_NONE, compositor_deps,
567 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
568 nullptr)) {
569 widget->CompleteInit();
570 return widget.get();
571 }
572 return nullptr;
573}
574
575// static
576blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18577 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46578 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18579 break;
[email protected]180ef242013-11-07 06:50:46580 case blink::WebPopupTypeSelect:
581 case blink::WebPopupTypeSuggestion:
[email protected]484955942010-08-19 16:13:18582 return WebPopupMenu::create(render_widget);
[email protected]180ef242013-11-07 06:50:46583 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44584 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18585 default:
586 NOTREACHED();
587 }
588 return NULL;
589}
590
kenrba7199832015-01-22 23:44:59591// static
592blink::WebWidget* RenderWidget::CreateWebFrameWidget(
593 RenderWidget* render_widget,
594 blink::WebLocalFrame* frame) {
595 return blink::WebFrameWidget::create(render_widget, frame);
596}
597
danakj6e3bf8012014-12-16 18:27:53598bool RenderWidget::Init(int32 opener_id,
599 CompositorDependencies* compositor_deps) {
600 return DoInit(opener_id, compositor_deps, RenderWidget::CreateWebWidget(this),
[email protected]a635f942012-12-07 10:34:29601 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
602 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18603}
604
[email protected]a635f942012-12-07 10:34:29605bool RenderWidget::DoInit(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53606 CompositorDependencies* compositor_deps,
[email protected]6a8ddba52010-09-05 04:38:06607 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18608 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29609 DCHECK(!webwidget_);
610
611 if (opener_id != MSG_ROUTING_NONE)
612 opener_id_ = opener_id;
613
danakj6e3bf8012014-12-16 18:27:53614 compositor_deps_ = compositor_deps;
[email protected]484955942010-08-19 16:13:18615 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29616
kenrba7199832015-01-22 23:44:59617 bool result = true;
618 if (create_widget_message)
619 result = RenderThread::Get()->Send(create_widget_message);
620
initial.commit09911bf2008-07-26 23:55:29621 if (result) {
[email protected]380244092011-10-07 17:26:27622 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29623 // Take a reference on behalf of the RenderThread. This will be balanced
624 // when we receive ViewMsg_Close.
625 AddRef();
[email protected]b2db9272014-01-10 17:42:00626 if (RenderThreadImpl::current()) {
627 RenderThreadImpl::current()->WidgetCreated();
628 if (is_hidden_)
629 RenderThreadImpl::current()->WidgetHidden();
630 }
[email protected]a635f942012-12-07 10:34:29631 return true;
initial.commit09911bf2008-07-26 23:55:29632 } else {
[email protected]a635f942012-12-07 10:34:29633 // The above Send can fail when the tab is closing.
634 return false;
initial.commit09911bf2008-07-26 23:55:29635 }
636}
637
[email protected]fc4404d2012-11-07 19:53:30638// This is used to complete pending inits and non-pending inits.
639void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29640 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29641
[email protected]fc4404d2012-11-07 19:53:30642 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42643
[email protected]7912e822014-04-16 02:37:03644 if (compositor_)
645 StartCompositor();
initial.commit09911bf2008-07-26 23:55:29646
[email protected]6de74452009-02-25 18:04:59647 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29648}
649
[email protected]992db4c2011-05-12 15:37:15650void RenderWidget::SetSwappedOut(bool is_swapped_out) {
651 // We should only toggle between states.
652 DCHECK(is_swapped_out_ != is_swapped_out);
653 is_swapped_out_ = is_swapped_out;
654
655 // If we are swapping out, we will call ReleaseProcess, allowing the process
656 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52657 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15658 // If we are swapping in, we call AddRefProcess to prevent the process from
659 // exiting.
[email protected]949b6592014-08-20 13:17:52660 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15661 RenderProcess::current()->AddRefProcess();
662}
663
[email protected]949b6592014-08-20 13:17:52664void RenderWidget::WasSwappedOut() {
665 // If we have been swapped out and no one else is using this process,
666 // it's safe to exit now.
667 CHECK(is_swapped_out_);
668 RenderProcess::current()->ReleaseProcess();
669}
670
[email protected]b2e4c70132013-10-03 02:07:51671void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
672 ScreenMetricsEmulator* emulator) {
673 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43674 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49675 popup_screen_origin_for_emulation_ = gfx::Point(
676 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
677 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56678 screen_info_ = emulator->original_screen_info();
679 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51680}
681
[email protected]2d6836f42014-07-02 17:25:31682gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
683 if (screen_metrics_emulator_)
684 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
685 return anchor;
686}
687
[email protected]b2e4c70132013-10-03 02:07:51688void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20689 bool enabled,
690 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51691 // This is only supported in RenderView.
692 NOTREACHED();
693}
694
[email protected]53907862014-03-25 15:42:40695#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51696void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
697 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49698 popup->SetOriginScaleAndOffsetForEmulation(
699 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51700}
[email protected]53907862014-03-25 15:42:40701#endif
[email protected]b2e4c70132013-10-03 02:07:51702
703void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
704 if (screen_metrics_emulator_)
705 screen_metrics_emulator_->OnShowContextMenu(params);
706}
707
[email protected]7d08a9352013-10-15 08:24:56708void RenderWidget::ScheduleCompositeWithForcedRedraw() {
709 if (compositor_) {
710 // Regardless of whether threaded compositing is enabled, always
711 // use this mechanism to force the compositor to redraw. However,
712 // the invalidation code path below is still needed for the
713 // non-threaded case.
714 compositor_->SetNeedsForcedRedraw();
715 }
[email protected]8b9e52b2014-01-17 16:35:31716 scheduleComposite();
[email protected]7d08a9352013-10-15 08:24:56717}
718
[email protected]a95986a82010-12-24 06:19:28719bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
720 bool handled = true;
721 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15722 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22723 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
724 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22725 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
726 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15727 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
728 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35729 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
730 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28731 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
732 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
733 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20734 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
735 OnEnableDeviceEmulation)
736 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
737 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41738 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54739 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28740 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41741 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]a95986a82010-12-24 06:19:28742 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
[email protected]37a241c2013-12-03 03:16:17743 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowShown, OnCandidateWindowShown)
744 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowUpdated,
745 OnCandidateWindowUpdated)
746 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowHidden, OnCandidateWindowHidden)
[email protected]3d9ec5052013-01-02 22:05:25747 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28748 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
749 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03750 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05751 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21752#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51753 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13754 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21755#endif
[email protected]a95986a82010-12-24 06:19:28756 IPC_MESSAGE_UNHANDLED(handled = false)
757 IPC_END_MESSAGE_MAP()
758 return handled;
759}
initial.commit09911bf2008-07-26 23:55:29760
761bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15762 // Don't send any messages after the browser has told us to close, and filter
763 // most outgoing messages while swapped out.
764 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26765 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11766 closing_) {
initial.commit09911bf2008-07-26 23:55:29767 delete message;
768 return false;
769 }
770
771 // If given a messsage without a routing ID, then assign our routing ID.
772 if (message->routing_id() == MSG_ROUTING_NONE)
773 message->set_routing_id(routing_id_);
774
[email protected]380244092011-10-07 17:26:27775 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44776}
777
[email protected]61e2b3cc2012-03-02 16:13:34778void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44779 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02780 bool top_controls_shrink_blink_size,
781 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44782 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34783 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12784 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12785 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58786 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56787 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48788 // A resize ack shouldn't be requested if we have not ACK'd the previous
789 // one.
790 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
791 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
792 }
initial.commit09911bf2008-07-26 23:55:29793
[email protected]61e2b3cc2012-03-02 16:13:34794 // Ignore this during shutdown.
795 if (!webwidget_)
796 return;
797
[email protected]d9083762013-03-24 01:36:40798 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44799 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40800 }
[email protected]60d47ac2013-03-01 23:42:44801
[email protected]dade8992013-03-04 07:34:34802 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02803 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
804 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28805 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34806 resizer_rect_ = resizer_rect;
807
808 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12809 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
[email protected]61e2b3cc2012-03-02 16:13:34810 if (fullscreen_change)
811 WillToggleFullscreen();
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12812 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12813 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34814
aelias6004fe02015-02-07 21:43:01815 webwidget_->setTopControlsHeight(top_controls_height,
816 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43817
[email protected]61e2b3cc2012-03-02 16:13:34818 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34819 size_ = new_size;
820
[email protected]61e2b3cc2012-03-02 16:13:34821 // When resizing, we want to wait to paint before ACK'ing the resize. This
822 // ensures that we only resize as fast as we can paint. We only need to
823 // send an ACK if we are resized to a non-empty rect.
824 webwidget_->resize(new_size);
[email protected]632c4382013-05-15 08:58:45825 }
826
[email protected]bb6378fe2014-04-28 21:19:44827 webwidget()->resizePinchViewport(gfx::Size(
828 visible_viewport_size.width(),
829 visible_viewport_size.height()));
830
[email protected]632c4382013-05-15 08:58:45831 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58832 // In this case there is no paint/composite and therefore no
833 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
834 // ack through a fake ViewHostMsg_UpdateRect or a different message.
835 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34836 }
837
[email protected]20fbfc22013-05-08 20:50:58838 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45839 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58840 set_next_paint_is_resize_ack();
841
[email protected]61e2b3cc2012-03-02 16:13:34842 if (fullscreen_change)
843 DidToggleFullscreen();
844
845 // If a resize ack is requested and it isn't set-up, then no more resizes will
846 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45847 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29848}
849
bokanc007c3a2015-02-03 07:15:56850void RenderWidget::SetWindowRectSynchronously(
851 const gfx::Rect& new_window_rect) {
852 Resize(new_window_rect.size(),
853 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02854 top_controls_shrink_blink_size_,
855 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56856 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01857 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12858 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12859 display_mode_,
[email protected]587941d2014-08-22 01:40:01860 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56861 view_screen_rect_ = new_window_rect;
862 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02863 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56864 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02865}
866
initial.commit09911bf2008-07-26 23:55:29867void RenderWidget::OnClose() {
868 if (closing_)
869 return;
dgozmancf9039cd2015-04-06 12:01:31870 NotifyOnClose();
initial.commit09911bf2008-07-26 23:55:29871 closing_ = true;
872
873 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03874 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27875 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03876 SetHidden(false);
rmcilroyaa296052015-04-14 15:35:27877 if (RenderThreadImpl::current())
878 RenderThreadImpl::current()->WidgetDestroyed();
[email protected]bee16aab2009-08-26 15:55:03879 }
initial.commit09911bf2008-07-26 23:55:29880
initial.commit09911bf2008-07-26 23:55:29881 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25882 // now. Post a task that only gets invoked when there are no nested message
883 // loops.
alexclarkee19d4ef2015-01-09 17:45:40884 RenderThread::Get()->GetTaskRunner()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29885 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25886
887 // Balances the AddRef taken when we called AddRoute.
888 Release();
initial.commit09911bf2008-07-26 23:55:29889}
890
[email protected]61e2b3cc2012-03-02 16:13:34891// Got a response from the browser after the renderer decided to create a new
892// view.
[email protected]fc4404d2012-11-07 19:53:30893void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34894 DCHECK(routing_id_ != MSG_ROUTING_NONE);
895
[email protected]fc4404d2012-11-07 19:53:30896 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34897}
898
[email protected]0fdd5012013-05-29 08:05:56899void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04900 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32901 return;
902
[email protected]b2e4c70132013-10-03 02:07:51903 if (screen_metrics_emulator_) {
904 screen_metrics_emulator_->OnResizeMessage(params);
905 return;
906 }
907
[email protected]fcdc5642014-05-09 14:32:24908 bool orientation_changed =
909 screen_info_.orientationAngle != params.screen_info.orientationAngle;
910
[email protected]0fdd5012013-05-29 08:05:56911 screen_info_ = params.screen_info;
912 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02913 Resize(params.new_size,
914 params.physical_backing_size,
915 params.top_controls_shrink_blink_size,
916 params.top_controls_height,
917 params.visible_viewport_size,
918 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12919 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12920 params.display_mode,
sievers4e33dae2015-02-25 20:43:58921 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24922
923 if (orientation_changed)
924 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29925}
926
dgozman9260b0a12015-03-16 13:45:20927void RenderWidget::OnEnableDeviceEmulation(
928 const blink::WebDeviceEmulationParams& params) {
929 if (!screen_metrics_emulator_)
930 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
931 else
932 screen_metrics_emulator_->ChangeEmulationParams(params);
933}
934
935void RenderWidget::OnDisableDeviceEmulation() {
936 screen_metrics_emulator_.reset();
937}
938
noel89949e62014-09-30 01:12:41939void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
940 SetDeviceColorProfile(color_profile);
941}
942
[email protected]b5913d72012-02-07 22:26:54943void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01944 if (resizer_rect_ == resizer_rect)
945 return;
946 resizer_rect_ = resizer_rect;
947 if (webwidget_)
948 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54949}
950
initial.commit09911bf2008-07-26 23:55:29951void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31952 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29953 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03954 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59955 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
956 WasHidden());
initial.commit09911bf2008-07-26 23:55:29957}
958
[email protected]3399dd822014-08-09 11:14:24959void RenderWidget::OnWasShown(bool needs_repainting,
960 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41961 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29962 // During shutdown we can just ignore this message.
963 if (!webwidget_)
964 return;
965
966 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03967 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59968 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
969 WasShown());
initial.commit09911bf2008-07-26 23:55:29970
[email protected]8a23afb32014-04-30 22:40:23971 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29972 return;
initial.commit09911bf2008-07-26 23:55:29973
974 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24975 if (compositor_) {
976 ui::LatencyInfo swap_latency_info(latency_info);
977 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
978 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05979 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24980 }
[email protected]aca33f4f2014-05-17 17:08:05981 scheduleComposite();
initial.commit09911bf2008-07-26 23:55:29982}
983
[email protected]53d3f302009-12-21 04:42:05984void RenderWidget::OnRequestMoveAck() {
985 DCHECK(pending_window_rect_count_);
986 pending_window_rect_count_--;
987}
988
[email protected]ed7defa2013-03-12 21:29:59989GURL RenderWidget::GetURLForGraphicsContext3D() {
990 return GURL();
[email protected]65225772011-05-12 21:10:24991}
992
[email protected]ebc0e1df2013-08-01 02:46:22993scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03994 // For widgets that are never visible, we don't start the compositor, so we
995 // never get a request for a cc::OutputSurface.
996 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19997
998#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01999 if (SynchronousCompositorFactory* factory =
1000 SynchronousCompositorFactory::GetInstance()) {
[email protected]586871b2014-07-22 17:05:111001 return factory->CreateOutputSurface(routing_id(),
1002 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:191003 }
1004#endif
1005
avi83883c82014-12-23 00:08:491006 const base::CommandLine& command_line =
1007 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:331008 bool use_software = fallback;
1009 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
1010 use_software = true;
1011
[email protected]0634cdd42013-08-16 00:46:091012 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:171013 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:331014 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:091015 context_provider = ContextProviderCommandBuffer::Create(
sieversfbaa5dc2015-04-28 00:45:311016 CreateGraphicsContext3D(), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:331017 if (!context_provider.get()) {
1018 // Cause the compositor to wait and try again.
1019 return scoped_ptr<cc::OutputSurface>();
1020 }
vmiura78b69282015-02-14 00:01:171021
1022 worker_context_provider = ContextProviderCommandBuffer::Create(
sieversfbaa5dc2015-04-28 00:45:311023 CreateGraphicsContext3D(), RENDER_WORKER_CONTEXT);
vmiura78b69282015-02-14 00:01:171024 if (!worker_context_provider.get()) {
1025 // Cause the compositor to wait and try again.
1026 return scoped_ptr<cc::OutputSurface>();
1027 }
[email protected]0634cdd42013-08-16 00:46:091028 }
[email protected]ebc0e1df2013-08-01 02:46:221029
[email protected]b6eb8e332013-09-10 00:51:011030 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:001031 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:531032 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
caseqff9c74c2015-02-10 14:56:291033 return scoped_ptr<cc::OutputSurface>(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171034 routing_id(), output_surface_id, context_provider,
1035 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091036 }
[email protected]0634cdd42013-08-16 00:46:091037 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091038 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121039 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091040
caseqff9c74c2015-02-10 14:56:291041 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
1042 routing_id(), output_surface_id, nullptr, nullptr,
1043 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221044 }
[email protected]ed7defa2013-03-12 21:29:591045
[email protected]36e5ff12013-06-11 12:19:291046 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:451047 // Composite-to-mailbox is currently used for layout tests in order to cause
1048 // them to draw inside in the renderer to do the readback there. This should
1049 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:531050 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:161051 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:271052 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:161053 format = cc::RGB_565;
caseqff9c74c2015-02-10 14:56:291054 return scoped_ptr<cc::OutputSurface>(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171055 routing_id(), output_surface_id, context_provider,
1056 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1057 frame_swap_message_queue_, format));
[email protected]36e5ff12013-06-11 12:19:291058 }
[email protected]0634cdd42013-08-16 00:46:091059 bool use_swap_compositor_frame_message = false;
caseqff9c74c2015-02-10 14:56:291060 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171061 routing_id(), output_surface_id, context_provider,
1062 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1063 frame_swap_message_queue_, use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281064}
1065
[email protected]4d7e46a2013-11-08 05:33:401066void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241067 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241068 // Schedule another frame so the compositor learns about it.
[email protected]8b9e52b2014-01-17 16:35:311069 scheduleComposite();
[email protected]65225772011-05-12 21:10:241070}
1071
[email protected]4d7e46a2013-11-08 05:33:401072void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081073 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081074}
1075
[email protected]4d7e46a2013-11-08 05:33:401076void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241077 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161078
[email protected]404939f2012-06-01 04:06:181079 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161080 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291081}
1082
[email protected]180ef242013-11-07 06:50:461083void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351084 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091085 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191086 base::AutoReset<bool> handling_input_event_resetter(
1087 &handling_input_event_, true);
1088 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291089 return;
[email protected]c27dd4f2014-05-22 18:05:191090 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1091 &handling_event_type_, input_event->type);
[email protected]25402eb2014-07-18 03:09:521092#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541093 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521094 // |AdapterInputConnection| generates input key events to make sure all JS
1095 // listeners that monitor KeyUp and KeyDown events receive the proper key
1096 // code. Since this input key event comes from IME, we need to set the
1097 // IME event guard here to make sure it does not interfere with other IME
1098 // events.
1099 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1100 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1101 const WebKeyboardEvent& key_event =
1102 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541103 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171104 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091105 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1106 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1107 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1108 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1109 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521110 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521111 }
1112#endif
initial.commit09911bf2008-07-26 23:55:291113
[email protected]8062ab262014-05-27 16:56:431114 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1115 &latency_info);
1116
[email protected]fd847792013-10-24 17:12:351117 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411118 if (base::TimeTicks::IsHighResolution())
1119 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351120
miletusfed8c43b2015-01-26 20:04:521121 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301122 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151123 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131124 TRACE_EVENT_FLOW_STEP0(
miletusfed8c43b2015-01-26 20:04:521125 "input,benchmark",
[email protected]15ba6dea2014-04-02 01:44:131126 "LatencyInfo.Flow",
1127 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1128 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101129
jdduke07788062014-12-05 03:16:301130 // If we don't have a high res timer, these metrics won't be accurate enough
1131 // to be worth collecting. Note that this does introduce some sampling bias.
1132 if (!start_time.is_null())
1133 LogInputEventLatencyUma(*input_event, start_time);
1134
[email protected]6be422b2013-12-08 06:47:311135 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351136 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311137 if (compositor_) {
1138 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351139 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1140 .Pass();
[email protected]6be422b2013-12-08 06:47:311141 }
[email protected]c2eaa8f2013-05-10 02:41:551142
[email protected]67bfb83f2011-09-22 03:36:371143 bool prevent_default = false;
1144 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261145 const WebMouseEvent& mouse_event =
1146 *static_cast<const WebMouseEvent*>(input_event);
1147 TRACE_EVENT2("renderer", "HandleMouseMove",
1148 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421149 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261150 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371151 }
1152
[email protected]cefe9b152014-03-27 18:16:151153 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421154 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151155#if defined(OS_ANDROID)
1156 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1157 // case it should behave like a select key (i.e. causing a click if a button
1158 // is focused). However, if a text field is focused (2), its intended
1159 // behavior is to just show the IME and don't propagate the key.
1160 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1161 // when clicked on an input text field and cause the form submit if clicked
1162 // when the submit button is focused, but not vice-versa.
1163 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1164 // but at this point we have to swallow the event for the scenario (2).
1165 const WebKeyboardEvent& key_event =
1166 *static_cast<const WebKeyboardEvent*>(input_event);
1167 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1168 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1169 OnShowImeIfNeeded();
1170 prevent_default = true;
1171 }
1172#endif
1173 }
[email protected]f56c7872013-06-18 12:31:571174
[email protected]41d86852012-11-07 12:23:241175 if (WebInputEvent::isGestureEventType(input_event->type)) {
1176 const WebGestureEvent& gesture_event =
1177 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421178 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241179 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1180 }
1181
[email protected]67bfb83f2011-09-22 03:36:371182 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121183 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1184 suppress_next_char_events_ = false;
1185 if (!processed && webwidget_)
1186 processed = webwidget_->handleInputEvent(*input_event);
1187 }
1188
1189 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1190 // it's not processed by webkit, then we need to suppress the upcoming Char
1191 // events.
1192 if (!processed && is_keyboard_shortcut)
1193 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291194
[email protected]3d5c243b2012-11-30 00:26:011195 InputEventAckState ack_result = processed ?
1196 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1197 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1198 const WebTouchEvent& touch_event =
1199 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251200 // Hit-test for all the pressed touch points. If there is a touch-handler
1201 // for any of the touch points, then the renderer should continue to receive
1202 // touch events.
1203 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1204 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1205 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271206 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391207 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251208 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1209 break;
1210 }
1211 }
[email protected]3d5c243b2012-11-30 00:26:011212 }
1213
ccamerond4ba47902014-12-17 07:20:311214 // Send mouse wheel events and their disposition to the compositor thread, so
1215 // that they can be used to produce the elastic overscroll effect on Mac.
1216 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311217 ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:311218 static_cast<const WebMouseWheelEvent&>(*input_event), processed);
1219 }
1220
[email protected]721e2302014-04-30 23:42:011221 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061222
charliea3be839702015-01-26 17:35:411223 // If we don't have a fast and accurate Now(), we assume the input handlers
1224 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301225 bool rate_limiting_wanted =
1226 input_event->type == WebInputEvent::MouseMove ||
1227 input_event->type == WebInputEvent::MouseWheel;
1228 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411229 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351230 total_input_handling_time_this_frame_ += (end_time - start_time);
1231 rate_limiting_wanted =
1232 total_input_handling_time_this_frame_.InMicroseconds() >
1233 kInputHandlingTimeThrottlingThresholdMicroseconds;
1234 }
1235
[email protected]7f19e9d2014-05-09 15:16:291236 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1237
[email protected]c27dd4f2014-05-22 18:05:191238 // Note that we can't use handling_event_type_ here since it will be overriden
1239 // by reentrant calls for events after the paused one.
1240 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1241 input_event->type == WebInputEvent::MouseMove;
lanweif1a22832015-05-19 17:24:101242 if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) &&
1243 !no_ack) {
1244 InputEventAck ack(input_event->type, ack_result, swap_latency_info,
1245 WebInputEventTraits::GetUniqueTouchEventId(*input_event));
[email protected]34afe102013-12-13 17:24:551246 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561247 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301248 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551249 // We want to rate limit the input events in this case, so we'll wait for
1250 // painting to finish before ACKing this message.
1251 TRACE_EVENT_INSTANT0("renderer",
1252 "RenderWidget::OnHandleInputEvent ack throttled",
1253 TRACE_EVENT_SCOPE_THREAD);
1254 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291255 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1256 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551257 // As two different kinds of events could cause us to postpone an ack
1258 // we send it now, if we have one pending. The Browser should never
1259 // send us the same kind of event we are delaying the ack for.
1260 Send(pending_input_event_ack_.release());
1261 }
1262 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291263 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1264 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551265 if (compositor_)
1266 compositor_->NotifyInputThrottledUntilCommit();
1267 } else {
1268 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171269 }
[email protected]12fbad812009-09-01 18:21:241270 }
alexclarke7819e2552015-06-03 11:17:211271 if (!no_ack && RenderThreadImpl::current()) {
1272 RenderThreadImpl::current()
1273 ->GetRendererScheduler()
1274 ->DidHandleInputEventOnMainThread(*input_event);
1275 }
[email protected]5fea4a52014-05-27 00:17:521276 if (input_event->type == WebInputEvent::MouseMove)
1277 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241278
[email protected]3306f262012-09-21 19:20:421279#if defined(OS_ANDROID)
1280 // Allow the IME to be shown when the focus changes as a consequence
1281 // of a processed touch end event.
1282 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361283 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021284#elif defined(USE_AURA)
1285 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1286 // change.
1287 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141288 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361289 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141290 }
[email protected]3306f262012-09-21 19:20:421291#endif
1292
[email protected]67bfb83f2011-09-22 03:36:371293 if (!prevent_default) {
1294 if (WebInputEvent::isKeyboardEventType(input_event->type))
1295 DidHandleKeyEvent();
1296 if (WebInputEvent::isMouseEventType(input_event->type))
1297 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
1298 }
rouslanf7ebd8832015-01-22 01:54:141299
1300// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1301// virtual keyboard.
1302#if !defined(OS_ANDROID)
1303 // Virtual keyboard is not supported, so react to focus change immediately.
1304 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1305 input_event->type == WebInputEvent::MouseUp)) {
1306 FocusChangeComplete();
1307 }
1308#endif
initial.commit09911bf2008-07-26 23:55:291309}
1310
[email protected]34202de2013-05-06 23:36:221311void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1312 if (webwidget_)
1313 webwidget_->setCursorVisibilityState(is_visible);
1314}
1315
initial.commit09911bf2008-07-26 23:55:291316void RenderWidget::OnMouseCaptureLost() {
1317 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281318 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291319}
1320
1321void RenderWidget::OnSetFocus(bool enable) {
1322 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331323 if (webwidget_)
1324 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291325}
1326
1327void RenderWidget::ClearFocus() {
1328 // We may have got the focus from the browser before this gets processed, in
1329 // which case we do not want to unfocus ourself.
1330 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281331 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291332}
1333
[email protected]fd847792013-10-24 17:12:351334void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291335 if (pending_input_event_ack_) {
1336 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1337 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071338 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291339 }
[email protected]fd847792013-10-24 17:12:351340 total_input_handling_time_this_frame_ = base::TimeDelta();
1341}
1342
initial.commit09911bf2008-07-26 23:55:291343///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461344// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291345
[email protected]244ac1892011-12-02 17:04:471346void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091347 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451348 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581349
[email protected]5b45ad42013-10-25 00:42:041350 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451351 WebRect new_pos(rootWindowRect().x,
1352 rootWindowRect().y,
1353 new_size.width,
1354 new_size.height);
1355 view_screen_rect_ = new_pos;
1356 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031357 }
[email protected]20fbfc22013-05-08 20:50:581358
[email protected]eac2b362013-05-22 07:01:451359 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581360
[email protected]5b45ad42013-10-25 00:42:041361 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581362 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091363 }
[email protected]244ac1892011-12-02 17:04:471364}
1365
[email protected]3a1c8a8032013-03-18 22:35:321366void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051367 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1368 device_scale_factor_));
1369 if (compositor_)
1370 compositor_->setViewportSize(size_, physical_backing_size_);
1371}
1372
[email protected]e195e582013-03-08 01:32:591373void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221374 DCHECK(!host_closing_);
1375
danakj6e3bf8012014-12-16 18:27:531376 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591377 compositor_->setViewportSize(size_, physical_backing_size_);
1378 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031379 StartCompositor();
[email protected]e195e582013-03-08 01:32:591380}
1381
ennef3c58142014-12-09 21:44:381382void RenderWidget::WillCloseLayerTreeView() {
1383 if (host_closing_)
1384 return;
1385
1386 // Prevent new compositors or output surfaces from being created.
1387 host_closing_ = true;
1388
[email protected]aeeedad2014-08-22 18:16:221389 // Always send this notification to prevent new layer tree views from
1390 // being created, even if one hasn't been created yet.
1391 if (webwidget_)
1392 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221393}
1394
[email protected]180ef242013-11-07 06:50:461395blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281396 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061397}
1398
[email protected]9cd43a62012-03-26 08:03:561399void RenderWidget::willBeginCompositorFrame() {
1400 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371401
[email protected]abe8b3a2012-03-28 21:19:371402 // The following two can result in further layout and possibly
1403 // enable GPU acceleration so they need to be called before any painting
1404 // is done.
shuchen3517bb62014-10-15 03:55:571405 UpdateTextInputType();
1406#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361407 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571408#endif
[email protected]abe8b3a2012-03-28 21:19:371409 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561410}
1411
[email protected]3391a0772012-03-28 00:32:071412void RenderWidget::didBecomeReadyForAdditionalInput() {
1413 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351414 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071415}
1416
[email protected]6fceb912013-02-15 06:24:151417void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441418 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1419 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271420 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161421 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171422#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271423 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1424 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171425#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151426}
1427
[email protected]586871b2014-07-22 17:05:111428// static
1429scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1430 IPC::Message* msg,
1431 MessageDeliveryPolicy policy,
1432 FrameSwapMessageQueue* frame_swap_message_queue,
1433 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111434 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111435 bool first_message_for_frame = false;
1436 frame_swap_message_queue->QueueMessageForFrame(policy,
1437 source_frame_number,
1438 make_scoped_ptr(msg),
1439 &first_message_for_frame);
1440 if (first_message_for_frame) {
1441 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1442 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061443 return promise;
[email protected]586871b2014-07-22 17:05:111444 }
dcheng4b6b5ff2014-10-16 00:42:061445 return nullptr;
[email protected]586871b2014-07-22 17:05:111446}
1447
1448void RenderWidget::QueueMessage(IPC::Message* msg,
1449 MessageDeliveryPolicy policy) {
1450 // RenderThreadImpl::current() is NULL in some tests.
1451 if (!compositor_ || !RenderThreadImpl::current()) {
1452 Send(msg);
1453 return;
1454 }
1455
1456 scoped_ptr<cc::SwapPromise> swap_promise =
1457 QueueMessageImpl(msg,
1458 policy,
dcheng58867a92014-08-26 02:50:221459 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111460 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111461 compositor_->GetSourceFrameNumber());
1462
1463 if (swap_promise) {
1464 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351465 // Request a commit. This might either A) request a commit ahead of time
1466 // or B) request a commit which is not needed because there are not
1467 // pending updates. If B) then the commit will be skipped and the swap
1468 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1469 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1470 // can_cancel_commit is not unset.
1471 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111472 }
1473}
1474
[email protected]58264a32011-11-17 23:36:151475void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101476 // NOTE: Tests may break if this event is renamed or moved. See
1477 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501478 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161479 // Notify subclasses that we initiated the paint operation.
1480 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151481}
1482
1483void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181484 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1485
1486 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561487 DidFlushPaint();
1488
[email protected]ea3ee0a2012-05-15 03:43:091489 if (!next_paint_flags_ &&
1490 !need_update_rect_for_auto_resize_ &&
1491 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151492 return;
[email protected]ea3ee0a2012-05-15 03:43:091493 }
[email protected]58264a32011-11-17 23:36:151494
1495 ViewHostMsg_UpdateRect_Params params;
1496 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151497 params.plugin_window_moves.swap(plugin_window_moves_);
1498 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151499
1500 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1501 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091502 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151503}
1504
[email protected]8b9e52b2014-01-17 16:35:311505void RenderWidget::scheduleComposite() {
danakj6e3bf8012014-12-16 18:27:531506 if (compositor_ &&
1507 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
[email protected]e221f9f2014-05-13 02:47:221508 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311509 }
1510}
1511
[email protected]4873c7d2009-07-16 06:36:281512void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301513 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521514 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401515 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291516 // Only send a SetCursor message if we need to make a change.
1517 if (!current_cursor_.IsEqual(cursor)) {
1518 current_cursor_ = cursor;
1519 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1520 }
1521}
1522
1523// We are supposed to get a single call to Show for a newly created RenderWidget
1524// that was created via RenderWidget::CreateWebView. So, we wait until this
1525// point to dispatch the ShowWidget message.
1526//
1527// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281528// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291529//
[email protected]4873c7d2009-07-16 06:36:281530void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291531 DCHECK(!did_show_) << "received extraneous Show call";
1532 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1533 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1534
[email protected]8de12d942010-11-17 20:42:441535 if (did_show_)
1536 return;
1537
1538 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561539 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441540 // that's okay. It'll be ignored if as_popup is false, or the browser
1541 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561542 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1543 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291544}
1545
[email protected]4873c7d2009-07-16 06:36:281546void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291547}
1548
[email protected]4873c7d2009-07-16 06:36:281549void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291550}
1551
[email protected]2533ce12009-05-09 00:02:241552void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381553 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241554 Send(new ViewHostMsg_Close(routing_id_));
1555}
1556
dgozmancf9039cd2015-04-06 12:01:311557void RenderWidget::NotifyOnClose() {
1558 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1559}
1560
[email protected]4873c7d2009-07-16 06:36:281561void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321562 if (is_swapped_out_) {
1563 // This widget is currently swapped out, and the active widget is in a
1564 // different process. Have the browser route the close request to the
1565 // active widget instead, so that the correct unload handlers are run.
1566 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1567 return;
1568 }
1569
initial.commit09911bf2008-07-26 23:55:291570 // If a page calls window.close() twice, we'll end up here twice, but that's
1571 // OK. It is safe to send multiple Close messages.
1572
[email protected]2533ce12009-05-09 00:02:241573 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1574 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1575 // could be closed before the JS finishes executing. So instead, post a
1576 // message back to the message loop, which won't run until the JS is
1577 // complete, and then the Close message can be sent.
alexclarkee19d4ef2015-01-09 17:45:401578 RenderThread::Get()->GetTaskRunner()->PostTask(
[email protected]32876ae2011-11-15 22:25:211579 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291580}
1581
[email protected]9017d7852013-11-21 17:47:351582void RenderWidget::QueueSyntheticGesture(
1583 scoped_ptr<SyntheticGestureParams> gesture_params,
1584 const SyntheticGestureCompletionCallback& callback) {
1585 DCHECK(!callback.is_null());
1586
1587 pending_synthetic_gesture_callbacks_.push(callback);
1588
1589 SyntheticGesturePacket gesture_packet;
1590 gesture_packet.set_gesture_params(gesture_params.Pass());
1591
1592 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1593}
1594
initial.commit09911bf2008-07-26 23:55:291595void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031596 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381597 WillCloseLayerTreeView();
1598 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291599 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281600 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291601 webwidget_ = NULL;
1602 }
1603}
1604
[email protected]4873c7d2009-07-16 06:36:281605WebRect RenderWidget::windowRect() {
1606 if (pending_window_rect_count_)
1607 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241608
[email protected]80ad8622012-11-07 16:33:031609 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291610}
1611
[email protected]180ef242013-11-07 06:50:461612void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301613 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541614 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301615}
1616
[email protected]b2e4c70132013-10-03 02:07:511617void RenderWidget::setWindowRect(const WebRect& rect) {
bokanc007c3a2015-02-03 07:15:561618 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511619 if (popup_origin_scale_for_emulation_) {
1620 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561621 window_rect.x = popup_screen_origin_for_emulation_.x() +
1622 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1623 window_rect.y = popup_screen_origin_for_emulation_.y() +
1624 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511625 }
1626
[email protected]5b45ad42013-10-25 00:42:041627 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201628 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561629 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1630 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031631 } else {
bokanc007c3a2015-02-03 07:15:561632 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031633 }
initial.commit09911bf2008-07-26 23:55:291634 } else {
bokanc007c3a2015-02-03 07:15:561635 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291636 }
1637}
1638
[email protected]2533ce12009-05-09 00:02:241639void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1640 pending_window_rect_ = rect;
1641 pending_window_rect_count_++;
1642}
1643
[email protected]4873c7d2009-07-16 06:36:281644WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241645 if (pending_window_rect_count_) {
1646 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1647 // the RootWindowRect is probably going to return wrong results since the
1648 // browser may not have processed the Move yet. There isn't really anything
1649 // good to do in this case, and it shouldn't happen - since this size is
1650 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281651 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241652 }
1653
[email protected]80ad8622012-11-07 16:33:031654 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371655}
1656
[email protected]4873c7d2009-07-16 06:36:281657WebRect RenderWidget::windowResizerRect() {
1658 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191659}
1660
[email protected]fa7b1dc2010-06-23 17:53:041661void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031662 // To prevent this renderer process from sending unnecessary IPC messages to
1663 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041664 // only during the input method attached to the browser process is active.
1665 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291666}
1667
[email protected]37a241c2013-12-03 03:16:171668void RenderWidget::OnCandidateWindowShown() {
[email protected]37a241c2013-12-03 03:16:171669}
1670
1671void RenderWidget::OnCandidateWindowUpdated() {
[email protected]37a241c2013-12-03 03:16:171672}
1673
1674void RenderWidget::OnCandidateWindowHidden() {
[email protected]37a241c2013-12-03 03:16:171675}
1676
[email protected]fa7b1dc2010-06-23 17:53:041677void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261678 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041679 const std::vector<WebCompositionUnderline>& underlines,
1680 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131681 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281682 return;
[email protected]66fca5bc2013-05-23 06:58:291683 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361684 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041685 text, WebVector<WebCompositionUnderline>(underlines),
1686 selection_start, selection_end)) {
1687 // If we failed to set the composition text, then we need to let the browser
1688 // process to cancel the input method's ongoing composition session, to make
1689 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221690 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261691 }
[email protected]88dbe32f2013-06-20 23:31:361692 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041693}
1694
[email protected]fcf75d42013-12-03 20:11:261695void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511696 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021697 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131698 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041699 return;
[email protected]66fca5bc2013-05-23 06:58:291700 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041701 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021702 if (text.length())
1703 webwidget_->confirmComposition(text);
1704 else if (keep_selection)
1705 webwidget_->confirmComposition(WebWidget::KeepSelection);
1706 else
1707 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041708 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361709 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291710}
1711
[email protected]0bc1f572013-04-17 01:46:311712void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121713 // During shutdown we can just ignore this message.
1714 if (!webwidget_)
1715 return;
1716
[email protected]0bc1f572013-04-17 01:46:311717 // Even if the browser provides an empty damage rect, it's still expecting to
1718 // receive a repaint ack so just damage the entire widget bounds.
1719 if (size_to_paint.IsEmpty()) {
1720 size_to_paint = size_;
1721 }
1722
[email protected]ec7dc112008-08-06 05:30:121723 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051724 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311725 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121726}
1727
[email protected]79fa22e2013-08-23 15:18:121728void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351729 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1730
1731 pending_synthetic_gesture_callbacks_.front().Run();
1732 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271733}
1734
[email protected]4873c7d2009-07-16 06:36:281735void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111736 if (!webwidget_)
1737 return;
[email protected]4873c7d2009-07-16 06:36:281738 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111739}
1740
[email protected]80ad8622012-11-07 16:33:031741void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1742 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511743 if (screen_metrics_emulator_) {
1744 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1745 view_screen_rect, window_screen_rect);
1746 } else {
1747 view_screen_rect_ = view_screen_rect;
1748 window_screen_rect_ = window_screen_rect;
1749 }
[email protected]80ad8622012-11-07 16:33:031750 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1751}
1752
kenrbb4e2a3b2015-05-14 15:05:051753void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1754 if (compositor_)
1755 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1756}
1757
[email protected]adb362312014-06-28 06:04:241758void RenderWidget::showImeIfNeeded() {
1759 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131760}
1761
[email protected]adb362312014-06-28 06:04:241762void RenderWidget::OnShowImeIfNeeded() {
1763#if defined(OS_ANDROID) || defined(USE_AURA)
1764 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1765#endif
rouslanf7ebd8832015-01-22 01:54:141766
1767// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1768// virtual keyboard.
1769#if !defined(OS_ANDROID)
1770 FocusChangeComplete();
1771#endif
[email protected]adb362312014-06-28 06:04:241772}
1773
1774#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131775void RenderWidget::IncrementOutstandingImeEventAcks() {
1776 ++outstanding_ime_acks_;
1777}
1778
1779void RenderWidget::OnImeEventAck() {
1780 --outstanding_ime_acks_;
1781 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511782}
[email protected]105dffb42013-02-20 03:46:211783#endif
1784
[email protected]0d1ebed12013-08-05 22:01:131785bool RenderWidget::ShouldHandleImeEvent() {
1786#if defined(OS_ANDROID)
1787 return !!webwidget_ && outstanding_ime_acks_ == 0;
1788#else
1789 return !!webwidget_;
1790#endif
1791}
1792
[email protected]c27dd4f2014-05-22 18:05:191793bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1794 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521795 // If we pause multiple times during a single mouse move event, we should
1796 // only send ACK once.
1797 if (!ignore_ack_for_mouse_move_from_debugger_) {
lanweif1a22832015-05-19 17:24:101798 InputEventAck ack(handling_event_type_, INPUT_EVENT_ACK_STATE_CONSUMED);
[email protected]5fea4a52014-05-27 00:17:521799 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dgozmanb739185d2015-04-10 15:04:021800 return true;
[email protected]5fea4a52014-05-27 00:17:521801 }
[email protected]c27dd4f2014-05-22 18:05:191802 }
1803 return false;
1804}
1805
1806void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1807 ignore_ack_for_mouse_move_from_debugger_ = true;
1808}
1809
[email protected]468ac582012-11-20 00:53:191810void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1811 if (device_scale_factor_ == device_scale_factor)
1812 return;
1813
1814 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051815 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191816}
1817
[email protected]28ed6b32014-06-08 02:16:271818bool RenderWidget::SetDeviceColorProfile(
1819 const std::vector<char>& color_profile) {
1820 if (device_color_profile_ == color_profile)
1821 return false;
1822
1823 device_color_profile_ = color_profile;
1824 return true;
1825}
1826
noeldb4df152014-09-16 17:45:201827void RenderWidget::ResetDeviceColorProfileForTesting() {
1828 if (!device_color_profile_.empty())
1829 device_color_profile_.clear();
1830 device_color_profile_.push_back('0');
1831}
1832
[email protected]fcdc5642014-05-09 14:32:241833void RenderWidget::OnOrientationChange() {
1834}
1835
[email protected]ceb36f7d2012-10-31 18:33:241836gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521837 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241838 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521839}
1840
[email protected]bee16aab2009-08-26 15:55:031841void RenderWidget::SetHidden(bool hidden) {
1842 if (is_hidden_ == hidden)
1843 return;
1844
jdduke8fac9d102014-12-20 02:40:131845 // The status has changed. Tell the RenderThread about it and ensure
1846 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031847 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131848 FlushPendingInputEventAck();
1849
[email protected]bee16aab2009-08-26 15:55:031850 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001851 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031852 else
[email protected]b2db9272014-01-10 17:42:001853 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031854}
1855
[email protected]2b624c562011-10-27 22:58:261856void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261857 if (!webwidget_)
1858 return;
1859
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121860 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261861 webwidget_->willExitFullScreen();
1862 } else {
1863 webwidget_->willEnterFullScreen();
1864 }
[email protected]2b624c562011-10-27 22:58:261865}
1866
1867void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261868 if (!webwidget_)
1869 return;
1870
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121871 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261872 webwidget_->didEnterFullScreen();
1873 } else {
1874 webwidget_->didExitFullScreen();
1875 }
[email protected]2b624c562011-10-27 22:58:261876}
1877
[email protected]674741932009-02-04 23:44:461878bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051879 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461880}
1881
[email protected]674741932009-02-04 23:44:461882void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051883 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461884}
1885
[email protected]674741932009-02-04 23:44:461886void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051887 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461888}
1889
[email protected]b18583c2012-12-18 06:55:271890static bool IsDateTimeInput(ui::TextInputType type) {
1891 return type == ui::TEXT_INPUT_TYPE_DATE ||
1892 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1893 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1894 type == ui::TEXT_INPUT_TYPE_MONTH ||
1895 type == ui::TEXT_INPUT_TYPE_TIME ||
1896 type == ui::TEXT_INPUT_TYPE_WEEK;
1897}
1898
[email protected]66fca5bc2013-05-23 06:58:291899
1900void RenderWidget::StartHandlingImeEvent() {
1901 DCHECK(!handling_ime_event_);
1902 handling_ime_event_ = true;
1903}
1904
1905void RenderWidget::FinishHandlingImeEvent() {
1906 DCHECK(handling_ime_event_);
1907 handling_ime_event_ = false;
1908 // While handling an ime event, text input state and selection bounds updates
1909 // are ignored. These must explicitly be updated once finished handling the
1910 // ime event.
1911 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471912#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361913 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471914#endif
[email protected]66fca5bc2013-05-23 06:58:291915}
1916
shuchen3517bb62014-10-15 03:55:571917void RenderWidget::UpdateTextInputType() {
1918 // On Windows, not only an IME but also an on-screen keyboard relies on the
1919 // latest TextInputType to optimize its layout and functionality. Thus
1920 // |input_method_is_active_| is no longer an appropriate condition to suppress
1921 // TextInputTypeChanged IPC on Windows.
1922 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1923 // on other platforms as well as Windows if the overhead is acceptable.
1924#if !defined(OS_WIN)
1925 if (!input_method_is_active_)
1926 return;
1927#endif
1928
1929 ui::TextInputType new_type = GetTextInputType();
1930 if (IsDateTimeInput(new_type))
1931 return; // Not considered as a text input field in WebKit/Chromium.
1932
1933 bool new_can_compose_inline = CanComposeInline();
1934
1935 blink::WebTextInputInfo new_info;
1936 if (webwidget_)
1937 new_info = webwidget_->textInputInfo();
1938 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201939 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571940
1941 if (text_input_type_ != new_type
1942 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201943 || text_input_mode_ != new_mode
1944 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571945 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1946 new_type,
1947 new_mode,
shuchen82ce8c52014-10-23 01:55:201948 new_can_compose_inline,
1949 new_flags));
shuchen3517bb62014-10-15 03:55:571950 text_input_type_ = new_type;
1951 can_compose_inline_ = new_can_compose_inline;
1952 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201953 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571954 }
1955}
1956
1957#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361958void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1959 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501960 if (handling_ime_event_)
1961 return;
[email protected]90f24152014-04-09 12:41:361962 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291963 return;
[email protected]ad26ef42011-06-17 07:59:451964 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271965 if (IsDateTimeInput(new_type))
1966 return; // Not considered as a text input field in WebKit/Chromium.
1967
[email protected]180ef242013-11-07 06:50:461968 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211969 if (webwidget_)
1970 new_info = webwidget_->textInputInfo();
1971
[email protected]ad26ef42011-06-17 07:59:451972 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211973
[email protected]3306f262012-09-21 19:20:421974 // Only sends text input params if they are changed or if the ime should be
1975 // shown.
[email protected]90f24152014-04-09 12:41:361976 if (show_ime == SHOW_IME_IF_NEEDED ||
1977 (text_input_type_ != new_type ||
1978 text_input_info_ != new_info ||
1979 can_compose_inline_ != new_can_compose_inline)
1980#if defined(OS_ANDROID)
1981 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021982#endif
[email protected]90f24152014-04-09 12:41:361983 ) {
1984 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211985 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401986 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211987 p.value = new_info.value.utf8();
1988 p.selection_start = new_info.selectionStart;
1989 p.selection_end = new_info.selectionEnd;
1990 p.composition_start = new_info.compositionStart;
1991 p.composition_end = new_info.compositionEnd;
1992 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361993 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1994#if defined(USE_AURA)
1995 p.is_non_ime_change = true;
1996#endif
[email protected]183e28d2014-01-20 18:18:021997#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361998 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1999 text_field_is_dirty_;
2000 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:132001 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:362002 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:022003#endif
shuchen3517bb62014-10-15 03:55:572004#if defined(USE_AURA)
2005 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
2006 new_type,
2007 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:202008 new_can_compose_inline,
2009 new_info.flags));
shuchen3517bb62014-10-15 03:55:572010#endif
[email protected]5b739cb2012-08-21 20:35:212011 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2012
2013 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042014 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452015 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:202016 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:292017 }
initial.commit09911bf2008-07-26 23:55:292018}
shuchen3517bb62014-10-15 03:55:572019#endif
initial.commit09911bf2008-07-26 23:55:292020
[email protected]7c8873e2013-02-05 08:03:012021void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2022 WebRect focus_webrect;
2023 WebRect anchor_webrect;
2024 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2025 *focus = focus_webrect;
2026 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322027}
2028
[email protected]e99ef6f2011-10-16 01:13:002029void RenderWidget::UpdateSelectionBounds() {
2030 if (!webwidget_)
2031 return;
[email protected]66fca5bc2013-05-23 06:58:292032 if (handling_ime_event_)
2033 return;
[email protected]e99ef6f2011-10-16 01:13:002034
jddukeacf809e2014-09-23 20:38:382035 // With composited selection updates, the selection bounds will be reported
2036 // directly by the compositor, in which case explicit IPC selection
2037 // notifications should be suppressed.
2038 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
2039 ViewHostMsg_SelectionBounds_Params params;
2040 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2041 if (selection_anchor_rect_ != params.anchor_rect ||
2042 selection_focus_rect_ != params.focus_rect) {
2043 selection_anchor_rect_ = params.anchor_rect;
2044 selection_focus_rect_ = params.focus_rect;
2045 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2046 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2047 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2048 }
[email protected]58b48a0d2012-06-13 07:01:352049 }
jddukeacf809e2014-09-23 20:38:382050
[email protected]88dbe32f2013-06-20 23:31:362051 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002052}
2053
[email protected]180ef242013-11-07 06:50:462054// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172055#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2056 static_assert(int(blink::WebTextInputType##a) \
2057 == int(ui::TEXT_INPUT_TYPE_##b), \
2058 "mismatching enums: " #a)
2059
2060STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2061STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2062STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2063STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2064STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2065STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2066STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2067STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2068STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2069STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2070STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2071STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2072STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2073STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2074STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2075STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2076STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452077
[email protected]5b739cb2012-08-21 20:35:212078ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462079 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212080 // Check the type is in the range representable by ui::TextInputType.
2081 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462082 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212083 return static_cast<ui::TextInputType>(type);
2084}
2085
[email protected]ad26ef42011-06-17 07:59:452086ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272087 if (webwidget_)
2088 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452089 return ui::TEXT_INPUT_TYPE_NONE;
2090}
2091
[email protected]501ea13d2013-07-09 17:03:292092void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302093#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112094 // TODO(yukawa): Start sending character bounds when the browser side
2095 // implementation becomes ready (crbug.com/424866).
2096#else
[email protected]db4fc1e2013-09-06 20:01:512097 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292098 if (should_update_range) {
2099 GetCompositionRange(&range);
2100 } else {
2101 range = composition_range_;
2102 }
2103 std::vector<gfx::Rect> character_bounds;
2104 GetCompositionCharacterBounds(&character_bounds);
2105
2106 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2107 return;
2108 composition_character_bounds_ = character_bounds;
2109 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222110 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292111 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112112#endif
[email protected]501ea13d2013-07-09 17:03:292113}
2114
[email protected]58b48a0d2012-06-13 07:01:352115void RenderWidget::GetCompositionCharacterBounds(
2116 std::vector<gfx::Rect>* bounds) {
2117 DCHECK(bounds);
2118 bounds->clear();
2119}
2120
[email protected]db4fc1e2013-09-06 20:01:512121void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362122 size_t location, length;
2123 if (webwidget_->compositionRange(&location, &length)) {
2124 range->set_start(location);
2125 range->set_end(location + length);
2126 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2127 range->set_start(location);
2128 range->set_end(location + length);
2129 } else {
[email protected]db4fc1e2013-09-06 20:01:512130 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362131 }
2132}
2133
[email protected]501ea13d2013-07-09 17:03:292134bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512135 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292136 const std::vector<gfx::Rect>& bounds) {
2137 if (composition_range_ != range)
2138 return true;
2139 if (bounds.size() != composition_character_bounds_.size())
2140 return true;
2141 for (size_t i = 0; i < bounds.size(); ++i) {
2142 if (bounds[i] != composition_character_bounds_[i])
2143 return true;
2144 }
2145 return false;
2146}
[email protected]501ea13d2013-07-09 17:03:292147
[email protected]a4f0d882014-05-01 23:48:102148#if defined(OS_ANDROID)
2149void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2150 // If not initialized, default to white. Note that 0 is different from black
2151 // as black still has alpha 0xFF.
2152 if (!bg_color)
2153 bg_color = SK_ColorWHITE;
2154
2155 if (bg_color != body_background_color_) {
2156 body_background_color_ = bg_color;
2157 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2158 }
2159}
timav7a5032e2014-12-05 01:59:432160
2161bool RenderWidget::DoesRecordFullLayer() const {
2162 SynchronousCompositorFactory* synchronous_compositor_factory =
2163 SynchronousCompositorFactory::GetInstance();
2164
2165 // We assume that the absence of synchronous_compositor_factory
2166 // means we are in Chrome. In chrome, we want to clip, i.e.
2167 // *not* to record the full layer.
2168 if (!synchronous_compositor_factory)
2169 return false;
2170
2171 return synchronous_compositor_factory->RecordFullLayer();
2172}
[email protected]a4f0d882014-05-01 23:48:102173#endif
2174
[email protected]ad26ef42011-06-17 07:59:452175bool RenderWidget::CanComposeInline() {
2176 return true;
[email protected]56ea1a62011-05-30 07:05:572177}
2178
[email protected]4873c7d2009-07-16 06:36:282179WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042180 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282181}
2182
[email protected]f660d9c2012-06-06 18:31:212183float RenderWidget::deviceScaleFactor() {
2184 return device_scale_factor_;
2185}
2186
[email protected]fa7b1dc2010-06-23 17:53:042187void RenderWidget::resetInputMethod() {
2188 if (!input_method_is_active_)
2189 return;
2190
[email protected]0e45bd02013-07-12 20:20:022191 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042192 // If the last text input type is not None, then we should finish any
2193 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452194 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042195 // If a composition text exists, then we need to let the browser process
2196 // to cancel the input method's ongoing composition session.
2197 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222198 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042199 }
[email protected]d4cff272011-05-02 15:46:012200
[email protected]88dbe32f2013-06-20 23:31:362201 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042202}
2203
donnda070f3c2015-01-16 19:54:112204#if defined(OS_ANDROID)
2205void RenderWidget::showUnhandledTapUIIfNeeded(
2206 const WebPoint& tapped_position,
2207 const WebNode& tapped_node,
2208 bool page_changed) {
2209 DCHECK(handling_input_event_);
2210 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372211 !tapped_node.isContentEditable() &&
2212 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112213 if (should_trigger) {
2214 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2215 tapped_position.x, tapped_position.y));
2216 }
2217}
2218#endif
2219
[email protected]c68c3e4e2013-01-24 00:36:562220void RenderWidget::didHandleGestureEvent(
2221 const WebGestureEvent& event,
2222 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022223#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562224 if (event_cancelled)
2225 return;
[email protected]07c70d22014-08-21 08:33:462226 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362227 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462228 } else if (event.type == WebInputEvent::GestureLongPress) {
2229 DCHECK(webwidget_);
2230 if (webwidget_->textInputInfo().value.isEmpty())
2231 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2232 else
2233 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562234 }
2235#endif
2236}
2237
[email protected]7912e822014-04-16 02:37:032238void RenderWidget::StartCompositor() {
2239 // For widgets that are never visible, we don't need the compositor to run
2240 // at all.
2241 if (never_visible_)
2242 return;
danakj6e3bf8012014-12-16 18:27:532243 // In tests without a RenderThreadImpl, don't set ready as this kicks
2244 // off creating output surfaces that the test can't create.
2245 if (!RenderThreadImpl::current())
2246 return;
danakj018271e32014-12-16 21:17:262247 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032248}
2249
[email protected]29e2fb42013-07-19 01:13:472250void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292251 size_t i = 0;
2252 for (; i < plugin_window_moves_.size(); ++i) {
2253 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582254 if (move.rects_valid) {
2255 plugin_window_moves_[i] = move;
2256 } else {
2257 plugin_window_moves_[i].visible = move.visible;
2258 }
initial.commit09911bf2008-07-26 23:55:292259 break;
2260 }
2261 }
2262
2263 if (i == plugin_window_moves_.size())
2264 plugin_window_moves_.push_back(move);
2265}
[email protected]268654772009-08-06 23:02:042266
2267void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2268 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2269 i != plugin_window_moves_.end(); ++i) {
2270 if (i->window == window) {
2271 plugin_window_moves_.erase(i);
2272 break;
2273 }
2274 }
2275}
[email protected]67bfb83f2011-09-22 03:36:372276
[email protected]63b465922012-09-06 02:04:522277
[email protected]24ed0432013-04-24 07:50:312278RenderWidgetCompositor* RenderWidget::compositor() const {
2279 return compositor_.get();
2280}
2281
[email protected]180ef242013-11-07 06:50:462282bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372283 return false;
2284}
[email protected]c3d45532011-10-07 19:20:402285
[email protected]41d86852012-11-07 12:23:242286bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462287 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242288 return false;
2289}
2290
ccamerona7644752014-12-30 01:16:312291void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312292 const blink::WebMouseWheelEvent& wheel_event,
2293 bool event_processed) {
ccamerona7644752014-12-30 01:16:312294 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312295 return;
2296
2297 // Blink does not accurately compute scroll bubbling or overscroll. For now,
2298 // assume that an unprocessed event was entirely an overscroll, and that a
2299 // processed event was entirely scroll.
2300 // TODO(ccameron): Retrieve an accurate scroll result from Blink.
2301 // http://crbug.com/442859
2302 cc::InputHandlerScrollResult scroll_result;
2303 if (event_processed) {
2304 scroll_result.did_scroll = true;
2305 } else {
2306 scroll_result.did_overscroll_root = true;
2307 scroll_result.unused_scroll_delta =
2308 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY);
2309 }
2310
2311 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2312 InputHandlerManager* input_handler_manager =
2313 render_thread ? render_thread->input_handler_manager() : NULL;
2314 if (input_handler_manager) {
2315 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2316 routing_id_, wheel_event, scroll_result);
2317 }
2318}
2319
[email protected]ce6689f2013-03-29 12:52:552320void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2321 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2322}
2323
mostynbe29b6882015-01-13 09:59:172324// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2325#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2326 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2327 "mismatching enums: " #a)
2328
dtapuskaa98ac8d72015-05-08 19:29:092329inline content::TouchAction& operator|=(content::TouchAction& a,
2330 content::TouchAction b) {
2331 a = static_cast<content::TouchAction>(static_cast<int>(a) |
2332 static_cast<int>(b));
2333 return a;
2334}
2335
[email protected]5d0bbdfa92013-12-10 00:35:512336void RenderWidget::setTouchAction(
2337 blink::WebTouchAction web_touch_action) {
2338
2339 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2340 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192341 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512342 return;
2343
dtapuskaa98ac8d72015-05-08 19:29:092344 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172345 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2346 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092347 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2348 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172349 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092350 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2351 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172352 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2353 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362354
2355 content::TouchAction content_touch_action =
2356 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512357 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2358}
2359
[email protected]90f24152014-04-09 12:41:362360void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2361#if defined(OS_ANDROID)
2362 text_field_is_dirty_ = true;
2363#endif
2364}
2365
[email protected]3d5c243b2012-11-30 00:26:012366bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2367 return true;
2368}
2369
[email protected]0634cdd42013-08-16 00:46:092370scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132371RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592372 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092373 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492374 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222375 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092376 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292377 if (!RenderThreadImpl::current())
2378 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402379 CauseForGpuLaunch cause =
2380 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292381 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402382 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222383 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292384 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592385
[email protected]828a3932014-04-02 14:43:132386 // Explicitly disable antialiasing for the compositor. As of the time of
2387 // this writing, the only platform that supported antialiasing for the
2388 // compositor was Mac OS X, because the on-screen OpenGL context creation
2389 // code paths on Windows and Linux didn't yet have multisampling support.
2390 // Mac OS X essentially always behaves as though it's rendering offscreen.
2391 // Multisampling has a heavy cost especially on devices with relatively low
2392 // fill rate like most notebooks, and the Mac implementation would need to
2393 // be optimized to resolve directly into the IOSurface shared between the
2394 // GPU and browser processes. For these reasons and to avoid platform
2395 // disparities we explicitly disable antialiasing.
2396 blink::WebGraphicsContext3D::Attributes attributes;
2397 attributes.antialias = false;
2398 attributes.shareResources = true;
2399 attributes.noAutomaticFlushes = true;
2400 attributes.depth = false;
2401 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132402 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292403 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012404#if defined(OS_ANDROID)
2405 // If we raster too fast we become upload bound, and pending
2406 // uploads consume memory. For maximum upload throughput, we would
2407 // want to allow for upload_throughput * pipeline_time of pending
2408 // uploads, after which we are just wasting memory. Since we don't
2409 // know our upload throughput yet, this just caps our memory usage.
2410 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272411 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032412 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012413 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032414 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012415 // Deadline to draw a frame to achieve 60 frames per second.
2416 const size_t kMillisecondsPerFrame = 16;
2417 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032418 size_t max_transfer_buffer_usage_mb =
2419 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2420 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012421 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2422 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292423 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032424 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012425#endif
[email protected]96ab016c2013-10-23 00:50:292426
[email protected]96ab016c2013-10-23 00:50:292427 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132428 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2429 GetURLForGraphicsContext3D(),
2430 gpu_channel_host.get(),
2431 attributes,
[email protected]828a3932014-04-02 14:43:132432 lose_context_when_out_of_memory,
2433 limits,
2434 NULL));
[email protected]0634cdd42013-08-16 00:46:092435 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592436}
2437
[email protected]e3244ed2014-06-20 20:04:272438void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2439 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162440}
2441
[email protected]e3244ed2014-06-20 20:04:272442void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2443 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162444}
2445
[email protected]de3c5d82014-05-28 22:12:592446void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2447 render_frames_.AddObserver(frame);
2448}
2449
2450void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2451 render_frames_.RemoveObserver(frame);
2452}
2453
[email protected]a017938b2014-05-27 21:17:172454#if defined(VIDEO_HOLE)
2455void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2456 video_hole_frames_.AddObserver(frame);
2457}
2458
2459void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2460 video_hole_frames_.RemoveObserver(frame);
2461}
2462#endif // defined(VIDEO_HOLE)
2463
[email protected]e9ff79c2012-10-19 21:31:262464} // namespace content