blob: 1b6be53c461c76623a143cb3cdbd71307c613cca [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"
[email protected]29e2fb42013-07-19 01:13:4725#include "content/child/npapi/webplugin.h"
[email protected]0634cdd42013-08-16 00:46:0926#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5927#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2928#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3529#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4430#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1531#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1532#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5033#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2934#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4235#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4036#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5137#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5938#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]2847b222013-04-06 00:59:2439#include "content/renderer/gpu/compositor_software_output_device.h"
[email protected]36e5ff12013-06-11 12:19:2940#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1141#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5942#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1143#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2844#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2945#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1346#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3247#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1648#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2749#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0550#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4451#include "content/renderer/render_thread_impl.h"
tfarina556a7232014-10-05 01:02:0952#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0453#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1854#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4855#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1856#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3057#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1158#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3059#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1860#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebSize.h"
62#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4363#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5964#include "third_party/WebKit/public/web/WebFrameWidget.h"
65#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1166#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3167#include "third_party/WebKit/public/web/WebPagePopup.h"
68#include "third_party/WebKit/public/web/WebPopupMenu.h"
69#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
70#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3871#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5972#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4173#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1374#include "ui/base/ui_base_switches.h"
[email protected]de2cf8c2013-10-25 19:46:4675#include "ui/gfx/frame_time.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::WebPopupMenu;
109using blink::WebPopupMenuInfo;
110using blink::WebPopupType;
111using blink::WebRange;
112using blink::WebRect;
113using blink::WebScreenInfo;
114using blink::WebSize;
115using blink::WebTextDirection;
116using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25117using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46118using blink::WebVector;
119using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26120
[email protected]6a4d7f62013-01-07 21:32:13121namespace {
[email protected]b256eca2013-07-11 10:57:40122
123typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
124
125class TextInputModeMapSingleton {
126 public:
127 static TextInputModeMapSingleton* GetInstance() {
128 return Singleton<TextInputModeMapSingleton>::get();
129 }
[email protected]dd705d4d2013-11-27 08:14:41130 TextInputModeMapSingleton() {
131 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
132 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
133 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
134 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
135 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
136 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
137 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
138 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
139 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
140 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
141 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40142 }
[email protected]dd705d4d2013-11-27 08:14:41143 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40144 private:
[email protected]dd705d4d2013-11-27 08:14:41145 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40146
147 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
148
149 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
150};
151
[email protected]dd705d4d2013-11-27 08:14:41152ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40153 static TextInputModeMapSingleton* singleton =
154 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41155 TextInputModeMap::const_iterator it =
156 singleton->map().find(input_mode.utf8());
157 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40158 return ui::TEXT_INPUT_MODE_DEFAULT;
159 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13160}
[email protected]b256eca2013-07-11 10:57:40161
[email protected]fd847792013-10-24 17:12:35162// TODO(brianderson): Replace the hard-coded threshold with a fraction of
163// the BeginMainFrame interval.
164// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
165// be spent in input hanlders before input starts getting throttled.
166const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
167
jdduke07788062014-12-05 03:16:30168int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) {
169 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds))
170 .ToInternalValue();
171}
172
173void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now) {
174 UMA_HISTOGRAM_CUSTOM_COUNTS(
175 "Event.AggregatedLatency.Renderer2",
176 GetEventLatencyMicros(event, now),
177 1,
178 10000000,
179 100);
180
181#define CASE_TYPE(t) \
182 case WebInputEvent::t: \
183 UMA_HISTOGRAM_CUSTOM_COUNTS( \
184 "Event.Latency.Renderer2." #t, \
185 GetEventLatencyMicros(event, now), \
186 1, \
187 10000000, \
188 100); \
189 break;
190
191 switch(event.type) {
192 CASE_TYPE(Undefined);
193 CASE_TYPE(MouseDown);
194 CASE_TYPE(MouseUp);
195 CASE_TYPE(MouseMove);
196 CASE_TYPE(MouseEnter);
197 CASE_TYPE(MouseLeave);
198 CASE_TYPE(ContextMenu);
199 CASE_TYPE(MouseWheel);
200 CASE_TYPE(RawKeyDown);
201 CASE_TYPE(KeyDown);
202 CASE_TYPE(KeyUp);
203 CASE_TYPE(Char);
204 CASE_TYPE(GestureScrollBegin);
205 CASE_TYPE(GestureScrollEnd);
206 CASE_TYPE(GestureScrollUpdate);
207 CASE_TYPE(GestureFlingStart);
208 CASE_TYPE(GestureFlingCancel);
209 CASE_TYPE(GestureShowPress);
210 CASE_TYPE(GestureTap);
211 CASE_TYPE(GestureTapUnconfirmed);
212 CASE_TYPE(GestureTapDown);
213 CASE_TYPE(GestureTapCancel);
214 CASE_TYPE(GestureDoubleTap);
215 CASE_TYPE(GestureTwoFingerTap);
216 CASE_TYPE(GestureLongPress);
217 CASE_TYPE(GestureLongTap);
218 CASE_TYPE(GesturePinchBegin);
219 CASE_TYPE(GesturePinchEnd);
220 CASE_TYPE(GesturePinchUpdate);
221 CASE_TYPE(TouchStart);
222 CASE_TYPE(TouchMove);
223 CASE_TYPE(TouchEnd);
224 CASE_TYPE(TouchCancel);
225 default:
226 // Must include default to let blink::WebInputEvent add new event types
227 // before they're added here.
228 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event.type;
229 break;
230 }
231
232#undef CASE_TYPE
233}
234
[email protected]b256eca2013-07-11 10:57:40235} // namespace
236
[email protected]e9ff79c2012-10-19 21:31:26237namespace content {
[email protected]62cb33cae2009-03-27 23:30:22238
[email protected]b2e4c70132013-10-03 02:07:51239// RenderWidget::ScreenMetricsEmulator ----------------------------------------
240
241class RenderWidget::ScreenMetricsEmulator {
242 public:
243 ScreenMetricsEmulator(
244 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43245 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51246 virtual ~ScreenMetricsEmulator();
247
[email protected]19193682014-04-03 15:01:43248 // Scale and offset used to convert between host coordinates
249 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51250 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20251 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43252 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51253 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56254 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51255
256 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43257 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51258
259 // The following methods alter handlers' behavior for messages related to
260 // widget size and position.
261 void OnResizeMessage(const ViewMsg_Resize_Params& params);
262 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
263 const gfx::Rect& window_screen_rect);
264 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31265 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51266
267 private:
[email protected]19193682014-04-03 15:01:43268 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02269 void Apply(bool top_controls_shrink_blink_size,
270 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44271 gfx::Rect resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12272 bool is_fullscreen_granted);
[email protected]b2e4c70132013-10-03 02:07:51273
274 RenderWidget* widget_;
275
[email protected]7f99fc22013-11-08 14:05:58276 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43277 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51278
[email protected]a179d3962013-11-12 14:44:40279 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51280 float scale_;
dgozman9260b0a12015-03-16 13:45:20281 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51282
[email protected]19193682014-04-03 15:01:43283 // Widget rect as passed to webwidget.
284 gfx::Rect applied_widget_rect_;
285
[email protected]b2e4c70132013-10-03 02:07:51286 // Original values to restore back after emulation ends.
287 gfx::Size original_size_;
288 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28289 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46290 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51291 gfx::Rect original_view_screen_rect_;
292 gfx::Rect original_window_screen_rect_;
293};
294
295RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
296 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43297 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51298 : widget_(widget),
[email protected]19193682014-04-03 15:01:43299 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51300 scale_(1.f) {
301 original_size_ = widget_->size_;
302 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28303 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51304 original_screen_info_ = widget_->screen_info_;
305 original_view_screen_rect_ = widget_->view_screen_rect_;
306 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02307 Apply(widget_->top_controls_shrink_blink_size_,
308 widget_->top_controls_height_,
309 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12310 widget_->is_fullscreen_granted_);
[email protected]b2e4c70132013-10-03 02:07:51311}
312
313RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
314 widget_->screen_info_ = original_screen_info_;
315
316 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20317 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51318 widget_->view_screen_rect_ = original_view_screen_rect_;
319 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01320 widget_->Resize(original_size_,
321 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02322 widget_->top_controls_shrink_blink_size_,
323 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01324 original_visible_viewport_size_,
325 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12326 widget_->is_fullscreen_granted_,
[email protected]587941d2014-08-22 01:40:01327 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51328}
329
330void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43331 const WebDeviceEmulationParams& params) {
332 params_ = params;
333 Reapply();
334}
335
336void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02337 Apply(widget_->top_controls_shrink_blink_size_,
338 widget_->top_controls_height_,
339 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12340 widget_->is_fullscreen_granted_);
[email protected]b2e4c70132013-10-03 02:07:51341}
342
[email protected]19193682014-04-03 15:01:43343void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02344 bool top_controls_shrink_blink_size,
345 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44346 gfx::Rect resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12347 bool is_fullscreen_granted) {
[email protected]92d13b72014-05-09 14:42:31348 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
349 if (!applied_widget_rect_.width())
350 applied_widget_rect_.set_width(original_size_.width());
351 if (!applied_widget_rect_.height())
352 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43353
[email protected]f442ee42014-05-14 11:53:12354 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02355 int original_width = std::max(original_size_.width(), 1);
356 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51357 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02358 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51359 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02360 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51361 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
362 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01363
364 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43365 offset_.set_x(
366 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01367 offset_.set_y(
[email protected]19193682014-04-03 15:01:43368 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51369 } else {
[email protected]0b3578c2014-06-20 18:29:02370 scale_ = params_.scale;
371 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01372 }
[email protected]7f0e8fa2014-03-26 12:32:01373
[email protected]19193682014-04-03 15:01:43374 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
375 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01376 widget_->screen_info_.rect = original_screen_info_.rect;
377 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
378 widget_->window_screen_rect_ = original_window_screen_rect_;
379 } else {
[email protected]19193682014-04-03 15:01:43380 applied_widget_rect_.set_origin(gfx::Point(0, 0));
381 widget_->screen_info_.rect = applied_widget_rect_;
382 widget_->screen_info_.availableRect = applied_widget_rect_;
383 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01384 }
[email protected]a179d3962013-11-12 14:44:40385
[email protected]19193682014-04-03 15:01:43386 float applied_device_scale_factor = params_.deviceScaleFactor ?
387 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01388 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51389
[email protected]7f99fc22013-11-08 14:05:58390 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51391 // - we keep the real device scale factor in compositor to produce sharp image
392 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58393 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51394 // root layer.
dgozman9260b0a12015-03-16 13:45:20395 blink::WebDeviceEmulationParams modified_params = params_;
396 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
397 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
398 modified_params.scale = scale_;
399 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51400
[email protected]7f0e8fa2014-03-26 12:32:01401 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43402 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51403
404 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
405 original_size_, original_screen_info_.deviceScaleFactor));
dtrainorcb7779b82014-12-04 01:08:02406 widget_->Resize(applied_widget_rect_.size(),
407 physical_backing_size,
408 top_controls_shrink_blink_size,
409 top_controls_height,
410 applied_widget_rect_.size(),
411 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12412 is_fullscreen_granted,
dtrainorcb7779b82014-12-04 01:08:02413 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51414}
415
416void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
417 const ViewMsg_Resize_Params& params) {
418 bool need_ack = params.new_size != original_size_ &&
419 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
420 original_size_ = params.new_size;
421 original_physical_backing_size_ = params.physical_backing_size;
422 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28423 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02424 Apply(params.top_controls_shrink_blink_size,
425 params.top_controls_height,
426 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12427 params.is_fullscreen_granted);
[email protected]b2e4c70132013-10-03 02:07:51428
429 if (need_ack) {
430 widget_->set_next_paint_is_resize_ack();
431 if (widget_->compositor_)
432 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
433 }
434}
435
436void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
437 const gfx::Rect& view_screen_rect,
438 const gfx::Rect& window_screen_rect) {
439 original_view_screen_rect_ = view_screen_rect;
440 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43441 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
442 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51443}
444
445void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
446 ContextMenuParams* params) {
447 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40448 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51449 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40450 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51451}
452
[email protected]2d6836f42014-07-02 17:25:31453gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
454 const gfx::Rect& anchor) {
455 gfx::Rect scaled = gfx::ToEnclosedRect(gfx::ScaleRect(anchor, scale_));
456 scaled.set_x(scaled.x() + offset_.x());
457 scaled.set_y(scaled.y() + offset_.y());
458 return scaled;
459}
460
[email protected]b2e4c70132013-10-03 02:07:51461// RenderWidget ---------------------------------------------------------------
462
[email protected]180ef242013-11-07 06:50:46463RenderWidget::RenderWidget(blink::WebPopupType popup_type,
464 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04465 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03466 bool hidden,
467 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29468 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56469 surface_id_(0),
danakj6e3bf8012014-12-16 18:27:53470 compositor_deps_(nullptr),
471 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29472 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30473 init_complete_(false),
dtrainorcb7779b82014-12-04 01:08:02474 top_controls_shrink_blink_size_(false),
475 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29476 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51477 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09478 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29479 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04480 is_hidden_(hidden),
[email protected]7912e822014-04-16 02:37:03481 never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12482 is_fullscreen_granted_(false),
initial.commit09911bf2008-07-26 23:55:29483 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49484 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50485 handling_ime_event_(false),
[email protected]c27dd4f2014-05-22 18:05:19486 handling_event_type_(WebInputEvent::Undefined),
487 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48488 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22489 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44490 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04491 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45492 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40493 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20494 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53495 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12496 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48497 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12498 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04499 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52500 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]8062ab262014-05-27 16:56:43501 current_event_latency_info_(NULL),
[email protected]53b4cc12013-07-18 23:02:30502 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13503#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36504 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13505 outstanding_ime_acks_(0),
[email protected]a4f0d882014-05-01 23:48:10506 body_background_color_(SK_ColorWHITE),
[email protected]0d1ebed12013-08-05 22:01:13507#endif
[email protected]b2e4c70132013-10-03 02:07:51508 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11509 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42510 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51511 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
512 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05513 if (!swapped_out)
514 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27515 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53516 device_color_profile_.push_back('0');
initial.commit09911bf2008-07-26 23:55:29517}
518
519RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11520 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16521
[email protected]992db4c2011-05-12 15:37:15522 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02523 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15524 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29525}
526
[email protected]484955942010-08-19 16:13:18527// static
[email protected]8085dbc82008-09-26 22:53:44528RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53529 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46530 blink::WebPopupType popup_type,
531 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29532 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41533 scoped_refptr<RenderWidget> widget(
[email protected]7912e822014-04-16 02:37:03534 new RenderWidget(popup_type, screen_info, false, false, false));
danakj6e3bf8012014-12-16 18:27:53535 if (widget->Init(opener_id, compositor_deps)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46536 return widget.get();
[email protected]a635f942012-12-07 10:34:29537 }
538 return NULL;
initial.commit09911bf2008-07-26 23:55:29539}
540
[email protected]484955942010-08-19 16:13:18541// static
kenrba7199832015-01-22 23:44:59542RenderWidget* RenderWidget::CreateForFrame(
543 int routing_id,
544 int surface_id,
545 bool hidden,
546 const blink::WebScreenInfo& screen_info,
547 CompositorDependencies* compositor_deps,
548 blink::WebLocalFrame* frame) {
549 CHECK_NE(routing_id, MSG_ROUTING_NONE);
550 scoped_refptr<RenderWidget> widget(new RenderWidget(
551 blink::WebPopupTypeNone, screen_info, false, hidden, false));
552 widget->routing_id_ = routing_id;
553 widget->surface_id_ = surface_id;
554 widget->compositor_deps_ = compositor_deps;
555 // DoInit increments the reference count on |widget|, keeping it alive after
556 // this function returns.
557 if (widget->DoInit(MSG_ROUTING_NONE, compositor_deps,
558 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
559 nullptr)) {
560 widget->CompleteInit();
561 return widget.get();
562 }
563 return nullptr;
564}
565
566// static
567blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18568 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46569 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18570 break;
[email protected]180ef242013-11-07 06:50:46571 case blink::WebPopupTypeSelect:
572 case blink::WebPopupTypeSuggestion:
[email protected]484955942010-08-19 16:13:18573 return WebPopupMenu::create(render_widget);
[email protected]180ef242013-11-07 06:50:46574 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44575 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18576 default:
577 NOTREACHED();
578 }
579 return NULL;
580}
581
kenrba7199832015-01-22 23:44:59582// static
583blink::WebWidget* RenderWidget::CreateWebFrameWidget(
584 RenderWidget* render_widget,
585 blink::WebLocalFrame* frame) {
586 return blink::WebFrameWidget::create(render_widget, frame);
587}
588
danakj6e3bf8012014-12-16 18:27:53589bool RenderWidget::Init(int32 opener_id,
590 CompositorDependencies* compositor_deps) {
591 return DoInit(opener_id, compositor_deps, RenderWidget::CreateWebWidget(this),
[email protected]a635f942012-12-07 10:34:29592 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
593 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18594}
595
[email protected]a635f942012-12-07 10:34:29596bool RenderWidget::DoInit(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53597 CompositorDependencies* compositor_deps,
[email protected]6a8ddba52010-09-05 04:38:06598 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18599 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29600 DCHECK(!webwidget_);
601
602 if (opener_id != MSG_ROUTING_NONE)
603 opener_id_ = opener_id;
604
danakj6e3bf8012014-12-16 18:27:53605 compositor_deps_ = compositor_deps;
[email protected]484955942010-08-19 16:13:18606 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29607
kenrba7199832015-01-22 23:44:59608 bool result = true;
609 if (create_widget_message)
610 result = RenderThread::Get()->Send(create_widget_message);
611
initial.commit09911bf2008-07-26 23:55:29612 if (result) {
[email protected]380244092011-10-07 17:26:27613 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29614 // Take a reference on behalf of the RenderThread. This will be balanced
615 // when we receive ViewMsg_Close.
616 AddRef();
[email protected]b2db9272014-01-10 17:42:00617 if (RenderThreadImpl::current()) {
618 RenderThreadImpl::current()->WidgetCreated();
619 if (is_hidden_)
620 RenderThreadImpl::current()->WidgetHidden();
621 }
[email protected]a635f942012-12-07 10:34:29622 return true;
initial.commit09911bf2008-07-26 23:55:29623 } else {
[email protected]a635f942012-12-07 10:34:29624 // The above Send can fail when the tab is closing.
625 return false;
initial.commit09911bf2008-07-26 23:55:29626 }
627}
628
[email protected]fc4404d2012-11-07 19:53:30629// This is used to complete pending inits and non-pending inits.
630void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29631 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29632
[email protected]fc4404d2012-11-07 19:53:30633 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42634
[email protected]7912e822014-04-16 02:37:03635 if (compositor_)
636 StartCompositor();
initial.commit09911bf2008-07-26 23:55:29637
[email protected]6de74452009-02-25 18:04:59638 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29639}
640
[email protected]992db4c2011-05-12 15:37:15641void RenderWidget::SetSwappedOut(bool is_swapped_out) {
642 // We should only toggle between states.
643 DCHECK(is_swapped_out_ != is_swapped_out);
644 is_swapped_out_ = is_swapped_out;
645
646 // If we are swapping out, we will call ReleaseProcess, allowing the process
647 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52648 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15649 // If we are swapping in, we call AddRefProcess to prevent the process from
650 // exiting.
[email protected]949b6592014-08-20 13:17:52651 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15652 RenderProcess::current()->AddRefProcess();
653}
654
[email protected]949b6592014-08-20 13:17:52655void RenderWidget::WasSwappedOut() {
656 // If we have been swapped out and no one else is using this process,
657 // it's safe to exit now.
658 CHECK(is_swapped_out_);
659 RenderProcess::current()->ReleaseProcess();
660}
661
[email protected]b2e4c70132013-10-03 02:07:51662void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
663 ScreenMetricsEmulator* emulator) {
664 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43665 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49666 popup_screen_origin_for_emulation_ = gfx::Point(
667 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
668 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56669 screen_info_ = emulator->original_screen_info();
670 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51671}
672
[email protected]2d6836f42014-07-02 17:25:31673gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
674 if (screen_metrics_emulator_)
675 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
676 return anchor;
677}
678
[email protected]b2e4c70132013-10-03 02:07:51679void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20680 bool enabled,
681 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51682 // This is only supported in RenderView.
683 NOTREACHED();
684}
685
[email protected]53907862014-03-25 15:42:40686#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51687void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
688 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49689 popup->SetOriginScaleAndOffsetForEmulation(
690 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51691}
[email protected]53907862014-03-25 15:42:40692#endif
[email protected]b2e4c70132013-10-03 02:07:51693
694void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
695 if (screen_metrics_emulator_)
696 screen_metrics_emulator_->OnShowContextMenu(params);
697}
698
[email protected]7d08a9352013-10-15 08:24:56699void RenderWidget::ScheduleCompositeWithForcedRedraw() {
700 if (compositor_) {
701 // Regardless of whether threaded compositing is enabled, always
702 // use this mechanism to force the compositor to redraw. However,
703 // the invalidation code path below is still needed for the
704 // non-threaded case.
705 compositor_->SetNeedsForcedRedraw();
706 }
[email protected]8b9e52b2014-01-17 16:35:31707 scheduleComposite();
[email protected]7d08a9352013-10-15 08:24:56708}
709
[email protected]a95986a82010-12-24 06:19:28710bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
711 bool handled = true;
712 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15713 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22714 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
715 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22716 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
717 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15718 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
719 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35720 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
721 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28722 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
723 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
724 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20725 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
726 OnEnableDeviceEmulation)
727 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
728 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41729 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54730 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28731 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41732 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]a95986a82010-12-24 06:19:28733 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
[email protected]37a241c2013-12-03 03:16:17734 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowShown, OnCandidateWindowShown)
735 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowUpdated,
736 OnCandidateWindowUpdated)
737 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowHidden, OnCandidateWindowHidden)
[email protected]3d9ec5052013-01-02 22:05:25738 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28739 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
740 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03741 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21742#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51743 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13744 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21745#endif
[email protected]a95986a82010-12-24 06:19:28746 IPC_MESSAGE_UNHANDLED(handled = false)
747 IPC_END_MESSAGE_MAP()
748 return handled;
749}
initial.commit09911bf2008-07-26 23:55:29750
751bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15752 // Don't send any messages after the browser has told us to close, and filter
753 // most outgoing messages while swapped out.
754 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26755 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11756 closing_) {
initial.commit09911bf2008-07-26 23:55:29757 delete message;
758 return false;
759 }
760
761 // If given a messsage without a routing ID, then assign our routing ID.
762 if (message->routing_id() == MSG_ROUTING_NONE)
763 message->set_routing_id(routing_id_);
764
[email protected]380244092011-10-07 17:26:27765 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44766}
767
[email protected]61e2b3cc2012-03-02 16:13:34768void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44769 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02770 bool top_controls_shrink_blink_size,
771 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44772 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34773 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12774 bool is_fullscreen_granted,
sievers4e33dae2015-02-25 20:43:58775 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56776 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48777 // A resize ack shouldn't be requested if we have not ACK'd the previous
778 // one.
779 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
780 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
781 }
initial.commit09911bf2008-07-26 23:55:29782
[email protected]61e2b3cc2012-03-02 16:13:34783 // Ignore this during shutdown.
784 if (!webwidget_)
785 return;
786
[email protected]d9083762013-03-24 01:36:40787 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44788 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40789 }
[email protected]60d47ac2013-03-01 23:42:44790
[email protected]dade8992013-03-04 07:34:34791 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02792 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
793 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28794 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34795 resizer_rect_ = resizer_rect;
796
797 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12798 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
[email protected]61e2b3cc2012-03-02 16:13:34799 if (fullscreen_change)
800 WillToggleFullscreen();
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12801 is_fullscreen_granted_ = is_fullscreen_granted;
[email protected]61e2b3cc2012-03-02 16:13:34802
aelias6004fe02015-02-07 21:43:01803 webwidget_->setTopControlsHeight(top_controls_height,
804 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43805
[email protected]61e2b3cc2012-03-02 16:13:34806 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34807 size_ = new_size;
808
[email protected]61e2b3cc2012-03-02 16:13:34809 // When resizing, we want to wait to paint before ACK'ing the resize. This
810 // ensures that we only resize as fast as we can paint. We only need to
811 // send an ACK if we are resized to a non-empty rect.
812 webwidget_->resize(new_size);
[email protected]632c4382013-05-15 08:58:45813 }
814
[email protected]bb6378fe2014-04-28 21:19:44815 webwidget()->resizePinchViewport(gfx::Size(
816 visible_viewport_size.width(),
817 visible_viewport_size.height()));
818
[email protected]632c4382013-05-15 08:58:45819 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58820 // In this case there is no paint/composite and therefore no
821 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
822 // ack through a fake ViewHostMsg_UpdateRect or a different message.
823 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34824 }
825
[email protected]20fbfc22013-05-08 20:50:58826 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45827 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58828 set_next_paint_is_resize_ack();
829
[email protected]61e2b3cc2012-03-02 16:13:34830 if (fullscreen_change)
831 DidToggleFullscreen();
832
833 // If a resize ack is requested and it isn't set-up, then no more resizes will
834 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45835 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29836}
837
bokanc007c3a2015-02-03 07:15:56838void RenderWidget::SetWindowRectSynchronously(
839 const gfx::Rect& new_window_rect) {
840 Resize(new_window_rect.size(),
841 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02842 top_controls_shrink_blink_size_,
843 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56844 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01845 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12846 is_fullscreen_granted_,
[email protected]587941d2014-08-22 01:40:01847 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56848 view_screen_rect_ = new_window_rect;
849 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02850 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56851 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02852}
853
initial.commit09911bf2008-07-26 23:55:29854void RenderWidget::OnClose() {
855 if (closing_)
856 return;
dgozmancf9039cd2015-04-06 12:01:31857 NotifyOnClose();
initial.commit09911bf2008-07-26 23:55:29858 closing_ = true;
859
860 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03861 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]b2db9272014-01-10 17:42:00862 if (RenderThreadImpl::current())
863 RenderThreadImpl::current()->WidgetDestroyed();
[email protected]380244092011-10-07 17:26:27864 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03865 SetHidden(false);
866 }
initial.commit09911bf2008-07-26 23:55:29867
initial.commit09911bf2008-07-26 23:55:29868 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25869 // now. Post a task that only gets invoked when there are no nested message
870 // loops.
alexclarkee19d4ef2015-01-09 17:45:40871 RenderThread::Get()->GetTaskRunner()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29872 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25873
874 // Balances the AddRef taken when we called AddRoute.
875 Release();
initial.commit09911bf2008-07-26 23:55:29876}
877
[email protected]61e2b3cc2012-03-02 16:13:34878// Got a response from the browser after the renderer decided to create a new
879// view.
[email protected]fc4404d2012-11-07 19:53:30880void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34881 DCHECK(routing_id_ != MSG_ROUTING_NONE);
882
[email protected]fc4404d2012-11-07 19:53:30883 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34884}
885
[email protected]0fdd5012013-05-29 08:05:56886void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04887 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32888 return;
889
[email protected]b2e4c70132013-10-03 02:07:51890 if (screen_metrics_emulator_) {
891 screen_metrics_emulator_->OnResizeMessage(params);
892 return;
893 }
894
[email protected]fcdc5642014-05-09 14:32:24895 bool orientation_changed =
896 screen_info_.orientationAngle != params.screen_info.orientationAngle;
897
[email protected]0fdd5012013-05-29 08:05:56898 screen_info_ = params.screen_info;
899 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02900 Resize(params.new_size,
901 params.physical_backing_size,
902 params.top_controls_shrink_blink_size,
903 params.top_controls_height,
904 params.visible_viewport_size,
905 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12906 params.is_fullscreen_granted,
sievers4e33dae2015-02-25 20:43:58907 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24908
909 if (orientation_changed)
910 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29911}
912
dgozman9260b0a12015-03-16 13:45:20913void RenderWidget::OnEnableDeviceEmulation(
914 const blink::WebDeviceEmulationParams& params) {
915 if (!screen_metrics_emulator_)
916 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
917 else
918 screen_metrics_emulator_->ChangeEmulationParams(params);
919}
920
921void RenderWidget::OnDisableDeviceEmulation() {
922 screen_metrics_emulator_.reset();
923}
924
noel89949e62014-09-30 01:12:41925void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
926 SetDeviceColorProfile(color_profile);
927}
928
[email protected]b5913d72012-02-07 22:26:54929void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01930 if (resizer_rect_ == resizer_rect)
931 return;
932 resizer_rect_ = resizer_rect;
933 if (webwidget_)
934 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54935}
936
initial.commit09911bf2008-07-26 23:55:29937void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31938 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29939 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03940 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59941 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
942 WasHidden());
initial.commit09911bf2008-07-26 23:55:29943}
944
[email protected]3399dd822014-08-09 11:14:24945void RenderWidget::OnWasShown(bool needs_repainting,
946 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41947 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29948 // During shutdown we can just ignore this message.
949 if (!webwidget_)
950 return;
951
952 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03953 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59954 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
955 WasShown());
initial.commit09911bf2008-07-26 23:55:29956
[email protected]8a23afb32014-04-30 22:40:23957 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29958 return;
initial.commit09911bf2008-07-26 23:55:29959
960 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24961 if (compositor_) {
962 ui::LatencyInfo swap_latency_info(latency_info);
963 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
964 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05965 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24966 }
[email protected]aca33f4f2014-05-17 17:08:05967 scheduleComposite();
initial.commit09911bf2008-07-26 23:55:29968}
969
[email protected]53d3f302009-12-21 04:42:05970void RenderWidget::OnRequestMoveAck() {
971 DCHECK(pending_window_rect_count_);
972 pending_window_rect_count_--;
973}
974
[email protected]ed7defa2013-03-12 21:29:59975GURL RenderWidget::GetURLForGraphicsContext3D() {
976 return GURL();
[email protected]65225772011-05-12 21:10:24977}
978
[email protected]ebc0e1df2013-08-01 02:46:22979scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03980 // For widgets that are never visible, we don't start the compositor, so we
981 // never get a request for a cc::OutputSurface.
982 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19983
984#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01985 if (SynchronousCompositorFactory* factory =
986 SynchronousCompositorFactory::GetInstance()) {
[email protected]586871b2014-07-22 17:05:11987 return factory->CreateOutputSurface(routing_id(),
988 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:19989 }
990#endif
991
avi83883c82014-12-23 00:08:49992 const base::CommandLine& command_line =
993 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33994 bool use_software = fallback;
995 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
996 use_software = true;
997
[email protected]0634cdd42013-08-16 00:46:09998 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17999 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:331000 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:091001 context_provider = ContextProviderCommandBuffer::Create(
[email protected]828a3932014-04-02 14:43:131002 CreateGraphicsContext3D(), "RenderCompositor");
[email protected]e09994a2014-03-26 19:59:331003 if (!context_provider.get()) {
1004 // Cause the compositor to wait and try again.
1005 return scoped_ptr<cc::OutputSurface>();
1006 }
vmiura78b69282015-02-14 00:01:171007
1008 worker_context_provider = ContextProviderCommandBuffer::Create(
1009 CreateGraphicsContext3D(), "RenderWorker");
1010 if (!worker_context_provider.get()) {
1011 // Cause the compositor to wait and try again.
1012 return scoped_ptr<cc::OutputSurface>();
1013 }
[email protected]0634cdd42013-08-16 00:46:091014 }
[email protected]ebc0e1df2013-08-01 02:46:221015
[email protected]b6eb8e332013-09-10 00:51:011016 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:001017 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:531018 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
caseqff9c74c2015-02-10 14:56:291019 return scoped_ptr<cc::OutputSurface>(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171020 routing_id(), output_surface_id, context_provider,
1021 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091022 }
[email protected]0634cdd42013-08-16 00:46:091023 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091024 scoped_ptr<cc::SoftwareOutputDevice> software_device(
1025 new CompositorSoftwareOutputDevice());
1026
caseqff9c74c2015-02-10 14:56:291027 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
1028 routing_id(), output_surface_id, nullptr, nullptr,
1029 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221030 }
[email protected]ed7defa2013-03-12 21:29:591031
[email protected]36e5ff12013-06-11 12:19:291032 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:451033 // Composite-to-mailbox is currently used for layout tests in order to cause
1034 // them to draw inside in the renderer to do the readback there. This should
1035 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:531036 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:161037 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:271038 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:161039 format = cc::RGB_565;
caseqff9c74c2015-02-10 14:56:291040 return scoped_ptr<cc::OutputSurface>(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171041 routing_id(), output_surface_id, context_provider,
1042 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1043 frame_swap_message_queue_, format));
[email protected]36e5ff12013-06-11 12:19:291044 }
[email protected]0634cdd42013-08-16 00:46:091045 bool use_swap_compositor_frame_message = false;
caseqff9c74c2015-02-10 14:56:291046 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171047 routing_id(), output_surface_id, context_provider,
1048 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1049 frame_swap_message_queue_, use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281050}
1051
[email protected]4d7e46a2013-11-08 05:33:401052void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241053 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241054 // Schedule another frame so the compositor learns about it.
[email protected]8b9e52b2014-01-17 16:35:311055 scheduleComposite();
[email protected]65225772011-05-12 21:10:241056}
1057
[email protected]4d7e46a2013-11-08 05:33:401058void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081059 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081060}
1061
[email protected]4d7e46a2013-11-08 05:33:401062void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241063 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161064
[email protected]404939f2012-06-01 04:06:181065 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161066 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291067}
1068
[email protected]180ef242013-11-07 06:50:461069void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351070 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091071 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191072 base::AutoReset<bool> handling_input_event_resetter(
1073 &handling_input_event_, true);
1074 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291075 return;
[email protected]c27dd4f2014-05-22 18:05:191076 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1077 &handling_event_type_, input_event->type);
[email protected]25402eb2014-07-18 03:09:521078#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541079 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521080 // |AdapterInputConnection| generates input key events to make sure all JS
1081 // listeners that monitor KeyUp and KeyDown events receive the proper key
1082 // code. Since this input key event comes from IME, we need to set the
1083 // IME event guard here to make sure it does not interfere with other IME
1084 // events.
1085 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1086 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1087 const WebKeyboardEvent& key_event =
1088 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541089 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171090 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091091 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1092 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1093 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1094 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1095 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521096 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521097 }
1098#endif
initial.commit09911bf2008-07-26 23:55:291099
[email protected]8062ab262014-05-27 16:56:431100 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1101 &latency_info);
1102
[email protected]fd847792013-10-24 17:12:351103 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411104 if (base::TimeTicks::IsHighResolution())
1105 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351106
miletusfed8c43b2015-01-26 20:04:521107 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301108 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151109 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131110 TRACE_EVENT_FLOW_STEP0(
miletusfed8c43b2015-01-26 20:04:521111 "input,benchmark",
[email protected]15ba6dea2014-04-02 01:44:131112 "LatencyInfo.Flow",
1113 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1114 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101115
jdduke07788062014-12-05 03:16:301116 // If we don't have a high res timer, these metrics won't be accurate enough
1117 // to be worth collecting. Note that this does introduce some sampling bias.
1118 if (!start_time.is_null())
1119 LogInputEventLatencyUma(*input_event, start_time);
1120
[email protected]6be422b2013-12-08 06:47:311121 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351122 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311123 if (compositor_) {
1124 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351125 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1126 .Pass();
[email protected]6be422b2013-12-08 06:47:311127 }
[email protected]c2eaa8f2013-05-10 02:41:551128
[email protected]67bfb83f2011-09-22 03:36:371129 bool prevent_default = false;
1130 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261131 const WebMouseEvent& mouse_event =
1132 *static_cast<const WebMouseEvent*>(input_event);
1133 TRACE_EVENT2("renderer", "HandleMouseMove",
1134 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421135 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261136 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371137 }
1138
[email protected]cefe9b152014-03-27 18:16:151139 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421140 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151141#if defined(OS_ANDROID)
1142 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1143 // case it should behave like a select key (i.e. causing a click if a button
1144 // is focused). However, if a text field is focused (2), its intended
1145 // behavior is to just show the IME and don't propagate the key.
1146 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1147 // when clicked on an input text field and cause the form submit if clicked
1148 // when the submit button is focused, but not vice-versa.
1149 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1150 // but at this point we have to swallow the event for the scenario (2).
1151 const WebKeyboardEvent& key_event =
1152 *static_cast<const WebKeyboardEvent*>(input_event);
1153 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1154 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1155 OnShowImeIfNeeded();
1156 prevent_default = true;
1157 }
1158#endif
1159 }
[email protected]f56c7872013-06-18 12:31:571160
[email protected]41d86852012-11-07 12:23:241161 if (WebInputEvent::isGestureEventType(input_event->type)) {
1162 const WebGestureEvent& gesture_event =
1163 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421164 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241165 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1166 }
1167
[email protected]67bfb83f2011-09-22 03:36:371168 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121169 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1170 suppress_next_char_events_ = false;
1171 if (!processed && webwidget_)
1172 processed = webwidget_->handleInputEvent(*input_event);
1173 }
1174
1175 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1176 // it's not processed by webkit, then we need to suppress the upcoming Char
1177 // events.
1178 if (!processed && is_keyboard_shortcut)
1179 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291180
[email protected]3d5c243b2012-11-30 00:26:011181 InputEventAckState ack_result = processed ?
1182 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1183 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1184 const WebTouchEvent& touch_event =
1185 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251186 // Hit-test for all the pressed touch points. If there is a touch-handler
1187 // for any of the touch points, then the renderer should continue to receive
1188 // touch events.
1189 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1190 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1191 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271192 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391193 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251194 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1195 break;
1196 }
1197 }
[email protected]3d5c243b2012-11-30 00:26:011198 }
1199
ccamerond4ba47902014-12-17 07:20:311200 // Send mouse wheel events and their disposition to the compositor thread, so
1201 // that they can be used to produce the elastic overscroll effect on Mac.
1202 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311203 ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:311204 static_cast<const WebMouseWheelEvent&>(*input_event), processed);
1205 }
1206
[email protected]721e2302014-04-30 23:42:011207 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061208
charliea3be839702015-01-26 17:35:411209 // If we don't have a fast and accurate Now(), we assume the input handlers
1210 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301211 bool rate_limiting_wanted =
1212 input_event->type == WebInputEvent::MouseMove ||
1213 input_event->type == WebInputEvent::MouseWheel;
1214 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411215 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351216 total_input_handling_time_this_frame_ += (end_time - start_time);
1217 rate_limiting_wanted =
1218 total_input_handling_time_this_frame_.InMicroseconds() >
1219 kInputHandlingTimeThrottlingThresholdMicroseconds;
1220 }
1221
[email protected]7f19e9d2014-05-09 15:16:291222 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1223
[email protected]c27dd4f2014-05-22 18:05:191224 // Note that we can't use handling_event_type_ here since it will be overriden
1225 // by reentrant calls for events after the paused one.
1226 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1227 input_event->type == WebInputEvent::MouseMove;
1228 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) {
[email protected]8e431f2032014-05-20 02:34:561229 InputHostMsg_HandleInputEvent_ACK_Params ack;
1230 ack.type = input_event->type;
1231 ack.state = ack_result;
1232 ack.latency = swap_latency_info;
[email protected]34afe102013-12-13 17:24:551233 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561234 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301235 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551236 // We want to rate limit the input events in this case, so we'll wait for
1237 // painting to finish before ACKing this message.
1238 TRACE_EVENT_INSTANT0("renderer",
1239 "RenderWidget::OnHandleInputEvent ack throttled",
1240 TRACE_EVENT_SCOPE_THREAD);
1241 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291242 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1243 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551244 // As two different kinds of events could cause us to postpone an ack
1245 // we send it now, if we have one pending. The Browser should never
1246 // send us the same kind of event we are delaying the ack for.
1247 Send(pending_input_event_ack_.release());
1248 }
1249 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291250 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1251 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551252 if (compositor_)
1253 compositor_->NotifyInputThrottledUntilCommit();
1254 } else {
1255 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171256 }
[email protected]12fbad812009-09-01 18:21:241257 }
[email protected]5fea4a52014-05-27 00:17:521258 if (input_event->type == WebInputEvent::MouseMove)
1259 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241260
[email protected]3306f262012-09-21 19:20:421261#if defined(OS_ANDROID)
1262 // Allow the IME to be shown when the focus changes as a consequence
1263 // of a processed touch end event.
1264 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361265 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021266#elif defined(USE_AURA)
1267 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1268 // change.
1269 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141270 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361271 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141272 }
[email protected]3306f262012-09-21 19:20:421273#endif
1274
[email protected]67bfb83f2011-09-22 03:36:371275 if (!prevent_default) {
1276 if (WebInputEvent::isKeyboardEventType(input_event->type))
1277 DidHandleKeyEvent();
1278 if (WebInputEvent::isMouseEventType(input_event->type))
1279 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241280 if (WebInputEvent::isTouchEventType(input_event->type))
1281 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[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) {
1306 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331307 if (webwidget_)
1308 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291309}
1310
1311void RenderWidget::ClearFocus() {
1312 // We may have got the focus from the browser before this gets processed, in
1313 // which case we do not want to unfocus ourself.
1314 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281315 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291316}
1317
[email protected]fd847792013-10-24 17:12:351318void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291319 if (pending_input_event_ack_) {
1320 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1321 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071322 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291323 }
[email protected]fd847792013-10-24 17:12:351324 total_input_handling_time_this_frame_ = base::TimeDelta();
1325}
1326
initial.commit09911bf2008-07-26 23:55:291327///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461328// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291329
[email protected]244ac1892011-12-02 17:04:471330void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091331 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451332 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581333
[email protected]5b45ad42013-10-25 00:42:041334 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451335 WebRect new_pos(rootWindowRect().x,
1336 rootWindowRect().y,
1337 new_size.width,
1338 new_size.height);
1339 view_screen_rect_ = new_pos;
1340 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031341 }
[email protected]20fbfc22013-05-08 20:50:581342
[email protected]eac2b362013-05-22 07:01:451343 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581344
[email protected]5b45ad42013-10-25 00:42:041345 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581346 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091347 }
[email protected]244ac1892011-12-02 17:04:471348}
1349
[email protected]3a1c8a8032013-03-18 22:35:321350void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051351 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1352 device_scale_factor_));
1353 if (compositor_)
1354 compositor_->setViewportSize(size_, physical_backing_size_);
1355}
1356
[email protected]e195e582013-03-08 01:32:591357void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221358 DCHECK(!host_closing_);
1359
danakj6e3bf8012014-12-16 18:27:531360 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591361 compositor_->setViewportSize(size_, physical_backing_size_);
1362 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031363 StartCompositor();
[email protected]e195e582013-03-08 01:32:591364}
1365
ennef3c58142014-12-09 21:44:381366void RenderWidget::WillCloseLayerTreeView() {
1367 if (host_closing_)
1368 return;
1369
1370 // Prevent new compositors or output surfaces from being created.
1371 host_closing_ = true;
1372
[email protected]aeeedad2014-08-22 18:16:221373 // Always send this notification to prevent new layer tree views from
1374 // being created, even if one hasn't been created yet.
1375 if (webwidget_)
1376 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221377}
1378
[email protected]180ef242013-11-07 06:50:461379blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281380 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061381}
1382
[email protected]9cd43a62012-03-26 08:03:561383void RenderWidget::willBeginCompositorFrame() {
1384 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371385
[email protected]abe8b3a2012-03-28 21:19:371386 // The following two can result in further layout and possibly
1387 // enable GPU acceleration so they need to be called before any painting
1388 // is done.
shuchen3517bb62014-10-15 03:55:571389 UpdateTextInputType();
1390#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361391 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571392#endif
[email protected]abe8b3a2012-03-28 21:19:371393 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561394}
1395
[email protected]3391a0772012-03-28 00:32:071396void RenderWidget::didBecomeReadyForAdditionalInput() {
1397 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351398 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071399}
1400
[email protected]6fceb912013-02-15 06:24:151401void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441402 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1403 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271404 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161405 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171406#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271407 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1408 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171409#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151410}
1411
[email protected]586871b2014-07-22 17:05:111412// static
1413scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1414 IPC::Message* msg,
1415 MessageDeliveryPolicy policy,
1416 FrameSwapMessageQueue* frame_swap_message_queue,
1417 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111418 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111419 bool first_message_for_frame = false;
1420 frame_swap_message_queue->QueueMessageForFrame(policy,
1421 source_frame_number,
1422 make_scoped_ptr(msg),
1423 &first_message_for_frame);
1424 if (first_message_for_frame) {
1425 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1426 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061427 return promise;
[email protected]586871b2014-07-22 17:05:111428 }
dcheng4b6b5ff2014-10-16 00:42:061429 return nullptr;
[email protected]586871b2014-07-22 17:05:111430}
1431
1432void RenderWidget::QueueMessage(IPC::Message* msg,
1433 MessageDeliveryPolicy policy) {
1434 // RenderThreadImpl::current() is NULL in some tests.
1435 if (!compositor_ || !RenderThreadImpl::current()) {
1436 Send(msg);
1437 return;
1438 }
1439
1440 scoped_ptr<cc::SwapPromise> swap_promise =
1441 QueueMessageImpl(msg,
1442 policy,
dcheng58867a92014-08-26 02:50:221443 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111444 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111445 compositor_->GetSourceFrameNumber());
1446
1447 if (swap_promise) {
1448 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351449 // Request a commit. This might either A) request a commit ahead of time
1450 // or B) request a commit which is not needed because there are not
1451 // pending updates. If B) then the commit will be skipped and the swap
1452 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1453 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1454 // can_cancel_commit is not unset.
1455 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111456 }
1457}
1458
[email protected]58264a32011-11-17 23:36:151459void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101460 // NOTE: Tests may break if this event is renamed or moved. See
1461 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501462 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161463 // Notify subclasses that we initiated the paint operation.
1464 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151465}
1466
1467void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181468 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1469
1470 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561471 DidFlushPaint();
1472
[email protected]ea3ee0a2012-05-15 03:43:091473 if (!next_paint_flags_ &&
1474 !need_update_rect_for_auto_resize_ &&
1475 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151476 return;
[email protected]ea3ee0a2012-05-15 03:43:091477 }
[email protected]58264a32011-11-17 23:36:151478
1479 ViewHostMsg_UpdateRect_Params params;
1480 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151481 params.plugin_window_moves.swap(plugin_window_moves_);
1482 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151483
1484 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1485 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091486 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151487}
1488
[email protected]8b9e52b2014-01-17 16:35:311489void RenderWidget::scheduleComposite() {
danakj6e3bf8012014-12-16 18:27:531490 if (compositor_ &&
1491 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
[email protected]e221f9f2014-05-13 02:47:221492 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311493 }
1494}
1495
[email protected]4873c7d2009-07-16 06:36:281496void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301497 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521498 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401499 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291500 // Only send a SetCursor message if we need to make a change.
1501 if (!current_cursor_.IsEqual(cursor)) {
1502 current_cursor_ = cursor;
1503 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1504 }
1505}
1506
1507// We are supposed to get a single call to Show for a newly created RenderWidget
1508// that was created via RenderWidget::CreateWebView. So, we wait until this
1509// point to dispatch the ShowWidget message.
1510//
1511// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281512// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291513//
[email protected]4873c7d2009-07-16 06:36:281514void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291515 DCHECK(!did_show_) << "received extraneous Show call";
1516 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1517 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1518
[email protected]8de12d942010-11-17 20:42:441519 if (did_show_)
1520 return;
1521
1522 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561523 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441524 // that's okay. It'll be ignored if as_popup is false, or the browser
1525 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561526 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1527 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291528}
1529
[email protected]4873c7d2009-07-16 06:36:281530void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291531}
1532
[email protected]4873c7d2009-07-16 06:36:281533void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291534}
1535
[email protected]2533ce12009-05-09 00:02:241536void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381537 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241538 Send(new ViewHostMsg_Close(routing_id_));
1539}
1540
dgozmancf9039cd2015-04-06 12:01:311541void RenderWidget::NotifyOnClose() {
1542 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1543}
1544
[email protected]4873c7d2009-07-16 06:36:281545void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321546 if (is_swapped_out_) {
1547 // This widget is currently swapped out, and the active widget is in a
1548 // different process. Have the browser route the close request to the
1549 // active widget instead, so that the correct unload handlers are run.
1550 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1551 return;
1552 }
1553
initial.commit09911bf2008-07-26 23:55:291554 // If a page calls window.close() twice, we'll end up here twice, but that's
1555 // OK. It is safe to send multiple Close messages.
1556
[email protected]2533ce12009-05-09 00:02:241557 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1558 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1559 // could be closed before the JS finishes executing. So instead, post a
1560 // message back to the message loop, which won't run until the JS is
1561 // complete, and then the Close message can be sent.
alexclarkee19d4ef2015-01-09 17:45:401562 RenderThread::Get()->GetTaskRunner()->PostTask(
[email protected]32876ae2011-11-15 22:25:211563 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291564}
1565
[email protected]9017d7852013-11-21 17:47:351566void RenderWidget::QueueSyntheticGesture(
1567 scoped_ptr<SyntheticGestureParams> gesture_params,
1568 const SyntheticGestureCompletionCallback& callback) {
1569 DCHECK(!callback.is_null());
1570
1571 pending_synthetic_gesture_callbacks_.push(callback);
1572
1573 SyntheticGesturePacket gesture_packet;
1574 gesture_packet.set_gesture_params(gesture_params.Pass());
1575
1576 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1577}
1578
initial.commit09911bf2008-07-26 23:55:291579void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031580 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381581 WillCloseLayerTreeView();
1582 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291583 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281584 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291585 webwidget_ = NULL;
1586 }
1587}
1588
[email protected]4873c7d2009-07-16 06:36:281589WebRect RenderWidget::windowRect() {
1590 if (pending_window_rect_count_)
1591 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241592
[email protected]80ad8622012-11-07 16:33:031593 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291594}
1595
[email protected]180ef242013-11-07 06:50:461596void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301597 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541598 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301599}
1600
[email protected]b2e4c70132013-10-03 02:07:511601void RenderWidget::setWindowRect(const WebRect& rect) {
bokanc007c3a2015-02-03 07:15:561602 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511603 if (popup_origin_scale_for_emulation_) {
1604 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561605 window_rect.x = popup_screen_origin_for_emulation_.x() +
1606 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1607 window_rect.y = popup_screen_origin_for_emulation_.y() +
1608 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511609 }
1610
[email protected]5b45ad42013-10-25 00:42:041611 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201612 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561613 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1614 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031615 } else {
bokanc007c3a2015-02-03 07:15:561616 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031617 }
initial.commit09911bf2008-07-26 23:55:291618 } else {
bokanc007c3a2015-02-03 07:15:561619 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291620 }
1621}
1622
[email protected]2533ce12009-05-09 00:02:241623void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1624 pending_window_rect_ = rect;
1625 pending_window_rect_count_++;
1626}
1627
[email protected]4873c7d2009-07-16 06:36:281628WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241629 if (pending_window_rect_count_) {
1630 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1631 // the RootWindowRect is probably going to return wrong results since the
1632 // browser may not have processed the Move yet. There isn't really anything
1633 // good to do in this case, and it shouldn't happen - since this size is
1634 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281635 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241636 }
1637
[email protected]80ad8622012-11-07 16:33:031638 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371639}
1640
[email protected]4873c7d2009-07-16 06:36:281641WebRect RenderWidget::windowResizerRect() {
1642 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191643}
1644
[email protected]fa7b1dc2010-06-23 17:53:041645void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031646 // To prevent this renderer process from sending unnecessary IPC messages to
1647 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041648 // only during the input method attached to the browser process is active.
1649 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291650}
1651
[email protected]37a241c2013-12-03 03:16:171652void RenderWidget::OnCandidateWindowShown() {
1653 webwidget_->didShowCandidateWindow();
1654}
1655
1656void RenderWidget::OnCandidateWindowUpdated() {
1657 webwidget_->didUpdateCandidateWindow();
1658}
1659
1660void RenderWidget::OnCandidateWindowHidden() {
1661 webwidget_->didHideCandidateWindow();
1662}
1663
[email protected]fa7b1dc2010-06-23 17:53:041664void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261665 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041666 const std::vector<WebCompositionUnderline>& underlines,
1667 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131668 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281669 return;
[email protected]66fca5bc2013-05-23 06:58:291670 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361671 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041672 text, WebVector<WebCompositionUnderline>(underlines),
1673 selection_start, selection_end)) {
1674 // If we failed to set the composition text, then we need to let the browser
1675 // process to cancel the input method's ongoing composition session, to make
1676 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221677 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261678 }
[email protected]88dbe32f2013-06-20 23:31:361679 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041680}
1681
[email protected]fcf75d42013-12-03 20:11:261682void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511683 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021684 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131685 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041686 return;
[email protected]66fca5bc2013-05-23 06:58:291687 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041688 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021689 if (text.length())
1690 webwidget_->confirmComposition(text);
1691 else if (keep_selection)
1692 webwidget_->confirmComposition(WebWidget::KeepSelection);
1693 else
1694 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041695 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361696 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291697}
1698
[email protected]0bc1f572013-04-17 01:46:311699void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121700 // During shutdown we can just ignore this message.
1701 if (!webwidget_)
1702 return;
1703
[email protected]0bc1f572013-04-17 01:46:311704 // Even if the browser provides an empty damage rect, it's still expecting to
1705 // receive a repaint ack so just damage the entire widget bounds.
1706 if (size_to_paint.IsEmpty()) {
1707 size_to_paint = size_;
1708 }
1709
[email protected]ec7dc112008-08-06 05:30:121710 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051711 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311712 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121713}
1714
[email protected]79fa22e2013-08-23 15:18:121715void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351716 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1717
1718 pending_synthetic_gesture_callbacks_.front().Run();
1719 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271720}
1721
[email protected]4873c7d2009-07-16 06:36:281722void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111723 if (!webwidget_)
1724 return;
[email protected]4873c7d2009-07-16 06:36:281725 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111726}
1727
[email protected]80ad8622012-11-07 16:33:031728void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1729 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511730 if (screen_metrics_emulator_) {
1731 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1732 view_screen_rect, window_screen_rect);
1733 } else {
1734 view_screen_rect_ = view_screen_rect;
1735 window_screen_rect_ = window_screen_rect;
1736 }
[email protected]80ad8622012-11-07 16:33:031737 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1738}
1739
[email protected]adb362312014-06-28 06:04:241740void RenderWidget::showImeIfNeeded() {
1741 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131742}
1743
[email protected]adb362312014-06-28 06:04:241744void RenderWidget::OnShowImeIfNeeded() {
1745#if defined(OS_ANDROID) || defined(USE_AURA)
1746 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1747#endif
rouslanf7ebd8832015-01-22 01:54:141748
1749// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1750// virtual keyboard.
1751#if !defined(OS_ANDROID)
1752 FocusChangeComplete();
1753#endif
[email protected]adb362312014-06-28 06:04:241754}
1755
1756#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131757void RenderWidget::IncrementOutstandingImeEventAcks() {
1758 ++outstanding_ime_acks_;
1759}
1760
1761void RenderWidget::OnImeEventAck() {
1762 --outstanding_ime_acks_;
1763 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511764}
[email protected]105dffb42013-02-20 03:46:211765#endif
1766
[email protected]0d1ebed12013-08-05 22:01:131767bool RenderWidget::ShouldHandleImeEvent() {
1768#if defined(OS_ANDROID)
1769 return !!webwidget_ && outstanding_ime_acks_ == 0;
1770#else
1771 return !!webwidget_;
1772#endif
1773}
1774
[email protected]c27dd4f2014-05-22 18:05:191775bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1776 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521777 // If we pause multiple times during a single mouse move event, we should
1778 // only send ACK once.
1779 if (!ignore_ack_for_mouse_move_from_debugger_) {
1780 InputHostMsg_HandleInputEvent_ACK_Params ack;
1781 ack.type = handling_event_type_;
1782 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED;
1783 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dgozmanb739185d2015-04-10 15:04:021784 return true;
[email protected]5fea4a52014-05-27 00:17:521785 }
[email protected]c27dd4f2014-05-22 18:05:191786 }
1787 return false;
1788}
1789
1790void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1791 ignore_ack_for_mouse_move_from_debugger_ = true;
1792}
1793
[email protected]468ac582012-11-20 00:53:191794void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1795 if (device_scale_factor_ == device_scale_factor)
1796 return;
1797
1798 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051799 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191800}
1801
[email protected]28ed6b32014-06-08 02:16:271802bool RenderWidget::SetDeviceColorProfile(
1803 const std::vector<char>& color_profile) {
1804 if (device_color_profile_ == color_profile)
1805 return false;
1806
1807 device_color_profile_ = color_profile;
1808 return true;
1809}
1810
noeldb4df152014-09-16 17:45:201811void RenderWidget::ResetDeviceColorProfileForTesting() {
1812 if (!device_color_profile_.empty())
1813 device_color_profile_.clear();
1814 device_color_profile_.push_back('0');
1815}
1816
[email protected]fcdc5642014-05-09 14:32:241817void RenderWidget::OnOrientationChange() {
1818}
1819
[email protected]ceb36f7d2012-10-31 18:33:241820gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521821 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241822 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521823}
1824
[email protected]bee16aab2009-08-26 15:55:031825void RenderWidget::SetHidden(bool hidden) {
1826 if (is_hidden_ == hidden)
1827 return;
1828
jdduke8fac9d102014-12-20 02:40:131829 // The status has changed. Tell the RenderThread about it and ensure
1830 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031831 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131832 FlushPendingInputEventAck();
1833
[email protected]bee16aab2009-08-26 15:55:031834 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001835 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031836 else
[email protected]b2db9272014-01-10 17:42:001837 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031838}
1839
[email protected]2b624c562011-10-27 22:58:261840void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261841 if (!webwidget_)
1842 return;
1843
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121844 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261845 webwidget_->willExitFullScreen();
1846 } else {
1847 webwidget_->willEnterFullScreen();
1848 }
[email protected]2b624c562011-10-27 22:58:261849}
1850
1851void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261852 if (!webwidget_)
1853 return;
1854
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121855 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261856 webwidget_->didEnterFullScreen();
1857 } else {
1858 webwidget_->didExitFullScreen();
1859 }
[email protected]2b624c562011-10-27 22:58:261860}
1861
[email protected]674741932009-02-04 23:44:461862bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051863 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461864}
1865
[email protected]674741932009-02-04 23:44:461866void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051867 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461868}
1869
[email protected]674741932009-02-04 23:44:461870void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051871 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461872}
1873
[email protected]b18583c2012-12-18 06:55:271874static bool IsDateTimeInput(ui::TextInputType type) {
1875 return type == ui::TEXT_INPUT_TYPE_DATE ||
1876 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1877 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1878 type == ui::TEXT_INPUT_TYPE_MONTH ||
1879 type == ui::TEXT_INPUT_TYPE_TIME ||
1880 type == ui::TEXT_INPUT_TYPE_WEEK;
1881}
1882
[email protected]66fca5bc2013-05-23 06:58:291883
1884void RenderWidget::StartHandlingImeEvent() {
1885 DCHECK(!handling_ime_event_);
1886 handling_ime_event_ = true;
1887}
1888
1889void RenderWidget::FinishHandlingImeEvent() {
1890 DCHECK(handling_ime_event_);
1891 handling_ime_event_ = false;
1892 // While handling an ime event, text input state and selection bounds updates
1893 // are ignored. These must explicitly be updated once finished handling the
1894 // ime event.
1895 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471896#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361897 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471898#endif
[email protected]66fca5bc2013-05-23 06:58:291899}
1900
shuchen3517bb62014-10-15 03:55:571901void RenderWidget::UpdateTextInputType() {
1902 // On Windows, not only an IME but also an on-screen keyboard relies on the
1903 // latest TextInputType to optimize its layout and functionality. Thus
1904 // |input_method_is_active_| is no longer an appropriate condition to suppress
1905 // TextInputTypeChanged IPC on Windows.
1906 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1907 // on other platforms as well as Windows if the overhead is acceptable.
1908#if !defined(OS_WIN)
1909 if (!input_method_is_active_)
1910 return;
1911#endif
1912
1913 ui::TextInputType new_type = GetTextInputType();
1914 if (IsDateTimeInput(new_type))
1915 return; // Not considered as a text input field in WebKit/Chromium.
1916
1917 bool new_can_compose_inline = CanComposeInline();
1918
1919 blink::WebTextInputInfo new_info;
1920 if (webwidget_)
1921 new_info = webwidget_->textInputInfo();
1922 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201923 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571924
1925 if (text_input_type_ != new_type
1926 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201927 || text_input_mode_ != new_mode
1928 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571929 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1930 new_type,
1931 new_mode,
shuchen82ce8c52014-10-23 01:55:201932 new_can_compose_inline,
1933 new_flags));
shuchen3517bb62014-10-15 03:55:571934 text_input_type_ = new_type;
1935 can_compose_inline_ = new_can_compose_inline;
1936 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201937 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571938 }
1939}
1940
1941#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361942void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1943 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501944 if (handling_ime_event_)
1945 return;
[email protected]90f24152014-04-09 12:41:361946 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291947 return;
[email protected]ad26ef42011-06-17 07:59:451948 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271949 if (IsDateTimeInput(new_type))
1950 return; // Not considered as a text input field in WebKit/Chromium.
1951
[email protected]180ef242013-11-07 06:50:461952 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211953 if (webwidget_)
1954 new_info = webwidget_->textInputInfo();
1955
[email protected]ad26ef42011-06-17 07:59:451956 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211957
[email protected]3306f262012-09-21 19:20:421958 // Only sends text input params if they are changed or if the ime should be
1959 // shown.
[email protected]90f24152014-04-09 12:41:361960 if (show_ime == SHOW_IME_IF_NEEDED ||
1961 (text_input_type_ != new_type ||
1962 text_input_info_ != new_info ||
1963 can_compose_inline_ != new_can_compose_inline)
1964#if defined(OS_ANDROID)
1965 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021966#endif
[email protected]90f24152014-04-09 12:41:361967 ) {
1968 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211969 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401970 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211971 p.value = new_info.value.utf8();
1972 p.selection_start = new_info.selectionStart;
1973 p.selection_end = new_info.selectionEnd;
1974 p.composition_start = new_info.compositionStart;
1975 p.composition_end = new_info.compositionEnd;
1976 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361977 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1978#if defined(USE_AURA)
1979 p.is_non_ime_change = true;
1980#endif
[email protected]183e28d2014-01-20 18:18:021981#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361982 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1983 text_field_is_dirty_;
1984 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131985 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361986 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021987#endif
shuchen3517bb62014-10-15 03:55:571988#if defined(USE_AURA)
1989 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1990 new_type,
1991 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:201992 new_can_compose_inline,
1993 new_info.flags));
shuchen3517bb62014-10-15 03:55:571994#endif
[email protected]5b739cb2012-08-21 20:35:211995 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1996
1997 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041998 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451999 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:202000 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:292001 }
initial.commit09911bf2008-07-26 23:55:292002}
shuchen3517bb62014-10-15 03:55:572003#endif
initial.commit09911bf2008-07-26 23:55:292004
[email protected]7c8873e2013-02-05 08:03:012005void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2006 WebRect focus_webrect;
2007 WebRect anchor_webrect;
2008 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2009 *focus = focus_webrect;
2010 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322011}
2012
[email protected]e99ef6f2011-10-16 01:13:002013void RenderWidget::UpdateSelectionBounds() {
2014 if (!webwidget_)
2015 return;
[email protected]66fca5bc2013-05-23 06:58:292016 if (handling_ime_event_)
2017 return;
[email protected]e99ef6f2011-10-16 01:13:002018
jddukeacf809e2014-09-23 20:38:382019 // With composited selection updates, the selection bounds will be reported
2020 // directly by the compositor, in which case explicit IPC selection
2021 // notifications should be suppressed.
2022 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
2023 ViewHostMsg_SelectionBounds_Params params;
2024 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2025 if (selection_anchor_rect_ != params.anchor_rect ||
2026 selection_focus_rect_ != params.focus_rect) {
2027 selection_anchor_rect_ = params.anchor_rect;
2028 selection_focus_rect_ = params.focus_rect;
2029 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2030 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2031 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2032 }
[email protected]58b48a0d2012-06-13 07:01:352033 }
jddukeacf809e2014-09-23 20:38:382034
[email protected]88dbe32f2013-06-20 23:31:362035 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002036}
2037
[email protected]180ef242013-11-07 06:50:462038// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172039#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2040 static_assert(int(blink::WebTextInputType##a) \
2041 == int(ui::TEXT_INPUT_TYPE_##b), \
2042 "mismatching enums: " #a)
2043
2044STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2045STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2046STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2047STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2048STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2049STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2050STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2051STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2052STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2053STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2054STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2055STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2056STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2057STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2058STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2059STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2060STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452061
[email protected]5b739cb2012-08-21 20:35:212062ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462063 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212064 // Check the type is in the range representable by ui::TextInputType.
2065 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462066 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212067 return static_cast<ui::TextInputType>(type);
2068}
2069
[email protected]ad26ef42011-06-17 07:59:452070ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272071 if (webwidget_)
2072 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452073 return ui::TEXT_INPUT_TYPE_NONE;
2074}
2075
[email protected]501ea13d2013-07-09 17:03:292076void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302077#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112078 // TODO(yukawa): Start sending character bounds when the browser side
2079 // implementation becomes ready (crbug.com/424866).
2080#else
[email protected]db4fc1e2013-09-06 20:01:512081 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292082 if (should_update_range) {
2083 GetCompositionRange(&range);
2084 } else {
2085 range = composition_range_;
2086 }
2087 std::vector<gfx::Rect> character_bounds;
2088 GetCompositionCharacterBounds(&character_bounds);
2089
2090 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2091 return;
2092 composition_character_bounds_ = character_bounds;
2093 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222094 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292095 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112096#endif
[email protected]501ea13d2013-07-09 17:03:292097}
2098
[email protected]58b48a0d2012-06-13 07:01:352099void RenderWidget::GetCompositionCharacterBounds(
2100 std::vector<gfx::Rect>* bounds) {
2101 DCHECK(bounds);
2102 bounds->clear();
2103}
2104
[email protected]db4fc1e2013-09-06 20:01:512105void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362106 size_t location, length;
2107 if (webwidget_->compositionRange(&location, &length)) {
2108 range->set_start(location);
2109 range->set_end(location + length);
2110 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2111 range->set_start(location);
2112 range->set_end(location + length);
2113 } else {
[email protected]db4fc1e2013-09-06 20:01:512114 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362115 }
2116}
2117
[email protected]501ea13d2013-07-09 17:03:292118bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512119 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292120 const std::vector<gfx::Rect>& bounds) {
2121 if (composition_range_ != range)
2122 return true;
2123 if (bounds.size() != composition_character_bounds_.size())
2124 return true;
2125 for (size_t i = 0; i < bounds.size(); ++i) {
2126 if (bounds[i] != composition_character_bounds_[i])
2127 return true;
2128 }
2129 return false;
2130}
[email protected]501ea13d2013-07-09 17:03:292131
[email protected]a4f0d882014-05-01 23:48:102132#if defined(OS_ANDROID)
2133void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2134 // If not initialized, default to white. Note that 0 is different from black
2135 // as black still has alpha 0xFF.
2136 if (!bg_color)
2137 bg_color = SK_ColorWHITE;
2138
2139 if (bg_color != body_background_color_) {
2140 body_background_color_ = bg_color;
2141 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2142 }
2143}
timav7a5032e2014-12-05 01:59:432144
2145bool RenderWidget::DoesRecordFullLayer() const {
2146 SynchronousCompositorFactory* synchronous_compositor_factory =
2147 SynchronousCompositorFactory::GetInstance();
2148
2149 // We assume that the absence of synchronous_compositor_factory
2150 // means we are in Chrome. In chrome, we want to clip, i.e.
2151 // *not* to record the full layer.
2152 if (!synchronous_compositor_factory)
2153 return false;
2154
2155 return synchronous_compositor_factory->RecordFullLayer();
2156}
[email protected]a4f0d882014-05-01 23:48:102157#endif
2158
[email protected]ad26ef42011-06-17 07:59:452159bool RenderWidget::CanComposeInline() {
2160 return true;
[email protected]56ea1a62011-05-30 07:05:572161}
2162
[email protected]4873c7d2009-07-16 06:36:282163WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042164 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282165}
2166
[email protected]f660d9c2012-06-06 18:31:212167float RenderWidget::deviceScaleFactor() {
2168 return device_scale_factor_;
2169}
2170
[email protected]fa7b1dc2010-06-23 17:53:042171void RenderWidget::resetInputMethod() {
2172 if (!input_method_is_active_)
2173 return;
2174
[email protected]0e45bd02013-07-12 20:20:022175 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042176 // If the last text input type is not None, then we should finish any
2177 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452178 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042179 // If a composition text exists, then we need to let the browser process
2180 // to cancel the input method's ongoing composition session.
2181 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222182 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042183 }
[email protected]d4cff272011-05-02 15:46:012184
[email protected]88dbe32f2013-06-20 23:31:362185 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042186}
2187
donnda070f3c2015-01-16 19:54:112188#if defined(OS_ANDROID)
2189void RenderWidget::showUnhandledTapUIIfNeeded(
2190 const WebPoint& tapped_position,
2191 const WebNode& tapped_node,
2192 bool page_changed) {
2193 DCHECK(handling_input_event_);
2194 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372195 !tapped_node.isContentEditable() &&
2196 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112197 if (should_trigger) {
2198 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2199 tapped_position.x, tapped_position.y));
2200 }
2201}
2202#endif
2203
[email protected]c68c3e4e2013-01-24 00:36:562204void RenderWidget::didHandleGestureEvent(
2205 const WebGestureEvent& event,
2206 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022207#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562208 if (event_cancelled)
2209 return;
[email protected]07c70d22014-08-21 08:33:462210 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362211 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462212 } else if (event.type == WebInputEvent::GestureLongPress) {
2213 DCHECK(webwidget_);
2214 if (webwidget_->textInputInfo().value.isEmpty())
2215 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2216 else
2217 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562218 }
2219#endif
2220}
2221
[email protected]7912e822014-04-16 02:37:032222void RenderWidget::StartCompositor() {
2223 // For widgets that are never visible, we don't need the compositor to run
2224 // at all.
2225 if (never_visible_)
2226 return;
danakj6e3bf8012014-12-16 18:27:532227 // In tests without a RenderThreadImpl, don't set ready as this kicks
2228 // off creating output surfaces that the test can't create.
2229 if (!RenderThreadImpl::current())
2230 return;
danakj018271e32014-12-16 21:17:262231 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032232}
2233
[email protected]29e2fb42013-07-19 01:13:472234void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292235 size_t i = 0;
2236 for (; i < plugin_window_moves_.size(); ++i) {
2237 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582238 if (move.rects_valid) {
2239 plugin_window_moves_[i] = move;
2240 } else {
2241 plugin_window_moves_[i].visible = move.visible;
2242 }
initial.commit09911bf2008-07-26 23:55:292243 break;
2244 }
2245 }
2246
2247 if (i == plugin_window_moves_.size())
2248 plugin_window_moves_.push_back(move);
2249}
[email protected]268654772009-08-06 23:02:042250
2251void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2252 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2253 i != plugin_window_moves_.end(); ++i) {
2254 if (i->window == window) {
2255 plugin_window_moves_.erase(i);
2256 break;
2257 }
2258 }
2259}
[email protected]67bfb83f2011-09-22 03:36:372260
[email protected]63b465922012-09-06 02:04:522261
[email protected]24ed0432013-04-24 07:50:312262RenderWidgetCompositor* RenderWidget::compositor() const {
2263 return compositor_.get();
2264}
2265
[email protected]180ef242013-11-07 06:50:462266bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372267 return false;
2268}
[email protected]c3d45532011-10-07 19:20:402269
[email protected]41d86852012-11-07 12:23:242270bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462271 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242272 return false;
2273}
2274
ccamerona7644752014-12-30 01:16:312275void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312276 const blink::WebMouseWheelEvent& wheel_event,
2277 bool event_processed) {
ccamerona7644752014-12-30 01:16:312278 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312279 return;
2280
2281 // Blink does not accurately compute scroll bubbling or overscroll. For now,
2282 // assume that an unprocessed event was entirely an overscroll, and that a
2283 // processed event was entirely scroll.
2284 // TODO(ccameron): Retrieve an accurate scroll result from Blink.
2285 // http://crbug.com/442859
2286 cc::InputHandlerScrollResult scroll_result;
2287 if (event_processed) {
2288 scroll_result.did_scroll = true;
2289 } else {
2290 scroll_result.did_overscroll_root = true;
2291 scroll_result.unused_scroll_delta =
2292 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY);
2293 }
2294
2295 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2296 InputHandlerManager* input_handler_manager =
2297 render_thread ? render_thread->input_handler_manager() : NULL;
2298 if (input_handler_manager) {
2299 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2300 routing_id_, wheel_event, scroll_result);
2301 }
2302}
2303
[email protected]ce6689f2013-03-29 12:52:552304void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2305 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2306}
2307
mostynbe29b6882015-01-13 09:59:172308// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2309#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2310 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2311 "mismatching enums: " #a)
2312
[email protected]5d0bbdfa92013-12-10 00:35:512313void RenderWidget::setTouchAction(
2314 blink::WebTouchAction web_touch_action) {
2315
2316 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2317 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192318 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512319 return;
2320
[email protected]a18f67a2013-12-20 19:44:362321 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172322 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2323 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
2324 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
2325 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2326 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362327
2328 content::TouchAction content_touch_action =
2329 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512330 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2331}
2332
[email protected]90f24152014-04-09 12:41:362333void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2334#if defined(OS_ANDROID)
2335 text_field_is_dirty_ = true;
2336#endif
2337}
2338
[email protected]3d5c243b2012-11-30 00:26:012339bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2340 return true;
2341}
2342
[email protected]0634cdd42013-08-16 00:46:092343scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132344RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592345 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092346 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492347 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222348 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092349 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292350 if (!RenderThreadImpl::current())
2351 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402352 CauseForGpuLaunch cause =
2353 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292354 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402355 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222356 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292357 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592358
[email protected]828a3932014-04-02 14:43:132359 // Explicitly disable antialiasing for the compositor. As of the time of
2360 // this writing, the only platform that supported antialiasing for the
2361 // compositor was Mac OS X, because the on-screen OpenGL context creation
2362 // code paths on Windows and Linux didn't yet have multisampling support.
2363 // Mac OS X essentially always behaves as though it's rendering offscreen.
2364 // Multisampling has a heavy cost especially on devices with relatively low
2365 // fill rate like most notebooks, and the Mac implementation would need to
2366 // be optimized to resolve directly into the IOSurface shared between the
2367 // GPU and browser processes. For these reasons and to avoid platform
2368 // disparities we explicitly disable antialiasing.
2369 blink::WebGraphicsContext3D::Attributes attributes;
2370 attributes.antialias = false;
2371 attributes.shareResources = true;
2372 attributes.noAutomaticFlushes = true;
2373 attributes.depth = false;
2374 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132375 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292376 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012377#if defined(OS_ANDROID)
2378 // If we raster too fast we become upload bound, and pending
2379 // uploads consume memory. For maximum upload throughput, we would
2380 // want to allow for upload_throughput * pipeline_time of pending
2381 // uploads, after which we are just wasting memory. Since we don't
2382 // know our upload throughput yet, this just caps our memory usage.
2383 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272384 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032385 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012386 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032387 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012388 // Deadline to draw a frame to achieve 60 frames per second.
2389 const size_t kMillisecondsPerFrame = 16;
2390 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032391 size_t max_transfer_buffer_usage_mb =
2392 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2393 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012394 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2395 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292396 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032397 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012398#endif
[email protected]96ab016c2013-10-23 00:50:292399
[email protected]96ab016c2013-10-23 00:50:292400 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132401 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2402 GetURLForGraphicsContext3D(),
2403 gpu_channel_host.get(),
2404 attributes,
[email protected]828a3932014-04-02 14:43:132405 lose_context_when_out_of_memory,
2406 limits,
2407 NULL));
[email protected]0634cdd42013-08-16 00:46:092408 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592409}
2410
[email protected]e3244ed2014-06-20 20:04:272411void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2412 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162413}
2414
[email protected]e3244ed2014-06-20 20:04:272415void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2416 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162417}
2418
[email protected]de3c5d82014-05-28 22:12:592419void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2420 render_frames_.AddObserver(frame);
2421}
2422
2423void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2424 render_frames_.RemoveObserver(frame);
2425}
2426
[email protected]a017938b2014-05-27 21:17:172427#if defined(VIDEO_HOLE)
2428void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2429 video_hole_frames_.AddObserver(frame);
2430}
2431
2432void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2433 video_hole_frames_.RemoveObserver(frame);
2434}
2435#endif // defined(VIDEO_HOLE)
2436
[email protected]e9ff79c2012-10-19 21:31:262437} // namespace content