blob: ee0f8973d5d1318ba451b3d46c3265751b6f040d [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]65225772011-05-12 21:10:24105 animation_task_posted_(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]8930d472009-02-21 08:05:28109 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27110 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18111 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
112 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:29113}
114
115RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11116 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21117 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35118 if (current_paint_buf_) {
119 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
120 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29121 }
[email protected]992db4c2011-05-12 15:37:15122 // If we are swapped out, we have released already.
123 if (!is_swapped_out_)
124 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29125}
126
[email protected]484955942010-08-19 16:13:18127// static
[email protected]8085dbc82008-09-26 22:53:44128RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]6fd35b72012-03-01 19:46:41129 WebKit::WebPopupType popup_type,
130 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29131 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41132 scoped_refptr<RenderWidget> widget(
133 new RenderWidget(popup_type, screen_info));
initial.commit09911bf2008-07-26 23:55:29134 widget->Init(opener_id); // adds reference
135 return widget;
136}
137
[email protected]484955942010-08-19 16:13:18138// static
139WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
140 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03141 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18142 break;
143 case WebKit::WebPopupTypeSelect:
144 case WebKit::WebPopupTypeSuggestion:
145 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44146 case WebKit::WebPopupTypePage:
147 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18148 default:
149 NOTREACHED();
150 }
151 return NULL;
152}
153
initial.commit09911bf2008-07-26 23:55:29154void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18155 DoInit(opener_id,
156 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56157 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
158 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18159}
160
[email protected]484955942010-08-19 16:13:18161void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06162 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18163 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29164 DCHECK(!webwidget_);
165
166 if (opener_id != MSG_ROUTING_NONE)
167 opener_id_ = opener_id;
168
[email protected]484955942010-08-19 16:13:18169 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29170
[email protected]380244092011-10-07 17:26:27171 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29172 if (result) {
[email protected]380244092011-10-07 17:26:27173 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29174 // Take a reference on behalf of the RenderThread. This will be balanced
175 // when we receive ViewMsg_Close.
176 AddRef();
177 } else {
178 DCHECK(false);
179 }
180}
181
182// This is used to complete pending inits and non-pending inits. For non-
183// pending cases, the parent will be the same as the current parent. This
184// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55185void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29186 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29187
188 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42189 host_window_set_ = true;
190
191 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29192
[email protected]6de74452009-02-25 18:04:59193 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29194}
195
[email protected]992db4c2011-05-12 15:37:15196void RenderWidget::SetSwappedOut(bool is_swapped_out) {
197 // We should only toggle between states.
198 DCHECK(is_swapped_out_ != is_swapped_out);
199 is_swapped_out_ = is_swapped_out;
200
201 // If we are swapping out, we will call ReleaseProcess, allowing the process
202 // to exit if all of its RenderViews are swapped out. We wait until the
203 // WasSwappedOut call to do this, to avoid showing the sad tab.
204 // If we are swapping in, we call AddRefProcess to prevent the process from
205 // exiting.
206 if (!is_swapped_out)
207 RenderProcess::current()->AddRefProcess();
208}
209
[email protected]a95986a82010-12-24 06:19:28210bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
211 bool handled = true;
212 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
213 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
214 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
215 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54216 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28217 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
218 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15219 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28220 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
221 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
222 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
223 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
224 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
225 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
226 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
227 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
228 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
229 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
230 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]4b03e292012-02-13 18:40:07231 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
[email protected]a95986a82010-12-24 06:19:28232 IPC_MESSAGE_UNHANDLED(handled = false)
233 IPC_END_MESSAGE_MAP()
234 return handled;
235}
initial.commit09911bf2008-07-26 23:55:29236
237bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15238 // Don't send any messages after the browser has told us to close, and filter
239 // most outgoing messages while swapped out.
240 if ((is_swapped_out_ &&
241 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
242 closing_) {
initial.commit09911bf2008-07-26 23:55:29243 delete message;
244 return false;
245 }
246
247 // If given a messsage without a routing ID, then assign our routing ID.
248 if (message->routing_id() == MSG_ROUTING_NONE)
249 message->set_routing_id(routing_id_);
250
[email protected]380244092011-10-07 17:26:27251 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44252}
253
[email protected]61e2b3cc2012-03-02 16:13:34254void RenderWidget::Resize(const gfx::Size& new_size,
255 const gfx::Rect& resizer_rect,
256 bool is_fullscreen,
257 ResizeAck resize_ack) {
258 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
259 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
260 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29261
[email protected]61e2b3cc2012-03-02 16:13:34262 // Ignore this during shutdown.
263 if (!webwidget_)
264 return;
265
266 // Remember the rect where the resize corner will be drawn.
267 resizer_rect_ = resizer_rect;
268
269 // NOTE: We may have entered fullscreen mode without changing our size.
270 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
271 if (fullscreen_change)
272 WillToggleFullscreen();
273 is_fullscreen_ = is_fullscreen;
274
275 if (size_ != new_size) {
276 // TODO(darin): We should not need to reset this here.
277 SetHidden(false);
278 needs_repainting_on_restore_ = false;
279
280 size_ = new_size;
281
282 paint_aggregator_.ClearPendingUpdate();
283
284 // When resizing, we want to wait to paint before ACK'ing the resize. This
285 // ensures that we only resize as fast as we can paint. We only need to
286 // send an ACK if we are resized to a non-empty rect.
287 webwidget_->resize(new_size);
288 if (!new_size.IsEmpty()) {
289 if (!is_accelerated_compositing_active_) {
290 // Resize should have caused an invalidation of the entire view.
291 DCHECK(paint_aggregator_.HasPendingUpdate());
292 }
293
294 // Send the Resize_ACK flag once we paint again if requested.
295 if (resize_ack == SEND_RESIZE_ACK)
296 set_next_paint_is_resize_ack();
297 }
298 }
299
300 if (fullscreen_change)
301 DidToggleFullscreen();
302
303 // If a resize ack is requested and it isn't set-up, then no more resizes will
304 // come in and in general things will go wrong.
305 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
306 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29307}
308
309void RenderWidget::OnClose() {
310 if (closing_)
311 return;
312 closing_ = true;
313
314 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03315 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27316 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03317 SetHidden(false);
318 }
initial.commit09911bf2008-07-26 23:55:29319
initial.commit09911bf2008-07-26 23:55:29320 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25321 // now. Post a task that only gets invoked when there are no nested message
322 // loops.
[email protected]32876ae2011-11-15 22:25:21323 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29324 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25325
326 // Balances the AddRef taken when we called AddRoute.
327 Release();
initial.commit09911bf2008-07-26 23:55:29328}
329
[email protected]61e2b3cc2012-03-02 16:13:34330// Got a response from the browser after the renderer decided to create a new
331// view.
332void RenderWidget::OnCreatingNewAck(
333 gfx::NativeViewId parent) {
334 DCHECK(routing_id_ != MSG_ROUTING_NONE);
335
336 CompleteInit(parent);
337}
338
[email protected]f21c613a2009-02-12 14:46:17339void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09340 const gfx::Rect& resizer_rect,
341 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34342 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29343}
344
[email protected]b5913d72012-02-07 22:26:54345void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
346 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59347 gfx::Rect view_rect(size_);
348
349 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
350 if (!old_damage_rect.IsEmpty())
351 paint_aggregator_.InvalidateRect(old_damage_rect);
352
353 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
354 if (!new_damage_rect.IsEmpty())
355 paint_aggregator_.InvalidateRect(new_damage_rect);
356
[email protected]b5913d72012-02-07 22:26:54357 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59358
[email protected]b5913d72012-02-07 22:26:54359 if (webwidget_)
360 webwidget_->didChangeWindowResizerRect();
361 }
362}
363
initial.commit09911bf2008-07-26 23:55:29364void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31365 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29366 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03367 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29368}
369
370void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31371 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29372 // During shutdown we can just ignore this message.
373 if (!webwidget_)
374 return;
375
376 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03377 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29378
379 if (!needs_repainting && !needs_repainting_on_restore_)
380 return;
381 needs_repainting_on_restore_ = false;
382
[email protected]d65adb12010-04-28 17:26:49383 // Tag the next paint as a restore ack, which is picked up by
384 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29385 set_next_paint_is_restore_ack();
386
387 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56388 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46389 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
390 } else {
391 scheduleComposite();
392 }
initial.commit09911bf2008-07-26 23:55:29393}
394
[email protected]992db4c2011-05-12 15:37:15395void RenderWidget::OnWasSwappedOut() {
396 // If we have been swapped out and no one else is using this process,
397 // it's safe to exit now. If we get swapped back in, we will call
398 // AddRefProcess in SetSwappedOut.
399 if (is_swapped_out_)
400 RenderProcess::current()->ReleaseProcess();
401}
402
[email protected]53d3f302009-12-21 04:42:05403void RenderWidget::OnRequestMoveAck() {
404 DCHECK(pending_window_rect_count_);
405 pending_window_rect_count_--;
406}
407
408void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58409 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21410 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05411 update_reply_pending_ = false;
412
[email protected]b4d08452010-10-05 17:34:35413 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
414 // have no current paint buffer.
415 if (current_paint_buf_) {
416 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
417 current_paint_buf_ = NULL;
418 }
419
[email protected]65225772011-05-12 21:10:24420 // If swapbuffers is still pending, then defer the update until the
421 // swapbuffers occurs.
422 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
423 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
424 return;
425 }
426
[email protected]29ed96a2012-02-04 18:12:16427 // Notify subclasses that software rendering was flushed to the screen.
428 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25429
initial.commit09911bf2008-07-26 23:55:29430 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24431 DoDeferredUpdateAndSendInputAck();
432}
433
[email protected]d0be63772011-12-20 23:18:04434bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24435 return false;
436}
437
[email protected]d0be63772011-12-20 23:18:04438void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24439 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21440 while (!updates_pending_swap_.empty()) {
441 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
442 updates_pending_swap_.pop_front();
443 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
444 // compositing pass, hence doesn't require an UpdateRect message.
445 if (msg)
446 Send(msg);
447 }
[email protected]65225772011-05-12 21:10:24448 num_swapbuffers_complete_pending_ = 0;
449 using_asynchronous_swapbuffers_ = false;
450 // Schedule another frame so the compositor learns about it.
451 scheduleComposite();
452}
453
[email protected]37a6f302011-07-11 23:43:08454void RenderWidget::OnSwapBuffersPosted() {
455 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21456
457 if (using_asynchronous_swapbuffers_) {
458 ViewHostMsg_UpdateRect* msg = NULL;
459 // pending_update_params_ can be NULL if the swap doesn't correspond to an
460 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
461 // message.
462 if (pending_update_params_.get()) {
463 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
464 pending_update_params_.reset();
465 }
466 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08467 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21468 }
[email protected]37a6f302011-07-11 23:43:08469}
470
471void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24472 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16473
474 // Notify subclasses that composited rendering got flushed to the screen.
475 DidFlushPaint();
476
[email protected]65225772011-05-12 21:10:24477 // When compositing deactivates, we reset the swapbuffers pending count. The
478 // swapbuffers acks may still arrive, however.
479 if (num_swapbuffers_complete_pending_ == 0) {
480 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
481 return;
482 }
[email protected]aa4117f2011-12-09 22:19:21483 DCHECK(!updates_pending_swap_.empty());
484 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
485 updates_pending_swap_.pop_front();
486 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
487 // compositing pass, hence doesn't require an UpdateRect message.
488 if (msg)
489 Send(msg);
[email protected]65225772011-05-12 21:10:24490 num_swapbuffers_complete_pending_--;
491
492 // If update reply is still pending, then defer the update until that reply
493 // occurs.
[email protected]d0be63772011-12-20 23:18:04494 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24495 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
496 return;
497 }
498
499 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06500 // when we were previously rendering. However, if an invalidation task is not
501 // posted, there may be software rendering work pending. In that case, don't
502 // early out.
503 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24504 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
505 return;
506 }
507
[email protected]65225772011-05-12 21:10:24508 // Continue painting if necessary...
509 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29510}
511
initial.commit09911bf2008-07-26 23:55:29512void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24513 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56514 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29515
516 const char* data;
517 int data_length;
[email protected]5dd768212009-08-13 23:34:49518 handling_input_event_ = true;
519 if (!message.ReadData(&iter, &data, &data_length)) {
520 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29521 return;
[email protected]5dd768212009-08-13 23:34:49522 }
initial.commit09911bf2008-07-26 23:55:29523
524 const WebInputEvent* input_event =
525 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48526
[email protected]b68a0e52011-12-08 15:11:12527 bool is_keyboard_shortcut = false;
528 // is_keyboard_shortcut flag is only available for RawKeyDown events.
529 if (input_event->type == WebInputEvent::RawKeyDown)
530 message.ReadBool(&iter, &is_keyboard_shortcut);
531
[email protected]67bfb83f2011-09-22 03:36:37532 bool prevent_default = false;
533 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26534 const WebMouseEvent& mouse_event =
535 *static_cast<const WebMouseEvent*>(input_event);
536 TRACE_EVENT2("renderer", "HandleMouseMove",
537 "x", mouse_event.x, "y", mouse_event.y);
538 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37539 }
540
541 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12542 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
543 suppress_next_char_events_ = false;
544 if (!processed && webwidget_)
545 processed = webwidget_->handleInputEvent(*input_event);
546 }
547
548 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
549 // it's not processed by webkit, then we need to suppress the upcoming Char
550 // events.
551 if (!processed && is_keyboard_shortcut)
552 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29553
[email protected]a9fb30aa2011-10-06 06:58:46554 IPC::Message* response =
555 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
556 processed);
[email protected]e2824412009-02-27 01:57:05557
[email protected]353a34c2010-05-28 23:35:17558 if ((input_event->type == WebInputEvent::MouseMove ||
[email protected]d93fc462011-03-14 23:03:03559 input_event->type == WebInputEvent::MouseWheel ||
[email protected]d329a912012-01-27 01:55:01560 WebInputEvent::isTouchEventType(input_event->type)) &&
[email protected]552e6002009-11-19 05:24:57561 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24562 // We want to rate limit the input events in this case, so we'll wait for
563 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17564 if (pending_input_event_ack_.get()) {
565 // As two different kinds of events could cause us to postpone an ack
566 // we send it now, if we have one pending. The Browser should never
567 // send us the same kind of event we are delaying the ack for.
568 Send(pending_input_event_ack_.release());
569 }
[email protected]12fbad812009-09-01 18:21:24570 pending_input_event_ack_.reset(response);
571 } else {
572 Send(response);
573 }
574
[email protected]5dd768212009-08-13 23:34:49575 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48576
[email protected]67bfb83f2011-09-22 03:36:37577 if (!prevent_default) {
578 if (WebInputEvent::isKeyboardEventType(input_event->type))
579 DidHandleKeyEvent();
580 if (WebInputEvent::isMouseEventType(input_event->type))
581 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24582 if (WebInputEvent::isTouchEventType(input_event->type))
583 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37584 }
initial.commit09911bf2008-07-26 23:55:29585}
586
587void RenderWidget::OnMouseCaptureLost() {
588 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28589 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29590}
591
592void RenderWidget::OnSetFocus(bool enable) {
593 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33594 if (webwidget_)
595 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29596}
597
598void RenderWidget::ClearFocus() {
599 // We may have got the focus from the browser before this gets processed, in
600 // which case we do not want to unfocus ourself.
601 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28602 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29603}
604
[email protected]2d5d09d52009-06-15 14:29:21605void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00606 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21607 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06608 TRACE_EVENT2("renderer", "PaintRect",
609 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00610 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21611
612 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00613 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
614 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03615
[email protected]4b03e292012-02-13 18:40:07616 if (invert_) {
617 // Draw everything to a temporary bitmap and then apply an
618 // inverting color map to the result. This is balanced by an extra
619 // call to canvas->restore(), below.
620 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48621 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07622 canvas->saveLayer(&bounds, invert_paint_.get());
623 }
624
[email protected]699ab0d2009-04-23 23:19:14625 // If there is a custom background, tile it.
626 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14627 SkPaint paint;
628 SkShader* shader = SkShader::CreateBitmapShader(background_,
629 SkShader::kRepeat_TileMode,
630 SkShader::kRepeat_TileMode);
631 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20632
633 // Use kSrc_Mode to handle background_ transparency properly.
634 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
635
636 // Canvas could contain multiple update rects. Clip to given rect so that
637 // we don't accidentally clear other update rects.
638 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48639 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14640 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20641 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14642 }
643
[email protected]719b36f2010-12-22 20:36:46644 // First see if this rect is a plugin that can paint itself faster.
645 TransportDIB* optimized_dib = NULL;
646 gfx::Rect optimized_copy_rect, optimized_copy_location;
647 webkit::ppapi::PluginInstance* optimized_instance =
648 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
649 &optimized_copy_location,
650 &optimized_copy_rect);
651 if (optimized_instance) {
652 // This plugin can be optimize-painted and we can just ask it to paint
653 // itself. We don't actually need the TransportDIB in this case.
654 //
655 // This is an optimization for PPAPI plugins that know they're on top of
656 // the page content. If this rect is inside such a plugin, we can save some
657 // time and avoid re-rendering the page content which we know will be
658 // covered by the plugin later (this time can be significant, especially
659 // for a playing movie that is invalidating a lot).
660 //
661 // In the plugin movie case, hopefully the similar call to
662 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
663 // painting, because that avoids copying the plugin image to a different
664 // paint rect. Unfortunately, if anything on the page is animating other
665 // than the movie, it break this optimization since the union of the
666 // invalid regions will be larger than the plugin.
667 //
668 // This code optimizes that case, where we can still avoid painting in
669 // WebKit and filling the background (which can be slow) and just painting
670 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
671 // required.
672 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27673 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46674 } else {
675 // Normal painting case.
676 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
677
678 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35679 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46680 }
initial.commit09911bf2008-07-26 23:55:29681
[email protected]4b03e292012-02-13 18:40:07682 if (invert_)
683 canvas->restore();
684
[email protected]4fb66842009-12-04 21:41:00685 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00686 canvas->restore();
687}
688
689void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
690 skia::PlatformCanvas* canvas) {
691 static bool kPaintBorder =
692 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
693 if (!kPaintBorder)
694 return;
695
[email protected]53d3f302009-12-21 04:42:05696 // Cycle through these colors to help distinguish new paint rects.
697 const SkColor colors[] = {
698 SkColorSetARGB(0x3F, 0xFF, 0, 0),
699 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
700 SkColorSetARGB(0x3F, 0, 0, 0xFF),
701 };
702 static int color_selector = 0;
703
[email protected]4fb66842009-12-04 21:41:00704 SkPaint paint;
705 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05706 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00707 paint.setStrokeWidth(1);
708
709 SkIRect irect;
710 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
711 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29712}
713
[email protected]52ccd0ea2011-02-16 01:09:05714void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30715 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]52ccd0ea2011-02-16 01:09:05716 animation_task_posted_ = false;
[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]32876ae2011-11-15 22:25:21755 MessageLoop::current()->PostDelayedTask(
756 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this),
757 animationInterval);
[email protected]7c4329e2011-02-18 22:02:59758 animation_task_posted_ = true;
759 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30760 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59761 return;
[email protected]5f8b1022011-01-21 23:34:50762 }
[email protected]bd37ae252011-06-03 01:28:18763 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]7c4329e2011-02-18 22:02:59764 if (animation_task_posted_)
765 return;
766 // This code uses base::Time::Now() to calculate the floor and next fire
767 // time because javascript's Date object uses base::Time::Now(). The
768 // message loop uses base::TimeTicks, which on windows can have a
769 // different granularity than base::Time.
770 // The upshot of all this is that this function might be called before
771 // base::Time::Now() has advanced past the animation_floor_time_. To
772 // avoid exposing this delay to javascript, we keep posting delayed
773 // tasks until base::Time::Now() has advanced far enough.
[email protected]02798a982012-01-27 00:45:33774 base::TimeDelta delay = animation_floor_time_ - now;
[email protected]7c4329e2011-02-18 22:02:59775 animation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:21776 MessageLoop::current()->PostDelayedTask(
777 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), delay);
[email protected]5f8b1022011-01-21 23:34:50778}
779
[email protected]bd37ae252011-06-03 01:28:18780bool RenderWidget::IsRenderingVSynced() {
781 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
782 // not caught by this check. This will lead to artificially low frame rates
783 // for people who force vsync off at a driver level and expect Chrome to speed
784 // up.
785 return !has_disable_gpu_vsync_switch_;
786}
787
[email protected]65225772011-05-12 21:10:24788void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06789 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24790 invalidation_task_posted_ = false;
791 DoDeferredUpdateAndSendInputAck();
792}
793
794void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05795 DoDeferredUpdate();
796
797 if (pending_input_event_ack_.get())
798 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21799}
800
[email protected]552e6002009-11-19 05:24:57801void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58802 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08803
[email protected]65225772011-05-12 21:10:24804 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29805 return;
[email protected]05a980d7a2012-02-07 22:16:42806
807 if (!host_window_set_) {
808 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
809 return;
810 }
[email protected]aa4117f2011-12-09 22:19:21811 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24812 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
813 return;
814 }
[email protected]9ca84622011-06-02 23:46:39815 if (is_accelerated_compositing_active_ &&
816 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24817 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
818 return;
819 }
initial.commit09911bf2008-07-26 23:55:29820
[email protected]552e6002009-11-19 05:24:57821 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29822 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57823 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29824 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24825 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29826 return;
827 }
828
[email protected]05a980d7a2012-02-07 22:16:42829 if (is_accelerated_compositing_active_)
830 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
831
[email protected]0fb93f52011-05-18 23:13:56832 // Tracking of frame rate jitter
833 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]52ccd0ea2011-02-16 01:09:05834 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50835
[email protected]f98d7e3c2010-09-13 22:30:46836 // Layout may generate more invalidation. It may also enable the
837 // GPU acceleration, so make sure to run layout before we send the
838 // GpuRenderingActivated message.
839 webwidget_->layout();
840
[email protected]dcca3aa92012-02-17 23:03:37841 // The following two can result in further layout and possibly
842 // enable GPU acceleration so they need to be called before any painting
843 // is done.
844 UpdateTextInputState();
845 UpdateSelectionBounds();
846
[email protected]5f8b1022011-01-21 23:34:50847 // Suppress painting if nothing is dirty. This has to be done after updating
848 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24849 if (!paint_aggregator_.HasPendingUpdate()) {
850 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[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.
1016 if (is_accelerated_compositing_active_ && animation_task_posted_)
[email protected]552e6002009-11-19 05:24:571017 return;
1018
1019 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291020 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1021 // on the call stack.
1022 // 2) Allows us to collect more damage rects before painting to help coalesce
1023 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241024 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211025 MessageLoop::current()->PostTask(
1026 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291027}
1028
[email protected]4873c7d2009-07-16 06:36:281029void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461030 // Drop scrolls on the floor when we are in compositing mode.
1031 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561032 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461033 return;
1034
[email protected]552e6002009-11-19 05:24:571035 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481036 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571037 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1038 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291039 return;
1040
[email protected]552e6002009-11-19 05:24:571041 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1042
1043 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241044 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571045 return;
1046 if (!paint_aggregator_.HasPendingUpdate())
1047 return;
[email protected]aa4117f2011-12-09 22:19:211048 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241049 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1050 return;
1051
1052 // When GPU rendering, combine pending animations and invalidations into
1053 // a single update.
1054 if (is_accelerated_compositing_active_ && animation_task_posted_)
[email protected]552e6002009-11-19 05:24:571055 return;
1056
1057 // Perform updating asynchronously. This serves two purposes:
1058 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1059 // on the call stack.
1060 // 2) Allows us to collect more damage rects before painting to help coalesce
1061 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241062 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211063 MessageLoop::current()->PostTask(
1064 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291065}
1066
[email protected]244ac1892011-12-02 17:04:471067void RenderWidget::didAutoResize(const WebSize& new_size) {
1068 size_ = new_size;
1069}
1070
[email protected]3da12cb2011-10-08 02:25:041071void RenderWidget::didActivateCompositor(int compositor_identifier) {
[email protected]ea162f92011-10-04 23:08:221072 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1073
[email protected]f3150172011-10-22 02:28:451074 CompositorThread* compositor_thread =
1075 RenderThreadImpl::current()->compositor_thread();
1076 if (compositor_thread)
1077 compositor_thread->AddCompositor(routing_id_, compositor_identifier);
[email protected]3da12cb2011-10-08 02:25:041078
[email protected]aa4117f2011-12-09 22:19:211079 if (!is_accelerated_compositing_active_) {
1080 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1081 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1082 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1083 // going to switch to accelerated compositing, the GPU process may need
1084 // round-trips to the browser's UI thread before finishing the frame,
1085 // causing deadlocks if we delay the UpdateRect until we receive the
1086 // OnSwapBuffersComplete. So send a dummy message that will unblock the
1087 // browser's UI thread.
1088 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1089 }
1090
[email protected]ea162f92011-10-04 23:08:221091 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421092 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241093 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221094}
1095
1096void RenderWidget::didDeactivateCompositor() {
1097 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1098
1099 is_accelerated_compositing_active_ = false;
1100 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1101 routing_id_, is_accelerated_compositing_active_));
1102
[email protected]ea162f92011-10-04 23:08:221103 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241104 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561105}
1106
[email protected]58264a32011-11-17 23:36:151107void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501108 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351109 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1110 // NOTE: Tests may break if this event is renamed or moved.
1111 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161112 // Notify subclasses that we initiated the paint operation.
1113 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151114}
1115
1116void RenderWidget::didCompleteSwapBuffers() {
[email protected]aa4117f2011-12-09 22:19:211117 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151118 return;
1119
1120 if (!next_paint_flags_ && !plugin_window_moves_.size())
1121 return;
1122
1123 ViewHostMsg_UpdateRect_Params params;
1124 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151125 params.plugin_window_moves.swap(plugin_window_moves_);
1126 params.flags = next_paint_flags_;
1127 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121128 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151129
1130 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1131 next_paint_flags_ = 0;
1132}
1133
[email protected]f98d7e3c2010-09-13 22:30:461134void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041135 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401136 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041137 } else {
[email protected]c3d45532011-10-07 19:20:401138 // TODO(nduca): replace with something a little less hacky. The reason this
1139 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1140 // contains a lot of host-renderer synchronization logic that is still
1141 // important for the accelerated compositing case. The option of simply
1142 // duplicating all that code is less desirable than "faking out" the
1143 // invalidation path using a magical damage rect.
1144 didInvalidateRect(WebRect(0, 0, 1, 1));
1145 }
[email protected]f98d7e3c2010-09-13 22:30:461146}
1147
[email protected]5f8b1022011-01-21 23:34:501148void RenderWidget::scheduleAnimation() {
[email protected]921244e42011-07-20 16:36:301149 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ee3d3ad2011-02-04 00:42:211150 if (!animation_update_pending_) {
1151 animation_update_pending_ = true;
[email protected]52ccd0ea2011-02-16 01:09:051152 if (!animation_task_posted_) {
1153 animation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211154 MessageLoop::current()->PostTask(
1155 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this));
[email protected]52ccd0ea2011-02-16 01:09:051156 }
[email protected]ee3d3ad2011-02-04 00:42:211157 }
[email protected]5f8b1022011-01-21 23:34:501158}
1159
[email protected]4873c7d2009-07-16 06:36:281160void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301161 // TODO(darin): Eliminate this temporary.
1162 WebCursor cursor(cursor_info);
1163
initial.commit09911bf2008-07-26 23:55:291164 // Only send a SetCursor message if we need to make a change.
1165 if (!current_cursor_.IsEqual(cursor)) {
1166 current_cursor_ = cursor;
1167 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1168 }
1169}
1170
1171// We are supposed to get a single call to Show for a newly created RenderWidget
1172// that was created via RenderWidget::CreateWebView. So, we wait until this
1173// point to dispatch the ShowWidget message.
1174//
1175// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281176// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291177//
[email protected]4873c7d2009-07-16 06:36:281178void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291179 DCHECK(!did_show_) << "received extraneous Show call";
1180 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1181 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1182
[email protected]8de12d942010-11-17 20:42:441183 if (did_show_)
1184 return;
1185
1186 did_show_ = true;
1187 // NOTE: initial_pos_ may still have its default values at this point, but
1188 // that's okay. It'll be ignored if as_popup is false, or the browser
1189 // process will impose a default position otherwise.
1190 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1191 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291192}
1193
[email protected]4873c7d2009-07-16 06:36:281194void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291195}
1196
[email protected]4873c7d2009-07-16 06:36:281197void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291198}
1199
[email protected]2533ce12009-05-09 00:02:241200void RenderWidget::DoDeferredClose() {
1201 Send(new ViewHostMsg_Close(routing_id_));
1202}
1203
[email protected]4873c7d2009-07-16 06:36:281204void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291205 // If a page calls window.close() twice, we'll end up here twice, but that's
1206 // OK. It is safe to send multiple Close messages.
1207
[email protected]2533ce12009-05-09 00:02:241208 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1209 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1210 // could be closed before the JS finishes executing. So instead, post a
1211 // message back to the message loop, which won't run until the JS is
1212 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211213 MessageLoop::current()->PostTask(
1214 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291215}
1216
1217void RenderWidget::Close() {
1218 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281219 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291220 webwidget_ = NULL;
1221 }
1222}
1223
[email protected]4873c7d2009-07-16 06:36:281224WebRect RenderWidget::windowRect() {
1225 if (pending_window_rect_count_)
1226 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241227
[email protected]b3f2b912009-04-09 16:18:521228 gfx::Rect rect;
1229 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281230 return rect;
initial.commit09911bf2008-07-26 23:55:291231}
1232
[email protected]8a9d6ca32011-06-06 20:11:301233void RenderWidget::setToolTipText(const WebKit::WebString& text,
1234 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541235 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301236}
1237
[email protected]4873c7d2009-07-16 06:36:281238void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291239 if (did_show_) {
1240 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241241 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291242 } else {
1243 initial_pos_ = pos;
1244 }
1245}
1246
[email protected]2533ce12009-05-09 00:02:241247void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1248 pending_window_rect_ = rect;
1249 pending_window_rect_count_++;
1250}
1251
[email protected]4873c7d2009-07-16 06:36:281252WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241253 if (pending_window_rect_count_) {
1254 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1255 // the RootWindowRect is probably going to return wrong results since the
1256 // browser may not have processed the Move yet. There isn't really anything
1257 // good to do in this case, and it shouldn't happen - since this size is
1258 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281259 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241260 }
1261
[email protected]b3f2b912009-04-09 16:18:521262 gfx::Rect rect;
1263 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281264 return rect;
[email protected]d4547452008-08-28 18:36:371265}
1266
[email protected]4873c7d2009-07-16 06:36:281267WebRect RenderWidget::windowResizerRect() {
1268 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191269}
1270
[email protected]fa7b1dc2010-06-23 17:53:041271void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031272 // To prevent this renderer process from sending unnecessary IPC messages to
1273 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041274 // only during the input method attached to the browser process is active.
1275 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291276}
1277
[email protected]fa7b1dc2010-06-23 17:53:041278void RenderWidget::OnImeSetComposition(
1279 const string16& text,
1280 const std::vector<WebCompositionUnderline>& underlines,
1281 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281282 if (!webwidget_)
1283 return;
[email protected]d4cff272011-05-02 15:46:011284 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041285 text, WebVector<WebCompositionUnderline>(underlines),
1286 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011287 // Setting the IME composition was successful. Send the new composition
1288 // range to the browser.
1289 ui::Range range(ui::Range::InvalidRange());
1290 size_t location, length;
1291 if (webwidget_->compositionRange(&location, &length)) {
1292 range.set_start(location);
1293 range.set_end(location + length);
1294 }
1295 // The IME was cancelled via the Esc key, so just send back the caret.
1296 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1297 range.set_start(location);
1298 range.set_end(location + length);
1299 }
1300 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1301 } else {
[email protected]fa7b1dc2010-06-23 17:53:041302 // If we failed to set the composition text, then we need to let the browser
1303 // process to cancel the input method's ongoing composition session, to make
1304 // sure we are in a consistent state.
1305 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011306
1307 // Send an updated IME range with just the caret range.
1308 ui::Range range(ui::Range::InvalidRange());
1309 size_t location, length;
1310 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1311 range.set_start(location);
1312 range.set_end(location + length);
1313 }
1314 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261315 }
[email protected]fa7b1dc2010-06-23 17:53:041316}
1317
[email protected]4de6d1692011-10-12 08:45:441318void RenderWidget::OnImeConfirmComposition(
1319 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041320 if (!webwidget_)
1321 return;
1322
1323 handling_input_event_ = true;
1324 webwidget_->confirmComposition(text);
1325 handling_input_event_ = false;
1326
[email protected]d4cff272011-05-02 15:46:011327 // Send an updated IME range with just the caret range.
1328 ui::Range range(ui::Range::InvalidRange());
1329 size_t location, length;
1330 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1331 range.set_start(location);
1332 range.set_end(location + length);
1333 }
1334 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291335}
1336
[email protected]948f7ab72010-05-28 23:48:081337// This message causes the renderer to render an image of the
1338// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491339void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091340 int tag,
[email protected]948f7ab72010-05-28 23:48:081341 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491342 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001343 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1344 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251345 // Close our unused handle.
1346#if defined(OS_WIN)
1347 ::CloseHandle(dib_handle);
1348#elif defined(OS_MACOSX)
1349 base::SharedMemory::CloseHandle(dib_handle);
1350#endif
1351 }
[email protected]d65adb12010-04-28 17:26:491352 return;
[email protected]45c6aad32010-11-11 04:46:251353 }
[email protected]d65adb12010-04-28 17:26:491354
[email protected]948f7ab72010-05-28 23:48:081355 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491356 // If one of these is empty, then we just return the dib we were
1357 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091358 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491359 return;
1360 }
1361
1362 // Map the given DIB ID into this process, and unmap it at the end
1363 // of this function.
[email protected]45c6aad32010-11-11 04:46:251364 scoped_ptr<TransportDIB> paint_at_size_buffer(
1365 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301366
1367 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491368 float x_scale = static_cast<float>(desired_size.width()) /
1369 static_cast<float>(canvas_size.width());
1370 float y_scale = static_cast<float>(desired_size.height()) /
1371 static_cast<float>(canvas_size.height());
1372
[email protected]ee8d6fd2010-05-26 17:05:481373 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491374 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1375 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481376 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491377
[email protected]36808ad2010-10-20 19:18:301378 scoped_ptr<skia::PlatformCanvas> canvas(
1379 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1380 canvas_size.height()));
1381 if (!canvas.get()) {
1382 NOTREACHED();
1383 return;
1384 }
1385
[email protected]d65adb12010-04-28 17:26:491386 // Reset bounds to what we actually received, but they should be the
1387 // same.
1388 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1389 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1390 bounds.set_width(canvas->getDevice()->width());
1391 bounds.set_height(canvas->getDevice()->height());
1392
1393 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081394 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491395 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1396
[email protected]948f7ab72010-05-28 23:48:081397 // Have to make sure we're laid out at the right size before
1398 // rendering.
1399 gfx::Size old_size = webwidget_->size();
1400 webwidget_->resize(page_size);
1401 webwidget_->layout();
1402
[email protected]d65adb12010-04-28 17:26:491403 // Paint the entire thing (using original bounds, not scaled bounds).
1404 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1405 canvas->restore();
1406
[email protected]948f7ab72010-05-28 23:48:081407 // Return the widget to its previous size.
1408 webwidget_->resize(old_size);
1409
[email protected]c88c9442010-07-19 18:55:091410 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491411}
1412
[email protected]ec7dc112008-08-06 05:30:121413void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1414 // During shutdown we can just ignore this message.
1415 if (!webwidget_)
1416 return;
1417
1418 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561419 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041420 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461421 scheduleComposite();
1422 } else {
1423 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1424 didInvalidateRect(repaint_rect);
1425 }
[email protected]ec7dc112008-08-06 05:30:121426}
1427
[email protected]4873c7d2009-07-16 06:36:281428void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111429 if (!webwidget_)
1430 return;
[email protected]4873c7d2009-07-16 06:36:281431 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111432}
1433
[email protected]4b03e292012-02-13 18:40:071434void RenderWidget::OnInvertWebContent(bool invert) {
1435 if (invert_ == invert)
1436 return;
1437
1438 invert_ = invert;
1439
1440 if (invert_ && !invert_paint_.get()) {
1441 // Gamma-aware color inversion: each source pixel value x is normally
1442 // displayed on a computer monitor with a gamma correction x^gamma,
1443 // where gamma is typically in the range 1.8...2.2. By approximating
1444 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1445 uint8_t table[256];
1446 for (unsigned int i = 0; i < 256; i++) {
1447 double value = i / 255.0;
1448 value = sqrt(1 - (value * value));
1449 table[i] = static_cast<uint8_t>(255 * value);
1450 }
1451
1452 // Create a Skia Paint with this inverting color map.
1453 invert_paint_.reset(new SkPaint());
1454 invert_paint_->setStyle(SkPaint::kFill_Style);
1455 invert_paint_->setColor(SK_ColorBLACK);
1456 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1457 NULL, table, table, table);
1458 invert_paint_->setColorFilter(filter);
1459 filter->unref();
1460 }
1461
1462 OnMsgRepaint(size_);
1463}
1464
[email protected]719b36f2010-12-22 20:36:461465webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151466 const gfx::Rect& paint_bounds,
1467 TransportDIB** dib,
1468 gfx::Rect* location,
1469 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461470 // Bare RenderWidgets don't support optimized plugin painting.
1471 return NULL;
[email protected]ca4847f2010-09-24 05:39:151472}
1473
[email protected]bcaf2272011-02-15 15:29:431474gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521475 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431476 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521477}
1478
[email protected]bee16aab2009-08-26 15:55:031479void RenderWidget::SetHidden(bool hidden) {
1480 if (is_hidden_ == hidden)
1481 return;
1482
1483 // The status has changed. Tell the RenderThread about it.
1484 is_hidden_ = hidden;
1485 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271486 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031487 else
[email protected]380244092011-10-07 17:26:271488 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031489}
1490
[email protected]2b624c562011-10-27 22:58:261491void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261492 if (!webwidget_)
1493 return;
1494
1495 if (is_fullscreen_) {
1496 webwidget_->willExitFullScreen();
1497 } else {
1498 webwidget_->willEnterFullScreen();
1499 }
[email protected]2b624c562011-10-27 22:58:261500}
1501
1502void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261503 if (!webwidget_)
1504 return;
1505
1506 if (is_fullscreen_) {
1507 webwidget_->didEnterFullScreen();
1508 } else {
1509 webwidget_->didExitFullScreen();
1510 }
[email protected]2b624c562011-10-27 22:58:261511}
1512
[email protected]699ab0d2009-04-23 23:19:141513void RenderWidget::SetBackground(const SkBitmap& background) {
1514 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461515
[email protected]699ab0d2009-04-23 23:19:141516 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281517 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141518}
1519
[email protected]674741932009-02-04 23:44:461520bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051521 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461522}
1523
1524bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051525 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461526}
1527
1528void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051529 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461530}
1531
1532void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051533 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461534}
1535
1536void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051537 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461538}
1539
[email protected]e99ef6f2011-10-16 01:13:001540void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041541 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291542 return;
[email protected]fa7b1dc2010-06-23 17:53:041543
[email protected]ad26ef42011-06-17 07:59:451544 ui::TextInputType new_type = GetTextInputType();
1545 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001546 // Only sends text input type and compose inline to the browser process if
1547 // they are changed.
1548 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451549 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041550 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451551 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001552 Send(new ViewHostMsg_TextInputStateChanged(
1553 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291554 }
initial.commit09911bf2008-07-26 23:55:291555}
1556
[email protected]3f783362011-10-21 22:40:501557void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1558 WebRect start_webrect;
1559 WebRect end_webrect;
1560 webwidget_->selectionBounds(start_webrect, end_webrect);
1561 *start = start_webrect;
1562 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321563}
1564
[email protected]e99ef6f2011-10-16 01:13:001565void RenderWidget::UpdateSelectionBounds() {
1566 if (!webwidget_)
1567 return;
1568
[email protected]3f783362011-10-21 22:40:501569 gfx::Rect start_rect;
1570 gfx::Rect end_rect;
1571 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001572 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1573 return;
1574
1575 selection_start_rect_ = start_rect;
1576 selection_end_rect_ = end_rect;
1577 Send(new ViewHostMsg_SelectionBoundsChanged(
1578 routing_id_, selection_start_rect_, selection_end_rect_));
1579}
1580
[email protected]73bf95812011-10-12 11:38:321581// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451582COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1583 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1584COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1585 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1586COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1587 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181588COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1589 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1590COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1591 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1592COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1593 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1594COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1595 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1596COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1597 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451598
1599ui::TextInputType RenderWidget::GetTextInputType() {
1600 if (webwidget_) {
1601 int type = webwidget_->textInputType();
1602 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181603 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451604 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1605 return static_cast<ui::TextInputType>(type);
1606 }
1607 return ui::TEXT_INPUT_TYPE_NONE;
1608}
1609
1610bool RenderWidget::CanComposeInline() {
1611 return true;
[email protected]56ea1a62011-05-30 07:05:571612}
1613
[email protected]4873c7d2009-07-16 06:36:281614WebScreenInfo RenderWidget::screenInfo() {
[email protected]6fd35b72012-03-01 19:46:411615 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281616}
1617
[email protected]fa7b1dc2010-06-23 17:53:041618void RenderWidget::resetInputMethod() {
1619 if (!input_method_is_active_)
1620 return;
1621
1622 // If the last text input type is not None, then we should finish any
1623 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451624 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041625 // If a composition text exists, then we need to let the browser process
1626 // to cancel the input method's ongoing composition session.
1627 if (webwidget_->confirmComposition())
1628 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1629 }
[email protected]d4cff272011-05-02 15:46:011630
1631 // Send an updated IME range with the current caret rect.
1632 ui::Range range(ui::Range::InvalidRange());
1633 size_t location, length;
1634 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1635 range.set_start(location);
1636 range.set_end(location + length);
1637 }
1638 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041639}
1640
[email protected]f103ab72009-09-02 17:10:591641void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501642 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291643 size_t i = 0;
1644 for (; i < plugin_window_moves_.size(); ++i) {
1645 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581646 if (move.rects_valid) {
1647 plugin_window_moves_[i] = move;
1648 } else {
1649 plugin_window_moves_[i].visible = move.visible;
1650 }
initial.commit09911bf2008-07-26 23:55:291651 break;
1652 }
1653 }
1654
1655 if (i == plugin_window_moves_.size())
1656 plugin_window_moves_.push_back(move);
1657}
[email protected]268654772009-08-06 23:02:041658
1659void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1660 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1661 i != plugin_window_moves_.end(); ++i) {
1662 if (i->window == window) {
1663 plugin_window_moves_.erase(i);
1664 break;
1665 }
1666 }
1667}
[email protected]67bfb83f2011-09-22 03:36:371668
1669bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1670 return false;
1671}
[email protected]c3d45532011-10-07 19:20:401672
1673bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1674 return false;
1675}