blob: e21aeda4b03bce52228e785255e7a77e5c2dc0b2 [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]d5282e72009-05-13 13:16:5225#include "third_party/skia/include/core/SkShader.h"
[email protected]4b03e292012-02-13 18:40:0726#include "third_party/skia/include/effects/SkTableColorFilter.h"
[email protected]8bd0fe62011-01-17 06:44:3727#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]e6e90dc2011-12-03 00:01:3728#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
[email protected]a7547fb2012-03-08 04:43:4429#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3730#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
31#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0132#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]e6e90dc2011-12-03 00:01:3733#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]8bd0fe62011-01-17 06:44:3734#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]e6e90dc2011-12-03 00:01:3735#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
36#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
[email protected]1835b9e2012-02-28 13:12:4837#include "ui/gfx/gl/gl_switches.h"
[email protected]08397d52011-02-05 01:53:3838#include "ui/gfx/point.h"
39#include "ui/gfx/size.h"
[email protected]1835b9e2012-02-28 13:12:4840#include "ui/gfx/skia_util.h"
[email protected]b9b751f22011-03-25 14:04:1241#include "ui/gfx/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/SkPixelRef.h"
49#include "third_party/skia/include/core/SkMallocPixelRef.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]6fd35b72012-03-01 19:46:4174RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
75 const WebKit::WebScreenInfo& screen_info)
initial.commit09911bf2008-07-26 23:55:2976 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:5677 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:1178 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2979 opener_id_(MSG_ROUTING_NONE),
[email protected]659f73fa2009-10-13 13:43:4280 host_window_(0),
[email protected]05a980d7a2012-02-07 22:16:4281 host_window_set_(false),
[email protected]b4d08452010-10-05 17:34:3582 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2983 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:0684 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:0585 update_reply_pending_(false),
[email protected]65225772011-05-12 21:10:2486 using_asynchronous_swapbuffers_(false),
87 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2988 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2989 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:0990 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:2991 needs_repainting_on_restore_(false),
92 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4993 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4894 closing_(false),
[email protected]992db4c2011-05-12 15:37:1595 is_swapped_out_(false),
[email protected]fa7b1dc2010-06-23 17:53:0496 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:4597 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
98 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:1299 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48100 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12101 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50102 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21103 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07104 invalidation_task_posted_(false),
[email protected]6fd35b72012-03-01 19:46:41105 screen_info_(screen_info),
[email protected]4b03e292012-02-13 18:40:07106 invert_(false) {
[email protected]8930d472009-02-21 08:05:28107 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27108 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18109 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
110 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:29111}
112
113RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11114 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21115 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35116 if (current_paint_buf_) {
117 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
118 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29119 }
[email protected]992db4c2011-05-12 15:37:15120 // If we are swapped out, we have released already.
121 if (!is_swapped_out_)
122 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29123}
124
[email protected]484955942010-08-19 16:13:18125// static
[email protected]8085dbc82008-09-26 22:53:44126RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]6fd35b72012-03-01 19:46:41127 WebKit::WebPopupType popup_type,
128 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29129 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41130 scoped_refptr<RenderWidget> widget(
131 new RenderWidget(popup_type, screen_info));
initial.commit09911bf2008-07-26 23:55:29132 widget->Init(opener_id); // adds reference
133 return widget;
134}
135
[email protected]484955942010-08-19 16:13:18136// static
137WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
138 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03139 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18140 break;
141 case WebKit::WebPopupTypeSelect:
142 case WebKit::WebPopupTypeSuggestion:
143 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44144 case WebKit::WebPopupTypePage:
145 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18146 default:
147 NOTREACHED();
148 }
149 return NULL;
150}
151
initial.commit09911bf2008-07-26 23:55:29152void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18153 DoInit(opener_id,
154 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56155 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
156 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18157}
158
[email protected]484955942010-08-19 16:13:18159void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06160 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18161 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29162 DCHECK(!webwidget_);
163
164 if (opener_id != MSG_ROUTING_NONE)
165 opener_id_ = opener_id;
166
[email protected]484955942010-08-19 16:13:18167 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29168
[email protected]380244092011-10-07 17:26:27169 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29170 if (result) {
[email protected]380244092011-10-07 17:26:27171 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29172 // Take a reference on behalf of the RenderThread. This will be balanced
173 // when we receive ViewMsg_Close.
174 AddRef();
175 } else {
176 DCHECK(false);
177 }
178}
179
180// This is used to complete pending inits and non-pending inits. For non-
181// pending cases, the parent will be the same as the current parent. This
182// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55183void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29184 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29185
186 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42187 host_window_set_ = true;
188
[email protected]f1d5de42012-04-20 01:47:14189#if WEBWIDGET_HAS_SETCOMPOSITORSURFACEREADY
190 if (webwidget_)
191 webwidget_->setCompositorSurfaceReady();
192#endif
[email protected]05a980d7a2012-02-07 22:16:42193 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29194
[email protected]6de74452009-02-25 18:04:59195 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29196}
197
[email protected]992db4c2011-05-12 15:37:15198void RenderWidget::SetSwappedOut(bool is_swapped_out) {
199 // We should only toggle between states.
200 DCHECK(is_swapped_out_ != is_swapped_out);
201 is_swapped_out_ = is_swapped_out;
202
203 // If we are swapping out, we will call ReleaseProcess, allowing the process
204 // to exit if all of its RenderViews are swapped out. We wait until the
205 // WasSwappedOut call to do this, to avoid showing the sad tab.
206 // If we are swapping in, we call AddRefProcess to prevent the process from
207 // exiting.
208 if (!is_swapped_out)
209 RenderProcess::current()->AddRefProcess();
210}
211
[email protected]a95986a82010-12-24 06:19:28212bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
213 bool handled = true;
214 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
215 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
216 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
217 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54218 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28219 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
220 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15221 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28222 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
223 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
224 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
225 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
226 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
227 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
228 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
229 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
230 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
231 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
232 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]4b03e292012-02-13 18:40:07233 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
[email protected]a95986a82010-12-24 06:19:28234 IPC_MESSAGE_UNHANDLED(handled = false)
235 IPC_END_MESSAGE_MAP()
236 return handled;
237}
initial.commit09911bf2008-07-26 23:55:29238
239bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15240 // Don't send any messages after the browser has told us to close, and filter
241 // most outgoing messages while swapped out.
242 if ((is_swapped_out_ &&
243 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
244 closing_) {
initial.commit09911bf2008-07-26 23:55:29245 delete message;
246 return false;
247 }
248
249 // If given a messsage without a routing ID, then assign our routing ID.
250 if (message->routing_id() == MSG_ROUTING_NONE)
251 message->set_routing_id(routing_id_);
252
[email protected]380244092011-10-07 17:26:27253 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44254}
255
[email protected]61e2b3cc2012-03-02 16:13:34256void RenderWidget::Resize(const gfx::Size& new_size,
257 const gfx::Rect& resizer_rect,
258 bool is_fullscreen,
259 ResizeAck resize_ack) {
260 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
261 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
262 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29263
[email protected]61e2b3cc2012-03-02 16:13:34264 // Ignore this during shutdown.
265 if (!webwidget_)
266 return;
267
268 // Remember the rect where the resize corner will be drawn.
269 resizer_rect_ = resizer_rect;
270
271 // NOTE: We may have entered fullscreen mode without changing our size.
272 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
273 if (fullscreen_change)
274 WillToggleFullscreen();
275 is_fullscreen_ = is_fullscreen;
276
277 if (size_ != new_size) {
278 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34279 needs_repainting_on_restore_ = false;
280
281 size_ = new_size;
282
283 paint_aggregator_.ClearPendingUpdate();
284
285 // When resizing, we want to wait to paint before ACK'ing the resize. This
286 // ensures that we only resize as fast as we can paint. We only need to
287 // send an ACK if we are resized to a non-empty rect.
288 webwidget_->resize(new_size);
289 if (!new_size.IsEmpty()) {
290 if (!is_accelerated_compositing_active_) {
291 // Resize should have caused an invalidation of the entire view.
292 DCHECK(paint_aggregator_.HasPendingUpdate());
293 }
294
295 // Send the Resize_ACK flag once we paint again if requested.
296 if (resize_ack == SEND_RESIZE_ACK)
297 set_next_paint_is_resize_ack();
298 }
[email protected]ff475a322012-03-14 00:05:35299 } else {
300 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34301 }
302
303 if (fullscreen_change)
304 DidToggleFullscreen();
305
306 // If a resize ack is requested and it isn't set-up, then no more resizes will
307 // come in and in general things will go wrong.
308 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
309 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29310}
311
312void RenderWidget::OnClose() {
313 if (closing_)
314 return;
315 closing_ = true;
316
317 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03318 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27319 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03320 SetHidden(false);
321 }
initial.commit09911bf2008-07-26 23:55:29322
initial.commit09911bf2008-07-26 23:55:29323 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25324 // now. Post a task that only gets invoked when there are no nested message
325 // loops.
[email protected]32876ae2011-11-15 22:25:21326 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29327 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25328
329 // Balances the AddRef taken when we called AddRoute.
330 Release();
initial.commit09911bf2008-07-26 23:55:29331}
332
[email protected]61e2b3cc2012-03-02 16:13:34333// Got a response from the browser after the renderer decided to create a new
334// view.
335void RenderWidget::OnCreatingNewAck(
336 gfx::NativeViewId parent) {
337 DCHECK(routing_id_ != MSG_ROUTING_NONE);
338
339 CompleteInit(parent);
340}
341
[email protected]f21c613a2009-02-12 14:46:17342void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09343 const gfx::Rect& resizer_rect,
344 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34345 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29346}
347
[email protected]b5913d72012-02-07 22:26:54348void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
349 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59350 gfx::Rect view_rect(size_);
351
352 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
353 if (!old_damage_rect.IsEmpty())
354 paint_aggregator_.InvalidateRect(old_damage_rect);
355
356 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
357 if (!new_damage_rect.IsEmpty())
358 paint_aggregator_.InvalidateRect(new_damage_rect);
359
[email protected]b5913d72012-02-07 22:26:54360 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59361
[email protected]b5913d72012-02-07 22:26:54362 if (webwidget_)
363 webwidget_->didChangeWindowResizerRect();
364 }
365}
366
initial.commit09911bf2008-07-26 23:55:29367void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31368 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29369 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03370 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29371}
372
373void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31374 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29375 // During shutdown we can just ignore this message.
376 if (!webwidget_)
377 return;
378
379 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03380 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29381
382 if (!needs_repainting && !needs_repainting_on_restore_)
383 return;
384 needs_repainting_on_restore_ = false;
385
[email protected]d65adb12010-04-28 17:26:49386 // Tag the next paint as a restore ack, which is picked up by
387 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29388 set_next_paint_is_restore_ack();
389
390 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56391 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46392 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
393 } else {
394 scheduleComposite();
395 }
initial.commit09911bf2008-07-26 23:55:29396}
397
[email protected]992db4c2011-05-12 15:37:15398void RenderWidget::OnWasSwappedOut() {
399 // If we have been swapped out and no one else is using this process,
400 // it's safe to exit now. If we get swapped back in, we will call
401 // AddRefProcess in SetSwappedOut.
402 if (is_swapped_out_)
403 RenderProcess::current()->ReleaseProcess();
404}
405
[email protected]53d3f302009-12-21 04:42:05406void RenderWidget::OnRequestMoveAck() {
407 DCHECK(pending_window_rect_count_);
408 pending_window_rect_count_--;
409}
410
411void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58412 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21413 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05414 update_reply_pending_ = false;
415
[email protected]b4d08452010-10-05 17:34:35416 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
417 // have no current paint buffer.
418 if (current_paint_buf_) {
419 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
420 current_paint_buf_ = NULL;
421 }
422
[email protected]65225772011-05-12 21:10:24423 // If swapbuffers is still pending, then defer the update until the
424 // swapbuffers occurs.
425 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
426 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
427 return;
428 }
429
[email protected]29ed96a2012-02-04 18:12:16430 // Notify subclasses that software rendering was flushed to the screen.
431 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25432
initial.commit09911bf2008-07-26 23:55:29433 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24434 DoDeferredUpdateAndSendInputAck();
435}
436
[email protected]d0be63772011-12-20 23:18:04437bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24438 return false;
439}
440
[email protected]d0be63772011-12-20 23:18:04441void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24442 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21443 while (!updates_pending_swap_.empty()) {
444 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
445 updates_pending_swap_.pop_front();
446 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
447 // compositing pass, hence doesn't require an UpdateRect message.
448 if (msg)
449 Send(msg);
450 }
[email protected]65225772011-05-12 21:10:24451 num_swapbuffers_complete_pending_ = 0;
452 using_asynchronous_swapbuffers_ = false;
453 // Schedule another frame so the compositor learns about it.
454 scheduleComposite();
455}
456
[email protected]37a6f302011-07-11 23:43:08457void RenderWidget::OnSwapBuffersPosted() {
458 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21459
460 if (using_asynchronous_swapbuffers_) {
461 ViewHostMsg_UpdateRect* msg = NULL;
462 // pending_update_params_ can be NULL if the swap doesn't correspond to an
463 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
464 // message.
465 if (pending_update_params_.get()) {
466 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
467 pending_update_params_.reset();
468 }
469 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08470 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21471 }
[email protected]37a6f302011-07-11 23:43:08472}
473
474void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24475 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16476
477 // Notify subclasses that composited rendering got flushed to the screen.
478 DidFlushPaint();
479
[email protected]65225772011-05-12 21:10:24480 // When compositing deactivates, we reset the swapbuffers pending count. The
481 // swapbuffers acks may still arrive, however.
482 if (num_swapbuffers_complete_pending_ == 0) {
483 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
484 return;
485 }
[email protected]aa4117f2011-12-09 22:19:21486 DCHECK(!updates_pending_swap_.empty());
487 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
488 updates_pending_swap_.pop_front();
489 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
490 // compositing pass, hence doesn't require an UpdateRect message.
491 if (msg)
492 Send(msg);
[email protected]65225772011-05-12 21:10:24493 num_swapbuffers_complete_pending_--;
494
495 // If update reply is still pending, then defer the update until that reply
496 // occurs.
[email protected]d0be63772011-12-20 23:18:04497 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24498 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
499 return;
500 }
501
502 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06503 // when we were previously rendering. However, if an invalidation task is not
504 // posted, there may be software rendering work pending. In that case, don't
505 // early out.
506 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24507 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
508 return;
509 }
510
[email protected]65225772011-05-12 21:10:24511 // Continue painting if necessary...
512 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29513}
514
initial.commit09911bf2008-07-26 23:55:29515void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24516 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56517 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29518
519 const char* data;
520 int data_length;
[email protected]5dd768212009-08-13 23:34:49521 handling_input_event_ = true;
522 if (!message.ReadData(&iter, &data, &data_length)) {
523 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29524 return;
[email protected]5dd768212009-08-13 23:34:49525 }
initial.commit09911bf2008-07-26 23:55:29526
527 const WebInputEvent* input_event =
528 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48529
[email protected]b68a0e52011-12-08 15:11:12530 bool is_keyboard_shortcut = false;
531 // is_keyboard_shortcut flag is only available for RawKeyDown events.
532 if (input_event->type == WebInputEvent::RawKeyDown)
533 message.ReadBool(&iter, &is_keyboard_shortcut);
534
[email protected]67bfb83f2011-09-22 03:36:37535 bool prevent_default = false;
536 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26537 const WebMouseEvent& mouse_event =
538 *static_cast<const WebMouseEvent*>(input_event);
539 TRACE_EVENT2("renderer", "HandleMouseMove",
540 "x", mouse_event.x, "y", mouse_event.y);
541 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37542 }
543
544 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12545 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
546 suppress_next_char_events_ = false;
547 if (!processed && webwidget_)
548 processed = webwidget_->handleInputEvent(*input_event);
549 }
550
551 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
552 // it's not processed by webkit, then we need to suppress the upcoming Char
553 // events.
554 if (!processed && is_keyboard_shortcut)
555 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29556
[email protected]a9fb30aa2011-10-06 06:58:46557 IPC::Message* response =
558 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
559 processed);
[email protected]3391a0772012-03-28 00:32:07560 bool event_type_gets_rate_limited =
561 input_event->type == WebInputEvent::MouseMove ||
562 input_event->type == WebInputEvent::MouseWheel ||
563 WebInputEvent::isTouchEventType(input_event->type);
564 bool is_input_throttled =
565 webwidget_->isInputThrottled() ||
566 paint_aggregator_.HasPendingUpdate();
[email protected]e2824412009-02-27 01:57:05567
[email protected]3391a0772012-03-28 00:32:07568 if (event_type_gets_rate_limited && is_input_throttled) {
[email protected]12fbad812009-09-01 18:21:24569 // We want to rate limit the input events in this case, so we'll wait for
570 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17571 if (pending_input_event_ack_.get()) {
572 // As two different kinds of events could cause us to postpone an ack
573 // we send it now, if we have one pending. The Browser should never
574 // send us the same kind of event we are delaying the ack for.
575 Send(pending_input_event_ack_.release());
576 }
[email protected]12fbad812009-09-01 18:21:24577 pending_input_event_ack_.reset(response);
578 } else {
579 Send(response);
580 }
581
[email protected]5dd768212009-08-13 23:34:49582 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48583
[email protected]67bfb83f2011-09-22 03:36:37584 if (!prevent_default) {
585 if (WebInputEvent::isKeyboardEventType(input_event->type))
586 DidHandleKeyEvent();
587 if (WebInputEvent::isMouseEventType(input_event->type))
588 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24589 if (WebInputEvent::isTouchEventType(input_event->type))
590 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37591 }
initial.commit09911bf2008-07-26 23:55:29592}
593
594void RenderWidget::OnMouseCaptureLost() {
595 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28596 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29597}
598
599void RenderWidget::OnSetFocus(bool enable) {
600 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33601 if (webwidget_)
602 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29603}
604
605void RenderWidget::ClearFocus() {
606 // We may have got the focus from the browser before this gets processed, in
607 // which case we do not want to unfocus ourself.
608 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28609 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29610}
611
[email protected]2d5d09d52009-06-15 14:29:21612void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00613 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21614 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06615 TRACE_EVENT2("renderer", "PaintRect",
616 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00617 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21618
619 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00620 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
621 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03622
[email protected]4b03e292012-02-13 18:40:07623 if (invert_) {
624 // Draw everything to a temporary bitmap and then apply an
625 // inverting color map to the result. This is balanced by an extra
626 // call to canvas->restore(), below.
627 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48628 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07629 canvas->saveLayer(&bounds, invert_paint_.get());
630 }
631
[email protected]699ab0d2009-04-23 23:19:14632 // If there is a custom background, tile it.
633 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14634 SkPaint paint;
635 SkShader* shader = SkShader::CreateBitmapShader(background_,
636 SkShader::kRepeat_TileMode,
637 SkShader::kRepeat_TileMode);
638 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20639
640 // Use kSrc_Mode to handle background_ transparency properly.
641 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
642
643 // Canvas could contain multiple update rects. Clip to given rect so that
644 // we don't accidentally clear other update rects.
645 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48646 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14647 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20648 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14649 }
650
[email protected]719b36f2010-12-22 20:36:46651 // First see if this rect is a plugin that can paint itself faster.
652 TransportDIB* optimized_dib = NULL;
653 gfx::Rect optimized_copy_rect, optimized_copy_location;
654 webkit::ppapi::PluginInstance* optimized_instance =
655 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
656 &optimized_copy_location,
657 &optimized_copy_rect);
658 if (optimized_instance) {
659 // This plugin can be optimize-painted and we can just ask it to paint
660 // itself. We don't actually need the TransportDIB in this case.
661 //
662 // This is an optimization for PPAPI plugins that know they're on top of
663 // the page content. If this rect is inside such a plugin, we can save some
664 // time and avoid re-rendering the page content which we know will be
665 // covered by the plugin later (this time can be significant, especially
666 // for a playing movie that is invalidating a lot).
667 //
668 // In the plugin movie case, hopefully the similar call to
669 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
670 // painting, because that avoids copying the plugin image to a different
671 // paint rect. Unfortunately, if anything on the page is animating other
672 // than the movie, it break this optimization since the union of the
673 // invalid regions will be larger than the plugin.
674 //
675 // This code optimizes that case, where we can still avoid painting in
676 // WebKit and filling the background (which can be slow) and just painting
677 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
678 // required.
679 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27680 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46681 } else {
682 // Normal painting case.
683 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
684
685 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35686 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46687 }
initial.commit09911bf2008-07-26 23:55:29688
[email protected]4b03e292012-02-13 18:40:07689 if (invert_)
690 canvas->restore();
691
[email protected]4fb66842009-12-04 21:41:00692 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00693 canvas->restore();
694}
695
696void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
697 skia::PlatformCanvas* canvas) {
698 static bool kPaintBorder =
699 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
700 if (!kPaintBorder)
701 return;
702
[email protected]53d3f302009-12-21 04:42:05703 // Cycle through these colors to help distinguish new paint rects.
704 const SkColor colors[] = {
705 SkColorSetARGB(0x3F, 0xFF, 0, 0),
706 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
707 SkColorSetARGB(0x3F, 0, 0, 0xFF),
708 };
709 static int color_selector = 0;
710
[email protected]4fb66842009-12-04 21:41:00711 SkPaint paint;
712 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05713 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00714 paint.setStrokeWidth(1);
715
716 SkIRect irect;
717 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
718 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29719}
720
[email protected]52ccd0ea2011-02-16 01:09:05721void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30722 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30723 if (!animation_update_pending_) {
724 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59725 return;
[email protected]921244e42011-07-20 16:36:30726 }
[email protected]bd37ae252011-06-03 01:28:18727 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59728 // Record when we fired (according to base::Time::Now()) relative to when
729 // we posted the task to quantify how much the base::Time/base::TimeTicks
730 // skew is affecting animations.
731 base::TimeDelta animation_callback_delay = base::Time::Now() -
732 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
733 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
734 animation_callback_delay,
735 base::TimeDelta::FromMilliseconds(0),
736 base::TimeDelta::FromMilliseconds(30),
737 25);
738 }
[email protected]65225772011-05-12 21:10:24739 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24740}
741
[email protected]52ccd0ea2011-02-16 01:09:05742void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59743 if (!animation_update_pending_)
744 return;
[email protected]bd37ae252011-06-03 01:28:18745
746 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33747 base::TimeDelta animationInterval = IsRenderingVSynced() ?
748 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18749
[email protected]7c4329e2011-02-18 22:02:59750 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45751
752 // animation_floor_time_ is the earliest time that we should animate when
753 // using the dead reckoning software scheduler. If we're using swapbuffers
754 // complete callbacks to rate limit, we can ignore this floor.
755 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30756 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33757 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18758 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59759 // running animation callbacks so that if a callback requests another
760 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38761 animation_timer_.Stop();
762 animation_timer_.Start(FROM_HERE, animationInterval, this,
763 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59764 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30765 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59766 return;
[email protected]5f8b1022011-01-21 23:34:50767 }
[email protected]bd37ae252011-06-03 01:28:18768 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38769 if (!animation_timer_.IsRunning()) {
770 // This code uses base::Time::Now() to calculate the floor and next fire
771 // time because javascript's Date object uses base::Time::Now(). The
772 // message loop uses base::TimeTicks, which on windows can have a
773 // different granularity than base::Time.
774 // The upshot of all this is that this function might be called before
775 // base::Time::Now() has advanced past the animation_floor_time_. To
776 // avoid exposing this delay to javascript, we keep posting delayed
777 // tasks until base::Time::Now() has advanced far enough.
778 base::TimeDelta delay = animation_floor_time_ - now;
779 animation_timer_.Start(FROM_HERE, delay, this,
780 &RenderWidget::AnimationCallback);
781 }
[email protected]5f8b1022011-01-21 23:34:50782}
783
[email protected]bd37ae252011-06-03 01:28:18784bool RenderWidget::IsRenderingVSynced() {
785 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
786 // not caught by this check. This will lead to artificially low frame rates
787 // for people who force vsync off at a driver level and expect Chrome to speed
788 // up.
789 return !has_disable_gpu_vsync_switch_;
790}
791
[email protected]65225772011-05-12 21:10:24792void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06793 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24794 invalidation_task_posted_ = false;
795 DoDeferredUpdateAndSendInputAck();
796}
797
798void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05799 DoDeferredUpdate();
800
801 if (pending_input_event_ack_.get())
802 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21803}
804
[email protected]552e6002009-11-19 05:24:57805void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58806 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08807
[email protected]65225772011-05-12 21:10:24808 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29809 return;
[email protected]05a980d7a2012-02-07 22:16:42810
811 if (!host_window_set_) {
812 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
813 return;
814 }
[email protected]aa4117f2011-12-09 22:19:21815 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24816 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
817 return;
818 }
[email protected]9ca84622011-06-02 23:46:39819 if (is_accelerated_compositing_active_ &&
820 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24821 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
822 return;
823 }
initial.commit09911bf2008-07-26 23:55:29824
[email protected]552e6002009-11-19 05:24:57825 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29826 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57827 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29828 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24829 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29830 return;
831 }
832
[email protected]05a980d7a2012-02-07 22:16:42833 if (is_accelerated_compositing_active_)
834 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
835
[email protected]0fb93f52011-05-18 23:13:56836 // Tracking of frame rate jitter
837 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51838 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05839 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50840
[email protected]f98d7e3c2010-09-13 22:30:46841 // Layout may generate more invalidation. It may also enable the
842 // GPU acceleration, so make sure to run layout before we send the
843 // GpuRenderingActivated message.
844 webwidget_->layout();
845
[email protected]dcca3aa92012-02-17 23:03:37846 // The following two can result in further layout and possibly
847 // enable GPU acceleration so they need to be called before any painting
848 // is done.
849 UpdateTextInputState();
850 UpdateSelectionBounds();
851
[email protected]5f8b1022011-01-21 23:34:50852 // Suppress painting if nothing is dirty. This has to be done after updating
853 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24854 if (!paint_aggregator_.HasPendingUpdate()) {
855 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51856 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50857 return;
[email protected]65225772011-05-12 21:10:24858 }
[email protected]5f8b1022011-01-21 23:34:50859
[email protected]872ae5b2011-05-26 20:20:50860 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56861 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04862 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56863 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
864 delay,
865 base::TimeDelta::FromMilliseconds(1),
866 base::TimeDelta::FromMilliseconds(60),
867 30);
[email protected]d0be63772011-12-20 23:18:04868 } else {
[email protected]0fb93f52011-05-18 23:13:56869 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
870 delay,
871 base::TimeDelta::FromMilliseconds(1),
872 base::TimeDelta::FromMilliseconds(60),
873 30);
[email protected]d0be63772011-12-20 23:18:04874 }
[email protected]872ae5b2011-05-26 20:20:50875
876 // Calculate filtered time per frame:
877 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
878 filtered_time_per_frame_ =
879 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56880 }
881 last_do_deferred_update_time_ = frame_begin_ticks;
882
[email protected]552e6002009-11-19 05:24:57883 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29884 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30885 PaintAggregator::PendingUpdate update;
886 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29887
[email protected]53d3f302009-12-21 04:42:05888 gfx::Rect scroll_damage = update.GetScrollDamage();
889 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29890
[email protected]29ed96a2012-02-04 18:12:16891 // Notify derived classes that we're about to initiate a paint.
892 WillInitiatePaint();
893
[email protected]ca4847f2010-09-24 05:39:15894 // A plugin may be able to do an optimized paint. First check this, in which
895 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46896 // This optimization allows PPAPI plugins that declare themselves on top of
897 // the page (like a traditional windowed plugin) to be able to animate (think
898 // movie playing) without repeatedly re-painting the page underneath, or
899 // copying the plugin backing store (since we can send the plugin's backing
900 // store directly to the browser).
901 //
902 // This optimization only works when the entire invalid region is contained
903 // within the plugin. There is a related optimization in PaintRect for the
904 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15905 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15906 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21907 DCHECK(!pending_update_params_.get());
908 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
909 pending_update_params_->dx = update.scroll_delta.x();
910 pending_update_params_->dy = update.scroll_delta.y();
911 pending_update_params_->scroll_rect = update.scroll_rect;
912 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21913 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
914 pending_update_params_->flags = next_paint_flags_;
915 pending_update_params_->scroll_offset = GetScrollOffset();
916 pending_update_params_->needs_ack = true;
917 next_paint_flags_ = 0;
918
[email protected]ca4847f2010-09-24 05:39:15919 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56920 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15921 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
922 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27923 // Only update the part of the plugin that actually changed.
924 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21925 pending_update_params_->bitmap = dib->id();
926 pending_update_params_->bitmap_rect = optimized_copy_location;
927 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56928 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46929 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15930 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35931 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
932 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46933 if (!canvas.get()) {
934 NOTREACHED();
935 return;
936 }
[email protected]cef3362f2009-12-21 17:48:45937
[email protected]f98d7e3c2010-09-13 22:30:46938 // We may get back a smaller canvas than we asked for.
939 // TODO(darin): This seems like it could cause painting problems!
940 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
941 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
942 bounds.set_width(canvas->getDevice()->width());
943 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05944
[email protected]f98d7e3c2010-09-13 22:30:46945 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
946
[email protected]aa4117f2011-12-09 22:19:21947 pending_update_params_->bitmap = current_paint_buf_->id();
948 pending_update_params_->bitmap_rect = bounds;
949
950 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46951 // The scroll damage is just another rectangle to paint and copy.
952 copy_rects.swap(update.paint_rects);
953 if (!scroll_damage.IsEmpty())
954 copy_rects.push_back(scroll_damage);
955
956 for (size_t i = 0; i < copy_rects.size(); ++i)
957 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35958
959 // Software FPS tick for performance tests. The accelerated path traces the
960 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
961 // NOTE: Tests may break if this event is renamed or moved.
962 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46963 } else { // Accelerated compositing path
964 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21965 // If painting is done via the gpu process then we don't set any damage
966 // rects to save the browser process from doing unecessary work.
967 pending_update_params_->bitmap_rect = bounds;
968 pending_update_params_->scroll_rect = gfx::Rect();
969 // We don't need an ack, because we're not sharing a DIB with the browser.
970 // If it needs to (e.g. composited UI), the GPU process does its own ACK
971 // with the browser for the GPU surface.
972 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42973 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46974 }
975
[email protected]936c6f52011-12-13 01:35:26976 // If we're holding a pending input event ACK, send the ACK before sending the
977 // UpdateReply message so we can receive another input event before the
978 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
979 // the UpdateRect IPC message handler.
980 if (pending_input_event_ack_.get())
981 Send(pending_input_event_ack_.release());
982
[email protected]aa4117f2011-12-09 22:19:21983 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
984 // OnSwapBuffersPosted), meaning a message has been added to the
985 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
986 // the message now.
987 if (pending_update_params_.get()) {
988 // sending an ack to browser process that the paint is complete...
989 update_reply_pending_ = pending_update_params_->needs_ack;
990 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
991 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:34992 }
[email protected]53d3f302009-12-21 04:42:05993
[email protected]29ed96a2012-02-04 18:12:16994 // If we're software rendering then we're done initiating the paint.
995 if (!is_accelerated_compositing_active_)
996 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29997}
998
999///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461000// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291001
[email protected]4873c7d2009-07-16 06:36:281002void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:571003 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481004 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571005 gfx::Rect damaged_rect = view_rect.Intersect(rect);
1006 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291007 return;
1008
[email protected]552e6002009-11-19 05:24:571009 paint_aggregator_.InvalidateRect(damaged_rect);
1010
1011 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241012 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571013 return;
1014 if (!paint_aggregator_.HasPendingUpdate())
1015 return;
[email protected]aa4117f2011-12-09 22:19:211016 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241017 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1018 return;
1019
1020 // When GPU rendering, combine pending animations and invalidations into
1021 // a single update.
[email protected]816edc62012-03-17 01:27:221022 if (is_accelerated_compositing_active_ &&
1023 animation_update_pending_ &&
1024 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571025 return;
1026
1027 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291028 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1029 // on the call stack.
1030 // 2) Allows us to collect more damage rects before painting to help coalesce
1031 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241032 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211033 MessageLoop::current()->PostTask(
1034 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291035}
1036
[email protected]4873c7d2009-07-16 06:36:281037void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461038 // Drop scrolls on the floor when we are in compositing mode.
1039 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561040 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461041 return;
1042
[email protected]552e6002009-11-19 05:24:571043 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481044 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571045 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1046 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291047 return;
1048
[email protected]552e6002009-11-19 05:24:571049 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1050
1051 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241052 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571053 return;
1054 if (!paint_aggregator_.HasPendingUpdate())
1055 return;
[email protected]aa4117f2011-12-09 22:19:211056 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241057 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1058 return;
1059
1060 // When GPU rendering, combine pending animations and invalidations into
1061 // a single update.
[email protected]816edc62012-03-17 01:27:221062 if (is_accelerated_compositing_active_ &&
1063 animation_update_pending_ &&
1064 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571065 return;
1066
1067 // Perform updating asynchronously. This serves two purposes:
1068 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1069 // on the call stack.
1070 // 2) Allows us to collect more damage rects before painting to help coalesce
1071 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241072 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211073 MessageLoop::current()->PostTask(
1074 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291075}
1076
[email protected]244ac1892011-12-02 17:04:471077void RenderWidget::didAutoResize(const WebSize& new_size) {
1078 size_ = new_size;
1079}
1080
[email protected]91acd1c2012-03-14 08:32:391081void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221082 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1083
[email protected]c63b4d42012-04-26 01:01:071084#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211085 if (!is_accelerated_compositing_active_) {
1086 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1087 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1088 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1089 // going to switch to accelerated compositing, the GPU process may need
1090 // round-trips to the browser's UI thread before finishing the frame,
1091 // causing deadlocks if we delay the UpdateRect until we receive the
1092 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071093 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1094 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211095 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1096 }
[email protected]c63b4d42012-04-26 01:01:071097#endif
[email protected]aa4117f2011-12-09 22:19:211098
[email protected]ea162f92011-10-04 23:08:221099 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421100 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241101 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221102}
1103
1104void RenderWidget::didDeactivateCompositor() {
1105 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1106
1107 is_accelerated_compositing_active_ = false;
1108 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1109 routing_id_, is_accelerated_compositing_active_));
1110
[email protected]ea162f92011-10-04 23:08:221111 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241112 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561113}
1114
[email protected]9cd43a62012-03-26 08:03:561115void RenderWidget::willBeginCompositorFrame() {
1116 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371117
1118 DCHECK(RenderThreadImpl::current()->compositor_thread());
1119
1120 // The following two can result in further layout and possibly
1121 // enable GPU acceleration so they need to be called before any painting
1122 // is done.
1123 UpdateTextInputState();
1124 UpdateSelectionBounds();
1125
[email protected]9cd43a62012-03-26 08:03:561126 WillInitiatePaint();
1127}
1128
[email protected]3391a0772012-03-28 00:32:071129void RenderWidget::didBecomeReadyForAdditionalInput() {
1130 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1131 if (pending_input_event_ack_.get())
1132 Send(pending_input_event_ack_.release());
1133}
1134
[email protected]58264a32011-11-17 23:36:151135void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501136 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351137 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1138 // NOTE: Tests may break if this event is renamed or moved.
1139 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161140 // Notify subclasses that we initiated the paint operation.
1141 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151142}
1143
1144void RenderWidget::didCompleteSwapBuffers() {
[email protected]9cd43a62012-03-26 08:03:561145 DidFlushPaint();
1146
[email protected]aa4117f2011-12-09 22:19:211147 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151148 return;
1149
1150 if (!next_paint_flags_ && !plugin_window_moves_.size())
1151 return;
1152
1153 ViewHostMsg_UpdateRect_Params params;
1154 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151155 params.plugin_window_moves.swap(plugin_window_moves_);
1156 params.flags = next_paint_flags_;
1157 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121158 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151159
1160 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1161 next_paint_flags_ = 0;
1162}
1163
[email protected]f98d7e3c2010-09-13 22:30:461164void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041165 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401166 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041167 } else {
[email protected]c3d45532011-10-07 19:20:401168 // TODO(nduca): replace with something a little less hacky. The reason this
1169 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1170 // contains a lot of host-renderer synchronization logic that is still
1171 // important for the accelerated compositing case. The option of simply
1172 // duplicating all that code is less desirable than "faking out" the
1173 // invalidation path using a magical damage rect.
1174 didInvalidateRect(WebRect(0, 0, 1, 1));
1175 }
[email protected]f98d7e3c2010-09-13 22:30:461176}
1177
[email protected]5f8b1022011-01-21 23:34:501178void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201179 if (animation_update_pending_)
1180 return;
1181
[email protected]921244e42011-07-20 16:36:301182 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201183 animation_update_pending_ = true;
1184 if (!animation_timer_.IsRunning()) {
1185 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1186 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211187 }
[email protected]5f8b1022011-01-21 23:34:501188}
1189
[email protected]4873c7d2009-07-16 06:36:281190void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301191 // TODO(darin): Eliminate this temporary.
1192 WebCursor cursor(cursor_info);
1193
initial.commit09911bf2008-07-26 23:55:291194 // Only send a SetCursor message if we need to make a change.
1195 if (!current_cursor_.IsEqual(cursor)) {
1196 current_cursor_ = cursor;
1197 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1198 }
1199}
1200
1201// We are supposed to get a single call to Show for a newly created RenderWidget
1202// that was created via RenderWidget::CreateWebView. So, we wait until this
1203// point to dispatch the ShowWidget message.
1204//
1205// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281206// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291207//
[email protected]4873c7d2009-07-16 06:36:281208void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291209 DCHECK(!did_show_) << "received extraneous Show call";
1210 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1211 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1212
[email protected]8de12d942010-11-17 20:42:441213 if (did_show_)
1214 return;
1215
1216 did_show_ = true;
1217 // NOTE: initial_pos_ may still have its default values at this point, but
1218 // that's okay. It'll be ignored if as_popup is false, or the browser
1219 // process will impose a default position otherwise.
1220 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1221 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291222}
1223
[email protected]4873c7d2009-07-16 06:36:281224void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291225}
1226
[email protected]4873c7d2009-07-16 06:36:281227void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291228}
1229
[email protected]2533ce12009-05-09 00:02:241230void RenderWidget::DoDeferredClose() {
1231 Send(new ViewHostMsg_Close(routing_id_));
1232}
1233
[email protected]4873c7d2009-07-16 06:36:281234void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291235 // If a page calls window.close() twice, we'll end up here twice, but that's
1236 // OK. It is safe to send multiple Close messages.
1237
[email protected]2533ce12009-05-09 00:02:241238 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1239 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1240 // could be closed before the JS finishes executing. So instead, post a
1241 // message back to the message loop, which won't run until the JS is
1242 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211243 MessageLoop::current()->PostTask(
1244 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291245}
1246
1247void RenderWidget::Close() {
1248 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281249 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291250 webwidget_ = NULL;
1251 }
1252}
1253
[email protected]4873c7d2009-07-16 06:36:281254WebRect RenderWidget::windowRect() {
1255 if (pending_window_rect_count_)
1256 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241257
[email protected]b3f2b912009-04-09 16:18:521258 gfx::Rect rect;
1259 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281260 return rect;
initial.commit09911bf2008-07-26 23:55:291261}
1262
[email protected]8a9d6ca32011-06-06 20:11:301263void RenderWidget::setToolTipText(const WebKit::WebString& text,
1264 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541265 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301266}
1267
[email protected]4873c7d2009-07-16 06:36:281268void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291269 if (did_show_) {
1270 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241271 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291272 } else {
1273 initial_pos_ = pos;
1274 }
1275}
1276
[email protected]2533ce12009-05-09 00:02:241277void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1278 pending_window_rect_ = rect;
1279 pending_window_rect_count_++;
1280}
1281
[email protected]4873c7d2009-07-16 06:36:281282WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241283 if (pending_window_rect_count_) {
1284 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1285 // the RootWindowRect is probably going to return wrong results since the
1286 // browser may not have processed the Move yet. There isn't really anything
1287 // good to do in this case, and it shouldn't happen - since this size is
1288 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281289 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241290 }
1291
[email protected]b3f2b912009-04-09 16:18:521292 gfx::Rect rect;
1293 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281294 return rect;
[email protected]d4547452008-08-28 18:36:371295}
1296
[email protected]4873c7d2009-07-16 06:36:281297WebRect RenderWidget::windowResizerRect() {
1298 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191299}
1300
[email protected]fa7b1dc2010-06-23 17:53:041301void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031302 // To prevent this renderer process from sending unnecessary IPC messages to
1303 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041304 // only during the input method attached to the browser process is active.
1305 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291306}
1307
[email protected]fa7b1dc2010-06-23 17:53:041308void RenderWidget::OnImeSetComposition(
1309 const string16& text,
1310 const std::vector<WebCompositionUnderline>& underlines,
1311 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281312 if (!webwidget_)
1313 return;
[email protected]d4cff272011-05-02 15:46:011314 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041315 text, WebVector<WebCompositionUnderline>(underlines),
1316 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011317 // Setting the IME composition was successful. Send the new composition
1318 // range to the browser.
1319 ui::Range range(ui::Range::InvalidRange());
1320 size_t location, length;
1321 if (webwidget_->compositionRange(&location, &length)) {
1322 range.set_start(location);
1323 range.set_end(location + length);
1324 }
1325 // The IME was cancelled via the Esc key, so just send back the caret.
1326 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1327 range.set_start(location);
1328 range.set_end(location + length);
1329 }
1330 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1331 } else {
[email protected]fa7b1dc2010-06-23 17:53:041332 // If we failed to set the composition text, then we need to let the browser
1333 // process to cancel the input method's ongoing composition session, to make
1334 // sure we are in a consistent state.
1335 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011336
1337 // Send an updated IME range with just the caret range.
1338 ui::Range range(ui::Range::InvalidRange());
1339 size_t location, length;
1340 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1341 range.set_start(location);
1342 range.set_end(location + length);
1343 }
1344 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261345 }
[email protected]fa7b1dc2010-06-23 17:53:041346}
1347
[email protected]4de6d1692011-10-12 08:45:441348void RenderWidget::OnImeConfirmComposition(
1349 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041350 if (!webwidget_)
1351 return;
1352
1353 handling_input_event_ = true;
1354 webwidget_->confirmComposition(text);
1355 handling_input_event_ = false;
1356
[email protected]d4cff272011-05-02 15:46:011357 // Send an updated IME range with just the caret range.
1358 ui::Range range(ui::Range::InvalidRange());
1359 size_t location, length;
1360 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1361 range.set_start(location);
1362 range.set_end(location + length);
1363 }
1364 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291365}
1366
[email protected]948f7ab72010-05-28 23:48:081367// This message causes the renderer to render an image of the
1368// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491369void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091370 int tag,
[email protected]948f7ab72010-05-28 23:48:081371 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491372 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001373 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1374 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251375 // Close our unused handle.
1376#if defined(OS_WIN)
1377 ::CloseHandle(dib_handle);
1378#elif defined(OS_MACOSX)
1379 base::SharedMemory::CloseHandle(dib_handle);
1380#endif
1381 }
[email protected]d65adb12010-04-28 17:26:491382 return;
[email protected]45c6aad32010-11-11 04:46:251383 }
[email protected]d65adb12010-04-28 17:26:491384
[email protected]948f7ab72010-05-28 23:48:081385 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491386 // If one of these is empty, then we just return the dib we were
1387 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091388 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491389 return;
1390 }
1391
1392 // Map the given DIB ID into this process, and unmap it at the end
1393 // of this function.
[email protected]45c6aad32010-11-11 04:46:251394 scoped_ptr<TransportDIB> paint_at_size_buffer(
1395 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301396
1397 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491398 float x_scale = static_cast<float>(desired_size.width()) /
1399 static_cast<float>(canvas_size.width());
1400 float y_scale = static_cast<float>(desired_size.height()) /
1401 static_cast<float>(canvas_size.height());
1402
[email protected]ee8d6fd2010-05-26 17:05:481403 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491404 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1405 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481406 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491407
[email protected]36808ad2010-10-20 19:18:301408 scoped_ptr<skia::PlatformCanvas> canvas(
1409 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1410 canvas_size.height()));
1411 if (!canvas.get()) {
1412 NOTREACHED();
1413 return;
1414 }
1415
[email protected]d65adb12010-04-28 17:26:491416 // Reset bounds to what we actually received, but they should be the
1417 // same.
1418 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1419 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1420 bounds.set_width(canvas->getDevice()->width());
1421 bounds.set_height(canvas->getDevice()->height());
1422
1423 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081424 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491425 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1426
[email protected]948f7ab72010-05-28 23:48:081427 // Have to make sure we're laid out at the right size before
1428 // rendering.
1429 gfx::Size old_size = webwidget_->size();
1430 webwidget_->resize(page_size);
1431 webwidget_->layout();
1432
[email protected]d65adb12010-04-28 17:26:491433 // Paint the entire thing (using original bounds, not scaled bounds).
1434 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1435 canvas->restore();
1436
[email protected]948f7ab72010-05-28 23:48:081437 // Return the widget to its previous size.
1438 webwidget_->resize(old_size);
1439
[email protected]c88c9442010-07-19 18:55:091440 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491441}
1442
[email protected]ec7dc112008-08-06 05:30:121443void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1444 // During shutdown we can just ignore this message.
1445 if (!webwidget_)
1446 return;
1447
1448 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561449 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041450 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461451 scheduleComposite();
1452 } else {
1453 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1454 didInvalidateRect(repaint_rect);
1455 }
[email protected]ec7dc112008-08-06 05:30:121456}
1457
[email protected]4873c7d2009-07-16 06:36:281458void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111459 if (!webwidget_)
1460 return;
[email protected]4873c7d2009-07-16 06:36:281461 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111462}
1463
[email protected]4b03e292012-02-13 18:40:071464void RenderWidget::OnInvertWebContent(bool invert) {
1465 if (invert_ == invert)
1466 return;
1467
1468 invert_ = invert;
1469
1470 if (invert_ && !invert_paint_.get()) {
1471 // Gamma-aware color inversion: each source pixel value x is normally
1472 // displayed on a computer monitor with a gamma correction x^gamma,
1473 // where gamma is typically in the range 1.8...2.2. By approximating
1474 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1475 uint8_t table[256];
1476 for (unsigned int i = 0; i < 256; i++) {
1477 double value = i / 255.0;
1478 value = sqrt(1 - (value * value));
1479 table[i] = static_cast<uint8_t>(255 * value);
1480 }
1481
1482 // Create a Skia Paint with this inverting color map.
1483 invert_paint_.reset(new SkPaint());
1484 invert_paint_->setStyle(SkPaint::kFill_Style);
1485 invert_paint_->setColor(SK_ColorBLACK);
1486 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1487 NULL, table, table, table);
1488 invert_paint_->setColorFilter(filter);
1489 filter->unref();
1490 }
1491
1492 OnMsgRepaint(size_);
1493}
1494
[email protected]719b36f2010-12-22 20:36:461495webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151496 const gfx::Rect& paint_bounds,
1497 TransportDIB** dib,
1498 gfx::Rect* location,
1499 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461500 // Bare RenderWidgets don't support optimized plugin painting.
1501 return NULL;
[email protected]ca4847f2010-09-24 05:39:151502}
1503
[email protected]bcaf2272011-02-15 15:29:431504gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521505 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431506 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521507}
1508
[email protected]bee16aab2009-08-26 15:55:031509void RenderWidget::SetHidden(bool hidden) {
1510 if (is_hidden_ == hidden)
1511 return;
1512
1513 // The status has changed. Tell the RenderThread about it.
1514 is_hidden_ = hidden;
1515 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271516 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031517 else
[email protected]380244092011-10-07 17:26:271518 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031519}
1520
[email protected]2b624c562011-10-27 22:58:261521void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261522 if (!webwidget_)
1523 return;
1524
1525 if (is_fullscreen_) {
1526 webwidget_->willExitFullScreen();
1527 } else {
1528 webwidget_->willEnterFullScreen();
1529 }
[email protected]2b624c562011-10-27 22:58:261530}
1531
1532void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261533 if (!webwidget_)
1534 return;
1535
1536 if (is_fullscreen_) {
1537 webwidget_->didEnterFullScreen();
1538 } else {
1539 webwidget_->didExitFullScreen();
1540 }
[email protected]2b624c562011-10-27 22:58:261541}
1542
[email protected]699ab0d2009-04-23 23:19:141543void RenderWidget::SetBackground(const SkBitmap& background) {
1544 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461545
[email protected]699ab0d2009-04-23 23:19:141546 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281547 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141548}
1549
[email protected]674741932009-02-04 23:44:461550bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051551 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461552}
1553
1554bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051555 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461556}
1557
1558void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051559 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461560}
1561
1562void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051563 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461564}
1565
1566void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051567 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461568}
1569
[email protected]e99ef6f2011-10-16 01:13:001570void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041571 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291572 return;
[email protected]fa7b1dc2010-06-23 17:53:041573
[email protected]ad26ef42011-06-17 07:59:451574 ui::TextInputType new_type = GetTextInputType();
1575 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001576 // Only sends text input type and compose inline to the browser process if
1577 // they are changed.
1578 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451579 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041580 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451581 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001582 Send(new ViewHostMsg_TextInputStateChanged(
1583 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291584 }
initial.commit09911bf2008-07-26 23:55:291585}
1586
[email protected]3f783362011-10-21 22:40:501587void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1588 WebRect start_webrect;
1589 WebRect end_webrect;
1590 webwidget_->selectionBounds(start_webrect, end_webrect);
1591 *start = start_webrect;
1592 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321593}
1594
[email protected]e99ef6f2011-10-16 01:13:001595void RenderWidget::UpdateSelectionBounds() {
1596 if (!webwidget_)
1597 return;
1598
[email protected]3f783362011-10-21 22:40:501599 gfx::Rect start_rect;
1600 gfx::Rect end_rect;
1601 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001602 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1603 return;
1604
1605 selection_start_rect_ = start_rect;
1606 selection_end_rect_ = end_rect;
1607 Send(new ViewHostMsg_SelectionBoundsChanged(
1608 routing_id_, selection_start_rect_, selection_end_rect_));
1609}
1610
[email protected]73bf95812011-10-12 11:38:321611// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451612COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1613 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1614COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1615 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1616COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1617 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181618COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1619 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1620COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1621 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1622COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1623 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1624COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1625 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1626COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1627 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451628
1629ui::TextInputType RenderWidget::GetTextInputType() {
1630 if (webwidget_) {
1631 int type = webwidget_->textInputType();
1632 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181633 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451634 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1635 return static_cast<ui::TextInputType>(type);
1636 }
1637 return ui::TEXT_INPUT_TYPE_NONE;
1638}
1639
1640bool RenderWidget::CanComposeInline() {
1641 return true;
[email protected]56ea1a62011-05-30 07:05:571642}
1643
[email protected]4873c7d2009-07-16 06:36:281644WebScreenInfo RenderWidget::screenInfo() {
[email protected]6fd35b72012-03-01 19:46:411645 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281646}
1647
[email protected]fa7b1dc2010-06-23 17:53:041648void RenderWidget::resetInputMethod() {
1649 if (!input_method_is_active_)
1650 return;
1651
1652 // If the last text input type is not None, then we should finish any
1653 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451654 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041655 // If a composition text exists, then we need to let the browser process
1656 // to cancel the input method's ongoing composition session.
1657 if (webwidget_->confirmComposition())
1658 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1659 }
[email protected]d4cff272011-05-02 15:46:011660
1661 // Send an updated IME range with the current caret rect.
1662 ui::Range range(ui::Range::InvalidRange());
1663 size_t location, length;
1664 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1665 range.set_start(location);
1666 range.set_end(location + length);
1667 }
1668 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041669}
1670
[email protected]f103ab72009-09-02 17:10:591671void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501672 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291673 size_t i = 0;
1674 for (; i < plugin_window_moves_.size(); ++i) {
1675 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581676 if (move.rects_valid) {
1677 plugin_window_moves_[i] = move;
1678 } else {
1679 plugin_window_moves_[i].visible = move.visible;
1680 }
initial.commit09911bf2008-07-26 23:55:291681 break;
1682 }
1683 }
1684
1685 if (i == plugin_window_moves_.size())
1686 plugin_window_moves_.push_back(move);
1687}
[email protected]268654772009-08-06 23:02:041688
1689void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1690 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1691 i != plugin_window_moves_.end(); ++i) {
1692 if (i->window == window) {
1693 plugin_window_moves_.erase(i);
1694 break;
1695 }
1696 }
1697}
[email protected]67bfb83f2011-09-22 03:36:371698
1699bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1700 return false;
1701}
[email protected]c3d45532011-10-07 19:20:401702
1703bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1704 return false;
1705}