blob: 3ec18652cd251b0e357bfdcfbc14adda35d7d0e9 [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]d3789ec2012-05-02 20:22:0317#include "content/common/pepper_file_messages.h"
[email protected]992db4c2011-05-12 15:37:1518#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5019#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2920#include "content/public/common/content_switches.h"
[email protected]8704f89b2011-04-15 00:30:0521#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4422#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1923#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1824#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5226#include "third_party/skia/include/core/SkShader.h"
[email protected]4b03e292012-02-13 18:40:0727#include "third_party/skia/include/effects/SkTableColorFilter.h"
[email protected]8bd0fe62011-01-17 06:44:3728#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]e6e90dc2011-12-03 00:01:3729#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
[email protected]a7547fb2012-03-08 04:43:4430#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3731#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
32#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0133#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]e6e90dc2011-12-03 00:01:3734#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]8bd0fe62011-01-17 06:44:3735#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]e6e90dc2011-12-03 00:01:3736#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
37#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
[email protected]1835b9e2012-02-28 13:12:4838#include "ui/gfx/gl/gl_switches.h"
[email protected]08397d52011-02-05 01:53:3839#include "ui/gfx/point.h"
40#include "ui/gfx/size.h"
[email protected]1835b9e2012-02-28 13:12:4841#include "ui/gfx/skia_util.h"
[email protected]b9b751f22011-03-25 14:04:1242#include "ui/gfx/surface/transport_dib.h"
[email protected]8c89e7792009-08-19 21:18:3443#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5044#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4645#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4846
47#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4948#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5249#include "third_party/skia/include/core/SkPixelRef.h"
50#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4851#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4452
[email protected]8bd0fe62011-01-17 06:44:3753#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2954
[email protected]fa7b1dc2010-06-23 17:53:0455using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3056using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2257using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0658using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2859using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4460using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0061using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2862using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5963using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1864using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0165using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5266using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1967using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5268using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2869using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2470using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0471using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1872using WebKit::WebWidget;
[email protected]380244092011-10-07 17:26:2773using content::RenderThread;
[email protected]62cb33cae2009-03-27 23:30:2274
[email protected]d3789ec2012-05-02 20:22:0375namespace {
76
77bool CanSendMessageWhileClosing(const IPC::Message* msg) {
78 // We filter out most IPC messages when closing. However, some are
79 // important for allowing pepper plugins to update their unsaved state
80 // when the renderer removes them.
81 switch (msg->type()) {
82 case PepperFileMsg_OpenFile::ID:
83 case PepperFileMsg_RenameFile::ID:
84 case PepperFileMsg_DeleteFileOrDir::ID:
85 case PepperFileMsg_CreateDir::ID:
86 return true;
87 default:
88 break;
89 }
90 return false;
91}
92
93} // namespace
94
[email protected]6fd35b72012-03-01 19:46:4195RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]14392a52012-05-02 20:28:4496 const WebKit::WebScreenInfo& screen_info,
97 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:2998 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:5699 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11100 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29101 opener_id_(MSG_ROUTING_NONE),
[email protected]659f73f2009-10-13 13:43:42102 host_window_(0),
[email protected]05a980d7a2012-02-07 22:16:42103 host_window_set_(false),
[email protected]b4d08452010-10-05 17:34:35104 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:29105 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06106 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05107 update_reply_pending_(false),
[email protected]65225772011-05-12 21:10:24108 using_asynchronous_swapbuffers_(false),
109 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29110 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29111 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09112 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29113 needs_repainting_on_restore_(false),
114 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49115 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:48116 closing_(false),
[email protected]14392a52012-05-02 20:28:44117 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04118 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45119 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
120 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12121 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48122 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12123 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50124 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21125 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07126 invalidation_task_posted_(false),
[email protected]6fd35b72012-03-01 19:46:41127 screen_info_(screen_info),
[email protected]4b03e292012-02-13 18:40:07128 invert_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05129 if (!swapped_out)
130 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27131 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18132 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
133 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:29134}
135
136RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11137 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21138 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35139 if (current_paint_buf_) {
140 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
141 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29142 }
[email protected]992db4c2011-05-12 15:37:15143 // If we are swapped out, we have released already.
144 if (!is_swapped_out_)
145 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29146}
147
[email protected]484955942010-08-19 16:13:18148// static
[email protected]8085dbc82008-09-26 22:53:44149RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]6fd35b72012-03-01 19:46:41150 WebKit::WebPopupType popup_type,
151 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29152 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41153 scoped_refptr<RenderWidget> widget(
[email protected]14392a52012-05-02 20:28:44154 new RenderWidget(popup_type, screen_info, false));
initial.commit09911bf2008-07-26 23:55:29155 widget->Init(opener_id); // adds reference
156 return widget;
157}
158
[email protected]484955942010-08-19 16:13:18159// static
160WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
161 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03162 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18163 break;
164 case WebKit::WebPopupTypeSelect:
165 case WebKit::WebPopupTypeSuggestion:
166 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44167 case WebKit::WebPopupTypePage:
168 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18169 default:
170 NOTREACHED();
171 }
172 return NULL;
173}
174
initial.commit09911bf2008-07-26 23:55:29175void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18176 DoInit(opener_id,
177 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56178 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
179 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18180}
181
[email protected]484955942010-08-19 16:13:18182void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06183 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18184 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29185 DCHECK(!webwidget_);
186
187 if (opener_id != MSG_ROUTING_NONE)
188 opener_id_ = opener_id;
189
[email protected]484955942010-08-19 16:13:18190 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29191
[email protected]380244092011-10-07 17:26:27192 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29193 if (result) {
[email protected]380244092011-10-07 17:26:27194 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29195 // Take a reference on behalf of the RenderThread. This will be balanced
196 // when we receive ViewMsg_Close.
197 AddRef();
198 } else {
199 DCHECK(false);
200 }
201}
202
203// This is used to complete pending inits and non-pending inits. For non-
204// pending cases, the parent will be the same as the current parent. This
205// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55206void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29207 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29208
209 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42210 host_window_set_ = true;
211
[email protected]f1d5de42012-04-20 01:47:14212#if WEBWIDGET_HAS_SETCOMPOSITORSURFACEREADY
213 if (webwidget_)
214 webwidget_->setCompositorSurfaceReady();
215#endif
[email protected]05a980d7a2012-02-07 22:16:42216 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29217
[email protected]6de74452009-02-25 18:04:59218 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29219}
220
[email protected]992db4c2011-05-12 15:37:15221void RenderWidget::SetSwappedOut(bool is_swapped_out) {
222 // We should only toggle between states.
223 DCHECK(is_swapped_out_ != is_swapped_out);
224 is_swapped_out_ = is_swapped_out;
225
226 // If we are swapping out, we will call ReleaseProcess, allowing the process
227 // to exit if all of its RenderViews are swapped out. We wait until the
228 // WasSwappedOut call to do this, to avoid showing the sad tab.
229 // If we are swapping in, we call AddRefProcess to prevent the process from
230 // exiting.
231 if (!is_swapped_out)
232 RenderProcess::current()->AddRefProcess();
233}
234
[email protected]a95986a82010-12-24 06:19:28235bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
236 bool handled = true;
237 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
238 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
239 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
240 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54241 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28242 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
243 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15244 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28245 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
246 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
247 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
248 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
249 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
250 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
251 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
252 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
253 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
254 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
255 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]4b03e292012-02-13 18:40:07256 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
[email protected]a95986a82010-12-24 06:19:28257 IPC_MESSAGE_UNHANDLED(handled = false)
258 IPC_END_MESSAGE_MAP()
259 return handled;
260}
initial.commit09911bf2008-07-26 23:55:29261
262bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15263 // Don't send any messages after the browser has told us to close, and filter
264 // most outgoing messages while swapped out.
265 if ((is_swapped_out_ &&
266 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]d3789ec2012-05-02 20:22:03267 (closing_ && !CanSendMessageWhileClosing(message))) {
initial.commit09911bf2008-07-26 23:55:29268 delete message;
269 return false;
270 }
271
272 // If given a messsage without a routing ID, then assign our routing ID.
273 if (message->routing_id() == MSG_ROUTING_NONE)
274 message->set_routing_id(routing_id_);
275
[email protected]380244092011-10-07 17:26:27276 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44277}
278
[email protected]61e2b3cc2012-03-02 16:13:34279void RenderWidget::Resize(const gfx::Size& new_size,
280 const gfx::Rect& resizer_rect,
281 bool is_fullscreen,
282 ResizeAck resize_ack) {
283 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
284 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
285 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29286
[email protected]61e2b3cc2012-03-02 16:13:34287 // Ignore this during shutdown.
288 if (!webwidget_)
289 return;
290
291 // Remember the rect where the resize corner will be drawn.
292 resizer_rect_ = resizer_rect;
293
294 // NOTE: We may have entered fullscreen mode without changing our size.
295 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
296 if (fullscreen_change)
297 WillToggleFullscreen();
298 is_fullscreen_ = is_fullscreen;
299
300 if (size_ != new_size) {
301 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34302 needs_repainting_on_restore_ = false;
303
304 size_ = new_size;
305
306 paint_aggregator_.ClearPendingUpdate();
307
308 // When resizing, we want to wait to paint before ACK'ing the resize. This
309 // ensures that we only resize as fast as we can paint. We only need to
310 // send an ACK if we are resized to a non-empty rect.
311 webwidget_->resize(new_size);
312 if (!new_size.IsEmpty()) {
313 if (!is_accelerated_compositing_active_) {
314 // Resize should have caused an invalidation of the entire view.
315 DCHECK(paint_aggregator_.HasPendingUpdate());
316 }
317
318 // Send the Resize_ACK flag once we paint again if requested.
319 if (resize_ack == SEND_RESIZE_ACK)
320 set_next_paint_is_resize_ack();
321 }
[email protected]ff475a322012-03-14 00:05:35322 } else {
323 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34324 }
325
326 if (fullscreen_change)
327 DidToggleFullscreen();
328
329 // If a resize ack is requested and it isn't set-up, then no more resizes will
330 // come in and in general things will go wrong.
331 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
332 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29333}
334
335void RenderWidget::OnClose() {
336 if (closing_)
337 return;
338 closing_ = true;
339
340 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03341 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27342 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03343 SetHidden(false);
344 }
initial.commit09911bf2008-07-26 23:55:29345
initial.commit09911bf2008-07-26 23:55:29346 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25347 // now. Post a task that only gets invoked when there are no nested message
348 // loops.
[email protected]32876ae2011-11-15 22:25:21349 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29350 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25351
352 // Balances the AddRef taken when we called AddRoute.
353 Release();
initial.commit09911bf2008-07-26 23:55:29354}
355
[email protected]61e2b3cc2012-03-02 16:13:34356// Got a response from the browser after the renderer decided to create a new
357// view.
358void RenderWidget::OnCreatingNewAck(
359 gfx::NativeViewId parent) {
360 DCHECK(routing_id_ != MSG_ROUTING_NONE);
361
362 CompleteInit(parent);
363}
364
[email protected]f21c613a2009-02-12 14:46:17365void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09366 const gfx::Rect& resizer_rect,
367 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34368 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29369}
370
[email protected]b5913d72012-02-07 22:26:54371void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
372 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59373 gfx::Rect view_rect(size_);
374
375 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
376 if (!old_damage_rect.IsEmpty())
377 paint_aggregator_.InvalidateRect(old_damage_rect);
378
379 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
380 if (!new_damage_rect.IsEmpty())
381 paint_aggregator_.InvalidateRect(new_damage_rect);
382
[email protected]b5913d72012-02-07 22:26:54383 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59384
[email protected]b5913d72012-02-07 22:26:54385 if (webwidget_)
386 webwidget_->didChangeWindowResizerRect();
387 }
388}
389
initial.commit09911bf2008-07-26 23:55:29390void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31391 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29392 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03393 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29394}
395
396void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31397 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29398 // During shutdown we can just ignore this message.
399 if (!webwidget_)
400 return;
401
402 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03403 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29404
405 if (!needs_repainting && !needs_repainting_on_restore_)
406 return;
407 needs_repainting_on_restore_ = false;
408
[email protected]d65adb12010-04-28 17:26:49409 // Tag the next paint as a restore ack, which is picked up by
410 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29411 set_next_paint_is_restore_ack();
412
413 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56414 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46415 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
416 } else {
417 scheduleComposite();
418 }
initial.commit09911bf2008-07-26 23:55:29419}
420
[email protected]992db4c2011-05-12 15:37:15421void RenderWidget::OnWasSwappedOut() {
422 // If we have been swapped out and no one else is using this process,
423 // it's safe to exit now. If we get swapped back in, we will call
424 // AddRefProcess in SetSwappedOut.
425 if (is_swapped_out_)
426 RenderProcess::current()->ReleaseProcess();
427}
428
[email protected]53d3f302009-12-21 04:42:05429void RenderWidget::OnRequestMoveAck() {
430 DCHECK(pending_window_rect_count_);
431 pending_window_rect_count_--;
432}
433
434void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58435 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21436 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05437 update_reply_pending_ = false;
438
[email protected]b4d08452010-10-05 17:34:35439 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
440 // have no current paint buffer.
441 if (current_paint_buf_) {
442 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
443 current_paint_buf_ = NULL;
444 }
445
[email protected]65225772011-05-12 21:10:24446 // If swapbuffers is still pending, then defer the update until the
447 // swapbuffers occurs.
448 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
449 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
450 return;
451 }
452
[email protected]29ed96a2012-02-04 18:12:16453 // Notify subclasses that software rendering was flushed to the screen.
454 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25455
initial.commit09911bf2008-07-26 23:55:29456 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24457 DoDeferredUpdateAndSendInputAck();
458}
459
[email protected]d0be63772011-12-20 23:18:04460bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24461 return false;
462}
463
[email protected]d0be63772011-12-20 23:18:04464void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24465 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21466 while (!updates_pending_swap_.empty()) {
467 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
468 updates_pending_swap_.pop_front();
469 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
470 // compositing pass, hence doesn't require an UpdateRect message.
471 if (msg)
472 Send(msg);
473 }
[email protected]65225772011-05-12 21:10:24474 num_swapbuffers_complete_pending_ = 0;
475 using_asynchronous_swapbuffers_ = false;
476 // Schedule another frame so the compositor learns about it.
477 scheduleComposite();
478}
479
[email protected]37a6f302011-07-11 23:43:08480void RenderWidget::OnSwapBuffersPosted() {
481 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21482
483 if (using_asynchronous_swapbuffers_) {
484 ViewHostMsg_UpdateRect* msg = NULL;
485 // pending_update_params_ can be NULL if the swap doesn't correspond to an
486 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
487 // message.
488 if (pending_update_params_.get()) {
489 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
490 pending_update_params_.reset();
491 }
492 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08493 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21494 }
[email protected]37a6f302011-07-11 23:43:08495}
496
497void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24498 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16499
500 // Notify subclasses that composited rendering got flushed to the screen.
501 DidFlushPaint();
502
[email protected]65225772011-05-12 21:10:24503 // When compositing deactivates, we reset the swapbuffers pending count. The
504 // swapbuffers acks may still arrive, however.
505 if (num_swapbuffers_complete_pending_ == 0) {
506 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
507 return;
508 }
[email protected]aa4117f2011-12-09 22:19:21509 DCHECK(!updates_pending_swap_.empty());
510 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
511 updates_pending_swap_.pop_front();
512 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
513 // compositing pass, hence doesn't require an UpdateRect message.
514 if (msg)
515 Send(msg);
[email protected]65225772011-05-12 21:10:24516 num_swapbuffers_complete_pending_--;
517
518 // If update reply is still pending, then defer the update until that reply
519 // occurs.
[email protected]d0be63772011-12-20 23:18:04520 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24521 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
522 return;
523 }
524
525 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06526 // when we were previously rendering. However, if an invalidation task is not
527 // posted, there may be software rendering work pending. In that case, don't
528 // early out.
529 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24530 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
531 return;
532 }
533
[email protected]65225772011-05-12 21:10:24534 // Continue painting if necessary...
535 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29536}
537
initial.commit09911bf2008-07-26 23:55:29538void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24539 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56540 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29541
542 const char* data;
543 int data_length;
[email protected]5dd768212009-08-13 23:34:49544 handling_input_event_ = true;
545 if (!message.ReadData(&iter, &data, &data_length)) {
546 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29547 return;
[email protected]5dd768212009-08-13 23:34:49548 }
initial.commit09911bf2008-07-26 23:55:29549
550 const WebInputEvent* input_event =
551 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48552
[email protected]b68a0e52011-12-08 15:11:12553 bool is_keyboard_shortcut = false;
554 // is_keyboard_shortcut flag is only available for RawKeyDown events.
555 if (input_event->type == WebInputEvent::RawKeyDown)
556 message.ReadBool(&iter, &is_keyboard_shortcut);
557
[email protected]67bfb83f2011-09-22 03:36:37558 bool prevent_default = false;
559 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26560 const WebMouseEvent& mouse_event =
561 *static_cast<const WebMouseEvent*>(input_event);
562 TRACE_EVENT2("renderer", "HandleMouseMove",
563 "x", mouse_event.x, "y", mouse_event.y);
564 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37565 }
566
567 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12568 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
569 suppress_next_char_events_ = false;
570 if (!processed && webwidget_)
571 processed = webwidget_->handleInputEvent(*input_event);
572 }
573
574 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
575 // it's not processed by webkit, then we need to suppress the upcoming Char
576 // events.
577 if (!processed && is_keyboard_shortcut)
578 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29579
[email protected]a9fb30aa2011-10-06 06:58:46580 IPC::Message* response =
581 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
582 processed);
[email protected]3391a0772012-03-28 00:32:07583 bool event_type_gets_rate_limited =
584 input_event->type == WebInputEvent::MouseMove ||
585 input_event->type == WebInputEvent::MouseWheel ||
586 WebInputEvent::isTouchEventType(input_event->type);
587 bool is_input_throttled =
588 webwidget_->isInputThrottled() ||
589 paint_aggregator_.HasPendingUpdate();
[email protected]e2824412009-02-27 01:57:05590
[email protected]f8868d72012-04-27 19:13:03591 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24592 // We want to rate limit the input events in this case, so we'll wait for
593 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17594 if (pending_input_event_ack_.get()) {
595 // As two different kinds of events could cause us to postpone an ack
596 // we send it now, if we have one pending. The Browser should never
597 // send us the same kind of event we are delaying the ack for.
598 Send(pending_input_event_ack_.release());
599 }
[email protected]12fbad812009-09-01 18:21:24600 pending_input_event_ack_.reset(response);
601 } else {
602 Send(response);
603 }
604
[email protected]5dd768212009-08-13 23:34:49605 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48606
[email protected]67bfb83f2011-09-22 03:36:37607 if (!prevent_default) {
608 if (WebInputEvent::isKeyboardEventType(input_event->type))
609 DidHandleKeyEvent();
610 if (WebInputEvent::isMouseEventType(input_event->type))
611 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24612 if (WebInputEvent::isTouchEventType(input_event->type))
613 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37614 }
initial.commit09911bf2008-07-26 23:55:29615}
616
617void RenderWidget::OnMouseCaptureLost() {
618 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28619 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29620}
621
622void RenderWidget::OnSetFocus(bool enable) {
623 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33624 if (webwidget_)
625 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29626}
627
628void RenderWidget::ClearFocus() {
629 // We may have got the focus from the browser before this gets processed, in
630 // which case we do not want to unfocus ourself.
631 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28632 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29633}
634
[email protected]2d5d09d52009-06-15 14:29:21635void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00636 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21637 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06638 TRACE_EVENT2("renderer", "PaintRect",
639 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00640 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21641
642 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00643 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
644 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03645
[email protected]4b03e292012-02-13 18:40:07646 if (invert_) {
647 // Draw everything to a temporary bitmap and then apply an
648 // inverting color map to the result. This is balanced by an extra
649 // call to canvas->restore(), below.
650 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48651 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07652 canvas->saveLayer(&bounds, invert_paint_.get());
653 }
654
[email protected]699ab0d2009-04-23 23:19:14655 // If there is a custom background, tile it.
656 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14657 SkPaint paint;
658 SkShader* shader = SkShader::CreateBitmapShader(background_,
659 SkShader::kRepeat_TileMode,
660 SkShader::kRepeat_TileMode);
661 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20662
663 // Use kSrc_Mode to handle background_ transparency properly.
664 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
665
666 // Canvas could contain multiple update rects. Clip to given rect so that
667 // we don't accidentally clear other update rects.
668 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48669 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14670 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20671 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14672 }
673
[email protected]719b36f2010-12-22 20:36:46674 // First see if this rect is a plugin that can paint itself faster.
675 TransportDIB* optimized_dib = NULL;
676 gfx::Rect optimized_copy_rect, optimized_copy_location;
677 webkit::ppapi::PluginInstance* optimized_instance =
678 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
679 &optimized_copy_location,
680 &optimized_copy_rect);
681 if (optimized_instance) {
682 // This plugin can be optimize-painted and we can just ask it to paint
683 // itself. We don't actually need the TransportDIB in this case.
684 //
685 // This is an optimization for PPAPI plugins that know they're on top of
686 // the page content. If this rect is inside such a plugin, we can save some
687 // time and avoid re-rendering the page content which we know will be
688 // covered by the plugin later (this time can be significant, especially
689 // for a playing movie that is invalidating a lot).
690 //
691 // In the plugin movie case, hopefully the similar call to
692 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
693 // painting, because that avoids copying the plugin image to a different
694 // paint rect. Unfortunately, if anything on the page is animating other
695 // than the movie, it break this optimization since the union of the
696 // invalid regions will be larger than the plugin.
697 //
698 // This code optimizes that case, where we can still avoid painting in
699 // WebKit and filling the background (which can be slow) and just painting
700 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
701 // required.
702 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27703 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46704 } else {
705 // Normal painting case.
706 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
707
708 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35709 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46710 }
initial.commit09911bf2008-07-26 23:55:29711
[email protected]4b03e292012-02-13 18:40:07712 if (invert_)
713 canvas->restore();
714
[email protected]4fb66842009-12-04 21:41:00715 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00716 canvas->restore();
717}
718
719void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
720 skia::PlatformCanvas* canvas) {
721 static bool kPaintBorder =
722 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
723 if (!kPaintBorder)
724 return;
725
[email protected]53d3f302009-12-21 04:42:05726 // Cycle through these colors to help distinguish new paint rects.
727 const SkColor colors[] = {
728 SkColorSetARGB(0x3F, 0xFF, 0, 0),
729 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
730 SkColorSetARGB(0x3F, 0, 0, 0xFF),
731 };
732 static int color_selector = 0;
733
[email protected]4fb66842009-12-04 21:41:00734 SkPaint paint;
735 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05736 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00737 paint.setStrokeWidth(1);
738
739 SkIRect irect;
740 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
741 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29742}
743
[email protected]52ccd0ea2011-02-16 01:09:05744void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30745 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30746 if (!animation_update_pending_) {
747 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59748 return;
[email protected]921244e42011-07-20 16:36:30749 }
[email protected]bd37ae252011-06-03 01:28:18750 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59751 // Record when we fired (according to base::Time::Now()) relative to when
752 // we posted the task to quantify how much the base::Time/base::TimeTicks
753 // skew is affecting animations.
754 base::TimeDelta animation_callback_delay = base::Time::Now() -
755 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
756 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
757 animation_callback_delay,
758 base::TimeDelta::FromMilliseconds(0),
759 base::TimeDelta::FromMilliseconds(30),
760 25);
761 }
[email protected]65225772011-05-12 21:10:24762 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24763}
764
[email protected]52ccd0ea2011-02-16 01:09:05765void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59766 if (!animation_update_pending_)
767 return;
[email protected]bd37ae252011-06-03 01:28:18768
769 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33770 base::TimeDelta animationInterval = IsRenderingVSynced() ?
771 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18772
[email protected]7c4329e2011-02-18 22:02:59773 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45774
775 // animation_floor_time_ is the earliest time that we should animate when
776 // using the dead reckoning software scheduler. If we're using swapbuffers
777 // complete callbacks to rate limit, we can ignore this floor.
778 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30779 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33780 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18781 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59782 // running animation callbacks so that if a callback requests another
783 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38784 animation_timer_.Stop();
785 animation_timer_.Start(FROM_HERE, animationInterval, this,
786 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59787 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30788 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59789 return;
[email protected]5f8b1022011-01-21 23:34:50790 }
[email protected]bd37ae252011-06-03 01:28:18791 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38792 if (!animation_timer_.IsRunning()) {
793 // This code uses base::Time::Now() to calculate the floor and next fire
794 // time because javascript's Date object uses base::Time::Now(). The
795 // message loop uses base::TimeTicks, which on windows can have a
796 // different granularity than base::Time.
797 // The upshot of all this is that this function might be called before
798 // base::Time::Now() has advanced past the animation_floor_time_. To
799 // avoid exposing this delay to javascript, we keep posting delayed
800 // tasks until base::Time::Now() has advanced far enough.
801 base::TimeDelta delay = animation_floor_time_ - now;
802 animation_timer_.Start(FROM_HERE, delay, this,
803 &RenderWidget::AnimationCallback);
804 }
[email protected]5f8b1022011-01-21 23:34:50805}
806
[email protected]bd37ae252011-06-03 01:28:18807bool RenderWidget::IsRenderingVSynced() {
808 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
809 // not caught by this check. This will lead to artificially low frame rates
810 // for people who force vsync off at a driver level and expect Chrome to speed
811 // up.
812 return !has_disable_gpu_vsync_switch_;
813}
814
[email protected]65225772011-05-12 21:10:24815void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06816 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24817 invalidation_task_posted_ = false;
818 DoDeferredUpdateAndSendInputAck();
819}
820
821void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05822 DoDeferredUpdate();
823
824 if (pending_input_event_ack_.get())
825 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21826}
827
[email protected]552e6002009-11-19 05:24:57828void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58829 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08830
[email protected]65225772011-05-12 21:10:24831 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29832 return;
[email protected]05a980d7a2012-02-07 22:16:42833
834 if (!host_window_set_) {
835 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
836 return;
837 }
[email protected]aa4117f2011-12-09 22:19:21838 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24839 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
840 return;
841 }
[email protected]9ca84622011-06-02 23:46:39842 if (is_accelerated_compositing_active_ &&
843 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24844 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
845 return;
846 }
initial.commit09911bf2008-07-26 23:55:29847
[email protected]552e6002009-11-19 05:24:57848 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29849 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57850 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29851 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24852 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29853 return;
854 }
855
[email protected]05a980d7a2012-02-07 22:16:42856 if (is_accelerated_compositing_active_)
857 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
858
[email protected]0fb93f52011-05-18 23:13:56859 // Tracking of frame rate jitter
860 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51861 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05862 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50863
[email protected]f98d7e3c2010-09-13 22:30:46864 // Layout may generate more invalidation. It may also enable the
865 // GPU acceleration, so make sure to run layout before we send the
866 // GpuRenderingActivated message.
867 webwidget_->layout();
868
[email protected]dcca3aa92012-02-17 23:03:37869 // The following two can result in further layout and possibly
870 // enable GPU acceleration so they need to be called before any painting
871 // is done.
872 UpdateTextInputState();
873 UpdateSelectionBounds();
874
[email protected]5f8b1022011-01-21 23:34:50875 // Suppress painting if nothing is dirty. This has to be done after updating
876 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24877 if (!paint_aggregator_.HasPendingUpdate()) {
878 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51879 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50880 return;
[email protected]65225772011-05-12 21:10:24881 }
[email protected]5f8b1022011-01-21 23:34:50882
[email protected]872ae5b2011-05-26 20:20:50883 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56884 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04885 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56886 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
887 delay,
888 base::TimeDelta::FromMilliseconds(1),
889 base::TimeDelta::FromMilliseconds(60),
890 30);
[email protected]d0be63772011-12-20 23:18:04891 } else {
[email protected]0fb93f52011-05-18 23:13:56892 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
893 delay,
894 base::TimeDelta::FromMilliseconds(1),
895 base::TimeDelta::FromMilliseconds(60),
896 30);
[email protected]d0be63772011-12-20 23:18:04897 }
[email protected]872ae5b2011-05-26 20:20:50898
899 // Calculate filtered time per frame:
900 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
901 filtered_time_per_frame_ =
902 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56903 }
904 last_do_deferred_update_time_ = frame_begin_ticks;
905
[email protected]552e6002009-11-19 05:24:57906 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29907 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30908 PaintAggregator::PendingUpdate update;
909 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29910
[email protected]53d3f302009-12-21 04:42:05911 gfx::Rect scroll_damage = update.GetScrollDamage();
912 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29913
[email protected]29ed96a2012-02-04 18:12:16914 // Notify derived classes that we're about to initiate a paint.
915 WillInitiatePaint();
916
[email protected]ca4847f2010-09-24 05:39:15917 // A plugin may be able to do an optimized paint. First check this, in which
918 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46919 // This optimization allows PPAPI plugins that declare themselves on top of
920 // the page (like a traditional windowed plugin) to be able to animate (think
921 // movie playing) without repeatedly re-painting the page underneath, or
922 // copying the plugin backing store (since we can send the plugin's backing
923 // store directly to the browser).
924 //
925 // This optimization only works when the entire invalid region is contained
926 // within the plugin. There is a related optimization in PaintRect for the
927 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15928 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15929 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21930 DCHECK(!pending_update_params_.get());
931 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
932 pending_update_params_->dx = update.scroll_delta.x();
933 pending_update_params_->dy = update.scroll_delta.y();
934 pending_update_params_->scroll_rect = update.scroll_rect;
935 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21936 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
937 pending_update_params_->flags = next_paint_flags_;
938 pending_update_params_->scroll_offset = GetScrollOffset();
939 pending_update_params_->needs_ack = true;
940 next_paint_flags_ = 0;
941
[email protected]ca4847f2010-09-24 05:39:15942 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56943 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15944 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
945 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27946 // Only update the part of the plugin that actually changed.
947 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21948 pending_update_params_->bitmap = dib->id();
949 pending_update_params_->bitmap_rect = optimized_copy_location;
950 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56951 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46952 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15953 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35954 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
955 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46956 if (!canvas.get()) {
957 NOTREACHED();
958 return;
959 }
[email protected]cef3362f2009-12-21 17:48:45960
[email protected]f98d7e3c2010-09-13 22:30:46961 // We may get back a smaller canvas than we asked for.
962 // TODO(darin): This seems like it could cause painting problems!
963 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
964 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
965 bounds.set_width(canvas->getDevice()->width());
966 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05967
[email protected]f98d7e3c2010-09-13 22:30:46968 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
969
[email protected]aa4117f2011-12-09 22:19:21970 pending_update_params_->bitmap = current_paint_buf_->id();
971 pending_update_params_->bitmap_rect = bounds;
972
973 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46974 // The scroll damage is just another rectangle to paint and copy.
975 copy_rects.swap(update.paint_rects);
976 if (!scroll_damage.IsEmpty())
977 copy_rects.push_back(scroll_damage);
978
979 for (size_t i = 0; i < copy_rects.size(); ++i)
980 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35981
982 // Software FPS tick for performance tests. The accelerated path traces the
983 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
984 // NOTE: Tests may break if this event is renamed or moved.
985 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46986 } else { // Accelerated compositing path
987 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21988 // If painting is done via the gpu process then we don't set any damage
989 // rects to save the browser process from doing unecessary work.
990 pending_update_params_->bitmap_rect = bounds;
991 pending_update_params_->scroll_rect = gfx::Rect();
992 // We don't need an ack, because we're not sharing a DIB with the browser.
993 // If it needs to (e.g. composited UI), the GPU process does its own ACK
994 // with the browser for the GPU surface.
995 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42996 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46997 }
998
[email protected]936c6f52011-12-13 01:35:26999 // If we're holding a pending input event ACK, send the ACK before sending the
1000 // UpdateReply message so we can receive another input event before the
1001 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1002 // the UpdateRect IPC message handler.
1003 if (pending_input_event_ack_.get())
1004 Send(pending_input_event_ack_.release());
1005
[email protected]aa4117f2011-12-09 22:19:211006 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
1007 // OnSwapBuffersPosted), meaning a message has been added to the
1008 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1009 // the message now.
1010 if (pending_update_params_.get()) {
1011 // sending an ack to browser process that the paint is complete...
1012 update_reply_pending_ = pending_update_params_->needs_ack;
1013 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1014 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341015 }
[email protected]53d3f302009-12-21 04:42:051016
[email protected]29ed96a2012-02-04 18:12:161017 // If we're software rendering then we're done initiating the paint.
1018 if (!is_accelerated_compositing_active_)
1019 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291020}
1021
1022///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461023// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291024
[email protected]4873c7d2009-07-16 06:36:281025void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:571026 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481027 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571028 gfx::Rect damaged_rect = view_rect.Intersect(rect);
1029 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291030 return;
1031
[email protected]552e6002009-11-19 05:24:571032 paint_aggregator_.InvalidateRect(damaged_rect);
1033
1034 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241035 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571036 return;
1037 if (!paint_aggregator_.HasPendingUpdate())
1038 return;
[email protected]aa4117f2011-12-09 22:19:211039 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241040 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1041 return;
1042
1043 // When GPU rendering, combine pending animations and invalidations into
1044 // a single update.
[email protected]816edc62012-03-17 01:27:221045 if (is_accelerated_compositing_active_ &&
1046 animation_update_pending_ &&
1047 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571048 return;
1049
1050 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291051 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1052 // on the call stack.
1053 // 2) Allows us to collect more damage rects before painting to help coalesce
1054 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241055 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211056 MessageLoop::current()->PostTask(
1057 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291058}
1059
[email protected]4873c7d2009-07-16 06:36:281060void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461061 // Drop scrolls on the floor when we are in compositing mode.
1062 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561063 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461064 return;
1065
[email protected]552e6002009-11-19 05:24:571066 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481067 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571068 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1069 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291070 return;
1071
[email protected]552e6002009-11-19 05:24:571072 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1073
1074 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241075 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571076 return;
1077 if (!paint_aggregator_.HasPendingUpdate())
1078 return;
[email protected]aa4117f2011-12-09 22:19:211079 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241080 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1081 return;
1082
1083 // When GPU rendering, combine pending animations and invalidations into
1084 // a single update.
[email protected]816edc62012-03-17 01:27:221085 if (is_accelerated_compositing_active_ &&
1086 animation_update_pending_ &&
1087 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571088 return;
1089
1090 // Perform updating asynchronously. This serves two purposes:
1091 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1092 // on the call stack.
1093 // 2) Allows us to collect more damage rects before painting to help coalesce
1094 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241095 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211096 MessageLoop::current()->PostTask(
1097 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291098}
1099
[email protected]244ac1892011-12-02 17:04:471100void RenderWidget::didAutoResize(const WebSize& new_size) {
1101 size_ = new_size;
1102}
1103
[email protected]91acd1c2012-03-14 08:32:391104void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221105 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1106
[email protected]c63b4d42012-04-26 01:01:071107#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211108 if (!is_accelerated_compositing_active_) {
1109 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1110 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1111 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1112 // going to switch to accelerated compositing, the GPU process may need
1113 // round-trips to the browser's UI thread before finishing the frame,
1114 // causing deadlocks if we delay the UpdateRect until we receive the
1115 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071116 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1117 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211118 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1119 }
[email protected]c63b4d42012-04-26 01:01:071120#endif
[email protected]aa4117f2011-12-09 22:19:211121
[email protected]ea162f92011-10-04 23:08:221122 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421123 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241124 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221125}
1126
1127void RenderWidget::didDeactivateCompositor() {
1128 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1129
1130 is_accelerated_compositing_active_ = false;
1131 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1132 routing_id_, is_accelerated_compositing_active_));
1133
[email protected]ea162f92011-10-04 23:08:221134 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241135 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561136}
1137
[email protected]9cd43a62012-03-26 08:03:561138void RenderWidget::willBeginCompositorFrame() {
1139 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371140
1141 DCHECK(RenderThreadImpl::current()->compositor_thread());
1142
1143 // The following two can result in further layout and possibly
1144 // enable GPU acceleration so they need to be called before any painting
1145 // is done.
1146 UpdateTextInputState();
1147 UpdateSelectionBounds();
1148
[email protected]9cd43a62012-03-26 08:03:561149 WillInitiatePaint();
1150}
1151
[email protected]3391a0772012-03-28 00:32:071152void RenderWidget::didBecomeReadyForAdditionalInput() {
1153 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1154 if (pending_input_event_ack_.get())
1155 Send(pending_input_event_ack_.release());
1156}
1157
[email protected]58264a32011-11-17 23:36:151158void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501159 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351160 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1161 // NOTE: Tests may break if this event is renamed or moved.
1162 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161163 // Notify subclasses that we initiated the paint operation.
1164 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151165}
1166
1167void RenderWidget::didCompleteSwapBuffers() {
[email protected]9cd43a62012-03-26 08:03:561168 DidFlushPaint();
1169
[email protected]aa4117f2011-12-09 22:19:211170 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151171 return;
1172
1173 if (!next_paint_flags_ && !plugin_window_moves_.size())
1174 return;
1175
1176 ViewHostMsg_UpdateRect_Params params;
1177 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151178 params.plugin_window_moves.swap(plugin_window_moves_);
1179 params.flags = next_paint_flags_;
1180 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121181 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151182
1183 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1184 next_paint_flags_ = 0;
1185}
1186
[email protected]f98d7e3c2010-09-13 22:30:461187void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041188 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401189 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041190 } else {
[email protected]c3d45532011-10-07 19:20:401191 // TODO(nduca): replace with something a little less hacky. The reason this
1192 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1193 // contains a lot of host-renderer synchronization logic that is still
1194 // important for the accelerated compositing case. The option of simply
1195 // duplicating all that code is less desirable than "faking out" the
1196 // invalidation path using a magical damage rect.
1197 didInvalidateRect(WebRect(0, 0, 1, 1));
1198 }
[email protected]f98d7e3c2010-09-13 22:30:461199}
1200
[email protected]5f8b1022011-01-21 23:34:501201void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201202 if (animation_update_pending_)
1203 return;
1204
[email protected]921244e42011-07-20 16:36:301205 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201206 animation_update_pending_ = true;
1207 if (!animation_timer_.IsRunning()) {
1208 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1209 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211210 }
[email protected]5f8b1022011-01-21 23:34:501211}
1212
[email protected]4873c7d2009-07-16 06:36:281213void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301214 // TODO(darin): Eliminate this temporary.
1215 WebCursor cursor(cursor_info);
1216
initial.commit09911bf2008-07-26 23:55:291217 // Only send a SetCursor message if we need to make a change.
1218 if (!current_cursor_.IsEqual(cursor)) {
1219 current_cursor_ = cursor;
1220 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1221 }
1222}
1223
1224// We are supposed to get a single call to Show for a newly created RenderWidget
1225// that was created via RenderWidget::CreateWebView. So, we wait until this
1226// point to dispatch the ShowWidget message.
1227//
1228// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281229// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291230//
[email protected]4873c7d2009-07-16 06:36:281231void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291232 DCHECK(!did_show_) << "received extraneous Show call";
1233 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1234 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1235
[email protected]8de12d942010-11-17 20:42:441236 if (did_show_)
1237 return;
1238
1239 did_show_ = true;
1240 // NOTE: initial_pos_ may still have its default values at this point, but
1241 // that's okay. It'll be ignored if as_popup is false, or the browser
1242 // process will impose a default position otherwise.
1243 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1244 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291245}
1246
[email protected]4873c7d2009-07-16 06:36:281247void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291248}
1249
[email protected]4873c7d2009-07-16 06:36:281250void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291251}
1252
[email protected]2533ce12009-05-09 00:02:241253void RenderWidget::DoDeferredClose() {
1254 Send(new ViewHostMsg_Close(routing_id_));
1255}
1256
[email protected]4873c7d2009-07-16 06:36:281257void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291258 // If a page calls window.close() twice, we'll end up here twice, but that's
1259 // OK. It is safe to send multiple Close messages.
1260
[email protected]2533ce12009-05-09 00:02:241261 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1262 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1263 // could be closed before the JS finishes executing. So instead, post a
1264 // message back to the message loop, which won't run until the JS is
1265 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211266 MessageLoop::current()->PostTask(
1267 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291268}
1269
1270void RenderWidget::Close() {
1271 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281272 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291273 webwidget_ = NULL;
1274 }
1275}
1276
[email protected]4873c7d2009-07-16 06:36:281277WebRect RenderWidget::windowRect() {
1278 if (pending_window_rect_count_)
1279 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241280
[email protected]b3f2b912009-04-09 16:18:521281 gfx::Rect rect;
1282 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281283 return rect;
initial.commit09911bf2008-07-26 23:55:291284}
1285
[email protected]8a9d6ca32011-06-06 20:11:301286void RenderWidget::setToolTipText(const WebKit::WebString& text,
1287 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541288 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301289}
1290
[email protected]4873c7d2009-07-16 06:36:281291void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291292 if (did_show_) {
1293 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241294 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291295 } else {
1296 initial_pos_ = pos;
1297 }
1298}
1299
[email protected]2533ce12009-05-09 00:02:241300void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1301 pending_window_rect_ = rect;
1302 pending_window_rect_count_++;
1303}
1304
[email protected]4873c7d2009-07-16 06:36:281305WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241306 if (pending_window_rect_count_) {
1307 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1308 // the RootWindowRect is probably going to return wrong results since the
1309 // browser may not have processed the Move yet. There isn't really anything
1310 // good to do in this case, and it shouldn't happen - since this size is
1311 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281312 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241313 }
1314
[email protected]b3f2b912009-04-09 16:18:521315 gfx::Rect rect;
1316 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281317 return rect;
[email protected]d4547452008-08-28 18:36:371318}
1319
[email protected]4873c7d2009-07-16 06:36:281320WebRect RenderWidget::windowResizerRect() {
1321 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191322}
1323
[email protected]fa7b1dc2010-06-23 17:53:041324void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031325 // To prevent this renderer process from sending unnecessary IPC messages to
1326 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041327 // only during the input method attached to the browser process is active.
1328 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291329}
1330
[email protected]fa7b1dc2010-06-23 17:53:041331void RenderWidget::OnImeSetComposition(
1332 const string16& text,
1333 const std::vector<WebCompositionUnderline>& underlines,
1334 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281335 if (!webwidget_)
1336 return;
[email protected]d4cff272011-05-02 15:46:011337 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041338 text, WebVector<WebCompositionUnderline>(underlines),
1339 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011340 // Setting the IME composition was successful. Send the new composition
1341 // range to the browser.
1342 ui::Range range(ui::Range::InvalidRange());
1343 size_t location, length;
1344 if (webwidget_->compositionRange(&location, &length)) {
1345 range.set_start(location);
1346 range.set_end(location + length);
1347 }
1348 // The IME was cancelled via the Esc key, so just send back the caret.
1349 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1350 range.set_start(location);
1351 range.set_end(location + length);
1352 }
1353 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1354 } else {
[email protected]fa7b1dc2010-06-23 17:53:041355 // If we failed to set the composition text, then we need to let the browser
1356 // process to cancel the input method's ongoing composition session, to make
1357 // sure we are in a consistent state.
1358 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011359
1360 // Send an updated IME range with just the caret range.
1361 ui::Range range(ui::Range::InvalidRange());
1362 size_t location, length;
1363 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1364 range.set_start(location);
1365 range.set_end(location + length);
1366 }
1367 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261368 }
[email protected]fa7b1dc2010-06-23 17:53:041369}
1370
[email protected]4de6d1692011-10-12 08:45:441371void RenderWidget::OnImeConfirmComposition(
1372 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041373 if (!webwidget_)
1374 return;
1375
1376 handling_input_event_ = true;
1377 webwidget_->confirmComposition(text);
1378 handling_input_event_ = false;
1379
[email protected]d4cff272011-05-02 15:46:011380 // Send an updated IME range with just the caret range.
1381 ui::Range range(ui::Range::InvalidRange());
1382 size_t location, length;
1383 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1384 range.set_start(location);
1385 range.set_end(location + length);
1386 }
1387 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291388}
1389
[email protected]948f7ab72010-05-28 23:48:081390// This message causes the renderer to render an image of the
1391// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491392void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091393 int tag,
[email protected]948f7ab72010-05-28 23:48:081394 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491395 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001396 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1397 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251398 // Close our unused handle.
1399#if defined(OS_WIN)
1400 ::CloseHandle(dib_handle);
1401#elif defined(OS_MACOSX)
1402 base::SharedMemory::CloseHandle(dib_handle);
1403#endif
1404 }
[email protected]d65adb12010-04-28 17:26:491405 return;
[email protected]45c6aad32010-11-11 04:46:251406 }
[email protected]d65adb12010-04-28 17:26:491407
[email protected]948f7ab72010-05-28 23:48:081408 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491409 // If one of these is empty, then we just return the dib we were
1410 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091411 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491412 return;
1413 }
1414
1415 // Map the given DIB ID into this process, and unmap it at the end
1416 // of this function.
[email protected]45c6aad32010-11-11 04:46:251417 scoped_ptr<TransportDIB> paint_at_size_buffer(
1418 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301419
1420 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491421 float x_scale = static_cast<float>(desired_size.width()) /
1422 static_cast<float>(canvas_size.width());
1423 float y_scale = static_cast<float>(desired_size.height()) /
1424 static_cast<float>(canvas_size.height());
1425
[email protected]ee8d6fd2010-05-26 17:05:481426 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491427 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1428 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481429 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491430
[email protected]36808ad2010-10-20 19:18:301431 scoped_ptr<skia::PlatformCanvas> canvas(
1432 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1433 canvas_size.height()));
1434 if (!canvas.get()) {
1435 NOTREACHED();
1436 return;
1437 }
1438
[email protected]d65adb12010-04-28 17:26:491439 // Reset bounds to what we actually received, but they should be the
1440 // same.
1441 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1442 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1443 bounds.set_width(canvas->getDevice()->width());
1444 bounds.set_height(canvas->getDevice()->height());
1445
1446 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081447 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491448 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1449
[email protected]948f7ab72010-05-28 23:48:081450 // Have to make sure we're laid out at the right size before
1451 // rendering.
1452 gfx::Size old_size = webwidget_->size();
1453 webwidget_->resize(page_size);
1454 webwidget_->layout();
1455
[email protected]d65adb12010-04-28 17:26:491456 // Paint the entire thing (using original bounds, not scaled bounds).
1457 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1458 canvas->restore();
1459
[email protected]948f7ab72010-05-28 23:48:081460 // Return the widget to its previous size.
1461 webwidget_->resize(old_size);
1462
[email protected]c88c9442010-07-19 18:55:091463 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491464}
1465
[email protected]ec7dc112008-08-06 05:30:121466void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1467 // During shutdown we can just ignore this message.
1468 if (!webwidget_)
1469 return;
1470
1471 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561472 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041473 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461474 scheduleComposite();
1475 } else {
1476 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1477 didInvalidateRect(repaint_rect);
1478 }
[email protected]ec7dc112008-08-06 05:30:121479}
1480
[email protected]4873c7d2009-07-16 06:36:281481void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111482 if (!webwidget_)
1483 return;
[email protected]4873c7d2009-07-16 06:36:281484 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111485}
1486
[email protected]4b03e292012-02-13 18:40:071487void RenderWidget::OnInvertWebContent(bool invert) {
1488 if (invert_ == invert)
1489 return;
1490
1491 invert_ = invert;
1492
1493 if (invert_ && !invert_paint_.get()) {
1494 // Gamma-aware color inversion: each source pixel value x is normally
1495 // displayed on a computer monitor with a gamma correction x^gamma,
1496 // where gamma is typically in the range 1.8...2.2. By approximating
1497 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1498 uint8_t table[256];
1499 for (unsigned int i = 0; i < 256; i++) {
1500 double value = i / 255.0;
1501 value = sqrt(1 - (value * value));
1502 table[i] = static_cast<uint8_t>(255 * value);
1503 }
1504
1505 // Create a Skia Paint with this inverting color map.
1506 invert_paint_.reset(new SkPaint());
1507 invert_paint_->setStyle(SkPaint::kFill_Style);
1508 invert_paint_->setColor(SK_ColorBLACK);
1509 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1510 NULL, table, table, table);
1511 invert_paint_->setColorFilter(filter);
1512 filter->unref();
1513 }
1514
1515 OnMsgRepaint(size_);
1516}
1517
[email protected]719b36f2010-12-22 20:36:461518webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151519 const gfx::Rect& paint_bounds,
1520 TransportDIB** dib,
1521 gfx::Rect* location,
1522 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461523 // Bare RenderWidgets don't support optimized plugin painting.
1524 return NULL;
[email protected]ca4847f2010-09-24 05:39:151525}
1526
[email protected]bcaf2272011-02-15 15:29:431527gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521528 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431529 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521530}
1531
[email protected]bee16aab2009-08-26 15:55:031532void RenderWidget::SetHidden(bool hidden) {
1533 if (is_hidden_ == hidden)
1534 return;
1535
1536 // The status has changed. Tell the RenderThread about it.
1537 is_hidden_ = hidden;
1538 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271539 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031540 else
[email protected]380244092011-10-07 17:26:271541 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031542}
1543
[email protected]2b624c562011-10-27 22:58:261544void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261545 if (!webwidget_)
1546 return;
1547
1548 if (is_fullscreen_) {
1549 webwidget_->willExitFullScreen();
1550 } else {
1551 webwidget_->willEnterFullScreen();
1552 }
[email protected]2b624c562011-10-27 22:58:261553}
1554
1555void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261556 if (!webwidget_)
1557 return;
1558
1559 if (is_fullscreen_) {
1560 webwidget_->didEnterFullScreen();
1561 } else {
1562 webwidget_->didExitFullScreen();
1563 }
[email protected]2b624c562011-10-27 22:58:261564}
1565
[email protected]699ab0d2009-04-23 23:19:141566void RenderWidget::SetBackground(const SkBitmap& background) {
1567 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461568
[email protected]699ab0d2009-04-23 23:19:141569 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281570 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141571}
1572
[email protected]674741932009-02-04 23:44:461573bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051574 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461575}
1576
1577bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051578 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461579}
1580
1581void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051582 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461583}
1584
1585void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051586 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461587}
1588
1589void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051590 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461591}
1592
[email protected]e99ef6f2011-10-16 01:13:001593void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041594 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291595 return;
[email protected]fa7b1dc2010-06-23 17:53:041596
[email protected]ad26ef42011-06-17 07:59:451597 ui::TextInputType new_type = GetTextInputType();
1598 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001599 // Only sends text input type and compose inline to the browser process if
1600 // they are changed.
1601 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451602 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041603 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451604 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001605 Send(new ViewHostMsg_TextInputStateChanged(
1606 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291607 }
initial.commit09911bf2008-07-26 23:55:291608}
1609
[email protected]3f783362011-10-21 22:40:501610void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1611 WebRect start_webrect;
1612 WebRect end_webrect;
1613 webwidget_->selectionBounds(start_webrect, end_webrect);
1614 *start = start_webrect;
1615 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321616}
1617
[email protected]e99ef6f2011-10-16 01:13:001618void RenderWidget::UpdateSelectionBounds() {
1619 if (!webwidget_)
1620 return;
1621
[email protected]3f783362011-10-21 22:40:501622 gfx::Rect start_rect;
1623 gfx::Rect end_rect;
1624 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001625 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1626 return;
1627
1628 selection_start_rect_ = start_rect;
1629 selection_end_rect_ = end_rect;
1630 Send(new ViewHostMsg_SelectionBoundsChanged(
1631 routing_id_, selection_start_rect_, selection_end_rect_));
1632}
1633
[email protected]73bf95812011-10-12 11:38:321634// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451635COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1636 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1637COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1638 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1639COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1640 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181641COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1642 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1643COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1644 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1645COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1646 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1647COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1648 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1649COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1650 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451651
1652ui::TextInputType RenderWidget::GetTextInputType() {
1653 if (webwidget_) {
1654 int type = webwidget_->textInputType();
1655 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181656 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451657 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1658 return static_cast<ui::TextInputType>(type);
1659 }
1660 return ui::TEXT_INPUT_TYPE_NONE;
1661}
1662
1663bool RenderWidget::CanComposeInline() {
1664 return true;
[email protected]56ea1a62011-05-30 07:05:571665}
1666
[email protected]4873c7d2009-07-16 06:36:281667WebScreenInfo RenderWidget::screenInfo() {
[email protected]6fd35b72012-03-01 19:46:411668 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281669}
1670
[email protected]fa7b1dc2010-06-23 17:53:041671void RenderWidget::resetInputMethod() {
1672 if (!input_method_is_active_)
1673 return;
1674
1675 // If the last text input type is not None, then we should finish any
1676 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451677 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041678 // If a composition text exists, then we need to let the browser process
1679 // to cancel the input method's ongoing composition session.
1680 if (webwidget_->confirmComposition())
1681 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1682 }
[email protected]d4cff272011-05-02 15:46:011683
1684 // Send an updated IME range with the current caret rect.
1685 ui::Range range(ui::Range::InvalidRange());
1686 size_t location, length;
1687 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1688 range.set_start(location);
1689 range.set_end(location + length);
1690 }
1691 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041692}
1693
[email protected]f103ab72009-09-02 17:10:591694void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501695 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291696 size_t i = 0;
1697 for (; i < plugin_window_moves_.size(); ++i) {
1698 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581699 if (move.rects_valid) {
1700 plugin_window_moves_[i] = move;
1701 } else {
1702 plugin_window_moves_[i].visible = move.visible;
1703 }
initial.commit09911bf2008-07-26 23:55:291704 break;
1705 }
1706 }
1707
1708 if (i == plugin_window_moves_.size())
1709 plugin_window_moves_.push_back(move);
1710}
[email protected]268654772009-08-06 23:02:041711
1712void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1713 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1714 i != plugin_window_moves_.end(); ++i) {
1715 if (i->window == window) {
1716 plugin_window_moves_.erase(i);
1717 break;
1718 }
1719 }
1720}
[email protected]67bfb83f2011-09-22 03:36:371721
1722bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1723 return false;
1724}
[email protected]c3d45532011-10-07 19:20:401725
1726bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1727 return false;
1728}