blob: 950881052a2f50d995422797c29c275ff6af8c2b [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"
[email protected]aaf68892013-07-18 00:11:3058#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1859#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3060#include "third_party/WebKit/public/platform/WebSize.h"
61#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4362#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
[email protected]2255a9332013-06-17 05:12:3163#include "third_party/WebKit/public/web/WebPagePopup.h"
64#include "third_party/WebKit/public/web/WebPopupMenu.h"
65#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
66#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3867#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
[email protected]d353541f2012-05-03 22:45:4168#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1369#include "ui/base/ui_base_switches.h"
[email protected]de2cf8c2013-10-25 19:46:4670#include "ui/gfx/frame_time.h"
[email protected]9c769d412014-03-20 18:27:3971#include "ui/gfx/point_conversions.h"
[email protected]a25e25b2012-09-28 14:32:3772#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3573#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4874#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2775#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4176#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4877
[email protected]eeb93112013-05-01 19:41:1078#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1579#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0780#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1081#endif
82
[email protected]661eb9d2009-02-03 02:11:4883#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4984#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5285#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4186#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4887#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4488
[email protected]2255a9332013-06-17 05:12:3189#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2990
[email protected]180ef242013-11-07 06:50:4691using blink::WebCompositionUnderline;
92using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4393using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4694using blink::WebGestureEvent;
95using blink::WebInputEvent;
96using blink::WebKeyboardEvent;
97using blink::WebMouseEvent;
98using blink::WebMouseWheelEvent;
99using blink::WebNavigationPolicy;
100using blink::WebPagePopup;
101using blink::WebPopupMenu;
102using blink::WebPopupMenuInfo;
103using blink::WebPopupType;
104using blink::WebRange;
105using blink::WebRect;
106using blink::WebScreenInfo;
107using blink::WebSize;
108using blink::WebTextDirection;
109using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25110using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46111using blink::WebVector;
112using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26113
[email protected]6a4d7f62013-01-07 21:32:13114namespace {
[email protected]b256eca2013-07-11 10:57:40115
116typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
117
118class TextInputModeMapSingleton {
119 public:
120 static TextInputModeMapSingleton* GetInstance() {
121 return Singleton<TextInputModeMapSingleton>::get();
122 }
[email protected]dd705d4d2013-11-27 08:14:41123 TextInputModeMapSingleton() {
124 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
125 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
126 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
127 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
128 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
129 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
130 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
131 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
132 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
133 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
134 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40135 }
[email protected]dd705d4d2013-11-27 08:14:41136 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40137 private:
[email protected]dd705d4d2013-11-27 08:14:41138 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40139
140 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
141
142 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
143};
144
[email protected]dd705d4d2013-11-27 08:14:41145ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40146 static TextInputModeMapSingleton* singleton =
147 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41148 TextInputModeMap::const_iterator it =
149 singleton->map().find(input_mode.utf8());
150 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40151 return ui::TEXT_INPUT_MODE_DEFAULT;
152 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13153}
[email protected]b256eca2013-07-11 10:57:40154
[email protected]e28a40b2014-07-17 21:06:52155bool IsThreadedCompositingEnabled() {
156 content::RenderThreadImpl* impl = content::RenderThreadImpl::current();
157 return impl && !!impl->compositor_message_loop_proxy().get();
158}
159
[email protected]fd847792013-10-24 17:12:35160// TODO(brianderson): Replace the hard-coded threshold with a fraction of
161// the BeginMainFrame interval.
162// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
163// be spent in input hanlders before input starts getting throttled.
164const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
165
jdduke07788062014-12-05 03:16:30166int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) {
167 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds))
168 .ToInternalValue();
169}
170
171void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now) {
172 UMA_HISTOGRAM_CUSTOM_COUNTS(
173 "Event.AggregatedLatency.Renderer2",
174 GetEventLatencyMicros(event, now),
175 1,
176 10000000,
177 100);
178
179#define CASE_TYPE(t) \
180 case WebInputEvent::t: \
181 UMA_HISTOGRAM_CUSTOM_COUNTS( \
182 "Event.Latency.Renderer2." #t, \
183 GetEventLatencyMicros(event, now), \
184 1, \
185 10000000, \
186 100); \
187 break;
188
189 switch(event.type) {
190 CASE_TYPE(Undefined);
191 CASE_TYPE(MouseDown);
192 CASE_TYPE(MouseUp);
193 CASE_TYPE(MouseMove);
194 CASE_TYPE(MouseEnter);
195 CASE_TYPE(MouseLeave);
196 CASE_TYPE(ContextMenu);
197 CASE_TYPE(MouseWheel);
198 CASE_TYPE(RawKeyDown);
199 CASE_TYPE(KeyDown);
200 CASE_TYPE(KeyUp);
201 CASE_TYPE(Char);
202 CASE_TYPE(GestureScrollBegin);
203 CASE_TYPE(GestureScrollEnd);
204 CASE_TYPE(GestureScrollUpdate);
205 CASE_TYPE(GestureFlingStart);
206 CASE_TYPE(GestureFlingCancel);
207 CASE_TYPE(GestureShowPress);
208 CASE_TYPE(GestureTap);
209 CASE_TYPE(GestureTapUnconfirmed);
210 CASE_TYPE(GestureTapDown);
211 CASE_TYPE(GestureTapCancel);
212 CASE_TYPE(GestureDoubleTap);
213 CASE_TYPE(GestureTwoFingerTap);
214 CASE_TYPE(GestureLongPress);
215 CASE_TYPE(GestureLongTap);
216 CASE_TYPE(GesturePinchBegin);
217 CASE_TYPE(GesturePinchEnd);
218 CASE_TYPE(GesturePinchUpdate);
219 CASE_TYPE(TouchStart);
220 CASE_TYPE(TouchMove);
221 CASE_TYPE(TouchEnd);
222 CASE_TYPE(TouchCancel);
223 default:
224 // Must include default to let blink::WebInputEvent add new event types
225 // before they're added here.
226 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event.type;
227 break;
228 }
229
230#undef CASE_TYPE
231}
232
[email protected]b256eca2013-07-11 10:57:40233} // namespace
234
[email protected]e9ff79c2012-10-19 21:31:26235namespace content {
[email protected]62cb33cae2009-03-27 23:30:22236
[email protected]b2e4c70132013-10-03 02:07:51237// RenderWidget::ScreenMetricsEmulator ----------------------------------------
238
239class RenderWidget::ScreenMetricsEmulator {
240 public:
241 ScreenMetricsEmulator(
242 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43243 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51244 virtual ~ScreenMetricsEmulator();
245
[email protected]19193682014-04-03 15:01:43246 // Scale and offset used to convert between host coordinates
247 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51248 float scale() { return scale_; }
[email protected]9a2d7ee32013-12-05 12:15:49249 gfx::Point offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43250 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51251 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56252 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51253
254 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43255 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51256
257 // The following methods alter handlers' behavior for messages related to
258 // widget size and position.
259 void OnResizeMessage(const ViewMsg_Resize_Params& params);
260 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
261 const gfx::Rect& window_screen_rect);
262 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31263 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51264
265 private:
[email protected]19193682014-04-03 15:01:43266 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02267 void Apply(bool top_controls_shrink_blink_size,
268 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44269 gfx::Rect resizer_rect,
270 bool is_fullscreen);
[email protected]b2e4c70132013-10-03 02:07:51271
272 RenderWidget* widget_;
273
[email protected]7f99fc22013-11-08 14:05:58274 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43275 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51276
[email protected]a179d3962013-11-12 14:44:40277 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51278 float scale_;
[email protected]a179d3962013-11-12 14:44:40279 gfx::Point offset_;
[email protected]b2e4c70132013-10-03 02:07:51280
[email protected]19193682014-04-03 15:01:43281 // Widget rect as passed to webwidget.
282 gfx::Rect applied_widget_rect_;
283
[email protected]b2e4c70132013-10-03 02:07:51284 // Original values to restore back after emulation ends.
285 gfx::Size original_size_;
286 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28287 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46288 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51289 gfx::Rect original_view_screen_rect_;
290 gfx::Rect original_window_screen_rect_;
291};
292
293RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
294 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43295 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51296 : widget_(widget),
[email protected]19193682014-04-03 15:01:43297 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51298 scale_(1.f) {
299 original_size_ = widget_->size_;
300 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28301 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51302 original_screen_info_ = widget_->screen_info_;
303 original_view_screen_rect_ = widget_->view_screen_rect_;
304 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02305 Apply(widget_->top_controls_shrink_blink_size_,
306 widget_->top_controls_height_,
307 widget_->resizer_rect_,
308 widget_->is_fullscreen_);
[email protected]b2e4c70132013-10-03 02:07:51309}
310
311RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
312 widget_->screen_info_ = original_screen_info_;
313
314 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
[email protected]7f99fc22013-11-08 14:05:58315 widget_->SetScreenMetricsEmulationParameters(0.f, gfx::Point(), 1.f);
[email protected]b2e4c70132013-10-03 02:07:51316 widget_->view_screen_rect_ = original_view_screen_rect_;
317 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01318 widget_->Resize(original_size_,
319 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02320 widget_->top_controls_shrink_blink_size_,
321 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01322 original_visible_viewport_size_,
323 widget_->resizer_rect_,
324 widget_->is_fullscreen_,
325 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51326}
327
328void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43329 const WebDeviceEmulationParams& params) {
330 params_ = params;
331 Reapply();
332}
333
334void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02335 Apply(widget_->top_controls_shrink_blink_size_,
336 widget_->top_controls_height_,
337 widget_->resizer_rect_,
338 widget_->is_fullscreen_);
[email protected]b2e4c70132013-10-03 02:07:51339}
340
[email protected]19193682014-04-03 15:01:43341void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02342 bool top_controls_shrink_blink_size,
343 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44344 gfx::Rect resizer_rect,
345 bool is_fullscreen) {
[email protected]92d13b72014-05-09 14:42:31346 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
347 if (!applied_widget_rect_.width())
348 applied_widget_rect_.set_width(original_size_.width());
349 if (!applied_widget_rect_.height())
350 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43351
[email protected]f442ee42014-05-14 11:53:12352 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02353 int original_width = std::max(original_size_.width(), 1);
354 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51355 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02356 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51357 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02358 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51359 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
360 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01361
362 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43363 offset_.set_x(
364 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01365 offset_.set_y(
[email protected]19193682014-04-03 15:01:43366 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51367 } else {
[email protected]0b3578c2014-06-20 18:29:02368 scale_ = params_.scale;
369 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01370 }
[email protected]7f0e8fa2014-03-26 12:32:01371
[email protected]19193682014-04-03 15:01:43372 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
373 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01374 widget_->screen_info_.rect = original_screen_info_.rect;
375 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
376 widget_->window_screen_rect_ = original_window_screen_rect_;
377 } else {
[email protected]19193682014-04-03 15:01:43378 applied_widget_rect_.set_origin(gfx::Point(0, 0));
379 widget_->screen_info_.rect = applied_widget_rect_;
380 widget_->screen_info_.availableRect = applied_widget_rect_;
381 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01382 }
[email protected]a179d3962013-11-12 14:44:40383
[email protected]19193682014-04-03 15:01:43384 float applied_device_scale_factor = params_.deviceScaleFactor ?
385 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01386 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51387
[email protected]7f99fc22013-11-08 14:05:58388 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51389 // - we keep the real device scale factor in compositor to produce sharp image
390 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58391 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51392 // root layer.
393 widget_->SetScreenMetricsEmulationParameters(
[email protected]a179d3962013-11-12 14:44:40394 original_screen_info_.deviceScaleFactor, offset_, scale_);
[email protected]b2e4c70132013-10-03 02:07:51395
[email protected]7f0e8fa2014-03-26 12:32:01396 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43397 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51398
399 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
400 original_size_, original_screen_info_.deviceScaleFactor));
dtrainorcb7779b82014-12-04 01:08:02401 widget_->Resize(applied_widget_rect_.size(),
402 physical_backing_size,
403 top_controls_shrink_blink_size,
404 top_controls_height,
405 applied_widget_rect_.size(),
406 resizer_rect,
407 is_fullscreen,
408 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51409}
410
411void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
412 const ViewMsg_Resize_Params& params) {
413 bool need_ack = params.new_size != original_size_ &&
414 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
415 original_size_ = params.new_size;
416 original_physical_backing_size_ = params.physical_backing_size;
417 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28418 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02419 Apply(params.top_controls_shrink_blink_size,
420 params.top_controls_height,
421 params.resizer_rect,
422 params.is_fullscreen);
[email protected]b2e4c70132013-10-03 02:07:51423
424 if (need_ack) {
425 widget_->set_next_paint_is_resize_ack();
426 if (widget_->compositor_)
427 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
428 }
429}
430
431void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
432 const gfx::Rect& view_screen_rect,
433 const gfx::Rect& window_screen_rect) {
434 original_view_screen_rect_ = view_screen_rect;
435 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43436 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
437 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51438}
439
440void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
441 ContextMenuParams* params) {
442 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40443 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51444 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40445 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51446}
447
[email protected]2d6836f42014-07-02 17:25:31448gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
449 const gfx::Rect& anchor) {
450 gfx::Rect scaled = gfx::ToEnclosedRect(gfx::ScaleRect(anchor, scale_));
451 scaled.set_x(scaled.x() + offset_.x());
452 scaled.set_y(scaled.y() + offset_.y());
453 return scaled;
454}
455
[email protected]b2e4c70132013-10-03 02:07:51456// RenderWidget ---------------------------------------------------------------
457
[email protected]180ef242013-11-07 06:50:46458RenderWidget::RenderWidget(blink::WebPopupType popup_type,
459 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04460 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03461 bool hidden,
462 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29463 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56464 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11465 webwidget_(NULL),
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,
[email protected]180ef242013-11-07 06:50:46523 blink::WebPopupType popup_type,
524 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29525 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41526 scoped_refptr<RenderWidget> widget(
[email protected]7912e822014-04-16 02:37:03527 new RenderWidget(popup_type, screen_info, false, false, false));
[email protected]a635f942012-12-07 10:34:29528 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46529 return widget.get();
[email protected]a635f942012-12-07 10:34:29530 }
531 return NULL;
initial.commit09911bf2008-07-26 23:55:29532}
533
[email protected]484955942010-08-19 16:13:18534// static
535WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
536 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46537 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18538 break;
[email protected]180ef242013-11-07 06:50:46539 case blink::WebPopupTypeSelect:
540 case blink::WebPopupTypeSuggestion:
[email protected]484955942010-08-19 16:13:18541 return WebPopupMenu::create(render_widget);
[email protected]180ef242013-11-07 06:50:46542 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44543 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18544 default:
545 NOTREACHED();
546 }
547 return NULL;
548}
549
[email protected]a635f942012-12-07 10:34:29550bool RenderWidget::Init(int32 opener_id) {
551 return DoInit(opener_id,
552 RenderWidget::CreateWebWidget(this),
553 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
554 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18555}
556
[email protected]a635f942012-12-07 10:34:29557bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06558 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18559 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29560 DCHECK(!webwidget_);
561
562 if (opener_id != MSG_ROUTING_NONE)
563 opener_id_ = opener_id;
564
[email protected]484955942010-08-19 16:13:18565 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29566
[email protected]380244092011-10-07 17:26:27567 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29568 if (result) {
[email protected]380244092011-10-07 17:26:27569 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29570 // Take a reference on behalf of the RenderThread. This will be balanced
571 // when we receive ViewMsg_Close.
572 AddRef();
[email protected]b2db9272014-01-10 17:42:00573 if (RenderThreadImpl::current()) {
574 RenderThreadImpl::current()->WidgetCreated();
575 if (is_hidden_)
576 RenderThreadImpl::current()->WidgetHidden();
577 }
[email protected]a635f942012-12-07 10:34:29578 return true;
initial.commit09911bf2008-07-26 23:55:29579 } else {
[email protected]a635f942012-12-07 10:34:29580 // The above Send can fail when the tab is closing.
581 return false;
initial.commit09911bf2008-07-26 23:55:29582 }
583}
584
[email protected]fc4404d2012-11-07 19:53:30585// This is used to complete pending inits and non-pending inits.
586void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29587 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29588
[email protected]fc4404d2012-11-07 19:53:30589 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42590
[email protected]7912e822014-04-16 02:37:03591 if (compositor_)
592 StartCompositor();
initial.commit09911bf2008-07-26 23:55:29593
[email protected]6de74452009-02-25 18:04:59594 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29595}
596
[email protected]992db4c2011-05-12 15:37:15597void RenderWidget::SetSwappedOut(bool is_swapped_out) {
598 // We should only toggle between states.
599 DCHECK(is_swapped_out_ != is_swapped_out);
600 is_swapped_out_ = is_swapped_out;
601
602 // If we are swapping out, we will call ReleaseProcess, allowing the process
603 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52604 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15605 // If we are swapping in, we call AddRefProcess to prevent the process from
606 // exiting.
[email protected]949b6592014-08-20 13:17:52607 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15608 RenderProcess::current()->AddRefProcess();
609}
610
[email protected]949b6592014-08-20 13:17:52611void RenderWidget::WasSwappedOut() {
612 // If we have been swapped out and no one else is using this process,
613 // it's safe to exit now.
614 CHECK(is_swapped_out_);
615 RenderProcess::current()->ReleaseProcess();
616}
617
[email protected]b2e4c70132013-10-03 02:07:51618void RenderWidget::EnableScreenMetricsEmulation(
[email protected]19193682014-04-03 15:01:43619 const WebDeviceEmulationParams& params) {
620 if (!screen_metrics_emulator_)
621 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
622 else
623 screen_metrics_emulator_->ChangeEmulationParams(params);
[email protected]b2e4c70132013-10-03 02:07:51624}
625
626void RenderWidget::DisableScreenMetricsEmulation() {
627 screen_metrics_emulator_.reset();
628}
629
630void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
631 ScreenMetricsEmulator* emulator) {
632 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43633 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49634 popup_screen_origin_for_emulation_ = gfx::Point(
635 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
636 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56637 screen_info_ = emulator->original_screen_info();
638 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51639}
640
[email protected]2d6836f42014-07-02 17:25:31641gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
642 if (screen_metrics_emulator_)
643 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
644 return anchor;
645}
646
[email protected]b2e4c70132013-10-03 02:07:51647void RenderWidget::SetScreenMetricsEmulationParameters(
[email protected]7f99fc22013-11-08 14:05:58648 float device_scale_factor,
649 const gfx::Point& root_layer_offset,
650 float root_layer_scale) {
[email protected]b2e4c70132013-10-03 02:07:51651 // This is only supported in RenderView.
652 NOTREACHED();
653}
654
[email protected]53907862014-03-25 15:42:40655#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51656void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
657 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49658 popup->SetOriginScaleAndOffsetForEmulation(
659 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51660}
[email protected]53907862014-03-25 15:42:40661#endif
[email protected]b2e4c70132013-10-03 02:07:51662
663void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
664 if (screen_metrics_emulator_)
665 screen_metrics_emulator_->OnShowContextMenu(params);
666}
667
[email protected]7d08a9352013-10-15 08:24:56668void RenderWidget::ScheduleCompositeWithForcedRedraw() {
669 if (compositor_) {
670 // Regardless of whether threaded compositing is enabled, always
671 // use this mechanism to force the compositor to redraw. However,
672 // the invalidation code path below is still needed for the
673 // non-threaded case.
674 compositor_->SetNeedsForcedRedraw();
675 }
[email protected]8b9e52b2014-01-17 16:35:31676 scheduleComposite();
[email protected]7d08a9352013-10-15 08:24:56677}
678
[email protected]a95986a82010-12-24 06:19:28679bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
680 bool handled = true;
681 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15682 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22683 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
684 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22685 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
686 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15687 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
688 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35689 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
690 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28691 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
692 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
693 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
noel89949e62014-09-30 01:12:41694 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54695 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28696 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41697 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]a95986a82010-12-24 06:19:28698 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
[email protected]37a241c2013-12-03 03:16:17699 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowShown, OnCandidateWindowShown)
700 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowUpdated,
701 OnCandidateWindowUpdated)
702 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowHidden, OnCandidateWindowHidden)
[email protected]3d9ec5052013-01-02 22:05:25703 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28704 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
705 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03706 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21707#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51708 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13709 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21710#endif
[email protected]a95986a82010-12-24 06:19:28711 IPC_MESSAGE_UNHANDLED(handled = false)
712 IPC_END_MESSAGE_MAP()
713 return handled;
714}
initial.commit09911bf2008-07-26 23:55:29715
716bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15717 // Don't send any messages after the browser has told us to close, and filter
718 // most outgoing messages while swapped out.
719 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26720 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11721 closing_) {
initial.commit09911bf2008-07-26 23:55:29722 delete message;
723 return false;
724 }
725
726 // If given a messsage without a routing ID, then assign our routing ID.
727 if (message->routing_id() == MSG_ROUTING_NONE)
728 message->set_routing_id(routing_id_);
729
[email protected]380244092011-10-07 17:26:27730 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44731}
732
[email protected]61e2b3cc2012-03-02 16:13:34733void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44734 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02735 bool top_controls_shrink_blink_size,
736 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44737 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34738 const gfx::Rect& resizer_rect,
739 bool is_fullscreen,
740 ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56741 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48742 // A resize ack shouldn't be requested if we have not ACK'd the previous
743 // one.
744 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
745 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
746 }
initial.commit09911bf2008-07-26 23:55:29747
[email protected]61e2b3cc2012-03-02 16:13:34748 // Ignore this during shutdown.
749 if (!webwidget_)
750 return;
751
[email protected]d9083762013-03-24 01:36:40752 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44753 compositor_->setViewportSize(new_size, physical_backing_size);
dtrainorcb7779b82014-12-04 01:08:02754 compositor_->SetTopControlsShrinkBlinkSize(top_controls_shrink_blink_size);
755 compositor_->SetTopControlsHeight(top_controls_height);
[email protected]d9083762013-03-24 01:36:40756 }
[email protected]60d47ac2013-03-01 23:42:44757
[email protected]dade8992013-03-04 07:34:34758 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02759 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
760 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28761 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34762 resizer_rect_ = resizer_rect;
763
764 // NOTE: We may have entered fullscreen mode without changing our size.
765 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
766 if (fullscreen_change)
767 WillToggleFullscreen();
768 is_fullscreen_ = is_fullscreen;
769
dtrainorcb7779b82014-12-04 01:08:02770 webwidget_->setTopControlsLayoutHeight(top_controls_shrink_blink_size_
771 ? top_controls_height : 0.f);
bokan0c93cd82014-09-30 19:20:43772
[email protected]61e2b3cc2012-03-02 16:13:34773 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34774 size_ = new_size;
775
[email protected]61e2b3cc2012-03-02 16:13:34776 // When resizing, we want to wait to paint before ACK'ing the resize. This
777 // ensures that we only resize as fast as we can paint. We only need to
778 // send an ACK if we are resized to a non-empty rect.
779 webwidget_->resize(new_size);
[email protected]5b45ad42013-10-25 00:42:04780 } else if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]632c4382013-05-15 08:58:45781 resize_ack = NO_RESIZE_ACK;
782 }
783
[email protected]bb6378fe2014-04-28 21:19:44784 webwidget()->resizePinchViewport(gfx::Size(
785 visible_viewport_size.width(),
786 visible_viewport_size.height()));
787
[email protected]632c4382013-05-15 08:58:45788 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
789 // For empty size or empty physical_backing_size, there is no next paint
790 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35791 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34792 }
793
[email protected]20fbfc22013-05-08 20:50:58794 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45795 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58796 set_next_paint_is_resize_ack();
797
[email protected]61e2b3cc2012-03-02 16:13:34798 if (fullscreen_change)
799 DidToggleFullscreen();
800
801 // If a resize ack is requested and it isn't set-up, then no more resizes will
802 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45803 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29804}
805
bokanf0fd2412014-10-30 15:28:55806void RenderWidget::ResizeSynchronously(
807 const gfx::Rect& new_position,
808 const gfx::Size& visible_viewport_size) {
[email protected]587941d2014-08-22 01:40:01809 Resize(new_position.size(),
810 new_position.size(),
dtrainorcb7779b82014-12-04 01:08:02811 top_controls_shrink_blink_size_,
812 top_controls_height_,
bokanf0fd2412014-10-30 15:28:55813 visible_viewport_size,
[email protected]587941d2014-08-22 01:40:01814 gfx::Rect(),
815 is_fullscreen_,
816 NO_RESIZE_ACK);
[email protected]92650162013-10-30 03:31:02817 view_screen_rect_ = new_position;
818 window_screen_rect_ = new_position;
819 if (!did_show_)
820 initial_pos_ = new_position;
821}
822
initial.commit09911bf2008-07-26 23:55:29823void RenderWidget::OnClose() {
824 if (closing_)
825 return;
826 closing_ = true;
827
828 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03829 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]b2db9272014-01-10 17:42:00830 if (RenderThreadImpl::current())
831 RenderThreadImpl::current()->WidgetDestroyed();
[email protected]380244092011-10-07 17:26:27832 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03833 SetHidden(false);
834 }
initial.commit09911bf2008-07-26 23:55:29835
initial.commit09911bf2008-07-26 23:55:29836 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25837 // now. Post a task that only gets invoked when there are no nested message
838 // loops.
[email protected]dd32b1272013-05-04 14:17:11839 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29840 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25841
842 // Balances the AddRef taken when we called AddRoute.
843 Release();
initial.commit09911bf2008-07-26 23:55:29844}
845
[email protected]61e2b3cc2012-03-02 16:13:34846// Got a response from the browser after the renderer decided to create a new
847// view.
[email protected]fc4404d2012-11-07 19:53:30848void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34849 DCHECK(routing_id_ != MSG_ROUTING_NONE);
850
[email protected]fc4404d2012-11-07 19:53:30851 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34852}
853
[email protected]0fdd5012013-05-29 08:05:56854void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04855 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32856 return;
857
[email protected]b2e4c70132013-10-03 02:07:51858 if (screen_metrics_emulator_) {
859 screen_metrics_emulator_->OnResizeMessage(params);
860 return;
861 }
862
[email protected]fcdc5642014-05-09 14:32:24863 bool orientation_changed =
864 screen_info_.orientationAngle != params.screen_info.orientationAngle;
865
[email protected]0fdd5012013-05-29 08:05:56866 screen_info_ = params.screen_info;
867 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02868 Resize(params.new_size,
869 params.physical_backing_size,
870 params.top_controls_shrink_blink_size,
871 params.top_controls_height,
872 params.visible_viewport_size,
873 params.resizer_rect,
874 params.is_fullscreen,
875 SEND_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24876
877 if (orientation_changed)
878 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29879}
880
noel89949e62014-09-30 01:12:41881void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
882 SetDeviceColorProfile(color_profile);
883}
884
[email protected]b5913d72012-02-07 22:26:54885void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01886 if (resizer_rect_ == resizer_rect)
887 return;
888 resizer_rect_ = resizer_rect;
889 if (webwidget_)
890 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54891}
892
initial.commit09911bf2008-07-26 23:55:29893void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31894 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29895 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03896 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59897 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
898 WasHidden());
initial.commit09911bf2008-07-26 23:55:29899}
900
[email protected]3399dd822014-08-09 11:14:24901void RenderWidget::OnWasShown(bool needs_repainting,
902 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41903 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29904 // During shutdown we can just ignore this message.
905 if (!webwidget_)
906 return;
907
908 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03909 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59910 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
911 WasShown());
initial.commit09911bf2008-07-26 23:55:29912
[email protected]8a23afb32014-04-30 22:40:23913 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29914 return;
initial.commit09911bf2008-07-26 23:55:29915
916 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24917 if (compositor_) {
918 ui::LatencyInfo swap_latency_info(latency_info);
919 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
920 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05921 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24922 }
[email protected]aca33f4f2014-05-17 17:08:05923 scheduleComposite();
initial.commit09911bf2008-07-26 23:55:29924}
925
[email protected]53d3f302009-12-21 04:42:05926void RenderWidget::OnRequestMoveAck() {
927 DCHECK(pending_window_rect_count_);
928 pending_window_rect_count_--;
929}
930
[email protected]ed7defa2013-03-12 21:29:59931GURL RenderWidget::GetURLForGraphicsContext3D() {
932 return GURL();
[email protected]65225772011-05-12 21:10:24933}
934
[email protected]ebc0e1df2013-08-01 02:46:22935scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03936 // For widgets that are never visible, we don't start the compositor, so we
937 // never get a request for a cc::OutputSurface.
938 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19939
940#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01941 if (SynchronousCompositorFactory* factory =
942 SynchronousCompositorFactory::GetInstance()) {
[email protected]586871b2014-07-22 17:05:11943 return factory->CreateOutputSurface(routing_id(),
944 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:19945 }
946#endif
947
[email protected]b6eb8e332013-09-10 00:51:01948 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33949 bool use_software = fallback;
950 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
951 use_software = true;
952
[email protected]0634cdd42013-08-16 00:46:09953 scoped_refptr<ContextProviderCommandBuffer> context_provider;
[email protected]e09994a2014-03-26 19:59:33954 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09955 context_provider = ContextProviderCommandBuffer::Create(
[email protected]828a3932014-04-02 14:43:13956 CreateGraphicsContext3D(), "RenderCompositor");
[email protected]e09994a2014-03-26 19:59:33957 if (!context_provider.get()) {
958 // Cause the compositor to wait and try again.
959 return scoped_ptr<cc::OutputSurface>();
960 }
[email protected]0634cdd42013-08-16 00:46:09961 }
[email protected]ebc0e1df2013-08-01 02:46:22962
[email protected]b6eb8e332013-09-10 00:51:01963 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:00964 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
[email protected]e28a40b2014-07-17 21:06:52965 DCHECK(IsThreadedCompositingEnabled());
[email protected]65a33ce2014-03-25 22:37:09966 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:11967 new DelegatedCompositorOutputSurface(routing_id(),
968 output_surface_id,
969 context_provider,
970 frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09971 }
[email protected]0634cdd42013-08-16 00:46:09972 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:09973 scoped_ptr<cc::SoftwareOutputDevice> software_device(
974 new CompositorSoftwareOutputDevice());
975
[email protected]586871b2014-07-22 17:05:11976 return scoped_ptr<cc::OutputSurface>(
977 new CompositorOutputSurface(routing_id(),
978 output_surface_id,
979 NULL,
980 software_device.Pass(),
981 frame_swap_message_queue_,
982 true));
[email protected]ebc0e1df2013-08-01 02:46:22983 }
[email protected]ed7defa2013-03-12 21:29:59984
[email protected]36e5ff12013-06-11 12:19:29985 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:45986 // Composite-to-mailbox is currently used for layout tests in order to cause
987 // them to draw inside in the renderer to do the readback there. This should
988 // no longer be the case when crbug.com/311404 is fixed.
[email protected]e28a40b2014-07-17 21:06:52989 DCHECK(IsThreadedCompositingEnabled() ||
[email protected]758efb02014-04-05 07:53:45990 RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:16991 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:27992 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:16993 format = cc::RGB_565;
[email protected]36e5ff12013-06-11 12:19:29994 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:11995 new MailboxOutputSurface(routing_id(),
996 output_surface_id,
997 context_provider,
998 scoped_ptr<cc::SoftwareOutputDevice>(),
999 frame_swap_message_queue_,
1000 format));
[email protected]36e5ff12013-06-11 12:19:291001 }
[email protected]0634cdd42013-08-16 00:46:091002 bool use_swap_compositor_frame_message = false;
[email protected]36e5ff12013-06-11 12:19:291003 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:111004 new CompositorOutputSurface(routing_id(),
1005 output_surface_id,
1006 context_provider,
1007 scoped_ptr<cc::SoftwareOutputDevice>(),
1008 frame_swap_message_queue_,
1009 use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281010}
1011
[email protected]4d7e46a2013-11-08 05:33:401012void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241013 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241014 // Schedule another frame so the compositor learns about it.
[email protected]8b9e52b2014-01-17 16:35:311015 scheduleComposite();
[email protected]65225772011-05-12 21:10:241016}
1017
[email protected]4d7e46a2013-11-08 05:33:401018void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081019 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081020}
1021
[email protected]4d7e46a2013-11-08 05:33:401022void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241023 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161024
[email protected]404939f2012-06-01 04:06:181025 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161026 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291027}
1028
[email protected]180ef242013-11-07 06:50:461029void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351030 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091031 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191032 base::AutoReset<bool> handling_input_event_resetter(
1033 &handling_input_event_, true);
1034 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291035 return;
[email protected]c27dd4f2014-05-22 18:05:191036 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1037 &handling_event_type_, input_event->type);
[email protected]25402eb2014-07-18 03:09:521038#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541039 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521040 // |AdapterInputConnection| generates input key events to make sure all JS
1041 // listeners that monitor KeyUp and KeyDown events receive the proper key
1042 // code. Since this input key event comes from IME, we need to set the
1043 // IME event guard here to make sure it does not interfere with other IME
1044 // events.
1045 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1046 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1047 const WebKeyboardEvent& key_event =
1048 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541049 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171050 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091051 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1052 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1053 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1054 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1055 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521056 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521057 }
1058#endif
initial.commit09911bf2008-07-26 23:55:291059
[email protected]8062ab262014-05-27 16:56:431060 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1061 &latency_info);
1062
[email protected]fd847792013-10-24 17:12:351063 base::TimeTicks start_time;
1064 if (base::TimeTicks::IsHighResNowFastAndReliable())
1065 start_time = base::TimeTicks::HighResNow();
1066
[email protected]b4841e1c2013-05-16 22:30:101067 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301068 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151069 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131070 TRACE_EVENT_FLOW_STEP0(
1071 "input",
1072 "LatencyInfo.Flow",
1073 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1074 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101075
jdduke07788062014-12-05 03:16:301076 // If we don't have a high res timer, these metrics won't be accurate enough
1077 // to be worth collecting. Note that this does introduce some sampling bias.
1078 if (!start_time.is_null())
1079 LogInputEventLatencyUma(*input_event, start_time);
1080
[email protected]6be422b2013-12-08 06:47:311081 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351082 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311083 if (compositor_) {
1084 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351085 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1086 .Pass();
[email protected]6be422b2013-12-08 06:47:311087 }
[email protected]c2eaa8f2013-05-10 02:41:551088
[email protected]67bfb83f2011-09-22 03:36:371089 bool prevent_default = false;
1090 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261091 const WebMouseEvent& mouse_event =
1092 *static_cast<const WebMouseEvent*>(input_event);
1093 TRACE_EVENT2("renderer", "HandleMouseMove",
1094 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421095 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261096 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371097 }
1098
[email protected]cefe9b152014-03-27 18:16:151099 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421100 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151101#if defined(OS_ANDROID)
1102 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1103 // case it should behave like a select key (i.e. causing a click if a button
1104 // is focused). However, if a text field is focused (2), its intended
1105 // behavior is to just show the IME and don't propagate the key.
1106 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1107 // when clicked on an input text field and cause the form submit if clicked
1108 // when the submit button is focused, but not vice-versa.
1109 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1110 // but at this point we have to swallow the event for the scenario (2).
1111 const WebKeyboardEvent& key_event =
1112 *static_cast<const WebKeyboardEvent*>(input_event);
1113 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1114 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1115 OnShowImeIfNeeded();
1116 prevent_default = true;
1117 }
1118#endif
1119 }
[email protected]f56c7872013-06-18 12:31:571120
[email protected]41d86852012-11-07 12:23:241121 if (WebInputEvent::isGestureEventType(input_event->type)) {
1122 const WebGestureEvent& gesture_event =
1123 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421124 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241125 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1126 }
1127
[email protected]67bfb83f2011-09-22 03:36:371128 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121129 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1130 suppress_next_char_events_ = false;
1131 if (!processed && webwidget_)
1132 processed = webwidget_->handleInputEvent(*input_event);
1133 }
1134
1135 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1136 // it's not processed by webkit, then we need to suppress the upcoming Char
1137 // events.
1138 if (!processed && is_keyboard_shortcut)
1139 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291140
[email protected]3d5c243b2012-11-30 00:26:011141 InputEventAckState ack_result = processed ?
1142 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1143 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1144 const WebTouchEvent& touch_event =
1145 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251146 // Hit-test for all the pressed touch points. If there is a touch-handler
1147 // for any of the touch points, then the renderer should continue to receive
1148 // touch events.
1149 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1150 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1151 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271152 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391153 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251154 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1155 break;
1156 }
1157 }
[email protected]3d5c243b2012-11-30 00:26:011158 }
1159
[email protected]721e2302014-04-30 23:42:011160 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061161
[email protected]fd847792013-10-24 17:12:351162 // If we don't have a fast and accurate HighResNow, we assume the input
1163 // handlers are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301164 bool rate_limiting_wanted =
1165 input_event->type == WebInputEvent::MouseMove ||
1166 input_event->type == WebInputEvent::MouseWheel;
1167 if (rate_limiting_wanted && !start_time.is_null()) {
[email protected]fd847792013-10-24 17:12:351168 base::TimeTicks end_time = base::TimeTicks::HighResNow();
1169 total_input_handling_time_this_frame_ += (end_time - start_time);
1170 rate_limiting_wanted =
1171 total_input_handling_time_this_frame_.InMicroseconds() >
1172 kInputHandlingTimeThrottlingThresholdMicroseconds;
1173 }
1174
[email protected]7f19e9d2014-05-09 15:16:291175 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1176
[email protected]c27dd4f2014-05-22 18:05:191177 // Note that we can't use handling_event_type_ here since it will be overriden
1178 // by reentrant calls for events after the paused one.
1179 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1180 input_event->type == WebInputEvent::MouseMove;
1181 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) {
[email protected]8e431f2032014-05-20 02:34:561182 InputHostMsg_HandleInputEvent_ACK_Params ack;
1183 ack.type = input_event->type;
1184 ack.state = ack_result;
1185 ack.latency = swap_latency_info;
[email protected]34afe102013-12-13 17:24:551186 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561187 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301188 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551189 // We want to rate limit the input events in this case, so we'll wait for
1190 // painting to finish before ACKing this message.
1191 TRACE_EVENT_INSTANT0("renderer",
1192 "RenderWidget::OnHandleInputEvent ack throttled",
1193 TRACE_EVENT_SCOPE_THREAD);
1194 if (pending_input_event_ack_) {
1195 // As two different kinds of events could cause us to postpone an ack
1196 // we send it now, if we have one pending. The Browser should never
1197 // send us the same kind of event we are delaying the ack for.
1198 Send(pending_input_event_ack_.release());
1199 }
1200 pending_input_event_ack_ = response.Pass();
1201 if (compositor_)
1202 compositor_->NotifyInputThrottledUntilCommit();
1203 } else {
1204 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171205 }
[email protected]12fbad812009-09-01 18:21:241206 }
[email protected]5fea4a52014-05-27 00:17:521207 if (input_event->type == WebInputEvent::MouseMove)
1208 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241209
[email protected]3306f262012-09-21 19:20:421210#if defined(OS_ANDROID)
1211 // Allow the IME to be shown when the focus changes as a consequence
1212 // of a processed touch end event.
1213 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361214 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021215#elif defined(USE_AURA)
1216 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1217 // change.
1218 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1219 input_event->type == WebInputEvent::MouseUp))
[email protected]90f24152014-04-09 12:41:361220 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
[email protected]3306f262012-09-21 19:20:421221#endif
1222
[email protected]67bfb83f2011-09-22 03:36:371223 if (!prevent_default) {
1224 if (WebInputEvent::isKeyboardEventType(input_event->type))
1225 DidHandleKeyEvent();
1226 if (WebInputEvent::isMouseEventType(input_event->type))
1227 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241228 if (WebInputEvent::isTouchEventType(input_event->type))
1229 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:371230 }
initial.commit09911bf2008-07-26 23:55:291231}
1232
[email protected]34202de2013-05-06 23:36:221233void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1234 if (webwidget_)
1235 webwidget_->setCursorVisibilityState(is_visible);
1236}
1237
initial.commit09911bf2008-07-26 23:55:291238void RenderWidget::OnMouseCaptureLost() {
1239 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281240 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291241}
1242
1243void RenderWidget::OnSetFocus(bool enable) {
1244 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331245 if (webwidget_)
1246 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291247}
1248
1249void RenderWidget::ClearFocus() {
1250 // We may have got the focus from the browser before this gets processed, in
1251 // which case we do not want to unfocus ourself.
1252 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281253 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291254}
1255
[email protected]fd847792013-10-24 17:12:351256void RenderWidget::FlushPendingInputEventAck() {
[email protected]d8a8ecb2013-10-23 18:03:071257 if (pending_input_event_ack_)
1258 Send(pending_input_event_ack_.release());
[email protected]fd847792013-10-24 17:12:351259 total_input_handling_time_this_frame_ = base::TimeDelta();
1260}
1261
initial.commit09911bf2008-07-26 23:55:291262///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461263// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291264
[email protected]244ac1892011-12-02 17:04:471265void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091266 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451267 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581268
[email protected]5b45ad42013-10-25 00:42:041269 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451270 WebRect new_pos(rootWindowRect().x,
1271 rootWindowRect().y,
1272 new_size.width,
1273 new_size.height);
1274 view_screen_rect_ = new_pos;
1275 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031276 }
[email protected]20fbfc22013-05-08 20:50:581277
[email protected]eac2b362013-05-22 07:01:451278 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581279
[email protected]5b45ad42013-10-25 00:42:041280 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581281 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091282 }
[email protected]244ac1892011-12-02 17:04:471283}
1284
[email protected]3a1c8a8032013-03-18 22:35:321285void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051286 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1287 device_scale_factor_));
1288 if (compositor_)
1289 compositor_->setViewportSize(size_, physical_backing_size_);
1290}
1291
[email protected]e195e582013-03-08 01:32:591292void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221293 DCHECK(!host_closing_);
1294
[email protected]e28a40b2014-07-17 21:06:521295 compositor_ =
1296 RenderWidgetCompositor::Create(this, IsThreadedCompositingEnabled());
[email protected]e195e582013-03-08 01:32:591297 compositor_->setViewportSize(size_, physical_backing_size_);
1298 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031299 StartCompositor();
[email protected]e195e582013-03-08 01:32:591300}
1301
ennef3c58142014-12-09 21:44:381302void RenderWidget::WillCloseLayerTreeView() {
1303 if (host_closing_)
1304 return;
1305
1306 // Prevent new compositors or output surfaces from being created.
1307 host_closing_ = true;
1308
[email protected]aeeedad2014-08-22 18:16:221309 // Always send this notification to prevent new layer tree views from
1310 // being created, even if one hasn't been created yet.
1311 if (webwidget_)
1312 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221313}
1314
[email protected]180ef242013-11-07 06:50:461315blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281316 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061317}
1318
[email protected]9cd43a62012-03-26 08:03:561319void RenderWidget::willBeginCompositorFrame() {
1320 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371321
[email protected]abe8b3a2012-03-28 21:19:371322 // The following two can result in further layout and possibly
1323 // enable GPU acceleration so they need to be called before any painting
1324 // is done.
shuchen3517bb62014-10-15 03:55:571325 UpdateTextInputType();
1326#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361327 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571328#endif
[email protected]abe8b3a2012-03-28 21:19:371329 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561330}
1331
[email protected]3391a0772012-03-28 00:32:071332void RenderWidget::didBecomeReadyForAdditionalInput() {
1333 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351334 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071335}
1336
[email protected]6fceb912013-02-15 06:24:151337void RenderWidget::DidCommitCompositorFrame() {
[email protected]e3244ed2014-06-20 20:04:271338 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161339 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171340#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271341 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1342 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171343#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151344}
1345
[email protected]586871b2014-07-22 17:05:111346// static
1347scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1348 IPC::Message* msg,
1349 MessageDeliveryPolicy policy,
1350 FrameSwapMessageQueue* frame_swap_message_queue,
1351 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
1352 bool commit_requested,
1353 int source_frame_number) {
1354 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE &&
1355 // No need for lock: this gets changed only on this thread.
1356 !commit_requested &&
1357 // No need for lock: Messages are only enqueued from this thread, if we
1358 // don't have any now, no other thread will add any.
1359 frame_swap_message_queue->Empty()) {
1360 sync_message_filter->Send(msg);
dcheng4b6b5ff2014-10-16 00:42:061361 return nullptr;
[email protected]586871b2014-07-22 17:05:111362 }
1363
1364 bool first_message_for_frame = false;
1365 frame_swap_message_queue->QueueMessageForFrame(policy,
1366 source_frame_number,
1367 make_scoped_ptr(msg),
1368 &first_message_for_frame);
1369 if (first_message_for_frame) {
1370 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1371 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061372 return promise;
[email protected]586871b2014-07-22 17:05:111373 }
dcheng4b6b5ff2014-10-16 00:42:061374 return nullptr;
[email protected]586871b2014-07-22 17:05:111375}
1376
1377void RenderWidget::QueueMessage(IPC::Message* msg,
1378 MessageDeliveryPolicy policy) {
1379 // RenderThreadImpl::current() is NULL in some tests.
1380 if (!compositor_ || !RenderThreadImpl::current()) {
1381 Send(msg);
1382 return;
1383 }
1384
1385 scoped_ptr<cc::SwapPromise> swap_promise =
1386 QueueMessageImpl(msg,
1387 policy,
dcheng58867a92014-08-26 02:50:221388 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111389 RenderThreadImpl::current()->sync_message_filter(),
1390 compositor_->commitRequested(),
1391 compositor_->GetSourceFrameNumber());
1392
1393 if (swap_promise) {
1394 compositor_->QueueSwapPromise(swap_promise.Pass());
1395 compositor_->SetNeedsCommit();
1396 }
1397}
1398
[email protected]58264a32011-11-17 23:36:151399void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101400 // NOTE: Tests may break if this event is renamed or moved. See
1401 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501402 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161403 // Notify subclasses that we initiated the paint operation.
1404 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151405}
1406
1407void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181408 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1409
1410 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561411 DidFlushPaint();
1412
[email protected]ea3ee0a2012-05-15 03:43:091413 if (!next_paint_flags_ &&
1414 !need_update_rect_for_auto_resize_ &&
1415 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151416 return;
[email protected]ea3ee0a2012-05-15 03:43:091417 }
[email protected]58264a32011-11-17 23:36:151418
1419 ViewHostMsg_UpdateRect_Params params;
1420 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151421 params.plugin_window_moves.swap(plugin_window_moves_);
1422 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151423
1424 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1425 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091426 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151427}
1428
[email protected]8b9e52b2014-01-17 16:35:311429void RenderWidget::scheduleComposite() {
[email protected]57178962014-04-24 08:52:351430 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1431 // render_thread may be NULL in tests.
1432 if (render_thread && render_thread->compositor_message_loop_proxy().get() &&
[email protected]8b9e52b2014-01-17 16:35:311433 compositor_) {
[email protected]e221f9f2014-05-13 02:47:221434 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311435 }
1436}
1437
[email protected]4873c7d2009-07-16 06:36:281438void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301439 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521440 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401441 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291442 // Only send a SetCursor message if we need to make a change.
1443 if (!current_cursor_.IsEqual(cursor)) {
1444 current_cursor_ = cursor;
1445 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1446 }
1447}
1448
1449// We are supposed to get a single call to Show for a newly created RenderWidget
1450// that was created via RenderWidget::CreateWebView. So, we wait until this
1451// point to dispatch the ShowWidget message.
1452//
1453// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281454// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291455//
[email protected]4873c7d2009-07-16 06:36:281456void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291457 DCHECK(!did_show_) << "received extraneous Show call";
1458 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1459 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1460
[email protected]8de12d942010-11-17 20:42:441461 if (did_show_)
1462 return;
1463
1464 did_show_ = true;
1465 // NOTE: initial_pos_ may still have its default values at this point, but
1466 // that's okay. It'll be ignored if as_popup is false, or the browser
1467 // process will impose a default position otherwise.
1468 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1469 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291470}
1471
[email protected]4873c7d2009-07-16 06:36:281472void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291473}
1474
[email protected]4873c7d2009-07-16 06:36:281475void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291476}
1477
[email protected]2533ce12009-05-09 00:02:241478void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381479 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241480 Send(new ViewHostMsg_Close(routing_id_));
1481}
1482
[email protected]4873c7d2009-07-16 06:36:281483void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321484 if (is_swapped_out_) {
1485 // This widget is currently swapped out, and the active widget is in a
1486 // different process. Have the browser route the close request to the
1487 // active widget instead, so that the correct unload handlers are run.
1488 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1489 return;
1490 }
1491
initial.commit09911bf2008-07-26 23:55:291492 // If a page calls window.close() twice, we'll end up here twice, but that's
1493 // OK. It is safe to send multiple Close messages.
1494
[email protected]2533ce12009-05-09 00:02:241495 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1496 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1497 // could be closed before the JS finishes executing. So instead, post a
1498 // message back to the message loop, which won't run until the JS is
1499 // complete, and then the Close message can be sent.
ennef3c58142014-12-09 21:44:381500 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211501 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291502}
1503
[email protected]9017d7852013-11-21 17:47:351504void RenderWidget::QueueSyntheticGesture(
1505 scoped_ptr<SyntheticGestureParams> gesture_params,
1506 const SyntheticGestureCompletionCallback& callback) {
1507 DCHECK(!callback.is_null());
1508
1509 pending_synthetic_gesture_callbacks_.push(callback);
1510
1511 SyntheticGesturePacket gesture_packet;
1512 gesture_packet.set_gesture_params(gesture_params.Pass());
1513
1514 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1515}
1516
initial.commit09911bf2008-07-26 23:55:291517void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031518 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381519 WillCloseLayerTreeView();
1520 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291521 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281522 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291523 webwidget_ = NULL;
1524 }
1525}
1526
[email protected]4873c7d2009-07-16 06:36:281527WebRect RenderWidget::windowRect() {
1528 if (pending_window_rect_count_)
1529 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241530
[email protected]80ad8622012-11-07 16:33:031531 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291532}
1533
[email protected]180ef242013-11-07 06:50:461534void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301535 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541536 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301537}
1538
[email protected]b2e4c70132013-10-03 02:07:511539void RenderWidget::setWindowRect(const WebRect& rect) {
1540 WebRect pos = rect;
1541 if (popup_origin_scale_for_emulation_) {
1542 float scale = popup_origin_scale_for_emulation_;
1543 pos.x = popup_screen_origin_for_emulation_.x() +
1544 (pos.x - popup_view_origin_for_emulation_.x()) * scale;
1545 pos.y = popup_screen_origin_for_emulation_.y() +
1546 (pos.y - popup_view_origin_for_emulation_.y()) * scale;
1547 }
1548
[email protected]5b45ad42013-10-25 00:42:041549 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201550 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031551 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1552 SetPendingWindowRect(pos);
1553 } else {
[email protected]ec951b9d2013-10-20 06:21:201554 initial_pos_ = pos;
[email protected]8be1c582013-03-06 00:55:031555 }
initial.commit09911bf2008-07-26 23:55:291556 } else {
bokanf0fd2412014-10-30 15:28:551557 ResizeSynchronously(pos, visible_viewport_size_);
initial.commit09911bf2008-07-26 23:55:291558 }
1559}
1560
[email protected]2533ce12009-05-09 00:02:241561void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1562 pending_window_rect_ = rect;
1563 pending_window_rect_count_++;
1564}
1565
[email protected]4873c7d2009-07-16 06:36:281566WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241567 if (pending_window_rect_count_) {
1568 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1569 // the RootWindowRect is probably going to return wrong results since the
1570 // browser may not have processed the Move yet. There isn't really anything
1571 // good to do in this case, and it shouldn't happen - since this size is
1572 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281573 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241574 }
1575
[email protected]80ad8622012-11-07 16:33:031576 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371577}
1578
[email protected]4873c7d2009-07-16 06:36:281579WebRect RenderWidget::windowResizerRect() {
1580 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191581}
1582
[email protected]fa7b1dc2010-06-23 17:53:041583void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031584 // To prevent this renderer process from sending unnecessary IPC messages to
1585 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041586 // only during the input method attached to the browser process is active.
1587 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291588}
1589
[email protected]37a241c2013-12-03 03:16:171590void RenderWidget::OnCandidateWindowShown() {
1591 webwidget_->didShowCandidateWindow();
1592}
1593
1594void RenderWidget::OnCandidateWindowUpdated() {
1595 webwidget_->didUpdateCandidateWindow();
1596}
1597
1598void RenderWidget::OnCandidateWindowHidden() {
1599 webwidget_->didHideCandidateWindow();
1600}
1601
[email protected]fa7b1dc2010-06-23 17:53:041602void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261603 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041604 const std::vector<WebCompositionUnderline>& underlines,
1605 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131606 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281607 return;
[email protected]66fca5bc2013-05-23 06:58:291608 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361609 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041610 text, WebVector<WebCompositionUnderline>(underlines),
1611 selection_start, selection_end)) {
1612 // If we failed to set the composition text, then we need to let the browser
1613 // process to cancel the input method's ongoing composition session, to make
1614 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221615 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261616 }
[email protected]88dbe32f2013-06-20 23:31:361617 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041618}
1619
[email protected]fcf75d42013-12-03 20:11:261620void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511621 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021622 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131623 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041624 return;
[email protected]66fca5bc2013-05-23 06:58:291625 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041626 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021627 if (text.length())
1628 webwidget_->confirmComposition(text);
1629 else if (keep_selection)
1630 webwidget_->confirmComposition(WebWidget::KeepSelection);
1631 else
1632 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041633 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361634 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291635}
1636
[email protected]0bc1f572013-04-17 01:46:311637void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121638 // During shutdown we can just ignore this message.
1639 if (!webwidget_)
1640 return;
1641
[email protected]0bc1f572013-04-17 01:46:311642 // Even if the browser provides an empty damage rect, it's still expecting to
1643 // receive a repaint ack so just damage the entire widget bounds.
1644 if (size_to_paint.IsEmpty()) {
1645 size_to_paint = size_;
1646 }
1647
[email protected]ec7dc112008-08-06 05:30:121648 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051649 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311650 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121651}
1652
[email protected]79fa22e2013-08-23 15:18:121653void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351654 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1655
1656 pending_synthetic_gesture_callbacks_.front().Run();
1657 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271658}
1659
[email protected]4873c7d2009-07-16 06:36:281660void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111661 if (!webwidget_)
1662 return;
[email protected]4873c7d2009-07-16 06:36:281663 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111664}
1665
[email protected]80ad8622012-11-07 16:33:031666void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1667 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511668 if (screen_metrics_emulator_) {
1669 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1670 view_screen_rect, window_screen_rect);
1671 } else {
1672 view_screen_rect_ = view_screen_rect;
1673 window_screen_rect_ = window_screen_rect;
1674 }
[email protected]80ad8622012-11-07 16:33:031675 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1676}
1677
[email protected]adb362312014-06-28 06:04:241678void RenderWidget::showImeIfNeeded() {
1679 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131680}
1681
[email protected]adb362312014-06-28 06:04:241682void RenderWidget::OnShowImeIfNeeded() {
1683#if defined(OS_ANDROID) || defined(USE_AURA)
1684 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1685#endif
1686}
1687
1688#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131689void RenderWidget::IncrementOutstandingImeEventAcks() {
1690 ++outstanding_ime_acks_;
1691}
1692
1693void RenderWidget::OnImeEventAck() {
1694 --outstanding_ime_acks_;
1695 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511696}
[email protected]105dffb42013-02-20 03:46:211697#endif
1698
[email protected]0d1ebed12013-08-05 22:01:131699bool RenderWidget::ShouldHandleImeEvent() {
1700#if defined(OS_ANDROID)
1701 return !!webwidget_ && outstanding_ime_acks_ == 0;
1702#else
1703 return !!webwidget_;
1704#endif
1705}
1706
[email protected]c27dd4f2014-05-22 18:05:191707bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1708 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521709 // If we pause multiple times during a single mouse move event, we should
1710 // only send ACK once.
1711 if (!ignore_ack_for_mouse_move_from_debugger_) {
1712 InputHostMsg_HandleInputEvent_ACK_Params ack;
1713 ack.type = handling_event_type_;
1714 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED;
1715 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
1716 }
[email protected]c27dd4f2014-05-22 18:05:191717 return true;
1718 }
1719 return false;
1720}
1721
1722void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1723 ignore_ack_for_mouse_move_from_debugger_ = true;
1724}
1725
[email protected]468ac582012-11-20 00:53:191726void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1727 if (device_scale_factor_ == device_scale_factor)
1728 return;
1729
1730 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051731 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191732}
1733
[email protected]28ed6b32014-06-08 02:16:271734bool RenderWidget::SetDeviceColorProfile(
1735 const std::vector<char>& color_profile) {
1736 if (device_color_profile_ == color_profile)
1737 return false;
1738
1739 device_color_profile_ = color_profile;
1740 return true;
1741}
1742
noeldb4df152014-09-16 17:45:201743void RenderWidget::ResetDeviceColorProfileForTesting() {
1744 if (!device_color_profile_.empty())
1745 device_color_profile_.clear();
1746 device_color_profile_.push_back('0');
1747}
1748
[email protected]fcdc5642014-05-09 14:32:241749void RenderWidget::OnOrientationChange() {
1750}
1751
[email protected]ceb36f7d2012-10-31 18:33:241752gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521753 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241754 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521755}
1756
[email protected]bee16aab2009-08-26 15:55:031757void RenderWidget::SetHidden(bool hidden) {
1758 if (is_hidden_ == hidden)
1759 return;
1760
1761 // The status has changed. Tell the RenderThread about it.
1762 is_hidden_ = hidden;
1763 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001764 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031765 else
[email protected]b2db9272014-01-10 17:42:001766 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031767}
1768
[email protected]2b624c562011-10-27 22:58:261769void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261770 if (!webwidget_)
1771 return;
1772
1773 if (is_fullscreen_) {
1774 webwidget_->willExitFullScreen();
1775 } else {
1776 webwidget_->willEnterFullScreen();
1777 }
[email protected]2b624c562011-10-27 22:58:261778}
1779
1780void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261781 if (!webwidget_)
1782 return;
1783
1784 if (is_fullscreen_) {
1785 webwidget_->didEnterFullScreen();
1786 } else {
1787 webwidget_->didExitFullScreen();
1788 }
[email protected]2b624c562011-10-27 22:58:261789}
1790
[email protected]674741932009-02-04 23:44:461791bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051792 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461793}
1794
[email protected]674741932009-02-04 23:44:461795void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051796 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461797}
1798
[email protected]674741932009-02-04 23:44:461799void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051800 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461801}
1802
[email protected]b18583c2012-12-18 06:55:271803static bool IsDateTimeInput(ui::TextInputType type) {
1804 return type == ui::TEXT_INPUT_TYPE_DATE ||
1805 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1806 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1807 type == ui::TEXT_INPUT_TYPE_MONTH ||
1808 type == ui::TEXT_INPUT_TYPE_TIME ||
1809 type == ui::TEXT_INPUT_TYPE_WEEK;
1810}
1811
[email protected]66fca5bc2013-05-23 06:58:291812
1813void RenderWidget::StartHandlingImeEvent() {
1814 DCHECK(!handling_ime_event_);
1815 handling_ime_event_ = true;
1816}
1817
1818void RenderWidget::FinishHandlingImeEvent() {
1819 DCHECK(handling_ime_event_);
1820 handling_ime_event_ = false;
1821 // While handling an ime event, text input state and selection bounds updates
1822 // are ignored. These must explicitly be updated once finished handling the
1823 // ime event.
1824 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471825#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361826 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471827#endif
[email protected]66fca5bc2013-05-23 06:58:291828}
1829
shuchen3517bb62014-10-15 03:55:571830void RenderWidget::UpdateTextInputType() {
1831 // On Windows, not only an IME but also an on-screen keyboard relies on the
1832 // latest TextInputType to optimize its layout and functionality. Thus
1833 // |input_method_is_active_| is no longer an appropriate condition to suppress
1834 // TextInputTypeChanged IPC on Windows.
1835 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1836 // on other platforms as well as Windows if the overhead is acceptable.
1837#if !defined(OS_WIN)
1838 if (!input_method_is_active_)
1839 return;
1840#endif
1841
1842 ui::TextInputType new_type = GetTextInputType();
1843 if (IsDateTimeInput(new_type))
1844 return; // Not considered as a text input field in WebKit/Chromium.
1845
1846 bool new_can_compose_inline = CanComposeInline();
1847
1848 blink::WebTextInputInfo new_info;
1849 if (webwidget_)
1850 new_info = webwidget_->textInputInfo();
1851 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201852 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571853
1854 if (text_input_type_ != new_type
1855 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201856 || text_input_mode_ != new_mode
1857 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571858 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1859 new_type,
1860 new_mode,
shuchen82ce8c52014-10-23 01:55:201861 new_can_compose_inline,
1862 new_flags));
shuchen3517bb62014-10-15 03:55:571863 text_input_type_ = new_type;
1864 can_compose_inline_ = new_can_compose_inline;
1865 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201866 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571867 }
1868}
1869
1870#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361871void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1872 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501873 if (handling_ime_event_)
1874 return;
[email protected]90f24152014-04-09 12:41:361875 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291876 return;
[email protected]ad26ef42011-06-17 07:59:451877 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271878 if (IsDateTimeInput(new_type))
1879 return; // Not considered as a text input field in WebKit/Chromium.
1880
[email protected]180ef242013-11-07 06:50:461881 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211882 if (webwidget_)
1883 new_info = webwidget_->textInputInfo();
1884
[email protected]ad26ef42011-06-17 07:59:451885 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211886
[email protected]3306f262012-09-21 19:20:421887 // Only sends text input params if they are changed or if the ime should be
1888 // shown.
[email protected]90f24152014-04-09 12:41:361889 if (show_ime == SHOW_IME_IF_NEEDED ||
1890 (text_input_type_ != new_type ||
1891 text_input_info_ != new_info ||
1892 can_compose_inline_ != new_can_compose_inline)
1893#if defined(OS_ANDROID)
1894 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021895#endif
[email protected]90f24152014-04-09 12:41:361896 ) {
1897 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211898 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401899 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211900 p.value = new_info.value.utf8();
1901 p.selection_start = new_info.selectionStart;
1902 p.selection_end = new_info.selectionEnd;
1903 p.composition_start = new_info.compositionStart;
1904 p.composition_end = new_info.compositionEnd;
1905 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361906 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1907#if defined(USE_AURA)
1908 p.is_non_ime_change = true;
1909#endif
[email protected]183e28d2014-01-20 18:18:021910#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361911 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1912 text_field_is_dirty_;
1913 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131914 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361915 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021916#endif
shuchen3517bb62014-10-15 03:55:571917#if defined(USE_AURA)
1918 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1919 new_type,
1920 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:201921 new_can_compose_inline,
1922 new_info.flags));
shuchen3517bb62014-10-15 03:55:571923#endif
[email protected]5b739cb2012-08-21 20:35:211924 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1925
1926 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041927 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451928 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201929 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291930 }
initial.commit09911bf2008-07-26 23:55:291931}
shuchen3517bb62014-10-15 03:55:571932#endif
initial.commit09911bf2008-07-26 23:55:291933
[email protected]7c8873e2013-02-05 08:03:011934void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1935 WebRect focus_webrect;
1936 WebRect anchor_webrect;
1937 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1938 *focus = focus_webrect;
1939 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321940}
1941
[email protected]e99ef6f2011-10-16 01:13:001942void RenderWidget::UpdateSelectionBounds() {
1943 if (!webwidget_)
1944 return;
[email protected]66fca5bc2013-05-23 06:58:291945 if (handling_ime_event_)
1946 return;
[email protected]e99ef6f2011-10-16 01:13:001947
jddukeacf809e2014-09-23 20:38:381948 // With composited selection updates, the selection bounds will be reported
1949 // directly by the compositor, in which case explicit IPC selection
1950 // notifications should be suppressed.
1951 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
1952 ViewHostMsg_SelectionBounds_Params params;
1953 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1954 if (selection_anchor_rect_ != params.anchor_rect ||
1955 selection_focus_rect_ != params.focus_rect) {
1956 selection_anchor_rect_ = params.anchor_rect;
1957 selection_focus_rect_ = params.focus_rect;
1958 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1959 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1960 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1961 }
[email protected]58b48a0d2012-06-13 07:01:351962 }
jddukeacf809e2014-09-23 20:38:381963
[email protected]88dbe32f2013-06-20 23:31:361964 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001965}
1966
[email protected]180ef242013-11-07 06:50:461967// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
1968COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \
[email protected]ad26ef42011-06-17 07:59:451969 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461970COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \
[email protected]ad26ef42011-06-17 07:59:451971 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461972COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \
[email protected]ad26ef42011-06-17 07:59:451973 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461974COMPILE_ASSERT(int(blink::WebTextInputTypeSearch) == \
[email protected]caf38ed2011-07-28 13:15:181975 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461976COMPILE_ASSERT(int(blink::WebTextInputTypeEmail) == \
[email protected]caf38ed2011-07-28 13:15:181977 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461978COMPILE_ASSERT(int(blink::WebTextInputTypeNumber) == \
[email protected]caf38ed2011-07-28 13:15:181979 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461980COMPILE_ASSERT(int(blink::WebTextInputTypeTelephone) == \
[email protected]caf38ed2011-07-28 13:15:181981 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461982COMPILE_ASSERT(int(blink::WebTextInputTypeURL) == \
[email protected]caf38ed2011-07-28 13:15:181983 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461984COMPILE_ASSERT(int(blink::WebTextInputTypeDate) == \
[email protected]feb8cf752012-06-08 04:48:001985 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461986COMPILE_ASSERT(int(blink::WebTextInputTypeDateTime) == \
[email protected]feb8cf752012-06-08 04:48:001987 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461988COMPILE_ASSERT(int(blink::WebTextInputTypeDateTimeLocal) == \
[email protected]feb8cf752012-06-08 04:48:001989 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461990COMPILE_ASSERT(int(blink::WebTextInputTypeMonth) == \
[email protected]feb8cf752012-06-08 04:48:001991 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461992COMPILE_ASSERT(int(blink::WebTextInputTypeTime) == \
[email protected]feb8cf752012-06-08 04:48:001993 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461994COMPILE_ASSERT(int(blink::WebTextInputTypeWeek) == \
[email protected]feb8cf752012-06-08 04:48:001995 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461996COMPILE_ASSERT(int(blink::WebTextInputTypeTextArea) == \
[email protected]2a9893672012-11-09 20:33:011997 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461998COMPILE_ASSERT(int(blink::WebTextInputTypeContentEditable) == \
[email protected]2a9893672012-11-09 20:33:011999 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:462000COMPILE_ASSERT(int(blink::WebTextInputTypeDateTimeField) == \
[email protected]8b4992e2013-03-01 15:42:152001 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452002
[email protected]5b739cb2012-08-21 20:35:212003ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462004 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212005 // Check the type is in the range representable by ui::TextInputType.
2006 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462007 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212008 return static_cast<ui::TextInputType>(type);
2009}
2010
[email protected]ad26ef42011-06-17 07:59:452011ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272012 if (webwidget_)
2013 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452014 return ui::TEXT_INPUT_TYPE_NONE;
2015}
2016
[email protected]501ea13d2013-07-09 17:03:292017void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302018#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112019 // TODO(yukawa): Start sending character bounds when the browser side
2020 // implementation becomes ready (crbug.com/424866).
2021#else
[email protected]db4fc1e2013-09-06 20:01:512022 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292023 if (should_update_range) {
2024 GetCompositionRange(&range);
2025 } else {
2026 range = composition_range_;
2027 }
2028 std::vector<gfx::Rect> character_bounds;
2029 GetCompositionCharacterBounds(&character_bounds);
2030
2031 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2032 return;
2033 composition_character_bounds_ = character_bounds;
2034 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222035 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292036 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112037#endif
[email protected]501ea13d2013-07-09 17:03:292038}
2039
[email protected]58b48a0d2012-06-13 07:01:352040void RenderWidget::GetCompositionCharacterBounds(
2041 std::vector<gfx::Rect>* bounds) {
2042 DCHECK(bounds);
2043 bounds->clear();
2044}
2045
[email protected]db4fc1e2013-09-06 20:01:512046void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362047 size_t location, length;
2048 if (webwidget_->compositionRange(&location, &length)) {
2049 range->set_start(location);
2050 range->set_end(location + length);
2051 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2052 range->set_start(location);
2053 range->set_end(location + length);
2054 } else {
[email protected]db4fc1e2013-09-06 20:01:512055 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362056 }
2057}
2058
[email protected]501ea13d2013-07-09 17:03:292059bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512060 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292061 const std::vector<gfx::Rect>& bounds) {
2062 if (composition_range_ != range)
2063 return true;
2064 if (bounds.size() != composition_character_bounds_.size())
2065 return true;
2066 for (size_t i = 0; i < bounds.size(); ++i) {
2067 if (bounds[i] != composition_character_bounds_[i])
2068 return true;
2069 }
2070 return false;
2071}
[email protected]501ea13d2013-07-09 17:03:292072
[email protected]a4f0d882014-05-01 23:48:102073#if defined(OS_ANDROID)
2074void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2075 // If not initialized, default to white. Note that 0 is different from black
2076 // as black still has alpha 0xFF.
2077 if (!bg_color)
2078 bg_color = SK_ColorWHITE;
2079
2080 if (bg_color != body_background_color_) {
2081 body_background_color_ = bg_color;
2082 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2083 }
2084}
timav7a5032e2014-12-05 01:59:432085
2086bool RenderWidget::DoesRecordFullLayer() const {
2087 SynchronousCompositorFactory* synchronous_compositor_factory =
2088 SynchronousCompositorFactory::GetInstance();
2089
2090 // We assume that the absence of synchronous_compositor_factory
2091 // means we are in Chrome. In chrome, we want to clip, i.e.
2092 // *not* to record the full layer.
2093 if (!synchronous_compositor_factory)
2094 return false;
2095
2096 return synchronous_compositor_factory->RecordFullLayer();
2097}
[email protected]a4f0d882014-05-01 23:48:102098#endif
2099
[email protected]ad26ef42011-06-17 07:59:452100bool RenderWidget::CanComposeInline() {
2101 return true;
[email protected]56ea1a62011-05-30 07:05:572102}
2103
[email protected]4873c7d2009-07-16 06:36:282104WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042105 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282106}
2107
[email protected]f660d9c2012-06-06 18:31:212108float RenderWidget::deviceScaleFactor() {
2109 return device_scale_factor_;
2110}
2111
[email protected]fa7b1dc2010-06-23 17:53:042112void RenderWidget::resetInputMethod() {
2113 if (!input_method_is_active_)
2114 return;
2115
[email protected]0e45bd02013-07-12 20:20:022116 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042117 // If the last text input type is not None, then we should finish any
2118 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452119 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042120 // If a composition text exists, then we need to let the browser process
2121 // to cancel the input method's ongoing composition session.
2122 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222123 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042124 }
[email protected]d4cff272011-05-02 15:46:012125
[email protected]88dbe32f2013-06-20 23:31:362126 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042127}
2128
[email protected]c68c3e4e2013-01-24 00:36:562129void RenderWidget::didHandleGestureEvent(
2130 const WebGestureEvent& event,
2131 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022132#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562133 if (event_cancelled)
2134 return;
[email protected]07c70d22014-08-21 08:33:462135 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362136 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462137 } else if (event.type == WebInputEvent::GestureLongPress) {
2138 DCHECK(webwidget_);
2139 if (webwidget_->textInputInfo().value.isEmpty())
2140 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2141 else
2142 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562143 }
2144#endif
2145}
2146
[email protected]7912e822014-04-16 02:37:032147void RenderWidget::StartCompositor() {
2148 // For widgets that are never visible, we don't need the compositor to run
2149 // at all.
2150 if (never_visible_)
2151 return;
2152 compositor_->setSurfaceReady();
2153}
2154
[email protected]29e2fb42013-07-19 01:13:472155void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292156 size_t i = 0;
2157 for (; i < plugin_window_moves_.size(); ++i) {
2158 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582159 if (move.rects_valid) {
2160 plugin_window_moves_[i] = move;
2161 } else {
2162 plugin_window_moves_[i].visible = move.visible;
2163 }
initial.commit09911bf2008-07-26 23:55:292164 break;
2165 }
2166 }
2167
2168 if (i == plugin_window_moves_.size())
2169 plugin_window_moves_.push_back(move);
2170}
[email protected]268654772009-08-06 23:02:042171
2172void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2173 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2174 i != plugin_window_moves_.end(); ++i) {
2175 if (i->window == window) {
2176 plugin_window_moves_.erase(i);
2177 break;
2178 }
2179 }
2180}
[email protected]67bfb83f2011-09-22 03:36:372181
[email protected]63b465922012-09-06 02:04:522182
[email protected]24ed0432013-04-24 07:50:312183RenderWidgetCompositor* RenderWidget::compositor() const {
2184 return compositor_.get();
2185}
2186
[email protected]180ef242013-11-07 06:50:462187bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372188 return false;
2189}
[email protected]c3d45532011-10-07 19:20:402190
[email protected]41d86852012-11-07 12:23:242191bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462192 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242193 return false;
2194}
2195
[email protected]ce6689f2013-03-29 12:52:552196void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2197 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2198}
2199
[email protected]5d0bbdfa92013-12-10 00:35:512200void RenderWidget::setTouchAction(
2201 blink::WebTouchAction web_touch_action) {
2202
2203 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2204 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192205 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512206 return;
2207
[email protected]a18f67a2013-12-20 19:44:362208 // Verify the same values are used by the types so we can cast between them.
2209 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_AUTO) ==
2210 blink::WebTouchActionAuto,
2211 enum_values_must_match_for_touch_action);
2212 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_NONE) ==
2213 blink::WebTouchActionNone,
2214 enum_values_must_match_for_touch_action);
2215 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_X) ==
2216 blink::WebTouchActionPanX,
2217 enum_values_must_match_for_touch_action);
2218 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_Y) ==
2219 blink::WebTouchActionPanY,
2220 enum_values_must_match_for_touch_action);
[email protected]2bd73272014-03-13 19:36:112221 COMPILE_ASSERT(
2222 static_cast<blink::WebTouchAction>(TOUCH_ACTION_PINCH_ZOOM) ==
2223 blink::WebTouchActionPinchZoom,
2224 enum_values_must_match_for_touch_action);
[email protected]a18f67a2013-12-20 19:44:362225
2226 content::TouchAction content_touch_action =
2227 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512228 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2229}
2230
[email protected]90f24152014-04-09 12:41:362231void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2232#if defined(OS_ANDROID)
2233 text_field_is_dirty_ = true;
2234#endif
2235}
2236
[email protected]3d5c243b2012-11-30 00:26:012237bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2238 return true;
2239}
2240
[email protected]0634cdd42013-08-16 00:46:092241scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132242RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592243 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092244 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ebc0e1df2013-08-01 02:46:222245 if (CommandLine::ForCurrentProcess()->HasSwitch(
2246 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092247 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292248 if (!RenderThreadImpl::current())
2249 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402250 CauseForGpuLaunch cause =
2251 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292252 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402253 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222254 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292255 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592256
[email protected]828a3932014-04-02 14:43:132257 // Explicitly disable antialiasing for the compositor. As of the time of
2258 // this writing, the only platform that supported antialiasing for the
2259 // compositor was Mac OS X, because the on-screen OpenGL context creation
2260 // code paths on Windows and Linux didn't yet have multisampling support.
2261 // Mac OS X essentially always behaves as though it's rendering offscreen.
2262 // Multisampling has a heavy cost especially on devices with relatively low
2263 // fill rate like most notebooks, and the Mac implementation would need to
2264 // be optimized to resolve directly into the IOSurface shared between the
2265 // GPU and browser processes. For these reasons and to avoid platform
2266 // disparities we explicitly disable antialiasing.
2267 blink::WebGraphicsContext3D::Attributes attributes;
2268 attributes.antialias = false;
2269 attributes.shareResources = true;
2270 attributes.noAutomaticFlushes = true;
2271 attributes.depth = false;
2272 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132273 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292274 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012275#if defined(OS_ANDROID)
2276 // If we raster too fast we become upload bound, and pending
2277 // uploads consume memory. For maximum upload throughput, we would
2278 // want to allow for upload_throughput * pipeline_time of pending
2279 // uploads, after which we are just wasting memory. Since we don't
2280 // know our upload throughput yet, this just caps our memory usage.
2281 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272282 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032283 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012284 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032285 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012286 // Deadline to draw a frame to achieve 60 frames per second.
2287 const size_t kMillisecondsPerFrame = 16;
2288 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032289 size_t max_transfer_buffer_usage_mb =
2290 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2291 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012292 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2293 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292294 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032295 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012296#endif
[email protected]96ab016c2013-10-23 00:50:292297
[email protected]96ab016c2013-10-23 00:50:292298 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132299 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2300 GetURLForGraphicsContext3D(),
2301 gpu_channel_host.get(),
2302 attributes,
[email protected]828a3932014-04-02 14:43:132303 lose_context_when_out_of_memory,
2304 limits,
2305 NULL));
[email protected]0634cdd42013-08-16 00:46:092306 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592307}
2308
[email protected]e3244ed2014-06-20 20:04:272309void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2310 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162311}
2312
[email protected]e3244ed2014-06-20 20:04:272313void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2314 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162315}
2316
[email protected]de3c5d82014-05-28 22:12:592317void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2318 render_frames_.AddObserver(frame);
2319}
2320
2321void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2322 render_frames_.RemoveObserver(frame);
2323}
2324
[email protected]a017938b2014-05-27 21:17:172325#if defined(VIDEO_HOLE)
2326void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2327 video_hole_frames_.AddObserver(frame);
2328}
2329
2330void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2331 video_hole_frames_.RemoveObserver(frame);
2332}
2333#endif // defined(VIDEO_HOLE)
2334
[email protected]e9ff79c2012-10-19 21:31:262335} // namespace content