blob: a22d374e6f796eb808d1c81c466c72b6cef5fc5e [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"
[email protected]366ae242011-05-10 02:23:5810#include "base/debug/trace_event.h"
[email protected]b2e92592014-01-10 15:47:1511#include "base/debug/trace_event_synthetic_delay.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4014#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3015#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2117#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0018#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2719#include "base/sys_info.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"
donnda070f3c2015-01-16 19:54:1164#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3165#include "third_party/WebKit/public/web/WebPagePopup.h"
66#include "third_party/WebKit/public/web/WebPopupMenu.h"
67#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
68#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3869#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
[email protected]d353541f2012-05-03 22:45:4170#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1371#include "ui/base/ui_base_switches.h"
[email protected]de2cf8c2013-10-25 19:46:4672#include "ui/gfx/frame_time.h"
tfarina655f81d2014-12-23 02:38:5073#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0974#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3275#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4876#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2777#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4178#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4879
[email protected]eeb93112013-05-01 19:41:1080#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1581#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0782#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1083#endif
84
[email protected]661eb9d2009-02-03 02:11:4885#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4986#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5287#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4188#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4889#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4490
[email protected]2255a9332013-06-17 05:12:3191#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2992
[email protected]180ef242013-11-07 06:50:4693using blink::WebCompositionUnderline;
94using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4395using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4696using blink::WebGestureEvent;
97using blink::WebInputEvent;
98using blink::WebKeyboardEvent;
99using blink::WebMouseEvent;
100using blink::WebMouseWheelEvent;
101using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11102using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46103using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11104using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46105using blink::WebPopupMenu;
106using blink::WebPopupMenuInfo;
107using blink::WebPopupType;
108using blink::WebRange;
109using blink::WebRect;
110using blink::WebScreenInfo;
111using blink::WebSize;
112using blink::WebTextDirection;
113using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25114using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46115using blink::WebVector;
116using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26117
[email protected]6a4d7f62013-01-07 21:32:13118namespace {
[email protected]b256eca2013-07-11 10:57:40119
120typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
121
122class TextInputModeMapSingleton {
123 public:
124 static TextInputModeMapSingleton* GetInstance() {
125 return Singleton<TextInputModeMapSingleton>::get();
126 }
[email protected]dd705d4d2013-11-27 08:14:41127 TextInputModeMapSingleton() {
128 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
129 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
130 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
131 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
132 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
133 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
134 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
135 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
136 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
137 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
138 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40139 }
[email protected]dd705d4d2013-11-27 08:14:41140 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40141 private:
[email protected]dd705d4d2013-11-27 08:14:41142 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40143
144 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
145
146 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
147};
148
[email protected]dd705d4d2013-11-27 08:14:41149ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40150 static TextInputModeMapSingleton* singleton =
151 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41152 TextInputModeMap::const_iterator it =
153 singleton->map().find(input_mode.utf8());
154 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40155 return ui::TEXT_INPUT_MODE_DEFAULT;
156 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13157}
[email protected]b256eca2013-07-11 10:57:40158
[email protected]fd847792013-10-24 17:12:35159// TODO(brianderson): Replace the hard-coded threshold with a fraction of
160// the BeginMainFrame interval.
161// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
162// be spent in input hanlders before input starts getting throttled.
163const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
164
jdduke07788062014-12-05 03:16:30165int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) {
166 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds))
167 .ToInternalValue();
168}
169
170void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now) {
171 UMA_HISTOGRAM_CUSTOM_COUNTS(
172 "Event.AggregatedLatency.Renderer2",
173 GetEventLatencyMicros(event, now),
174 1,
175 10000000,
176 100);
177
178#define CASE_TYPE(t) \
179 case WebInputEvent::t: \
180 UMA_HISTOGRAM_CUSTOM_COUNTS( \
181 "Event.Latency.Renderer2." #t, \
182 GetEventLatencyMicros(event, now), \
183 1, \
184 10000000, \
185 100); \
186 break;
187
188 switch(event.type) {
189 CASE_TYPE(Undefined);
190 CASE_TYPE(MouseDown);
191 CASE_TYPE(MouseUp);
192 CASE_TYPE(MouseMove);
193 CASE_TYPE(MouseEnter);
194 CASE_TYPE(MouseLeave);
195 CASE_TYPE(ContextMenu);
196 CASE_TYPE(MouseWheel);
197 CASE_TYPE(RawKeyDown);
198 CASE_TYPE(KeyDown);
199 CASE_TYPE(KeyUp);
200 CASE_TYPE(Char);
201 CASE_TYPE(GestureScrollBegin);
202 CASE_TYPE(GestureScrollEnd);
203 CASE_TYPE(GestureScrollUpdate);
204 CASE_TYPE(GestureFlingStart);
205 CASE_TYPE(GestureFlingCancel);
206 CASE_TYPE(GestureShowPress);
207 CASE_TYPE(GestureTap);
208 CASE_TYPE(GestureTapUnconfirmed);
209 CASE_TYPE(GestureTapDown);
210 CASE_TYPE(GestureTapCancel);
211 CASE_TYPE(GestureDoubleTap);
212 CASE_TYPE(GestureTwoFingerTap);
213 CASE_TYPE(GestureLongPress);
214 CASE_TYPE(GestureLongTap);
215 CASE_TYPE(GesturePinchBegin);
216 CASE_TYPE(GesturePinchEnd);
217 CASE_TYPE(GesturePinchUpdate);
218 CASE_TYPE(TouchStart);
219 CASE_TYPE(TouchMove);
220 CASE_TYPE(TouchEnd);
221 CASE_TYPE(TouchCancel);
222 default:
223 // Must include default to let blink::WebInputEvent add new event types
224 // before they're added here.
225 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event.type;
226 break;
227 }
228
229#undef CASE_TYPE
230}
231
[email protected]b256eca2013-07-11 10:57:40232} // namespace
233
[email protected]e9ff79c2012-10-19 21:31:26234namespace content {
[email protected]62cb33cae2009-03-27 23:30:22235
[email protected]b2e4c70132013-10-03 02:07:51236// RenderWidget::ScreenMetricsEmulator ----------------------------------------
237
238class RenderWidget::ScreenMetricsEmulator {
239 public:
240 ScreenMetricsEmulator(
241 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43242 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51243 virtual ~ScreenMetricsEmulator();
244
[email protected]19193682014-04-03 15:01:43245 // Scale and offset used to convert between host coordinates
246 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51247 float scale() { return scale_; }
[email protected]9a2d7ee32013-12-05 12:15:49248 gfx::Point offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43249 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51250 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56251 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51252
253 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43254 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51255
256 // The following methods alter handlers' behavior for messages related to
257 // widget size and position.
258 void OnResizeMessage(const ViewMsg_Resize_Params& params);
259 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
260 const gfx::Rect& window_screen_rect);
261 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31262 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51263
264 private:
[email protected]19193682014-04-03 15:01:43265 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02266 void Apply(bool top_controls_shrink_blink_size,
267 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44268 gfx::Rect resizer_rect,
269 bool is_fullscreen);
[email protected]b2e4c70132013-10-03 02:07:51270
271 RenderWidget* widget_;
272
[email protected]7f99fc22013-11-08 14:05:58273 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43274 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51275
[email protected]a179d3962013-11-12 14:44:40276 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51277 float scale_;
[email protected]a179d3962013-11-12 14:44:40278 gfx::Point offset_;
[email protected]b2e4c70132013-10-03 02:07:51279
[email protected]19193682014-04-03 15:01:43280 // Widget rect as passed to webwidget.
281 gfx::Rect applied_widget_rect_;
282
[email protected]b2e4c70132013-10-03 02:07:51283 // Original values to restore back after emulation ends.
284 gfx::Size original_size_;
285 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28286 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46287 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51288 gfx::Rect original_view_screen_rect_;
289 gfx::Rect original_window_screen_rect_;
290};
291
292RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
293 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43294 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51295 : widget_(widget),
[email protected]19193682014-04-03 15:01:43296 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51297 scale_(1.f) {
298 original_size_ = widget_->size_;
299 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28300 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51301 original_screen_info_ = widget_->screen_info_;
302 original_view_screen_rect_ = widget_->view_screen_rect_;
303 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02304 Apply(widget_->top_controls_shrink_blink_size_,
305 widget_->top_controls_height_,
306 widget_->resizer_rect_,
307 widget_->is_fullscreen_);
[email protected]b2e4c70132013-10-03 02:07:51308}
309
310RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
311 widget_->screen_info_ = original_screen_info_;
312
313 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
[email protected]7f99fc22013-11-08 14:05:58314 widget_->SetScreenMetricsEmulationParameters(0.f, gfx::Point(), 1.f);
[email protected]b2e4c70132013-10-03 02:07:51315 widget_->view_screen_rect_ = original_view_screen_rect_;
316 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01317 widget_->Resize(original_size_,
318 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02319 widget_->top_controls_shrink_blink_size_,
320 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01321 original_visible_viewport_size_,
322 widget_->resizer_rect_,
323 widget_->is_fullscreen_,
324 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51325}
326
327void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43328 const WebDeviceEmulationParams& params) {
329 params_ = params;
330 Reapply();
331}
332
333void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02334 Apply(widget_->top_controls_shrink_blink_size_,
335 widget_->top_controls_height_,
336 widget_->resizer_rect_,
337 widget_->is_fullscreen_);
[email protected]b2e4c70132013-10-03 02:07:51338}
339
[email protected]19193682014-04-03 15:01:43340void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02341 bool top_controls_shrink_blink_size,
342 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44343 gfx::Rect resizer_rect,
344 bool is_fullscreen) {
[email protected]92d13b72014-05-09 14:42:31345 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
346 if (!applied_widget_rect_.width())
347 applied_widget_rect_.set_width(original_size_.width());
348 if (!applied_widget_rect_.height())
349 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43350
[email protected]f442ee42014-05-14 11:53:12351 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02352 int original_width = std::max(original_size_.width(), 1);
353 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51354 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02355 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51356 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02357 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51358 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
359 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01360
361 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43362 offset_.set_x(
363 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01364 offset_.set_y(
[email protected]19193682014-04-03 15:01:43365 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51366 } else {
[email protected]0b3578c2014-06-20 18:29:02367 scale_ = params_.scale;
368 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01369 }
[email protected]7f0e8fa2014-03-26 12:32:01370
[email protected]19193682014-04-03 15:01:43371 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
372 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01373 widget_->screen_info_.rect = original_screen_info_.rect;
374 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
375 widget_->window_screen_rect_ = original_window_screen_rect_;
376 } else {
[email protected]19193682014-04-03 15:01:43377 applied_widget_rect_.set_origin(gfx::Point(0, 0));
378 widget_->screen_info_.rect = applied_widget_rect_;
379 widget_->screen_info_.availableRect = applied_widget_rect_;
380 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01381 }
[email protected]a179d3962013-11-12 14:44:40382
[email protected]19193682014-04-03 15:01:43383 float applied_device_scale_factor = params_.deviceScaleFactor ?
384 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01385 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51386
[email protected]7f99fc22013-11-08 14:05:58387 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51388 // - we keep the real device scale factor in compositor to produce sharp image
389 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58390 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51391 // root layer.
392 widget_->SetScreenMetricsEmulationParameters(
[email protected]a179d3962013-11-12 14:44:40393 original_screen_info_.deviceScaleFactor, offset_, scale_);
[email protected]b2e4c70132013-10-03 02:07:51394
[email protected]7f0e8fa2014-03-26 12:32:01395 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43396 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51397
398 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
399 original_size_, original_screen_info_.deviceScaleFactor));
dtrainorcb7779b82014-12-04 01:08:02400 widget_->Resize(applied_widget_rect_.size(),
401 physical_backing_size,
402 top_controls_shrink_blink_size,
403 top_controls_height,
404 applied_widget_rect_.size(),
405 resizer_rect,
406 is_fullscreen,
407 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51408}
409
410void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
411 const ViewMsg_Resize_Params& params) {
412 bool need_ack = params.new_size != original_size_ &&
413 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
414 original_size_ = params.new_size;
415 original_physical_backing_size_ = params.physical_backing_size;
416 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28417 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02418 Apply(params.top_controls_shrink_blink_size,
419 params.top_controls_height,
420 params.resizer_rect,
421 params.is_fullscreen);
[email protected]b2e4c70132013-10-03 02:07:51422
423 if (need_ack) {
424 widget_->set_next_paint_is_resize_ack();
425 if (widget_->compositor_)
426 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
427 }
428}
429
430void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
431 const gfx::Rect& view_screen_rect,
432 const gfx::Rect& window_screen_rect) {
433 original_view_screen_rect_ = view_screen_rect;
434 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43435 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
436 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51437}
438
439void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
440 ContextMenuParams* params) {
441 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40442 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51443 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40444 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51445}
446
[email protected]2d6836f42014-07-02 17:25:31447gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
448 const gfx::Rect& anchor) {
449 gfx::Rect scaled = gfx::ToEnclosedRect(gfx::ScaleRect(anchor, scale_));
450 scaled.set_x(scaled.x() + offset_.x());
451 scaled.set_y(scaled.y() + offset_.y());
452 return scaled;
453}
454
[email protected]b2e4c70132013-10-03 02:07:51455// RenderWidget ---------------------------------------------------------------
456
[email protected]180ef242013-11-07 06:50:46457RenderWidget::RenderWidget(blink::WebPopupType popup_type,
458 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04459 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03460 bool hidden,
461 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29462 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56463 surface_id_(0),
danakj6e3bf8012014-12-16 18:27:53464 compositor_deps_(nullptr),
465 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29466 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30467 init_complete_(false),
dtrainorcb7779b82014-12-04 01:08:02468 top_controls_shrink_blink_size_(false),
469 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29470 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51471 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09472 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29473 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04474 is_hidden_(hidden),
[email protected]7912e822014-04-16 02:37:03475 never_visible_(never_visible),
[email protected]ee41e7d22011-10-14 19:34:09476 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29477 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49478 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50479 handling_ime_event_(false),
[email protected]c27dd4f2014-05-22 18:05:19480 handling_event_type_(WebInputEvent::Undefined),
481 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48482 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22483 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44484 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04485 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45486 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40487 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20488 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53489 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12490 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48491 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12492 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04493 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52494 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]8062ab262014-05-27 16:56:43495 current_event_latency_info_(NULL),
[email protected]53b4cc12013-07-18 23:02:30496 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13497#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36498 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13499 outstanding_ime_acks_(0),
[email protected]a4f0d882014-05-01 23:48:10500 body_background_color_(SK_ColorWHITE),
[email protected]0d1ebed12013-08-05 22:01:13501#endif
[email protected]b2e4c70132013-10-03 02:07:51502 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11503 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42504 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51505 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
506 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05507 if (!swapped_out)
508 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27509 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53510 device_color_profile_.push_back('0');
initial.commit09911bf2008-07-26 23:55:29511}
512
513RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11514 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16515
[email protected]992db4c2011-05-12 15:37:15516 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02517 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15518 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29519}
520
[email protected]484955942010-08-19 16:13:18521// static
[email protected]8085dbc82008-09-26 22:53:44522RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53523 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46524 blink::WebPopupType popup_type,
525 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29526 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41527 scoped_refptr<RenderWidget> widget(
[email protected]7912e822014-04-16 02:37:03528 new RenderWidget(popup_type, screen_info, false, false, false));
danakj6e3bf8012014-12-16 18:27:53529 if (widget->Init(opener_id, compositor_deps)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46530 return widget.get();
[email protected]a635f942012-12-07 10:34:29531 }
532 return NULL;
initial.commit09911bf2008-07-26 23:55:29533}
534
[email protected]484955942010-08-19 16:13:18535// static
cmumford04094bf2015-01-21 22:07:24536WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18537 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46538 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18539 break;
[email protected]180ef242013-11-07 06:50:46540 case blink::WebPopupTypeSelect:
541 case blink::WebPopupTypeSuggestion:
[email protected]484955942010-08-19 16:13:18542 return WebPopupMenu::create(render_widget);
[email protected]180ef242013-11-07 06:50:46543 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44544 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18545 default:
546 NOTREACHED();
547 }
548 return NULL;
549}
550
danakj6e3bf8012014-12-16 18:27:53551bool RenderWidget::Init(int32 opener_id,
552 CompositorDependencies* compositor_deps) {
553 return DoInit(opener_id, compositor_deps, RenderWidget::CreateWebWidget(this),
[email protected]a635f942012-12-07 10:34:29554 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
555 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18556}
557
[email protected]a635f942012-12-07 10:34:29558bool RenderWidget::DoInit(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53559 CompositorDependencies* compositor_deps,
[email protected]6a8ddba52010-09-05 04:38:06560 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18561 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29562 DCHECK(!webwidget_);
563
564 if (opener_id != MSG_ROUTING_NONE)
565 opener_id_ = opener_id;
566
danakj6e3bf8012014-12-16 18:27:53567 compositor_deps_ = compositor_deps;
[email protected]484955942010-08-19 16:13:18568 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29569
cmumford04094bf2015-01-21 22:07:24570 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29571 if (result) {
[email protected]380244092011-10-07 17:26:27572 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29573 // Take a reference on behalf of the RenderThread. This will be balanced
574 // when we receive ViewMsg_Close.
575 AddRef();
[email protected]b2db9272014-01-10 17:42:00576 if (RenderThreadImpl::current()) {
577 RenderThreadImpl::current()->WidgetCreated();
578 if (is_hidden_)
579 RenderThreadImpl::current()->WidgetHidden();
580 }
[email protected]a635f942012-12-07 10:34:29581 return true;
initial.commit09911bf2008-07-26 23:55:29582 } else {
[email protected]a635f942012-12-07 10:34:29583 // The above Send can fail when the tab is closing.
584 return false;
initial.commit09911bf2008-07-26 23:55:29585 }
586}
587
[email protected]fc4404d2012-11-07 19:53:30588// This is used to complete pending inits and non-pending inits.
589void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29590 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29591
[email protected]fc4404d2012-11-07 19:53:30592 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42593
[email protected]7912e822014-04-16 02:37:03594 if (compositor_)
595 StartCompositor();
initial.commit09911bf2008-07-26 23:55:29596
[email protected]6de74452009-02-25 18:04:59597 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29598}
599
[email protected]992db4c2011-05-12 15:37:15600void RenderWidget::SetSwappedOut(bool is_swapped_out) {
601 // We should only toggle between states.
602 DCHECK(is_swapped_out_ != is_swapped_out);
603 is_swapped_out_ = is_swapped_out;
604
605 // If we are swapping out, we will call ReleaseProcess, allowing the process
606 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52607 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15608 // If we are swapping in, we call AddRefProcess to prevent the process from
609 // exiting.
[email protected]949b6592014-08-20 13:17:52610 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15611 RenderProcess::current()->AddRefProcess();
612}
613
[email protected]949b6592014-08-20 13:17:52614void RenderWidget::WasSwappedOut() {
615 // If we have been swapped out and no one else is using this process,
616 // it's safe to exit now.
617 CHECK(is_swapped_out_);
618 RenderProcess::current()->ReleaseProcess();
619}
620
[email protected]b2e4c70132013-10-03 02:07:51621void RenderWidget::EnableScreenMetricsEmulation(
[email protected]19193682014-04-03 15:01:43622 const WebDeviceEmulationParams& params) {
623 if (!screen_metrics_emulator_)
624 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
625 else
626 screen_metrics_emulator_->ChangeEmulationParams(params);
[email protected]b2e4c70132013-10-03 02:07:51627}
628
629void RenderWidget::DisableScreenMetricsEmulation() {
630 screen_metrics_emulator_.reset();
631}
632
633void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
634 ScreenMetricsEmulator* emulator) {
635 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43636 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49637 popup_screen_origin_for_emulation_ = gfx::Point(
638 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
639 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56640 screen_info_ = emulator->original_screen_info();
641 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51642}
643
[email protected]2d6836f42014-07-02 17:25:31644gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
645 if (screen_metrics_emulator_)
646 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
647 return anchor;
648}
649
[email protected]b2e4c70132013-10-03 02:07:51650void RenderWidget::SetScreenMetricsEmulationParameters(
[email protected]7f99fc22013-11-08 14:05:58651 float device_scale_factor,
652 const gfx::Point& root_layer_offset,
653 float root_layer_scale) {
[email protected]b2e4c70132013-10-03 02:07:51654 // This is only supported in RenderView.
655 NOTREACHED();
656}
657
[email protected]53907862014-03-25 15:42:40658#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51659void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
660 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49661 popup->SetOriginScaleAndOffsetForEmulation(
662 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51663}
[email protected]53907862014-03-25 15:42:40664#endif
[email protected]b2e4c70132013-10-03 02:07:51665
666void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
667 if (screen_metrics_emulator_)
668 screen_metrics_emulator_->OnShowContextMenu(params);
669}
670
[email protected]7d08a9352013-10-15 08:24:56671void RenderWidget::ScheduleCompositeWithForcedRedraw() {
672 if (compositor_) {
673 // Regardless of whether threaded compositing is enabled, always
674 // use this mechanism to force the compositor to redraw. However,
675 // the invalidation code path below is still needed for the
676 // non-threaded case.
677 compositor_->SetNeedsForcedRedraw();
678 }
[email protected]8b9e52b2014-01-17 16:35:31679 scheduleComposite();
[email protected]7d08a9352013-10-15 08:24:56680}
681
[email protected]a95986a82010-12-24 06:19:28682bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
683 bool handled = true;
684 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15685 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22686 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
687 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22688 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
689 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15690 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
691 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35692 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
693 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28694 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
695 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
696 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
noel89949e62014-09-30 01:12:41697 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54698 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28699 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41700 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]a95986a82010-12-24 06:19:28701 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
[email protected]37a241c2013-12-03 03:16:17702 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowShown, OnCandidateWindowShown)
703 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowUpdated,
704 OnCandidateWindowUpdated)
705 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowHidden, OnCandidateWindowHidden)
[email protected]3d9ec5052013-01-02 22:05:25706 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28707 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
708 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03709 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21710#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51711 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13712 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21713#endif
[email protected]a95986a82010-12-24 06:19:28714 IPC_MESSAGE_UNHANDLED(handled = false)
715 IPC_END_MESSAGE_MAP()
716 return handled;
717}
initial.commit09911bf2008-07-26 23:55:29718
719bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15720 // Don't send any messages after the browser has told us to close, and filter
721 // most outgoing messages while swapped out.
722 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26723 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11724 closing_) {
initial.commit09911bf2008-07-26 23:55:29725 delete message;
726 return false;
727 }
728
729 // If given a messsage without a routing ID, then assign our routing ID.
730 if (message->routing_id() == MSG_ROUTING_NONE)
731 message->set_routing_id(routing_id_);
732
[email protected]380244092011-10-07 17:26:27733 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44734}
735
[email protected]61e2b3cc2012-03-02 16:13:34736void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44737 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02738 bool top_controls_shrink_blink_size,
739 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44740 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34741 const gfx::Rect& resizer_rect,
742 bool is_fullscreen,
743 ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56744 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48745 // A resize ack shouldn't be requested if we have not ACK'd the previous
746 // one.
747 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
748 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
749 }
initial.commit09911bf2008-07-26 23:55:29750
[email protected]61e2b3cc2012-03-02 16:13:34751 // Ignore this during shutdown.
752 if (!webwidget_)
753 return;
754
[email protected]d9083762013-03-24 01:36:40755 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44756 compositor_->setViewportSize(new_size, physical_backing_size);
dtrainorcb7779b82014-12-04 01:08:02757 compositor_->SetTopControlsShrinkBlinkSize(top_controls_shrink_blink_size);
758 compositor_->SetTopControlsHeight(top_controls_height);
[email protected]d9083762013-03-24 01:36:40759 }
[email protected]60d47ac2013-03-01 23:42:44760
[email protected]dade8992013-03-04 07:34:34761 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02762 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
763 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28764 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34765 resizer_rect_ = resizer_rect;
766
767 // NOTE: We may have entered fullscreen mode without changing our size.
768 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
769 if (fullscreen_change)
770 WillToggleFullscreen();
771 is_fullscreen_ = is_fullscreen;
772
dtrainorcb7779b82014-12-04 01:08:02773 webwidget_->setTopControlsLayoutHeight(top_controls_shrink_blink_size_
774 ? top_controls_height : 0.f);
bokan0c93cd82014-09-30 19:20:43775
[email protected]61e2b3cc2012-03-02 16:13:34776 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34777 size_ = new_size;
778
[email protected]61e2b3cc2012-03-02 16:13:34779 // When resizing, we want to wait to paint before ACK'ing the resize. This
780 // ensures that we only resize as fast as we can paint. We only need to
781 // send an ACK if we are resized to a non-empty rect.
782 webwidget_->resize(new_size);
[email protected]5b45ad42013-10-25 00:42:04783 } else if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]632c4382013-05-15 08:58:45784 resize_ack = NO_RESIZE_ACK;
785 }
786
[email protected]bb6378fe2014-04-28 21:19:44787 webwidget()->resizePinchViewport(gfx::Size(
788 visible_viewport_size.width(),
789 visible_viewport_size.height()));
790
[email protected]632c4382013-05-15 08:58:45791 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
792 // For empty size or empty physical_backing_size, there is no next paint
793 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35794 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34795 }
796
[email protected]20fbfc22013-05-08 20:50:58797 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45798 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58799 set_next_paint_is_resize_ack();
800
[email protected]61e2b3cc2012-03-02 16:13:34801 if (fullscreen_change)
802 DidToggleFullscreen();
803
804 // If a resize ack is requested and it isn't set-up, then no more resizes will
805 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45806 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29807}
808
bokanf0fd2412014-10-30 15:28:55809void RenderWidget::ResizeSynchronously(
810 const gfx::Rect& new_position,
811 const gfx::Size& visible_viewport_size) {
[email protected]587941d2014-08-22 01:40:01812 Resize(new_position.size(),
813 new_position.size(),
dtrainorcb7779b82014-12-04 01:08:02814 top_controls_shrink_blink_size_,
815 top_controls_height_,
bokanf0fd2412014-10-30 15:28:55816 visible_viewport_size,
[email protected]587941d2014-08-22 01:40:01817 gfx::Rect(),
818 is_fullscreen_,
819 NO_RESIZE_ACK);
[email protected]92650162013-10-30 03:31:02820 view_screen_rect_ = new_position;
821 window_screen_rect_ = new_position;
822 if (!did_show_)
823 initial_pos_ = new_position;
824}
825
initial.commit09911bf2008-07-26 23:55:29826void RenderWidget::OnClose() {
827 if (closing_)
828 return;
829 closing_ = true;
830
831 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03832 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]b2db9272014-01-10 17:42:00833 if (RenderThreadImpl::current())
834 RenderThreadImpl::current()->WidgetDestroyed();
[email protected]380244092011-10-07 17:26:27835 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03836 SetHidden(false);
837 }
initial.commit09911bf2008-07-26 23:55:29838
initial.commit09911bf2008-07-26 23:55:29839 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25840 // now. Post a task that only gets invoked when there are no nested message
841 // loops.
alexclarkee19d4ef2015-01-09 17:45:40842 RenderThread::Get()->GetTaskRunner()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29843 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25844
845 // Balances the AddRef taken when we called AddRoute.
846 Release();
initial.commit09911bf2008-07-26 23:55:29847}
848
[email protected]61e2b3cc2012-03-02 16:13:34849// Got a response from the browser after the renderer decided to create a new
850// view.
[email protected]fc4404d2012-11-07 19:53:30851void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34852 DCHECK(routing_id_ != MSG_ROUTING_NONE);
853
[email protected]fc4404d2012-11-07 19:53:30854 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34855}
856
[email protected]0fdd5012013-05-29 08:05:56857void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04858 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32859 return;
860
[email protected]b2e4c70132013-10-03 02:07:51861 if (screen_metrics_emulator_) {
862 screen_metrics_emulator_->OnResizeMessage(params);
863 return;
864 }
865
[email protected]fcdc5642014-05-09 14:32:24866 bool orientation_changed =
867 screen_info_.orientationAngle != params.screen_info.orientationAngle;
868
[email protected]0fdd5012013-05-29 08:05:56869 screen_info_ = params.screen_info;
870 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02871 Resize(params.new_size,
872 params.physical_backing_size,
873 params.top_controls_shrink_blink_size,
874 params.top_controls_height,
875 params.visible_viewport_size,
876 params.resizer_rect,
877 params.is_fullscreen,
878 SEND_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24879
880 if (orientation_changed)
881 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29882}
883
noel89949e62014-09-30 01:12:41884void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
885 SetDeviceColorProfile(color_profile);
886}
887
[email protected]b5913d72012-02-07 22:26:54888void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01889 if (resizer_rect_ == resizer_rect)
890 return;
891 resizer_rect_ = resizer_rect;
892 if (webwidget_)
893 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54894}
895
initial.commit09911bf2008-07-26 23:55:29896void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31897 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29898 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03899 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59900 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
901 WasHidden());
initial.commit09911bf2008-07-26 23:55:29902}
903
[email protected]3399dd822014-08-09 11:14:24904void RenderWidget::OnWasShown(bool needs_repainting,
905 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41906 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29907 // During shutdown we can just ignore this message.
908 if (!webwidget_)
909 return;
910
911 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03912 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59913 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
914 WasShown());
initial.commit09911bf2008-07-26 23:55:29915
[email protected]8a23afb32014-04-30 22:40:23916 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29917 return;
initial.commit09911bf2008-07-26 23:55:29918
919 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24920 if (compositor_) {
921 ui::LatencyInfo swap_latency_info(latency_info);
922 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
923 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05924 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24925 }
[email protected]aca33f4f2014-05-17 17:08:05926 scheduleComposite();
initial.commit09911bf2008-07-26 23:55:29927}
928
[email protected]53d3f302009-12-21 04:42:05929void RenderWidget::OnRequestMoveAck() {
930 DCHECK(pending_window_rect_count_);
931 pending_window_rect_count_--;
932}
933
[email protected]ed7defa2013-03-12 21:29:59934GURL RenderWidget::GetURLForGraphicsContext3D() {
935 return GURL();
[email protected]65225772011-05-12 21:10:24936}
937
[email protected]ebc0e1df2013-08-01 02:46:22938scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03939 // For widgets that are never visible, we don't start the compositor, so we
940 // never get a request for a cc::OutputSurface.
941 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19942
943#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01944 if (SynchronousCompositorFactory* factory =
945 SynchronousCompositorFactory::GetInstance()) {
[email protected]586871b2014-07-22 17:05:11946 return factory->CreateOutputSurface(routing_id(),
947 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:19948 }
949#endif
950
avi83883c82014-12-23 00:08:49951 const base::CommandLine& command_line =
952 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33953 bool use_software = fallback;
954 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
955 use_software = true;
956
[email protected]0634cdd42013-08-16 00:46:09957 scoped_refptr<ContextProviderCommandBuffer> context_provider;
[email protected]e09994a2014-03-26 19:59:33958 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09959 context_provider = ContextProviderCommandBuffer::Create(
[email protected]828a3932014-04-02 14:43:13960 CreateGraphicsContext3D(), "RenderCompositor");
[email protected]e09994a2014-03-26 19:59:33961 if (!context_provider.get()) {
962 // Cause the compositor to wait and try again.
963 return scoped_ptr<cc::OutputSurface>();
964 }
[email protected]0634cdd42013-08-16 00:46:09965 }
[email protected]ebc0e1df2013-08-01 02:46:22966
[email protected]b6eb8e332013-09-10 00:51:01967 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:00968 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:53969 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
[email protected]65a33ce2014-03-25 22:37:09970 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:11971 new DelegatedCompositorOutputSurface(routing_id(),
972 output_surface_id,
973 context_provider,
974 frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09975 }
[email protected]0634cdd42013-08-16 00:46:09976 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:09977 scoped_ptr<cc::SoftwareOutputDevice> software_device(
978 new CompositorSoftwareOutputDevice());
979
[email protected]586871b2014-07-22 17:05:11980 return scoped_ptr<cc::OutputSurface>(
981 new CompositorOutputSurface(routing_id(),
982 output_surface_id,
983 NULL,
984 software_device.Pass(),
985 frame_swap_message_queue_,
986 true));
[email protected]ebc0e1df2013-08-01 02:46:22987 }
[email protected]ed7defa2013-03-12 21:29:59988
[email protected]36e5ff12013-06-11 12:19:29989 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:45990 // Composite-to-mailbox is currently used for layout tests in order to cause
991 // them to draw inside in the renderer to do the readback there. This should
992 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:53993 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:16994 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:27995 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:16996 format = cc::RGB_565;
[email protected]36e5ff12013-06-11 12:19:29997 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:11998 new MailboxOutputSurface(routing_id(),
999 output_surface_id,
1000 context_provider,
1001 scoped_ptr<cc::SoftwareOutputDevice>(),
1002 frame_swap_message_queue_,
1003 format));
[email protected]36e5ff12013-06-11 12:19:291004 }
[email protected]0634cdd42013-08-16 00:46:091005 bool use_swap_compositor_frame_message = false;
[email protected]36e5ff12013-06-11 12:19:291006 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:111007 new CompositorOutputSurface(routing_id(),
1008 output_surface_id,
1009 context_provider,
1010 scoped_ptr<cc::SoftwareOutputDevice>(),
1011 frame_swap_message_queue_,
1012 use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281013}
1014
[email protected]4d7e46a2013-11-08 05:33:401015void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241016 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241017 // Schedule another frame so the compositor learns about it.
[email protected]8b9e52b2014-01-17 16:35:311018 scheduleComposite();
[email protected]65225772011-05-12 21:10:241019}
1020
[email protected]4d7e46a2013-11-08 05:33:401021void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081022 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081023}
1024
[email protected]4d7e46a2013-11-08 05:33:401025void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241026 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161027
[email protected]404939f2012-06-01 04:06:181028 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161029 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291030}
1031
[email protected]180ef242013-11-07 06:50:461032void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351033 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091034 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191035 base::AutoReset<bool> handling_input_event_resetter(
1036 &handling_input_event_, true);
1037 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291038 return;
[email protected]c27dd4f2014-05-22 18:05:191039 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1040 &handling_event_type_, input_event->type);
[email protected]25402eb2014-07-18 03:09:521041#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541042 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521043 // |AdapterInputConnection| generates input key events to make sure all JS
1044 // listeners that monitor KeyUp and KeyDown events receive the proper key
1045 // code. Since this input key event comes from IME, we need to set the
1046 // IME event guard here to make sure it does not interfere with other IME
1047 // events.
1048 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1049 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1050 const WebKeyboardEvent& key_event =
1051 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541052 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171053 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091054 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1055 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1056 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1057 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1058 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521059 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521060 }
1061#endif
initial.commit09911bf2008-07-26 23:55:291062
[email protected]8062ab262014-05-27 16:56:431063 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1064 &latency_info);
1065
[email protected]fd847792013-10-24 17:12:351066 base::TimeTicks start_time;
1067 if (base::TimeTicks::IsHighResNowFastAndReliable())
1068 start_time = base::TimeTicks::HighResNow();
1069
[email protected]b4841e1c2013-05-16 22:30:101070 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301071 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151072 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131073 TRACE_EVENT_FLOW_STEP0(
1074 "input",
1075 "LatencyInfo.Flow",
1076 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1077 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101078
jdduke07788062014-12-05 03:16:301079 // If we don't have a high res timer, these metrics won't be accurate enough
1080 // to be worth collecting. Note that this does introduce some sampling bias.
1081 if (!start_time.is_null())
1082 LogInputEventLatencyUma(*input_event, start_time);
1083
[email protected]6be422b2013-12-08 06:47:311084 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351085 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311086 if (compositor_) {
1087 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351088 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1089 .Pass();
[email protected]6be422b2013-12-08 06:47:311090 }
[email protected]c2eaa8f2013-05-10 02:41:551091
[email protected]67bfb83f2011-09-22 03:36:371092 bool prevent_default = false;
1093 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261094 const WebMouseEvent& mouse_event =
1095 *static_cast<const WebMouseEvent*>(input_event);
1096 TRACE_EVENT2("renderer", "HandleMouseMove",
1097 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421098 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261099 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371100 }
1101
[email protected]cefe9b152014-03-27 18:16:151102 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421103 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151104#if defined(OS_ANDROID)
1105 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1106 // case it should behave like a select key (i.e. causing a click if a button
1107 // is focused). However, if a text field is focused (2), its intended
1108 // behavior is to just show the IME and don't propagate the key.
1109 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1110 // when clicked on an input text field and cause the form submit if clicked
1111 // when the submit button is focused, but not vice-versa.
1112 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1113 // but at this point we have to swallow the event for the scenario (2).
1114 const WebKeyboardEvent& key_event =
1115 *static_cast<const WebKeyboardEvent*>(input_event);
1116 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1117 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1118 OnShowImeIfNeeded();
1119 prevent_default = true;
1120 }
1121#endif
1122 }
[email protected]f56c7872013-06-18 12:31:571123
[email protected]41d86852012-11-07 12:23:241124 if (WebInputEvent::isGestureEventType(input_event->type)) {
1125 const WebGestureEvent& gesture_event =
1126 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421127 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241128 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1129 }
1130
[email protected]67bfb83f2011-09-22 03:36:371131 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121132 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1133 suppress_next_char_events_ = false;
1134 if (!processed && webwidget_)
1135 processed = webwidget_->handleInputEvent(*input_event);
1136 }
1137
1138 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1139 // it's not processed by webkit, then we need to suppress the upcoming Char
1140 // events.
1141 if (!processed && is_keyboard_shortcut)
1142 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291143
[email protected]3d5c243b2012-11-30 00:26:011144 InputEventAckState ack_result = processed ?
1145 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1146 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1147 const WebTouchEvent& touch_event =
1148 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251149 // Hit-test for all the pressed touch points. If there is a touch-handler
1150 // for any of the touch points, then the renderer should continue to receive
1151 // touch events.
1152 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1153 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1154 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271155 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391156 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251157 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1158 break;
1159 }
1160 }
[email protected]3d5c243b2012-11-30 00:26:011161 }
1162
ccamerond4ba47902014-12-17 07:20:311163 // Send mouse wheel events and their disposition to the compositor thread, so
1164 // that they can be used to produce the elastic overscroll effect on Mac.
1165 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311166 ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:311167 static_cast<const WebMouseWheelEvent&>(*input_event), processed);
1168 }
1169
[email protected]721e2302014-04-30 23:42:011170 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061171
[email protected]fd847792013-10-24 17:12:351172 // If we don't have a fast and accurate HighResNow, we assume the input
1173 // handlers are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301174 bool rate_limiting_wanted =
1175 input_event->type == WebInputEvent::MouseMove ||
1176 input_event->type == WebInputEvent::MouseWheel;
1177 if (rate_limiting_wanted && !start_time.is_null()) {
[email protected]fd847792013-10-24 17:12:351178 base::TimeTicks end_time = base::TimeTicks::HighResNow();
1179 total_input_handling_time_this_frame_ += (end_time - start_time);
1180 rate_limiting_wanted =
1181 total_input_handling_time_this_frame_.InMicroseconds() >
1182 kInputHandlingTimeThrottlingThresholdMicroseconds;
1183 }
1184
[email protected]7f19e9d2014-05-09 15:16:291185 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1186
[email protected]c27dd4f2014-05-22 18:05:191187 // Note that we can't use handling_event_type_ here since it will be overriden
1188 // by reentrant calls for events after the paused one.
1189 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1190 input_event->type == WebInputEvent::MouseMove;
1191 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) {
[email protected]8e431f2032014-05-20 02:34:561192 InputHostMsg_HandleInputEvent_ACK_Params ack;
1193 ack.type = input_event->type;
1194 ack.state = ack_result;
1195 ack.latency = swap_latency_info;
[email protected]34afe102013-12-13 17:24:551196 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561197 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301198 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551199 // We want to rate limit the input events in this case, so we'll wait for
1200 // painting to finish before ACKing this message.
1201 TRACE_EVENT_INSTANT0("renderer",
1202 "RenderWidget::OnHandleInputEvent ack throttled",
1203 TRACE_EVENT_SCOPE_THREAD);
1204 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291205 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1206 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551207 // As two different kinds of events could cause us to postpone an ack
1208 // we send it now, if we have one pending. The Browser should never
1209 // send us the same kind of event we are delaying the ack for.
1210 Send(pending_input_event_ack_.release());
1211 }
1212 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291213 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1214 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551215 if (compositor_)
1216 compositor_->NotifyInputThrottledUntilCommit();
1217 } else {
1218 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171219 }
[email protected]12fbad812009-09-01 18:21:241220 }
[email protected]5fea4a52014-05-27 00:17:521221 if (input_event->type == WebInputEvent::MouseMove)
1222 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241223
[email protected]3306f262012-09-21 19:20:421224#if defined(OS_ANDROID)
1225 // Allow the IME to be shown when the focus changes as a consequence
1226 // of a processed touch end event.
1227 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361228 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021229#elif defined(USE_AURA)
1230 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1231 // change.
1232 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141233 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361234 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141235 }
[email protected]3306f262012-09-21 19:20:421236#endif
1237
[email protected]67bfb83f2011-09-22 03:36:371238 if (!prevent_default) {
1239 if (WebInputEvent::isKeyboardEventType(input_event->type))
1240 DidHandleKeyEvent();
1241 if (WebInputEvent::isMouseEventType(input_event->type))
1242 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241243 if (WebInputEvent::isTouchEventType(input_event->type))
1244 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:371245 }
rouslanf7ebd8832015-01-22 01:54:141246
1247// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1248// virtual keyboard.
1249#if !defined(OS_ANDROID)
1250 // Virtual keyboard is not supported, so react to focus change immediately.
1251 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1252 input_event->type == WebInputEvent::MouseUp)) {
1253 FocusChangeComplete();
1254 }
1255#endif
initial.commit09911bf2008-07-26 23:55:291256}
1257
[email protected]34202de2013-05-06 23:36:221258void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1259 if (webwidget_)
1260 webwidget_->setCursorVisibilityState(is_visible);
1261}
1262
initial.commit09911bf2008-07-26 23:55:291263void RenderWidget::OnMouseCaptureLost() {
1264 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281265 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291266}
1267
1268void RenderWidget::OnSetFocus(bool enable) {
1269 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331270 if (webwidget_)
1271 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291272}
1273
1274void RenderWidget::ClearFocus() {
1275 // We may have got the focus from the browser before this gets processed, in
1276 // which case we do not want to unfocus ourself.
1277 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281278 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291279}
1280
[email protected]fd847792013-10-24 17:12:351281void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291282 if (pending_input_event_ack_) {
1283 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1284 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071285 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291286 }
[email protected]fd847792013-10-24 17:12:351287 total_input_handling_time_this_frame_ = base::TimeDelta();
1288}
1289
initial.commit09911bf2008-07-26 23:55:291290///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461291// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291292
[email protected]244ac1892011-12-02 17:04:471293void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091294 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451295 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581296
[email protected]5b45ad42013-10-25 00:42:041297 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451298 WebRect new_pos(rootWindowRect().x,
1299 rootWindowRect().y,
1300 new_size.width,
1301 new_size.height);
1302 view_screen_rect_ = new_pos;
1303 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031304 }
[email protected]20fbfc22013-05-08 20:50:581305
[email protected]eac2b362013-05-22 07:01:451306 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581307
[email protected]5b45ad42013-10-25 00:42:041308 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581309 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091310 }
[email protected]244ac1892011-12-02 17:04:471311}
1312
[email protected]3a1c8a8032013-03-18 22:35:321313void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051314 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1315 device_scale_factor_));
1316 if (compositor_)
1317 compositor_->setViewportSize(size_, physical_backing_size_);
1318}
1319
[email protected]e195e582013-03-08 01:32:591320void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221321 DCHECK(!host_closing_);
1322
danakj6e3bf8012014-12-16 18:27:531323 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591324 compositor_->setViewportSize(size_, physical_backing_size_);
1325 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031326 StartCompositor();
[email protected]e195e582013-03-08 01:32:591327}
1328
ennef3c58142014-12-09 21:44:381329void RenderWidget::WillCloseLayerTreeView() {
1330 if (host_closing_)
1331 return;
1332
1333 // Prevent new compositors or output surfaces from being created.
1334 host_closing_ = true;
1335
[email protected]aeeedad2014-08-22 18:16:221336 // Always send this notification to prevent new layer tree views from
1337 // being created, even if one hasn't been created yet.
1338 if (webwidget_)
1339 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221340}
1341
[email protected]180ef242013-11-07 06:50:461342blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281343 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061344}
1345
[email protected]9cd43a62012-03-26 08:03:561346void RenderWidget::willBeginCompositorFrame() {
1347 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371348
[email protected]abe8b3a2012-03-28 21:19:371349 // The following two can result in further layout and possibly
1350 // enable GPU acceleration so they need to be called before any painting
1351 // is done.
shuchen3517bb62014-10-15 03:55:571352 UpdateTextInputType();
1353#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361354 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571355#endif
[email protected]abe8b3a2012-03-28 21:19:371356 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561357}
1358
[email protected]3391a0772012-03-28 00:32:071359void RenderWidget::didBecomeReadyForAdditionalInput() {
1360 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351361 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071362}
1363
[email protected]6fceb912013-02-15 06:24:151364void RenderWidget::DidCommitCompositorFrame() {
[email protected]e3244ed2014-06-20 20:04:271365 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161366 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171367#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271368 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1369 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171370#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151371}
1372
[email protected]586871b2014-07-22 17:05:111373// static
1374scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1375 IPC::Message* msg,
1376 MessageDeliveryPolicy policy,
1377 FrameSwapMessageQueue* frame_swap_message_queue,
1378 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
1379 bool commit_requested,
1380 int source_frame_number) {
1381 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE &&
1382 // No need for lock: this gets changed only on this thread.
1383 !commit_requested &&
1384 // No need for lock: Messages are only enqueued from this thread, if we
1385 // don't have any now, no other thread will add any.
1386 frame_swap_message_queue->Empty()) {
1387 sync_message_filter->Send(msg);
dcheng4b6b5ff2014-10-16 00:42:061388 return nullptr;
[email protected]586871b2014-07-22 17:05:111389 }
1390
1391 bool first_message_for_frame = false;
1392 frame_swap_message_queue->QueueMessageForFrame(policy,
1393 source_frame_number,
1394 make_scoped_ptr(msg),
1395 &first_message_for_frame);
1396 if (first_message_for_frame) {
1397 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1398 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061399 return promise;
[email protected]586871b2014-07-22 17:05:111400 }
dcheng4b6b5ff2014-10-16 00:42:061401 return nullptr;
[email protected]586871b2014-07-22 17:05:111402}
1403
1404void RenderWidget::QueueMessage(IPC::Message* msg,
1405 MessageDeliveryPolicy policy) {
1406 // RenderThreadImpl::current() is NULL in some tests.
1407 if (!compositor_ || !RenderThreadImpl::current()) {
1408 Send(msg);
1409 return;
1410 }
1411
1412 scoped_ptr<cc::SwapPromise> swap_promise =
1413 QueueMessageImpl(msg,
1414 policy,
dcheng58867a92014-08-26 02:50:221415 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111416 RenderThreadImpl::current()->sync_message_filter(),
igsolla70d74312015-01-13 11:17:071417 compositor_->BeginMainFrameRequested(),
[email protected]586871b2014-07-22 17:05:111418 compositor_->GetSourceFrameNumber());
1419
1420 if (swap_promise) {
1421 compositor_->QueueSwapPromise(swap_promise.Pass());
1422 compositor_->SetNeedsCommit();
1423 }
1424}
1425
[email protected]58264a32011-11-17 23:36:151426void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101427 // NOTE: Tests may break if this event is renamed or moved. See
1428 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501429 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161430 // Notify subclasses that we initiated the paint operation.
1431 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151432}
1433
1434void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181435 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1436
1437 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561438 DidFlushPaint();
1439
[email protected]ea3ee0a2012-05-15 03:43:091440 if (!next_paint_flags_ &&
1441 !need_update_rect_for_auto_resize_ &&
1442 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151443 return;
[email protected]ea3ee0a2012-05-15 03:43:091444 }
[email protected]58264a32011-11-17 23:36:151445
1446 ViewHostMsg_UpdateRect_Params params;
1447 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151448 params.plugin_window_moves.swap(plugin_window_moves_);
1449 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151450
1451 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1452 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091453 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151454}
1455
[email protected]8b9e52b2014-01-17 16:35:311456void RenderWidget::scheduleComposite() {
danakj6e3bf8012014-12-16 18:27:531457 if (compositor_ &&
1458 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
[email protected]e221f9f2014-05-13 02:47:221459 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311460 }
1461}
1462
[email protected]4873c7d2009-07-16 06:36:281463void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301464 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521465 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401466 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291467 // Only send a SetCursor message if we need to make a change.
1468 if (!current_cursor_.IsEqual(cursor)) {
1469 current_cursor_ = cursor;
1470 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1471 }
1472}
1473
1474// We are supposed to get a single call to Show for a newly created RenderWidget
1475// that was created via RenderWidget::CreateWebView. So, we wait until this
1476// point to dispatch the ShowWidget message.
1477//
1478// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281479// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291480//
[email protected]4873c7d2009-07-16 06:36:281481void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291482 DCHECK(!did_show_) << "received extraneous Show call";
1483 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1484 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1485
[email protected]8de12d942010-11-17 20:42:441486 if (did_show_)
1487 return;
1488
1489 did_show_ = true;
1490 // NOTE: initial_pos_ may still have its default values at this point, but
1491 // that's okay. It'll be ignored if as_popup is false, or the browser
1492 // process will impose a default position otherwise.
1493 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1494 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291495}
1496
[email protected]4873c7d2009-07-16 06:36:281497void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291498}
1499
[email protected]4873c7d2009-07-16 06:36:281500void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291501}
1502
[email protected]2533ce12009-05-09 00:02:241503void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381504 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241505 Send(new ViewHostMsg_Close(routing_id_));
1506}
1507
[email protected]4873c7d2009-07-16 06:36:281508void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321509 if (is_swapped_out_) {
1510 // This widget is currently swapped out, and the active widget is in a
1511 // different process. Have the browser route the close request to the
1512 // active widget instead, so that the correct unload handlers are run.
1513 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1514 return;
1515 }
1516
initial.commit09911bf2008-07-26 23:55:291517 // If a page calls window.close() twice, we'll end up here twice, but that's
1518 // OK. It is safe to send multiple Close messages.
1519
[email protected]2533ce12009-05-09 00:02:241520 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1521 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1522 // could be closed before the JS finishes executing. So instead, post a
1523 // message back to the message loop, which won't run until the JS is
1524 // complete, and then the Close message can be sent.
alexclarkee19d4ef2015-01-09 17:45:401525 RenderThread::Get()->GetTaskRunner()->PostTask(
[email protected]32876ae2011-11-15 22:25:211526 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291527}
1528
[email protected]9017d7852013-11-21 17:47:351529void RenderWidget::QueueSyntheticGesture(
1530 scoped_ptr<SyntheticGestureParams> gesture_params,
1531 const SyntheticGestureCompletionCallback& callback) {
1532 DCHECK(!callback.is_null());
1533
1534 pending_synthetic_gesture_callbacks_.push(callback);
1535
1536 SyntheticGesturePacket gesture_packet;
1537 gesture_packet.set_gesture_params(gesture_params.Pass());
1538
1539 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1540}
1541
initial.commit09911bf2008-07-26 23:55:291542void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031543 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381544 WillCloseLayerTreeView();
1545 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291546 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281547 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291548 webwidget_ = NULL;
1549 }
1550}
1551
[email protected]4873c7d2009-07-16 06:36:281552WebRect RenderWidget::windowRect() {
1553 if (pending_window_rect_count_)
1554 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241555
[email protected]80ad8622012-11-07 16:33:031556 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291557}
1558
[email protected]180ef242013-11-07 06:50:461559void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301560 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541561 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301562}
1563
[email protected]b2e4c70132013-10-03 02:07:511564void RenderWidget::setWindowRect(const WebRect& rect) {
1565 WebRect pos = rect;
1566 if (popup_origin_scale_for_emulation_) {
1567 float scale = popup_origin_scale_for_emulation_;
1568 pos.x = popup_screen_origin_for_emulation_.x() +
1569 (pos.x - popup_view_origin_for_emulation_.x()) * scale;
1570 pos.y = popup_screen_origin_for_emulation_.y() +
1571 (pos.y - popup_view_origin_for_emulation_.y()) * scale;
1572 }
1573
[email protected]5b45ad42013-10-25 00:42:041574 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201575 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031576 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1577 SetPendingWindowRect(pos);
1578 } else {
[email protected]ec951b9d2013-10-20 06:21:201579 initial_pos_ = pos;
[email protected]8be1c582013-03-06 00:55:031580 }
initial.commit09911bf2008-07-26 23:55:291581 } else {
bokanf0fd2412014-10-30 15:28:551582 ResizeSynchronously(pos, visible_viewport_size_);
initial.commit09911bf2008-07-26 23:55:291583 }
1584}
1585
[email protected]2533ce12009-05-09 00:02:241586void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1587 pending_window_rect_ = rect;
1588 pending_window_rect_count_++;
1589}
1590
[email protected]4873c7d2009-07-16 06:36:281591WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241592 if (pending_window_rect_count_) {
1593 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1594 // the RootWindowRect is probably going to return wrong results since the
1595 // browser may not have processed the Move yet. There isn't really anything
1596 // good to do in this case, and it shouldn't happen - since this size is
1597 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281598 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241599 }
1600
[email protected]80ad8622012-11-07 16:33:031601 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371602}
1603
[email protected]4873c7d2009-07-16 06:36:281604WebRect RenderWidget::windowResizerRect() {
1605 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191606}
1607
[email protected]fa7b1dc2010-06-23 17:53:041608void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031609 // To prevent this renderer process from sending unnecessary IPC messages to
1610 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041611 // only during the input method attached to the browser process is active.
1612 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291613}
1614
[email protected]37a241c2013-12-03 03:16:171615void RenderWidget::OnCandidateWindowShown() {
1616 webwidget_->didShowCandidateWindow();
1617}
1618
1619void RenderWidget::OnCandidateWindowUpdated() {
1620 webwidget_->didUpdateCandidateWindow();
1621}
1622
1623void RenderWidget::OnCandidateWindowHidden() {
1624 webwidget_->didHideCandidateWindow();
1625}
1626
[email protected]fa7b1dc2010-06-23 17:53:041627void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261628 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041629 const std::vector<WebCompositionUnderline>& underlines,
1630 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131631 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281632 return;
[email protected]66fca5bc2013-05-23 06:58:291633 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361634 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041635 text, WebVector<WebCompositionUnderline>(underlines),
1636 selection_start, selection_end)) {
1637 // If we failed to set the composition text, then we need to let the browser
1638 // process to cancel the input method's ongoing composition session, to make
1639 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221640 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261641 }
[email protected]88dbe32f2013-06-20 23:31:361642 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041643}
1644
[email protected]fcf75d42013-12-03 20:11:261645void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511646 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021647 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131648 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041649 return;
[email protected]66fca5bc2013-05-23 06:58:291650 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041651 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021652 if (text.length())
1653 webwidget_->confirmComposition(text);
1654 else if (keep_selection)
1655 webwidget_->confirmComposition(WebWidget::KeepSelection);
1656 else
1657 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041658 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361659 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291660}
1661
[email protected]0bc1f572013-04-17 01:46:311662void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121663 // During shutdown we can just ignore this message.
1664 if (!webwidget_)
1665 return;
1666
[email protected]0bc1f572013-04-17 01:46:311667 // Even if the browser provides an empty damage rect, it's still expecting to
1668 // receive a repaint ack so just damage the entire widget bounds.
1669 if (size_to_paint.IsEmpty()) {
1670 size_to_paint = size_;
1671 }
1672
[email protected]ec7dc112008-08-06 05:30:121673 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051674 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311675 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121676}
1677
[email protected]79fa22e2013-08-23 15:18:121678void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351679 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1680
1681 pending_synthetic_gesture_callbacks_.front().Run();
1682 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271683}
1684
[email protected]4873c7d2009-07-16 06:36:281685void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111686 if (!webwidget_)
1687 return;
[email protected]4873c7d2009-07-16 06:36:281688 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111689}
1690
[email protected]80ad8622012-11-07 16:33:031691void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1692 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511693 if (screen_metrics_emulator_) {
1694 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1695 view_screen_rect, window_screen_rect);
1696 } else {
1697 view_screen_rect_ = view_screen_rect;
1698 window_screen_rect_ = window_screen_rect;
1699 }
[email protected]80ad8622012-11-07 16:33:031700 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1701}
1702
[email protected]adb362312014-06-28 06:04:241703void RenderWidget::showImeIfNeeded() {
1704 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131705}
1706
[email protected]adb362312014-06-28 06:04:241707void RenderWidget::OnShowImeIfNeeded() {
1708#if defined(OS_ANDROID) || defined(USE_AURA)
1709 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1710#endif
rouslanf7ebd8832015-01-22 01:54:141711
1712// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1713// virtual keyboard.
1714#if !defined(OS_ANDROID)
1715 FocusChangeComplete();
1716#endif
[email protected]adb362312014-06-28 06:04:241717}
1718
1719#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131720void RenderWidget::IncrementOutstandingImeEventAcks() {
1721 ++outstanding_ime_acks_;
1722}
1723
1724void RenderWidget::OnImeEventAck() {
1725 --outstanding_ime_acks_;
1726 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511727}
[email protected]105dffb42013-02-20 03:46:211728#endif
1729
[email protected]0d1ebed12013-08-05 22:01:131730bool RenderWidget::ShouldHandleImeEvent() {
1731#if defined(OS_ANDROID)
1732 return !!webwidget_ && outstanding_ime_acks_ == 0;
1733#else
1734 return !!webwidget_;
1735#endif
1736}
1737
[email protected]c27dd4f2014-05-22 18:05:191738bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1739 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521740 // If we pause multiple times during a single mouse move event, we should
1741 // only send ACK once.
1742 if (!ignore_ack_for_mouse_move_from_debugger_) {
1743 InputHostMsg_HandleInputEvent_ACK_Params ack;
1744 ack.type = handling_event_type_;
1745 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED;
1746 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
1747 }
[email protected]c27dd4f2014-05-22 18:05:191748 return true;
1749 }
1750 return false;
1751}
1752
1753void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1754 ignore_ack_for_mouse_move_from_debugger_ = true;
1755}
1756
[email protected]468ac582012-11-20 00:53:191757void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1758 if (device_scale_factor_ == device_scale_factor)
1759 return;
1760
1761 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051762 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191763}
1764
[email protected]28ed6b32014-06-08 02:16:271765bool RenderWidget::SetDeviceColorProfile(
1766 const std::vector<char>& color_profile) {
1767 if (device_color_profile_ == color_profile)
1768 return false;
1769
1770 device_color_profile_ = color_profile;
1771 return true;
1772}
1773
noeldb4df152014-09-16 17:45:201774void RenderWidget::ResetDeviceColorProfileForTesting() {
1775 if (!device_color_profile_.empty())
1776 device_color_profile_.clear();
1777 device_color_profile_.push_back('0');
1778}
1779
[email protected]fcdc5642014-05-09 14:32:241780void RenderWidget::OnOrientationChange() {
1781}
1782
[email protected]ceb36f7d2012-10-31 18:33:241783gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521784 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241785 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521786}
1787
[email protected]bee16aab2009-08-26 15:55:031788void RenderWidget::SetHidden(bool hidden) {
1789 if (is_hidden_ == hidden)
1790 return;
1791
jdduke8fac9d102014-12-20 02:40:131792 // The status has changed. Tell the RenderThread about it and ensure
1793 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031794 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131795 FlushPendingInputEventAck();
1796
[email protected]bee16aab2009-08-26 15:55:031797 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001798 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031799 else
[email protected]b2db9272014-01-10 17:42:001800 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031801}
1802
[email protected]2b624c562011-10-27 22:58:261803void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261804 if (!webwidget_)
1805 return;
1806
1807 if (is_fullscreen_) {
1808 webwidget_->willExitFullScreen();
1809 } else {
1810 webwidget_->willEnterFullScreen();
1811 }
[email protected]2b624c562011-10-27 22:58:261812}
1813
1814void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261815 if (!webwidget_)
1816 return;
1817
1818 if (is_fullscreen_) {
1819 webwidget_->didEnterFullScreen();
1820 } else {
1821 webwidget_->didExitFullScreen();
1822 }
[email protected]2b624c562011-10-27 22:58:261823}
1824
[email protected]674741932009-02-04 23:44:461825bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051826 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461827}
1828
[email protected]674741932009-02-04 23:44:461829void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051830 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461831}
1832
[email protected]674741932009-02-04 23:44:461833void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051834 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461835}
1836
[email protected]b18583c2012-12-18 06:55:271837static bool IsDateTimeInput(ui::TextInputType type) {
1838 return type == ui::TEXT_INPUT_TYPE_DATE ||
1839 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1840 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1841 type == ui::TEXT_INPUT_TYPE_MONTH ||
1842 type == ui::TEXT_INPUT_TYPE_TIME ||
1843 type == ui::TEXT_INPUT_TYPE_WEEK;
1844}
1845
[email protected]66fca5bc2013-05-23 06:58:291846
1847void RenderWidget::StartHandlingImeEvent() {
1848 DCHECK(!handling_ime_event_);
1849 handling_ime_event_ = true;
1850}
1851
1852void RenderWidget::FinishHandlingImeEvent() {
1853 DCHECK(handling_ime_event_);
1854 handling_ime_event_ = false;
1855 // While handling an ime event, text input state and selection bounds updates
1856 // are ignored. These must explicitly be updated once finished handling the
1857 // ime event.
1858 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471859#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361860 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471861#endif
[email protected]66fca5bc2013-05-23 06:58:291862}
1863
shuchen3517bb62014-10-15 03:55:571864void RenderWidget::UpdateTextInputType() {
1865 // On Windows, not only an IME but also an on-screen keyboard relies on the
1866 // latest TextInputType to optimize its layout and functionality. Thus
1867 // |input_method_is_active_| is no longer an appropriate condition to suppress
1868 // TextInputTypeChanged IPC on Windows.
1869 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1870 // on other platforms as well as Windows if the overhead is acceptable.
1871#if !defined(OS_WIN)
1872 if (!input_method_is_active_)
1873 return;
1874#endif
1875
1876 ui::TextInputType new_type = GetTextInputType();
1877 if (IsDateTimeInput(new_type))
1878 return; // Not considered as a text input field in WebKit/Chromium.
1879
1880 bool new_can_compose_inline = CanComposeInline();
1881
1882 blink::WebTextInputInfo new_info;
1883 if (webwidget_)
1884 new_info = webwidget_->textInputInfo();
1885 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201886 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571887
1888 if (text_input_type_ != new_type
1889 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201890 || text_input_mode_ != new_mode
1891 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571892 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1893 new_type,
1894 new_mode,
shuchen82ce8c52014-10-23 01:55:201895 new_can_compose_inline,
1896 new_flags));
shuchen3517bb62014-10-15 03:55:571897 text_input_type_ = new_type;
1898 can_compose_inline_ = new_can_compose_inline;
1899 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201900 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571901 }
1902}
1903
1904#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361905void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1906 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501907 if (handling_ime_event_)
1908 return;
[email protected]90f24152014-04-09 12:41:361909 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291910 return;
[email protected]ad26ef42011-06-17 07:59:451911 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271912 if (IsDateTimeInput(new_type))
1913 return; // Not considered as a text input field in WebKit/Chromium.
1914
[email protected]180ef242013-11-07 06:50:461915 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211916 if (webwidget_)
1917 new_info = webwidget_->textInputInfo();
1918
[email protected]ad26ef42011-06-17 07:59:451919 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211920
[email protected]3306f262012-09-21 19:20:421921 // Only sends text input params if they are changed or if the ime should be
1922 // shown.
[email protected]90f24152014-04-09 12:41:361923 if (show_ime == SHOW_IME_IF_NEEDED ||
1924 (text_input_type_ != new_type ||
1925 text_input_info_ != new_info ||
1926 can_compose_inline_ != new_can_compose_inline)
1927#if defined(OS_ANDROID)
1928 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021929#endif
[email protected]90f24152014-04-09 12:41:361930 ) {
1931 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211932 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401933 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211934 p.value = new_info.value.utf8();
1935 p.selection_start = new_info.selectionStart;
1936 p.selection_end = new_info.selectionEnd;
1937 p.composition_start = new_info.compositionStart;
1938 p.composition_end = new_info.compositionEnd;
1939 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361940 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1941#if defined(USE_AURA)
1942 p.is_non_ime_change = true;
1943#endif
[email protected]183e28d2014-01-20 18:18:021944#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361945 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1946 text_field_is_dirty_;
1947 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131948 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361949 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021950#endif
shuchen3517bb62014-10-15 03:55:571951#if defined(USE_AURA)
1952 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1953 new_type,
1954 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:201955 new_can_compose_inline,
1956 new_info.flags));
shuchen3517bb62014-10-15 03:55:571957#endif
[email protected]5b739cb2012-08-21 20:35:211958 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1959
1960 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041961 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451962 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201963 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291964 }
initial.commit09911bf2008-07-26 23:55:291965}
shuchen3517bb62014-10-15 03:55:571966#endif
initial.commit09911bf2008-07-26 23:55:291967
[email protected]7c8873e2013-02-05 08:03:011968void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1969 WebRect focus_webrect;
1970 WebRect anchor_webrect;
1971 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1972 *focus = focus_webrect;
1973 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321974}
1975
[email protected]e99ef6f2011-10-16 01:13:001976void RenderWidget::UpdateSelectionBounds() {
1977 if (!webwidget_)
1978 return;
[email protected]66fca5bc2013-05-23 06:58:291979 if (handling_ime_event_)
1980 return;
[email protected]e99ef6f2011-10-16 01:13:001981
jddukeacf809e2014-09-23 20:38:381982 // With composited selection updates, the selection bounds will be reported
1983 // directly by the compositor, in which case explicit IPC selection
1984 // notifications should be suppressed.
1985 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
1986 ViewHostMsg_SelectionBounds_Params params;
1987 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1988 if (selection_anchor_rect_ != params.anchor_rect ||
1989 selection_focus_rect_ != params.focus_rect) {
1990 selection_anchor_rect_ = params.anchor_rect;
1991 selection_focus_rect_ = params.focus_rect;
1992 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1993 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1994 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1995 }
[email protected]58b48a0d2012-06-13 07:01:351996 }
jddukeacf809e2014-09-23 20:38:381997
[email protected]88dbe32f2013-06-20 23:31:361998 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001999}
2000
[email protected]180ef242013-11-07 06:50:462001// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172002#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2003 static_assert(int(blink::WebTextInputType##a) \
2004 == int(ui::TEXT_INPUT_TYPE_##b), \
2005 "mismatching enums: " #a)
2006
2007STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2008STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2009STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2010STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2011STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2012STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2013STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2014STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2015STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2016STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2017STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2018STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2019STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2020STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2021STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2022STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2023STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452024
[email protected]5b739cb2012-08-21 20:35:212025ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462026 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212027 // Check the type is in the range representable by ui::TextInputType.
2028 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462029 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212030 return static_cast<ui::TextInputType>(type);
2031}
2032
[email protected]ad26ef42011-06-17 07:59:452033ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272034 if (webwidget_)
2035 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452036 return ui::TEXT_INPUT_TYPE_NONE;
2037}
2038
[email protected]501ea13d2013-07-09 17:03:292039void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302040#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112041 // TODO(yukawa): Start sending character bounds when the browser side
2042 // implementation becomes ready (crbug.com/424866).
2043#else
[email protected]db4fc1e2013-09-06 20:01:512044 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292045 if (should_update_range) {
2046 GetCompositionRange(&range);
2047 } else {
2048 range = composition_range_;
2049 }
2050 std::vector<gfx::Rect> character_bounds;
2051 GetCompositionCharacterBounds(&character_bounds);
2052
2053 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2054 return;
2055 composition_character_bounds_ = character_bounds;
2056 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222057 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292058 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112059#endif
[email protected]501ea13d2013-07-09 17:03:292060}
2061
[email protected]58b48a0d2012-06-13 07:01:352062void RenderWidget::GetCompositionCharacterBounds(
2063 std::vector<gfx::Rect>* bounds) {
2064 DCHECK(bounds);
2065 bounds->clear();
2066}
2067
[email protected]db4fc1e2013-09-06 20:01:512068void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362069 size_t location, length;
2070 if (webwidget_->compositionRange(&location, &length)) {
2071 range->set_start(location);
2072 range->set_end(location + length);
2073 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2074 range->set_start(location);
2075 range->set_end(location + length);
2076 } else {
[email protected]db4fc1e2013-09-06 20:01:512077 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362078 }
2079}
2080
[email protected]501ea13d2013-07-09 17:03:292081bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512082 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292083 const std::vector<gfx::Rect>& bounds) {
2084 if (composition_range_ != range)
2085 return true;
2086 if (bounds.size() != composition_character_bounds_.size())
2087 return true;
2088 for (size_t i = 0; i < bounds.size(); ++i) {
2089 if (bounds[i] != composition_character_bounds_[i])
2090 return true;
2091 }
2092 return false;
2093}
[email protected]501ea13d2013-07-09 17:03:292094
[email protected]a4f0d882014-05-01 23:48:102095#if defined(OS_ANDROID)
2096void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2097 // If not initialized, default to white. Note that 0 is different from black
2098 // as black still has alpha 0xFF.
2099 if (!bg_color)
2100 bg_color = SK_ColorWHITE;
2101
2102 if (bg_color != body_background_color_) {
2103 body_background_color_ = bg_color;
2104 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2105 }
2106}
timav7a5032e2014-12-05 01:59:432107
2108bool RenderWidget::DoesRecordFullLayer() const {
2109 SynchronousCompositorFactory* synchronous_compositor_factory =
2110 SynchronousCompositorFactory::GetInstance();
2111
2112 // We assume that the absence of synchronous_compositor_factory
2113 // means we are in Chrome. In chrome, we want to clip, i.e.
2114 // *not* to record the full layer.
2115 if (!synchronous_compositor_factory)
2116 return false;
2117
2118 return synchronous_compositor_factory->RecordFullLayer();
2119}
[email protected]a4f0d882014-05-01 23:48:102120#endif
2121
[email protected]ad26ef42011-06-17 07:59:452122bool RenderWidget::CanComposeInline() {
2123 return true;
[email protected]56ea1a62011-05-30 07:05:572124}
2125
[email protected]4873c7d2009-07-16 06:36:282126WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042127 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282128}
2129
[email protected]f660d9c2012-06-06 18:31:212130float RenderWidget::deviceScaleFactor() {
2131 return device_scale_factor_;
2132}
2133
[email protected]fa7b1dc2010-06-23 17:53:042134void RenderWidget::resetInputMethod() {
2135 if (!input_method_is_active_)
2136 return;
2137
[email protected]0e45bd02013-07-12 20:20:022138 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042139 // If the last text input type is not None, then we should finish any
2140 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452141 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042142 // If a composition text exists, then we need to let the browser process
2143 // to cancel the input method's ongoing composition session.
2144 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222145 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042146 }
[email protected]d4cff272011-05-02 15:46:012147
[email protected]88dbe32f2013-06-20 23:31:362148 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042149}
2150
donnda070f3c2015-01-16 19:54:112151#if defined(OS_ANDROID)
2152void RenderWidget::showUnhandledTapUIIfNeeded(
2153 const WebPoint& tapped_position,
2154 const WebNode& tapped_node,
2155 bool page_changed) {
2156 DCHECK(handling_input_event_);
2157 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
2158 !tapped_node.isContentEditable();
2159 if (should_trigger) {
2160 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2161 tapped_position.x, tapped_position.y));
2162 }
2163}
2164#endif
2165
[email protected]c68c3e4e2013-01-24 00:36:562166void RenderWidget::didHandleGestureEvent(
2167 const WebGestureEvent& event,
2168 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022169#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562170 if (event_cancelled)
2171 return;
[email protected]07c70d22014-08-21 08:33:462172 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362173 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462174 } else if (event.type == WebInputEvent::GestureLongPress) {
2175 DCHECK(webwidget_);
2176 if (webwidget_->textInputInfo().value.isEmpty())
2177 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2178 else
2179 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562180 }
2181#endif
2182}
2183
[email protected]7912e822014-04-16 02:37:032184void RenderWidget::StartCompositor() {
2185 // For widgets that are never visible, we don't need the compositor to run
2186 // at all.
2187 if (never_visible_)
2188 return;
danakj6e3bf8012014-12-16 18:27:532189 // In tests without a RenderThreadImpl, don't set ready as this kicks
2190 // off creating output surfaces that the test can't create.
2191 if (!RenderThreadImpl::current())
2192 return;
danakj018271e32014-12-16 21:17:262193 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032194}
2195
[email protected]29e2fb42013-07-19 01:13:472196void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292197 size_t i = 0;
2198 for (; i < plugin_window_moves_.size(); ++i) {
2199 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582200 if (move.rects_valid) {
2201 plugin_window_moves_[i] = move;
2202 } else {
2203 plugin_window_moves_[i].visible = move.visible;
2204 }
initial.commit09911bf2008-07-26 23:55:292205 break;
2206 }
2207 }
2208
2209 if (i == plugin_window_moves_.size())
2210 plugin_window_moves_.push_back(move);
2211}
[email protected]268654772009-08-06 23:02:042212
2213void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2214 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2215 i != plugin_window_moves_.end(); ++i) {
2216 if (i->window == window) {
2217 plugin_window_moves_.erase(i);
2218 break;
2219 }
2220 }
2221}
[email protected]67bfb83f2011-09-22 03:36:372222
[email protected]63b465922012-09-06 02:04:522223
[email protected]24ed0432013-04-24 07:50:312224RenderWidgetCompositor* RenderWidget::compositor() const {
2225 return compositor_.get();
2226}
2227
[email protected]180ef242013-11-07 06:50:462228bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372229 return false;
2230}
[email protected]c3d45532011-10-07 19:20:402231
[email protected]41d86852012-11-07 12:23:242232bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462233 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242234 return false;
2235}
2236
ccamerona7644752014-12-30 01:16:312237void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312238 const blink::WebMouseWheelEvent& wheel_event,
2239 bool event_processed) {
ccamerona7644752014-12-30 01:16:312240 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312241 return;
2242
2243 // Blink does not accurately compute scroll bubbling or overscroll. For now,
2244 // assume that an unprocessed event was entirely an overscroll, and that a
2245 // processed event was entirely scroll.
2246 // TODO(ccameron): Retrieve an accurate scroll result from Blink.
2247 // http://crbug.com/442859
2248 cc::InputHandlerScrollResult scroll_result;
2249 if (event_processed) {
2250 scroll_result.did_scroll = true;
2251 } else {
2252 scroll_result.did_overscroll_root = true;
2253 scroll_result.unused_scroll_delta =
2254 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY);
2255 }
2256
2257 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2258 InputHandlerManager* input_handler_manager =
2259 render_thread ? render_thread->input_handler_manager() : NULL;
2260 if (input_handler_manager) {
2261 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2262 routing_id_, wheel_event, scroll_result);
2263 }
2264}
2265
[email protected]ce6689f2013-03-29 12:52:552266void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2267 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2268}
2269
mostynbe29b6882015-01-13 09:59:172270// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2271#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2272 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2273 "mismatching enums: " #a)
2274
[email protected]5d0bbdfa92013-12-10 00:35:512275void RenderWidget::setTouchAction(
2276 blink::WebTouchAction web_touch_action) {
2277
2278 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2279 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192280 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512281 return;
2282
[email protected]a18f67a2013-12-20 19:44:362283 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172284 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2285 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
2286 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
2287 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2288 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362289
2290 content::TouchAction content_touch_action =
2291 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512292 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2293}
2294
[email protected]90f24152014-04-09 12:41:362295void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2296#if defined(OS_ANDROID)
2297 text_field_is_dirty_ = true;
2298#endif
2299}
2300
[email protected]3d5c243b2012-11-30 00:26:012301bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2302 return true;
2303}
2304
[email protected]0634cdd42013-08-16 00:46:092305scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132306RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592307 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092308 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492309 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222310 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092311 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292312 if (!RenderThreadImpl::current())
2313 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402314 CauseForGpuLaunch cause =
2315 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292316 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402317 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222318 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292319 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592320
[email protected]828a3932014-04-02 14:43:132321 // Explicitly disable antialiasing for the compositor. As of the time of
2322 // this writing, the only platform that supported antialiasing for the
2323 // compositor was Mac OS X, because the on-screen OpenGL context creation
2324 // code paths on Windows and Linux didn't yet have multisampling support.
2325 // Mac OS X essentially always behaves as though it's rendering offscreen.
2326 // Multisampling has a heavy cost especially on devices with relatively low
2327 // fill rate like most notebooks, and the Mac implementation would need to
2328 // be optimized to resolve directly into the IOSurface shared between the
2329 // GPU and browser processes. For these reasons and to avoid platform
2330 // disparities we explicitly disable antialiasing.
2331 blink::WebGraphicsContext3D::Attributes attributes;
2332 attributes.antialias = false;
2333 attributes.shareResources = true;
2334 attributes.noAutomaticFlushes = true;
2335 attributes.depth = false;
2336 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132337 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292338 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012339#if defined(OS_ANDROID)
2340 // If we raster too fast we become upload bound, and pending
2341 // uploads consume memory. For maximum upload throughput, we would
2342 // want to allow for upload_throughput * pipeline_time of pending
2343 // uploads, after which we are just wasting memory. Since we don't
2344 // know our upload throughput yet, this just caps our memory usage.
2345 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272346 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032347 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012348 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032349 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012350 // Deadline to draw a frame to achieve 60 frames per second.
2351 const size_t kMillisecondsPerFrame = 16;
2352 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032353 size_t max_transfer_buffer_usage_mb =
2354 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2355 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012356 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2357 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292358 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032359 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012360#endif
[email protected]96ab016c2013-10-23 00:50:292361
[email protected]96ab016c2013-10-23 00:50:292362 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132363 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2364 GetURLForGraphicsContext3D(),
2365 gpu_channel_host.get(),
2366 attributes,
[email protected]828a3932014-04-02 14:43:132367 lose_context_when_out_of_memory,
2368 limits,
2369 NULL));
[email protected]0634cdd42013-08-16 00:46:092370 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592371}
2372
[email protected]e3244ed2014-06-20 20:04:272373void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2374 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162375}
2376
[email protected]e3244ed2014-06-20 20:04:272377void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2378 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162379}
2380
[email protected]de3c5d82014-05-28 22:12:592381void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2382 render_frames_.AddObserver(frame);
2383}
2384
2385void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2386 render_frames_.RemoveObserver(frame);
2387}
2388
[email protected]a017938b2014-05-27 21:17:172389#if defined(VIDEO_HOLE)
2390void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2391 video_hole_frames_.AddObserver(frame);
2392}
2393
2394void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2395 video_hole_frames_.RemoveObserver(frame);
2396}
2397#endif // defined(VIDEO_HOLE)
2398
[email protected]e9ff79c2012-10-19 21:31:262399} // namespace content