blob: 65841501bc00b3e394cdf724cacec63ed881d19f [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]3da12cb2011-10-08 02:25:0420#include "content/renderer/gpu/compositor_thread.h"
[email protected]8704f89b2011-04-15 00:30:0521#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4422#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1923#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1824#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5226#include "third_party/skia/include/core/SkShader.h"
[email protected]8bd0fe62011-01-17 06:44:3727#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]e6e90dc2011-12-03 00:01:3728#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
[email protected]8bd0fe62011-01-17 06:44:3729#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
30#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0131#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]e6e90dc2011-12-03 00:01:3732#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]8bd0fe62011-01-17 06:44:3733#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.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]08397d52011-02-05 01:53:3836#include "ui/gfx/point.h"
37#include "ui/gfx/size.h"
[email protected]b9b751f22011-03-25 14:04:1238#include "ui/gfx/surface/transport_dib.h"
[email protected]bd37ae252011-06-03 01:28:1839#include "ui/gfx/gl/gl_switches.h"
[email protected]8c89e7792009-08-19 21:18:3440#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5041#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4642#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4843
44#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4945#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5246#include "third_party/skia/include/core/SkPixelRef.h"
47#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4848#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4449
[email protected]8bd0fe62011-01-17 06:44:3750#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2951
[email protected]fa7b1dc2010-06-23 17:53:0452using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3053using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2254using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0655using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2856using WebKit::WebNavigationPolicy;
[email protected]e99ef6f2011-10-16 01:13:0057using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2858using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5959using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1860using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0161using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5262using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1963using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5264using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2865using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2466using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0467using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1868using WebKit::WebWidget;
[email protected]380244092011-10-07 17:26:2769using content::RenderThread;
[email protected]62cb33cae2009-03-27 23:30:2270
[email protected]380244092011-10-07 17:26:2771RenderWidget::RenderWidget(WebKit::WebPopupType popup_type)
initial.commit09911bf2008-07-26 23:55:2972 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:5673 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:1174 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2975 opener_id_(MSG_ROUTING_NONE),
[email protected]659f73f2009-10-13 13:43:4276 host_window_(0),
[email protected]05a980d7a2012-02-07 22:16:4277 host_window_set_(false),
[email protected]b4d08452010-10-05 17:34:3578 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2979 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:0680 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:0581 update_reply_pending_(false),
[email protected]65225772011-05-12 21:10:2482 using_asynchronous_swapbuffers_(false),
83 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2984 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2985 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:0986 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:2987 needs_repainting_on_restore_(false),
88 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4989 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4890 closing_(false),
[email protected]992db4c2011-05-12 15:37:1591 is_swapped_out_(false),
[email protected]fa7b1dc2010-06-23 17:53:0492 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:4593 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
94 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:1295 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:4896 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:1297 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:5098 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:2199 animation_update_pending_(false),
[email protected]65225772011-05-12 21:10:24100 animation_task_posted_(false),
101 invalidation_task_posted_(false) {
[email protected]8930d472009-02-21 08:05:28102 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27103 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18104 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
105 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:29106}
107
108RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11109 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21110 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35111 if (current_paint_buf_) {
112 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
113 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29114 }
[email protected]992db4c2011-05-12 15:37:15115 // If we are swapped out, we have released already.
116 if (!is_swapped_out_)
117 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29118}
119
[email protected]484955942010-08-19 16:13:18120// static
[email protected]8085dbc82008-09-26 22:53:44121RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]3e2b375b2010-04-07 17:03:12122 WebKit::WebPopupType popup_type) {
initial.commit09911bf2008-07-26 23:55:29123 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]380244092011-10-07 17:26:27124 scoped_refptr<RenderWidget> widget(new RenderWidget(popup_type));
initial.commit09911bf2008-07-26 23:55:29125 widget->Init(opener_id); // adds reference
126 return widget;
127}
128
[email protected]484955942010-08-19 16:13:18129// static
130WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
131 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03132 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18133 break;
134 case WebKit::WebPopupTypeSelect:
135 case WebKit::WebPopupTypeSuggestion:
136 return WebPopupMenu::create(render_widget);
137 default:
138 NOTREACHED();
139 }
140 return NULL;
141}
142
initial.commit09911bf2008-07-26 23:55:29143void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18144 DoInit(opener_id,
145 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56146 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
147 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18148}
149
[email protected]484955942010-08-19 16:13:18150void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06151 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18152 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29153 DCHECK(!webwidget_);
154
155 if (opener_id != MSG_ROUTING_NONE)
156 opener_id_ = opener_id;
157
[email protected]484955942010-08-19 16:13:18158 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29159
[email protected]380244092011-10-07 17:26:27160 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29161 if (result) {
[email protected]380244092011-10-07 17:26:27162 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29163 // Take a reference on behalf of the RenderThread. This will be balanced
164 // when we receive ViewMsg_Close.
165 AddRef();
166 } else {
167 DCHECK(false);
168 }
169}
170
171// This is used to complete pending inits and non-pending inits. For non-
172// pending cases, the parent will be the same as the current parent. This
173// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55174void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29175 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29176
177 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42178 host_window_set_ = true;
179
180 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29181
[email protected]6de74452009-02-25 18:04:59182 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29183}
184
[email protected]992db4c2011-05-12 15:37:15185void RenderWidget::SetSwappedOut(bool is_swapped_out) {
186 // We should only toggle between states.
187 DCHECK(is_swapped_out_ != is_swapped_out);
188 is_swapped_out_ = is_swapped_out;
189
190 // If we are swapping out, we will call ReleaseProcess, allowing the process
191 // to exit if all of its RenderViews are swapped out. We wait until the
192 // WasSwappedOut call to do this, to avoid showing the sad tab.
193 // If we are swapping in, we call AddRefProcess to prevent the process from
194 // exiting.
195 if (!is_swapped_out)
196 RenderProcess::current()->AddRefProcess();
197}
198
[email protected]a95986a82010-12-24 06:19:28199bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
200 bool handled = true;
201 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
202 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
203 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
204 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54205 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28206 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
207 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15208 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28209 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
210 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
211 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
212 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
213 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
214 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
215 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
216 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
217 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
218 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
219 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
220 IPC_MESSAGE_UNHANDLED(handled = false)
221 IPC_END_MESSAGE_MAP()
222 return handled;
223}
initial.commit09911bf2008-07-26 23:55:29224
225bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15226 // Don't send any messages after the browser has told us to close, and filter
227 // most outgoing messages while swapped out.
228 if ((is_swapped_out_ &&
229 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
230 closing_) {
initial.commit09911bf2008-07-26 23:55:29231 delete message;
232 return false;
233 }
234
235 // If given a messsage without a routing ID, then assign our routing ID.
236 if (message->routing_id() == MSG_ROUTING_NONE)
237 message->set_routing_id(routing_id_);
238
[email protected]380244092011-10-07 17:26:27239 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44240}
241
initial.commit09911bf2008-07-26 23:55:29242// Got a response from the browser after the renderer decided to create a new
243// view.
[email protected]c03a6e72011-04-19 21:42:06244void RenderWidget::OnCreatingNewAck(
[email protected]2d7c8552011-06-27 19:21:55245 gfx::NativeViewId parent) {
initial.commit09911bf2008-07-26 23:55:29246 DCHECK(routing_id_ != MSG_ROUTING_NONE);
247
[email protected]2d7c8552011-06-27 19:21:55248 CompleteInit(parent);
initial.commit09911bf2008-07-26 23:55:29249}
250
251void RenderWidget::OnClose() {
252 if (closing_)
253 return;
254 closing_ = true;
255
256 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03257 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27258 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03259 SetHidden(false);
260 }
initial.commit09911bf2008-07-26 23:55:29261
initial.commit09911bf2008-07-26 23:55:29262 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25263 // now. Post a task that only gets invoked when there are no nested message
264 // loops.
[email protected]32876ae2011-11-15 22:25:21265 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29266 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25267
268 // Balances the AddRef taken when we called AddRoute.
269 Release();
initial.commit09911bf2008-07-26 23:55:29270}
271
[email protected]f21c613a2009-02-12 14:46:17272void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09273 const gfx::Rect& resizer_rect,
274 bool is_fullscreen) {
initial.commit09911bf2008-07-26 23:55:29275 // During shutdown we can just ignore this message.
276 if (!webwidget_)
277 return;
278
[email protected]f21c613a2009-02-12 14:46:17279 // Remember the rect where the resize corner will be drawn.
280 resizer_rect_ = resizer_rect;
281
[email protected]2b624c562011-10-27 22:58:26282 // NOTE: We may have entered fullscreen mode without changing our size.
283 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
284 if (fullscreen_change)
285 WillToggleFullscreen();
[email protected]ee41e7d22011-10-14 19:34:09286 is_fullscreen_ = is_fullscreen;
initial.commit09911bf2008-07-26 23:55:29287
[email protected]2b624c562011-10-27 22:58:26288 if (size_ != new_size) {
289 // TODO(darin): We should not need to reset this here.
290 SetHidden(false);
291 needs_repainting_on_restore_ = false;
initial.commit09911bf2008-07-26 23:55:29292
[email protected]2b624c562011-10-27 22:58:26293 size_ = new_size;
[email protected]552e6002009-11-19 05:24:57294
[email protected]2b624c562011-10-27 22:58:26295 // We should not be sent a Resize message if we have not ACK'd the previous
296 DCHECK(!next_paint_is_resize_ack());
297
298 paint_aggregator_.ClearPendingUpdate();
299
300 // When resizing, we want to wait to paint before ACK'ing the resize. This
301 // ensures that we only resize as fast as we can paint. We only need to
302 // send an ACK if we are resized to a non-empty rect.
303 webwidget_->resize(new_size);
304 if (!new_size.IsEmpty()) {
305 if (!is_accelerated_compositing_active_) {
306 // Resize should have caused an invalidation of the entire view.
307 DCHECK(paint_aggregator_.HasPendingUpdate());
308 }
309
310 // We will send the Resize_ACK flag once we paint again.
311 set_next_paint_is_resize_ack();
[email protected]f98d7e3c2010-09-13 22:30:46312 }
initial.commit09911bf2008-07-26 23:55:29313 }
[email protected]2b624c562011-10-27 22:58:26314
315 if (fullscreen_change)
316 DidToggleFullscreen();
initial.commit09911bf2008-07-26 23:55:29317}
318
[email protected]b5913d72012-02-07 22:26:54319void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
320 if (resizer_rect_ != resizer_rect) {
321 paint_aggregator_.InvalidateRect(resizer_rect_);
322 paint_aggregator_.InvalidateRect(resizer_rect);
323 resizer_rect_ = resizer_rect;
324 if (webwidget_)
325 webwidget_->didChangeWindowResizerRect();
326 }
327}
328
initial.commit09911bf2008-07-26 23:55:29329void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31330 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29331 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03332 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29333}
334
335void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31336 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29337 // During shutdown we can just ignore this message.
338 if (!webwidget_)
339 return;
340
341 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03342 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29343
344 if (!needs_repainting && !needs_repainting_on_restore_)
345 return;
346 needs_repainting_on_restore_ = false;
347
[email protected]d65adb12010-04-28 17:26:49348 // Tag the next paint as a restore ack, which is picked up by
349 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29350 set_next_paint_is_restore_ack();
351
352 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56353 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46354 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
355 } else {
356 scheduleComposite();
357 }
initial.commit09911bf2008-07-26 23:55:29358}
359
[email protected]992db4c2011-05-12 15:37:15360void RenderWidget::OnWasSwappedOut() {
361 // If we have been swapped out and no one else is using this process,
362 // it's safe to exit now. If we get swapped back in, we will call
363 // AddRefProcess in SetSwappedOut.
364 if (is_swapped_out_)
365 RenderProcess::current()->ReleaseProcess();
366}
367
[email protected]53d3f302009-12-21 04:42:05368void RenderWidget::OnRequestMoveAck() {
369 DCHECK(pending_window_rect_count_);
370 pending_window_rect_count_--;
371}
372
373void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58374 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21375 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05376 update_reply_pending_ = false;
377
[email protected]b4d08452010-10-05 17:34:35378 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
379 // have no current paint buffer.
380 if (current_paint_buf_) {
381 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
382 current_paint_buf_ = NULL;
383 }
384
[email protected]65225772011-05-12 21:10:24385 // If swapbuffers is still pending, then defer the update until the
386 // swapbuffers occurs.
387 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
388 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
389 return;
390 }
391
[email protected]29ed96a2012-02-04 18:12:16392 // Notify subclasses that software rendering was flushed to the screen.
393 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25394
initial.commit09911bf2008-07-26 23:55:29395 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24396 DoDeferredUpdateAndSendInputAck();
397}
398
[email protected]d0be63772011-12-20 23:18:04399bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24400 return false;
401}
402
[email protected]d0be63772011-12-20 23:18:04403void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24404 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21405 while (!updates_pending_swap_.empty()) {
406 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
407 updates_pending_swap_.pop_front();
408 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
409 // compositing pass, hence doesn't require an UpdateRect message.
410 if (msg)
411 Send(msg);
412 }
[email protected]65225772011-05-12 21:10:24413 num_swapbuffers_complete_pending_ = 0;
414 using_asynchronous_swapbuffers_ = false;
415 // Schedule another frame so the compositor learns about it.
416 scheduleComposite();
417}
418
[email protected]37a6f302011-07-11 23:43:08419void RenderWidget::OnSwapBuffersPosted() {
420 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21421
422 if (using_asynchronous_swapbuffers_) {
423 ViewHostMsg_UpdateRect* msg = NULL;
424 // pending_update_params_ can be NULL if the swap doesn't correspond to an
425 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
426 // message.
427 if (pending_update_params_.get()) {
428 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
429 pending_update_params_.reset();
430 }
431 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08432 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21433 }
[email protected]37a6f302011-07-11 23:43:08434}
435
436void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24437 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16438
439 // Notify subclasses that composited rendering got flushed to the screen.
440 DidFlushPaint();
441
[email protected]65225772011-05-12 21:10:24442 // When compositing deactivates, we reset the swapbuffers pending count. The
443 // swapbuffers acks may still arrive, however.
444 if (num_swapbuffers_complete_pending_ == 0) {
445 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
446 return;
447 }
[email protected]aa4117f2011-12-09 22:19:21448 DCHECK(!updates_pending_swap_.empty());
449 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
450 updates_pending_swap_.pop_front();
451 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
452 // compositing pass, hence doesn't require an UpdateRect message.
453 if (msg)
454 Send(msg);
[email protected]65225772011-05-12 21:10:24455 num_swapbuffers_complete_pending_--;
456
457 // If update reply is still pending, then defer the update until that reply
458 // occurs.
[email protected]d0be63772011-12-20 23:18:04459 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24460 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
461 return;
462 }
463
464 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06465 // when we were previously rendering. However, if an invalidation task is not
466 // posted, there may be software rendering work pending. In that case, don't
467 // early out.
468 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24469 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
470 return;
471 }
472
[email protected]65225772011-05-12 21:10:24473 // Continue painting if necessary...
474 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29475}
476
initial.commit09911bf2008-07-26 23:55:29477void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24478 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
initial.commit09911bf2008-07-26 23:55:29479 void* iter = NULL;
480
481 const char* data;
482 int data_length;
[email protected]5dd768212009-08-13 23:34:49483 handling_input_event_ = true;
484 if (!message.ReadData(&iter, &data, &data_length)) {
485 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29486 return;
[email protected]5dd768212009-08-13 23:34:49487 }
initial.commit09911bf2008-07-26 23:55:29488
489 const WebInputEvent* input_event =
490 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48491
[email protected]b68a0e52011-12-08 15:11:12492 bool is_keyboard_shortcut = false;
493 // is_keyboard_shortcut flag is only available for RawKeyDown events.
494 if (input_event->type == WebInputEvent::RawKeyDown)
495 message.ReadBool(&iter, &is_keyboard_shortcut);
496
[email protected]67bfb83f2011-09-22 03:36:37497 bool prevent_default = false;
498 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26499 const WebMouseEvent& mouse_event =
500 *static_cast<const WebMouseEvent*>(input_event);
501 TRACE_EVENT2("renderer", "HandleMouseMove",
502 "x", mouse_event.x, "y", mouse_event.y);
503 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37504 }
505
506 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12507 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
508 suppress_next_char_events_ = false;
509 if (!processed && webwidget_)
510 processed = webwidget_->handleInputEvent(*input_event);
511 }
512
513 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
514 // it's not processed by webkit, then we need to suppress the upcoming Char
515 // events.
516 if (!processed && is_keyboard_shortcut)
517 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29518
[email protected]a9fb30aa2011-10-06 06:58:46519 IPC::Message* response =
520 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
521 processed);
[email protected]e2824412009-02-27 01:57:05522
[email protected]353a34c2010-05-28 23:35:17523 if ((input_event->type == WebInputEvent::MouseMove ||
[email protected]d93fc462011-03-14 23:03:03524 input_event->type == WebInputEvent::MouseWheel ||
[email protected]d329a912012-01-27 01:55:01525 WebInputEvent::isTouchEventType(input_event->type)) &&
[email protected]552e6002009-11-19 05:24:57526 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24527 // We want to rate limit the input events in this case, so we'll wait for
528 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17529 if (pending_input_event_ack_.get()) {
530 // As two different kinds of events could cause us to postpone an ack
531 // we send it now, if we have one pending. The Browser should never
532 // send us the same kind of event we are delaying the ack for.
533 Send(pending_input_event_ack_.release());
534 }
[email protected]12fbad812009-09-01 18:21:24535 pending_input_event_ack_.reset(response);
536 } else {
537 Send(response);
538 }
539
[email protected]5dd768212009-08-13 23:34:49540 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48541
[email protected]67bfb83f2011-09-22 03:36:37542 if (!prevent_default) {
543 if (WebInputEvent::isKeyboardEventType(input_event->type))
544 DidHandleKeyEvent();
545 if (WebInputEvent::isMouseEventType(input_event->type))
546 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24547 if (WebInputEvent::isTouchEventType(input_event->type))
548 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37549 }
initial.commit09911bf2008-07-26 23:55:29550}
551
552void RenderWidget::OnMouseCaptureLost() {
553 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28554 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29555}
556
557void RenderWidget::OnSetFocus(bool enable) {
558 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33559 if (webwidget_)
560 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29561}
562
563void RenderWidget::ClearFocus() {
564 // We may have got the focus from the browser before this gets processed, in
565 // which case we do not want to unfocus ourself.
566 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28567 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29568}
569
[email protected]2d5d09d52009-06-15 14:29:21570void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00571 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21572 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06573 TRACE_EVENT2("renderer", "PaintRect",
574 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00575 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21576
577 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00578 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
579 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03580
[email protected]699ab0d2009-04-23 23:19:14581 // If there is a custom background, tile it.
582 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14583 SkPaint paint;
584 SkShader* shader = SkShader::CreateBitmapShader(background_,
585 SkShader::kRepeat_TileMode,
586 SkShader::kRepeat_TileMode);
587 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20588
589 // Use kSrc_Mode to handle background_ transparency properly.
590 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
591
592 // Canvas could contain multiple update rects. Clip to given rect so that
593 // we don't accidentally clear other update rects.
594 canvas->save();
595 SkRect clip;
596 clip.set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y()),
597 SkIntToScalar(rect.right()), SkIntToScalar(rect.bottom()));
598 canvas->clipRect(clip);
[email protected]699ab0d2009-04-23 23:19:14599 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20600 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14601 }
602
[email protected]719b36f2010-12-22 20:36:46603 // First see if this rect is a plugin that can paint itself faster.
604 TransportDIB* optimized_dib = NULL;
605 gfx::Rect optimized_copy_rect, optimized_copy_location;
606 webkit::ppapi::PluginInstance* optimized_instance =
607 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
608 &optimized_copy_location,
609 &optimized_copy_rect);
610 if (optimized_instance) {
611 // This plugin can be optimize-painted and we can just ask it to paint
612 // itself. We don't actually need the TransportDIB in this case.
613 //
614 // This is an optimization for PPAPI plugins that know they're on top of
615 // the page content. If this rect is inside such a plugin, we can save some
616 // time and avoid re-rendering the page content which we know will be
617 // covered by the plugin later (this time can be significant, especially
618 // for a playing movie that is invalidating a lot).
619 //
620 // In the plugin movie case, hopefully the similar call to
621 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
622 // painting, because that avoids copying the plugin image to a different
623 // paint rect. Unfortunately, if anything on the page is animating other
624 // than the movie, it break this optimization since the union of the
625 // invalid regions will be larger than the plugin.
626 //
627 // This code optimizes that case, where we can still avoid painting in
628 // WebKit and filling the background (which can be slow) and just painting
629 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
630 // required.
631 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27632 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46633 } else {
634 // Normal painting case.
635 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
636
637 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35638 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46639 }
initial.commit09911bf2008-07-26 23:55:29640
[email protected]4fb66842009-12-04 21:41:00641 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00642 canvas->restore();
643}
644
645void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
646 skia::PlatformCanvas* canvas) {
647 static bool kPaintBorder =
648 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
649 if (!kPaintBorder)
650 return;
651
[email protected]53d3f302009-12-21 04:42:05652 // Cycle through these colors to help distinguish new paint rects.
653 const SkColor colors[] = {
654 SkColorSetARGB(0x3F, 0xFF, 0, 0),
655 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
656 SkColorSetARGB(0x3F, 0, 0, 0xFF),
657 };
658 static int color_selector = 0;
659
[email protected]4fb66842009-12-04 21:41:00660 SkPaint paint;
661 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05662 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00663 paint.setStrokeWidth(1);
664
665 SkIRect irect;
666 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
667 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29668}
669
[email protected]52ccd0ea2011-02-16 01:09:05670void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30671 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]52ccd0ea2011-02-16 01:09:05672 animation_task_posted_ = false;
[email protected]921244e42011-07-20 16:36:30673 if (!animation_update_pending_) {
674 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59675 return;
[email protected]921244e42011-07-20 16:36:30676 }
[email protected]bd37ae252011-06-03 01:28:18677 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59678 // Record when we fired (according to base::Time::Now()) relative to when
679 // we posted the task to quantify how much the base::Time/base::TimeTicks
680 // skew is affecting animations.
681 base::TimeDelta animation_callback_delay = base::Time::Now() -
682 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
683 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
684 animation_callback_delay,
685 base::TimeDelta::FromMilliseconds(0),
686 base::TimeDelta::FromMilliseconds(30),
687 25);
688 }
[email protected]65225772011-05-12 21:10:24689 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24690}
691
[email protected]52ccd0ea2011-02-16 01:09:05692void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59693 if (!animation_update_pending_)
694 return;
[email protected]bd37ae252011-06-03 01:28:18695
696 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33697 base::TimeDelta animationInterval = IsRenderingVSynced() ?
698 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18699
[email protected]7c4329e2011-02-18 22:02:59700 base::Time now = base::Time::Now();
[email protected]46d8c8292011-12-12 18:15:05701 if (now >= animation_floor_time_ || is_accelerated_compositing_active_) {
[email protected]921244e42011-07-20 16:36:30702 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33703 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18704 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59705 // running animation callbacks so that if a callback requests another
706 // we'll be sure to run it at the proper time.
[email protected]32876ae2011-11-15 22:25:21707 MessageLoop::current()->PostDelayedTask(
708 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this),
709 animationInterval);
[email protected]7c4329e2011-02-18 22:02:59710 animation_task_posted_ = true;
711 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30712 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59713 return;
[email protected]5f8b1022011-01-21 23:34:50714 }
[email protected]bd37ae252011-06-03 01:28:18715 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]7c4329e2011-02-18 22:02:59716 if (animation_task_posted_)
717 return;
718 // This code uses base::Time::Now() to calculate the floor and next fire
719 // time because javascript's Date object uses base::Time::Now(). The
720 // message loop uses base::TimeTicks, which on windows can have a
721 // different granularity than base::Time.
722 // The upshot of all this is that this function might be called before
723 // base::Time::Now() has advanced past the animation_floor_time_. To
724 // avoid exposing this delay to javascript, we keep posting delayed
725 // tasks until base::Time::Now() has advanced far enough.
[email protected]02798a982012-01-27 00:45:33726 base::TimeDelta delay = animation_floor_time_ - now;
[email protected]7c4329e2011-02-18 22:02:59727 animation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:21728 MessageLoop::current()->PostDelayedTask(
729 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), delay);
[email protected]5f8b1022011-01-21 23:34:50730}
731
[email protected]bd37ae252011-06-03 01:28:18732bool RenderWidget::IsRenderingVSynced() {
733 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
734 // not caught by this check. This will lead to artificially low frame rates
735 // for people who force vsync off at a driver level and expect Chrome to speed
736 // up.
737 return !has_disable_gpu_vsync_switch_;
738}
739
[email protected]65225772011-05-12 21:10:24740void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06741 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24742 invalidation_task_posted_ = false;
743 DoDeferredUpdateAndSendInputAck();
744}
745
746void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05747 DoDeferredUpdate();
748
749 if (pending_input_event_ack_.get())
750 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21751}
752
[email protected]552e6002009-11-19 05:24:57753void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58754 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08755
[email protected]65225772011-05-12 21:10:24756 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29757 return;
[email protected]05a980d7a2012-02-07 22:16:42758
759 if (!host_window_set_) {
760 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
761 return;
762 }
[email protected]aa4117f2011-12-09 22:19:21763 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24764 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
765 return;
766 }
[email protected]9ca84622011-06-02 23:46:39767 if (is_accelerated_compositing_active_ &&
768 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24769 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
770 return;
771 }
initial.commit09911bf2008-07-26 23:55:29772
[email protected]552e6002009-11-19 05:24:57773 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29774 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57775 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29776 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24777 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29778 return;
779 }
780
[email protected]05a980d7a2012-02-07 22:16:42781 if (is_accelerated_compositing_active_)
782 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
783
[email protected]0fb93f52011-05-18 23:13:56784 // Tracking of frame rate jitter
785 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]52ccd0ea2011-02-16 01:09:05786 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50787
[email protected]f98d7e3c2010-09-13 22:30:46788 // Layout may generate more invalidation. It may also enable the
789 // GPU acceleration, so make sure to run layout before we send the
790 // GpuRenderingActivated message.
791 webwidget_->layout();
792
[email protected]5f8b1022011-01-21 23:34:50793 // Suppress painting if nothing is dirty. This has to be done after updating
794 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24795 if (!paint_aggregator_.HasPendingUpdate()) {
796 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]5f8b1022011-01-21 23:34:50797 return;
[email protected]65225772011-05-12 21:10:24798 }
[email protected]5f8b1022011-01-21 23:34:50799
[email protected]872ae5b2011-05-26 20:20:50800 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56801 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04802 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56803 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
804 delay,
805 base::TimeDelta::FromMilliseconds(1),
806 base::TimeDelta::FromMilliseconds(60),
807 30);
[email protected]d0be63772011-12-20 23:18:04808 } else {
[email protected]0fb93f52011-05-18 23:13:56809 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
810 delay,
811 base::TimeDelta::FromMilliseconds(1),
812 base::TimeDelta::FromMilliseconds(60),
813 30);
[email protected]d0be63772011-12-20 23:18:04814 }
[email protected]872ae5b2011-05-26 20:20:50815
816 // Calculate filtered time per frame:
817 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
818 filtered_time_per_frame_ =
819 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56820 }
821 last_do_deferred_update_time_ = frame_begin_ticks;
822
[email protected]552e6002009-11-19 05:24:57823 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29824 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30825 PaintAggregator::PendingUpdate update;
826 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29827
[email protected]53d3f302009-12-21 04:42:05828 gfx::Rect scroll_damage = update.GetScrollDamage();
829 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29830
[email protected]29ed96a2012-02-04 18:12:16831 // Notify derived classes that we're about to initiate a paint.
832 WillInitiatePaint();
833
[email protected]ca4847f2010-09-24 05:39:15834 // A plugin may be able to do an optimized paint. First check this, in which
835 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46836 // This optimization allows PPAPI plugins that declare themselves on top of
837 // the page (like a traditional windowed plugin) to be able to animate (think
838 // movie playing) without repeatedly re-painting the page underneath, or
839 // copying the plugin backing store (since we can send the plugin's backing
840 // store directly to the browser).
841 //
842 // This optimization only works when the entire invalid region is contained
843 // within the plugin. There is a related optimization in PaintRect for the
844 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15845 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15846 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21847 DCHECK(!pending_update_params_.get());
848 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
849 pending_update_params_->dx = update.scroll_delta.x();
850 pending_update_params_->dy = update.scroll_delta.y();
851 pending_update_params_->scroll_rect = update.scroll_rect;
852 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21853 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
854 pending_update_params_->flags = next_paint_flags_;
855 pending_update_params_->scroll_offset = GetScrollOffset();
856 pending_update_params_->needs_ack = true;
857 next_paint_flags_ = 0;
858
[email protected]ca4847f2010-09-24 05:39:15859 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56860 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15861 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
862 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27863 // Only update the part of the plugin that actually changed.
864 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21865 pending_update_params_->bitmap = dib->id();
866 pending_update_params_->bitmap_rect = optimized_copy_location;
867 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56868 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46869 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15870 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35871 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
872 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46873 if (!canvas.get()) {
874 NOTREACHED();
875 return;
876 }
[email protected]cef3362f2009-12-21 17:48:45877
[email protected]f98d7e3c2010-09-13 22:30:46878 // We may get back a smaller canvas than we asked for.
879 // TODO(darin): This seems like it could cause painting problems!
880 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
881 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
882 bounds.set_width(canvas->getDevice()->width());
883 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05884
[email protected]f98d7e3c2010-09-13 22:30:46885 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
886
[email protected]aa4117f2011-12-09 22:19:21887 pending_update_params_->bitmap = current_paint_buf_->id();
888 pending_update_params_->bitmap_rect = bounds;
889
890 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46891 // The scroll damage is just another rectangle to paint and copy.
892 copy_rects.swap(update.paint_rects);
893 if (!scroll_damage.IsEmpty())
894 copy_rects.push_back(scroll_damage);
895
896 for (size_t i = 0; i < copy_rects.size(); ++i)
897 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35898
899 // Software FPS tick for performance tests. The accelerated path traces the
900 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
901 // NOTE: Tests may break if this event is renamed or moved.
902 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46903 } else { // Accelerated compositing path
904 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21905 // If painting is done via the gpu process then we don't set any damage
906 // rects to save the browser process from doing unecessary work.
907 pending_update_params_->bitmap_rect = bounds;
908 pending_update_params_->scroll_rect = gfx::Rect();
909 // We don't need an ack, because we're not sharing a DIB with the browser.
910 // If it needs to (e.g. composited UI), the GPU process does its own ACK
911 // with the browser for the GPU surface.
912 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42913 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46914 }
915
[email protected]936c6f52011-12-13 01:35:26916 // If we're holding a pending input event ACK, send the ACK before sending the
917 // UpdateReply message so we can receive another input event before the
918 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
919 // the UpdateRect IPC message handler.
920 if (pending_input_event_ack_.get())
921 Send(pending_input_event_ack_.release());
922
[email protected]aa4117f2011-12-09 22:19:21923 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
924 // OnSwapBuffersPosted), meaning a message has been added to the
925 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
926 // the message now.
927 if (pending_update_params_.get()) {
928 // sending an ack to browser process that the paint is complete...
929 update_reply_pending_ = pending_update_params_->needs_ack;
930 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
931 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:34932 }
[email protected]53d3f302009-12-21 04:42:05933
[email protected]e99ef6f2011-10-16 01:13:00934 UpdateTextInputState();
935 UpdateSelectionBounds();
[email protected]00c39612010-03-06 02:53:28936
[email protected]29ed96a2012-02-04 18:12:16937 // If we're software rendering then we're done initiating the paint.
938 if (!is_accelerated_compositing_active_)
939 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29940}
941
942///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:46943// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:29944
[email protected]4873c7d2009-07-16 06:36:28945void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:57946 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48947 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57948 gfx::Rect damaged_rect = view_rect.Intersect(rect);
949 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29950 return;
951
[email protected]552e6002009-11-19 05:24:57952 paint_aggregator_.InvalidateRect(damaged_rect);
953
954 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:24955 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:57956 return;
957 if (!paint_aggregator_.HasPendingUpdate())
958 return;
[email protected]aa4117f2011-12-09 22:19:21959 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:24960 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
961 return;
962
963 // When GPU rendering, combine pending animations and invalidations into
964 // a single update.
965 if (is_accelerated_compositing_active_ && animation_task_posted_)
[email protected]552e6002009-11-19 05:24:57966 return;
967
968 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:29969 // 1) Ensures that we call WebView::Paint without a bunch of other junk
970 // on the call stack.
971 // 2) Allows us to collect more damage rects before painting to help coalesce
972 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:24973 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:21974 MessageLoop::current()->PostTask(
975 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:29976}
977
[email protected]4873c7d2009-07-16 06:36:28978void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:46979 // Drop scrolls on the floor when we are in compositing mode.
980 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:56981 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:46982 return;
983
[email protected]552e6002009-11-19 05:24:57984 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48985 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57986 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
987 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29988 return;
989
[email protected]552e6002009-11-19 05:24:57990 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
991
992 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:24993 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:57994 return;
995 if (!paint_aggregator_.HasPendingUpdate())
996 return;
[email protected]aa4117f2011-12-09 22:19:21997 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:24998 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
999 return;
1000
1001 // When GPU rendering, combine pending animations and invalidations into
1002 // a single update.
1003 if (is_accelerated_compositing_active_ && animation_task_posted_)
[email protected]552e6002009-11-19 05:24:571004 return;
1005
1006 // Perform updating asynchronously. This serves two purposes:
1007 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1008 // on the call stack.
1009 // 2) Allows us to collect more damage rects before painting to help coalesce
1010 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241011 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211012 MessageLoop::current()->PostTask(
1013 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291014}
1015
[email protected]244ac1892011-12-02 17:04:471016void RenderWidget::didAutoResize(const WebSize& new_size) {
1017 size_ = new_size;
1018}
1019
[email protected]3da12cb2011-10-08 02:25:041020void RenderWidget::didActivateCompositor(int compositor_identifier) {
[email protected]ea162f92011-10-04 23:08:221021 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1022
[email protected]f3150172011-10-22 02:28:451023 CompositorThread* compositor_thread =
1024 RenderThreadImpl::current()->compositor_thread();
1025 if (compositor_thread)
1026 compositor_thread->AddCompositor(routing_id_, compositor_identifier);
[email protected]3da12cb2011-10-08 02:25:041027
[email protected]aa4117f2011-12-09 22:19:211028 if (!is_accelerated_compositing_active_) {
1029 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1030 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1031 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1032 // going to switch to accelerated compositing, the GPU process may need
1033 // round-trips to the browser's UI thread before finishing the frame,
1034 // causing deadlocks if we delay the UpdateRect until we receive the
1035 // OnSwapBuffersComplete. So send a dummy message that will unblock the
1036 // browser's UI thread.
1037 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1038 }
1039
[email protected]ea162f92011-10-04 23:08:221040 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421041 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241042 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221043}
1044
1045void RenderWidget::didDeactivateCompositor() {
1046 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1047
1048 is_accelerated_compositing_active_ = false;
1049 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1050 routing_id_, is_accelerated_compositing_active_));
1051
[email protected]ea162f92011-10-04 23:08:221052 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241053 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561054}
1055
[email protected]58264a32011-11-17 23:36:151056void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501057 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351058 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1059 // NOTE: Tests may break if this event is renamed or moved.
1060 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161061 // Notify subclasses that we initiated the paint operation.
1062 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151063}
1064
1065void RenderWidget::didCompleteSwapBuffers() {
[email protected]aa4117f2011-12-09 22:19:211066 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151067 return;
1068
1069 if (!next_paint_flags_ && !plugin_window_moves_.size())
1070 return;
1071
1072 ViewHostMsg_UpdateRect_Params params;
1073 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151074 params.plugin_window_moves.swap(plugin_window_moves_);
1075 params.flags = next_paint_flags_;
1076 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121077 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151078
1079 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1080 next_paint_flags_ = 0;
1081}
1082
[email protected]f98d7e3c2010-09-13 22:30:461083void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041084 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401085 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041086 } else {
[email protected]c3d45532011-10-07 19:20:401087 // TODO(nduca): replace with something a little less hacky. The reason this
1088 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1089 // contains a lot of host-renderer synchronization logic that is still
1090 // important for the accelerated compositing case. The option of simply
1091 // duplicating all that code is less desirable than "faking out" the
1092 // invalidation path using a magical damage rect.
1093 didInvalidateRect(WebRect(0, 0, 1, 1));
1094 }
[email protected]f98d7e3c2010-09-13 22:30:461095}
1096
[email protected]5f8b1022011-01-21 23:34:501097void RenderWidget::scheduleAnimation() {
[email protected]921244e42011-07-20 16:36:301098 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ee3d3ad2011-02-04 00:42:211099 if (!animation_update_pending_) {
1100 animation_update_pending_ = true;
[email protected]52ccd0ea2011-02-16 01:09:051101 if (!animation_task_posted_) {
1102 animation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211103 MessageLoop::current()->PostTask(
1104 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this));
[email protected]52ccd0ea2011-02-16 01:09:051105 }
[email protected]ee3d3ad2011-02-04 00:42:211106 }
[email protected]5f8b1022011-01-21 23:34:501107}
1108
[email protected]4873c7d2009-07-16 06:36:281109void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301110 // TODO(darin): Eliminate this temporary.
1111 WebCursor cursor(cursor_info);
1112
initial.commit09911bf2008-07-26 23:55:291113 // Only send a SetCursor message if we need to make a change.
1114 if (!current_cursor_.IsEqual(cursor)) {
1115 current_cursor_ = cursor;
1116 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1117 }
1118}
1119
1120// We are supposed to get a single call to Show for a newly created RenderWidget
1121// that was created via RenderWidget::CreateWebView. So, we wait until this
1122// point to dispatch the ShowWidget message.
1123//
1124// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281125// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291126//
[email protected]4873c7d2009-07-16 06:36:281127void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291128 DCHECK(!did_show_) << "received extraneous Show call";
1129 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1130 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1131
[email protected]8de12d942010-11-17 20:42:441132 if (did_show_)
1133 return;
1134
1135 did_show_ = true;
1136 // NOTE: initial_pos_ may still have its default values at this point, but
1137 // that's okay. It'll be ignored if as_popup is false, or the browser
1138 // process will impose a default position otherwise.
1139 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1140 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291141}
1142
[email protected]4873c7d2009-07-16 06:36:281143void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291144}
1145
[email protected]4873c7d2009-07-16 06:36:281146void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291147}
1148
[email protected]2533ce12009-05-09 00:02:241149void RenderWidget::DoDeferredClose() {
1150 Send(new ViewHostMsg_Close(routing_id_));
1151}
1152
[email protected]4873c7d2009-07-16 06:36:281153void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291154 // If a page calls window.close() twice, we'll end up here twice, but that's
1155 // OK. It is safe to send multiple Close messages.
1156
[email protected]2533ce12009-05-09 00:02:241157 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1158 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1159 // could be closed before the JS finishes executing. So instead, post a
1160 // message back to the message loop, which won't run until the JS is
1161 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211162 MessageLoop::current()->PostTask(
1163 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291164}
1165
1166void RenderWidget::Close() {
1167 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281168 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291169 webwidget_ = NULL;
1170 }
1171}
1172
[email protected]4873c7d2009-07-16 06:36:281173WebRect RenderWidget::windowRect() {
1174 if (pending_window_rect_count_)
1175 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241176
[email protected]b3f2b912009-04-09 16:18:521177 gfx::Rect rect;
1178 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281179 return rect;
initial.commit09911bf2008-07-26 23:55:291180}
1181
[email protected]8a9d6ca32011-06-06 20:11:301182void RenderWidget::setToolTipText(const WebKit::WebString& text,
1183 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541184 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301185}
1186
[email protected]4873c7d2009-07-16 06:36:281187void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291188 if (did_show_) {
1189 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241190 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291191 } else {
1192 initial_pos_ = pos;
1193 }
1194}
1195
[email protected]2533ce12009-05-09 00:02:241196void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1197 pending_window_rect_ = rect;
1198 pending_window_rect_count_++;
1199}
1200
[email protected]4873c7d2009-07-16 06:36:281201WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241202 if (pending_window_rect_count_) {
1203 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1204 // the RootWindowRect is probably going to return wrong results since the
1205 // browser may not have processed the Move yet. There isn't really anything
1206 // good to do in this case, and it shouldn't happen - since this size is
1207 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281208 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241209 }
1210
[email protected]b3f2b912009-04-09 16:18:521211 gfx::Rect rect;
1212 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281213 return rect;
[email protected]d4547452008-08-28 18:36:371214}
1215
[email protected]4873c7d2009-07-16 06:36:281216WebRect RenderWidget::windowResizerRect() {
1217 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191218}
1219
[email protected]fa7b1dc2010-06-23 17:53:041220void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031221 // To prevent this renderer process from sending unnecessary IPC messages to
1222 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041223 // only during the input method attached to the browser process is active.
1224 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291225}
1226
[email protected]fa7b1dc2010-06-23 17:53:041227void RenderWidget::OnImeSetComposition(
1228 const string16& text,
1229 const std::vector<WebCompositionUnderline>& underlines,
1230 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281231 if (!webwidget_)
1232 return;
[email protected]d4cff272011-05-02 15:46:011233 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041234 text, WebVector<WebCompositionUnderline>(underlines),
1235 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011236 // Setting the IME composition was successful. Send the new composition
1237 // range to the browser.
1238 ui::Range range(ui::Range::InvalidRange());
1239 size_t location, length;
1240 if (webwidget_->compositionRange(&location, &length)) {
1241 range.set_start(location);
1242 range.set_end(location + length);
1243 }
1244 // The IME was cancelled via the Esc key, so just send back the caret.
1245 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1246 range.set_start(location);
1247 range.set_end(location + length);
1248 }
1249 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1250 } else {
[email protected]fa7b1dc2010-06-23 17:53:041251 // If we failed to set the composition text, then we need to let the browser
1252 // process to cancel the input method's ongoing composition session, to make
1253 // sure we are in a consistent state.
1254 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011255
1256 // Send an updated IME range with just the caret range.
1257 ui::Range range(ui::Range::InvalidRange());
1258 size_t location, length;
1259 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1260 range.set_start(location);
1261 range.set_end(location + length);
1262 }
1263 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261264 }
[email protected]fa7b1dc2010-06-23 17:53:041265}
1266
[email protected]4de6d1692011-10-12 08:45:441267void RenderWidget::OnImeConfirmComposition(
1268 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041269 if (!webwidget_)
1270 return;
1271
1272 handling_input_event_ = true;
1273 webwidget_->confirmComposition(text);
1274 handling_input_event_ = false;
1275
[email protected]d4cff272011-05-02 15:46:011276 // Send an updated IME range with just the caret range.
1277 ui::Range range(ui::Range::InvalidRange());
1278 size_t location, length;
1279 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1280 range.set_start(location);
1281 range.set_end(location + length);
1282 }
1283 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291284}
1285
[email protected]948f7ab72010-05-28 23:48:081286// This message causes the renderer to render an image of the
1287// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491288void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091289 int tag,
[email protected]948f7ab72010-05-28 23:48:081290 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491291 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001292 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1293 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251294 // Close our unused handle.
1295#if defined(OS_WIN)
1296 ::CloseHandle(dib_handle);
1297#elif defined(OS_MACOSX)
1298 base::SharedMemory::CloseHandle(dib_handle);
1299#endif
1300 }
[email protected]d65adb12010-04-28 17:26:491301 return;
[email protected]45c6aad32010-11-11 04:46:251302 }
[email protected]d65adb12010-04-28 17:26:491303
[email protected]948f7ab72010-05-28 23:48:081304 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491305 // If one of these is empty, then we just return the dib we were
1306 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091307 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491308 return;
1309 }
1310
1311 // Map the given DIB ID into this process, and unmap it at the end
1312 // of this function.
[email protected]45c6aad32010-11-11 04:46:251313 scoped_ptr<TransportDIB> paint_at_size_buffer(
1314 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301315
1316 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491317 float x_scale = static_cast<float>(desired_size.width()) /
1318 static_cast<float>(canvas_size.width());
1319 float y_scale = static_cast<float>(desired_size.height()) /
1320 static_cast<float>(canvas_size.height());
1321
[email protected]ee8d6fd2010-05-26 17:05:481322 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491323 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1324 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481325 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491326
[email protected]36808ad2010-10-20 19:18:301327 scoped_ptr<skia::PlatformCanvas> canvas(
1328 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1329 canvas_size.height()));
1330 if (!canvas.get()) {
1331 NOTREACHED();
1332 return;
1333 }
1334
[email protected]d65adb12010-04-28 17:26:491335 // Reset bounds to what we actually received, but they should be the
1336 // same.
1337 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1338 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1339 bounds.set_width(canvas->getDevice()->width());
1340 bounds.set_height(canvas->getDevice()->height());
1341
1342 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081343 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491344 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1345
[email protected]948f7ab72010-05-28 23:48:081346 // Have to make sure we're laid out at the right size before
1347 // rendering.
1348 gfx::Size old_size = webwidget_->size();
1349 webwidget_->resize(page_size);
1350 webwidget_->layout();
1351
[email protected]d65adb12010-04-28 17:26:491352 // Paint the entire thing (using original bounds, not scaled bounds).
1353 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1354 canvas->restore();
1355
[email protected]948f7ab72010-05-28 23:48:081356 // Return the widget to its previous size.
1357 webwidget_->resize(old_size);
1358
[email protected]c88c9442010-07-19 18:55:091359 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491360}
1361
[email protected]ec7dc112008-08-06 05:30:121362void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1363 // During shutdown we can just ignore this message.
1364 if (!webwidget_)
1365 return;
1366
1367 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561368 if (is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461369 scheduleComposite();
1370 } else {
1371 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1372 didInvalidateRect(repaint_rect);
1373 }
[email protected]ec7dc112008-08-06 05:30:121374}
1375
[email protected]4873c7d2009-07-16 06:36:281376void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111377 if (!webwidget_)
1378 return;
[email protected]4873c7d2009-07-16 06:36:281379 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111380}
1381
[email protected]719b36f2010-12-22 20:36:461382webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151383 const gfx::Rect& paint_bounds,
1384 TransportDIB** dib,
1385 gfx::Rect* location,
1386 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461387 // Bare RenderWidgets don't support optimized plugin painting.
1388 return NULL;
[email protected]ca4847f2010-09-24 05:39:151389}
1390
[email protected]bcaf2272011-02-15 15:29:431391gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521392 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431393 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521394}
1395
[email protected]bee16aab2009-08-26 15:55:031396void RenderWidget::SetHidden(bool hidden) {
1397 if (is_hidden_ == hidden)
1398 return;
1399
1400 // The status has changed. Tell the RenderThread about it.
1401 is_hidden_ = hidden;
1402 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271403 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031404 else
[email protected]380244092011-10-07 17:26:271405 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031406}
1407
[email protected]2b624c562011-10-27 22:58:261408void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261409 if (!webwidget_)
1410 return;
1411
1412 if (is_fullscreen_) {
1413 webwidget_->willExitFullScreen();
1414 } else {
1415 webwidget_->willEnterFullScreen();
1416 }
[email protected]2b624c562011-10-27 22:58:261417}
1418
1419void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261420 if (!webwidget_)
1421 return;
1422
1423 if (is_fullscreen_) {
1424 webwidget_->didEnterFullScreen();
1425 } else {
1426 webwidget_->didExitFullScreen();
1427 }
[email protected]2b624c562011-10-27 22:58:261428}
1429
[email protected]699ab0d2009-04-23 23:19:141430void RenderWidget::SetBackground(const SkBitmap& background) {
1431 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461432
[email protected]699ab0d2009-04-23 23:19:141433 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281434 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141435}
1436
[email protected]674741932009-02-04 23:44:461437bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051438 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461439}
1440
1441bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051442 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461443}
1444
1445void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051446 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461447}
1448
1449void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051450 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461451}
1452
1453void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051454 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461455}
1456
[email protected]e99ef6f2011-10-16 01:13:001457void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041458 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291459 return;
[email protected]fa7b1dc2010-06-23 17:53:041460
[email protected]ad26ef42011-06-17 07:59:451461 ui::TextInputType new_type = GetTextInputType();
1462 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001463 // Only sends text input type and compose inline to the browser process if
1464 // they are changed.
1465 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451466 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041467 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451468 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001469 Send(new ViewHostMsg_TextInputStateChanged(
1470 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291471 }
initial.commit09911bf2008-07-26 23:55:291472}
1473
[email protected]3f783362011-10-21 22:40:501474void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1475 WebRect start_webrect;
1476 WebRect end_webrect;
1477 webwidget_->selectionBounds(start_webrect, end_webrect);
1478 *start = start_webrect;
1479 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321480}
1481
[email protected]e99ef6f2011-10-16 01:13:001482void RenderWidget::UpdateSelectionBounds() {
1483 if (!webwidget_)
1484 return;
1485
[email protected]3f783362011-10-21 22:40:501486 gfx::Rect start_rect;
1487 gfx::Rect end_rect;
1488 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001489 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1490 return;
1491
1492 selection_start_rect_ = start_rect;
1493 selection_end_rect_ = end_rect;
1494 Send(new ViewHostMsg_SelectionBoundsChanged(
1495 routing_id_, selection_start_rect_, selection_end_rect_));
1496}
1497
[email protected]73bf95812011-10-12 11:38:321498// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451499COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1500 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1501COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1502 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1503COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1504 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181505COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1506 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1507COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1508 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1509COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1510 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1511COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1512 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1513COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1514 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451515
1516ui::TextInputType RenderWidget::GetTextInputType() {
1517 if (webwidget_) {
1518 int type = webwidget_->textInputType();
1519 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181520 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451521 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1522 return static_cast<ui::TextInputType>(type);
1523 }
1524 return ui::TEXT_INPUT_TYPE_NONE;
1525}
1526
1527bool RenderWidget::CanComposeInline() {
1528 return true;
[email protected]56ea1a62011-05-30 07:05:571529}
1530
[email protected]4873c7d2009-07-16 06:36:281531WebScreenInfo RenderWidget::screenInfo() {
1532 WebScreenInfo results;
[email protected]05a980d7a2012-02-07 22:16:421533 if (host_window_set_)
[email protected]a8628df2012-01-27 23:14:171534 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results));
[email protected]fb200c72012-01-30 21:22:211535 else {
[email protected]a8628df2012-01-27 23:14:171536 DLOG(WARNING) << "Unable to retrieve screen information, no host window";
[email protected]fb200c72012-01-30 21:22:211537#if defined(USE_AURA)
1538 // TODO(backer): Remove this a temporary workaround for crbug.com/111929
1539 // once we get a proper fix.
[email protected]957e2c32012-01-31 17:42:201540 results.availableRect.width = 1000;
1541 results.availableRect.height = 1000;
[email protected]fb200c72012-01-30 21:22:211542#endif
1543 }
[email protected]4873c7d2009-07-16 06:36:281544 return results;
1545}
1546
[email protected]fa7b1dc2010-06-23 17:53:041547void RenderWidget::resetInputMethod() {
1548 if (!input_method_is_active_)
1549 return;
1550
1551 // If the last text input type is not None, then we should finish any
1552 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451553 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041554 // If a composition text exists, then we need to let the browser process
1555 // to cancel the input method's ongoing composition session.
1556 if (webwidget_->confirmComposition())
1557 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1558 }
[email protected]d4cff272011-05-02 15:46:011559
1560 // Send an updated IME range with the current caret rect.
1561 ui::Range range(ui::Range::InvalidRange());
1562 size_t location, length;
1563 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1564 range.set_start(location);
1565 range.set_end(location + length);
1566 }
1567 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041568}
1569
[email protected]f103ab72009-09-02 17:10:591570void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501571 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291572 size_t i = 0;
1573 for (; i < plugin_window_moves_.size(); ++i) {
1574 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581575 if (move.rects_valid) {
1576 plugin_window_moves_[i] = move;
1577 } else {
1578 plugin_window_moves_[i].visible = move.visible;
1579 }
initial.commit09911bf2008-07-26 23:55:291580 break;
1581 }
1582 }
1583
1584 if (i == plugin_window_moves_.size())
1585 plugin_window_moves_.push_back(move);
1586}
[email protected]268654772009-08-06 23:02:041587
1588void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1589 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1590 i != plugin_window_moves_.end(); ++i) {
1591 if (i->window == window) {
1592 plugin_window_moves_.erase(i);
1593 break;
1594 }
1595 }
1596}
[email protected]67bfb83f2011-09-22 03:36:371597
1598bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1599 return false;
1600}
[email protected]c3d45532011-10-07 19:20:401601
1602bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1603 return false;
1604}