blob: eb78d81cef70f34bbd932cc92568655426f4c9f4 [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]8930d472009-02-21 08:05:28129 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27130 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18131 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
132 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:29133}
134
135RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11136 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21137 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35138 if (current_paint_buf_) {
139 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
140 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29141 }
[email protected]992db4c2011-05-12 15:37:15142 // If we are swapped out, we have released already.
143 if (!is_swapped_out_)
144 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29145}
146
[email protected]484955942010-08-19 16:13:18147// static
[email protected]8085dbc82008-09-26 22:53:44148RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]6fd35b72012-03-01 19:46:41149 WebKit::WebPopupType popup_type,
150 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29151 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41152 scoped_refptr<RenderWidget> widget(
[email protected]14392a52012-05-02 20:28:44153 new RenderWidget(popup_type, screen_info, false));
initial.commit09911bf2008-07-26 23:55:29154 widget->Init(opener_id); // adds reference
155 return widget;
156}
157
[email protected]484955942010-08-19 16:13:18158// static
159WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
160 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03161 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18162 break;
163 case WebKit::WebPopupTypeSelect:
164 case WebKit::WebPopupTypeSuggestion:
165 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44166 case WebKit::WebPopupTypePage:
167 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18168 default:
169 NOTREACHED();
170 }
171 return NULL;
172}
173
initial.commit09911bf2008-07-26 23:55:29174void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18175 DoInit(opener_id,
176 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56177 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
178 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18179}
180
[email protected]484955942010-08-19 16:13:18181void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06182 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18183 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29184 DCHECK(!webwidget_);
185
186 if (opener_id != MSG_ROUTING_NONE)
187 opener_id_ = opener_id;
188
[email protected]484955942010-08-19 16:13:18189 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29190
[email protected]380244092011-10-07 17:26:27191 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29192 if (result) {
[email protected]380244092011-10-07 17:26:27193 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29194 // Take a reference on behalf of the RenderThread. This will be balanced
195 // when we receive ViewMsg_Close.
196 AddRef();
197 } else {
198 DCHECK(false);
199 }
200}
201
202// This is used to complete pending inits and non-pending inits. For non-
203// pending cases, the parent will be the same as the current parent. This
204// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55205void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29206 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29207
208 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42209 host_window_set_ = true;
210
[email protected]f1d5de42012-04-20 01:47:14211#if WEBWIDGET_HAS_SETCOMPOSITORSURFACEREADY
212 if (webwidget_)
213 webwidget_->setCompositorSurfaceReady();
214#endif
[email protected]05a980d7a2012-02-07 22:16:42215 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29216
[email protected]6de74452009-02-25 18:04:59217 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29218}
219
[email protected]992db4c2011-05-12 15:37:15220void RenderWidget::SetSwappedOut(bool is_swapped_out) {
221 // We should only toggle between states.
222 DCHECK(is_swapped_out_ != is_swapped_out);
223 is_swapped_out_ = is_swapped_out;
224
225 // If we are swapping out, we will call ReleaseProcess, allowing the process
226 // to exit if all of its RenderViews are swapped out. We wait until the
227 // WasSwappedOut call to do this, to avoid showing the sad tab.
228 // If we are swapping in, we call AddRefProcess to prevent the process from
229 // exiting.
230 if (!is_swapped_out)
231 RenderProcess::current()->AddRefProcess();
232}
233
[email protected]a95986a82010-12-24 06:19:28234bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
235 bool handled = true;
236 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
237 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
238 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
239 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54240 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28241 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
242 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15243 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28244 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
245 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
246 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
247 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
248 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
249 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
250 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
251 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
252 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
253 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
254 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]4b03e292012-02-13 18:40:07255 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
[email protected]a95986a82010-12-24 06:19:28256 IPC_MESSAGE_UNHANDLED(handled = false)
257 IPC_END_MESSAGE_MAP()
258 return handled;
259}
initial.commit09911bf2008-07-26 23:55:29260
261bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15262 // Don't send any messages after the browser has told us to close, and filter
263 // most outgoing messages while swapped out.
264 if ((is_swapped_out_ &&
265 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]d3789ec2012-05-02 20:22:03266 (closing_ && !CanSendMessageWhileClosing(message))) {
initial.commit09911bf2008-07-26 23:55:29267 delete message;
268 return false;
269 }
270
271 // If given a messsage without a routing ID, then assign our routing ID.
272 if (message->routing_id() == MSG_ROUTING_NONE)
273 message->set_routing_id(routing_id_);
274
[email protected]380244092011-10-07 17:26:27275 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44276}
277
[email protected]61e2b3cc2012-03-02 16:13:34278void RenderWidget::Resize(const gfx::Size& new_size,
279 const gfx::Rect& resizer_rect,
280 bool is_fullscreen,
281 ResizeAck resize_ack) {
282 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
283 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
284 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29285
[email protected]61e2b3cc2012-03-02 16:13:34286 // Ignore this during shutdown.
287 if (!webwidget_)
288 return;
289
290 // Remember the rect where the resize corner will be drawn.
291 resizer_rect_ = resizer_rect;
292
293 // NOTE: We may have entered fullscreen mode without changing our size.
294 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
295 if (fullscreen_change)
296 WillToggleFullscreen();
297 is_fullscreen_ = is_fullscreen;
298
299 if (size_ != new_size) {
300 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34301 needs_repainting_on_restore_ = false;
302
303 size_ = new_size;
304
305 paint_aggregator_.ClearPendingUpdate();
306
307 // When resizing, we want to wait to paint before ACK'ing the resize. This
308 // ensures that we only resize as fast as we can paint. We only need to
309 // send an ACK if we are resized to a non-empty rect.
310 webwidget_->resize(new_size);
311 if (!new_size.IsEmpty()) {
312 if (!is_accelerated_compositing_active_) {
313 // Resize should have caused an invalidation of the entire view.
314 DCHECK(paint_aggregator_.HasPendingUpdate());
315 }
316
317 // Send the Resize_ACK flag once we paint again if requested.
318 if (resize_ack == SEND_RESIZE_ACK)
319 set_next_paint_is_resize_ack();
320 }
[email protected]ff475a322012-03-14 00:05:35321 } else {
322 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34323 }
324
325 if (fullscreen_change)
326 DidToggleFullscreen();
327
328 // If a resize ack is requested and it isn't set-up, then no more resizes will
329 // come in and in general things will go wrong.
330 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
331 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29332}
333
334void RenderWidget::OnClose() {
335 if (closing_)
336 return;
337 closing_ = true;
338
339 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03340 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27341 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03342 SetHidden(false);
343 }
initial.commit09911bf2008-07-26 23:55:29344
initial.commit09911bf2008-07-26 23:55:29345 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25346 // now. Post a task that only gets invoked when there are no nested message
347 // loops.
[email protected]32876ae2011-11-15 22:25:21348 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29349 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25350
351 // Balances the AddRef taken when we called AddRoute.
352 Release();
initial.commit09911bf2008-07-26 23:55:29353}
354
[email protected]61e2b3cc2012-03-02 16:13:34355// Got a response from the browser after the renderer decided to create a new
356// view.
357void RenderWidget::OnCreatingNewAck(
358 gfx::NativeViewId parent) {
359 DCHECK(routing_id_ != MSG_ROUTING_NONE);
360
361 CompleteInit(parent);
362}
363
[email protected]f21c613a2009-02-12 14:46:17364void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09365 const gfx::Rect& resizer_rect,
366 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34367 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29368}
369
[email protected]b5913d72012-02-07 22:26:54370void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
371 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59372 gfx::Rect view_rect(size_);
373
374 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
375 if (!old_damage_rect.IsEmpty())
376 paint_aggregator_.InvalidateRect(old_damage_rect);
377
378 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
379 if (!new_damage_rect.IsEmpty())
380 paint_aggregator_.InvalidateRect(new_damage_rect);
381
[email protected]b5913d72012-02-07 22:26:54382 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59383
[email protected]b5913d72012-02-07 22:26:54384 if (webwidget_)
385 webwidget_->didChangeWindowResizerRect();
386 }
387}
388
initial.commit09911bf2008-07-26 23:55:29389void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31390 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29391 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03392 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29393}
394
395void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31396 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29397 // During shutdown we can just ignore this message.
398 if (!webwidget_)
399 return;
400
401 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03402 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29403
404 if (!needs_repainting && !needs_repainting_on_restore_)
405 return;
406 needs_repainting_on_restore_ = false;
407
[email protected]d65adb12010-04-28 17:26:49408 // Tag the next paint as a restore ack, which is picked up by
409 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29410 set_next_paint_is_restore_ack();
411
412 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56413 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46414 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
415 } else {
416 scheduleComposite();
417 }
initial.commit09911bf2008-07-26 23:55:29418}
419
[email protected]992db4c2011-05-12 15:37:15420void RenderWidget::OnWasSwappedOut() {
421 // If we have been swapped out and no one else is using this process,
422 // it's safe to exit now. If we get swapped back in, we will call
423 // AddRefProcess in SetSwappedOut.
424 if (is_swapped_out_)
425 RenderProcess::current()->ReleaseProcess();
426}
427
[email protected]53d3f302009-12-21 04:42:05428void RenderWidget::OnRequestMoveAck() {
429 DCHECK(pending_window_rect_count_);
430 pending_window_rect_count_--;
431}
432
433void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58434 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21435 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05436 update_reply_pending_ = false;
437
[email protected]b4d08452010-10-05 17:34:35438 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
439 // have no current paint buffer.
440 if (current_paint_buf_) {
441 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
442 current_paint_buf_ = NULL;
443 }
444
[email protected]65225772011-05-12 21:10:24445 // If swapbuffers is still pending, then defer the update until the
446 // swapbuffers occurs.
447 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
448 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
449 return;
450 }
451
[email protected]29ed96a2012-02-04 18:12:16452 // Notify subclasses that software rendering was flushed to the screen.
453 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25454
initial.commit09911bf2008-07-26 23:55:29455 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24456 DoDeferredUpdateAndSendInputAck();
457}
458
[email protected]d0be63772011-12-20 23:18:04459bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24460 return false;
461}
462
[email protected]d0be63772011-12-20 23:18:04463void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24464 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21465 while (!updates_pending_swap_.empty()) {
466 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
467 updates_pending_swap_.pop_front();
468 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
469 // compositing pass, hence doesn't require an UpdateRect message.
470 if (msg)
471 Send(msg);
472 }
[email protected]65225772011-05-12 21:10:24473 num_swapbuffers_complete_pending_ = 0;
474 using_asynchronous_swapbuffers_ = false;
475 // Schedule another frame so the compositor learns about it.
476 scheduleComposite();
477}
478
[email protected]37a6f302011-07-11 23:43:08479void RenderWidget::OnSwapBuffersPosted() {
480 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21481
482 if (using_asynchronous_swapbuffers_) {
483 ViewHostMsg_UpdateRect* msg = NULL;
484 // pending_update_params_ can be NULL if the swap doesn't correspond to an
485 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
486 // message.
487 if (pending_update_params_.get()) {
488 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
489 pending_update_params_.reset();
490 }
491 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08492 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21493 }
[email protected]37a6f302011-07-11 23:43:08494}
495
496void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24497 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16498
499 // Notify subclasses that composited rendering got flushed to the screen.
500 DidFlushPaint();
501
[email protected]65225772011-05-12 21:10:24502 // When compositing deactivates, we reset the swapbuffers pending count. The
503 // swapbuffers acks may still arrive, however.
504 if (num_swapbuffers_complete_pending_ == 0) {
505 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
506 return;
507 }
[email protected]aa4117f2011-12-09 22:19:21508 DCHECK(!updates_pending_swap_.empty());
509 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
510 updates_pending_swap_.pop_front();
511 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
512 // compositing pass, hence doesn't require an UpdateRect message.
513 if (msg)
514 Send(msg);
[email protected]65225772011-05-12 21:10:24515 num_swapbuffers_complete_pending_--;
516
517 // If update reply is still pending, then defer the update until that reply
518 // occurs.
[email protected]d0be63772011-12-20 23:18:04519 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24520 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
521 return;
522 }
523
524 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06525 // when we were previously rendering. However, if an invalidation task is not
526 // posted, there may be software rendering work pending. In that case, don't
527 // early out.
528 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24529 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
530 return;
531 }
532
[email protected]65225772011-05-12 21:10:24533 // Continue painting if necessary...
534 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29535}
536
initial.commit09911bf2008-07-26 23:55:29537void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24538 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56539 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29540
541 const char* data;
542 int data_length;
[email protected]5dd768212009-08-13 23:34:49543 handling_input_event_ = true;
544 if (!message.ReadData(&iter, &data, &data_length)) {
545 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29546 return;
[email protected]5dd768212009-08-13 23:34:49547 }
initial.commit09911bf2008-07-26 23:55:29548
549 const WebInputEvent* input_event =
550 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48551
[email protected]b68a0e52011-12-08 15:11:12552 bool is_keyboard_shortcut = false;
553 // is_keyboard_shortcut flag is only available for RawKeyDown events.
554 if (input_event->type == WebInputEvent::RawKeyDown)
555 message.ReadBool(&iter, &is_keyboard_shortcut);
556
[email protected]67bfb83f2011-09-22 03:36:37557 bool prevent_default = false;
558 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26559 const WebMouseEvent& mouse_event =
560 *static_cast<const WebMouseEvent*>(input_event);
561 TRACE_EVENT2("renderer", "HandleMouseMove",
562 "x", mouse_event.x, "y", mouse_event.y);
563 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37564 }
565
566 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12567 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
568 suppress_next_char_events_ = false;
569 if (!processed && webwidget_)
570 processed = webwidget_->handleInputEvent(*input_event);
571 }
572
573 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
574 // it's not processed by webkit, then we need to suppress the upcoming Char
575 // events.
576 if (!processed && is_keyboard_shortcut)
577 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29578
[email protected]a9fb30aa2011-10-06 06:58:46579 IPC::Message* response =
580 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
581 processed);
[email protected]3391a0772012-03-28 00:32:07582 bool event_type_gets_rate_limited =
583 input_event->type == WebInputEvent::MouseMove ||
584 input_event->type == WebInputEvent::MouseWheel ||
585 WebInputEvent::isTouchEventType(input_event->type);
586 bool is_input_throttled =
587 webwidget_->isInputThrottled() ||
588 paint_aggregator_.HasPendingUpdate();
[email protected]e2824412009-02-27 01:57:05589
[email protected]f8868d72012-04-27 19:13:03590 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24591 // We want to rate limit the input events in this case, so we'll wait for
592 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17593 if (pending_input_event_ack_.get()) {
594 // As two different kinds of events could cause us to postpone an ack
595 // we send it now, if we have one pending. The Browser should never
596 // send us the same kind of event we are delaying the ack for.
597 Send(pending_input_event_ack_.release());
598 }
[email protected]12fbad812009-09-01 18:21:24599 pending_input_event_ack_.reset(response);
600 } else {
601 Send(response);
602 }
603
[email protected]5dd768212009-08-13 23:34:49604 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48605
[email protected]67bfb83f2011-09-22 03:36:37606 if (!prevent_default) {
607 if (WebInputEvent::isKeyboardEventType(input_event->type))
608 DidHandleKeyEvent();
609 if (WebInputEvent::isMouseEventType(input_event->type))
610 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24611 if (WebInputEvent::isTouchEventType(input_event->type))
612 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37613 }
initial.commit09911bf2008-07-26 23:55:29614}
615
616void RenderWidget::OnMouseCaptureLost() {
617 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28618 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29619}
620
621void RenderWidget::OnSetFocus(bool enable) {
622 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33623 if (webwidget_)
624 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29625}
626
627void RenderWidget::ClearFocus() {
628 // We may have got the focus from the browser before this gets processed, in
629 // which case we do not want to unfocus ourself.
630 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28631 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29632}
633
[email protected]2d5d09d52009-06-15 14:29:21634void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00635 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21636 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06637 TRACE_EVENT2("renderer", "PaintRect",
638 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00639 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21640
641 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00642 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
643 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03644
[email protected]4b03e292012-02-13 18:40:07645 if (invert_) {
646 // Draw everything to a temporary bitmap and then apply an
647 // inverting color map to the result. This is balanced by an extra
648 // call to canvas->restore(), below.
649 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48650 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07651 canvas->saveLayer(&bounds, invert_paint_.get());
652 }
653
[email protected]699ab0d2009-04-23 23:19:14654 // If there is a custom background, tile it.
655 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14656 SkPaint paint;
657 SkShader* shader = SkShader::CreateBitmapShader(background_,
658 SkShader::kRepeat_TileMode,
659 SkShader::kRepeat_TileMode);
660 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20661
662 // Use kSrc_Mode to handle background_ transparency properly.
663 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
664
665 // Canvas could contain multiple update rects. Clip to given rect so that
666 // we don't accidentally clear other update rects.
667 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48668 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14669 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20670 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14671 }
672
[email protected]719b36f2010-12-22 20:36:46673 // First see if this rect is a plugin that can paint itself faster.
674 TransportDIB* optimized_dib = NULL;
675 gfx::Rect optimized_copy_rect, optimized_copy_location;
676 webkit::ppapi::PluginInstance* optimized_instance =
677 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
678 &optimized_copy_location,
679 &optimized_copy_rect);
680 if (optimized_instance) {
681 // This plugin can be optimize-painted and we can just ask it to paint
682 // itself. We don't actually need the TransportDIB in this case.
683 //
684 // This is an optimization for PPAPI plugins that know they're on top of
685 // the page content. If this rect is inside such a plugin, we can save some
686 // time and avoid re-rendering the page content which we know will be
687 // covered by the plugin later (this time can be significant, especially
688 // for a playing movie that is invalidating a lot).
689 //
690 // In the plugin movie case, hopefully the similar call to
691 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
692 // painting, because that avoids copying the plugin image to a different
693 // paint rect. Unfortunately, if anything on the page is animating other
694 // than the movie, it break this optimization since the union of the
695 // invalid regions will be larger than the plugin.
696 //
697 // This code optimizes that case, where we can still avoid painting in
698 // WebKit and filling the background (which can be slow) and just painting
699 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
700 // required.
701 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27702 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46703 } else {
704 // Normal painting case.
705 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
706
707 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35708 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46709 }
initial.commit09911bf2008-07-26 23:55:29710
[email protected]4b03e292012-02-13 18:40:07711 if (invert_)
712 canvas->restore();
713
[email protected]4fb66842009-12-04 21:41:00714 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00715 canvas->restore();
716}
717
718void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
719 skia::PlatformCanvas* canvas) {
720 static bool kPaintBorder =
721 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
722 if (!kPaintBorder)
723 return;
724
[email protected]53d3f302009-12-21 04:42:05725 // Cycle through these colors to help distinguish new paint rects.
726 const SkColor colors[] = {
727 SkColorSetARGB(0x3F, 0xFF, 0, 0),
728 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
729 SkColorSetARGB(0x3F, 0, 0, 0xFF),
730 };
731 static int color_selector = 0;
732
[email protected]4fb66842009-12-04 21:41:00733 SkPaint paint;
734 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05735 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00736 paint.setStrokeWidth(1);
737
738 SkIRect irect;
739 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
740 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29741}
742
[email protected]52ccd0ea2011-02-16 01:09:05743void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30744 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30745 if (!animation_update_pending_) {
746 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59747 return;
[email protected]921244e42011-07-20 16:36:30748 }
[email protected]bd37ae252011-06-03 01:28:18749 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59750 // Record when we fired (according to base::Time::Now()) relative to when
751 // we posted the task to quantify how much the base::Time/base::TimeTicks
752 // skew is affecting animations.
753 base::TimeDelta animation_callback_delay = base::Time::Now() -
754 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
755 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
756 animation_callback_delay,
757 base::TimeDelta::FromMilliseconds(0),
758 base::TimeDelta::FromMilliseconds(30),
759 25);
760 }
[email protected]65225772011-05-12 21:10:24761 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24762}
763
[email protected]52ccd0ea2011-02-16 01:09:05764void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59765 if (!animation_update_pending_)
766 return;
[email protected]bd37ae252011-06-03 01:28:18767
768 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33769 base::TimeDelta animationInterval = IsRenderingVSynced() ?
770 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18771
[email protected]7c4329e2011-02-18 22:02:59772 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45773
774 // animation_floor_time_ is the earliest time that we should animate when
775 // using the dead reckoning software scheduler. If we're using swapbuffers
776 // complete callbacks to rate limit, we can ignore this floor.
777 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30778 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33779 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18780 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59781 // running animation callbacks so that if a callback requests another
782 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38783 animation_timer_.Stop();
784 animation_timer_.Start(FROM_HERE, animationInterval, this,
785 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59786 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30787 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59788 return;
[email protected]5f8b1022011-01-21 23:34:50789 }
[email protected]bd37ae252011-06-03 01:28:18790 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38791 if (!animation_timer_.IsRunning()) {
792 // This code uses base::Time::Now() to calculate the floor and next fire
793 // time because javascript's Date object uses base::Time::Now(). The
794 // message loop uses base::TimeTicks, which on windows can have a
795 // different granularity than base::Time.
796 // The upshot of all this is that this function might be called before
797 // base::Time::Now() has advanced past the animation_floor_time_. To
798 // avoid exposing this delay to javascript, we keep posting delayed
799 // tasks until base::Time::Now() has advanced far enough.
800 base::TimeDelta delay = animation_floor_time_ - now;
801 animation_timer_.Start(FROM_HERE, delay, this,
802 &RenderWidget::AnimationCallback);
803 }
[email protected]5f8b1022011-01-21 23:34:50804}
805
[email protected]bd37ae252011-06-03 01:28:18806bool RenderWidget::IsRenderingVSynced() {
807 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
808 // not caught by this check. This will lead to artificially low frame rates
809 // for people who force vsync off at a driver level and expect Chrome to speed
810 // up.
811 return !has_disable_gpu_vsync_switch_;
812}
813
[email protected]65225772011-05-12 21:10:24814void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06815 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24816 invalidation_task_posted_ = false;
817 DoDeferredUpdateAndSendInputAck();
818}
819
820void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05821 DoDeferredUpdate();
822
823 if (pending_input_event_ack_.get())
824 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21825}
826
[email protected]552e6002009-11-19 05:24:57827void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58828 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08829
[email protected]65225772011-05-12 21:10:24830 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29831 return;
[email protected]05a980d7a2012-02-07 22:16:42832
833 if (!host_window_set_) {
834 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
835 return;
836 }
[email protected]aa4117f2011-12-09 22:19:21837 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24838 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
839 return;
840 }
[email protected]9ca84622011-06-02 23:46:39841 if (is_accelerated_compositing_active_ &&
842 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24843 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
844 return;
845 }
initial.commit09911bf2008-07-26 23:55:29846
[email protected]552e6002009-11-19 05:24:57847 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29848 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57849 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29850 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24851 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29852 return;
853 }
854
[email protected]05a980d7a2012-02-07 22:16:42855 if (is_accelerated_compositing_active_)
856 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
857
[email protected]0fb93f52011-05-18 23:13:56858 // Tracking of frame rate jitter
859 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51860 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05861 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50862
[email protected]f98d7e3c2010-09-13 22:30:46863 // Layout may generate more invalidation. It may also enable the
864 // GPU acceleration, so make sure to run layout before we send the
865 // GpuRenderingActivated message.
866 webwidget_->layout();
867
[email protected]dcca3aa92012-02-17 23:03:37868 // The following two can result in further layout and possibly
869 // enable GPU acceleration so they need to be called before any painting
870 // is done.
871 UpdateTextInputState();
872 UpdateSelectionBounds();
873
[email protected]5f8b1022011-01-21 23:34:50874 // Suppress painting if nothing is dirty. This has to be done after updating
875 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24876 if (!paint_aggregator_.HasPendingUpdate()) {
877 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51878 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50879 return;
[email protected]65225772011-05-12 21:10:24880 }
[email protected]5f8b1022011-01-21 23:34:50881
[email protected]872ae5b2011-05-26 20:20:50882 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56883 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04884 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56885 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
886 delay,
887 base::TimeDelta::FromMilliseconds(1),
888 base::TimeDelta::FromMilliseconds(60),
889 30);
[email protected]d0be63772011-12-20 23:18:04890 } else {
[email protected]0fb93f52011-05-18 23:13:56891 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
892 delay,
893 base::TimeDelta::FromMilliseconds(1),
894 base::TimeDelta::FromMilliseconds(60),
895 30);
[email protected]d0be63772011-12-20 23:18:04896 }
[email protected]872ae5b2011-05-26 20:20:50897
898 // Calculate filtered time per frame:
899 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
900 filtered_time_per_frame_ =
901 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56902 }
903 last_do_deferred_update_time_ = frame_begin_ticks;
904
[email protected]552e6002009-11-19 05:24:57905 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29906 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30907 PaintAggregator::PendingUpdate update;
908 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29909
[email protected]53d3f302009-12-21 04:42:05910 gfx::Rect scroll_damage = update.GetScrollDamage();
911 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29912
[email protected]29ed96a2012-02-04 18:12:16913 // Notify derived classes that we're about to initiate a paint.
914 WillInitiatePaint();
915
[email protected]ca4847f2010-09-24 05:39:15916 // A plugin may be able to do an optimized paint. First check this, in which
917 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46918 // This optimization allows PPAPI plugins that declare themselves on top of
919 // the page (like a traditional windowed plugin) to be able to animate (think
920 // movie playing) without repeatedly re-painting the page underneath, or
921 // copying the plugin backing store (since we can send the plugin's backing
922 // store directly to the browser).
923 //
924 // This optimization only works when the entire invalid region is contained
925 // within the plugin. There is a related optimization in PaintRect for the
926 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15927 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15928 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21929 DCHECK(!pending_update_params_.get());
930 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
931 pending_update_params_->dx = update.scroll_delta.x();
932 pending_update_params_->dy = update.scroll_delta.y();
933 pending_update_params_->scroll_rect = update.scroll_rect;
934 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21935 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
936 pending_update_params_->flags = next_paint_flags_;
937 pending_update_params_->scroll_offset = GetScrollOffset();
938 pending_update_params_->needs_ack = true;
939 next_paint_flags_ = 0;
940
[email protected]ca4847f2010-09-24 05:39:15941 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56942 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15943 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
944 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27945 // Only update the part of the plugin that actually changed.
946 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21947 pending_update_params_->bitmap = dib->id();
948 pending_update_params_->bitmap_rect = optimized_copy_location;
949 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56950 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46951 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15952 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35953 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
954 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46955 if (!canvas.get()) {
956 NOTREACHED();
957 return;
958 }
[email protected]cef3362f2009-12-21 17:48:45959
[email protected]f98d7e3c2010-09-13 22:30:46960 // We may get back a smaller canvas than we asked for.
961 // TODO(darin): This seems like it could cause painting problems!
962 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
963 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
964 bounds.set_width(canvas->getDevice()->width());
965 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05966
[email protected]f98d7e3c2010-09-13 22:30:46967 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
968
[email protected]aa4117f2011-12-09 22:19:21969 pending_update_params_->bitmap = current_paint_buf_->id();
970 pending_update_params_->bitmap_rect = bounds;
971
972 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46973 // The scroll damage is just another rectangle to paint and copy.
974 copy_rects.swap(update.paint_rects);
975 if (!scroll_damage.IsEmpty())
976 copy_rects.push_back(scroll_damage);
977
978 for (size_t i = 0; i < copy_rects.size(); ++i)
979 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35980
981 // Software FPS tick for performance tests. The accelerated path traces the
982 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
983 // NOTE: Tests may break if this event is renamed or moved.
984 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46985 } else { // Accelerated compositing path
986 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21987 // If painting is done via the gpu process then we don't set any damage
988 // rects to save the browser process from doing unecessary work.
989 pending_update_params_->bitmap_rect = bounds;
990 pending_update_params_->scroll_rect = gfx::Rect();
991 // We don't need an ack, because we're not sharing a DIB with the browser.
992 // If it needs to (e.g. composited UI), the GPU process does its own ACK
993 // with the browser for the GPU surface.
994 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42995 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46996 }
997
[email protected]936c6f52011-12-13 01:35:26998 // If we're holding a pending input event ACK, send the ACK before sending the
999 // UpdateReply message so we can receive another input event before the
1000 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1001 // the UpdateRect IPC message handler.
1002 if (pending_input_event_ack_.get())
1003 Send(pending_input_event_ack_.release());
1004
[email protected]aa4117f2011-12-09 22:19:211005 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
1006 // OnSwapBuffersPosted), meaning a message has been added to the
1007 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1008 // the message now.
1009 if (pending_update_params_.get()) {
1010 // sending an ack to browser process that the paint is complete...
1011 update_reply_pending_ = pending_update_params_->needs_ack;
1012 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1013 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341014 }
[email protected]53d3f302009-12-21 04:42:051015
[email protected]29ed96a2012-02-04 18:12:161016 // If we're software rendering then we're done initiating the paint.
1017 if (!is_accelerated_compositing_active_)
1018 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291019}
1020
1021///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461022// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291023
[email protected]4873c7d2009-07-16 06:36:281024void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:571025 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481026 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571027 gfx::Rect damaged_rect = view_rect.Intersect(rect);
1028 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291029 return;
1030
[email protected]552e6002009-11-19 05:24:571031 paint_aggregator_.InvalidateRect(damaged_rect);
1032
1033 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241034 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571035 return;
1036 if (!paint_aggregator_.HasPendingUpdate())
1037 return;
[email protected]aa4117f2011-12-09 22:19:211038 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241039 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1040 return;
1041
1042 // When GPU rendering, combine pending animations and invalidations into
1043 // a single update.
[email protected]816edc62012-03-17 01:27:221044 if (is_accelerated_compositing_active_ &&
1045 animation_update_pending_ &&
1046 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571047 return;
1048
1049 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291050 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1051 // on the call stack.
1052 // 2) Allows us to collect more damage rects before painting to help coalesce
1053 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241054 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211055 MessageLoop::current()->PostTask(
1056 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291057}
1058
[email protected]4873c7d2009-07-16 06:36:281059void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461060 // Drop scrolls on the floor when we are in compositing mode.
1061 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561062 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461063 return;
1064
[email protected]552e6002009-11-19 05:24:571065 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481066 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571067 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1068 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291069 return;
1070
[email protected]552e6002009-11-19 05:24:571071 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1072
1073 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241074 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571075 return;
1076 if (!paint_aggregator_.HasPendingUpdate())
1077 return;
[email protected]aa4117f2011-12-09 22:19:211078 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241079 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1080 return;
1081
1082 // When GPU rendering, combine pending animations and invalidations into
1083 // a single update.
[email protected]816edc62012-03-17 01:27:221084 if (is_accelerated_compositing_active_ &&
1085 animation_update_pending_ &&
1086 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571087 return;
1088
1089 // Perform updating asynchronously. This serves two purposes:
1090 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1091 // on the call stack.
1092 // 2) Allows us to collect more damage rects before painting to help coalesce
1093 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241094 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211095 MessageLoop::current()->PostTask(
1096 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291097}
1098
[email protected]244ac1892011-12-02 17:04:471099void RenderWidget::didAutoResize(const WebSize& new_size) {
1100 size_ = new_size;
1101}
1102
[email protected]91acd1c2012-03-14 08:32:391103void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221104 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1105
[email protected]c63b4d42012-04-26 01:01:071106#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211107 if (!is_accelerated_compositing_active_) {
1108 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1109 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1110 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1111 // going to switch to accelerated compositing, the GPU process may need
1112 // round-trips to the browser's UI thread before finishing the frame,
1113 // causing deadlocks if we delay the UpdateRect until we receive the
1114 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071115 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1116 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211117 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1118 }
[email protected]c63b4d42012-04-26 01:01:071119#endif
[email protected]aa4117f2011-12-09 22:19:211120
[email protected]ea162f92011-10-04 23:08:221121 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421122 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241123 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221124}
1125
1126void RenderWidget::didDeactivateCompositor() {
1127 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1128
1129 is_accelerated_compositing_active_ = false;
1130 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1131 routing_id_, is_accelerated_compositing_active_));
1132
[email protected]ea162f92011-10-04 23:08:221133 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241134 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561135}
1136
[email protected]9cd43a62012-03-26 08:03:561137void RenderWidget::willBeginCompositorFrame() {
1138 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371139
1140 DCHECK(RenderThreadImpl::current()->compositor_thread());
1141
1142 // The following two can result in further layout and possibly
1143 // enable GPU acceleration so they need to be called before any painting
1144 // is done.
1145 UpdateTextInputState();
1146 UpdateSelectionBounds();
1147
[email protected]9cd43a62012-03-26 08:03:561148 WillInitiatePaint();
1149}
1150
[email protected]3391a0772012-03-28 00:32:071151void RenderWidget::didBecomeReadyForAdditionalInput() {
1152 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1153 if (pending_input_event_ack_.get())
1154 Send(pending_input_event_ack_.release());
1155}
1156
[email protected]58264a32011-11-17 23:36:151157void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501158 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351159 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1160 // NOTE: Tests may break if this event is renamed or moved.
1161 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161162 // Notify subclasses that we initiated the paint operation.
1163 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151164}
1165
1166void RenderWidget::didCompleteSwapBuffers() {
[email protected]9cd43a62012-03-26 08:03:561167 DidFlushPaint();
1168
[email protected]aa4117f2011-12-09 22:19:211169 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151170 return;
1171
1172 if (!next_paint_flags_ && !plugin_window_moves_.size())
1173 return;
1174
1175 ViewHostMsg_UpdateRect_Params params;
1176 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151177 params.plugin_window_moves.swap(plugin_window_moves_);
1178 params.flags = next_paint_flags_;
1179 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121180 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151181
1182 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1183 next_paint_flags_ = 0;
1184}
1185
[email protected]f98d7e3c2010-09-13 22:30:461186void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041187 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401188 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041189 } else {
[email protected]c3d45532011-10-07 19:20:401190 // TODO(nduca): replace with something a little less hacky. The reason this
1191 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1192 // contains a lot of host-renderer synchronization logic that is still
1193 // important for the accelerated compositing case. The option of simply
1194 // duplicating all that code is less desirable than "faking out" the
1195 // invalidation path using a magical damage rect.
1196 didInvalidateRect(WebRect(0, 0, 1, 1));
1197 }
[email protected]f98d7e3c2010-09-13 22:30:461198}
1199
[email protected]5f8b1022011-01-21 23:34:501200void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201201 if (animation_update_pending_)
1202 return;
1203
[email protected]921244e42011-07-20 16:36:301204 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201205 animation_update_pending_ = true;
1206 if (!animation_timer_.IsRunning()) {
1207 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1208 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211209 }
[email protected]5f8b1022011-01-21 23:34:501210}
1211
[email protected]4873c7d2009-07-16 06:36:281212void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301213 // TODO(darin): Eliminate this temporary.
1214 WebCursor cursor(cursor_info);
1215
initial.commit09911bf2008-07-26 23:55:291216 // Only send a SetCursor message if we need to make a change.
1217 if (!current_cursor_.IsEqual(cursor)) {
1218 current_cursor_ = cursor;
1219 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1220 }
1221}
1222
1223// We are supposed to get a single call to Show for a newly created RenderWidget
1224// that was created via RenderWidget::CreateWebView. So, we wait until this
1225// point to dispatch the ShowWidget message.
1226//
1227// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281228// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291229//
[email protected]4873c7d2009-07-16 06:36:281230void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291231 DCHECK(!did_show_) << "received extraneous Show call";
1232 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1233 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1234
[email protected]8de12d942010-11-17 20:42:441235 if (did_show_)
1236 return;
1237
1238 did_show_ = true;
1239 // NOTE: initial_pos_ may still have its default values at this point, but
1240 // that's okay. It'll be ignored if as_popup is false, or the browser
1241 // process will impose a default position otherwise.
1242 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1243 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291244}
1245
[email protected]4873c7d2009-07-16 06:36:281246void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291247}
1248
[email protected]4873c7d2009-07-16 06:36:281249void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291250}
1251
[email protected]2533ce12009-05-09 00:02:241252void RenderWidget::DoDeferredClose() {
1253 Send(new ViewHostMsg_Close(routing_id_));
1254}
1255
[email protected]4873c7d2009-07-16 06:36:281256void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291257 // If a page calls window.close() twice, we'll end up here twice, but that's
1258 // OK. It is safe to send multiple Close messages.
1259
[email protected]2533ce12009-05-09 00:02:241260 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1261 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1262 // could be closed before the JS finishes executing. So instead, post a
1263 // message back to the message loop, which won't run until the JS is
1264 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211265 MessageLoop::current()->PostTask(
1266 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291267}
1268
1269void RenderWidget::Close() {
1270 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281271 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291272 webwidget_ = NULL;
1273 }
1274}
1275
[email protected]4873c7d2009-07-16 06:36:281276WebRect RenderWidget::windowRect() {
1277 if (pending_window_rect_count_)
1278 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241279
[email protected]b3f2b912009-04-09 16:18:521280 gfx::Rect rect;
1281 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281282 return rect;
initial.commit09911bf2008-07-26 23:55:291283}
1284
[email protected]8a9d6ca32011-06-06 20:11:301285void RenderWidget::setToolTipText(const WebKit::WebString& text,
1286 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541287 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301288}
1289
[email protected]4873c7d2009-07-16 06:36:281290void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291291 if (did_show_) {
1292 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241293 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291294 } else {
1295 initial_pos_ = pos;
1296 }
1297}
1298
[email protected]2533ce12009-05-09 00:02:241299void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1300 pending_window_rect_ = rect;
1301 pending_window_rect_count_++;
1302}
1303
[email protected]4873c7d2009-07-16 06:36:281304WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241305 if (pending_window_rect_count_) {
1306 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1307 // the RootWindowRect is probably going to return wrong results since the
1308 // browser may not have processed the Move yet. There isn't really anything
1309 // good to do in this case, and it shouldn't happen - since this size is
1310 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281311 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241312 }
1313
[email protected]b3f2b912009-04-09 16:18:521314 gfx::Rect rect;
1315 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281316 return rect;
[email protected]d4547452008-08-28 18:36:371317}
1318
[email protected]4873c7d2009-07-16 06:36:281319WebRect RenderWidget::windowResizerRect() {
1320 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191321}
1322
[email protected]fa7b1dc2010-06-23 17:53:041323void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031324 // To prevent this renderer process from sending unnecessary IPC messages to
1325 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041326 // only during the input method attached to the browser process is active.
1327 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291328}
1329
[email protected]fa7b1dc2010-06-23 17:53:041330void RenderWidget::OnImeSetComposition(
1331 const string16& text,
1332 const std::vector<WebCompositionUnderline>& underlines,
1333 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281334 if (!webwidget_)
1335 return;
[email protected]d4cff272011-05-02 15:46:011336 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041337 text, WebVector<WebCompositionUnderline>(underlines),
1338 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011339 // Setting the IME composition was successful. Send the new composition
1340 // range to the browser.
1341 ui::Range range(ui::Range::InvalidRange());
1342 size_t location, length;
1343 if (webwidget_->compositionRange(&location, &length)) {
1344 range.set_start(location);
1345 range.set_end(location + length);
1346 }
1347 // The IME was cancelled via the Esc key, so just send back the caret.
1348 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1349 range.set_start(location);
1350 range.set_end(location + length);
1351 }
1352 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1353 } else {
[email protected]fa7b1dc2010-06-23 17:53:041354 // If we failed to set the composition text, then we need to let the browser
1355 // process to cancel the input method's ongoing composition session, to make
1356 // sure we are in a consistent state.
1357 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011358
1359 // Send an updated IME range with just the caret range.
1360 ui::Range range(ui::Range::InvalidRange());
1361 size_t location, length;
1362 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1363 range.set_start(location);
1364 range.set_end(location + length);
1365 }
1366 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261367 }
[email protected]fa7b1dc2010-06-23 17:53:041368}
1369
[email protected]4de6d1692011-10-12 08:45:441370void RenderWidget::OnImeConfirmComposition(
1371 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041372 if (!webwidget_)
1373 return;
1374
1375 handling_input_event_ = true;
1376 webwidget_->confirmComposition(text);
1377 handling_input_event_ = false;
1378
[email protected]d4cff272011-05-02 15:46:011379 // Send an updated IME range with just the caret range.
1380 ui::Range range(ui::Range::InvalidRange());
1381 size_t location, length;
1382 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1383 range.set_start(location);
1384 range.set_end(location + length);
1385 }
1386 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291387}
1388
[email protected]948f7ab72010-05-28 23:48:081389// This message causes the renderer to render an image of the
1390// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491391void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091392 int tag,
[email protected]948f7ab72010-05-28 23:48:081393 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491394 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001395 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1396 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251397 // Close our unused handle.
1398#if defined(OS_WIN)
1399 ::CloseHandle(dib_handle);
1400#elif defined(OS_MACOSX)
1401 base::SharedMemory::CloseHandle(dib_handle);
1402#endif
1403 }
[email protected]d65adb12010-04-28 17:26:491404 return;
[email protected]45c6aad32010-11-11 04:46:251405 }
[email protected]d65adb12010-04-28 17:26:491406
[email protected]948f7ab72010-05-28 23:48:081407 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491408 // If one of these is empty, then we just return the dib we were
1409 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091410 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491411 return;
1412 }
1413
1414 // Map the given DIB ID into this process, and unmap it at the end
1415 // of this function.
[email protected]45c6aad32010-11-11 04:46:251416 scoped_ptr<TransportDIB> paint_at_size_buffer(
1417 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301418
1419 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491420 float x_scale = static_cast<float>(desired_size.width()) /
1421 static_cast<float>(canvas_size.width());
1422 float y_scale = static_cast<float>(desired_size.height()) /
1423 static_cast<float>(canvas_size.height());
1424
[email protected]ee8d6fd2010-05-26 17:05:481425 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491426 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1427 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481428 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491429
[email protected]36808ad2010-10-20 19:18:301430 scoped_ptr<skia::PlatformCanvas> canvas(
1431 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1432 canvas_size.height()));
1433 if (!canvas.get()) {
1434 NOTREACHED();
1435 return;
1436 }
1437
[email protected]d65adb12010-04-28 17:26:491438 // Reset bounds to what we actually received, but they should be the
1439 // same.
1440 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1441 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1442 bounds.set_width(canvas->getDevice()->width());
1443 bounds.set_height(canvas->getDevice()->height());
1444
1445 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081446 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491447 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1448
[email protected]948f7ab72010-05-28 23:48:081449 // Have to make sure we're laid out at the right size before
1450 // rendering.
1451 gfx::Size old_size = webwidget_->size();
1452 webwidget_->resize(page_size);
1453 webwidget_->layout();
1454
[email protected]d65adb12010-04-28 17:26:491455 // Paint the entire thing (using original bounds, not scaled bounds).
1456 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1457 canvas->restore();
1458
[email protected]948f7ab72010-05-28 23:48:081459 // Return the widget to its previous size.
1460 webwidget_->resize(old_size);
1461
[email protected]c88c9442010-07-19 18:55:091462 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491463}
1464
[email protected]ec7dc112008-08-06 05:30:121465void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1466 // During shutdown we can just ignore this message.
1467 if (!webwidget_)
1468 return;
1469
1470 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561471 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041472 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461473 scheduleComposite();
1474 } else {
1475 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1476 didInvalidateRect(repaint_rect);
1477 }
[email protected]ec7dc112008-08-06 05:30:121478}
1479
[email protected]4873c7d2009-07-16 06:36:281480void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111481 if (!webwidget_)
1482 return;
[email protected]4873c7d2009-07-16 06:36:281483 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111484}
1485
[email protected]4b03e292012-02-13 18:40:071486void RenderWidget::OnInvertWebContent(bool invert) {
1487 if (invert_ == invert)
1488 return;
1489
1490 invert_ = invert;
1491
1492 if (invert_ && !invert_paint_.get()) {
1493 // Gamma-aware color inversion: each source pixel value x is normally
1494 // displayed on a computer monitor with a gamma correction x^gamma,
1495 // where gamma is typically in the range 1.8...2.2. By approximating
1496 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1497 uint8_t table[256];
1498 for (unsigned int i = 0; i < 256; i++) {
1499 double value = i / 255.0;
1500 value = sqrt(1 - (value * value));
1501 table[i] = static_cast<uint8_t>(255 * value);
1502 }
1503
1504 // Create a Skia Paint with this inverting color map.
1505 invert_paint_.reset(new SkPaint());
1506 invert_paint_->setStyle(SkPaint::kFill_Style);
1507 invert_paint_->setColor(SK_ColorBLACK);
1508 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1509 NULL, table, table, table);
1510 invert_paint_->setColorFilter(filter);
1511 filter->unref();
1512 }
1513
1514 OnMsgRepaint(size_);
1515}
1516
[email protected]719b36f2010-12-22 20:36:461517webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151518 const gfx::Rect& paint_bounds,
1519 TransportDIB** dib,
1520 gfx::Rect* location,
1521 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461522 // Bare RenderWidgets don't support optimized plugin painting.
1523 return NULL;
[email protected]ca4847f2010-09-24 05:39:151524}
1525
[email protected]bcaf2272011-02-15 15:29:431526gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521527 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431528 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521529}
1530
[email protected]bee16aab2009-08-26 15:55:031531void RenderWidget::SetHidden(bool hidden) {
1532 if (is_hidden_ == hidden)
1533 return;
1534
1535 // The status has changed. Tell the RenderThread about it.
1536 is_hidden_ = hidden;
1537 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271538 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031539 else
[email protected]380244092011-10-07 17:26:271540 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031541}
1542
[email protected]2b624c562011-10-27 22:58:261543void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261544 if (!webwidget_)
1545 return;
1546
1547 if (is_fullscreen_) {
1548 webwidget_->willExitFullScreen();
1549 } else {
1550 webwidget_->willEnterFullScreen();
1551 }
[email protected]2b624c562011-10-27 22:58:261552}
1553
1554void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261555 if (!webwidget_)
1556 return;
1557
1558 if (is_fullscreen_) {
1559 webwidget_->didEnterFullScreen();
1560 } else {
1561 webwidget_->didExitFullScreen();
1562 }
[email protected]2b624c562011-10-27 22:58:261563}
1564
[email protected]699ab0d2009-04-23 23:19:141565void RenderWidget::SetBackground(const SkBitmap& background) {
1566 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461567
[email protected]699ab0d2009-04-23 23:19:141568 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281569 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141570}
1571
[email protected]674741932009-02-04 23:44:461572bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051573 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461574}
1575
1576bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051577 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461578}
1579
1580void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051581 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461582}
1583
1584void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051585 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461586}
1587
1588void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051589 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461590}
1591
[email protected]e99ef6f2011-10-16 01:13:001592void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041593 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291594 return;
[email protected]fa7b1dc2010-06-23 17:53:041595
[email protected]ad26ef42011-06-17 07:59:451596 ui::TextInputType new_type = GetTextInputType();
1597 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001598 // Only sends text input type and compose inline to the browser process if
1599 // they are changed.
1600 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451601 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041602 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451603 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001604 Send(new ViewHostMsg_TextInputStateChanged(
1605 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291606 }
initial.commit09911bf2008-07-26 23:55:291607}
1608
[email protected]3f783362011-10-21 22:40:501609void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1610 WebRect start_webrect;
1611 WebRect end_webrect;
1612 webwidget_->selectionBounds(start_webrect, end_webrect);
1613 *start = start_webrect;
1614 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321615}
1616
[email protected]e99ef6f2011-10-16 01:13:001617void RenderWidget::UpdateSelectionBounds() {
1618 if (!webwidget_)
1619 return;
1620
[email protected]3f783362011-10-21 22:40:501621 gfx::Rect start_rect;
1622 gfx::Rect end_rect;
1623 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001624 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1625 return;
1626
1627 selection_start_rect_ = start_rect;
1628 selection_end_rect_ = end_rect;
1629 Send(new ViewHostMsg_SelectionBoundsChanged(
1630 routing_id_, selection_start_rect_, selection_end_rect_));
1631}
1632
[email protected]73bf95812011-10-12 11:38:321633// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451634COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1635 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1636COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1637 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1638COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1639 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181640COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1641 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1642COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1643 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1644COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1645 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1646COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1647 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1648COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1649 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451650
1651ui::TextInputType RenderWidget::GetTextInputType() {
1652 if (webwidget_) {
1653 int type = webwidget_->textInputType();
1654 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181655 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451656 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1657 return static_cast<ui::TextInputType>(type);
1658 }
1659 return ui::TEXT_INPUT_TYPE_NONE;
1660}
1661
1662bool RenderWidget::CanComposeInline() {
1663 return true;
[email protected]56ea1a62011-05-30 07:05:571664}
1665
[email protected]4873c7d2009-07-16 06:36:281666WebScreenInfo RenderWidget::screenInfo() {
[email protected]6fd35b72012-03-01 19:46:411667 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281668}
1669
[email protected]fa7b1dc2010-06-23 17:53:041670void RenderWidget::resetInputMethod() {
1671 if (!input_method_is_active_)
1672 return;
1673
1674 // If the last text input type is not None, then we should finish any
1675 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451676 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041677 // If a composition text exists, then we need to let the browser process
1678 // to cancel the input method's ongoing composition session.
1679 if (webwidget_->confirmComposition())
1680 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1681 }
[email protected]d4cff272011-05-02 15:46:011682
1683 // Send an updated IME range with the current caret rect.
1684 ui::Range range(ui::Range::InvalidRange());
1685 size_t location, length;
1686 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1687 range.set_start(location);
1688 range.set_end(location + length);
1689 }
1690 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041691}
1692
[email protected]f103ab72009-09-02 17:10:591693void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501694 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291695 size_t i = 0;
1696 for (; i < plugin_window_moves_.size(); ++i) {
1697 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581698 if (move.rects_valid) {
1699 plugin_window_moves_[i] = move;
1700 } else {
1701 plugin_window_moves_[i].visible = move.visible;
1702 }
initial.commit09911bf2008-07-26 23:55:291703 break;
1704 }
1705 }
1706
1707 if (i == plugin_window_moves_.size())
1708 plugin_window_moves_.push_back(move);
1709}
[email protected]268654772009-08-06 23:02:041710
1711void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1712 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1713 i != plugin_window_moves_.end(); ++i) {
1714 if (i->window == window) {
1715 plugin_window_moves_.erase(i);
1716 break;
1717 }
1718 }
1719}
[email protected]67bfb83f2011-09-22 03:36:371720
1721bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1722 return false;
1723}
[email protected]c3d45532011-10-07 19:20:401724
1725bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1726 return false;
1727}