blob: 684d74da1dc4f5fed9b23f5c0595fa61e5775449 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]c27dd4f2014-05-22 18:05:197#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:218#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:009#include "base/command_line.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4012#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3013#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3814#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2115#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0016#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2717#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0118#include "base/trace_event/trace_event.h"
19#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4820#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5221#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3322#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3023#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0424#include "cc/trees/layer_tree_host.h"
alexclarke7819e2552015-06-03 11:17:2125#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]29e2fb42013-07-19 01:13:4726#include "content/child/npapi/webplugin.h"
[email protected]0634cdd42013-08-16 00:46:0927#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5928#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2929#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3530#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4431#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1532#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1533#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5034#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2935#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4236#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4037#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5138#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5939#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2940#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1141#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5942#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1143#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2844#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2945#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1346#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3247#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1648#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2749#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0550#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4451#include "content/renderer/render_thread_impl.h"
tfarina556a7232014-10-05 01:02:0952#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0453#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1854#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4855#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1856#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3057#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1158#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3059#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1860#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebSize.h"
62#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4363#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5964#include "third_party/WebKit/public/web/WebFrameWidget.h"
65#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1166#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3167#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3168#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
69#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3870#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5971#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4172#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1373#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5074#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0975#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3276#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4877#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2778#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4179#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4880
[email protected]eeb93112013-05-01 19:41:1081#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1582#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0783#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1084#endif
85
[email protected]661eb9d2009-02-03 02:11:4886#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4987#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5288#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4189#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4890#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4491
[email protected]2255a9332013-06-17 05:12:3192#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2993
[email protected]180ef242013-11-07 06:50:4694using blink::WebCompositionUnderline;
95using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4396using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4697using blink::WebGestureEvent;
98using blink::WebInputEvent;
99using blink::WebKeyboardEvent;
100using blink::WebMouseEvent;
101using blink::WebMouseWheelEvent;
102using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11103using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46104using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11105using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46106using blink::WebPopupType;
107using blink::WebRange;
108using blink::WebRect;
109using blink::WebScreenInfo;
110using blink::WebSize;
111using blink::WebTextDirection;
112using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25113using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46114using blink::WebVector;
115using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26116
[email protected]6a4d7f62013-01-07 21:32:13117namespace {
[email protected]b256eca2013-07-11 10:57:40118
119typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
120
121class TextInputModeMapSingleton {
122 public:
123 static TextInputModeMapSingleton* GetInstance() {
124 return Singleton<TextInputModeMapSingleton>::get();
125 }
[email protected]dd705d4d2013-11-27 08:14:41126 TextInputModeMapSingleton() {
127 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
128 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
129 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
130 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
131 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
132 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
133 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
134 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
135 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
136 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
137 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40138 }
[email protected]dd705d4d2013-11-27 08:14:41139 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40140 private:
[email protected]dd705d4d2013-11-27 08:14:41141 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40142
143 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
144
145 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
146};
147
[email protected]dd705d4d2013-11-27 08:14:41148ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40149 static TextInputModeMapSingleton* singleton =
150 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41151 TextInputModeMap::const_iterator it =
152 singleton->map().find(input_mode.utf8());
153 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40154 return ui::TEXT_INPUT_MODE_DEFAULT;
155 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13156}
[email protected]b256eca2013-07-11 10:57:40157
[email protected]fd847792013-10-24 17:12:35158// TODO(brianderson): Replace the hard-coded threshold with a fraction of
159// the BeginMainFrame interval.
160// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
161// be spent in input hanlders before input starts getting throttled.
162const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
163
miletus14a25642015-08-13 19:23:23164int64 GetEventLatencyMicros(double event_timestamp, base::TimeTicks now) {
165 return (now - base::TimeDelta::FromSecondsD(event_timestamp))
jdduke07788062014-12-05 03:16:30166 .ToInternalValue();
167}
168
miletus14a25642015-08-13 19:23:23169void LogInputEventLatencyUmaImpl(WebInputEvent::Type event_type,
170 double event_timestamp,
171 base::TimeTicks now) {
172 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.AggregatedLatency.Renderer2",
173 GetEventLatencyMicros(event_timestamp, now), 1,
174 10000000, 100);
jdduke07788062014-12-05 03:16:30175
miletus14a25642015-08-13 19:23:23176#define CASE_TYPE(t) \
177 case WebInputEvent::t: \
178 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer2." #t, \
179 GetEventLatencyMicros(event_timestamp, now), \
180 1, 10000000, 100); \
181 break;
jdduke07788062014-12-05 03:16:30182
miletus14a25642015-08-13 19:23:23183 switch (event_type) {
jdduke07788062014-12-05 03:16:30184 CASE_TYPE(Undefined);
185 CASE_TYPE(MouseDown);
186 CASE_TYPE(MouseUp);
187 CASE_TYPE(MouseMove);
188 CASE_TYPE(MouseEnter);
189 CASE_TYPE(MouseLeave);
190 CASE_TYPE(ContextMenu);
191 CASE_TYPE(MouseWheel);
192 CASE_TYPE(RawKeyDown);
193 CASE_TYPE(KeyDown);
194 CASE_TYPE(KeyUp);
195 CASE_TYPE(Char);
196 CASE_TYPE(GestureScrollBegin);
197 CASE_TYPE(GestureScrollEnd);
198 CASE_TYPE(GestureScrollUpdate);
199 CASE_TYPE(GestureFlingStart);
200 CASE_TYPE(GestureFlingCancel);
201 CASE_TYPE(GestureShowPress);
202 CASE_TYPE(GestureTap);
203 CASE_TYPE(GestureTapUnconfirmed);
204 CASE_TYPE(GestureTapDown);
205 CASE_TYPE(GestureTapCancel);
206 CASE_TYPE(GestureDoubleTap);
207 CASE_TYPE(GestureTwoFingerTap);
208 CASE_TYPE(GestureLongPress);
209 CASE_TYPE(GestureLongTap);
210 CASE_TYPE(GesturePinchBegin);
211 CASE_TYPE(GesturePinchEnd);
212 CASE_TYPE(GesturePinchUpdate);
213 CASE_TYPE(TouchStart);
214 CASE_TYPE(TouchMove);
215 CASE_TYPE(TouchEnd);
216 CASE_TYPE(TouchCancel);
217 default:
218 // Must include default to let blink::WebInputEvent add new event types
219 // before they're added here.
miletus14a25642015-08-13 19:23:23220 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event_type;
jdduke07788062014-12-05 03:16:30221 break;
222 }
223
224#undef CASE_TYPE
225}
226
miletus14a25642015-08-13 19:23:23227void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now,
228 const ui::LatencyInfo& latency_info) {
229 LogInputEventLatencyUmaImpl(event.type, event.timeStampSeconds, now);
230 for (size_t i = 0; i < latency_info.coalesced_events_size(); i++) {
231 LogInputEventLatencyUmaImpl(
232 event.type,
233 latency_info.timestamps_of_coalesced_events()[i],
234 now);
235 }
236}
237
[email protected]b256eca2013-07-11 10:57:40238} // namespace
239
[email protected]e9ff79c2012-10-19 21:31:26240namespace content {
[email protected]62cb33cae2009-03-27 23:30:22241
[email protected]b2e4c70132013-10-03 02:07:51242// RenderWidget::ScreenMetricsEmulator ----------------------------------------
243
244class RenderWidget::ScreenMetricsEmulator {
245 public:
246 ScreenMetricsEmulator(
247 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43248 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51249 virtual ~ScreenMetricsEmulator();
250
[email protected]19193682014-04-03 15:01:43251 // Scale and offset used to convert between host coordinates
252 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51253 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20254 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43255 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51256 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56257 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51258
259 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43260 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51261
262 // The following methods alter handlers' behavior for messages related to
263 // widget size and position.
264 void OnResizeMessage(const ViewMsg_Resize_Params& params);
265 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
266 const gfx::Rect& window_screen_rect);
267 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31268 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51269
270 private:
[email protected]19193682014-04-03 15:01:43271 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02272 void Apply(bool top_controls_shrink_blink_size,
273 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44274 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12275 bool is_fullscreen_granted,
276 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51277
278 RenderWidget* widget_;
279
[email protected]7f99fc22013-11-08 14:05:58280 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43281 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51282
[email protected]a179d3962013-11-12 14:44:40283 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51284 float scale_;
dgozman9260b0a12015-03-16 13:45:20285 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51286
[email protected]19193682014-04-03 15:01:43287 // Widget rect as passed to webwidget.
288 gfx::Rect applied_widget_rect_;
289
[email protected]b2e4c70132013-10-03 02:07:51290 // Original values to restore back after emulation ends.
291 gfx::Size original_size_;
292 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28293 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46294 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51295 gfx::Rect original_view_screen_rect_;
296 gfx::Rect original_window_screen_rect_;
297};
298
299RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
300 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43301 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51302 : widget_(widget),
[email protected]19193682014-04-03 15:01:43303 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51304 scale_(1.f) {
305 original_size_ = widget_->size_;
306 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28307 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51308 original_screen_info_ = widget_->screen_info_;
309 original_view_screen_rect_ = widget_->view_screen_rect_;
310 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02311 Apply(widget_->top_controls_shrink_blink_size_,
312 widget_->top_controls_height_,
313 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12314 widget_->is_fullscreen_granted_,
315 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51316}
317
318RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
319 widget_->screen_info_ = original_screen_info_;
320
321 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20322 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51323 widget_->view_screen_rect_ = original_view_screen_rect_;
324 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01325 widget_->Resize(original_size_,
326 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02327 widget_->top_controls_shrink_blink_size_,
328 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01329 original_visible_viewport_size_,
330 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12331 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12332 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01333 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51334}
335
336void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43337 const WebDeviceEmulationParams& params) {
338 params_ = params;
339 Reapply();
340}
341
342void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02343 Apply(widget_->top_controls_shrink_blink_size_,
344 widget_->top_controls_height_,
345 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12346 widget_->is_fullscreen_granted_,
347 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51348}
349
[email protected]19193682014-04-03 15:01:43350void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02351 bool top_controls_shrink_blink_size,
352 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44353 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12354 bool is_fullscreen_granted,
355 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31356 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
357 if (!applied_widget_rect_.width())
358 applied_widget_rect_.set_width(original_size_.width());
359 if (!applied_widget_rect_.height())
360 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43361
[email protected]f442ee42014-05-14 11:53:12362 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02363 int original_width = std::max(original_size_.width(), 1);
364 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51365 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02366 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51367 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02368 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51369 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
370 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01371
372 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43373 offset_.set_x(
374 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01375 offset_.set_y(
[email protected]19193682014-04-03 15:01:43376 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51377 } else {
[email protected]0b3578c2014-06-20 18:29:02378 scale_ = params_.scale;
379 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01380 }
[email protected]7f0e8fa2014-03-26 12:32:01381
[email protected]19193682014-04-03 15:01:43382 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
383 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01384 widget_->screen_info_.rect = original_screen_info_.rect;
385 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
386 widget_->window_screen_rect_ = original_window_screen_rect_;
387 } else {
dgozmanf28ccbe2015-06-24 08:50:49388 applied_widget_rect_.set_origin(params_.viewPosition);
389 gfx::Rect screen_rect = applied_widget_rect_;
390 if (!params_.screenSize.isEmpty()) {
391 screen_rect =
392 gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height);
393 }
394 widget_->screen_info_.rect = screen_rect;
395 widget_->screen_info_.availableRect = screen_rect;
[email protected]19193682014-04-03 15:01:43396 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01397 }
[email protected]a179d3962013-11-12 14:44:40398
[email protected]19193682014-04-03 15:01:43399 float applied_device_scale_factor = params_.deviceScaleFactor ?
400 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01401 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51402
[email protected]7f99fc22013-11-08 14:05:58403 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51404 // - we keep the real device scale factor in compositor to produce sharp image
405 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58406 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51407 // root layer.
dgozman9260b0a12015-03-16 13:45:20408 blink::WebDeviceEmulationParams modified_params = params_;
409 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
410 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
411 modified_params.scale = scale_;
412 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51413
[email protected]7f0e8fa2014-03-26 12:32:01414 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43415 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51416
417 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
418 original_size_, original_screen_info_.deviceScaleFactor));
dtrainorcb7779b82014-12-04 01:08:02419 widget_->Resize(applied_widget_rect_.size(),
420 physical_backing_size,
421 top_controls_shrink_blink_size,
422 top_controls_height,
423 applied_widget_rect_.size(),
424 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12425 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12426 display_mode,
dtrainorcb7779b82014-12-04 01:08:02427 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51428}
429
430void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
431 const ViewMsg_Resize_Params& params) {
432 bool need_ack = params.new_size != original_size_ &&
433 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
434 original_size_ = params.new_size;
435 original_physical_backing_size_ = params.physical_backing_size;
436 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28437 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02438 Apply(params.top_controls_shrink_blink_size,
439 params.top_controls_height,
440 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12441 params.is_fullscreen_granted,
442 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51443
444 if (need_ack) {
445 widget_->set_next_paint_is_resize_ack();
446 if (widget_->compositor_)
447 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
448 }
449}
450
451void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
452 const gfx::Rect& view_screen_rect,
453 const gfx::Rect& window_screen_rect) {
454 original_view_screen_rect_ = view_screen_rect;
455 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43456 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
457 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51458}
459
460void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
461 ContextMenuParams* params) {
462 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40463 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51464 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40465 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51466}
467
[email protected]2d6836f42014-07-02 17:25:31468gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
469 const gfx::Rect& anchor) {
470 gfx::Rect scaled = gfx::ToEnclosedRect(gfx::ScaleRect(anchor, scale_));
471 scaled.set_x(scaled.x() + offset_.x());
472 scaled.set_y(scaled.y() + offset_.y());
473 return scaled;
474}
475
[email protected]b2e4c70132013-10-03 02:07:51476// RenderWidget ---------------------------------------------------------------
477
dcheng35d31c112015-07-22 00:17:36478RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
479 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46480 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04481 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03482 bool hidden,
483 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29484 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56485 surface_id_(0),
dcheng35d31c112015-07-22 00:17:36486 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53487 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29488 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30489 init_complete_(false),
dtrainorcb7779b82014-12-04 01:08:02490 top_controls_shrink_blink_size_(false),
491 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29492 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51493 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09494 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29495 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04496 is_hidden_(hidden),
[email protected]7912e822014-04-16 02:37:03497 never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12498 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12499 display_mode_(blink::WebDisplayModeUndefined),
initial.commit09911bf2008-07-26 23:55:29500 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49501 handling_input_event_(false),
jddukec05612b2015-06-25 23:13:18502 handling_event_overscroll_(nullptr),
[email protected]e8f775f2013-02-14 21:00:50503 handling_ime_event_(false),
[email protected]c27dd4f2014-05-22 18:05:19504 handling_event_type_(WebInputEvent::Undefined),
505 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48506 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22507 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44508 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20509 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45510 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40511 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20512 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53513 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12514 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48515 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12516 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04517 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52518 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30519 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13520#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36521 text_field_is_dirty_(false),
[email protected]a4f0d882014-05-01 23:48:10522 body_background_color_(SK_ColorWHITE),
[email protected]0d1ebed12013-08-05 22:01:13523#endif
[email protected]b2e4c70132013-10-03 02:07:51524 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11525 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42526 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51527 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
528 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05529 if (!swapped_out)
530 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27531 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53532 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37533#if defined(OS_ANDROID)
534 text_input_info_history_.push_back(blink::WebTextInputInfo());
535#endif
initial.commit09911bf2008-07-26 23:55:29536}
537
538RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11539 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16540
[email protected]992db4c2011-05-12 15:37:15541 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02542 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15543 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29544}
545
[email protected]484955942010-08-19 16:13:18546// static
[email protected]8085dbc82008-09-26 22:53:44547RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53548 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46549 blink::WebPopupType popup_type,
550 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29551 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36552 scoped_refptr<RenderWidget> widget(new RenderWidget(
553 compositor_deps, popup_type, screen_info, false, false, false));
554 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46555 return widget.get();
[email protected]a635f942012-12-07 10:34:29556 }
557 return NULL;
initial.commit09911bf2008-07-26 23:55:29558}
559
[email protected]484955942010-08-19 16:13:18560// static
kenrba7199832015-01-22 23:44:59561RenderWidget* RenderWidget::CreateForFrame(
562 int routing_id,
563 int surface_id,
564 bool hidden,
565 const blink::WebScreenInfo& screen_info,
566 CompositorDependencies* compositor_deps,
567 blink::WebLocalFrame* frame) {
568 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36569 scoped_refptr<RenderWidget> widget(
570 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
571 false, hidden, false));
kenrba7199832015-01-22 23:44:59572 widget->routing_id_ = routing_id;
573 widget->surface_id_ = surface_id;
simonhong628f9812015-04-27 23:13:20574 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59575 // DoInit increments the reference count on |widget|, keeping it alive after
576 // this function returns.
dcheng35d31c112015-07-22 00:17:36577 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59578 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
579 nullptr)) {
580 widget->CompleteInit();
581 return widget.get();
582 }
583 return nullptr;
584}
585
586// static
dchengda9b4bb2015-07-20 20:58:08587blink::WebWidget* RenderWidget::CreateWebFrameWidget(
588 RenderWidget* render_widget,
589 blink::WebLocalFrame* frame) {
590 return blink::WebFrameWidget::create(render_widget, frame);
591}
592
593// static
kenrba7199832015-01-22 23:44:59594blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18595 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46596 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18597 break;
[email protected]180ef242013-11-07 06:50:46598 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44599 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18600 default:
601 NOTREACHED();
602 }
603 return NULL;
604}
605
dchengda9b4bb2015-07-20 20:58:08606void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32607 OnClose();
kenrba7199832015-01-22 23:44:59608}
609
dcheng35d31c112015-07-22 00:17:36610bool RenderWidget::Init(int32 opener_id) {
611 return DoInit(opener_id, RenderWidget::CreateWebWidget(this),
[email protected]a635f942012-12-07 10:34:29612 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
613 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18614}
615
[email protected]a635f942012-12-07 10:34:29616bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06617 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18618 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29619 DCHECK(!webwidget_);
620
621 if (opener_id != MSG_ROUTING_NONE)
622 opener_id_ = opener_id;
623
[email protected]484955942010-08-19 16:13:18624 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29625
kenrba7199832015-01-22 23:44:59626 bool result = true;
627 if (create_widget_message)
628 result = RenderThread::Get()->Send(create_widget_message);
629
initial.commit09911bf2008-07-26 23:55:29630 if (result) {
[email protected]380244092011-10-07 17:26:27631 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29632 // Take a reference on behalf of the RenderThread. This will be balanced
633 // when we receive ViewMsg_Close.
634 AddRef();
[email protected]b2db9272014-01-10 17:42:00635 if (RenderThreadImpl::current()) {
636 RenderThreadImpl::current()->WidgetCreated();
637 if (is_hidden_)
638 RenderThreadImpl::current()->WidgetHidden();
639 }
[email protected]a635f942012-12-07 10:34:29640 return true;
initial.commit09911bf2008-07-26 23:55:29641 } else {
[email protected]a635f942012-12-07 10:34:29642 // The above Send can fail when the tab is closing.
643 return false;
initial.commit09911bf2008-07-26 23:55:29644 }
645}
646
[email protected]fc4404d2012-11-07 19:53:30647// This is used to complete pending inits and non-pending inits.
648void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29649 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29650
[email protected]fc4404d2012-11-07 19:53:30651 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42652
[email protected]7912e822014-04-16 02:37:03653 if (compositor_)
654 StartCompositor();
initial.commit09911bf2008-07-26 23:55:29655
[email protected]6de74452009-02-25 18:04:59656 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29657}
658
[email protected]992db4c2011-05-12 15:37:15659void RenderWidget::SetSwappedOut(bool is_swapped_out) {
660 // We should only toggle between states.
661 DCHECK(is_swapped_out_ != is_swapped_out);
662 is_swapped_out_ = is_swapped_out;
663
664 // If we are swapping out, we will call ReleaseProcess, allowing the process
665 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52666 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15667 // If we are swapping in, we call AddRefProcess to prevent the process from
668 // exiting.
[email protected]949b6592014-08-20 13:17:52669 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15670 RenderProcess::current()->AddRefProcess();
671}
672
[email protected]949b6592014-08-20 13:17:52673void RenderWidget::WasSwappedOut() {
674 // If we have been swapped out and no one else is using this process,
675 // it's safe to exit now.
676 CHECK(is_swapped_out_);
677 RenderProcess::current()->ReleaseProcess();
678}
679
[email protected]b2e4c70132013-10-03 02:07:51680void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
681 ScreenMetricsEmulator* emulator) {
682 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43683 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49684 popup_screen_origin_for_emulation_ = gfx::Point(
685 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
686 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56687 screen_info_ = emulator->original_screen_info();
688 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51689}
690
[email protected]2d6836f42014-07-02 17:25:31691gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
692 if (screen_metrics_emulator_)
693 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
694 return anchor;
695}
696
[email protected]b2e4c70132013-10-03 02:07:51697void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20698 bool enabled,
699 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51700 // This is only supported in RenderView.
701 NOTREACHED();
702}
703
[email protected]53907862014-03-25 15:42:40704#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51705void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
706 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49707 popup->SetOriginScaleAndOffsetForEmulation(
708 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51709}
[email protected]53907862014-03-25 15:42:40710#endif
[email protected]b2e4c70132013-10-03 02:07:51711
712void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
713 if (screen_metrics_emulator_)
714 screen_metrics_emulator_->OnShowContextMenu(params);
715}
716
[email protected]a95986a82010-12-24 06:19:28717bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
718 bool handled = true;
719 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15720 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22721 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
722 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22723 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
724 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15725 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
726 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35727 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
728 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28729 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
730 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
731 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20732 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
733 OnEnableDeviceEmulation)
734 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
735 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41736 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54737 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28738 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41739 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25740 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28741 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
742 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03743 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05744 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21745#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37746 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
[email protected]2384b6c2013-02-28 23:58:51747 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21748#endif
[email protected]a95986a82010-12-24 06:19:28749 IPC_MESSAGE_UNHANDLED(handled = false)
750 IPC_END_MESSAGE_MAP()
751 return handled;
752}
initial.commit09911bf2008-07-26 23:55:29753
754bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15755 // Don't send any messages after the browser has told us to close, and filter
756 // most outgoing messages while swapped out.
757 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26758 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11759 closing_) {
initial.commit09911bf2008-07-26 23:55:29760 delete message;
761 return false;
762 }
763
764 // If given a messsage without a routing ID, then assign our routing ID.
765 if (message->routing_id() == MSG_ROUTING_NONE)
766 message->set_routing_id(routing_id_);
767
[email protected]380244092011-10-07 17:26:27768 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44769}
770
[email protected]61e2b3cc2012-03-02 16:13:34771void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44772 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02773 bool top_controls_shrink_blink_size,
774 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44775 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34776 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12777 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12778 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58779 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56780 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48781 // A resize ack shouldn't be requested if we have not ACK'd the previous
782 // one.
783 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
784 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
785 }
initial.commit09911bf2008-07-26 23:55:29786
[email protected]61e2b3cc2012-03-02 16:13:34787 // Ignore this during shutdown.
788 if (!webwidget_)
789 return;
790
[email protected]d9083762013-03-24 01:36:40791 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44792 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40793 }
[email protected]60d47ac2013-03-01 23:42:44794
[email protected]dade8992013-03-04 07:34:34795 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02796 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
797 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28798 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34799 resizer_rect_ = resizer_rect;
800
801 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12802 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12803 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12804 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34805
aelias6004fe02015-02-07 21:43:01806 webwidget_->setTopControlsHeight(top_controls_height,
807 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43808
[email protected]61e2b3cc2012-03-02 16:13:34809 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34810 size_ = new_size;
811
[email protected]61e2b3cc2012-03-02 16:13:34812 // When resizing, we want to wait to paint before ACK'ing the resize. This
813 // ensures that we only resize as fast as we can paint. We only need to
814 // send an ACK if we are resized to a non-empty rect.
815 webwidget_->resize(new_size);
[email protected]632c4382013-05-15 08:58:45816 }
817
[email protected]bb6378fe2014-04-28 21:19:44818 webwidget()->resizePinchViewport(gfx::Size(
819 visible_viewport_size.width(),
820 visible_viewport_size.height()));
821
[email protected]632c4382013-05-15 08:58:45822 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58823 // In this case there is no paint/composite and therefore no
824 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
825 // ack through a fake ViewHostMsg_UpdateRect or a different message.
826 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34827 }
828
[email protected]20fbfc22013-05-08 20:50:58829 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45830 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58831 set_next_paint_is_resize_ack();
832
[email protected]61e2b3cc2012-03-02 16:13:34833 if (fullscreen_change)
834 DidToggleFullscreen();
835
836 // If a resize ack is requested and it isn't set-up, then no more resizes will
837 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45838 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29839}
840
bokanc007c3a2015-02-03 07:15:56841void RenderWidget::SetWindowRectSynchronously(
842 const gfx::Rect& new_window_rect) {
843 Resize(new_window_rect.size(),
844 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02845 top_controls_shrink_blink_size_,
846 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56847 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01848 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12849 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12850 display_mode_,
[email protected]587941d2014-08-22 01:40:01851 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56852 view_screen_rect_ = new_window_rect;
853 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02854 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56855 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02856}
857
initial.commit09911bf2008-07-26 23:55:29858void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32859 DCHECK(content::RenderThread::Get());
860 if (closing_)
861 return;
862 NotifyOnClose();
863 closing_ = true;
864
865 // Browser correspondence is no longer needed at this point.
866 if (routing_id_ != MSG_ROUTING_NONE) {
867 RenderThread::Get()->RemoveRoute(routing_id_);
868 SetHidden(false);
869 if (RenderThreadImpl::current())
870 RenderThreadImpl::current()->WidgetDestroyed();
871 }
872
873 if (for_oopif_) {
874 // Widgets for frames may be created and closed at any time while the frame
875 // is alive. However, the closing process must happen synchronously. Frame
876 // widget and frames hold pointers to each other. If Close() is deferred to
877 // the message loop like in the non-frame widget case, WebWidget::close()
878 // can end up accessing members of an already-deleted frame.
879 Close();
880 } else {
881 // If there is a Send call on the stack, then it could be dangerous to close
882 // now. Post a task that only gets invoked when there are no nested message
883 // loops.
884 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
885 FROM_HERE, base::Bind(&RenderWidget::Close, this));
886 }
887
888 // Balances the AddRef taken when we called AddRoute.
889 Release();
initial.commit09911bf2008-07-26 23:55:29890}
891
[email protected]61e2b3cc2012-03-02 16:13:34892// Got a response from the browser after the renderer decided to create a new
893// view.
[email protected]fc4404d2012-11-07 19:53:30894void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34895 DCHECK(routing_id_ != MSG_ROUTING_NONE);
896
[email protected]fc4404d2012-11-07 19:53:30897 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34898}
899
[email protected]0fdd5012013-05-29 08:05:56900void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04901 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32902 return;
903
[email protected]b2e4c70132013-10-03 02:07:51904 if (screen_metrics_emulator_) {
905 screen_metrics_emulator_->OnResizeMessage(params);
906 return;
907 }
908
[email protected]fcdc5642014-05-09 14:32:24909 bool orientation_changed =
910 screen_info_.orientationAngle != params.screen_info.orientationAngle;
911
[email protected]0fdd5012013-05-29 08:05:56912 screen_info_ = params.screen_info;
913 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02914 Resize(params.new_size,
915 params.physical_backing_size,
916 params.top_controls_shrink_blink_size,
917 params.top_controls_height,
918 params.visible_viewport_size,
919 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12920 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12921 params.display_mode,
sievers4e33dae2015-02-25 20:43:58922 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24923
924 if (orientation_changed)
925 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29926}
927
dgozman9260b0a12015-03-16 13:45:20928void RenderWidget::OnEnableDeviceEmulation(
929 const blink::WebDeviceEmulationParams& params) {
930 if (!screen_metrics_emulator_)
931 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
932 else
933 screen_metrics_emulator_->ChangeEmulationParams(params);
934}
935
936void RenderWidget::OnDisableDeviceEmulation() {
937 screen_metrics_emulator_.reset();
938}
939
noel89949e62014-09-30 01:12:41940void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
941 SetDeviceColorProfile(color_profile);
942}
943
[email protected]b5913d72012-02-07 22:26:54944void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01945 if (resizer_rect_ == resizer_rect)
946 return;
947 resizer_rect_ = resizer_rect;
948 if (webwidget_)
949 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54950}
951
initial.commit09911bf2008-07-26 23:55:29952void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31953 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29954 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03955 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59956 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
957 WasHidden());
initial.commit09911bf2008-07-26 23:55:29958}
959
[email protected]3399dd822014-08-09 11:14:24960void RenderWidget::OnWasShown(bool needs_repainting,
961 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41962 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29963 // During shutdown we can just ignore this message.
964 if (!webwidget_)
965 return;
966
967 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03968 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59969 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
970 WasShown());
initial.commit09911bf2008-07-26 23:55:29971
[email protected]8a23afb32014-04-30 22:40:23972 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29973 return;
initial.commit09911bf2008-07-26 23:55:29974
975 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24976 if (compositor_) {
977 ui::LatencyInfo swap_latency_info(latency_info);
978 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
979 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05980 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24981 }
jdduke491a3f0c2015-06-15 23:30:26982 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29983}
984
[email protected]53d3f302009-12-21 04:42:05985void RenderWidget::OnRequestMoveAck() {
986 DCHECK(pending_window_rect_count_);
987 pending_window_rect_count_--;
988}
989
[email protected]ed7defa2013-03-12 21:29:59990GURL RenderWidget::GetURLForGraphicsContext3D() {
991 return GURL();
[email protected]65225772011-05-12 21:10:24992}
993
[email protected]ebc0e1df2013-08-01 02:46:22994scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03995 // For widgets that are never visible, we don't start the compositor, so we
996 // never get a request for a cc::OutputSurface.
997 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19998
999#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:011000 if (SynchronousCompositorFactory* factory =
1001 SynchronousCompositorFactory::GetInstance()) {
boliuaeb1e4c2015-07-29 03:09:381002 return factory->CreateOutputSurface(routing_id(), surface_id(),
[email protected]586871b2014-07-22 17:05:111003 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:191004 }
1005#endif
1006
avi83883c82014-12-23 00:08:491007 const base::CommandLine& command_line =
1008 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:331009 bool use_software = fallback;
1010 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
1011 use_software = true;
1012
[email protected]0634cdd42013-08-16 00:46:091013 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:171014 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:331015 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:091016 context_provider = ContextProviderCommandBuffer::Create(
jbauman5e420d32015-08-05 09:33:011017 CreateGraphicsContext3D(true), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:331018 if (!context_provider.get()) {
1019 // Cause the compositor to wait and try again.
1020 return scoped_ptr<cc::OutputSurface>();
1021 }
vmiura78b69282015-02-14 00:01:171022
1023 worker_context_provider = ContextProviderCommandBuffer::Create(
jbauman5e420d32015-08-05 09:33:011024 CreateGraphicsContext3D(false), RENDER_WORKER_CONTEXT);
vmiura78b69282015-02-14 00:01:171025 if (!worker_context_provider.get()) {
1026 // Cause the compositor to wait and try again.
1027 return scoped_ptr<cc::OutputSurface>();
1028 }
[email protected]0634cdd42013-08-16 00:46:091029 }
[email protected]ebc0e1df2013-08-01 02:46:221030
[email protected]b6eb8e332013-09-10 00:51:011031 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:001032 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:531033 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
caseqff9c74c2015-02-10 14:56:291034 return scoped_ptr<cc::OutputSurface>(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171035 routing_id(), output_surface_id, context_provider,
1036 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091037 }
[email protected]0634cdd42013-08-16 00:46:091038 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091039 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121040 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091041
caseqff9c74c2015-02-10 14:56:291042 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
1043 routing_id(), output_surface_id, nullptr, nullptr,
1044 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221045 }
[email protected]ed7defa2013-03-12 21:29:591046
[email protected]36e5ff12013-06-11 12:19:291047 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:451048 // Composite-to-mailbox is currently used for layout tests in order to cause
1049 // them to draw inside in the renderer to do the readback there. This should
1050 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:531051 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:161052 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:271053 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:161054 format = cc::RGB_565;
caseqff9c74c2015-02-10 14:56:291055 return scoped_ptr<cc::OutputSurface>(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171056 routing_id(), output_surface_id, context_provider,
1057 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1058 frame_swap_message_queue_, format));
[email protected]36e5ff12013-06-11 12:19:291059 }
[email protected]0634cdd42013-08-16 00:46:091060 bool use_swap_compositor_frame_message = false;
caseqff9c74c2015-02-10 14:56:291061 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171062 routing_id(), output_surface_id, context_provider,
1063 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1064 frame_swap_message_queue_, use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281065}
1066
[email protected]4d7e46a2013-11-08 05:33:401067void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241068 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241069 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:261070 ScheduleComposite();
[email protected]65225772011-05-12 21:10:241071}
1072
[email protected]4d7e46a2013-11-08 05:33:401073void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081074 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081075}
1076
[email protected]4d7e46a2013-11-08 05:33:401077void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241078 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161079
[email protected]404939f2012-06-01 04:06:181080 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161081 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291082}
1083
[email protected]180ef242013-11-07 06:50:461084void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351085 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091086 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191087 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291088 return;
jddukec05612b2015-06-25 23:13:181089 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_,
1090 true);
[email protected]c27dd4f2014-05-22 18:05:191091 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1092 &handling_event_type_, input_event->type);
jddukec05612b2015-06-25 23:13:181093
1094 // Calls into |didOverscroll()| while handling this event will populate
1095 // |event_overscroll|, which in turn will be bundled with the event ack.
1096 scoped_ptr<DidOverscrollParams> event_overscroll;
1097 base::AutoReset<scoped_ptr<DidOverscrollParams>*>
1098 handling_event_overscroll_resetter(&handling_event_overscroll_,
1099 &event_overscroll);
1100
[email protected]25402eb2014-07-18 03:09:521101#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541102 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521103 // |AdapterInputConnection| generates input key events to make sure all JS
1104 // listeners that monitor KeyUp and KeyDown events receive the proper key
1105 // code. Since this input key event comes from IME, we need to set the
1106 // IME event guard here to make sure it does not interfere with other IME
1107 // events.
1108 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1109 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1110 const WebKeyboardEvent& key_event =
1111 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541112 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171113 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091114 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1115 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1116 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1117 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1118 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521119 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521120 }
1121#endif
initial.commit09911bf2008-07-26 23:55:291122
[email protected]fd847792013-10-24 17:12:351123 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411124 if (base::TimeTicks::IsHighResolution())
1125 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351126
miletusfed8c43b2015-01-26 20:04:521127 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301128 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151129 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
yuhaoz8df9334c2015-08-18 17:48:511130 TRACE_EVENT_WITH_FLOW1("input,benchmark",
1131 "LatencyInfo.Flow",
1132 TRACE_ID_DONT_MANGLE(latency_info.trace_id()),
1133 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
1134 "step", "HandleInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101135
jdduke07788062014-12-05 03:16:301136 // If we don't have a high res timer, these metrics won't be accurate enough
1137 // to be worth collecting. Note that this does introduce some sampling bias.
1138 if (!start_time.is_null())
miletus14a25642015-08-13 19:23:231139 LogInputEventLatencyUma(*input_event, start_time, latency_info);
jdduke07788062014-12-05 03:16:301140
[email protected]6be422b2013-12-08 06:47:311141 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351142 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311143 if (compositor_) {
1144 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351145 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1146 .Pass();
[email protected]6be422b2013-12-08 06:47:311147 }
[email protected]c2eaa8f2013-05-10 02:41:551148
[email protected]67bfb83f2011-09-22 03:36:371149 bool prevent_default = false;
1150 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261151 const WebMouseEvent& mouse_event =
1152 *static_cast<const WebMouseEvent*>(input_event);
1153 TRACE_EVENT2("renderer", "HandleMouseMove",
1154 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421155 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261156 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371157 }
1158
[email protected]cefe9b152014-03-27 18:16:151159 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421160 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151161#if defined(OS_ANDROID)
1162 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1163 // case it should behave like a select key (i.e. causing a click if a button
1164 // is focused). However, if a text field is focused (2), its intended
1165 // behavior is to just show the IME and don't propagate the key.
1166 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1167 // when clicked on an input text field and cause the form submit if clicked
1168 // when the submit button is focused, but not vice-versa.
1169 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1170 // but at this point we have to swallow the event for the scenario (2).
1171 const WebKeyboardEvent& key_event =
1172 *static_cast<const WebKeyboardEvent*>(input_event);
1173 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1174 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1175 OnShowImeIfNeeded();
1176 prevent_default = true;
1177 }
1178#endif
1179 }
[email protected]f56c7872013-06-18 12:31:571180
[email protected]41d86852012-11-07 12:23:241181 if (WebInputEvent::isGestureEventType(input_event->type)) {
1182 const WebGestureEvent& gesture_event =
1183 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421184 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241185 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1186 }
1187
[email protected]67bfb83f2011-09-22 03:36:371188 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121189 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1190 suppress_next_char_events_ = false;
1191 if (!processed && webwidget_)
1192 processed = webwidget_->handleInputEvent(*input_event);
1193 }
1194
1195 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1196 // it's not processed by webkit, then we need to suppress the upcoming Char
1197 // events.
1198 if (!processed && is_keyboard_shortcut)
1199 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291200
[email protected]3d5c243b2012-11-30 00:26:011201 InputEventAckState ack_result = processed ?
1202 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1203 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1204 const WebTouchEvent& touch_event =
1205 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251206 // Hit-test for all the pressed touch points. If there is a touch-handler
1207 // for any of the touch points, then the renderer should continue to receive
1208 // touch events.
1209 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1210 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1211 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271212 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391213 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251214 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1215 break;
1216 }
1217 }
[email protected]3d5c243b2012-11-30 00:26:011218 }
1219
ccamerond4ba47902014-12-17 07:20:311220 // Send mouse wheel events and their disposition to the compositor thread, so
1221 // that they can be used to produce the elastic overscroll effect on Mac.
1222 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311223 ObserveWheelEventAndResult(
sataya.mf405d0e2015-07-07 16:51:111224 static_cast<const WebMouseWheelEvent&>(*input_event),
1225 event_overscroll ? event_overscroll->latest_overscroll_delta
1226 : gfx::Vector2dF(),
1227 processed);
ccamerond4ba47902014-12-17 07:20:311228 }
1229
[email protected]721e2302014-04-30 23:42:011230 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061231
charliea3be839702015-01-26 17:35:411232 // If we don't have a fast and accurate Now(), we assume the input handlers
1233 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301234 bool rate_limiting_wanted =
1235 input_event->type == WebInputEvent::MouseMove ||
1236 input_event->type == WebInputEvent::MouseWheel;
1237 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411238 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351239 total_input_handling_time_this_frame_ += (end_time - start_time);
1240 rate_limiting_wanted =
1241 total_input_handling_time_this_frame_.InMicroseconds() >
1242 kInputHandlingTimeThrottlingThresholdMicroseconds;
1243 }
1244
[email protected]7f19e9d2014-05-09 15:16:291245 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1246
[email protected]c27dd4f2014-05-22 18:05:191247 // Note that we can't use handling_event_type_ here since it will be overriden
1248 // by reentrant calls for events after the paused one.
1249 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1250 input_event->type == WebInputEvent::MouseMove;
lanweif1a22832015-05-19 17:24:101251 if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) &&
1252 !no_ack) {
1253 InputEventAck ack(input_event->type, ack_result, swap_latency_info,
jddukec05612b2015-06-25 23:13:181254 event_overscroll.Pass(),
lanweif1a22832015-05-19 17:24:101255 WebInputEventTraits::GetUniqueTouchEventId(*input_event));
[email protected]34afe102013-12-13 17:24:551256 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561257 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301258 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551259 // We want to rate limit the input events in this case, so we'll wait for
1260 // painting to finish before ACKing this message.
1261 TRACE_EVENT_INSTANT0("renderer",
1262 "RenderWidget::OnHandleInputEvent ack throttled",
1263 TRACE_EVENT_SCOPE_THREAD);
1264 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291265 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1266 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551267 // As two different kinds of events could cause us to postpone an ack
1268 // we send it now, if we have one pending. The Browser should never
1269 // send us the same kind of event we are delaying the ack for.
1270 Send(pending_input_event_ack_.release());
1271 }
1272 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291273 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1274 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551275 if (compositor_)
1276 compositor_->NotifyInputThrottledUntilCommit();
1277 } else {
1278 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171279 }
jddukec05612b2015-06-25 23:13:181280 } else {
1281 DCHECK(!event_overscroll) << "Unexpected overscroll for un-acked event";
[email protected]12fbad812009-09-01 18:21:241282 }
alexclarke7819e2552015-06-03 11:17:211283 if (!no_ack && RenderThreadImpl::current()) {
1284 RenderThreadImpl::current()
1285 ->GetRendererScheduler()
1286 ->DidHandleInputEventOnMainThread(*input_event);
1287 }
[email protected]5fea4a52014-05-27 00:17:521288 if (input_event->type == WebInputEvent::MouseMove)
1289 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241290
[email protected]3306f262012-09-21 19:20:421291#if defined(OS_ANDROID)
1292 // Allow the IME to be shown when the focus changes as a consequence
1293 // of a processed touch end event.
1294 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361295 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021296#elif defined(USE_AURA)
1297 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1298 // change.
1299 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141300 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361301 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141302 }
[email protected]3306f262012-09-21 19:20:421303#endif
1304
[email protected]67bfb83f2011-09-22 03:36:371305 if (!prevent_default) {
1306 if (WebInputEvent::isKeyboardEventType(input_event->type))
1307 DidHandleKeyEvent();
[email protected]67bfb83f2011-09-22 03:36:371308 }
rouslanf7ebd8832015-01-22 01:54:141309
1310// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1311// virtual keyboard.
1312#if !defined(OS_ANDROID)
1313 // Virtual keyboard is not supported, so react to focus change immediately.
1314 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1315 input_event->type == WebInputEvent::MouseUp)) {
1316 FocusChangeComplete();
1317 }
1318#endif
initial.commit09911bf2008-07-26 23:55:291319}
1320
[email protected]34202de2013-05-06 23:36:221321void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1322 if (webwidget_)
1323 webwidget_->setCursorVisibilityState(is_visible);
1324}
1325
initial.commit09911bf2008-07-26 23:55:291326void RenderWidget::OnMouseCaptureLost() {
1327 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281328 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291329}
1330
1331void RenderWidget::OnSetFocus(bool enable) {
1332 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331333 if (webwidget_)
1334 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291335}
1336
1337void RenderWidget::ClearFocus() {
1338 // We may have got the focus from the browser before this gets processed, in
1339 // which case we do not want to unfocus ourself.
1340 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281341 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291342}
1343
[email protected]fd847792013-10-24 17:12:351344void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291345 if (pending_input_event_ack_) {
1346 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1347 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071348 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291349 }
[email protected]fd847792013-10-24 17:12:351350 total_input_handling_time_this_frame_ = base::TimeDelta();
1351}
1352
initial.commit09911bf2008-07-26 23:55:291353///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461354// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291355
[email protected]244ac1892011-12-02 17:04:471356void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091357 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451358 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581359
[email protected]5b45ad42013-10-25 00:42:041360 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451361 WebRect new_pos(rootWindowRect().x,
1362 rootWindowRect().y,
1363 new_size.width,
1364 new_size.height);
1365 view_screen_rect_ = new_pos;
1366 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031367 }
[email protected]20fbfc22013-05-08 20:50:581368
[email protected]eac2b362013-05-22 07:01:451369 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581370
[email protected]5b45ad42013-10-25 00:42:041371 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581372 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091373 }
[email protected]244ac1892011-12-02 17:04:471374}
1375
[email protected]3a1c8a8032013-03-18 22:35:321376void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051377 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1378 device_scale_factor_));
1379 if (compositor_)
1380 compositor_->setViewportSize(size_, physical_backing_size_);
1381}
1382
[email protected]e195e582013-03-08 01:32:591383void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221384 DCHECK(!host_closing_);
1385
danakj6e3bf8012014-12-16 18:27:531386 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591387 compositor_->setViewportSize(size_, physical_backing_size_);
1388 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031389 StartCompositor();
[email protected]e195e582013-03-08 01:32:591390}
1391
ennef3c58142014-12-09 21:44:381392void RenderWidget::WillCloseLayerTreeView() {
1393 if (host_closing_)
1394 return;
1395
1396 // Prevent new compositors or output surfaces from being created.
1397 host_closing_ = true;
1398
[email protected]aeeedad2014-08-22 18:16:221399 // Always send this notification to prevent new layer tree views from
1400 // being created, even if one hasn't been created yet.
1401 if (webwidget_)
1402 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221403}
1404
[email protected]180ef242013-11-07 06:50:461405blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281406 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061407}
1408
dglazkov79c426102015-08-31 21:22:431409void RenderWidget::didFirstVisuallyNonEmptyLayout() {
1410 // TODO(dglazkov): Remove this -- we should just pass background color
1411 // in CompositorFrameMetadata.
1412#if defined(OS_ANDROID)
1413 DidChangeBodyBackgroundColor(webwidget_->backgroundColor());
1414#endif
1415
1416 QueueMessage(
1417 new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1418 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1419}
1420
1421void RenderWidget::didFirstLayoutAfterFinishedParsing() {
1422 // TODO(dglazkov): Use this hook to drive CapturePageInfo.
1423}
1424
jdduke491a3f0c2015-06-15 23:30:261425void RenderWidget::WillBeginCompositorFrame() {
[email protected]9cd43a62012-03-26 08:03:561426 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371427
shuchen913f8b622015-07-31 13:22:431428 // The UpdateTextInputState can result in further layout and possibly
[email protected]abe8b3a2012-03-28 21:19:371429 // enable GPU acceleration so they need to be called before any painting
1430 // is done.
[email protected]90f24152014-04-09 12:41:361431 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
[email protected]abe8b3a2012-03-28 21:19:371432 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561433}
1434
[email protected]6fceb912013-02-15 06:24:151435void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441436 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1437 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271438 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161439 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171440#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271441 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1442 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171443#endif // defined(VIDEO_HOLE)
jdduke491a3f0c2015-06-15 23:30:261444 FlushPendingInputEventAck();
1445}
1446
1447void RenderWidget::DidCommitAndDrawCompositorFrame() {
1448 // NOTE: Tests may break if this event is renamed or moved. See
1449 // tab_capture_performancetest.cc.
1450 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
1451 // Notify subclasses that we initiated the paint operation.
1452 DidInitiatePaint();
1453}
1454
1455void RenderWidget::DidCompleteSwapBuffers() {
1456 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
1457
1458 // Notify subclasses threaded composited rendering was flushed to the screen.
1459 DidFlushPaint();
1460
1461 if (!next_paint_flags_ &&
1462 !need_update_rect_for_auto_resize_ &&
1463 !plugin_window_moves_.size()) {
1464 return;
1465 }
1466
1467 ViewHostMsg_UpdateRect_Params params;
1468 params.view_size = size_;
1469 params.plugin_window_moves.swap(plugin_window_moves_);
1470 params.flags = next_paint_flags_;
1471
1472 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1473 next_paint_flags_ = 0;
1474 need_update_rect_for_auto_resize_ = false;
1475}
1476
1477void RenderWidget::ScheduleComposite() {
1478 if (compositor_ &&
1479 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1480 compositor_->setNeedsAnimate();
1481 }
1482}
1483
1484void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1485 if (compositor_) {
1486 // Regardless of whether threaded compositing is enabled, always
1487 // use this mechanism to force the compositor to redraw. However,
1488 // the invalidation code path below is still needed for the
1489 // non-threaded case.
1490 compositor_->SetNeedsForcedRedraw();
1491 }
1492 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151493}
1494
[email protected]586871b2014-07-22 17:05:111495// static
1496scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1497 IPC::Message* msg,
1498 MessageDeliveryPolicy policy,
1499 FrameSwapMessageQueue* frame_swap_message_queue,
1500 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111501 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111502 bool first_message_for_frame = false;
1503 frame_swap_message_queue->QueueMessageForFrame(policy,
1504 source_frame_number,
1505 make_scoped_ptr(msg),
1506 &first_message_for_frame);
1507 if (first_message_for_frame) {
1508 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1509 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061510 return promise;
[email protected]586871b2014-07-22 17:05:111511 }
dcheng4b6b5ff2014-10-16 00:42:061512 return nullptr;
[email protected]586871b2014-07-22 17:05:111513}
1514
1515void RenderWidget::QueueMessage(IPC::Message* msg,
1516 MessageDeliveryPolicy policy) {
1517 // RenderThreadImpl::current() is NULL in some tests.
1518 if (!compositor_ || !RenderThreadImpl::current()) {
1519 Send(msg);
1520 return;
1521 }
1522
1523 scoped_ptr<cc::SwapPromise> swap_promise =
1524 QueueMessageImpl(msg,
1525 policy,
dcheng58867a92014-08-26 02:50:221526 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111527 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111528 compositor_->GetSourceFrameNumber());
1529
1530 if (swap_promise) {
1531 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351532 // Request a commit. This might either A) request a commit ahead of time
1533 // or B) request a commit which is not needed because there are not
1534 // pending updates. If B) then the commit will be skipped and the swap
1535 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1536 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1537 // can_cancel_commit is not unset.
1538 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111539 }
1540}
1541
[email protected]4873c7d2009-07-16 06:36:281542void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301543 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521544 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401545 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291546 // Only send a SetCursor message if we need to make a change.
1547 if (!current_cursor_.IsEqual(cursor)) {
1548 current_cursor_ = cursor;
1549 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1550 }
1551}
1552
1553// We are supposed to get a single call to Show for a newly created RenderWidget
1554// that was created via RenderWidget::CreateWebView. So, we wait until this
1555// point to dispatch the ShowWidget message.
1556//
1557// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281558// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291559//
[email protected]4873c7d2009-07-16 06:36:281560void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291561 DCHECK(!did_show_) << "received extraneous Show call";
1562 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1563 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1564
[email protected]8de12d942010-11-17 20:42:441565 if (did_show_)
1566 return;
1567
1568 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561569 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441570 // that's okay. It'll be ignored if as_popup is false, or the browser
1571 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561572 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1573 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291574}
1575
[email protected]4873c7d2009-07-16 06:36:281576void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291577}
1578
[email protected]4873c7d2009-07-16 06:36:281579void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291580}
1581
[email protected]2533ce12009-05-09 00:02:241582void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381583 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241584 Send(new ViewHostMsg_Close(routing_id_));
1585}
1586
dgozmancf9039cd2015-04-06 12:01:311587void RenderWidget::NotifyOnClose() {
1588 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1589}
1590
[email protected]4873c7d2009-07-16 06:36:281591void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081592 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321593 if (is_swapped_out_) {
1594 // This widget is currently swapped out, and the active widget is in a
1595 // different process. Have the browser route the close request to the
1596 // active widget instead, so that the correct unload handlers are run.
1597 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1598 return;
1599 }
1600
initial.commit09911bf2008-07-26 23:55:291601 // If a page calls window.close() twice, we'll end up here twice, but that's
1602 // OK. It is safe to send multiple Close messages.
1603
[email protected]2533ce12009-05-09 00:02:241604 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1605 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1606 // could be closed before the JS finishes executing. So instead, post a
1607 // message back to the message loop, which won't run until the JS is
1608 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081609 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211610 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291611}
1612
[email protected]9017d7852013-11-21 17:47:351613void RenderWidget::QueueSyntheticGesture(
1614 scoped_ptr<SyntheticGestureParams> gesture_params,
1615 const SyntheticGestureCompletionCallback& callback) {
1616 DCHECK(!callback.is_null());
1617
1618 pending_synthetic_gesture_callbacks_.push(callback);
1619
1620 SyntheticGesturePacket gesture_packet;
1621 gesture_packet.set_gesture_params(gesture_params.Pass());
1622
1623 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1624}
1625
initial.commit09911bf2008-07-26 23:55:291626void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031627 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381628 WillCloseLayerTreeView();
1629 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291630 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281631 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291632 webwidget_ = NULL;
1633 }
1634}
1635
[email protected]4873c7d2009-07-16 06:36:281636WebRect RenderWidget::windowRect() {
1637 if (pending_window_rect_count_)
1638 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241639
[email protected]80ad8622012-11-07 16:33:031640 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291641}
1642
[email protected]180ef242013-11-07 06:50:461643void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301644 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541645 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301646}
1647
[email protected]b2e4c70132013-10-03 02:07:511648void RenderWidget::setWindowRect(const WebRect& rect) {
bokanc007c3a2015-02-03 07:15:561649 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511650 if (popup_origin_scale_for_emulation_) {
1651 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561652 window_rect.x = popup_screen_origin_for_emulation_.x() +
1653 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1654 window_rect.y = popup_screen_origin_for_emulation_.y() +
1655 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511656 }
1657
[email protected]5b45ad42013-10-25 00:42:041658 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201659 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561660 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1661 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031662 } else {
bokanc007c3a2015-02-03 07:15:561663 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031664 }
initial.commit09911bf2008-07-26 23:55:291665 } else {
bokanc007c3a2015-02-03 07:15:561666 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291667 }
1668}
1669
[email protected]2533ce12009-05-09 00:02:241670void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1671 pending_window_rect_ = rect;
1672 pending_window_rect_count_++;
1673}
1674
[email protected]4873c7d2009-07-16 06:36:281675WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241676 if (pending_window_rect_count_) {
1677 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1678 // the RootWindowRect is probably going to return wrong results since the
1679 // browser may not have processed the Move yet. There isn't really anything
1680 // good to do in this case, and it shouldn't happen - since this size is
1681 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281682 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241683 }
1684
[email protected]80ad8622012-11-07 16:33:031685 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371686}
1687
[email protected]4873c7d2009-07-16 06:36:281688WebRect RenderWidget::windowResizerRect() {
1689 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191690}
1691
[email protected]fa7b1dc2010-06-23 17:53:041692void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261693 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041694 const std::vector<WebCompositionUnderline>& underlines,
1695 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131696 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281697 return;
[email protected]66fca5bc2013-05-23 06:58:291698 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361699 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041700 text, WebVector<WebCompositionUnderline>(underlines),
1701 selection_start, selection_end)) {
1702 // If we failed to set the composition text, then we need to let the browser
1703 // process to cancel the input method's ongoing composition session, to make
1704 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221705 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261706 }
[email protected]88dbe32f2013-06-20 23:31:361707 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041708}
1709
[email protected]fcf75d42013-12-03 20:11:261710void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511711 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021712 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131713 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041714 return;
[email protected]66fca5bc2013-05-23 06:58:291715 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041716 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021717 if (text.length())
1718 webwidget_->confirmComposition(text);
1719 else if (keep_selection)
1720 webwidget_->confirmComposition(WebWidget::KeepSelection);
1721 else
1722 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041723 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361724 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291725}
1726
[email protected]0bc1f572013-04-17 01:46:311727void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121728 // During shutdown we can just ignore this message.
1729 if (!webwidget_)
1730 return;
1731
[email protected]0bc1f572013-04-17 01:46:311732 // Even if the browser provides an empty damage rect, it's still expecting to
1733 // receive a repaint ack so just damage the entire widget bounds.
1734 if (size_to_paint.IsEmpty()) {
1735 size_to_paint = size_;
1736 }
1737
[email protected]ec7dc112008-08-06 05:30:121738 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051739 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311740 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121741}
1742
[email protected]79fa22e2013-08-23 15:18:121743void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351744 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1745
1746 pending_synthetic_gesture_callbacks_.front().Run();
1747 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271748}
1749
[email protected]4873c7d2009-07-16 06:36:281750void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111751 if (!webwidget_)
1752 return;
[email protected]4873c7d2009-07-16 06:36:281753 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111754}
1755
[email protected]80ad8622012-11-07 16:33:031756void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1757 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511758 if (screen_metrics_emulator_) {
1759 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1760 view_screen_rect, window_screen_rect);
1761 } else {
1762 view_screen_rect_ = view_screen_rect;
1763 window_screen_rect_ = window_screen_rect;
1764 }
[email protected]80ad8622012-11-07 16:33:031765 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1766}
1767
kenrbb4e2a3b2015-05-14 15:05:051768void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1769 if (compositor_)
1770 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1771}
1772
[email protected]adb362312014-06-28 06:04:241773void RenderWidget::showImeIfNeeded() {
1774 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131775}
1776
[email protected]adb362312014-06-28 06:04:241777void RenderWidget::OnShowImeIfNeeded() {
1778#if defined(OS_ANDROID) || defined(USE_AURA)
1779 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1780#endif
rouslanf7ebd8832015-01-22 01:54:141781
1782// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1783// virtual keyboard.
1784#if !defined(OS_ANDROID)
1785 FocusChangeComplete();
1786#endif
[email protected]adb362312014-06-28 06:04:241787}
1788
1789#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371790void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1791 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131792}
1793
1794void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371795 DCHECK_GE(text_input_info_history_.size(), 1u);
1796 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511797}
[email protected]105dffb42013-02-20 03:46:211798#endif
1799
[email protected]0d1ebed12013-08-05 22:01:131800bool RenderWidget::ShouldHandleImeEvent() {
1801#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371802 if (!webwidget_)
1803 return false;
1804
1805 // We cannot handle IME events if there is any chance that the event we are
1806 // receiving here from the browser is based on the state that is different
1807 // from our current one as indicated by |text_input_info_|.
1808 // The states the browser might be in are:
1809 // text_input_info_history_[0] - current state ack'd by browser
1810 // text_input_info_history_[1...N] - pending state changes
1811 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1812 if (text_input_info_history_[i] != text_input_info_)
1813 return false;
1814 }
1815 return true;
[email protected]0d1ebed12013-08-05 22:01:131816#else
1817 return !!webwidget_;
1818#endif
1819}
1820
[email protected]c27dd4f2014-05-22 18:05:191821bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1822 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521823 // If we pause multiple times during a single mouse move event, we should
1824 // only send ACK once.
1825 if (!ignore_ack_for_mouse_move_from_debugger_) {
lanweif1a22832015-05-19 17:24:101826 InputEventAck ack(handling_event_type_, INPUT_EVENT_ACK_STATE_CONSUMED);
[email protected]5fea4a52014-05-27 00:17:521827 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dgozmanb739185d2015-04-10 15:04:021828 return true;
[email protected]5fea4a52014-05-27 00:17:521829 }
[email protected]c27dd4f2014-05-22 18:05:191830 }
1831 return false;
1832}
1833
1834void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1835 ignore_ack_for_mouse_move_from_debugger_ = true;
1836}
1837
[email protected]468ac582012-11-20 00:53:191838void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1839 if (device_scale_factor_ == device_scale_factor)
1840 return;
1841
1842 device_scale_factor_ = device_scale_factor;
jdduke491a3f0c2015-06-15 23:30:261843 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191844}
1845
[email protected]28ed6b32014-06-08 02:16:271846bool RenderWidget::SetDeviceColorProfile(
1847 const std::vector<char>& color_profile) {
1848 if (device_color_profile_ == color_profile)
1849 return false;
1850
1851 device_color_profile_ = color_profile;
1852 return true;
1853}
1854
noeldb4df152014-09-16 17:45:201855void RenderWidget::ResetDeviceColorProfileForTesting() {
1856 if (!device_color_profile_.empty())
1857 device_color_profile_.clear();
1858 device_color_profile_.push_back('0');
1859}
1860
[email protected]fcdc5642014-05-09 14:32:241861void RenderWidget::OnOrientationChange() {
1862}
1863
[email protected]ceb36f7d2012-10-31 18:33:241864gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521865 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241866 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521867}
1868
[email protected]bee16aab2009-08-26 15:55:031869void RenderWidget::SetHidden(bool hidden) {
1870 if (is_hidden_ == hidden)
1871 return;
1872
jdduke8fac9d102014-12-20 02:40:131873 // The status has changed. Tell the RenderThread about it and ensure
1874 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031875 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131876 FlushPendingInputEventAck();
1877
[email protected]bee16aab2009-08-26 15:55:031878 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001879 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031880 else
[email protected]b2db9272014-01-10 17:42:001881 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031882}
1883
[email protected]2b624c562011-10-27 22:58:261884void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261885 if (!webwidget_)
1886 return;
1887
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121888 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261889 webwidget_->didEnterFullScreen();
1890 } else {
1891 webwidget_->didExitFullScreen();
1892 }
[email protected]2b624c562011-10-27 22:58:261893}
1894
[email protected]674741932009-02-04 23:44:461895bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051896 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461897}
1898
[email protected]674741932009-02-04 23:44:461899void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051900 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461901}
1902
[email protected]674741932009-02-04 23:44:461903void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051904 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461905}
1906
[email protected]b18583c2012-12-18 06:55:271907static bool IsDateTimeInput(ui::TextInputType type) {
1908 return type == ui::TEXT_INPUT_TYPE_DATE ||
1909 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1910 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1911 type == ui::TEXT_INPUT_TYPE_MONTH ||
1912 type == ui::TEXT_INPUT_TYPE_TIME ||
1913 type == ui::TEXT_INPUT_TYPE_WEEK;
1914}
1915
[email protected]66fca5bc2013-05-23 06:58:291916
1917void RenderWidget::StartHandlingImeEvent() {
1918 DCHECK(!handling_ime_event_);
1919 handling_ime_event_ = true;
1920}
1921
1922void RenderWidget::FinishHandlingImeEvent() {
1923 DCHECK(handling_ime_event_);
1924 handling_ime_event_ = false;
1925 // While handling an ime event, text input state and selection bounds updates
1926 // are ignored. These must explicitly be updated once finished handling the
1927 // ime event.
1928 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471929#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361930 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471931#endif
[email protected]66fca5bc2013-05-23 06:58:291932}
1933
[email protected]90f24152014-04-09 12:41:361934void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1935 ChangeSource change_source) {
jdduke1aebad8e2015-07-22 23:25:081936 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
[email protected]e8f775f2013-02-14 21:00:501937 if (handling_ime_event_)
1938 return;
[email protected]ad26ef42011-06-17 07:59:451939 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271940 if (IsDateTimeInput(new_type))
1941 return; // Not considered as a text input field in WebKit/Chromium.
1942
[email protected]180ef242013-11-07 06:50:461943 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211944 if (webwidget_)
1945 new_info = webwidget_->textInputInfo();
shuchen913f8b622015-07-31 13:22:431946 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
[email protected]5b739cb2012-08-21 20:35:211947
[email protected]ad26ef42011-06-17 07:59:451948 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211949
[email protected]3306f262012-09-21 19:20:421950 // Only sends text input params if they are changed or if the ime should be
1951 // shown.
[email protected]90f24152014-04-09 12:41:361952 if (show_ime == SHOW_IME_IF_NEEDED ||
1953 (text_input_type_ != new_type ||
shuchen913f8b622015-07-31 13:22:431954 text_input_mode_ != new_mode ||
[email protected]90f24152014-04-09 12:41:361955 text_input_info_ != new_info ||
1956 can_compose_inline_ != new_can_compose_inline)
1957#if defined(OS_ANDROID)
1958 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021959#endif
[email protected]90f24152014-04-09 12:41:361960 ) {
shuchen913f8b622015-07-31 13:22:431961 ViewHostMsg_TextInputState_Params params;
1962 params.type = new_type;
1963 params.mode = new_mode;
1964 params.flags = new_info.flags;
1965 params.value = new_info.value.utf8();
1966 params.selection_start = new_info.selectionStart;
1967 params.selection_end = new_info.selectionEnd;
1968 params.composition_start = new_info.compositionStart;
1969 params.composition_end = new_info.compositionEnd;
1970 params.can_compose_inline = new_can_compose_inline;
1971 params.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
[email protected]90f24152014-04-09 12:41:361972#if defined(USE_AURA)
shuchen913f8b622015-07-31 13:22:431973 params.is_non_ime_change = true;
[email protected]90f24152014-04-09 12:41:361974#endif
[email protected]183e28d2014-01-20 18:18:021975#if defined(OS_ANDROID)
shuchen913f8b622015-07-31 13:22:431976 params.is_non_ime_change = (change_source == FROM_NON_IME) ||
[email protected]90f24152014-04-09 12:41:361977 text_field_is_dirty_;
shuchen913f8b622015-07-31 13:22:431978 if (params.is_non_ime_change)
changwan3a841162015-08-11 02:53:371979 OnImeEventSentForAck(new_info);
[email protected]90f24152014-04-09 12:41:361980 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021981#endif
shuchen913f8b622015-07-31 13:22:431982 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
[email protected]5b739cb2012-08-21 20:35:211983
1984 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041985 text_input_type_ = new_type;
shuchen913f8b622015-07-31 13:22:431986 text_input_mode_ = new_mode;
[email protected]ad26ef42011-06-17 07:59:451987 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201988 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291989 }
initial.commit09911bf2008-07-26 23:55:291990}
1991
[email protected]7c8873e2013-02-05 08:03:011992void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1993 WebRect focus_webrect;
1994 WebRect anchor_webrect;
1995 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1996 *focus = focus_webrect;
1997 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321998}
1999
[email protected]e99ef6f2011-10-16 01:13:002000void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082001 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:002002 if (!webwidget_)
2003 return;
[email protected]66fca5bc2013-05-23 06:58:292004 if (handling_ime_event_)
2005 return;
[email protected]e99ef6f2011-10-16 01:13:002006
mohsenb0eeba72015-08-09 06:20:082007#if defined(USE_AURA)
2008 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2009 // Aura beucause composited selection updates are not working for webview tags
2010 // which regresses IME inside webview. Remove this when composited selection
2011 // updates are fixed for webviews. See, http://crbug.com/510568.
2012 bool send_ipc = true;
2013#else
jddukeacf809e2014-09-23 20:38:382014 // With composited selection updates, the selection bounds will be reported
2015 // directly by the compositor, in which case explicit IPC selection
2016 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082017 bool send_ipc =
2018 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
2019#endif
2020 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382021 ViewHostMsg_SelectionBounds_Params params;
2022 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2023 if (selection_anchor_rect_ != params.anchor_rect ||
2024 selection_focus_rect_ != params.focus_rect) {
2025 selection_anchor_rect_ = params.anchor_rect;
2026 selection_focus_rect_ = params.focus_rect;
2027 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2028 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2029 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2030 }
[email protected]58b48a0d2012-06-13 07:01:352031 }
jddukeacf809e2014-09-23 20:38:382032
[email protected]88dbe32f2013-06-20 23:31:362033 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002034}
2035
[email protected]180ef242013-11-07 06:50:462036// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172037#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2038 static_assert(int(blink::WebTextInputType##a) \
2039 == int(ui::TEXT_INPUT_TYPE_##b), \
2040 "mismatching enums: " #a)
2041
2042STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2043STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2044STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2045STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2046STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2047STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2048STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2049STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2050STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2051STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2052STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2053STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2054STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2055STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2056STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2057STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2058STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452059
[email protected]5b739cb2012-08-21 20:35:212060ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462061 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212062 // Check the type is in the range representable by ui::TextInputType.
2063 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462064 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212065 return static_cast<ui::TextInputType>(type);
2066}
2067
[email protected]ad26ef42011-06-17 07:59:452068ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272069 if (webwidget_)
2070 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452071 return ui::TEXT_INPUT_TYPE_NONE;
2072}
2073
[email protected]501ea13d2013-07-09 17:03:292074void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302075#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112076 // TODO(yukawa): Start sending character bounds when the browser side
2077 // implementation becomes ready (crbug.com/424866).
2078#else
jdduke1aebad8e2015-07-22 23:25:082079 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
[email protected]db4fc1e2013-09-06 20:01:512080 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292081 if (should_update_range) {
2082 GetCompositionRange(&range);
2083 } else {
2084 range = composition_range_;
2085 }
2086 std::vector<gfx::Rect> character_bounds;
2087 GetCompositionCharacterBounds(&character_bounds);
2088
2089 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2090 return;
2091 composition_character_bounds_ = character_bounds;
2092 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222093 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292094 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112095#endif
[email protected]501ea13d2013-07-09 17:03:292096}
2097
[email protected]58b48a0d2012-06-13 07:01:352098void RenderWidget::GetCompositionCharacterBounds(
2099 std::vector<gfx::Rect>* bounds) {
2100 DCHECK(bounds);
2101 bounds->clear();
2102}
2103
[email protected]db4fc1e2013-09-06 20:01:512104void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362105 size_t location, length;
2106 if (webwidget_->compositionRange(&location, &length)) {
2107 range->set_start(location);
2108 range->set_end(location + length);
2109 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2110 range->set_start(location);
2111 range->set_end(location + length);
2112 } else {
[email protected]db4fc1e2013-09-06 20:01:512113 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362114 }
2115}
2116
[email protected]501ea13d2013-07-09 17:03:292117bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512118 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292119 const std::vector<gfx::Rect>& bounds) {
2120 if (composition_range_ != range)
2121 return true;
2122 if (bounds.size() != composition_character_bounds_.size())
2123 return true;
2124 for (size_t i = 0; i < bounds.size(); ++i) {
2125 if (bounds[i] != composition_character_bounds_[i])
2126 return true;
2127 }
2128 return false;
2129}
[email protected]501ea13d2013-07-09 17:03:292130
[email protected]a4f0d882014-05-01 23:48:102131#if defined(OS_ANDROID)
2132void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2133 // If not initialized, default to white. Note that 0 is different from black
2134 // as black still has alpha 0xFF.
2135 if (!bg_color)
2136 bg_color = SK_ColorWHITE;
2137
2138 if (bg_color != body_background_color_) {
2139 body_background_color_ = bg_color;
2140 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2141 }
2142}
timav7a5032e2014-12-05 01:59:432143
2144bool RenderWidget::DoesRecordFullLayer() const {
2145 SynchronousCompositorFactory* synchronous_compositor_factory =
2146 SynchronousCompositorFactory::GetInstance();
2147
2148 // We assume that the absence of synchronous_compositor_factory
2149 // means we are in Chrome. In chrome, we want to clip, i.e.
2150 // *not* to record the full layer.
2151 if (!synchronous_compositor_factory)
2152 return false;
2153
2154 return synchronous_compositor_factory->RecordFullLayer();
2155}
[email protected]a4f0d882014-05-01 23:48:102156#endif
2157
[email protected]ad26ef42011-06-17 07:59:452158bool RenderWidget::CanComposeInline() {
2159 return true;
[email protected]56ea1a62011-05-30 07:05:572160}
2161
[email protected]4873c7d2009-07-16 06:36:282162WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042163 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282164}
2165
[email protected]f660d9c2012-06-06 18:31:212166float RenderWidget::deviceScaleFactor() {
2167 return device_scale_factor_;
2168}
2169
[email protected]fa7b1dc2010-06-23 17:53:042170void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022171 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042172 // If the last text input type is not None, then we should finish any
2173 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452174 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042175 // If a composition text exists, then we need to let the browser process
2176 // to cancel the input method's ongoing composition session.
2177 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222178 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042179 }
[email protected]d4cff272011-05-02 15:46:012180
[email protected]88dbe32f2013-06-20 23:31:362181 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042182}
2183
donnda070f3c2015-01-16 19:54:112184#if defined(OS_ANDROID)
2185void RenderWidget::showUnhandledTapUIIfNeeded(
2186 const WebPoint& tapped_position,
2187 const WebNode& tapped_node,
2188 bool page_changed) {
2189 DCHECK(handling_input_event_);
2190 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372191 !tapped_node.isContentEditable() &&
2192 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112193 if (should_trigger) {
2194 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2195 tapped_position.x, tapped_position.y));
2196 }
2197}
2198#endif
2199
[email protected]c68c3e4e2013-01-24 00:36:562200void RenderWidget::didHandleGestureEvent(
2201 const WebGestureEvent& event,
2202 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022203#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562204 if (event_cancelled)
2205 return;
[email protected]07c70d22014-08-21 08:33:462206 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362207 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462208 } else if (event.type == WebInputEvent::GestureLongPress) {
2209 DCHECK(webwidget_);
2210 if (webwidget_->textInputInfo().value.isEmpty())
2211 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2212 else
2213 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562214 }
2215#endif
2216}
2217
sataya.m582c9ce2015-06-09 08:03:422218void RenderWidget::didOverscroll(
2219 const blink::WebFloatSize& unusedDelta,
2220 const blink::WebFloatSize& accumulatedRootOverScroll,
2221 const blink::WebFloatPoint& position,
2222 const blink::WebFloatSize& velocity) {
2223 DidOverscrollParams params;
sataya.m582c9ce2015-06-09 08:03:422224 params.accumulated_overscroll = gfx::Vector2dF(
2225 accumulatedRootOverScroll.width, accumulatedRootOverScroll.height);
2226 params.latest_overscroll_delta =
2227 gfx::Vector2dF(unusedDelta.width, unusedDelta.height);
sataya.ma5cc13a2015-06-13 11:06:022228 // TODO(sataya.m): don't negate velocity once http://crbug.com/499743 is
2229 // fixed.
sataya.m582c9ce2015-06-09 08:03:422230 params.current_fling_velocity =
sataya.ma5cc13a2015-06-13 11:06:022231 gfx::Vector2dF(-velocity.width, -velocity.height);
sataya.m582c9ce2015-06-09 08:03:422232 params.causal_event_viewport_point = gfx::PointF(position.x, position.y);
jddukec05612b2015-06-25 23:13:182233
2234 // If we're currently handling an event, stash the overscroll data such that
2235 // it can be bundled in the event ack.
2236 if (handling_event_overscroll_) {
2237 handling_event_overscroll_->reset(new DidOverscrollParams(params));
2238 return;
2239 }
2240
sataya.m582c9ce2015-06-09 08:03:422241 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
2242}
2243
[email protected]7912e822014-04-16 02:37:032244void RenderWidget::StartCompositor() {
2245 // For widgets that are never visible, we don't need the compositor to run
2246 // at all.
2247 if (never_visible_)
2248 return;
danakj6e3bf8012014-12-16 18:27:532249 // In tests without a RenderThreadImpl, don't set ready as this kicks
2250 // off creating output surfaces that the test can't create.
2251 if (!RenderThreadImpl::current())
2252 return;
danakj018271e32014-12-16 21:17:262253 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032254}
2255
[email protected]29e2fb42013-07-19 01:13:472256void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292257 size_t i = 0;
2258 for (; i < plugin_window_moves_.size(); ++i) {
2259 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582260 if (move.rects_valid) {
2261 plugin_window_moves_[i] = move;
2262 } else {
2263 plugin_window_moves_[i].visible = move.visible;
2264 }
initial.commit09911bf2008-07-26 23:55:292265 break;
2266 }
2267 }
2268
2269 if (i == plugin_window_moves_.size())
2270 plugin_window_moves_.push_back(move);
2271}
[email protected]268654772009-08-06 23:02:042272
2273void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2274 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2275 i != plugin_window_moves_.end(); ++i) {
2276 if (i->window == window) {
2277 plugin_window_moves_.erase(i);
2278 break;
2279 }
2280 }
2281}
[email protected]67bfb83f2011-09-22 03:36:372282
[email protected]63b465922012-09-06 02:04:522283
[email protected]24ed0432013-04-24 07:50:312284RenderWidgetCompositor* RenderWidget::compositor() const {
2285 return compositor_.get();
2286}
2287
[email protected]180ef242013-11-07 06:50:462288bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372289 return false;
2290}
[email protected]c3d45532011-10-07 19:20:402291
[email protected]41d86852012-11-07 12:23:242292bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462293 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242294 return false;
2295}
2296
ccamerona7644752014-12-30 01:16:312297void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312298 const blink::WebMouseWheelEvent& wheel_event,
sataya.mf405d0e2015-07-07 16:51:112299 const gfx::Vector2dF& wheel_unused_delta,
ccamerond4ba47902014-12-17 07:20:312300 bool event_processed) {
ccamerona7644752014-12-30 01:16:312301 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312302 return;
2303
ccamerond4ba47902014-12-17 07:20:312304 cc::InputHandlerScrollResult scroll_result;
sataya.mf405d0e2015-07-07 16:51:112305 scroll_result.did_scroll = event_processed;
2306 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
2307 scroll_result.unused_scroll_delta = wheel_unused_delta;
ccamerond4ba47902014-12-17 07:20:312308
2309 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2310 InputHandlerManager* input_handler_manager =
2311 render_thread ? render_thread->input_handler_manager() : NULL;
2312 if (input_handler_manager) {
2313 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2314 routing_id_, wheel_event, scroll_result);
2315 }
2316}
2317
[email protected]ce6689f2013-03-29 12:52:552318void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2319 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2320}
2321
mostynbe29b6882015-01-13 09:59:172322// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2323#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2324 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2325 "mismatching enums: " #a)
2326
dtapuskaa98ac8d72015-05-08 19:29:092327inline content::TouchAction& operator|=(content::TouchAction& a,
2328 content::TouchAction b) {
2329 a = static_cast<content::TouchAction>(static_cast<int>(a) |
2330 static_cast<int>(b));
2331 return a;
2332}
2333
[email protected]5d0bbdfa92013-12-10 00:35:512334void RenderWidget::setTouchAction(
2335 blink::WebTouchAction web_touch_action) {
2336
2337 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2338 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192339 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512340 return;
2341
dtapuskaa98ac8d72015-05-08 19:29:092342 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172343 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2344 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092345 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2346 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172347 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092348 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2349 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172350 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2351 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362352
2353 content::TouchAction content_touch_action =
2354 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512355 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2356}
2357
[email protected]90f24152014-04-09 12:41:362358void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2359#if defined(OS_ANDROID)
2360 text_field_is_dirty_ = true;
2361#endif
2362}
2363
[email protected]3d5c243b2012-11-30 00:26:012364bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2365 return true;
2366}
2367
[email protected]0634cdd42013-08-16 00:46:092368scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
jbauman5e420d32015-08-05 09:33:012369RenderWidget::CreateGraphicsContext3D(bool compositor) {
[email protected]ed7defa2013-03-12 21:29:592370 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092371 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492372 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222373 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092374 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292375 if (!RenderThreadImpl::current())
2376 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402377 CauseForGpuLaunch cause =
2378 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292379 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402380 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222381 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292382 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592383
[email protected]828a3932014-04-02 14:43:132384 // Explicitly disable antialiasing for the compositor. As of the time of
2385 // this writing, the only platform that supported antialiasing for the
2386 // compositor was Mac OS X, because the on-screen OpenGL context creation
2387 // code paths on Windows and Linux didn't yet have multisampling support.
2388 // Mac OS X essentially always behaves as though it's rendering offscreen.
2389 // Multisampling has a heavy cost especially on devices with relatively low
2390 // fill rate like most notebooks, and the Mac implementation would need to
2391 // be optimized to resolve directly into the IOSurface shared between the
2392 // GPU and browser processes. For these reasons and to avoid platform
2393 // disparities we explicitly disable antialiasing.
2394 blink::WebGraphicsContext3D::Attributes attributes;
2395 attributes.antialias = false;
2396 attributes.shareResources = true;
2397 attributes.noAutomaticFlushes = true;
2398 attributes.depth = false;
2399 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132400 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292401 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012402#if defined(OS_ANDROID)
2403 // If we raster too fast we become upload bound, and pending
2404 // uploads consume memory. For maximum upload throughput, we would
2405 // want to allow for upload_throughput * pipeline_time of pending
2406 // uploads, after which we are just wasting memory. Since we don't
2407 // know our upload throughput yet, this just caps our memory usage.
2408 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272409 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032410 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012411 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032412 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012413 // Deadline to draw a frame to achieve 60 frames per second.
2414 const size_t kMillisecondsPerFrame = 16;
2415 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032416 size_t max_transfer_buffer_usage_mb =
2417 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2418 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012419 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2420 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292421 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032422 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012423#endif
jbauman00ca2dc2015-08-10 23:21:152424 if (compositor) {
jbauman5e420d32015-08-05 09:33:012425 limits.command_buffer_size = 64 * 1024;
jbauman00ca2dc2015-08-10 23:21:152426 limits.start_transfer_buffer_size = 64 * 1024;
2427 limits.min_transfer_buffer_size = 64 * 1024;
2428 }
[email protected]96ab016c2013-10-23 00:50:292429
[email protected]96ab016c2013-10-23 00:50:292430 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132431 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2432 GetURLForGraphicsContext3D(),
2433 gpu_channel_host.get(),
2434 attributes,
[email protected]828a3932014-04-02 14:43:132435 lose_context_when_out_of_memory,
2436 limits,
2437 NULL));
[email protected]0634cdd42013-08-16 00:46:092438 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592439}
2440
[email protected]e3244ed2014-06-20 20:04:272441void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2442 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162443}
2444
[email protected]e3244ed2014-06-20 20:04:272445void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2446 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162447}
2448
[email protected]de3c5d82014-05-28 22:12:592449void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2450 render_frames_.AddObserver(frame);
2451}
2452
2453void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2454 render_frames_.RemoveObserver(frame);
2455}
2456
[email protected]a017938b2014-05-27 21:17:172457#if defined(VIDEO_HOLE)
2458void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2459 video_hole_frames_.AddObserver(frame);
2460}
2461
2462void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2463 video_hole_frames_.RemoveObserver(frame);
2464}
2465#endif // defined(VIDEO_HOLE)
2466
[email protected]e9ff79c2012-10-19 21:31:262467} // namespace content