blob: 5d7cf89c45bc219c67a39c01903eee6377c02265 [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]8d6cba42011-09-02 10:05:1920#include "content/renderer/renderer_webkitplatformsupport_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]2d0f2e92011-10-03 09:02:2461using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0462using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1863using WebKit::WebWidget;
[email protected]62cb33cae2009-03-27 23:30:2264
[email protected]3e2b375b2010-04-07 17:03:1265RenderWidget::RenderWidget(RenderThreadBase* render_thread,
66 WebKit::WebPopupType popup_type)
initial.commit09911bf2008-07-26 23:55:2967 : routing_id_(MSG_ROUTING_NONE),
[email protected]c5b3b5e2009-02-13 06:41:1168 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2969 opener_id_(MSG_ROUTING_NONE),
[email protected]8085dbc82008-09-26 22:53:4470 render_thread_(render_thread),
[email protected]659f73f2009-10-13 13:43:4271 host_window_(0),
[email protected]b4d08452010-10-05 17:34:3572 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2973 next_paint_flags_(0),
[email protected]872ae5b2011-05-26 20:20:5074 filtered_time_per_frame_(1.0f/60.0f),
[email protected]53d3f302009-12-21 04:42:0575 update_reply_pending_(false),
[email protected]65225772011-05-12 21:10:2476 using_asynchronous_swapbuffers_(false),
77 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2978 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2979 is_hidden_(false),
80 needs_repainting_on_restore_(false),
81 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4982 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4883 closing_(false),
[email protected]992db4c2011-05-12 15:37:1584 is_swapped_out_(false),
[email protected]fa7b1dc2010-06-23 17:53:0485 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:4586 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
87 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:1288 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:4889 pending_window_rect_count_(0),
[email protected]edbcde932010-05-07 17:10:4690 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:5091 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:2192 animation_update_pending_(false),
[email protected]65225772011-05-12 21:10:2493 animation_task_posted_(false),
94 invalidation_task_posted_(false) {
[email protected]8930d472009-02-21 08:05:2895 RenderProcess::current()->AddRefProcess();
[email protected]8085dbc82008-09-26 22:53:4496 DCHECK(render_thread_);
[email protected]bd37ae252011-06-03 01:28:1897 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
98 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:2999}
100
101RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11102 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]b4d08452010-10-05 17:34:35103 if (current_paint_buf_) {
104 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
105 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29106 }
[email protected]992db4c2011-05-12 15:37:15107 // If we are swapped out, we have released already.
108 if (!is_swapped_out_)
109 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29110}
111
[email protected]484955942010-08-19 16:13:18112// static
[email protected]8085dbc82008-09-26 22:53:44113RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]0ebf3872008-11-07 21:35:03114 RenderThreadBase* render_thread,
[email protected]3e2b375b2010-04-07 17:03:12115 WebKit::WebPopupType popup_type) {
initial.commit09911bf2008-07-26 23:55:29116 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]ad8e04a2010-11-01 04:16:27117 scoped_refptr<RenderWidget> widget(new RenderWidget(render_thread,
118 popup_type));
initial.commit09911bf2008-07-26 23:55:29119 widget->Init(opener_id); // adds reference
120 return widget;
121}
122
[email protected]484955942010-08-19 16:13:18123// static
124WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
125 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03126 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18127 break;
128 case WebKit::WebPopupTypeSelect:
129 case WebKit::WebPopupTypeSuggestion:
130 return WebPopupMenu::create(render_widget);
131 default:
132 NOTREACHED();
133 }
134 return NULL;
135}
136
initial.commit09911bf2008-07-26 23:55:29137void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18138 DoInit(opener_id,
139 RenderWidget::CreateWebWidget(this),
140 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
141}
142
[email protected]484955942010-08-19 16:13:18143void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06144 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18145 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29146 DCHECK(!webwidget_);
147
148 if (opener_id != MSG_ROUTING_NONE)
149 opener_id_ = opener_id;
150
[email protected]484955942010-08-19 16:13:18151 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29152
[email protected]484955942010-08-19 16:13:18153 bool result = render_thread_->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29154 if (result) {
[email protected]8085dbc82008-09-26 22:53:44155 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29156 // Take a reference on behalf of the RenderThread. This will be balanced
157 // when we receive ViewMsg_Close.
158 AddRef();
159 } else {
160 DCHECK(false);
161 }
162}
163
164// This is used to complete pending inits and non-pending inits. For non-
165// pending cases, the parent will be the same as the current parent. This
166// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55167void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29168 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29169
170 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29171
[email protected]6de74452009-02-25 18:04:59172 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29173}
174
[email protected]992db4c2011-05-12 15:37:15175void RenderWidget::SetSwappedOut(bool is_swapped_out) {
176 // We should only toggle between states.
177 DCHECK(is_swapped_out_ != is_swapped_out);
178 is_swapped_out_ = is_swapped_out;
179
180 // If we are swapping out, we will call ReleaseProcess, allowing the process
181 // to exit if all of its RenderViews are swapped out. We wait until the
182 // WasSwappedOut call to do this, to avoid showing the sad tab.
183 // If we are swapping in, we call AddRefProcess to prevent the process from
184 // exiting.
185 if (!is_swapped_out)
186 RenderProcess::current()->AddRefProcess();
187}
188
[email protected]a95986a82010-12-24 06:19:28189bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
190 bool handled = true;
191 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
192 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
193 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
194 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
195 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
196 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15197 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28198 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
199 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
200 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
201 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
202 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
203 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
204 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
205 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
206 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
207 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
208 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[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
[email protected]67bfb83f2011-09-22 03:36:37450 bool prevent_default = false;
451 if (WebInputEvent::isMouseEventType(input_event->type)) {
452 prevent_default = WillHandleMouseEvent(
453 *(static_cast<const WebMouseEvent*>(input_event)));
454 }
455
456 bool processed = prevent_default;
[email protected]867125a02009-12-10 06:01:48457 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
458 suppress_next_char_events_ = false;
[email protected]67bfb83f2011-09-22 03:36:37459 if (!processed && webwidget_)
[email protected]867125a02009-12-10 06:01:48460 processed = webwidget_->handleInputEvent(*input_event);
461 }
462
463 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
464 // it's not processed by webkit, then we need to suppress the upcoming Char
465 // events.
466 if (!processed && is_keyboard_shortcut)
467 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29468
469 IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_);
470 response->WriteInt(input_event->type);
[email protected]e2824412009-02-27 01:57:05471 response->WriteBool(processed);
472
[email protected]353a34c2010-05-28 23:35:17473 if ((input_event->type == WebInputEvent::MouseMove ||
[email protected]d93fc462011-03-14 23:03:03474 input_event->type == WebInputEvent::MouseWheel ||
475 input_event->type == WebInputEvent::TouchMove) &&
[email protected]552e6002009-11-19 05:24:57476 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24477 // We want to rate limit the input events in this case, so we'll wait for
478 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17479 if (pending_input_event_ack_.get()) {
480 // As two different kinds of events could cause us to postpone an ack
481 // we send it now, if we have one pending. The Browser should never
482 // send us the same kind of event we are delaying the ack for.
483 Send(pending_input_event_ack_.release());
484 }
[email protected]12fbad812009-09-01 18:21:24485 pending_input_event_ack_.reset(response);
486 } else {
487 Send(response);
488 }
489
[email protected]5dd768212009-08-13 23:34:49490 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48491
[email protected]67bfb83f2011-09-22 03:36:37492 if (!prevent_default) {
493 if (WebInputEvent::isKeyboardEventType(input_event->type))
494 DidHandleKeyEvent();
495 if (WebInputEvent::isMouseEventType(input_event->type))
496 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24497 if (WebInputEvent::isTouchEventType(input_event->type))
498 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37499 }
initial.commit09911bf2008-07-26 23:55:29500}
501
502void RenderWidget::OnMouseCaptureLost() {
503 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28504 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29505}
506
507void RenderWidget::OnSetFocus(bool enable) {
508 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33509 if (webwidget_)
510 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29511}
512
513void RenderWidget::ClearFocus() {
514 // We may have got the focus from the browser before this gets processed, in
515 // which case we do not want to unfocus ourself.
516 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28517 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29518}
519
[email protected]2d5d09d52009-06-15 14:29:21520void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00521 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21522 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06523 TRACE_EVENT2("renderer", "PaintRect",
524 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00525 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21526
527 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00528 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
529 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03530
[email protected]699ab0d2009-04-23 23:19:14531 // If there is a custom background, tile it.
532 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14533 SkPaint paint;
534 SkShader* shader = SkShader::CreateBitmapShader(background_,
535 SkShader::kRepeat_TileMode,
536 SkShader::kRepeat_TileMode);
537 paint.setShader(shader)->unref();
[email protected]8860e4f52009-06-25 01:01:52538 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
[email protected]699ab0d2009-04-23 23:19:14539 canvas->drawPaint(paint);
[email protected]699ab0d2009-04-23 23:19:14540 }
541
[email protected]719b36f2010-12-22 20:36:46542 // First see if this rect is a plugin that can paint itself faster.
543 TransportDIB* optimized_dib = NULL;
544 gfx::Rect optimized_copy_rect, optimized_copy_location;
545 webkit::ppapi::PluginInstance* optimized_instance =
546 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
547 &optimized_copy_location,
548 &optimized_copy_rect);
549 if (optimized_instance) {
550 // This plugin can be optimize-painted and we can just ask it to paint
551 // itself. We don't actually need the TransportDIB in this case.
552 //
553 // This is an optimization for PPAPI plugins that know they're on top of
554 // the page content. If this rect is inside such a plugin, we can save some
555 // time and avoid re-rendering the page content which we know will be
556 // covered by the plugin later (this time can be significant, especially
557 // for a playing movie that is invalidating a lot).
558 //
559 // In the plugin movie case, hopefully the similar call to
560 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
561 // painting, because that avoids copying the plugin image to a different
562 // paint rect. Unfortunately, if anything on the page is animating other
563 // than the movie, it break this optimization since the union of the
564 // invalid regions will be larger than the plugin.
565 //
566 // This code optimizes that case, where we can still avoid painting in
567 // WebKit and filling the background (which can be slow) and just painting
568 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
569 // required.
570 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27571 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46572 } else {
573 // Normal painting case.
574 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
575
576 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35577 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46578 }
initial.commit09911bf2008-07-26 23:55:29579
[email protected]4fb66842009-12-04 21:41:00580 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00581 canvas->restore();
582}
583
584void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
585 skia::PlatformCanvas* canvas) {
586 static bool kPaintBorder =
587 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
588 if (!kPaintBorder)
589 return;
590
[email protected]53d3f302009-12-21 04:42:05591 // Cycle through these colors to help distinguish new paint rects.
592 const SkColor colors[] = {
593 SkColorSetARGB(0x3F, 0xFF, 0, 0),
594 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
595 SkColorSetARGB(0x3F, 0, 0, 0xFF),
596 };
597 static int color_selector = 0;
598
[email protected]4fb66842009-12-04 21:41:00599 SkPaint paint;
600 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05601 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00602 paint.setStrokeWidth(1);
603
604 SkIRect irect;
605 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
606 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29607}
608
[email protected]52ccd0ea2011-02-16 01:09:05609void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30610 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]52ccd0ea2011-02-16 01:09:05611 animation_task_posted_ = false;
[email protected]921244e42011-07-20 16:36:30612 if (!animation_update_pending_) {
613 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59614 return;
[email protected]921244e42011-07-20 16:36:30615 }
[email protected]bd37ae252011-06-03 01:28:18616 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59617 // Record when we fired (according to base::Time::Now()) relative to when
618 // we posted the task to quantify how much the base::Time/base::TimeTicks
619 // skew is affecting animations.
620 base::TimeDelta animation_callback_delay = base::Time::Now() -
621 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
622 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
623 animation_callback_delay,
624 base::TimeDelta::FromMilliseconds(0),
625 base::TimeDelta::FromMilliseconds(30),
626 25);
627 }
[email protected]65225772011-05-12 21:10:24628 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24629}
630
[email protected]52ccd0ea2011-02-16 01:09:05631void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59632 if (!animation_update_pending_)
633 return;
[email protected]bd37ae252011-06-03 01:28:18634
635 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
636 int animationInterval = IsRenderingVSynced() ? 16 : 0;
637
[email protected]7c4329e2011-02-18 22:02:59638 base::Time now = base::Time::Now();
639 if (now >= animation_floor_time_) {
[email protected]921244e42011-07-20 16:36:30640 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]bd37ae252011-06-03 01:28:18641 animation_floor_time_ = now +
642 base::TimeDelta::FromMilliseconds(animationInterval);
643 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59644 // running animation callbacks so that if a callback requests another
645 // we'll be sure to run it at the proper time.
646 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(
[email protected]bd37ae252011-06-03 01:28:18647 this, &RenderWidget::AnimationCallback), animationInterval);
[email protected]7c4329e2011-02-18 22:02:59648 animation_task_posted_ = true;
649 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30650 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59651 return;
[email protected]5f8b1022011-01-21 23:34:50652 }
[email protected]bd37ae252011-06-03 01:28:18653 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]7c4329e2011-02-18 22:02:59654 if (animation_task_posted_)
655 return;
656 // This code uses base::Time::Now() to calculate the floor and next fire
657 // time because javascript's Date object uses base::Time::Now(). The
658 // message loop uses base::TimeTicks, which on windows can have a
659 // different granularity than base::Time.
660 // The upshot of all this is that this function might be called before
661 // base::Time::Now() has advanced past the animation_floor_time_. To
662 // avoid exposing this delay to javascript, we keep posting delayed
663 // tasks until base::Time::Now() has advanced far enough.
664 int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp();
665 animation_task_posted_ = true;
666 MessageLoop::current()->PostDelayedTask(FROM_HERE,
667 NewRunnableMethod(this, &RenderWidget::AnimationCallback), delay);
[email protected]5f8b1022011-01-21 23:34:50668}
669
[email protected]bd37ae252011-06-03 01:28:18670bool RenderWidget::IsRenderingVSynced() {
671 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
672 // not caught by this check. This will lead to artificially low frame rates
673 // for people who force vsync off at a driver level and expect Chrome to speed
674 // up.
675 return !has_disable_gpu_vsync_switch_;
676}
677
[email protected]65225772011-05-12 21:10:24678void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06679 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24680 invalidation_task_posted_ = false;
681 DoDeferredUpdateAndSendInputAck();
682}
683
684void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05685 DoDeferredUpdate();
686
687 if (pending_input_event_ack_.get())
688 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21689}
690
[email protected]552e6002009-11-19 05:24:57691void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58692 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08693
[email protected]65225772011-05-12 21:10:24694 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29695 return;
[email protected]65225772011-05-12 21:10:24696 if (update_reply_pending()) {
697 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
698 return;
699 }
[email protected]9ca84622011-06-02 23:46:39700 if (is_accelerated_compositing_active_ &&
701 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24702 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
703 return;
704 }
initial.commit09911bf2008-07-26 23:55:29705
[email protected]552e6002009-11-19 05:24:57706 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29707 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57708 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29709 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24710 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29711 return;
712 }
713
[email protected]0fb93f52011-05-18 23:13:56714 // Tracking of frame rate jitter
715 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]52ccd0ea2011-02-16 01:09:05716 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50717
[email protected]f98d7e3c2010-09-13 22:30:46718 // Layout may generate more invalidation. It may also enable the
719 // GPU acceleration, so make sure to run layout before we send the
720 // GpuRenderingActivated message.
721 webwidget_->layout();
722
[email protected]5f8b1022011-01-21 23:34:50723 // Suppress painting if nothing is dirty. This has to be done after updating
724 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24725 if (!paint_aggregator_.HasPendingUpdate()) {
726 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]5f8b1022011-01-21 23:34:50727 return;
[email protected]65225772011-05-12 21:10:24728 }
[email protected]5f8b1022011-01-21 23:34:50729
[email protected]872ae5b2011-05-26 20:20:50730 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56731 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
732 if(is_accelerated_compositing_active_)
733 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
734 delay,
735 base::TimeDelta::FromMilliseconds(1),
736 base::TimeDelta::FromMilliseconds(60),
737 30);
738 else
739 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
740 delay,
741 base::TimeDelta::FromMilliseconds(1),
742 base::TimeDelta::FromMilliseconds(60),
743 30);
[email protected]872ae5b2011-05-26 20:20:50744
745 // Calculate filtered time per frame:
746 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
747 filtered_time_per_frame_ =
748 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56749 }
750 last_do_deferred_update_time_ = frame_begin_ticks;
751
[email protected]552e6002009-11-19 05:24:57752 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29753 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30754 PaintAggregator::PendingUpdate update;
755 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29756
[email protected]53d3f302009-12-21 04:42:05757 gfx::Rect scroll_damage = update.GetScrollDamage();
758 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29759
[email protected]27543452011-03-25 00:14:00760 // Compositing the page may disable accelerated compositing.
761 bool accelerated_compositing_was_active = is_accelerated_compositing_active_;
762
[email protected]ca4847f2010-09-24 05:39:15763 // A plugin may be able to do an optimized paint. First check this, in which
764 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46765 // This optimization allows PPAPI plugins that declare themselves on top of
766 // the page (like a traditional windowed plugin) to be able to animate (think
767 // movie playing) without repeatedly re-painting the page underneath, or
768 // copying the plugin backing store (since we can send the plugin's backing
769 // store directly to the browser).
770 //
771 // This optimization only works when the entire invalid region is contained
772 // within the plugin. There is a related optimization in PaintRect for the
773 // case where there may be multiple invalid regions.
[email protected]2650bd52011-03-25 00:34:44774 TransportDIB::Id dib_id = TransportDIB::Id();
[email protected]ca4847f2010-09-24 05:39:15775 TransportDIB* dib = NULL;
[email protected]cef3362f2009-12-21 17:48:45776 std::vector<gfx::Rect> copy_rects;
[email protected]ca4847f2010-09-24 05:39:15777 gfx::Rect optimized_copy_rect, optimized_copy_location;
778 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56779 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15780 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
781 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27782 // Only update the part of the plugin that actually changed.
783 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]ca4847f2010-09-24 05:39:15784 bounds = optimized_copy_location;
785 copy_rects.push_back(optimized_copy_rect);
786 dib_id = dib->id();
[email protected]a79d8a632010-11-18 22:35:56787 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46788 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15789 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35790 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
791 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46792 if (!canvas.get()) {
793 NOTREACHED();
794 return;
795 }
[email protected]cef3362f2009-12-21 17:48:45796
[email protected]f98d7e3c2010-09-13 22:30:46797 // We may get back a smaller canvas than we asked for.
798 // TODO(darin): This seems like it could cause painting problems!
799 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
800 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
801 bounds.set_width(canvas->getDevice()->width());
802 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05803
[email protected]f98d7e3c2010-09-13 22:30:46804 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
805
[email protected]f98d7e3c2010-09-13 22:30:46806 // The scroll damage is just another rectangle to paint and copy.
807 copy_rects.swap(update.paint_rects);
808 if (!scroll_damage.IsEmpty())
809 copy_rects.push_back(scroll_damage);
810
811 for (size_t i = 0; i < copy_rects.size(); ++i)
812 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]ca4847f2010-09-24 05:39:15813
[email protected]b4d08452010-10-05 17:34:35814 dib_id = current_paint_buf_->id();
[email protected]f98d7e3c2010-09-13 22:30:46815 } else { // Accelerated compositing path
816 // Begin painting.
[email protected]50bd6452010-11-27 19:39:42817 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46818 }
819
820 // sending an ack to browser process that the paint is complete...
[email protected]53d3f302009-12-21 04:42:05821 ViewHostMsg_UpdateRect_Params params;
[email protected]36808ad2010-10-20 19:18:30822 params.bitmap = dib_id;
[email protected]53d3f302009-12-21 04:42:05823 params.bitmap_rect = bounds;
824 params.dx = update.scroll_delta.x();
825 params.dy = update.scroll_delta.y();
[email protected]27543452011-03-25 00:14:00826 if (accelerated_compositing_was_active) {
[email protected]b167ca662010-05-14 00:05:34827 // If painting is done via the gpu process then we clear out all damage
828 // rects to save the browser process from doing unecessary work.
829 params.scroll_rect = gfx::Rect();
830 params.copy_rects.clear();
831 } else {
832 params.scroll_rect = update.scroll_rect;
833 params.copy_rects.swap(copy_rects); // TODO(darin): clip to bounds?
834 }
[email protected]53d3f302009-12-21 04:42:05835 params.view_size = size_;
[email protected]e2356242010-11-16 22:33:03836 params.resizer_rect = resizer_rect_;
[email protected]53d3f302009-12-21 04:42:05837 params.plugin_window_moves.swap(plugin_window_moves_);
838 params.flags = next_paint_flags_;
[email protected]d54169e92011-01-21 09:19:52839 params.scroll_offset = GetScrollOffset();
[email protected]53d3f302009-12-21 04:42:05840
841 update_reply_pending_ = true;
842 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
843 next_paint_flags_ = 0;
844
[email protected]fa7b1dc2010-06-23 17:53:04845 UpdateInputMethod();
[email protected]00c39612010-03-06 02:53:28846
847 // Let derived classes know we've painted.
848 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29849}
850
851///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:46852// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:29853
[email protected]4873c7d2009-07-16 06:36:28854void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:57855 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48856 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57857 gfx::Rect damaged_rect = view_rect.Intersect(rect);
858 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29859 return;
860
[email protected]552e6002009-11-19 05:24:57861 paint_aggregator_.InvalidateRect(damaged_rect);
862
863 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:24864 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:57865 return;
866 if (!paint_aggregator_.HasPendingUpdate())
867 return;
[email protected]65225772011-05-12 21:10:24868 if (update_reply_pending() ||
869 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
870 return;
871
872 // When GPU rendering, combine pending animations and invalidations into
873 // a single update.
874 if (is_accelerated_compositing_active_ && animation_task_posted_)
[email protected]552e6002009-11-19 05:24:57875 return;
876
877 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:29878 // 1) Ensures that we call WebView::Paint without a bunch of other junk
879 // on the call stack.
880 // 2) Allows us to collect more damage rects before painting to help coalesce
881 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:24882 invalidation_task_posted_ = true;
initial.commit09911bf2008-07-26 23:55:29883 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]65225772011-05-12 21:10:24884 this, &RenderWidget::InvalidationCallback));
initial.commit09911bf2008-07-26 23:55:29885}
886
[email protected]4873c7d2009-07-16 06:36:28887void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:46888 // Drop scrolls on the floor when we are in compositing mode.
889 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:56890 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:46891 return;
892
[email protected]552e6002009-11-19 05:24:57893 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48894 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57895 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
896 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29897 return;
898
[email protected]552e6002009-11-19 05:24:57899 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
900
901 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:24902 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:57903 return;
904 if (!paint_aggregator_.HasPendingUpdate())
905 return;
[email protected]65225772011-05-12 21:10:24906 if (update_reply_pending() ||
907 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
908 return;
909
910 // When GPU rendering, combine pending animations and invalidations into
911 // a single update.
912 if (is_accelerated_compositing_active_ && animation_task_posted_)
[email protected]552e6002009-11-19 05:24:57913 return;
914
915 // Perform updating asynchronously. This serves two purposes:
916 // 1) Ensures that we call WebView::Paint without a bunch of other junk
917 // on the call stack.
918 // 2) Allows us to collect more damage rects before painting to help coalesce
919 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:24920 invalidation_task_posted_ = true;
initial.commit09911bf2008-07-26 23:55:29921 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]65225772011-05-12 21:10:24922 this, &RenderWidget::InvalidationCallback));
initial.commit09911bf2008-07-26 23:55:29923}
924
[email protected]ea162f92011-10-04 23:08:22925void RenderWidget::didActivateCompositor(int compositorIdentifier) {
926 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
927
928 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:42929 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:24930 routing_id_, is_accelerated_compositing_active_));
931
[email protected]5834f4392011-09-13 20:06:17932#ifndef WTF_USE_THREADED_COMPOSITING
[email protected]ea162f92011-10-04 23:08:22933 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
934#endif
935}
936
937void RenderWidget::didDeactivateCompositor() {
938 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
939
940 is_accelerated_compositing_active_ = false;
941 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
942 routing_id_, is_accelerated_compositing_active_));
943
944#ifndef WTF_USE_THREADED_COMPOSITING
945 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:24946 using_asynchronous_swapbuffers_ = false;
[email protected]5834f4392011-09-13 20:06:17947#endif
[email protected]a79d8a632010-11-18 22:35:56948}
949
[email protected]f98d7e3c2010-09-13 22:30:46950void RenderWidget::scheduleComposite() {
[email protected]a5922cc2011-05-24 23:06:30951#if WTF_USE_THREADED_COMPOSITING
952 NOTREACHED();
953#else
[email protected]f98d7e3c2010-09-13 22:30:46954 // TODO(nduca): replace with something a little less hacky. The reason this
955 // hack is still used is because the Invalidate-DoDeferredUpdate loop
956 // contains a lot of host-renderer synchronization logic that is still
957 // important for the accelerated compositing case. The option of simply
958 // duplicating all that code is less desirable than "faking out" the
959 // invalidation path using a magical damage rect.
[email protected]e2356242010-11-16 22:33:03960 didInvalidateRect(WebRect(0, 0, 1, 1));
[email protected]a5922cc2011-05-24 23:06:30961#endif
[email protected]f98d7e3c2010-09-13 22:30:46962}
963
[email protected]5f8b1022011-01-21 23:34:50964void RenderWidget::scheduleAnimation() {
[email protected]921244e42011-07-20 16:36:30965 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ee3d3ad2011-02-04 00:42:21966 if (!animation_update_pending_) {
967 animation_update_pending_ = true;
[email protected]52ccd0ea2011-02-16 01:09:05968 if (!animation_task_posted_) {
969 animation_task_posted_ = true;
970 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
971 this, &RenderWidget::AnimationCallback));
972 }
[email protected]ee3d3ad2011-02-04 00:42:21973 }
[email protected]5f8b1022011-01-21 23:34:50974}
975
[email protected]4873c7d2009-07-16 06:36:28976void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:30977 // TODO(darin): Eliminate this temporary.
978 WebCursor cursor(cursor_info);
979
initial.commit09911bf2008-07-26 23:55:29980 // Only send a SetCursor message if we need to make a change.
981 if (!current_cursor_.IsEqual(cursor)) {
982 current_cursor_ = cursor;
983 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
984 }
985}
986
987// We are supposed to get a single call to Show for a newly created RenderWidget
988// that was created via RenderWidget::CreateWebView. So, we wait until this
989// point to dispatch the ShowWidget message.
990//
991// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:28992// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:29993//
[email protected]4873c7d2009-07-16 06:36:28994void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:29995 DCHECK(!did_show_) << "received extraneous Show call";
996 DCHECK(routing_id_ != MSG_ROUTING_NONE);
997 DCHECK(opener_id_ != MSG_ROUTING_NONE);
998
[email protected]8de12d942010-11-17 20:42:44999 if (did_show_)
1000 return;
1001
1002 did_show_ = true;
1003 // NOTE: initial_pos_ may still have its default values at this point, but
1004 // that's okay. It'll be ignored if as_popup is false, or the browser
1005 // process will impose a default position otherwise.
1006 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1007 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291008}
1009
[email protected]4873c7d2009-07-16 06:36:281010void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291011}
1012
[email protected]4873c7d2009-07-16 06:36:281013void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291014}
1015
[email protected]2533ce12009-05-09 00:02:241016void RenderWidget::DoDeferredClose() {
1017 Send(new ViewHostMsg_Close(routing_id_));
1018}
1019
[email protected]4873c7d2009-07-16 06:36:281020void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291021 // If a page calls window.close() twice, we'll end up here twice, but that's
1022 // OK. It is safe to send multiple Close messages.
1023
[email protected]2533ce12009-05-09 00:02:241024 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1025 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1026 // could be closed before the JS finishes executing. So instead, post a
1027 // message back to the message loop, which won't run until the JS is
1028 // complete, and then the Close message can be sent.
[email protected]75ae4492009-07-10 00:05:151029 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
[email protected]2533ce12009-05-09 00:02:241030 this, &RenderWidget::DoDeferredClose));
initial.commit09911bf2008-07-26 23:55:291031}
1032
1033void RenderWidget::Close() {
1034 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281035 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291036 webwidget_ = NULL;
1037 }
1038}
1039
[email protected]4873c7d2009-07-16 06:36:281040WebRect RenderWidget::windowRect() {
1041 if (pending_window_rect_count_)
1042 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241043
[email protected]b3f2b912009-04-09 16:18:521044 gfx::Rect rect;
1045 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281046 return rect;
initial.commit09911bf2008-07-26 23:55:291047}
1048
[email protected]8a9d6ca32011-06-06 20:11:301049void RenderWidget::setToolTipText(const WebKit::WebString& text,
1050 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541051 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301052}
1053
[email protected]4873c7d2009-07-16 06:36:281054void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291055 if (did_show_) {
1056 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241057 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291058 } else {
1059 initial_pos_ = pos;
1060 }
1061}
1062
[email protected]2533ce12009-05-09 00:02:241063void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1064 pending_window_rect_ = rect;
1065 pending_window_rect_count_++;
1066}
1067
[email protected]4873c7d2009-07-16 06:36:281068WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241069 if (pending_window_rect_count_) {
1070 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1071 // the RootWindowRect is probably going to return wrong results since the
1072 // browser may not have processed the Move yet. There isn't really anything
1073 // good to do in this case, and it shouldn't happen - since this size is
1074 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281075 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241076 }
1077
[email protected]b3f2b912009-04-09 16:18:521078 gfx::Rect rect;
1079 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281080 return rect;
[email protected]d4547452008-08-28 18:36:371081}
1082
[email protected]4873c7d2009-07-16 06:36:281083WebRect RenderWidget::windowResizerRect() {
1084 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191085}
1086
[email protected]fa7b1dc2010-06-23 17:53:041087void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031088 // To prevent this renderer process from sending unnecessary IPC messages to
1089 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041090 // only during the input method attached to the browser process is active.
1091 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291092}
1093
[email protected]fa7b1dc2010-06-23 17:53:041094void RenderWidget::OnImeSetComposition(
1095 const string16& text,
1096 const std::vector<WebCompositionUnderline>& underlines,
1097 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281098 if (!webwidget_)
1099 return;
[email protected]d4cff272011-05-02 15:46:011100 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041101 text, WebVector<WebCompositionUnderline>(underlines),
1102 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011103 // Setting the IME composition was successful. Send the new composition
1104 // range to the browser.
1105 ui::Range range(ui::Range::InvalidRange());
1106 size_t location, length;
1107 if (webwidget_->compositionRange(&location, &length)) {
1108 range.set_start(location);
1109 range.set_end(location + length);
1110 }
1111 // The IME was cancelled via the Esc key, so just send back the caret.
1112 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1113 range.set_start(location);
1114 range.set_end(location + length);
1115 }
1116 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1117 } else {
[email protected]fa7b1dc2010-06-23 17:53:041118 // If we failed to set the composition text, then we need to let the browser
1119 // process to cancel the input method's ongoing composition session, to make
1120 // sure we are in a consistent state.
1121 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011122
1123 // Send an updated IME range with just the caret range.
1124 ui::Range range(ui::Range::InvalidRange());
1125 size_t location, length;
1126 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1127 range.set_start(location);
1128 range.set_end(location + length);
1129 }
1130 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261131 }
[email protected]fa7b1dc2010-06-23 17:53:041132}
1133
[email protected]6b349652011-01-05 18:36:241134void RenderWidget::OnImeConfirmComposition(const string16& text) {
[email protected]fa7b1dc2010-06-23 17:53:041135 if (webwidget_)
[email protected]6b349652011-01-05 18:36:241136 webwidget_->confirmComposition(text);
[email protected]d4cff272011-05-02 15:46:011137 // Send an updated IME range with just the caret range.
1138 ui::Range range(ui::Range::InvalidRange());
1139 size_t location, length;
1140 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1141 range.set_start(location);
1142 range.set_end(location + length);
1143 }
1144 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291145}
1146
[email protected]948f7ab72010-05-28 23:48:081147// This message causes the renderer to render an image of the
1148// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491149void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091150 int tag,
[email protected]948f7ab72010-05-28 23:48:081151 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491152 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001153 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1154 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251155 // Close our unused handle.
1156#if defined(OS_WIN)
1157 ::CloseHandle(dib_handle);
1158#elif defined(OS_MACOSX)
1159 base::SharedMemory::CloseHandle(dib_handle);
1160#endif
1161 }
[email protected]d65adb12010-04-28 17:26:491162 return;
[email protected]45c6aad32010-11-11 04:46:251163 }
[email protected]d65adb12010-04-28 17:26:491164
[email protected]948f7ab72010-05-28 23:48:081165 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491166 // If one of these is empty, then we just return the dib we were
1167 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091168 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491169 return;
1170 }
1171
1172 // Map the given DIB ID into this process, and unmap it at the end
1173 // of this function.
[email protected]45c6aad32010-11-11 04:46:251174 scoped_ptr<TransportDIB> paint_at_size_buffer(
1175 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301176
1177 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491178 float x_scale = static_cast<float>(desired_size.width()) /
1179 static_cast<float>(canvas_size.width());
1180 float y_scale = static_cast<float>(desired_size.height()) /
1181 static_cast<float>(canvas_size.height());
1182
[email protected]ee8d6fd2010-05-26 17:05:481183 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491184 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1185 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481186 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491187
[email protected]36808ad2010-10-20 19:18:301188 scoped_ptr<skia::PlatformCanvas> canvas(
1189 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1190 canvas_size.height()));
1191 if (!canvas.get()) {
1192 NOTREACHED();
1193 return;
1194 }
1195
[email protected]d65adb12010-04-28 17:26:491196 // Reset bounds to what we actually received, but they should be the
1197 // same.
1198 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1199 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1200 bounds.set_width(canvas->getDevice()->width());
1201 bounds.set_height(canvas->getDevice()->height());
1202
1203 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081204 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491205 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1206
[email protected]948f7ab72010-05-28 23:48:081207 // Have to make sure we're laid out at the right size before
1208 // rendering.
1209 gfx::Size old_size = webwidget_->size();
1210 webwidget_->resize(page_size);
1211 webwidget_->layout();
1212
[email protected]d65adb12010-04-28 17:26:491213 // Paint the entire thing (using original bounds, not scaled bounds).
1214 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1215 canvas->restore();
1216
[email protected]948f7ab72010-05-28 23:48:081217 // Return the widget to its previous size.
1218 webwidget_->resize(old_size);
1219
[email protected]c88c9442010-07-19 18:55:091220 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491221}
1222
[email protected]ec7dc112008-08-06 05:30:121223void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1224 // During shutdown we can just ignore this message.
1225 if (!webwidget_)
1226 return;
1227
1228 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561229 if (is_accelerated_compositing_active_) {
[email protected]a5922cc2011-05-24 23:06:301230#ifndef WTF_USE_THREADED_COMPOSITING
[email protected]f98d7e3c2010-09-13 22:30:461231 scheduleComposite();
[email protected]a5922cc2011-05-24 23:06:301232#else
1233#ifdef WEBWIDGET_HAS_THREADED_COMPOSITING_CHANGES
1234 webwidget_->composite(false);
1235#endif
1236#endif
[email protected]f98d7e3c2010-09-13 22:30:461237 } else {
1238 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1239 didInvalidateRect(repaint_rect);
1240 }
[email protected]ec7dc112008-08-06 05:30:121241}
1242
[email protected]4873c7d2009-07-16 06:36:281243void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111244 if (!webwidget_)
1245 return;
[email protected]4873c7d2009-07-16 06:36:281246 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111247}
1248
[email protected]719b36f2010-12-22 20:36:461249webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151250 const gfx::Rect& paint_bounds,
1251 TransportDIB** dib,
1252 gfx::Rect* location,
1253 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461254 // Bare RenderWidgets don't support optimized plugin painting.
1255 return NULL;
[email protected]ca4847f2010-09-24 05:39:151256}
1257
[email protected]bcaf2272011-02-15 15:29:431258gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521259 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431260 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521261}
1262
[email protected]bee16aab2009-08-26 15:55:031263void RenderWidget::SetHidden(bool hidden) {
1264 if (is_hidden_ == hidden)
1265 return;
1266
1267 // The status has changed. Tell the RenderThread about it.
1268 is_hidden_ = hidden;
1269 if (is_hidden_)
1270 render_thread_->WidgetHidden();
1271 else
1272 render_thread_->WidgetRestored();
1273}
1274
[email protected]699ab0d2009-04-23 23:19:141275void RenderWidget::SetBackground(const SkBitmap& background) {
1276 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461277
[email protected]699ab0d2009-04-23 23:19:141278 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281279 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141280}
1281
[email protected]674741932009-02-04 23:44:461282bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051283 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461284}
1285
1286bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051287 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461288}
1289
1290void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051291 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461292}
1293
1294void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051295 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461296}
1297
1298void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051299 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461300}
1301
[email protected]fa7b1dc2010-06-23 17:53:041302void RenderWidget::UpdateInputMethod() {
1303 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291304 return;
[email protected]fa7b1dc2010-06-23 17:53:041305
[email protected]ad26ef42011-06-17 07:59:451306 ui::TextInputType new_type = GetTextInputType();
1307 bool new_can_compose_inline = CanComposeInline();
[email protected]fa7b1dc2010-06-23 17:53:041308 WebRect new_caret_bounds;
1309
[email protected]56ea1a62011-05-30 07:05:571310 if (webwidget_)
1311 new_caret_bounds = webwidget_->caretOrSelectionBounds();
[email protected]fa7b1dc2010-06-23 17:53:041312
1313 // Only sends text input type and caret bounds to the browser process if they
1314 // are changed.
[email protected]ad26ef42011-06-17 07:59:451315 if (text_input_type_ != new_type || caret_bounds_ != new_caret_bounds ||
1316 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041317 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451318 can_compose_inline_ = new_can_compose_inline;
[email protected]fa7b1dc2010-06-23 17:53:041319 caret_bounds_ = new_caret_bounds;
1320 Send(new ViewHostMsg_ImeUpdateTextInputState(
[email protected]ad26ef42011-06-17 07:59:451321 routing_id(), new_type, new_can_compose_inline, new_caret_bounds));
initial.commit09911bf2008-07-26 23:55:291322 }
initial.commit09911bf2008-07-26 23:55:291323}
1324
[email protected]ad26ef42011-06-17 07:59:451325COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1326 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1327COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1328 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1329COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1330 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181331COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1332 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1333COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1334 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1335COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1336 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1337COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1338 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1339COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1340 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451341
1342ui::TextInputType RenderWidget::GetTextInputType() {
1343 if (webwidget_) {
1344 int type = webwidget_->textInputType();
1345 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181346 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451347 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1348 return static_cast<ui::TextInputType>(type);
1349 }
1350 return ui::TEXT_INPUT_TYPE_NONE;
1351}
1352
1353bool RenderWidget::CanComposeInline() {
1354 return true;
[email protected]56ea1a62011-05-30 07:05:571355}
1356
[email protected]4873c7d2009-07-16 06:36:281357WebScreenInfo RenderWidget::screenInfo() {
1358 WebScreenInfo results;
1359 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results));
1360 return results;
1361}
1362
[email protected]fa7b1dc2010-06-23 17:53:041363void RenderWidget::resetInputMethod() {
1364 if (!input_method_is_active_)
1365 return;
1366
1367 // If the last text input type is not None, then we should finish any
1368 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451369 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041370 // If a composition text exists, then we need to let the browser process
1371 // to cancel the input method's ongoing composition session.
1372 if (webwidget_->confirmComposition())
1373 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1374 }
[email protected]d4cff272011-05-02 15:46:011375
1376 // Send an updated IME range with the current caret rect.
1377 ui::Range range(ui::Range::InvalidRange());
1378 size_t location, length;
1379 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1380 range.set_start(location);
1381 range.set_end(location + length);
1382 }
1383 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041384}
1385
[email protected]f103ab72009-09-02 17:10:591386void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501387 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291388 size_t i = 0;
1389 for (; i < plugin_window_moves_.size(); ++i) {
1390 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581391 if (move.rects_valid) {
1392 plugin_window_moves_[i] = move;
1393 } else {
1394 plugin_window_moves_[i].visible = move.visible;
1395 }
initial.commit09911bf2008-07-26 23:55:291396 break;
1397 }
1398 }
1399
1400 if (i == plugin_window_moves_.size())
1401 plugin_window_moves_.push_back(move);
1402}
[email protected]268654772009-08-06 23:02:041403
1404void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1405 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1406 i != plugin_window_moves_.end(); ++i) {
1407 if (i->window == window) {
1408 plugin_window_moves_.erase(i);
1409 break;
1410 }
1411 }
1412}
[email protected]67bfb83f2011-09-22 03:36:371413
1414bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1415 return false;
1416}