blob: 14b716e5315b5d53e2b444482d3831ea79f7886b [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]32876ae2011-11-15 22:25:217#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:008#include "base/command_line.h"
[email protected]366ae242011-05-10 02:23:589#include "base/debug/trace_event.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2114#include "base/stl_util.h"
[email protected]8a9d6ca32011-06-06 20:11:3015#include "base/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4816#include "build/build_config.h"
[email protected]992db4c2011-05-12 15:37:1517#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5018#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2919#include "content/public/common/content_switches.h"
[email protected]8704f89b2011-04-15 00:30:0520#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4421#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1922#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1823#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4824#include "skia/ext/platform_canvas.h"
[email protected]8bd0fe62011-01-17 06:44:3725#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]a7547fb2012-03-08 04:43:4426#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3727#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
28#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0129#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3730#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4131#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
32#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]e6e90dc2011-12-03 00:01:3733#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
34#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
[email protected]d353541f2012-05-03 22:45:4135#include "third_party/skia/include/core/SkShader.h"
36#include "third_party/skia/include/effects/SkTableColorFilter.h"
[email protected]08397d52011-02-05 01:53:3837#include "ui/gfx/point.h"
38#include "ui/gfx/size.h"
[email protected]1835b9e2012-02-28 13:12:4839#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2740#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4141#include "ui/surface/transport_dib.h"
[email protected]8c89e7792009-08-19 21:18:3442#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5043#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4644#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4845
46#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4947#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5248#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4149#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4850#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4451
[email protected]8bd0fe62011-01-17 06:44:3752#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2953
[email protected]fa7b1dc2010-06-23 17:53:0454using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3055using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2256using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0657using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2858using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4459using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0060using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2861using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5962using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1863using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0164using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5265using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1966using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5267using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2868using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2469using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0470using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1871using WebKit::WebWidget;
[email protected]380244092011-10-07 17:26:2772using content::RenderThread;
[email protected]62cb33cae2009-03-27 23:30:2273
[email protected]6fd35b72012-03-01 19:46:4174RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]14392a52012-05-02 20:28:4475 const WebKit::WebScreenInfo& screen_info,
76 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:2977 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:5678 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:1179 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2980 opener_id_(MSG_ROUTING_NONE),
[email protected]659f73fa2009-10-13 13:43:4281 host_window_(0),
[email protected]05a980d7a2012-02-07 22:16:4282 host_window_set_(false),
[email protected]b4d08452010-10-05 17:34:3583 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2984 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:0685 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:0586 update_reply_pending_(false),
[email protected]ea3ee0a2012-05-15 03:43:0987 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:2488 using_asynchronous_swapbuffers_(false),
89 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2990 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2991 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:0992 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:2993 needs_repainting_on_restore_(false),
94 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4995 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4896 closing_(false),
[email protected]14392a52012-05-02 20:28:4497 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:0498 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:4599 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
100 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12101 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48102 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12103 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50104 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21105 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07106 invalidation_task_posted_(false),
[email protected]6fd35b72012-03-01 19:46:41107 screen_info_(screen_info),
[email protected]4b03e292012-02-13 18:40:07108 invert_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05109 if (!swapped_out)
110 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27111 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18112 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
113 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:29114}
115
116RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11117 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21118 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35119 if (current_paint_buf_) {
120 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
121 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29122 }
[email protected]992db4c2011-05-12 15:37:15123 // If we are swapped out, we have released already.
124 if (!is_swapped_out_)
125 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29126}
127
[email protected]484955942010-08-19 16:13:18128// static
[email protected]8085dbc82008-09-26 22:53:44129RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]6fd35b72012-03-01 19:46:41130 WebKit::WebPopupType popup_type,
131 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29132 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41133 scoped_refptr<RenderWidget> widget(
[email protected]14392a52012-05-02 20:28:44134 new RenderWidget(popup_type, screen_info, false));
initial.commit09911bf2008-07-26 23:55:29135 widget->Init(opener_id); // adds reference
136 return widget;
137}
138
[email protected]484955942010-08-19 16:13:18139// static
140WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
141 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03142 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18143 break;
144 case WebKit::WebPopupTypeSelect:
145 case WebKit::WebPopupTypeSuggestion:
146 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44147 case WebKit::WebPopupTypePage:
148 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18149 default:
150 NOTREACHED();
151 }
152 return NULL;
153}
154
initial.commit09911bf2008-07-26 23:55:29155void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18156 DoInit(opener_id,
157 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56158 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
159 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18160}
161
[email protected]484955942010-08-19 16:13:18162void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06163 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18164 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29165 DCHECK(!webwidget_);
166
167 if (opener_id != MSG_ROUTING_NONE)
168 opener_id_ = opener_id;
169
[email protected]484955942010-08-19 16:13:18170 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29171
[email protected]380244092011-10-07 17:26:27172 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29173 if (result) {
[email protected]380244092011-10-07 17:26:27174 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29175 // Take a reference on behalf of the RenderThread. This will be balanced
176 // when we receive ViewMsg_Close.
177 AddRef();
178 } else {
179 DCHECK(false);
180 }
181}
182
183// This is used to complete pending inits and non-pending inits. For non-
184// pending cases, the parent will be the same as the current parent. This
185// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55186void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29187 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29188
189 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42190 host_window_set_ = true;
191
[email protected]f1d5de42012-04-20 01:47:14192#if WEBWIDGET_HAS_SETCOMPOSITORSURFACEREADY
193 if (webwidget_)
194 webwidget_->setCompositorSurfaceReady();
195#endif
[email protected]05a980d7a2012-02-07 22:16:42196 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29197
[email protected]6de74452009-02-25 18:04:59198 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29199}
200
[email protected]992db4c2011-05-12 15:37:15201void RenderWidget::SetSwappedOut(bool is_swapped_out) {
202 // We should only toggle between states.
203 DCHECK(is_swapped_out_ != is_swapped_out);
204 is_swapped_out_ = is_swapped_out;
205
206 // If we are swapping out, we will call ReleaseProcess, allowing the process
207 // to exit if all of its RenderViews are swapped out. We wait until the
208 // WasSwappedOut call to do this, to avoid showing the sad tab.
209 // If we are swapping in, we call AddRefProcess to prevent the process from
210 // exiting.
211 if (!is_swapped_out)
212 RenderProcess::current()->AddRefProcess();
213}
214
[email protected]a95986a82010-12-24 06:19:28215bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
216 bool handled = true;
217 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
218 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
219 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
220 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54221 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28222 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
223 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15224 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28225 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
226 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
227 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
228 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
229 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
230 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
231 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
232 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
233 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
234 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
235 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]4b03e292012-02-13 18:40:07236 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
[email protected]a95986a82010-12-24 06:19:28237 IPC_MESSAGE_UNHANDLED(handled = false)
238 IPC_END_MESSAGE_MAP()
239 return handled;
240}
initial.commit09911bf2008-07-26 23:55:29241
242bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15243 // Don't send any messages after the browser has told us to close, and filter
244 // most outgoing messages while swapped out.
245 if ((is_swapped_out_ &&
246 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11247 closing_) {
initial.commit09911bf2008-07-26 23:55:29248 delete message;
249 return false;
250 }
251
252 // If given a messsage without a routing ID, then assign our routing ID.
253 if (message->routing_id() == MSG_ROUTING_NONE)
254 message->set_routing_id(routing_id_);
255
[email protected]380244092011-10-07 17:26:27256 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44257}
258
[email protected]61e2b3cc2012-03-02 16:13:34259void RenderWidget::Resize(const gfx::Size& new_size,
260 const gfx::Rect& resizer_rect,
261 bool is_fullscreen,
262 ResizeAck resize_ack) {
263 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
264 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
265 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29266
[email protected]61e2b3cc2012-03-02 16:13:34267 // Ignore this during shutdown.
268 if (!webwidget_)
269 return;
270
271 // Remember the rect where the resize corner will be drawn.
272 resizer_rect_ = resizer_rect;
273
274 // NOTE: We may have entered fullscreen mode without changing our size.
275 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
276 if (fullscreen_change)
277 WillToggleFullscreen();
278 is_fullscreen_ = is_fullscreen;
279
280 if (size_ != new_size) {
281 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34282 needs_repainting_on_restore_ = false;
283
284 size_ = new_size;
285
286 paint_aggregator_.ClearPendingUpdate();
287
288 // When resizing, we want to wait to paint before ACK'ing the resize. This
289 // ensures that we only resize as fast as we can paint. We only need to
290 // send an ACK if we are resized to a non-empty rect.
291 webwidget_->resize(new_size);
292 if (!new_size.IsEmpty()) {
293 if (!is_accelerated_compositing_active_) {
294 // Resize should have caused an invalidation of the entire view.
295 DCHECK(paint_aggregator_.HasPendingUpdate());
296 }
297
298 // Send the Resize_ACK flag once we paint again if requested.
299 if (resize_ack == SEND_RESIZE_ACK)
300 set_next_paint_is_resize_ack();
301 }
[email protected]ff475a322012-03-14 00:05:35302 } else {
303 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34304 }
305
306 if (fullscreen_change)
307 DidToggleFullscreen();
308
309 // If a resize ack is requested and it isn't set-up, then no more resizes will
310 // come in and in general things will go wrong.
311 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
312 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29313}
314
315void RenderWidget::OnClose() {
316 if (closing_)
317 return;
318 closing_ = true;
319
320 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03321 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27322 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03323 SetHidden(false);
324 }
initial.commit09911bf2008-07-26 23:55:29325
initial.commit09911bf2008-07-26 23:55:29326 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25327 // now. Post a task that only gets invoked when there are no nested message
328 // loops.
[email protected]32876ae2011-11-15 22:25:21329 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29330 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25331
332 // Balances the AddRef taken when we called AddRoute.
333 Release();
initial.commit09911bf2008-07-26 23:55:29334}
335
[email protected]61e2b3cc2012-03-02 16:13:34336// Got a response from the browser after the renderer decided to create a new
337// view.
338void RenderWidget::OnCreatingNewAck(
339 gfx::NativeViewId parent) {
340 DCHECK(routing_id_ != MSG_ROUTING_NONE);
341
342 CompleteInit(parent);
343}
344
[email protected]f21c613a2009-02-12 14:46:17345void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09346 const gfx::Rect& resizer_rect,
347 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34348 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29349}
350
[email protected]b5913d72012-02-07 22:26:54351void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
352 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59353 gfx::Rect view_rect(size_);
354
355 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
356 if (!old_damage_rect.IsEmpty())
357 paint_aggregator_.InvalidateRect(old_damage_rect);
358
359 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
360 if (!new_damage_rect.IsEmpty())
361 paint_aggregator_.InvalidateRect(new_damage_rect);
362
[email protected]b5913d72012-02-07 22:26:54363 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59364
[email protected]b5913d72012-02-07 22:26:54365 if (webwidget_)
366 webwidget_->didChangeWindowResizerRect();
367 }
368}
369
initial.commit09911bf2008-07-26 23:55:29370void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31371 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29372 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03373 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29374}
375
376void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31377 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29378 // During shutdown we can just ignore this message.
379 if (!webwidget_)
380 return;
381
382 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03383 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29384
385 if (!needs_repainting && !needs_repainting_on_restore_)
386 return;
387 needs_repainting_on_restore_ = false;
388
[email protected]d65adb12010-04-28 17:26:49389 // Tag the next paint as a restore ack, which is picked up by
390 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29391 set_next_paint_is_restore_ack();
392
393 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56394 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46395 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
396 } else {
397 scheduleComposite();
398 }
initial.commit09911bf2008-07-26 23:55:29399}
400
[email protected]992db4c2011-05-12 15:37:15401void RenderWidget::OnWasSwappedOut() {
402 // If we have been swapped out and no one else is using this process,
403 // it's safe to exit now. If we get swapped back in, we will call
404 // AddRefProcess in SetSwappedOut.
405 if (is_swapped_out_)
406 RenderProcess::current()->ReleaseProcess();
407}
408
[email protected]53d3f302009-12-21 04:42:05409void RenderWidget::OnRequestMoveAck() {
410 DCHECK(pending_window_rect_count_);
411 pending_window_rect_count_--;
412}
413
414void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58415 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21416 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05417 update_reply_pending_ = false;
418
[email protected]b4d08452010-10-05 17:34:35419 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
420 // have no current paint buffer.
421 if (current_paint_buf_) {
422 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
423 current_paint_buf_ = NULL;
424 }
425
[email protected]65225772011-05-12 21:10:24426 // If swapbuffers is still pending, then defer the update until the
427 // swapbuffers occurs.
428 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
429 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
430 return;
431 }
432
[email protected]29ed96a2012-02-04 18:12:16433 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18434 if (!is_accelerated_compositing_active_) {
435 DidFlushPaint();
436 }
[email protected]a2f6bc112009-06-27 16:27:25437
initial.commit09911bf2008-07-26 23:55:29438 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24439 DoDeferredUpdateAndSendInputAck();
440}
441
[email protected]d0be63772011-12-20 23:18:04442bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24443 return false;
444}
445
[email protected]d0be63772011-12-20 23:18:04446void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24447 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21448 while (!updates_pending_swap_.empty()) {
449 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
450 updates_pending_swap_.pop_front();
451 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
452 // compositing pass, hence doesn't require an UpdateRect message.
453 if (msg)
454 Send(msg);
455 }
[email protected]65225772011-05-12 21:10:24456 num_swapbuffers_complete_pending_ = 0;
457 using_asynchronous_swapbuffers_ = false;
458 // Schedule another frame so the compositor learns about it.
459 scheduleComposite();
460}
461
[email protected]37a6f302011-07-11 23:43:08462void RenderWidget::OnSwapBuffersPosted() {
463 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21464
465 if (using_asynchronous_swapbuffers_) {
466 ViewHostMsg_UpdateRect* msg = NULL;
467 // pending_update_params_ can be NULL if the swap doesn't correspond to an
468 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
469 // message.
470 if (pending_update_params_.get()) {
471 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
472 pending_update_params_.reset();
473 }
474 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08475 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21476 }
[email protected]37a6f302011-07-11 23:43:08477}
478
479void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24480 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16481
[email protected]404939f2012-06-01 04:06:18482 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16483 DidFlushPaint();
484
[email protected]65225772011-05-12 21:10:24485 // When compositing deactivates, we reset the swapbuffers pending count. The
486 // swapbuffers acks may still arrive, however.
487 if (num_swapbuffers_complete_pending_ == 0) {
488 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
489 return;
490 }
[email protected]aa4117f2011-12-09 22:19:21491 DCHECK(!updates_pending_swap_.empty());
492 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
493 updates_pending_swap_.pop_front();
494 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
495 // compositing pass, hence doesn't require an UpdateRect message.
496 if (msg)
497 Send(msg);
[email protected]65225772011-05-12 21:10:24498 num_swapbuffers_complete_pending_--;
499
500 // If update reply is still pending, then defer the update until that reply
501 // occurs.
[email protected]d0be63772011-12-20 23:18:04502 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24503 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
504 return;
505 }
506
507 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06508 // when we were previously rendering. However, if an invalidation task is not
509 // posted, there may be software rendering work pending. In that case, don't
510 // early out.
511 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24512 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
513 return;
514 }
515
[email protected]65225772011-05-12 21:10:24516 // Continue painting if necessary...
517 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29518}
519
initial.commit09911bf2008-07-26 23:55:29520void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24521 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56522 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29523
524 const char* data;
525 int data_length;
[email protected]5dd768212009-08-13 23:34:49526 handling_input_event_ = true;
527 if (!message.ReadData(&iter, &data, &data_length)) {
528 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29529 return;
[email protected]5dd768212009-08-13 23:34:49530 }
initial.commit09911bf2008-07-26 23:55:29531
532 const WebInputEvent* input_event =
533 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48534
[email protected]b68a0e52011-12-08 15:11:12535 bool is_keyboard_shortcut = false;
536 // is_keyboard_shortcut flag is only available for RawKeyDown events.
537 if (input_event->type == WebInputEvent::RawKeyDown)
538 message.ReadBool(&iter, &is_keyboard_shortcut);
539
[email protected]67bfb83f2011-09-22 03:36:37540 bool prevent_default = false;
541 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26542 const WebMouseEvent& mouse_event =
543 *static_cast<const WebMouseEvent*>(input_event);
544 TRACE_EVENT2("renderer", "HandleMouseMove",
545 "x", mouse_event.x, "y", mouse_event.y);
546 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37547 }
548
549 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12550 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
551 suppress_next_char_events_ = false;
552 if (!processed && webwidget_)
553 processed = webwidget_->handleInputEvent(*input_event);
554 }
555
556 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
557 // it's not processed by webkit, then we need to suppress the upcoming Char
558 // events.
559 if (!processed && is_keyboard_shortcut)
560 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29561
[email protected]a9fb30aa2011-10-06 06:58:46562 IPC::Message* response =
563 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
564 processed);
[email protected]3391a0772012-03-28 00:32:07565 bool event_type_gets_rate_limited =
566 input_event->type == WebInputEvent::MouseMove ||
567 input_event->type == WebInputEvent::MouseWheel ||
568 WebInputEvent::isTouchEventType(input_event->type);
569 bool is_input_throttled =
570 webwidget_->isInputThrottled() ||
571 paint_aggregator_.HasPendingUpdate();
[email protected]e2824412009-02-27 01:57:05572
[email protected]f8868d72012-04-27 19:13:03573 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24574 // We want to rate limit the input events in this case, so we'll wait for
575 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17576 if (pending_input_event_ack_.get()) {
577 // As two different kinds of events could cause us to postpone an ack
578 // we send it now, if we have one pending. The Browser should never
579 // send us the same kind of event we are delaying the ack for.
580 Send(pending_input_event_ack_.release());
581 }
[email protected]12fbad812009-09-01 18:21:24582 pending_input_event_ack_.reset(response);
583 } else {
584 Send(response);
585 }
586
[email protected]5dd768212009-08-13 23:34:49587 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48588
[email protected]67bfb83f2011-09-22 03:36:37589 if (!prevent_default) {
590 if (WebInputEvent::isKeyboardEventType(input_event->type))
591 DidHandleKeyEvent();
592 if (WebInputEvent::isMouseEventType(input_event->type))
593 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24594 if (WebInputEvent::isTouchEventType(input_event->type))
595 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37596 }
initial.commit09911bf2008-07-26 23:55:29597}
598
599void RenderWidget::OnMouseCaptureLost() {
600 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28601 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29602}
603
604void RenderWidget::OnSetFocus(bool enable) {
605 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33606 if (webwidget_)
607 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29608}
609
610void RenderWidget::ClearFocus() {
611 // We may have got the focus from the browser before this gets processed, in
612 // which case we do not want to unfocus ourself.
613 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28614 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29615}
616
[email protected]2d5d09d52009-06-15 14:29:21617void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00618 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21619 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06620 TRACE_EVENT2("renderer", "PaintRect",
621 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00622 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21623
624 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00625 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
626 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03627
[email protected]4b03e292012-02-13 18:40:07628 if (invert_) {
629 // Draw everything to a temporary bitmap and then apply an
630 // inverting color map to the result. This is balanced by an extra
631 // call to canvas->restore(), below.
632 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48633 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07634 canvas->saveLayer(&bounds, invert_paint_.get());
635 }
636
[email protected]699ab0d2009-04-23 23:19:14637 // If there is a custom background, tile it.
638 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14639 SkPaint paint;
640 SkShader* shader = SkShader::CreateBitmapShader(background_,
641 SkShader::kRepeat_TileMode,
642 SkShader::kRepeat_TileMode);
643 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20644
645 // Use kSrc_Mode to handle background_ transparency properly.
646 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
647
648 // Canvas could contain multiple update rects. Clip to given rect so that
649 // we don't accidentally clear other update rects.
650 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48651 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14652 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20653 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14654 }
655
[email protected]719b36f2010-12-22 20:36:46656 // First see if this rect is a plugin that can paint itself faster.
657 TransportDIB* optimized_dib = NULL;
658 gfx::Rect optimized_copy_rect, optimized_copy_location;
659 webkit::ppapi::PluginInstance* optimized_instance =
660 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
661 &optimized_copy_location,
662 &optimized_copy_rect);
663 if (optimized_instance) {
664 // This plugin can be optimize-painted and we can just ask it to paint
665 // itself. We don't actually need the TransportDIB in this case.
666 //
667 // This is an optimization for PPAPI plugins that know they're on top of
668 // the page content. If this rect is inside such a plugin, we can save some
669 // time and avoid re-rendering the page content which we know will be
670 // covered by the plugin later (this time can be significant, especially
671 // for a playing movie that is invalidating a lot).
672 //
673 // In the plugin movie case, hopefully the similar call to
674 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
675 // painting, because that avoids copying the plugin image to a different
676 // paint rect. Unfortunately, if anything on the page is animating other
677 // than the movie, it break this optimization since the union of the
678 // invalid regions will be larger than the plugin.
679 //
680 // This code optimizes that case, where we can still avoid painting in
681 // WebKit and filling the background (which can be slow) and just painting
682 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
683 // required.
684 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27685 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46686 } else {
687 // Normal painting case.
688 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
689
690 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35691 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46692 }
initial.commit09911bf2008-07-26 23:55:29693
[email protected]4b03e292012-02-13 18:40:07694 if (invert_)
695 canvas->restore();
696
[email protected]4fb66842009-12-04 21:41:00697 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00698 canvas->restore();
699}
700
701void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
702 skia::PlatformCanvas* canvas) {
703 static bool kPaintBorder =
704 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
705 if (!kPaintBorder)
706 return;
707
[email protected]53d3f302009-12-21 04:42:05708 // Cycle through these colors to help distinguish new paint rects.
709 const SkColor colors[] = {
710 SkColorSetARGB(0x3F, 0xFF, 0, 0),
711 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
712 SkColorSetARGB(0x3F, 0, 0, 0xFF),
713 };
714 static int color_selector = 0;
715
[email protected]4fb66842009-12-04 21:41:00716 SkPaint paint;
717 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05718 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00719 paint.setStrokeWidth(1);
720
721 SkIRect irect;
722 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
723 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29724}
725
[email protected]52ccd0ea2011-02-16 01:09:05726void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30727 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30728 if (!animation_update_pending_) {
729 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59730 return;
[email protected]921244e42011-07-20 16:36:30731 }
[email protected]bd37ae252011-06-03 01:28:18732 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59733 // Record when we fired (according to base::Time::Now()) relative to when
734 // we posted the task to quantify how much the base::Time/base::TimeTicks
735 // skew is affecting animations.
736 base::TimeDelta animation_callback_delay = base::Time::Now() -
737 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
738 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
739 animation_callback_delay,
740 base::TimeDelta::FromMilliseconds(0),
741 base::TimeDelta::FromMilliseconds(30),
742 25);
743 }
[email protected]65225772011-05-12 21:10:24744 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24745}
746
[email protected]52ccd0ea2011-02-16 01:09:05747void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59748 if (!animation_update_pending_)
749 return;
[email protected]bd37ae252011-06-03 01:28:18750
751 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33752 base::TimeDelta animationInterval = IsRenderingVSynced() ?
753 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18754
[email protected]7c4329e2011-02-18 22:02:59755 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45756
757 // animation_floor_time_ is the earliest time that we should animate when
758 // using the dead reckoning software scheduler. If we're using swapbuffers
759 // complete callbacks to rate limit, we can ignore this floor.
760 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30761 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33762 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18763 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59764 // running animation callbacks so that if a callback requests another
765 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38766 animation_timer_.Stop();
767 animation_timer_.Start(FROM_HERE, animationInterval, this,
768 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59769 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30770 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59771 return;
[email protected]5f8b1022011-01-21 23:34:50772 }
[email protected]bd37ae252011-06-03 01:28:18773 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38774 if (!animation_timer_.IsRunning()) {
775 // This code uses base::Time::Now() to calculate the floor and next fire
776 // time because javascript's Date object uses base::Time::Now(). The
777 // message loop uses base::TimeTicks, which on windows can have a
778 // different granularity than base::Time.
779 // The upshot of all this is that this function might be called before
780 // base::Time::Now() has advanced past the animation_floor_time_. To
781 // avoid exposing this delay to javascript, we keep posting delayed
782 // tasks until base::Time::Now() has advanced far enough.
783 base::TimeDelta delay = animation_floor_time_ - now;
784 animation_timer_.Start(FROM_HERE, delay, this,
785 &RenderWidget::AnimationCallback);
786 }
[email protected]5f8b1022011-01-21 23:34:50787}
788
[email protected]bd37ae252011-06-03 01:28:18789bool RenderWidget::IsRenderingVSynced() {
790 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
791 // not caught by this check. This will lead to artificially low frame rates
792 // for people who force vsync off at a driver level and expect Chrome to speed
793 // up.
794 return !has_disable_gpu_vsync_switch_;
795}
796
[email protected]65225772011-05-12 21:10:24797void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06798 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24799 invalidation_task_posted_ = false;
800 DoDeferredUpdateAndSendInputAck();
801}
802
803void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05804 DoDeferredUpdate();
805
806 if (pending_input_event_ack_.get())
807 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21808}
809
[email protected]552e6002009-11-19 05:24:57810void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58811 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08812
[email protected]65225772011-05-12 21:10:24813 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29814 return;
[email protected]05a980d7a2012-02-07 22:16:42815
816 if (!host_window_set_) {
817 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
818 return;
819 }
[email protected]aa4117f2011-12-09 22:19:21820 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24821 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
822 return;
823 }
[email protected]9ca84622011-06-02 23:46:39824 if (is_accelerated_compositing_active_ &&
825 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24826 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
827 return;
828 }
initial.commit09911bf2008-07-26 23:55:29829
[email protected]552e6002009-11-19 05:24:57830 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29831 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57832 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29833 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24834 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29835 return;
836 }
837
[email protected]05a980d7a2012-02-07 22:16:42838 if (is_accelerated_compositing_active_)
839 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
840
[email protected]0fb93f52011-05-18 23:13:56841 // Tracking of frame rate jitter
842 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51843 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05844 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50845
[email protected]f98d7e3c2010-09-13 22:30:46846 // Layout may generate more invalidation. It may also enable the
847 // GPU acceleration, so make sure to run layout before we send the
848 // GpuRenderingActivated message.
849 webwidget_->layout();
850
[email protected]dcca3aa92012-02-17 23:03:37851 // The following two can result in further layout and possibly
852 // enable GPU acceleration so they need to be called before any painting
853 // is done.
854 UpdateTextInputState();
855 UpdateSelectionBounds();
856
[email protected]5f8b1022011-01-21 23:34:50857 // Suppress painting if nothing is dirty. This has to be done after updating
858 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24859 if (!paint_aggregator_.HasPendingUpdate()) {
860 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51861 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50862 return;
[email protected]65225772011-05-12 21:10:24863 }
[email protected]5f8b1022011-01-21 23:34:50864
[email protected]872ae5b2011-05-26 20:20:50865 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56866 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04867 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56868 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
869 delay,
870 base::TimeDelta::FromMilliseconds(1),
871 base::TimeDelta::FromMilliseconds(60),
872 30);
[email protected]d0be63772011-12-20 23:18:04873 } else {
[email protected]0fb93f52011-05-18 23:13:56874 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
875 delay,
876 base::TimeDelta::FromMilliseconds(1),
877 base::TimeDelta::FromMilliseconds(60),
878 30);
[email protected]d0be63772011-12-20 23:18:04879 }
[email protected]872ae5b2011-05-26 20:20:50880
881 // Calculate filtered time per frame:
882 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
883 filtered_time_per_frame_ =
884 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56885 }
886 last_do_deferred_update_time_ = frame_begin_ticks;
887
[email protected]552e6002009-11-19 05:24:57888 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29889 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30890 PaintAggregator::PendingUpdate update;
891 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29892
[email protected]53d3f302009-12-21 04:42:05893 gfx::Rect scroll_damage = update.GetScrollDamage();
894 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29895
[email protected]29ed96a2012-02-04 18:12:16896 // Notify derived classes that we're about to initiate a paint.
897 WillInitiatePaint();
898
[email protected]ca4847f2010-09-24 05:39:15899 // A plugin may be able to do an optimized paint. First check this, in which
900 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46901 // This optimization allows PPAPI plugins that declare themselves on top of
902 // the page (like a traditional windowed plugin) to be able to animate (think
903 // movie playing) without repeatedly re-painting the page underneath, or
904 // copying the plugin backing store (since we can send the plugin's backing
905 // store directly to the browser).
906 //
907 // This optimization only works when the entire invalid region is contained
908 // within the plugin. There is a related optimization in PaintRect for the
909 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15910 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15911 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21912 DCHECK(!pending_update_params_.get());
913 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
914 pending_update_params_->dx = update.scroll_delta.x();
915 pending_update_params_->dy = update.scroll_delta.y();
916 pending_update_params_->scroll_rect = update.scroll_rect;
917 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21918 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
919 pending_update_params_->flags = next_paint_flags_;
920 pending_update_params_->scroll_offset = GetScrollOffset();
921 pending_update_params_->needs_ack = true;
922 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:09923 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:21924
[email protected]ca4847f2010-09-24 05:39:15925 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56926 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15927 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
928 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27929 // Only update the part of the plugin that actually changed.
930 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21931 pending_update_params_->bitmap = dib->id();
932 pending_update_params_->bitmap_rect = optimized_copy_location;
933 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56934 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46935 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15936 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35937 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
938 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46939 if (!canvas.get()) {
940 NOTREACHED();
941 return;
942 }
[email protected]cef3362f2009-12-21 17:48:45943
[email protected]f98d7e3c2010-09-13 22:30:46944 // We may get back a smaller canvas than we asked for.
945 // TODO(darin): This seems like it could cause painting problems!
946 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
947 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
948 bounds.set_width(canvas->getDevice()->width());
949 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05950
[email protected]f98d7e3c2010-09-13 22:30:46951 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
952
[email protected]aa4117f2011-12-09 22:19:21953 pending_update_params_->bitmap = current_paint_buf_->id();
954 pending_update_params_->bitmap_rect = bounds;
955
956 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46957 // The scroll damage is just another rectangle to paint and copy.
958 copy_rects.swap(update.paint_rects);
959 if (!scroll_damage.IsEmpty())
960 copy_rects.push_back(scroll_damage);
961
962 for (size_t i = 0; i < copy_rects.size(); ++i)
963 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35964
965 // Software FPS tick for performance tests. The accelerated path traces the
966 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
967 // NOTE: Tests may break if this event is renamed or moved.
968 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46969 } else { // Accelerated compositing path
970 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21971 // If painting is done via the gpu process then we don't set any damage
972 // rects to save the browser process from doing unecessary work.
973 pending_update_params_->bitmap_rect = bounds;
974 pending_update_params_->scroll_rect = gfx::Rect();
975 // We don't need an ack, because we're not sharing a DIB with the browser.
976 // If it needs to (e.g. composited UI), the GPU process does its own ACK
977 // with the browser for the GPU surface.
978 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42979 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46980 }
981
[email protected]936c6f52011-12-13 01:35:26982 // If we're holding a pending input event ACK, send the ACK before sending the
983 // UpdateReply message so we can receive another input event before the
984 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
985 // the UpdateRect IPC message handler.
986 if (pending_input_event_ack_.get())
987 Send(pending_input_event_ack_.release());
988
[email protected]aa4117f2011-12-09 22:19:21989 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
990 // OnSwapBuffersPosted), meaning a message has been added to the
991 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
992 // the message now.
993 if (pending_update_params_.get()) {
994 // sending an ack to browser process that the paint is complete...
995 update_reply_pending_ = pending_update_params_->needs_ack;
996 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
997 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:34998 }
[email protected]53d3f302009-12-21 04:42:05999
[email protected]29ed96a2012-02-04 18:12:161000 // If we're software rendering then we're done initiating the paint.
1001 if (!is_accelerated_compositing_active_)
1002 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291003}
1004
1005///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461006// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291007
[email protected]4873c7d2009-07-16 06:36:281008void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:571009 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481010 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571011 gfx::Rect damaged_rect = view_rect.Intersect(rect);
1012 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291013 return;
1014
[email protected]552e6002009-11-19 05:24:571015 paint_aggregator_.InvalidateRect(damaged_rect);
1016
1017 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241018 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571019 return;
1020 if (!paint_aggregator_.HasPendingUpdate())
1021 return;
[email protected]aa4117f2011-12-09 22:19:211022 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241023 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1024 return;
1025
1026 // When GPU rendering, combine pending animations and invalidations into
1027 // a single update.
[email protected]816edc62012-03-17 01:27:221028 if (is_accelerated_compositing_active_ &&
1029 animation_update_pending_ &&
1030 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571031 return;
1032
1033 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291034 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1035 // on the call stack.
1036 // 2) Allows us to collect more damage rects before painting to help coalesce
1037 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241038 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211039 MessageLoop::current()->PostTask(
1040 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291041}
1042
[email protected]4873c7d2009-07-16 06:36:281043void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461044 // Drop scrolls on the floor when we are in compositing mode.
1045 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561046 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461047 return;
1048
[email protected]552e6002009-11-19 05:24:571049 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481050 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571051 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1052 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291053 return;
1054
[email protected]552e6002009-11-19 05:24:571055 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1056
1057 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241058 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571059 return;
1060 if (!paint_aggregator_.HasPendingUpdate())
1061 return;
[email protected]aa4117f2011-12-09 22:19:211062 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241063 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1064 return;
1065
1066 // When GPU rendering, combine pending animations and invalidations into
1067 // a single update.
[email protected]816edc62012-03-17 01:27:221068 if (is_accelerated_compositing_active_ &&
1069 animation_update_pending_ &&
1070 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571071 return;
1072
1073 // Perform updating asynchronously. This serves two purposes:
1074 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1075 // on the call stack.
1076 // 2) Allows us to collect more damage rects before painting to help coalesce
1077 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241078 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211079 MessageLoop::current()->PostTask(
1080 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291081}
1082
[email protected]244ac1892011-12-02 17:04:471083void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091084 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1085 size_ = new_size;
1086 need_update_rect_for_auto_resize_ = true;
1087 }
[email protected]244ac1892011-12-02 17:04:471088}
1089
[email protected]91acd1c2012-03-14 08:32:391090void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221091 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1092
[email protected]c63b4d42012-04-26 01:01:071093#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211094 if (!is_accelerated_compositing_active_) {
1095 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1096 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1097 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1098 // going to switch to accelerated compositing, the GPU process may need
1099 // round-trips to the browser's UI thread before finishing the frame,
1100 // causing deadlocks if we delay the UpdateRect until we receive the
1101 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071102 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1103 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211104 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1105 }
[email protected]c63b4d42012-04-26 01:01:071106#endif
[email protected]aa4117f2011-12-09 22:19:211107
[email protected]ea162f92011-10-04 23:08:221108 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421109 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241110 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221111}
1112
1113void RenderWidget::didDeactivateCompositor() {
1114 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1115
1116 is_accelerated_compositing_active_ = false;
1117 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1118 routing_id_, is_accelerated_compositing_active_));
1119
[email protected]ea162f92011-10-04 23:08:221120 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241121 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561122}
1123
[email protected]9cd43a62012-03-26 08:03:561124void RenderWidget::willBeginCompositorFrame() {
1125 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371126
1127 DCHECK(RenderThreadImpl::current()->compositor_thread());
1128
1129 // The following two can result in further layout and possibly
1130 // enable GPU acceleration so they need to be called before any painting
1131 // is done.
1132 UpdateTextInputState();
1133 UpdateSelectionBounds();
1134
[email protected]9cd43a62012-03-26 08:03:561135 WillInitiatePaint();
1136}
1137
[email protected]3391a0772012-03-28 00:32:071138void RenderWidget::didBecomeReadyForAdditionalInput() {
1139 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1140 if (pending_input_event_ack_.get())
1141 Send(pending_input_event_ack_.release());
1142}
1143
[email protected]58264a32011-11-17 23:36:151144void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501145 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351146 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1147 // NOTE: Tests may break if this event is renamed or moved.
1148 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161149 // Notify subclasses that we initiated the paint operation.
1150 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151151}
1152
1153void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181154 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1155
1156 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561157 DidFlushPaint();
1158
[email protected]aa4117f2011-12-09 22:19:211159 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151160 return;
1161
[email protected]ea3ee0a2012-05-15 03:43:091162 if (!next_paint_flags_ &&
1163 !need_update_rect_for_auto_resize_ &&
1164 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151165 return;
[email protected]ea3ee0a2012-05-15 03:43:091166 }
[email protected]58264a32011-11-17 23:36:151167
1168 ViewHostMsg_UpdateRect_Params params;
1169 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151170 params.plugin_window_moves.swap(plugin_window_moves_);
1171 params.flags = next_paint_flags_;
1172 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121173 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151174
1175 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1176 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091177 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151178}
1179
[email protected]f98d7e3c2010-09-13 22:30:461180void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041181 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401182 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041183 } else {
[email protected]c3d45532011-10-07 19:20:401184 // TODO(nduca): replace with something a little less hacky. The reason this
1185 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1186 // contains a lot of host-renderer synchronization logic that is still
1187 // important for the accelerated compositing case. The option of simply
1188 // duplicating all that code is less desirable than "faking out" the
1189 // invalidation path using a magical damage rect.
1190 didInvalidateRect(WebRect(0, 0, 1, 1));
1191 }
[email protected]f98d7e3c2010-09-13 22:30:461192}
1193
[email protected]5f8b1022011-01-21 23:34:501194void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201195 if (animation_update_pending_)
1196 return;
1197
[email protected]921244e42011-07-20 16:36:301198 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201199 animation_update_pending_ = true;
1200 if (!animation_timer_.IsRunning()) {
1201 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1202 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211203 }
[email protected]5f8b1022011-01-21 23:34:501204}
1205
[email protected]4873c7d2009-07-16 06:36:281206void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301207 // TODO(darin): Eliminate this temporary.
1208 WebCursor cursor(cursor_info);
1209
initial.commit09911bf2008-07-26 23:55:291210 // Only send a SetCursor message if we need to make a change.
1211 if (!current_cursor_.IsEqual(cursor)) {
1212 current_cursor_ = cursor;
1213 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1214 }
1215}
1216
1217// We are supposed to get a single call to Show for a newly created RenderWidget
1218// that was created via RenderWidget::CreateWebView. So, we wait until this
1219// point to dispatch the ShowWidget message.
1220//
1221// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281222// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291223//
[email protected]4873c7d2009-07-16 06:36:281224void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291225 DCHECK(!did_show_) << "received extraneous Show call";
1226 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1227 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1228
[email protected]8de12d942010-11-17 20:42:441229 if (did_show_)
1230 return;
1231
1232 did_show_ = true;
1233 // NOTE: initial_pos_ may still have its default values at this point, but
1234 // that's okay. It'll be ignored if as_popup is false, or the browser
1235 // process will impose a default position otherwise.
1236 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1237 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291238}
1239
[email protected]4873c7d2009-07-16 06:36:281240void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291241}
1242
[email protected]4873c7d2009-07-16 06:36:281243void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291244}
1245
[email protected]2533ce12009-05-09 00:02:241246void RenderWidget::DoDeferredClose() {
1247 Send(new ViewHostMsg_Close(routing_id_));
1248}
1249
[email protected]4873c7d2009-07-16 06:36:281250void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321251 if (is_swapped_out_) {
1252 // This widget is currently swapped out, and the active widget is in a
1253 // different process. Have the browser route the close request to the
1254 // active widget instead, so that the correct unload handlers are run.
1255 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1256 return;
1257 }
1258
initial.commit09911bf2008-07-26 23:55:291259 // If a page calls window.close() twice, we'll end up here twice, but that's
1260 // OK. It is safe to send multiple Close messages.
1261
[email protected]2533ce12009-05-09 00:02:241262 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1263 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1264 // could be closed before the JS finishes executing. So instead, post a
1265 // message back to the message loop, which won't run until the JS is
1266 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211267 MessageLoop::current()->PostTask(
1268 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291269}
1270
1271void RenderWidget::Close() {
1272 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281273 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291274 webwidget_ = NULL;
1275 }
1276}
1277
[email protected]4873c7d2009-07-16 06:36:281278WebRect RenderWidget::windowRect() {
1279 if (pending_window_rect_count_)
1280 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241281
[email protected]b3f2b912009-04-09 16:18:521282 gfx::Rect rect;
1283 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281284 return rect;
initial.commit09911bf2008-07-26 23:55:291285}
1286
[email protected]8a9d6ca32011-06-06 20:11:301287void RenderWidget::setToolTipText(const WebKit::WebString& text,
1288 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541289 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301290}
1291
[email protected]4873c7d2009-07-16 06:36:281292void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291293 if (did_show_) {
1294 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241295 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291296 } else {
1297 initial_pos_ = pos;
1298 }
1299}
1300
[email protected]2533ce12009-05-09 00:02:241301void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1302 pending_window_rect_ = rect;
1303 pending_window_rect_count_++;
1304}
1305
[email protected]4873c7d2009-07-16 06:36:281306WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241307 if (pending_window_rect_count_) {
1308 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1309 // the RootWindowRect is probably going to return wrong results since the
1310 // browser may not have processed the Move yet. There isn't really anything
1311 // good to do in this case, and it shouldn't happen - since this size is
1312 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281313 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241314 }
1315
[email protected]b3f2b912009-04-09 16:18:521316 gfx::Rect rect;
1317 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281318 return rect;
[email protected]d4547452008-08-28 18:36:371319}
1320
[email protected]4873c7d2009-07-16 06:36:281321WebRect RenderWidget::windowResizerRect() {
1322 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191323}
1324
[email protected]fa7b1dc2010-06-23 17:53:041325void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031326 // To prevent this renderer process from sending unnecessary IPC messages to
1327 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041328 // only during the input method attached to the browser process is active.
1329 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291330}
1331
[email protected]fa7b1dc2010-06-23 17:53:041332void RenderWidget::OnImeSetComposition(
1333 const string16& text,
1334 const std::vector<WebCompositionUnderline>& underlines,
1335 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281336 if (!webwidget_)
1337 return;
[email protected]d4cff272011-05-02 15:46:011338 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041339 text, WebVector<WebCompositionUnderline>(underlines),
1340 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011341 // Setting the IME composition was successful. Send the new composition
1342 // range to the browser.
1343 ui::Range range(ui::Range::InvalidRange());
1344 size_t location, length;
1345 if (webwidget_->compositionRange(&location, &length)) {
1346 range.set_start(location);
1347 range.set_end(location + length);
1348 }
1349 // The IME was cancelled via the Esc key, so just send back the caret.
1350 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1351 range.set_start(location);
1352 range.set_end(location + length);
1353 }
1354 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1355 } else {
[email protected]fa7b1dc2010-06-23 17:53:041356 // If we failed to set the composition text, then we need to let the browser
1357 // process to cancel the input method's ongoing composition session, to make
1358 // sure we are in a consistent state.
1359 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011360
1361 // Send an updated IME range with just the caret range.
1362 ui::Range range(ui::Range::InvalidRange());
1363 size_t location, length;
1364 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1365 range.set_start(location);
1366 range.set_end(location + length);
1367 }
1368 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261369 }
[email protected]fa7b1dc2010-06-23 17:53:041370}
1371
[email protected]4de6d1692011-10-12 08:45:441372void RenderWidget::OnImeConfirmComposition(
1373 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041374 if (!webwidget_)
1375 return;
1376
1377 handling_input_event_ = true;
1378 webwidget_->confirmComposition(text);
1379 handling_input_event_ = false;
1380
[email protected]d4cff272011-05-02 15:46:011381 // Send an updated IME range with just the caret range.
1382 ui::Range range(ui::Range::InvalidRange());
1383 size_t location, length;
1384 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1385 range.set_start(location);
1386 range.set_end(location + length);
1387 }
1388 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291389}
1390
[email protected]948f7ab72010-05-28 23:48:081391// This message causes the renderer to render an image of the
1392// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491393void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091394 int tag,
[email protected]948f7ab72010-05-28 23:48:081395 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491396 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001397 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1398 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251399 // Close our unused handle.
1400#if defined(OS_WIN)
1401 ::CloseHandle(dib_handle);
1402#elif defined(OS_MACOSX)
1403 base::SharedMemory::CloseHandle(dib_handle);
1404#endif
1405 }
[email protected]d65adb12010-04-28 17:26:491406 return;
[email protected]45c6aad32010-11-11 04:46:251407 }
[email protected]d65adb12010-04-28 17:26:491408
[email protected]948f7ab72010-05-28 23:48:081409 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491410 // If one of these is empty, then we just return the dib we were
1411 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091412 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491413 return;
1414 }
1415
1416 // Map the given DIB ID into this process, and unmap it at the end
1417 // of this function.
[email protected]45c6aad32010-11-11 04:46:251418 scoped_ptr<TransportDIB> paint_at_size_buffer(
1419 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301420
1421 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491422 float x_scale = static_cast<float>(desired_size.width()) /
1423 static_cast<float>(canvas_size.width());
1424 float y_scale = static_cast<float>(desired_size.height()) /
1425 static_cast<float>(canvas_size.height());
1426
[email protected]ee8d6fd2010-05-26 17:05:481427 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491428 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1429 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481430 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491431
[email protected]36808ad2010-10-20 19:18:301432 scoped_ptr<skia::PlatformCanvas> canvas(
1433 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1434 canvas_size.height()));
1435 if (!canvas.get()) {
1436 NOTREACHED();
1437 return;
1438 }
1439
[email protected]d65adb12010-04-28 17:26:491440 // Reset bounds to what we actually received, but they should be the
1441 // same.
1442 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1443 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1444 bounds.set_width(canvas->getDevice()->width());
1445 bounds.set_height(canvas->getDevice()->height());
1446
1447 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081448 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491449 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1450
[email protected]948f7ab72010-05-28 23:48:081451 // Have to make sure we're laid out at the right size before
1452 // rendering.
1453 gfx::Size old_size = webwidget_->size();
1454 webwidget_->resize(page_size);
1455 webwidget_->layout();
1456
[email protected]d65adb12010-04-28 17:26:491457 // Paint the entire thing (using original bounds, not scaled bounds).
1458 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1459 canvas->restore();
1460
[email protected]948f7ab72010-05-28 23:48:081461 // Return the widget to its previous size.
1462 webwidget_->resize(old_size);
1463
[email protected]c88c9442010-07-19 18:55:091464 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491465}
1466
[email protected]ec7dc112008-08-06 05:30:121467void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1468 // During shutdown we can just ignore this message.
1469 if (!webwidget_)
1470 return;
1471
1472 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561473 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041474 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461475 scheduleComposite();
1476 } else {
1477 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1478 didInvalidateRect(repaint_rect);
1479 }
[email protected]ec7dc112008-08-06 05:30:121480}
1481
[email protected]4873c7d2009-07-16 06:36:281482void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111483 if (!webwidget_)
1484 return;
[email protected]4873c7d2009-07-16 06:36:281485 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111486}
1487
[email protected]4b03e292012-02-13 18:40:071488void RenderWidget::OnInvertWebContent(bool invert) {
1489 if (invert_ == invert)
1490 return;
1491
1492 invert_ = invert;
1493
1494 if (invert_ && !invert_paint_.get()) {
1495 // Gamma-aware color inversion: each source pixel value x is normally
1496 // displayed on a computer monitor with a gamma correction x^gamma,
1497 // where gamma is typically in the range 1.8...2.2. By approximating
1498 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1499 uint8_t table[256];
1500 for (unsigned int i = 0; i < 256; i++) {
1501 double value = i / 255.0;
1502 value = sqrt(1 - (value * value));
1503 table[i] = static_cast<uint8_t>(255 * value);
1504 }
1505
1506 // Create a Skia Paint with this inverting color map.
1507 invert_paint_.reset(new SkPaint());
1508 invert_paint_->setStyle(SkPaint::kFill_Style);
1509 invert_paint_->setColor(SK_ColorBLACK);
1510 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1511 NULL, table, table, table);
1512 invert_paint_->setColorFilter(filter);
1513 filter->unref();
1514 }
1515
1516 OnMsgRepaint(size_);
1517}
1518
[email protected]719b36f2010-12-22 20:36:461519webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151520 const gfx::Rect& paint_bounds,
1521 TransportDIB** dib,
1522 gfx::Rect* location,
1523 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461524 // Bare RenderWidgets don't support optimized plugin painting.
1525 return NULL;
[email protected]ca4847f2010-09-24 05:39:151526}
1527
[email protected]bcaf2272011-02-15 15:29:431528gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521529 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431530 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521531}
1532
[email protected]bee16aab2009-08-26 15:55:031533void RenderWidget::SetHidden(bool hidden) {
1534 if (is_hidden_ == hidden)
1535 return;
1536
1537 // The status has changed. Tell the RenderThread about it.
1538 is_hidden_ = hidden;
1539 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271540 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031541 else
[email protected]380244092011-10-07 17:26:271542 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031543}
1544
[email protected]2b624c562011-10-27 22:58:261545void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261546 if (!webwidget_)
1547 return;
1548
1549 if (is_fullscreen_) {
1550 webwidget_->willExitFullScreen();
1551 } else {
1552 webwidget_->willEnterFullScreen();
1553 }
[email protected]2b624c562011-10-27 22:58:261554}
1555
1556void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261557 if (!webwidget_)
1558 return;
1559
1560 if (is_fullscreen_) {
1561 webwidget_->didEnterFullScreen();
1562 } else {
1563 webwidget_->didExitFullScreen();
1564 }
[email protected]2b624c562011-10-27 22:58:261565}
1566
[email protected]699ab0d2009-04-23 23:19:141567void RenderWidget::SetBackground(const SkBitmap& background) {
1568 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461569
[email protected]699ab0d2009-04-23 23:19:141570 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281571 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141572}
1573
[email protected]674741932009-02-04 23:44:461574bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051575 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461576}
1577
1578bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051579 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461580}
1581
1582void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051583 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461584}
1585
1586void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051587 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461588}
1589
1590void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051591 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461592}
1593
[email protected]e99ef6f2011-10-16 01:13:001594void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041595 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291596 return;
[email protected]fa7b1dc2010-06-23 17:53:041597
[email protected]ad26ef42011-06-17 07:59:451598 ui::TextInputType new_type = GetTextInputType();
1599 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001600 // Only sends text input type and compose inline to the browser process if
1601 // they are changed.
1602 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451603 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041604 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451605 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001606 Send(new ViewHostMsg_TextInputStateChanged(
1607 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291608 }
initial.commit09911bf2008-07-26 23:55:291609}
1610
[email protected]3f783362011-10-21 22:40:501611void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1612 WebRect start_webrect;
1613 WebRect end_webrect;
1614 webwidget_->selectionBounds(start_webrect, end_webrect);
1615 *start = start_webrect;
1616 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321617}
1618
[email protected]e99ef6f2011-10-16 01:13:001619void RenderWidget::UpdateSelectionBounds() {
1620 if (!webwidget_)
1621 return;
1622
[email protected]3f783362011-10-21 22:40:501623 gfx::Rect start_rect;
1624 gfx::Rect end_rect;
1625 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001626 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1627 return;
1628
1629 selection_start_rect_ = start_rect;
1630 selection_end_rect_ = end_rect;
1631 Send(new ViewHostMsg_SelectionBoundsChanged(
1632 routing_id_, selection_start_rect_, selection_end_rect_));
1633}
1634
[email protected]73bf95812011-10-12 11:38:321635// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451636COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1637 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1638COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1639 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1640COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1641 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181642COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1643 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1644COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1645 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1646COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1647 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1648COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1649 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1650COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1651 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451652
1653ui::TextInputType RenderWidget::GetTextInputType() {
1654 if (webwidget_) {
1655 int type = webwidget_->textInputType();
1656 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181657 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451658 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1659 return static_cast<ui::TextInputType>(type);
1660 }
1661 return ui::TEXT_INPUT_TYPE_NONE;
1662}
1663
1664bool RenderWidget::CanComposeInline() {
1665 return true;
[email protected]56ea1a62011-05-30 07:05:571666}
1667
[email protected]4873c7d2009-07-16 06:36:281668WebScreenInfo RenderWidget::screenInfo() {
[email protected]6fd35b72012-03-01 19:46:411669 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281670}
1671
[email protected]fa7b1dc2010-06-23 17:53:041672void RenderWidget::resetInputMethod() {
1673 if (!input_method_is_active_)
1674 return;
1675
1676 // If the last text input type is not None, then we should finish any
1677 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451678 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041679 // If a composition text exists, then we need to let the browser process
1680 // to cancel the input method's ongoing composition session.
1681 if (webwidget_->confirmComposition())
1682 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1683 }
[email protected]d4cff272011-05-02 15:46:011684
1685 // Send an updated IME range with the current caret rect.
1686 ui::Range range(ui::Range::InvalidRange());
1687 size_t location, length;
1688 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1689 range.set_start(location);
1690 range.set_end(location + length);
1691 }
1692 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041693}
1694
[email protected]f103ab72009-09-02 17:10:591695void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501696 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291697 size_t i = 0;
1698 for (; i < plugin_window_moves_.size(); ++i) {
1699 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581700 if (move.rects_valid) {
1701 plugin_window_moves_[i] = move;
1702 } else {
1703 plugin_window_moves_[i].visible = move.visible;
1704 }
initial.commit09911bf2008-07-26 23:55:291705 break;
1706 }
1707 }
1708
1709 if (i == plugin_window_moves_.size())
1710 plugin_window_moves_.push_back(move);
1711}
[email protected]268654772009-08-06 23:02:041712
1713void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1714 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1715 i != plugin_window_moves_.end(); ++i) {
1716 if (i->window == window) {
1717 plugin_window_moves_.erase(i);
1718 break;
1719 }
1720 }
1721}
[email protected]67bfb83f2011-09-22 03:36:371722
1723bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1724 return false;
1725}
[email protected]c3d45532011-10-07 19:20:401726
1727bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1728 return false;
1729}