blob: b77715722d0d94ac36eaabf3d95d1b55b465fb4f [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 }
297 }
298
299 if (fullscreen_change)
300 DidToggleFullscreen();
301
302 // If a resize ack is requested and it isn't set-up, then no more resizes will
303 // come in and in general things will go wrong.
304 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
305 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29306}
307
308void RenderWidget::OnClose() {
309 if (closing_)
310 return;
311 closing_ = true;
312
313 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03314 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27315 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03316 SetHidden(false);
317 }
initial.commit09911bf2008-07-26 23:55:29318
initial.commit09911bf2008-07-26 23:55:29319 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25320 // now. Post a task that only gets invoked when there are no nested message
321 // loops.
[email protected]32876ae2011-11-15 22:25:21322 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29323 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25324
325 // Balances the AddRef taken when we called AddRoute.
326 Release();
initial.commit09911bf2008-07-26 23:55:29327}
328
[email protected]61e2b3cc2012-03-02 16:13:34329// Got a response from the browser after the renderer decided to create a new
330// view.
331void RenderWidget::OnCreatingNewAck(
332 gfx::NativeViewId parent) {
333 DCHECK(routing_id_ != MSG_ROUTING_NONE);
334
335 CompleteInit(parent);
336}
337
[email protected]f21c613a2009-02-12 14:46:17338void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09339 const gfx::Rect& resizer_rect,
340 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34341 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29342}
343
[email protected]b5913d72012-02-07 22:26:54344void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
345 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59346 gfx::Rect view_rect(size_);
347
348 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
349 if (!old_damage_rect.IsEmpty())
350 paint_aggregator_.InvalidateRect(old_damage_rect);
351
352 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
353 if (!new_damage_rect.IsEmpty())
354 paint_aggregator_.InvalidateRect(new_damage_rect);
355
[email protected]b5913d72012-02-07 22:26:54356 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59357
[email protected]b5913d72012-02-07 22:26:54358 if (webwidget_)
359 webwidget_->didChangeWindowResizerRect();
360 }
361}
362
initial.commit09911bf2008-07-26 23:55:29363void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31364 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29365 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03366 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29367}
368
369void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31370 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29371 // During shutdown we can just ignore this message.
372 if (!webwidget_)
373 return;
374
375 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03376 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29377
378 if (!needs_repainting && !needs_repainting_on_restore_)
379 return;
380 needs_repainting_on_restore_ = false;
381
[email protected]d65adb12010-04-28 17:26:49382 // Tag the next paint as a restore ack, which is picked up by
383 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29384 set_next_paint_is_restore_ack();
385
386 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56387 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46388 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
389 } else {
390 scheduleComposite();
391 }
initial.commit09911bf2008-07-26 23:55:29392}
393
[email protected]992db4c2011-05-12 15:37:15394void RenderWidget::OnWasSwappedOut() {
395 // If we have been swapped out and no one else is using this process,
396 // it's safe to exit now. If we get swapped back in, we will call
397 // AddRefProcess in SetSwappedOut.
398 if (is_swapped_out_)
399 RenderProcess::current()->ReleaseProcess();
400}
401
[email protected]53d3f302009-12-21 04:42:05402void RenderWidget::OnRequestMoveAck() {
403 DCHECK(pending_window_rect_count_);
404 pending_window_rect_count_--;
405}
406
407void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58408 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21409 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05410 update_reply_pending_ = false;
411
[email protected]b4d08452010-10-05 17:34:35412 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
413 // have no current paint buffer.
414 if (current_paint_buf_) {
415 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
416 current_paint_buf_ = NULL;
417 }
418
[email protected]65225772011-05-12 21:10:24419 // If swapbuffers is still pending, then defer the update until the
420 // swapbuffers occurs.
421 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
422 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
423 return;
424 }
425
[email protected]29ed96a2012-02-04 18:12:16426 // Notify subclasses that software rendering was flushed to the screen.
427 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25428
initial.commit09911bf2008-07-26 23:55:29429 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24430 DoDeferredUpdateAndSendInputAck();
431}
432
[email protected]d0be63772011-12-20 23:18:04433bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24434 return false;
435}
436
[email protected]d0be63772011-12-20 23:18:04437void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24438 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21439 while (!updates_pending_swap_.empty()) {
440 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
441 updates_pending_swap_.pop_front();
442 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
443 // compositing pass, hence doesn't require an UpdateRect message.
444 if (msg)
445 Send(msg);
446 }
[email protected]65225772011-05-12 21:10:24447 num_swapbuffers_complete_pending_ = 0;
448 using_asynchronous_swapbuffers_ = false;
449 // Schedule another frame so the compositor learns about it.
450 scheduleComposite();
451}
452
[email protected]37a6f302011-07-11 23:43:08453void RenderWidget::OnSwapBuffersPosted() {
454 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21455
456 if (using_asynchronous_swapbuffers_) {
457 ViewHostMsg_UpdateRect* msg = NULL;
458 // pending_update_params_ can be NULL if the swap doesn't correspond to an
459 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
460 // message.
461 if (pending_update_params_.get()) {
462 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
463 pending_update_params_.reset();
464 }
465 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08466 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21467 }
[email protected]37a6f302011-07-11 23:43:08468}
469
470void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24471 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16472
473 // Notify subclasses that composited rendering got flushed to the screen.
474 DidFlushPaint();
475
[email protected]65225772011-05-12 21:10:24476 // When compositing deactivates, we reset the swapbuffers pending count. The
477 // swapbuffers acks may still arrive, however.
478 if (num_swapbuffers_complete_pending_ == 0) {
479 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
480 return;
481 }
[email protected]aa4117f2011-12-09 22:19:21482 DCHECK(!updates_pending_swap_.empty());
483 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
484 updates_pending_swap_.pop_front();
485 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
486 // compositing pass, hence doesn't require an UpdateRect message.
487 if (msg)
488 Send(msg);
[email protected]65225772011-05-12 21:10:24489 num_swapbuffers_complete_pending_--;
490
491 // If update reply is still pending, then defer the update until that reply
492 // occurs.
[email protected]d0be63772011-12-20 23:18:04493 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24494 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
495 return;
496 }
497
498 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06499 // when we were previously rendering. However, if an invalidation task is not
500 // posted, there may be software rendering work pending. In that case, don't
501 // early out.
502 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24503 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
504 return;
505 }
506
[email protected]65225772011-05-12 21:10:24507 // Continue painting if necessary...
508 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29509}
510
initial.commit09911bf2008-07-26 23:55:29511void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24512 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56513 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29514
515 const char* data;
516 int data_length;
[email protected]5dd768212009-08-13 23:34:49517 handling_input_event_ = true;
518 if (!message.ReadData(&iter, &data, &data_length)) {
519 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29520 return;
[email protected]5dd768212009-08-13 23:34:49521 }
initial.commit09911bf2008-07-26 23:55:29522
523 const WebInputEvent* input_event =
524 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48525
[email protected]b68a0e52011-12-08 15:11:12526 bool is_keyboard_shortcut = false;
527 // is_keyboard_shortcut flag is only available for RawKeyDown events.
528 if (input_event->type == WebInputEvent::RawKeyDown)
529 message.ReadBool(&iter, &is_keyboard_shortcut);
530
[email protected]67bfb83f2011-09-22 03:36:37531 bool prevent_default = false;
532 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26533 const WebMouseEvent& mouse_event =
534 *static_cast<const WebMouseEvent*>(input_event);
535 TRACE_EVENT2("renderer", "HandleMouseMove",
536 "x", mouse_event.x, "y", mouse_event.y);
537 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37538 }
539
540 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12541 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
542 suppress_next_char_events_ = false;
543 if (!processed && webwidget_)
544 processed = webwidget_->handleInputEvent(*input_event);
545 }
546
547 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
548 // it's not processed by webkit, then we need to suppress the upcoming Char
549 // events.
550 if (!processed && is_keyboard_shortcut)
551 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29552
[email protected]a9fb30aa2011-10-06 06:58:46553 IPC::Message* response =
554 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
555 processed);
[email protected]e2824412009-02-27 01:57:05556
[email protected]353a34c2010-05-28 23:35:17557 if ((input_event->type == WebInputEvent::MouseMove ||
[email protected]d93fc462011-03-14 23:03:03558 input_event->type == WebInputEvent::MouseWheel ||
[email protected]d329a912012-01-27 01:55:01559 WebInputEvent::isTouchEventType(input_event->type)) &&
[email protected]552e6002009-11-19 05:24:57560 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24561 // We want to rate limit the input events in this case, so we'll wait for
562 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17563 if (pending_input_event_ack_.get()) {
564 // As two different kinds of events could cause us to postpone an ack
565 // we send it now, if we have one pending. The Browser should never
566 // send us the same kind of event we are delaying the ack for.
567 Send(pending_input_event_ack_.release());
568 }
[email protected]12fbad812009-09-01 18:21:24569 pending_input_event_ack_.reset(response);
570 } else {
571 Send(response);
572 }
573
[email protected]5dd768212009-08-13 23:34:49574 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48575
[email protected]67bfb83f2011-09-22 03:36:37576 if (!prevent_default) {
577 if (WebInputEvent::isKeyboardEventType(input_event->type))
578 DidHandleKeyEvent();
579 if (WebInputEvent::isMouseEventType(input_event->type))
580 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24581 if (WebInputEvent::isTouchEventType(input_event->type))
582 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37583 }
initial.commit09911bf2008-07-26 23:55:29584}
585
586void RenderWidget::OnMouseCaptureLost() {
587 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28588 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29589}
590
591void RenderWidget::OnSetFocus(bool enable) {
592 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33593 if (webwidget_)
594 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29595}
596
597void RenderWidget::ClearFocus() {
598 // We may have got the focus from the browser before this gets processed, in
599 // which case we do not want to unfocus ourself.
600 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28601 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29602}
603
[email protected]2d5d09d52009-06-15 14:29:21604void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00605 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21606 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06607 TRACE_EVENT2("renderer", "PaintRect",
608 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00609 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21610
611 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00612 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
613 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03614
[email protected]4b03e292012-02-13 18:40:07615 if (invert_) {
616 // Draw everything to a temporary bitmap and then apply an
617 // inverting color map to the result. This is balanced by an extra
618 // call to canvas->restore(), below.
619 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48620 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07621 canvas->saveLayer(&bounds, invert_paint_.get());
622 }
623
[email protected]699ab0d2009-04-23 23:19:14624 // If there is a custom background, tile it.
625 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14626 SkPaint paint;
627 SkShader* shader = SkShader::CreateBitmapShader(background_,
628 SkShader::kRepeat_TileMode,
629 SkShader::kRepeat_TileMode);
630 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20631
632 // Use kSrc_Mode to handle background_ transparency properly.
633 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
634
635 // Canvas could contain multiple update rects. Clip to given rect so that
636 // we don't accidentally clear other update rects.
637 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48638 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14639 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20640 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14641 }
642
[email protected]719b36f2010-12-22 20:36:46643 // First see if this rect is a plugin that can paint itself faster.
644 TransportDIB* optimized_dib = NULL;
645 gfx::Rect optimized_copy_rect, optimized_copy_location;
646 webkit::ppapi::PluginInstance* optimized_instance =
647 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
648 &optimized_copy_location,
649 &optimized_copy_rect);
650 if (optimized_instance) {
651 // This plugin can be optimize-painted and we can just ask it to paint
652 // itself. We don't actually need the TransportDIB in this case.
653 //
654 // This is an optimization for PPAPI plugins that know they're on top of
655 // the page content. If this rect is inside such a plugin, we can save some
656 // time and avoid re-rendering the page content which we know will be
657 // covered by the plugin later (this time can be significant, especially
658 // for a playing movie that is invalidating a lot).
659 //
660 // In the plugin movie case, hopefully the similar call to
661 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
662 // painting, because that avoids copying the plugin image to a different
663 // paint rect. Unfortunately, if anything on the page is animating other
664 // than the movie, it break this optimization since the union of the
665 // invalid regions will be larger than the plugin.
666 //
667 // This code optimizes that case, where we can still avoid painting in
668 // WebKit and filling the background (which can be slow) and just painting
669 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
670 // required.
671 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27672 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46673 } else {
674 // Normal painting case.
675 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
676
677 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35678 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46679 }
initial.commit09911bf2008-07-26 23:55:29680
[email protected]4b03e292012-02-13 18:40:07681 if (invert_)
682 canvas->restore();
683
[email protected]4fb66842009-12-04 21:41:00684 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00685 canvas->restore();
686}
687
688void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
689 skia::PlatformCanvas* canvas) {
690 static bool kPaintBorder =
691 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
692 if (!kPaintBorder)
693 return;
694
[email protected]53d3f302009-12-21 04:42:05695 // Cycle through these colors to help distinguish new paint rects.
696 const SkColor colors[] = {
697 SkColorSetARGB(0x3F, 0xFF, 0, 0),
698 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
699 SkColorSetARGB(0x3F, 0, 0, 0xFF),
700 };
701 static int color_selector = 0;
702
[email protected]4fb66842009-12-04 21:41:00703 SkPaint paint;
704 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05705 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00706 paint.setStrokeWidth(1);
707
708 SkIRect irect;
709 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
710 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29711}
712
[email protected]52ccd0ea2011-02-16 01:09:05713void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30714 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30715 if (!animation_update_pending_) {
716 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59717 return;
[email protected]921244e42011-07-20 16:36:30718 }
[email protected]bd37ae252011-06-03 01:28:18719 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59720 // Record when we fired (according to base::Time::Now()) relative to when
721 // we posted the task to quantify how much the base::Time/base::TimeTicks
722 // skew is affecting animations.
723 base::TimeDelta animation_callback_delay = base::Time::Now() -
724 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
725 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
726 animation_callback_delay,
727 base::TimeDelta::FromMilliseconds(0),
728 base::TimeDelta::FromMilliseconds(30),
729 25);
730 }
[email protected]65225772011-05-12 21:10:24731 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24732}
733
[email protected]52ccd0ea2011-02-16 01:09:05734void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59735 if (!animation_update_pending_)
736 return;
[email protected]bd37ae252011-06-03 01:28:18737
738 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33739 base::TimeDelta animationInterval = IsRenderingVSynced() ?
740 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18741
[email protected]7c4329e2011-02-18 22:02:59742 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45743
744 // animation_floor_time_ is the earliest time that we should animate when
745 // using the dead reckoning software scheduler. If we're using swapbuffers
746 // complete callbacks to rate limit, we can ignore this floor.
747 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30748 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33749 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18750 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59751 // running animation callbacks so that if a callback requests another
752 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38753 animation_timer_.Stop();
754 animation_timer_.Start(FROM_HERE, animationInterval, this,
755 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59756 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30757 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59758 return;
[email protected]5f8b1022011-01-21 23:34:50759 }
[email protected]bd37ae252011-06-03 01:28:18760 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38761 if (!animation_timer_.IsRunning()) {
762 // This code uses base::Time::Now() to calculate the floor and next fire
763 // time because javascript's Date object uses base::Time::Now(). The
764 // message loop uses base::TimeTicks, which on windows can have a
765 // different granularity than base::Time.
766 // The upshot of all this is that this function might be called before
767 // base::Time::Now() has advanced past the animation_floor_time_. To
768 // avoid exposing this delay to javascript, we keep posting delayed
769 // tasks until base::Time::Now() has advanced far enough.
770 base::TimeDelta delay = animation_floor_time_ - now;
771 animation_timer_.Start(FROM_HERE, delay, this,
772 &RenderWidget::AnimationCallback);
773 }
[email protected]5f8b1022011-01-21 23:34:50774}
775
[email protected]bd37ae252011-06-03 01:28:18776bool RenderWidget::IsRenderingVSynced() {
777 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
778 // not caught by this check. This will lead to artificially low frame rates
779 // for people who force vsync off at a driver level and expect Chrome to speed
780 // up.
781 return !has_disable_gpu_vsync_switch_;
782}
783
[email protected]65225772011-05-12 21:10:24784void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06785 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24786 invalidation_task_posted_ = false;
787 DoDeferredUpdateAndSendInputAck();
788}
789
790void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05791 DoDeferredUpdate();
792
793 if (pending_input_event_ack_.get())
794 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21795}
796
[email protected]552e6002009-11-19 05:24:57797void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58798 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08799
[email protected]65225772011-05-12 21:10:24800 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29801 return;
[email protected]05a980d7a2012-02-07 22:16:42802
803 if (!host_window_set_) {
804 TRACE_EVENT0("renderer", "EarlyOut_NoHostWindow");
805 return;
806 }
[email protected]aa4117f2011-12-09 22:19:21807 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24808 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
809 return;
810 }
[email protected]9ca84622011-06-02 23:46:39811 if (is_accelerated_compositing_active_ &&
812 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24813 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
814 return;
815 }
initial.commit09911bf2008-07-26 23:55:29816
[email protected]552e6002009-11-19 05:24:57817 // Suppress updating when we are hidden.
initial.commit09911bf2008-07-26 23:55:29818 if (is_hidden_ || size_.IsEmpty()) {
[email protected]552e6002009-11-19 05:24:57819 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29820 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24821 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29822 return;
823 }
824
[email protected]05a980d7a2012-02-07 22:16:42825 if (is_accelerated_compositing_active_)
826 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
827
[email protected]0fb93f52011-05-18 23:13:56828 // Tracking of frame rate jitter
829 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]52ccd0ea2011-02-16 01:09:05830 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50831
[email protected]f98d7e3c2010-09-13 22:30:46832 // Layout may generate more invalidation. It may also enable the
833 // GPU acceleration, so make sure to run layout before we send the
834 // GpuRenderingActivated message.
835 webwidget_->layout();
836
[email protected]dcca3aa92012-02-17 23:03:37837 // The following two can result in further layout and possibly
838 // enable GPU acceleration so they need to be called before any painting
839 // is done.
840 UpdateTextInputState();
841 UpdateSelectionBounds();
842
[email protected]5f8b1022011-01-21 23:34:50843 // Suppress painting if nothing is dirty. This has to be done after updating
844 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24845 if (!paint_aggregator_.HasPendingUpdate()) {
846 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]5f8b1022011-01-21 23:34:50847 return;
[email protected]65225772011-05-12 21:10:24848 }
[email protected]5f8b1022011-01-21 23:34:50849
[email protected]872ae5b2011-05-26 20:20:50850 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:56851 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:04852 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:56853 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
854 delay,
855 base::TimeDelta::FromMilliseconds(1),
856 base::TimeDelta::FromMilliseconds(60),
857 30);
[email protected]d0be63772011-12-20 23:18:04858 } else {
[email protected]0fb93f52011-05-18 23:13:56859 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
860 delay,
861 base::TimeDelta::FromMilliseconds(1),
862 base::TimeDelta::FromMilliseconds(60),
863 30);
[email protected]d0be63772011-12-20 23:18:04864 }
[email protected]872ae5b2011-05-26 20:20:50865
866 // Calculate filtered time per frame:
867 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
868 filtered_time_per_frame_ =
869 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:56870 }
871 last_do_deferred_update_time_ = frame_begin_ticks;
872
[email protected]552e6002009-11-19 05:24:57873 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:29874 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:30875 PaintAggregator::PendingUpdate update;
876 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:29877
[email protected]53d3f302009-12-21 04:42:05878 gfx::Rect scroll_damage = update.GetScrollDamage();
879 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage);
initial.commit09911bf2008-07-26 23:55:29880
[email protected]29ed96a2012-02-04 18:12:16881 // Notify derived classes that we're about to initiate a paint.
882 WillInitiatePaint();
883
[email protected]ca4847f2010-09-24 05:39:15884 // A plugin may be able to do an optimized paint. First check this, in which
885 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:46886 // This optimization allows PPAPI plugins that declare themselves on top of
887 // the page (like a traditional windowed plugin) to be able to animate (think
888 // movie playing) without repeatedly re-painting the page underneath, or
889 // copying the plugin backing store (since we can send the plugin's backing
890 // store directly to the browser).
891 //
892 // This optimization only works when the entire invalid region is contained
893 // within the plugin. There is a related optimization in PaintRect for the
894 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:15895 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:15896 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]aa4117f2011-12-09 22:19:21897 DCHECK(!pending_update_params_.get());
898 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
899 pending_update_params_->dx = update.scroll_delta.x();
900 pending_update_params_->dy = update.scroll_delta.y();
901 pending_update_params_->scroll_rect = update.scroll_rect;
902 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:21903 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
904 pending_update_params_->flags = next_paint_flags_;
905 pending_update_params_->scroll_offset = GetScrollOffset();
906 pending_update_params_->needs_ack = true;
907 next_paint_flags_ = 0;
908
[email protected]ca4847f2010-09-24 05:39:15909 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:56910 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:15911 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
912 &optimized_copy_rect)) {
[email protected]2df1b362011-01-21 21:22:27913 // Only update the part of the plugin that actually changed.
914 optimized_copy_rect = optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:21915 pending_update_params_->bitmap = dib->id();
916 pending_update_params_->bitmap_rect = optimized_copy_location;
917 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]a79d8a632010-11-18 22:35:56918 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46919 // Compute a buffer for painting and cache it.
[email protected]ca4847f2010-09-24 05:39:15920 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:35921 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
922 bounds));
[email protected]f98d7e3c2010-09-13 22:30:46923 if (!canvas.get()) {
924 NOTREACHED();
925 return;
926 }
[email protected]cef3362f2009-12-21 17:48:45927
[email protected]f98d7e3c2010-09-13 22:30:46928 // We may get back a smaller canvas than we asked for.
929 // TODO(darin): This seems like it could cause painting problems!
930 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
931 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
932 bounds.set_width(canvas->getDevice()->width());
933 bounds.set_height(canvas->getDevice()->height());
[email protected]53d3f302009-12-21 04:42:05934
[email protected]f98d7e3c2010-09-13 22:30:46935 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
936
[email protected]aa4117f2011-12-09 22:19:21937 pending_update_params_->bitmap = current_paint_buf_->id();
938 pending_update_params_->bitmap_rect = bounds;
939
940 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:46941 // The scroll damage is just another rectangle to paint and copy.
942 copy_rects.swap(update.paint_rects);
943 if (!scroll_damage.IsEmpty())
944 copy_rects.push_back(scroll_damage);
945
946 for (size_t i = 0; i < copy_rects.size(); ++i)
947 PaintRect(copy_rects[i], bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:35948
949 // Software FPS tick for performance tests. The accelerated path traces the
950 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
951 // NOTE: Tests may break if this event is renamed or moved.
952 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:46953 } else { // Accelerated compositing path
954 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:21955 // If painting is done via the gpu process then we don't set any damage
956 // rects to save the browser process from doing unecessary work.
957 pending_update_params_->bitmap_rect = bounds;
958 pending_update_params_->scroll_rect = gfx::Rect();
959 // We don't need an ack, because we're not sharing a DIB with the browser.
960 // If it needs to (e.g. composited UI), the GPU process does its own ACK
961 // with the browser for the GPU surface.
962 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:42963 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:46964 }
965
[email protected]936c6f52011-12-13 01:35:26966 // If we're holding a pending input event ACK, send the ACK before sending the
967 // UpdateReply message so we can receive another input event before the
968 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
969 // the UpdateRect IPC message handler.
970 if (pending_input_event_ack_.get())
971 Send(pending_input_event_ack_.release());
972
[email protected]aa4117f2011-12-09 22:19:21973 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
974 // OnSwapBuffersPosted), meaning a message has been added to the
975 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
976 // the message now.
977 if (pending_update_params_.get()) {
978 // sending an ack to browser process that the paint is complete...
979 update_reply_pending_ = pending_update_params_->needs_ack;
980 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
981 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:34982 }
[email protected]53d3f302009-12-21 04:42:05983
[email protected]29ed96a2012-02-04 18:12:16984 // If we're software rendering then we're done initiating the paint.
985 if (!is_accelerated_compositing_active_)
986 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:29987}
988
989///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:46990// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:29991
[email protected]4873c7d2009-07-16 06:36:28992void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:57993 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:48994 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:57995 gfx::Rect damaged_rect = view_rect.Intersect(rect);
996 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:29997 return;
998
[email protected]552e6002009-11-19 05:24:57999 paint_aggregator_.InvalidateRect(damaged_rect);
1000
1001 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241002 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571003 return;
1004 if (!paint_aggregator_.HasPendingUpdate())
1005 return;
[email protected]aa4117f2011-12-09 22:19:211006 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241007 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1008 return;
1009
1010 // When GPU rendering, combine pending animations and invalidations into
1011 // a single update.
[email protected]350ce8702012-03-09 04:23:381012 if (is_accelerated_compositing_active_ && animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571013 return;
1014
1015 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291016 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1017 // on the call stack.
1018 // 2) Allows us to collect more damage rects before painting to help coalesce
1019 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241020 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211021 MessageLoop::current()->PostTask(
1022 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291023}
1024
[email protected]4873c7d2009-07-16 06:36:281025void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461026 // Drop scrolls on the floor when we are in compositing mode.
1027 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561028 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461029 return;
1030
[email protected]552e6002009-11-19 05:24:571031 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481032 gfx::Rect view_rect(size_);
[email protected]552e6002009-11-19 05:24:571033 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect);
1034 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291035 return;
1036
[email protected]552e6002009-11-19 05:24:571037 paint_aggregator_.ScrollRect(dx, dy, damaged_rect);
1038
1039 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241040 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571041 return;
1042 if (!paint_aggregator_.HasPendingUpdate())
1043 return;
[email protected]aa4117f2011-12-09 22:19:211044 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241045 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1046 return;
1047
1048 // When GPU rendering, combine pending animations and invalidations into
1049 // a single update.
[email protected]350ce8702012-03-09 04:23:381050 if (is_accelerated_compositing_active_ && animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571051 return;
1052
1053 // Perform updating asynchronously. This serves two purposes:
1054 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1055 // on the call stack.
1056 // 2) Allows us to collect more damage rects before painting to help coalesce
1057 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241058 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211059 MessageLoop::current()->PostTask(
1060 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291061}
1062
[email protected]244ac1892011-12-02 17:04:471063void RenderWidget::didAutoResize(const WebSize& new_size) {
1064 size_ = new_size;
1065}
1066
[email protected]3da12cb2011-10-08 02:25:041067void RenderWidget::didActivateCompositor(int compositor_identifier) {
[email protected]ea162f92011-10-04 23:08:221068 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1069
[email protected]f3150172011-10-22 02:28:451070 CompositorThread* compositor_thread =
1071 RenderThreadImpl::current()->compositor_thread();
1072 if (compositor_thread)
1073 compositor_thread->AddCompositor(routing_id_, compositor_identifier);
[email protected]3da12cb2011-10-08 02:25:041074
[email protected]aa4117f2011-12-09 22:19:211075 if (!is_accelerated_compositing_active_) {
1076 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1077 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1078 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1079 // going to switch to accelerated compositing, the GPU process may need
1080 // round-trips to the browser's UI thread before finishing the frame,
1081 // causing deadlocks if we delay the UpdateRect until we receive the
1082 // OnSwapBuffersComplete. So send a dummy message that will unblock the
1083 // browser's UI thread.
1084 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1085 }
1086
[email protected]ea162f92011-10-04 23:08:221087 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421088 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241089 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221090}
1091
1092void RenderWidget::didDeactivateCompositor() {
1093 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1094
1095 is_accelerated_compositing_active_ = false;
1096 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1097 routing_id_, is_accelerated_compositing_active_));
1098
[email protected]ea162f92011-10-04 23:08:221099 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241100 using_asynchronous_swapbuffers_ = false;
[email protected]a79d8a632010-11-18 22:35:561101}
1102
[email protected]58264a32011-11-17 23:36:151103void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501104 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351105 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1106 // NOTE: Tests may break if this event is renamed or moved.
1107 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161108 // Notify subclasses that we initiated the paint operation.
1109 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151110}
1111
1112void RenderWidget::didCompleteSwapBuffers() {
[email protected]aa4117f2011-12-09 22:19:211113 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151114 return;
1115
1116 if (!next_paint_flags_ && !plugin_window_moves_.size())
1117 return;
1118
1119 ViewHostMsg_UpdateRect_Params params;
1120 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151121 params.plugin_window_moves.swap(plugin_window_moves_);
1122 params.flags = next_paint_flags_;
1123 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121124 params.needs_ack = false;
[email protected]58264a32011-11-17 23:36:151125
1126 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1127 next_paint_flags_ = 0;
1128}
1129
[email protected]f98d7e3c2010-09-13 22:30:461130void RenderWidget::scheduleComposite() {
[email protected]d0be63772011-12-20 23:18:041131 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401132 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041133 } else {
[email protected]c3d45532011-10-07 19:20:401134 // TODO(nduca): replace with something a little less hacky. The reason this
1135 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1136 // contains a lot of host-renderer synchronization logic that is still
1137 // important for the accelerated compositing case. The option of simply
1138 // duplicating all that code is less desirable than "faking out" the
1139 // invalidation path using a magical damage rect.
1140 didInvalidateRect(WebRect(0, 0, 1, 1));
1141 }
[email protected]f98d7e3c2010-09-13 22:30:461142}
1143
[email protected]5f8b1022011-01-21 23:34:501144void RenderWidget::scheduleAnimation() {
[email protected]921244e42011-07-20 16:36:301145 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ee3d3ad2011-02-04 00:42:211146 if (!animation_update_pending_) {
1147 animation_update_pending_ = true;
[email protected]350ce8702012-03-09 04:23:381148 if (!animation_timer_.IsRunning()) {
1149 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1150 &RenderWidget::AnimationCallback);
[email protected]52ccd0ea2011-02-16 01:09:051151 }
[email protected]ee3d3ad2011-02-04 00:42:211152 }
[email protected]5f8b1022011-01-21 23:34:501153}
1154
[email protected]4873c7d2009-07-16 06:36:281155void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301156 // TODO(darin): Eliminate this temporary.
1157 WebCursor cursor(cursor_info);
1158
initial.commit09911bf2008-07-26 23:55:291159 // Only send a SetCursor message if we need to make a change.
1160 if (!current_cursor_.IsEqual(cursor)) {
1161 current_cursor_ = cursor;
1162 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1163 }
1164}
1165
1166// We are supposed to get a single call to Show for a newly created RenderWidget
1167// that was created via RenderWidget::CreateWebView. So, we wait until this
1168// point to dispatch the ShowWidget message.
1169//
1170// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281171// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291172//
[email protected]4873c7d2009-07-16 06:36:281173void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291174 DCHECK(!did_show_) << "received extraneous Show call";
1175 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1176 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1177
[email protected]8de12d942010-11-17 20:42:441178 if (did_show_)
1179 return;
1180
1181 did_show_ = true;
1182 // NOTE: initial_pos_ may still have its default values at this point, but
1183 // that's okay. It'll be ignored if as_popup is false, or the browser
1184 // process will impose a default position otherwise.
1185 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1186 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291187}
1188
[email protected]4873c7d2009-07-16 06:36:281189void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291190}
1191
[email protected]4873c7d2009-07-16 06:36:281192void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291193}
1194
[email protected]2533ce12009-05-09 00:02:241195void RenderWidget::DoDeferredClose() {
1196 Send(new ViewHostMsg_Close(routing_id_));
1197}
1198
[email protected]4873c7d2009-07-16 06:36:281199void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291200 // If a page calls window.close() twice, we'll end up here twice, but that's
1201 // OK. It is safe to send multiple Close messages.
1202
[email protected]2533ce12009-05-09 00:02:241203 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1204 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1205 // could be closed before the JS finishes executing. So instead, post a
1206 // message back to the message loop, which won't run until the JS is
1207 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211208 MessageLoop::current()->PostTask(
1209 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291210}
1211
1212void RenderWidget::Close() {
1213 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281214 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291215 webwidget_ = NULL;
1216 }
1217}
1218
[email protected]4873c7d2009-07-16 06:36:281219WebRect RenderWidget::windowRect() {
1220 if (pending_window_rect_count_)
1221 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241222
[email protected]b3f2b912009-04-09 16:18:521223 gfx::Rect rect;
1224 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281225 return rect;
initial.commit09911bf2008-07-26 23:55:291226}
1227
[email protected]8a9d6ca32011-06-06 20:11:301228void RenderWidget::setToolTipText(const WebKit::WebString& text,
1229 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541230 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301231}
1232
[email protected]4873c7d2009-07-16 06:36:281233void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291234 if (did_show_) {
1235 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241236 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291237 } else {
1238 initial_pos_ = pos;
1239 }
1240}
1241
[email protected]2533ce12009-05-09 00:02:241242void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1243 pending_window_rect_ = rect;
1244 pending_window_rect_count_++;
1245}
1246
[email protected]4873c7d2009-07-16 06:36:281247WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241248 if (pending_window_rect_count_) {
1249 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1250 // the RootWindowRect is probably going to return wrong results since the
1251 // browser may not have processed the Move yet. There isn't really anything
1252 // good to do in this case, and it shouldn't happen - since this size is
1253 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281254 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241255 }
1256
[email protected]b3f2b912009-04-09 16:18:521257 gfx::Rect rect;
1258 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281259 return rect;
[email protected]d4547452008-08-28 18:36:371260}
1261
[email protected]4873c7d2009-07-16 06:36:281262WebRect RenderWidget::windowResizerRect() {
1263 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191264}
1265
[email protected]fa7b1dc2010-06-23 17:53:041266void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031267 // To prevent this renderer process from sending unnecessary IPC messages to
1268 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041269 // only during the input method attached to the browser process is active.
1270 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291271}
1272
[email protected]fa7b1dc2010-06-23 17:53:041273void RenderWidget::OnImeSetComposition(
1274 const string16& text,
1275 const std::vector<WebCompositionUnderline>& underlines,
1276 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281277 if (!webwidget_)
1278 return;
[email protected]d4cff272011-05-02 15:46:011279 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041280 text, WebVector<WebCompositionUnderline>(underlines),
1281 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011282 // Setting the IME composition was successful. Send the new composition
1283 // range to the browser.
1284 ui::Range range(ui::Range::InvalidRange());
1285 size_t location, length;
1286 if (webwidget_->compositionRange(&location, &length)) {
1287 range.set_start(location);
1288 range.set_end(location + length);
1289 }
1290 // The IME was cancelled via the Esc key, so just send back the caret.
1291 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1292 range.set_start(location);
1293 range.set_end(location + length);
1294 }
1295 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1296 } else {
[email protected]fa7b1dc2010-06-23 17:53:041297 // If we failed to set the composition text, then we need to let the browser
1298 // process to cancel the input method's ongoing composition session, to make
1299 // sure we are in a consistent state.
1300 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011301
1302 // Send an updated IME range with just the caret range.
1303 ui::Range range(ui::Range::InvalidRange());
1304 size_t location, length;
1305 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1306 range.set_start(location);
1307 range.set_end(location + length);
1308 }
1309 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261310 }
[email protected]fa7b1dc2010-06-23 17:53:041311}
1312
[email protected]4de6d1692011-10-12 08:45:441313void RenderWidget::OnImeConfirmComposition(
1314 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041315 if (!webwidget_)
1316 return;
1317
1318 handling_input_event_ = true;
1319 webwidget_->confirmComposition(text);
1320 handling_input_event_ = false;
1321
[email protected]d4cff272011-05-02 15:46:011322 // Send an updated IME range with just the caret range.
1323 ui::Range range(ui::Range::InvalidRange());
1324 size_t location, length;
1325 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1326 range.set_start(location);
1327 range.set_end(location + length);
1328 }
1329 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291330}
1331
[email protected]948f7ab72010-05-28 23:48:081332// This message causes the renderer to render an image of the
1333// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491334void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091335 int tag,
[email protected]948f7ab72010-05-28 23:48:081336 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491337 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001338 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1339 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251340 // Close our unused handle.
1341#if defined(OS_WIN)
1342 ::CloseHandle(dib_handle);
1343#elif defined(OS_MACOSX)
1344 base::SharedMemory::CloseHandle(dib_handle);
1345#endif
1346 }
[email protected]d65adb12010-04-28 17:26:491347 return;
[email protected]45c6aad32010-11-11 04:46:251348 }
[email protected]d65adb12010-04-28 17:26:491349
[email protected]948f7ab72010-05-28 23:48:081350 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491351 // If one of these is empty, then we just return the dib we were
1352 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091353 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491354 return;
1355 }
1356
1357 // Map the given DIB ID into this process, and unmap it at the end
1358 // of this function.
[email protected]45c6aad32010-11-11 04:46:251359 scoped_ptr<TransportDIB> paint_at_size_buffer(
1360 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301361
1362 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491363 float x_scale = static_cast<float>(desired_size.width()) /
1364 static_cast<float>(canvas_size.width());
1365 float y_scale = static_cast<float>(desired_size.height()) /
1366 static_cast<float>(canvas_size.height());
1367
[email protected]ee8d6fd2010-05-26 17:05:481368 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491369 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1370 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481371 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491372
[email protected]36808ad2010-10-20 19:18:301373 scoped_ptr<skia::PlatformCanvas> canvas(
1374 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1375 canvas_size.height()));
1376 if (!canvas.get()) {
1377 NOTREACHED();
1378 return;
1379 }
1380
[email protected]d65adb12010-04-28 17:26:491381 // Reset bounds to what we actually received, but they should be the
1382 // same.
1383 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1384 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1385 bounds.set_width(canvas->getDevice()->width());
1386 bounds.set_height(canvas->getDevice()->height());
1387
1388 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081389 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491390 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1391
[email protected]948f7ab72010-05-28 23:48:081392 // Have to make sure we're laid out at the right size before
1393 // rendering.
1394 gfx::Size old_size = webwidget_->size();
1395 webwidget_->resize(page_size);
1396 webwidget_->layout();
1397
[email protected]d65adb12010-04-28 17:26:491398 // Paint the entire thing (using original bounds, not scaled bounds).
1399 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1400 canvas->restore();
1401
[email protected]948f7ab72010-05-28 23:48:081402 // Return the widget to its previous size.
1403 webwidget_->resize(old_size);
1404
[email protected]c88c9442010-07-19 18:55:091405 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491406}
1407
[email protected]ec7dc112008-08-06 05:30:121408void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1409 // During shutdown we can just ignore this message.
1410 if (!webwidget_)
1411 return;
1412
1413 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561414 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041415 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461416 scheduleComposite();
1417 } else {
1418 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1419 didInvalidateRect(repaint_rect);
1420 }
[email protected]ec7dc112008-08-06 05:30:121421}
1422
[email protected]4873c7d2009-07-16 06:36:281423void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111424 if (!webwidget_)
1425 return;
[email protected]4873c7d2009-07-16 06:36:281426 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111427}
1428
[email protected]4b03e292012-02-13 18:40:071429void RenderWidget::OnInvertWebContent(bool invert) {
1430 if (invert_ == invert)
1431 return;
1432
1433 invert_ = invert;
1434
1435 if (invert_ && !invert_paint_.get()) {
1436 // Gamma-aware color inversion: each source pixel value x is normally
1437 // displayed on a computer monitor with a gamma correction x^gamma,
1438 // where gamma is typically in the range 1.8...2.2. By approximating
1439 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1440 uint8_t table[256];
1441 for (unsigned int i = 0; i < 256; i++) {
1442 double value = i / 255.0;
1443 value = sqrt(1 - (value * value));
1444 table[i] = static_cast<uint8_t>(255 * value);
1445 }
1446
1447 // Create a Skia Paint with this inverting color map.
1448 invert_paint_.reset(new SkPaint());
1449 invert_paint_->setStyle(SkPaint::kFill_Style);
1450 invert_paint_->setColor(SK_ColorBLACK);
1451 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1452 NULL, table, table, table);
1453 invert_paint_->setColorFilter(filter);
1454 filter->unref();
1455 }
1456
1457 OnMsgRepaint(size_);
1458}
1459
[email protected]719b36f2010-12-22 20:36:461460webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151461 const gfx::Rect& paint_bounds,
1462 TransportDIB** dib,
1463 gfx::Rect* location,
1464 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461465 // Bare RenderWidgets don't support optimized plugin painting.
1466 return NULL;
[email protected]ca4847f2010-09-24 05:39:151467}
1468
[email protected]bcaf2272011-02-15 15:29:431469gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521470 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431471 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521472}
1473
[email protected]bee16aab2009-08-26 15:55:031474void RenderWidget::SetHidden(bool hidden) {
1475 if (is_hidden_ == hidden)
1476 return;
1477
1478 // The status has changed. Tell the RenderThread about it.
1479 is_hidden_ = hidden;
1480 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271481 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031482 else
[email protected]380244092011-10-07 17:26:271483 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031484}
1485
[email protected]2b624c562011-10-27 22:58:261486void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261487 if (!webwidget_)
1488 return;
1489
1490 if (is_fullscreen_) {
1491 webwidget_->willExitFullScreen();
1492 } else {
1493 webwidget_->willEnterFullScreen();
1494 }
[email protected]2b624c562011-10-27 22:58:261495}
1496
1497void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261498 if (!webwidget_)
1499 return;
1500
1501 if (is_fullscreen_) {
1502 webwidget_->didEnterFullScreen();
1503 } else {
1504 webwidget_->didExitFullScreen();
1505 }
[email protected]2b624c562011-10-27 22:58:261506}
1507
[email protected]699ab0d2009-04-23 23:19:141508void RenderWidget::SetBackground(const SkBitmap& background) {
1509 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461510
[email protected]699ab0d2009-04-23 23:19:141511 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281512 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141513}
1514
[email protected]674741932009-02-04 23:44:461515bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051516 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461517}
1518
1519bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051520 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461521}
1522
1523void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051524 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461525}
1526
1527void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051528 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461529}
1530
1531void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051532 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461533}
1534
[email protected]e99ef6f2011-10-16 01:13:001535void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041536 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291537 return;
[email protected]fa7b1dc2010-06-23 17:53:041538
[email protected]ad26ef42011-06-17 07:59:451539 ui::TextInputType new_type = GetTextInputType();
1540 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001541 // Only sends text input type and compose inline to the browser process if
1542 // they are changed.
1543 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451544 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041545 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451546 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001547 Send(new ViewHostMsg_TextInputStateChanged(
1548 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291549 }
initial.commit09911bf2008-07-26 23:55:291550}
1551
[email protected]3f783362011-10-21 22:40:501552void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1553 WebRect start_webrect;
1554 WebRect end_webrect;
1555 webwidget_->selectionBounds(start_webrect, end_webrect);
1556 *start = start_webrect;
1557 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321558}
1559
[email protected]e99ef6f2011-10-16 01:13:001560void RenderWidget::UpdateSelectionBounds() {
1561 if (!webwidget_)
1562 return;
1563
[email protected]3f783362011-10-21 22:40:501564 gfx::Rect start_rect;
1565 gfx::Rect end_rect;
1566 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001567 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1568 return;
1569
1570 selection_start_rect_ = start_rect;
1571 selection_end_rect_ = end_rect;
1572 Send(new ViewHostMsg_SelectionBoundsChanged(
1573 routing_id_, selection_start_rect_, selection_end_rect_));
1574}
1575
[email protected]73bf95812011-10-12 11:38:321576// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451577COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1578 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1579COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1580 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1581COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1582 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181583COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1584 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1585COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1586 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1587COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1588 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1589COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1590 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1591COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1592 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451593
1594ui::TextInputType RenderWidget::GetTextInputType() {
1595 if (webwidget_) {
1596 int type = webwidget_->textInputType();
1597 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181598 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451599 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1600 return static_cast<ui::TextInputType>(type);
1601 }
1602 return ui::TEXT_INPUT_TYPE_NONE;
1603}
1604
1605bool RenderWidget::CanComposeInline() {
1606 return true;
[email protected]56ea1a62011-05-30 07:05:571607}
1608
[email protected]4873c7d2009-07-16 06:36:281609WebScreenInfo RenderWidget::screenInfo() {
[email protected]6fd35b72012-03-01 19:46:411610 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281611}
1612
[email protected]fa7b1dc2010-06-23 17:53:041613void RenderWidget::resetInputMethod() {
1614 if (!input_method_is_active_)
1615 return;
1616
1617 // If the last text input type is not None, then we should finish any
1618 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451619 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041620 // If a composition text exists, then we need to let the browser process
1621 // to cancel the input method's ongoing composition session.
1622 if (webwidget_->confirmComposition())
1623 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1624 }
[email protected]d4cff272011-05-02 15:46:011625
1626 // Send an updated IME range with the current caret rect.
1627 ui::Range range(ui::Range::InvalidRange());
1628 size_t location, length;
1629 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1630 range.set_start(location);
1631 range.set_end(location + length);
1632 }
1633 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041634}
1635
[email protected]f103ab72009-09-02 17:10:591636void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501637 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291638 size_t i = 0;
1639 for (; i < plugin_window_moves_.size(); ++i) {
1640 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581641 if (move.rects_valid) {
1642 plugin_window_moves_[i] = move;
1643 } else {
1644 plugin_window_moves_[i].visible = move.visible;
1645 }
initial.commit09911bf2008-07-26 23:55:291646 break;
1647 }
1648 }
1649
1650 if (i == plugin_window_moves_.size())
1651 plugin_window_moves_.push_back(move);
1652}
[email protected]268654772009-08-06 23:02:041653
1654void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1655 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1656 i != plugin_window_moves_.end(); ++i) {
1657 if (i->window == window) {
1658 plugin_window_moves_.erase(i);
1659 break;
1660 }
1661 }
1662}
[email protected]67bfb83f2011-09-22 03:36:371663
1664bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1665 return false;
1666}
[email protected]c3d45532011-10-07 19:20:401667
1668bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1669 return false;
1670}