blob: 549331a39a0d764e8907f17667d1f9d1e0ceb9e6 [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]8bd0fe62011-01-17 06:44:3730#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
31#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0132#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]e6e90dc2011-12-03 00:01:3733#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]8bd0fe62011-01-17 06:44:3734#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]e6e90dc2011-12-03 00:01:3735#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
36#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
[email protected]1835b9e2012-02-28 13:12:4837#include "ui/gfx/gl/gl_switches.h"
[email protected]08397d52011-02-05 01:53:3838#include "ui/gfx/point.h"
39#include "ui/gfx/size.h"
[email protected]1835b9e2012-02-28 13:12:4840#include "ui/gfx/skia_util.h"
[email protected]b9b751f22011-03-25 14:04:1241#include "ui/gfx/surface/transport_dib.h"
[email protected]8c89e7792009-08-19 21:18:3442#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5043#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4644#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4845
46#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4947#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5248#include "third_party/skia/include/core/SkPixelRef.h"
49#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4850#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4451
[email protected]8bd0fe62011-01-17 06:44:3752#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2953
[email protected]fa7b1dc2010-06-23 17:53:0454using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3055using WebKit::WebCursorInfo;
[email protected]62cb33cae2009-03-27 23:30:2256using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0657using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2858using WebKit::WebNavigationPolicy;
[email protected]e99ef6f2011-10-16 01:13:0059using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2860using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5961using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1862using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0163using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5264using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1965using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5266using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2867using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2468using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0469using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1870using WebKit::WebWidget;
[email protected]380244092011-10-07 17:26:2771using content::RenderThread;
[email protected]62cb33cae2009-03-27 23:30:2272
[email protected]6fd35b72012-03-01 19:46:4173RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
74 const WebKit::WebScreenInfo& screen_info)
initial.commit09911bf2008-07-26 23:55:2975 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:5676 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:1177 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:2978 opener_id_(MSG_ROUTING_NONE),
[email protected]659f73f2009-10-13 13:43:4279 host_window_(0),
[email protected]05a980d7a2012-02-07 22:16:4280 host_window_set_(false),
[email protected]b4d08452010-10-05 17:34:3581 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:2982 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:0683 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:0584 update_reply_pending_(false),
[email protected]65225772011-05-12 21:10:2485 using_asynchronous_swapbuffers_(false),
86 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:2987 did_show_(false),
initial.commit09911bf2008-07-26 23:55:2988 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:0989 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:2990 needs_repainting_on_restore_(false),
91 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:4992 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:4893 closing_(false),
[email protected]992db4c2011-05-12 15:37:1594 is_swapped_out_(false),
[email protected]fa7b1dc2010-06-23 17:53:0495 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:4596 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
97 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:1298 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:4899 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12100 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50101 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21102 animation_update_pending_(false),
[email protected]65225772011-05-12 21:10:24103 animation_task_posted_(false),
[email protected]4b03e292012-02-13 18:40:07104 invalidation_task_posted_(false),
[email protected]6fd35b72012-03-01 19:46:41105 screen_info_(screen_info),
[email protected]4b03e292012-02-13 18:40:07106 invert_(false) {
[email protected]8930d472009-02-21 08:05:28107 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27108 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18109 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
110 switches::kDisableGpuVsync);
initial.commit09911bf2008-07-26 23:55:29111}
112
113RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11114 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21115 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35116 if (current_paint_buf_) {
117 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
118 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29119 }
[email protected]992db4c2011-05-12 15:37:15120 // If we are swapped out, we have released already.
121 if (!is_swapped_out_)
122 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29123}
124
[email protected]484955942010-08-19 16:13:18125// static
[email protected]8085dbc82008-09-26 22:53:44126RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]6fd35b72012-03-01 19:46:41127 WebKit::WebPopupType popup_type,
128 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29129 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41130 scoped_refptr<RenderWidget> widget(
131 new RenderWidget(popup_type, screen_info));
initial.commit09911bf2008-07-26 23:55:29132 widget->Init(opener_id); // adds reference
133 return widget;
134}
135
[email protected]484955942010-08-19 16:13:18136// static
137WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
138 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03139 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18140 break;
141 case WebKit::WebPopupTypeSelect:
142 case WebKit::WebPopupTypeSuggestion:
143 return WebPopupMenu::create(render_widget);
144 default:
145 NOTREACHED();
146 }
147 return NULL;
148}
149
initial.commit09911bf2008-07-26 23:55:29150void RenderWidget::Init(int32 opener_id) {
[email protected]484955942010-08-19 16:13:18151 DoInit(opener_id,
152 RenderWidget::CreateWebWidget(this),
[email protected]9f4f3322012-01-18 22:29:56153 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
154 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18155}
156
[email protected]484955942010-08-19 16:13:18157void RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06158 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18159 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29160 DCHECK(!webwidget_);
161
162 if (opener_id != MSG_ROUTING_NONE)
163 opener_id_ = opener_id;
164
[email protected]484955942010-08-19 16:13:18165 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29166
[email protected]380244092011-10-07 17:26:27167 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29168 if (result) {
[email protected]380244092011-10-07 17:26:27169 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29170 // Take a reference on behalf of the RenderThread. This will be balanced
171 // when we receive ViewMsg_Close.
172 AddRef();
173 } else {
174 DCHECK(false);
175 }
176}
177
178// This is used to complete pending inits and non-pending inits. For non-
179// pending cases, the parent will be the same as the current parent. This
180// indicates we do not need to reparent or anything.
[email protected]2d7c8552011-06-27 19:21:55181void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) {
initial.commit09911bf2008-07-26 23:55:29182 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29183
184 host_window_ = parent_hwnd;
[email protected]05a980d7a2012-02-07 22:16:42185 host_window_set_ = true;
186
187 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29188
[email protected]6de74452009-02-25 18:04:59189 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29190}
191
[email protected]992db4c2011-05-12 15:37:15192void RenderWidget::SetSwappedOut(bool is_swapped_out) {
193 // We should only toggle between states.
194 DCHECK(is_swapped_out_ != is_swapped_out);
195 is_swapped_out_ = is_swapped_out;
196
197 // If we are swapping out, we will call ReleaseProcess, allowing the process
198 // to exit if all of its RenderViews are swapped out. We wait until the
199 // WasSwappedOut call to do this, to avoid showing the sad tab.
200 // If we are swapping in, we call AddRefProcess to prevent the process from
201 // exiting.
202 if (!is_swapped_out)
203 RenderProcess::current()->AddRefProcess();
204}
205
[email protected]a95986a82010-12-24 06:19:28206bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
207 bool handled = true;
208 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
209 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
210 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
211 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54212 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28213 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
214 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored)
[email protected]992db4c2011-05-12 15:37:15215 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28216 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
217 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
218 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
219 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
220 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
221 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
222 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
223 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize)
224 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
225 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
226 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]4b03e292012-02-13 18:40:07227 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent)
[email protected]a95986a82010-12-24 06:19:28228 IPC_MESSAGE_UNHANDLED(handled = false)
229 IPC_END_MESSAGE_MAP()
230 return handled;
231}
initial.commit09911bf2008-07-26 23:55:29232
233bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15234 // Don't send any messages after the browser has told us to close, and filter
235 // most outgoing messages while swapped out.
236 if ((is_swapped_out_ &&
237 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
238 closing_) {
initial.commit09911bf2008-07-26 23:55:29239 delete message;
240 return false;
241 }
242
243 // If given a messsage without a routing ID, then assign our routing ID.
244 if (message->routing_id() == MSG_ROUTING_NONE)
245 message->set_routing_id(routing_id_);
246
[email protected]380244092011-10-07 17:26:27247 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44248}
249
[email protected]61e2b3cc2012-03-02 16:13:34250void RenderWidget::Resize(const gfx::Size& new_size,
251 const gfx::Rect& resizer_rect,
252 bool is_fullscreen,
253 ResizeAck resize_ack) {
254 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
255 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
256 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29257
[email protected]61e2b3cc2012-03-02 16:13:34258 // Ignore this during shutdown.
259 if (!webwidget_)
260 return;
261
262 // Remember the rect where the resize corner will be drawn.
263 resizer_rect_ = resizer_rect;
264
265 // NOTE: We may have entered fullscreen mode without changing our size.
266 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
267 if (fullscreen_change)
268 WillToggleFullscreen();
269 is_fullscreen_ = is_fullscreen;
270
271 if (size_ != new_size) {
272 // TODO(darin): We should not need to reset this here.
273 SetHidden(false);
274 needs_repainting_on_restore_ = false;
275
276 size_ = new_size;
277
278 paint_aggregator_.ClearPendingUpdate();
279
280 // When resizing, we want to wait to paint before ACK'ing the resize. This
281 // ensures that we only resize as fast as we can paint. We only need to
282 // send an ACK if we are resized to a non-empty rect.
283 webwidget_->resize(new_size);
284 if (!new_size.IsEmpty()) {
285 if (!is_accelerated_compositing_active_) {
286 // Resize should have caused an invalidation of the entire view.
287 DCHECK(paint_aggregator_.HasPendingUpdate());
288 }
289
290 // Send the Resize_ACK flag once we paint again if requested.
291 if (resize_ack == SEND_RESIZE_ACK)
292 set_next_paint_is_resize_ack();
293 }
294 }
295
296 if (fullscreen_change)
297 DidToggleFullscreen();
298
299 // If a resize ack is requested and it isn't set-up, then no more resizes will
300 // come in and in general things will go wrong.
301 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
302 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29303}
304
305void RenderWidget::OnClose() {
306 if (closing_)
307 return;
308 closing_ = true;
309
310 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03311 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27312 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03313 SetHidden(false);
314 }
initial.commit09911bf2008-07-26 23:55:29315
initial.commit09911bf2008-07-26 23:55:29316 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25317 // now. Post a task that only gets invoked when there are no nested message
318 // loops.
[email protected]32876ae2011-11-15 22:25:21319 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29320 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25321
322 // Balances the AddRef taken when we called AddRoute.
323 Release();
initial.commit09911bf2008-07-26 23:55:29324}
325
[email protected]61e2b3cc2012-03-02 16:13:34326// Got a response from the browser after the renderer decided to create a new
327// view.
328void RenderWidget::OnCreatingNewAck(
329 gfx::NativeViewId parent) {
330 DCHECK(routing_id_ != MSG_ROUTING_NONE);
331
332 CompleteInit(parent);
333}
334
[email protected]f21c613a2009-02-12 14:46:17335void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09336 const gfx::Rect& resizer_rect,
337 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34338 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29339}
340
[email protected]b5913d72012-02-07 22:26:54341void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
342 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59343 gfx::Rect view_rect(size_);
344
345 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_);
346 if (!old_damage_rect.IsEmpty())
347 paint_aggregator_.InvalidateRect(old_damage_rect);
348
349 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect);
350 if (!new_damage_rect.IsEmpty())
351 paint_aggregator_.InvalidateRect(new_damage_rect);
352
[email protected]b5913d72012-02-07 22:26:54353 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59354
[email protected]b5913d72012-02-07 22:26:54355 if (webwidget_)
356 webwidget_->didChangeWindowResizerRect();
357 }
358}
359
initial.commit09911bf2008-07-26 23:55:29360void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31361 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29362 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03363 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29364}
365
366void RenderWidget::OnWasRestored(bool needs_repainting) {
[email protected]9c3085f2011-06-09 02:10:31367 TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored");
initial.commit09911bf2008-07-26 23:55:29368 // During shutdown we can just ignore this message.
369 if (!webwidget_)
370 return;
371
372 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03373 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29374
375 if (!needs_repainting && !needs_repainting_on_restore_)
376 return;
377 needs_repainting_on_restore_ = false;
378
[email protected]d65adb12010-04-28 17:26:49379 // Tag the next paint as a restore ack, which is picked up by
380 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29381 set_next_paint_is_restore_ack();
382
383 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56384 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46385 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
386 } else {
387 scheduleComposite();
388 }
initial.commit09911bf2008-07-26 23:55:29389}
390
[email protected]992db4c2011-05-12 15:37:15391void RenderWidget::OnWasSwappedOut() {
392 // If we have been swapped out and no one else is using this process,
393 // it's safe to exit now. If we get swapped back in, we will call
394 // AddRefProcess in SetSwappedOut.
395 if (is_swapped_out_)
396 RenderProcess::current()->ReleaseProcess();
397}
398
[email protected]53d3f302009-12-21 04:42:05399void RenderWidget::OnRequestMoveAck() {
400 DCHECK(pending_window_rect_count_);
401 pending_window_rect_count_--;
402}
403
404void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58405 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21406 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05407 update_reply_pending_ = false;
408
[email protected]b4d08452010-10-05 17:34:35409 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
410 // have no current paint buffer.
411 if (current_paint_buf_) {
412 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
413 current_paint_buf_ = NULL;
414 }
415
[email protected]65225772011-05-12 21:10:24416 // If swapbuffers is still pending, then defer the update until the
417 // swapbuffers occurs.
418 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
419 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
420 return;
421 }
422
[email protected]29ed96a2012-02-04 18:12:16423 // Notify subclasses that software rendering was flushed to the screen.
424 DidFlushPaint();
[email protected]a2f6bc112009-06-27 16:27:25425
initial.commit09911bf2008-07-26 23:55:29426 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24427 DoDeferredUpdateAndSendInputAck();
428}
429
[email protected]d0be63772011-12-20 23:18:04430bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24431 return false;
432}
433
[email protected]d0be63772011-12-20 23:18:04434void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24435 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21436 while (!updates_pending_swap_.empty()) {
437 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
438 updates_pending_swap_.pop_front();
439 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
440 // compositing pass, hence doesn't require an UpdateRect message.
441 if (msg)
442 Send(msg);
443 }
[email protected]65225772011-05-12 21:10:24444 num_swapbuffers_complete_pending_ = 0;
445 using_asynchronous_swapbuffers_ = false;
446 // Schedule another frame so the compositor learns about it.
447 scheduleComposite();
448}
449
[email protected]37a6f302011-07-11 23:43:08450void RenderWidget::OnSwapBuffersPosted() {
451 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21452
453 if (using_asynchronous_swapbuffers_) {
454 ViewHostMsg_UpdateRect* msg = NULL;
455 // pending_update_params_ can be NULL if the swap doesn't correspond to an
456 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
457 // message.
458 if (pending_update_params_.get()) {
459 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
460 pending_update_params_.reset();
461 }
462 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08463 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21464 }
[email protected]37a6f302011-07-11 23:43:08465}
466
467void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24468 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16469
470 // Notify subclasses that composited rendering got flushed to the screen.
471 DidFlushPaint();
472
[email protected]65225772011-05-12 21:10:24473 // When compositing deactivates, we reset the swapbuffers pending count. The
474 // swapbuffers acks may still arrive, however.
475 if (num_swapbuffers_complete_pending_ == 0) {
476 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
477 return;
478 }
[email protected]aa4117f2011-12-09 22:19:21479 DCHECK(!updates_pending_swap_.empty());
480 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
481 updates_pending_swap_.pop_front();
482 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
483 // compositing pass, hence doesn't require an UpdateRect message.
484 if (msg)
485 Send(msg);
[email protected]65225772011-05-12 21:10:24486 num_swapbuffers_complete_pending_--;
487
488 // If update reply is still pending, then defer the update until that reply
489 // occurs.
[email protected]d0be63772011-12-20 23:18:04490 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24491 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
492 return;
493 }
494
495 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06496 // when we were previously rendering. However, if an invalidation task is not
497 // posted, there may be software rendering work pending. In that case, don't
498 // early out.
499 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24500 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
501 return;
502 }
503
[email protected]65225772011-05-12 21:10:24504 // Continue painting if necessary...
505 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29506}
507
initial.commit09911bf2008-07-26 23:55:29508void RenderWidget::OnHandleInputEvent(const IPC::Message& message) {
[email protected]65225772011-05-12 21:10:24509 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
[email protected]ce208f872012-03-07 20:42:56510 PickleIterator iter(message);
initial.commit09911bf2008-07-26 23:55:29511
512 const char* data;
513 int data_length;
[email protected]5dd768212009-08-13 23:34:49514 handling_input_event_ = true;
515 if (!message.ReadData(&iter, &data, &data_length)) {
516 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29517 return;
[email protected]5dd768212009-08-13 23:34:49518 }
initial.commit09911bf2008-07-26 23:55:29519
520 const WebInputEvent* input_event =
521 reinterpret_cast<const WebInputEvent*>(data);
[email protected]867125a02009-12-10 06:01:48522
[email protected]b68a0e52011-12-08 15:11:12523 bool is_keyboard_shortcut = false;
524 // is_keyboard_shortcut flag is only available for RawKeyDown events.
525 if (input_event->type == WebInputEvent::RawKeyDown)
526 message.ReadBool(&iter, &is_keyboard_shortcut);
527
[email protected]67bfb83f2011-09-22 03:36:37528 bool prevent_default = false;
529 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26530 const WebMouseEvent& mouse_event =
531 *static_cast<const WebMouseEvent*>(input_event);
532 TRACE_EVENT2("renderer", "HandleMouseMove",
533 "x", mouse_event.x, "y", mouse_event.y);
534 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37535 }
536
537 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12538 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
539 suppress_next_char_events_ = false;
540 if (!processed && webwidget_)
541 processed = webwidget_->handleInputEvent(*input_event);
542 }
543
544 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
545 // it's not processed by webkit, then we need to suppress the upcoming Char
546 // events.
547 if (!processed && is_keyboard_shortcut)
548 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29549
[email protected]a9fb30aa2011-10-06 06:58:46550 IPC::Message* response =
551 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
552 processed);
[email protected]e2824412009-02-27 01:57:05553
[email protected]353a34c2010-05-28 23:35:17554 if ((input_event->type == WebInputEvent::MouseMove ||
[email protected]d93fc462011-03-14 23:03:03555 input_event->type == WebInputEvent::MouseWheel ||
[email protected]d329a912012-01-27 01:55:01556 WebInputEvent::isTouchEventType(input_event->type)) &&
[email protected]552e6002009-11-19 05:24:57557 paint_aggregator_.HasPendingUpdate()) {
[email protected]12fbad812009-09-01 18:21:24558 // We want to rate limit the input events in this case, so we'll wait for
559 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17560 if (pending_input_event_ack_.get()) {
561 // As two different kinds of events could cause us to postpone an ack
562 // we send it now, if we have one pending. The Browser should never
563 // send us the same kind of event we are delaying the ack for.
564 Send(pending_input_event_ack_.release());
565 }
[email protected]12fbad812009-09-01 18:21:24566 pending_input_event_ack_.reset(response);
567 } else {
568 Send(response);
569 }
570
[email protected]5dd768212009-08-13 23:34:49571 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48572
[email protected]67bfb83f2011-09-22 03:36:37573 if (!prevent_default) {
574 if (WebInputEvent::isKeyboardEventType(input_event->type))
575 DidHandleKeyEvent();
576 if (WebInputEvent::isMouseEventType(input_event->type))
577 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24578 if (WebInputEvent::isTouchEventType(input_event->type))
579 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37580 }
initial.commit09911bf2008-07-26 23:55:29581}
582
583void RenderWidget::OnMouseCaptureLost() {
584 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28585 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29586}
587
588void RenderWidget::OnSetFocus(bool enable) {
589 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33590 if (webwidget_)
591 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29592}
593
594void RenderWidget::ClearFocus() {
595 // We may have got the focus from the browser before this gets processed, in
596 // which case we do not want to unfocus ourself.
597 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28598 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29599}
600
[email protected]2d5d09d52009-06-15 14:29:21601void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00602 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21603 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06604 TRACE_EVENT2("renderer", "PaintRect",
605 "width", rect.width(), "height", rect.height());
[email protected]4fb66842009-12-04 21:41:00606 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21607
608 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00609 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
610 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03611
[email protected]4b03e292012-02-13 18:40:07612 if (invert_) {
613 // Draw everything to a temporary bitmap and then apply an
614 // inverting color map to the result. This is balanced by an extra
615 // call to canvas->restore(), below.
616 DCHECK(invert_paint_.get());
[email protected]1835b9e2012-02-28 13:12:48617 SkRect bounds(gfx::RectToSkRect(rect));
[email protected]4b03e292012-02-13 18:40:07618 canvas->saveLayer(&bounds, invert_paint_.get());
619 }
620
[email protected]699ab0d2009-04-23 23:19:14621 // If there is a custom background, tile it.
622 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14623 SkPaint paint;
624 SkShader* shader = SkShader::CreateBitmapShader(background_,
625 SkShader::kRepeat_TileMode,
626 SkShader::kRepeat_TileMode);
627 paint.setShader(shader)->unref();
[email protected]fb10ec5b2011-10-24 17:54:20628
629 // Use kSrc_Mode to handle background_ transparency properly.
630 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
631
632 // Canvas could contain multiple update rects. Clip to given rect so that
633 // we don't accidentally clear other update rects.
634 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48635 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14636 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20637 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14638 }
639
[email protected]719b36f2010-12-22 20:36:46640 // First see if this rect is a plugin that can paint itself faster.
641 TransportDIB* optimized_dib = NULL;
642 gfx::Rect optimized_copy_rect, optimized_copy_location;
643 webkit::ppapi::PluginInstance* optimized_instance =
644 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
645 &optimized_copy_location,
646 &optimized_copy_rect);
647 if (optimized_instance) {
648 // This plugin can be optimize-painted and we can just ask it to paint
649 // itself. We don't actually need the TransportDIB in this case.
650 //
651 // This is an optimization for PPAPI plugins that know they're on top of
652 // the page content. If this rect is inside such a plugin, we can save some
653 // time and avoid re-rendering the page content which we know will be
654 // covered by the plugin later (this time can be significant, especially
655 // for a playing movie that is invalidating a lot).
656 //
657 // In the plugin movie case, hopefully the similar call to
658 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
659 // painting, because that avoids copying the plugin image to a different
660 // paint rect. Unfortunately, if anything on the page is animating other
661 // than the movie, it break this optimization since the union of the
662 // invalid regions will be larger than the plugin.
663 //
664 // This code optimizes that case, where we can still avoid painting in
665 // WebKit and filling the background (which can be slow) and just painting
666 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
667 // required.
668 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27669 optimized_copy_location, rect);
[email protected]719b36f2010-12-22 20:36:46670 } else {
671 // Normal painting case.
672 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
673
674 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35675 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46676 }
initial.commit09911bf2008-07-26 23:55:29677
[email protected]4b03e292012-02-13 18:40:07678 if (invert_)
679 canvas->restore();
680
[email protected]4fb66842009-12-04 21:41:00681 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00682 canvas->restore();
683}
684
685void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
686 skia::PlatformCanvas* canvas) {
687 static bool kPaintBorder =
688 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
689 if (!kPaintBorder)
690 return;
691
[email protected]53d3f302009-12-21 04:42:05692 // Cycle through these colors to help distinguish new paint rects.
693 const SkColor colors[] = {
694 SkColorSetARGB(0x3F, 0xFF, 0, 0),
695 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
696 SkColorSetARGB(0x3F, 0, 0, 0xFF),
697 };
698 static int color_selector = 0;
699
[email protected]4fb66842009-12-04 21:41:00700 SkPaint paint;
701 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05702 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00703 paint.setStrokeWidth(1);
704
705 SkIRect irect;
706 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
707 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29708}
709
[email protected]52ccd0ea2011-02-16 01:09:05710void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30711 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]52ccd0ea2011-02-16 01:09:05712 animation_task_posted_ = false;
[email protected]921244e42011-07-20 16:36:30713 if (!animation_update_pending_) {
714 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59715 return;
[email protected]921244e42011-07-20 16:36:30716 }
[email protected]bd37ae252011-06-03 01:28:18717 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59718 // Record when we fired (according to base::Time::Now()) relative to when
719 // we posted the task to quantify how much the base::Time/base::TimeTicks
720 // skew is affecting animations.
721 base::TimeDelta animation_callback_delay = base::Time::Now() -
722 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
723 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
724 animation_callback_delay,
725 base::TimeDelta::FromMilliseconds(0),
726 base::TimeDelta::FromMilliseconds(30),
727 25);
728 }
[email protected]65225772011-05-12 21:10:24729 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24730}
731
[email protected]52ccd0ea2011-02-16 01:09:05732void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59733 if (!animation_update_pending_)
734 return;
[email protected]bd37ae252011-06-03 01:28:18735
736 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33737 base::TimeDelta animationInterval = IsRenderingVSynced() ?
738 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18739
[email protected]7c4329e2011-02-18 22:02:59740 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45741
742 // animation_floor_time_ is the earliest time that we should animate when
743 // using the dead reckoning software scheduler. If we're using swapbuffers
744 // complete callbacks to rate limit, we can ignore this floor.
745 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30746 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33747 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18748 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59749 // running animation callbacks so that if a callback requests another
750 // we'll be sure to run it at the proper time.
[email protected]32876ae2011-11-15 22:25:21751 MessageLoop::current()->PostDelayedTask(
752 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this),
753 animationInterval);
[email protected]7c4329e2011-02-18 22:02:59754 animation_task_posted_ = true;
755 animation_update_pending_ = false;
[email protected]a5922cc2011-05-24 23:06:30756 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59757 return;
[email protected]5f8b1022011-01-21 23:34:50758 }
[email protected]bd37ae252011-06-03 01:28:18759 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]7c4329e2011-02-18 22:02:59760 if (animation_task_posted_)
761 return;
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.
[email protected]02798a982012-01-27 00:45:33770 base::TimeDelta delay = animation_floor_time_ - now;
[email protected]7c4329e2011-02-18 22:02:59771 animation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:21772 MessageLoop::current()->PostDelayedTask(
773 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), delay);
[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.
1012 if (is_accelerated_compositing_active_ && animation_task_posted_)
[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.
1050 if (is_accelerated_compositing_active_ && animation_task_posted_)
[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]52ccd0ea2011-02-16 01:09:051148 if (!animation_task_posted_) {
1149 animation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211150 MessageLoop::current()->PostTask(
1151 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this));
[email protected]52ccd0ea2011-02-16 01:09:051152 }
[email protected]ee3d3ad2011-02-04 00:42:211153 }
[email protected]5f8b1022011-01-21 23:34:501154}
1155
[email protected]4873c7d2009-07-16 06:36:281156void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301157 // TODO(darin): Eliminate this temporary.
1158 WebCursor cursor(cursor_info);
1159
initial.commit09911bf2008-07-26 23:55:291160 // Only send a SetCursor message if we need to make a change.
1161 if (!current_cursor_.IsEqual(cursor)) {
1162 current_cursor_ = cursor;
1163 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1164 }
1165}
1166
1167// We are supposed to get a single call to Show for a newly created RenderWidget
1168// that was created via RenderWidget::CreateWebView. So, we wait until this
1169// point to dispatch the ShowWidget message.
1170//
1171// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281172// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291173//
[email protected]4873c7d2009-07-16 06:36:281174void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291175 DCHECK(!did_show_) << "received extraneous Show call";
1176 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1177 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1178
[email protected]8de12d942010-11-17 20:42:441179 if (did_show_)
1180 return;
1181
1182 did_show_ = true;
1183 // NOTE: initial_pos_ may still have its default values at this point, but
1184 // that's okay. It'll be ignored if as_popup is false, or the browser
1185 // process will impose a default position otherwise.
1186 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1187 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291188}
1189
[email protected]4873c7d2009-07-16 06:36:281190void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291191}
1192
[email protected]4873c7d2009-07-16 06:36:281193void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291194}
1195
[email protected]2533ce12009-05-09 00:02:241196void RenderWidget::DoDeferredClose() {
1197 Send(new ViewHostMsg_Close(routing_id_));
1198}
1199
[email protected]4873c7d2009-07-16 06:36:281200void RenderWidget::closeWidgetSoon() {
initial.commit09911bf2008-07-26 23:55:291201 // If a page calls window.close() twice, we'll end up here twice, but that's
1202 // OK. It is safe to send multiple Close messages.
1203
[email protected]2533ce12009-05-09 00:02:241204 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1205 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1206 // could be closed before the JS finishes executing. So instead, post a
1207 // message back to the message loop, which won't run until the JS is
1208 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211209 MessageLoop::current()->PostTask(
1210 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291211}
1212
1213void RenderWidget::Close() {
1214 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281215 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291216 webwidget_ = NULL;
1217 }
1218}
1219
[email protected]4873c7d2009-07-16 06:36:281220WebRect RenderWidget::windowRect() {
1221 if (pending_window_rect_count_)
1222 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241223
[email protected]b3f2b912009-04-09 16:18:521224 gfx::Rect rect;
1225 Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281226 return rect;
initial.commit09911bf2008-07-26 23:55:291227}
1228
[email protected]8a9d6ca32011-06-06 20:11:301229void RenderWidget::setToolTipText(const WebKit::WebString& text,
1230 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541231 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301232}
1233
[email protected]4873c7d2009-07-16 06:36:281234void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291235 if (did_show_) {
1236 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241237 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291238 } else {
1239 initial_pos_ = pos;
1240 }
1241}
1242
[email protected]2533ce12009-05-09 00:02:241243void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1244 pending_window_rect_ = rect;
1245 pending_window_rect_count_++;
1246}
1247
[email protected]4873c7d2009-07-16 06:36:281248WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241249 if (pending_window_rect_count_) {
1250 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1251 // the RootWindowRect is probably going to return wrong results since the
1252 // browser may not have processed the Move yet. There isn't really anything
1253 // good to do in this case, and it shouldn't happen - since this size is
1254 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281255 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241256 }
1257
[email protected]b3f2b912009-04-09 16:18:521258 gfx::Rect rect;
1259 Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect));
[email protected]4873c7d2009-07-16 06:36:281260 return rect;
[email protected]d4547452008-08-28 18:36:371261}
1262
[email protected]4873c7d2009-07-16 06:36:281263WebRect RenderWidget::windowResizerRect() {
1264 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191265}
1266
[email protected]fa7b1dc2010-06-23 17:53:041267void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031268 // To prevent this renderer process from sending unnecessary IPC messages to
1269 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041270 // only during the input method attached to the browser process is active.
1271 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291272}
1273
[email protected]fa7b1dc2010-06-23 17:53:041274void RenderWidget::OnImeSetComposition(
1275 const string16& text,
1276 const std::vector<WebCompositionUnderline>& underlines,
1277 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281278 if (!webwidget_)
1279 return;
[email protected]d4cff272011-05-02 15:46:011280 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041281 text, WebVector<WebCompositionUnderline>(underlines),
1282 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011283 // Setting the IME composition was successful. Send the new composition
1284 // range to the browser.
1285 ui::Range range(ui::Range::InvalidRange());
1286 size_t location, length;
1287 if (webwidget_->compositionRange(&location, &length)) {
1288 range.set_start(location);
1289 range.set_end(location + length);
1290 }
1291 // The IME was cancelled via the Esc key, so just send back the caret.
1292 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1293 range.set_start(location);
1294 range.set_end(location + length);
1295 }
1296 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
1297 } else {
[email protected]fa7b1dc2010-06-23 17:53:041298 // If we failed to set the composition text, then we need to let the browser
1299 // process to cancel the input method's ongoing composition session, to make
1300 // sure we are in a consistent state.
1301 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011302
1303 // Send an updated IME range with just the caret range.
1304 ui::Range range(ui::Range::InvalidRange());
1305 size_t location, length;
1306 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1307 range.set_start(location);
1308 range.set_end(location + length);
1309 }
1310 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]7f00efa2010-04-15 05:01:261311 }
[email protected]fa7b1dc2010-06-23 17:53:041312}
1313
[email protected]4de6d1692011-10-12 08:45:441314void RenderWidget::OnImeConfirmComposition(
1315 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041316 if (!webwidget_)
1317 return;
1318
1319 handling_input_event_ = true;
1320 webwidget_->confirmComposition(text);
1321 handling_input_event_ = false;
1322
[email protected]d4cff272011-05-02 15:46:011323 // Send an updated IME range with just the caret range.
1324 ui::Range range(ui::Range::InvalidRange());
1325 size_t location, length;
1326 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1327 range.set_start(location);
1328 range.set_end(location + length);
1329 }
1330 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
initial.commit09911bf2008-07-26 23:55:291331}
1332
[email protected]948f7ab72010-05-28 23:48:081333// This message causes the renderer to render an image of the
1334// desired_size, regardless of whether the tab is hidden or not.
[email protected]d65adb12010-04-28 17:26:491335void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
[email protected]c88c9442010-07-19 18:55:091336 int tag,
[email protected]948f7ab72010-05-28 23:48:081337 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:491338 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001339 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1340 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251341 // Close our unused handle.
1342#if defined(OS_WIN)
1343 ::CloseHandle(dib_handle);
1344#elif defined(OS_MACOSX)
1345 base::SharedMemory::CloseHandle(dib_handle);
1346#endif
1347 }
[email protected]d65adb12010-04-28 17:26:491348 return;
[email protected]45c6aad32010-11-11 04:46:251349 }
[email protected]d65adb12010-04-28 17:26:491350
[email protected]948f7ab72010-05-28 23:48:081351 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491352 // If one of these is empty, then we just return the dib we were
1353 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091354 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491355 return;
1356 }
1357
1358 // Map the given DIB ID into this process, and unmap it at the end
1359 // of this function.
[email protected]45c6aad32010-11-11 04:46:251360 scoped_ptr<TransportDIB> paint_at_size_buffer(
1361 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301362
1363 gfx::Size canvas_size = page_size;
[email protected]d65adb12010-04-28 17:26:491364 float x_scale = static_cast<float>(desired_size.width()) /
1365 static_cast<float>(canvas_size.width());
1366 float y_scale = static_cast<float>(desired_size.height()) /
1367 static_cast<float>(canvas_size.height());
1368
[email protected]ee8d6fd2010-05-26 17:05:481369 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491370 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1371 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481372 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491373
[email protected]36808ad2010-10-20 19:18:301374 scoped_ptr<skia::PlatformCanvas> canvas(
1375 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1376 canvas_size.height()));
1377 if (!canvas.get()) {
1378 NOTREACHED();
1379 return;
1380 }
1381
[email protected]d65adb12010-04-28 17:26:491382 // Reset bounds to what we actually received, but they should be the
1383 // same.
1384 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1385 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1386 bounds.set_width(canvas->getDevice()->width());
1387 bounds.set_height(canvas->getDevice()->height());
1388
1389 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081390 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491391 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1392
[email protected]948f7ab72010-05-28 23:48:081393 // Have to make sure we're laid out at the right size before
1394 // rendering.
1395 gfx::Size old_size = webwidget_->size();
1396 webwidget_->resize(page_size);
1397 webwidget_->layout();
1398
[email protected]d65adb12010-04-28 17:26:491399 // Paint the entire thing (using original bounds, not scaled bounds).
1400 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1401 canvas->restore();
1402
[email protected]948f7ab72010-05-28 23:48:081403 // Return the widget to its previous size.
1404 webwidget_->resize(old_size);
1405
[email protected]c88c9442010-07-19 18:55:091406 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491407}
1408
[email protected]ec7dc112008-08-06 05:30:121409void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1410 // During shutdown we can just ignore this message.
1411 if (!webwidget_)
1412 return;
1413
1414 set_next_paint_is_repaint_ack();
[email protected]a79d8a632010-11-18 22:35:561415 if (is_accelerated_compositing_active_) {
[email protected]8c49fa982012-02-10 14:37:041416 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461417 scheduleComposite();
1418 } else {
1419 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1420 didInvalidateRect(repaint_rect);
1421 }
[email protected]ec7dc112008-08-06 05:30:121422}
1423
[email protected]4873c7d2009-07-16 06:36:281424void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111425 if (!webwidget_)
1426 return;
[email protected]4873c7d2009-07-16 06:36:281427 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111428}
1429
[email protected]4b03e292012-02-13 18:40:071430void RenderWidget::OnInvertWebContent(bool invert) {
1431 if (invert_ == invert)
1432 return;
1433
1434 invert_ = invert;
1435
1436 if (invert_ && !invert_paint_.get()) {
1437 // Gamma-aware color inversion: each source pixel value x is normally
1438 // displayed on a computer monitor with a gamma correction x^gamma,
1439 // where gamma is typically in the range 1.8...2.2. By approximating
1440 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2).
1441 uint8_t table[256];
1442 for (unsigned int i = 0; i < 256; i++) {
1443 double value = i / 255.0;
1444 value = sqrt(1 - (value * value));
1445 table[i] = static_cast<uint8_t>(255 * value);
1446 }
1447
1448 // Create a Skia Paint with this inverting color map.
1449 invert_paint_.reset(new SkPaint());
1450 invert_paint_->setStyle(SkPaint::kFill_Style);
1451 invert_paint_->setColor(SK_ColorBLACK);
1452 SkColorFilter* filter = SkTableColorFilter::CreateARGB(
1453 NULL, table, table, table);
1454 invert_paint_->setColorFilter(filter);
1455 filter->unref();
1456 }
1457
1458 OnMsgRepaint(size_);
1459}
1460
[email protected]719b36f2010-12-22 20:36:461461webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151462 const gfx::Rect& paint_bounds,
1463 TransportDIB** dib,
1464 gfx::Rect* location,
1465 gfx::Rect* clip) {
[email protected]719b36f2010-12-22 20:36:461466 // Bare RenderWidgets don't support optimized plugin painting.
1467 return NULL;
[email protected]ca4847f2010-09-24 05:39:151468}
1469
[email protected]bcaf2272011-02-15 15:29:431470gfx::Point RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521471 // Bare RenderWidgets don't support scroll offset.
[email protected]bcaf2272011-02-15 15:29:431472 return gfx::Point(0, 0);
[email protected]d54169e92011-01-21 09:19:521473}
1474
[email protected]bee16aab2009-08-26 15:55:031475void RenderWidget::SetHidden(bool hidden) {
1476 if (is_hidden_ == hidden)
1477 return;
1478
1479 // The status has changed. Tell the RenderThread about it.
1480 is_hidden_ = hidden;
1481 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271482 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031483 else
[email protected]380244092011-10-07 17:26:271484 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031485}
1486
[email protected]2b624c562011-10-27 22:58:261487void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261488 if (!webwidget_)
1489 return;
1490
1491 if (is_fullscreen_) {
1492 webwidget_->willExitFullScreen();
1493 } else {
1494 webwidget_->willEnterFullScreen();
1495 }
[email protected]2b624c562011-10-27 22:58:261496}
1497
1498void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261499 if (!webwidget_)
1500 return;
1501
1502 if (is_fullscreen_) {
1503 webwidget_->didEnterFullScreen();
1504 } else {
1505 webwidget_->didExitFullScreen();
1506 }
[email protected]2b624c562011-10-27 22:58:261507}
1508
[email protected]699ab0d2009-04-23 23:19:141509void RenderWidget::SetBackground(const SkBitmap& background) {
1510 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461511
[email protected]699ab0d2009-04-23 23:19:141512 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281513 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141514}
1515
[email protected]674741932009-02-04 23:44:461516bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051517 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461518}
1519
1520bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051521 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461522}
1523
1524void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051525 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461526}
1527
1528void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051529 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461530}
1531
1532void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051533 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461534}
1535
[email protected]e99ef6f2011-10-16 01:13:001536void RenderWidget::UpdateTextInputState() {
[email protected]fa7b1dc2010-06-23 17:53:041537 if (!input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291538 return;
[email protected]fa7b1dc2010-06-23 17:53:041539
[email protected]ad26ef42011-06-17 07:59:451540 ui::TextInputType new_type = GetTextInputType();
1541 bool new_can_compose_inline = CanComposeInline();
[email protected]e99ef6f2011-10-16 01:13:001542 // Only sends text input type and compose inline to the browser process if
1543 // they are changed.
1544 if (text_input_type_ != new_type ||
[email protected]ad26ef42011-06-17 07:59:451545 can_compose_inline_ != new_can_compose_inline) {
[email protected]fa7b1dc2010-06-23 17:53:041546 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451547 can_compose_inline_ = new_can_compose_inline;
[email protected]e99ef6f2011-10-16 01:13:001548 Send(new ViewHostMsg_TextInputStateChanged(
1549 routing_id(), new_type, new_can_compose_inline));
initial.commit09911bf2008-07-26 23:55:291550 }
initial.commit09911bf2008-07-26 23:55:291551}
1552
[email protected]3f783362011-10-21 22:40:501553void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1554 WebRect start_webrect;
1555 WebRect end_webrect;
1556 webwidget_->selectionBounds(start_webrect, end_webrect);
1557 *start = start_webrect;
1558 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321559}
1560
[email protected]e99ef6f2011-10-16 01:13:001561void RenderWidget::UpdateSelectionBounds() {
1562 if (!webwidget_)
1563 return;
1564
[email protected]3f783362011-10-21 22:40:501565 gfx::Rect start_rect;
1566 gfx::Rect end_rect;
1567 GetSelectionBounds(&start_rect, &end_rect);
[email protected]e99ef6f2011-10-16 01:13:001568 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
1569 return;
1570
1571 selection_start_rect_ = start_rect;
1572 selection_end_rect_ = end_rect;
1573 Send(new ViewHostMsg_SelectionBoundsChanged(
1574 routing_id_, selection_start_rect_, selection_end_rect_));
1575}
1576
[email protected]73bf95812011-10-12 11:38:321577// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451578COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1579 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1580COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1581 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1582COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1583 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181584COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1585 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1586COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1587 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1588COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1589 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1590COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1591 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1592COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1593 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451594
1595ui::TextInputType RenderWidget::GetTextInputType() {
1596 if (webwidget_) {
1597 int type = webwidget_->textInputType();
1598 // Check the type is in the range representable by ui::TextInputType.
[email protected]caf38ed2011-07-28 13:15:181599 DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) <<
[email protected]ad26ef42011-06-17 07:59:451600 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1601 return static_cast<ui::TextInputType>(type);
1602 }
1603 return ui::TEXT_INPUT_TYPE_NONE;
1604}
1605
1606bool RenderWidget::CanComposeInline() {
1607 return true;
[email protected]56ea1a62011-05-30 07:05:571608}
1609
[email protected]4873c7d2009-07-16 06:36:281610WebScreenInfo RenderWidget::screenInfo() {
[email protected]6fd35b72012-03-01 19:46:411611 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281612}
1613
[email protected]fa7b1dc2010-06-23 17:53:041614void RenderWidget::resetInputMethod() {
1615 if (!input_method_is_active_)
1616 return;
1617
1618 // If the last text input type is not None, then we should finish any
1619 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451620 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041621 // If a composition text exists, then we need to let the browser process
1622 // to cancel the input method's ongoing composition session.
1623 if (webwidget_->confirmComposition())
1624 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1625 }
[email protected]d4cff272011-05-02 15:46:011626
1627 // Send an updated IME range with the current caret rect.
1628 ui::Range range(ui::Range::InvalidRange());
1629 size_t location, length;
1630 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1631 range.set_start(location);
1632 range.set_end(location + length);
1633 }
1634 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
[email protected]fa7b1dc2010-06-23 17:53:041635}
1636
[email protected]f103ab72009-09-02 17:10:591637void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501638 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291639 size_t i = 0;
1640 for (; i < plugin_window_moves_.size(); ++i) {
1641 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581642 if (move.rects_valid) {
1643 plugin_window_moves_[i] = move;
1644 } else {
1645 plugin_window_moves_[i].visible = move.visible;
1646 }
initial.commit09911bf2008-07-26 23:55:291647 break;
1648 }
1649 }
1650
1651 if (i == plugin_window_moves_.size())
1652 plugin_window_moves_.push_back(move);
1653}
[email protected]268654772009-08-06 23:02:041654
1655void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1656 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1657 i != plugin_window_moves_.end(); ++i) {
1658 if (i->window == window) {
1659 plugin_window_moves_.erase(i);
1660 break;
1661 }
1662 }
1663}
[email protected]67bfb83f2011-09-22 03:36:371664
1665bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
1666 return false;
1667}
[email protected]c3d45532011-10-07 19:20:401668
1669bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1670 return false;
1671}