blob: 69e7d730865ccc2262ff6e6e13ae9aea0c646428 [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"
36#include "third_party/skia/include/effects/SkTableColorFilter.h"
[email protected]08397d52011-02-05 01:53:3837#include "ui/gfx/point.h"
38#include "ui/gfx/size.h"
[email protected]1835b9e2012-02-28 13:12:4839#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2740#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4141#include "ui/surface/transport_dib.h"
[email protected]8c89e7792009-08-19 21:18:3442#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5043#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4644#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4845
46#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4947#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5248#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4149#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4850#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4451
[email protected]8bd0fe62011-01-17 06:44:3752#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2953
[email protected]fa7b1dc2010-06-23 17:53:0454using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3055using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2256using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0657using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2858using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4459using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0060using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2861using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5962using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1863using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0164using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5265using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1966using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5267using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2868using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2469using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0470using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1871using WebKit::WebWidget;
[email protected]380244092011-10-07 17:26:2772using content::RenderThread;
[email protected]62cb33cae2009-03-27 23:30:2273
[email protected]f1cccb32012-06-06 18:29:5974static const int kStandardDPI = 160;
75
[email protected]6fd35b72012-03-01 19:46:4176RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:0477 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:4478 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:2979 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:5680 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:1181 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2982 opener_id_(MSG_ROUTING_NONE),
[email protected]659f73f2009-10-13 13:43:4283 host_window_(0),
[email protected]05a980d7a2012-02-07 22:16:4284 host_window_set_(false),
[email protected]b4d08452010-10-05 17:34:3585 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2986 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:0687 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:0588 update_reply_pending_(false),
[email protected]ea3ee0a2012-05-15 03:43:0989 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:2490 using_asynchronous_swapbuffers_(false),
91 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2992 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2993 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:0994 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:2995 needs_repainting_on_restore_(false),
96 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4997 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4898 closing_(false),
[email protected]14392a52012-05-02 20:28:4499 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04100 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45101 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
102 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12103 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48104 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12105 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50106 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21107 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07108 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04109 screen_info_(screen_info),
[email protected]f1cccb32012-06-06 18:29:59110 device_scale_factor_(1),
[email protected]4b03e292012-02-13 18:40:07111 invert_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05112 if (!swapped_out)
113 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27114 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18115 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
116 switches::kDisableGpuVsync);
[email protected]424820962012-06-08 15:33:19117#if defined(OS_CHROMEOS) || defined(OS_MACOSX)
[email protected]f1cccb32012-06-06 18:29:59118 device_scale_factor_ = screen_info.verticalDPI / kStandardDPI;
119#endif
initial.commit09911bf2008-07-26 23:55:29120}
121
122RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11123 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21124 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35125 if (current_paint_buf_) {
126 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
127 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29128 }
[email protected]992db4c2011-05-12 15:37:15129 // If we are swapped out, we have released already.
130 if (!is_swapped_out_)
131 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29132}
133
[email protected]484955942010-08-19 16:13:18134// static
[email protected]8085dbc82008-09-26 22:53:44135RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04136 WebKit::WebPopupType popup_type,
137 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29138 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41139 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04140 new RenderWidget(popup_type, screen_info, false));
initial.commit09911bf2008-07-26 23:55:29141 widget->Init(opener_id); // adds reference
142 return widget;
143}
144
[email protected]484955942010-08-19 16:13:18145// static
146WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
147 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03148 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18149 break;
150 case WebKit::WebPopupTypeSelect:
151 case WebKit::WebPopupTypeSuggestion:
152 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44153 case WebKit::WebPopupTypePage:
154 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18155 default:
156 NOTREACHED();
157 }
158 return NULL;
159}
160
initial.commit09911bf2008-07-26 23:55:29161void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18162 DoInit(opener_id,
163 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56164 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
165 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18166}
167
[email protected]484955942010-08-19 16:13:18168void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06169 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18170 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29171 DCHECK(!webwidget_);
172
173 if (opener_id != MSG_ROUTING_NONE)
174 opener_id_ = opener_id;
175
[email protected]484955942010-08-19 16:13:18176 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29177
[email protected]380244092011-10-07 17:26:27178 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29179 if (result) {
[email protected]380244092011-10-07 17:26:27180 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29181 // Take a reference on behalf of the RenderThread. This will be balanced
182 // when we receive ViewMsg_Close.
183 AddRef();
184 } else {
185 DCHECK(false);
186 }
187}
188
189// This is used to complete pending inits and non-pending inits. For non-
190// pending cases, the parent will be the same as the current parent. This
191// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55192void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29193 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29194
195 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42196 host_window_set_ = true;
197
[email protected]f1d5de42012-04-20 01:47:14198#if WEBWIDGET_HAS_SETCOMPOSITORSURFACEREADY
199 if (webwidget_)
200 webwidget_->setCompositorSurfaceReady();
201#endif
[email protected]05a980d7a2012-02-07 22:16:42202 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29203
[email protected]6de74452009-02-25 18:04:59204 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29205}
206
[email protected]992db4c2011-05-12 15:37:15207void RenderWidget::SetSwappedOut(bool is_swapped_out) {
208 // We should only toggle between states.
209 DCHECK(is_swapped_out_ != is_swapped_out);
210 is_swapped_out_ = is_swapped_out;
211
212 // If we are swapping out, we will call ReleaseProcess, allowing the process
213 // to exit if all of its RenderViews are swapped out. We wait until the
214 // WasSwappedOut call to do this, to avoid showing the sad tab.
215 // If we are swapping in, we call AddRefProcess to prevent the process from
216 // exiting.
217 if (!is_swapped_out)
218 RenderProcess::current()->AddRefProcess();
219}
220
[email protected]a95986a82010-12-24 06:19:28221bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
222 bool handled = true;
223 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
224 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
225 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
226 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54227 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28228 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
229 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15230 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28231 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
232 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
233 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
234 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
235 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
236 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
237 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
238 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
239 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
240 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
241 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]4b03e292012-02-13 18:40:07242 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
[email protected]a95986a82010-12-24 06:19:28243 IPC_MESSAGE_UNHANDLED(handled = false)
244 IPC_END_MESSAGE_MAP()
245 return handled;
246}
initial.commit09911bf2008-07-26 23:55:29247
248bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15249 // Don't send any messages after the browser has told us to close, and filter
250 // most outgoing messages while swapped out.
251 if ((is_swapped_out_ &&
252 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11253 closing_) {
initial.commit09911bf2008-07-26 23:55:29254 delete message;
255 return false;
256 }
257
258 // If given a messsage without a routing ID, then assign our routing ID.
259 if (message->routing_id() == MSG_ROUTING_NONE)
260 message->set_routing_id(routing_id_);
261
[email protected]380244092011-10-07 17:26:27262 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44263}
264
[email protected]61e2b3cc2012-03-02 16:13:34265void RenderWidget::Resize(const gfx::Size& new_size,
266 const gfx::Rect& resizer_rect,
267 bool is_fullscreen,
268 ResizeAck resize_ack) {
269 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
270 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
271 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29272
[email protected]61e2b3cc2012-03-02 16:13:34273 // Ignore this during shutdown.
274 if (!webwidget_)
275 return;
276
277 // Remember the rect where the resize corner will be drawn.
278 resizer_rect_ = resizer_rect;
279
280 // NOTE: We may have entered fullscreen mode without changing our size.
281 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
282 if (fullscreen_change)
283 WillToggleFullscreen();
284 is_fullscreen_ = is_fullscreen;
285
286 if (size_ != new_size) {
287 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34288 needs_repainting_on_restore_ = false;
289
290 size_ = new_size;
291
292 paint_aggregator_.ClearPendingUpdate();
293
294 // When resizing, we want to wait to paint before ACK'ing the resize. This
295 // ensures that we only resize as fast as we can paint. We only need to
296 // send an ACK if we are resized to a non-empty rect.
297 webwidget_->resize(new_size);
298 if (!new_size.IsEmpty()) {
299 if (!is_accelerated_compositing_active_) {
300 // Resize should have caused an invalidation of the entire view.
301 DCHECK(paint_aggregator_.HasPendingUpdate());
302 }
303
304 // Send the Resize_ACK flag once we paint again if requested.
305 if (resize_ack == SEND_RESIZE_ACK)
306 set_next_paint_is_resize_ack();
307 }
[email protected]ff475a322012-03-14 00:05:35308 } else {
309 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34310 }
311
312 if (fullscreen_change)
313 DidToggleFullscreen();
314
315 // If a resize ack is requested and it isn't set-up, then no more resizes will
316 // come in and in general things will go wrong.
317 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
318 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29319}
320
321void RenderWidget::OnClose() {
322 if (closing_)
323 return;
324 closing_ = true;
325
326 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03327 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27328 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03329 SetHidden(false);
330 }
initial.commit09911bf2008-07-26 23:55:29331
initial.commit09911bf2008-07-26 23:55:29332 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25333 // now. Post a task that only gets invoked when there are no nested message
334 // loops.
[email protected]32876ae2011-11-15 22:25:21335 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29336 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25337
338 // Balances the AddRef taken when we called AddRoute.
339 Release();
initial.commit09911bf2008-07-26 23:55:29340}
341
[email protected]61e2b3cc2012-03-02 16:13:34342// Got a response from the browser after the renderer decided to create a new
343// view.
344void RenderWidget::OnCreatingNewAck(
345 gfx::NativeViewId parent) {
346 DCHECK(routing_id_ != MSG_ROUTING_NONE);
347
348 CompleteInit(parent);
349}
350
[email protected]f21c613a2009-02-12 14:46:17351void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09352 const gfx::Rect& resizer_rect,
353 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34354 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29355}
356
[email protected]b5913d72012-02-07 22:26:54357void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
358 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59359 gfx::Rect view_rect(size_);
360
361 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
362 if (!old_damage_rect.IsEmpty())
363 paint_aggregator_.InvalidateRect(old_damage_rect);
364
365 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
366 if (!new_damage_rect.IsEmpty())
367 paint_aggregator_.InvalidateRect(new_damage_rect);
368
[email protected]b5913d72012-02-07 22:26:54369 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59370
[email protected]b5913d72012-02-07 22:26:54371 if (webwidget_)
372 webwidget_->didChangeWindowResizerRect();
373 }
374}
375
initial.commit09911bf2008-07-26 23:55:29376void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31377 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29378 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03379 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29380}
381
382void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31383 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29384 // During shutdown we can just ignore this message.
385 if (!webwidget_)
386 return;
387
388 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03389 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29390
391 if (!needs_repainting && !needs_repainting_on_restore_)
392 return;
393 needs_repainting_on_restore_ = false;
394
[email protected]d65adb12010-04-28 17:26:49395 // Tag the next paint as a restore ack, which is picked up by
396 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29397 set_next_paint_is_restore_ack();
398
399 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56400 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46401 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
402 } else {
403 scheduleComposite();
404 }
initial.commit09911bf2008-07-26 23:55:29405}
406
[email protected]992db4c2011-05-12 15:37:15407void RenderWidget::OnWasSwappedOut() {
408 // If we have been swapped out and no one else is using this process,
409 // it's safe to exit now. If we get swapped back in, we will call
410 // AddRefProcess in SetSwappedOut.
411 if (is_swapped_out_)
412 RenderProcess::current()->ReleaseProcess();
413}
414
[email protected]53d3f302009-12-21 04:42:05415void RenderWidget::OnRequestMoveAck() {
416 DCHECK(pending_window_rect_count_);
417 pending_window_rect_count_--;
418}
419
420void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58421 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21422 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05423 update_reply_pending_ = false;
424
[email protected]b4d08452010-10-05 17:34:35425 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
426 // have no current paint buffer.
427 if (current_paint_buf_) {
428 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
429 current_paint_buf_ = NULL;
430 }
431
[email protected]65225772011-05-12 21:10:24432 // If swapbuffers is still pending, then defer the update until the
433 // swapbuffers occurs.
434 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
435 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
436 return;
437 }
438
[email protected]29ed96a2012-02-04 18:12:16439 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18440 if (!is_accelerated_compositing_active_) {
441 DidFlushPaint();
442 }
[email protected]a2f6bc112009-06-27 16:27:25443
initial.commit09911bf2008-07-26 23:55:29444 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24445 DoDeferredUpdateAndSendInputAck();
446}
447
[email protected]d0be63772011-12-20 23:18:04448bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24449 return false;
450}
451
[email protected]d0be63772011-12-20 23:18:04452void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24453 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21454 while (!updates_pending_swap_.empty()) {
455 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
456 updates_pending_swap_.pop_front();
457 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
458 // compositing pass, hence doesn't require an UpdateRect message.
459 if (msg)
460 Send(msg);
461 }
[email protected]65225772011-05-12 21:10:24462 num_swapbuffers_complete_pending_ = 0;
463 using_asynchronous_swapbuffers_ = false;
464 // Schedule another frame so the compositor learns about it.
465 scheduleComposite();
466}
467
[email protected]37a6f302011-07-11 23:43:08468void RenderWidget::OnSwapBuffersPosted() {
469 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21470
471 if (using_asynchronous_swapbuffers_) {
472 ViewHostMsg_UpdateRect* msg = NULL;
473 // pending_update_params_ can be NULL if the swap doesn't correspond to an
474 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
475 // message.
476 if (pending_update_params_.get()) {
477 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
478 pending_update_params_.reset();
479 }
480 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08481 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21482 }
[email protected]37a6f302011-07-11 23:43:08483}
484
485void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24486 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16487
[email protected]404939f2012-06-01 04:06:18488 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16489 DidFlushPaint();
490
[email protected]65225772011-05-12 21:10:24491 // When compositing deactivates, we reset the swapbuffers pending count. The
492 // swapbuffers acks may still arrive, however.
493 if (num_swapbuffers_complete_pending_ == 0) {
494 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
495 return;
496 }
[email protected]aa4117f2011-12-09 22:19:21497 DCHECK(!updates_pending_swap_.empty());
498 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
499 updates_pending_swap_.pop_front();
500 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
501 // compositing pass, hence doesn't require an UpdateRect message.
502 if (msg)
503 Send(msg);
[email protected]65225772011-05-12 21:10:24504 num_swapbuffers_complete_pending_--;
505
506 // If update reply is still pending, then defer the update until that reply
507 // occurs.
[email protected]d0be63772011-12-20 23:18:04508 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24509 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
510 return;
511 }
512
513 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06514 // when we were previously rendering. However, if an invalidation task is not
515 // posted, there may be software rendering work pending. In that case, don't
516 // early out.
517 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24518 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
519 return;
520 }
521
[email protected]65225772011-05-12 21:10:24522 // Continue painting if necessary...
523 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29524}
525
initial.commit09911bf2008-07-26 23:55:29526void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24527 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56528 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29529
530 const char* data;
531 int data_length;
[email protected]5dd768212009-08-13 23:34:49532 handling_input_event_ = true;
533 if (!message.ReadData(&iter, &data, &data_length)) {
534 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29535 return;
[email protected]5dd768212009-08-13 23:34:49536 }
initial.commit09911bf2008-07-26 23:55:29537
538 const WebInputEvent* input_event =
539 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48540
[email protected]b68a0e52011-12-08 15:11:12541 bool is_keyboard_shortcut = false;
542 // is_keyboard_shortcut flag is only available for RawKeyDown events.
543 if (input_event->type == WebInputEvent::RawKeyDown)
544 message.ReadBool(&iter, &is_keyboard_shortcut);
545
[email protected]67bfb83f2011-09-22 03:36:37546 bool prevent_default = false;
547 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26548 const WebMouseEvent& mouse_event =
549 *static_cast<const WebMouseEvent*>(input_event);
550 TRACE_EVENT2("renderer", "HandleMouseMove",
551 "x", mouse_event.x, "y", mouse_event.y);
552 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37553 }
554
555 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12556 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
557 suppress_next_char_events_ = false;
558 if (!processed && webwidget_)
559 processed = webwidget_->handleInputEvent(*input_event);
560 }
561
562 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
563 // it's not processed by webkit, then we need to suppress the upcoming Char
564 // events.
565 if (!processed && is_keyboard_shortcut)
566 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29567
[email protected]a9fb30aa2011-10-06 06:58:46568 IPC::Message* response =
569 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
570 processed);
[email protected]3391a0772012-03-28 00:32:07571 bool event_type_gets_rate_limited =
572 input_event->type == WebInputEvent::MouseMove ||
573 input_event->type == WebInputEvent::MouseWheel ||
574 WebInputEvent::isTouchEventType(input_event->type);
575 bool is_input_throttled =
576 webwidget_->isInputThrottled() ||
577 paint_aggregator_.HasPendingUpdate();
[email protected]e2824412009-02-27 01:57:05578
[email protected]f8868d72012-04-27 19:13:03579 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24580 // We want to rate limit the input events in this case, so we'll wait for
581 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17582 if (pending_input_event_ack_.get()) {
583 // As two different kinds of events could cause us to postpone an ack
584 // we send it now, if we have one pending. The Browser should never
585 // send us the same kind of event we are delaying the ack for.
586 Send(pending_input_event_ack_.release());
587 }
[email protected]12fbad812009-09-01 18:21:24588 pending_input_event_ack_.reset(response);
589 } else {
590 Send(response);
591 }
592
[email protected]5dd768212009-08-13 23:34:49593 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48594
[email protected]67bfb83f2011-09-22 03:36:37595 if (!prevent_default) {
596 if (WebInputEvent::isKeyboardEventType(input_event->type))
597 DidHandleKeyEvent();
598 if (WebInputEvent::isMouseEventType(input_event->type))
599 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24600 if (WebInputEvent::isTouchEventType(input_event->type))
601 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37602 }
initial.commit09911bf2008-07-26 23:55:29603}
604
605void RenderWidget::OnMouseCaptureLost() {
606 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28607 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29608}
609
610void RenderWidget::OnSetFocus(bool enable) {
611 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33612 if (webwidget_)
613 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29614}
615
616void RenderWidget::ClearFocus() {
617 // We may have got the focus from the browser before this gets processed, in
618 // which case we do not want to unfocus ourself.
619 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28620 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29621}
622
[email protected]2d5d09d52009-06-15 14:29:21623void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00624 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21625 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06626 TRACE_EVENT2("renderer", "PaintRect",
627 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00628 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21629
630 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00631 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
632 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03633
[email protected]4b03e292012-02-13 18:40:07634 if (invert_) {
635 // Draw everything to a temporary bitmap and then apply an
636 // inverting color map to the result. This is balanced by an extra
637 // call to canvas->restore(), below.
638 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48639 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07640 canvas->saveLayer(&bounds, invert_paint_.get());
641 }
642
[email protected]699ab0d2009-04-23 23:19:14643 // If there is a custom background, tile it.
644 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14645 SkPaint paint;
646 SkShader* shader = SkShader::CreateBitmapShader(background_,
647 SkShader::kRepeat_TileMode,
648 SkShader::kRepeat_TileMode);
649 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20650
651 // Use kSrc_Mode to handle background_ transparency properly.
652 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
653
654 // Canvas could contain multiple update rects. Clip to given rect so that
655 // we don't accidentally clear other update rects.
656 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48657 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14658 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20659 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14660 }
661
[email protected]719b36f2010-12-22 20:36:46662 // First see if this rect is a plugin that can paint itself faster.
663 TransportDIB* optimized_dib = NULL;
664 gfx::Rect optimized_copy_rect, optimized_copy_location;
665 webkit::ppapi::PluginInstance* optimized_instance =
666 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
667 &optimized_copy_location,
668 &optimized_copy_rect);
669 if (optimized_instance) {
670 // This plugin can be optimize-painted and we can just ask it to paint
671 // itself. We don't actually need the TransportDIB in this case.
672 //
673 // This is an optimization for PPAPI plugins that know they're on top of
674 // the page content. If this rect is inside such a plugin, we can save some
675 // time and avoid re-rendering the page content which we know will be
676 // covered by the plugin later (this time can be significant, especially
677 // for a playing movie that is invalidating a lot).
678 //
679 // In the plugin movie case, hopefully the similar call to
680 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
681 // painting, because that avoids copying the plugin image to a different
682 // paint rect. Unfortunately, if anything on the page is animating other
683 // than the movie, it break this optimization since the union of the
684 // invalid regions will be larger than the plugin.
685 //
686 // This code optimizes that case, where we can still avoid painting in
687 // WebKit and filling the background (which can be slow) and just painting
688 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
689 // required.
690 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27691 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46692 } else {
693 // Normal painting case.
694 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
695
696 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35697 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46698 }
initial.commit09911bf2008-07-26 23:55:29699
[email protected]4b03e292012-02-13 18:40:07700 if (invert_)
701 canvas->restore();
702
[email protected]4fb66842009-12-04 21:41:00703 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00704 canvas->restore();
705}
706
707void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
708 skia::PlatformCanvas* canvas) {
709 static bool kPaintBorder =
710 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
711 if (!kPaintBorder)
712 return;
713
[email protected]53d3f302009-12-21 04:42:05714 // Cycle through these colors to help distinguish new paint rects.
715 const SkColor colors[] = {
716 SkColorSetARGB(0x3F, 0xFF, 0, 0),
717 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
718 SkColorSetARGB(0x3F, 0, 0, 0xFF),
719 };
720 static int color_selector = 0;
721
[email protected]4fb66842009-12-04 21:41:00722 SkPaint paint;
723 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05724 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00725 paint.setStrokeWidth(1);
726
727 SkIRect irect;
728 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
729 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29730}
731
[email protected]52ccd0ea2011-02-16 01:09:05732void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30733 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30734 if (!animation_update_pending_) {
735 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59736 return;
[email protected]921244e42011-07-20 16:36:30737 }
[email protected]bd37ae252011-06-03 01:28:18738 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59739 // Record when we fired (according to base::Time::Now()) relative to when
740 // we posted the task to quantify how much the base::Time/base::TimeTicks
741 // skew is affecting animations.
742 base::TimeDelta animation_callback_delay = base::Time::Now() -
743 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
744 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
745 animation_callback_delay,
746 base::TimeDelta::FromMilliseconds(0),
747 base::TimeDelta::FromMilliseconds(30),
748 25);
749 }
[email protected]65225772011-05-12 21:10:24750 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24751}
752
[email protected]52ccd0ea2011-02-16 01:09:05753void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59754 if (!animation_update_pending_)
755 return;
[email protected]bd37ae252011-06-03 01:28:18756
757 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33758 base::TimeDelta animationInterval = IsRenderingVSynced() ?
759 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18760
[email protected]7c4329e2011-02-18 22:02:59761 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45762
763 // animation_floor_time_ is the earliest time that we should animate when
764 // using the dead reckoning software scheduler. If we're using swapbuffers
765 // complete callbacks to rate limit, we can ignore this floor.
766 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30767 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33768 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18769 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59770 // running animation callbacks so that if a callback requests another
771 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38772 animation_timer_.Stop();
773 animation_timer_.Start(FROM_HERE, animationInterval, this,
774 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59775 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30776 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59777 return;
[email protected]5f8b1022011-01-21 23:34:50778 }
[email protected]bd37ae252011-06-03 01:28:18779 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38780 if (!animation_timer_.IsRunning()) {
781 // This code uses base::Time::Now() to calculate the floor and next fire
782 // time because javascript's Date object uses base::Time::Now(). The
783 // message loop uses base::TimeTicks, which on windows can have a
784 // different granularity than base::Time.
785 // The upshot of all this is that this function might be called before
786 // base::Time::Now() has advanced past the animation_floor_time_. To
787 // avoid exposing this delay to javascript, we keep posting delayed
788 // tasks until base::Time::Now() has advanced far enough.
789 base::TimeDelta delay = animation_floor_time_ - now;
790 animation_timer_.Start(FROM_HERE, delay, this,
791 &RenderWidget::AnimationCallback);
792 }
[email protected]5f8b1022011-01-21 23:34:50793}
794
[email protected]bd37ae252011-06-03 01:28:18795bool RenderWidget::IsRenderingVSynced() {
796 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
797 // not caught by this check. This will lead to artificially low frame rates
798 // for people who force vsync off at a driver level and expect Chrome to speed
799 // up.
800 return !has_disable_gpu_vsync_switch_;
801}
802
[email protected]65225772011-05-12 21:10:24803void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06804 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24805 invalidation_task_posted_ = false;
806 DoDeferredUpdateAndSendInputAck();
807}
808
809void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05810 DoDeferredUpdate();
811
812 if (pending_input_event_ack_.get())
813 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21814}
815
[email protected]552e6002009-11-19 05:24:57816void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58817 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08818
[email protected]65225772011-05-12 21:10:24819 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29820 return;
[email protected]05a980d7a2012-02-07 22:16:42821
822 if (!host_window_set_) {
823 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
824 return;
825 }
[email protected]aa4117f2011-12-09 22:19:21826 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24827 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
828 return;
829 }
[email protected]9ca84622011-06-02 23:46:39830 if (is_accelerated_compositing_active_ &&
831 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24832 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
833 return;
834 }
initial.commit09911bf2008-07-26 23:55:29835
[email protected]552e6002009-11-19 05:24:57836 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29837 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57838 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29839 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24840 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29841 return;
842 }
843
[email protected]05a980d7a2012-02-07 22:16:42844 if (is_accelerated_compositing_active_)
845 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
846
[email protected]0fb93f52011-05-18 23:13:56847 // Tracking of frame rate jitter
848 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51849 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05850 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50851
[email protected]f98d7e3c2010-09-13 22:30:46852 // Layout may generate more invalidation. It may also enable the
853 // GPU acceleration, so make sure to run layout before we send the
854 // GpuRenderingActivated message.
855 webwidget_->layout();
856
[email protected]dcca3aa92012-02-17 23:03:37857 // The following two can result in further layout and possibly
858 // enable GPU acceleration so they need to be called before any painting
859 // is done.
860 UpdateTextInputState();
861 UpdateSelectionBounds();
862
[email protected]5f8b1022011-01-21 23:34:50863 // Suppress painting if nothing is dirty. This has to be done after updating
864 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24865 if (!paint_aggregator_.HasPendingUpdate()) {
866 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51867 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50868 return;
[email protected]65225772011-05-12 21:10:24869 }
[email protected]5f8b1022011-01-21 23:34:50870
[email protected]872ae5b2011-05-26 20:20:50871 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56872 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04873 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56874 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
875 delay,
876 base::TimeDelta::FromMilliseconds(1),
877 base::TimeDelta::FromMilliseconds(60),
878 30);
[email protected]d0be63772011-12-20 23:18:04879 } else {
[email protected]0fb93f52011-05-18 23:13:56880 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
881 delay,
882 base::TimeDelta::FromMilliseconds(1),
883 base::TimeDelta::FromMilliseconds(60),
884 30);
[email protected]d0be63772011-12-20 23:18:04885 }
[email protected]872ae5b2011-05-26 20:20:50886
887 // Calculate filtered time per frame:
888 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
889 filtered_time_per_frame_ =
890 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56891 }
892 last_do_deferred_update_time_ = frame_begin_ticks;
893
[email protected]552e6002009-11-19 05:24:57894 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29895 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30896 PaintAggregator::PendingUpdate update;
897 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29898
[email protected]53d3f302009-12-21 04:42:05899 gfx::Rect scroll_damage = update.GetScrollDamage();
900 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29901
[email protected]29ed96a2012-02-04 18:12:16902 // Notify derived classes that we're about to initiate a paint.
903 WillInitiatePaint();
904
[email protected]ca4847f2010-09-24 05:39:15905 // A plugin may be able to do an optimized paint. First check this, in which
906 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46907 // This optimization allows PPAPI plugins that declare themselves on top of
908 // the page (like a traditional windowed plugin) to be able to animate (think
909 // movie playing) without repeatedly re-painting the page underneath, or
910 // copying the plugin backing store (since we can send the plugin's backing
911 // store directly to the browser).
912 //
913 // This optimization only works when the entire invalid region is contained
914 // within the plugin. There is a related optimization in PaintRect for the
915 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15916 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15917 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21918 DCHECK(!pending_update_params_.get());
919 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
920 pending_update_params_->dx = update.scroll_delta.x();
921 pending_update_params_->dy = update.scroll_delta.y();
922 pending_update_params_->scroll_rect = update.scroll_rect;
923 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21924 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
925 pending_update_params_->flags = next_paint_flags_;
926 pending_update_params_->scroll_offset = GetScrollOffset();
927 pending_update_params_->needs_ack = true;
928 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:09929 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:21930
[email protected]ca4847f2010-09-24 05:39:15931 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56932 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15933 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
934 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27935 // Only update the part of the plugin that actually changed.
936 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21937 pending_update_params_->bitmap = dib->id();
938 pending_update_params_->bitmap_rect = optimized_copy_location;
939 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56940 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46941 // Compute a buffer for painting and cache it.
[email protected]f1cccb32012-06-06 18:29:59942 gfx::Rect pixel_bounds = bounds.Scale(device_scale_factor_);
[email protected]ca4847f2010-09-24 05:39:15943 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35944 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:59945 pixel_bounds));
[email protected]f98d7e3c2010-09-13 22:30:46946 if (!canvas.get()) {
947 NOTREACHED();
948 return;
949 }
[email protected]cef3362f2009-12-21 17:48:45950
[email protected]f98d7e3c2010-09-13 22:30:46951 // We may get back a smaller canvas than we asked for.
952 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:59953 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
954 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
955 pixel_bounds.set_width(canvas->getDevice()->width());
956 pixel_bounds.set_height(canvas->getDevice()->height());
957 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
958 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:05959
[email protected]f98d7e3c2010-09-13 22:30:46960 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
961
[email protected]aa4117f2011-12-09 22:19:21962 pending_update_params_->bitmap = current_paint_buf_->id();
963 pending_update_params_->bitmap_rect = bounds;
964
965 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46966 // The scroll damage is just another rectangle to paint and copy.
967 copy_rects.swap(update.paint_rects);
968 if (!scroll_damage.IsEmpty())
969 copy_rects.push_back(scroll_damage);
970
971 for (size_t i = 0; i < copy_rects.size(); ++i)
[email protected]f1cccb32012-06-06 18:29:59972 PaintRect(copy_rects[i], pixel_bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35973
974 // Software FPS tick for performance tests. The accelerated path traces the
975 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
976 // NOTE: Tests may break if this event is renamed or moved.
977 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46978 } else { // Accelerated compositing path
979 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21980 // If painting is done via the gpu process then we don't set any damage
981 // rects to save the browser process from doing unecessary work.
982 pending_update_params_->bitmap_rect = bounds;
983 pending_update_params_->scroll_rect = gfx::Rect();
984 // We don't need an ack, because we're not sharing a DIB with the browser.
985 // If it needs to (e.g. composited UI), the GPU process does its own ACK
986 // with the browser for the GPU surface.
987 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42988 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46989 }
990
[email protected]936c6f52011-12-13 01:35:26991 // If we're holding a pending input event ACK, send the ACK before sending the
992 // UpdateReply message so we can receive another input event before the
993 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
994 // the UpdateRect IPC message handler.
995 if (pending_input_event_ack_.get())
996 Send(pending_input_event_ack_.release());
997
[email protected]aa4117f2011-12-09 22:19:21998 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
999 // OnSwapBuffersPosted), meaning a message has been added to the
1000 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1001 // the message now.
1002 if (pending_update_params_.get()) {
1003 // sending an ack to browser process that the paint is complete...
1004 update_reply_pending_ = pending_update_params_->needs_ack;
1005 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1006 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341007 }
[email protected]53d3f302009-12-21 04:42:051008
[email protected]29ed96a2012-02-04 18:12:161009 // If we're software rendering then we're done initiating the paint.
1010 if (!is_accelerated_compositing_active_)
1011 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291012}
1013
1014///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461015// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291016
[email protected]4873c7d2009-07-16 06:36:281017void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:571018 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481019 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571020 gfx::Rect damaged_rect = view_rect.Intersect(rect);
1021 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291022 return;
1023
[email protected]552e6002009-11-19 05:24:571024 paint_aggregator_.InvalidateRect(damaged_rect);
1025
1026 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241027 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571028 return;
1029 if (!paint_aggregator_.HasPendingUpdate())
1030 return;
[email protected]aa4117f2011-12-09 22:19:211031 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241032 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1033 return;
1034
1035 // When GPU rendering, combine pending animations and invalidations into
1036 // a single update.
[email protected]816edc62012-03-17 01:27:221037 if (is_accelerated_compositing_active_ &&
1038 animation_update_pending_ &&
1039 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571040 return;
1041
1042 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291043 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1044 // on the call stack.
1045 // 2) Allows us to collect more damage rects before painting to help coalesce
1046 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241047 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211048 MessageLoop::current()->PostTask(
1049 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291050}
1051
[email protected]4873c7d2009-07-16 06:36:281052void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461053 // Drop scrolls on the floor when we are in compositing mode.
1054 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561055 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461056 return;
1057
[email protected]552e6002009-11-19 05:24:571058 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481059 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571060 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1061 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291062 return;
1063
[email protected]552e6002009-11-19 05:24:571064 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1065
1066 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241067 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571068 return;
1069 if (!paint_aggregator_.HasPendingUpdate())
1070 return;
[email protected]aa4117f2011-12-09 22:19:211071 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241072 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1073 return;
1074
1075 // When GPU rendering, combine pending animations and invalidations into
1076 // a single update.
[email protected]816edc62012-03-17 01:27:221077 if (is_accelerated_compositing_active_ &&
1078 animation_update_pending_ &&
1079 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571080 return;
1081
1082 // Perform updating asynchronously. This serves two purposes:
1083 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1084 // on the call stack.
1085 // 2) Allows us to collect more damage rects before painting to help coalesce
1086 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241087 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211088 MessageLoop::current()->PostTask(
1089 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291090}
1091
[email protected]244ac1892011-12-02 17:04:471092void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091093 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1094 size_ = new_size;
1095 need_update_rect_for_auto_resize_ = true;
1096 }
[email protected]244ac1892011-12-02 17:04:471097}
1098
[email protected]91acd1c2012-03-14 08:32:391099void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221100 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1101
[email protected]c63b4d42012-04-26 01:01:071102#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211103 if (!is_accelerated_compositing_active_) {
1104 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1105 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1106 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1107 // going to switch to accelerated compositing, the GPU process may need
1108 // round-trips to the browser's UI thread before finishing the frame,
1109 // causing deadlocks if we delay the UpdateRect until we receive the
1110 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071111 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1112 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211113 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1114 }
[email protected]c63b4d42012-04-26 01:01:071115#endif
[email protected]aa4117f2011-12-09 22:19:211116
[email protected]ea162f92011-10-04 23:08:221117 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421118 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241119 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221120}
1121
1122void RenderWidget::didDeactivateCompositor() {
1123 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1124
1125 is_accelerated_compositing_active_ = false;
1126 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1127 routing_id_, is_accelerated_compositing_active_));
1128
[email protected]ea162f92011-10-04 23:08:221129 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241130 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561131}
1132
[email protected]9cd43a62012-03-26 08:03:561133void RenderWidget::willBeginCompositorFrame() {
1134 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371135
1136 DCHECK(RenderThreadImpl::current()->compositor_thread());
1137
1138 // The following two can result in further layout and possibly
1139 // enable GPU acceleration so they need to be called before any painting
1140 // is done.
1141 UpdateTextInputState();
1142 UpdateSelectionBounds();
1143
[email protected]9cd43a62012-03-26 08:03:561144 WillInitiatePaint();
1145}
1146
[email protected]3391a0772012-03-28 00:32:071147void RenderWidget::didBecomeReadyForAdditionalInput() {
1148 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1149 if (pending_input_event_ack_.get())
1150 Send(pending_input_event_ack_.release());
1151}
1152
[email protected]58264a32011-11-17 23:36:151153void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501154 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351155 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1156 // NOTE: Tests may break if this event is renamed or moved.
1157 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161158 // Notify subclasses that we initiated the paint operation.
1159 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151160}
1161
1162void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181163 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1164
1165 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561166 DidFlushPaint();
1167
[email protected]aa4117f2011-12-09 22:19:211168 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151169 return;
1170
[email protected]ea3ee0a2012-05-15 03:43:091171 if (!next_paint_flags_ &&
1172 !need_update_rect_for_auto_resize_ &&
1173 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151174 return;
[email protected]ea3ee0a2012-05-15 03:43:091175 }
[email protected]58264a32011-11-17 23:36:151176
1177 ViewHostMsg_UpdateRect_Params params;
1178 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151179 params.plugin_window_moves.swap(plugin_window_moves_);
1180 params.flags = next_paint_flags_;
1181 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121182 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151183
1184 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1185 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091186 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151187}
1188
[email protected]f98d7e3c2010-09-13 22:30:461189void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041190 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401191 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041192 } else {
[email protected]c3d45532011-10-07 19:20:401193 // TODO(nduca): replace with something a little less hacky. The reason this
1194 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1195 // contains a lot of host-renderer synchronization logic that is still
1196 // important for the accelerated compositing case. The option of simply
1197 // duplicating all that code is less desirable than "faking out" the
1198 // invalidation path using a magical damage rect.
1199 didInvalidateRect(WebRect(0, 0, 1, 1));
1200 }
[email protected]f98d7e3c2010-09-13 22:30:461201}
1202
[email protected]5f8b1022011-01-21 23:34:501203void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201204 if (animation_update_pending_)
1205 return;
1206
[email protected]921244e42011-07-20 16:36:301207 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201208 animation_update_pending_ = true;
1209 if (!animation_timer_.IsRunning()) {
1210 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1211 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211212 }
[email protected]5f8b1022011-01-21 23:34:501213}
1214
[email protected]4873c7d2009-07-16 06:36:281215void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301216 // TODO(darin): Eliminate this temporary.
1217 WebCursor cursor(cursor_info);
1218
initial.commit09911bf2008-07-26 23:55:291219 // Only send a SetCursor message if we need to make a change.
1220 if (!current_cursor_.IsEqual(cursor)) {
1221 current_cursor_ = cursor;
1222 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1223 }
1224}
1225
1226// We are supposed to get a single call to Show for a newly created RenderWidget
1227// that was created via RenderWidget::CreateWebView. So, we wait until this
1228// point to dispatch the ShowWidget message.
1229//
1230// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281231// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291232//
[email protected]4873c7d2009-07-16 06:36:281233void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291234 DCHECK(!did_show_) << "received extraneous Show call";
1235 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1236 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1237
[email protected]8de12d942010-11-17 20:42:441238 if (did_show_)
1239 return;
1240
1241 did_show_ = true;
1242 // NOTE: initial_pos_ may still have its default values at this point, but
1243 // that's okay. It'll be ignored if as_popup is false, or the browser
1244 // process will impose a default position otherwise.
1245 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1246 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291247}
1248
[email protected]4873c7d2009-07-16 06:36:281249void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291250}
1251
[email protected]4873c7d2009-07-16 06:36:281252void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291253}
1254
[email protected]2533ce12009-05-09 00:02:241255void RenderWidget::DoDeferredClose() {
1256 Send(new ViewHostMsg_Close(routing_id_));
1257}
1258
[email protected]4873c7d2009-07-16 06:36:281259void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321260 if (is_swapped_out_) {
1261 // This widget is currently swapped out, and the active widget is in a
1262 // different process. Have the browser route the close request to the
1263 // active widget instead, so that the correct unload handlers are run.
1264 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1265 return;
1266 }
1267
initial.commit09911bf2008-07-26 23:55:291268 // If a page calls window.close() twice, we'll end up here twice, but that's
1269 // OK. It is safe to send multiple Close messages.
1270
[email protected]2533ce12009-05-09 00:02:241271 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1272 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1273 // could be closed before the JS finishes executing. So instead, post a
1274 // message back to the message loop, which won't run until the JS is
1275 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211276 MessageLoop::current()->PostTask(
1277 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291278}
1279
1280void RenderWidget::Close() {
1281 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281282 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291283 webwidget_ = NULL;
1284 }
1285}
1286
[email protected]4873c7d2009-07-16 06:36:281287WebRect RenderWidget::windowRect() {
1288 if (pending_window_rect_count_)
1289 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241290
[email protected]b3f2b912009-04-09 16:18:521291 gfx::Rect rect;
1292 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281293 return rect;
initial.commit09911bf2008-07-26 23:55:291294}
1295
[email protected]8a9d6ca32011-06-06 20:11:301296void RenderWidget::setToolTipText(const WebKit::WebString& text,
1297 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541298 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301299}
1300
[email protected]4873c7d2009-07-16 06:36:281301void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291302 if (did_show_) {
1303 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241304 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291305 } else {
1306 initial_pos_ = pos;
1307 }
1308}
1309
[email protected]2533ce12009-05-09 00:02:241310void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1311 pending_window_rect_ = rect;
1312 pending_window_rect_count_++;
1313}
1314
[email protected]4873c7d2009-07-16 06:36:281315WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241316 if (pending_window_rect_count_) {
1317 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1318 // the RootWindowRect is probably going to return wrong results since the
1319 // browser may not have processed the Move yet. There isn't really anything
1320 // good to do in this case, and it shouldn't happen - since this size is
1321 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281322 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241323 }
1324
[email protected]b3f2b912009-04-09 16:18:521325 gfx::Rect rect;
1326 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281327 return rect;
[email protected]d4547452008-08-28 18:36:371328}
1329
[email protected]4873c7d2009-07-16 06:36:281330WebRect RenderWidget::windowResizerRect() {
1331 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191332}
1333
[email protected]fa7b1dc2010-06-23 17:53:041334void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031335 // To prevent this renderer process from sending unnecessary IPC messages to
1336 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041337 // only during the input method attached to the browser process is active.
1338 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291339}
1340
[email protected]fa7b1dc2010-06-23 17:53:041341void RenderWidget::OnImeSetComposition(
1342 const string16& text,
1343 const std::vector<WebCompositionUnderline>& underlines,
1344 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281345 if (!webwidget_)
1346 return;
[email protected]d4cff272011-05-02 15:46:011347 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041348 text, WebVector<WebCompositionUnderline>(underlines),
1349 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011350 // Setting the IME composition was successful. Send the new composition
1351 // range to the browser.
1352 ui::Range range(ui::Range::InvalidRange());
1353 size_t location, length;
1354 if (webwidget_->compositionRange(&location, &length)) {
1355 range.set_start(location);
1356 range.set_end(location + length);
1357 }
1358 // The IME was cancelled via the Esc key, so just send back the caret.
1359 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1360 range.set_start(location);
1361 range.set_end(location + length);
1362 }
1363 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1364 } else {
[email protected]fa7b1dc2010-06-23 17:53:041365 // If we failed to set the composition text, then we need to let the browser
1366 // process to cancel the input method's ongoing composition session, to make
1367 // sure we are in a consistent state.
1368 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011369
1370 // Send an updated IME range with just the caret range.
1371 ui::Range range(ui::Range::InvalidRange());
1372 size_t location, length;
1373 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1374 range.set_start(location);
1375 range.set_end(location + length);
1376 }
1377 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261378 }
[email protected]fa7b1dc2010-06-23 17:53:041379}
1380
[email protected]4de6d1692011-10-12 08:45:441381void RenderWidget::OnImeConfirmComposition(
1382 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041383 if (!webwidget_)
1384 return;
1385
1386 handling_input_event_ = true;
1387 webwidget_->confirmComposition(text);
1388 handling_input_event_ = false;
1389
[email protected]d4cff272011-05-02 15:46:011390 // Send an updated IME range with just the caret range.
1391 ui::Range range(ui::Range::InvalidRange());
1392 size_t location, length;
1393 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1394 range.set_start(location);
1395 range.set_end(location + length);
1396 }
1397 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291398}
1399
[email protected]948f7ab72010-05-28 23:48:081400// This message causes the renderer to render an image of the
1401// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491402void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091403 int tag,
[email protected]948f7ab72010-05-28 23:48:081404 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491405 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001406 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1407 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251408 // Close our unused handle.
1409#if defined(OS_WIN)
1410 ::CloseHandle(dib_handle);
1411#elif defined(OS_MACOSX)
1412 base::SharedMemory::CloseHandle(dib_handle);
1413#endif
1414 }
[email protected]d65adb12010-04-28 17:26:491415 return;
[email protected]45c6aad32010-11-11 04:46:251416 }
[email protected]d65adb12010-04-28 17:26:491417
[email protected]948f7ab72010-05-28 23:48:081418 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491419 // If one of these is empty, then we just return the dib we were
1420 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091421 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491422 return;
1423 }
1424
1425 // Map the given DIB ID into this process, and unmap it at the end
1426 // of this function.
[email protected]45c6aad32010-11-11 04:46:251427 scoped_ptr<TransportDIB> paint_at_size_buffer(
1428 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301429
1430 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491431 float x_scale = static_cast<float>(desired_size.width()) /
1432 static_cast<float>(canvas_size.width());
1433 float y_scale = static_cast<float>(desired_size.height()) /
1434 static_cast<float>(canvas_size.height());
1435
[email protected]ee8d6fd2010-05-26 17:05:481436 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491437 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1438 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481439 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491440
[email protected]36808ad2010-10-20 19:18:301441 scoped_ptr<skia::PlatformCanvas> canvas(
1442 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1443 canvas_size.height()));
1444 if (!canvas.get()) {
1445 NOTREACHED();
1446 return;
1447 }
1448
[email protected]d65adb12010-04-28 17:26:491449 // Reset bounds to what we actually received, but they should be the
1450 // same.
1451 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1452 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1453 bounds.set_width(canvas->getDevice()->width());
1454 bounds.set_height(canvas->getDevice()->height());
1455
1456 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081457 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491458 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1459
[email protected]948f7ab72010-05-28 23:48:081460 // Have to make sure we're laid out at the right size before
1461 // rendering.
1462 gfx::Size old_size = webwidget_->size();
1463 webwidget_->resize(page_size);
1464 webwidget_->layout();
1465
[email protected]d65adb12010-04-28 17:26:491466 // Paint the entire thing (using original bounds, not scaled bounds).
1467 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1468 canvas->restore();
1469
[email protected]948f7ab72010-05-28 23:48:081470 // Return the widget to its previous size.
1471 webwidget_->resize(old_size);
1472
[email protected]c88c9442010-07-19 18:55:091473 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491474}
1475
[email protected]ec7dc112008-08-06 05:30:121476void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1477 // During shutdown we can just ignore this message.
1478 if (!webwidget_)
1479 return;
1480
1481 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561482 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041483 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461484 scheduleComposite();
1485 } else {
1486 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1487 didInvalidateRect(repaint_rect);
1488 }
[email protected]ec7dc112008-08-06 05:30:121489}
1490
[email protected]4873c7d2009-07-16 06:36:281491void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111492 if (!webwidget_)
1493 return;
[email protected]4873c7d2009-07-16 06:36:281494 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111495}
1496
[email protected]4b03e292012-02-13 18:40:071497void RenderWidget::OnInvertWebContent(bool invert) {
1498 if (invert_ == invert)
1499 return;
1500
1501 invert_ = invert;
1502
1503 if (invert_ && !invert_paint_.get()) {
1504 // Gamma-aware color inversion: each source pixel value x is normally
1505 // displayed on a computer monitor with a gamma correction x^gamma,
1506 // where gamma is typically in the range 1.8...2.2. By approximating
1507 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1508 uint8_t table[256];
1509 for (unsigned int i = 0; i < 256; i++) {
1510 double value = i / 255.0;
1511 value = sqrt(1 - (value * value));
1512 table[i] = static_cast<uint8_t>(255 * value);
1513 }
1514
1515 // Create a Skia Paint with this inverting color map.
1516 invert_paint_.reset(new SkPaint());
1517 invert_paint_->setStyle(SkPaint::kFill_Style);
1518 invert_paint_->setColor(SK_ColorBLACK);
1519 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1520 NULL, table, table, table);
1521 invert_paint_->setColorFilter(filter);
1522 filter->unref();
1523 }
1524
1525 OnMsgRepaint(size_);
1526}
1527
[email protected]719b36f2010-12-22 20:36:461528webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151529 const gfx::Rect& paint_bounds,
1530 TransportDIB** dib,
1531 gfx::Rect* location,
1532 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461533 // Bare RenderWidgets don't support optimized plugin painting.
1534 return NULL;
[email protected]ca4847f2010-09-24 05:39:151535}
1536
[email protected]bcaf2272011-02-15 15:29:431537gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521538 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431539 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521540}
1541
[email protected]bee16aab2009-08-26 15:55:031542void RenderWidget::SetHidden(bool hidden) {
1543 if (is_hidden_ == hidden)
1544 return;
1545
1546 // The status has changed. Tell the RenderThread about it.
1547 is_hidden_ = hidden;
1548 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271549 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031550 else
[email protected]380244092011-10-07 17:26:271551 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031552}
1553
[email protected]2b624c562011-10-27 22:58:261554void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261555 if (!webwidget_)
1556 return;
1557
1558 if (is_fullscreen_) {
1559 webwidget_->willExitFullScreen();
1560 } else {
1561 webwidget_->willEnterFullScreen();
1562 }
[email protected]2b624c562011-10-27 22:58:261563}
1564
1565void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261566 if (!webwidget_)
1567 return;
1568
1569 if (is_fullscreen_) {
1570 webwidget_->didEnterFullScreen();
1571 } else {
1572 webwidget_->didExitFullScreen();
1573 }
[email protected]2b624c562011-10-27 22:58:261574}
1575
[email protected]699ab0d2009-04-23 23:19:141576void RenderWidget::SetBackground(const SkBitmap& background) {
1577 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461578
[email protected]699ab0d2009-04-23 23:19:141579 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281580 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141581}
1582
[email protected]674741932009-02-04 23:44:461583bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051584 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461585}
1586
1587bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051588 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461589}
1590
1591void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051592 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461593}
1594
1595void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051596 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461597}
1598
1599void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051600 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461601}
1602
[email protected]e99ef6f2011-10-16 01:13:001603void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041604 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291605 return;
[email protected]fa7b1dc2010-06-23 17:53:041606
[email protected]ad26ef42011-06-17 07:59:451607 ui::TextInputType new_type = GetTextInputType();
1608 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001609 // Only sends text input type and compose inline to the browser process if
1610 // they are changed.
1611 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451612 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041613 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451614 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001615 Send(new ViewHostMsg_TextInputStateChanged(
1616 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291617 }
initial.commit09911bf2008-07-26 23:55:291618}
1619
[email protected]3f783362011-10-21 22:40:501620void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1621 WebRect start_webrect;
1622 WebRect end_webrect;
1623 webwidget_->selectionBounds(start_webrect, end_webrect);
1624 *start = start_webrect;
1625 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321626}
1627
[email protected]e99ef6f2011-10-16 01:13:001628void RenderWidget::UpdateSelectionBounds() {
1629 if (!webwidget_)
1630 return;
1631
[email protected]3f783362011-10-21 22:40:501632 gfx::Rect start_rect;
1633 gfx::Rect end_rect;
1634 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001635 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1636 return;
1637
1638 selection_start_rect_ = start_rect;
1639 selection_end_rect_ = end_rect;
1640 Send(new ViewHostMsg_SelectionBoundsChanged(
1641 routing_id_, selection_start_rect_, selection_end_rect_));
1642}
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
1685bool RenderWidget::CanComposeInline() {
1686 return true;
[email protected]56ea1a62011-05-30 07:05:571687}
1688
[email protected]4873c7d2009-07-16 06:36:281689WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041690 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281691}
1692
[email protected]f660d9c2012-06-06 18:31:211693float RenderWidget::deviceScaleFactor() {
1694 return device_scale_factor_;
1695}
1696
[email protected]fa7b1dc2010-06-23 17:53:041697void RenderWidget::resetInputMethod() {
1698 if (!input_method_is_active_)
1699 return;
1700
1701 // If the last text input type is not None, then we should finish any
1702 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451703 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041704 // If a composition text exists, then we need to let the browser process
1705 // to cancel the input method's ongoing composition session.
1706 if (webwidget_->confirmComposition())
1707 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1708 }
[email protected]d4cff272011-05-02 15:46:011709
1710 // Send an updated IME range with the current caret rect.
1711 ui::Range range(ui::Range::InvalidRange());
1712 size_t location, length;
1713 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1714 range.set_start(location);
1715 range.set_end(location + length);
1716 }
1717 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041718}
1719
[email protected]f103ab72009-09-02 17:10:591720void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501721 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291722 size_t i = 0;
1723 for (; i < plugin_window_moves_.size(); ++i) {
1724 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581725 if (move.rects_valid) {
1726 plugin_window_moves_[i] = move;
1727 } else {
1728 plugin_window_moves_[i].visible = move.visible;
1729 }
initial.commit09911bf2008-07-26 23:55:291730 break;
1731 }
1732 }
1733
1734 if (i == plugin_window_moves_.size())
1735 plugin_window_moves_.push_back(move);
1736}
[email protected]268654772009-08-06 23:02:041737
1738void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1739 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1740 i != plugin_window_moves_.end(); ++i) {
1741 if (i->window == window) {
1742 plugin_window_moves_.erase(i);
1743 break;
1744 }
1745 }
1746}
[email protected]67bfb83f2011-09-22 03:36:371747
1748bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1749 return false;
1750}
[email protected]c3d45532011-10-07 19:20:401751
1752bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1753 return false;
1754}