blob: 6e38df8a0b6014a1ff1af08e59e25169cdc0b91d [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]b89c90762013-01-06 20:29:30204 if (webwidget_) {
205 webwidget_->setCompositorSurfaceReady();
206 if (is_threaded_compositing_enabled_)
207 webwidget_->enterForceCompositingMode(true);
[email protected]479b0172012-10-29 19:27:09208 }
[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)
[email protected]3d9ec5052013-01-02 22:05:25246 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
247 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
248 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28249 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
250 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53251 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03252 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]a95986a82010-12-24 06:19:28253 IPC_MESSAGE_UNHANDLED(handled = false)
254 IPC_END_MESSAGE_MAP()
255 return handled;
256}
initial.commit09911bf2008-07-26 23:55:29257
258bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15259 // Don't send any messages after the browser has told us to close, and filter
260 // most outgoing messages while swapped out.
261 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26262 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11263 closing_) {
initial.commit09911bf2008-07-26 23:55:29264 delete message;
265 return false;
266 }
267
268 // If given a messsage without a routing ID, then assign our routing ID.
269 if (message->routing_id() == MSG_ROUTING_NONE)
270 message->set_routing_id(routing_id_);
271
[email protected]380244092011-10-07 17:26:27272 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44273}
274
[email protected]61e2b3cc2012-03-02 16:13:34275void RenderWidget::Resize(const gfx::Size& new_size,
276 const gfx::Rect& resizer_rect,
277 bool is_fullscreen,
278 ResizeAck resize_ack) {
279 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
280 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
281 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29282
[email protected]61e2b3cc2012-03-02 16:13:34283 // Ignore this during shutdown.
284 if (!webwidget_)
285 return;
286
287 // Remember the rect where the resize corner will be drawn.
288 resizer_rect_ = resizer_rect;
289
290 // NOTE: We may have entered fullscreen mode without changing our size.
291 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
292 if (fullscreen_change)
293 WillToggleFullscreen();
294 is_fullscreen_ = is_fullscreen;
295
296 if (size_ != new_size) {
297 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34298 needs_repainting_on_restore_ = false;
299
300 size_ = new_size;
301
302 paint_aggregator_.ClearPendingUpdate();
303
304 // When resizing, we want to wait to paint before ACK'ing the resize. This
305 // ensures that we only resize as fast as we can paint. We only need to
306 // send an ACK if we are resized to a non-empty rect.
307 webwidget_->resize(new_size);
308 if (!new_size.IsEmpty()) {
309 if (!is_accelerated_compositing_active_) {
310 // Resize should have caused an invalidation of the entire view.
311 DCHECK(paint_aggregator_.HasPendingUpdate());
312 }
313
314 // Send the Resize_ACK flag once we paint again if requested.
315 if (resize_ack == SEND_RESIZE_ACK)
316 set_next_paint_is_resize_ack();
317 }
[email protected]ff475a322012-03-14 00:05:35318 } else {
319 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34320 }
321
322 if (fullscreen_change)
323 DidToggleFullscreen();
324
325 // If a resize ack is requested and it isn't set-up, then no more resizes will
326 // come in and in general things will go wrong.
327 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
328 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29329}
330
331void RenderWidget::OnClose() {
332 if (closing_)
333 return;
334 closing_ = true;
335
336 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03337 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27338 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03339 SetHidden(false);
340 }
initial.commit09911bf2008-07-26 23:55:29341
initial.commit09911bf2008-07-26 23:55:29342 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25343 // now. Post a task that only gets invoked when there are no nested message
344 // loops.
[email protected]32876ae2011-11-15 22:25:21345 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29346 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25347
348 // Balances the AddRef taken when we called AddRoute.
349 Release();
initial.commit09911bf2008-07-26 23:55:29350}
351
[email protected]61e2b3cc2012-03-02 16:13:34352// Got a response from the browser after the renderer decided to create a new
353// view.
[email protected]fc4404d2012-11-07 19:53:30354void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34355 DCHECK(routing_id_ != MSG_ROUTING_NONE);
356
[email protected]fc4404d2012-11-07 19:53:30357 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34358}
359
[email protected]f21c613a2009-02-12 14:46:17360void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09361 const gfx::Rect& resizer_rect,
362 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34363 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29364}
365
[email protected]b5913d72012-02-07 22:26:54366void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
367 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59368 gfx::Rect view_rect(size_);
369
[email protected]ce112fe2012-10-29 22:52:18370 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59371 if (!old_damage_rect.IsEmpty())
372 paint_aggregator_.InvalidateRect(old_damage_rect);
373
[email protected]ce112fe2012-10-29 22:52:18374 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59375 if (!new_damage_rect.IsEmpty())
376 paint_aggregator_.InvalidateRect(new_damage_rect);
377
[email protected]b5913d72012-02-07 22:26:54378 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59379
[email protected]b5913d72012-02-07 22:26:54380 if (webwidget_)
381 webwidget_->didChangeWindowResizerRect();
382 }
383}
384
initial.commit09911bf2008-07-26 23:55:29385void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31386 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29387 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03388 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29389}
390
[email protected]9e2e4632012-07-27 16:38:41391void RenderWidget::OnWasShown(bool needs_repainting) {
392 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29393 // During shutdown we can just ignore this message.
394 if (!webwidget_)
395 return;
396
397 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03398 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29399
400 if (!needs_repainting && !needs_repainting_on_restore_)
401 return;
402 needs_repainting_on_restore_ = false;
403
[email protected]d65adb12010-04-28 17:26:49404 // Tag the next paint as a restore ack, which is picked up by
405 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29406 set_next_paint_is_restore_ack();
407
408 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56409 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46410 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
411 } else {
412 scheduleComposite();
413 }
initial.commit09911bf2008-07-26 23:55:29414}
415
[email protected]992db4c2011-05-12 15:37:15416void RenderWidget::OnWasSwappedOut() {
417 // If we have been swapped out and no one else is using this process,
418 // it's safe to exit now. If we get swapped back in, we will call
419 // AddRefProcess in SetSwappedOut.
420 if (is_swapped_out_)
421 RenderProcess::current()->ReleaseProcess();
422}
423
[email protected]53d3f302009-12-21 04:42:05424void RenderWidget::OnRequestMoveAck() {
425 DCHECK(pending_window_rect_count_);
426 pending_window_rect_count_--;
427}
428
429void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58430 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21431 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05432 update_reply_pending_ = false;
433
[email protected]b4d08452010-10-05 17:34:35434 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
435 // have no current paint buffer.
436 if (current_paint_buf_) {
437 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
438 current_paint_buf_ = NULL;
439 }
440
[email protected]65225772011-05-12 21:10:24441 // If swapbuffers is still pending, then defer the update until the
442 // swapbuffers occurs.
443 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
444 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
445 return;
446 }
447
[email protected]29ed96a2012-02-04 18:12:16448 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18449 if (!is_accelerated_compositing_active_) {
450 DidFlushPaint();
451 }
[email protected]a2f6bc112009-06-27 16:27:25452
initial.commit09911bf2008-07-26 23:55:29453 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24454 DoDeferredUpdateAndSendInputAck();
455}
456
[email protected]d0be63772011-12-20 23:18:04457bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24458 return false;
459}
460
[email protected]479b0172012-10-29 19:27:09461bool RenderWidget::ForceCompositingModeEnabled() {
462 return false;
463}
464
[email protected]d0be63772011-12-20 23:18:04465void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24466 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21467 while (!updates_pending_swap_.empty()) {
468 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
469 updates_pending_swap_.pop_front();
470 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
471 // compositing pass, hence doesn't require an UpdateRect message.
472 if (msg)
473 Send(msg);
474 }
[email protected]65225772011-05-12 21:10:24475 num_swapbuffers_complete_pending_ = 0;
476 using_asynchronous_swapbuffers_ = false;
477 // Schedule another frame so the compositor learns about it.
478 scheduleComposite();
479}
480
[email protected]37a6f302011-07-11 23:43:08481void RenderWidget::OnSwapBuffersPosted() {
482 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21483
484 if (using_asynchronous_swapbuffers_) {
485 ViewHostMsg_UpdateRect* msg = NULL;
486 // pending_update_params_ can be NULL if the swap doesn't correspond to an
487 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
488 // message.
489 if (pending_update_params_.get()) {
490 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
491 pending_update_params_.reset();
492 }
493 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08494 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21495 }
[email protected]37a6f302011-07-11 23:43:08496}
497
498void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24499 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16500
[email protected]404939f2012-06-01 04:06:18501 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16502 DidFlushPaint();
503
[email protected]65225772011-05-12 21:10:24504 // When compositing deactivates, we reset the swapbuffers pending count. The
505 // swapbuffers acks may still arrive, however.
506 if (num_swapbuffers_complete_pending_ == 0) {
507 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
508 return;
509 }
[email protected]aa4117f2011-12-09 22:19:21510 DCHECK(!updates_pending_swap_.empty());
511 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
512 updates_pending_swap_.pop_front();
513 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
514 // compositing pass, hence doesn't require an UpdateRect message.
515 if (msg)
516 Send(msg);
[email protected]65225772011-05-12 21:10:24517 num_swapbuffers_complete_pending_--;
518
519 // If update reply is still pending, then defer the update until that reply
520 // occurs.
[email protected]d0be63772011-12-20 23:18:04521 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24522 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
523 return;
524 }
525
526 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06527 // when we were previously rendering. However, if an invalidation task is not
528 // posted, there may be software rendering work pending. In that case, don't
529 // early out.
530 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24531 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
532 return;
533 }
534
[email protected]cc66e682012-10-02 06:48:18535 // Do not call DoDeferredUpdate unless there's animation work to be done or
536 // a real invalidation. This prevents rendering in response to a swapbuffers
537 // callback coming back after we've navigated away from the page that
538 // generated it.
539 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
540 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
541 return;
542 }
543
[email protected]65225772011-05-12 21:10:24544 // Continue painting if necessary...
545 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29546}
547
[email protected]0dea1652012-12-14 00:09:09548void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
549 bool is_keyboard_shortcut) {
[email protected]65225772011-05-12 21:10:24550 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
initial.commit09911bf2008-07-26 23:55:29551
[email protected]5dd768212009-08-13 23:34:49552 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09553 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49554 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29555 return;
[email protected]5dd768212009-08-13 23:34:49556 }
initial.commit09911bf2008-07-26 23:55:29557
[email protected]67bfb83f2011-09-22 03:36:37558 bool prevent_default = false;
559 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26560 const WebMouseEvent& mouse_event =
561 *static_cast<const WebMouseEvent*>(input_event);
562 TRACE_EVENT2("renderer", "HandleMouseMove",
563 "x", mouse_event.x, "y", mouse_event.y);
564 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37565 }
566
[email protected]41d86852012-11-07 12:23:24567 if (WebInputEvent::isGestureEventType(input_event->type)) {
568 const WebGestureEvent& gesture_event =
569 *static_cast<const WebGestureEvent*>(input_event);
570 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
571 }
572
[email protected]67bfb83f2011-09-22 03:36:37573 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12574 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
575 suppress_next_char_events_ = false;
576 if (!processed && webwidget_)
577 processed = webwidget_->handleInputEvent(*input_event);
578 }
579
580 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
581 // it's not processed by webkit, then we need to suppress the upcoming Char
582 // events.
583 if (!processed && is_keyboard_shortcut)
584 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29585
[email protected]3d5c243b2012-11-30 00:26:01586 InputEventAckState ack_result = processed ?
587 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
588 if (!processed && input_event->type == WebInputEvent::TouchStart) {
589 const WebTouchEvent& touch_event =
590 *static_cast<const WebTouchEvent*>(input_event);
591 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
592 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
593 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
594 }
595
[email protected]a9fb30aa2011-10-06 06:58:46596 IPC::Message* response =
597 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
[email protected]3d5c243b2012-11-30 00:26:01598 ack_result);
[email protected]3391a0772012-03-28 00:32:07599 bool event_type_gets_rate_limited =
600 input_event->type == WebInputEvent::MouseMove ||
601 input_event->type == WebInputEvent::MouseWheel ||
602 WebInputEvent::isTouchEventType(input_event->type);
603 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57604 throttle_input_events_ &&
[email protected]b89c90762013-01-06 20:29:30605 ((webwidget_ ? webwidget_->isInputThrottled() : false) ||
606 paint_aggregator_.HasPendingUpdate());
[email protected]e2824412009-02-27 01:57:05607
[email protected]f8868d72012-04-27 19:13:03608 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24609 // We want to rate limit the input events in this case, so we'll wait for
610 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17611 if (pending_input_event_ack_.get()) {
612 // As two different kinds of events could cause us to postpone an ack
613 // we send it now, if we have one pending. The Browser should never
614 // send us the same kind of event we are delaying the ack for.
615 Send(pending_input_event_ack_.release());
616 }
[email protected]12fbad812009-09-01 18:21:24617 pending_input_event_ack_.reset(response);
618 } else {
619 Send(response);
620 }
621
[email protected]3306f262012-09-21 19:20:42622#if defined(OS_ANDROID)
623 // Allow the IME to be shown when the focus changes as a consequence
624 // of a processed touch end event.
625 if (input_event->type == WebInputEvent::TouchEnd && processed)
626 UpdateTextInputState(SHOW_IME_IF_NEEDED);
627#endif
628
[email protected]5dd768212009-08-13 23:34:49629 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48630
[email protected]67bfb83f2011-09-22 03:36:37631 if (!prevent_default) {
632 if (WebInputEvent::isKeyboardEventType(input_event->type))
633 DidHandleKeyEvent();
634 if (WebInputEvent::isMouseEventType(input_event->type))
635 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24636 if (WebInputEvent::isTouchEventType(input_event->type))
637 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37638 }
initial.commit09911bf2008-07-26 23:55:29639}
640
641void RenderWidget::OnMouseCaptureLost() {
642 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28643 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29644}
645
646void RenderWidget::OnSetFocus(bool enable) {
647 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33648 if (webwidget_)
649 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29650}
651
652void RenderWidget::ClearFocus() {
653 // We may have got the focus from the browser before this gets processed, in
654 // which case we do not want to unfocus ourself.
655 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28656 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29657}
658
[email protected]2d5d09d52009-06-15 14:29:21659void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00660 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21661 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06662 TRACE_EVENT2("renderer", "PaintRect",
663 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45664
665 const bool kEnableGpuBenchmarking =
666 CommandLine::ForCurrentProcess()->HasSwitch(
667 switches::kEnableGpuBenchmarking);
668 base::TimeTicks rasterize_begin_ticks;
669 if (kEnableGpuBenchmarking)
670 rasterize_begin_ticks = base::TimeTicks::HighResNow();
[email protected]4fb66842009-12-04 21:41:00671 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21672
673 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00674 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
675 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03676
[email protected]699ab0d2009-04-23 23:19:14677 // If there is a custom background, tile it.
678 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14679 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11680 skia::RefPtr<SkShader> shader = skia::AdoptRef(
681 SkShader::CreateBitmapShader(background_,
682 SkShader::kRepeat_TileMode,
683 SkShader::kRepeat_TileMode));
684 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20685
686 // Use kSrc_Mode to handle background_ transparency properly.
687 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
688
689 // Canvas could contain multiple update rects. Clip to given rect so that
690 // we don't accidentally clear other update rects.
691 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48692 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14693 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20694 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14695 }
696
[email protected]719b36f2010-12-22 20:36:46697 // First see if this rect is a plugin that can paint itself faster.
698 TransportDIB* optimized_dib = NULL;
699 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20700 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46701 webkit::ppapi::PluginInstance* optimized_instance =
702 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
703 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20704 &optimized_copy_rect,
705 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46706 if (optimized_instance) {
707 // This plugin can be optimize-painted and we can just ask it to paint
708 // itself. We don't actually need the TransportDIB in this case.
709 //
710 // This is an optimization for PPAPI plugins that know they're on top of
711 // the page content. If this rect is inside such a plugin, we can save some
712 // time and avoid re-rendering the page content which we know will be
713 // covered by the plugin later (this time can be significant, especially
714 // for a playing movie that is invalidating a lot).
715 //
716 // In the plugin movie case, hopefully the similar call to
717 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
718 // painting, because that avoids copying the plugin image to a different
719 // paint rect. Unfortunately, if anything on the page is animating other
720 // than the movie, it break this optimization since the union of the
721 // invalid regions will be larger than the plugin.
722 //
723 // This code optimizes that case, where we can still avoid painting in
724 // WebKit and filling the background (which can be slow) and just painting
725 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
726 // required.
[email protected]63ab54262012-11-09 15:58:45727 base::TimeTicks paint_begin_ticks;
728 if (kEnableGpuBenchmarking)
729 paint_begin_ticks = base::TimeTicks::HighResNow();
730
[email protected]df59dd42012-09-14 22:56:30731 SkAutoCanvasRestore auto_restore(canvas, true);
732 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46733 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27734 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21735 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45736 if (kEnableGpuBenchmarking) {
737 base::TimeDelta paint_time =
738 base::TimeTicks::HighResNow() - paint_begin_ticks;
739 if (!is_accelerated_compositing_active_)
740 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
741 }
[email protected]719b36f2010-12-22 20:36:46742 } else {
743 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45744 base::TimeTicks paint_begin_ticks;
745 if (kEnableGpuBenchmarking)
746 paint_begin_ticks = base::TimeTicks::HighResNow();
747
[email protected]719b36f2010-12-22 20:36:46748 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45749
750 if (kEnableGpuBenchmarking) {
751 base::TimeDelta paint_time =
752 base::TimeTicks::HighResNow() - paint_begin_ticks;
753 if (!is_accelerated_compositing_active_)
754 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
755 }
[email protected]719b36f2010-12-22 20:36:46756
757 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35758 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46759 }
initial.commit09911bf2008-07-26 23:55:29760
[email protected]4fb66842009-12-04 21:41:00761 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00762 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45763
764 if (kEnableGpuBenchmarking) {
765 base::TimeDelta rasterize_time =
766 base::TimeTicks::HighResNow() - rasterize_begin_ticks;
767 software_stats_.totalRasterizeTimeInSeconds += rasterize_time.InSecondsF();
768
769 int64 num_pixels_processed = rect.width() * rect.height();
770 software_stats_.totalPixelsPainted += num_pixels_processed;
771 software_stats_.totalPixelsRasterized += num_pixels_processed;
772 }
[email protected]4fb66842009-12-04 21:41:00773}
774
775void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
776 skia::PlatformCanvas* canvas) {
777 static bool kPaintBorder =
778 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
779 if (!kPaintBorder)
780 return;
781
[email protected]53d3f302009-12-21 04:42:05782 // Cycle through these colors to help distinguish new paint rects.
783 const SkColor colors[] = {
784 SkColorSetARGB(0x3F, 0xFF, 0, 0),
785 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
786 SkColorSetARGB(0x3F, 0, 0, 0xFF),
787 };
788 static int color_selector = 0;
789
[email protected]4fb66842009-12-04 21:41:00790 SkPaint paint;
791 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05792 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00793 paint.setStrokeWidth(1);
794
795 SkIRect irect;
796 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
797 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29798}
799
[email protected]52ccd0ea2011-02-16 01:09:05800void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30801 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30802 if (!animation_update_pending_) {
803 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59804 return;
[email protected]921244e42011-07-20 16:36:30805 }
[email protected]bd37ae252011-06-03 01:28:18806 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59807 // Record when we fired (according to base::Time::Now()) relative to when
808 // we posted the task to quantify how much the base::Time/base::TimeTicks
809 // skew is affecting animations.
810 base::TimeDelta animation_callback_delay = base::Time::Now() -
811 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
812 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
813 animation_callback_delay,
814 base::TimeDelta::FromMilliseconds(0),
815 base::TimeDelta::FromMilliseconds(30),
816 25);
817 }
[email protected]65225772011-05-12 21:10:24818 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24819}
820
[email protected]52ccd0ea2011-02-16 01:09:05821void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59822 if (!animation_update_pending_)
823 return;
[email protected]bd37ae252011-06-03 01:28:18824
825 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33826 base::TimeDelta animationInterval = IsRenderingVSynced() ?
827 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18828
[email protected]7c4329e2011-02-18 22:02:59829 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45830
831 // animation_floor_time_ is the earliest time that we should animate when
832 // using the dead reckoning software scheduler. If we're using swapbuffers
833 // complete callbacks to rate limit, we can ignore this floor.
834 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30835 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33836 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18837 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59838 // running animation callbacks so that if a callback requests another
839 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38840 animation_timer_.Stop();
841 animation_timer_.Start(FROM_HERE, animationInterval, this,
842 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59843 animation_update_pending_ = false;
[email protected]b89c90762013-01-06 20:29:30844 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59845 return;
[email protected]5f8b1022011-01-21 23:34:50846 }
[email protected]bd37ae252011-06-03 01:28:18847 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38848 if (!animation_timer_.IsRunning()) {
849 // This code uses base::Time::Now() to calculate the floor and next fire
850 // time because javascript's Date object uses base::Time::Now(). The
851 // message loop uses base::TimeTicks, which on windows can have a
852 // different granularity than base::Time.
853 // The upshot of all this is that this function might be called before
854 // base::Time::Now() has advanced past the animation_floor_time_. To
855 // avoid exposing this delay to javascript, we keep posting delayed
856 // tasks until base::Time::Now() has advanced far enough.
857 base::TimeDelta delay = animation_floor_time_ - now;
858 animation_timer_.Start(FROM_HERE, delay, this,
859 &RenderWidget::AnimationCallback);
860 }
[email protected]5f8b1022011-01-21 23:34:50861}
862
[email protected]bd37ae252011-06-03 01:28:18863bool RenderWidget::IsRenderingVSynced() {
864 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
865 // not caught by this check. This will lead to artificially low frame rates
866 // for people who force vsync off at a driver level and expect Chrome to speed
867 // up.
868 return !has_disable_gpu_vsync_switch_;
869}
870
[email protected]65225772011-05-12 21:10:24871void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06872 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24873 invalidation_task_posted_ = false;
874 DoDeferredUpdateAndSendInputAck();
875}
876
877void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05878 DoDeferredUpdate();
879
880 if (pending_input_event_ack_.get())
881 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21882}
883
[email protected]552e6002009-11-19 05:24:57884void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58885 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08886
[email protected]65225772011-05-12 21:10:24887 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29888 return;
[email protected]05a980d7a2012-02-07 22:16:42889
[email protected]fc4404d2012-11-07 19:53:30890 if (!init_complete_) {
891 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:42892 return;
893 }
[email protected]aa4117f2011-12-09 22:19:21894 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24895 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
896 return;
897 }
[email protected]9ca84622011-06-02 23:46:39898 if (is_accelerated_compositing_active_ &&
899 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24900 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
901 return;
902 }
initial.commit09911bf2008-07-26 23:55:29903
[email protected]552e6002009-11-19 05:24:57904 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29905 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57906 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29907 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24908 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29909 return;
910 }
911
[email protected]05a980d7a2012-02-07 22:16:42912 if (is_accelerated_compositing_active_)
913 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
914
[email protected]0fb93f52011-05-18 23:13:56915 // Tracking of frame rate jitter
916 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51917 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05918 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50919
[email protected]f98d7e3c2010-09-13 22:30:46920 // Layout may generate more invalidation. It may also enable the
921 // GPU acceleration, so make sure to run layout before we send the
922 // GpuRenderingActivated message.
923 webwidget_->layout();
924
[email protected]dcca3aa92012-02-17 23:03:37925 // The following two can result in further layout and possibly
926 // enable GPU acceleration so they need to be called before any painting
927 // is done.
[email protected]3306f262012-09-21 19:20:42928 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:37929 UpdateSelectionBounds();
930
[email protected]5f8b1022011-01-21 23:34:50931 // Suppress painting if nothing is dirty. This has to be done after updating
932 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24933 if (!paint_aggregator_.HasPendingUpdate()) {
934 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51935 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50936 return;
[email protected]65225772011-05-12 21:10:24937 }
[email protected]5f8b1022011-01-21 23:34:50938
[email protected]479b0172012-10-29 19:27:09939 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:36940 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:09941 ForceCompositingModeEnabled()) {
942 webwidget_->enterForceCompositingMode(true);
943 }
944
[email protected]872ae5b2011-05-26 20:20:50945 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56946 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04947 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56948 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
949 delay,
950 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:41951 base::TimeDelta::FromMilliseconds(120),
952 60);
[email protected]d0be63772011-12-20 23:18:04953 } else {
[email protected]0fb93f52011-05-18 23:13:56954 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
955 delay,
956 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:41957 base::TimeDelta::FromMilliseconds(120),
958 60);
[email protected]d0be63772011-12-20 23:18:04959 }
[email protected]872ae5b2011-05-26 20:20:50960
961 // Calculate filtered time per frame:
962 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
963 filtered_time_per_frame_ =
964 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56965 }
966 last_do_deferred_update_time_ = frame_begin_ticks;
967
[email protected]fef5e3972012-08-07 03:59:47968 if (!is_accelerated_compositing_active_) {
969 software_stats_.numAnimationFrames++;
970 software_stats_.numFramesSentToScreen++;
971 }
972
[email protected]552e6002009-11-19 05:24:57973 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29974 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30975 PaintAggregator::PendingUpdate update;
976 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29977
[email protected]53d3f302009-12-21 04:42:05978 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:18979 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:29980
[email protected]29ed96a2012-02-04 18:12:16981 // Notify derived classes that we're about to initiate a paint.
982 WillInitiatePaint();
983
[email protected]ca4847f2010-09-24 05:39:15984 // A plugin may be able to do an optimized paint. First check this, in which
985 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46986 // This optimization allows PPAPI plugins that declare themselves on top of
987 // the page (like a traditional windowed plugin) to be able to animate (think
988 // movie playing) without repeatedly re-painting the page underneath, or
989 // copying the plugin backing store (since we can send the plugin's backing
990 // store directly to the browser).
991 //
992 // This optimization only works when the entire invalid region is contained
993 // within the plugin. There is a related optimization in PaintRect for the
994 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15995 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15996 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20997 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:21998 DCHECK(!pending_update_params_.get());
999 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551000 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211001 pending_update_params_->scroll_rect = update.scroll_rect;
1002 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211003 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1004 pending_update_params_->flags = next_paint_flags_;
1005 pending_update_params_->scroll_offset = GetScrollOffset();
1006 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091007 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211008 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091009 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211010
[email protected]ca4847f2010-09-24 05:39:151011 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561012 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151013 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201014 &optimized_copy_rect,
1015 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271016 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471017 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211018 pending_update_params_->bitmap = dib->id();
1019 pending_update_params_->bitmap_rect = optimized_copy_location;
1020 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201021 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561022 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461023 // Compute a buffer for painting and cache it.
[email protected]ce112fe2012-10-29 22:52:181024 gfx::Rect pixel_bounds = gfx::ToFlooredRectDeprecated(
1025 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]ca4847f2010-09-24 05:39:151026 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351027 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591028 pixel_bounds));
[email protected]f98d7e3c2010-09-13 22:30:461029 if (!canvas.get()) {
1030 NOTREACHED();
1031 return;
1032 }
[email protected]cef3362f2009-12-21 17:48:451033
[email protected]f98d7e3c2010-09-13 22:30:461034 // We may get back a smaller canvas than we asked for.
1035 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591036 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1037 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1038 pixel_bounds.set_width(canvas->getDevice()->width());
1039 pixel_bounds.set_height(canvas->getDevice()->height());
1040 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1041 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051042
[email protected]f98d7e3c2010-09-13 22:30:461043 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1044
[email protected]aa4117f2011-12-09 22:19:211045 pending_update_params_->bitmap = current_paint_buf_->id();
1046 pending_update_params_->bitmap_rect = bounds;
1047
1048 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461049 // The scroll damage is just another rectangle to paint and copy.
1050 copy_rects.swap(update.paint_rects);
1051 if (!scroll_damage.IsEmpty())
1052 copy_rects.push_back(scroll_damage);
1053
1054 for (size_t i = 0; i < copy_rects.size(); ++i)
[email protected]f1cccb32012-06-06 18:29:591055 PaintRect(copy_rects[i], pixel_bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:351056
1057 // Software FPS tick for performance tests. The accelerated path traces the
1058 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1059 // NOTE: Tests may break if this event is renamed or moved.
1060 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:461061 } else { // Accelerated compositing path
1062 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211063 // If painting is done via the gpu process then we don't set any damage
1064 // rects to save the browser process from doing unecessary work.
1065 pending_update_params_->bitmap_rect = bounds;
1066 pending_update_params_->scroll_rect = gfx::Rect();
1067 // We don't need an ack, because we're not sharing a DIB with the browser.
1068 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1069 // with the browser for the GPU surface.
1070 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:421071 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:461072 }
1073
[email protected]936c6f52011-12-13 01:35:261074 // If we're holding a pending input event ACK, send the ACK before sending the
1075 // UpdateReply message so we can receive another input event before the
1076 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1077 // the UpdateRect IPC message handler.
1078 if (pending_input_event_ack_.get())
1079 Send(pending_input_event_ack_.release());
1080
[email protected]aa4117f2011-12-09 22:19:211081 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
1082 // OnSwapBuffersPosted), meaning a message has been added to the
1083 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1084 // the message now.
1085 if (pending_update_params_.get()) {
1086 // sending an ack to browser process that the paint is complete...
1087 update_reply_pending_ = pending_update_params_->needs_ack;
1088 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1089 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341090 }
[email protected]53d3f302009-12-21 04:42:051091
[email protected]29ed96a2012-02-04 18:12:161092 // If we're software rendering then we're done initiating the paint.
1093 if (!is_accelerated_compositing_active_)
1094 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291095}
1096
1097///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461098// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291099
[email protected]4873c7d2009-07-16 06:36:281100void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091101 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1102 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571103 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481104 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181105 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571106 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291107 return;
1108
[email protected]552e6002009-11-19 05:24:571109 paint_aggregator_.InvalidateRect(damaged_rect);
1110
1111 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241112 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571113 return;
1114 if (!paint_aggregator_.HasPendingUpdate())
1115 return;
[email protected]aa4117f2011-12-09 22:19:211116 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241117 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1118 return;
1119
1120 // When GPU rendering, combine pending animations and invalidations into
1121 // a single update.
[email protected]816edc62012-03-17 01:27:221122 if (is_accelerated_compositing_active_ &&
1123 animation_update_pending_ &&
1124 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571125 return;
1126
1127 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291128 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1129 // on the call stack.
1130 // 2) Allows us to collect more damage rects before painting to help coalesce
1131 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241132 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211133 MessageLoop::current()->PostTask(
1134 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291135}
1136
[email protected]990278ff2012-11-13 02:12:551137void RenderWidget::didScrollRect(int dx, int dy,
1138 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461139 // Drop scrolls on the floor when we are in compositing mode.
1140 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561141 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461142 return;
1143
[email protected]552e6002009-11-19 05:24:571144 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481145 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181146 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571147 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291148 return;
1149
[email protected]990278ff2012-11-13 02:12:551150 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571151
1152 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241153 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571154 return;
1155 if (!paint_aggregator_.HasPendingUpdate())
1156 return;
[email protected]aa4117f2011-12-09 22:19:211157 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241158 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1159 return;
1160
1161 // When GPU rendering, combine pending animations and invalidations into
1162 // a single update.
[email protected]816edc62012-03-17 01:27:221163 if (is_accelerated_compositing_active_ &&
1164 animation_update_pending_ &&
1165 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571166 return;
1167
1168 // Perform updating asynchronously. This serves two purposes:
1169 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1170 // on the call stack.
1171 // 2) Allows us to collect more damage rects before painting to help coalesce
1172 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241173 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211174 MessageLoop::current()->PostTask(
1175 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291176}
1177
[email protected]244ac1892011-12-02 17:04:471178void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091179 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1180 size_ = new_size;
1181 need_update_rect_for_auto_resize_ = true;
[email protected]240b5c32012-11-09 19:17:181182 // If we don't clear PaintAggregator after changing autoResize state, then
1183 // we might end up in a situation where bitmap_rect is larger than the
1184 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1185 // with invalid damage rects.
1186 paint_aggregator_.ClearPendingUpdate();
[email protected]ea3ee0a2012-05-15 03:43:091187 }
[email protected]244ac1892011-12-02 17:04:471188}
1189
[email protected]91acd1c2012-03-14 08:32:391190void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221191 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1192
[email protected]c63b4d42012-04-26 01:01:071193#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211194 if (!is_accelerated_compositing_active_) {
1195 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1196 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1197 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1198 // going to switch to accelerated compositing, the GPU process may need
1199 // round-trips to the browser's UI thread before finishing the frame,
1200 // causing deadlocks if we delay the UpdateRect until we receive the
1201 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071202 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1203 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211204 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1205 }
[email protected]c63b4d42012-04-26 01:01:071206#endif
[email protected]aa4117f2011-12-09 22:19:211207
[email protected]ea162f92011-10-04 23:08:221208 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421209 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241210 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221211}
1212
1213void RenderWidget::didDeactivateCompositor() {
1214 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1215
1216 is_accelerated_compositing_active_ = false;
1217 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1218 routing_id_, is_accelerated_compositing_active_));
1219
[email protected]ea162f92011-10-04 23:08:221220 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241221 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091222
1223 // In single-threaded mode, we exit force compositing mode and re-enter in
1224 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1225 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1226 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361227 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091228 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561229}
1230
[email protected]9cd43a62012-03-26 08:03:561231void RenderWidget::willBeginCompositorFrame() {
1232 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371233
1234 DCHECK(RenderThreadImpl::current()->compositor_thread());
1235
1236 // The following two can result in further layout and possibly
1237 // enable GPU acceleration so they need to be called before any painting
1238 // is done.
[email protected]3306f262012-09-21 19:20:421239 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371240 UpdateSelectionBounds();
1241
[email protected]9cd43a62012-03-26 08:03:561242 WillInitiatePaint();
1243}
1244
[email protected]3391a0772012-03-28 00:32:071245void RenderWidget::didBecomeReadyForAdditionalInput() {
1246 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1247 if (pending_input_event_ack_.get())
1248 Send(pending_input_event_ack_.release());
1249}
1250
[email protected]58264a32011-11-17 23:36:151251void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501252 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351253 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1254 // NOTE: Tests may break if this event is renamed or moved.
1255 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161256 // Notify subclasses that we initiated the paint operation.
1257 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151258}
1259
1260void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181261 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1262
1263 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561264 DidFlushPaint();
1265
[email protected]aa4117f2011-12-09 22:19:211266 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151267 return;
1268
[email protected]ea3ee0a2012-05-15 03:43:091269 if (!next_paint_flags_ &&
1270 !need_update_rect_for_auto_resize_ &&
1271 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151272 return;
[email protected]ea3ee0a2012-05-15 03:43:091273 }
[email protected]58264a32011-11-17 23:36:151274
1275 ViewHostMsg_UpdateRect_Params params;
1276 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151277 params.plugin_window_moves.swap(plugin_window_moves_);
1278 params.flags = next_paint_flags_;
1279 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121280 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091281 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151282
1283 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1284 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091285 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151286}
1287
[email protected]f98d7e3c2010-09-13 22:30:461288void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091289 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]d0be63772011-12-20 23:18:041290 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401291 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041292 } else {
[email protected]c3d45532011-10-07 19:20:401293 // TODO(nduca): replace with something a little less hacky. The reason this
1294 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1295 // contains a lot of host-renderer synchronization logic that is still
1296 // important for the accelerated compositing case. The option of simply
1297 // duplicating all that code is less desirable than "faking out" the
1298 // invalidation path using a magical damage rect.
1299 didInvalidateRect(WebRect(0, 0, 1, 1));
1300 }
[email protected]f98d7e3c2010-09-13 22:30:461301}
1302
[email protected]5f8b1022011-01-21 23:34:501303void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201304 if (animation_update_pending_)
1305 return;
1306
[email protected]921244e42011-07-20 16:36:301307 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201308 animation_update_pending_ = true;
1309 if (!animation_timer_.IsRunning()) {
1310 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1311 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211312 }
[email protected]5f8b1022011-01-21 23:34:501313}
1314
[email protected]4873c7d2009-07-16 06:36:281315void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301316 // TODO(darin): Eliminate this temporary.
1317 WebCursor cursor(cursor_info);
1318
initial.commit09911bf2008-07-26 23:55:291319 // Only send a SetCursor message if we need to make a change.
1320 if (!current_cursor_.IsEqual(cursor)) {
1321 current_cursor_ = cursor;
1322 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1323 }
1324}
1325
1326// We are supposed to get a single call to Show for a newly created RenderWidget
1327// that was created via RenderWidget::CreateWebView. So, we wait until this
1328// point to dispatch the ShowWidget message.
1329//
1330// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281331// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291332//
[email protected]4873c7d2009-07-16 06:36:281333void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291334 DCHECK(!did_show_) << "received extraneous Show call";
1335 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1336 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1337
[email protected]8de12d942010-11-17 20:42:441338 if (did_show_)
1339 return;
1340
1341 did_show_ = true;
1342 // NOTE: initial_pos_ may still have its default values at this point, but
1343 // that's okay. It'll be ignored if as_popup is false, or the browser
1344 // process will impose a default position otherwise.
1345 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1346 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291347}
1348
[email protected]4873c7d2009-07-16 06:36:281349void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291350}
1351
[email protected]4873c7d2009-07-16 06:36:281352void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291353}
1354
[email protected]2533ce12009-05-09 00:02:241355void RenderWidget::DoDeferredClose() {
1356 Send(new ViewHostMsg_Close(routing_id_));
1357}
1358
[email protected]4873c7d2009-07-16 06:36:281359void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321360 if (is_swapped_out_) {
1361 // This widget is currently swapped out, and the active widget is in a
1362 // different process. Have the browser route the close request to the
1363 // active widget instead, so that the correct unload handlers are run.
1364 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1365 return;
1366 }
1367
initial.commit09911bf2008-07-26 23:55:291368 // If a page calls window.close() twice, we'll end up here twice, but that's
1369 // OK. It is safe to send multiple Close messages.
1370
[email protected]2533ce12009-05-09 00:02:241371 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1372 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1373 // could be closed before the JS finishes executing. So instead, post a
1374 // message back to the message loop, which won't run until the JS is
1375 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211376 MessageLoop::current()->PostTask(
1377 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291378}
1379
1380void RenderWidget::Close() {
1381 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281382 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291383 webwidget_ = NULL;
1384 }
1385}
1386
[email protected]4873c7d2009-07-16 06:36:281387WebRect RenderWidget::windowRect() {
1388 if (pending_window_rect_count_)
1389 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241390
[email protected]80ad8622012-11-07 16:33:031391 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291392}
1393
[email protected]8a9d6ca32011-06-06 20:11:301394void RenderWidget::setToolTipText(const WebKit::WebString& text,
1395 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541396 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301397}
1398
[email protected]4873c7d2009-07-16 06:36:281399void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291400 if (did_show_) {
1401 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241402 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291403 } else {
1404 initial_pos_ = pos;
1405 }
1406}
1407
[email protected]2533ce12009-05-09 00:02:241408void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1409 pending_window_rect_ = rect;
1410 pending_window_rect_count_++;
1411}
1412
[email protected]4873c7d2009-07-16 06:36:281413WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241414 if (pending_window_rect_count_) {
1415 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1416 // the RootWindowRect is probably going to return wrong results since the
1417 // browser may not have processed the Move yet. There isn't really anything
1418 // good to do in this case, and it shouldn't happen - since this size is
1419 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281420 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241421 }
1422
[email protected]80ad8622012-11-07 16:33:031423 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371424}
1425
[email protected]4873c7d2009-07-16 06:36:281426WebRect RenderWidget::windowResizerRect() {
1427 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191428}
1429
[email protected]fa7b1dc2010-06-23 17:53:041430void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031431 // To prevent this renderer process from sending unnecessary IPC messages to
1432 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041433 // only during the input method attached to the browser process is active.
1434 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291435}
1436
[email protected]58b48a0d2012-06-13 07:01:351437void RenderWidget::UpdateCompositionInfo(
1438 const ui::Range& range,
1439 const std::vector<gfx::Rect>& character_bounds) {
1440 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1441 return;
1442 composition_character_bounds_ = character_bounds;
1443 composition_range_ = range;
1444 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1445 routing_id(), composition_range_, composition_character_bounds_));
1446}
1447
[email protected]fa7b1dc2010-06-23 17:53:041448void RenderWidget::OnImeSetComposition(
1449 const string16& text,
1450 const std::vector<WebCompositionUnderline>& underlines,
1451 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281452 if (!webwidget_)
1453 return;
[email protected]d4cff272011-05-02 15:46:011454 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041455 text, WebVector<WebCompositionUnderline>(underlines),
1456 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011457 // Setting the IME composition was successful. Send the new composition
1458 // range to the browser.
1459 ui::Range range(ui::Range::InvalidRange());
1460 size_t location, length;
1461 if (webwidget_->compositionRange(&location, &length)) {
1462 range.set_start(location);
1463 range.set_end(location + length);
1464 }
1465 // The IME was cancelled via the Esc key, so just send back the caret.
1466 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1467 range.set_start(location);
1468 range.set_end(location + length);
1469 }
[email protected]58b48a0d2012-06-13 07:01:351470 std::vector<gfx::Rect> character_bounds;
1471 GetCompositionCharacterBounds(&character_bounds);
1472 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011473 } else {
[email protected]fa7b1dc2010-06-23 17:53:041474 // If we failed to set the composition text, then we need to let the browser
1475 // process to cancel the input method's ongoing composition session, to make
1476 // sure we are in a consistent state.
1477 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011478
1479 // Send an updated IME range with just the caret range.
1480 ui::Range range(ui::Range::InvalidRange());
1481 size_t location, length;
1482 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1483 range.set_start(location);
1484 range.set_end(location + length);
1485 }
[email protected]58b48a0d2012-06-13 07:01:351486 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261487 }
[email protected]fa7b1dc2010-06-23 17:53:041488}
1489
[email protected]4de6d1692011-10-12 08:45:441490void RenderWidget::OnImeConfirmComposition(
1491 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041492 if (!webwidget_)
1493 return;
1494
1495 handling_input_event_ = true;
1496 webwidget_->confirmComposition(text);
1497 handling_input_event_ = false;
1498
[email protected]d4cff272011-05-02 15:46:011499 // Send an updated IME range with just the caret range.
1500 ui::Range range(ui::Range::InvalidRange());
1501 size_t location, length;
1502 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1503 range.set_start(location);
1504 range.set_end(location + length);
1505 }
[email protected]58b48a0d2012-06-13 07:01:351506 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291507}
1508
[email protected]948f7ab72010-05-28 23:48:081509// This message causes the renderer to render an image of the
1510// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251511void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1512 int tag,
1513 const gfx::Size& page_size,
1514 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001515 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1516 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251517 // Close our unused handle.
1518#if defined(OS_WIN)
1519 ::CloseHandle(dib_handle);
1520#elif defined(OS_MACOSX)
1521 base::SharedMemory::CloseHandle(dib_handle);
1522#endif
1523 }
[email protected]d65adb12010-04-28 17:26:491524 return;
[email protected]45c6aad32010-11-11 04:46:251525 }
[email protected]d65adb12010-04-28 17:26:491526
[email protected]948f7ab72010-05-28 23:48:081527 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491528 // If one of these is empty, then we just return the dib we were
1529 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091530 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491531 return;
1532 }
1533
1534 // Map the given DIB ID into this process, and unmap it at the end
1535 // of this function.
[email protected]45c6aad32010-11-11 04:46:251536 scoped_ptr<TransportDIB> paint_at_size_buffer(
1537 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301538
[email protected]4b01b962012-10-09 23:17:351539 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281540 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351541 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281542 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511543 gfx::Size canvas_size = page_size_in_pixel;
1544 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491545 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511546 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491547 static_cast<float>(canvas_size.height());
1548
[email protected]ee8d6fd2010-05-26 17:05:481549 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491550 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1551 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481552 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491553
[email protected]36808ad2010-10-20 19:18:301554 scoped_ptr<skia::PlatformCanvas> canvas(
1555 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1556 canvas_size.height()));
1557 if (!canvas.get()) {
1558 NOTREACHED();
1559 return;
1560 }
1561
[email protected]d65adb12010-04-28 17:26:491562 // Reset bounds to what we actually received, but they should be the
1563 // same.
1564 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1565 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1566 bounds.set_width(canvas->getDevice()->width());
1567 bounds.set_height(canvas->getDevice()->height());
1568
1569 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081570 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491571 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1572
[email protected]948f7ab72010-05-28 23:48:081573 // Have to make sure we're laid out at the right size before
1574 // rendering.
1575 gfx::Size old_size = webwidget_->size();
1576 webwidget_->resize(page_size);
1577 webwidget_->layout();
1578
[email protected]d65adb12010-04-28 17:26:491579 // Paint the entire thing (using original bounds, not scaled bounds).
1580 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1581 canvas->restore();
1582
[email protected]948f7ab72010-05-28 23:48:081583 // Return the widget to its previous size.
1584 webwidget_->resize(old_size);
1585
[email protected]c88c9442010-07-19 18:55:091586 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491587}
1588
[email protected]3d9ec5052013-01-02 22:05:251589void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121590 // During shutdown we can just ignore this message.
1591 if (!webwidget_)
1592 return;
1593
1594 set_next_paint_is_repaint_ack();
[email protected]b89c90762013-01-06 20:29:301595 if (is_accelerated_compositing_active_) {
1596 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461597 scheduleComposite();
1598 } else {
1599 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1600 didInvalidateRect(repaint_rect);
1601 }
[email protected]ec7dc112008-08-06 05:30:121602}
1603
[email protected]3d9ec5052013-01-02 22:05:251604void RenderWidget::OnSmoothScrollCompleted(int gesture_id) {
[email protected]0e241b4b2012-08-18 09:06:271605 PendingSmoothScrollGestureMap::iterator it =
1606 pending_smooth_scroll_gestures_.find(gesture_id);
1607 DCHECK(it != pending_smooth_scroll_gestures_.end());
1608 it->second.Run();
1609 pending_smooth_scroll_gestures_.erase(it);
1610}
1611
[email protected]4873c7d2009-07-16 06:36:281612void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111613 if (!webwidget_)
1614 return;
[email protected]4873c7d2009-07-16 06:36:281615 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111616}
1617
[email protected]6131a642012-06-15 23:26:531618void RenderWidget::OnScreenInfoChanged(
1619 const WebKit::WebScreenInfo& screen_info) {
1620 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191621 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531622}
1623
[email protected]80ad8622012-11-07 16:33:031624void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1625 const gfx::Rect& window_screen_rect) {
1626 view_screen_rect_ = view_screen_rect;
1627 window_screen_rect_ = window_screen_rect;
1628 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1629}
1630
[email protected]468ac582012-11-20 00:53:191631void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1632 if (device_scale_factor_ == device_scale_factor)
1633 return;
1634
1635 device_scale_factor_ = device_scale_factor;
1636
1637 if (!is_accelerated_compositing_active_) {
1638 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1639 } else {
1640 scheduleComposite();
1641 }
1642}
1643
[email protected]719b36f2010-12-22 20:36:461644webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151645 const gfx::Rect& paint_bounds,
1646 TransportDIB** dib,
1647 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201648 gfx::Rect* clip,
1649 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461650 // Bare RenderWidgets don't support optimized plugin painting.
1651 return NULL;
[email protected]ca4847f2010-09-24 05:39:151652}
1653
[email protected]ceb36f7d2012-10-31 18:33:241654gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521655 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241656 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521657}
1658
[email protected]bee16aab2009-08-26 15:55:031659void RenderWidget::SetHidden(bool hidden) {
1660 if (is_hidden_ == hidden)
1661 return;
1662
1663 // The status has changed. Tell the RenderThread about it.
1664 is_hidden_ = hidden;
1665 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271666 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031667 else
[email protected]380244092011-10-07 17:26:271668 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031669}
1670
[email protected]2b624c562011-10-27 22:58:261671void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261672 if (!webwidget_)
1673 return;
1674
1675 if (is_fullscreen_) {
1676 webwidget_->willExitFullScreen();
1677 } else {
1678 webwidget_->willEnterFullScreen();
1679 }
[email protected]2b624c562011-10-27 22:58:261680}
1681
1682void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261683 if (!webwidget_)
1684 return;
1685
1686 if (is_fullscreen_) {
1687 webwidget_->didEnterFullScreen();
1688 } else {
1689 webwidget_->didExitFullScreen();
1690 }
[email protected]2b624c562011-10-27 22:58:261691}
1692
[email protected]699ab0d2009-04-23 23:19:141693void RenderWidget::SetBackground(const SkBitmap& background) {
1694 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461695
[email protected]699ab0d2009-04-23 23:19:141696 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281697 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141698}
1699
[email protected]674741932009-02-04 23:44:461700bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051701 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461702}
1703
1704bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051705 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461706}
1707
1708void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051709 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461710}
1711
1712void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051713 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461714}
1715
1716void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051717 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461718}
1719
[email protected]b18583c2012-12-18 06:55:271720static bool IsDateTimeInput(ui::TextInputType type) {
1721 return type == ui::TEXT_INPUT_TYPE_DATE ||
1722 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1723 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1724 type == ui::TEXT_INPUT_TYPE_MONTH ||
1725 type == ui::TEXT_INPUT_TYPE_TIME ||
1726 type == ui::TEXT_INPUT_TYPE_WEEK;
1727}
1728
1729
[email protected]3306f262012-09-21 19:20:421730void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
1731 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1732 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291733 return;
[email protected]ad26ef42011-06-17 07:59:451734 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271735 if (IsDateTimeInput(new_type))
1736 return; // Not considered as a text input field in WebKit/Chromium.
1737
[email protected]5b739cb2012-08-21 20:35:211738 WebKit::WebTextInputInfo new_info;
1739 if (webwidget_)
1740 new_info = webwidget_->textInputInfo();
1741
[email protected]ad26ef42011-06-17 07:59:451742 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211743
[email protected]3306f262012-09-21 19:20:421744 // Only sends text input params if they are changed or if the ime should be
1745 // shown.
1746 if (show_ime_if_needed || (text_input_type_ != new_type
1747 || text_input_info_ != new_info
1748 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:211749 ViewHostMsg_TextInputState_Params p;
1750 p.type = new_type;
1751 p.value = new_info.value.utf8();
1752 p.selection_start = new_info.selectionStart;
1753 p.selection_end = new_info.selectionEnd;
1754 p.composition_start = new_info.compositionStart;
1755 p.composition_end = new_info.compositionEnd;
1756 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:421757 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:211758 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1759
1760 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041761 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451762 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:291763 }
initial.commit09911bf2008-07-26 23:55:291764}
1765
[email protected]3f783362011-10-21 22:40:501766void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1767 WebRect start_webrect;
1768 WebRect end_webrect;
1769 webwidget_->selectionBounds(start_webrect, end_webrect);
1770 *start = start_webrect;
1771 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321772}
1773
[email protected]e99ef6f2011-10-16 01:13:001774void RenderWidget::UpdateSelectionBounds() {
1775 if (!webwidget_)
1776 return;
1777
[email protected]3f783362011-10-21 22:40:501778 gfx::Rect start_rect;
1779 gfx::Rect end_rect;
1780 GetSelectionBounds(&start_rect, &end_rect);
[email protected]58b48a0d2012-06-13 07:01:351781 if (selection_start_rect_ != start_rect || selection_end_rect_ != end_rect) {
1782 selection_start_rect_ = start_rect;
1783 selection_end_rect_ = end_rect;
[email protected]b556c2e2012-08-10 22:18:271784 WebTextDirection start_dir = WebKit::WebTextDirectionLeftToRight;
1785 WebTextDirection end_dir = WebKit::WebTextDirectionLeftToRight;
1786 webwidget_->selectionTextDirection(start_dir, end_dir);
1787 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_,
1788 selection_start_rect_, start_dir, selection_end_rect_, end_dir));
[email protected]58b48a0d2012-06-13 07:01:351789 }
[email protected]e99ef6f2011-10-16 01:13:001790
[email protected]58b48a0d2012-06-13 07:01:351791 std::vector<gfx::Rect> character_bounds;
1792 GetCompositionCharacterBounds(&character_bounds);
1793 UpdateCompositionInfo(composition_range_, character_bounds);
1794}
1795
1796bool RenderWidget::ShouldUpdateCompositionInfo(
1797 const ui::Range& range,
1798 const std::vector<gfx::Rect>& bounds) {
1799 if (composition_range_ != range)
1800 return true;
1801 if (bounds.size() != composition_character_bounds_.size())
1802 return true;
1803 for (size_t i = 0; i < bounds.size(); ++i) {
1804 if (bounds[i] != composition_character_bounds_[i])
1805 return true;
1806 }
1807 return false;
[email protected]e99ef6f2011-10-16 01:13:001808}
1809
[email protected]73bf95812011-10-12 11:38:321810// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451811COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1812 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1813COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1814 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1815COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1816 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181817COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1818 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1819COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1820 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1821COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1822 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1823COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1824 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1825COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1826 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:001827COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
1828 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
1829COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
1830 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
1831COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
1832 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
1833COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
1834 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
1835COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
1836 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
1837COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
1838 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:011839COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
1840 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
1841COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
1842 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451843
[email protected]5b739cb2012-08-21 20:35:211844ui::TextInputType RenderWidget::WebKitToUiTextInputType(
1845 WebKit::WebTextInputType type) {
1846 // Check the type is in the range representable by ui::TextInputType.
1847 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
1848 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1849 return static_cast<ui::TextInputType>(type);
1850}
1851
[email protected]ad26ef42011-06-17 07:59:451852ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:271853 if (webwidget_)
1854 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:451855 return ui::TEXT_INPUT_TYPE_NONE;
1856}
1857
[email protected]58b48a0d2012-06-13 07:01:351858void RenderWidget::GetCompositionCharacterBounds(
1859 std::vector<gfx::Rect>* bounds) {
1860 DCHECK(bounds);
1861 bounds->clear();
1862}
1863
[email protected]ad26ef42011-06-17 07:59:451864bool RenderWidget::CanComposeInline() {
1865 return true;
[email protected]56ea1a62011-05-30 07:05:571866}
1867
[email protected]4873c7d2009-07-16 06:36:281868WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041869 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281870}
1871
[email protected]f660d9c2012-06-06 18:31:211872float RenderWidget::deviceScaleFactor() {
1873 return device_scale_factor_;
1874}
1875
[email protected]fa7b1dc2010-06-23 17:53:041876void RenderWidget::resetInputMethod() {
1877 if (!input_method_is_active_)
1878 return;
1879
1880 // If the last text input type is not None, then we should finish any
1881 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451882 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041883 // If a composition text exists, then we need to let the browser process
1884 // to cancel the input method's ongoing composition session.
1885 if (webwidget_->confirmComposition())
1886 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1887 }
[email protected]d4cff272011-05-02 15:46:011888
1889 // Send an updated IME range with the current caret rect.
1890 ui::Range range(ui::Range::InvalidRange());
1891 size_t location, length;
1892 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1893 range.set_start(location);
1894 range.set_end(location + length);
1895 }
[email protected]58b48a0d2012-06-13 07:01:351896
1897 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:041898}
1899
[email protected]f103ab72009-09-02 17:10:591900void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501901 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291902 size_t i = 0;
1903 for (; i < plugin_window_moves_.size(); ++i) {
1904 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581905 if (move.rects_valid) {
1906 plugin_window_moves_[i] = move;
1907 } else {
1908 plugin_window_moves_[i].visible = move.visible;
1909 }
initial.commit09911bf2008-07-26 23:55:291910 break;
1911 }
1912 }
1913
1914 if (i == plugin_window_moves_.size())
1915 plugin_window_moves_.push_back(move);
1916}
[email protected]268654772009-08-06 23:02:041917
1918void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1919 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1920 i != plugin_window_moves_.end(); ++i) {
1921 if (i->window == window) {
1922 plugin_window_moves_.erase(i);
1923 break;
1924 }
1925 }
1926}
[email protected]67bfb83f2011-09-22 03:36:371927
[email protected]b63d58d2012-11-26 22:37:441928void RenderWidget::GetRenderingStats(
1929 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]b89c90762013-01-06 20:29:301930 webwidget()->renderingStats(stats);
[email protected]b63d58d2012-11-26 22:37:441931
1932 stats.rendering_stats.numAnimationFrames +=
1933 software_stats_.numAnimationFrames;
1934 stats.rendering_stats.numFramesSentToScreen +=
1935 software_stats_.numFramesSentToScreen;
1936 stats.rendering_stats.totalPaintTimeInSeconds +=
1937 software_stats_.totalPaintTimeInSeconds;
1938 stats.rendering_stats.totalPixelsPainted +=
1939 software_stats_.totalPixelsPainted;
1940 stats.rendering_stats.totalRasterizeTimeInSeconds +=
[email protected]63ab54262012-11-09 15:58:451941 software_stats_.totalRasterizeTimeInSeconds;
[email protected]b63d58d2012-11-26 22:37:441942 stats.rendering_stats.totalPixelsRasterized +=
1943 software_stats_.totalPixelsRasterized;
[email protected]fef5e3972012-08-07 03:59:471944}
1945
[email protected]e9ff79c2012-10-19 21:31:261946bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:521947 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
1948 if (!gpu_channel)
1949 return false;
1950
1951 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
1952}
1953
[email protected]0e241b4b2012-08-18 09:06:271954void RenderWidget::BeginSmoothScroll(
1955 bool down,
[email protected]ebd8b562012-10-09 14:44:291956 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:191957 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:291958 int mouse_event_x,
1959 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:271960 DCHECK(!callback.is_null());
1961 int id = next_smooth_scroll_gesture_id_++;
[email protected]267909d2012-10-20 04:36:191962
1963 ViewHostMsg_BeginSmoothScroll_Params params;
1964 params.scroll_down = down;
1965 params.pixels_to_scroll = pixels_to_scroll;
1966 params.mouse_event_x = mouse_event_x;
1967 params.mouse_event_y = mouse_event_y;
1968
1969 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, params));
[email protected]0e241b4b2012-08-18 09:06:271970 pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback));
[email protected]a39ca1652012-07-13 21:30:581971}
1972
[email protected]67bfb83f2011-09-22 03:36:371973bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1974 return false;
1975}
[email protected]c3d45532011-10-07 19:20:401976
[email protected]41d86852012-11-07 12:23:241977bool RenderWidget::WillHandleGestureEvent(
1978 const WebKit::WebGestureEvent& event) {
1979 return false;
1980}
1981
[email protected]c3d45532011-10-07 19:20:401982bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1983 return false;
1984}
[email protected]e9ff79c2012-10-19 21:31:261985
[email protected]3d5c243b2012-11-30 00:26:011986bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
1987 return true;
1988}
1989
[email protected]e9ff79c2012-10-19 21:31:261990} // namespace content