blob: 33d2bd5c7aae9b87f925080e9f1ae238d0384ee2 [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]3da12cb2011-10-08 02:25:0420#include "content/renderer/gpu/compositor_thread.h"
[email protected]8704f89b2011-04-15 00:30:0521#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4422#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1923#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1824#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5226#include "third_party/skia/include/core/SkShader.h"
[email protected]4b03e292012-02-13 18:40:0727#include "third_party/skia/include/effects/SkTableColorFilter.h"
[email protected]8bd0fe62011-01-17 06:44:3728#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]e6e90dc2011-12-03 00:01:3729#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
[email protected]a7547fb2012-03-08 04:43:4430#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3731#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
32#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0133#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]e6e90dc2011-12-03 00:01:3734#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]8bd0fe62011-01-17 06:44:3735#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]e6e90dc2011-12-03 00:01:3736#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
37#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
[email protected]1835b9e2012-02-28 13:12:4838#include "ui/gfx/gl/gl_switches.h"
[email protected]08397d52011-02-05 01:53:3839#include "ui/gfx/point.h"
40#include "ui/gfx/size.h"
[email protected]1835b9e2012-02-28 13:12:4841#include "ui/gfx/skia_util.h"
[email protected]b9b751f22011-03-25 14:04:1242#include "ui/gfx/surface/transport_dib.h"
[email protected]8c89e7792009-08-19 21:18:3443#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5044#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4645#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4846
47#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4948#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5249#include "third_party/skia/include/core/SkPixelRef.h"
50#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4851#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4452
[email protected]8bd0fe62011-01-17 06:44:3753#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2954
[email protected]fa7b1dc2010-06-23 17:53:0455using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3056using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2257using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0658using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2859using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4460using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0061using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2862using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5963using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1864using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0165using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5266using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1967using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5268using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2869using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2470using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0471using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1872using WebKit::WebWidget;
[email protected]380244092011-10-07 17:26:2773using content::RenderThread;
[email protected]62cb33cae2009-03-27 23:30:2274
[email protected]6fd35b72012-03-01 19:46:4175RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
76 const WebKit::WebScreenInfo& screen_info)
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]659f73f2009-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]65225772011-05-12 21:10:2487 using_asynchronous_swapbuffers_(false),
88 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2989 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2990 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:0991 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:2992 needs_repainting_on_restore_(false),
93 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4994 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4895 closing_(false),
[email protected]992db4c2011-05-12 15:37:1596 is_swapped_out_(false),
[email protected]fa7b1dc2010-06-23 17:53:0497 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:4598 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
99 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12100 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48101 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12102 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50103 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21104 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07105 invalidation_task_posted_(false),
[email protected]6fd35b72012-03-01 19:46:41106 screen_info_(screen_info),
[email protected]4b03e292012-02-13 18:40:07107 invert_(false) {
[email protected]8930d472009-02-21 08:05:28108 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27109 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18110 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
111 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:29112}
113
114RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11115 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21116 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35117 if (current_paint_buf_) {
118 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
119 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29120 }
[email protected]992db4c2011-05-12 15:37:15121 // If we are swapped out, we have released already.
122 if (!is_swapped_out_)
123 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29124}
125
[email protected]484955942010-08-19 16:13:18126// static
[email protected]8085dbc82008-09-26 22:53:44127RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]6fd35b72012-03-01 19:46:41128 WebKit::WebPopupType popup_type,
129 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29130 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41131 scoped_refptr<RenderWidget> widget(
132 new RenderWidget(popup_type, screen_info));
initial.commit09911bf2008-07-26 23:55:29133 widget->Init(opener_id); // adds reference
134 return widget;
135}
136
[email protected]484955942010-08-19 16:13:18137// static
138WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
139 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03140 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18141 break;
142 case WebKit::WebPopupTypeSelect:
143 case WebKit::WebPopupTypeSuggestion:
144 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44145 case WebKit::WebPopupTypePage:
146 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18147 default:
148 NOTREACHED();
149 }
150 return NULL;
151}
152
initial.commit09911bf2008-07-26 23:55:29153void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18154 DoInit(opener_id,
155 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56156 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
157 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18158}
159
[email protected]484955942010-08-19 16:13:18160void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06161 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18162 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29163 DCHECK(!webwidget_);
164
165 if (opener_id != MSG_ROUTING_NONE)
166 opener_id_ = opener_id;
167
[email protected]484955942010-08-19 16:13:18168 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29169
[email protected]380244092011-10-07 17:26:27170 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29171 if (result) {
[email protected]380244092011-10-07 17:26:27172 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29173 // Take a reference on behalf of the RenderThread. This will be balanced
174 // when we receive ViewMsg_Close.
175 AddRef();
176 } else {
177 DCHECK(false);
178 }
179}
180
181// This is used to complete pending inits and non-pending inits. For non-
182// pending cases, the parent will be the same as the current parent. This
183// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55184void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29185 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29186
187 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42188 host_window_set_ = true;
189
190 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29191
[email protected]6de74452009-02-25 18:04:59192 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29193}
194
[email protected]992db4c2011-05-12 15:37:15195void RenderWidget::SetSwappedOut(bool is_swapped_out) {
196 // We should only toggle between states.
197 DCHECK(is_swapped_out_ != is_swapped_out);
198 is_swapped_out_ = is_swapped_out;
199
200 // If we are swapping out, we will call ReleaseProcess, allowing the process
201 // to exit if all of its RenderViews are swapped out. We wait until the
202 // WasSwappedOut call to do this, to avoid showing the sad tab.
203 // If we are swapping in, we call AddRefProcess to prevent the process from
204 // exiting.
205 if (!is_swapped_out)
206 RenderProcess::current()->AddRefProcess();
207}
208
[email protected]a95986a82010-12-24 06:19:28209bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
210 bool handled = true;
211 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
212 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
213 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
214 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54215 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28216 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
217 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15218 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28219 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
220 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
221 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
222 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
223 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
224 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
225 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
226 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
227 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
228 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
229 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]4b03e292012-02-13 18:40:07230 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
[email protected]a95986a82010-12-24 06:19:28231 IPC_MESSAGE_UNHANDLED(handled = false)
232 IPC_END_MESSAGE_MAP()
233 return handled;
234}
initial.commit09911bf2008-07-26 23:55:29235
236bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15237 // Don't send any messages after the browser has told us to close, and filter
238 // most outgoing messages while swapped out.
239 if ((is_swapped_out_ &&
240 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
241 closing_) {
initial.commit09911bf2008-07-26 23:55:29242 delete message;
243 return false;
244 }
245
246 // If given a messsage without a routing ID, then assign our routing ID.
247 if (message->routing_id() == MSG_ROUTING_NONE)
248 message->set_routing_id(routing_id_);
249
[email protected]380244092011-10-07 17:26:27250 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44251}
252
[email protected]61e2b3cc2012-03-02 16:13:34253void RenderWidget::Resize(const gfx::Size& new_size,
254 const gfx::Rect& resizer_rect,
255 bool is_fullscreen,
256 ResizeAck resize_ack) {
257 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
258 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
259 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29260
[email protected]61e2b3cc2012-03-02 16:13:34261 // Ignore this during shutdown.
262 if (!webwidget_)
263 return;
264
265 // Remember the rect where the resize corner will be drawn.
266 resizer_rect_ = resizer_rect;
267
268 // NOTE: We may have entered fullscreen mode without changing our size.
269 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
270 if (fullscreen_change)
271 WillToggleFullscreen();
272 is_fullscreen_ = is_fullscreen;
273
274 if (size_ != new_size) {
275 // TODO(darin): We should not need to reset this here.
276 SetHidden(false);
277 needs_repainting_on_restore_ = false;
278
279 size_ = new_size;
280
281 paint_aggregator_.ClearPendingUpdate();
282
283 // When resizing, we want to wait to paint before ACK'ing the resize. This
284 // ensures that we only resize as fast as we can paint. We only need to
285 // send an ACK if we are resized to a non-empty rect.
286 webwidget_->resize(new_size);
287 if (!new_size.IsEmpty()) {
288 if (!is_accelerated_compositing_active_) {
289 // Resize should have caused an invalidation of the entire view.
290 DCHECK(paint_aggregator_.HasPendingUpdate());
291 }
292
293 // Send the Resize_ACK flag once we paint again if requested.
294 if (resize_ack == SEND_RESIZE_ACK)
295 set_next_paint_is_resize_ack();
296 }
[email protected]ff475a322012-03-14 00:05:35297 } else {
298 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34299 }
300
301 if (fullscreen_change)
302 DidToggleFullscreen();
303
304 // If a resize ack is requested and it isn't set-up, then no more resizes will
305 // come in and in general things will go wrong.
306 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
307 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29308}
309
310void RenderWidget::OnClose() {
311 if (closing_)
312 return;
313 closing_ = true;
314
315 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03316 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27317 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03318 SetHidden(false);
319 }
initial.commit09911bf2008-07-26 23:55:29320
initial.commit09911bf2008-07-26 23:55:29321 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25322 // now. Post a task that only gets invoked when there are no nested message
323 // loops.
[email protected]32876ae2011-11-15 22:25:21324 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29325 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25326
327 // Balances the AddRef taken when we called AddRoute.
328 Release();
initial.commit09911bf2008-07-26 23:55:29329}
330
[email protected]61e2b3cc2012-03-02 16:13:34331// Got a response from the browser after the renderer decided to create a new
332// view.
333void RenderWidget::OnCreatingNewAck(
334 gfx::NativeViewId parent) {
335 DCHECK(routing_id_ != MSG_ROUTING_NONE);
336
337 CompleteInit(parent);
338}
339
[email protected]f21c613a2009-02-12 14:46:17340void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09341 const gfx::Rect& resizer_rect,
342 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34343 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29344}
345
[email protected]b5913d72012-02-07 22:26:54346void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
347 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59348 gfx::Rect view_rect(size_);
349
350 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
351 if (!old_damage_rect.IsEmpty())
352 paint_aggregator_.InvalidateRect(old_damage_rect);
353
354 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
355 if (!new_damage_rect.IsEmpty())
356 paint_aggregator_.InvalidateRect(new_damage_rect);
357
[email protected]b5913d72012-02-07 22:26:54358 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59359
[email protected]b5913d72012-02-07 22:26:54360 if (webwidget_)
361 webwidget_->didChangeWindowResizerRect();
362 }
363}
364
initial.commit09911bf2008-07-26 23:55:29365void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31366 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29367 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03368 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29369}
370
371void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31372 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29373 // During shutdown we can just ignore this message.
374 if (!webwidget_)
375 return;
376
377 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03378 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29379
380 if (!needs_repainting && !needs_repainting_on_restore_)
381 return;
382 needs_repainting_on_restore_ = false;
383
[email protected]d65adb12010-04-28 17:26:49384 // Tag the next paint as a restore ack, which is picked up by
385 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29386 set_next_paint_is_restore_ack();
387
388 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56389 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46390 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
391 } else {
392 scheduleComposite();
393 }
initial.commit09911bf2008-07-26 23:55:29394}
395
[email protected]992db4c2011-05-12 15:37:15396void RenderWidget::OnWasSwappedOut() {
397 // If we have been swapped out and no one else is using this process,
398 // it's safe to exit now. If we get swapped back in, we will call
399 // AddRefProcess in SetSwappedOut.
400 if (is_swapped_out_)
401 RenderProcess::current()->ReleaseProcess();
402}
403
[email protected]53d3f302009-12-21 04:42:05404void RenderWidget::OnRequestMoveAck() {
405 DCHECK(pending_window_rect_count_);
406 pending_window_rect_count_--;
407}
408
409void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58410 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21411 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05412 update_reply_pending_ = false;
413
[email protected]b4d08452010-10-05 17:34:35414 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
415 // have no current paint buffer.
416 if (current_paint_buf_) {
417 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
418 current_paint_buf_ = NULL;
419 }
420
[email protected]65225772011-05-12 21:10:24421 // If swapbuffers is still pending, then defer the update until the
422 // swapbuffers occurs.
423 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
424 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
425 return;
426 }
427
[email protected]29ed96a2012-02-04 18:12:16428 // Notify subclasses that software rendering was flushed to the screen.
429 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25430
initial.commit09911bf2008-07-26 23:55:29431 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24432 DoDeferredUpdateAndSendInputAck();
433}
434
[email protected]d0be63772011-12-20 23:18:04435bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24436 return false;
437}
438
[email protected]d0be63772011-12-20 23:18:04439void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24440 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21441 while (!updates_pending_swap_.empty()) {
442 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
443 updates_pending_swap_.pop_front();
444 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
445 // compositing pass, hence doesn't require an UpdateRect message.
446 if (msg)
447 Send(msg);
448 }
[email protected]65225772011-05-12 21:10:24449 num_swapbuffers_complete_pending_ = 0;
450 using_asynchronous_swapbuffers_ = false;
451 // Schedule another frame so the compositor learns about it.
452 scheduleComposite();
453}
454
[email protected]37a6f302011-07-11 23:43:08455void RenderWidget::OnSwapBuffersPosted() {
456 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21457
458 if (using_asynchronous_swapbuffers_) {
459 ViewHostMsg_UpdateRect* msg = NULL;
460 // pending_update_params_ can be NULL if the swap doesn't correspond to an
461 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
462 // message.
463 if (pending_update_params_.get()) {
464 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
465 pending_update_params_.reset();
466 }
467 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08468 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21469 }
[email protected]37a6f302011-07-11 23:43:08470}
471
472void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24473 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16474
475 // Notify subclasses that composited rendering got flushed to the screen.
476 DidFlushPaint();
477
[email protected]65225772011-05-12 21:10:24478 // When compositing deactivates, we reset the swapbuffers pending count. The
479 // swapbuffers acks may still arrive, however.
480 if (num_swapbuffers_complete_pending_ == 0) {
481 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
482 return;
483 }
[email protected]aa4117f2011-12-09 22:19:21484 DCHECK(!updates_pending_swap_.empty());
485 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
486 updates_pending_swap_.pop_front();
487 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
488 // compositing pass, hence doesn't require an UpdateRect message.
489 if (msg)
490 Send(msg);
[email protected]65225772011-05-12 21:10:24491 num_swapbuffers_complete_pending_--;
492
493 // If update reply is still pending, then defer the update until that reply
494 // occurs.
[email protected]d0be63772011-12-20 23:18:04495 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24496 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
497 return;
498 }
499
500 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06501 // when we were previously rendering. However, if an invalidation task is not
502 // posted, there may be software rendering work pending. In that case, don't
503 // early out.
504 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24505 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
506 return;
507 }
508
[email protected]65225772011-05-12 21:10:24509 // Continue painting if necessary...
510 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29511}
512
initial.commit09911bf2008-07-26 23:55:29513void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24514 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56515 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29516
517 const char* data;
518 int data_length;
[email protected]5dd768212009-08-13 23:34:49519 handling_input_event_ = true;
520 if (!message.ReadData(&iter, &data, &data_length)) {
521 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29522 return;
[email protected]5dd768212009-08-13 23:34:49523 }
initial.commit09911bf2008-07-26 23:55:29524
525 const WebInputEvent* input_event =
526 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48527
[email protected]b68a0e52011-12-08 15:11:12528 bool is_keyboard_shortcut = false;
529 // is_keyboard_shortcut flag is only available for RawKeyDown events.
530 if (input_event->type == WebInputEvent::RawKeyDown)
531 message.ReadBool(&iter, &is_keyboard_shortcut);
532
[email protected]67bfb83f2011-09-22 03:36:37533 bool prevent_default = false;
534 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26535 const WebMouseEvent& mouse_event =
536 *static_cast<const WebMouseEvent*>(input_event);
537 TRACE_EVENT2("renderer", "HandleMouseMove",
538 "x", mouse_event.x, "y", mouse_event.y);
539 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37540 }
541
542 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12543 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
544 suppress_next_char_events_ = false;
545 if (!processed && webwidget_)
546 processed = webwidget_->handleInputEvent(*input_event);
547 }
548
549 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
550 // it's not processed by webkit, then we need to suppress the upcoming Char
551 // events.
552 if (!processed && is_keyboard_shortcut)
553 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29554
[email protected]a9fb30aa2011-10-06 06:58:46555 IPC::Message* response =
556 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
557 processed);
[email protected]e2824412009-02-27 01:57:05558
[email protected]353a34c2010-05-28 23:35:17559 if ((input_event->type == WebInputEvent::MouseMove ||
[email protected]d93fc462011-03-14 23:03:03560 input_event->type == WebInputEvent::MouseWheel ||
[email protected]d329a912012-01-27 01:55:01561 WebInputEvent::isTouchEventType(input_event->type)) &&
[email protected]552e6002009-11-19 05:24:57562 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24563 // We want to rate limit the input events in this case, so we'll wait for
564 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17565 if (pending_input_event_ack_.get()) {
566 // As two different kinds of events could cause us to postpone an ack
567 // we send it now, if we have one pending. The Browser should never
568 // send us the same kind of event we are delaying the ack for.
569 Send(pending_input_event_ack_.release());
570 }
[email protected]12fbad812009-09-01 18:21:24571 pending_input_event_ack_.reset(response);
572 } else {
573 Send(response);
574 }
575
[email protected]5dd768212009-08-13 23:34:49576 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48577
[email protected]67bfb83f2011-09-22 03:36:37578 if (!prevent_default) {
579 if (WebInputEvent::isKeyboardEventType(input_event->type))
580 DidHandleKeyEvent();
581 if (WebInputEvent::isMouseEventType(input_event->type))
582 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24583 if (WebInputEvent::isTouchEventType(input_event->type))
584 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37585 }
initial.commit09911bf2008-07-26 23:55:29586}
587
588void RenderWidget::OnMouseCaptureLost() {
589 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28590 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29591}
592
593void RenderWidget::OnSetFocus(bool enable) {
594 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33595 if (webwidget_)
596 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29597}
598
599void RenderWidget::ClearFocus() {
600 // We may have got the focus from the browser before this gets processed, in
601 // which case we do not want to unfocus ourself.
602 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28603 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29604}
605
[email protected]2d5d09d52009-06-15 14:29:21606void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00607 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21608 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06609 TRACE_EVENT2("renderer", "PaintRect",
610 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00611 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21612
613 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00614 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
615 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03616
[email protected]4b03e292012-02-13 18:40:07617 if (invert_) {
618 // Draw everything to a temporary bitmap and then apply an
619 // inverting color map to the result. This is balanced by an extra
620 // call to canvas->restore(), below.
621 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48622 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07623 canvas->saveLayer(&bounds, invert_paint_.get());
624 }
625
[email protected]699ab0d2009-04-23 23:19:14626 // If there is a custom background, tile it.
627 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14628 SkPaint paint;
629 SkShader* shader = SkShader::CreateBitmapShader(background_,
630 SkShader::kRepeat_TileMode,
631 SkShader::kRepeat_TileMode);
632 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20633
634 // Use kSrc_Mode to handle background_ transparency properly.
635 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
636
637 // Canvas could contain multiple update rects. Clip to given rect so that
638 // we don't accidentally clear other update rects.
639 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48640 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14641 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20642 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14643 }
644
[email protected]719b36f2010-12-22 20:36:46645 // First see if this rect is a plugin that can paint itself faster.
646 TransportDIB* optimized_dib = NULL;
647 gfx::Rect optimized_copy_rect, optimized_copy_location;
648 webkit::ppapi::PluginInstance* optimized_instance =
649 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
650 &optimized_copy_location,
651 &optimized_copy_rect);
652 if (optimized_instance) {
653 // This plugin can be optimize-painted and we can just ask it to paint
654 // itself. We don't actually need the TransportDIB in this case.
655 //
656 // This is an optimization for PPAPI plugins that know they're on top of
657 // the page content. If this rect is inside such a plugin, we can save some
658 // time and avoid re-rendering the page content which we know will be
659 // covered by the plugin later (this time can be significant, especially
660 // for a playing movie that is invalidating a lot).
661 //
662 // In the plugin movie case, hopefully the similar call to
663 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
664 // painting, because that avoids copying the plugin image to a different
665 // paint rect. Unfortunately, if anything on the page is animating other
666 // than the movie, it break this optimization since the union of the
667 // invalid regions will be larger than the plugin.
668 //
669 // This code optimizes that case, where we can still avoid painting in
670 // WebKit and filling the background (which can be slow) and just painting
671 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
672 // required.
673 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27674 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46675 } else {
676 // Normal painting case.
677 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
678
679 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35680 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46681 }
initial.commit09911bf2008-07-26 23:55:29682
[email protected]4b03e292012-02-13 18:40:07683 if (invert_)
684 canvas->restore();
685
[email protected]4fb66842009-12-04 21:41:00686 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00687 canvas->restore();
688}
689
690void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
691 skia::PlatformCanvas* canvas) {
692 static bool kPaintBorder =
693 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
694 if (!kPaintBorder)
695 return;
696
[email protected]53d3f302009-12-21 04:42:05697 // Cycle through these colors to help distinguish new paint rects.
698 const SkColor colors[] = {
699 SkColorSetARGB(0x3F, 0xFF, 0, 0),
700 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
701 SkColorSetARGB(0x3F, 0, 0, 0xFF),
702 };
703 static int color_selector = 0;
704
[email protected]4fb66842009-12-04 21:41:00705 SkPaint paint;
706 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05707 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00708 paint.setStrokeWidth(1);
709
710 SkIRect irect;
711 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
712 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29713}
714
[email protected]52ccd0ea2011-02-16 01:09:05715void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30716 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30717 if (!animation_update_pending_) {
718 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59719 return;
[email protected]921244e42011-07-20 16:36:30720 }
[email protected]bd37ae252011-06-03 01:28:18721 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59722 // Record when we fired (according to base::Time::Now()) relative to when
723 // we posted the task to quantify how much the base::Time/base::TimeTicks
724 // skew is affecting animations.
725 base::TimeDelta animation_callback_delay = base::Time::Now() -
726 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
727 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
728 animation_callback_delay,
729 base::TimeDelta::FromMilliseconds(0),
730 base::TimeDelta::FromMilliseconds(30),
731 25);
732 }
[email protected]65225772011-05-12 21:10:24733 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24734}
735
[email protected]52ccd0ea2011-02-16 01:09:05736void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59737 if (!animation_update_pending_)
738 return;
[email protected]bd37ae252011-06-03 01:28:18739
740 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33741 base::TimeDelta animationInterval = IsRenderingVSynced() ?
742 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18743
[email protected]7c4329e2011-02-18 22:02:59744 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45745
746 // animation_floor_time_ is the earliest time that we should animate when
747 // using the dead reckoning software scheduler. If we're using swapbuffers
748 // complete callbacks to rate limit, we can ignore this floor.
749 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30750 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33751 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18752 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59753 // running animation callbacks so that if a callback requests another
754 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38755 animation_timer_.Stop();
756 animation_timer_.Start(FROM_HERE, animationInterval, this,
757 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59758 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30759 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59760 return;
[email protected]5f8b1022011-01-21 23:34:50761 }
[email protected]bd37ae252011-06-03 01:28:18762 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38763 if (!animation_timer_.IsRunning()) {
764 // This code uses base::Time::Now() to calculate the floor and next fire
765 // time because javascript's Date object uses base::Time::Now(). The
766 // message loop uses base::TimeTicks, which on windows can have a
767 // different granularity than base::Time.
768 // The upshot of all this is that this function might be called before
769 // base::Time::Now() has advanced past the animation_floor_time_. To
770 // avoid exposing this delay to javascript, we keep posting delayed
771 // tasks until base::Time::Now() has advanced far enough.
772 base::TimeDelta delay = animation_floor_time_ - now;
773 animation_timer_.Start(FROM_HERE, delay, this,
774 &RenderWidget::AnimationCallback);
775 }
[email protected]5f8b1022011-01-21 23:34:50776}
777
[email protected]bd37ae252011-06-03 01:28:18778bool RenderWidget::IsRenderingVSynced() {
779 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
780 // not caught by this check. This will lead to artificially low frame rates
781 // for people who force vsync off at a driver level and expect Chrome to speed
782 // up.
783 return !has_disable_gpu_vsync_switch_;
784}
785
[email protected]65225772011-05-12 21:10:24786void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06787 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24788 invalidation_task_posted_ = false;
789 DoDeferredUpdateAndSendInputAck();
790}
791
792void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05793 DoDeferredUpdate();
794
795 if (pending_input_event_ack_.get())
796 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21797}
798
[email protected]552e6002009-11-19 05:24:57799void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58800 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08801
[email protected]65225772011-05-12 21:10:24802 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29803 return;
[email protected]05a980d7a2012-02-07 22:16:42804
805 if (!host_window_set_) {
806 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
807 return;
808 }
[email protected]aa4117f2011-12-09 22:19:21809 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24810 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
811 return;
812 }
[email protected]9ca84622011-06-02 23:46:39813 if (is_accelerated_compositing_active_ &&
814 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24815 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
816 return;
817 }
initial.commit09911bf2008-07-26 23:55:29818
[email protected]552e6002009-11-19 05:24:57819 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29820 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57821 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29822 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24823 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29824 return;
825 }
826
[email protected]05a980d7a2012-02-07 22:16:42827 if (is_accelerated_compositing_active_)
828 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
829
[email protected]0fb93f52011-05-18 23:13:56830 // Tracking of frame rate jitter
831 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51832 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05833 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50834
[email protected]f98d7e3c2010-09-13 22:30:46835 // Layout may generate more invalidation. It may also enable the
836 // GPU acceleration, so make sure to run layout before we send the
837 // GpuRenderingActivated message.
838 webwidget_->layout();
839
[email protected]dcca3aa92012-02-17 23:03:37840 // The following two can result in further layout and possibly
841 // enable GPU acceleration so they need to be called before any painting
842 // is done.
843 UpdateTextInputState();
844 UpdateSelectionBounds();
845
[email protected]5f8b1022011-01-21 23:34:50846 // Suppress painting if nothing is dirty. This has to be done after updating
847 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24848 if (!paint_aggregator_.HasPendingUpdate()) {
849 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:51850 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:50851 return;
[email protected]65225772011-05-12 21:10:24852 }
[email protected]5f8b1022011-01-21 23:34:50853
[email protected]872ae5b2011-05-26 20:20:50854 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56855 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04856 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56857 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
858 delay,
859 base::TimeDelta::FromMilliseconds(1),
860 base::TimeDelta::FromMilliseconds(60),
861 30);
[email protected]d0be63772011-12-20 23:18:04862 } else {
[email protected]0fb93f52011-05-18 23:13:56863 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
864 delay,
865 base::TimeDelta::FromMilliseconds(1),
866 base::TimeDelta::FromMilliseconds(60),
867 30);
[email protected]d0be63772011-12-20 23:18:04868 }
[email protected]872ae5b2011-05-26 20:20:50869
870 // Calculate filtered time per frame:
871 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
872 filtered_time_per_frame_ =
873 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56874 }
875 last_do_deferred_update_time_ = frame_begin_ticks;
876
[email protected]552e6002009-11-19 05:24:57877 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29878 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30879 PaintAggregator::PendingUpdate update;
880 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29881
[email protected]53d3f302009-12-21 04:42:05882 gfx::Rect scroll_damage = update.GetScrollDamage();
883 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29884
[email protected]29ed96a2012-02-04 18:12:16885 // Notify derived classes that we're about to initiate a paint.
886 WillInitiatePaint();
887
[email protected]ca4847f2010-09-24 05:39:15888 // A plugin may be able to do an optimized paint. First check this, in which
889 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46890 // This optimization allows PPAPI plugins that declare themselves on top of
891 // the page (like a traditional windowed plugin) to be able to animate (think
892 // movie playing) without repeatedly re-painting the page underneath, or
893 // copying the plugin backing store (since we can send the plugin's backing
894 // store directly to the browser).
895 //
896 // This optimization only works when the entire invalid region is contained
897 // within the plugin. There is a related optimization in PaintRect for the
898 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15899 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15900 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21901 DCHECK(!pending_update_params_.get());
902 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
903 pending_update_params_->dx = update.scroll_delta.x();
904 pending_update_params_->dy = update.scroll_delta.y();
905 pending_update_params_->scroll_rect = update.scroll_rect;
906 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21907 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
908 pending_update_params_->flags = next_paint_flags_;
909 pending_update_params_->scroll_offset = GetScrollOffset();
910 pending_update_params_->needs_ack = true;
911 next_paint_flags_ = 0;
912
[email protected]ca4847f2010-09-24 05:39:15913 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56914 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15915 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
916 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27917 // Only update the part of the plugin that actually changed.
918 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21919 pending_update_params_->bitmap = dib->id();
920 pending_update_params_->bitmap_rect = optimized_copy_location;
921 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56922 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46923 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15924 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35925 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
926 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46927 if (!canvas.get()) {
928 NOTREACHED();
929 return;
930 }
[email protected]cef3362f2009-12-21 17:48:45931
[email protected]f98d7e3c2010-09-13 22:30:46932 // We may get back a smaller canvas than we asked for.
933 // TODO(darin): This seems like it could cause painting problems!
934 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
935 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
936 bounds.set_width(canvas->getDevice()->width());
937 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05938
[email protected]f98d7e3c2010-09-13 22:30:46939 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
940
[email protected]aa4117f2011-12-09 22:19:21941 pending_update_params_->bitmap = current_paint_buf_->id();
942 pending_update_params_->bitmap_rect = bounds;
943
944 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46945 // The scroll damage is just another rectangle to paint and copy.
946 copy_rects.swap(update.paint_rects);
947 if (!scroll_damage.IsEmpty())
948 copy_rects.push_back(scroll_damage);
949
950 for (size_t i = 0; i < copy_rects.size(); ++i)
951 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35952
953 // Software FPS tick for performance tests. The accelerated path traces the
954 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
955 // NOTE: Tests may break if this event is renamed or moved.
956 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46957 } else { // Accelerated compositing path
958 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21959 // If painting is done via the gpu process then we don't set any damage
960 // rects to save the browser process from doing unecessary work.
961 pending_update_params_->bitmap_rect = bounds;
962 pending_update_params_->scroll_rect = gfx::Rect();
963 // We don't need an ack, because we're not sharing a DIB with the browser.
964 // If it needs to (e.g. composited UI), the GPU process does its own ACK
965 // with the browser for the GPU surface.
966 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42967 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46968 }
969
[email protected]936c6f52011-12-13 01:35:26970 // If we're holding a pending input event ACK, send the ACK before sending the
971 // UpdateReply message so we can receive another input event before the
972 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
973 // the UpdateRect IPC message handler.
974 if (pending_input_event_ack_.get())
975 Send(pending_input_event_ack_.release());
976
[email protected]aa4117f2011-12-09 22:19:21977 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
978 // OnSwapBuffersPosted), meaning a message has been added to the
979 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
980 // the message now.
981 if (pending_update_params_.get()) {
982 // sending an ack to browser process that the paint is complete...
983 update_reply_pending_ = pending_update_params_->needs_ack;
984 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
985 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:34986 }
[email protected]53d3f302009-12-21 04:42:05987
[email protected]29ed96a2012-02-04 18:12:16988 // If we're software rendering then we're done initiating the paint.
989 if (!is_accelerated_compositing_active_)
990 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29991}
992
993///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:46994// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:29995
[email protected]4873c7d2009-07-16 06:36:28996void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:57997 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48998 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57999 gfx::Rect damaged_rect = view_rect.Intersect(rect);
1000 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291001 return;
1002
[email protected]552e6002009-11-19 05:24:571003 paint_aggregator_.InvalidateRect(damaged_rect);
1004
1005 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241006 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571007 return;
1008 if (!paint_aggregator_.HasPendingUpdate())
1009 return;
[email protected]aa4117f2011-12-09 22:19:211010 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241011 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1012 return;
1013
1014 // When GPU rendering, combine pending animations and invalidations into
1015 // a single update.
[email protected]816edc62012-03-17 01:27:221016 if (is_accelerated_compositing_active_ &&
1017 animation_update_pending_ &&
1018 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571019 return;
1020
1021 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291022 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1023 // on the call stack.
1024 // 2) Allows us to collect more damage rects before painting to help coalesce
1025 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241026 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211027 MessageLoop::current()->PostTask(
1028 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291029}
1030
[email protected]4873c7d2009-07-16 06:36:281031void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461032 // Drop scrolls on the floor when we are in compositing mode.
1033 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561034 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461035 return;
1036
[email protected]552e6002009-11-19 05:24:571037 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481038 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571039 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1040 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291041 return;
1042
[email protected]552e6002009-11-19 05:24:571043 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1044
1045 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241046 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571047 return;
1048 if (!paint_aggregator_.HasPendingUpdate())
1049 return;
[email protected]aa4117f2011-12-09 22:19:211050 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241051 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1052 return;
1053
1054 // When GPU rendering, combine pending animations and invalidations into
1055 // a single update.
[email protected]816edc62012-03-17 01:27:221056 if (is_accelerated_compositing_active_ &&
1057 animation_update_pending_ &&
1058 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571059 return;
1060
1061 // Perform updating asynchronously. This serves two purposes:
1062 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1063 // on the call stack.
1064 // 2) Allows us to collect more damage rects before painting to help coalesce
1065 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241066 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211067 MessageLoop::current()->PostTask(
1068 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291069}
1070
[email protected]244ac1892011-12-02 17:04:471071void RenderWidget::didAutoResize(const WebSize& new_size) {
1072 size_ = new_size;
1073}
1074
[email protected]91acd1c2012-03-14 08:32:391075void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221076 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1077
[email protected]f3150172011-10-22 02:28:451078 CompositorThread* compositor_thread =
1079 RenderThreadImpl::current()->compositor_thread();
1080 if (compositor_thread)
[email protected]91acd1c2012-03-14 08:32:391081 compositor_thread->AddInputHandler(routing_id_, input_handler_identifier);
[email protected]3da12cb2011-10-08 02:25:041082
[email protected]aa4117f2011-12-09 22:19:211083 if (!is_accelerated_compositing_active_) {
1084 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1085 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1086 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1087 // going to switch to accelerated compositing, the GPU process may need
1088 // round-trips to the browser's UI thread before finishing the frame,
1089 // causing deadlocks if we delay the UpdateRect until we receive the
1090 // OnSwapBuffersComplete. So send a dummy message that will unblock the
1091 // browser's UI thread.
1092 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1093 }
1094
[email protected]ea162f92011-10-04 23:08:221095 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421096 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241097 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221098}
1099
1100void RenderWidget::didDeactivateCompositor() {
1101 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1102
1103 is_accelerated_compositing_active_ = false;
1104 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1105 routing_id_, is_accelerated_compositing_active_));
1106
[email protected]ea162f92011-10-04 23:08:221107 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241108 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561109}
1110
[email protected]58264a32011-11-17 23:36:151111void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501112 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351113 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1114 // NOTE: Tests may break if this event is renamed or moved.
1115 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161116 // Notify subclasses that we initiated the paint operation.
1117 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151118}
1119
1120void RenderWidget::didCompleteSwapBuffers() {
[email protected]aa4117f2011-12-09 22:19:211121 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151122 return;
1123
1124 if (!next_paint_flags_ && !plugin_window_moves_.size())
1125 return;
1126
1127 ViewHostMsg_UpdateRect_Params params;
1128 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151129 params.plugin_window_moves.swap(plugin_window_moves_);
1130 params.flags = next_paint_flags_;
1131 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121132 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151133
1134 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1135 next_paint_flags_ = 0;
1136}
1137
[email protected]f98d7e3c2010-09-13 22:30:461138void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041139 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401140 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041141 } else {
[email protected]c3d45532011-10-07 19:20:401142 // TODO(nduca): replace with something a little less hacky. The reason this
1143 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1144 // contains a lot of host-renderer synchronization logic that is still
1145 // important for the accelerated compositing case. The option of simply
1146 // duplicating all that code is less desirable than "faking out" the
1147 // invalidation path using a magical damage rect.
1148 didInvalidateRect(WebRect(0, 0, 1, 1));
1149 }
[email protected]f98d7e3c2010-09-13 22:30:461150}
1151
[email protected]5f8b1022011-01-21 23:34:501152void RenderWidget::scheduleAnimation() {
[email protected]921244e42011-07-20 16:36:301153 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ee3d3ad2011-02-04 00:42:211154 if (!animation_update_pending_) {
1155 animation_update_pending_ = true;
[email protected]350ce8702012-03-09 04:23:381156 if (!animation_timer_.IsRunning()) {
1157 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1158 &RenderWidget::AnimationCallback);
[email protected]52ccd0ea2011-02-16 01:09:051159 }
[email protected]ee3d3ad2011-02-04 00:42:211160 }
[email protected]5f8b1022011-01-21 23:34:501161}
1162
[email protected]4873c7d2009-07-16 06:36:281163void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301164 // TODO(darin): Eliminate this temporary.
1165 WebCursor cursor(cursor_info);
1166
initial.commit09911bf2008-07-26 23:55:291167 // Only send a SetCursor message if we need to make a change.
1168 if (!current_cursor_.IsEqual(cursor)) {
1169 current_cursor_ = cursor;
1170 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1171 }
1172}
1173
1174// We are supposed to get a single call to Show for a newly created RenderWidget
1175// that was created via RenderWidget::CreateWebView. So, we wait until this
1176// point to dispatch the ShowWidget message.
1177//
1178// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281179// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291180//
[email protected]4873c7d2009-07-16 06:36:281181void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291182 DCHECK(!did_show_) << "received extraneous Show call";
1183 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1184 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1185
[email protected]8de12d942010-11-17 20:42:441186 if (did_show_)
1187 return;
1188
1189 did_show_ = true;
1190 // NOTE: initial_pos_ may still have its default values at this point, but
1191 // that's okay. It'll be ignored if as_popup is false, or the browser
1192 // process will impose a default position otherwise.
1193 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1194 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291195}
1196
[email protected]4873c7d2009-07-16 06:36:281197void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291198}
1199
[email protected]4873c7d2009-07-16 06:36:281200void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291201}
1202
[email protected]2533ce12009-05-09 00:02:241203void RenderWidget::DoDeferredClose() {
1204 Send(new ViewHostMsg_Close(routing_id_));
1205}
1206
[email protected]4873c7d2009-07-16 06:36:281207void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291208 // If a page calls window.close() twice, we'll end up here twice, but that's
1209 // OK. It is safe to send multiple Close messages.
1210
[email protected]2533ce12009-05-09 00:02:241211 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1212 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1213 // could be closed before the JS finishes executing. So instead, post a
1214 // message back to the message loop, which won't run until the JS is
1215 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211216 MessageLoop::current()->PostTask(
1217 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291218}
1219
1220void RenderWidget::Close() {
1221 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281222 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291223 webwidget_ = NULL;
1224 }
1225}
1226
[email protected]4873c7d2009-07-16 06:36:281227WebRect RenderWidget::windowRect() {
1228 if (pending_window_rect_count_)
1229 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241230
[email protected]b3f2b912009-04-09 16:18:521231 gfx::Rect rect;
1232 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281233 return rect;
initial.commit09911bf2008-07-26 23:55:291234}
1235
[email protected]8a9d6ca32011-06-06 20:11:301236void RenderWidget::setToolTipText(const WebKit::WebString& text,
1237 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541238 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301239}
1240
[email protected]4873c7d2009-07-16 06:36:281241void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291242 if (did_show_) {
1243 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241244 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291245 } else {
1246 initial_pos_ = pos;
1247 }
1248}
1249
[email protected]2533ce12009-05-09 00:02:241250void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1251 pending_window_rect_ = rect;
1252 pending_window_rect_count_++;
1253}
1254
[email protected]4873c7d2009-07-16 06:36:281255WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241256 if (pending_window_rect_count_) {
1257 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1258 // the RootWindowRect is probably going to return wrong results since the
1259 // browser may not have processed the Move yet. There isn't really anything
1260 // good to do in this case, and it shouldn't happen - since this size is
1261 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281262 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241263 }
1264
[email protected]b3f2b912009-04-09 16:18:521265 gfx::Rect rect;
1266 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281267 return rect;
[email protected]d4547452008-08-28 18:36:371268}
1269
[email protected]4873c7d2009-07-16 06:36:281270WebRect RenderWidget::windowResizerRect() {
1271 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191272}
1273
[email protected]fa7b1dc2010-06-23 17:53:041274void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031275 // To prevent this renderer process from sending unnecessary IPC messages to
1276 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041277 // only during the input method attached to the browser process is active.
1278 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291279}
1280
[email protected]fa7b1dc2010-06-23 17:53:041281void RenderWidget::OnImeSetComposition(
1282 const string16& text,
1283 const std::vector<WebCompositionUnderline>& underlines,
1284 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281285 if (!webwidget_)
1286 return;
[email protected]d4cff272011-05-02 15:46:011287 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041288 text, WebVector<WebCompositionUnderline>(underlines),
1289 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011290 // Setting the IME composition was successful. Send the new composition
1291 // range to the browser.
1292 ui::Range range(ui::Range::InvalidRange());
1293 size_t location, length;
1294 if (webwidget_->compositionRange(&location, &length)) {
1295 range.set_start(location);
1296 range.set_end(location + length);
1297 }
1298 // The IME was cancelled via the Esc key, so just send back the caret.
1299 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1300 range.set_start(location);
1301 range.set_end(location + length);
1302 }
1303 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1304 } else {
[email protected]fa7b1dc2010-06-23 17:53:041305 // If we failed to set the composition text, then we need to let the browser
1306 // process to cancel the input method's ongoing composition session, to make
1307 // sure we are in a consistent state.
1308 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011309
1310 // Send an updated IME range with just the caret range.
1311 ui::Range range(ui::Range::InvalidRange());
1312 size_t location, length;
1313 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1314 range.set_start(location);
1315 range.set_end(location + length);
1316 }
1317 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261318 }
[email protected]fa7b1dc2010-06-23 17:53:041319}
1320
[email protected]4de6d1692011-10-12 08:45:441321void RenderWidget::OnImeConfirmComposition(
1322 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041323 if (!webwidget_)
1324 return;
1325
1326 handling_input_event_ = true;
1327 webwidget_->confirmComposition(text);
1328 handling_input_event_ = false;
1329
[email protected]d4cff272011-05-02 15:46:011330 // Send an updated IME range with just the caret range.
1331 ui::Range range(ui::Range::InvalidRange());
1332 size_t location, length;
1333 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1334 range.set_start(location);
1335 range.set_end(location + length);
1336 }
1337 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291338}
1339
[email protected]948f7ab72010-05-28 23:48:081340// This message causes the renderer to render an image of the
1341// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491342void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091343 int tag,
[email protected]948f7ab72010-05-28 23:48:081344 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491345 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001346 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1347 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251348 // Close our unused handle.
1349#if defined(OS_WIN)
1350 ::CloseHandle(dib_handle);
1351#elif defined(OS_MACOSX)
1352 base::SharedMemory::CloseHandle(dib_handle);
1353#endif
1354 }
[email protected]d65adb12010-04-28 17:26:491355 return;
[email protected]45c6aad32010-11-11 04:46:251356 }
[email protected]d65adb12010-04-28 17:26:491357
[email protected]948f7ab72010-05-28 23:48:081358 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491359 // If one of these is empty, then we just return the dib we were
1360 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091361 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491362 return;
1363 }
1364
1365 // Map the given DIB ID into this process, and unmap it at the end
1366 // of this function.
[email protected]45c6aad32010-11-11 04:46:251367 scoped_ptr<TransportDIB> paint_at_size_buffer(
1368 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301369
1370 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491371 float x_scale = static_cast<float>(desired_size.width()) /
1372 static_cast<float>(canvas_size.width());
1373 float y_scale = static_cast<float>(desired_size.height()) /
1374 static_cast<float>(canvas_size.height());
1375
[email protected]ee8d6fd2010-05-26 17:05:481376 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491377 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1378 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481379 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491380
[email protected]36808ad2010-10-20 19:18:301381 scoped_ptr<skia::PlatformCanvas> canvas(
1382 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1383 canvas_size.height()));
1384 if (!canvas.get()) {
1385 NOTREACHED();
1386 return;
1387 }
1388
[email protected]d65adb12010-04-28 17:26:491389 // Reset bounds to what we actually received, but they should be the
1390 // same.
1391 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1392 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1393 bounds.set_width(canvas->getDevice()->width());
1394 bounds.set_height(canvas->getDevice()->height());
1395
1396 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081397 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491398 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1399
[email protected]948f7ab72010-05-28 23:48:081400 // Have to make sure we're laid out at the right size before
1401 // rendering.
1402 gfx::Size old_size = webwidget_->size();
1403 webwidget_->resize(page_size);
1404 webwidget_->layout();
1405
[email protected]d65adb12010-04-28 17:26:491406 // Paint the entire thing (using original bounds, not scaled bounds).
1407 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1408 canvas->restore();
1409
[email protected]948f7ab72010-05-28 23:48:081410 // Return the widget to its previous size.
1411 webwidget_->resize(old_size);
1412
[email protected]c88c9442010-07-19 18:55:091413 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491414}
1415
[email protected]ec7dc112008-08-06 05:30:121416void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1417 // During shutdown we can just ignore this message.
1418 if (!webwidget_)
1419 return;
1420
1421 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561422 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041423 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461424 scheduleComposite();
1425 } else {
1426 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1427 didInvalidateRect(repaint_rect);
1428 }
[email protected]ec7dc112008-08-06 05:30:121429}
1430
[email protected]4873c7d2009-07-16 06:36:281431void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111432 if (!webwidget_)
1433 return;
[email protected]4873c7d2009-07-16 06:36:281434 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111435}
1436
[email protected]4b03e292012-02-13 18:40:071437void RenderWidget::OnInvertWebContent(bool invert) {
1438 if (invert_ == invert)
1439 return;
1440
1441 invert_ = invert;
1442
1443 if (invert_ && !invert_paint_.get()) {
1444 // Gamma-aware color inversion: each source pixel value x is normally
1445 // displayed on a computer monitor with a gamma correction x^gamma,
1446 // where gamma is typically in the range 1.8...2.2. By approximating
1447 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1448 uint8_t table[256];
1449 for (unsigned int i = 0; i < 256; i++) {
1450 double value = i / 255.0;
1451 value = sqrt(1 - (value * value));
1452 table[i] = static_cast<uint8_t>(255 * value);
1453 }
1454
1455 // Create a Skia Paint with this inverting color map.
1456 invert_paint_.reset(new SkPaint());
1457 invert_paint_->setStyle(SkPaint::kFill_Style);
1458 invert_paint_->setColor(SK_ColorBLACK);
1459 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1460 NULL, table, table, table);
1461 invert_paint_->setColorFilter(filter);
1462 filter->unref();
1463 }
1464
1465 OnMsgRepaint(size_);
1466}
1467
[email protected]719b36f2010-12-22 20:36:461468webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151469 const gfx::Rect& paint_bounds,
1470 TransportDIB** dib,
1471 gfx::Rect* location,
1472 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461473 // Bare RenderWidgets don't support optimized plugin painting.
1474 return NULL;
[email protected]ca4847f2010-09-24 05:39:151475}
1476
[email protected]bcaf2272011-02-15 15:29:431477gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521478 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431479 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521480}
1481
[email protected]bee16aab2009-08-26 15:55:031482void RenderWidget::SetHidden(bool hidden) {
1483 if (is_hidden_ == hidden)
1484 return;
1485
1486 // The status has changed. Tell the RenderThread about it.
1487 is_hidden_ = hidden;
1488 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271489 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031490 else
[email protected]380244092011-10-07 17:26:271491 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031492}
1493
[email protected]2b624c562011-10-27 22:58:261494void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261495 if (!webwidget_)
1496 return;
1497
1498 if (is_fullscreen_) {
1499 webwidget_->willExitFullScreen();
1500 } else {
1501 webwidget_->willEnterFullScreen();
1502 }
[email protected]2b624c562011-10-27 22:58:261503}
1504
1505void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261506 if (!webwidget_)
1507 return;
1508
1509 if (is_fullscreen_) {
1510 webwidget_->didEnterFullScreen();
1511 } else {
1512 webwidget_->didExitFullScreen();
1513 }
[email protected]2b624c562011-10-27 22:58:261514}
1515
[email protected]699ab0d2009-04-23 23:19:141516void RenderWidget::SetBackground(const SkBitmap& background) {
1517 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461518
[email protected]699ab0d2009-04-23 23:19:141519 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281520 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141521}
1522
[email protected]674741932009-02-04 23:44:461523bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051524 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461525}
1526
1527bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051528 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461529}
1530
1531void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051532 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461533}
1534
1535void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051536 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461537}
1538
1539void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051540 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461541}
1542
[email protected]e99ef6f2011-10-16 01:13:001543void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041544 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291545 return;
[email protected]fa7b1dc2010-06-23 17:53:041546
[email protected]ad26ef42011-06-17 07:59:451547 ui::TextInputType new_type = GetTextInputType();
1548 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001549 // Only sends text input type and compose inline to the browser process if
1550 // they are changed.
1551 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451552 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041553 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451554 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001555 Send(new ViewHostMsg_TextInputStateChanged(
1556 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291557 }
initial.commit09911bf2008-07-26 23:55:291558}
1559
[email protected]3f783362011-10-21 22:40:501560void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1561 WebRect start_webrect;
1562 WebRect end_webrect;
1563 webwidget_->selectionBounds(start_webrect, end_webrect);
1564 *start = start_webrect;
1565 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321566}
1567
[email protected]e99ef6f2011-10-16 01:13:001568void RenderWidget::UpdateSelectionBounds() {
1569 if (!webwidget_)
1570 return;
1571
[email protected]3f783362011-10-21 22:40:501572 gfx::Rect start_rect;
1573 gfx::Rect end_rect;
1574 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001575 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1576 return;
1577
1578 selection_start_rect_ = start_rect;
1579 selection_end_rect_ = end_rect;
1580 Send(new ViewHostMsg_SelectionBoundsChanged(
1581 routing_id_, selection_start_rect_, selection_end_rect_));
1582}
1583
[email protected]73bf95812011-10-12 11:38:321584// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451585COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1586 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1587COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1588 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1589COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1590 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181591COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1592 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1593COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1594 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1595COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1596 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1597COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1598 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1599COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1600 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451601
1602ui::TextInputType RenderWidget::GetTextInputType() {
1603 if (webwidget_) {
1604 int type = webwidget_->textInputType();
1605 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181606 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451607 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1608 return static_cast<ui::TextInputType>(type);
1609 }
1610 return ui::TEXT_INPUT_TYPE_NONE;
1611}
1612
1613bool RenderWidget::CanComposeInline() {
1614 return true;
[email protected]56ea1a62011-05-30 07:05:571615}
1616
[email protected]4873c7d2009-07-16 06:36:281617WebScreenInfo RenderWidget::screenInfo() {
[email protected]6fd35b72012-03-01 19:46:411618 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281619}
1620
[email protected]fa7b1dc2010-06-23 17:53:041621void RenderWidget::resetInputMethod() {
1622 if (!input_method_is_active_)
1623 return;
1624
1625 // If the last text input type is not None, then we should finish any
1626 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451627 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041628 // If a composition text exists, then we need to let the browser process
1629 // to cancel the input method's ongoing composition session.
1630 if (webwidget_->confirmComposition())
1631 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1632 }
[email protected]d4cff272011-05-02 15:46:011633
1634 // Send an updated IME range with the current caret rect.
1635 ui::Range range(ui::Range::InvalidRange());
1636 size_t location, length;
1637 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1638 range.set_start(location);
1639 range.set_end(location + length);
1640 }
1641 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041642}
1643
[email protected]f103ab72009-09-02 17:10:591644void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501645 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291646 size_t i = 0;
1647 for (; i < plugin_window_moves_.size(); ++i) {
1648 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581649 if (move.rects_valid) {
1650 plugin_window_moves_[i] = move;
1651 } else {
1652 plugin_window_moves_[i].visible = move.visible;
1653 }
initial.commit09911bf2008-07-26 23:55:291654 break;
1655 }
1656 }
1657
1658 if (i == plugin_window_moves_.size())
1659 plugin_window_moves_.push_back(move);
1660}
[email protected]268654772009-08-06 23:02:041661
1662void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1663 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1664 i != plugin_window_moves_.end(); ++i) {
1665 if (i->window == window) {
1666 plugin_window_moves_.erase(i);
1667 break;
1668 }
1669 }
1670}
[email protected]67bfb83f2011-09-22 03:36:371671
1672bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1673 return false;
1674}
[email protected]c3d45532011-10-07 19:20:401675
1676bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1677 return false;
1678}