blob: fdf034b0dcd1cf291b21f8a2cccb2cba4a183a6b [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]32876ae2011-11-15 22:25:217#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:008#include "base/command_line.h"
[email protected]366ae242011-05-10 02:23:589#include "base/debug/trace_event.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2114#include "base/stl_util.h"
[email protected]8a9d6ca32011-06-06 20:11:3015#include "base/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4816#include "build/build_config.h"
[email protected]992db4c2011-05-12 15:37:1517#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5018#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2919#include "content/public/common/content_switches.h"
[email protected]8704f89b2011-04-15 00:30:0520#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4421#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1922#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1823#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4824#include "skia/ext/platform_canvas.h"
[email protected]8bd0fe62011-01-17 06:44:3725#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]4b1146bc2012-07-10 18:46:0326#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]a7547fb2012-03-08 04:43:4427#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3728#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
29#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0130#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3731#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4132#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
33#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]e6e90dc2011-12-03 00:01:3734#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
35#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
[email protected]d353541f2012-05-03 22:45:4136#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1337#include "ui/base/ui_base_switches.h"
[email protected]a25e25b2012-09-28 14:32:3738#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3539#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4840#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2741#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4142#include "ui/surface/transport_dib.h"
[email protected]b63d58d2012-11-26 22:37:4443#include "webkit/compositor_bindings/web_rendering_stats_impl.h"
[email protected]8c89e7792009-08-19 21:18:3444#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5045#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4646#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4847
48#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4949#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5250#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4151#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4852#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4453
[email protected]8bd0fe62011-01-17 06:44:3754#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2955
[email protected]fa7b1dc2010-06-23 17:53:0456using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3057using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2458using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2259using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0660using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2861using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4462using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0063using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2864using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5965using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1866using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0167using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5268using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1969using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5270using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2871using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2472using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0473using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1874using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2675
76namespace content {
[email protected]62cb33cae2009-03-27 23:30:2277
[email protected]6fd35b72012-03-01 19:46:4178RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:0479 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:4480 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:2981 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:5682 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:1183 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2984 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:3085 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:3586 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2987 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:0688 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:0589 update_reply_pending_(false),
[email protected]ea3ee0a2012-05-15 03:43:0990 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:2491 using_asynchronous_swapbuffers_(false),
92 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2993 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2994 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:0995 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:2996 needs_repainting_on_restore_(false),
97 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4998 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4899 closing_(false),
[email protected]14392a52012-05-02 20:28:44100 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04101 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45102 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
103 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12104 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48105 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12106 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50107 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21108 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07109 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04110 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52111 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27112 throttle_input_events_(true),
[email protected]cb6430932012-10-31 00:53:36113 next_smooth_scroll_gesture_id_(0),
114 is_threaded_compositing_enabled_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05115 if (!swapped_out)
116 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27117 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18118 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
119 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36120 is_threaded_compositing_enabled_ =
121 CommandLine::ForCurrentProcess()->HasSwitch(
122 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29123}
124
125RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11126 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21127 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35128 if (current_paint_buf_) {
129 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
130 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29131 }
[email protected]992db4c2011-05-12 15:37:15132 // If we are swapped out, we have released already.
133 if (!is_swapped_out_)
134 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29135}
136
[email protected]484955942010-08-19 16:13:18137// static
[email protected]8085dbc82008-09-26 22:53:44138RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04139 WebKit::WebPopupType popup_type,
140 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29141 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41142 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04143 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29144 if (widget->Init(opener_id)) { // adds reference on success.
145 return widget;
146 }
147 return NULL;
initial.commit09911bf2008-07-26 23:55:29148}
149
[email protected]484955942010-08-19 16:13:18150// static
151WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
152 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03153 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18154 break;
155 case WebKit::WebPopupTypeSelect:
156 case WebKit::WebPopupTypeSuggestion:
157 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44158 case WebKit::WebPopupTypePage:
159 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03160 case WebKit::WebPopupTypeHelperPlugin:
161 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18162 default:
163 NOTREACHED();
164 }
165 return NULL;
166}
167
[email protected]a635f942012-12-07 10:34:29168bool RenderWidget::Init(int32 opener_id) {
169 return DoInit(opener_id,
170 RenderWidget::CreateWebWidget(this),
171 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
172 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18173}
174
[email protected]a635f942012-12-07 10:34:29175bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06176 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18177 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29178 DCHECK(!webwidget_);
179
180 if (opener_id != MSG_ROUTING_NONE)
181 opener_id_ = opener_id;
182
[email protected]484955942010-08-19 16:13:18183 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29184
[email protected]380244092011-10-07 17:26:27185 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29186 if (result) {
[email protected]380244092011-10-07 17:26:27187 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29188 // Take a reference on behalf of the RenderThread. This will be balanced
189 // when we receive ViewMsg_Close.
190 AddRef();
[email protected]a635f942012-12-07 10:34:29191 return true;
initial.commit09911bf2008-07-26 23:55:29192 } else {
[email protected]a635f942012-12-07 10:34:29193 // The above Send can fail when the tab is closing.
194 return false;
initial.commit09911bf2008-07-26 23:55:29195 }
196}
197
[email protected]fc4404d2012-11-07 19:53:30198// This is used to complete pending inits and non-pending inits.
199void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29200 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29201
[email protected]fc4404d2012-11-07 19:53:30202 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42203
[email protected]479b0172012-10-29 19:27:09204 if (webwidget_) {
205 webwidget_->setCompositorSurfaceReady();
[email protected]cb6430932012-10-31 00:53:36206 if (is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:09207 webwidget_->enterForceCompositingMode(true);
208 }
[email protected]05a980d7a2012-02-07 22:16:42209 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29210
[email protected]6de74452009-02-25 18:04:59211 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29212}
213
[email protected]992db4c2011-05-12 15:37:15214void RenderWidget::SetSwappedOut(bool is_swapped_out) {
215 // We should only toggle between states.
216 DCHECK(is_swapped_out_ != is_swapped_out);
217 is_swapped_out_ = is_swapped_out;
218
219 // If we are swapping out, we will call ReleaseProcess, allowing the process
220 // to exit if all of its RenderViews are swapped out. We wait until the
221 // WasSwappedOut call to do this, to avoid showing the sad tab.
222 // If we are swapping in, we call AddRefProcess to prevent the process from
223 // exiting.
224 if (!is_swapped_out)
225 RenderProcess::current()->AddRefProcess();
226}
227
[email protected]a95986a82010-12-24 06:19:28228bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
229 bool handled = true;
230 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
231 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
232 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
233 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54234 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28235 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41236 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15237 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28238 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]a7266a92012-06-28 02:11:08239 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK, OnSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28240 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
241 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
242 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
243 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
244 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
245 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
246 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
247 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
[email protected]0e241b4b2012-08-18 09:06:27248 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted,
249 OnMsgSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28250 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
251 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53252 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03253 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]a95986a82010-12-24 06:19:28254 IPC_MESSAGE_UNHANDLED(handled = false)
255 IPC_END_MESSAGE_MAP()
256 return handled;
257}
initial.commit09911bf2008-07-26 23:55:29258
259bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15260 // Don't send any messages after the browser has told us to close, and filter
261 // most outgoing messages while swapped out.
262 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26263 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11264 closing_) {
initial.commit09911bf2008-07-26 23:55:29265 delete message;
266 return false;
267 }
268
269 // If given a messsage without a routing ID, then assign our routing ID.
270 if (message->routing_id() == MSG_ROUTING_NONE)
271 message->set_routing_id(routing_id_);
272
[email protected]380244092011-10-07 17:26:27273 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44274}
275
[email protected]61e2b3cc2012-03-02 16:13:34276void RenderWidget::Resize(const gfx::Size& new_size,
277 const gfx::Rect& resizer_rect,
278 bool is_fullscreen,
279 ResizeAck resize_ack) {
280 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
281 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
282 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29283
[email protected]61e2b3cc2012-03-02 16:13:34284 // Ignore this during shutdown.
285 if (!webwidget_)
286 return;
287
288 // Remember the rect where the resize corner will be drawn.
289 resizer_rect_ = resizer_rect;
290
291 // NOTE: We may have entered fullscreen mode without changing our size.
292 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
293 if (fullscreen_change)
294 WillToggleFullscreen();
295 is_fullscreen_ = is_fullscreen;
296
297 if (size_ != new_size) {
298 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34299 needs_repainting_on_restore_ = false;
300
301 size_ = new_size;
302
303 paint_aggregator_.ClearPendingUpdate();
304
305 // When resizing, we want to wait to paint before ACK'ing the resize. This
306 // ensures that we only resize as fast as we can paint. We only need to
307 // send an ACK if we are resized to a non-empty rect.
308 webwidget_->resize(new_size);
309 if (!new_size.IsEmpty()) {
310 if (!is_accelerated_compositing_active_) {
311 // Resize should have caused an invalidation of the entire view.
312 DCHECK(paint_aggregator_.HasPendingUpdate());
313 }
314
315 // Send the Resize_ACK flag once we paint again if requested.
316 if (resize_ack == SEND_RESIZE_ACK)
317 set_next_paint_is_resize_ack();
318 }
[email protected]ff475a322012-03-14 00:05:35319 } else {
320 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34321 }
322
323 if (fullscreen_change)
324 DidToggleFullscreen();
325
326 // If a resize ack is requested and it isn't set-up, then no more resizes will
327 // come in and in general things will go wrong.
328 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
329 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29330}
331
332void RenderWidget::OnClose() {
333 if (closing_)
334 return;
335 closing_ = true;
336
337 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03338 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27339 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03340 SetHidden(false);
341 }
initial.commit09911bf2008-07-26 23:55:29342
initial.commit09911bf2008-07-26 23:55:29343 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25344 // now. Post a task that only gets invoked when there are no nested message
345 // loops.
[email protected]32876ae2011-11-15 22:25:21346 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29347 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25348
349 // Balances the AddRef taken when we called AddRoute.
350 Release();
initial.commit09911bf2008-07-26 23:55:29351}
352
[email protected]61e2b3cc2012-03-02 16:13:34353// Got a response from the browser after the renderer decided to create a new
354// view.
[email protected]fc4404d2012-11-07 19:53:30355void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34356 DCHECK(routing_id_ != MSG_ROUTING_NONE);
357
[email protected]fc4404d2012-11-07 19:53:30358 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34359}
360
[email protected]f21c613a2009-02-12 14:46:17361void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09362 const gfx::Rect& resizer_rect,
363 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34364 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29365}
366
[email protected]b5913d72012-02-07 22:26:54367void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
368 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59369 gfx::Rect view_rect(size_);
370
[email protected]ce112fe2012-10-29 22:52:18371 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59372 if (!old_damage_rect.IsEmpty())
373 paint_aggregator_.InvalidateRect(old_damage_rect);
374
[email protected]ce112fe2012-10-29 22:52:18375 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59376 if (!new_damage_rect.IsEmpty())
377 paint_aggregator_.InvalidateRect(new_damage_rect);
378
[email protected]b5913d72012-02-07 22:26:54379 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59380
[email protected]b5913d72012-02-07 22:26:54381 if (webwidget_)
382 webwidget_->didChangeWindowResizerRect();
383 }
384}
385
initial.commit09911bf2008-07-26 23:55:29386void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31387 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29388 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03389 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29390}
391
[email protected]9e2e4632012-07-27 16:38:41392void RenderWidget::OnWasShown(bool needs_repainting) {
393 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29394 // During shutdown we can just ignore this message.
395 if (!webwidget_)
396 return;
397
398 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03399 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29400
401 if (!needs_repainting && !needs_repainting_on_restore_)
402 return;
403 needs_repainting_on_restore_ = false;
404
[email protected]d65adb12010-04-28 17:26:49405 // Tag the next paint as a restore ack, which is picked up by
406 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29407 set_next_paint_is_restore_ack();
408
409 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56410 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46411 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
412 } else {
413 scheduleComposite();
414 }
initial.commit09911bf2008-07-26 23:55:29415}
416
[email protected]992db4c2011-05-12 15:37:15417void RenderWidget::OnWasSwappedOut() {
418 // If we have been swapped out and no one else is using this process,
419 // it's safe to exit now. If we get swapped back in, we will call
420 // AddRefProcess in SetSwappedOut.
421 if (is_swapped_out_)
422 RenderProcess::current()->ReleaseProcess();
423}
424
[email protected]53d3f302009-12-21 04:42:05425void RenderWidget::OnRequestMoveAck() {
426 DCHECK(pending_window_rect_count_);
427 pending_window_rect_count_--;
428}
429
430void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58431 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21432 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05433 update_reply_pending_ = false;
434
[email protected]b4d08452010-10-05 17:34:35435 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
436 // have no current paint buffer.
437 if (current_paint_buf_) {
438 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
439 current_paint_buf_ = NULL;
440 }
441
[email protected]65225772011-05-12 21:10:24442 // If swapbuffers is still pending, then defer the update until the
443 // swapbuffers occurs.
444 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
445 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
446 return;
447 }
448
[email protected]29ed96a2012-02-04 18:12:16449 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18450 if (!is_accelerated_compositing_active_) {
451 DidFlushPaint();
452 }
[email protected]a2f6bc112009-06-27 16:27:25453
initial.commit09911bf2008-07-26 23:55:29454 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24455 DoDeferredUpdateAndSendInputAck();
456}
457
[email protected]d0be63772011-12-20 23:18:04458bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24459 return false;
460}
461
[email protected]479b0172012-10-29 19:27:09462bool RenderWidget::ForceCompositingModeEnabled() {
463 return false;
464}
465
[email protected]d0be63772011-12-20 23:18:04466void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24467 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21468 while (!updates_pending_swap_.empty()) {
469 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
470 updates_pending_swap_.pop_front();
471 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
472 // compositing pass, hence doesn't require an UpdateRect message.
473 if (msg)
474 Send(msg);
475 }
[email protected]65225772011-05-12 21:10:24476 num_swapbuffers_complete_pending_ = 0;
477 using_asynchronous_swapbuffers_ = false;
478 // Schedule another frame so the compositor learns about it.
479 scheduleComposite();
480}
481
[email protected]37a6f302011-07-11 23:43:08482void RenderWidget::OnSwapBuffersPosted() {
483 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21484
485 if (using_asynchronous_swapbuffers_) {
486 ViewHostMsg_UpdateRect* msg = NULL;
487 // pending_update_params_ can be NULL if the swap doesn't correspond to an
488 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
489 // message.
490 if (pending_update_params_.get()) {
491 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
492 pending_update_params_.reset();
493 }
494 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08495 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21496 }
[email protected]37a6f302011-07-11 23:43:08497}
498
499void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24500 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16501
[email protected]404939f2012-06-01 04:06:18502 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16503 DidFlushPaint();
504
[email protected]65225772011-05-12 21:10:24505 // When compositing deactivates, we reset the swapbuffers pending count. The
506 // swapbuffers acks may still arrive, however.
507 if (num_swapbuffers_complete_pending_ == 0) {
508 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
509 return;
510 }
[email protected]aa4117f2011-12-09 22:19:21511 DCHECK(!updates_pending_swap_.empty());
512 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
513 updates_pending_swap_.pop_front();
514 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
515 // compositing pass, hence doesn't require an UpdateRect message.
516 if (msg)
517 Send(msg);
[email protected]65225772011-05-12 21:10:24518 num_swapbuffers_complete_pending_--;
519
520 // If update reply is still pending, then defer the update until that reply
521 // occurs.
[email protected]d0be63772011-12-20 23:18:04522 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24523 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
524 return;
525 }
526
527 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06528 // when we were previously rendering. However, if an invalidation task is not
529 // posted, there may be software rendering work pending. In that case, don't
530 // early out.
531 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24532 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
533 return;
534 }
535
[email protected]cc66e682012-10-02 06:48:18536 // Do not call DoDeferredUpdate unless there's animation work to be done or
537 // a real invalidation. This prevents rendering in response to a swapbuffers
538 // callback coming back after we've navigated away from the page that
539 // generated it.
540 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
541 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
542 return;
543 }
544
[email protected]65225772011-05-12 21:10:24545 // Continue painting if necessary...
546 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29547}
548
initial.commit09911bf2008-07-26 23:55:29549void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24550 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56551 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29552
553 const char* data;
554 int data_length;
[email protected]5dd768212009-08-13 23:34:49555 handling_input_event_ = true;
556 if (!message.ReadData(&iter, &data, &data_length)) {
557 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29558 return;
[email protected]5dd768212009-08-13 23:34:49559 }
initial.commit09911bf2008-07-26 23:55:29560
561 const WebInputEvent* input_event =
562 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48563
[email protected]b68a0e52011-12-08 15:11:12564 bool is_keyboard_shortcut = false;
565 // is_keyboard_shortcut flag is only available for RawKeyDown events.
566 if (input_event->type == WebInputEvent::RawKeyDown)
567 message.ReadBool(&iter, &is_keyboard_shortcut);
568
[email protected]67bfb83f2011-09-22 03:36:37569 bool prevent_default = false;
570 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26571 const WebMouseEvent& mouse_event =
572 *static_cast<const WebMouseEvent*>(input_event);
573 TRACE_EVENT2("renderer", "HandleMouseMove",
574 "x", mouse_event.x, "y", mouse_event.y);
575 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37576 }
577
[email protected]41d86852012-11-07 12:23:24578 if (WebInputEvent::isGestureEventType(input_event->type)) {
579 const WebGestureEvent& gesture_event =
580 *static_cast<const WebGestureEvent*>(input_event);
581 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
582 }
583
[email protected]67bfb83f2011-09-22 03:36:37584 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12585 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
586 suppress_next_char_events_ = false;
587 if (!processed && webwidget_)
588 processed = webwidget_->handleInputEvent(*input_event);
589 }
590
591 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
592 // it's not processed by webkit, then we need to suppress the upcoming Char
593 // events.
594 if (!processed && is_keyboard_shortcut)
595 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29596
[email protected]3d5c243b2012-11-30 00:26:01597 InputEventAckState ack_result = processed ?
598 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
599 if (!processed && input_event->type == WebInputEvent::TouchStart) {
600 const WebTouchEvent& touch_event =
601 *static_cast<const WebTouchEvent*>(input_event);
602 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
603 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
604 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
605 }
606
[email protected]a9fb30aa2011-10-06 06:58:46607 IPC::Message* response =
608 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
[email protected]3d5c243b2012-11-30 00:26:01609 ack_result);
[email protected]3391a0772012-03-28 00:32:07610 bool event_type_gets_rate_limited =
611 input_event->type == WebInputEvent::MouseMove ||
612 input_event->type == WebInputEvent::MouseWheel ||
613 WebInputEvent::isTouchEventType(input_event->type);
614 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57615 throttle_input_events_ &&
616 ((webwidget_ ? webwidget_->isInputThrottled() : false) ||
617 paint_aggregator_.HasPendingUpdate());
[email protected]e2824412009-02-27 01:57:05618
[email protected]f8868d72012-04-27 19:13:03619 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24620 // We want to rate limit the input events in this case, so we'll wait for
621 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17622 if (pending_input_event_ack_.get()) {
623 // As two different kinds of events could cause us to postpone an ack
624 // we send it now, if we have one pending. The Browser should never
625 // send us the same kind of event we are delaying the ack for.
626 Send(pending_input_event_ack_.release());
627 }
[email protected]12fbad812009-09-01 18:21:24628 pending_input_event_ack_.reset(response);
629 } else {
630 Send(response);
631 }
632
[email protected]3306f262012-09-21 19:20:42633#if defined(OS_ANDROID)
634 // Allow the IME to be shown when the focus changes as a consequence
635 // of a processed touch end event.
636 if (input_event->type == WebInputEvent::TouchEnd && processed)
637 UpdateTextInputState(SHOW_IME_IF_NEEDED);
638#endif
639
[email protected]5dd768212009-08-13 23:34:49640 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48641
[email protected]67bfb83f2011-09-22 03:36:37642 if (!prevent_default) {
643 if (WebInputEvent::isKeyboardEventType(input_event->type))
644 DidHandleKeyEvent();
645 if (WebInputEvent::isMouseEventType(input_event->type))
646 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24647 if (WebInputEvent::isTouchEventType(input_event->type))
648 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37649 }
initial.commit09911bf2008-07-26 23:55:29650}
651
652void RenderWidget::OnMouseCaptureLost() {
653 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28654 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29655}
656
657void RenderWidget::OnSetFocus(bool enable) {
658 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33659 if (webwidget_)
660 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29661}
662
663void RenderWidget::ClearFocus() {
664 // We may have got the focus from the browser before this gets processed, in
665 // which case we do not want to unfocus ourself.
666 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28667 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29668}
669
[email protected]2d5d09d52009-06-15 14:29:21670void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00671 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21672 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06673 TRACE_EVENT2("renderer", "PaintRect",
674 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45675
676 const bool kEnableGpuBenchmarking =
677 CommandLine::ForCurrentProcess()->HasSwitch(
678 switches::kEnableGpuBenchmarking);
679 base::TimeTicks rasterize_begin_ticks;
680 if (kEnableGpuBenchmarking)
681 rasterize_begin_ticks = base::TimeTicks::HighResNow();
[email protected]4fb66842009-12-04 21:41:00682 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21683
684 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00685 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
686 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03687
[email protected]699ab0d2009-04-23 23:19:14688 // If there is a custom background, tile it.
689 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14690 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11691 skia::RefPtr<SkShader> shader = skia::AdoptRef(
692 SkShader::CreateBitmapShader(background_,
693 SkShader::kRepeat_TileMode,
694 SkShader::kRepeat_TileMode));
695 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20696
697 // Use kSrc_Mode to handle background_ transparency properly.
698 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
699
700 // Canvas could contain multiple update rects. Clip to given rect so that
701 // we don't accidentally clear other update rects.
702 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48703 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14704 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20705 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14706 }
707
[email protected]719b36f2010-12-22 20:36:46708 // First see if this rect is a plugin that can paint itself faster.
709 TransportDIB* optimized_dib = NULL;
710 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20711 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46712 webkit::ppapi::PluginInstance* optimized_instance =
713 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
714 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20715 &optimized_copy_rect,
716 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46717 if (optimized_instance) {
718 // This plugin can be optimize-painted and we can just ask it to paint
719 // itself. We don't actually need the TransportDIB in this case.
720 //
721 // This is an optimization for PPAPI plugins that know they're on top of
722 // the page content. If this rect is inside such a plugin, we can save some
723 // time and avoid re-rendering the page content which we know will be
724 // covered by the plugin later (this time can be significant, especially
725 // for a playing movie that is invalidating a lot).
726 //
727 // In the plugin movie case, hopefully the similar call to
728 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
729 // painting, because that avoids copying the plugin image to a different
730 // paint rect. Unfortunately, if anything on the page is animating other
731 // than the movie, it break this optimization since the union of the
732 // invalid regions will be larger than the plugin.
733 //
734 // This code optimizes that case, where we can still avoid painting in
735 // WebKit and filling the background (which can be slow) and just painting
736 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
737 // required.
[email protected]63ab54262012-11-09 15:58:45738 base::TimeTicks paint_begin_ticks;
739 if (kEnableGpuBenchmarking)
740 paint_begin_ticks = base::TimeTicks::HighResNow();
741
[email protected]df59dd42012-09-14 22:56:30742 SkAutoCanvasRestore auto_restore(canvas, true);
743 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46744 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27745 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21746 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45747 if (kEnableGpuBenchmarking) {
748 base::TimeDelta paint_time =
749 base::TimeTicks::HighResNow() - paint_begin_ticks;
750 if (!is_accelerated_compositing_active_)
751 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
752 }
[email protected]719b36f2010-12-22 20:36:46753 } else {
754 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45755 base::TimeTicks paint_begin_ticks;
756 if (kEnableGpuBenchmarking)
757 paint_begin_ticks = base::TimeTicks::HighResNow();
758
[email protected]719b36f2010-12-22 20:36:46759 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45760
761 if (kEnableGpuBenchmarking) {
762 base::TimeDelta paint_time =
763 base::TimeTicks::HighResNow() - paint_begin_ticks;
764 if (!is_accelerated_compositing_active_)
765 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
766 }
[email protected]719b36f2010-12-22 20:36:46767
768 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35769 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46770 }
initial.commit09911bf2008-07-26 23:55:29771
[email protected]4fb66842009-12-04 21:41:00772 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00773 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45774
775 if (kEnableGpuBenchmarking) {
776 base::TimeDelta rasterize_time =
777 base::TimeTicks::HighResNow() - rasterize_begin_ticks;
778 software_stats_.totalRasterizeTimeInSeconds += rasterize_time.InSecondsF();
779
780 int64 num_pixels_processed = rect.width() * rect.height();
781 software_stats_.totalPixelsPainted += num_pixels_processed;
782 software_stats_.totalPixelsRasterized += num_pixels_processed;
783 }
[email protected]4fb66842009-12-04 21:41:00784}
785
786void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
787 skia::PlatformCanvas* canvas) {
788 static bool kPaintBorder =
789 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
790 if (!kPaintBorder)
791 return;
792
[email protected]53d3f302009-12-21 04:42:05793 // Cycle through these colors to help distinguish new paint rects.
794 const SkColor colors[] = {
795 SkColorSetARGB(0x3F, 0xFF, 0, 0),
796 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
797 SkColorSetARGB(0x3F, 0, 0, 0xFF),
798 };
799 static int color_selector = 0;
800
[email protected]4fb66842009-12-04 21:41:00801 SkPaint paint;
802 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05803 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00804 paint.setStrokeWidth(1);
805
806 SkIRect irect;
807 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
808 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29809}
810
[email protected]52ccd0ea2011-02-16 01:09:05811void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30812 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30813 if (!animation_update_pending_) {
814 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59815 return;
[email protected]921244e42011-07-20 16:36:30816 }
[email protected]bd37ae252011-06-03 01:28:18817 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59818 // Record when we fired (according to base::Time::Now()) relative to when
819 // we posted the task to quantify how much the base::Time/base::TimeTicks
820 // skew is affecting animations.
821 base::TimeDelta animation_callback_delay = base::Time::Now() -
822 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
823 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
824 animation_callback_delay,
825 base::TimeDelta::FromMilliseconds(0),
826 base::TimeDelta::FromMilliseconds(30),
827 25);
828 }
[email protected]65225772011-05-12 21:10:24829 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24830}
831
[email protected]52ccd0ea2011-02-16 01:09:05832void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59833 if (!animation_update_pending_)
834 return;
[email protected]bd37ae252011-06-03 01:28:18835
836 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33837 base::TimeDelta animationInterval = IsRenderingVSynced() ?
838 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18839
[email protected]7c4329e2011-02-18 22:02:59840 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45841
842 // animation_floor_time_ is the earliest time that we should animate when
843 // using the dead reckoning software scheduler. If we're using swapbuffers
844 // complete callbacks to rate limit, we can ignore this floor.
845 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30846 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33847 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18848 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59849 // running animation callbacks so that if a callback requests another
850 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38851 animation_timer_.Stop();
852 animation_timer_.Start(FROM_HERE, animationInterval, this,
853 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59854 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30855 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59856 return;
[email protected]5f8b1022011-01-21 23:34:50857 }
[email protected]bd37ae252011-06-03 01:28:18858 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38859 if (!animation_timer_.IsRunning()) {
860 // This code uses base::Time::Now() to calculate the floor and next fire
861 // time because javascript's Date object uses base::Time::Now(). The
862 // message loop uses base::TimeTicks, which on windows can have a
863 // different granularity than base::Time.
864 // The upshot of all this is that this function might be called before
865 // base::Time::Now() has advanced past the animation_floor_time_. To
866 // avoid exposing this delay to javascript, we keep posting delayed
867 // tasks until base::Time::Now() has advanced far enough.
868 base::TimeDelta delay = animation_floor_time_ - now;
869 animation_timer_.Start(FROM_HERE, delay, this,
870 &RenderWidget::AnimationCallback);
871 }
[email protected]5f8b1022011-01-21 23:34:50872}
873
[email protected]bd37ae252011-06-03 01:28:18874bool RenderWidget::IsRenderingVSynced() {
875 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
876 // not caught by this check. This will lead to artificially low frame rates
877 // for people who force vsync off at a driver level and expect Chrome to speed
878 // up.
879 return !has_disable_gpu_vsync_switch_;
880}
881
[email protected]65225772011-05-12 21:10:24882void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06883 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24884 invalidation_task_posted_ = false;
885 DoDeferredUpdateAndSendInputAck();
886}
887
888void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05889 DoDeferredUpdate();
890
891 if (pending_input_event_ack_.get())
892 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21893}
894
[email protected]552e6002009-11-19 05:24:57895void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58896 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08897
[email protected]65225772011-05-12 21:10:24898 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29899 return;
[email protected]05a980d7a2012-02-07 22:16:42900
[email protected]fc4404d2012-11-07 19:53:30901 if (!init_complete_) {
902 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:42903 return;
904 }
[email protected]aa4117f2011-12-09 22:19:21905 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24906 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
907 return;
908 }
[email protected]9ca84622011-06-02 23:46:39909 if (is_accelerated_compositing_active_ &&
910 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24911 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
912 return;
913 }
initial.commit09911bf2008-07-26 23:55:29914
[email protected]552e6002009-11-19 05:24:57915 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29916 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57917 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29918 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24919 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29920 return;
921 }
922
[email protected]05a980d7a2012-02-07 22:16:42923 if (is_accelerated_compositing_active_)
924 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
925
[email protected]0fb93f52011-05-18 23:13:56926 // Tracking of frame rate jitter
927 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51928 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05929 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50930
[email protected]f98d7e3c2010-09-13 22:30:46931 // Layout may generate more invalidation. It may also enable the
932 // GPU acceleration, so make sure to run layout before we send the
933 // GpuRenderingActivated message.
934 webwidget_->layout();
935
[email protected]dcca3aa92012-02-17 23:03:37936 // The following two can result in further layout and possibly
937 // enable GPU acceleration so they need to be called before any painting
938 // is done.
[email protected]3306f262012-09-21 19:20:42939 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:37940 UpdateSelectionBounds();
941
[email protected]5f8b1022011-01-21 23:34:50942 // Suppress painting if nothing is dirty. This has to be done after updating
943 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24944 if (!paint_aggregator_.HasPendingUpdate()) {
945 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51946 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50947 return;
[email protected]65225772011-05-12 21:10:24948 }
[email protected]5f8b1022011-01-21 23:34:50949
[email protected]479b0172012-10-29 19:27:09950 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:36951 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:09952 ForceCompositingModeEnabled()) {
953 webwidget_->enterForceCompositingMode(true);
954 }
955
[email protected]872ae5b2011-05-26 20:20:50956 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56957 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04958 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56959 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
960 delay,
961 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:41962 base::TimeDelta::FromMilliseconds(120),
963 60);
[email protected]d0be63772011-12-20 23:18:04964 } else {
[email protected]0fb93f52011-05-18 23:13:56965 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
966 delay,
967 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:41968 base::TimeDelta::FromMilliseconds(120),
969 60);
[email protected]d0be63772011-12-20 23:18:04970 }
[email protected]872ae5b2011-05-26 20:20:50971
972 // Calculate filtered time per frame:
973 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
974 filtered_time_per_frame_ =
975 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56976 }
977 last_do_deferred_update_time_ = frame_begin_ticks;
978
[email protected]fef5e3972012-08-07 03:59:47979 if (!is_accelerated_compositing_active_) {
980 software_stats_.numAnimationFrames++;
981 software_stats_.numFramesSentToScreen++;
982 }
983
[email protected]552e6002009-11-19 05:24:57984 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29985 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30986 PaintAggregator::PendingUpdate update;
987 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29988
[email protected]53d3f302009-12-21 04:42:05989 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:18990 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:29991
[email protected]29ed96a2012-02-04 18:12:16992 // Notify derived classes that we're about to initiate a paint.
993 WillInitiatePaint();
994
[email protected]ca4847f2010-09-24 05:39:15995 // A plugin may be able to do an optimized paint. First check this, in which
996 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46997 // This optimization allows PPAPI plugins that declare themselves on top of
998 // the page (like a traditional windowed plugin) to be able to animate (think
999 // movie playing) without repeatedly re-painting the page underneath, or
1000 // copying the plugin backing store (since we can send the plugin's backing
1001 // store directly to the browser).
1002 //
1003 // This optimization only works when the entire invalid region is contained
1004 // within the plugin. There is a related optimization in PaintRect for the
1005 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151006 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151007 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201008 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211009 DCHECK(!pending_update_params_.get());
1010 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551011 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211012 pending_update_params_->scroll_rect = update.scroll_rect;
1013 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211014 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1015 pending_update_params_->flags = next_paint_flags_;
1016 pending_update_params_->scroll_offset = GetScrollOffset();
1017 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091018 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211019 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091020 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211021
[email protected]ca4847f2010-09-24 05:39:151022 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561023 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151024 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201025 &optimized_copy_rect,
1026 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271027 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471028 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211029 pending_update_params_->bitmap = dib->id();
1030 pending_update_params_->bitmap_rect = optimized_copy_location;
1031 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201032 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561033 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461034 // Compute a buffer for painting and cache it.
[email protected]ce112fe2012-10-29 22:52:181035 gfx::Rect pixel_bounds = gfx::ToFlooredRectDeprecated(
1036 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]ca4847f2010-09-24 05:39:151037 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351038 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591039 pixel_bounds));
[email protected]f98d7e3c2010-09-13 22:30:461040 if (!canvas.get()) {
1041 NOTREACHED();
1042 return;
1043 }
[email protected]cef3362f2009-12-21 17:48:451044
[email protected]f98d7e3c2010-09-13 22:30:461045 // We may get back a smaller canvas than we asked for.
1046 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591047 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1048 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1049 pixel_bounds.set_width(canvas->getDevice()->width());
1050 pixel_bounds.set_height(canvas->getDevice()->height());
1051 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1052 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051053
[email protected]f98d7e3c2010-09-13 22:30:461054 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1055
[email protected]aa4117f2011-12-09 22:19:211056 pending_update_params_->bitmap = current_paint_buf_->id();
1057 pending_update_params_->bitmap_rect = bounds;
1058
1059 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461060 // The scroll damage is just another rectangle to paint and copy.
1061 copy_rects.swap(update.paint_rects);
1062 if (!scroll_damage.IsEmpty())
1063 copy_rects.push_back(scroll_damage);
1064
1065 for (size_t i = 0; i < copy_rects.size(); ++i)
[email protected]f1cccb32012-06-06 18:29:591066 PaintRect(copy_rects[i], pixel_bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:351067
1068 // Software FPS tick for performance tests. The accelerated path traces the
1069 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1070 // NOTE: Tests may break if this event is renamed or moved.
1071 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:461072 } else { // Accelerated compositing path
1073 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211074 // If painting is done via the gpu process then we don't set any damage
1075 // rects to save the browser process from doing unecessary work.
1076 pending_update_params_->bitmap_rect = bounds;
1077 pending_update_params_->scroll_rect = gfx::Rect();
1078 // We don't need an ack, because we're not sharing a DIB with the browser.
1079 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1080 // with the browser for the GPU surface.
1081 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:421082 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:461083 }
1084
[email protected]936c6f52011-12-13 01:35:261085 // If we're holding a pending input event ACK, send the ACK before sending the
1086 // UpdateReply message so we can receive another input event before the
1087 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1088 // the UpdateRect IPC message handler.
1089 if (pending_input_event_ack_.get())
1090 Send(pending_input_event_ack_.release());
1091
[email protected]aa4117f2011-12-09 22:19:211092 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
1093 // OnSwapBuffersPosted), meaning a message has been added to the
1094 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1095 // the message now.
1096 if (pending_update_params_.get()) {
1097 // sending an ack to browser process that the paint is complete...
1098 update_reply_pending_ = pending_update_params_->needs_ack;
1099 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1100 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341101 }
[email protected]53d3f302009-12-21 04:42:051102
[email protected]29ed96a2012-02-04 18:12:161103 // If we're software rendering then we're done initiating the paint.
1104 if (!is_accelerated_compositing_active_)
1105 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291106}
1107
1108///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461109// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291110
[email protected]4873c7d2009-07-16 06:36:281111void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091112 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1113 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571114 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481115 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181116 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571117 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291118 return;
1119
[email protected]552e6002009-11-19 05:24:571120 paint_aggregator_.InvalidateRect(damaged_rect);
1121
1122 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241123 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571124 return;
1125 if (!paint_aggregator_.HasPendingUpdate())
1126 return;
[email protected]aa4117f2011-12-09 22:19:211127 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241128 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1129 return;
1130
1131 // When GPU rendering, combine pending animations and invalidations into
1132 // a single update.
[email protected]816edc62012-03-17 01:27:221133 if (is_accelerated_compositing_active_ &&
1134 animation_update_pending_ &&
1135 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571136 return;
1137
1138 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291139 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1140 // on the call stack.
1141 // 2) Allows us to collect more damage rects before painting to help coalesce
1142 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241143 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211144 MessageLoop::current()->PostTask(
1145 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291146}
1147
[email protected]990278ff2012-11-13 02:12:551148void RenderWidget::didScrollRect(int dx, int dy,
1149 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461150 // Drop scrolls on the floor when we are in compositing mode.
1151 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561152 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461153 return;
1154
[email protected]552e6002009-11-19 05:24:571155 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481156 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181157 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571158 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291159 return;
1160
[email protected]990278ff2012-11-13 02:12:551161 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571162
1163 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241164 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571165 return;
1166 if (!paint_aggregator_.HasPendingUpdate())
1167 return;
[email protected]aa4117f2011-12-09 22:19:211168 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241169 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1170 return;
1171
1172 // When GPU rendering, combine pending animations and invalidations into
1173 // a single update.
[email protected]816edc62012-03-17 01:27:221174 if (is_accelerated_compositing_active_ &&
1175 animation_update_pending_ &&
1176 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571177 return;
1178
1179 // Perform updating asynchronously. This serves two purposes:
1180 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1181 // on the call stack.
1182 // 2) Allows us to collect more damage rects before painting to help coalesce
1183 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241184 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211185 MessageLoop::current()->PostTask(
1186 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291187}
1188
[email protected]244ac1892011-12-02 17:04:471189void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091190 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1191 size_ = new_size;
1192 need_update_rect_for_auto_resize_ = true;
[email protected]240b5c32012-11-09 19:17:181193 // If we don't clear PaintAggregator after changing autoResize state, then
1194 // we might end up in a situation where bitmap_rect is larger than the
1195 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1196 // with invalid damage rects.
1197 paint_aggregator_.ClearPendingUpdate();
[email protected]ea3ee0a2012-05-15 03:43:091198 }
[email protected]244ac1892011-12-02 17:04:471199}
1200
[email protected]91acd1c2012-03-14 08:32:391201void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221202 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1203
[email protected]c63b4d42012-04-26 01:01:071204#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211205 if (!is_accelerated_compositing_active_) {
1206 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1207 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1208 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1209 // going to switch to accelerated compositing, the GPU process may need
1210 // round-trips to the browser's UI thread before finishing the frame,
1211 // causing deadlocks if we delay the UpdateRect until we receive the
1212 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071213 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1214 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211215 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1216 }
[email protected]c63b4d42012-04-26 01:01:071217#endif
[email protected]aa4117f2011-12-09 22:19:211218
[email protected]ea162f92011-10-04 23:08:221219 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421220 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241221 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221222}
1223
1224void RenderWidget::didDeactivateCompositor() {
1225 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1226
1227 is_accelerated_compositing_active_ = false;
1228 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1229 routing_id_, is_accelerated_compositing_active_));
1230
[email protected]ea162f92011-10-04 23:08:221231 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241232 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091233
1234 // In single-threaded mode, we exit force compositing mode and re-enter in
1235 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1236 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1237 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361238 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091239 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561240}
1241
[email protected]9cd43a62012-03-26 08:03:561242void RenderWidget::willBeginCompositorFrame() {
1243 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371244
1245 DCHECK(RenderThreadImpl::current()->compositor_thread());
1246
1247 // The following two can result in further layout and possibly
1248 // enable GPU acceleration so they need to be called before any painting
1249 // is done.
[email protected]3306f262012-09-21 19:20:421250 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371251 UpdateSelectionBounds();
1252
[email protected]9cd43a62012-03-26 08:03:561253 WillInitiatePaint();
1254}
1255
[email protected]3391a0772012-03-28 00:32:071256void RenderWidget::didBecomeReadyForAdditionalInput() {
1257 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1258 if (pending_input_event_ack_.get())
1259 Send(pending_input_event_ack_.release());
1260}
1261
[email protected]58264a32011-11-17 23:36:151262void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501263 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351264 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1265 // NOTE: Tests may break if this event is renamed or moved.
1266 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161267 // Notify subclasses that we initiated the paint operation.
1268 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151269}
1270
1271void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181272 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1273
1274 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561275 DidFlushPaint();
1276
[email protected]aa4117f2011-12-09 22:19:211277 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151278 return;
1279
[email protected]ea3ee0a2012-05-15 03:43:091280 if (!next_paint_flags_ &&
1281 !need_update_rect_for_auto_resize_ &&
1282 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151283 return;
[email protected]ea3ee0a2012-05-15 03:43:091284 }
[email protected]58264a32011-11-17 23:36:151285
1286 ViewHostMsg_UpdateRect_Params params;
1287 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151288 params.plugin_window_moves.swap(plugin_window_moves_);
1289 params.flags = next_paint_flags_;
1290 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121291 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091292 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151293
1294 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1295 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091296 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151297}
1298
[email protected]f98d7e3c2010-09-13 22:30:461299void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091300 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]d0be63772011-12-20 23:18:041301 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401302 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041303 } else {
[email protected]c3d45532011-10-07 19:20:401304 // TODO(nduca): replace with something a little less hacky. The reason this
1305 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1306 // contains a lot of host-renderer synchronization logic that is still
1307 // important for the accelerated compositing case. The option of simply
1308 // duplicating all that code is less desirable than "faking out" the
1309 // invalidation path using a magical damage rect.
1310 didInvalidateRect(WebRect(0, 0, 1, 1));
1311 }
[email protected]f98d7e3c2010-09-13 22:30:461312}
1313
[email protected]5f8b1022011-01-21 23:34:501314void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201315 if (animation_update_pending_)
1316 return;
1317
[email protected]921244e42011-07-20 16:36:301318 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201319 animation_update_pending_ = true;
1320 if (!animation_timer_.IsRunning()) {
1321 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1322 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211323 }
[email protected]5f8b1022011-01-21 23:34:501324}
1325
[email protected]4873c7d2009-07-16 06:36:281326void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301327 // TODO(darin): Eliminate this temporary.
1328 WebCursor cursor(cursor_info);
1329
initial.commit09911bf2008-07-26 23:55:291330 // Only send a SetCursor message if we need to make a change.
1331 if (!current_cursor_.IsEqual(cursor)) {
1332 current_cursor_ = cursor;
1333 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1334 }
1335}
1336
1337// We are supposed to get a single call to Show for a newly created RenderWidget
1338// that was created via RenderWidget::CreateWebView. So, we wait until this
1339// point to dispatch the ShowWidget message.
1340//
1341// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281342// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291343//
[email protected]4873c7d2009-07-16 06:36:281344void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291345 DCHECK(!did_show_) << "received extraneous Show call";
1346 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1347 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1348
[email protected]8de12d942010-11-17 20:42:441349 if (did_show_)
1350 return;
1351
1352 did_show_ = true;
1353 // NOTE: initial_pos_ may still have its default values at this point, but
1354 // that's okay. It'll be ignored if as_popup is false, or the browser
1355 // process will impose a default position otherwise.
1356 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1357 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291358}
1359
[email protected]4873c7d2009-07-16 06:36:281360void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291361}
1362
[email protected]4873c7d2009-07-16 06:36:281363void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291364}
1365
[email protected]2533ce12009-05-09 00:02:241366void RenderWidget::DoDeferredClose() {
1367 Send(new ViewHostMsg_Close(routing_id_));
1368}
1369
[email protected]4873c7d2009-07-16 06:36:281370void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321371 if (is_swapped_out_) {
1372 // This widget is currently swapped out, and the active widget is in a
1373 // different process. Have the browser route the close request to the
1374 // active widget instead, so that the correct unload handlers are run.
1375 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1376 return;
1377 }
1378
initial.commit09911bf2008-07-26 23:55:291379 // If a page calls window.close() twice, we'll end up here twice, but that's
1380 // OK. It is safe to send multiple Close messages.
1381
[email protected]2533ce12009-05-09 00:02:241382 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1383 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1384 // could be closed before the JS finishes executing. So instead, post a
1385 // message back to the message loop, which won't run until the JS is
1386 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211387 MessageLoop::current()->PostTask(
1388 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291389}
1390
1391void RenderWidget::Close() {
1392 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281393 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291394 webwidget_ = NULL;
1395 }
1396}
1397
[email protected]4873c7d2009-07-16 06:36:281398WebRect RenderWidget::windowRect() {
1399 if (pending_window_rect_count_)
1400 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241401
[email protected]80ad8622012-11-07 16:33:031402 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291403}
1404
[email protected]8a9d6ca32011-06-06 20:11:301405void RenderWidget::setToolTipText(const WebKit::WebString& text,
1406 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541407 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301408}
1409
[email protected]4873c7d2009-07-16 06:36:281410void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291411 if (did_show_) {
1412 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241413 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291414 } else {
1415 initial_pos_ = pos;
1416 }
1417}
1418
[email protected]2533ce12009-05-09 00:02:241419void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1420 pending_window_rect_ = rect;
1421 pending_window_rect_count_++;
1422}
1423
[email protected]4873c7d2009-07-16 06:36:281424WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241425 if (pending_window_rect_count_) {
1426 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1427 // the RootWindowRect is probably going to return wrong results since the
1428 // browser may not have processed the Move yet. There isn't really anything
1429 // good to do in this case, and it shouldn't happen - since this size is
1430 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281431 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241432 }
1433
[email protected]80ad8622012-11-07 16:33:031434 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371435}
1436
[email protected]4873c7d2009-07-16 06:36:281437WebRect RenderWidget::windowResizerRect() {
1438 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191439}
1440
[email protected]fa7b1dc2010-06-23 17:53:041441void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031442 // To prevent this renderer process from sending unnecessary IPC messages to
1443 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041444 // only during the input method attached to the browser process is active.
1445 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291446}
1447
[email protected]58b48a0d2012-06-13 07:01:351448void RenderWidget::UpdateCompositionInfo(
1449 const ui::Range& range,
1450 const std::vector<gfx::Rect>& character_bounds) {
1451 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1452 return;
1453 composition_character_bounds_ = character_bounds;
1454 composition_range_ = range;
1455 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1456 routing_id(), composition_range_, composition_character_bounds_));
1457}
1458
[email protected]fa7b1dc2010-06-23 17:53:041459void RenderWidget::OnImeSetComposition(
1460 const string16& text,
1461 const std::vector<WebCompositionUnderline>& underlines,
1462 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281463 if (!webwidget_)
1464 return;
[email protected]d4cff272011-05-02 15:46:011465 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041466 text, WebVector<WebCompositionUnderline>(underlines),
1467 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011468 // Setting the IME composition was successful. Send the new composition
1469 // range to the browser.
1470 ui::Range range(ui::Range::InvalidRange());
1471 size_t location, length;
1472 if (webwidget_->compositionRange(&location, &length)) {
1473 range.set_start(location);
1474 range.set_end(location + length);
1475 }
1476 // The IME was cancelled via the Esc key, so just send back the caret.
1477 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1478 range.set_start(location);
1479 range.set_end(location + length);
1480 }
[email protected]58b48a0d2012-06-13 07:01:351481 std::vector<gfx::Rect> character_bounds;
1482 GetCompositionCharacterBounds(&character_bounds);
1483 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011484 } else {
[email protected]fa7b1dc2010-06-23 17:53:041485 // If we failed to set the composition text, then we need to let the browser
1486 // process to cancel the input method's ongoing composition session, to make
1487 // sure we are in a consistent state.
1488 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011489
1490 // Send an updated IME range with just the caret range.
1491 ui::Range range(ui::Range::InvalidRange());
1492 size_t location, length;
1493 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1494 range.set_start(location);
1495 range.set_end(location + length);
1496 }
[email protected]58b48a0d2012-06-13 07:01:351497 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261498 }
[email protected]fa7b1dc2010-06-23 17:53:041499}
1500
[email protected]4de6d1692011-10-12 08:45:441501void RenderWidget::OnImeConfirmComposition(
1502 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041503 if (!webwidget_)
1504 return;
1505
1506 handling_input_event_ = true;
1507 webwidget_->confirmComposition(text);
1508 handling_input_event_ = false;
1509
[email protected]d4cff272011-05-02 15:46:011510 // Send an updated IME range with just the caret range.
1511 ui::Range range(ui::Range::InvalidRange());
1512 size_t location, length;
1513 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1514 range.set_start(location);
1515 range.set_end(location + length);
1516 }
[email protected]58b48a0d2012-06-13 07:01:351517 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291518}
1519
[email protected]948f7ab72010-05-28 23:48:081520// This message causes the renderer to render an image of the
1521// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491522void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091523 int tag,
[email protected]948f7ab72010-05-28 23:48:081524 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491525 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001526 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1527 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251528 // Close our unused handle.
1529#if defined(OS_WIN)
1530 ::CloseHandle(dib_handle);
1531#elif defined(OS_MACOSX)
1532 base::SharedMemory::CloseHandle(dib_handle);
1533#endif
1534 }
[email protected]d65adb12010-04-28 17:26:491535 return;
[email protected]45c6aad32010-11-11 04:46:251536 }
[email protected]d65adb12010-04-28 17:26:491537
[email protected]948f7ab72010-05-28 23:48:081538 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491539 // If one of these is empty, then we just return the dib we were
1540 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091541 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491542 return;
1543 }
1544
1545 // Map the given DIB ID into this process, and unmap it at the end
1546 // of this function.
[email protected]45c6aad32010-11-11 04:46:251547 scoped_ptr<TransportDIB> paint_at_size_buffer(
1548 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301549
[email protected]4b01b962012-10-09 23:17:351550 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281551 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351552 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281553 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511554 gfx::Size canvas_size = page_size_in_pixel;
1555 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491556 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511557 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491558 static_cast<float>(canvas_size.height());
1559
[email protected]ee8d6fd2010-05-26 17:05:481560 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491561 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1562 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481563 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491564
[email protected]36808ad2010-10-20 19:18:301565 scoped_ptr<skia::PlatformCanvas> canvas(
1566 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1567 canvas_size.height()));
1568 if (!canvas.get()) {
1569 NOTREACHED();
1570 return;
1571 }
1572
[email protected]d65adb12010-04-28 17:26:491573 // Reset bounds to what we actually received, but they should be the
1574 // same.
1575 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1576 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1577 bounds.set_width(canvas->getDevice()->width());
1578 bounds.set_height(canvas->getDevice()->height());
1579
1580 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081581 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491582 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1583
[email protected]948f7ab72010-05-28 23:48:081584 // Have to make sure we're laid out at the right size before
1585 // rendering.
1586 gfx::Size old_size = webwidget_->size();
1587 webwidget_->resize(page_size);
1588 webwidget_->layout();
1589
[email protected]d65adb12010-04-28 17:26:491590 // Paint the entire thing (using original bounds, not scaled bounds).
1591 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1592 canvas->restore();
1593
[email protected]948f7ab72010-05-28 23:48:081594 // Return the widget to its previous size.
1595 webwidget_->resize(old_size);
1596
[email protected]c88c9442010-07-19 18:55:091597 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491598}
1599
[email protected]ec7dc112008-08-06 05:30:121600void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1601 // During shutdown we can just ignore this message.
1602 if (!webwidget_)
1603 return;
1604
1605 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561606 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041607 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461608 scheduleComposite();
1609 } else {
1610 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1611 didInvalidateRect(repaint_rect);
1612 }
[email protected]ec7dc112008-08-06 05:30:121613}
1614
[email protected]0e241b4b2012-08-18 09:06:271615void RenderWidget::OnMsgSmoothScrollCompleted(int gesture_id) {
1616 PendingSmoothScrollGestureMap::iterator it =
1617 pending_smooth_scroll_gestures_.find(gesture_id);
1618 DCHECK(it != pending_smooth_scroll_gestures_.end());
1619 it->second.Run();
1620 pending_smooth_scroll_gestures_.erase(it);
1621}
1622
[email protected]4873c7d2009-07-16 06:36:281623void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111624 if (!webwidget_)
1625 return;
[email protected]4873c7d2009-07-16 06:36:281626 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111627}
1628
[email protected]6131a642012-06-15 23:26:531629void RenderWidget::OnScreenInfoChanged(
1630 const WebKit::WebScreenInfo& screen_info) {
1631 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191632 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531633}
1634
[email protected]80ad8622012-11-07 16:33:031635void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1636 const gfx::Rect& window_screen_rect) {
1637 view_screen_rect_ = view_screen_rect;
1638 window_screen_rect_ = window_screen_rect;
1639 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1640}
1641
[email protected]468ac582012-11-20 00:53:191642void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1643 if (device_scale_factor_ == device_scale_factor)
1644 return;
1645
1646 device_scale_factor_ = device_scale_factor;
1647
1648 if (!is_accelerated_compositing_active_) {
1649 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1650 } else {
1651 scheduleComposite();
1652 }
1653}
1654
[email protected]719b36f2010-12-22 20:36:461655webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151656 const gfx::Rect& paint_bounds,
1657 TransportDIB** dib,
1658 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201659 gfx::Rect* clip,
1660 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461661 // Bare RenderWidgets don't support optimized plugin painting.
1662 return NULL;
[email protected]ca4847f2010-09-24 05:39:151663}
1664
[email protected]ceb36f7d2012-10-31 18:33:241665gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521666 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241667 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521668}
1669
[email protected]bee16aab2009-08-26 15:55:031670void RenderWidget::SetHidden(bool hidden) {
1671 if (is_hidden_ == hidden)
1672 return;
1673
1674 // The status has changed. Tell the RenderThread about it.
1675 is_hidden_ = hidden;
1676 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271677 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031678 else
[email protected]380244092011-10-07 17:26:271679 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031680}
1681
[email protected]2b624c562011-10-27 22:58:261682void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261683 if (!webwidget_)
1684 return;
1685
1686 if (is_fullscreen_) {
1687 webwidget_->willExitFullScreen();
1688 } else {
1689 webwidget_->willEnterFullScreen();
1690 }
[email protected]2b624c562011-10-27 22:58:261691}
1692
1693void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261694 if (!webwidget_)
1695 return;
1696
1697 if (is_fullscreen_) {
1698 webwidget_->didEnterFullScreen();
1699 } else {
1700 webwidget_->didExitFullScreen();
1701 }
[email protected]2b624c562011-10-27 22:58:261702}
1703
[email protected]699ab0d2009-04-23 23:19:141704void RenderWidget::SetBackground(const SkBitmap& background) {
1705 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461706
[email protected]699ab0d2009-04-23 23:19:141707 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281708 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141709}
1710
[email protected]674741932009-02-04 23:44:461711bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051712 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461713}
1714
1715bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051716 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461717}
1718
1719void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051720 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461721}
1722
1723void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051724 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461725}
1726
1727void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051728 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461729}
1730
[email protected]3306f262012-09-21 19:20:421731void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
1732 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1733 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291734 return;
[email protected]ad26ef42011-06-17 07:59:451735 ui::TextInputType new_type = GetTextInputType();
[email protected]5b739cb2012-08-21 20:35:211736 WebKit::WebTextInputInfo new_info;
1737 if (webwidget_)
1738 new_info = webwidget_->textInputInfo();
1739
[email protected]ad26ef42011-06-17 07:59:451740 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211741
[email protected]3306f262012-09-21 19:20:421742 // Only sends text input params if they are changed or if the ime should be
1743 // shown.
1744 if (show_ime_if_needed || (text_input_type_ != new_type
1745 || text_input_info_ != new_info
1746 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:211747 ViewHostMsg_TextInputState_Params p;
1748 p.type = new_type;
1749 p.value = new_info.value.utf8();
1750 p.selection_start = new_info.selectionStart;
1751 p.selection_end = new_info.selectionEnd;
1752 p.composition_start = new_info.compositionStart;
1753 p.composition_end = new_info.compositionEnd;
1754 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:421755 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:211756 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1757
1758 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041759 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451760 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:291761 }
initial.commit09911bf2008-07-26 23:55:291762}
1763
[email protected]3f783362011-10-21 22:40:501764void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1765 WebRect start_webrect;
1766 WebRect end_webrect;
1767 webwidget_->selectionBounds(start_webrect, end_webrect);
1768 *start = start_webrect;
1769 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321770}
1771
[email protected]e99ef6f2011-10-16 01:13:001772void RenderWidget::UpdateSelectionBounds() {
1773 if (!webwidget_)
1774 return;
1775
[email protected]3f783362011-10-21 22:40:501776 gfx::Rect start_rect;
1777 gfx::Rect end_rect;
1778 GetSelectionBounds(&start_rect, &end_rect);
[email protected]58b48a0d2012-06-13 07:01:351779 if (selection_start_rect_ != start_rect || selection_end_rect_ != end_rect) {
1780 selection_start_rect_ = start_rect;
1781 selection_end_rect_ = end_rect;
[email protected]b556c2e2012-08-10 22:18:271782 WebTextDirection start_dir = WebKit::WebTextDirectionLeftToRight;
1783 WebTextDirection end_dir = WebKit::WebTextDirectionLeftToRight;
1784 webwidget_->selectionTextDirection(start_dir, end_dir);
1785 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_,
1786 selection_start_rect_, start_dir, selection_end_rect_, end_dir));
[email protected]58b48a0d2012-06-13 07:01:351787 }
[email protected]e99ef6f2011-10-16 01:13:001788
[email protected]58b48a0d2012-06-13 07:01:351789 std::vector<gfx::Rect> character_bounds;
1790 GetCompositionCharacterBounds(&character_bounds);
1791 UpdateCompositionInfo(composition_range_, character_bounds);
1792}
1793
1794bool RenderWidget::ShouldUpdateCompositionInfo(
1795 const ui::Range& range,
1796 const std::vector<gfx::Rect>& bounds) {
1797 if (composition_range_ != range)
1798 return true;
1799 if (bounds.size() != composition_character_bounds_.size())
1800 return true;
1801 for (size_t i = 0; i < bounds.size(); ++i) {
1802 if (bounds[i] != composition_character_bounds_[i])
1803 return true;
1804 }
1805 return false;
[email protected]e99ef6f2011-10-16 01:13:001806}
1807
[email protected]73bf95812011-10-12 11:38:321808// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451809COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1810 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1811COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1812 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1813COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1814 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181815COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1816 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1817COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1818 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1819COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1820 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1821COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1822 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1823COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1824 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:001825COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
1826 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
1827COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
1828 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
1829COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
1830 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
1831COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
1832 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
1833COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
1834 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
1835COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
1836 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:011837COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
1838 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
1839COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
1840 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451841
[email protected]5b739cb2012-08-21 20:35:211842ui::TextInputType RenderWidget::WebKitToUiTextInputType(
1843 WebKit::WebTextInputType type) {
1844 // Check the type is in the range representable by ui::TextInputType.
1845 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
1846 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1847 return static_cast<ui::TextInputType>(type);
1848}
1849
[email protected]ad26ef42011-06-17 07:59:451850ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:271851 if (webwidget_)
1852 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:451853 return ui::TEXT_INPUT_TYPE_NONE;
1854}
1855
[email protected]58b48a0d2012-06-13 07:01:351856void RenderWidget::GetCompositionCharacterBounds(
1857 std::vector<gfx::Rect>* bounds) {
1858 DCHECK(bounds);
1859 bounds->clear();
1860}
1861
[email protected]ad26ef42011-06-17 07:59:451862bool RenderWidget::CanComposeInline() {
1863 return true;
[email protected]56ea1a62011-05-30 07:05:571864}
1865
[email protected]4873c7d2009-07-16 06:36:281866WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041867 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281868}
1869
[email protected]f660d9c2012-06-06 18:31:211870float RenderWidget::deviceScaleFactor() {
1871 return device_scale_factor_;
1872}
1873
[email protected]fa7b1dc2010-06-23 17:53:041874void RenderWidget::resetInputMethod() {
1875 if (!input_method_is_active_)
1876 return;
1877
1878 // If the last text input type is not None, then we should finish any
1879 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451880 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041881 // If a composition text exists, then we need to let the browser process
1882 // to cancel the input method's ongoing composition session.
1883 if (webwidget_->confirmComposition())
1884 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1885 }
[email protected]d4cff272011-05-02 15:46:011886
1887 // Send an updated IME range with the current caret rect.
1888 ui::Range range(ui::Range::InvalidRange());
1889 size_t location, length;
1890 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1891 range.set_start(location);
1892 range.set_end(location + length);
1893 }
[email protected]58b48a0d2012-06-13 07:01:351894
1895 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:041896}
1897
[email protected]f103ab72009-09-02 17:10:591898void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501899 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291900 size_t i = 0;
1901 for (; i < plugin_window_moves_.size(); ++i) {
1902 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581903 if (move.rects_valid) {
1904 plugin_window_moves_[i] = move;
1905 } else {
1906 plugin_window_moves_[i].visible = move.visible;
1907 }
initial.commit09911bf2008-07-26 23:55:291908 break;
1909 }
1910 }
1911
1912 if (i == plugin_window_moves_.size())
1913 plugin_window_moves_.push_back(move);
1914}
[email protected]268654772009-08-06 23:02:041915
1916void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1917 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1918 i != plugin_window_moves_.end(); ++i) {
1919 if (i->window == window) {
1920 plugin_window_moves_.erase(i);
1921 break;
1922 }
1923 }
1924}
[email protected]67bfb83f2011-09-22 03:36:371925
[email protected]b63d58d2012-11-26 22:37:441926void RenderWidget::GetRenderingStats(
1927 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]fef5e3972012-08-07 03:59:471928 webwidget()->renderingStats(stats);
[email protected]b63d58d2012-11-26 22:37:441929
1930 stats.rendering_stats.numAnimationFrames +=
1931 software_stats_.numAnimationFrames;
1932 stats.rendering_stats.numFramesSentToScreen +=
1933 software_stats_.numFramesSentToScreen;
1934 stats.rendering_stats.totalPaintTimeInSeconds +=
1935 software_stats_.totalPaintTimeInSeconds;
1936 stats.rendering_stats.totalPixelsPainted +=
1937 software_stats_.totalPixelsPainted;
1938 stats.rendering_stats.totalRasterizeTimeInSeconds +=
[email protected]63ab54262012-11-09 15:58:451939 software_stats_.totalRasterizeTimeInSeconds;
[email protected]b63d58d2012-11-26 22:37:441940 stats.rendering_stats.totalPixelsRasterized +=
1941 software_stats_.totalPixelsRasterized;
[email protected]fef5e3972012-08-07 03:59:471942}
1943
[email protected]e9ff79c2012-10-19 21:31:261944bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:521945 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
1946 if (!gpu_channel)
1947 return false;
1948
1949 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
1950}
1951
[email protected]0e241b4b2012-08-18 09:06:271952void RenderWidget::BeginSmoothScroll(
1953 bool down,
[email protected]ebd8b562012-10-09 14:44:291954 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:191955 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:291956 int mouse_event_x,
1957 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:271958 DCHECK(!callback.is_null());
1959 int id = next_smooth_scroll_gesture_id_++;
[email protected]267909d2012-10-20 04:36:191960
1961 ViewHostMsg_BeginSmoothScroll_Params params;
1962 params.scroll_down = down;
1963 params.pixels_to_scroll = pixels_to_scroll;
1964 params.mouse_event_x = mouse_event_x;
1965 params.mouse_event_y = mouse_event_y;
1966
1967 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, params));
[email protected]0e241b4b2012-08-18 09:06:271968 pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback));
[email protected]a39ca1652012-07-13 21:30:581969}
1970
[email protected]67bfb83f2011-09-22 03:36:371971bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1972 return false;
1973}
[email protected]c3d45532011-10-07 19:20:401974
[email protected]41d86852012-11-07 12:23:241975bool RenderWidget::WillHandleGestureEvent(
1976 const WebKit::WebGestureEvent& event) {
1977 return false;
1978}
1979
[email protected]c3d45532011-10-07 19:20:401980bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1981 return false;
1982}
[email protected]e9ff79c2012-10-19 21:31:261983
[email protected]3d5c243b2012-11-30 00:26:011984bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
1985 return true;
1986}
1987
[email protected]e9ff79c2012-10-19 21:31:261988} // namespace content