blob: 12cad673523e1ce468b9ed67990fc7878b2cd35c [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]32876ae2011-11-15 22:25:217#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:008#include "base/command_line.h"
[email protected]366ae242011-05-10 02:23:589#include "base/debug/trace_event.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2114#include "base/stl_util.h"
[email protected]8a9d6ca32011-06-06 20:11:3015#include "base/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4816#include "build/build_config.h"
[email protected]992db4c2011-05-12 15:37:1517#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5018#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2919#include "content/public/common/content_switches.h"
[email protected]8704f89b2011-04-15 00:30:0520#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4421#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1922#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1823#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4824#include "skia/ext/platform_canvas.h"
[email protected]8bd0fe62011-01-17 06:44:3725#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]a7547fb2012-03-08 04:43:4426#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3727#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
28#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0129#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3730#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4131#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
32#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]e6e90dc2011-12-03 00:01:3733#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
34#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
[email protected]d353541f2012-05-03 22:45:4135#include "third_party/skia/include/core/SkShader.h"
[email protected]08397d52011-02-05 01:53:3836#include "ui/gfx/point.h"
37#include "ui/gfx/size.h"
[email protected]1835b9e2012-02-28 13:12:4838#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2739#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4140#include "ui/surface/transport_dib.h"
[email protected]8c89e7792009-08-19 21:18:3441#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5042#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4643#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4844
45#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4946#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5247#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4148#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4849#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4450
[email protected]8bd0fe62011-01-17 06:44:3751#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2952
[email protected]fa7b1dc2010-06-23 17:53:0453using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3054using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2255using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0656using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2857using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4458using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0059using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2860using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5961using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1862using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0163using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5264using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1965using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5266using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2867using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2468using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0469using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1870using WebKit::WebWidget;
[email protected]380244092011-10-07 17:26:2771using content::RenderThread;
[email protected]62cb33cae2009-03-27 23:30:2272
[email protected]f1cccb32012-06-06 18:29:5973static const int kStandardDPI = 160;
74
[email protected]6fd35b72012-03-01 19:46:4175RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:0476 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:4477 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:2978 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:5679 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:1180 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2981 opener_id_(MSG_ROUTING_NONE),
[email protected]659f73f2009-10-13 13:43:4282 host_window_(0),
[email protected]05a980d7a2012-02-07 22:16:4283 host_window_set_(false),
[email protected]b4d08452010-10-05 17:34:3584 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2985 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:0686 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:0587 update_reply_pending_(false),
[email protected]ea3ee0a2012-05-15 03:43:0988 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:2489 using_asynchronous_swapbuffers_(false),
90 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2991 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2992 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:0993 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:2994 needs_repainting_on_restore_(false),
95 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4996 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4897 closing_(false),
[email protected]14392a52012-05-02 20:28:4498 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:0499 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45100 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
101 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12102 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48103 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12104 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50105 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21106 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07107 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04108 screen_info_(screen_info),
[email protected]75bfbf92012-06-12 19:12:02109 device_scale_factor_(1) {
[email protected]8b3f0eb2012-05-03 19:15:05110 if (!swapped_out)
111 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27112 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18113 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
114 switches::kDisableGpuVsync);
[email protected]424820962012-06-08 15:33:19115#if defined(OS_CHROMEOS) || defined(OS_MACOSX)
[email protected]60051ec2012-06-08 22:40:57116 device_scale_factor_ = std::max(1, screen_info.verticalDPI / kStandardDPI);
[email protected]f1cccb32012-06-06 18:29:59117#endif
initial.commit09911bf2008-07-26 23:55:29118}
119
120RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11121 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21122 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35123 if (current_paint_buf_) {
124 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
125 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29126 }
[email protected]992db4c2011-05-12 15:37:15127 // If we are swapped out, we have released already.
128 if (!is_swapped_out_)
129 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29130}
131
[email protected]484955942010-08-19 16:13:18132// static
[email protected]8085dbc82008-09-26 22:53:44133RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04134 WebKit::WebPopupType popup_type,
135 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29136 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41137 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04138 new RenderWidget(popup_type, screen_info, false));
initial.commit09911bf2008-07-26 23:55:29139 widget->Init(opener_id); // adds reference
140 return widget;
141}
142
[email protected]484955942010-08-19 16:13:18143// static
144WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
145 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03146 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18147 break;
148 case WebKit::WebPopupTypeSelect:
149 case WebKit::WebPopupTypeSuggestion:
150 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44151 case WebKit::WebPopupTypePage:
152 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18153 default:
154 NOTREACHED();
155 }
156 return NULL;
157}
158
initial.commit09911bf2008-07-26 23:55:29159void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18160 DoInit(opener_id,
161 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56162 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
163 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18164}
165
[email protected]484955942010-08-19 16:13:18166void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06167 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18168 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29169 DCHECK(!webwidget_);
170
171 if (opener_id != MSG_ROUTING_NONE)
172 opener_id_ = opener_id;
173
[email protected]484955942010-08-19 16:13:18174 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29175
[email protected]380244092011-10-07 17:26:27176 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29177 if (result) {
[email protected]380244092011-10-07 17:26:27178 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29179 // Take a reference on behalf of the RenderThread. This will be balanced
180 // when we receive ViewMsg_Close.
181 AddRef();
182 } else {
183 DCHECK(false);
184 }
185}
186
187// This is used to complete pending inits and non-pending inits. For non-
188// pending cases, the parent will be the same as the current parent. This
189// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55190void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29191 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29192
193 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42194 host_window_set_ = true;
195
[email protected]f1d5de42012-04-20 01:47:14196#if WEBWIDGET_HAS_SETCOMPOSITORSURFACEREADY
197 if (webwidget_)
198 webwidget_->setCompositorSurfaceReady();
199#endif
[email protected]05a980d7a2012-02-07 22:16:42200 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29201
[email protected]6de74452009-02-25 18:04:59202 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29203}
204
[email protected]992db4c2011-05-12 15:37:15205void RenderWidget::SetSwappedOut(bool is_swapped_out) {
206 // We should only toggle between states.
207 DCHECK(is_swapped_out_ != is_swapped_out);
208 is_swapped_out_ = is_swapped_out;
209
210 // If we are swapping out, we will call ReleaseProcess, allowing the process
211 // to exit if all of its RenderViews are swapped out. We wait until the
212 // WasSwappedOut call to do this, to avoid showing the sad tab.
213 // If we are swapping in, we call AddRefProcess to prevent the process from
214 // exiting.
215 if (!is_swapped_out)
216 RenderProcess::current()->AddRefProcess();
217}
218
[email protected]a95986a82010-12-24 06:19:28219bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
220 bool handled = true;
221 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
222 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
223 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
224 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54225 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28226 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
227 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15228 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28229 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
230 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
231 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
232 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
233 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
234 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
235 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
236 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
237 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
[email protected]fea38fc2012-06-13 17:38:37238 IPC_MESSAGE_HANDLER(ViewMsg_SetDeviceScaleFactor, OnSetDeviceScaleFactor)
[email protected]a95986a82010-12-24 06:19:28239 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
240 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
241 IPC_MESSAGE_UNHANDLED(handled = false)
242 IPC_END_MESSAGE_MAP()
243 return handled;
244}
initial.commit09911bf2008-07-26 23:55:29245
246bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15247 // Don't send any messages after the browser has told us to close, and filter
248 // most outgoing messages while swapped out.
249 if ((is_swapped_out_ &&
250 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11251 closing_) {
initial.commit09911bf2008-07-26 23:55:29252 delete message;
253 return false;
254 }
255
256 // If given a messsage without a routing ID, then assign our routing ID.
257 if (message->routing_id() == MSG_ROUTING_NONE)
258 message->set_routing_id(routing_id_);
259
[email protected]380244092011-10-07 17:26:27260 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44261}
262
[email protected]61e2b3cc2012-03-02 16:13:34263void RenderWidget::Resize(const gfx::Size& new_size,
264 const gfx::Rect& resizer_rect,
265 bool is_fullscreen,
266 ResizeAck resize_ack) {
267 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
268 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
269 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29270
[email protected]61e2b3cc2012-03-02 16:13:34271 // Ignore this during shutdown.
272 if (!webwidget_)
273 return;
274
275 // Remember the rect where the resize corner will be drawn.
276 resizer_rect_ = resizer_rect;
277
278 // NOTE: We may have entered fullscreen mode without changing our size.
279 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
280 if (fullscreen_change)
281 WillToggleFullscreen();
282 is_fullscreen_ = is_fullscreen;
283
284 if (size_ != new_size) {
285 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34286 needs_repainting_on_restore_ = false;
287
288 size_ = new_size;
289
290 paint_aggregator_.ClearPendingUpdate();
291
292 // When resizing, we want to wait to paint before ACK'ing the resize. This
293 // ensures that we only resize as fast as we can paint. We only need to
294 // send an ACK if we are resized to a non-empty rect.
295 webwidget_->resize(new_size);
296 if (!new_size.IsEmpty()) {
297 if (!is_accelerated_compositing_active_) {
298 // Resize should have caused an invalidation of the entire view.
299 DCHECK(paint_aggregator_.HasPendingUpdate());
300 }
301
302 // Send the Resize_ACK flag once we paint again if requested.
303 if (resize_ack == SEND_RESIZE_ACK)
304 set_next_paint_is_resize_ack();
305 }
[email protected]ff475a322012-03-14 00:05:35306 } else {
307 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34308 }
309
310 if (fullscreen_change)
311 DidToggleFullscreen();
312
313 // If a resize ack is requested and it isn't set-up, then no more resizes will
314 // come in and in general things will go wrong.
315 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
316 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29317}
318
319void RenderWidget::OnClose() {
320 if (closing_)
321 return;
322 closing_ = true;
323
324 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03325 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27326 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03327 SetHidden(false);
328 }
initial.commit09911bf2008-07-26 23:55:29329
initial.commit09911bf2008-07-26 23:55:29330 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25331 // now. Post a task that only gets invoked when there are no nested message
332 // loops.
[email protected]32876ae2011-11-15 22:25:21333 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29334 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25335
336 // Balances the AddRef taken when we called AddRoute.
337 Release();
initial.commit09911bf2008-07-26 23:55:29338}
339
[email protected]61e2b3cc2012-03-02 16:13:34340// Got a response from the browser after the renderer decided to create a new
341// view.
342void RenderWidget::OnCreatingNewAck(
343 gfx::NativeViewId parent) {
344 DCHECK(routing_id_ != MSG_ROUTING_NONE);
345
346 CompleteInit(parent);
347}
348
[email protected]f21c613a2009-02-12 14:46:17349void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09350 const gfx::Rect& resizer_rect,
351 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34352 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29353}
354
[email protected]b5913d72012-02-07 22:26:54355void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
356 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59357 gfx::Rect view_rect(size_);
358
359 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
360 if (!old_damage_rect.IsEmpty())
361 paint_aggregator_.InvalidateRect(old_damage_rect);
362
363 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
364 if (!new_damage_rect.IsEmpty())
365 paint_aggregator_.InvalidateRect(new_damage_rect);
366
[email protected]b5913d72012-02-07 22:26:54367 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59368
[email protected]b5913d72012-02-07 22:26:54369 if (webwidget_)
370 webwidget_->didChangeWindowResizerRect();
371 }
372}
373
initial.commit09911bf2008-07-26 23:55:29374void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31375 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29376 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03377 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29378}
379
380void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31381 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29382 // During shutdown we can just ignore this message.
383 if (!webwidget_)
384 return;
385
386 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03387 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29388
389 if (!needs_repainting && !needs_repainting_on_restore_)
390 return;
391 needs_repainting_on_restore_ = false;
392
[email protected]d65adb12010-04-28 17:26:49393 // Tag the next paint as a restore ack, which is picked up by
394 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29395 set_next_paint_is_restore_ack();
396
397 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56398 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46399 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
400 } else {
401 scheduleComposite();
402 }
initial.commit09911bf2008-07-26 23:55:29403}
404
[email protected]992db4c2011-05-12 15:37:15405void RenderWidget::OnWasSwappedOut() {
406 // If we have been swapped out and no one else is using this process,
407 // it's safe to exit now. If we get swapped back in, we will call
408 // AddRefProcess in SetSwappedOut.
409 if (is_swapped_out_)
410 RenderProcess::current()->ReleaseProcess();
411}
412
[email protected]53d3f302009-12-21 04:42:05413void RenderWidget::OnRequestMoveAck() {
414 DCHECK(pending_window_rect_count_);
415 pending_window_rect_count_--;
416}
417
418void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58419 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21420 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05421 update_reply_pending_ = false;
422
[email protected]b4d08452010-10-05 17:34:35423 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
424 // have no current paint buffer.
425 if (current_paint_buf_) {
426 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
427 current_paint_buf_ = NULL;
428 }
429
[email protected]65225772011-05-12 21:10:24430 // If swapbuffers is still pending, then defer the update until the
431 // swapbuffers occurs.
432 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
433 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
434 return;
435 }
436
[email protected]29ed96a2012-02-04 18:12:16437 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18438 if (!is_accelerated_compositing_active_) {
439 DidFlushPaint();
440 }
[email protected]a2f6bc112009-06-27 16:27:25441
initial.commit09911bf2008-07-26 23:55:29442 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24443 DoDeferredUpdateAndSendInputAck();
444}
445
[email protected]d0be63772011-12-20 23:18:04446bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24447 return false;
448}
449
[email protected]d0be63772011-12-20 23:18:04450void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24451 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21452 while (!updates_pending_swap_.empty()) {
453 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
454 updates_pending_swap_.pop_front();
455 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
456 // compositing pass, hence doesn't require an UpdateRect message.
457 if (msg)
458 Send(msg);
459 }
[email protected]65225772011-05-12 21:10:24460 num_swapbuffers_complete_pending_ = 0;
461 using_asynchronous_swapbuffers_ = false;
462 // Schedule another frame so the compositor learns about it.
463 scheduleComposite();
464}
465
[email protected]37a6f302011-07-11 23:43:08466void RenderWidget::OnSwapBuffersPosted() {
467 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21468
469 if (using_asynchronous_swapbuffers_) {
470 ViewHostMsg_UpdateRect* msg = NULL;
471 // pending_update_params_ can be NULL if the swap doesn't correspond to an
472 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
473 // message.
474 if (pending_update_params_.get()) {
475 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
476 pending_update_params_.reset();
477 }
478 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08479 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21480 }
[email protected]37a6f302011-07-11 23:43:08481}
482
483void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24484 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16485
[email protected]404939f2012-06-01 04:06:18486 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16487 DidFlushPaint();
488
[email protected]65225772011-05-12 21:10:24489 // When compositing deactivates, we reset the swapbuffers pending count. The
490 // swapbuffers acks may still arrive, however.
491 if (num_swapbuffers_complete_pending_ == 0) {
492 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
493 return;
494 }
[email protected]aa4117f2011-12-09 22:19:21495 DCHECK(!updates_pending_swap_.empty());
496 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
497 updates_pending_swap_.pop_front();
498 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
499 // compositing pass, hence doesn't require an UpdateRect message.
500 if (msg)
501 Send(msg);
[email protected]65225772011-05-12 21:10:24502 num_swapbuffers_complete_pending_--;
503
504 // If update reply is still pending, then defer the update until that reply
505 // occurs.
[email protected]d0be63772011-12-20 23:18:04506 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24507 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
508 return;
509 }
510
511 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06512 // when we were previously rendering. However, if an invalidation task is not
513 // posted, there may be software rendering work pending. In that case, don't
514 // early out.
515 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24516 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
517 return;
518 }
519
[email protected]65225772011-05-12 21:10:24520 // Continue painting if necessary...
521 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29522}
523
initial.commit09911bf2008-07-26 23:55:29524void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24525 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56526 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29527
528 const char* data;
529 int data_length;
[email protected]5dd768212009-08-13 23:34:49530 handling_input_event_ = true;
531 if (!message.ReadData(&iter, &data, &data_length)) {
532 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29533 return;
[email protected]5dd768212009-08-13 23:34:49534 }
initial.commit09911bf2008-07-26 23:55:29535
536 const WebInputEvent* input_event =
537 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48538
[email protected]b68a0e52011-12-08 15:11:12539 bool is_keyboard_shortcut = false;
540 // is_keyboard_shortcut flag is only available for RawKeyDown events.
541 if (input_event->type == WebInputEvent::RawKeyDown)
542 message.ReadBool(&iter, &is_keyboard_shortcut);
543
[email protected]67bfb83f2011-09-22 03:36:37544 bool prevent_default = false;
545 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26546 const WebMouseEvent& mouse_event =
547 *static_cast<const WebMouseEvent*>(input_event);
548 TRACE_EVENT2("renderer", "HandleMouseMove",
549 "x", mouse_event.x, "y", mouse_event.y);
550 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37551 }
552
553 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12554 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
555 suppress_next_char_events_ = false;
556 if (!processed && webwidget_)
557 processed = webwidget_->handleInputEvent(*input_event);
558 }
559
560 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
561 // it's not processed by webkit, then we need to suppress the upcoming Char
562 // events.
563 if (!processed && is_keyboard_shortcut)
564 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29565
[email protected]a9fb30aa2011-10-06 06:58:46566 IPC::Message* response =
567 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
568 processed);
[email protected]3391a0772012-03-28 00:32:07569 bool event_type_gets_rate_limited =
570 input_event->type == WebInputEvent::MouseMove ||
571 input_event->type == WebInputEvent::MouseWheel ||
572 WebInputEvent::isTouchEventType(input_event->type);
573 bool is_input_throttled =
574 webwidget_->isInputThrottled() ||
575 paint_aggregator_.HasPendingUpdate();
[email protected]e2824412009-02-27 01:57:05576
[email protected]f8868d72012-04-27 19:13:03577 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24578 // We want to rate limit the input events in this case, so we'll wait for
579 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17580 if (pending_input_event_ack_.get()) {
581 // As two different kinds of events could cause us to postpone an ack
582 // we send it now, if we have one pending. The Browser should never
583 // send us the same kind of event we are delaying the ack for.
584 Send(pending_input_event_ack_.release());
585 }
[email protected]12fbad812009-09-01 18:21:24586 pending_input_event_ack_.reset(response);
587 } else {
588 Send(response);
589 }
590
[email protected]5dd768212009-08-13 23:34:49591 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48592
[email protected]67bfb83f2011-09-22 03:36:37593 if (!prevent_default) {
594 if (WebInputEvent::isKeyboardEventType(input_event->type))
595 DidHandleKeyEvent();
596 if (WebInputEvent::isMouseEventType(input_event->type))
597 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24598 if (WebInputEvent::isTouchEventType(input_event->type))
599 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37600 }
initial.commit09911bf2008-07-26 23:55:29601}
602
603void RenderWidget::OnMouseCaptureLost() {
604 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28605 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29606}
607
608void RenderWidget::OnSetFocus(bool enable) {
609 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33610 if (webwidget_)
611 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29612}
613
614void RenderWidget::ClearFocus() {
615 // We may have got the focus from the browser before this gets processed, in
616 // which case we do not want to unfocus ourself.
617 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28618 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29619}
620
[email protected]2d5d09d52009-06-15 14:29:21621void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00622 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21623 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06624 TRACE_EVENT2("renderer", "PaintRect",
625 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00626 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21627
628 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00629 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
630 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03631
[email protected]699ab0d2009-04-23 23:19:14632 // If there is a custom background, tile it.
633 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14634 SkPaint paint;
635 SkShader* shader = SkShader::CreateBitmapShader(background_,
636 SkShader::kRepeat_TileMode,
637 SkShader::kRepeat_TileMode);
638 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20639
640 // Use kSrc_Mode to handle background_ transparency properly.
641 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
642
643 // Canvas could contain multiple update rects. Clip to given rect so that
644 // we don't accidentally clear other update rects.
645 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48646 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14647 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20648 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14649 }
650
[email protected]719b36f2010-12-22 20:36:46651 // First see if this rect is a plugin that can paint itself faster.
652 TransportDIB* optimized_dib = NULL;
653 gfx::Rect optimized_copy_rect, optimized_copy_location;
654 webkit::ppapi::PluginInstance* optimized_instance =
655 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
656 &optimized_copy_location,
657 &optimized_copy_rect);
658 if (optimized_instance) {
659 // This plugin can be optimize-painted and we can just ask it to paint
660 // itself. We don't actually need the TransportDIB in this case.
661 //
662 // This is an optimization for PPAPI plugins that know they're on top of
663 // the page content. If this rect is inside such a plugin, we can save some
664 // time and avoid re-rendering the page content which we know will be
665 // covered by the plugin later (this time can be significant, especially
666 // for a playing movie that is invalidating a lot).
667 //
668 // In the plugin movie case, hopefully the similar call to
669 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
670 // painting, because that avoids copying the plugin image to a different
671 // paint rect. Unfortunately, if anything on the page is animating other
672 // than the movie, it break this optimization since the union of the
673 // invalid regions will be larger than the plugin.
674 //
675 // This code optimizes that case, where we can still avoid painting in
676 // WebKit and filling the background (which can be slow) and just painting
677 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
678 // required.
679 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27680 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46681 } else {
682 // Normal painting case.
683 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
684
685 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35686 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46687 }
initial.commit09911bf2008-07-26 23:55:29688
[email protected]4fb66842009-12-04 21:41:00689 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00690 canvas->restore();
691}
692
693void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
694 skia::PlatformCanvas* canvas) {
695 static bool kPaintBorder =
696 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
697 if (!kPaintBorder)
698 return;
699
[email protected]53d3f302009-12-21 04:42:05700 // Cycle through these colors to help distinguish new paint rects.
701 const SkColor colors[] = {
702 SkColorSetARGB(0x3F, 0xFF, 0, 0),
703 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
704 SkColorSetARGB(0x3F, 0, 0, 0xFF),
705 };
706 static int color_selector = 0;
707
[email protected]4fb66842009-12-04 21:41:00708 SkPaint paint;
709 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05710 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00711 paint.setStrokeWidth(1);
712
713 SkIRect irect;
714 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
715 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29716}
717
[email protected]52ccd0ea2011-02-16 01:09:05718void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30719 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30720 if (!animation_update_pending_) {
721 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59722 return;
[email protected]921244e42011-07-20 16:36:30723 }
[email protected]bd37ae252011-06-03 01:28:18724 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59725 // Record when we fired (according to base::Time::Now()) relative to when
726 // we posted the task to quantify how much the base::Time/base::TimeTicks
727 // skew is affecting animations.
728 base::TimeDelta animation_callback_delay = base::Time::Now() -
729 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
730 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
731 animation_callback_delay,
732 base::TimeDelta::FromMilliseconds(0),
733 base::TimeDelta::FromMilliseconds(30),
734 25);
735 }
[email protected]65225772011-05-12 21:10:24736 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24737}
738
[email protected]52ccd0ea2011-02-16 01:09:05739void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59740 if (!animation_update_pending_)
741 return;
[email protected]bd37ae252011-06-03 01:28:18742
743 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33744 base::TimeDelta animationInterval = IsRenderingVSynced() ?
745 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18746
[email protected]7c4329e2011-02-18 22:02:59747 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45748
749 // animation_floor_time_ is the earliest time that we should animate when
750 // using the dead reckoning software scheduler. If we're using swapbuffers
751 // complete callbacks to rate limit, we can ignore this floor.
752 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30753 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33754 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18755 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59756 // running animation callbacks so that if a callback requests another
757 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38758 animation_timer_.Stop();
759 animation_timer_.Start(FROM_HERE, animationInterval, this,
760 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59761 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30762 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59763 return;
[email protected]5f8b1022011-01-21 23:34:50764 }
[email protected]bd37ae252011-06-03 01:28:18765 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38766 if (!animation_timer_.IsRunning()) {
767 // This code uses base::Time::Now() to calculate the floor and next fire
768 // time because javascript's Date object uses base::Time::Now(). The
769 // message loop uses base::TimeTicks, which on windows can have a
770 // different granularity than base::Time.
771 // The upshot of all this is that this function might be called before
772 // base::Time::Now() has advanced past the animation_floor_time_. To
773 // avoid exposing this delay to javascript, we keep posting delayed
774 // tasks until base::Time::Now() has advanced far enough.
775 base::TimeDelta delay = animation_floor_time_ - now;
776 animation_timer_.Start(FROM_HERE, delay, this,
777 &RenderWidget::AnimationCallback);
778 }
[email protected]5f8b1022011-01-21 23:34:50779}
780
[email protected]bd37ae252011-06-03 01:28:18781bool RenderWidget::IsRenderingVSynced() {
782 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
783 // not caught by this check. This will lead to artificially low frame rates
784 // for people who force vsync off at a driver level and expect Chrome to speed
785 // up.
786 return !has_disable_gpu_vsync_switch_;
787}
788
[email protected]65225772011-05-12 21:10:24789void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06790 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24791 invalidation_task_posted_ = false;
792 DoDeferredUpdateAndSendInputAck();
793}
794
795void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05796 DoDeferredUpdate();
797
798 if (pending_input_event_ack_.get())
799 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21800}
801
[email protected]552e6002009-11-19 05:24:57802void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58803 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08804
[email protected]65225772011-05-12 21:10:24805 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29806 return;
[email protected]05a980d7a2012-02-07 22:16:42807
808 if (!host_window_set_) {
809 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
810 return;
811 }
[email protected]aa4117f2011-12-09 22:19:21812 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24813 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
814 return;
815 }
[email protected]9ca84622011-06-02 23:46:39816 if (is_accelerated_compositing_active_ &&
817 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24818 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
819 return;
820 }
initial.commit09911bf2008-07-26 23:55:29821
[email protected]552e6002009-11-19 05:24:57822 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29823 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57824 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29825 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24826 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29827 return;
828 }
829
[email protected]05a980d7a2012-02-07 22:16:42830 if (is_accelerated_compositing_active_)
831 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
832
[email protected]0fb93f52011-05-18 23:13:56833 // Tracking of frame rate jitter
834 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51835 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05836 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50837
[email protected]f98d7e3c2010-09-13 22:30:46838 // Layout may generate more invalidation. It may also enable the
839 // GPU acceleration, so make sure to run layout before we send the
840 // GpuRenderingActivated message.
841 webwidget_->layout();
842
[email protected]dcca3aa92012-02-17 23:03:37843 // The following two can result in further layout and possibly
844 // enable GPU acceleration so they need to be called before any painting
845 // is done.
846 UpdateTextInputState();
847 UpdateSelectionBounds();
848
[email protected]5f8b1022011-01-21 23:34:50849 // Suppress painting if nothing is dirty. This has to be done after updating
850 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24851 if (!paint_aggregator_.HasPendingUpdate()) {
852 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51853 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50854 return;
[email protected]65225772011-05-12 21:10:24855 }
[email protected]5f8b1022011-01-21 23:34:50856
[email protected]872ae5b2011-05-26 20:20:50857 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56858 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04859 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56860 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
861 delay,
862 base::TimeDelta::FromMilliseconds(1),
863 base::TimeDelta::FromMilliseconds(60),
864 30);
[email protected]d0be63772011-12-20 23:18:04865 } else {
[email protected]0fb93f52011-05-18 23:13:56866 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
867 delay,
868 base::TimeDelta::FromMilliseconds(1),
869 base::TimeDelta::FromMilliseconds(60),
870 30);
[email protected]d0be63772011-12-20 23:18:04871 }
[email protected]872ae5b2011-05-26 20:20:50872
873 // Calculate filtered time per frame:
874 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
875 filtered_time_per_frame_ =
876 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56877 }
878 last_do_deferred_update_time_ = frame_begin_ticks;
879
[email protected]552e6002009-11-19 05:24:57880 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29881 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30882 PaintAggregator::PendingUpdate update;
883 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29884
[email protected]53d3f302009-12-21 04:42:05885 gfx::Rect scroll_damage = update.GetScrollDamage();
886 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29887
[email protected]29ed96a2012-02-04 18:12:16888 // Notify derived classes that we're about to initiate a paint.
889 WillInitiatePaint();
890
[email protected]ca4847f2010-09-24 05:39:15891 // A plugin may be able to do an optimized paint. First check this, in which
892 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46893 // This optimization allows PPAPI plugins that declare themselves on top of
894 // the page (like a traditional windowed plugin) to be able to animate (think
895 // movie playing) without repeatedly re-painting the page underneath, or
896 // copying the plugin backing store (since we can send the plugin's backing
897 // store directly to the browser).
898 //
899 // This optimization only works when the entire invalid region is contained
900 // within the plugin. There is a related optimization in PaintRect for the
901 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15902 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15903 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21904 DCHECK(!pending_update_params_.get());
905 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
906 pending_update_params_->dx = update.scroll_delta.x();
907 pending_update_params_->dy = update.scroll_delta.y();
908 pending_update_params_->scroll_rect = update.scroll_rect;
909 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21910 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
911 pending_update_params_->flags = next_paint_flags_;
912 pending_update_params_->scroll_offset = GetScrollOffset();
913 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:09914 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:21915 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:09916 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:21917
[email protected]ca4847f2010-09-24 05:39:15918 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56919 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15920 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
921 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27922 // Only update the part of the plugin that actually changed.
923 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21924 pending_update_params_->bitmap = dib->id();
925 pending_update_params_->bitmap_rect = optimized_copy_location;
926 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56927 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46928 // Compute a buffer for painting and cache it.
[email protected]f1cccb32012-06-06 18:29:59929 gfx::Rect pixel_bounds = bounds.Scale(device_scale_factor_);
[email protected]ca4847f2010-09-24 05:39:15930 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35931 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:59932 pixel_bounds));
[email protected]f98d7e3c2010-09-13 22:30:46933 if (!canvas.get()) {
934 NOTREACHED();
935 return;
936 }
[email protected]cef3362f2009-12-21 17:48:45937
[email protected]f98d7e3c2010-09-13 22:30:46938 // We may get back a smaller canvas than we asked for.
939 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:59940 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
941 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
942 pixel_bounds.set_width(canvas->getDevice()->width());
943 pixel_bounds.set_height(canvas->getDevice()->height());
944 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
945 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:05946
[email protected]f98d7e3c2010-09-13 22:30:46947 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
948
[email protected]aa4117f2011-12-09 22:19:21949 pending_update_params_->bitmap = current_paint_buf_->id();
950 pending_update_params_->bitmap_rect = bounds;
951
952 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46953 // The scroll damage is just another rectangle to paint and copy.
954 copy_rects.swap(update.paint_rects);
955 if (!scroll_damage.IsEmpty())
956 copy_rects.push_back(scroll_damage);
957
958 for (size_t i = 0; i < copy_rects.size(); ++i)
[email protected]f1cccb32012-06-06 18:29:59959 PaintRect(copy_rects[i], pixel_bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35960
961 // Software FPS tick for performance tests. The accelerated path traces the
962 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
963 // NOTE: Tests may break if this event is renamed or moved.
964 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46965 } else { // Accelerated compositing path
966 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21967 // If painting is done via the gpu process then we don't set any damage
968 // rects to save the browser process from doing unecessary work.
969 pending_update_params_->bitmap_rect = bounds;
970 pending_update_params_->scroll_rect = gfx::Rect();
971 // We don't need an ack, because we're not sharing a DIB with the browser.
972 // If it needs to (e.g. composited UI), the GPU process does its own ACK
973 // with the browser for the GPU surface.
974 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42975 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46976 }
977
[email protected]936c6f52011-12-13 01:35:26978 // If we're holding a pending input event ACK, send the ACK before sending the
979 // UpdateReply message so we can receive another input event before the
980 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
981 // the UpdateRect IPC message handler.
982 if (pending_input_event_ack_.get())
983 Send(pending_input_event_ack_.release());
984
[email protected]aa4117f2011-12-09 22:19:21985 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
986 // OnSwapBuffersPosted), meaning a message has been added to the
987 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
988 // the message now.
989 if (pending_update_params_.get()) {
990 // sending an ack to browser process that the paint is complete...
991 update_reply_pending_ = pending_update_params_->needs_ack;
992 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
993 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:34994 }
[email protected]53d3f302009-12-21 04:42:05995
[email protected]29ed96a2012-02-04 18:12:16996 // If we're software rendering then we're done initiating the paint.
997 if (!is_accelerated_compositing_active_)
998 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29999}
1000
1001///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461002// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291003
[email protected]4873c7d2009-07-16 06:36:281004void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:571005 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481006 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571007 gfx::Rect damaged_rect = view_rect.Intersect(rect);
1008 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291009 return;
1010
[email protected]552e6002009-11-19 05:24:571011 paint_aggregator_.InvalidateRect(damaged_rect);
1012
1013 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241014 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571015 return;
1016 if (!paint_aggregator_.HasPendingUpdate())
1017 return;
[email protected]aa4117f2011-12-09 22:19:211018 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241019 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1020 return;
1021
1022 // When GPU rendering, combine pending animations and invalidations into
1023 // a single update.
[email protected]816edc62012-03-17 01:27:221024 if (is_accelerated_compositing_active_ &&
1025 animation_update_pending_ &&
1026 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571027 return;
1028
1029 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291030 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1031 // on the call stack.
1032 // 2) Allows us to collect more damage rects before painting to help coalesce
1033 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241034 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211035 MessageLoop::current()->PostTask(
1036 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291037}
1038
[email protected]4873c7d2009-07-16 06:36:281039void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461040 // Drop scrolls on the floor when we are in compositing mode.
1041 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561042 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461043 return;
1044
[email protected]552e6002009-11-19 05:24:571045 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481046 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571047 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1048 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291049 return;
1050
[email protected]552e6002009-11-19 05:24:571051 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1052
1053 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241054 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571055 return;
1056 if (!paint_aggregator_.HasPendingUpdate())
1057 return;
[email protected]aa4117f2011-12-09 22:19:211058 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241059 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1060 return;
1061
1062 // When GPU rendering, combine pending animations and invalidations into
1063 // a single update.
[email protected]816edc62012-03-17 01:27:221064 if (is_accelerated_compositing_active_ &&
1065 animation_update_pending_ &&
1066 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571067 return;
1068
1069 // Perform updating asynchronously. This serves two purposes:
1070 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1071 // on the call stack.
1072 // 2) Allows us to collect more damage rects before painting to help coalesce
1073 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241074 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211075 MessageLoop::current()->PostTask(
1076 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291077}
1078
[email protected]244ac1892011-12-02 17:04:471079void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091080 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1081 size_ = new_size;
1082 need_update_rect_for_auto_resize_ = true;
1083 }
[email protected]244ac1892011-12-02 17:04:471084}
1085
[email protected]91acd1c2012-03-14 08:32:391086void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221087 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1088
[email protected]c63b4d42012-04-26 01:01:071089#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211090 if (!is_accelerated_compositing_active_) {
1091 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1092 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1093 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1094 // going to switch to accelerated compositing, the GPU process may need
1095 // round-trips to the browser's UI thread before finishing the frame,
1096 // causing deadlocks if we delay the UpdateRect until we receive the
1097 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071098 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1099 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211100 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1101 }
[email protected]c63b4d42012-04-26 01:01:071102#endif
[email protected]aa4117f2011-12-09 22:19:211103
[email protected]ea162f92011-10-04 23:08:221104 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421105 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241106 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221107}
1108
1109void RenderWidget::didDeactivateCompositor() {
1110 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1111
1112 is_accelerated_compositing_active_ = false;
1113 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1114 routing_id_, is_accelerated_compositing_active_));
1115
[email protected]ea162f92011-10-04 23:08:221116 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241117 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561118}
1119
[email protected]9cd43a62012-03-26 08:03:561120void RenderWidget::willBeginCompositorFrame() {
1121 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371122
1123 DCHECK(RenderThreadImpl::current()->compositor_thread());
1124
1125 // The following two can result in further layout and possibly
1126 // enable GPU acceleration so they need to be called before any painting
1127 // is done.
1128 UpdateTextInputState();
1129 UpdateSelectionBounds();
1130
[email protected]9cd43a62012-03-26 08:03:561131 WillInitiatePaint();
1132}
1133
[email protected]3391a0772012-03-28 00:32:071134void RenderWidget::didBecomeReadyForAdditionalInput() {
1135 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1136 if (pending_input_event_ack_.get())
1137 Send(pending_input_event_ack_.release());
1138}
1139
[email protected]58264a32011-11-17 23:36:151140void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501141 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351142 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1143 // NOTE: Tests may break if this event is renamed or moved.
1144 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161145 // Notify subclasses that we initiated the paint operation.
1146 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151147}
1148
1149void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181150 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1151
1152 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561153 DidFlushPaint();
1154
[email protected]aa4117f2011-12-09 22:19:211155 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151156 return;
1157
[email protected]ea3ee0a2012-05-15 03:43:091158 if (!next_paint_flags_ &&
1159 !need_update_rect_for_auto_resize_ &&
1160 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151161 return;
[email protected]ea3ee0a2012-05-15 03:43:091162 }
[email protected]58264a32011-11-17 23:36:151163
1164 ViewHostMsg_UpdateRect_Params params;
1165 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151166 params.plugin_window_moves.swap(plugin_window_moves_);
1167 params.flags = next_paint_flags_;
1168 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121169 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091170 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151171
1172 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1173 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091174 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151175}
1176
[email protected]f98d7e3c2010-09-13 22:30:461177void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041178 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401179 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041180 } else {
[email protected]c3d45532011-10-07 19:20:401181 // TODO(nduca): replace with something a little less hacky. The reason this
1182 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1183 // contains a lot of host-renderer synchronization logic that is still
1184 // important for the accelerated compositing case. The option of simply
1185 // duplicating all that code is less desirable than "faking out" the
1186 // invalidation path using a magical damage rect.
1187 didInvalidateRect(WebRect(0, 0, 1, 1));
1188 }
[email protected]f98d7e3c2010-09-13 22:30:461189}
1190
[email protected]5f8b1022011-01-21 23:34:501191void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201192 if (animation_update_pending_)
1193 return;
1194
[email protected]921244e42011-07-20 16:36:301195 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201196 animation_update_pending_ = true;
1197 if (!animation_timer_.IsRunning()) {
1198 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1199 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211200 }
[email protected]5f8b1022011-01-21 23:34:501201}
1202
[email protected]4873c7d2009-07-16 06:36:281203void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301204 // TODO(darin): Eliminate this temporary.
1205 WebCursor cursor(cursor_info);
1206
initial.commit09911bf2008-07-26 23:55:291207 // Only send a SetCursor message if we need to make a change.
1208 if (!current_cursor_.IsEqual(cursor)) {
1209 current_cursor_ = cursor;
1210 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1211 }
1212}
1213
1214// We are supposed to get a single call to Show for a newly created RenderWidget
1215// that was created via RenderWidget::CreateWebView. So, we wait until this
1216// point to dispatch the ShowWidget message.
1217//
1218// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281219// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291220//
[email protected]4873c7d2009-07-16 06:36:281221void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291222 DCHECK(!did_show_) << "received extraneous Show call";
1223 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1224 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1225
[email protected]8de12d942010-11-17 20:42:441226 if (did_show_)
1227 return;
1228
1229 did_show_ = true;
1230 // NOTE: initial_pos_ may still have its default values at this point, but
1231 // that's okay. It'll be ignored if as_popup is false, or the browser
1232 // process will impose a default position otherwise.
1233 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1234 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291235}
1236
[email protected]4873c7d2009-07-16 06:36:281237void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291238}
1239
[email protected]4873c7d2009-07-16 06:36:281240void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291241}
1242
[email protected]2533ce12009-05-09 00:02:241243void RenderWidget::DoDeferredClose() {
1244 Send(new ViewHostMsg_Close(routing_id_));
1245}
1246
[email protected]4873c7d2009-07-16 06:36:281247void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321248 if (is_swapped_out_) {
1249 // This widget is currently swapped out, and the active widget is in a
1250 // different process. Have the browser route the close request to the
1251 // active widget instead, so that the correct unload handlers are run.
1252 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1253 return;
1254 }
1255
initial.commit09911bf2008-07-26 23:55:291256 // If a page calls window.close() twice, we'll end up here twice, but that's
1257 // OK. It is safe to send multiple Close messages.
1258
[email protected]2533ce12009-05-09 00:02:241259 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1260 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1261 // could be closed before the JS finishes executing. So instead, post a
1262 // message back to the message loop, which won't run until the JS is
1263 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211264 MessageLoop::current()->PostTask(
1265 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291266}
1267
1268void RenderWidget::Close() {
1269 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281270 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291271 webwidget_ = NULL;
1272 }
1273}
1274
[email protected]4873c7d2009-07-16 06:36:281275WebRect RenderWidget::windowRect() {
1276 if (pending_window_rect_count_)
1277 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241278
[email protected]b3f2b912009-04-09 16:18:521279 gfx::Rect rect;
1280 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281281 return rect;
initial.commit09911bf2008-07-26 23:55:291282}
1283
[email protected]8a9d6ca32011-06-06 20:11:301284void RenderWidget::setToolTipText(const WebKit::WebString& text,
1285 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541286 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301287}
1288
[email protected]4873c7d2009-07-16 06:36:281289void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291290 if (did_show_) {
1291 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241292 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291293 } else {
1294 initial_pos_ = pos;
1295 }
1296}
1297
[email protected]2533ce12009-05-09 00:02:241298void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1299 pending_window_rect_ = rect;
1300 pending_window_rect_count_++;
1301}
1302
[email protected]4873c7d2009-07-16 06:36:281303WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241304 if (pending_window_rect_count_) {
1305 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1306 // the RootWindowRect is probably going to return wrong results since the
1307 // browser may not have processed the Move yet. There isn't really anything
1308 // good to do in this case, and it shouldn't happen - since this size is
1309 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281310 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241311 }
1312
[email protected]b3f2b912009-04-09 16:18:521313 gfx::Rect rect;
1314 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281315 return rect;
[email protected]d4547452008-08-28 18:36:371316}
1317
[email protected]4873c7d2009-07-16 06:36:281318WebRect RenderWidget::windowResizerRect() {
1319 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191320}
1321
[email protected]fa7b1dc2010-06-23 17:53:041322void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031323 // To prevent this renderer process from sending unnecessary IPC messages to
1324 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041325 // only during the input method attached to the browser process is active.
1326 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291327}
1328
[email protected]58b48a0d2012-06-13 07:01:351329void RenderWidget::UpdateCompositionInfo(
1330 const ui::Range& range,
1331 const std::vector<gfx::Rect>& character_bounds) {
1332 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1333 return;
1334 composition_character_bounds_ = character_bounds;
1335 composition_range_ = range;
1336 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1337 routing_id(), composition_range_, composition_character_bounds_));
1338}
1339
[email protected]fa7b1dc2010-06-23 17:53:041340void RenderWidget::OnImeSetComposition(
1341 const string16& text,
1342 const std::vector<WebCompositionUnderline>& underlines,
1343 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281344 if (!webwidget_)
1345 return;
[email protected]d4cff272011-05-02 15:46:011346 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041347 text, WebVector<WebCompositionUnderline>(underlines),
1348 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011349 // Setting the IME composition was successful. Send the new composition
1350 // range to the browser.
1351 ui::Range range(ui::Range::InvalidRange());
1352 size_t location, length;
1353 if (webwidget_->compositionRange(&location, &length)) {
1354 range.set_start(location);
1355 range.set_end(location + length);
1356 }
1357 // The IME was cancelled via the Esc key, so just send back the caret.
1358 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1359 range.set_start(location);
1360 range.set_end(location + length);
1361 }
[email protected]58b48a0d2012-06-13 07:01:351362 std::vector<gfx::Rect> character_bounds;
1363 GetCompositionCharacterBounds(&character_bounds);
1364 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011365 } else {
[email protected]fa7b1dc2010-06-23 17:53:041366 // If we failed to set the composition text, then we need to let the browser
1367 // process to cancel the input method's ongoing composition session, to make
1368 // sure we are in a consistent state.
1369 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011370
1371 // Send an updated IME range with just the caret range.
1372 ui::Range range(ui::Range::InvalidRange());
1373 size_t location, length;
1374 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1375 range.set_start(location);
1376 range.set_end(location + length);
1377 }
[email protected]58b48a0d2012-06-13 07:01:351378 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261379 }
[email protected]fa7b1dc2010-06-23 17:53:041380}
1381
[email protected]4de6d1692011-10-12 08:45:441382void RenderWidget::OnImeConfirmComposition(
1383 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041384 if (!webwidget_)
1385 return;
1386
1387 handling_input_event_ = true;
1388 webwidget_->confirmComposition(text);
1389 handling_input_event_ = false;
1390
[email protected]d4cff272011-05-02 15:46:011391 // Send an updated IME range with just the caret range.
1392 ui::Range range(ui::Range::InvalidRange());
1393 size_t location, length;
1394 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1395 range.set_start(location);
1396 range.set_end(location + length);
1397 }
[email protected]58b48a0d2012-06-13 07:01:351398 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291399}
1400
[email protected]948f7ab72010-05-28 23:48:081401// This message causes the renderer to render an image of the
1402// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491403void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091404 int tag,
[email protected]948f7ab72010-05-28 23:48:081405 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491406 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001407 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1408 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251409 // Close our unused handle.
1410#if defined(OS_WIN)
1411 ::CloseHandle(dib_handle);
1412#elif defined(OS_MACOSX)
1413 base::SharedMemory::CloseHandle(dib_handle);
1414#endif
1415 }
[email protected]d65adb12010-04-28 17:26:491416 return;
[email protected]45c6aad32010-11-11 04:46:251417 }
[email protected]d65adb12010-04-28 17:26:491418
[email protected]948f7ab72010-05-28 23:48:081419 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491420 // If one of these is empty, then we just return the dib we were
1421 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091422 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491423 return;
1424 }
1425
1426 // Map the given DIB ID into this process, and unmap it at the end
1427 // of this function.
[email protected]45c6aad32010-11-11 04:46:251428 scoped_ptr<TransportDIB> paint_at_size_buffer(
1429 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301430
1431 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491432 float x_scale = static_cast<float>(desired_size.width()) /
1433 static_cast<float>(canvas_size.width());
1434 float y_scale = static_cast<float>(desired_size.height()) /
1435 static_cast<float>(canvas_size.height());
1436
[email protected]ee8d6fd2010-05-26 17:05:481437 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491438 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1439 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481440 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491441
[email protected]36808ad2010-10-20 19:18:301442 scoped_ptr<skia::PlatformCanvas> canvas(
1443 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1444 canvas_size.height()));
1445 if (!canvas.get()) {
1446 NOTREACHED();
1447 return;
1448 }
1449
[email protected]d65adb12010-04-28 17:26:491450 // Reset bounds to what we actually received, but they should be the
1451 // same.
1452 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1453 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1454 bounds.set_width(canvas->getDevice()->width());
1455 bounds.set_height(canvas->getDevice()->height());
1456
1457 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081458 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491459 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1460
[email protected]948f7ab72010-05-28 23:48:081461 // Have to make sure we're laid out at the right size before
1462 // rendering.
1463 gfx::Size old_size = webwidget_->size();
1464 webwidget_->resize(page_size);
1465 webwidget_->layout();
1466
[email protected]d65adb12010-04-28 17:26:491467 // Paint the entire thing (using original bounds, not scaled bounds).
1468 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1469 canvas->restore();
1470
[email protected]948f7ab72010-05-28 23:48:081471 // Return the widget to its previous size.
1472 webwidget_->resize(old_size);
1473
[email protected]c88c9442010-07-19 18:55:091474 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491475}
1476
[email protected]ec7dc112008-08-06 05:30:121477void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1478 // During shutdown we can just ignore this message.
1479 if (!webwidget_)
1480 return;
1481
1482 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561483 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041484 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461485 scheduleComposite();
1486 } else {
1487 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1488 didInvalidateRect(repaint_rect);
1489 }
[email protected]ec7dc112008-08-06 05:30:121490}
1491
[email protected]fea38fc2012-06-13 17:38:371492void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]dea5e7682012-06-14 05:21:241493 if (device_scale_factor_ == device_scale_factor)
1494 return;
1495
1496 device_scale_factor_ = device_scale_factor;
1497
1498 if (!is_accelerated_compositing_active_) {
1499 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1500 } else {
1501 scheduleComposite();
1502 }
[email protected]fea38fc2012-06-13 17:38:371503}
1504
[email protected]4873c7d2009-07-16 06:36:281505void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111506 if (!webwidget_)
1507 return;
[email protected]4873c7d2009-07-16 06:36:281508 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111509}
1510
[email protected]719b36f2010-12-22 20:36:461511webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151512 const gfx::Rect& paint_bounds,
1513 TransportDIB** dib,
1514 gfx::Rect* location,
1515 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461516 // Bare RenderWidgets don't support optimized plugin painting.
1517 return NULL;
[email protected]ca4847f2010-09-24 05:39:151518}
1519
[email protected]bcaf2272011-02-15 15:29:431520gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521521 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431522 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521523}
1524
[email protected]bee16aab2009-08-26 15:55:031525void RenderWidget::SetHidden(bool hidden) {
1526 if (is_hidden_ == hidden)
1527 return;
1528
1529 // The status has changed. Tell the RenderThread about it.
1530 is_hidden_ = hidden;
1531 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271532 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031533 else
[email protected]380244092011-10-07 17:26:271534 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031535}
1536
[email protected]2b624c562011-10-27 22:58:261537void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261538 if (!webwidget_)
1539 return;
1540
1541 if (is_fullscreen_) {
1542 webwidget_->willExitFullScreen();
1543 } else {
1544 webwidget_->willEnterFullScreen();
1545 }
[email protected]2b624c562011-10-27 22:58:261546}
1547
1548void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261549 if (!webwidget_)
1550 return;
1551
1552 if (is_fullscreen_) {
1553 webwidget_->didEnterFullScreen();
1554 } else {
1555 webwidget_->didExitFullScreen();
1556 }
[email protected]2b624c562011-10-27 22:58:261557}
1558
[email protected]699ab0d2009-04-23 23:19:141559void RenderWidget::SetBackground(const SkBitmap& background) {
1560 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461561
[email protected]699ab0d2009-04-23 23:19:141562 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281563 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141564}
1565
[email protected]674741932009-02-04 23:44:461566bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051567 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461568}
1569
1570bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051571 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461572}
1573
1574void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051575 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461576}
1577
1578void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051579 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461580}
1581
1582void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051583 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461584}
1585
[email protected]e99ef6f2011-10-16 01:13:001586void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041587 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291588 return;
[email protected]fa7b1dc2010-06-23 17:53:041589
[email protected]ad26ef42011-06-17 07:59:451590 ui::TextInputType new_type = GetTextInputType();
1591 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001592 // Only sends text input type and compose inline to the browser process if
1593 // they are changed.
1594 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451595 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041596 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451597 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001598 Send(new ViewHostMsg_TextInputStateChanged(
1599 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291600 }
initial.commit09911bf2008-07-26 23:55:291601}
1602
[email protected]3f783362011-10-21 22:40:501603void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1604 WebRect start_webrect;
1605 WebRect end_webrect;
1606 webwidget_->selectionBounds(start_webrect, end_webrect);
1607 *start = start_webrect;
1608 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321609}
1610
[email protected]e99ef6f2011-10-16 01:13:001611void RenderWidget::UpdateSelectionBounds() {
1612 if (!webwidget_)
1613 return;
1614
[email protected]3f783362011-10-21 22:40:501615 gfx::Rect start_rect;
1616 gfx::Rect end_rect;
1617 GetSelectionBounds(&start_rect, &end_rect);
[email protected]58b48a0d2012-06-13 07:01:351618 if (selection_start_rect_ != start_rect || selection_end_rect_ != end_rect) {
1619 selection_start_rect_ = start_rect;
1620 selection_end_rect_ = end_rect;
1621 Send(new ViewHostMsg_SelectionBoundsChanged(
1622 routing_id_, selection_start_rect_, selection_end_rect_));
1623 }
[email protected]e99ef6f2011-10-16 01:13:001624
[email protected]58b48a0d2012-06-13 07:01:351625 std::vector<gfx::Rect> character_bounds;
1626 GetCompositionCharacterBounds(&character_bounds);
1627 UpdateCompositionInfo(composition_range_, character_bounds);
1628}
1629
1630bool RenderWidget::ShouldUpdateCompositionInfo(
1631 const ui::Range& range,
1632 const std::vector<gfx::Rect>& bounds) {
1633 if (composition_range_ != range)
1634 return true;
1635 if (bounds.size() != composition_character_bounds_.size())
1636 return true;
1637 for (size_t i = 0; i < bounds.size(); ++i) {
1638 if (bounds[i] != composition_character_bounds_[i])
1639 return true;
1640 }
1641 return false;
[email protected]e99ef6f2011-10-16 01:13:001642}
1643
[email protected]73bf95812011-10-12 11:38:321644// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451645COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1646 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1647COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1648 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1649COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1650 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181651COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1652 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1653COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1654 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1655COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1656 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1657COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1658 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1659COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1660 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:001661COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
1662 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
1663COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
1664 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
1665COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
1666 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
1667COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
1668 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
1669COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
1670 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
1671COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
1672 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]ad26ef42011-06-17 07:59:451673
1674ui::TextInputType RenderWidget::GetTextInputType() {
1675 if (webwidget_) {
1676 int type = webwidget_->textInputType();
1677 // Check the type is in the range representable by ui::TextInputType.
[email protected]feb8cf752012-06-08 04:48:001678 DCHECK_LE(type, ui::TEXT_INPUT_TYPE_WEEK) <<
[email protected]ad26ef42011-06-17 07:59:451679 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1680 return static_cast<ui::TextInputType>(type);
1681 }
1682 return ui::TEXT_INPUT_TYPE_NONE;
1683}
1684
[email protected]58b48a0d2012-06-13 07:01:351685void RenderWidget::GetCompositionCharacterBounds(
1686 std::vector<gfx::Rect>* bounds) {
1687 DCHECK(bounds);
1688 bounds->clear();
1689}
1690
[email protected]ad26ef42011-06-17 07:59:451691bool RenderWidget::CanComposeInline() {
1692 return true;
[email protected]56ea1a62011-05-30 07:05:571693}
1694
[email protected]4873c7d2009-07-16 06:36:281695WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041696 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281697}
1698
[email protected]f660d9c2012-06-06 18:31:211699float RenderWidget::deviceScaleFactor() {
1700 return device_scale_factor_;
1701}
1702
[email protected]fa7b1dc2010-06-23 17:53:041703void RenderWidget::resetInputMethod() {
1704 if (!input_method_is_active_)
1705 return;
1706
1707 // If the last text input type is not None, then we should finish any
1708 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451709 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041710 // If a composition text exists, then we need to let the browser process
1711 // to cancel the input method's ongoing composition session.
1712 if (webwidget_->confirmComposition())
1713 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1714 }
[email protected]d4cff272011-05-02 15:46:011715
1716 // Send an updated IME range with the current caret rect.
1717 ui::Range range(ui::Range::InvalidRange());
1718 size_t location, length;
1719 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1720 range.set_start(location);
1721 range.set_end(location + length);
1722 }
[email protected]58b48a0d2012-06-13 07:01:351723
1724 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:041725}
1726
[email protected]f103ab72009-09-02 17:10:591727void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501728 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291729 size_t i = 0;
1730 for (; i < plugin_window_moves_.size(); ++i) {
1731 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581732 if (move.rects_valid) {
1733 plugin_window_moves_[i] = move;
1734 } else {
1735 plugin_window_moves_[i].visible = move.visible;
1736 }
initial.commit09911bf2008-07-26 23:55:291737 break;
1738 }
1739 }
1740
1741 if (i == plugin_window_moves_.size())
1742 plugin_window_moves_.push_back(move);
1743}
[email protected]268654772009-08-06 23:02:041744
1745void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1746 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1747 i != plugin_window_moves_.end(); ++i) {
1748 if (i->window == window) {
1749 plugin_window_moves_.erase(i);
1750 break;
1751 }
1752 }
1753}
[email protected]67bfb83f2011-09-22 03:36:371754
1755bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1756 return false;
1757}
[email protected]c3d45532011-10-07 19:20:401758
1759bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1760 return false;
1761}