blob: 7edaf7259d412ff6676b44dd3026c650c04ccf67 [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]8c89e7792009-08-19 21:18:3443#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5044#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4645#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4846
47#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4948#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5249#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4150#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4851#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4452
[email protected]8bd0fe62011-01-17 06:44:3753#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2954
[email protected]fa7b1dc2010-06-23 17:53:0455using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3056using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2457using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2258using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0659using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2860using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4461using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0062using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2863using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5964using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1865using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0166using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5267using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1968using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5269using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2870using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2471using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0472using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1873using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2674
75namespace content {
[email protected]62cb33cae2009-03-27 23:30:2276
[email protected]faec7b12012-06-19 14:42:1377static const float kStandardDPI = 160;
[email protected]f1cccb32012-06-06 18:29:5978
[email protected]6fd35b72012-03-01 19:46:4179RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:0480 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:4481 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:2982 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:5683 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:1184 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2985 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:3086 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:3587 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2988 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:0689 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:0590 update_reply_pending_(false),
[email protected]ea3ee0a2012-05-15 03:43:0991 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:2492 using_asynchronous_swapbuffers_(false),
93 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2994 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2995 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:0996 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:2997 needs_repainting_on_restore_(false),
98 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4999 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:48100 closing_(false),
[email protected]14392a52012-05-02 20:28:44101 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04102 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45103 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
104 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12105 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48106 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12107 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50108 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21109 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07110 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04111 screen_info_(screen_info),
[email protected]ce2b28e2012-08-09 15:53:57112 device_scale_factor_(1),
[email protected]0e241b4b2012-08-18 09:06:27113 throttle_input_events_(true),
[email protected]cb6430932012-10-31 00:53:36114 next_smooth_scroll_gesture_id_(0),
115 is_threaded_compositing_enabled_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05116 if (!swapped_out)
117 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27118 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18119 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
120 switches::kDisableGpuVsync);
[email protected]424820962012-06-08 15:33:19121#if defined(OS_CHROMEOS) || defined(OS_MACOSX)
[email protected]faec7b12012-06-19 14:42:13122 device_scale_factor_ = screen_info.verticalDPI / kStandardDPI;
123 // Unless an explicit scale factor was provided for testing, ensure the scale
124 // is integral.
125 if (!CommandLine::ForCurrentProcess()->HasSwitch(
126 switches::kForceDeviceScaleFactor))
127 device_scale_factor_ = static_cast<int>(device_scale_factor_);
128 device_scale_factor_ = std::max(1.0f, device_scale_factor_);
[email protected]f1cccb32012-06-06 18:29:59129#endif
[email protected]cb6430932012-10-31 00:53:36130 is_threaded_compositing_enabled_ =
131 CommandLine::ForCurrentProcess()->HasSwitch(
132 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29133}
134
135RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11136 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21137 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35138 if (current_paint_buf_) {
139 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
140 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29141 }
[email protected]992db4c2011-05-12 15:37:15142 // If we are swapped out, we have released already.
143 if (!is_swapped_out_)
144 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29145}
146
[email protected]484955942010-08-19 16:13:18147// static
[email protected]8085dbc82008-09-26 22:53:44148RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04149 WebKit::WebPopupType popup_type,
150 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29151 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41152 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04153 new RenderWidget(popup_type, screen_info, false));
initial.commit09911bf2008-07-26 23:55:29154 widget->Init(opener_id); // adds reference
155 return widget;
156}
157
[email protected]484955942010-08-19 16:13:18158// static
159WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
160 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03161 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18162 break;
163 case WebKit::WebPopupTypeSelect:
164 case WebKit::WebPopupTypeSuggestion:
165 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44166 case WebKit::WebPopupTypePage:
167 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03168 case WebKit::WebPopupTypeHelperPlugin:
169 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18170 default:
171 NOTREACHED();
172 }
173 return NULL;
174}
175
initial.commit09911bf2008-07-26 23:55:29176void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18177 DoInit(opener_id,
178 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56179 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
180 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18181}
182
[email protected]484955942010-08-19 16:13:18183void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06184 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18185 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29186 DCHECK(!webwidget_);
187
188 if (opener_id != MSG_ROUTING_NONE)
189 opener_id_ = opener_id;
190
[email protected]484955942010-08-19 16:13:18191 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29192
[email protected]380244092011-10-07 17:26:27193 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29194 if (result) {
[email protected]380244092011-10-07 17:26:27195 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29196 // Take a reference on behalf of the RenderThread. This will be balanced
197 // when we receive ViewMsg_Close.
198 AddRef();
199 } else {
200 DCHECK(false);
201 }
202}
203
[email protected]fc4404d2012-11-07 19:53:30204// This is used to complete pending inits and non-pending inits.
205void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29206 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29207
[email protected]fc4404d2012-11-07 19:53:30208 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42209
[email protected]479b0172012-10-29 19:27:09210 if (webwidget_) {
211 webwidget_->setCompositorSurfaceReady();
[email protected]cb6430932012-10-31 00:53:36212 if (is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:09213 webwidget_->enterForceCompositingMode(true);
214 }
[email protected]05a980d7a2012-02-07 22:16:42215 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29216
[email protected]6de74452009-02-25 18:04:59217 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29218}
219
[email protected]992db4c2011-05-12 15:37:15220void RenderWidget::SetSwappedOut(bool is_swapped_out) {
221 // We should only toggle between states.
222 DCHECK(is_swapped_out_ != is_swapped_out);
223 is_swapped_out_ = is_swapped_out;
224
225 // If we are swapping out, we will call ReleaseProcess, allowing the process
226 // to exit if all of its RenderViews are swapped out. We wait until the
227 // WasSwappedOut call to do this, to avoid showing the sad tab.
228 // If we are swapping in, we call AddRefProcess to prevent the process from
229 // exiting.
230 if (!is_swapped_out)
231 RenderProcess::current()->AddRefProcess();
232}
233
[email protected]a95986a82010-12-24 06:19:28234bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
235 bool handled = true;
236 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
237 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
238 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
239 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54240 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28241 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41242 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15243 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28244 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]a7266a92012-06-28 02:11:08245 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK, OnSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28246 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
247 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
248 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
249 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
250 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
251 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
252 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
253 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
[email protected]0e241b4b2012-08-18 09:06:27254 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted,
255 OnMsgSmoothScrollCompleted)
[email protected]fea38fc2012-06-13 17:38:37256 IPC_MESSAGE_HANDLER(ViewMsg_SetDeviceScaleFactor, OnSetDeviceScaleFactor)
[email protected]a95986a82010-12-24 06:19:28257 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
258 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53259 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03260 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]a95986a82010-12-24 06:19:28261 IPC_MESSAGE_UNHANDLED(handled = false)
262 IPC_END_MESSAGE_MAP()
263 return handled;
264}
initial.commit09911bf2008-07-26 23:55:29265
266bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15267 // Don't send any messages after the browser has told us to close, and filter
268 // most outgoing messages while swapped out.
269 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26270 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11271 closing_) {
initial.commit09911bf2008-07-26 23:55:29272 delete message;
273 return false;
274 }
275
276 // If given a messsage without a routing ID, then assign our routing ID.
277 if (message->routing_id() == MSG_ROUTING_NONE)
278 message->set_routing_id(routing_id_);
279
[email protected]380244092011-10-07 17:26:27280 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44281}
282
[email protected]61e2b3cc2012-03-02 16:13:34283void RenderWidget::Resize(const gfx::Size& new_size,
284 const gfx::Rect& resizer_rect,
285 bool is_fullscreen,
286 ResizeAck resize_ack) {
287 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
288 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
289 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29290
[email protected]61e2b3cc2012-03-02 16:13:34291 // Ignore this during shutdown.
292 if (!webwidget_)
293 return;
294
295 // Remember the rect where the resize corner will be drawn.
296 resizer_rect_ = resizer_rect;
297
298 // NOTE: We may have entered fullscreen mode without changing our size.
299 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
300 if (fullscreen_change)
301 WillToggleFullscreen();
302 is_fullscreen_ = is_fullscreen;
303
304 if (size_ != new_size) {
305 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34306 needs_repainting_on_restore_ = false;
307
308 size_ = new_size;
309
310 paint_aggregator_.ClearPendingUpdate();
311
312 // When resizing, we want to wait to paint before ACK'ing the resize. This
313 // ensures that we only resize as fast as we can paint. We only need to
314 // send an ACK if we are resized to a non-empty rect.
315 webwidget_->resize(new_size);
316 if (!new_size.IsEmpty()) {
317 if (!is_accelerated_compositing_active_) {
318 // Resize should have caused an invalidation of the entire view.
319 DCHECK(paint_aggregator_.HasPendingUpdate());
320 }
321
322 // Send the Resize_ACK flag once we paint again if requested.
323 if (resize_ack == SEND_RESIZE_ACK)
324 set_next_paint_is_resize_ack();
325 }
[email protected]ff475a322012-03-14 00:05:35326 } else {
327 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34328 }
329
330 if (fullscreen_change)
331 DidToggleFullscreen();
332
333 // If a resize ack is requested and it isn't set-up, then no more resizes will
334 // come in and in general things will go wrong.
335 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
336 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29337}
338
339void RenderWidget::OnClose() {
340 if (closing_)
341 return;
342 closing_ = true;
343
344 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03345 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27346 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03347 SetHidden(false);
348 }
initial.commit09911bf2008-07-26 23:55:29349
initial.commit09911bf2008-07-26 23:55:29350 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25351 // now. Post a task that only gets invoked when there are no nested message
352 // loops.
[email protected]32876ae2011-11-15 22:25:21353 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29354 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25355
356 // Balances the AddRef taken when we called AddRoute.
357 Release();
initial.commit09911bf2008-07-26 23:55:29358}
359
[email protected]61e2b3cc2012-03-02 16:13:34360// Got a response from the browser after the renderer decided to create a new
361// view.
[email protected]fc4404d2012-11-07 19:53:30362void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34363 DCHECK(routing_id_ != MSG_ROUTING_NONE);
364
[email protected]fc4404d2012-11-07 19:53:30365 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34366}
367
[email protected]f21c613a2009-02-12 14:46:17368void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09369 const gfx::Rect& resizer_rect,
370 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34371 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29372}
373
[email protected]b5913d72012-02-07 22:26:54374void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
375 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59376 gfx::Rect view_rect(size_);
377
[email protected]ce112fe2012-10-29 22:52:18378 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59379 if (!old_damage_rect.IsEmpty())
380 paint_aggregator_.InvalidateRect(old_damage_rect);
381
[email protected]ce112fe2012-10-29 22:52:18382 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59383 if (!new_damage_rect.IsEmpty())
384 paint_aggregator_.InvalidateRect(new_damage_rect);
385
[email protected]b5913d72012-02-07 22:26:54386 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59387
[email protected]b5913d72012-02-07 22:26:54388 if (webwidget_)
389 webwidget_->didChangeWindowResizerRect();
390 }
391}
392
initial.commit09911bf2008-07-26 23:55:29393void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31394 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29395 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03396 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29397}
398
[email protected]9e2e4632012-07-27 16:38:41399void RenderWidget::OnWasShown(bool needs_repainting) {
400 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29401 // During shutdown we can just ignore this message.
402 if (!webwidget_)
403 return;
404
405 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03406 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29407
408 if (!needs_repainting && !needs_repainting_on_restore_)
409 return;
410 needs_repainting_on_restore_ = false;
411
[email protected]d65adb12010-04-28 17:26:49412 // Tag the next paint as a restore ack, which is picked up by
413 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29414 set_next_paint_is_restore_ack();
415
416 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56417 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46418 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
419 } else {
420 scheduleComposite();
421 }
initial.commit09911bf2008-07-26 23:55:29422}
423
[email protected]992db4c2011-05-12 15:37:15424void RenderWidget::OnWasSwappedOut() {
425 // If we have been swapped out and no one else is using this process,
426 // it's safe to exit now. If we get swapped back in, we will call
427 // AddRefProcess in SetSwappedOut.
428 if (is_swapped_out_)
429 RenderProcess::current()->ReleaseProcess();
430}
431
[email protected]53d3f302009-12-21 04:42:05432void RenderWidget::OnRequestMoveAck() {
433 DCHECK(pending_window_rect_count_);
434 pending_window_rect_count_--;
435}
436
437void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58438 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21439 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05440 update_reply_pending_ = false;
441
[email protected]b4d08452010-10-05 17:34:35442 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
443 // have no current paint buffer.
444 if (current_paint_buf_) {
445 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
446 current_paint_buf_ = NULL;
447 }
448
[email protected]65225772011-05-12 21:10:24449 // If swapbuffers is still pending, then defer the update until the
450 // swapbuffers occurs.
451 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
452 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
453 return;
454 }
455
[email protected]29ed96a2012-02-04 18:12:16456 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18457 if (!is_accelerated_compositing_active_) {
458 DidFlushPaint();
459 }
[email protected]a2f6bc112009-06-27 16:27:25460
initial.commit09911bf2008-07-26 23:55:29461 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24462 DoDeferredUpdateAndSendInputAck();
463}
464
[email protected]d0be63772011-12-20 23:18:04465bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24466 return false;
467}
468
[email protected]479b0172012-10-29 19:27:09469bool RenderWidget::ForceCompositingModeEnabled() {
470 return false;
471}
472
[email protected]d0be63772011-12-20 23:18:04473void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24474 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21475 while (!updates_pending_swap_.empty()) {
476 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
477 updates_pending_swap_.pop_front();
478 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
479 // compositing pass, hence doesn't require an UpdateRect message.
480 if (msg)
481 Send(msg);
482 }
[email protected]65225772011-05-12 21:10:24483 num_swapbuffers_complete_pending_ = 0;
484 using_asynchronous_swapbuffers_ = false;
485 // Schedule another frame so the compositor learns about it.
486 scheduleComposite();
487}
488
[email protected]37a6f302011-07-11 23:43:08489void RenderWidget::OnSwapBuffersPosted() {
490 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21491
492 if (using_asynchronous_swapbuffers_) {
493 ViewHostMsg_UpdateRect* msg = NULL;
494 // pending_update_params_ can be NULL if the swap doesn't correspond to an
495 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
496 // message.
497 if (pending_update_params_.get()) {
498 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
499 pending_update_params_.reset();
500 }
501 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08502 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21503 }
[email protected]37a6f302011-07-11 23:43:08504}
505
506void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24507 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16508
[email protected]404939f2012-06-01 04:06:18509 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16510 DidFlushPaint();
511
[email protected]65225772011-05-12 21:10:24512 // When compositing deactivates, we reset the swapbuffers pending count. The
513 // swapbuffers acks may still arrive, however.
514 if (num_swapbuffers_complete_pending_ == 0) {
515 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
516 return;
517 }
[email protected]aa4117f2011-12-09 22:19:21518 DCHECK(!updates_pending_swap_.empty());
519 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
520 updates_pending_swap_.pop_front();
521 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
522 // compositing pass, hence doesn't require an UpdateRect message.
523 if (msg)
524 Send(msg);
[email protected]65225772011-05-12 21:10:24525 num_swapbuffers_complete_pending_--;
526
527 // If update reply is still pending, then defer the update until that reply
528 // occurs.
[email protected]d0be63772011-12-20 23:18:04529 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24530 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
531 return;
532 }
533
534 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06535 // when we were previously rendering. However, if an invalidation task is not
536 // posted, there may be software rendering work pending. In that case, don't
537 // early out.
538 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24539 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
540 return;
541 }
542
[email protected]cc66e682012-10-02 06:48:18543 // Do not call DoDeferredUpdate unless there's animation work to be done or
544 // a real invalidation. This prevents rendering in response to a swapbuffers
545 // callback coming back after we've navigated away from the page that
546 // generated it.
547 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
548 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
549 return;
550 }
551
[email protected]65225772011-05-12 21:10:24552 // Continue painting if necessary...
553 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29554}
555
initial.commit09911bf2008-07-26 23:55:29556void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24557 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56558 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29559
560 const char* data;
561 int data_length;
[email protected]5dd768212009-08-13 23:34:49562 handling_input_event_ = true;
563 if (!message.ReadData(&iter, &data, &data_length)) {
564 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29565 return;
[email protected]5dd768212009-08-13 23:34:49566 }
initial.commit09911bf2008-07-26 23:55:29567
568 const WebInputEvent* input_event =
569 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48570
[email protected]b68a0e52011-12-08 15:11:12571 bool is_keyboard_shortcut = false;
572 // is_keyboard_shortcut flag is only available for RawKeyDown events.
573 if (input_event->type == WebInputEvent::RawKeyDown)
574 message.ReadBool(&iter, &is_keyboard_shortcut);
575
[email protected]67bfb83f2011-09-22 03:36:37576 bool prevent_default = false;
577 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26578 const WebMouseEvent& mouse_event =
579 *static_cast<const WebMouseEvent*>(input_event);
580 TRACE_EVENT2("renderer", "HandleMouseMove",
581 "x", mouse_event.x, "y", mouse_event.y);
582 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37583 }
584
[email protected]41d86852012-11-07 12:23:24585 if (WebInputEvent::isGestureEventType(input_event->type)) {
586 const WebGestureEvent& gesture_event =
587 *static_cast<const WebGestureEvent*>(input_event);
588 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
589 }
590
[email protected]67bfb83f2011-09-22 03:36:37591 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12592 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
593 suppress_next_char_events_ = false;
594 if (!processed && webwidget_)
595 processed = webwidget_->handleInputEvent(*input_event);
596 }
597
598 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
599 // it's not processed by webkit, then we need to suppress the upcoming Char
600 // events.
601 if (!processed && is_keyboard_shortcut)
602 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29603
[email protected]a9fb30aa2011-10-06 06:58:46604 IPC::Message* response =
605 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
606 processed);
[email protected]3391a0772012-03-28 00:32:07607 bool event_type_gets_rate_limited =
608 input_event->type == WebInputEvent::MouseMove ||
609 input_event->type == WebInputEvent::MouseWheel ||
610 WebInputEvent::isTouchEventType(input_event->type);
611 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57612 throttle_input_events_ &&
613 ((webwidget_ ? webwidget_->isInputThrottled() : false) ||
614 paint_aggregator_.HasPendingUpdate());
[email protected]e2824412009-02-27 01:57:05615
[email protected]f8868d72012-04-27 19:13:03616 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24617 // We want to rate limit the input events in this case, so we'll wait for
618 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17619 if (pending_input_event_ack_.get()) {
620 // As two different kinds of events could cause us to postpone an ack
621 // we send it now, if we have one pending. The Browser should never
622 // send us the same kind of event we are delaying the ack for.
623 Send(pending_input_event_ack_.release());
624 }
[email protected]12fbad812009-09-01 18:21:24625 pending_input_event_ack_.reset(response);
626 } else {
627 Send(response);
628 }
629
[email protected]3306f262012-09-21 19:20:42630#if defined(OS_ANDROID)
631 // Allow the IME to be shown when the focus changes as a consequence
632 // of a processed touch end event.
633 if (input_event->type == WebInputEvent::TouchEnd && processed)
634 UpdateTextInputState(SHOW_IME_IF_NEEDED);
635#endif
636
[email protected]5dd768212009-08-13 23:34:49637 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48638
[email protected]67bfb83f2011-09-22 03:36:37639 if (!prevent_default) {
640 if (WebInputEvent::isKeyboardEventType(input_event->type))
641 DidHandleKeyEvent();
642 if (WebInputEvent::isMouseEventType(input_event->type))
643 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24644 if (WebInputEvent::isTouchEventType(input_event->type))
645 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37646 }
initial.commit09911bf2008-07-26 23:55:29647}
648
649void RenderWidget::OnMouseCaptureLost() {
650 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28651 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29652}
653
654void RenderWidget::OnSetFocus(bool enable) {
655 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33656 if (webwidget_)
657 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29658}
659
660void RenderWidget::ClearFocus() {
661 // We may have got the focus from the browser before this gets processed, in
662 // which case we do not want to unfocus ourself.
663 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28664 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29665}
666
[email protected]2d5d09d52009-06-15 14:29:21667void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00668 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21669 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06670 TRACE_EVENT2("renderer", "PaintRect",
671 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45672
673 const bool kEnableGpuBenchmarking =
674 CommandLine::ForCurrentProcess()->HasSwitch(
675 switches::kEnableGpuBenchmarking);
676 base::TimeTicks rasterize_begin_ticks;
677 if (kEnableGpuBenchmarking)
678 rasterize_begin_ticks = base::TimeTicks::HighResNow();
[email protected]4fb66842009-12-04 21:41:00679 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21680
681 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00682 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
683 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03684
[email protected]699ab0d2009-04-23 23:19:14685 // If there is a custom background, tile it.
686 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14687 SkPaint paint;
688 SkShader* shader = SkShader::CreateBitmapShader(background_,
689 SkShader::kRepeat_TileMode,
690 SkShader::kRepeat_TileMode);
691 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20692
693 // Use kSrc_Mode to handle background_ transparency properly.
694 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
695
696 // Canvas could contain multiple update rects. Clip to given rect so that
697 // we don't accidentally clear other update rects.
698 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48699 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14700 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20701 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14702 }
703
[email protected]719b36f2010-12-22 20:36:46704 // First see if this rect is a plugin that can paint itself faster.
705 TransportDIB* optimized_dib = NULL;
706 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20707 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46708 webkit::ppapi::PluginInstance* optimized_instance =
709 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
710 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20711 &optimized_copy_rect,
712 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46713 if (optimized_instance) {
714 // This plugin can be optimize-painted and we can just ask it to paint
715 // itself. We don't actually need the TransportDIB in this case.
716 //
717 // This is an optimization for PPAPI plugins that know they're on top of
718 // the page content. If this rect is inside such a plugin, we can save some
719 // time and avoid re-rendering the page content which we know will be
720 // covered by the plugin later (this time can be significant, especially
721 // for a playing movie that is invalidating a lot).
722 //
723 // In the plugin movie case, hopefully the similar call to
724 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
725 // painting, because that avoids copying the plugin image to a different
726 // paint rect. Unfortunately, if anything on the page is animating other
727 // than the movie, it break this optimization since the union of the
728 // invalid regions will be larger than the plugin.
729 //
730 // This code optimizes that case, where we can still avoid painting in
731 // WebKit and filling the background (which can be slow) and just painting
732 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
733 // required.
[email protected]63ab54262012-11-09 15:58:45734 base::TimeTicks paint_begin_ticks;
735 if (kEnableGpuBenchmarking)
736 paint_begin_ticks = base::TimeTicks::HighResNow();
737
[email protected]df59dd42012-09-14 22:56:30738 SkAutoCanvasRestore auto_restore(canvas, true);
739 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46740 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27741 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21742 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45743 if (kEnableGpuBenchmarking) {
744 base::TimeDelta paint_time =
745 base::TimeTicks::HighResNow() - paint_begin_ticks;
746 if (!is_accelerated_compositing_active_)
747 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
748 }
[email protected]719b36f2010-12-22 20:36:46749 } else {
750 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45751 base::TimeTicks paint_begin_ticks;
752 if (kEnableGpuBenchmarking)
753 paint_begin_ticks = base::TimeTicks::HighResNow();
754
[email protected]719b36f2010-12-22 20:36:46755 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45756
757 if (kEnableGpuBenchmarking) {
758 base::TimeDelta paint_time =
759 base::TimeTicks::HighResNow() - paint_begin_ticks;
760 if (!is_accelerated_compositing_active_)
761 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
762 }
[email protected]719b36f2010-12-22 20:36:46763
764 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35765 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46766 }
initial.commit09911bf2008-07-26 23:55:29767
[email protected]4fb66842009-12-04 21:41:00768 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00769 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45770
771 if (kEnableGpuBenchmarking) {
772 base::TimeDelta rasterize_time =
773 base::TimeTicks::HighResNow() - rasterize_begin_ticks;
774 software_stats_.totalRasterizeTimeInSeconds += rasterize_time.InSecondsF();
775
776 int64 num_pixels_processed = rect.width() * rect.height();
777 software_stats_.totalPixelsPainted += num_pixels_processed;
778 software_stats_.totalPixelsRasterized += num_pixels_processed;
779 }
[email protected]4fb66842009-12-04 21:41:00780}
781
782void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
783 skia::PlatformCanvas* canvas) {
784 static bool kPaintBorder =
785 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
786 if (!kPaintBorder)
787 return;
788
[email protected]53d3f302009-12-21 04:42:05789 // Cycle through these colors to help distinguish new paint rects.
790 const SkColor colors[] = {
791 SkColorSetARGB(0x3F, 0xFF, 0, 0),
792 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
793 SkColorSetARGB(0x3F, 0, 0, 0xFF),
794 };
795 static int color_selector = 0;
796
[email protected]4fb66842009-12-04 21:41:00797 SkPaint paint;
798 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05799 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00800 paint.setStrokeWidth(1);
801
802 SkIRect irect;
803 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
804 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29805}
806
[email protected]52ccd0ea2011-02-16 01:09:05807void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30808 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30809 if (!animation_update_pending_) {
810 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59811 return;
[email protected]921244e42011-07-20 16:36:30812 }
[email protected]bd37ae252011-06-03 01:28:18813 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59814 // Record when we fired (according to base::Time::Now()) relative to when
815 // we posted the task to quantify how much the base::Time/base::TimeTicks
816 // skew is affecting animations.
817 base::TimeDelta animation_callback_delay = base::Time::Now() -
818 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
819 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
820 animation_callback_delay,
821 base::TimeDelta::FromMilliseconds(0),
822 base::TimeDelta::FromMilliseconds(30),
823 25);
824 }
[email protected]65225772011-05-12 21:10:24825 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24826}
827
[email protected]52ccd0ea2011-02-16 01:09:05828void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59829 if (!animation_update_pending_)
830 return;
[email protected]bd37ae252011-06-03 01:28:18831
832 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33833 base::TimeDelta animationInterval = IsRenderingVSynced() ?
834 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18835
[email protected]7c4329e2011-02-18 22:02:59836 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45837
838 // animation_floor_time_ is the earliest time that we should animate when
839 // using the dead reckoning software scheduler. If we're using swapbuffers
840 // complete callbacks to rate limit, we can ignore this floor.
841 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30842 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33843 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18844 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59845 // running animation callbacks so that if a callback requests another
846 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38847 animation_timer_.Stop();
848 animation_timer_.Start(FROM_HERE, animationInterval, this,
849 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59850 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30851 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59852 return;
[email protected]5f8b1022011-01-21 23:34:50853 }
[email protected]bd37ae252011-06-03 01:28:18854 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38855 if (!animation_timer_.IsRunning()) {
856 // This code uses base::Time::Now() to calculate the floor and next fire
857 // time because javascript's Date object uses base::Time::Now(). The
858 // message loop uses base::TimeTicks, which on windows can have a
859 // different granularity than base::Time.
860 // The upshot of all this is that this function might be called before
861 // base::Time::Now() has advanced past the animation_floor_time_. To
862 // avoid exposing this delay to javascript, we keep posting delayed
863 // tasks until base::Time::Now() has advanced far enough.
864 base::TimeDelta delay = animation_floor_time_ - now;
865 animation_timer_.Start(FROM_HERE, delay, this,
866 &RenderWidget::AnimationCallback);
867 }
[email protected]5f8b1022011-01-21 23:34:50868}
869
[email protected]bd37ae252011-06-03 01:28:18870bool RenderWidget::IsRenderingVSynced() {
871 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
872 // not caught by this check. This will lead to artificially low frame rates
873 // for people who force vsync off at a driver level and expect Chrome to speed
874 // up.
875 return !has_disable_gpu_vsync_switch_;
876}
877
[email protected]65225772011-05-12 21:10:24878void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06879 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24880 invalidation_task_posted_ = false;
881 DoDeferredUpdateAndSendInputAck();
882}
883
884void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05885 DoDeferredUpdate();
886
887 if (pending_input_event_ack_.get())
888 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21889}
890
[email protected]552e6002009-11-19 05:24:57891void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58892 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08893
[email protected]65225772011-05-12 21:10:24894 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29895 return;
[email protected]05a980d7a2012-02-07 22:16:42896
[email protected]fc4404d2012-11-07 19:53:30897 if (!init_complete_) {
898 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:42899 return;
900 }
[email protected]aa4117f2011-12-09 22:19:21901 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24902 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
903 return;
904 }
[email protected]9ca84622011-06-02 23:46:39905 if (is_accelerated_compositing_active_ &&
906 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24907 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
908 return;
909 }
initial.commit09911bf2008-07-26 23:55:29910
[email protected]552e6002009-11-19 05:24:57911 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29912 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57913 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29914 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24915 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29916 return;
917 }
918
[email protected]05a980d7a2012-02-07 22:16:42919 if (is_accelerated_compositing_active_)
920 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
921
[email protected]0fb93f52011-05-18 23:13:56922 // Tracking of frame rate jitter
923 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51924 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05925 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50926
[email protected]f98d7e3c2010-09-13 22:30:46927 // Layout may generate more invalidation. It may also enable the
928 // GPU acceleration, so make sure to run layout before we send the
929 // GpuRenderingActivated message.
930 webwidget_->layout();
931
[email protected]dcca3aa92012-02-17 23:03:37932 // The following two can result in further layout and possibly
933 // enable GPU acceleration so they need to be called before any painting
934 // is done.
[email protected]3306f262012-09-21 19:20:42935 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:37936 UpdateSelectionBounds();
937
[email protected]5f8b1022011-01-21 23:34:50938 // Suppress painting if nothing is dirty. This has to be done after updating
939 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24940 if (!paint_aggregator_.HasPendingUpdate()) {
941 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51942 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50943 return;
[email protected]65225772011-05-12 21:10:24944 }
[email protected]5f8b1022011-01-21 23:34:50945
[email protected]479b0172012-10-29 19:27:09946 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:36947 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:09948 ForceCompositingModeEnabled()) {
949 webwidget_->enterForceCompositingMode(true);
950 }
951
[email protected]872ae5b2011-05-26 20:20:50952 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56953 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04954 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56955 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
956 delay,
957 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:41958 base::TimeDelta::FromMilliseconds(120),
959 60);
[email protected]d0be63772011-12-20 23:18:04960 } else {
[email protected]0fb93f52011-05-18 23:13:56961 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
962 delay,
963 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:41964 base::TimeDelta::FromMilliseconds(120),
965 60);
[email protected]d0be63772011-12-20 23:18:04966 }
[email protected]872ae5b2011-05-26 20:20:50967
968 // Calculate filtered time per frame:
969 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
970 filtered_time_per_frame_ =
971 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56972 }
973 last_do_deferred_update_time_ = frame_begin_ticks;
974
[email protected]fef5e3972012-08-07 03:59:47975 if (!is_accelerated_compositing_active_) {
976 software_stats_.numAnimationFrames++;
977 software_stats_.numFramesSentToScreen++;
978 }
979
[email protected]552e6002009-11-19 05:24:57980 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29981 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30982 PaintAggregator::PendingUpdate update;
983 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29984
[email protected]53d3f302009-12-21 04:42:05985 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:18986 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:29987
[email protected]29ed96a2012-02-04 18:12:16988 // Notify derived classes that we're about to initiate a paint.
989 WillInitiatePaint();
990
[email protected]ca4847f2010-09-24 05:39:15991 // A plugin may be able to do an optimized paint. First check this, in which
992 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46993 // This optimization allows PPAPI plugins that declare themselves on top of
994 // the page (like a traditional windowed plugin) to be able to animate (think
995 // movie playing) without repeatedly re-painting the page underneath, or
996 // copying the plugin backing store (since we can send the plugin's backing
997 // store directly to the browser).
998 //
999 // This optimization only works when the entire invalid region is contained
1000 // within the plugin. There is a related optimization in PaintRect for the
1001 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151002 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151003 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201004 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211005 DCHECK(!pending_update_params_.get());
1006 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551007 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211008 pending_update_params_->scroll_rect = update.scroll_rect;
1009 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211010 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1011 pending_update_params_->flags = next_paint_flags_;
1012 pending_update_params_->scroll_offset = GetScrollOffset();
1013 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091014 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211015 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091016 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211017
[email protected]ca4847f2010-09-24 05:39:151018 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561019 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151020 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201021 &optimized_copy_rect,
1022 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271023 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471024 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211025 pending_update_params_->bitmap = dib->id();
1026 pending_update_params_->bitmap_rect = optimized_copy_location;
1027 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201028 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561029 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461030 // Compute a buffer for painting and cache it.
[email protected]ce112fe2012-10-29 22:52:181031 gfx::Rect pixel_bounds = gfx::ToFlooredRectDeprecated(
1032 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]ca4847f2010-09-24 05:39:151033 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351034 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591035 pixel_bounds));
[email protected]f98d7e3c2010-09-13 22:30:461036 if (!canvas.get()) {
1037 NOTREACHED();
1038 return;
1039 }
[email protected]cef3362f2009-12-21 17:48:451040
[email protected]f98d7e3c2010-09-13 22:30:461041 // We may get back a smaller canvas than we asked for.
1042 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591043 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1044 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1045 pixel_bounds.set_width(canvas->getDevice()->width());
1046 pixel_bounds.set_height(canvas->getDevice()->height());
1047 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1048 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051049
[email protected]f98d7e3c2010-09-13 22:30:461050 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1051
[email protected]aa4117f2011-12-09 22:19:211052 pending_update_params_->bitmap = current_paint_buf_->id();
1053 pending_update_params_->bitmap_rect = bounds;
1054
1055 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461056 // The scroll damage is just another rectangle to paint and copy.
1057 copy_rects.swap(update.paint_rects);
1058 if (!scroll_damage.IsEmpty())
1059 copy_rects.push_back(scroll_damage);
1060
1061 for (size_t i = 0; i < copy_rects.size(); ++i)
[email protected]f1cccb32012-06-06 18:29:591062 PaintRect(copy_rects[i], pixel_bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:351063
1064 // Software FPS tick for performance tests. The accelerated path traces the
1065 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1066 // NOTE: Tests may break if this event is renamed or moved.
1067 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:461068 } else { // Accelerated compositing path
1069 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211070 // If painting is done via the gpu process then we don't set any damage
1071 // rects to save the browser process from doing unecessary work.
1072 pending_update_params_->bitmap_rect = bounds;
1073 pending_update_params_->scroll_rect = gfx::Rect();
1074 // We don't need an ack, because we're not sharing a DIB with the browser.
1075 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1076 // with the browser for the GPU surface.
1077 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:421078 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:461079 }
1080
[email protected]936c6f52011-12-13 01:35:261081 // If we're holding a pending input event ACK, send the ACK before sending the
1082 // UpdateReply message so we can receive another input event before the
1083 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1084 // the UpdateRect IPC message handler.
1085 if (pending_input_event_ack_.get())
1086 Send(pending_input_event_ack_.release());
1087
[email protected]aa4117f2011-12-09 22:19:211088 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
1089 // OnSwapBuffersPosted), meaning a message has been added to the
1090 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1091 // the message now.
1092 if (pending_update_params_.get()) {
1093 // sending an ack to browser process that the paint is complete...
1094 update_reply_pending_ = pending_update_params_->needs_ack;
1095 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1096 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341097 }
[email protected]53d3f302009-12-21 04:42:051098
[email protected]29ed96a2012-02-04 18:12:161099 // If we're software rendering then we're done initiating the paint.
1100 if (!is_accelerated_compositing_active_)
1101 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291102}
1103
1104///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461105// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291106
[email protected]4873c7d2009-07-16 06:36:281107void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091108 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1109 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571110 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481111 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181112 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571113 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291114 return;
1115
[email protected]552e6002009-11-19 05:24:571116 paint_aggregator_.InvalidateRect(damaged_rect);
1117
1118 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241119 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571120 return;
1121 if (!paint_aggregator_.HasPendingUpdate())
1122 return;
[email protected]aa4117f2011-12-09 22:19:211123 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241124 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1125 return;
1126
1127 // When GPU rendering, combine pending animations and invalidations into
1128 // a single update.
[email protected]816edc62012-03-17 01:27:221129 if (is_accelerated_compositing_active_ &&
1130 animation_update_pending_ &&
1131 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571132 return;
1133
1134 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291135 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1136 // on the call stack.
1137 // 2) Allows us to collect more damage rects before painting to help coalesce
1138 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241139 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211140 MessageLoop::current()->PostTask(
1141 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291142}
1143
[email protected]990278ff2012-11-13 02:12:551144void RenderWidget::didScrollRect(int dx, int dy,
1145 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461146 // Drop scrolls on the floor when we are in compositing mode.
1147 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561148 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461149 return;
1150
[email protected]552e6002009-11-19 05:24:571151 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481152 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181153 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571154 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291155 return;
1156
[email protected]990278ff2012-11-13 02:12:551157 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571158
1159 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241160 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571161 return;
1162 if (!paint_aggregator_.HasPendingUpdate())
1163 return;
[email protected]aa4117f2011-12-09 22:19:211164 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241165 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1166 return;
1167
1168 // When GPU rendering, combine pending animations and invalidations into
1169 // a single update.
[email protected]816edc62012-03-17 01:27:221170 if (is_accelerated_compositing_active_ &&
1171 animation_update_pending_ &&
1172 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571173 return;
1174
1175 // Perform updating asynchronously. This serves two purposes:
1176 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1177 // on the call stack.
1178 // 2) Allows us to collect more damage rects before painting to help coalesce
1179 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241180 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211181 MessageLoop::current()->PostTask(
1182 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291183}
1184
[email protected]244ac1892011-12-02 17:04:471185void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091186 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1187 size_ = new_size;
1188 need_update_rect_for_auto_resize_ = true;
[email protected]240b5c32012-11-09 19:17:181189 // If we don't clear PaintAggregator after changing autoResize state, then
1190 // we might end up in a situation where bitmap_rect is larger than the
1191 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1192 // with invalid damage rects.
1193 paint_aggregator_.ClearPendingUpdate();
[email protected]ea3ee0a2012-05-15 03:43:091194 }
[email protected]244ac1892011-12-02 17:04:471195}
1196
[email protected]91acd1c2012-03-14 08:32:391197void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221198 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1199
[email protected]c63b4d42012-04-26 01:01:071200#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211201 if (!is_accelerated_compositing_active_) {
1202 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1203 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1204 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1205 // going to switch to accelerated compositing, the GPU process may need
1206 // round-trips to the browser's UI thread before finishing the frame,
1207 // causing deadlocks if we delay the UpdateRect until we receive the
1208 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071209 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1210 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211211 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1212 }
[email protected]c63b4d42012-04-26 01:01:071213#endif
[email protected]aa4117f2011-12-09 22:19:211214
[email protected]ea162f92011-10-04 23:08:221215 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421216 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241217 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221218}
1219
1220void RenderWidget::didDeactivateCompositor() {
1221 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1222
1223 is_accelerated_compositing_active_ = false;
1224 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1225 routing_id_, is_accelerated_compositing_active_));
1226
[email protected]ea162f92011-10-04 23:08:221227 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241228 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091229
1230 // In single-threaded mode, we exit force compositing mode and re-enter in
1231 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1232 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1233 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361234 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091235 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561236}
1237
[email protected]9cd43a62012-03-26 08:03:561238void RenderWidget::willBeginCompositorFrame() {
1239 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371240
1241 DCHECK(RenderThreadImpl::current()->compositor_thread());
1242
1243 // The following two can result in further layout and possibly
1244 // enable GPU acceleration so they need to be called before any painting
1245 // is done.
[email protected]3306f262012-09-21 19:20:421246 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371247 UpdateSelectionBounds();
1248
[email protected]9cd43a62012-03-26 08:03:561249 WillInitiatePaint();
1250}
1251
[email protected]3391a0772012-03-28 00:32:071252void RenderWidget::didBecomeReadyForAdditionalInput() {
1253 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1254 if (pending_input_event_ack_.get())
1255 Send(pending_input_event_ack_.release());
1256}
1257
[email protected]58264a32011-11-17 23:36:151258void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501259 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351260 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1261 // NOTE: Tests may break if this event is renamed or moved.
1262 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161263 // Notify subclasses that we initiated the paint operation.
1264 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151265}
1266
1267void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181268 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1269
1270 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561271 DidFlushPaint();
1272
[email protected]aa4117f2011-12-09 22:19:211273 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151274 return;
1275
[email protected]ea3ee0a2012-05-15 03:43:091276 if (!next_paint_flags_ &&
1277 !need_update_rect_for_auto_resize_ &&
1278 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151279 return;
[email protected]ea3ee0a2012-05-15 03:43:091280 }
[email protected]58264a32011-11-17 23:36:151281
1282 ViewHostMsg_UpdateRect_Params params;
1283 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151284 params.plugin_window_moves.swap(plugin_window_moves_);
1285 params.flags = next_paint_flags_;
1286 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121287 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091288 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151289
1290 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1291 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091292 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151293}
1294
[email protected]f98d7e3c2010-09-13 22:30:461295void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091296 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]d0be63772011-12-20 23:18:041297 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401298 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041299 } else {
[email protected]c3d45532011-10-07 19:20:401300 // TODO(nduca): replace with something a little less hacky. The reason this
1301 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1302 // contains a lot of host-renderer synchronization logic that is still
1303 // important for the accelerated compositing case. The option of simply
1304 // duplicating all that code is less desirable than "faking out" the
1305 // invalidation path using a magical damage rect.
1306 didInvalidateRect(WebRect(0, 0, 1, 1));
1307 }
[email protected]f98d7e3c2010-09-13 22:30:461308}
1309
[email protected]5f8b1022011-01-21 23:34:501310void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201311 if (animation_update_pending_)
1312 return;
1313
[email protected]921244e42011-07-20 16:36:301314 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201315 animation_update_pending_ = true;
1316 if (!animation_timer_.IsRunning()) {
1317 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1318 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211319 }
[email protected]5f8b1022011-01-21 23:34:501320}
1321
[email protected]4873c7d2009-07-16 06:36:281322void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301323 // TODO(darin): Eliminate this temporary.
1324 WebCursor cursor(cursor_info);
1325
initial.commit09911bf2008-07-26 23:55:291326 // Only send a SetCursor message if we need to make a change.
1327 if (!current_cursor_.IsEqual(cursor)) {
1328 current_cursor_ = cursor;
1329 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1330 }
1331}
1332
1333// We are supposed to get a single call to Show for a newly created RenderWidget
1334// that was created via RenderWidget::CreateWebView. So, we wait until this
1335// point to dispatch the ShowWidget message.
1336//
1337// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281338// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291339//
[email protected]4873c7d2009-07-16 06:36:281340void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291341 DCHECK(!did_show_) << "received extraneous Show call";
1342 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1343 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1344
[email protected]8de12d942010-11-17 20:42:441345 if (did_show_)
1346 return;
1347
1348 did_show_ = true;
1349 // NOTE: initial_pos_ may still have its default values at this point, but
1350 // that's okay. It'll be ignored if as_popup is false, or the browser
1351 // process will impose a default position otherwise.
1352 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1353 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291354}
1355
[email protected]4873c7d2009-07-16 06:36:281356void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291357}
1358
[email protected]4873c7d2009-07-16 06:36:281359void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291360}
1361
[email protected]2533ce12009-05-09 00:02:241362void RenderWidget::DoDeferredClose() {
1363 Send(new ViewHostMsg_Close(routing_id_));
1364}
1365
[email protected]4873c7d2009-07-16 06:36:281366void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321367 if (is_swapped_out_) {
1368 // This widget is currently swapped out, and the active widget is in a
1369 // different process. Have the browser route the close request to the
1370 // active widget instead, so that the correct unload handlers are run.
1371 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1372 return;
1373 }
1374
initial.commit09911bf2008-07-26 23:55:291375 // If a page calls window.close() twice, we'll end up here twice, but that's
1376 // OK. It is safe to send multiple Close messages.
1377
[email protected]2533ce12009-05-09 00:02:241378 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1379 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1380 // could be closed before the JS finishes executing. So instead, post a
1381 // message back to the message loop, which won't run until the JS is
1382 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211383 MessageLoop::current()->PostTask(
1384 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291385}
1386
1387void RenderWidget::Close() {
1388 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281389 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291390 webwidget_ = NULL;
1391 }
1392}
1393
[email protected]4873c7d2009-07-16 06:36:281394WebRect RenderWidget::windowRect() {
1395 if (pending_window_rect_count_)
1396 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241397
[email protected]80ad8622012-11-07 16:33:031398 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291399}
1400
[email protected]8a9d6ca32011-06-06 20:11:301401void RenderWidget::setToolTipText(const WebKit::WebString& text,
1402 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541403 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301404}
1405
[email protected]4873c7d2009-07-16 06:36:281406void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291407 if (did_show_) {
1408 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241409 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291410 } else {
1411 initial_pos_ = pos;
1412 }
1413}
1414
[email protected]2533ce12009-05-09 00:02:241415void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1416 pending_window_rect_ = rect;
1417 pending_window_rect_count_++;
1418}
1419
[email protected]4873c7d2009-07-16 06:36:281420WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241421 if (pending_window_rect_count_) {
1422 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1423 // the RootWindowRect is probably going to return wrong results since the
1424 // browser may not have processed the Move yet. There isn't really anything
1425 // good to do in this case, and it shouldn't happen - since this size is
1426 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281427 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241428 }
1429
[email protected]80ad8622012-11-07 16:33:031430 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371431}
1432
[email protected]4873c7d2009-07-16 06:36:281433WebRect RenderWidget::windowResizerRect() {
1434 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191435}
1436
[email protected]fa7b1dc2010-06-23 17:53:041437void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031438 // To prevent this renderer process from sending unnecessary IPC messages to
1439 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041440 // only during the input method attached to the browser process is active.
1441 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291442}
1443
[email protected]58b48a0d2012-06-13 07:01:351444void RenderWidget::UpdateCompositionInfo(
1445 const ui::Range& range,
1446 const std::vector<gfx::Rect>& character_bounds) {
1447 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1448 return;
1449 composition_character_bounds_ = character_bounds;
1450 composition_range_ = range;
1451 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1452 routing_id(), composition_range_, composition_character_bounds_));
1453}
1454
[email protected]fa7b1dc2010-06-23 17:53:041455void RenderWidget::OnImeSetComposition(
1456 const string16& text,
1457 const std::vector<WebCompositionUnderline>& underlines,
1458 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281459 if (!webwidget_)
1460 return;
[email protected]d4cff272011-05-02 15:46:011461 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041462 text, WebVector<WebCompositionUnderline>(underlines),
1463 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011464 // Setting the IME composition was successful. Send the new composition
1465 // range to the browser.
1466 ui::Range range(ui::Range::InvalidRange());
1467 size_t location, length;
1468 if (webwidget_->compositionRange(&location, &length)) {
1469 range.set_start(location);
1470 range.set_end(location + length);
1471 }
1472 // The IME was cancelled via the Esc key, so just send back the caret.
1473 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1474 range.set_start(location);
1475 range.set_end(location + length);
1476 }
[email protected]58b48a0d2012-06-13 07:01:351477 std::vector<gfx::Rect> character_bounds;
1478 GetCompositionCharacterBounds(&character_bounds);
1479 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011480 } else {
[email protected]fa7b1dc2010-06-23 17:53:041481 // If we failed to set the composition text, then we need to let the browser
1482 // process to cancel the input method's ongoing composition session, to make
1483 // sure we are in a consistent state.
1484 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011485
1486 // Send an updated IME range with just the caret range.
1487 ui::Range range(ui::Range::InvalidRange());
1488 size_t location, length;
1489 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1490 range.set_start(location);
1491 range.set_end(location + length);
1492 }
[email protected]58b48a0d2012-06-13 07:01:351493 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261494 }
[email protected]fa7b1dc2010-06-23 17:53:041495}
1496
[email protected]4de6d1692011-10-12 08:45:441497void RenderWidget::OnImeConfirmComposition(
1498 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041499 if (!webwidget_)
1500 return;
1501
1502 handling_input_event_ = true;
1503 webwidget_->confirmComposition(text);
1504 handling_input_event_ = false;
1505
[email protected]d4cff272011-05-02 15:46:011506 // Send an updated IME range with just the caret range.
1507 ui::Range range(ui::Range::InvalidRange());
1508 size_t location, length;
1509 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1510 range.set_start(location);
1511 range.set_end(location + length);
1512 }
[email protected]58b48a0d2012-06-13 07:01:351513 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291514}
1515
[email protected]948f7ab72010-05-28 23:48:081516// This message causes the renderer to render an image of the
1517// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491518void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091519 int tag,
[email protected]948f7ab72010-05-28 23:48:081520 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491521 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001522 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1523 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251524 // Close our unused handle.
1525#if defined(OS_WIN)
1526 ::CloseHandle(dib_handle);
1527#elif defined(OS_MACOSX)
1528 base::SharedMemory::CloseHandle(dib_handle);
1529#endif
1530 }
[email protected]d65adb12010-04-28 17:26:491531 return;
[email protected]45c6aad32010-11-11 04:46:251532 }
[email protected]d65adb12010-04-28 17:26:491533
[email protected]948f7ab72010-05-28 23:48:081534 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491535 // If one of these is empty, then we just return the dib we were
1536 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091537 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491538 return;
1539 }
1540
1541 // Map the given DIB ID into this process, and unmap it at the end
1542 // of this function.
[email protected]45c6aad32010-11-11 04:46:251543 scoped_ptr<TransportDIB> paint_at_size_buffer(
1544 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301545
[email protected]4b01b962012-10-09 23:17:351546 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281547 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351548 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281549 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511550 gfx::Size canvas_size = page_size_in_pixel;
1551 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491552 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511553 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491554 static_cast<float>(canvas_size.height());
1555
[email protected]ee8d6fd2010-05-26 17:05:481556 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491557 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1558 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481559 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491560
[email protected]36808ad2010-10-20 19:18:301561 scoped_ptr<skia::PlatformCanvas> canvas(
1562 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1563 canvas_size.height()));
1564 if (!canvas.get()) {
1565 NOTREACHED();
1566 return;
1567 }
1568
[email protected]d65adb12010-04-28 17:26:491569 // Reset bounds to what we actually received, but they should be the
1570 // same.
1571 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1572 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1573 bounds.set_width(canvas->getDevice()->width());
1574 bounds.set_height(canvas->getDevice()->height());
1575
1576 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081577 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491578 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1579
[email protected]948f7ab72010-05-28 23:48:081580 // Have to make sure we're laid out at the right size before
1581 // rendering.
1582 gfx::Size old_size = webwidget_->size();
1583 webwidget_->resize(page_size);
1584 webwidget_->layout();
1585
[email protected]d65adb12010-04-28 17:26:491586 // Paint the entire thing (using original bounds, not scaled bounds).
1587 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1588 canvas->restore();
1589
[email protected]948f7ab72010-05-28 23:48:081590 // Return the widget to its previous size.
1591 webwidget_->resize(old_size);
1592
[email protected]c88c9442010-07-19 18:55:091593 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491594}
1595
[email protected]ec7dc112008-08-06 05:30:121596void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1597 // During shutdown we can just ignore this message.
1598 if (!webwidget_)
1599 return;
1600
1601 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561602 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041603 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461604 scheduleComposite();
1605 } else {
1606 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1607 didInvalidateRect(repaint_rect);
1608 }
[email protected]ec7dc112008-08-06 05:30:121609}
1610
[email protected]fea38fc2012-06-13 17:38:371611void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]dea5e7682012-06-14 05:21:241612 if (device_scale_factor_ == device_scale_factor)
1613 return;
1614
1615 device_scale_factor_ = device_scale_factor;
1616
1617 if (!is_accelerated_compositing_active_) {
1618 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1619 } else {
1620 scheduleComposite();
1621 }
[email protected]fea38fc2012-06-13 17:38:371622}
1623
[email protected]0e241b4b2012-08-18 09:06:271624void RenderWidget::OnMsgSmoothScrollCompleted(int gesture_id) {
1625 PendingSmoothScrollGestureMap::iterator it =
1626 pending_smooth_scroll_gestures_.find(gesture_id);
1627 DCHECK(it != pending_smooth_scroll_gestures_.end());
1628 it->second.Run();
1629 pending_smooth_scroll_gestures_.erase(it);
1630}
1631
[email protected]4873c7d2009-07-16 06:36:281632void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111633 if (!webwidget_)
1634 return;
[email protected]4873c7d2009-07-16 06:36:281635 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111636}
1637
[email protected]6131a642012-06-15 23:26:531638void RenderWidget::OnScreenInfoChanged(
1639 const WebKit::WebScreenInfo& screen_info) {
1640 screen_info_ = screen_info;
1641}
1642
[email protected]80ad8622012-11-07 16:33:031643void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1644 const gfx::Rect& window_screen_rect) {
1645 view_screen_rect_ = view_screen_rect;
1646 window_screen_rect_ = window_screen_rect;
1647 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1648}
1649
[email protected]719b36f2010-12-22 20:36:461650webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151651 const gfx::Rect& paint_bounds,
1652 TransportDIB** dib,
1653 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201654 gfx::Rect* clip,
1655 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461656 // Bare RenderWidgets don't support optimized plugin painting.
1657 return NULL;
[email protected]ca4847f2010-09-24 05:39:151658}
1659
[email protected]ceb36f7d2012-10-31 18:33:241660gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521661 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241662 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521663}
1664
[email protected]bee16aab2009-08-26 15:55:031665void RenderWidget::SetHidden(bool hidden) {
1666 if (is_hidden_ == hidden)
1667 return;
1668
1669 // The status has changed. Tell the RenderThread about it.
1670 is_hidden_ = hidden;
1671 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271672 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031673 else
[email protected]380244092011-10-07 17:26:271674 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031675}
1676
[email protected]2b624c562011-10-27 22:58:261677void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261678 if (!webwidget_)
1679 return;
1680
1681 if (is_fullscreen_) {
1682 webwidget_->willExitFullScreen();
1683 } else {
1684 webwidget_->willEnterFullScreen();
1685 }
[email protected]2b624c562011-10-27 22:58:261686}
1687
1688void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261689 if (!webwidget_)
1690 return;
1691
1692 if (is_fullscreen_) {
1693 webwidget_->didEnterFullScreen();
1694 } else {
1695 webwidget_->didExitFullScreen();
1696 }
[email protected]2b624c562011-10-27 22:58:261697}
1698
[email protected]699ab0d2009-04-23 23:19:141699void RenderWidget::SetBackground(const SkBitmap& background) {
1700 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461701
[email protected]699ab0d2009-04-23 23:19:141702 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281703 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141704}
1705
[email protected]674741932009-02-04 23:44:461706bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051707 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461708}
1709
1710bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051711 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461712}
1713
1714void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051715 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461716}
1717
1718void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051719 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461720}
1721
1722void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051723 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461724}
1725
[email protected]3306f262012-09-21 19:20:421726void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
1727 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1728 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291729 return;
[email protected]ad26ef42011-06-17 07:59:451730 ui::TextInputType new_type = GetTextInputType();
[email protected]5b739cb2012-08-21 20:35:211731 WebKit::WebTextInputInfo new_info;
1732 if (webwidget_)
1733 new_info = webwidget_->textInputInfo();
1734
[email protected]ad26ef42011-06-17 07:59:451735 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211736
[email protected]3306f262012-09-21 19:20:421737 // Only sends text input params if they are changed or if the ime should be
1738 // shown.
1739 if (show_ime_if_needed || (text_input_type_ != new_type
1740 || text_input_info_ != new_info
1741 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:211742 ViewHostMsg_TextInputState_Params p;
1743 p.type = new_type;
1744 p.value = new_info.value.utf8();
1745 p.selection_start = new_info.selectionStart;
1746 p.selection_end = new_info.selectionEnd;
1747 p.composition_start = new_info.compositionStart;
1748 p.composition_end = new_info.compositionEnd;
1749 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:421750 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:211751 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1752
1753 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041754 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451755 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:291756 }
initial.commit09911bf2008-07-26 23:55:291757}
1758
[email protected]3f783362011-10-21 22:40:501759void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1760 WebRect start_webrect;
1761 WebRect end_webrect;
1762 webwidget_->selectionBounds(start_webrect, end_webrect);
1763 *start = start_webrect;
1764 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321765}
1766
[email protected]e99ef6f2011-10-16 01:13:001767void RenderWidget::UpdateSelectionBounds() {
1768 if (!webwidget_)
1769 return;
1770
[email protected]3f783362011-10-21 22:40:501771 gfx::Rect start_rect;
1772 gfx::Rect end_rect;
1773 GetSelectionBounds(&start_rect, &end_rect);
[email protected]58b48a0d2012-06-13 07:01:351774 if (selection_start_rect_ != start_rect || selection_end_rect_ != end_rect) {
1775 selection_start_rect_ = start_rect;
1776 selection_end_rect_ = end_rect;
[email protected]b556c2e2012-08-10 22:18:271777 WebTextDirection start_dir = WebKit::WebTextDirectionLeftToRight;
1778 WebTextDirection end_dir = WebKit::WebTextDirectionLeftToRight;
1779 webwidget_->selectionTextDirection(start_dir, end_dir);
1780 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_,
1781 selection_start_rect_, start_dir, selection_end_rect_, end_dir));
[email protected]58b48a0d2012-06-13 07:01:351782 }
[email protected]e99ef6f2011-10-16 01:13:001783
[email protected]58b48a0d2012-06-13 07:01:351784 std::vector<gfx::Rect> character_bounds;
1785 GetCompositionCharacterBounds(&character_bounds);
1786 UpdateCompositionInfo(composition_range_, character_bounds);
1787}
1788
1789bool RenderWidget::ShouldUpdateCompositionInfo(
1790 const ui::Range& range,
1791 const std::vector<gfx::Rect>& bounds) {
1792 if (composition_range_ != range)
1793 return true;
1794 if (bounds.size() != composition_character_bounds_.size())
1795 return true;
1796 for (size_t i = 0; i < bounds.size(); ++i) {
1797 if (bounds[i] != composition_character_bounds_[i])
1798 return true;
1799 }
1800 return false;
[email protected]e99ef6f2011-10-16 01:13:001801}
1802
[email protected]73bf95812011-10-12 11:38:321803// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451804COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1805 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1806COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1807 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1808COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1809 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181810COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1811 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1812COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1813 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1814COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1815 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1816COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1817 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1818COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1819 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:001820COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
1821 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
1822COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
1823 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
1824COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
1825 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
1826COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
1827 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
1828COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
1829 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
1830COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
1831 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:011832COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
1833 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
1834COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
1835 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451836
[email protected]5b739cb2012-08-21 20:35:211837ui::TextInputType RenderWidget::WebKitToUiTextInputType(
1838 WebKit::WebTextInputType type) {
1839 // Check the type is in the range representable by ui::TextInputType.
1840 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
1841 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1842 return static_cast<ui::TextInputType>(type);
1843}
1844
[email protected]ad26ef42011-06-17 07:59:451845ui::TextInputType RenderWidget::GetTextInputType() {
1846 if (webwidget_) {
[email protected]5b739cb2012-08-21 20:35:211847 WebKit::WebTextInputType type = webwidget_->textInputType();
1848 return WebKitToUiTextInputType(type);
[email protected]ad26ef42011-06-17 07:59:451849 }
1850 return ui::TEXT_INPUT_TYPE_NONE;
1851}
1852
[email protected]58b48a0d2012-06-13 07:01:351853void RenderWidget::GetCompositionCharacterBounds(
1854 std::vector<gfx::Rect>* bounds) {
1855 DCHECK(bounds);
1856 bounds->clear();
1857}
1858
[email protected]ad26ef42011-06-17 07:59:451859bool RenderWidget::CanComposeInline() {
1860 return true;
[email protected]56ea1a62011-05-30 07:05:571861}
1862
[email protected]4873c7d2009-07-16 06:36:281863WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041864 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281865}
1866
[email protected]f660d9c2012-06-06 18:31:211867float RenderWidget::deviceScaleFactor() {
1868 return device_scale_factor_;
1869}
1870
[email protected]fa7b1dc2010-06-23 17:53:041871void RenderWidget::resetInputMethod() {
1872 if (!input_method_is_active_)
1873 return;
1874
1875 // If the last text input type is not None, then we should finish any
1876 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451877 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041878 // If a composition text exists, then we need to let the browser process
1879 // to cancel the input method's ongoing composition session.
1880 if (webwidget_->confirmComposition())
1881 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1882 }
[email protected]d4cff272011-05-02 15:46:011883
1884 // Send an updated IME range with the current caret rect.
1885 ui::Range range(ui::Range::InvalidRange());
1886 size_t location, length;
1887 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1888 range.set_start(location);
1889 range.set_end(location + length);
1890 }
[email protected]58b48a0d2012-06-13 07:01:351891
1892 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:041893}
1894
[email protected]f103ab72009-09-02 17:10:591895void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501896 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291897 size_t i = 0;
1898 for (; i < plugin_window_moves_.size(); ++i) {
1899 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581900 if (move.rects_valid) {
1901 plugin_window_moves_[i] = move;
1902 } else {
1903 plugin_window_moves_[i].visible = move.visible;
1904 }
initial.commit09911bf2008-07-26 23:55:291905 break;
1906 }
1907 }
1908
1909 if (i == plugin_window_moves_.size())
1910 plugin_window_moves_.push_back(move);
1911}
[email protected]268654772009-08-06 23:02:041912
1913void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1914 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1915 i != plugin_window_moves_.end(); ++i) {
1916 if (i->window == window) {
1917 plugin_window_moves_.erase(i);
1918 break;
1919 }
1920 }
1921}
[email protected]67bfb83f2011-09-22 03:36:371922
[email protected]fef5e3972012-08-07 03:59:471923void RenderWidget::GetRenderingStats(WebKit::WebRenderingStats& stats) const {
1924 webwidget()->renderingStats(stats);
1925 stats.numAnimationFrames += software_stats_.numAnimationFrames;
1926 stats.numFramesSentToScreen += software_stats_.numFramesSentToScreen;
1927 stats.totalPaintTimeInSeconds += software_stats_.totalPaintTimeInSeconds;
[email protected]63ab54262012-11-09 15:58:451928 stats.totalPixelsPainted += software_stats_.totalPixelsPainted;
1929 stats.totalRasterizeTimeInSeconds +=
1930 software_stats_.totalRasterizeTimeInSeconds;
1931 stats.totalPixelsRasterized += software_stats_.totalPixelsRasterized;
[email protected]fef5e3972012-08-07 03:59:471932}
1933
[email protected]e9ff79c2012-10-19 21:31:261934bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:521935 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
1936 if (!gpu_channel)
1937 return false;
1938
1939 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
1940}
1941
[email protected]0e241b4b2012-08-18 09:06:271942void RenderWidget::BeginSmoothScroll(
1943 bool down,
[email protected]ebd8b562012-10-09 14:44:291944 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:191945 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:291946 int mouse_event_x,
1947 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:271948 DCHECK(!callback.is_null());
1949 int id = next_smooth_scroll_gesture_id_++;
[email protected]267909d2012-10-20 04:36:191950
1951 ViewHostMsg_BeginSmoothScroll_Params params;
1952 params.scroll_down = down;
1953 params.pixels_to_scroll = pixels_to_scroll;
1954 params.mouse_event_x = mouse_event_x;
1955 params.mouse_event_y = mouse_event_y;
1956
1957 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, params));
[email protected]0e241b4b2012-08-18 09:06:271958 pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback));
[email protected]a39ca1652012-07-13 21:30:581959}
1960
[email protected]67bfb83f2011-09-22 03:36:371961bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1962 return false;
1963}
[email protected]c3d45532011-10-07 19:20:401964
[email protected]41d86852012-11-07 12:23:241965bool RenderWidget::WillHandleGestureEvent(
1966 const WebKit::WebGestureEvent& event) {
1967 return false;
1968}
1969
[email protected]c3d45532011-10-07 19:20:401970bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1971 return false;
1972}
[email protected]e9ff79c2012-10-19 21:31:261973
1974} // namespace content