blob: b835799b03b057e2ba8b2df3d3d6e95bb80e9500 [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"
[email protected]0634cdd42013-08-16 00:46:0928#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5929#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2930#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3531#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4432#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1533#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1534#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5035#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2936#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4237#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4038#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5139#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5940#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2941#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1142#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5943#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1144#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2845#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2946#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1347#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3248#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1649#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2750#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0551#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4452#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5553#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:0954#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0455#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1856#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4857#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1858#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3059#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1160#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1862#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3063#include "third_party/WebKit/public/platform/WebSize.h"
64#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4365#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5966#include "third_party/WebKit/public/web/WebFrameWidget.h"
67#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1168#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3169#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3170#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
71#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3872#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5973#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4174#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1375#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5076#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0977#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3278#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4879#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2780#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4181#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4882
[email protected]eeb93112013-05-01 19:41:1083#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1584#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0785#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1086#endif
87
[email protected]661eb9d2009-02-03 02:11:4888#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4989#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5290#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4191#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4892#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4493
[email protected]2255a9332013-06-17 05:12:3194#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2995
[email protected]180ef242013-11-07 06:50:4696using blink::WebCompositionUnderline;
97using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4398using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4699using blink::WebGestureEvent;
100using blink::WebInputEvent;
101using blink::WebKeyboardEvent;
102using blink::WebMouseEvent;
103using blink::WebMouseWheelEvent;
104using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11105using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46106using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11107using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46108using blink::WebPopupType;
109using blink::WebRange;
110using blink::WebRect;
111using blink::WebScreenInfo;
112using blink::WebSize;
113using blink::WebTextDirection;
114using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25115using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46116using blink::WebVector;
117using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26118
[email protected]6a4d7f62013-01-07 21:32:13119namespace {
[email protected]b256eca2013-07-11 10:57:40120
121typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
122
123class TextInputModeMapSingleton {
124 public:
125 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22126 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40127 }
[email protected]dd705d4d2013-11-27 08:14:41128 TextInputModeMapSingleton() {
129 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
130 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
131 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
132 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
133 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
134 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
135 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
136 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
137 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
138 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
139 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40140 }
[email protected]dd705d4d2013-11-27 08:14:41141 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40142 private:
[email protected]dd705d4d2013-11-27 08:14:41143 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40144
olli.raula36aa8be2015-09-10 11:14:22145 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40146
147 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
148};
149
[email protected]dd705d4d2013-11-27 08:14:41150ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40151 static TextInputModeMapSingleton* singleton =
152 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41153 TextInputModeMap::const_iterator it =
154 singleton->map().find(input_mode.utf8());
155 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40156 return ui::TEXT_INPUT_MODE_DEFAULT;
157 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13158}
[email protected]b256eca2013-07-11 10:57:40159
[email protected]fd847792013-10-24 17:12:35160// TODO(brianderson): Replace the hard-coded threshold with a fraction of
161// the BeginMainFrame interval.
162// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
163// be spent in input hanlders before input starts getting throttled.
164const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
165
miletus14a25642015-08-13 19:23:23166int64 GetEventLatencyMicros(double event_timestamp, base::TimeTicks now) {
167 return (now - base::TimeDelta::FromSecondsD(event_timestamp))
jdduke07788062014-12-05 03:16:30168 .ToInternalValue();
169}
170
miletus14a25642015-08-13 19:23:23171void LogInputEventLatencyUmaImpl(WebInputEvent::Type event_type,
172 double event_timestamp,
173 base::TimeTicks now) {
174 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.AggregatedLatency.Renderer2",
175 GetEventLatencyMicros(event_timestamp, now), 1,
176 10000000, 100);
jdduke07788062014-12-05 03:16:30177
miletus14a25642015-08-13 19:23:23178#define CASE_TYPE(t) \
179 case WebInputEvent::t: \
180 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer2." #t, \
181 GetEventLatencyMicros(event_timestamp, now), \
182 1, 10000000, 100); \
183 break;
jdduke07788062014-12-05 03:16:30184
miletus14a25642015-08-13 19:23:23185 switch (event_type) {
jdduke07788062014-12-05 03:16:30186 CASE_TYPE(Undefined);
187 CASE_TYPE(MouseDown);
188 CASE_TYPE(MouseUp);
189 CASE_TYPE(MouseMove);
190 CASE_TYPE(MouseEnter);
191 CASE_TYPE(MouseLeave);
192 CASE_TYPE(ContextMenu);
193 CASE_TYPE(MouseWheel);
194 CASE_TYPE(RawKeyDown);
195 CASE_TYPE(KeyDown);
196 CASE_TYPE(KeyUp);
197 CASE_TYPE(Char);
198 CASE_TYPE(GestureScrollBegin);
199 CASE_TYPE(GestureScrollEnd);
200 CASE_TYPE(GestureScrollUpdate);
201 CASE_TYPE(GestureFlingStart);
202 CASE_TYPE(GestureFlingCancel);
203 CASE_TYPE(GestureShowPress);
204 CASE_TYPE(GestureTap);
205 CASE_TYPE(GestureTapUnconfirmed);
206 CASE_TYPE(GestureTapDown);
207 CASE_TYPE(GestureTapCancel);
208 CASE_TYPE(GestureDoubleTap);
209 CASE_TYPE(GestureTwoFingerTap);
210 CASE_TYPE(GestureLongPress);
211 CASE_TYPE(GestureLongTap);
212 CASE_TYPE(GesturePinchBegin);
213 CASE_TYPE(GesturePinchEnd);
214 CASE_TYPE(GesturePinchUpdate);
215 CASE_TYPE(TouchStart);
216 CASE_TYPE(TouchMove);
217 CASE_TYPE(TouchEnd);
218 CASE_TYPE(TouchCancel);
219 default:
220 // Must include default to let blink::WebInputEvent add new event types
221 // before they're added here.
miletus14a25642015-08-13 19:23:23222 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event_type;
jdduke07788062014-12-05 03:16:30223 break;
224 }
225
226#undef CASE_TYPE
227}
228
miletus14a25642015-08-13 19:23:23229void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now,
230 const ui::LatencyInfo& latency_info) {
231 LogInputEventLatencyUmaImpl(event.type, event.timeStampSeconds, now);
232 for (size_t i = 0; i < latency_info.coalesced_events_size(); i++) {
233 LogInputEventLatencyUmaImpl(
234 event.type,
235 latency_info.timestamps_of_coalesced_events()[i],
236 now);
237 }
238}
239
[email protected]b256eca2013-07-11 10:57:40240} // namespace
241
[email protected]e9ff79c2012-10-19 21:31:26242namespace content {
[email protected]62cb33cae2009-03-27 23:30:22243
[email protected]b2e4c70132013-10-03 02:07:51244// RenderWidget::ScreenMetricsEmulator ----------------------------------------
245
246class RenderWidget::ScreenMetricsEmulator {
247 public:
248 ScreenMetricsEmulator(
249 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43250 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51251 virtual ~ScreenMetricsEmulator();
252
[email protected]19193682014-04-03 15:01:43253 // Scale and offset used to convert between host coordinates
254 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51255 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20256 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43257 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51258 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56259 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51260
261 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43262 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51263
264 // The following methods alter handlers' behavior for messages related to
265 // widget size and position.
266 void OnResizeMessage(const ViewMsg_Resize_Params& params);
267 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
268 const gfx::Rect& window_screen_rect);
269 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31270 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51271
272 private:
[email protected]19193682014-04-03 15:01:43273 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02274 void Apply(bool top_controls_shrink_blink_size,
275 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44276 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12277 bool is_fullscreen_granted,
278 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51279
280 RenderWidget* widget_;
281
[email protected]7f99fc22013-11-08 14:05:58282 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43283 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51284
[email protected]a179d3962013-11-12 14:44:40285 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51286 float scale_;
dgozman9260b0a12015-03-16 13:45:20287 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51288
[email protected]19193682014-04-03 15:01:43289 // Widget rect as passed to webwidget.
290 gfx::Rect applied_widget_rect_;
291
[email protected]b2e4c70132013-10-03 02:07:51292 // Original values to restore back after emulation ends.
293 gfx::Size original_size_;
294 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28295 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46296 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51297 gfx::Rect original_view_screen_rect_;
298 gfx::Rect original_window_screen_rect_;
299};
300
301RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
302 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43303 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51304 : widget_(widget),
[email protected]19193682014-04-03 15:01:43305 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51306 scale_(1.f) {
307 original_size_ = widget_->size_;
308 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28309 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51310 original_screen_info_ = widget_->screen_info_;
311 original_view_screen_rect_ = widget_->view_screen_rect_;
312 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02313 Apply(widget_->top_controls_shrink_blink_size_,
314 widget_->top_controls_height_,
315 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12316 widget_->is_fullscreen_granted_,
317 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51318}
319
320RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
321 widget_->screen_info_ = original_screen_info_;
322
323 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20324 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51325 widget_->view_screen_rect_ = original_view_screen_rect_;
326 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01327 widget_->Resize(original_size_,
328 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02329 widget_->top_controls_shrink_blink_size_,
330 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01331 original_visible_viewport_size_,
332 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12333 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12334 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01335 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51336}
337
338void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43339 const WebDeviceEmulationParams& params) {
340 params_ = params;
341 Reapply();
342}
343
344void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02345 Apply(widget_->top_controls_shrink_blink_size_,
346 widget_->top_controls_height_,
347 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12348 widget_->is_fullscreen_granted_,
349 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51350}
351
[email protected]19193682014-04-03 15:01:43352void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02353 bool top_controls_shrink_blink_size,
354 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44355 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12356 bool is_fullscreen_granted,
357 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31358 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
359 if (!applied_widget_rect_.width())
360 applied_widget_rect_.set_width(original_size_.width());
361 if (!applied_widget_rect_.height())
362 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43363
[email protected]f442ee42014-05-14 11:53:12364 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02365 int original_width = std::max(original_size_.width(), 1);
366 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51367 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02368 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51369 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02370 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51371 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
372 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01373
374 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43375 offset_.set_x(
376 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01377 offset_.set_y(
[email protected]19193682014-04-03 15:01:43378 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51379 } else {
[email protected]0b3578c2014-06-20 18:29:02380 scale_ = params_.scale;
381 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01382 }
[email protected]7f0e8fa2014-03-26 12:32:01383
[email protected]19193682014-04-03 15:01:43384 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
385 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01386 widget_->screen_info_.rect = original_screen_info_.rect;
387 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
388 widget_->window_screen_rect_ = original_window_screen_rect_;
389 } else {
dgozmanf28ccbe2015-06-24 08:50:49390 applied_widget_rect_.set_origin(params_.viewPosition);
391 gfx::Rect screen_rect = applied_widget_rect_;
392 if (!params_.screenSize.isEmpty()) {
393 screen_rect =
394 gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height);
395 }
396 widget_->screen_info_.rect = screen_rect;
397 widget_->screen_info_.availableRect = screen_rect;
[email protected]19193682014-04-03 15:01:43398 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01399 }
[email protected]a179d3962013-11-12 14:44:40400
[email protected]19193682014-04-03 15:01:43401 float applied_device_scale_factor = params_.deviceScaleFactor ?
402 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01403 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51404
[email protected]7f99fc22013-11-08 14:05:58405 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51406 // - we keep the real device scale factor in compositor to produce sharp image
407 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58408 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51409 // root layer.
dgozman9260b0a12015-03-16 13:45:20410 blink::WebDeviceEmulationParams modified_params = params_;
411 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
412 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
413 modified_params.scale = scale_;
414 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51415
[email protected]7f0e8fa2014-03-26 12:32:01416 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43417 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51418
danakjddaec912015-09-25 19:38:40419 gfx::Size physical_backing_size = gfx::ScaleToCeiledSize(
420 original_size_, original_screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02421 widget_->Resize(applied_widget_rect_.size(),
422 physical_backing_size,
423 top_controls_shrink_blink_size,
424 top_controls_height,
425 applied_widget_rect_.size(),
426 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12427 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12428 display_mode,
dtrainorcb7779b82014-12-04 01:08:02429 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51430}
431
432void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
433 const ViewMsg_Resize_Params& params) {
434 bool need_ack = params.new_size != original_size_ &&
435 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
436 original_size_ = params.new_size;
437 original_physical_backing_size_ = params.physical_backing_size;
438 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28439 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02440 Apply(params.top_controls_shrink_blink_size,
441 params.top_controls_height,
442 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12443 params.is_fullscreen_granted,
444 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51445
446 if (need_ack) {
447 widget_->set_next_paint_is_resize_ack();
448 if (widget_->compositor_)
449 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
450 }
451}
452
453void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
454 const gfx::Rect& view_screen_rect,
455 const gfx::Rect& window_screen_rect) {
456 original_view_screen_rect_ = view_screen_rect;
457 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43458 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
459 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51460}
461
462void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
463 ContextMenuParams* params) {
464 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40465 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51466 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40467 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51468}
469
[email protected]2d6836f42014-07-02 17:25:31470gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
471 const gfx::Rect& anchor) {
danakj4606f6332015-08-31 23:56:56472 gfx::Rect scaled = gfx::ScaleToEnclosedRect(anchor, scale_);
[email protected]2d6836f42014-07-02 17:25:31473 scaled.set_x(scaled.x() + offset_.x());
474 scaled.set_y(scaled.y() + offset_.y());
475 return scaled;
476}
477
[email protected]b2e4c70132013-10-03 02:07:51478// RenderWidget ---------------------------------------------------------------
479
dcheng35d31c112015-07-22 00:17:36480RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
481 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46482 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04483 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03484 bool hidden,
485 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29486 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36487 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53488 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29489 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02490 top_controls_shrink_blink_size_(false),
491 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29492 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51493 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09494 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29495 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04496 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39497 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12498 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12499 display_mode_(blink::WebDisplayModeUndefined),
[email protected]5dd768212009-08-13 23:34:49500 handling_input_event_(false),
jddukec05612b2015-06-25 23:13:18501 handling_event_overscroll_(nullptr),
changwanf2a707b2015-10-30 08:22:16502 ime_event_guard_(nullptr),
[email protected]c27dd4f2014-05-22 18:05:19503 handling_event_type_(WebInputEvent::Undefined),
504 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48505 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22506 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44507 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20508 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45509 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40510 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20511 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53512 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12513 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48514 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12515 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04516 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52517 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30518 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13519#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36520 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13521#endif
[email protected]b2e4c70132013-10-03 02:07:51522 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11523 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42524 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51525 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
526 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05527 if (!swapped_out)
528 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27529 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53530 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37531#if defined(OS_ANDROID)
532 text_input_info_history_.push_back(blink::WebTextInputInfo());
533#endif
alexclarke7fa93942015-10-21 15:37:11534
535 // In tests there may not be a RenderThreadImpl.
536 if (RenderThreadImpl::current()) {
537 render_widget_scheduling_state_ = RenderThreadImpl::current()
538 ->GetRendererScheduler()
539 ->NewRenderWidgetSchedulingState()
540 .Pass();
541 render_widget_scheduling_state_->SetHidden(is_hidden_);
542 }
initial.commit09911bf2008-07-26 23:55:29543}
544
545RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11546 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16547
[email protected]992db4c2011-05-12 15:37:15548 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02549 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15550 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29551}
552
[email protected]484955942010-08-19 16:13:18553// static
[email protected]8085dbc82008-09-26 22:53:44554RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53555 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46556 blink::WebPopupType popup_type,
557 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29558 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36559 scoped_refptr<RenderWidget> widget(new RenderWidget(
560 compositor_deps, popup_type, screen_info, false, false, false));
561 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46562 return widget.get();
[email protected]a635f942012-12-07 10:34:29563 }
564 return NULL;
initial.commit09911bf2008-07-26 23:55:29565}
566
[email protected]484955942010-08-19 16:13:18567// static
kenrba7199832015-01-22 23:44:59568RenderWidget* RenderWidget::CreateForFrame(
569 int routing_id,
kenrba7199832015-01-22 23:44:59570 bool hidden,
571 const blink::WebScreenInfo& screen_info,
572 CompositorDependencies* compositor_deps,
573 blink::WebLocalFrame* frame) {
574 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55575 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
576 // same routing ID for both the view routing ID and the main frame widget
577 // routing ID. https://crbug.com/545684
578 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
579 if (view) {
580 view->AttachWebFrameWidget(RenderWidget::CreateWebFrameWidget(view, frame));
581 return view;
582 }
dcheng35d31c112015-07-22 00:17:36583 scoped_refptr<RenderWidget> widget(
584 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
585 false, hidden, false));
kenrba7199832015-01-22 23:44:59586 widget->routing_id_ = routing_id;
simonhong628f9812015-04-27 23:13:20587 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59588 // DoInit increments the reference count on |widget|, keeping it alive after
589 // this function returns.
dcheng35d31c112015-07-22 00:17:36590 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59591 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
592 nullptr)) {
kenrba7199832015-01-22 23:44:59593 return widget.get();
594 }
595 return nullptr;
596}
597
598// static
dchengda9b4bb2015-07-20 20:58:08599blink::WebWidget* RenderWidget::CreateWebFrameWidget(
600 RenderWidget* render_widget,
601 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55602 if (!frame->parent()) {
603 // TODO(dcheng): The main frame widget currently has a special case.
604 // Eliminate this once WebView is no longer a WebWidget.
605 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
606 }
dchengda9b4bb2015-07-20 20:58:08607 return blink::WebFrameWidget::create(render_widget, frame);
608}
609
610// static
kenrba7199832015-01-22 23:44:59611blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18612 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46613 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18614 break;
[email protected]180ef242013-11-07 06:50:46615 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44616 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18617 default:
618 NOTREACHED();
619 }
620 return NULL;
621}
622
dchengda9b4bb2015-07-20 20:58:08623void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32624 OnClose();
kenrba7199832015-01-22 23:44:59625}
626
dcheng35d31c112015-07-22 00:17:36627bool RenderWidget::Init(int32 opener_id) {
piman5d36dae2015-09-24 22:47:05628 return DoInit(
629 opener_id, RenderWidget::CreateWebWidget(this),
630 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
[email protected]484955942010-08-19 16:13:18631}
632
[email protected]a635f942012-12-07 10:34:29633bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06634 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18635 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29636 DCHECK(!webwidget_);
637
638 if (opener_id != MSG_ROUTING_NONE)
639 opener_id_ = opener_id;
640
[email protected]484955942010-08-19 16:13:18641 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29642
kenrba7199832015-01-22 23:44:59643 bool result = true;
644 if (create_widget_message)
645 result = RenderThread::Get()->Send(create_widget_message);
646
initial.commit09911bf2008-07-26 23:55:29647 if (result) {
[email protected]380244092011-10-07 17:26:27648 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29649 // Take a reference on behalf of the RenderThread. This will be balanced
650 // when we receive ViewMsg_Close.
651 AddRef();
[email protected]b2db9272014-01-10 17:42:00652 if (RenderThreadImpl::current()) {
653 RenderThreadImpl::current()->WidgetCreated();
654 if (is_hidden_)
655 RenderThreadImpl::current()->WidgetHidden();
656 }
[email protected]a635f942012-12-07 10:34:29657 return true;
initial.commit09911bf2008-07-26 23:55:29658 } else {
[email protected]a635f942012-12-07 10:34:29659 // The above Send can fail when the tab is closing.
660 return false;
initial.commit09911bf2008-07-26 23:55:29661 }
662}
663
[email protected]992db4c2011-05-12 15:37:15664void RenderWidget::SetSwappedOut(bool is_swapped_out) {
665 // We should only toggle between states.
666 DCHECK(is_swapped_out_ != is_swapped_out);
667 is_swapped_out_ = is_swapped_out;
668
669 // If we are swapping out, we will call ReleaseProcess, allowing the process
670 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52671 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15672 // If we are swapping in, we call AddRefProcess to prevent the process from
673 // exiting.
[email protected]949b6592014-08-20 13:17:52674 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15675 RenderProcess::current()->AddRefProcess();
676}
677
[email protected]949b6592014-08-20 13:17:52678void RenderWidget::WasSwappedOut() {
679 // If we have been swapped out and no one else is using this process,
680 // it's safe to exit now.
681 CHECK(is_swapped_out_);
682 RenderProcess::current()->ReleaseProcess();
683}
684
[email protected]b2e4c70132013-10-03 02:07:51685void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
686 ScreenMetricsEmulator* emulator) {
687 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43688 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49689 popup_screen_origin_for_emulation_ = gfx::Point(
690 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
691 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56692 screen_info_ = emulator->original_screen_info();
693 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51694}
695
[email protected]2d6836f42014-07-02 17:25:31696gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
697 if (screen_metrics_emulator_)
698 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
699 return anchor;
700}
701
[email protected]b2e4c70132013-10-03 02:07:51702void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20703 bool enabled,
704 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51705 // This is only supported in RenderView.
706 NOTREACHED();
707}
708
[email protected]53907862014-03-25 15:42:40709#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51710void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
711 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49712 popup->SetOriginScaleAndOffsetForEmulation(
713 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51714}
[email protected]53907862014-03-25 15:42:40715#endif
[email protected]b2e4c70132013-10-03 02:07:51716
717void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
718 if (screen_metrics_emulator_)
719 screen_metrics_emulator_->OnShowContextMenu(params);
720}
721
[email protected]a95986a82010-12-24 06:19:28722bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
723 bool handled = true;
724 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15725 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22726 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
727 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22728 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
729 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15730 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
731 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35732 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
733 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28734 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28735 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20736 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
737 OnEnableDeviceEmulation)
738 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
739 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41740 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54741 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28742 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41743 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25744 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28745 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
746 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03747 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05748 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21749#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37750 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
[email protected]2384b6c2013-02-28 23:58:51751 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21752#endif
[email protected]a95986a82010-12-24 06:19:28753 IPC_MESSAGE_UNHANDLED(handled = false)
754 IPC_END_MESSAGE_MAP()
755 return handled;
756}
initial.commit09911bf2008-07-26 23:55:29757
758bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15759 // Don't send any messages after the browser has told us to close, and filter
760 // most outgoing messages while swapped out.
761 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26762 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11763 closing_) {
initial.commit09911bf2008-07-26 23:55:29764 delete message;
765 return false;
766 }
767
768 // If given a messsage without a routing ID, then assign our routing ID.
769 if (message->routing_id() == MSG_ROUTING_NONE)
770 message->set_routing_id(routing_id_);
771
[email protected]380244092011-10-07 17:26:27772 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44773}
774
[email protected]61e2b3cc2012-03-02 16:13:34775void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44776 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02777 bool top_controls_shrink_blink_size,
778 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44779 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34780 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12781 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12782 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58783 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56784 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48785 // A resize ack shouldn't be requested if we have not ACK'd the previous
786 // one.
787 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
788 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
789 }
initial.commit09911bf2008-07-26 23:55:29790
[email protected]61e2b3cc2012-03-02 16:13:34791 // Ignore this during shutdown.
792 if (!webwidget_)
793 return;
794
[email protected]d9083762013-03-24 01:36:40795 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44796 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40797 }
[email protected]60d47ac2013-03-01 23:42:44798
[email protected]dade8992013-03-04 07:34:34799 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02800 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
801 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28802 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34803 resizer_rect_ = resizer_rect;
804
805 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12806 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12807 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12808 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34809
aelias6004fe02015-02-07 21:43:01810 webwidget_->setTopControlsHeight(top_controls_height,
811 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43812
[email protected]61e2b3cc2012-03-02 16:13:34813 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34814 size_ = new_size;
815
[email protected]61e2b3cc2012-03-02 16:13:34816 // When resizing, we want to wait to paint before ACK'ing the resize. This
817 // ensures that we only resize as fast as we can paint. We only need to
818 // send an ACK if we are resized to a non-empty rect.
819 webwidget_->resize(new_size);
[email protected]632c4382013-05-15 08:58:45820 }
821
[email protected]bb6378fe2014-04-28 21:19:44822 webwidget()->resizePinchViewport(gfx::Size(
823 visible_viewport_size.width(),
824 visible_viewport_size.height()));
825
[email protected]632c4382013-05-15 08:58:45826 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58827 // In this case there is no paint/composite and therefore no
828 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
829 // ack through a fake ViewHostMsg_UpdateRect or a different message.
830 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34831 }
832
[email protected]20fbfc22013-05-08 20:50:58833 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45834 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58835 set_next_paint_is_resize_ack();
836
[email protected]61e2b3cc2012-03-02 16:13:34837 if (fullscreen_change)
838 DidToggleFullscreen();
839
840 // If a resize ack is requested and it isn't set-up, then no more resizes will
841 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45842 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29843}
844
bokanc007c3a2015-02-03 07:15:56845void RenderWidget::SetWindowRectSynchronously(
846 const gfx::Rect& new_window_rect) {
847 Resize(new_window_rect.size(),
848 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02849 top_controls_shrink_blink_size_,
850 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56851 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01852 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12853 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12854 display_mode_,
[email protected]587941d2014-08-22 01:40:01855 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56856 view_screen_rect_ = new_window_rect;
857 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02858 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56859 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02860}
861
initial.commit09911bf2008-07-26 23:55:29862void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32863 DCHECK(content::RenderThread::Get());
864 if (closing_)
865 return;
866 NotifyOnClose();
867 closing_ = true;
868
869 // Browser correspondence is no longer needed at this point.
870 if (routing_id_ != MSG_ROUTING_NONE) {
871 RenderThread::Get()->RemoveRoute(routing_id_);
872 SetHidden(false);
873 if (RenderThreadImpl::current())
874 RenderThreadImpl::current()->WidgetDestroyed();
875 }
876
877 if (for_oopif_) {
878 // Widgets for frames may be created and closed at any time while the frame
879 // is alive. However, the closing process must happen synchronously. Frame
880 // widget and frames hold pointers to each other. If Close() is deferred to
881 // the message loop like in the non-frame widget case, WebWidget::close()
882 // can end up accessing members of an already-deleted frame.
883 Close();
884 } else {
885 // If there is a Send call on the stack, then it could be dangerous to close
886 // now. Post a task that only gets invoked when there are no nested message
887 // loops.
888 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
889 FROM_HERE, base::Bind(&RenderWidget::Close, this));
890 }
891
892 // Balances the AddRef taken when we called AddRoute.
893 Release();
initial.commit09911bf2008-07-26 23:55:29894}
895
[email protected]0fdd5012013-05-29 08:05:56896void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04897 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32898 return;
899
[email protected]b2e4c70132013-10-03 02:07:51900 if (screen_metrics_emulator_) {
901 screen_metrics_emulator_->OnResizeMessage(params);
902 return;
903 }
904
[email protected]fcdc5642014-05-09 14:32:24905 bool orientation_changed =
906 screen_info_.orientationAngle != params.screen_info.orientationAngle;
907
[email protected]0fdd5012013-05-29 08:05:56908 screen_info_ = params.screen_info;
909 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02910 Resize(params.new_size,
911 params.physical_backing_size,
912 params.top_controls_shrink_blink_size,
913 params.top_controls_height,
914 params.visible_viewport_size,
915 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12916 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12917 params.display_mode,
sievers4e33dae2015-02-25 20:43:58918 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24919
920 if (orientation_changed)
921 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29922}
923
dgozman9260b0a12015-03-16 13:45:20924void RenderWidget::OnEnableDeviceEmulation(
925 const blink::WebDeviceEmulationParams& params) {
926 if (!screen_metrics_emulator_)
927 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
928 else
929 screen_metrics_emulator_->ChangeEmulationParams(params);
930}
931
932void RenderWidget::OnDisableDeviceEmulation() {
933 screen_metrics_emulator_.reset();
934}
935
noel89949e62014-09-30 01:12:41936void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
937 SetDeviceColorProfile(color_profile);
938}
939
[email protected]b5913d72012-02-07 22:26:54940void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01941 if (resizer_rect_ == resizer_rect)
942 return;
943 resizer_rect_ = resizer_rect;
944 if (webwidget_)
945 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54946}
947
initial.commit09911bf2008-07-26 23:55:29948void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31949 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29950 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03951 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59952 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
953 WasHidden());
initial.commit09911bf2008-07-26 23:55:29954}
955
[email protected]3399dd822014-08-09 11:14:24956void RenderWidget::OnWasShown(bool needs_repainting,
957 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41958 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29959 // During shutdown we can just ignore this message.
960 if (!webwidget_)
961 return;
962
963 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03964 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59965 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
966 WasShown());
initial.commit09911bf2008-07-26 23:55:29967
[email protected]8a23afb32014-04-30 22:40:23968 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29969 return;
initial.commit09911bf2008-07-26 23:55:29970
971 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24972 if (compositor_) {
973 ui::LatencyInfo swap_latency_info(latency_info);
974 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
975 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05976 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24977 }
jdduke491a3f0c2015-06-15 23:30:26978 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29979}
980
[email protected]53d3f302009-12-21 04:42:05981void RenderWidget::OnRequestMoveAck() {
982 DCHECK(pending_window_rect_count_);
983 pending_window_rect_count_--;
984}
985
[email protected]ed7defa2013-03-12 21:29:59986GURL RenderWidget::GetURLForGraphicsContext3D() {
987 return GURL();
[email protected]65225772011-05-12 21:10:24988}
989
[email protected]ebc0e1df2013-08-01 02:46:22990scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03991 // For widgets that are never visible, we don't start the compositor, so we
992 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39993 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:19994
avi83883c82014-12-23 00:08:49995 const base::CommandLine& command_line =
996 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33997 bool use_software = fallback;
998 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
999 use_software = true;
1000
[email protected]0634cdd42013-08-16 00:46:091001 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:171002 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:331003 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:091004 context_provider = ContextProviderCommandBuffer::Create(
jbauman5e420d32015-08-05 09:33:011005 CreateGraphicsContext3D(true), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:331006 if (!context_provider.get()) {
1007 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:341008 return nullptr;
[email protected]e09994a2014-03-26 19:59:331009 }
revemand180dfc32015-09-24 00:19:431010 worker_context_provider =
1011 RenderThreadImpl::current()->SharedWorkerContextProvider();
1012 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:171013 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:341014 return nullptr;
vmiura78b69282015-02-14 00:01:171015 }
boliu853d46052015-10-13 20:20:061016
1017#if defined(OS_ANDROID)
1018 if (SynchronousCompositorFactory* factory =
1019 SynchronousCompositorFactory::GetInstance()) {
1020 return factory->CreateOutputSurface(
1021 routing_id(), frame_swap_message_queue_, context_provider,
1022 worker_context_provider);
1023 }
1024#endif
[email protected]0634cdd42013-08-16 00:46:091025 }
[email protected]ebc0e1df2013-08-01 02:46:221026
[email protected]b6eb8e332013-09-10 00:51:011027 uint32 output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:341028 // Composite-to-mailbox is currently used for layout tests in order to cause
1029 // them to draw inside in the renderer to do the readback there. This should
1030 // no longer be the case when crbug.com/311404 is fixed.
1031 if (!RenderThreadImpl::current() ||
1032 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:531033 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
piman8944e1c2015-09-22 21:10:341034 return make_scoped_ptr(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171035 routing_id(), output_surface_id, context_provider,
1036 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091037 }
piman8944e1c2015-09-22 21:10:341038
[email protected]0634cdd42013-08-16 00:46:091039 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091040 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121041 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091042
piman8944e1c2015-09-22 21:10:341043 return make_scoped_ptr(new CompositorOutputSurface(
caseqff9c74c2015-02-10 14:56:291044 routing_id(), output_surface_id, nullptr, nullptr,
1045 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221046 }
[email protected]ed7defa2013-03-12 21:29:591047
piman8944e1c2015-09-22 21:10:341048 return make_scoped_ptr(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171049 routing_id(), output_surface_id, context_provider,
piman8944e1c2015-09-22 21:10:341050 worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:281051}
1052
[email protected]4d7e46a2013-11-08 05:33:401053void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241054 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241055 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:261056 ScheduleComposite();
[email protected]65225772011-05-12 21:10:241057}
1058
[email protected]4d7e46a2013-11-08 05:33:401059void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081060 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081061}
1062
[email protected]4d7e46a2013-11-08 05:33:401063void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241064 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161065
[email protected]404939f2012-06-01 04:06:181066 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161067 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291068}
1069
[email protected]180ef242013-11-07 06:50:461070void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
jdduke0cf1e662015-10-15 22:43:281071 const ui::LatencyInfo& latency_info) {
[email protected]c27dd4f2014-05-22 18:05:191072 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291073 return;
jddukec05612b2015-06-25 23:13:181074 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_,
1075 true);
[email protected]c27dd4f2014-05-22 18:05:191076 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1077 &handling_event_type_, input_event->type);
jddukec05612b2015-06-25 23:13:181078
1079 // Calls into |didOverscroll()| while handling this event will populate
1080 // |event_overscroll|, which in turn will be bundled with the event ack.
1081 scoped_ptr<DidOverscrollParams> event_overscroll;
1082 base::AutoReset<scoped_ptr<DidOverscrollParams>*>
1083 handling_event_overscroll_resetter(&handling_event_overscroll_,
1084 &event_overscroll);
1085
[email protected]25402eb2014-07-18 03:09:521086#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161087 const bool is_keyboard_event =
1088 WebInputEvent::isKeyboardEventType(input_event->type);
1089
1090 // For non-keyboard events, we want the change source to be FROM_NON_IME.
1091 ImeEventGuard guard(this, false, is_keyboard_event);
[email protected]25402eb2014-07-18 03:09:521092#endif
initial.commit09911bf2008-07-26 23:55:291093
[email protected]fd847792013-10-24 17:12:351094 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411095 if (base::TimeTicks::IsHighResolution())
1096 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351097
miletusfed8c43b2015-01-26 20:04:521098 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301099 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151100 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
yuhaoz8df9334c2015-08-18 17:48:511101 TRACE_EVENT_WITH_FLOW1("input,benchmark",
1102 "LatencyInfo.Flow",
1103 TRACE_ID_DONT_MANGLE(latency_info.trace_id()),
1104 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
1105 "step", "HandleInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101106
jdduke07788062014-12-05 03:16:301107 // If we don't have a high res timer, these metrics won't be accurate enough
1108 // to be worth collecting. Note that this does introduce some sampling bias.
1109 if (!start_time.is_null())
miletus14a25642015-08-13 19:23:231110 LogInputEventLatencyUma(*input_event, start_time, latency_info);
jdduke07788062014-12-05 03:16:301111
[email protected]6be422b2013-12-08 06:47:311112 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351113 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311114 if (compositor_) {
1115 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351116 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1117 .Pass();
[email protected]6be422b2013-12-08 06:47:311118 }
[email protected]c2eaa8f2013-05-10 02:41:551119
[email protected]67bfb83f2011-09-22 03:36:371120 bool prevent_default = false;
1121 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261122 const WebMouseEvent& mouse_event =
1123 *static_cast<const WebMouseEvent*>(input_event);
1124 TRACE_EVENT2("renderer", "HandleMouseMove",
1125 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421126 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261127 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371128 }
1129
[email protected]cefe9b152014-03-27 18:16:151130 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421131 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151132#if defined(OS_ANDROID)
1133 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1134 // case it should behave like a select key (i.e. causing a click if a button
1135 // is focused). However, if a text field is focused (2), its intended
1136 // behavior is to just show the IME and don't propagate the key.
1137 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1138 // when clicked on an input text field and cause the form submit if clicked
1139 // when the submit button is focused, but not vice-versa.
1140 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1141 // but at this point we have to swallow the event for the scenario (2).
1142 const WebKeyboardEvent& key_event =
1143 *static_cast<const WebKeyboardEvent*>(input_event);
1144 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1145 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1146 OnShowImeIfNeeded();
1147 prevent_default = true;
1148 }
1149#endif
1150 }
[email protected]f56c7872013-06-18 12:31:571151
[email protected]41d86852012-11-07 12:23:241152 if (WebInputEvent::isGestureEventType(input_event->type)) {
1153 const WebGestureEvent& gesture_event =
1154 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421155 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241156 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1157 }
1158
[email protected]67bfb83f2011-09-22 03:36:371159 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121160 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1161 suppress_next_char_events_ = false;
1162 if (!processed && webwidget_)
1163 processed = webwidget_->handleInputEvent(*input_event);
1164 }
1165
1166 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1167 // it's not processed by webkit, then we need to suppress the upcoming Char
1168 // events.
jdduke0cf1e662015-10-15 22:43:281169 bool is_keyboard_shortcut =
1170 input_event->type == WebInputEvent::RawKeyDown &&
1171 static_cast<const WebKeyboardEvent*>(input_event)->isBrowserShortcut;
[email protected]b68a0e52011-12-08 15:11:121172 if (!processed && is_keyboard_shortcut)
1173 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291174
[email protected]3d5c243b2012-11-30 00:26:011175 InputEventAckState ack_result = processed ?
1176 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1177 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1178 const WebTouchEvent& touch_event =
1179 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251180 // Hit-test for all the pressed touch points. If there is a touch-handler
1181 // for any of the touch points, then the renderer should continue to receive
1182 // touch events.
1183 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1184 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1185 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271186 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391187 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251188 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1189 break;
1190 }
1191 }
[email protected]3d5c243b2012-11-30 00:26:011192 }
1193
ccamerond4ba47902014-12-17 07:20:311194 // Send mouse wheel events and their disposition to the compositor thread, so
1195 // that they can be used to produce the elastic overscroll effect on Mac.
1196 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311197 ObserveWheelEventAndResult(
sataya.mf405d0e2015-07-07 16:51:111198 static_cast<const WebMouseWheelEvent&>(*input_event),
1199 event_overscroll ? event_overscroll->latest_overscroll_delta
1200 : gfx::Vector2dF(),
1201 processed);
ccamerond4ba47902014-12-17 07:20:311202 }
1203
[email protected]721e2302014-04-30 23:42:011204 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061205
charliea3be839702015-01-26 17:35:411206 // If we don't have a fast and accurate Now(), we assume the input handlers
1207 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301208 bool rate_limiting_wanted =
1209 input_event->type == WebInputEvent::MouseMove ||
1210 input_event->type == WebInputEvent::MouseWheel;
1211 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411212 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351213 total_input_handling_time_this_frame_ += (end_time - start_time);
1214 rate_limiting_wanted =
1215 total_input_handling_time_this_frame_.InMicroseconds() >
1216 kInputHandlingTimeThrottlingThresholdMicroseconds;
1217 }
1218
[email protected]7f19e9d2014-05-09 15:16:291219 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1220
[email protected]c27dd4f2014-05-22 18:05:191221 // Note that we can't use handling_event_type_ here since it will be overriden
1222 // by reentrant calls for events after the paused one.
1223 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1224 input_event->type == WebInputEvent::MouseMove;
lanweif1a22832015-05-19 17:24:101225 if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) &&
1226 !no_ack) {
1227 InputEventAck ack(input_event->type, ack_result, swap_latency_info,
jddukec05612b2015-06-25 23:13:181228 event_overscroll.Pass(),
lanweif1a22832015-05-19 17:24:101229 WebInputEventTraits::GetUniqueTouchEventId(*input_event));
[email protected]34afe102013-12-13 17:24:551230 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561231 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301232 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551233 // We want to rate limit the input events in this case, so we'll wait for
1234 // painting to finish before ACKing this message.
1235 TRACE_EVENT_INSTANT0("renderer",
1236 "RenderWidget::OnHandleInputEvent ack throttled",
1237 TRACE_EVENT_SCOPE_THREAD);
1238 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291239 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1240 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551241 // As two different kinds of events could cause us to postpone an ack
1242 // we send it now, if we have one pending. The Browser should never
1243 // send us the same kind of event we are delaying the ack for.
1244 Send(pending_input_event_ack_.release());
1245 }
1246 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291247 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1248 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551249 if (compositor_)
1250 compositor_->NotifyInputThrottledUntilCommit();
1251 } else {
1252 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171253 }
jddukec05612b2015-06-25 23:13:181254 } else {
1255 DCHECK(!event_overscroll) << "Unexpected overscroll for un-acked event";
[email protected]12fbad812009-09-01 18:21:241256 }
alexclarke7819e2552015-06-03 11:17:211257 if (!no_ack && RenderThreadImpl::current()) {
1258 RenderThreadImpl::current()
1259 ->GetRendererScheduler()
1260 ->DidHandleInputEventOnMainThread(*input_event);
1261 }
[email protected]5fea4a52014-05-27 00:17:521262 if (input_event->type == WebInputEvent::MouseMove)
1263 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241264
[email protected]3306f262012-09-21 19:20:421265#if defined(OS_ANDROID)
1266 // Allow the IME to be shown when the focus changes as a consequence
1267 // of a processed touch end event.
1268 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361269 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021270#elif defined(USE_AURA)
1271 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1272 // change.
1273 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141274 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361275 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141276 }
[email protected]3306f262012-09-21 19:20:421277#endif
1278
[email protected]67bfb83f2011-09-22 03:36:371279 if (!prevent_default) {
1280 if (WebInputEvent::isKeyboardEventType(input_event->type))
1281 DidHandleKeyEvent();
[email protected]67bfb83f2011-09-22 03:36:371282 }
rouslanf7ebd8832015-01-22 01:54:141283
1284// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1285// virtual keyboard.
1286#if !defined(OS_ANDROID)
1287 // Virtual keyboard is not supported, so react to focus change immediately.
1288 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1289 input_event->type == WebInputEvent::MouseUp)) {
1290 FocusChangeComplete();
1291 }
1292#endif
initial.commit09911bf2008-07-26 23:55:291293}
1294
[email protected]34202de2013-05-06 23:36:221295void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1296 if (webwidget_)
1297 webwidget_->setCursorVisibilityState(is_visible);
1298}
1299
initial.commit09911bf2008-07-26 23:55:291300void RenderWidget::OnMouseCaptureLost() {
1301 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281302 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291303}
1304
1305void RenderWidget::OnSetFocus(bool enable) {
[email protected]9d166af2010-03-02 22:04:331306 if (webwidget_)
1307 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291308}
1309
[email protected]fd847792013-10-24 17:12:351310void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291311 if (pending_input_event_ack_) {
1312 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1313 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071314 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291315 }
[email protected]fd847792013-10-24 17:12:351316 total_input_handling_time_this_frame_ = base::TimeDelta();
1317}
1318
initial.commit09911bf2008-07-26 23:55:291319///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461320// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291321
[email protected]244ac1892011-12-02 17:04:471322void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091323 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451324 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581325
[email protected]5b45ad42013-10-25 00:42:041326 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451327 WebRect new_pos(rootWindowRect().x,
1328 rootWindowRect().y,
1329 new_size.width,
1330 new_size.height);
1331 view_screen_rect_ = new_pos;
1332 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031333 }
[email protected]20fbfc22013-05-08 20:50:581334
[email protected]eac2b362013-05-22 07:01:451335 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581336
[email protected]5b45ad42013-10-25 00:42:041337 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581338 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091339 }
[email protected]244ac1892011-12-02 17:04:471340}
1341
[email protected]3a1c8a8032013-03-18 22:35:321342void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401343 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051344 if (compositor_)
1345 compositor_->setViewportSize(size_, physical_backing_size_);
1346}
1347
[email protected]e195e582013-03-08 01:32:591348void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221349 DCHECK(!host_closing_);
1350
danakj6e3bf8012014-12-16 18:27:531351 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591352 compositor_->setViewportSize(size_, physical_backing_size_);
sievers71c62dd52015-10-07 01:44:391353
1354 // For background pages and certain tests, we don't want to trigger
1355 // OutputSurface creation.
1356 if (compositor_never_visible_ || !RenderThreadImpl::current())
1357 compositor_->SetNeverVisible();
1358
pimanc4af3072015-10-02 03:45:591359 StartCompositor();
[email protected]e195e582013-03-08 01:32:591360}
1361
ennef3c58142014-12-09 21:44:381362void RenderWidget::WillCloseLayerTreeView() {
1363 if (host_closing_)
1364 return;
1365
1366 // Prevent new compositors or output surfaces from being created.
1367 host_closing_ = true;
1368
[email protected]aeeedad2014-08-22 18:16:221369 // Always send this notification to prevent new layer tree views from
1370 // being created, even if one hasn't been created yet.
1371 if (webwidget_)
1372 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221373}
1374
[email protected]180ef242013-11-07 06:50:461375blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281376 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061377}
1378
dglazkovf0e1d6d2015-10-10 02:13:481379void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1380 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1381 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1382 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1383 }
dglazkov79c426102015-08-31 21:22:431384
dglazkovf0e1d6d2015-10-10 02:13:481385 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1386 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431387}
1388
jdduke491a3f0c2015-06-15 23:30:261389void RenderWidget::WillBeginCompositorFrame() {
[email protected]9cd43a62012-03-26 08:03:561390 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371391
shuchen913f8b622015-07-31 13:22:431392 // The UpdateTextInputState can result in further layout and possibly
[email protected]abe8b3a2012-03-28 21:19:371393 // enable GPU acceleration so they need to be called before any painting
1394 // is done.
[email protected]90f24152014-04-09 12:41:361395 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
[email protected]abe8b3a2012-03-28 21:19:371396 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561397}
1398
[email protected]6fceb912013-02-15 06:24:151399void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441400 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1401 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271402 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161403 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171404#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271405 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1406 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171407#endif // defined(VIDEO_HOLE)
jdduke491a3f0c2015-06-15 23:30:261408 FlushPendingInputEventAck();
1409}
1410
1411void RenderWidget::DidCommitAndDrawCompositorFrame() {
1412 // NOTE: Tests may break if this event is renamed or moved. See
1413 // tab_capture_performancetest.cc.
1414 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
1415 // Notify subclasses that we initiated the paint operation.
1416 DidInitiatePaint();
1417}
1418
1419void RenderWidget::DidCompleteSwapBuffers() {
1420 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
1421
1422 // Notify subclasses threaded composited rendering was flushed to the screen.
1423 DidFlushPaint();
1424
1425 if (!next_paint_flags_ &&
1426 !need_update_rect_for_auto_resize_ &&
1427 !plugin_window_moves_.size()) {
1428 return;
1429 }
1430
1431 ViewHostMsg_UpdateRect_Params params;
1432 params.view_size = size_;
1433 params.plugin_window_moves.swap(plugin_window_moves_);
1434 params.flags = next_paint_flags_;
1435
1436 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1437 next_paint_flags_ = 0;
1438 need_update_rect_for_auto_resize_ = false;
1439}
1440
1441void RenderWidget::ScheduleComposite() {
1442 if (compositor_ &&
1443 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1444 compositor_->setNeedsAnimate();
1445 }
1446}
1447
1448void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1449 if (compositor_) {
1450 // Regardless of whether threaded compositing is enabled, always
1451 // use this mechanism to force the compositor to redraw. However,
1452 // the invalidation code path below is still needed for the
1453 // non-threaded case.
1454 compositor_->SetNeedsForcedRedraw();
1455 }
1456 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151457}
1458
[email protected]586871b2014-07-22 17:05:111459// static
1460scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1461 IPC::Message* msg,
1462 MessageDeliveryPolicy policy,
1463 FrameSwapMessageQueue* frame_swap_message_queue,
1464 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111465 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111466 bool first_message_for_frame = false;
1467 frame_swap_message_queue->QueueMessageForFrame(policy,
1468 source_frame_number,
1469 make_scoped_ptr(msg),
1470 &first_message_for_frame);
1471 if (first_message_for_frame) {
1472 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1473 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061474 return promise;
[email protected]586871b2014-07-22 17:05:111475 }
dcheng4b6b5ff2014-10-16 00:42:061476 return nullptr;
[email protected]586871b2014-07-22 17:05:111477}
1478
1479void RenderWidget::QueueMessage(IPC::Message* msg,
1480 MessageDeliveryPolicy policy) {
1481 // RenderThreadImpl::current() is NULL in some tests.
1482 if (!compositor_ || !RenderThreadImpl::current()) {
1483 Send(msg);
1484 return;
1485 }
1486
1487 scoped_ptr<cc::SwapPromise> swap_promise =
1488 QueueMessageImpl(msg,
1489 policy,
dcheng58867a92014-08-26 02:50:221490 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111491 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111492 compositor_->GetSourceFrameNumber());
1493
1494 if (swap_promise) {
1495 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351496 // Request a commit. This might either A) request a commit ahead of time
1497 // or B) request a commit which is not needed because there are not
1498 // pending updates. If B) then the commit will be skipped and the swap
1499 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1500 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1501 // can_cancel_commit is not unset.
1502 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111503 }
1504}
1505
[email protected]4873c7d2009-07-16 06:36:281506void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301507 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521508 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181509 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291510 // Only send a SetCursor message if we need to make a change.
1511 if (!current_cursor_.IsEqual(cursor)) {
1512 current_cursor_ = cursor;
1513 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1514 }
1515}
1516
1517// We are supposed to get a single call to Show for a newly created RenderWidget
1518// that was created via RenderWidget::CreateWebView. So, we wait until this
1519// point to dispatch the ShowWidget message.
1520//
1521// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281522// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291523//
[email protected]4873c7d2009-07-16 06:36:281524void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291525 DCHECK(!did_show_) << "received extraneous Show call";
1526 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1527 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1528
[email protected]8de12d942010-11-17 20:42:441529 if (did_show_)
1530 return;
1531
1532 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561533 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441534 // that's okay. It'll be ignored if as_popup is false, or the browser
1535 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561536 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1537 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291538}
1539
[email protected]4873c7d2009-07-16 06:36:281540void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291541}
1542
[email protected]2533ce12009-05-09 00:02:241543void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381544 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241545 Send(new ViewHostMsg_Close(routing_id_));
1546}
1547
dgozmancf9039cd2015-04-06 12:01:311548void RenderWidget::NotifyOnClose() {
1549 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1550}
1551
[email protected]4873c7d2009-07-16 06:36:281552void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081553 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321554 if (is_swapped_out_) {
1555 // This widget is currently swapped out, and the active widget is in a
1556 // different process. Have the browser route the close request to the
1557 // active widget instead, so that the correct unload handlers are run.
1558 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1559 return;
1560 }
1561
initial.commit09911bf2008-07-26 23:55:291562 // If a page calls window.close() twice, we'll end up here twice, but that's
1563 // OK. It is safe to send multiple Close messages.
1564
[email protected]2533ce12009-05-09 00:02:241565 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1566 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1567 // could be closed before the JS finishes executing. So instead, post a
1568 // message back to the message loop, which won't run until the JS is
1569 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081570 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211571 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291572}
1573
[email protected]9017d7852013-11-21 17:47:351574void RenderWidget::QueueSyntheticGesture(
1575 scoped_ptr<SyntheticGestureParams> gesture_params,
1576 const SyntheticGestureCompletionCallback& callback) {
1577 DCHECK(!callback.is_null());
1578
1579 pending_synthetic_gesture_callbacks_.push(callback);
1580
1581 SyntheticGesturePacket gesture_packet;
1582 gesture_packet.set_gesture_params(gesture_params.Pass());
1583
1584 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1585}
1586
initial.commit09911bf2008-07-26 23:55:291587void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031588 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381589 WillCloseLayerTreeView();
1590 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291591 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281592 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291593 webwidget_ = NULL;
1594 }
1595}
1596
[email protected]4873c7d2009-07-16 06:36:281597WebRect RenderWidget::windowRect() {
1598 if (pending_window_rect_count_)
1599 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241600
[email protected]80ad8622012-11-07 16:33:031601 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291602}
1603
[email protected]180ef242013-11-07 06:50:461604void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301605 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541606 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301607}
1608
[email protected]b2e4c70132013-10-03 02:07:511609void RenderWidget::setWindowRect(const WebRect& rect) {
bokanc007c3a2015-02-03 07:15:561610 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511611 if (popup_origin_scale_for_emulation_) {
1612 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561613 window_rect.x = popup_screen_origin_for_emulation_.x() +
1614 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1615 window_rect.y = popup_screen_origin_for_emulation_.y() +
1616 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511617 }
1618
[email protected]5b45ad42013-10-25 00:42:041619 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201620 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561621 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1622 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031623 } else {
bokanc007c3a2015-02-03 07:15:561624 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031625 }
initial.commit09911bf2008-07-26 23:55:291626 } else {
bokanc007c3a2015-02-03 07:15:561627 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291628 }
1629}
1630
[email protected]2533ce12009-05-09 00:02:241631void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1632 pending_window_rect_ = rect;
1633 pending_window_rect_count_++;
1634}
1635
[email protected]4873c7d2009-07-16 06:36:281636WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241637 if (pending_window_rect_count_) {
1638 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1639 // the RootWindowRect is probably going to return wrong results since the
1640 // browser may not have processed the Move yet. There isn't really anything
1641 // good to do in this case, and it shouldn't happen - since this size is
1642 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281643 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241644 }
1645
[email protected]80ad8622012-11-07 16:33:031646 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371647}
1648
[email protected]4873c7d2009-07-16 06:36:281649WebRect RenderWidget::windowResizerRect() {
1650 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191651}
1652
[email protected]fa7b1dc2010-06-23 17:53:041653void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261654 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041655 const std::vector<WebCompositionUnderline>& underlines,
1656 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131657 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281658 return;
[email protected]66fca5bc2013-05-23 06:58:291659 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361660 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041661 text, WebVector<WebCompositionUnderline>(underlines),
1662 selection_start, selection_end)) {
1663 // If we failed to set the composition text, then we need to let the browser
1664 // process to cancel the input method's ongoing composition session, to make
1665 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221666 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261667 }
[email protected]88dbe32f2013-06-20 23:31:361668 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041669}
1670
[email protected]fcf75d42013-12-03 20:11:261671void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511672 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021673 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131674 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041675 return;
[email protected]66fca5bc2013-05-23 06:58:291676 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041677 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021678 if (text.length())
1679 webwidget_->confirmComposition(text);
1680 else if (keep_selection)
1681 webwidget_->confirmComposition(WebWidget::KeepSelection);
1682 else
1683 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041684 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361685 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291686}
1687
[email protected]0bc1f572013-04-17 01:46:311688void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121689 // During shutdown we can just ignore this message.
1690 if (!webwidget_)
1691 return;
1692
[email protected]0bc1f572013-04-17 01:46:311693 // Even if the browser provides an empty damage rect, it's still expecting to
1694 // receive a repaint ack so just damage the entire widget bounds.
1695 if (size_to_paint.IsEmpty()) {
1696 size_to_paint = size_;
1697 }
1698
[email protected]ec7dc112008-08-06 05:30:121699 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051700 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311701 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121702}
1703
[email protected]79fa22e2013-08-23 15:18:121704void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351705 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1706
1707 pending_synthetic_gesture_callbacks_.front().Run();
1708 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271709}
1710
[email protected]4873c7d2009-07-16 06:36:281711void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111712 if (!webwidget_)
1713 return;
[email protected]4873c7d2009-07-16 06:36:281714 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111715}
1716
[email protected]80ad8622012-11-07 16:33:031717void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1718 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511719 if (screen_metrics_emulator_) {
1720 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1721 view_screen_rect, window_screen_rect);
1722 } else {
1723 view_screen_rect_ = view_screen_rect;
1724 window_screen_rect_ = window_screen_rect;
1725 }
[email protected]80ad8622012-11-07 16:33:031726 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1727}
1728
kenrbb4e2a3b2015-05-14 15:05:051729void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1730 if (compositor_)
1731 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1732}
1733
[email protected]adb362312014-06-28 06:04:241734void RenderWidget::showImeIfNeeded() {
1735 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131736}
1737
[email protected]adb362312014-06-28 06:04:241738void RenderWidget::OnShowImeIfNeeded() {
1739#if defined(OS_ANDROID) || defined(USE_AURA)
1740 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1741#endif
rouslanf7ebd8832015-01-22 01:54:141742
1743// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1744// virtual keyboard.
1745#if !defined(OS_ANDROID)
1746 FocusChangeComplete();
1747#endif
[email protected]adb362312014-06-28 06:04:241748}
1749
1750#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371751void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1752 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131753}
1754
1755void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371756 DCHECK_GE(text_input_info_history_.size(), 1u);
1757 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511758}
[email protected]105dffb42013-02-20 03:46:211759#endif
1760
[email protected]0d1ebed12013-08-05 22:01:131761bool RenderWidget::ShouldHandleImeEvent() {
1762#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371763 if (!webwidget_)
1764 return false;
1765
1766 // We cannot handle IME events if there is any chance that the event we are
1767 // receiving here from the browser is based on the state that is different
1768 // from our current one as indicated by |text_input_info_|.
1769 // The states the browser might be in are:
1770 // text_input_info_history_[0] - current state ack'd by browser
1771 // text_input_info_history_[1...N] - pending state changes
1772 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1773 if (text_input_info_history_[i] != text_input_info_)
1774 return false;
1775 }
1776 return true;
[email protected]0d1ebed12013-08-05 22:01:131777#else
1778 return !!webwidget_;
1779#endif
1780}
1781
[email protected]c27dd4f2014-05-22 18:05:191782bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1783 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521784 // If we pause multiple times during a single mouse move event, we should
1785 // only send ACK once.
1786 if (!ignore_ack_for_mouse_move_from_debugger_) {
lanweif1a22832015-05-19 17:24:101787 InputEventAck ack(handling_event_type_, INPUT_EVENT_ACK_STATE_CONSUMED);
[email protected]5fea4a52014-05-27 00:17:521788 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dgozmanb739185d2015-04-10 15:04:021789 return true;
[email protected]5fea4a52014-05-27 00:17:521790 }
[email protected]c27dd4f2014-05-22 18:05:191791 }
1792 return false;
1793}
1794
1795void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1796 ignore_ack_for_mouse_move_from_debugger_ = true;
1797}
1798
[email protected]468ac582012-11-20 00:53:191799void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1800 if (device_scale_factor_ == device_scale_factor)
1801 return;
1802
1803 device_scale_factor_ = device_scale_factor;
jdduke491a3f0c2015-06-15 23:30:261804 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191805}
1806
[email protected]28ed6b32014-06-08 02:16:271807bool RenderWidget::SetDeviceColorProfile(
1808 const std::vector<char>& color_profile) {
1809 if (device_color_profile_ == color_profile)
1810 return false;
1811
1812 device_color_profile_ = color_profile;
1813 return true;
1814}
1815
noeldb4df152014-09-16 17:45:201816void RenderWidget::ResetDeviceColorProfileForTesting() {
1817 if (!device_color_profile_.empty())
1818 device_color_profile_.clear();
1819 device_color_profile_.push_back('0');
1820}
1821
[email protected]fcdc5642014-05-09 14:32:241822void RenderWidget::OnOrientationChange() {
1823}
1824
[email protected]ceb36f7d2012-10-31 18:33:241825gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521826 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241827 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521828}
1829
[email protected]bee16aab2009-08-26 15:55:031830void RenderWidget::SetHidden(bool hidden) {
1831 if (is_hidden_ == hidden)
1832 return;
1833
jdduke8fac9d102014-12-20 02:40:131834 // The status has changed. Tell the RenderThread about it and ensure
1835 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031836 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131837 FlushPendingInputEventAck();
1838
[email protected]bee16aab2009-08-26 15:55:031839 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001840 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031841 else
[email protected]b2db9272014-01-10 17:42:001842 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111843
1844 if (render_widget_scheduling_state_)
1845 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031846}
1847
[email protected]2b624c562011-10-27 22:58:261848void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261849 if (!webwidget_)
1850 return;
1851
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121852 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261853 webwidget_->didEnterFullScreen();
1854 } else {
1855 webwidget_->didExitFullScreen();
1856 }
[email protected]2b624c562011-10-27 22:58:261857}
1858
[email protected]674741932009-02-04 23:44:461859bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051860 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461861}
1862
[email protected]674741932009-02-04 23:44:461863void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051864 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461865}
1866
[email protected]674741932009-02-04 23:44:461867void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051868 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461869}
1870
[email protected]b18583c2012-12-18 06:55:271871static bool IsDateTimeInput(ui::TextInputType type) {
1872 return type == ui::TEXT_INPUT_TYPE_DATE ||
1873 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1874 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1875 type == ui::TEXT_INPUT_TYPE_MONTH ||
1876 type == ui::TEXT_INPUT_TYPE_TIME ||
1877 type == ui::TEXT_INPUT_TYPE_WEEK;
1878}
1879
changwanf2a707b2015-10-30 08:22:161880void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1881 if (!ime_event_guard_)
1882 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291883}
1884
changwanf2a707b2015-10-30 08:22:161885void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1886 if (ime_event_guard_ != guard) {
1887#if defined(OS_ANDROID)
1888 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1889 // (e.g. long press gesture), we want to treat it as not-from-IME event
1890 // so that AdapterInputConnection can make changes to its Editable model.
1891 // Therefore, we want to mark this text state update as 'from IME' only
1892 // when all the nested events are all originating from IME.
1893 ime_event_guard_->set_from_ime(
1894 ime_event_guard_->from_ime() && guard->from_ime());
1895#endif
1896 return;
1897 }
1898 ime_event_guard_ = nullptr;
1899
[email protected]66fca5bc2013-05-23 06:58:291900 // While handling an ime event, text input state and selection bounds updates
1901 // are ignored. These must explicitly be updated once finished handling the
1902 // ime event.
1903 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471904#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161905 UpdateTextInputState(
1906 guard->show_ime() ? SHOW_IME_IF_NEEDED : NO_SHOW_IME,
1907 guard->from_ime() ? FROM_IME : FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471908#endif
[email protected]66fca5bc2013-05-23 06:58:291909}
1910
[email protected]90f24152014-04-09 12:41:361911void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1912 ChangeSource change_source) {
jdduke1aebad8e2015-07-22 23:25:081913 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwanf2a707b2015-10-30 08:22:161914 if (ime_event_guard_) {
1915 // show_ime should still be effective even if it was set inside the IME
1916 // event guard.
1917 if (show_ime == SHOW_IME_IF_NEEDED) {
1918 ime_event_guard_->set_show_ime(true);
1919 }
[email protected]e8f775f2013-02-14 21:00:501920 return;
changwanf2a707b2015-10-30 08:22:161921 }
1922
[email protected]ad26ef42011-06-17 07:59:451923 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271924 if (IsDateTimeInput(new_type))
1925 return; // Not considered as a text input field in WebKit/Chromium.
1926
[email protected]180ef242013-11-07 06:50:461927 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211928 if (webwidget_)
1929 new_info = webwidget_->textInputInfo();
shuchen913f8b622015-07-31 13:22:431930 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
[email protected]5b739cb2012-08-21 20:35:211931
[email protected]ad26ef42011-06-17 07:59:451932 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211933
[email protected]3306f262012-09-21 19:20:421934 // Only sends text input params if they are changed or if the ime should be
1935 // shown.
[email protected]90f24152014-04-09 12:41:361936 if (show_ime == SHOW_IME_IF_NEEDED ||
1937 (text_input_type_ != new_type ||
shuchen913f8b622015-07-31 13:22:431938 text_input_mode_ != new_mode ||
[email protected]90f24152014-04-09 12:41:361939 text_input_info_ != new_info ||
1940 can_compose_inline_ != new_can_compose_inline)
1941#if defined(OS_ANDROID)
1942 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021943#endif
[email protected]90f24152014-04-09 12:41:361944 ) {
shuchen913f8b622015-07-31 13:22:431945 ViewHostMsg_TextInputState_Params params;
1946 params.type = new_type;
1947 params.mode = new_mode;
1948 params.flags = new_info.flags;
1949 params.value = new_info.value.utf8();
1950 params.selection_start = new_info.selectionStart;
1951 params.selection_end = new_info.selectionEnd;
1952 params.composition_start = new_info.compositionStart;
1953 params.composition_end = new_info.compositionEnd;
1954 params.can_compose_inline = new_can_compose_inline;
1955 params.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
[email protected]90f24152014-04-09 12:41:361956#if defined(USE_AURA)
shuchen913f8b622015-07-31 13:22:431957 params.is_non_ime_change = true;
[email protected]90f24152014-04-09 12:41:361958#endif
[email protected]183e28d2014-01-20 18:18:021959#if defined(OS_ANDROID)
shuchen913f8b622015-07-31 13:22:431960 params.is_non_ime_change = (change_source == FROM_NON_IME) ||
[email protected]90f24152014-04-09 12:41:361961 text_field_is_dirty_;
shuchen913f8b622015-07-31 13:22:431962 if (params.is_non_ime_change)
changwan3a841162015-08-11 02:53:371963 OnImeEventSentForAck(new_info);
[email protected]90f24152014-04-09 12:41:361964 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021965#endif
shuchen913f8b622015-07-31 13:22:431966 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
[email protected]5b739cb2012-08-21 20:35:211967
1968 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041969 text_input_type_ = new_type;
shuchen913f8b622015-07-31 13:22:431970 text_input_mode_ = new_mode;
[email protected]ad26ef42011-06-17 07:59:451971 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201972 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291973 }
initial.commit09911bf2008-07-26 23:55:291974}
1975
[email protected]7c8873e2013-02-05 08:03:011976void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1977 WebRect focus_webrect;
1978 WebRect anchor_webrect;
1979 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1980 *focus = focus_webrect;
1981 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321982}
1983
[email protected]e99ef6f2011-10-16 01:13:001984void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081985 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001986 if (!webwidget_)
1987 return;
changwanf2a707b2015-10-30 08:22:161988 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291989 return;
[email protected]e99ef6f2011-10-16 01:13:001990
mohsenb0eeba72015-08-09 06:20:081991#if defined(USE_AURA)
1992 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1993 // Aura beucause composited selection updates are not working for webview tags
1994 // which regresses IME inside webview. Remove this when composited selection
1995 // updates are fixed for webviews. See, http://crbug.com/510568.
1996 bool send_ipc = true;
1997#else
jddukeacf809e2014-09-23 20:38:381998 // With composited selection updates, the selection bounds will be reported
1999 // directly by the compositor, in which case explicit IPC selection
2000 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082001 bool send_ipc =
2002 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
2003#endif
2004 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382005 ViewHostMsg_SelectionBounds_Params params;
2006 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2007 if (selection_anchor_rect_ != params.anchor_rect ||
2008 selection_focus_rect_ != params.focus_rect) {
2009 selection_anchor_rect_ = params.anchor_rect;
2010 selection_focus_rect_ = params.focus_rect;
2011 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2012 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2013 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2014 }
[email protected]58b48a0d2012-06-13 07:01:352015 }
jddukeacf809e2014-09-23 20:38:382016
[email protected]88dbe32f2013-06-20 23:31:362017 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002018}
2019
[email protected]180ef242013-11-07 06:50:462020// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172021#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2022 static_assert(int(blink::WebTextInputType##a) \
2023 == int(ui::TEXT_INPUT_TYPE_##b), \
2024 "mismatching enums: " #a)
2025
2026STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2027STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2028STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2029STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2030STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2031STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2032STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2033STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2034STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2035STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2036STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2037STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2038STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2039STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2040STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2041STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2042STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452043
[email protected]5b739cb2012-08-21 20:35:212044ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462045 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212046 // Check the type is in the range representable by ui::TextInputType.
2047 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462048 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212049 return static_cast<ui::TextInputType>(type);
2050}
2051
[email protected]ad26ef42011-06-17 07:59:452052ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272053 if (webwidget_)
jdduke3bf083fe2015-09-29 23:40:532054 return WebKitToUiTextInputType(webwidget_->textInputType());
[email protected]ad26ef42011-06-17 07:59:452055 return ui::TEXT_INPUT_TYPE_NONE;
2056}
2057
[email protected]501ea13d2013-07-09 17:03:292058void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302059#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112060 // TODO(yukawa): Start sending character bounds when the browser side
2061 // implementation becomes ready (crbug.com/424866).
2062#else
jdduke1aebad8e2015-07-22 23:25:082063 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
[email protected]db4fc1e2013-09-06 20:01:512064 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292065 if (should_update_range) {
2066 GetCompositionRange(&range);
2067 } else {
2068 range = composition_range_;
2069 }
2070 std::vector<gfx::Rect> character_bounds;
2071 GetCompositionCharacterBounds(&character_bounds);
2072
2073 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2074 return;
2075 composition_character_bounds_ = character_bounds;
2076 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222077 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292078 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112079#endif
[email protected]501ea13d2013-07-09 17:03:292080}
2081
[email protected]58b48a0d2012-06-13 07:01:352082void RenderWidget::GetCompositionCharacterBounds(
2083 std::vector<gfx::Rect>* bounds) {
2084 DCHECK(bounds);
2085 bounds->clear();
2086}
2087
[email protected]db4fc1e2013-09-06 20:01:512088void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362089 size_t location, length;
2090 if (webwidget_->compositionRange(&location, &length)) {
2091 range->set_start(location);
2092 range->set_end(location + length);
2093 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2094 range->set_start(location);
2095 range->set_end(location + length);
2096 } else {
[email protected]db4fc1e2013-09-06 20:01:512097 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362098 }
2099}
2100
[email protected]501ea13d2013-07-09 17:03:292101bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512102 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292103 const std::vector<gfx::Rect>& bounds) {
2104 if (composition_range_ != range)
2105 return true;
2106 if (bounds.size() != composition_character_bounds_.size())
2107 return true;
2108 for (size_t i = 0; i < bounds.size(); ++i) {
2109 if (bounds[i] != composition_character_bounds_[i])
2110 return true;
2111 }
2112 return false;
2113}
[email protected]501ea13d2013-07-09 17:03:292114
[email protected]a4f0d882014-05-01 23:48:102115#if defined(OS_ANDROID)
timav7a5032e2014-12-05 01:59:432116bool RenderWidget::DoesRecordFullLayer() const {
boliu15ca2652015-09-04 23:33:402117 return false;
timav7a5032e2014-12-05 01:59:432118}
[email protected]a4f0d882014-05-01 23:48:102119#endif
2120
[email protected]ad26ef42011-06-17 07:59:452121bool RenderWidget::CanComposeInline() {
2122 return true;
[email protected]56ea1a62011-05-30 07:05:572123}
2124
[email protected]4873c7d2009-07-16 06:36:282125WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042126 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282127}
2128
[email protected]f660d9c2012-06-06 18:31:212129float RenderWidget::deviceScaleFactor() {
2130 return device_scale_factor_;
2131}
2132
[email protected]fa7b1dc2010-06-23 17:53:042133void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022134 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042135 // If the last text input type is not None, then we should finish any
2136 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452137 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042138 // If a composition text exists, then we need to let the browser process
2139 // to cancel the input method's ongoing composition session.
2140 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222141 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042142 }
[email protected]d4cff272011-05-02 15:46:012143
[email protected]88dbe32f2013-06-20 23:31:362144 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042145}
2146
donnda070f3c2015-01-16 19:54:112147#if defined(OS_ANDROID)
2148void RenderWidget::showUnhandledTapUIIfNeeded(
2149 const WebPoint& tapped_position,
2150 const WebNode& tapped_node,
2151 bool page_changed) {
2152 DCHECK(handling_input_event_);
2153 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372154 !tapped_node.isContentEditable() &&
2155 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112156 if (should_trigger) {
2157 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2158 tapped_position.x, tapped_position.y));
2159 }
2160}
2161#endif
2162
[email protected]c68c3e4e2013-01-24 00:36:562163void RenderWidget::didHandleGestureEvent(
2164 const WebGestureEvent& event,
2165 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022166#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562167 if (event_cancelled)
2168 return;
[email protected]07c70d22014-08-21 08:33:462169 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362170 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462171 } else if (event.type == WebInputEvent::GestureLongPress) {
2172 DCHECK(webwidget_);
2173 if (webwidget_->textInputInfo().value.isEmpty())
2174 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2175 else
2176 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562177 }
2178#endif
2179}
2180
sataya.m582c9ce2015-06-09 08:03:422181void RenderWidget::didOverscroll(
2182 const blink::WebFloatSize& unusedDelta,
2183 const blink::WebFloatSize& accumulatedRootOverScroll,
2184 const blink::WebFloatPoint& position,
2185 const blink::WebFloatSize& velocity) {
2186 DidOverscrollParams params;
sataya.m582c9ce2015-06-09 08:03:422187 params.accumulated_overscroll = gfx::Vector2dF(
2188 accumulatedRootOverScroll.width, accumulatedRootOverScroll.height);
2189 params.latest_overscroll_delta =
2190 gfx::Vector2dF(unusedDelta.width, unusedDelta.height);
sataya.ma5cc13a2015-06-13 11:06:022191 // TODO(sataya.m): don't negate velocity once http://crbug.com/499743 is
2192 // fixed.
sataya.m582c9ce2015-06-09 08:03:422193 params.current_fling_velocity =
sataya.ma5cc13a2015-06-13 11:06:022194 gfx::Vector2dF(-velocity.width, -velocity.height);
sataya.m582c9ce2015-06-09 08:03:422195 params.causal_event_viewport_point = gfx::PointF(position.x, position.y);
jddukec05612b2015-06-25 23:13:182196
2197 // If we're currently handling an event, stash the overscroll data such that
2198 // it can be bundled in the event ack.
2199 if (handling_event_overscroll_) {
2200 handling_event_overscroll_->reset(new DidOverscrollParams(params));
2201 return;
2202 }
2203
sataya.m582c9ce2015-06-09 08:03:422204 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
2205}
2206
[email protected]7912e822014-04-16 02:37:032207void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392208 if (!is_hidden())
2209 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032210}
2211
[email protected]29e2fb42013-07-19 01:13:472212void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292213 size_t i = 0;
2214 for (; i < plugin_window_moves_.size(); ++i) {
2215 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582216 if (move.rects_valid) {
2217 plugin_window_moves_[i] = move;
2218 } else {
2219 plugin_window_moves_[i].visible = move.visible;
2220 }
initial.commit09911bf2008-07-26 23:55:292221 break;
2222 }
2223 }
2224
2225 if (i == plugin_window_moves_.size())
2226 plugin_window_moves_.push_back(move);
2227}
[email protected]268654772009-08-06 23:02:042228
2229void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2230 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2231 i != plugin_window_moves_.end(); ++i) {
2232 if (i->window == window) {
2233 plugin_window_moves_.erase(i);
2234 break;
2235 }
2236 }
2237}
[email protected]67bfb83f2011-09-22 03:36:372238
[email protected]63b465922012-09-06 02:04:522239
[email protected]24ed0432013-04-24 07:50:312240RenderWidgetCompositor* RenderWidget::compositor() const {
2241 return compositor_.get();
2242}
2243
[email protected]180ef242013-11-07 06:50:462244bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372245 return false;
2246}
[email protected]c3d45532011-10-07 19:20:402247
[email protected]41d86852012-11-07 12:23:242248bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462249 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242250 return false;
2251}
2252
ccamerona7644752014-12-30 01:16:312253void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312254 const blink::WebMouseWheelEvent& wheel_event,
sataya.mf405d0e2015-07-07 16:51:112255 const gfx::Vector2dF& wheel_unused_delta,
ccamerond4ba47902014-12-17 07:20:312256 bool event_processed) {
ccamerona7644752014-12-30 01:16:312257 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312258 return;
2259
ccamerond4ba47902014-12-17 07:20:312260 cc::InputHandlerScrollResult scroll_result;
sataya.mf405d0e2015-07-07 16:51:112261 scroll_result.did_scroll = event_processed;
2262 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
2263 scroll_result.unused_scroll_delta = wheel_unused_delta;
ccamerond4ba47902014-12-17 07:20:312264
2265 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2266 InputHandlerManager* input_handler_manager =
2267 render_thread ? render_thread->input_handler_manager() : NULL;
2268 if (input_handler_manager) {
2269 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2270 routing_id_, wheel_event, scroll_result);
2271 }
2272}
2273
[email protected]ce6689f2013-03-29 12:52:552274void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112275 if (render_widget_scheduling_state_)
2276 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552277 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2278}
2279
mostynbe29b6882015-01-13 09:59:172280// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2281#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2282 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2283 "mismatching enums: " #a)
2284
dtapuskaa98ac8d72015-05-08 19:29:092285inline content::TouchAction& operator|=(content::TouchAction& a,
2286 content::TouchAction b) {
2287 a = static_cast<content::TouchAction>(static_cast<int>(a) |
2288 static_cast<int>(b));
2289 return a;
2290}
2291
[email protected]5d0bbdfa92013-12-10 00:35:512292void RenderWidget::setTouchAction(
2293 blink::WebTouchAction web_touch_action) {
2294
2295 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2296 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192297 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512298 return;
2299
dtapuskaa98ac8d72015-05-08 19:29:092300 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172301 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2302 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092303 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2304 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172305 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092306 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2307 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172308 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2309 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362310
2311 content::TouchAction content_touch_action =
2312 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512313 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2314}
2315
[email protected]90f24152014-04-09 12:41:362316void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2317#if defined(OS_ANDROID)
2318 text_field_is_dirty_ = true;
2319#endif
2320}
2321
[email protected]3d5c243b2012-11-30 00:26:012322bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2323 return true;
2324}
2325
[email protected]0634cdd42013-08-16 00:46:092326scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
jbauman5e420d32015-08-05 09:33:012327RenderWidget::CreateGraphicsContext3D(bool compositor) {
[email protected]ed7defa2013-03-12 21:29:592328 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092329 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492330 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222331 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092332 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292333 if (!RenderThreadImpl::current())
2334 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402335 CauseForGpuLaunch cause =
2336 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292337 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402338 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222339 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292340 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592341
[email protected]828a3932014-04-02 14:43:132342 // Explicitly disable antialiasing for the compositor. As of the time of
2343 // this writing, the only platform that supported antialiasing for the
2344 // compositor was Mac OS X, because the on-screen OpenGL context creation
2345 // code paths on Windows and Linux didn't yet have multisampling support.
2346 // Mac OS X essentially always behaves as though it's rendering offscreen.
2347 // Multisampling has a heavy cost especially on devices with relatively low
2348 // fill rate like most notebooks, and the Mac implementation would need to
2349 // be optimized to resolve directly into the IOSurface shared between the
2350 // GPU and browser processes. For these reasons and to avoid platform
2351 // disparities we explicitly disable antialiasing.
2352 blink::WebGraphicsContext3D::Attributes attributes;
2353 attributes.antialias = false;
2354 attributes.shareResources = true;
2355 attributes.noAutomaticFlushes = true;
2356 attributes.depth = false;
2357 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132358 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292359 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012360#if defined(OS_ANDROID)
boliu853d46052015-10-13 20:20:062361 bool using_synchronous_compositing =
2362 SynchronousCompositorFactory::GetInstance();
[email protected]b6eb8e332013-09-10 00:51:012363 // If we raster too fast we become upload bound, and pending
2364 // uploads consume memory. For maximum upload throughput, we would
2365 // want to allow for upload_throughput * pipeline_time of pending
2366 // uploads, after which we are just wasting memory. Since we don't
2367 // know our upload throughput yet, this just caps our memory usage.
boliu853d46052015-10-13 20:20:062368 // Synchronous compositor uses half because synchronous compositor
2369 // pipeline is only one frame deep. But twice of half for low end
2370 // because 16bit texture is not supported.
2371 size_t divider = using_synchronous_compositing ? 2 : 1;
[email protected]35b4f0c2014-06-26 16:55:272372 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032373 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012374 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032375 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012376 // Deadline to draw a frame to achieve 60 frames per second.
2377 const size_t kMillisecondsPerFrame = 16;
2378 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032379 size_t max_transfer_buffer_usage_mb =
2380 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2381 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012382 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2383 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292384 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032385 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012386#endif
jbauman00ca2dc2015-08-10 23:21:152387 if (compositor) {
jbauman5e420d32015-08-05 09:33:012388 limits.command_buffer_size = 64 * 1024;
jbauman00ca2dc2015-08-10 23:21:152389 limits.start_transfer_buffer_size = 64 * 1024;
2390 limits.min_transfer_buffer_size = 64 * 1024;
2391 }
[email protected]96ab016c2013-10-23 00:50:292392
[email protected]96ab016c2013-10-23 00:50:292393 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
piman5d36dae2015-09-24 22:47:052394 new WebGraphicsContext3DCommandBufferImpl(
piman08f75532015-10-05 18:58:012395 0, GetURLForGraphicsContext3D(), gpu_channel_host.get(), attributes,
2396 lose_context_when_out_of_memory, limits, NULL));
[email protected]0634cdd42013-08-16 00:46:092397 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592398}
2399
[email protected]e3244ed2014-06-20 20:04:272400void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2401 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162402}
2403
[email protected]e3244ed2014-06-20 20:04:272404void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2405 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162406}
2407
[email protected]de3c5d82014-05-28 22:12:592408void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2409 render_frames_.AddObserver(frame);
2410}
2411
2412void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2413 render_frames_.RemoveObserver(frame);
2414}
2415
[email protected]a017938b2014-05-27 21:17:172416#if defined(VIDEO_HOLE)
2417void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2418 video_hole_frames_.AddObserver(frame);
2419}
2420
2421void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2422 video_hole_frames_.RemoveObserver(frame);
2423}
2424#endif // defined(VIDEO_HOLE)
2425
[email protected]e9ff79c2012-10-19 21:31:262426} // namespace content