blob: 3225feefadf268dd8043100cfcd179c312d299f8 [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]659f73f2009-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
189 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29190
[email protected]6de74452009-02-25 18:04:59191 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29192}
193
[email protected]992db4c2011-05-12 15:37:15194void RenderWidget::SetSwappedOut(bool is_swapped_out) {
195 // We should only toggle between states.
196 DCHECK(is_swapped_out_ != is_swapped_out);
197 is_swapped_out_ = is_swapped_out;
198
199 // If we are swapping out, we will call ReleaseProcess, allowing the process
200 // to exit if all of its RenderViews are swapped out. We wait until the
201 // WasSwappedOut call to do this, to avoid showing the sad tab.
202 // If we are swapping in, we call AddRefProcess to prevent the process from
203 // exiting.
204 if (!is_swapped_out)
205 RenderProcess::current()->AddRefProcess();
206}
207
[email protected]a95986a82010-12-24 06:19:28208bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
209 bool handled = true;
210 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
211 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
212 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
213 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54214 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28215 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
216 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15217 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28218 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
219 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
220 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
221 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
222 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
223 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
224 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
225 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
226 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
227 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
228 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]4b03e292012-02-13 18:40:07229 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
[email protected]a95986a82010-12-24 06:19:28230 IPC_MESSAGE_UNHANDLED(handled = false)
231 IPC_END_MESSAGE_MAP()
232 return handled;
233}
initial.commit09911bf2008-07-26 23:55:29234
235bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15236 // Don't send any messages after the browser has told us to close, and filter
237 // most outgoing messages while swapped out.
238 if ((is_swapped_out_ &&
239 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
240 closing_) {
initial.commit09911bf2008-07-26 23:55:29241 delete message;
242 return false;
243 }
244
245 // If given a messsage without a routing ID, then assign our routing ID.
246 if (message->routing_id() == MSG_ROUTING_NONE)
247 message->set_routing_id(routing_id_);
248
[email protected]380244092011-10-07 17:26:27249 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44250}
251
[email protected]61e2b3cc2012-03-02 16:13:34252void RenderWidget::Resize(const gfx::Size& new_size,
253 const gfx::Rect& resizer_rect,
254 bool is_fullscreen,
255 ResizeAck resize_ack) {
256 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
257 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
258 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29259
[email protected]61e2b3cc2012-03-02 16:13:34260 // Ignore this during shutdown.
261 if (!webwidget_)
262 return;
263
264 // Remember the rect where the resize corner will be drawn.
265 resizer_rect_ = resizer_rect;
266
267 // NOTE: We may have entered fullscreen mode without changing our size.
268 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
269 if (fullscreen_change)
270 WillToggleFullscreen();
271 is_fullscreen_ = is_fullscreen;
272
273 if (size_ != new_size) {
274 // TODO(darin): We should not need to reset this here.
275 SetHidden(false);
276 needs_repainting_on_restore_ = false;
277
278 size_ = new_size;
279
280 paint_aggregator_.ClearPendingUpdate();
281
282 // When resizing, we want to wait to paint before ACK'ing the resize. This
283 // ensures that we only resize as fast as we can paint. We only need to
284 // send an ACK if we are resized to a non-empty rect.
285 webwidget_->resize(new_size);
286 if (!new_size.IsEmpty()) {
287 if (!is_accelerated_compositing_active_) {
288 // Resize should have caused an invalidation of the entire view.
289 DCHECK(paint_aggregator_.HasPendingUpdate());
290 }
291
292 // Send the Resize_ACK flag once we paint again if requested.
293 if (resize_ack == SEND_RESIZE_ACK)
294 set_next_paint_is_resize_ack();
295 }
[email protected]ff475a322012-03-14 00:05:35296 } else {
297 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34298 }
299
300 if (fullscreen_change)
301 DidToggleFullscreen();
302
303 // If a resize ack is requested and it isn't set-up, then no more resizes will
304 // come in and in general things will go wrong.
305 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
306 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29307}
308
309void RenderWidget::OnClose() {
310 if (closing_)
311 return;
312 closing_ = true;
313
314 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03315 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27316 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03317 SetHidden(false);
318 }
initial.commit09911bf2008-07-26 23:55:29319
initial.commit09911bf2008-07-26 23:55:29320 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25321 // now. Post a task that only gets invoked when there are no nested message
322 // loops.
[email protected]32876ae2011-11-15 22:25:21323 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29324 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25325
326 // Balances the AddRef taken when we called AddRoute.
327 Release();
initial.commit09911bf2008-07-26 23:55:29328}
329
[email protected]61e2b3cc2012-03-02 16:13:34330// Got a response from the browser after the renderer decided to create a new
331// view.
332void RenderWidget::OnCreatingNewAck(
333 gfx::NativeViewId parent) {
334 DCHECK(routing_id_ != MSG_ROUTING_NONE);
335
336 CompleteInit(parent);
337}
338
[email protected]f21c613a2009-02-12 14:46:17339void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09340 const gfx::Rect& resizer_rect,
341 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34342 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29343}
344
[email protected]b5913d72012-02-07 22:26:54345void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
346 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59347 gfx::Rect view_rect(size_);
348
349 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
350 if (!old_damage_rect.IsEmpty())
351 paint_aggregator_.InvalidateRect(old_damage_rect);
352
353 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
354 if (!new_damage_rect.IsEmpty())
355 paint_aggregator_.InvalidateRect(new_damage_rect);
356
[email protected]b5913d72012-02-07 22:26:54357 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59358
[email protected]b5913d72012-02-07 22:26:54359 if (webwidget_)
360 webwidget_->didChangeWindowResizerRect();
361 }
362}
363
initial.commit09911bf2008-07-26 23:55:29364void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31365 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29366 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03367 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29368}
369
370void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31371 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29372 // During shutdown we can just ignore this message.
373 if (!webwidget_)
374 return;
375
376 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03377 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29378
379 if (!needs_repainting && !needs_repainting_on_restore_)
380 return;
381 needs_repainting_on_restore_ = false;
382
[email protected]d65adb12010-04-28 17:26:49383 // Tag the next paint as a restore ack, which is picked up by
384 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29385 set_next_paint_is_restore_ack();
386
387 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56388 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46389 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
390 } else {
391 scheduleComposite();
392 }
initial.commit09911bf2008-07-26 23:55:29393}
394
[email protected]992db4c2011-05-12 15:37:15395void RenderWidget::OnWasSwappedOut() {
396 // If we have been swapped out and no one else is using this process,
397 // it's safe to exit now. If we get swapped back in, we will call
398 // AddRefProcess in SetSwappedOut.
399 if (is_swapped_out_)
400 RenderProcess::current()->ReleaseProcess();
401}
402
[email protected]53d3f302009-12-21 04:42:05403void RenderWidget::OnRequestMoveAck() {
404 DCHECK(pending_window_rect_count_);
405 pending_window_rect_count_--;
406}
407
408void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58409 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21410 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05411 update_reply_pending_ = false;
412
[email protected]b4d08452010-10-05 17:34:35413 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
414 // have no current paint buffer.
415 if (current_paint_buf_) {
416 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
417 current_paint_buf_ = NULL;
418 }
419
[email protected]65225772011-05-12 21:10:24420 // If swapbuffers is still pending, then defer the update until the
421 // swapbuffers occurs.
422 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
423 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
424 return;
425 }
426
[email protected]29ed96a2012-02-04 18:12:16427 // Notify subclasses that software rendering was flushed to the screen.
428 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25429
initial.commit09911bf2008-07-26 23:55:29430 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24431 DoDeferredUpdateAndSendInputAck();
432}
433
[email protected]d0be63772011-12-20 23:18:04434bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24435 return false;
436}
437
[email protected]d0be63772011-12-20 23:18:04438void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24439 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21440 while (!updates_pending_swap_.empty()) {
441 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
442 updates_pending_swap_.pop_front();
443 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
444 // compositing pass, hence doesn't require an UpdateRect message.
445 if (msg)
446 Send(msg);
447 }
[email protected]65225772011-05-12 21:10:24448 num_swapbuffers_complete_pending_ = 0;
449 using_asynchronous_swapbuffers_ = false;
450 // Schedule another frame so the compositor learns about it.
451 scheduleComposite();
452}
453
[email protected]37a6f302011-07-11 23:43:08454void RenderWidget::OnSwapBuffersPosted() {
455 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21456
457 if (using_asynchronous_swapbuffers_) {
458 ViewHostMsg_UpdateRect* msg = NULL;
459 // pending_update_params_ can be NULL if the swap doesn't correspond to an
460 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
461 // message.
462 if (pending_update_params_.get()) {
463 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
464 pending_update_params_.reset();
465 }
466 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08467 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21468 }
[email protected]37a6f302011-07-11 23:43:08469}
470
471void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24472 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16473
474 // Notify subclasses that composited rendering got flushed to the screen.
475 DidFlushPaint();
476
[email protected]65225772011-05-12 21:10:24477 // When compositing deactivates, we reset the swapbuffers pending count. The
478 // swapbuffers acks may still arrive, however.
479 if (num_swapbuffers_complete_pending_ == 0) {
480 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
481 return;
482 }
[email protected]aa4117f2011-12-09 22:19:21483 DCHECK(!updates_pending_swap_.empty());
484 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
485 updates_pending_swap_.pop_front();
486 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
487 // compositing pass, hence doesn't require an UpdateRect message.
488 if (msg)
489 Send(msg);
[email protected]65225772011-05-12 21:10:24490 num_swapbuffers_complete_pending_--;
491
492 // If update reply is still pending, then defer the update until that reply
493 // occurs.
[email protected]d0be63772011-12-20 23:18:04494 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24495 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
496 return;
497 }
498
499 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06500 // when we were previously rendering. However, if an invalidation task is not
501 // posted, there may be software rendering work pending. In that case, don't
502 // early out.
503 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24504 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
505 return;
506 }
507
[email protected]65225772011-05-12 21:10:24508 // Continue painting if necessary...
509 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29510}
511
initial.commit09911bf2008-07-26 23:55:29512void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24513 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56514 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29515
516 const char* data;
517 int data_length;
[email protected]5dd768212009-08-13 23:34:49518 handling_input_event_ = true;
519 if (!message.ReadData(&iter, &data, &data_length)) {
520 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29521 return;
[email protected]5dd768212009-08-13 23:34:49522 }
initial.commit09911bf2008-07-26 23:55:29523
524 const WebInputEvent* input_event =
525 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48526
[email protected]b68a0e52011-12-08 15:11:12527 bool is_keyboard_shortcut = false;
528 // is_keyboard_shortcut flag is only available for RawKeyDown events.
529 if (input_event->type == WebInputEvent::RawKeyDown)
530 message.ReadBool(&iter, &is_keyboard_shortcut);
531
[email protected]67bfb83f2011-09-22 03:36:37532 bool prevent_default = false;
533 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26534 const WebMouseEvent& mouse_event =
535 *static_cast<const WebMouseEvent*>(input_event);
536 TRACE_EVENT2("renderer", "HandleMouseMove",
537 "x", mouse_event.x, "y", mouse_event.y);
538 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37539 }
540
541 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12542 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
543 suppress_next_char_events_ = false;
544 if (!processed && webwidget_)
545 processed = webwidget_->handleInputEvent(*input_event);
546 }
547
548 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
549 // it's not processed by webkit, then we need to suppress the upcoming Char
550 // events.
551 if (!processed && is_keyboard_shortcut)
552 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29553
[email protected]a9fb30aa2011-10-06 06:58:46554 IPC::Message* response =
555 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
556 processed);
[email protected]3391a0772012-03-28 00:32:07557 bool event_type_gets_rate_limited =
558 input_event->type == WebInputEvent::MouseMove ||
559 input_event->type == WebInputEvent::MouseWheel ||
560 WebInputEvent::isTouchEventType(input_event->type);
561 bool is_input_throttled =
562 webwidget_->isInputThrottled() ||
563 paint_aggregator_.HasPendingUpdate();
[email protected]e2824412009-02-27 01:57:05564
[email protected]3391a0772012-03-28 00:32:07565 if (event_type_gets_rate_limited && is_input_throttled) {
[email protected]12fbad812009-09-01 18:21:24566 // We want to rate limit the input events in this case, so we'll wait for
567 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17568 if (pending_input_event_ack_.get()) {
569 // As two different kinds of events could cause us to postpone an ack
570 // we send it now, if we have one pending. The Browser should never
571 // send us the same kind of event we are delaying the ack for.
572 Send(pending_input_event_ack_.release());
573 }
[email protected]12fbad812009-09-01 18:21:24574 pending_input_event_ack_.reset(response);
575 } else {
576 Send(response);
577 }
578
[email protected]5dd768212009-08-13 23:34:49579 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48580
[email protected]67bfb83f2011-09-22 03:36:37581 if (!prevent_default) {
582 if (WebInputEvent::isKeyboardEventType(input_event->type))
583 DidHandleKeyEvent();
584 if (WebInputEvent::isMouseEventType(input_event->type))
585 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24586 if (WebInputEvent::isTouchEventType(input_event->type))
587 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37588 }
initial.commit09911bf2008-07-26 23:55:29589}
590
591void RenderWidget::OnMouseCaptureLost() {
592 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28593 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29594}
595
596void RenderWidget::OnSetFocus(bool enable) {
597 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33598 if (webwidget_)
599 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29600}
601
602void RenderWidget::ClearFocus() {
603 // We may have got the focus from the browser before this gets processed, in
604 // which case we do not want to unfocus ourself.
605 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28606 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29607}
608
[email protected]2d5d09d52009-06-15 14:29:21609void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00610 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21611 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06612 TRACE_EVENT2("renderer", "PaintRect",
613 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00614 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21615
616 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00617 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
618 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03619
[email protected]4b03e292012-02-13 18:40:07620 if (invert_) {
621 // Draw everything to a temporary bitmap and then apply an
622 // inverting color map to the result. This is balanced by an extra
623 // call to canvas->restore(), below.
624 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48625 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07626 canvas->saveLayer(&bounds, invert_paint_.get());
627 }
628
[email protected]699ab0d2009-04-23 23:19:14629 // If there is a custom background, tile it.
630 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14631 SkPaint paint;
632 SkShader* shader = SkShader::CreateBitmapShader(background_,
633 SkShader::kRepeat_TileMode,
634 SkShader::kRepeat_TileMode);
635 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20636
637 // Use kSrc_Mode to handle background_ transparency properly.
638 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
639
640 // Canvas could contain multiple update rects. Clip to given rect so that
641 // we don't accidentally clear other update rects.
642 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48643 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14644 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20645 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14646 }
647
[email protected]719b36f2010-12-22 20:36:46648 // First see if this rect is a plugin that can paint itself faster.
649 TransportDIB* optimized_dib = NULL;
650 gfx::Rect optimized_copy_rect, optimized_copy_location;
651 webkit::ppapi::PluginInstance* optimized_instance =
652 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
653 &optimized_copy_location,
654 &optimized_copy_rect);
655 if (optimized_instance) {
656 // This plugin can be optimize-painted and we can just ask it to paint
657 // itself. We don't actually need the TransportDIB in this case.
658 //
659 // This is an optimization for PPAPI plugins that know they're on top of
660 // the page content. If this rect is inside such a plugin, we can save some
661 // time and avoid re-rendering the page content which we know will be
662 // covered by the plugin later (this time can be significant, especially
663 // for a playing movie that is invalidating a lot).
664 //
665 // In the plugin movie case, hopefully the similar call to
666 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
667 // painting, because that avoids copying the plugin image to a different
668 // paint rect. Unfortunately, if anything on the page is animating other
669 // than the movie, it break this optimization since the union of the
670 // invalid regions will be larger than the plugin.
671 //
672 // This code optimizes that case, where we can still avoid painting in
673 // WebKit and filling the background (which can be slow) and just painting
674 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
675 // required.
676 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27677 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46678 } else {
679 // Normal painting case.
680 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
681
682 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35683 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46684 }
initial.commit09911bf2008-07-26 23:55:29685
[email protected]4b03e292012-02-13 18:40:07686 if (invert_)
687 canvas->restore();
688
[email protected]4fb66842009-12-04 21:41:00689 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00690 canvas->restore();
691}
692
693void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
694 skia::PlatformCanvas* canvas) {
695 static bool kPaintBorder =
696 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
697 if (!kPaintBorder)
698 return;
699
[email protected]53d3f302009-12-21 04:42:05700 // Cycle through these colors to help distinguish new paint rects.
701 const SkColor colors[] = {
702 SkColorSetARGB(0x3F, 0xFF, 0, 0),
703 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
704 SkColorSetARGB(0x3F, 0, 0, 0xFF),
705 };
706 static int color_selector = 0;
707
[email protected]4fb66842009-12-04 21:41:00708 SkPaint paint;
709 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05710 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00711 paint.setStrokeWidth(1);
712
713 SkIRect irect;
714 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
715 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29716}
717
[email protected]52ccd0ea2011-02-16 01:09:05718void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30719 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30720 if (!animation_update_pending_) {
721 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59722 return;
[email protected]921244e42011-07-20 16:36:30723 }
[email protected]bd37ae252011-06-03 01:28:18724 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59725 // Record when we fired (according to base::Time::Now()) relative to when
726 // we posted the task to quantify how much the base::Time/base::TimeTicks
727 // skew is affecting animations.
728 base::TimeDelta animation_callback_delay = base::Time::Now() -
729 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
730 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
731 animation_callback_delay,
732 base::TimeDelta::FromMilliseconds(0),
733 base::TimeDelta::FromMilliseconds(30),
734 25);
735 }
[email protected]65225772011-05-12 21:10:24736 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24737}
738
[email protected]52ccd0ea2011-02-16 01:09:05739void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59740 if (!animation_update_pending_)
741 return;
[email protected]bd37ae252011-06-03 01:28:18742
743 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33744 base::TimeDelta animationInterval = IsRenderingVSynced() ?
745 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18746
[email protected]7c4329e2011-02-18 22:02:59747 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45748
749 // animation_floor_time_ is the earliest time that we should animate when
750 // using the dead reckoning software scheduler. If we're using swapbuffers
751 // complete callbacks to rate limit, we can ignore this floor.
752 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30753 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33754 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18755 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59756 // running animation callbacks so that if a callback requests another
757 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38758 animation_timer_.Stop();
759 animation_timer_.Start(FROM_HERE, animationInterval, this,
760 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59761 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30762 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59763 return;
[email protected]5f8b1022011-01-21 23:34:50764 }
[email protected]bd37ae252011-06-03 01:28:18765 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38766 if (!animation_timer_.IsRunning()) {
767 // This code uses base::Time::Now() to calculate the floor and next fire
768 // time because javascript's Date object uses base::Time::Now(). The
769 // message loop uses base::TimeTicks, which on windows can have a
770 // different granularity than base::Time.
771 // The upshot of all this is that this function might be called before
772 // base::Time::Now() has advanced past the animation_floor_time_. To
773 // avoid exposing this delay to javascript, we keep posting delayed
774 // tasks until base::Time::Now() has advanced far enough.
775 base::TimeDelta delay = animation_floor_time_ - now;
776 animation_timer_.Start(FROM_HERE, delay, this,
777 &RenderWidget::AnimationCallback);
778 }
[email protected]5f8b1022011-01-21 23:34:50779}
780
[email protected]bd37ae252011-06-03 01:28:18781bool RenderWidget::IsRenderingVSynced() {
782 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
783 // not caught by this check. This will lead to artificially low frame rates
784 // for people who force vsync off at a driver level and expect Chrome to speed
785 // up.
786 return !has_disable_gpu_vsync_switch_;
787}
788
[email protected]65225772011-05-12 21:10:24789void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06790 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24791 invalidation_task_posted_ = false;
792 DoDeferredUpdateAndSendInputAck();
793}
794
795void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05796 DoDeferredUpdate();
797
798 if (pending_input_event_ack_.get())
799 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21800}
801
[email protected]552e6002009-11-19 05:24:57802void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58803 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08804
[email protected]65225772011-05-12 21:10:24805 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29806 return;
[email protected]05a980d7a2012-02-07 22:16:42807
808 if (!host_window_set_) {
809 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
810 return;
811 }
[email protected]aa4117f2011-12-09 22:19:21812 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24813 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
814 return;
815 }
[email protected]9ca84622011-06-02 23:46:39816 if (is_accelerated_compositing_active_ &&
817 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24818 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
819 return;
820 }
initial.commit09911bf2008-07-26 23:55:29821
[email protected]552e6002009-11-19 05:24:57822 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29823 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57824 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29825 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24826 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29827 return;
828 }
829
[email protected]05a980d7a2012-02-07 22:16:42830 if (is_accelerated_compositing_active_)
831 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
832
[email protected]0fb93f52011-05-18 23:13:56833 // Tracking of frame rate jitter
834 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51835 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05836 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50837
[email protected]f98d7e3c2010-09-13 22:30:46838 // Layout may generate more invalidation. It may also enable the
839 // GPU acceleration, so make sure to run layout before we send the
840 // GpuRenderingActivated message.
841 webwidget_->layout();
842
[email protected]dcca3aa92012-02-17 23:03:37843 // The following two can result in further layout and possibly
844 // enable GPU acceleration so they need to be called before any painting
845 // is done.
846 UpdateTextInputState();
847 UpdateSelectionBounds();
848
[email protected]5f8b1022011-01-21 23:34:50849 // Suppress painting if nothing is dirty. This has to be done after updating
850 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24851 if (!paint_aggregator_.HasPendingUpdate()) {
852 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51853 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50854 return;
[email protected]65225772011-05-12 21:10:24855 }
[email protected]5f8b1022011-01-21 23:34:50856
[email protected]872ae5b2011-05-26 20:20:50857 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56858 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04859 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56860 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
861 delay,
862 base::TimeDelta::FromMilliseconds(1),
863 base::TimeDelta::FromMilliseconds(60),
864 30);
[email protected]d0be63772011-12-20 23:18:04865 } else {
[email protected]0fb93f52011-05-18 23:13:56866 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
867 delay,
868 base::TimeDelta::FromMilliseconds(1),
869 base::TimeDelta::FromMilliseconds(60),
870 30);
[email protected]d0be63772011-12-20 23:18:04871 }
[email protected]872ae5b2011-05-26 20:20:50872
873 // Calculate filtered time per frame:
874 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
875 filtered_time_per_frame_ =
876 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56877 }
878 last_do_deferred_update_time_ = frame_begin_ticks;
879
[email protected]552e6002009-11-19 05:24:57880 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29881 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30882 PaintAggregator::PendingUpdate update;
883 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29884
[email protected]53d3f302009-12-21 04:42:05885 gfx::Rect scroll_damage = update.GetScrollDamage();
886 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29887
[email protected]29ed96a2012-02-04 18:12:16888 // Notify derived classes that we're about to initiate a paint.
889 WillInitiatePaint();
890
[email protected]ca4847f2010-09-24 05:39:15891 // A plugin may be able to do an optimized paint. First check this, in which
892 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46893 // This optimization allows PPAPI plugins that declare themselves on top of
894 // the page (like a traditional windowed plugin) to be able to animate (think
895 // movie playing) without repeatedly re-painting the page underneath, or
896 // copying the plugin backing store (since we can send the plugin's backing
897 // store directly to the browser).
898 //
899 // This optimization only works when the entire invalid region is contained
900 // within the plugin. There is a related optimization in PaintRect for the
901 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15902 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15903 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21904 DCHECK(!pending_update_params_.get());
905 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
906 pending_update_params_->dx = update.scroll_delta.x();
907 pending_update_params_->dy = update.scroll_delta.y();
908 pending_update_params_->scroll_rect = update.scroll_rect;
909 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21910 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
911 pending_update_params_->flags = next_paint_flags_;
912 pending_update_params_->scroll_offset = GetScrollOffset();
913 pending_update_params_->needs_ack = true;
914 next_paint_flags_ = 0;
915
[email protected]ca4847f2010-09-24 05:39:15916 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56917 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15918 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
919 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27920 // Only update the part of the plugin that actually changed.
921 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21922 pending_update_params_->bitmap = dib->id();
923 pending_update_params_->bitmap_rect = optimized_copy_location;
924 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56925 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46926 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15927 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35928 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
929 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46930 if (!canvas.get()) {
931 NOTREACHED();
932 return;
933 }
[email protected]cef3362f2009-12-21 17:48:45934
[email protected]f98d7e3c2010-09-13 22:30:46935 // We may get back a smaller canvas than we asked for.
936 // TODO(darin): This seems like it could cause painting problems!
937 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
938 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
939 bounds.set_width(canvas->getDevice()->width());
940 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05941
[email protected]f98d7e3c2010-09-13 22:30:46942 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
943
[email protected]aa4117f2011-12-09 22:19:21944 pending_update_params_->bitmap = current_paint_buf_->id();
945 pending_update_params_->bitmap_rect = bounds;
946
947 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46948 // The scroll damage is just another rectangle to paint and copy.
949 copy_rects.swap(update.paint_rects);
950 if (!scroll_damage.IsEmpty())
951 copy_rects.push_back(scroll_damage);
952
953 for (size_t i = 0; i < copy_rects.size(); ++i)
954 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35955
956 // Software FPS tick for performance tests. The accelerated path traces the
957 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
958 // NOTE: Tests may break if this event is renamed or moved.
959 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46960 } else { // Accelerated compositing path
961 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21962 // If painting is done via the gpu process then we don't set any damage
963 // rects to save the browser process from doing unecessary work.
964 pending_update_params_->bitmap_rect = bounds;
965 pending_update_params_->scroll_rect = gfx::Rect();
966 // We don't need an ack, because we're not sharing a DIB with the browser.
967 // If it needs to (e.g. composited UI), the GPU process does its own ACK
968 // with the browser for the GPU surface.
969 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42970 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46971 }
972
[email protected]936c6f52011-12-13 01:35:26973 // If we're holding a pending input event ACK, send the ACK before sending the
974 // UpdateReply message so we can receive another input event before the
975 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
976 // the UpdateRect IPC message handler.
977 if (pending_input_event_ack_.get())
978 Send(pending_input_event_ack_.release());
979
[email protected]aa4117f2011-12-09 22:19:21980 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
981 // OnSwapBuffersPosted), meaning a message has been added to the
982 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
983 // the message now.
984 if (pending_update_params_.get()) {
985 // sending an ack to browser process that the paint is complete...
986 update_reply_pending_ = pending_update_params_->needs_ack;
987 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
988 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:34989 }
[email protected]53d3f302009-12-21 04:42:05990
[email protected]29ed96a2012-02-04 18:12:16991 // If we're software rendering then we're done initiating the paint.
992 if (!is_accelerated_compositing_active_)
993 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29994}
995
996///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:46997// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:29998
[email protected]4873c7d2009-07-16 06:36:28999void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:571000 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481001 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571002 gfx::Rect damaged_rect = view_rect.Intersect(rect);
1003 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291004 return;
1005
[email protected]552e6002009-11-19 05:24:571006 paint_aggregator_.InvalidateRect(damaged_rect);
1007
1008 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241009 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571010 return;
1011 if (!paint_aggregator_.HasPendingUpdate())
1012 return;
[email protected]aa4117f2011-12-09 22:19:211013 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241014 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1015 return;
1016
1017 // When GPU rendering, combine pending animations and invalidations into
1018 // a single update.
[email protected]816edc62012-03-17 01:27:221019 if (is_accelerated_compositing_active_ &&
1020 animation_update_pending_ &&
1021 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571022 return;
1023
1024 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291025 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1026 // on the call stack.
1027 // 2) Allows us to collect more damage rects before painting to help coalesce
1028 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241029 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211030 MessageLoop::current()->PostTask(
1031 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291032}
1033
[email protected]4873c7d2009-07-16 06:36:281034void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461035 // Drop scrolls on the floor when we are in compositing mode.
1036 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561037 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461038 return;
1039
[email protected]552e6002009-11-19 05:24:571040 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481041 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571042 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1043 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291044 return;
1045
[email protected]552e6002009-11-19 05:24:571046 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1047
1048 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241049 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571050 return;
1051 if (!paint_aggregator_.HasPendingUpdate())
1052 return;
[email protected]aa4117f2011-12-09 22:19:211053 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241054 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1055 return;
1056
1057 // When GPU rendering, combine pending animations and invalidations into
1058 // a single update.
[email protected]816edc62012-03-17 01:27:221059 if (is_accelerated_compositing_active_ &&
1060 animation_update_pending_ &&
1061 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571062 return;
1063
1064 // Perform updating asynchronously. This serves two purposes:
1065 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1066 // on the call stack.
1067 // 2) Allows us to collect more damage rects before painting to help coalesce
1068 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241069 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211070 MessageLoop::current()->PostTask(
1071 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291072}
1073
[email protected]244ac1892011-12-02 17:04:471074void RenderWidget::didAutoResize(const WebSize& new_size) {
1075 size_ = new_size;
1076}
1077
[email protected]91acd1c2012-03-14 08:32:391078void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221079 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1080
[email protected]aa4117f2011-12-09 22:19:211081 if (!is_accelerated_compositing_active_) {
1082 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1083 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1084 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1085 // going to switch to accelerated compositing, the GPU process may need
1086 // round-trips to the browser's UI thread before finishing the frame,
1087 // causing deadlocks if we delay the UpdateRect until we receive the
1088 // OnSwapBuffersComplete. So send a dummy message that will unblock the
1089 // browser's UI thread.
1090 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1091 }
1092
[email protected]ea162f92011-10-04 23:08:221093 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421094 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241095 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221096}
1097
1098void RenderWidget::didDeactivateCompositor() {
1099 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1100
1101 is_accelerated_compositing_active_ = false;
1102 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1103 routing_id_, is_accelerated_compositing_active_));
1104
[email protected]ea162f92011-10-04 23:08:221105 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241106 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561107}
1108
[email protected]9cd43a62012-03-26 08:03:561109void RenderWidget::willBeginCompositorFrame() {
1110 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371111
1112 DCHECK(RenderThreadImpl::current()->compositor_thread());
1113
1114 // The following two can result in further layout and possibly
1115 // enable GPU acceleration so they need to be called before any painting
1116 // is done.
1117 UpdateTextInputState();
1118 UpdateSelectionBounds();
1119
[email protected]9cd43a62012-03-26 08:03:561120 WillInitiatePaint();
1121}
1122
[email protected]3391a0772012-03-28 00:32:071123void RenderWidget::didBecomeReadyForAdditionalInput() {
1124 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1125 if (pending_input_event_ack_.get())
1126 Send(pending_input_event_ack_.release());
1127}
1128
[email protected]58264a32011-11-17 23:36:151129void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501130 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351131 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1132 // NOTE: Tests may break if this event is renamed or moved.
1133 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161134 // Notify subclasses that we initiated the paint operation.
1135 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151136}
1137
1138void RenderWidget::didCompleteSwapBuffers() {
[email protected]9cd43a62012-03-26 08:03:561139 DidFlushPaint();
1140
[email protected]aa4117f2011-12-09 22:19:211141 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151142 return;
1143
1144 if (!next_paint_flags_ && !plugin_window_moves_.size())
1145 return;
1146
1147 ViewHostMsg_UpdateRect_Params params;
1148 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151149 params.plugin_window_moves.swap(plugin_window_moves_);
1150 params.flags = next_paint_flags_;
1151 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121152 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151153
1154 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1155 next_paint_flags_ = 0;
1156}
1157
[email protected]f98d7e3c2010-09-13 22:30:461158void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041159 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401160 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041161 } else {
[email protected]c3d45532011-10-07 19:20:401162 // TODO(nduca): replace with something a little less hacky. The reason this
1163 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1164 // contains a lot of host-renderer synchronization logic that is still
1165 // important for the accelerated compositing case. The option of simply
1166 // duplicating all that code is less desirable than "faking out" the
1167 // invalidation path using a magical damage rect.
1168 didInvalidateRect(WebRect(0, 0, 1, 1));
1169 }
[email protected]f98d7e3c2010-09-13 22:30:461170}
1171
[email protected]5f8b1022011-01-21 23:34:501172void RenderWidget::scheduleAnimation() {
[email protected]921244e42011-07-20 16:36:301173 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ee3d3ad2011-02-04 00:42:211174 if (!animation_update_pending_) {
1175 animation_update_pending_ = true;
[email protected]350ce8702012-03-09 04:23:381176 if (!animation_timer_.IsRunning()) {
1177 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1178 &RenderWidget::AnimationCallback);
[email protected]52ccd0ea2011-02-16 01:09:051179 }
[email protected]ee3d3ad2011-02-04 00:42:211180 }
[email protected]5f8b1022011-01-21 23:34:501181}
1182
[email protected]4873c7d2009-07-16 06:36:281183void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301184 // TODO(darin): Eliminate this temporary.
1185 WebCursor cursor(cursor_info);
1186
initial.commit09911bf2008-07-26 23:55:291187 // Only send a SetCursor message if we need to make a change.
1188 if (!current_cursor_.IsEqual(cursor)) {
1189 current_cursor_ = cursor;
1190 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1191 }
1192}
1193
1194// We are supposed to get a single call to Show for a newly created RenderWidget
1195// that was created via RenderWidget::CreateWebView. So, we wait until this
1196// point to dispatch the ShowWidget message.
1197//
1198// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281199// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291200//
[email protected]4873c7d2009-07-16 06:36:281201void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291202 DCHECK(!did_show_) << "received extraneous Show call";
1203 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1204 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1205
[email protected]8de12d942010-11-17 20:42:441206 if (did_show_)
1207 return;
1208
1209 did_show_ = true;
1210 // NOTE: initial_pos_ may still have its default values at this point, but
1211 // that's okay. It'll be ignored if as_popup is false, or the browser
1212 // process will impose a default position otherwise.
1213 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1214 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291215}
1216
[email protected]4873c7d2009-07-16 06:36:281217void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291218}
1219
[email protected]4873c7d2009-07-16 06:36:281220void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291221}
1222
[email protected]2533ce12009-05-09 00:02:241223void RenderWidget::DoDeferredClose() {
1224 Send(new ViewHostMsg_Close(routing_id_));
1225}
1226
[email protected]4873c7d2009-07-16 06:36:281227void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291228 // If a page calls window.close() twice, we'll end up here twice, but that's
1229 // OK. It is safe to send multiple Close messages.
1230
[email protected]2533ce12009-05-09 00:02:241231 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1232 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1233 // could be closed before the JS finishes executing. So instead, post a
1234 // message back to the message loop, which won't run until the JS is
1235 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211236 MessageLoop::current()->PostTask(
1237 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291238}
1239
1240void RenderWidget::Close() {
1241 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281242 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291243 webwidget_ = NULL;
1244 }
1245}
1246
[email protected]4873c7d2009-07-16 06:36:281247WebRect RenderWidget::windowRect() {
1248 if (pending_window_rect_count_)
1249 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241250
[email protected]b3f2b912009-04-09 16:18:521251 gfx::Rect rect;
1252 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281253 return rect;
initial.commit09911bf2008-07-26 23:55:291254}
1255
[email protected]8a9d6ca32011-06-06 20:11:301256void RenderWidget::setToolTipText(const WebKit::WebString& text,
1257 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541258 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301259}
1260
[email protected]4873c7d2009-07-16 06:36:281261void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291262 if (did_show_) {
1263 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241264 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291265 } else {
1266 initial_pos_ = pos;
1267 }
1268}
1269
[email protected]2533ce12009-05-09 00:02:241270void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1271 pending_window_rect_ = rect;
1272 pending_window_rect_count_++;
1273}
1274
[email protected]4873c7d2009-07-16 06:36:281275WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241276 if (pending_window_rect_count_) {
1277 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1278 // the RootWindowRect is probably going to return wrong results since the
1279 // browser may not have processed the Move yet. There isn't really anything
1280 // good to do in this case, and it shouldn't happen - since this size is
1281 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281282 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241283 }
1284
[email protected]b3f2b912009-04-09 16:18:521285 gfx::Rect rect;
1286 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281287 return rect;
[email protected]d4547452008-08-28 18:36:371288}
1289
[email protected]4873c7d2009-07-16 06:36:281290WebRect RenderWidget::windowResizerRect() {
1291 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191292}
1293
[email protected]fa7b1dc2010-06-23 17:53:041294void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031295 // To prevent this renderer process from sending unnecessary IPC messages to
1296 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041297 // only during the input method attached to the browser process is active.
1298 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291299}
1300
[email protected]fa7b1dc2010-06-23 17:53:041301void RenderWidget::OnImeSetComposition(
1302 const string16& text,
1303 const std::vector<WebCompositionUnderline>& underlines,
1304 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281305 if (!webwidget_)
1306 return;
[email protected]d4cff272011-05-02 15:46:011307 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041308 text, WebVector<WebCompositionUnderline>(underlines),
1309 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011310 // Setting the IME composition was successful. Send the new composition
1311 // range to the browser.
1312 ui::Range range(ui::Range::InvalidRange());
1313 size_t location, length;
1314 if (webwidget_->compositionRange(&location, &length)) {
1315 range.set_start(location);
1316 range.set_end(location + length);
1317 }
1318 // The IME was cancelled via the Esc key, so just send back the caret.
1319 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1320 range.set_start(location);
1321 range.set_end(location + length);
1322 }
1323 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1324 } else {
[email protected]fa7b1dc2010-06-23 17:53:041325 // If we failed to set the composition text, then we need to let the browser
1326 // process to cancel the input method's ongoing composition session, to make
1327 // sure we are in a consistent state.
1328 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011329
1330 // Send an updated IME range with just the caret range.
1331 ui::Range range(ui::Range::InvalidRange());
1332 size_t location, length;
1333 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1334 range.set_start(location);
1335 range.set_end(location + length);
1336 }
1337 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261338 }
[email protected]fa7b1dc2010-06-23 17:53:041339}
1340
[email protected]4de6d1692011-10-12 08:45:441341void RenderWidget::OnImeConfirmComposition(
1342 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041343 if (!webwidget_)
1344 return;
1345
1346 handling_input_event_ = true;
1347 webwidget_->confirmComposition(text);
1348 handling_input_event_ = false;
1349
[email protected]d4cff272011-05-02 15:46:011350 // Send an updated IME range with just the caret range.
1351 ui::Range range(ui::Range::InvalidRange());
1352 size_t location, length;
1353 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1354 range.set_start(location);
1355 range.set_end(location + length);
1356 }
1357 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291358}
1359
[email protected]948f7ab72010-05-28 23:48:081360// This message causes the renderer to render an image of the
1361// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491362void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091363 int tag,
[email protected]948f7ab72010-05-28 23:48:081364 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491365 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001366 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1367 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251368 // Close our unused handle.
1369#if defined(OS_WIN)
1370 ::CloseHandle(dib_handle);
1371#elif defined(OS_MACOSX)
1372 base::SharedMemory::CloseHandle(dib_handle);
1373#endif
1374 }
[email protected]d65adb12010-04-28 17:26:491375 return;
[email protected]45c6aad32010-11-11 04:46:251376 }
[email protected]d65adb12010-04-28 17:26:491377
[email protected]948f7ab72010-05-28 23:48:081378 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491379 // If one of these is empty, then we just return the dib we were
1380 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091381 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491382 return;
1383 }
1384
1385 // Map the given DIB ID into this process, and unmap it at the end
1386 // of this function.
[email protected]45c6aad32010-11-11 04:46:251387 scoped_ptr<TransportDIB> paint_at_size_buffer(
1388 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301389
1390 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491391 float x_scale = static_cast<float>(desired_size.width()) /
1392 static_cast<float>(canvas_size.width());
1393 float y_scale = static_cast<float>(desired_size.height()) /
1394 static_cast<float>(canvas_size.height());
1395
[email protected]ee8d6fd2010-05-26 17:05:481396 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491397 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1398 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481399 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491400
[email protected]36808ad2010-10-20 19:18:301401 scoped_ptr<skia::PlatformCanvas> canvas(
1402 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1403 canvas_size.height()));
1404 if (!canvas.get()) {
1405 NOTREACHED();
1406 return;
1407 }
1408
[email protected]d65adb12010-04-28 17:26:491409 // Reset bounds to what we actually received, but they should be the
1410 // same.
1411 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1412 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1413 bounds.set_width(canvas->getDevice()->width());
1414 bounds.set_height(canvas->getDevice()->height());
1415
1416 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081417 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491418 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1419
[email protected]948f7ab72010-05-28 23:48:081420 // Have to make sure we're laid out at the right size before
1421 // rendering.
1422 gfx::Size old_size = webwidget_->size();
1423 webwidget_->resize(page_size);
1424 webwidget_->layout();
1425
[email protected]d65adb12010-04-28 17:26:491426 // Paint the entire thing (using original bounds, not scaled bounds).
1427 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1428 canvas->restore();
1429
[email protected]948f7ab72010-05-28 23:48:081430 // Return the widget to its previous size.
1431 webwidget_->resize(old_size);
1432
[email protected]c88c9442010-07-19 18:55:091433 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491434}
1435
[email protected]ec7dc112008-08-06 05:30:121436void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1437 // During shutdown we can just ignore this message.
1438 if (!webwidget_)
1439 return;
1440
1441 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561442 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041443 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461444 scheduleComposite();
1445 } else {
1446 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1447 didInvalidateRect(repaint_rect);
1448 }
[email protected]ec7dc112008-08-06 05:30:121449}
1450
[email protected]4873c7d2009-07-16 06:36:281451void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111452 if (!webwidget_)
1453 return;
[email protected]4873c7d2009-07-16 06:36:281454 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111455}
1456
[email protected]4b03e292012-02-13 18:40:071457void RenderWidget::OnInvertWebContent(bool invert) {
1458 if (invert_ == invert)
1459 return;
1460
1461 invert_ = invert;
1462
1463 if (invert_ && !invert_paint_.get()) {
1464 // Gamma-aware color inversion: each source pixel value x is normally
1465 // displayed on a computer monitor with a gamma correction x^gamma,
1466 // where gamma is typically in the range 1.8...2.2. By approximating
1467 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1468 uint8_t table[256];
1469 for (unsigned int i = 0; i < 256; i++) {
1470 double value = i / 255.0;
1471 value = sqrt(1 - (value * value));
1472 table[i] = static_cast<uint8_t>(255 * value);
1473 }
1474
1475 // Create a Skia Paint with this inverting color map.
1476 invert_paint_.reset(new SkPaint());
1477 invert_paint_->setStyle(SkPaint::kFill_Style);
1478 invert_paint_->setColor(SK_ColorBLACK);
1479 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1480 NULL, table, table, table);
1481 invert_paint_->setColorFilter(filter);
1482 filter->unref();
1483 }
1484
1485 OnMsgRepaint(size_);
1486}
1487
[email protected]719b36f2010-12-22 20:36:461488webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151489 const gfx::Rect& paint_bounds,
1490 TransportDIB** dib,
1491 gfx::Rect* location,
1492 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461493 // Bare RenderWidgets don't support optimized plugin painting.
1494 return NULL;
[email protected]ca4847f2010-09-24 05:39:151495}
1496
[email protected]bcaf2272011-02-15 15:29:431497gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521498 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431499 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521500}
1501
[email protected]bee16aab2009-08-26 15:55:031502void RenderWidget::SetHidden(bool hidden) {
1503 if (is_hidden_ == hidden)
1504 return;
1505
1506 // The status has changed. Tell the RenderThread about it.
1507 is_hidden_ = hidden;
1508 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271509 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031510 else
[email protected]380244092011-10-07 17:26:271511 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031512}
1513
[email protected]2b624c562011-10-27 22:58:261514void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261515 if (!webwidget_)
1516 return;
1517
1518 if (is_fullscreen_) {
1519 webwidget_->willExitFullScreen();
1520 } else {
1521 webwidget_->willEnterFullScreen();
1522 }
[email protected]2b624c562011-10-27 22:58:261523}
1524
1525void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261526 if (!webwidget_)
1527 return;
1528
1529 if (is_fullscreen_) {
1530 webwidget_->didEnterFullScreen();
1531 } else {
1532 webwidget_->didExitFullScreen();
1533 }
[email protected]2b624c562011-10-27 22:58:261534}
1535
[email protected]699ab0d2009-04-23 23:19:141536void RenderWidget::SetBackground(const SkBitmap& background) {
1537 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461538
[email protected]699ab0d2009-04-23 23:19:141539 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281540 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141541}
1542
[email protected]674741932009-02-04 23:44:461543bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051544 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461545}
1546
1547bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051548 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461549}
1550
1551void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051552 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461553}
1554
1555void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051556 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461557}
1558
1559void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051560 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461561}
1562
[email protected]e99ef6f2011-10-16 01:13:001563void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041564 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291565 return;
[email protected]fa7b1dc2010-06-23 17:53:041566
[email protected]ad26ef42011-06-17 07:59:451567 ui::TextInputType new_type = GetTextInputType();
1568 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001569 // Only sends text input type and compose inline to the browser process if
1570 // they are changed.
1571 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451572 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041573 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451574 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001575 Send(new ViewHostMsg_TextInputStateChanged(
1576 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291577 }
initial.commit09911bf2008-07-26 23:55:291578}
1579
[email protected]3f783362011-10-21 22:40:501580void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1581 WebRect start_webrect;
1582 WebRect end_webrect;
1583 webwidget_->selectionBounds(start_webrect, end_webrect);
1584 *start = start_webrect;
1585 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321586}
1587
[email protected]e99ef6f2011-10-16 01:13:001588void RenderWidget::UpdateSelectionBounds() {
1589 if (!webwidget_)
1590 return;
1591
[email protected]3f783362011-10-21 22:40:501592 gfx::Rect start_rect;
1593 gfx::Rect end_rect;
1594 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001595 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1596 return;
1597
1598 selection_start_rect_ = start_rect;
1599 selection_end_rect_ = end_rect;
1600 Send(new ViewHostMsg_SelectionBoundsChanged(
1601 routing_id_, selection_start_rect_, selection_end_rect_));
1602}
1603
[email protected]73bf95812011-10-12 11:38:321604// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451605COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1606 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1607COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1608 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1609COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1610 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181611COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1612 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1613COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1614 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1615COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1616 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1617COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1618 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1619COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1620 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451621
1622ui::TextInputType RenderWidget::GetTextInputType() {
1623 if (webwidget_) {
1624 int type = webwidget_->textInputType();
1625 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181626 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451627 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1628 return static_cast<ui::TextInputType>(type);
1629 }
1630 return ui::TEXT_INPUT_TYPE_NONE;
1631}
1632
1633bool RenderWidget::CanComposeInline() {
1634 return true;
[email protected]56ea1a62011-05-30 07:05:571635}
1636
[email protected]4873c7d2009-07-16 06:36:281637WebScreenInfo RenderWidget::screenInfo() {
[email protected]6fd35b72012-03-01 19:46:411638 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281639}
1640
[email protected]fa7b1dc2010-06-23 17:53:041641void RenderWidget::resetInputMethod() {
1642 if (!input_method_is_active_)
1643 return;
1644
1645 // If the last text input type is not None, then we should finish any
1646 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451647 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041648 // If a composition text exists, then we need to let the browser process
1649 // to cancel the input method's ongoing composition session.
1650 if (webwidget_->confirmComposition())
1651 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1652 }
[email protected]d4cff272011-05-02 15:46:011653
1654 // Send an updated IME range with the current caret rect.
1655 ui::Range range(ui::Range::InvalidRange());
1656 size_t location, length;
1657 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1658 range.set_start(location);
1659 range.set_end(location + length);
1660 }
1661 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041662}
1663
[email protected]f103ab72009-09-02 17:10:591664void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501665 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291666 size_t i = 0;
1667 for (; i < plugin_window_moves_.size(); ++i) {
1668 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581669 if (move.rects_valid) {
1670 plugin_window_moves_[i] = move;
1671 } else {
1672 plugin_window_moves_[i].visible = move.visible;
1673 }
initial.commit09911bf2008-07-26 23:55:291674 break;
1675 }
1676 }
1677
1678 if (i == plugin_window_moves_.size())
1679 plugin_window_moves_.push_back(move);
1680}
[email protected]268654772009-08-06 23:02:041681
1682void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1683 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1684 i != plugin_window_moves_.end(); ++i) {
1685 if (i->window == window) {
1686 plugin_window_moves_.erase(i);
1687 break;
1688 }
1689 }
1690}
[email protected]67bfb83f2011-09-22 03:36:371691
1692bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1693 return false;
1694}
[email protected]c3d45532011-10-07 19:20:401695
1696bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1697 return false;
1698}