blob: 3f4c190c2c644a4e696b0d75070ebeee702ca03c [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"
alexclarke7fa93942015-10-21 15:37:1125#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2126#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]29e2fb42013-07-19 01:13:4727#include "content/child/npapi/webplugin.h"
oshima750cb4342015-10-31 00:59:0128#include "content/common/content_switches_internal.h"
[email protected]0634cdd42013-08-16 00:46:0929#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5930#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2931#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3532#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4433#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1534#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1535#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5036#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2937#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4238#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4039#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5140#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5941#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2942#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1143#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5944#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1145#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2846#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2947#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1348#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3249#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1650#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2751#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0552#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4453#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5554#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:0955#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0456#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1857#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4858#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1859#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3060#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1161#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3062#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1863#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3064#include "third_party/WebKit/public/platform/WebSize.h"
65#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4366#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5967#include "third_party/WebKit/public/web/WebFrameWidget.h"
68#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1169#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3170#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3171#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
72#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3873#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5974#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4175#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1376#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5077#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0978#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3279#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4880#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2781#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4883
[email protected]eeb93112013-05-01 19:41:1084#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1585#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0786#include "content/renderer/android/synchronous_compositor_factory.h"
boliubee541f42015-11-05 00:52:5387#include "content/renderer/android/synchronous_compositor_filter.h"
88#include "content/renderer/android/synchronous_compositor_output_surface.h"
[email protected]eeb93112013-05-01 19:41:1089#endif
90
[email protected]661eb9d2009-02-03 02:11:4891#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4992#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5293#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4194#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4895#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4496
[email protected]2255a9332013-06-17 05:12:3197#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2998
[email protected]180ef242013-11-07 06:50:4699using blink::WebCompositionUnderline;
100using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43101using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46102using blink::WebGestureEvent;
103using blink::WebInputEvent;
104using blink::WebKeyboardEvent;
105using blink::WebMouseEvent;
106using blink::WebMouseWheelEvent;
107using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11108using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46109using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11110using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46111using blink::WebPopupType;
112using blink::WebRange;
113using blink::WebRect;
114using blink::WebScreenInfo;
115using blink::WebSize;
116using blink::WebTextDirection;
117using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25118using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46119using blink::WebVector;
120using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26121
[email protected]6a4d7f62013-01-07 21:32:13122namespace {
[email protected]b256eca2013-07-11 10:57:40123
124typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
125
126class TextInputModeMapSingleton {
127 public:
128 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22129 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40130 }
[email protected]dd705d4d2013-11-27 08:14:41131 TextInputModeMapSingleton() {
132 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
133 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
134 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
135 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
136 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
137 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
138 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
139 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
140 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
141 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
142 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40143 }
[email protected]dd705d4d2013-11-27 08:14:41144 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40145 private:
[email protected]dd705d4d2013-11-27 08:14:41146 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40147
olli.raula36aa8be2015-09-10 11:14:22148 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40149
150 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
151};
152
[email protected]dd705d4d2013-11-27 08:14:41153ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40154 static TextInputModeMapSingleton* singleton =
155 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41156 TextInputModeMap::const_iterator it =
157 singleton->map().find(input_mode.utf8());
158 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40159 return ui::TEXT_INPUT_MODE_DEFAULT;
160 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13161}
[email protected]b256eca2013-07-11 10:57:40162
[email protected]fd847792013-10-24 17:12:35163// TODO(brianderson): Replace the hard-coded threshold with a fraction of
164// the BeginMainFrame interval.
165// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
166// be spent in input hanlders before input starts getting throttled.
167const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
168
miletus14a25642015-08-13 19:23:23169int64 GetEventLatencyMicros(double event_timestamp, base::TimeTicks now) {
170 return (now - base::TimeDelta::FromSecondsD(event_timestamp))
jdduke07788062014-12-05 03:16:30171 .ToInternalValue();
172}
173
miletus14a25642015-08-13 19:23:23174void LogInputEventLatencyUmaImpl(WebInputEvent::Type event_type,
175 double event_timestamp,
176 base::TimeTicks now) {
177 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.AggregatedLatency.Renderer2",
178 GetEventLatencyMicros(event_timestamp, now), 1,
179 10000000, 100);
jdduke07788062014-12-05 03:16:30180
miletus14a25642015-08-13 19:23:23181#define CASE_TYPE(t) \
182 case WebInputEvent::t: \
183 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer2." #t, \
184 GetEventLatencyMicros(event_timestamp, now), \
185 1, 10000000, 100); \
186 break;
jdduke07788062014-12-05 03:16:30187
miletus14a25642015-08-13 19:23:23188 switch (event_type) {
jdduke07788062014-12-05 03:16:30189 CASE_TYPE(Undefined);
190 CASE_TYPE(MouseDown);
191 CASE_TYPE(MouseUp);
192 CASE_TYPE(MouseMove);
193 CASE_TYPE(MouseEnter);
194 CASE_TYPE(MouseLeave);
195 CASE_TYPE(ContextMenu);
196 CASE_TYPE(MouseWheel);
197 CASE_TYPE(RawKeyDown);
198 CASE_TYPE(KeyDown);
199 CASE_TYPE(KeyUp);
200 CASE_TYPE(Char);
201 CASE_TYPE(GestureScrollBegin);
202 CASE_TYPE(GestureScrollEnd);
203 CASE_TYPE(GestureScrollUpdate);
204 CASE_TYPE(GestureFlingStart);
205 CASE_TYPE(GestureFlingCancel);
206 CASE_TYPE(GestureShowPress);
207 CASE_TYPE(GestureTap);
208 CASE_TYPE(GestureTapUnconfirmed);
209 CASE_TYPE(GestureTapDown);
210 CASE_TYPE(GestureTapCancel);
211 CASE_TYPE(GestureDoubleTap);
212 CASE_TYPE(GestureTwoFingerTap);
213 CASE_TYPE(GestureLongPress);
214 CASE_TYPE(GestureLongTap);
215 CASE_TYPE(GesturePinchBegin);
216 CASE_TYPE(GesturePinchEnd);
217 CASE_TYPE(GesturePinchUpdate);
218 CASE_TYPE(TouchStart);
219 CASE_TYPE(TouchMove);
220 CASE_TYPE(TouchEnd);
221 CASE_TYPE(TouchCancel);
222 default:
223 // Must include default to let blink::WebInputEvent add new event types
224 // before they're added here.
miletus14a25642015-08-13 19:23:23225 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event_type;
jdduke07788062014-12-05 03:16:30226 break;
227 }
228
229#undef CASE_TYPE
230}
231
miletus14a25642015-08-13 19:23:23232void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now,
233 const ui::LatencyInfo& latency_info) {
234 LogInputEventLatencyUmaImpl(event.type, event.timeStampSeconds, now);
235 for (size_t i = 0; i < latency_info.coalesced_events_size(); i++) {
236 LogInputEventLatencyUmaImpl(
237 event.type,
238 latency_info.timestamps_of_coalesced_events()[i],
239 now);
240 }
241}
242
[email protected]b256eca2013-07-11 10:57:40243} // namespace
244
[email protected]e9ff79c2012-10-19 21:31:26245namespace content {
[email protected]62cb33cae2009-03-27 23:30:22246
[email protected]b2e4c70132013-10-03 02:07:51247// RenderWidget::ScreenMetricsEmulator ----------------------------------------
248
249class RenderWidget::ScreenMetricsEmulator {
250 public:
251 ScreenMetricsEmulator(
252 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43253 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51254 virtual ~ScreenMetricsEmulator();
255
[email protected]19193682014-04-03 15:01:43256 // Scale and offset used to convert between host coordinates
257 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51258 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20259 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43260 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51261 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56262 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51263
264 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43265 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51266
267 // The following methods alter handlers' behavior for messages related to
268 // widget size and position.
269 void OnResizeMessage(const ViewMsg_Resize_Params& params);
270 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
271 const gfx::Rect& window_screen_rect);
272 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31273 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51274
275 private:
[email protected]19193682014-04-03 15:01:43276 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02277 void Apply(bool top_controls_shrink_blink_size,
278 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44279 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12280 bool is_fullscreen_granted,
281 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51282
283 RenderWidget* widget_;
284
[email protected]7f99fc22013-11-08 14:05:58285 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43286 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51287
[email protected]a179d3962013-11-12 14:44:40288 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51289 float scale_;
dgozman9260b0a12015-03-16 13:45:20290 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51291
[email protected]19193682014-04-03 15:01:43292 // Widget rect as passed to webwidget.
293 gfx::Rect applied_widget_rect_;
294
[email protected]b2e4c70132013-10-03 02:07:51295 // Original values to restore back after emulation ends.
296 gfx::Size original_size_;
297 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28298 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46299 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51300 gfx::Rect original_view_screen_rect_;
301 gfx::Rect original_window_screen_rect_;
302};
303
304RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
305 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43306 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51307 : widget_(widget),
[email protected]19193682014-04-03 15:01:43308 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51309 scale_(1.f) {
310 original_size_ = widget_->size_;
311 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28312 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51313 original_screen_info_ = widget_->screen_info_;
314 original_view_screen_rect_ = widget_->view_screen_rect_;
315 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02316 Apply(widget_->top_controls_shrink_blink_size_,
317 widget_->top_controls_height_,
318 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12319 widget_->is_fullscreen_granted_,
320 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51321}
322
323RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
324 widget_->screen_info_ = original_screen_info_;
325
326 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20327 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51328 widget_->view_screen_rect_ = original_view_screen_rect_;
329 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01330 widget_->Resize(original_size_,
331 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02332 widget_->top_controls_shrink_blink_size_,
333 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01334 original_visible_viewport_size_,
335 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12336 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12337 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01338 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51339}
340
341void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43342 const WebDeviceEmulationParams& params) {
343 params_ = params;
344 Reapply();
345}
346
347void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02348 Apply(widget_->top_controls_shrink_blink_size_,
349 widget_->top_controls_height_,
350 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12351 widget_->is_fullscreen_granted_,
352 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51353}
354
[email protected]19193682014-04-03 15:01:43355void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02356 bool top_controls_shrink_blink_size,
357 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44358 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12359 bool is_fullscreen_granted,
360 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31361 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
362 if (!applied_widget_rect_.width())
363 applied_widget_rect_.set_width(original_size_.width());
364 if (!applied_widget_rect_.height())
365 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43366
[email protected]f442ee42014-05-14 11:53:12367 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02368 int original_width = std::max(original_size_.width(), 1);
369 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51370 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02371 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51372 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02373 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51374 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
375 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01376
377 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43378 offset_.set_x(
379 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01380 offset_.set_y(
[email protected]19193682014-04-03 15:01:43381 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51382 } else {
[email protected]0b3578c2014-06-20 18:29:02383 scale_ = params_.scale;
384 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01385 }
[email protected]7f0e8fa2014-03-26 12:32:01386
[email protected]19193682014-04-03 15:01:43387 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
388 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01389 widget_->screen_info_.rect = original_screen_info_.rect;
390 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
391 widget_->window_screen_rect_ = original_window_screen_rect_;
392 } else {
dgozmanf28ccbe2015-06-24 08:50:49393 applied_widget_rect_.set_origin(params_.viewPosition);
394 gfx::Rect screen_rect = applied_widget_rect_;
395 if (!params_.screenSize.isEmpty()) {
396 screen_rect =
397 gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height);
398 }
399 widget_->screen_info_.rect = screen_rect;
400 widget_->screen_info_.availableRect = screen_rect;
[email protected]19193682014-04-03 15:01:43401 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01402 }
[email protected]a179d3962013-11-12 14:44:40403
[email protected]19193682014-04-03 15:01:43404 float applied_device_scale_factor = params_.deviceScaleFactor ?
405 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01406 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51407
[email protected]7f99fc22013-11-08 14:05:58408 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51409 // - we keep the real device scale factor in compositor to produce sharp image
410 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58411 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51412 // root layer.
dgozman9260b0a12015-03-16 13:45:20413 blink::WebDeviceEmulationParams modified_params = params_;
414 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
415 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
416 modified_params.scale = scale_;
417 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51418
[email protected]7f0e8fa2014-03-26 12:32:01419 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43420 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51421
danakjddaec912015-09-25 19:38:40422 gfx::Size physical_backing_size = gfx::ScaleToCeiledSize(
423 original_size_, original_screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02424 widget_->Resize(applied_widget_rect_.size(),
425 physical_backing_size,
426 top_controls_shrink_blink_size,
427 top_controls_height,
428 applied_widget_rect_.size(),
429 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12430 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12431 display_mode,
dtrainorcb7779b82014-12-04 01:08:02432 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51433}
434
435void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
436 const ViewMsg_Resize_Params& params) {
437 bool need_ack = params.new_size != original_size_ &&
438 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
439 original_size_ = params.new_size;
440 original_physical_backing_size_ = params.physical_backing_size;
441 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28442 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02443 Apply(params.top_controls_shrink_blink_size,
444 params.top_controls_height,
445 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12446 params.is_fullscreen_granted,
447 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51448
449 if (need_ack) {
450 widget_->set_next_paint_is_resize_ack();
451 if (widget_->compositor_)
452 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
453 }
454}
455
456void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
457 const gfx::Rect& view_screen_rect,
458 const gfx::Rect& window_screen_rect) {
459 original_view_screen_rect_ = view_screen_rect;
460 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43461 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
462 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51463}
464
465void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
466 ContextMenuParams* params) {
467 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40468 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51469 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40470 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51471}
472
[email protected]2d6836f42014-07-02 17:25:31473gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
474 const gfx::Rect& anchor) {
danakj4606f6332015-08-31 23:56:56475 gfx::Rect scaled = gfx::ScaleToEnclosedRect(anchor, scale_);
[email protected]2d6836f42014-07-02 17:25:31476 scaled.set_x(scaled.x() + offset_.x());
477 scaled.set_y(scaled.y() + offset_.y());
478 return scaled;
479}
480
[email protected]b2e4c70132013-10-03 02:07:51481// RenderWidget ---------------------------------------------------------------
482
dcheng35d31c112015-07-22 00:17:36483RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
484 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46485 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04486 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03487 bool hidden,
488 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29489 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36490 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53491 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29492 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02493 top_controls_shrink_blink_size_(false),
494 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29495 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51496 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09497 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29498 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04499 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39500 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12501 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12502 display_mode_(blink::WebDisplayModeUndefined),
[email protected]5dd768212009-08-13 23:34:49503 handling_input_event_(false),
jddukec05612b2015-06-25 23:13:18504 handling_event_overscroll_(nullptr),
changwanf2a707b2015-10-30 08:22:16505 ime_event_guard_(nullptr),
[email protected]c27dd4f2014-05-22 18:05:19506 handling_event_type_(WebInputEvent::Undefined),
507 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48508 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22509 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44510 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20511 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45512 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40513 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20514 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53515 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12516 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48517 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12518 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04519 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52520 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30521 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13522#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36523 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13524#endif
[email protected]b2e4c70132013-10-03 02:07:51525 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11526 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42527 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51528 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
529 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05530 if (!swapped_out)
531 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27532 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53533 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37534#if defined(OS_ANDROID)
535 text_input_info_history_.push_back(blink::WebTextInputInfo());
536#endif
alexclarke7fa93942015-10-21 15:37:11537
538 // In tests there may not be a RenderThreadImpl.
539 if (RenderThreadImpl::current()) {
540 render_widget_scheduling_state_ = RenderThreadImpl::current()
541 ->GetRendererScheduler()
542 ->NewRenderWidgetSchedulingState()
543 .Pass();
544 render_widget_scheduling_state_->SetHidden(is_hidden_);
545 }
initial.commit09911bf2008-07-26 23:55:29546}
547
548RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11549 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16550
[email protected]992db4c2011-05-12 15:37:15551 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02552 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15553 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29554}
555
[email protected]484955942010-08-19 16:13:18556// static
[email protected]8085dbc82008-09-26 22:53:44557RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53558 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46559 blink::WebPopupType popup_type,
560 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29561 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36562 scoped_refptr<RenderWidget> widget(new RenderWidget(
563 compositor_deps, popup_type, screen_info, false, false, false));
564 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46565 return widget.get();
[email protected]a635f942012-12-07 10:34:29566 }
567 return NULL;
initial.commit09911bf2008-07-26 23:55:29568}
569
[email protected]484955942010-08-19 16:13:18570// static
kenrba7199832015-01-22 23:44:59571RenderWidget* RenderWidget::CreateForFrame(
572 int routing_id,
kenrba7199832015-01-22 23:44:59573 bool hidden,
574 const blink::WebScreenInfo& screen_info,
575 CompositorDependencies* compositor_deps,
576 blink::WebLocalFrame* frame) {
577 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55578 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
579 // same routing ID for both the view routing ID and the main frame widget
580 // routing ID. https://crbug.com/545684
581 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
582 if (view) {
583 view->AttachWebFrameWidget(RenderWidget::CreateWebFrameWidget(view, frame));
584 return view;
585 }
dcheng35d31c112015-07-22 00:17:36586 scoped_refptr<RenderWidget> widget(
587 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
588 false, hidden, false));
kenrba7199832015-01-22 23:44:59589 widget->routing_id_ = routing_id;
simonhong628f9812015-04-27 23:13:20590 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59591 // DoInit increments the reference count on |widget|, keeping it alive after
592 // this function returns.
dcheng35d31c112015-07-22 00:17:36593 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59594 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
595 nullptr)) {
kenrba7199832015-01-22 23:44:59596 return widget.get();
597 }
598 return nullptr;
599}
600
601// static
dchengda9b4bb2015-07-20 20:58:08602blink::WebWidget* RenderWidget::CreateWebFrameWidget(
603 RenderWidget* render_widget,
604 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55605 if (!frame->parent()) {
606 // TODO(dcheng): The main frame widget currently has a special case.
607 // Eliminate this once WebView is no longer a WebWidget.
608 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
609 }
dchengda9b4bb2015-07-20 20:58:08610 return blink::WebFrameWidget::create(render_widget, frame);
611}
612
613// static
kenrba7199832015-01-22 23:44:59614blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18615 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46616 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18617 break;
[email protected]180ef242013-11-07 06:50:46618 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44619 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18620 default:
621 NOTREACHED();
622 }
623 return NULL;
624}
625
dchengda9b4bb2015-07-20 20:58:08626void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32627 OnClose();
kenrba7199832015-01-22 23:44:59628}
629
dcheng35d31c112015-07-22 00:17:36630bool RenderWidget::Init(int32 opener_id) {
piman5d36dae2015-09-24 22:47:05631 return DoInit(
632 opener_id, RenderWidget::CreateWebWidget(this),
633 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
[email protected]484955942010-08-19 16:13:18634}
635
[email protected]a635f942012-12-07 10:34:29636bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06637 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18638 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29639 DCHECK(!webwidget_);
640
641 if (opener_id != MSG_ROUTING_NONE)
642 opener_id_ = opener_id;
643
[email protected]484955942010-08-19 16:13:18644 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29645
kenrba7199832015-01-22 23:44:59646 bool result = true;
647 if (create_widget_message)
648 result = RenderThread::Get()->Send(create_widget_message);
649
initial.commit09911bf2008-07-26 23:55:29650 if (result) {
[email protected]380244092011-10-07 17:26:27651 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29652 // Take a reference on behalf of the RenderThread. This will be balanced
653 // when we receive ViewMsg_Close.
654 AddRef();
[email protected]b2db9272014-01-10 17:42:00655 if (RenderThreadImpl::current()) {
656 RenderThreadImpl::current()->WidgetCreated();
657 if (is_hidden_)
658 RenderThreadImpl::current()->WidgetHidden();
659 }
[email protected]a635f942012-12-07 10:34:29660 return true;
initial.commit09911bf2008-07-26 23:55:29661 } else {
[email protected]a635f942012-12-07 10:34:29662 // The above Send can fail when the tab is closing.
663 return false;
initial.commit09911bf2008-07-26 23:55:29664 }
665}
666
[email protected]992db4c2011-05-12 15:37:15667void RenderWidget::SetSwappedOut(bool is_swapped_out) {
668 // We should only toggle between states.
669 DCHECK(is_swapped_out_ != is_swapped_out);
670 is_swapped_out_ = is_swapped_out;
671
672 // If we are swapping out, we will call ReleaseProcess, allowing the process
673 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52674 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15675 // If we are swapping in, we call AddRefProcess to prevent the process from
676 // exiting.
[email protected]949b6592014-08-20 13:17:52677 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15678 RenderProcess::current()->AddRefProcess();
679}
680
[email protected]949b6592014-08-20 13:17:52681void RenderWidget::WasSwappedOut() {
682 // If we have been swapped out and no one else is using this process,
683 // it's safe to exit now.
684 CHECK(is_swapped_out_);
685 RenderProcess::current()->ReleaseProcess();
686}
687
[email protected]b2e4c70132013-10-03 02:07:51688void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
689 ScreenMetricsEmulator* emulator) {
690 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43691 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49692 popup_screen_origin_for_emulation_ = gfx::Point(
693 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
694 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56695 screen_info_ = emulator->original_screen_info();
696 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51697}
698
[email protected]2d6836f42014-07-02 17:25:31699gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
700 if (screen_metrics_emulator_)
701 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
702 return anchor;
703}
704
[email protected]b2e4c70132013-10-03 02:07:51705void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20706 bool enabled,
707 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51708 // This is only supported in RenderView.
709 NOTREACHED();
710}
711
[email protected]53907862014-03-25 15:42:40712#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51713void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
714 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49715 popup->SetOriginScaleAndOffsetForEmulation(
716 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51717}
[email protected]53907862014-03-25 15:42:40718#endif
[email protected]b2e4c70132013-10-03 02:07:51719
720void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
721 if (screen_metrics_emulator_)
722 screen_metrics_emulator_->OnShowContextMenu(params);
723}
724
[email protected]a95986a82010-12-24 06:19:28725bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
726 bool handled = true;
727 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15728 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22729 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
730 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22731 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
732 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15733 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
734 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35735 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
736 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28737 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28738 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20739 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
740 OnEnableDeviceEmulation)
741 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
742 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41743 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54744 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28745 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41746 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25747 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28748 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
749 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03750 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05751 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21752#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37753 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
[email protected]2384b6c2013-02-28 23:58:51754 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21755#endif
dtrainor5ef644e2015-11-19 00:12:47756 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28757 IPC_MESSAGE_UNHANDLED(handled = false)
758 IPC_END_MESSAGE_MAP()
759 return handled;
760}
initial.commit09911bf2008-07-26 23:55:29761
762bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15763 // Don't send any messages after the browser has told us to close, and filter
764 // most outgoing messages while swapped out.
765 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26766 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11767 closing_) {
initial.commit09911bf2008-07-26 23:55:29768 delete message;
769 return false;
770 }
771
772 // If given a messsage without a routing ID, then assign our routing ID.
773 if (message->routing_id() == MSG_ROUTING_NONE)
774 message->set_routing_id(routing_id_);
775
[email protected]380244092011-10-07 17:26:27776 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44777}
778
[email protected]61e2b3cc2012-03-02 16:13:34779void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44780 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02781 bool top_controls_shrink_blink_size,
782 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44783 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34784 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12785 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12786 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58787 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56788 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48789 // A resize ack shouldn't be requested if we have not ACK'd the previous
790 // one.
791 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
792 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
793 }
initial.commit09911bf2008-07-26 23:55:29794
[email protected]61e2b3cc2012-03-02 16:13:34795 // Ignore this during shutdown.
796 if (!webwidget_)
797 return;
798
oshima750cb4342015-10-31 00:59:01799 if (compositor_)
800 compositor_->setViewportSize(physical_backing_size);
[email protected]60d47ac2013-03-01 23:42:44801
oshima750cb4342015-10-31 00:59:01802 bool resized = size_ != new_size ||
803 physical_backing_size_ != physical_backing_size;
804
805 size_ = new_size;
[email protected]dade8992013-03-04 07:34:34806 physical_backing_size_ = physical_backing_size;
oshima750cb4342015-10-31 00:59:01807
dtrainorcb7779b82014-12-04 01:08:02808 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
809 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28810 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34811 resizer_rect_ = resizer_rect;
812
813 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12814 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12815 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12816 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34817
aelias6004fe02015-02-07 21:43:01818 webwidget_->setTopControlsHeight(top_controls_height,
819 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43820
oshima750cb4342015-10-31 00:59:01821 if (resized) {
822 gfx::Size new_widget_size =
823 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_;
[email protected]61e2b3cc2012-03-02 16:13:34824 // When resizing, we want to wait to paint before ACK'ing the resize. This
825 // ensures that we only resize as fast as we can paint. We only need to
826 // send an ACK if we are resized to a non-empty rect.
oshima750cb4342015-10-31 00:59:01827 webwidget_->resize(new_widget_size);
828 }
jbroman304f01a2015-11-05 17:04:21829 WebSize visual_viewport_size;
oshima750cb4342015-10-31 00:59:01830
831 if (IsUseZoomForDSFEnabled()) {
832 gfx::SizeF scaled_visible_viewport_size =
833 gfx::ScaleSize(gfx::SizeF(visible_viewport_size), device_scale_factor_);
jbroman304f01a2015-11-05 17:04:21834 visual_viewport_size = gfx::ToCeiledSize(scaled_visible_viewport_size);
oshima750cb4342015-10-31 00:59:01835 } else {
jbroman304f01a2015-11-05 17:04:21836 visual_viewport_size = visible_viewport_size_;
[email protected]632c4382013-05-15 08:58:45837 }
838
jbroman304f01a2015-11-05 17:04:21839 webwidget()->resizeVisualViewport(visual_viewport_size);
[email protected]bb6378fe2014-04-28 21:19:44840
[email protected]632c4382013-05-15 08:58:45841 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58842 // In this case there is no paint/composite and therefore no
843 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
844 // ack through a fake ViewHostMsg_UpdateRect or a different message.
845 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34846 }
847
[email protected]20fbfc22013-05-08 20:50:58848 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45849 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58850 set_next_paint_is_resize_ack();
851
[email protected]61e2b3cc2012-03-02 16:13:34852 if (fullscreen_change)
853 DidToggleFullscreen();
854
855 // If a resize ack is requested and it isn't set-up, then no more resizes will
856 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45857 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29858}
859
bokanc007c3a2015-02-03 07:15:56860void RenderWidget::SetWindowRectSynchronously(
861 const gfx::Rect& new_window_rect) {
862 Resize(new_window_rect.size(),
863 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02864 top_controls_shrink_blink_size_,
865 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56866 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01867 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12868 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12869 display_mode_,
[email protected]587941d2014-08-22 01:40:01870 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56871 view_screen_rect_ = new_window_rect;
872 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02873 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56874 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02875}
876
initial.commit09911bf2008-07-26 23:55:29877void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32878 DCHECK(content::RenderThread::Get());
879 if (closing_)
880 return;
881 NotifyOnClose();
882 closing_ = true;
883
884 // Browser correspondence is no longer needed at this point.
885 if (routing_id_ != MSG_ROUTING_NONE) {
886 RenderThread::Get()->RemoveRoute(routing_id_);
887 SetHidden(false);
888 if (RenderThreadImpl::current())
889 RenderThreadImpl::current()->WidgetDestroyed();
890 }
891
892 if (for_oopif_) {
893 // Widgets for frames may be created and closed at any time while the frame
894 // is alive. However, the closing process must happen synchronously. Frame
895 // widget and frames hold pointers to each other. If Close() is deferred to
896 // the message loop like in the non-frame widget case, WebWidget::close()
897 // can end up accessing members of an already-deleted frame.
898 Close();
899 } else {
900 // If there is a Send call on the stack, then it could be dangerous to close
901 // now. Post a task that only gets invoked when there are no nested message
902 // loops.
903 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
904 FROM_HERE, base::Bind(&RenderWidget::Close, this));
905 }
906
907 // Balances the AddRef taken when we called AddRoute.
908 Release();
initial.commit09911bf2008-07-26 23:55:29909}
910
[email protected]0fdd5012013-05-29 08:05:56911void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04912 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32913 return;
914
[email protected]b2e4c70132013-10-03 02:07:51915 if (screen_metrics_emulator_) {
916 screen_metrics_emulator_->OnResizeMessage(params);
917 return;
918 }
919
[email protected]fcdc5642014-05-09 14:32:24920 bool orientation_changed =
921 screen_info_.orientationAngle != params.screen_info.orientationAngle;
922
[email protected]0fdd5012013-05-29 08:05:56923 screen_info_ = params.screen_info;
924 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02925 Resize(params.new_size,
926 params.physical_backing_size,
927 params.top_controls_shrink_blink_size,
928 params.top_controls_height,
929 params.visible_viewport_size,
930 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12931 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12932 params.display_mode,
sievers4e33dae2015-02-25 20:43:58933 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24934
935 if (orientation_changed)
936 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29937}
938
dgozman9260b0a12015-03-16 13:45:20939void RenderWidget::OnEnableDeviceEmulation(
940 const blink::WebDeviceEmulationParams& params) {
941 if (!screen_metrics_emulator_)
942 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
943 else
944 screen_metrics_emulator_->ChangeEmulationParams(params);
945}
946
947void RenderWidget::OnDisableDeviceEmulation() {
948 screen_metrics_emulator_.reset();
949}
950
noel89949e62014-09-30 01:12:41951void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
952 SetDeviceColorProfile(color_profile);
953}
954
[email protected]b5913d72012-02-07 22:26:54955void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01956 if (resizer_rect_ == resizer_rect)
957 return;
958 resizer_rect_ = resizer_rect;
959 if (webwidget_)
960 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54961}
962
initial.commit09911bf2008-07-26 23:55:29963void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31964 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29965 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03966 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59967 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
968 WasHidden());
initial.commit09911bf2008-07-26 23:55:29969}
970
[email protected]3399dd822014-08-09 11:14:24971void RenderWidget::OnWasShown(bool needs_repainting,
972 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41973 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29974 // During shutdown we can just ignore this message.
975 if (!webwidget_)
976 return;
977
978 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03979 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59980 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
981 WasShown());
initial.commit09911bf2008-07-26 23:55:29982
[email protected]8a23afb32014-04-30 22:40:23983 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29984 return;
initial.commit09911bf2008-07-26 23:55:29985
986 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24987 if (compositor_) {
988 ui::LatencyInfo swap_latency_info(latency_info);
989 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
990 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05991 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24992 }
jdduke491a3f0c2015-06-15 23:30:26993 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29994}
995
[email protected]53d3f302009-12-21 04:42:05996void RenderWidget::OnRequestMoveAck() {
997 DCHECK(pending_window_rect_count_);
998 pending_window_rect_count_--;
999}
1000
[email protected]ed7defa2013-03-12 21:29:591001GURL RenderWidget::GetURLForGraphicsContext3D() {
1002 return GURL();
[email protected]65225772011-05-12 21:10:241003}
1004
[email protected]ebc0e1df2013-08-01 02:46:221005scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:031006 // For widgets that are never visible, we don't start the compositor, so we
1007 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:391008 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:191009
avi83883c82014-12-23 00:08:491010 const base::CommandLine& command_line =
1011 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:331012 bool use_software = fallback;
1013 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
1014 use_software = true;
1015
[email protected]0634cdd42013-08-16 00:46:091016 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:171017 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:331018 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:091019 context_provider = ContextProviderCommandBuffer::Create(
jbauman5e420d32015-08-05 09:33:011020 CreateGraphicsContext3D(true), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:331021 if (!context_provider.get()) {
1022 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:341023 return nullptr;
[email protected]e09994a2014-03-26 19:59:331024 }
revemand180dfc32015-09-24 00:19:431025 worker_context_provider =
1026 RenderThreadImpl::current()->SharedWorkerContextProvider();
1027 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:171028 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:341029 return nullptr;
vmiura78b69282015-02-14 00:01:171030 }
boliu853d46052015-10-13 20:20:061031
1032#if defined(OS_ANDROID)
1033 if (SynchronousCompositorFactory* factory =
1034 SynchronousCompositorFactory::GetInstance()) {
1035 return factory->CreateOutputSurface(
1036 routing_id(), frame_swap_message_queue_, context_provider,
1037 worker_context_provider);
boliubee541f42015-11-05 00:52:531038 } else if (RenderThreadImpl::current()->sync_compositor_message_filter()) {
1039 return make_scoped_ptr(new SynchronousCompositorOutputSurface(
1040 context_provider, worker_context_provider, routing_id(),
1041 content::RenderThreadImpl::current()
1042 ->sync_compositor_message_filter(),
1043 frame_swap_message_queue_));
boliu853d46052015-10-13 20:20:061044 }
1045#endif
[email protected]0634cdd42013-08-16 00:46:091046 }
[email protected]ebc0e1df2013-08-01 02:46:221047
[email protected]b6eb8e332013-09-10 00:51:011048 uint32 output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:341049 // Composite-to-mailbox is currently used for layout tests in order to cause
1050 // them to draw inside in the renderer to do the readback there. This should
1051 // no longer be the case when crbug.com/311404 is fixed.
1052 if (!RenderThreadImpl::current() ||
1053 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:531054 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
piman8944e1c2015-09-22 21:10:341055 return make_scoped_ptr(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171056 routing_id(), output_surface_id, context_provider,
1057 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091058 }
piman8944e1c2015-09-22 21:10:341059
[email protected]0634cdd42013-08-16 00:46:091060 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091061 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121062 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091063
piman8944e1c2015-09-22 21:10:341064 return make_scoped_ptr(new CompositorOutputSurface(
caseqff9c74c2015-02-10 14:56:291065 routing_id(), output_surface_id, nullptr, nullptr,
1066 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221067 }
[email protected]ed7defa2013-03-12 21:29:591068
piman8944e1c2015-09-22 21:10:341069 return make_scoped_ptr(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171070 routing_id(), output_surface_id, context_provider,
piman8944e1c2015-09-22 21:10:341071 worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:281072}
1073
[email protected]4d7e46a2013-11-08 05:33:401074void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241075 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241076 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:261077 ScheduleComposite();
[email protected]65225772011-05-12 21:10:241078}
1079
[email protected]4d7e46a2013-11-08 05:33:401080void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081081 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081082}
1083
[email protected]4d7e46a2013-11-08 05:33:401084void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241085 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161086
[email protected]404939f2012-06-01 04:06:181087 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161088 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291089}
1090
[email protected]180ef242013-11-07 06:50:461091void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
jdduke0cf1e662015-10-15 22:43:281092 const ui::LatencyInfo& latency_info) {
[email protected]c27dd4f2014-05-22 18:05:191093 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291094 return;
jddukec05612b2015-06-25 23:13:181095 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_,
1096 true);
[email protected]c27dd4f2014-05-22 18:05:191097 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1098 &handling_event_type_, input_event->type);
jddukec05612b2015-06-25 23:13:181099
1100 // Calls into |didOverscroll()| while handling this event will populate
1101 // |event_overscroll|, which in turn will be bundled with the event ack.
1102 scoped_ptr<DidOverscrollParams> event_overscroll;
1103 base::AutoReset<scoped_ptr<DidOverscrollParams>*>
1104 handling_event_overscroll_resetter(&handling_event_overscroll_,
1105 &event_overscroll);
1106
[email protected]25402eb2014-07-18 03:09:521107#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161108 const bool is_keyboard_event =
1109 WebInputEvent::isKeyboardEventType(input_event->type);
1110
1111 // For non-keyboard events, we want the change source to be FROM_NON_IME.
1112 ImeEventGuard guard(this, false, is_keyboard_event);
[email protected]25402eb2014-07-18 03:09:521113#endif
initial.commit09911bf2008-07-26 23:55:291114
[email protected]fd847792013-10-24 17:12:351115 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411116 if (base::TimeTicks::IsHighResolution())
1117 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351118
miletusfed8c43b2015-01-26 20:04:521119 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301120 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151121 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
yuhaoz8df9334c2015-08-18 17:48:511122 TRACE_EVENT_WITH_FLOW1("input,benchmark",
1123 "LatencyInfo.Flow",
1124 TRACE_ID_DONT_MANGLE(latency_info.trace_id()),
1125 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
1126 "step", "HandleInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101127
jdduke07788062014-12-05 03:16:301128 // If we don't have a high res timer, these metrics won't be accurate enough
1129 // to be worth collecting. Note that this does introduce some sampling bias.
1130 if (!start_time.is_null())
miletus14a25642015-08-13 19:23:231131 LogInputEventLatencyUma(*input_event, start_time, latency_info);
jdduke07788062014-12-05 03:16:301132
[email protected]6be422b2013-12-08 06:47:311133 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351134 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311135 if (compositor_) {
1136 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351137 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1138 .Pass();
[email protected]6be422b2013-12-08 06:47:311139 }
[email protected]c2eaa8f2013-05-10 02:41:551140
[email protected]67bfb83f2011-09-22 03:36:371141 bool prevent_default = false;
1142 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261143 const WebMouseEvent& mouse_event =
1144 *static_cast<const WebMouseEvent*>(input_event);
1145 TRACE_EVENT2("renderer", "HandleMouseMove",
1146 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421147 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261148 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371149 }
1150
[email protected]cefe9b152014-03-27 18:16:151151 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421152 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151153#if defined(OS_ANDROID)
1154 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1155 // case it should behave like a select key (i.e. causing a click if a button
1156 // is focused). However, if a text field is focused (2), its intended
1157 // behavior is to just show the IME and don't propagate the key.
1158 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1159 // when clicked on an input text field and cause the form submit if clicked
1160 // when the submit button is focused, but not vice-versa.
1161 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1162 // but at this point we have to swallow the event for the scenario (2).
1163 const WebKeyboardEvent& key_event =
1164 *static_cast<const WebKeyboardEvent*>(input_event);
1165 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1166 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1167 OnShowImeIfNeeded();
1168 prevent_default = true;
1169 }
1170#endif
1171 }
[email protected]f56c7872013-06-18 12:31:571172
[email protected]41d86852012-11-07 12:23:241173 if (WebInputEvent::isGestureEventType(input_event->type)) {
1174 const WebGestureEvent& gesture_event =
1175 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421176 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241177 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1178 }
1179
[email protected]67bfb83f2011-09-22 03:36:371180 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121181 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1182 suppress_next_char_events_ = false;
1183 if (!processed && webwidget_)
1184 processed = webwidget_->handleInputEvent(*input_event);
1185 }
1186
1187 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1188 // it's not processed by webkit, then we need to suppress the upcoming Char
1189 // events.
jdduke0cf1e662015-10-15 22:43:281190 bool is_keyboard_shortcut =
1191 input_event->type == WebInputEvent::RawKeyDown &&
1192 static_cast<const WebKeyboardEvent*>(input_event)->isBrowserShortcut;
[email protected]b68a0e52011-12-08 15:11:121193 if (!processed && is_keyboard_shortcut)
1194 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291195
[email protected]3d5c243b2012-11-30 00:26:011196 InputEventAckState ack_result = processed ?
1197 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1198 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1199 const WebTouchEvent& touch_event =
1200 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251201 // Hit-test for all the pressed touch points. If there is a touch-handler
1202 // for any of the touch points, then the renderer should continue to receive
1203 // touch events.
1204 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1205 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1206 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271207 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391208 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251209 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1210 break;
1211 }
1212 }
[email protected]3d5c243b2012-11-30 00:26:011213 }
1214
ccamerond4ba47902014-12-17 07:20:311215 // Send mouse wheel events and their disposition to the compositor thread, so
1216 // that they can be used to produce the elastic overscroll effect on Mac.
1217 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311218 ObserveWheelEventAndResult(
sataya.mf405d0e2015-07-07 16:51:111219 static_cast<const WebMouseWheelEvent&>(*input_event),
1220 event_overscroll ? event_overscroll->latest_overscroll_delta
1221 : gfx::Vector2dF(),
1222 processed);
ccamerond4ba47902014-12-17 07:20:311223 }
1224
[email protected]721e2302014-04-30 23:42:011225 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061226
charliea3be839702015-01-26 17:35:411227 // If we don't have a fast and accurate Now(), we assume the input handlers
1228 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301229 bool rate_limiting_wanted =
1230 input_event->type == WebInputEvent::MouseMove ||
1231 input_event->type == WebInputEvent::MouseWheel;
1232 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411233 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351234 total_input_handling_time_this_frame_ += (end_time - start_time);
1235 rate_limiting_wanted =
1236 total_input_handling_time_this_frame_.InMicroseconds() >
1237 kInputHandlingTimeThrottlingThresholdMicroseconds;
1238 }
1239
[email protected]7f19e9d2014-05-09 15:16:291240 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1241
[email protected]c27dd4f2014-05-22 18:05:191242 // Note that we can't use handling_event_type_ here since it will be overriden
1243 // by reentrant calls for events after the paused one.
1244 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1245 input_event->type == WebInputEvent::MouseMove;
lanweif1a22832015-05-19 17:24:101246 if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) &&
1247 !no_ack) {
1248 InputEventAck ack(input_event->type, ack_result, swap_latency_info,
jddukec05612b2015-06-25 23:13:181249 event_overscroll.Pass(),
lanweif1a22832015-05-19 17:24:101250 WebInputEventTraits::GetUniqueTouchEventId(*input_event));
[email protected]34afe102013-12-13 17:24:551251 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561252 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301253 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551254 // We want to rate limit the input events in this case, so we'll wait for
1255 // painting to finish before ACKing this message.
1256 TRACE_EVENT_INSTANT0("renderer",
1257 "RenderWidget::OnHandleInputEvent ack throttled",
1258 TRACE_EVENT_SCOPE_THREAD);
1259 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291260 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1261 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551262 // As two different kinds of events could cause us to postpone an ack
1263 // we send it now, if we have one pending. The Browser should never
1264 // send us the same kind of event we are delaying the ack for.
1265 Send(pending_input_event_ack_.release());
1266 }
1267 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291268 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1269 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551270 if (compositor_)
1271 compositor_->NotifyInputThrottledUntilCommit();
1272 } else {
1273 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171274 }
jddukec05612b2015-06-25 23:13:181275 } else {
1276 DCHECK(!event_overscroll) << "Unexpected overscroll for un-acked event";
[email protected]12fbad812009-09-01 18:21:241277 }
alexclarke7819e2552015-06-03 11:17:211278 if (!no_ack && RenderThreadImpl::current()) {
1279 RenderThreadImpl::current()
1280 ->GetRendererScheduler()
1281 ->DidHandleInputEventOnMainThread(*input_event);
1282 }
[email protected]5fea4a52014-05-27 00:17:521283 if (input_event->type == WebInputEvent::MouseMove)
1284 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241285
[email protected]3306f262012-09-21 19:20:421286#if defined(OS_ANDROID)
1287 // Allow the IME to be shown when the focus changes as a consequence
1288 // of a processed touch end event.
1289 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361290 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021291#elif defined(USE_AURA)
1292 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1293 // change.
1294 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141295 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361296 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141297 }
[email protected]3306f262012-09-21 19:20:421298#endif
1299
[email protected]67bfb83f2011-09-22 03:36:371300 if (!prevent_default) {
1301 if (WebInputEvent::isKeyboardEventType(input_event->type))
1302 DidHandleKeyEvent();
[email protected]67bfb83f2011-09-22 03:36:371303 }
rouslanf7ebd8832015-01-22 01:54:141304
1305// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1306// virtual keyboard.
1307#if !defined(OS_ANDROID)
1308 // Virtual keyboard is not supported, so react to focus change immediately.
1309 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1310 input_event->type == WebInputEvent::MouseUp)) {
1311 FocusChangeComplete();
1312 }
1313#endif
initial.commit09911bf2008-07-26 23:55:291314}
1315
[email protected]34202de2013-05-06 23:36:221316void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1317 if (webwidget_)
1318 webwidget_->setCursorVisibilityState(is_visible);
1319}
1320
initial.commit09911bf2008-07-26 23:55:291321void RenderWidget::OnMouseCaptureLost() {
1322 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281323 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291324}
1325
1326void RenderWidget::OnSetFocus(bool enable) {
[email protected]9d166af2010-03-02 22:04:331327 if (webwidget_)
1328 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291329}
1330
[email protected]fd847792013-10-24 17:12:351331void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291332 if (pending_input_event_ack_) {
1333 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1334 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071335 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291336 }
[email protected]fd847792013-10-24 17:12:351337 total_input_handling_time_this_frame_ = base::TimeDelta();
1338}
1339
initial.commit09911bf2008-07-26 23:55:291340///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461341// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291342
[email protected]244ac1892011-12-02 17:04:471343void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima750cb4342015-10-31 00:59:011344 // TODO(oshima): support UseZoomForDSFEnabled()
[email protected]ea3ee0a2012-05-15 03:43:091345 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451346 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581347
[email protected]5b45ad42013-10-25 00:42:041348 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451349 WebRect new_pos(rootWindowRect().x,
1350 rootWindowRect().y,
1351 new_size.width,
1352 new_size.height);
1353 view_screen_rect_ = new_pos;
1354 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031355 }
[email protected]20fbfc22013-05-08 20:50:581356
[email protected]eac2b362013-05-22 07:01:451357 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581358
[email protected]5b45ad42013-10-25 00:42:041359 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581360 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091361 }
[email protected]244ac1892011-12-02 17:04:471362}
1363
[email protected]3a1c8a8032013-03-18 22:35:321364void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401365 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051366 if (compositor_)
oshima750cb4342015-10-31 00:59:011367 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051368}
1369
[email protected]e195e582013-03-08 01:32:591370void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221371 DCHECK(!host_closing_);
1372
danakj6e3bf8012014-12-16 18:27:531373 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
oshima750cb4342015-10-31 00:59:011374 compositor_->setViewportSize(physical_backing_size_);
sievers71c62dd52015-10-07 01:44:391375
1376 // For background pages and certain tests, we don't want to trigger
1377 // OutputSurface creation.
1378 if (compositor_never_visible_ || !RenderThreadImpl::current())
1379 compositor_->SetNeverVisible();
1380
pimanc4af3072015-10-02 03:45:591381 StartCompositor();
[email protected]e195e582013-03-08 01:32:591382}
1383
ennef3c58142014-12-09 21:44:381384void RenderWidget::WillCloseLayerTreeView() {
1385 if (host_closing_)
1386 return;
1387
1388 // Prevent new compositors or output surfaces from being created.
1389 host_closing_ = true;
1390
[email protected]aeeedad2014-08-22 18:16:221391 // Always send this notification to prevent new layer tree views from
1392 // being created, even if one hasn't been created yet.
1393 if (webwidget_)
1394 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221395}
1396
[email protected]180ef242013-11-07 06:50:461397blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281398 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061399}
1400
dglazkovf0e1d6d2015-10-10 02:13:481401void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1402 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1403 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1404 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1405 }
dglazkov79c426102015-08-31 21:22:431406
dglazkovf0e1d6d2015-10-10 02:13:481407 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1408 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431409}
1410
jdduke491a3f0c2015-06-15 23:30:261411void RenderWidget::WillBeginCompositorFrame() {
[email protected]9cd43a62012-03-26 08:03:561412 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371413
shuchen913f8b622015-07-31 13:22:431414 // The UpdateTextInputState can result in further layout and possibly
[email protected]abe8b3a2012-03-28 21:19:371415 // enable GPU acceleration so they need to be called before any painting
1416 // is done.
[email protected]90f24152014-04-09 12:41:361417 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
[email protected]abe8b3a2012-03-28 21:19:371418 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561419}
1420
[email protected]6fceb912013-02-15 06:24:151421void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441422 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1423 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271424 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161425 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171426#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271427 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1428 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171429#endif // defined(VIDEO_HOLE)
jdduke491a3f0c2015-06-15 23:30:261430 FlushPendingInputEventAck();
1431}
1432
1433void RenderWidget::DidCommitAndDrawCompositorFrame() {
1434 // NOTE: Tests may break if this event is renamed or moved. See
1435 // tab_capture_performancetest.cc.
1436 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
1437 // Notify subclasses that we initiated the paint operation.
1438 DidInitiatePaint();
1439}
1440
1441void RenderWidget::DidCompleteSwapBuffers() {
1442 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
1443
1444 // Notify subclasses threaded composited rendering was flushed to the screen.
1445 DidFlushPaint();
1446
1447 if (!next_paint_flags_ &&
1448 !need_update_rect_for_auto_resize_ &&
1449 !plugin_window_moves_.size()) {
1450 return;
1451 }
1452
1453 ViewHostMsg_UpdateRect_Params params;
1454 params.view_size = size_;
1455 params.plugin_window_moves.swap(plugin_window_moves_);
1456 params.flags = next_paint_flags_;
1457
1458 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1459 next_paint_flags_ = 0;
1460 need_update_rect_for_auto_resize_ = false;
1461}
1462
1463void RenderWidget::ScheduleComposite() {
1464 if (compositor_ &&
1465 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1466 compositor_->setNeedsAnimate();
1467 }
1468}
1469
1470void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1471 if (compositor_) {
1472 // Regardless of whether threaded compositing is enabled, always
1473 // use this mechanism to force the compositor to redraw. However,
1474 // the invalidation code path below is still needed for the
1475 // non-threaded case.
1476 compositor_->SetNeedsForcedRedraw();
1477 }
1478 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151479}
1480
[email protected]586871b2014-07-22 17:05:111481// static
1482scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1483 IPC::Message* msg,
1484 MessageDeliveryPolicy policy,
1485 FrameSwapMessageQueue* frame_swap_message_queue,
1486 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111487 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111488 bool first_message_for_frame = false;
1489 frame_swap_message_queue->QueueMessageForFrame(policy,
1490 source_frame_number,
1491 make_scoped_ptr(msg),
1492 &first_message_for_frame);
1493 if (first_message_for_frame) {
1494 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1495 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061496 return promise;
[email protected]586871b2014-07-22 17:05:111497 }
dcheng4b6b5ff2014-10-16 00:42:061498 return nullptr;
[email protected]586871b2014-07-22 17:05:111499}
1500
1501void RenderWidget::QueueMessage(IPC::Message* msg,
1502 MessageDeliveryPolicy policy) {
1503 // RenderThreadImpl::current() is NULL in some tests.
1504 if (!compositor_ || !RenderThreadImpl::current()) {
1505 Send(msg);
1506 return;
1507 }
1508
1509 scoped_ptr<cc::SwapPromise> swap_promise =
1510 QueueMessageImpl(msg,
1511 policy,
dcheng58867a92014-08-26 02:50:221512 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111513 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111514 compositor_->GetSourceFrameNumber());
1515
1516 if (swap_promise) {
1517 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351518 // Request a commit. This might either A) request a commit ahead of time
1519 // or B) request a commit which is not needed because there are not
1520 // pending updates. If B) then the commit will be skipped and the swap
1521 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1522 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1523 // can_cancel_commit is not unset.
1524 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111525 }
1526}
1527
[email protected]4873c7d2009-07-16 06:36:281528void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301529 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521530 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181531 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291532 // Only send a SetCursor message if we need to make a change.
1533 if (!current_cursor_.IsEqual(cursor)) {
1534 current_cursor_ = cursor;
1535 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1536 }
1537}
1538
1539// We are supposed to get a single call to Show for a newly created RenderWidget
1540// that was created via RenderWidget::CreateWebView. So, we wait until this
1541// point to dispatch the ShowWidget message.
1542//
1543// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281544// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291545//
[email protected]4873c7d2009-07-16 06:36:281546void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291547 DCHECK(!did_show_) << "received extraneous Show call";
1548 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1549 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1550
[email protected]8de12d942010-11-17 20:42:441551 if (did_show_)
1552 return;
1553
1554 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561555 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441556 // that's okay. It'll be ignored if as_popup is false, or the browser
1557 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561558 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1559 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291560}
1561
[email protected]4873c7d2009-07-16 06:36:281562void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291563}
1564
[email protected]2533ce12009-05-09 00:02:241565void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381566 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241567 Send(new ViewHostMsg_Close(routing_id_));
1568}
1569
dgozmancf9039cd2015-04-06 12:01:311570void RenderWidget::NotifyOnClose() {
1571 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1572}
1573
[email protected]4873c7d2009-07-16 06:36:281574void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081575 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321576 if (is_swapped_out_) {
1577 // This widget is currently swapped out, and the active widget is in a
1578 // different process. Have the browser route the close request to the
1579 // active widget instead, so that the correct unload handlers are run.
1580 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1581 return;
1582 }
1583
initial.commit09911bf2008-07-26 23:55:291584 // If a page calls window.close() twice, we'll end up here twice, but that's
1585 // OK. It is safe to send multiple Close messages.
1586
[email protected]2533ce12009-05-09 00:02:241587 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1588 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1589 // could be closed before the JS finishes executing. So instead, post a
1590 // message back to the message loop, which won't run until the JS is
1591 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081592 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211593 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291594}
1595
[email protected]9017d7852013-11-21 17:47:351596void RenderWidget::QueueSyntheticGesture(
1597 scoped_ptr<SyntheticGestureParams> gesture_params,
1598 const SyntheticGestureCompletionCallback& callback) {
1599 DCHECK(!callback.is_null());
1600
1601 pending_synthetic_gesture_callbacks_.push(callback);
1602
1603 SyntheticGesturePacket gesture_packet;
1604 gesture_packet.set_gesture_params(gesture_params.Pass());
1605
1606 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1607}
1608
initial.commit09911bf2008-07-26 23:55:291609void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031610 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381611 WillCloseLayerTreeView();
1612 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291613 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281614 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291615 webwidget_ = NULL;
1616 }
1617}
1618
[email protected]4873c7d2009-07-16 06:36:281619WebRect RenderWidget::windowRect() {
1620 if (pending_window_rect_count_)
1621 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241622
[email protected]80ad8622012-11-07 16:33:031623 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291624}
1625
[email protected]180ef242013-11-07 06:50:461626void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301627 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541628 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301629}
1630
[email protected]b2e4c70132013-10-03 02:07:511631void RenderWidget::setWindowRect(const WebRect& rect) {
oshima750cb4342015-10-31 00:59:011632 // TODO(oshima): Scale back to DIP coordinates.
bokanc007c3a2015-02-03 07:15:561633 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511634 if (popup_origin_scale_for_emulation_) {
1635 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561636 window_rect.x = popup_screen_origin_for_emulation_.x() +
1637 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1638 window_rect.y = popup_screen_origin_for_emulation_.y() +
1639 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511640 }
1641
[email protected]5b45ad42013-10-25 00:42:041642 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201643 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561644 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1645 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031646 } else {
bokanc007c3a2015-02-03 07:15:561647 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031648 }
initial.commit09911bf2008-07-26 23:55:291649 } else {
bokanc007c3a2015-02-03 07:15:561650 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291651 }
1652}
1653
[email protected]2533ce12009-05-09 00:02:241654void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1655 pending_window_rect_ = rect;
1656 pending_window_rect_count_++;
1657}
1658
[email protected]4873c7d2009-07-16 06:36:281659WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241660 if (pending_window_rect_count_) {
1661 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1662 // the RootWindowRect is probably going to return wrong results since the
1663 // browser may not have processed the Move yet. There isn't really anything
1664 // good to do in this case, and it shouldn't happen - since this size is
1665 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281666 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241667 }
1668
[email protected]80ad8622012-11-07 16:33:031669 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371670}
1671
[email protected]4873c7d2009-07-16 06:36:281672WebRect RenderWidget::windowResizerRect() {
1673 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191674}
1675
[email protected]fa7b1dc2010-06-23 17:53:041676void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261677 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041678 const std::vector<WebCompositionUnderline>& underlines,
1679 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131680 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281681 return;
[email protected]66fca5bc2013-05-23 06:58:291682 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361683 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041684 text, WebVector<WebCompositionUnderline>(underlines),
1685 selection_start, selection_end)) {
1686 // If we failed to set the composition text, then we need to let the browser
1687 // process to cancel the input method's ongoing composition session, to make
1688 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221689 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261690 }
[email protected]88dbe32f2013-06-20 23:31:361691 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041692}
1693
[email protected]fcf75d42013-12-03 20:11:261694void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511695 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021696 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131697 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041698 return;
[email protected]66fca5bc2013-05-23 06:58:291699 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041700 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021701 if (text.length())
1702 webwidget_->confirmComposition(text);
1703 else if (keep_selection)
1704 webwidget_->confirmComposition(WebWidget::KeepSelection);
1705 else
1706 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041707 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361708 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291709}
1710
[email protected]0bc1f572013-04-17 01:46:311711void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121712 // During shutdown we can just ignore this message.
1713 if (!webwidget_)
1714 return;
1715
[email protected]0bc1f572013-04-17 01:46:311716 // Even if the browser provides an empty damage rect, it's still expecting to
1717 // receive a repaint ack so just damage the entire widget bounds.
1718 if (size_to_paint.IsEmpty()) {
1719 size_to_paint = size_;
1720 }
1721
[email protected]ec7dc112008-08-06 05:30:121722 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051723 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311724 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121725}
1726
[email protected]79fa22e2013-08-23 15:18:121727void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351728 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1729
1730 pending_synthetic_gesture_callbacks_.front().Run();
1731 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271732}
1733
[email protected]4873c7d2009-07-16 06:36:281734void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111735 if (!webwidget_)
1736 return;
[email protected]4873c7d2009-07-16 06:36:281737 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111738}
1739
[email protected]80ad8622012-11-07 16:33:031740void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1741 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511742 if (screen_metrics_emulator_) {
1743 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1744 view_screen_rect, window_screen_rect);
1745 } else {
1746 view_screen_rect_ = view_screen_rect;
1747 window_screen_rect_ = window_screen_rect;
1748 }
[email protected]80ad8622012-11-07 16:33:031749 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1750}
1751
kenrbb4e2a3b2015-05-14 15:05:051752void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1753 if (compositor_)
1754 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1755}
1756
dtrainor5ef644e2015-11-19 00:12:471757void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1758 if (compositor_)
1759 compositor_->OnHandleCompositorProto(proto);
1760}
1761
[email protected]adb362312014-06-28 06:04:241762void RenderWidget::showImeIfNeeded() {
1763 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131764}
1765
[email protected]adb362312014-06-28 06:04:241766void RenderWidget::OnShowImeIfNeeded() {
1767#if defined(OS_ANDROID) || defined(USE_AURA)
1768 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1769#endif
rouslanf7ebd8832015-01-22 01:54:141770
1771// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1772// virtual keyboard.
1773#if !defined(OS_ANDROID)
1774 FocusChangeComplete();
1775#endif
[email protected]adb362312014-06-28 06:04:241776}
1777
1778#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371779void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1780 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131781}
1782
1783void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371784 DCHECK_GE(text_input_info_history_.size(), 1u);
1785 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511786}
[email protected]105dffb42013-02-20 03:46:211787#endif
1788
[email protected]0d1ebed12013-08-05 22:01:131789bool RenderWidget::ShouldHandleImeEvent() {
1790#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371791 if (!webwidget_)
1792 return false;
1793
1794 // We cannot handle IME events if there is any chance that the event we are
1795 // receiving here from the browser is based on the state that is different
1796 // from our current one as indicated by |text_input_info_|.
1797 // The states the browser might be in are:
1798 // text_input_info_history_[0] - current state ack'd by browser
1799 // text_input_info_history_[1...N] - pending state changes
1800 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1801 if (text_input_info_history_[i] != text_input_info_)
1802 return false;
1803 }
1804 return true;
[email protected]0d1ebed12013-08-05 22:01:131805#else
1806 return !!webwidget_;
1807#endif
1808}
1809
[email protected]c27dd4f2014-05-22 18:05:191810bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1811 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521812 // If we pause multiple times during a single mouse move event, we should
1813 // only send ACK once.
1814 if (!ignore_ack_for_mouse_move_from_debugger_) {
lanweif1a22832015-05-19 17:24:101815 InputEventAck ack(handling_event_type_, INPUT_EVENT_ACK_STATE_CONSUMED);
[email protected]5fea4a52014-05-27 00:17:521816 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dgozmanb739185d2015-04-10 15:04:021817 return true;
[email protected]5fea4a52014-05-27 00:17:521818 }
[email protected]c27dd4f2014-05-22 18:05:191819 }
1820 return false;
1821}
1822
1823void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1824 ignore_ack_for_mouse_move_from_debugger_ = true;
1825}
1826
[email protected]468ac582012-11-20 00:53:191827void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1828 if (device_scale_factor_ == device_scale_factor)
1829 return;
1830
1831 device_scale_factor_ = device_scale_factor;
jdduke491a3f0c2015-06-15 23:30:261832 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191833}
1834
[email protected]28ed6b32014-06-08 02:16:271835bool RenderWidget::SetDeviceColorProfile(
1836 const std::vector<char>& color_profile) {
1837 if (device_color_profile_ == color_profile)
1838 return false;
1839
1840 device_color_profile_ = color_profile;
1841 return true;
1842}
1843
noeldb4df152014-09-16 17:45:201844void RenderWidget::ResetDeviceColorProfileForTesting() {
1845 if (!device_color_profile_.empty())
1846 device_color_profile_.clear();
1847 device_color_profile_.push_back('0');
1848}
1849
[email protected]fcdc5642014-05-09 14:32:241850void RenderWidget::OnOrientationChange() {
1851}
1852
[email protected]ceb36f7d2012-10-31 18:33:241853gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521854 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241855 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521856}
1857
[email protected]bee16aab2009-08-26 15:55:031858void RenderWidget::SetHidden(bool hidden) {
1859 if (is_hidden_ == hidden)
1860 return;
1861
jdduke8fac9d102014-12-20 02:40:131862 // The status has changed. Tell the RenderThread about it and ensure
1863 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031864 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131865 FlushPendingInputEventAck();
1866
[email protected]bee16aab2009-08-26 15:55:031867 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001868 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031869 else
[email protected]b2db9272014-01-10 17:42:001870 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111871
1872 if (render_widget_scheduling_state_)
1873 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031874}
1875
[email protected]2b624c562011-10-27 22:58:261876void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261877 if (!webwidget_)
1878 return;
1879
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121880 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261881 webwidget_->didEnterFullScreen();
1882 } else {
1883 webwidget_->didExitFullScreen();
1884 }
[email protected]2b624c562011-10-27 22:58:261885}
1886
[email protected]674741932009-02-04 23:44:461887bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051888 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461889}
1890
[email protected]674741932009-02-04 23:44:461891void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051892 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461893}
1894
[email protected]674741932009-02-04 23:44:461895void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051896 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461897}
1898
[email protected]b18583c2012-12-18 06:55:271899static bool IsDateTimeInput(ui::TextInputType type) {
1900 return type == ui::TEXT_INPUT_TYPE_DATE ||
1901 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1902 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1903 type == ui::TEXT_INPUT_TYPE_MONTH ||
1904 type == ui::TEXT_INPUT_TYPE_TIME ||
1905 type == ui::TEXT_INPUT_TYPE_WEEK;
1906}
1907
changwanf2a707b2015-10-30 08:22:161908void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1909 if (!ime_event_guard_)
1910 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291911}
1912
changwanf2a707b2015-10-30 08:22:161913void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1914 if (ime_event_guard_ != guard) {
1915#if defined(OS_ANDROID)
1916 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1917 // (e.g. long press gesture), we want to treat it as not-from-IME event
1918 // so that AdapterInputConnection can make changes to its Editable model.
1919 // Therefore, we want to mark this text state update as 'from IME' only
1920 // when all the nested events are all originating from IME.
1921 ime_event_guard_->set_from_ime(
1922 ime_event_guard_->from_ime() && guard->from_ime());
1923#endif
1924 return;
1925 }
1926 ime_event_guard_ = nullptr;
1927
[email protected]66fca5bc2013-05-23 06:58:291928 // While handling an ime event, text input state and selection bounds updates
1929 // are ignored. These must explicitly be updated once finished handling the
1930 // ime event.
1931 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471932#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161933 UpdateTextInputState(
1934 guard->show_ime() ? SHOW_IME_IF_NEEDED : NO_SHOW_IME,
1935 guard->from_ime() ? FROM_IME : FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471936#endif
[email protected]66fca5bc2013-05-23 06:58:291937}
1938
[email protected]90f24152014-04-09 12:41:361939void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1940 ChangeSource change_source) {
jdduke1aebad8e2015-07-22 23:25:081941 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwanf2a707b2015-10-30 08:22:161942 if (ime_event_guard_) {
1943 // show_ime should still be effective even if it was set inside the IME
1944 // event guard.
1945 if (show_ime == SHOW_IME_IF_NEEDED) {
1946 ime_event_guard_->set_show_ime(true);
1947 }
[email protected]e8f775f2013-02-14 21:00:501948 return;
changwanf2a707b2015-10-30 08:22:161949 }
1950
[email protected]ad26ef42011-06-17 07:59:451951 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271952 if (IsDateTimeInput(new_type))
1953 return; // Not considered as a text input field in WebKit/Chromium.
1954
[email protected]180ef242013-11-07 06:50:461955 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211956 if (webwidget_)
1957 new_info = webwidget_->textInputInfo();
shuchen913f8b622015-07-31 13:22:431958 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
[email protected]5b739cb2012-08-21 20:35:211959
[email protected]ad26ef42011-06-17 07:59:451960 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211961
[email protected]3306f262012-09-21 19:20:421962 // Only sends text input params if they are changed or if the ime should be
1963 // shown.
[email protected]90f24152014-04-09 12:41:361964 if (show_ime == SHOW_IME_IF_NEEDED ||
1965 (text_input_type_ != new_type ||
shuchen913f8b622015-07-31 13:22:431966 text_input_mode_ != new_mode ||
[email protected]90f24152014-04-09 12:41:361967 text_input_info_ != new_info ||
1968 can_compose_inline_ != new_can_compose_inline)
1969#if defined(OS_ANDROID)
1970 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021971#endif
[email protected]90f24152014-04-09 12:41:361972 ) {
shuchen913f8b622015-07-31 13:22:431973 ViewHostMsg_TextInputState_Params params;
1974 params.type = new_type;
1975 params.mode = new_mode;
1976 params.flags = new_info.flags;
1977 params.value = new_info.value.utf8();
1978 params.selection_start = new_info.selectionStart;
1979 params.selection_end = new_info.selectionEnd;
1980 params.composition_start = new_info.compositionStart;
1981 params.composition_end = new_info.compositionEnd;
1982 params.can_compose_inline = new_can_compose_inline;
1983 params.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
[email protected]90f24152014-04-09 12:41:361984#if defined(USE_AURA)
shuchen913f8b622015-07-31 13:22:431985 params.is_non_ime_change = true;
[email protected]90f24152014-04-09 12:41:361986#endif
[email protected]183e28d2014-01-20 18:18:021987#if defined(OS_ANDROID)
shuchen913f8b622015-07-31 13:22:431988 params.is_non_ime_change = (change_source == FROM_NON_IME) ||
[email protected]90f24152014-04-09 12:41:361989 text_field_is_dirty_;
shuchen913f8b622015-07-31 13:22:431990 if (params.is_non_ime_change)
changwan3a841162015-08-11 02:53:371991 OnImeEventSentForAck(new_info);
[email protected]90f24152014-04-09 12:41:361992 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021993#endif
shuchen913f8b622015-07-31 13:22:431994 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
[email protected]5b739cb2012-08-21 20:35:211995
1996 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041997 text_input_type_ = new_type;
shuchen913f8b622015-07-31 13:22:431998 text_input_mode_ = new_mode;
[email protected]ad26ef42011-06-17 07:59:451999 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:202000 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:292001 }
initial.commit09911bf2008-07-26 23:55:292002}
2003
[email protected]7c8873e2013-02-05 08:03:012004void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2005 WebRect focus_webrect;
2006 WebRect anchor_webrect;
2007 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima750cb4342015-10-31 00:59:012008 if (IsUseZoomForDSFEnabled()) {
2009 float inverse_scale = 1.f / device_scale_factor_;
2010 gfx::RectF focus_rect(focus_webrect);
2011 *focus = gfx::ToEnclosingRect(gfx::ScaleRect(focus_rect, inverse_scale));
2012 gfx::RectF anchor_rect(anchor_webrect);
2013 *anchor = gfx::ToEnclosingRect(gfx::ScaleRect(anchor_rect, inverse_scale));
2014 } else {
2015 *focus = focus_webrect;
2016 *anchor = anchor_webrect;
2017 }
[email protected]73bf95812011-10-12 11:38:322018}
2019
[email protected]e99ef6f2011-10-16 01:13:002020void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082021 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:002022 if (!webwidget_)
2023 return;
changwanf2a707b2015-10-30 08:22:162024 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292025 return;
[email protected]e99ef6f2011-10-16 01:13:002026
mohsenb0eeba72015-08-09 06:20:082027#if defined(USE_AURA)
2028 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2029 // Aura beucause composited selection updates are not working for webview tags
2030 // which regresses IME inside webview. Remove this when composited selection
2031 // updates are fixed for webviews. See, http://crbug.com/510568.
2032 bool send_ipc = true;
2033#else
jddukeacf809e2014-09-23 20:38:382034 // With composited selection updates, the selection bounds will be reported
2035 // directly by the compositor, in which case explicit IPC selection
2036 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082037 bool send_ipc =
2038 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
2039#endif
2040 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382041 ViewHostMsg_SelectionBounds_Params params;
2042 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2043 if (selection_anchor_rect_ != params.anchor_rect ||
2044 selection_focus_rect_ != params.focus_rect) {
2045 selection_anchor_rect_ = params.anchor_rect;
2046 selection_focus_rect_ = params.focus_rect;
2047 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2048 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2049 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2050 }
[email protected]58b48a0d2012-06-13 07:01:352051 }
jddukeacf809e2014-09-23 20:38:382052
[email protected]88dbe32f2013-06-20 23:31:362053 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002054}
2055
dtrainor5ef644e2015-11-19 00:12:472056void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
2057 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
2058}
2059
[email protected]180ef242013-11-07 06:50:462060// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172061#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2062 static_assert(int(blink::WebTextInputType##a) \
2063 == int(ui::TEXT_INPUT_TYPE_##b), \
2064 "mismatching enums: " #a)
2065
2066STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2067STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2068STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2069STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2070STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2071STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2072STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2073STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2074STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2075STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2076STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2077STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2078STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2079STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2080STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2081STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2082STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452083
[email protected]5b739cb2012-08-21 20:35:212084ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462085 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212086 // Check the type is in the range representable by ui::TextInputType.
2087 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462088 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212089 return static_cast<ui::TextInputType>(type);
2090}
2091
[email protected]ad26ef42011-06-17 07:59:452092ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272093 if (webwidget_)
jdduke3bf083fe2015-09-29 23:40:532094 return WebKitToUiTextInputType(webwidget_->textInputType());
[email protected]ad26ef42011-06-17 07:59:452095 return ui::TEXT_INPUT_TYPE_NONE;
2096}
2097
[email protected]501ea13d2013-07-09 17:03:292098void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302099#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112100 // TODO(yukawa): Start sending character bounds when the browser side
2101 // implementation becomes ready (crbug.com/424866).
2102#else
jdduke1aebad8e2015-07-22 23:25:082103 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
[email protected]db4fc1e2013-09-06 20:01:512104 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292105 if (should_update_range) {
2106 GetCompositionRange(&range);
2107 } else {
2108 range = composition_range_;
2109 }
2110 std::vector<gfx::Rect> character_bounds;
2111 GetCompositionCharacterBounds(&character_bounds);
2112
2113 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2114 return;
2115 composition_character_bounds_ = character_bounds;
2116 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222117 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292118 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112119#endif
[email protected]501ea13d2013-07-09 17:03:292120}
2121
[email protected]58b48a0d2012-06-13 07:01:352122void RenderWidget::GetCompositionCharacterBounds(
2123 std::vector<gfx::Rect>* bounds) {
2124 DCHECK(bounds);
2125 bounds->clear();
2126}
2127
[email protected]db4fc1e2013-09-06 20:01:512128void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362129 size_t location, length;
2130 if (webwidget_->compositionRange(&location, &length)) {
2131 range->set_start(location);
2132 range->set_end(location + length);
2133 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2134 range->set_start(location);
2135 range->set_end(location + length);
2136 } else {
[email protected]db4fc1e2013-09-06 20:01:512137 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362138 }
2139}
2140
[email protected]501ea13d2013-07-09 17:03:292141bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512142 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292143 const std::vector<gfx::Rect>& bounds) {
2144 if (composition_range_ != range)
2145 return true;
2146 if (bounds.size() != composition_character_bounds_.size())
2147 return true;
2148 for (size_t i = 0; i < bounds.size(); ++i) {
2149 if (bounds[i] != composition_character_bounds_[i])
2150 return true;
2151 }
2152 return false;
2153}
[email protected]501ea13d2013-07-09 17:03:292154
[email protected]a4f0d882014-05-01 23:48:102155#if defined(OS_ANDROID)
timav7a5032e2014-12-05 01:59:432156bool RenderWidget::DoesRecordFullLayer() const {
boliu15ca2652015-09-04 23:33:402157 return false;
timav7a5032e2014-12-05 01:59:432158}
[email protected]a4f0d882014-05-01 23:48:102159#endif
2160
[email protected]ad26ef42011-06-17 07:59:452161bool RenderWidget::CanComposeInline() {
2162 return true;
[email protected]56ea1a62011-05-30 07:05:572163}
2164
[email protected]4873c7d2009-07-16 06:36:282165WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042166 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282167}
2168
[email protected]fa7b1dc2010-06-23 17:53:042169void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022170 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042171 // If the last text input type is not None, then we should finish any
2172 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452173 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042174 // If a composition text exists, then we need to let the browser process
2175 // to cancel the input method's ongoing composition session.
2176 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222177 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042178 }
[email protected]d4cff272011-05-02 15:46:012179
[email protected]88dbe32f2013-06-20 23:31:362180 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042181}
2182
donnda070f3c2015-01-16 19:54:112183#if defined(OS_ANDROID)
2184void RenderWidget::showUnhandledTapUIIfNeeded(
2185 const WebPoint& tapped_position,
2186 const WebNode& tapped_node,
2187 bool page_changed) {
2188 DCHECK(handling_input_event_);
2189 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372190 !tapped_node.isContentEditable() &&
2191 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112192 if (should_trigger) {
2193 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2194 tapped_position.x, tapped_position.y));
2195 }
2196}
2197#endif
2198
[email protected]c68c3e4e2013-01-24 00:36:562199void RenderWidget::didHandleGestureEvent(
2200 const WebGestureEvent& event,
2201 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022202#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562203 if (event_cancelled)
2204 return;
[email protected]07c70d22014-08-21 08:33:462205 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362206 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462207 } else if (event.type == WebInputEvent::GestureLongPress) {
2208 DCHECK(webwidget_);
2209 if (webwidget_->textInputInfo().value.isEmpty())
2210 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2211 else
2212 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562213 }
2214#endif
2215}
2216
sataya.m582c9ce2015-06-09 08:03:422217void RenderWidget::didOverscroll(
2218 const blink::WebFloatSize& unusedDelta,
2219 const blink::WebFloatSize& accumulatedRootOverScroll,
2220 const blink::WebFloatPoint& position,
2221 const blink::WebFloatSize& velocity) {
2222 DidOverscrollParams params;
sataya.m582c9ce2015-06-09 08:03:422223 params.accumulated_overscroll = gfx::Vector2dF(
2224 accumulatedRootOverScroll.width, accumulatedRootOverScroll.height);
2225 params.latest_overscroll_delta =
2226 gfx::Vector2dF(unusedDelta.width, unusedDelta.height);
sataya.ma5cc13a2015-06-13 11:06:022227 // TODO(sataya.m): don't negate velocity once http://crbug.com/499743 is
2228 // fixed.
sataya.m582c9ce2015-06-09 08:03:422229 params.current_fling_velocity =
sataya.ma5cc13a2015-06-13 11:06:022230 gfx::Vector2dF(-velocity.width, -velocity.height);
sataya.m582c9ce2015-06-09 08:03:422231 params.causal_event_viewport_point = gfx::PointF(position.x, position.y);
jddukec05612b2015-06-25 23:13:182232
2233 // If we're currently handling an event, stash the overscroll data such that
2234 // it can be bundled in the event ack.
2235 if (handling_event_overscroll_) {
2236 handling_event_overscroll_->reset(new DidOverscrollParams(params));
2237 return;
2238 }
2239
sataya.m582c9ce2015-06-09 08:03:422240 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
2241}
2242
[email protected]7912e822014-04-16 02:37:032243void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392244 if (!is_hidden())
2245 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032246}
2247
[email protected]29e2fb42013-07-19 01:13:472248void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292249 size_t i = 0;
2250 for (; i < plugin_window_moves_.size(); ++i) {
2251 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582252 if (move.rects_valid) {
2253 plugin_window_moves_[i] = move;
2254 } else {
2255 plugin_window_moves_[i].visible = move.visible;
2256 }
initial.commit09911bf2008-07-26 23:55:292257 break;
2258 }
2259 }
2260
2261 if (i == plugin_window_moves_.size())
2262 plugin_window_moves_.push_back(move);
2263}
[email protected]268654772009-08-06 23:02:042264
2265void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2266 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2267 i != plugin_window_moves_.end(); ++i) {
2268 if (i->window == window) {
2269 plugin_window_moves_.erase(i);
2270 break;
2271 }
2272 }
2273}
[email protected]67bfb83f2011-09-22 03:36:372274
[email protected]63b465922012-09-06 02:04:522275
[email protected]24ed0432013-04-24 07:50:312276RenderWidgetCompositor* RenderWidget::compositor() const {
2277 return compositor_.get();
2278}
2279
[email protected]180ef242013-11-07 06:50:462280bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372281 return false;
2282}
[email protected]c3d45532011-10-07 19:20:402283
[email protected]41d86852012-11-07 12:23:242284bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462285 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242286 return false;
2287}
2288
ccamerona7644752014-12-30 01:16:312289void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312290 const blink::WebMouseWheelEvent& wheel_event,
sataya.mf405d0e2015-07-07 16:51:112291 const gfx::Vector2dF& wheel_unused_delta,
ccamerond4ba47902014-12-17 07:20:312292 bool event_processed) {
ccamerona7644752014-12-30 01:16:312293 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312294 return;
2295
ccamerond4ba47902014-12-17 07:20:312296 cc::InputHandlerScrollResult scroll_result;
sataya.mf405d0e2015-07-07 16:51:112297 scroll_result.did_scroll = event_processed;
2298 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
2299 scroll_result.unused_scroll_delta = wheel_unused_delta;
ccamerond4ba47902014-12-17 07:20:312300
2301 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2302 InputHandlerManager* input_handler_manager =
2303 render_thread ? render_thread->input_handler_manager() : NULL;
2304 if (input_handler_manager) {
2305 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2306 routing_id_, wheel_event, scroll_result);
2307 }
2308}
2309
[email protected]ce6689f2013-03-29 12:52:552310void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112311 if (render_widget_scheduling_state_)
2312 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552313 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2314}
2315
mostynbe29b6882015-01-13 09:59:172316// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2317#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2318 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2319 "mismatching enums: " #a)
2320
[email protected]5d0bbdfa92013-12-10 00:35:512321void RenderWidget::setTouchAction(
2322 blink::WebTouchAction web_touch_action) {
2323
2324 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2325 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192326 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512327 return;
2328
dtapuskaa98ac8d72015-05-08 19:29:092329 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172330 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092331 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2332 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172333 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092334 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2335 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172336 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
rbyersa8b478d2015-10-30 15:49:102337 STATIC_ASSERT_WTI_ENUM_MATCH(Pan, PAN);
mostynbe29b6882015-01-13 09:59:172338 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
rbyersa8b478d2015-10-30 15:49:102339 STATIC_ASSERT_WTI_ENUM_MATCH(Manipulation, MANIPULATION);
2340 STATIC_ASSERT_WTI_ENUM_MATCH(DoubleTapZoom, DOUBLE_TAP_ZOOM);
2341 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
[email protected]a18f67a2013-12-20 19:44:362342
2343 content::TouchAction content_touch_action =
2344 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512345 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2346}
2347
[email protected]90f24152014-04-09 12:41:362348void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2349#if defined(OS_ANDROID)
2350 text_field_is_dirty_ = true;
2351#endif
2352}
2353
[email protected]3d5c243b2012-11-30 00:26:012354bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2355 return true;
2356}
2357
[email protected]0634cdd42013-08-16 00:46:092358scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
jbauman5e420d32015-08-05 09:33:012359RenderWidget::CreateGraphicsContext3D(bool compositor) {
[email protected]ed7defa2013-03-12 21:29:592360 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092361 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492362 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222363 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092364 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292365 if (!RenderThreadImpl::current())
2366 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402367 CauseForGpuLaunch cause =
2368 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292369 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402370 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222371 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292372 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592373
[email protected]828a3932014-04-02 14:43:132374 // Explicitly disable antialiasing for the compositor. As of the time of
2375 // this writing, the only platform that supported antialiasing for the
2376 // compositor was Mac OS X, because the on-screen OpenGL context creation
2377 // code paths on Windows and Linux didn't yet have multisampling support.
2378 // Mac OS X essentially always behaves as though it's rendering offscreen.
2379 // Multisampling has a heavy cost especially on devices with relatively low
2380 // fill rate like most notebooks, and the Mac implementation would need to
2381 // be optimized to resolve directly into the IOSurface shared between the
2382 // GPU and browser processes. For these reasons and to avoid platform
2383 // disparities we explicitly disable antialiasing.
2384 blink::WebGraphicsContext3D::Attributes attributes;
2385 attributes.antialias = false;
2386 attributes.shareResources = true;
2387 attributes.noAutomaticFlushes = true;
2388 attributes.depth = false;
2389 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132390 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292391 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012392#if defined(OS_ANDROID)
boliu853d46052015-10-13 20:20:062393 bool using_synchronous_compositing =
boliubee541f42015-11-05 00:52:532394 SynchronousCompositorFactory::GetInstance() ||
2395 base::CommandLine::ForCurrentProcess()->HasSwitch(
2396 switches::kIPCSyncCompositing);
[email protected]b6eb8e332013-09-10 00:51:012397 // If we raster too fast we become upload bound, and pending
2398 // uploads consume memory. For maximum upload throughput, we would
2399 // want to allow for upload_throughput * pipeline_time of pending
2400 // uploads, after which we are just wasting memory. Since we don't
2401 // know our upload throughput yet, this just caps our memory usage.
boliu853d46052015-10-13 20:20:062402 // Synchronous compositor uses half because synchronous compositor
2403 // pipeline is only one frame deep. But twice of half for low end
2404 // because 16bit texture is not supported.
2405 size_t divider = using_synchronous_compositing ? 2 : 1;
[email protected]35b4f0c2014-06-26 16:55:272406 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032407 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012408 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032409 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012410 // Deadline to draw a frame to achieve 60 frames per second.
2411 const size_t kMillisecondsPerFrame = 16;
2412 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032413 size_t max_transfer_buffer_usage_mb =
2414 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2415 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012416 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2417 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292418 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032419 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012420#endif
jbauman00ca2dc2015-08-10 23:21:152421 if (compositor) {
jbauman5e420d32015-08-05 09:33:012422 limits.command_buffer_size = 64 * 1024;
jbauman00ca2dc2015-08-10 23:21:152423 limits.start_transfer_buffer_size = 64 * 1024;
2424 limits.min_transfer_buffer_size = 64 * 1024;
2425 }
[email protected]96ab016c2013-10-23 00:50:292426
[email protected]96ab016c2013-10-23 00:50:292427 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
piman5d36dae2015-09-24 22:47:052428 new WebGraphicsContext3DCommandBufferImpl(
piman08f75532015-10-05 18:58:012429 0, GetURLForGraphicsContext3D(), gpu_channel_host.get(), attributes,
2430 lose_context_when_out_of_memory, limits, NULL));
[email protected]0634cdd42013-08-16 00:46:092431 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592432}
2433
[email protected]e3244ed2014-06-20 20:04:272434void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2435 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162436}
2437
[email protected]e3244ed2014-06-20 20:04:272438void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2439 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162440}
2441
[email protected]de3c5d82014-05-28 22:12:592442void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2443 render_frames_.AddObserver(frame);
2444}
2445
2446void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2447 render_frames_.RemoveObserver(frame);
2448}
2449
[email protected]a017938b2014-05-27 21:17:172450#if defined(VIDEO_HOLE)
2451void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2452 video_hole_frames_.AddObserver(frame);
2453}
2454
2455void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2456 video_hole_frames_.RemoveObserver(frame);
2457}
2458#endif // defined(VIDEO_HOLE)
2459
[email protected]e9ff79c2012-10-19 21:31:262460} // namespace content