blob: 782681eb56f8200eba16bf1c97b3b2eb7f706a61 [file] [log] [blame]
[email protected]c5218762011-03-24 17:48:511// Copyright (c) 2011 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]4fb66842009-12-04 21:41:007#include "base/command_line.h"
[email protected]366ae242011-05-10 02:23:588#include "base/debug/trace_event.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1510#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/histogram.h"
[email protected]8a9d6ca32011-06-06 20:11:3013#include "base/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4814#include "build/build_config.h"
[email protected]38b592902011-04-16 02:08:4215#include "content/common/content_switches.h"
[email protected]992db4c2011-05-12 15:37:1516#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5017#include "content/common/view_messages.h"
[email protected]8704f89b2011-04-15 00:30:0518#include "content/renderer/render_process.h"
[email protected]10e6ab572011-04-14 23:42:0019#include "content/renderer/render_thread.h"
[email protected]acb94722011-03-18 01:33:3420#include "content/renderer/renderer_webkitclient_impl.h"
[email protected]484955942010-08-19 16:13:1821#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4822#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5223#include "third_party/skia/include/core/SkShader.h"
[email protected]8bd0fe62011-01-17 06:44:3724#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
25#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
26#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0127#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3728#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
29#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
30#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
[email protected]8a9d6ca32011-06-06 20:11:3031#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
[email protected]08397d52011-02-05 01:53:3832#include "ui/gfx/point.h"
33#include "ui/gfx/size.h"
[email protected]b9b751f22011-03-25 14:04:1234#include "ui/gfx/surface/transport_dib.h"
[email protected]bd37ae252011-06-03 01:28:1835#include "ui/gfx/gl/gl_switches.h"
[email protected]8c89e7792009-08-19 21:18:3436#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5037#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4638#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4839
40#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4941#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5242#include "third_party/skia/include/core/SkPixelRef.h"
43#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4844#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4445
[email protected]8bd0fe62011-01-17 06:44:3746#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2947
[email protected]fa7b1dc2010-06-23 17:53:0448using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3049using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2250using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0651using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2852using WebKit::WebNavigationPolicy;
53using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5954using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1855using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0156using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5257using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1958using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5259using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2860using WebKit::WebTextDirection;
[email protected]fa7b1dc2010-06-23 17:53:0461using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1862using WebKit::WebWidget;
[email protected]62cb33cae2009-03-27 23:30:2263
[email protected]3e2b375b2010-04-07 17:03:1264RenderWidget::RenderWidget(RenderThreadBase* render_thread,
65 WebKit::WebPopupType popup_type)
initial.commit09911bf2008-07-26 23:55:2966 : routing_id_(MSG_ROUTING_NONE),
[email protected]c5b3b5e2009-02-13 06:41:1167 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2968 opener_id_(MSG_ROUTING_NONE),
[email protected]8085dbc82008-09-26 22:53:4469 render_thread_(render_thread),
[email protected]659f73f2009-10-13 13:43:4270 host_window_(0),
[email protected]b4d08452010-10-05 17:34:3571 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2972 next_paint_flags_(0),
[email protected]872ae5b2011-05-26 20:20:5073 filtered_time_per_frame_(1.0f/60.0f),
[email protected]53d3f302009-12-21 04:42:0574 update_reply_pending_(false),
[email protected]65225772011-05-12 21:10:2475 using_asynchronous_swapbuffers_(false),
76 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2977 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2978 is_hidden_(false),
79 needs_repainting_on_restore_(false),
80 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4981 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4882 closing_(false),
[email protected]992db4c2011-05-12 15:37:1583 is_swapped_out_(false),
[email protected]fa7b1dc2010-06-23 17:53:0484 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:4585 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
86 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:1287 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:4888 pending_window_rect_count_(0),
[email protected]edbcde932010-05-07 17:10:4689 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:5090 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:2191 animation_update_pending_(false),
[email protected]65225772011-05-12 21:10:2492 animation_task_posted_(false),
93 invalidation_task_posted_(false) {
[email protected]8930d472009-02-21 08:05:2894 RenderProcess::current()->AddRefProcess();
[email protected]8085dbc82008-09-26 22:53:4495 DCHECK(render_thread_);
[email protected]bd37ae252011-06-03 01:28:1896 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
97 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:2998}
99
100RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11101 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]b4d08452010-10-05 17:34:35102 if (current_paint_buf_) {
103 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
104 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29105 }
[email protected]992db4c2011-05-12 15:37:15106 // If we are swapped out, we have released already.
107 if (!is_swapped_out_)
108 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29109}
110
[email protected]484955942010-08-19 16:13:18111// static
[email protected]8085dbc82008-09-26 22:53:44112RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]0ebf3872008-11-07 21:35:03113 RenderThreadBase* render_thread,
[email protected]3e2b375b2010-04-07 17:03:12114 WebKit::WebPopupType popup_type) {
initial.commit09911bf2008-07-26 23:55:29115 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]ad8e04a2010-11-01 04:16:27116 scoped_refptr<RenderWidget> widget(new RenderWidget(render_thread,
117 popup_type));
initial.commit09911bf2008-07-26 23:55:29118 widget->Init(opener_id); // adds reference
119 return widget;
120}
121
[email protected]484955942010-08-19 16:13:18122// static
123WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
124 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03125 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18126 break;
127 case WebKit::WebPopupTypeSelect:
128 case WebKit::WebPopupTypeSuggestion:
129 return WebPopupMenu::create(render_widget);
130 default:
131 NOTREACHED();
132 }
133 return NULL;
134}
135
initial.commit09911bf2008-07-26 23:55:29136void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18137 DoInit(opener_id,
138 RenderWidget::CreateWebWidget(this),
139 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
140}
141
[email protected]484955942010-08-19 16:13:18142void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06143 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18144 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29145 DCHECK(!webwidget_);
146
147 if (opener_id != MSG_ROUTING_NONE)
148 opener_id_ = opener_id;
149
[email protected]484955942010-08-19 16:13:18150 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29151
[email protected]484955942010-08-19 16:13:18152 bool result = render_thread_->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29153 if (result) {
[email protected]8085dbc82008-09-26 22:53:44154 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29155 // Take a reference on behalf of the RenderThread. This will be balanced
156 // when we receive ViewMsg_Close.
157 AddRef();
158 } else {
159 DCHECK(false);
160 }
161}
162
163// This is used to complete pending inits and non-pending inits. For non-
164// pending cases, the parent will be the same as the current parent. This
165// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55166void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29167 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29168
169 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29170
[email protected]6de74452009-02-25 18:04:59171 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29172}
173
[email protected]992db4c2011-05-12 15:37:15174void RenderWidget::SetSwappedOut(bool is_swapped_out) {
175 // We should only toggle between states.
176 DCHECK(is_swapped_out_ != is_swapped_out);
177 is_swapped_out_ = is_swapped_out;
178
179 // If we are swapping out, we will call ReleaseProcess, allowing the process
180 // to exit if all of its RenderViews are swapped out. We wait until the
181 // WasSwappedOut call to do this, to avoid showing the sad tab.
182 // If we are swapping in, we call AddRefProcess to prevent the process from
183 // exiting.
184 if (!is_swapped_out)
185 RenderProcess::current()->AddRefProcess();
186}
187
[email protected]a95986a82010-12-24 06:19:28188bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
189 bool handled = true;
190 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
191 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
192 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
193 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
194 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
195 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15196 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28197 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
198 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
199 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
200 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
201 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
202 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
203 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
204 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
205 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
206 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
207 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]872ae5b2011-05-26 20:20:50208 IPC_MESSAGE_HANDLER(ViewMsg_GetFPS, OnGetFPS)
[email protected]a95986a82010-12-24 06:19:28209 IPC_MESSAGE_UNHANDLED(handled = false)
210 IPC_END_MESSAGE_MAP()
211 return handled;
212}
initial.commit09911bf2008-07-26 23:55:29213
214bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15215 // Don't send any messages after the browser has told us to close, and filter
216 // most outgoing messages while swapped out.
217 if ((is_swapped_out_ &&
218 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
219 closing_) {
initial.commit09911bf2008-07-26 23:55:29220 delete message;
221 return false;
222 }
223
224 // If given a messsage without a routing ID, then assign our routing ID.
225 if (message->routing_id() == MSG_ROUTING_NONE)
226 message->set_routing_id(routing_id_);
227
[email protected]d3fc25652009-02-24 22:31:25228 return render_thread_->Send(message);
[email protected]8085dbc82008-09-26 22:53:44229}
230
initial.commit09911bf2008-07-26 23:55:29231// Got a response from the browser after the renderer decided to create a new
232// view.
[email protected]c03a6e72011-04-19 21:42:06233void RenderWidget::OnCreatingNewAck(
[email protected]2d7c8552011-06-27 19:21:55234 gfx::NativeViewId parent) {
initial.commit09911bf2008-07-26 23:55:29235 DCHECK(routing_id_ != MSG_ROUTING_NONE);
236
[email protected]2d7c8552011-06-27 19:21:55237 CompleteInit(parent);
initial.commit09911bf2008-07-26 23:55:29238}
239
240void RenderWidget::OnClose() {
241 if (closing_)
242 return;
243 closing_ = true;
244
245 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03246 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]8085dbc82008-09-26 22:53:44247 render_thread_->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03248 SetHidden(false);
249 }
initial.commit09911bf2008-07-26 23:55:29250
initial.commit09911bf2008-07-26 23:55:29251 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25252 // now. Post a task that only gets invoked when there are no nested message
253 // loops.
254 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
255 NewRunnableMethod(this, &RenderWidget::Close));
256
257 // Balances the AddRef taken when we called AddRoute.
258 Release();
initial.commit09911bf2008-07-26 23:55:29259}
260
[email protected]f21c613a2009-02-12 14:46:17261void RenderWidget::OnResize(const gfx::Size& new_size,
262 const gfx::Rect& resizer_rect) {
initial.commit09911bf2008-07-26 23:55:29263 // During shutdown we can just ignore this message.
264 if (!webwidget_)
265 return;
266
[email protected]e2356242010-11-16 22:33:03267 // We shouldn't be asked to resize to our current size.
268 DCHECK(size_ != new_size || resizer_rect_ != resizer_rect);
269
[email protected]f21c613a2009-02-12 14:46:17270 // Remember the rect where the resize corner will be drawn.
271 resizer_rect_ = resizer_rect;
272
[email protected]e2356242010-11-16 22:33:03273 if (size_ == new_size)
274 return;
275
initial.commit09911bf2008-07-26 23:55:29276 // TODO(darin): We should not need to reset this here.
[email protected]bee16aab2009-08-26 15:55:03277 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29278 needs_repainting_on_restore_ = false;
279
initial.commit09911bf2008-07-26 23:55:29280 size_ = new_size;
281
282 // We should not be sent a Resize message if we have not ACK'd the previous
283 DCHECK(!next_paint_is_resize_ack());
284
[email protected]552e6002009-11-19 05:24:57285 paint_aggregator_.ClearPendingUpdate();
286
initial.commit09911bf2008-07-26 23:55:29287 // When resizing, we want to wait to paint before ACK'ing the resize. This
288 // ensures that we only resize as fast as we can paint. We only need to send
289 // an ACK if we are resized to a non-empty rect.
[email protected]4873c7d2009-07-16 06:36:28290 webwidget_->resize(new_size);
initial.commit09911bf2008-07-26 23:55:29291 if (!new_size.IsEmpty()) {
[email protected]a79d8a632010-11-18 22:35:56292 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46293 // Resize should have caused an invalidation of the entire view.
294 DCHECK(paint_aggregator_.HasPendingUpdate());
295 }
[email protected]2d5d09d52009-06-15 14:29:21296
initial.commit09911bf2008-07-26 23:55:29297 // We will send the Resize_ACK flag once we paint again.
298 set_next_paint_is_resize_ack();
299 }
300}
301
302void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31303 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29304 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03305 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29306}
307
308void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31309 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29310 // During shutdown we can just ignore this message.
311 if (!webwidget_)
312 return;
313
314 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03315 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29316
317 if (!needs_repainting && !needs_repainting_on_restore_)
318 return;
319 needs_repainting_on_restore_ = false;
320
[email protected]d65adb12010-04-28 17:26:49321 // Tag the next paint as a restore ack, which is picked up by
322 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29323 set_next_paint_is_restore_ack();
324
325 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56326 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46327 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
328 } else {
[email protected]9c3085f2011-06-09 02:10:31329#ifdef WTF_USE_THREADED_COMPOSITING
[email protected]a5922cc2011-05-24 23:06:30330 webwidget_->composite(false);
331#else
[email protected]f98d7e3c2010-09-13 22:30:46332 scheduleComposite();
[email protected]a5922cc2011-05-24 23:06:30333#endif
[email protected]f98d7e3c2010-09-13 22:30:46334 }
initial.commit09911bf2008-07-26 23:55:29335}
336
[email protected]992db4c2011-05-12 15:37:15337void RenderWidget::OnWasSwappedOut() {
338 // If we have been swapped out and no one else is using this process,
339 // it's safe to exit now. If we get swapped back in, we will call
340 // AddRefProcess in SetSwappedOut.
341 if (is_swapped_out_)
342 RenderProcess::current()->ReleaseProcess();
343}
344
[email protected]53d3f302009-12-21 04:42:05345void RenderWidget::OnRequestMoveAck() {
346 DCHECK(pending_window_rect_count_);
347 pending_window_rect_count_--;
348}
349
350void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58351 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]53d3f302009-12-21 04:42:05352 DCHECK(update_reply_pending());
353 update_reply_pending_ = false;
354
[email protected]b4d08452010-10-05 17:34:35355 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
356 // have no current paint buffer.
357 if (current_paint_buf_) {
358 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
359 current_paint_buf_ = NULL;
360 }
361
[email protected]65225772011-05-12 21:10:24362 // If swapbuffers is still pending, then defer the update until the
363 // swapbuffers occurs.
364 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
365 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
366 return;
367 }
368
[email protected]00c39612010-03-06 02:53:28369 // Notify subclasses.
370 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25371
initial.commit09911bf2008-07-26 23:55:29372 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24373 DoDeferredUpdateAndSendInputAck();
374}
375
376bool RenderWidget::SupportsAsynchronousSwapBuffers()
377{
378 return false;
379}
380
381void RenderWidget::OnSwapBuffersAborted()
382{
383 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
384 num_swapbuffers_complete_pending_ = 0;
385 using_asynchronous_swapbuffers_ = false;
386 // Schedule another frame so the compositor learns about it.
387 scheduleComposite();
388}
389
[email protected]37a6f302011-07-11 23:43:08390void RenderWidget::OnSwapBuffersPosted() {
391 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
392 if (using_asynchronous_swapbuffers_)
393 num_swapbuffers_complete_pending_++;
394}
395
396void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24397 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
398 // When compositing deactivates, we reset the swapbuffers pending count. The
399 // swapbuffers acks may still arrive, however.
400 if (num_swapbuffers_complete_pending_ == 0) {
401 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
402 return;
403 }
404 num_swapbuffers_complete_pending_--;
405
406 // If update reply is still pending, then defer the update until that reply
407 // occurs.
408 if (update_reply_pending_){
409 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
410 return;
411 }
412
413 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06414 // when we were previously rendering. However, if an invalidation task is not
415 // posted, there may be software rendering work pending. In that case, don't
416 // early out.
417 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24418 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
419 return;
420 }
421
422 // Notify subclasses.
[email protected]50312bf2011-06-22 23:30:06423 if(is_accelerated_compositing_active_)
424 DidFlushPaint();
[email protected]65225772011-05-12 21:10:24425
426 // Continue painting if necessary...
427 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29428}
429
initial.commit09911bf2008-07-26 23:55:29430void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24431 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
initial.commit09911bf2008-07-26 23:55:29432 void* iter = NULL;
433
434 const char* data;
435 int data_length;
[email protected]5dd768212009-08-13 23:34:49436 handling_input_event_ = true;
437 if (!message.ReadData(&iter, &data, &data_length)) {
438 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29439 return;
[email protected]5dd768212009-08-13 23:34:49440 }
initial.commit09911bf2008-07-26 23:55:29441
442 const WebInputEvent* input_event =
443 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48444
445 bool is_keyboard_shortcut = false;
446 // is_keyboard_shortcut flag is only available for RawKeyDown events.
447 if (input_event->type == WebInputEvent::RawKeyDown)
448 message.ReadBool(&iter, &is_keyboard_shortcut);
449
initial.commit09911bf2008-07-26 23:55:29450 bool processed = false;
[email protected]867125a02009-12-10 06:01:48451 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
452 suppress_next_char_events_ = false;
453 if (webwidget_)
454 processed = webwidget_->handleInputEvent(*input_event);
455 }
456
457 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
458 // it's not processed by webkit, then we need to suppress the upcoming Char
459 // events.
460 if (!processed && is_keyboard_shortcut)
461 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29462
463 IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_);
464 response->WriteInt(input_event->type);
[email protected]e2824412009-02-27 01:57:05465 response->WriteBool(processed);
466
[email protected]353a34c2010-05-28 23:35:17467 if ((input_event->type == WebInputEvent::MouseMove ||
[email protected]d93fc462011-03-14 23:03:03468 input_event->type == WebInputEvent::MouseWheel ||
469 input_event->type == WebInputEvent::TouchMove) &&
[email protected]552e6002009-11-19 05:24:57470 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24471 // We want to rate limit the input events in this case, so we'll wait for
472 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17473 if (pending_input_event_ack_.get()) {
474 // As two different kinds of events could cause us to postpone an ack
475 // we send it now, if we have one pending. The Browser should never
476 // send us the same kind of event we are delaying the ack for.
477 Send(pending_input_event_ack_.release());
478 }
[email protected]12fbad812009-09-01 18:21:24479 pending_input_event_ack_.reset(response);
480 } else {
481 Send(response);
482 }
483
[email protected]5dd768212009-08-13 23:34:49484 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48485
[email protected]867125a02009-12-10 06:01:48486 if (WebInputEvent::isKeyboardEventType(input_event->type))
[email protected]446705872009-09-10 07:22:48487 DidHandleKeyEvent();
[email protected]6a8ddba52010-09-05 04:38:06488 if (WebInputEvent::isMouseEventType(input_event->type))
489 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
initial.commit09911bf2008-07-26 23:55:29490}
491
492void RenderWidget::OnMouseCaptureLost() {
493 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28494 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29495}
496
497void RenderWidget::OnSetFocus(bool enable) {
498 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33499 if (webwidget_)
500 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29501}
502
503void RenderWidget::ClearFocus() {
504 // We may have got the focus from the browser before this gets processed, in
505 // which case we do not want to unfocus ourself.
506 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28507 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29508}
509
[email protected]2d5d09d52009-06-15 14:29:21510void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00511 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21512 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06513 TRACE_EVENT2("renderer", "PaintRect",
514 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00515 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21516
517 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00518 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
519 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03520
[email protected]699ab0d2009-04-23 23:19:14521 // If there is a custom background, tile it.
522 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14523 SkPaint paint;
524 SkShader* shader = SkShader::CreateBitmapShader(background_,
525 SkShader::kRepeat_TileMode,
526 SkShader::kRepeat_TileMode);
527 paint.setShader(shader)->unref();
[email protected]8860e4f52009-06-25 01:01:52528 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
[email protected]699ab0d2009-04-23 23:19:14529 canvas->drawPaint(paint);
[email protected]699ab0d2009-04-23 23:19:14530 }
531
[email protected]719b36f2010-12-22 20:36:46532 // First see if this rect is a plugin that can paint itself faster.
533 TransportDIB* optimized_dib = NULL;
534 gfx::Rect optimized_copy_rect, optimized_copy_location;
535 webkit::ppapi::PluginInstance* optimized_instance =
536 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
537 &optimized_copy_location,
538 &optimized_copy_rect);
539 if (optimized_instance) {
540 // This plugin can be optimize-painted and we can just ask it to paint
541 // itself. We don't actually need the TransportDIB in this case.
542 //
543 // This is an optimization for PPAPI plugins that know they're on top of
544 // the page content. If this rect is inside such a plugin, we can save some
545 // time and avoid re-rendering the page content which we know will be
546 // covered by the plugin later (this time can be significant, especially
547 // for a playing movie that is invalidating a lot).
548 //
549 // In the plugin movie case, hopefully the similar call to
550 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
551 // painting, because that avoids copying the plugin image to a different
552 // paint rect. Unfortunately, if anything on the page is animating other
553 // than the movie, it break this optimization since the union of the
554 // invalid regions will be larger than the plugin.
555 //
556 // This code optimizes that case, where we can still avoid painting in
557 // WebKit and filling the background (which can be slow) and just painting
558 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
559 // required.
560 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27561 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46562 } else {
563 // Normal painting case.
564 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
565
566 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35567 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46568 }
initial.commit09911bf2008-07-26 23:55:29569
[email protected]4fb66842009-12-04 21:41:00570 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00571 canvas->restore();
572}
573
574void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
575 skia::PlatformCanvas* canvas) {
576 static bool kPaintBorder =
577 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
578 if (!kPaintBorder)
579 return;
580
[email protected]53d3f302009-12-21 04:42:05581 // Cycle through these colors to help distinguish new paint rects.
582 const SkColor colors[] = {
583 SkColorSetARGB(0x3F, 0xFF, 0, 0),
584 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
585 SkColorSetARGB(0x3F, 0, 0, 0xFF),
586 };
587 static int color_selector = 0;
588
[email protected]4fb66842009-12-04 21:41:00589 SkPaint paint;
590 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05591 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00592 paint.setStrokeWidth(1);
593
594 SkIRect irect;
595 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
596 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29597}
598
[email protected]52ccd0ea2011-02-16 01:09:05599void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30600 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]52ccd0ea2011-02-16 01:09:05601 animation_task_posted_ = false;
[email protected]921244e42011-07-20 16:36:30602 if (!animation_update_pending_) {
603 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59604 return;
[email protected]921244e42011-07-20 16:36:30605 }
[email protected]bd37ae252011-06-03 01:28:18606 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59607 // Record when we fired (according to base::Time::Now()) relative to when
608 // we posted the task to quantify how much the base::Time/base::TimeTicks
609 // skew is affecting animations.
610 base::TimeDelta animation_callback_delay = base::Time::Now() -
611 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
612 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
613 animation_callback_delay,
614 base::TimeDelta::FromMilliseconds(0),
615 base::TimeDelta::FromMilliseconds(30),
616 25);
617 }
[email protected]65225772011-05-12 21:10:24618 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24619}
620
[email protected]52ccd0ea2011-02-16 01:09:05621void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59622 if (!animation_update_pending_)
623 return;
[email protected]bd37ae252011-06-03 01:28:18624
625 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
626 int animationInterval = IsRenderingVSynced() ? 16 : 0;
627
[email protected]7c4329e2011-02-18 22:02:59628 base::Time now = base::Time::Now();
629 if (now >= animation_floor_time_) {
[email protected]921244e42011-07-20 16:36:30630 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]bd37ae252011-06-03 01:28:18631 animation_floor_time_ = now +
632 base::TimeDelta::FromMilliseconds(animationInterval);
633 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59634 // running animation callbacks so that if a callback requests another
635 // we'll be sure to run it at the proper time.
636 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(
[email protected]bd37ae252011-06-03 01:28:18637 this, &RenderWidget::AnimationCallback), animationInterval);
[email protected]7c4329e2011-02-18 22:02:59638 animation_task_posted_ = true;
639 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30640#ifdef WEBWIDGET_HAS_ANIMATE_CHANGES
641 webwidget_->animate(0.0);
642#else
[email protected]7c4329e2011-02-18 22:02:59643 webwidget_->animate();
[email protected]a5922cc2011-05-24 23:06:30644#endif
[email protected]7c4329e2011-02-18 22:02:59645 return;
[email protected]5f8b1022011-01-21 23:34:50646 }
[email protected]bd37ae252011-06-03 01:28:18647 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]7c4329e2011-02-18 22:02:59648 if (animation_task_posted_)
649 return;
650 // This code uses base::Time::Now() to calculate the floor and next fire
651 // time because javascript's Date object uses base::Time::Now(). The
652 // message loop uses base::TimeTicks, which on windows can have a
653 // different granularity than base::Time.
654 // The upshot of all this is that this function might be called before
655 // base::Time::Now() has advanced past the animation_floor_time_. To
656 // avoid exposing this delay to javascript, we keep posting delayed
657 // tasks until base::Time::Now() has advanced far enough.
658 int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp();
659 animation_task_posted_ = true;
660 MessageLoop::current()->PostDelayedTask(FROM_HERE,
661 NewRunnableMethod(this, &RenderWidget::AnimationCallback), delay);
[email protected]5f8b1022011-01-21 23:34:50662}
663
[email protected]bd37ae252011-06-03 01:28:18664bool RenderWidget::IsRenderingVSynced() {
665 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
666 // not caught by this check. This will lead to artificially low frame rates
667 // for people who force vsync off at a driver level and expect Chrome to speed
668 // up.
669 return !has_disable_gpu_vsync_switch_;
670}
671
[email protected]65225772011-05-12 21:10:24672void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06673 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24674 invalidation_task_posted_ = false;
675 DoDeferredUpdateAndSendInputAck();
676}
677
678void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05679 DoDeferredUpdate();
680
681 if (pending_input_event_ack_.get())
682 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21683}
684
[email protected]552e6002009-11-19 05:24:57685void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58686 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08687
[email protected]65225772011-05-12 21:10:24688 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29689 return;
[email protected]65225772011-05-12 21:10:24690 if (update_reply_pending()) {
691 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
692 return;
693 }
[email protected]9ca84622011-06-02 23:46:39694 if (is_accelerated_compositing_active_ &&
695 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24696 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
697 return;
698 }
initial.commit09911bf2008-07-26 23:55:29699
[email protected]552e6002009-11-19 05:24:57700 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29701 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57702 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29703 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24704 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29705 return;
706 }
707
[email protected]0fb93f52011-05-18 23:13:56708 // Tracking of frame rate jitter
709 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]52ccd0ea2011-02-16 01:09:05710 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50711
[email protected]f98d7e3c2010-09-13 22:30:46712 // Layout may generate more invalidation. It may also enable the
713 // GPU acceleration, so make sure to run layout before we send the
714 // GpuRenderingActivated message.
715 webwidget_->layout();
716
[email protected]5f8b1022011-01-21 23:34:50717 // Suppress painting if nothing is dirty. This has to be done after updating
718 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24719 if (!paint_aggregator_.HasPendingUpdate()) {
720 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]5f8b1022011-01-21 23:34:50721 return;
[email protected]65225772011-05-12 21:10:24722 }
[email protected]5f8b1022011-01-21 23:34:50723
[email protected]872ae5b2011-05-26 20:20:50724 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56725 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
726 if(is_accelerated_compositing_active_)
727 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
728 delay,
729 base::TimeDelta::FromMilliseconds(1),
730 base::TimeDelta::FromMilliseconds(60),
731 30);
732 else
733 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
734 delay,
735 base::TimeDelta::FromMilliseconds(1),
736 base::TimeDelta::FromMilliseconds(60),
737 30);
[email protected]872ae5b2011-05-26 20:20:50738
739 // Calculate filtered time per frame:
740 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
741 filtered_time_per_frame_ =
742 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56743 }
744 last_do_deferred_update_time_ = frame_begin_ticks;
745
[email protected]552e6002009-11-19 05:24:57746 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29747 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30748 PaintAggregator::PendingUpdate update;
749 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29750
[email protected]53d3f302009-12-21 04:42:05751 gfx::Rect scroll_damage = update.GetScrollDamage();
752 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29753
[email protected]27543452011-03-25 00:14:00754 // Compositing the page may disable accelerated compositing.
755 bool accelerated_compositing_was_active = is_accelerated_compositing_active_;
756
[email protected]ca4847f2010-09-24 05:39:15757 // A plugin may be able to do an optimized paint. First check this, in which
758 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46759 // This optimization allows PPAPI plugins that declare themselves on top of
760 // the page (like a traditional windowed plugin) to be able to animate (think
761 // movie playing) without repeatedly re-painting the page underneath, or
762 // copying the plugin backing store (since we can send the plugin's backing
763 // store directly to the browser).
764 //
765 // This optimization only works when the entire invalid region is contained
766 // within the plugin. There is a related optimization in PaintRect for the
767 // case where there may be multiple invalid regions.
[email protected]2650bd52011-03-25 00:34:44768 TransportDIB::Id dib_id = TransportDIB::Id();
[email protected]ca4847f2010-09-24 05:39:15769 TransportDIB* dib = NULL;
[email protected]cef3362f2009-12-21 17:48:45770 std::vector<gfx::Rect> copy_rects;
[email protected]ca4847f2010-09-24 05:39:15771 gfx::Rect optimized_copy_rect, optimized_copy_location;
772 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56773 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15774 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
775 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27776 // Only update the part of the plugin that actually changed.
777 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]ca4847f2010-09-24 05:39:15778 bounds = optimized_copy_location;
779 copy_rects.push_back(optimized_copy_rect);
780 dib_id = dib->id();
[email protected]a79d8a632010-11-18 22:35:56781 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46782 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15783 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35784 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
785 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46786 if (!canvas.get()) {
787 NOTREACHED();
788 return;
789 }
[email protected]cef3362f2009-12-21 17:48:45790
[email protected]f98d7e3c2010-09-13 22:30:46791 // We may get back a smaller canvas than we asked for.
792 // TODO(darin): This seems like it could cause painting problems!
793 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
794 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
795 bounds.set_width(canvas->getDevice()->width());
796 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05797
[email protected]f98d7e3c2010-09-13 22:30:46798 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
799
[email protected]f98d7e3c2010-09-13 22:30:46800 // The scroll damage is just another rectangle to paint and copy.
801 copy_rects.swap(update.paint_rects);
802 if (!scroll_damage.IsEmpty())
803 copy_rects.push_back(scroll_damage);
804
805 for (size_t i = 0; i < copy_rects.size(); ++i)
806 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]ca4847f2010-09-24 05:39:15807
[email protected]b4d08452010-10-05 17:34:35808 dib_id = current_paint_buf_->id();
[email protected]f98d7e3c2010-09-13 22:30:46809 } else { // Accelerated compositing path
810 // Begin painting.
[email protected]50bd6452010-11-27 19:39:42811 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46812 }
813
814 // sending an ack to browser process that the paint is complete...
[email protected]53d3f302009-12-21 04:42:05815 ViewHostMsg_UpdateRect_Params params;
[email protected]36808ad2010-10-20 19:18:30816 params.bitmap = dib_id;
[email protected]53d3f302009-12-21 04:42:05817 params.bitmap_rect = bounds;
818 params.dx = update.scroll_delta.x();
819 params.dy = update.scroll_delta.y();
[email protected]27543452011-03-25 00:14:00820 if (accelerated_compositing_was_active) {
[email protected]b167ca662010-05-14 00:05:34821 // If painting is done via the gpu process then we clear out all damage
822 // rects to save the browser process from doing unecessary work.
823 params.scroll_rect = gfx::Rect();
824 params.copy_rects.clear();
825 } else {
826 params.scroll_rect = update.scroll_rect;
827 params.copy_rects.swap(copy_rects); // TODO(darin): clip to bounds?
828 }
[email protected]53d3f302009-12-21 04:42:05829 params.view_size = size_;
[email protected]e2356242010-11-16 22:33:03830 params.resizer_rect = resizer_rect_;
[email protected]53d3f302009-12-21 04:42:05831 params.plugin_window_moves.swap(plugin_window_moves_);
832 params.flags = next_paint_flags_;
[email protected]d54169e92011-01-21 09:19:52833 params.scroll_offset = GetScrollOffset();
[email protected]53d3f302009-12-21 04:42:05834
835 update_reply_pending_ = true;
836 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
837 next_paint_flags_ = 0;
838
[email protected]fa7b1dc2010-06-23 17:53:04839 UpdateInputMethod();
[email protected]00c39612010-03-06 02:53:28840
841 // Let derived classes know we've painted.
842 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29843}
844
845///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:46846// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:29847
[email protected]4873c7d2009-07-16 06:36:28848void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:57849 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48850 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57851 gfx::Rect damaged_rect = view_rect.Intersect(rect);
852 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29853 return;
854
[email protected]552e6002009-11-19 05:24:57855 paint_aggregator_.InvalidateRect(damaged_rect);
856
857 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:24858 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:57859 return;
860 if (!paint_aggregator_.HasPendingUpdate())
861 return;
[email protected]65225772011-05-12 21:10:24862 if (update_reply_pending() ||
863 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
864 return;
865
866 // When GPU rendering, combine pending animations and invalidations into
867 // a single update.
868 if (is_accelerated_compositing_active_ && animation_task_posted_)
[email protected]552e6002009-11-19 05:24:57869 return;
870
871 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:29872 // 1) Ensures that we call WebView::Paint without a bunch of other junk
873 // on the call stack.
874 // 2) Allows us to collect more damage rects before painting to help coalesce
875 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:24876 invalidation_task_posted_ = true;
initial.commit09911bf2008-07-26 23:55:29877 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]65225772011-05-12 21:10:24878 this, &RenderWidget::InvalidationCallback));
initial.commit09911bf2008-07-26 23:55:29879}
880
[email protected]4873c7d2009-07-16 06:36:28881void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:46882 // Drop scrolls on the floor when we are in compositing mode.
883 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:56884 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:46885 return;
886
[email protected]552e6002009-11-19 05:24:57887 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48888 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57889 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
890 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29891 return;
892
[email protected]552e6002009-11-19 05:24:57893 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
894
895 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:24896 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:57897 return;
898 if (!paint_aggregator_.HasPendingUpdate())
899 return;
[email protected]65225772011-05-12 21:10:24900 if (update_reply_pending() ||
901 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
902 return;
903
904 // When GPU rendering, combine pending animations and invalidations into
905 // a single update.
906 if (is_accelerated_compositing_active_ && animation_task_posted_)
[email protected]552e6002009-11-19 05:24:57907 return;
908
909 // Perform updating asynchronously. This serves two purposes:
910 // 1) Ensures that we call WebView::Paint without a bunch of other junk
911 // on the call stack.
912 // 2) Allows us to collect more damage rects before painting to help coalesce
913 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:24914 invalidation_task_posted_ = true;
initial.commit09911bf2008-07-26 23:55:29915 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]65225772011-05-12 21:10:24916 this, &RenderWidget::InvalidationCallback));
initial.commit09911bf2008-07-26 23:55:29917}
918
[email protected]a79d8a632010-11-18 22:35:56919void RenderWidget::didActivateAcceleratedCompositing(bool active) {
[email protected]0c8fabf2011-06-14 19:35:22920 TRACE_EVENT1("gpu", "RenderWidget::didActivateAcceleratedCompositing",
921 "active", active);
[email protected]a79d8a632010-11-18 22:35:56922 is_accelerated_compositing_active_ = active;
[email protected]50bd6452010-11-27 19:39:42923 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:24924 routing_id_, is_accelerated_compositing_active_));
925
926 if (active)
927 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
928 else if (using_asynchronous_swapbuffers_)
929 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:56930}
931
[email protected]f98d7e3c2010-09-13 22:30:46932void RenderWidget::scheduleComposite() {
[email protected]a5922cc2011-05-24 23:06:30933#if WTF_USE_THREADED_COMPOSITING
934 NOTREACHED();
935#else
[email protected]f98d7e3c2010-09-13 22:30:46936 // TODO(nduca): replace with something a little less hacky. The reason this
937 // hack is still used is because the Invalidate-DoDeferredUpdate loop
938 // contains a lot of host-renderer synchronization logic that is still
939 // important for the accelerated compositing case. The option of simply
940 // duplicating all that code is less desirable than "faking out" the
941 // invalidation path using a magical damage rect.
[email protected]e2356242010-11-16 22:33:03942 didInvalidateRect(WebRect(0, 0, 1, 1));
[email protected]a5922cc2011-05-24 23:06:30943#endif
[email protected]f98d7e3c2010-09-13 22:30:46944}
945
[email protected]5f8b1022011-01-21 23:34:50946void RenderWidget::scheduleAnimation() {
[email protected]921244e42011-07-20 16:36:30947 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ee3d3ad2011-02-04 00:42:21948 if (!animation_update_pending_) {
949 animation_update_pending_ = true;
[email protected]52ccd0ea2011-02-16 01:09:05950 if (!animation_task_posted_) {
951 animation_task_posted_ = true;
952 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
953 this, &RenderWidget::AnimationCallback));
954 }
[email protected]ee3d3ad2011-02-04 00:42:21955 }
[email protected]5f8b1022011-01-21 23:34:50956}
957
[email protected]4873c7d2009-07-16 06:36:28958void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:30959 // TODO(darin): Eliminate this temporary.
960 WebCursor cursor(cursor_info);
961
initial.commit09911bf2008-07-26 23:55:29962 // Only send a SetCursor message if we need to make a change.
963 if (!current_cursor_.IsEqual(cursor)) {
964 current_cursor_ = cursor;
965 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
966 }
967}
968
969// We are supposed to get a single call to Show for a newly created RenderWidget
970// that was created via RenderWidget::CreateWebView. So, we wait until this
971// point to dispatch the ShowWidget message.
972//
973// This method provides us with the information about how to display the newly
974// created RenderWidget (i.e., as a constrained popup or as a new tab).
975//
[email protected]4873c7d2009-07-16 06:36:28976void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:29977 DCHECK(!did_show_) << "received extraneous Show call";
978 DCHECK(routing_id_ != MSG_ROUTING_NONE);
979 DCHECK(opener_id_ != MSG_ROUTING_NONE);
980
[email protected]8de12d942010-11-17 20:42:44981 if (did_show_)
982 return;
983
984 did_show_ = true;
985 // NOTE: initial_pos_ may still have its default values at this point, but
986 // that's okay. It'll be ignored if as_popup is false, or the browser
987 // process will impose a default position otherwise.
988 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
989 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:29990}
991
[email protected]4873c7d2009-07-16 06:36:28992void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:29993}
994
[email protected]4873c7d2009-07-16 06:36:28995void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:29996}
997
[email protected]2533ce12009-05-09 00:02:24998void RenderWidget::DoDeferredClose() {
999 Send(new ViewHostMsg_Close(routing_id_));
1000}
1001
[email protected]4873c7d2009-07-16 06:36:281002void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291003 // If a page calls window.close() twice, we'll end up here twice, but that's
1004 // OK. It is safe to send multiple Close messages.
1005
[email protected]2533ce12009-05-09 00:02:241006 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1007 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1008 // could be closed before the JS finishes executing. So instead, post a
1009 // message back to the message loop, which won't run until the JS is
1010 // complete, and then the Close message can be sent.
[email protected]75ae4492009-07-10 00:05:151011 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]2533ce12009-05-09 00:02:241012 this, &RenderWidget::DoDeferredClose));
initial.commit09911bf2008-07-26 23:55:291013}
1014
1015void RenderWidget::Close() {
1016 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281017 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291018 webwidget_ = NULL;
1019 }
1020}
1021
[email protected]4873c7d2009-07-16 06:36:281022WebRect RenderWidget::windowRect() {
1023 if (pending_window_rect_count_)
1024 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241025
[email protected]b3f2b912009-04-09 16:18:521026 gfx::Rect rect;
1027 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281028 return rect;
initial.commit09911bf2008-07-26 23:55:291029}
1030
[email protected]8a9d6ca32011-06-06 20:11:301031void RenderWidget::setToolTipText(const WebKit::WebString& text,
1032 WebTextDirection hint) {
1033 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1034 hint));
1035}
1036
[email protected]4873c7d2009-07-16 06:36:281037void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291038 if (did_show_) {
1039 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241040 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291041 } else {
1042 initial_pos_ = pos;
1043 }
1044}
1045
[email protected]2533ce12009-05-09 00:02:241046void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1047 pending_window_rect_ = rect;
1048 pending_window_rect_count_++;
1049}
1050
[email protected]4873c7d2009-07-16 06:36:281051WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241052 if (pending_window_rect_count_) {
1053 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1054 // the RootWindowRect is probably going to return wrong results since the
1055 // browser may not have processed the Move yet. There isn't really anything
1056 // good to do in this case, and it shouldn't happen - since this size is
1057 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281058 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241059 }
1060
[email protected]b3f2b912009-04-09 16:18:521061 gfx::Rect rect;
1062 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281063 return rect;
[email protected]d4547452008-08-28 18:36:371064}
1065
[email protected]4873c7d2009-07-16 06:36:281066WebRect RenderWidget::windowResizerRect() {
1067 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191068}
1069
[email protected]fa7b1dc2010-06-23 17:53:041070void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031071 // To prevent this renderer process from sending unnecessary IPC messages to
1072 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041073 // only during the input method attached to the browser process is active.
1074 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291075}
1076
[email protected]fa7b1dc2010-06-23 17:53:041077void RenderWidget::OnImeSetComposition(
1078 const string16& text,
1079 const std::vector<WebCompositionUnderline>& underlines,
1080 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281081 if (!webwidget_)
1082 return;
[email protected]d4cff272011-05-02 15:46:011083 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041084 text, WebVector<WebCompositionUnderline>(underlines),
1085 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011086 // Setting the IME composition was successful. Send the new composition
1087 // range to the browser.
1088 ui::Range range(ui::Range::InvalidRange());
1089 size_t location, length;
1090 if (webwidget_->compositionRange(&location, &length)) {
1091 range.set_start(location);
1092 range.set_end(location + length);
1093 }
1094 // The IME was cancelled via the Esc key, so just send back the caret.
1095 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1096 range.set_start(location);
1097 range.set_end(location + length);
1098 }
1099 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1100 } else {
[email protected]fa7b1dc2010-06-23 17:53:041101 // If we failed to set the composition text, then we need to let the browser
1102 // process to cancel the input method's ongoing composition session, to make
1103 // sure we are in a consistent state.
1104 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011105
1106 // Send an updated IME range with just the caret range.
1107 ui::Range range(ui::Range::InvalidRange());
1108 size_t location, length;
1109 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1110 range.set_start(location);
1111 range.set_end(location + length);
1112 }
1113 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261114 }
[email protected]fa7b1dc2010-06-23 17:53:041115}
1116
[email protected]6b349652011-01-05 18:36:241117void RenderWidget::OnImeConfirmComposition(const string16& text) {
[email protected]fa7b1dc2010-06-23 17:53:041118 if (webwidget_)
[email protected]6b349652011-01-05 18:36:241119 webwidget_->confirmComposition(text);
[email protected]d4cff272011-05-02 15:46:011120 // Send an updated IME range with just the caret range.
1121 ui::Range range(ui::Range::InvalidRange());
1122 size_t location, length;
1123 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1124 range.set_start(location);
1125 range.set_end(location + length);
1126 }
1127 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291128}
1129
[email protected]948f7ab72010-05-28 23:48:081130// This message causes the renderer to render an image of the
1131// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491132void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091133 int tag,
[email protected]948f7ab72010-05-28 23:48:081134 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491135 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001136 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1137 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251138 // Close our unused handle.
1139#if defined(OS_WIN)
1140 ::CloseHandle(dib_handle);
1141#elif defined(OS_MACOSX)
1142 base::SharedMemory::CloseHandle(dib_handle);
1143#endif
1144 }
[email protected]d65adb12010-04-28 17:26:491145 return;
[email protected]45c6aad32010-11-11 04:46:251146 }
[email protected]d65adb12010-04-28 17:26:491147
[email protected]948f7ab72010-05-28 23:48:081148 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491149 // If one of these is empty, then we just return the dib we were
1150 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091151 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491152 return;
1153 }
1154
1155 // Map the given DIB ID into this process, and unmap it at the end
1156 // of this function.
[email protected]45c6aad32010-11-11 04:46:251157 scoped_ptr<TransportDIB> paint_at_size_buffer(
1158 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301159
1160 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491161 float x_scale = static_cast<float>(desired_size.width()) /
1162 static_cast<float>(canvas_size.width());
1163 float y_scale = static_cast<float>(desired_size.height()) /
1164 static_cast<float>(canvas_size.height());
1165
[email protected]ee8d6fd2010-05-26 17:05:481166 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491167 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1168 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481169 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491170
[email protected]36808ad2010-10-20 19:18:301171 scoped_ptr<skia::PlatformCanvas> canvas(
1172 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1173 canvas_size.height()));
1174 if (!canvas.get()) {
1175 NOTREACHED();
1176 return;
1177 }
1178
[email protected]d65adb12010-04-28 17:26:491179 // Reset bounds to what we actually received, but they should be the
1180 // same.
1181 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1182 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1183 bounds.set_width(canvas->getDevice()->width());
1184 bounds.set_height(canvas->getDevice()->height());
1185
1186 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081187 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491188 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1189
[email protected]948f7ab72010-05-28 23:48:081190 // Have to make sure we're laid out at the right size before
1191 // rendering.
1192 gfx::Size old_size = webwidget_->size();
1193 webwidget_->resize(page_size);
1194 webwidget_->layout();
1195
[email protected]d65adb12010-04-28 17:26:491196 // Paint the entire thing (using original bounds, not scaled bounds).
1197 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1198 canvas->restore();
1199
[email protected]948f7ab72010-05-28 23:48:081200 // Return the widget to its previous size.
1201 webwidget_->resize(old_size);
1202
[email protected]c88c9442010-07-19 18:55:091203 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491204}
1205
[email protected]ec7dc112008-08-06 05:30:121206void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1207 // During shutdown we can just ignore this message.
1208 if (!webwidget_)
1209 return;
1210
1211 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561212 if (is_accelerated_compositing_active_) {
[email protected]a5922cc2011-05-24 23:06:301213#ifndef WTF_USE_THREADED_COMPOSITING
[email protected]f98d7e3c2010-09-13 22:30:461214 scheduleComposite();
[email protected]a5922cc2011-05-24 23:06:301215#else
1216#ifdef WEBWIDGET_HAS_THREADED_COMPOSITING_CHANGES
1217 webwidget_->composite(false);
1218#endif
1219#endif
[email protected]f98d7e3c2010-09-13 22:30:461220 } else {
1221 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1222 didInvalidateRect(repaint_rect);
1223 }
[email protected]ec7dc112008-08-06 05:30:121224}
1225
[email protected]4873c7d2009-07-16 06:36:281226void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111227 if (!webwidget_)
1228 return;
[email protected]4873c7d2009-07-16 06:36:281229 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111230}
1231
[email protected]872ae5b2011-05-26 20:20:501232void RenderWidget::OnGetFPS() {
1233 float fps = (filtered_time_per_frame_ > 0.0f)?
1234 1.0f / filtered_time_per_frame_ : 0.0f;
1235 Send(new ViewHostMsg_FPS(routing_id_, fps));
1236}
1237
[email protected]719b36f2010-12-22 20:36:461238webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151239 const gfx::Rect& paint_bounds,
1240 TransportDIB** dib,
1241 gfx::Rect* location,
1242 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461243 // Bare RenderWidgets don't support optimized plugin painting.
1244 return NULL;
[email protected]ca4847f2010-09-24 05:39:151245}
1246
[email protected]bcaf2272011-02-15 15:29:431247gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521248 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431249 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521250}
1251
[email protected]bee16aab2009-08-26 15:55:031252void RenderWidget::SetHidden(bool hidden) {
1253 if (is_hidden_ == hidden)
1254 return;
1255
1256 // The status has changed. Tell the RenderThread about it.
1257 is_hidden_ = hidden;
1258 if (is_hidden_)
1259 render_thread_->WidgetHidden();
1260 else
1261 render_thread_->WidgetRestored();
1262}
1263
[email protected]699ab0d2009-04-23 23:19:141264void RenderWidget::SetBackground(const SkBitmap& background) {
1265 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461266
[email protected]699ab0d2009-04-23 23:19:141267 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281268 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141269}
1270
[email protected]674741932009-02-04 23:44:461271bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051272 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461273}
1274
1275bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051276 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461277}
1278
1279void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051280 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461281}
1282
1283void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051284 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461285}
1286
1287void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051288 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461289}
1290
[email protected]fa7b1dc2010-06-23 17:53:041291void RenderWidget::UpdateInputMethod() {
1292 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291293 return;
[email protected]fa7b1dc2010-06-23 17:53:041294
[email protected]ad26ef42011-06-17 07:59:451295 ui::TextInputType new_type = GetTextInputType();
1296 bool new_can_compose_inline = CanComposeInline();
[email protected]fa7b1dc2010-06-23 17:53:041297 WebRect new_caret_bounds;
1298
[email protected]56ea1a62011-05-30 07:05:571299 if (webwidget_)
1300 new_caret_bounds = webwidget_->caretOrSelectionBounds();
[email protected]fa7b1dc2010-06-23 17:53:041301
1302 // Only sends text input type and caret bounds to the browser process if they
1303 // are changed.
[email protected]ad26ef42011-06-17 07:59:451304 if (text_input_type_ != new_type || caret_bounds_ != new_caret_bounds ||
1305 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041306 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451307 can_compose_inline_ = new_can_compose_inline;
[email protected]fa7b1dc2010-06-23 17:53:041308 caret_bounds_ = new_caret_bounds;
1309 Send(new ViewHostMsg_ImeUpdateTextInputState(
[email protected]ad26ef42011-06-17 07:59:451310 routing_id(), new_type, new_can_compose_inline, new_caret_bounds));
initial.commit09911bf2008-07-26 23:55:291311 }
initial.commit09911bf2008-07-26 23:55:291312}
1313
[email protected]ad26ef42011-06-17 07:59:451314COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1315 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1316COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1317 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1318COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1319 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
1320
1321ui::TextInputType RenderWidget::GetTextInputType() {
1322 if (webwidget_) {
1323 int type = webwidget_->textInputType();
1324 // Check the type is in the range representable by ui::TextInputType.
1325 DCHECK(type <= ui::TEXT_INPUT_TYPE_PASSWORD) <<
1326 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1327 return static_cast<ui::TextInputType>(type);
1328 }
1329 return ui::TEXT_INPUT_TYPE_NONE;
1330}
1331
1332bool RenderWidget::CanComposeInline() {
1333 return true;
[email protected]56ea1a62011-05-30 07:05:571334}
1335
[email protected]4873c7d2009-07-16 06:36:281336WebScreenInfo RenderWidget::screenInfo() {
1337 WebScreenInfo results;
1338 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results));
1339 return results;
1340}
1341
[email protected]fa7b1dc2010-06-23 17:53:041342void RenderWidget::resetInputMethod() {
1343 if (!input_method_is_active_)
1344 return;
1345
1346 // If the last text input type is not None, then we should finish any
1347 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451348 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041349 // If a composition text exists, then we need to let the browser process
1350 // to cancel the input method's ongoing composition session.
1351 if (webwidget_->confirmComposition())
1352 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1353 }
[email protected]d4cff272011-05-02 15:46:011354
1355 // Send an updated IME range with the current caret rect.
1356 ui::Range range(ui::Range::InvalidRange());
1357 size_t location, length;
1358 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1359 range.set_start(location);
1360 range.set_end(location + length);
1361 }
1362 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041363}
1364
[email protected]f103ab72009-09-02 17:10:591365void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501366 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291367 size_t i = 0;
1368 for (; i < plugin_window_moves_.size(); ++i) {
1369 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581370 if (move.rects_valid) {
1371 plugin_window_moves_[i] = move;
1372 } else {
1373 plugin_window_moves_[i].visible = move.visible;
1374 }
initial.commit09911bf2008-07-26 23:55:291375 break;
1376 }
1377 }
1378
1379 if (i == plugin_window_moves_.size())
1380 plugin_window_moves_.push_back(move);
1381}
[email protected]268654772009-08-06 23:02:041382
1383void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1384 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1385 i != plugin_window_moves_.end(); ++i) {
1386 if (i->window == window) {
1387 plugin_window_moves_.erase(i);
1388 break;
1389 }
1390 }
1391}