blob: f97d0fc93662fefc8263d201a6cef5920e758401 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]32876ae2011-11-15 22:25:217#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:008#include "base/command_line.h"
[email protected]366ae242011-05-10 02:23:589#include "base/debug/trace_event.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2114#include "base/stl_util.h"
[email protected]8a9d6ca32011-06-06 20:11:3015#include "base/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4816#include "build/build_config.h"
[email protected]992db4c2011-05-12 15:37:1517#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5018#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2919#include "content/public/common/content_switches.h"
[email protected]8704f89b2011-04-15 00:30:0520#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4421#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1922#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1823#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4824#include "skia/ext/platform_canvas.h"
[email protected]8bd0fe62011-01-17 06:44:3725#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]4b1146bc2012-07-10 18:46:0326#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]a7547fb2012-03-08 04:43:4427#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3728#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
29#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0130#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3731#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4132#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
33#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]e6e90dc2011-12-03 00:01:3734#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
35#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
[email protected]d353541f2012-05-03 22:45:4136#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1337#include "ui/base/ui_base_switches.h"
[email protected]a25e25b2012-09-28 14:32:3738#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3539#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4840#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2741#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4142#include "ui/surface/transport_dib.h"
[email protected]b63d58d2012-11-26 22:37:4443#include "webkit/compositor_bindings/web_rendering_stats_impl.h"
[email protected]8c89e7792009-08-19 21:18:3444#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5045#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4646#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4847
48#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4949#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5250#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4151#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4852#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4453
[email protected]8bd0fe62011-01-17 06:44:3754#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2955
[email protected]fa7b1dc2010-06-23 17:53:0456using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3057using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2458using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2259using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0660using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2861using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4462using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0063using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2864using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5965using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1866using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0167using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5268using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1969using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5270using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2871using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2472using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0473using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1874using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2675
[email protected]6a4d7f62013-01-07 21:32:1376namespace {
77const char* GetEventName(WebInputEvent::Type type) {
78#define CASE_TYPE(t) case WebInputEvent::t: return #t
79 switch(type) {
80 CASE_TYPE(Undefined);
81 CASE_TYPE(MouseDown);
82 CASE_TYPE(MouseUp);
83 CASE_TYPE(MouseMove);
84 CASE_TYPE(MouseEnter);
85 CASE_TYPE(MouseLeave);
86 CASE_TYPE(ContextMenu);
87 CASE_TYPE(MouseWheel);
88 CASE_TYPE(RawKeyDown);
89 CASE_TYPE(KeyDown);
90 CASE_TYPE(KeyUp);
91 CASE_TYPE(Char);
92 CASE_TYPE(GestureScrollBegin);
93 CASE_TYPE(GestureScrollEnd);
94 CASE_TYPE(GestureScrollUpdate);
95 CASE_TYPE(GestureFlingStart);
96 CASE_TYPE(GestureFlingCancel);
97 CASE_TYPE(GestureTap);
98 CASE_TYPE(GestureTapDown);
99 CASE_TYPE(GestureTapCancel);
100 CASE_TYPE(GestureDoubleTap);
101 CASE_TYPE(GestureTwoFingerTap);
102 CASE_TYPE(GestureLongPress);
103 CASE_TYPE(GestureLongTap);
104 CASE_TYPE(GesturePinchBegin);
105 CASE_TYPE(GesturePinchEnd);
106 CASE_TYPE(GesturePinchUpdate);
107 CASE_TYPE(TouchStart);
108 CASE_TYPE(TouchMove);
109 CASE_TYPE(TouchEnd);
110 CASE_TYPE(TouchCancel);
111 // Don't include default, so that we get an error when new type is added.
112 }
113#undef CASE_TYPE
114 NOTREACHED();
115 return "Undefined";
116}
117}
[email protected]e9ff79c2012-10-19 21:31:26118namespace content {
[email protected]62cb33cae2009-03-27 23:30:22119
[email protected]6fd35b72012-03-01 19:46:41120RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04121 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44122 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29123 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56124 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11125 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29126 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30127 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35128 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:29129 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06130 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05131 update_reply_pending_(false),
[email protected]ea3ee0a2012-05-15 03:43:09132 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24133 using_asynchronous_swapbuffers_(false),
134 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29135 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29136 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09137 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29138 needs_repainting_on_restore_(false),
139 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49140 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:48141 closing_(false),
[email protected]14392a52012-05-02 20:28:44142 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04143 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45144 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
145 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12146 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48147 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12148 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50149 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21150 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07151 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04152 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52153 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27154 throttle_input_events_(true),
[email protected]cb6430932012-10-31 00:53:36155 next_smooth_scroll_gesture_id_(0),
156 is_threaded_compositing_enabled_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05157 if (!swapped_out)
158 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27159 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18160 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
161 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36162 is_threaded_compositing_enabled_ =
163 CommandLine::ForCurrentProcess()->HasSwitch(
164 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29165}
166
167RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11168 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21169 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35170 if (current_paint_buf_) {
171 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
172 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29173 }
[email protected]992db4c2011-05-12 15:37:15174 // If we are swapped out, we have released already.
175 if (!is_swapped_out_)
176 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29177}
178
[email protected]484955942010-08-19 16:13:18179// static
[email protected]8085dbc82008-09-26 22:53:44180RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04181 WebKit::WebPopupType popup_type,
182 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29183 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41184 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04185 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29186 if (widget->Init(opener_id)) { // adds reference on success.
187 return widget;
188 }
189 return NULL;
initial.commit09911bf2008-07-26 23:55:29190}
191
[email protected]484955942010-08-19 16:13:18192// static
193WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
194 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03195 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18196 break;
197 case WebKit::WebPopupTypeSelect:
198 case WebKit::WebPopupTypeSuggestion:
199 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44200 case WebKit::WebPopupTypePage:
201 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03202 case WebKit::WebPopupTypeHelperPlugin:
203 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18204 default:
205 NOTREACHED();
206 }
207 return NULL;
208}
209
[email protected]a635f942012-12-07 10:34:29210bool RenderWidget::Init(int32 opener_id) {
211 return DoInit(opener_id,
212 RenderWidget::CreateWebWidget(this),
213 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
214 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18215}
216
[email protected]a635f942012-12-07 10:34:29217bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06218 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18219 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29220 DCHECK(!webwidget_);
221
222 if (opener_id != MSG_ROUTING_NONE)
223 opener_id_ = opener_id;
224
[email protected]484955942010-08-19 16:13:18225 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29226
[email protected]380244092011-10-07 17:26:27227 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29228 if (result) {
[email protected]380244092011-10-07 17:26:27229 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29230 // Take a reference on behalf of the RenderThread. This will be balanced
231 // when we receive ViewMsg_Close.
232 AddRef();
[email protected]a635f942012-12-07 10:34:29233 return true;
initial.commit09911bf2008-07-26 23:55:29234 } else {
[email protected]a635f942012-12-07 10:34:29235 // The above Send can fail when the tab is closing.
236 return false;
initial.commit09911bf2008-07-26 23:55:29237 }
238}
239
[email protected]fc4404d2012-11-07 19:53:30240// This is used to complete pending inits and non-pending inits.
241void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29242 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29243
[email protected]fc4404d2012-11-07 19:53:30244 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42245
[email protected]ffd156732013-01-09 18:29:11246 if (webwidget_) {
247 webwidget_->setCompositorSurfaceReady();
248 if (is_threaded_compositing_enabled_)
249 webwidget_->enterForceCompositingMode(true);
[email protected]479b0172012-10-29 19:27:09250 }
[email protected]05a980d7a2012-02-07 22:16:42251 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29252
[email protected]6de74452009-02-25 18:04:59253 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29254}
255
[email protected]992db4c2011-05-12 15:37:15256void RenderWidget::SetSwappedOut(bool is_swapped_out) {
257 // We should only toggle between states.
258 DCHECK(is_swapped_out_ != is_swapped_out);
259 is_swapped_out_ = is_swapped_out;
260
261 // If we are swapping out, we will call ReleaseProcess, allowing the process
262 // to exit if all of its RenderViews are swapped out. We wait until the
263 // WasSwappedOut call to do this, to avoid showing the sad tab.
264 // If we are swapping in, we call AddRefProcess to prevent the process from
265 // exiting.
266 if (!is_swapped_out)
267 RenderProcess::current()->AddRefProcess();
268}
269
[email protected]a95986a82010-12-24 06:19:28270bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
271 bool handled = true;
272 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
273 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
274 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
275 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54276 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28277 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41278 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15279 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28280 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]a7266a92012-06-28 02:11:08281 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK, OnSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28282 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
283 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
284 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
285 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
286 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
287 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25288 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
289 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
290 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28291 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
292 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53293 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03294 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]a95986a82010-12-24 06:19:28295 IPC_MESSAGE_UNHANDLED(handled = false)
296 IPC_END_MESSAGE_MAP()
297 return handled;
298}
initial.commit09911bf2008-07-26 23:55:29299
300bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15301 // Don't send any messages after the browser has told us to close, and filter
302 // most outgoing messages while swapped out.
303 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26304 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11305 closing_) {
initial.commit09911bf2008-07-26 23:55:29306 delete message;
307 return false;
308 }
309
310 // If given a messsage without a routing ID, then assign our routing ID.
311 if (message->routing_id() == MSG_ROUTING_NONE)
312 message->set_routing_id(routing_id_);
313
[email protected]380244092011-10-07 17:26:27314 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44315}
316
[email protected]61e2b3cc2012-03-02 16:13:34317void RenderWidget::Resize(const gfx::Size& new_size,
318 const gfx::Rect& resizer_rect,
319 bool is_fullscreen,
320 ResizeAck resize_ack) {
321 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
322 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
323 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29324
[email protected]61e2b3cc2012-03-02 16:13:34325 // Ignore this during shutdown.
326 if (!webwidget_)
327 return;
328
329 // Remember the rect where the resize corner will be drawn.
330 resizer_rect_ = resizer_rect;
331
332 // NOTE: We may have entered fullscreen mode without changing our size.
333 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
334 if (fullscreen_change)
335 WillToggleFullscreen();
336 is_fullscreen_ = is_fullscreen;
337
338 if (size_ != new_size) {
339 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34340 needs_repainting_on_restore_ = false;
341
342 size_ = new_size;
343
344 paint_aggregator_.ClearPendingUpdate();
345
346 // When resizing, we want to wait to paint before ACK'ing the resize. This
347 // ensures that we only resize as fast as we can paint. We only need to
348 // send an ACK if we are resized to a non-empty rect.
349 webwidget_->resize(new_size);
350 if (!new_size.IsEmpty()) {
351 if (!is_accelerated_compositing_active_) {
352 // Resize should have caused an invalidation of the entire view.
353 DCHECK(paint_aggregator_.HasPendingUpdate());
354 }
355
356 // Send the Resize_ACK flag once we paint again if requested.
357 if (resize_ack == SEND_RESIZE_ACK)
358 set_next_paint_is_resize_ack();
359 }
[email protected]ff475a322012-03-14 00:05:35360 } else {
361 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34362 }
363
364 if (fullscreen_change)
365 DidToggleFullscreen();
366
367 // If a resize ack is requested and it isn't set-up, then no more resizes will
368 // come in and in general things will go wrong.
369 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
370 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29371}
372
373void RenderWidget::OnClose() {
374 if (closing_)
375 return;
376 closing_ = true;
377
378 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03379 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27380 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03381 SetHidden(false);
382 }
initial.commit09911bf2008-07-26 23:55:29383
initial.commit09911bf2008-07-26 23:55:29384 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25385 // now. Post a task that only gets invoked when there are no nested message
386 // loops.
[email protected]32876ae2011-11-15 22:25:21387 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29388 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25389
390 // Balances the AddRef taken when we called AddRoute.
391 Release();
initial.commit09911bf2008-07-26 23:55:29392}
393
[email protected]61e2b3cc2012-03-02 16:13:34394// Got a response from the browser after the renderer decided to create a new
395// view.
[email protected]fc4404d2012-11-07 19:53:30396void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34397 DCHECK(routing_id_ != MSG_ROUTING_NONE);
398
[email protected]fc4404d2012-11-07 19:53:30399 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34400}
401
[email protected]f21c613a2009-02-12 14:46:17402void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09403 const gfx::Rect& resizer_rect,
404 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34405 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29406}
407
[email protected]b5913d72012-02-07 22:26:54408void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
409 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59410 gfx::Rect view_rect(size_);
411
[email protected]ce112fe2012-10-29 22:52:18412 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59413 if (!old_damage_rect.IsEmpty())
414 paint_aggregator_.InvalidateRect(old_damage_rect);
415
[email protected]ce112fe2012-10-29 22:52:18416 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59417 if (!new_damage_rect.IsEmpty())
418 paint_aggregator_.InvalidateRect(new_damage_rect);
419
[email protected]b5913d72012-02-07 22:26:54420 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59421
[email protected]b5913d72012-02-07 22:26:54422 if (webwidget_)
423 webwidget_->didChangeWindowResizerRect();
424 }
425}
426
initial.commit09911bf2008-07-26 23:55:29427void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31428 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29429 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03430 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29431}
432
[email protected]9e2e4632012-07-27 16:38:41433void RenderWidget::OnWasShown(bool needs_repainting) {
434 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29435 // During shutdown we can just ignore this message.
436 if (!webwidget_)
437 return;
438
439 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03440 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29441
442 if (!needs_repainting && !needs_repainting_on_restore_)
443 return;
444 needs_repainting_on_restore_ = false;
445
[email protected]d65adb12010-04-28 17:26:49446 // Tag the next paint as a restore ack, which is picked up by
447 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29448 set_next_paint_is_restore_ack();
449
450 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56451 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46452 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
453 } else {
454 scheduleComposite();
455 }
initial.commit09911bf2008-07-26 23:55:29456}
457
[email protected]992db4c2011-05-12 15:37:15458void RenderWidget::OnWasSwappedOut() {
459 // If we have been swapped out and no one else is using this process,
460 // it's safe to exit now. If we get swapped back in, we will call
461 // AddRefProcess in SetSwappedOut.
462 if (is_swapped_out_)
463 RenderProcess::current()->ReleaseProcess();
464}
465
[email protected]53d3f302009-12-21 04:42:05466void RenderWidget::OnRequestMoveAck() {
467 DCHECK(pending_window_rect_count_);
468 pending_window_rect_count_--;
469}
470
471void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58472 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21473 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05474 update_reply_pending_ = false;
475
[email protected]b4d08452010-10-05 17:34:35476 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
477 // have no current paint buffer.
478 if (current_paint_buf_) {
479 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
480 current_paint_buf_ = NULL;
481 }
482
[email protected]65225772011-05-12 21:10:24483 // If swapbuffers is still pending, then defer the update until the
484 // swapbuffers occurs.
485 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
486 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
487 return;
488 }
489
[email protected]29ed96a2012-02-04 18:12:16490 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18491 if (!is_accelerated_compositing_active_) {
492 DidFlushPaint();
493 }
[email protected]a2f6bc112009-06-27 16:27:25494
initial.commit09911bf2008-07-26 23:55:29495 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24496 DoDeferredUpdateAndSendInputAck();
497}
498
[email protected]d0be63772011-12-20 23:18:04499bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24500 return false;
501}
502
[email protected]479b0172012-10-29 19:27:09503bool RenderWidget::ForceCompositingModeEnabled() {
504 return false;
505}
506
[email protected]d0be63772011-12-20 23:18:04507void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24508 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21509 while (!updates_pending_swap_.empty()) {
510 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
511 updates_pending_swap_.pop_front();
512 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
513 // compositing pass, hence doesn't require an UpdateRect message.
514 if (msg)
515 Send(msg);
516 }
[email protected]65225772011-05-12 21:10:24517 num_swapbuffers_complete_pending_ = 0;
518 using_asynchronous_swapbuffers_ = false;
519 // Schedule another frame so the compositor learns about it.
520 scheduleComposite();
521}
522
[email protected]37a6f302011-07-11 23:43:08523void RenderWidget::OnSwapBuffersPosted() {
524 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21525
526 if (using_asynchronous_swapbuffers_) {
527 ViewHostMsg_UpdateRect* msg = NULL;
528 // pending_update_params_ can be NULL if the swap doesn't correspond to an
529 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
530 // message.
531 if (pending_update_params_.get()) {
532 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
533 pending_update_params_.reset();
534 }
535 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08536 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21537 }
[email protected]37a6f302011-07-11 23:43:08538}
539
540void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24541 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16542
[email protected]404939f2012-06-01 04:06:18543 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16544 DidFlushPaint();
545
[email protected]65225772011-05-12 21:10:24546 // When compositing deactivates, we reset the swapbuffers pending count. The
547 // swapbuffers acks may still arrive, however.
548 if (num_swapbuffers_complete_pending_ == 0) {
549 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
550 return;
551 }
[email protected]aa4117f2011-12-09 22:19:21552 DCHECK(!updates_pending_swap_.empty());
553 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
554 updates_pending_swap_.pop_front();
555 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
556 // compositing pass, hence doesn't require an UpdateRect message.
557 if (msg)
558 Send(msg);
[email protected]65225772011-05-12 21:10:24559 num_swapbuffers_complete_pending_--;
560
561 // If update reply is still pending, then defer the update until that reply
562 // occurs.
[email protected]d0be63772011-12-20 23:18:04563 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24564 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
565 return;
566 }
567
568 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06569 // when we were previously rendering. However, if an invalidation task is not
570 // posted, there may be software rendering work pending. In that case, don't
571 // early out.
572 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24573 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
574 return;
575 }
576
[email protected]cc66e682012-10-02 06:48:18577 // Do not call DoDeferredUpdate unless there's animation work to be done or
578 // a real invalidation. This prevents rendering in response to a swapbuffers
579 // callback coming back after we've navigated away from the page that
580 // generated it.
581 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
582 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
583 return;
584 }
585
[email protected]65225772011-05-12 21:10:24586 // Continue painting if necessary...
587 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29588}
589
[email protected]0dea1652012-12-14 00:09:09590void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
591 bool is_keyboard_shortcut) {
[email protected]65225772011-05-12 21:10:24592 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
initial.commit09911bf2008-07-26 23:55:29593
[email protected]5dd768212009-08-13 23:34:49594 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09595 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49596 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29597 return;
[email protected]5dd768212009-08-13 23:34:49598 }
initial.commit09911bf2008-07-26 23:55:29599
[email protected]6a4d7f62013-01-07 21:32:13600 base::TimeDelta now = base::TimeDelta::FromInternalValue(
601 base::TimeTicks::Now().ToInternalValue());
602
603 int64 delta = static_cast<int64>(
604 (now.InSecondsF() - input_event->timeStampSeconds) *
605 base::Time::kMicrosecondsPerSecond);
606 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
607 std::string name_for_event =
608 base::StringPrintf("Event.Latency.Renderer.%s",
609 GetEventName(input_event->type));
610 base::Histogram* counter_for_type =
611 base::Histogram::FactoryTimeGet(
612 name_for_event,
613 base::TimeDelta::FromMilliseconds(0),
614 base::TimeDelta::FromMilliseconds(1000000),
615 100,
616 base::Histogram::kUmaTargetedHistogramFlag);
617 counter_for_type->AddTime(base::TimeDelta::FromMicroseconds(delta));
618
[email protected]67bfb83f2011-09-22 03:36:37619 bool prevent_default = false;
620 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26621 const WebMouseEvent& mouse_event =
622 *static_cast<const WebMouseEvent*>(input_event);
623 TRACE_EVENT2("renderer", "HandleMouseMove",
624 "x", mouse_event.x, "y", mouse_event.y);
625 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37626 }
627
[email protected]41d86852012-11-07 12:23:24628 if (WebInputEvent::isGestureEventType(input_event->type)) {
629 const WebGestureEvent& gesture_event =
630 *static_cast<const WebGestureEvent*>(input_event);
631 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
632 }
633
[email protected]3ebcc7c2013-01-09 05:34:46634 if (input_event->type == WebInputEvent::GestureTap ||
635 input_event->type == WebInputEvent::GestureLongPress)
636 resetInputMethod();
637
[email protected]67bfb83f2011-09-22 03:36:37638 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12639 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
640 suppress_next_char_events_ = false;
641 if (!processed && webwidget_)
642 processed = webwidget_->handleInputEvent(*input_event);
643 }
644
645 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
646 // it's not processed by webkit, then we need to suppress the upcoming Char
647 // events.
648 if (!processed && is_keyboard_shortcut)
649 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29650
[email protected]3d5c243b2012-11-30 00:26:01651 InputEventAckState ack_result = processed ?
652 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
653 if (!processed && input_event->type == WebInputEvent::TouchStart) {
654 const WebTouchEvent& touch_event =
655 *static_cast<const WebTouchEvent*>(input_event);
656 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
657 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
658 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
659 }
660
[email protected]a9fb30aa2011-10-06 06:58:46661 IPC::Message* response =
662 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
[email protected]3d5c243b2012-11-30 00:26:01663 ack_result);
[email protected]3391a0772012-03-28 00:32:07664 bool event_type_gets_rate_limited =
665 input_event->type == WebInputEvent::MouseMove ||
666 input_event->type == WebInputEvent::MouseWheel ||
667 WebInputEvent::isTouchEventType(input_event->type);
668 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57669 throttle_input_events_ &&
[email protected]ffd156732013-01-09 18:29:11670 ((webwidget_ ? webwidget_->isInputThrottled() : false) ||
671 paint_aggregator_.HasPendingUpdate());
[email protected]e2824412009-02-27 01:57:05672
[email protected]f8868d72012-04-27 19:13:03673 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24674 // We want to rate limit the input events in this case, so we'll wait for
675 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17676 if (pending_input_event_ack_.get()) {
677 // As two different kinds of events could cause us to postpone an ack
678 // we send it now, if we have one pending. The Browser should never
679 // send us the same kind of event we are delaying the ack for.
680 Send(pending_input_event_ack_.release());
681 }
[email protected]12fbad812009-09-01 18:21:24682 pending_input_event_ack_.reset(response);
683 } else {
684 Send(response);
685 }
686
[email protected]3306f262012-09-21 19:20:42687#if defined(OS_ANDROID)
688 // Allow the IME to be shown when the focus changes as a consequence
689 // of a processed touch end event.
690 if (input_event->type == WebInputEvent::TouchEnd && processed)
691 UpdateTextInputState(SHOW_IME_IF_NEEDED);
692#endif
693
[email protected]5dd768212009-08-13 23:34:49694 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48695
[email protected]67bfb83f2011-09-22 03:36:37696 if (!prevent_default) {
697 if (WebInputEvent::isKeyboardEventType(input_event->type))
698 DidHandleKeyEvent();
699 if (WebInputEvent::isMouseEventType(input_event->type))
700 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24701 if (WebInputEvent::isTouchEventType(input_event->type))
702 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37703 }
initial.commit09911bf2008-07-26 23:55:29704}
705
706void RenderWidget::OnMouseCaptureLost() {
707 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28708 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29709}
710
711void RenderWidget::OnSetFocus(bool enable) {
712 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33713 if (webwidget_)
714 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29715}
716
717void RenderWidget::ClearFocus() {
718 // We may have got the focus from the browser before this gets processed, in
719 // which case we do not want to unfocus ourself.
720 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28721 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29722}
723
[email protected]2d5d09d52009-06-15 14:29:21724void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00725 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21726 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06727 TRACE_EVENT2("renderer", "PaintRect",
728 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45729
730 const bool kEnableGpuBenchmarking =
731 CommandLine::ForCurrentProcess()->HasSwitch(
732 switches::kEnableGpuBenchmarking);
733 base::TimeTicks rasterize_begin_ticks;
734 if (kEnableGpuBenchmarking)
735 rasterize_begin_ticks = base::TimeTicks::HighResNow();
[email protected]4fb66842009-12-04 21:41:00736 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21737
738 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00739 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
740 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03741
[email protected]699ab0d2009-04-23 23:19:14742 // If there is a custom background, tile it.
743 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14744 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11745 skia::RefPtr<SkShader> shader = skia::AdoptRef(
746 SkShader::CreateBitmapShader(background_,
747 SkShader::kRepeat_TileMode,
748 SkShader::kRepeat_TileMode));
749 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20750
751 // Use kSrc_Mode to handle background_ transparency properly.
752 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
753
754 // Canvas could contain multiple update rects. Clip to given rect so that
755 // we don't accidentally clear other update rects.
756 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48757 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14758 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20759 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14760 }
761
[email protected]719b36f2010-12-22 20:36:46762 // First see if this rect is a plugin that can paint itself faster.
763 TransportDIB* optimized_dib = NULL;
764 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20765 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46766 webkit::ppapi::PluginInstance* optimized_instance =
767 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
768 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20769 &optimized_copy_rect,
770 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46771 if (optimized_instance) {
772 // This plugin can be optimize-painted and we can just ask it to paint
773 // itself. We don't actually need the TransportDIB in this case.
774 //
775 // This is an optimization for PPAPI plugins that know they're on top of
776 // the page content. If this rect is inside such a plugin, we can save some
777 // time and avoid re-rendering the page content which we know will be
778 // covered by the plugin later (this time can be significant, especially
779 // for a playing movie that is invalidating a lot).
780 //
781 // In the plugin movie case, hopefully the similar call to
782 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
783 // painting, because that avoids copying the plugin image to a different
784 // paint rect. Unfortunately, if anything on the page is animating other
785 // than the movie, it break this optimization since the union of the
786 // invalid regions will be larger than the plugin.
787 //
788 // This code optimizes that case, where we can still avoid painting in
789 // WebKit and filling the background (which can be slow) and just painting
790 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
791 // required.
[email protected]63ab54262012-11-09 15:58:45792 base::TimeTicks paint_begin_ticks;
793 if (kEnableGpuBenchmarking)
794 paint_begin_ticks = base::TimeTicks::HighResNow();
795
[email protected]df59dd42012-09-14 22:56:30796 SkAutoCanvasRestore auto_restore(canvas, true);
797 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46798 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27799 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21800 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45801 if (kEnableGpuBenchmarking) {
802 base::TimeDelta paint_time =
803 base::TimeTicks::HighResNow() - paint_begin_ticks;
804 if (!is_accelerated_compositing_active_)
805 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
806 }
[email protected]719b36f2010-12-22 20:36:46807 } else {
808 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45809 base::TimeTicks paint_begin_ticks;
810 if (kEnableGpuBenchmarking)
811 paint_begin_ticks = base::TimeTicks::HighResNow();
812
[email protected]719b36f2010-12-22 20:36:46813 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45814
815 if (kEnableGpuBenchmarking) {
816 base::TimeDelta paint_time =
817 base::TimeTicks::HighResNow() - paint_begin_ticks;
818 if (!is_accelerated_compositing_active_)
819 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
820 }
[email protected]719b36f2010-12-22 20:36:46821
822 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35823 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46824 }
initial.commit09911bf2008-07-26 23:55:29825
[email protected]4fb66842009-12-04 21:41:00826 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00827 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45828
829 if (kEnableGpuBenchmarking) {
830 base::TimeDelta rasterize_time =
831 base::TimeTicks::HighResNow() - rasterize_begin_ticks;
832 software_stats_.totalRasterizeTimeInSeconds += rasterize_time.InSecondsF();
833
834 int64 num_pixels_processed = rect.width() * rect.height();
835 software_stats_.totalPixelsPainted += num_pixels_processed;
836 software_stats_.totalPixelsRasterized += num_pixels_processed;
837 }
[email protected]4fb66842009-12-04 21:41:00838}
839
840void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
841 skia::PlatformCanvas* canvas) {
842 static bool kPaintBorder =
843 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
844 if (!kPaintBorder)
845 return;
846
[email protected]53d3f302009-12-21 04:42:05847 // Cycle through these colors to help distinguish new paint rects.
848 const SkColor colors[] = {
849 SkColorSetARGB(0x3F, 0xFF, 0, 0),
850 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
851 SkColorSetARGB(0x3F, 0, 0, 0xFF),
852 };
853 static int color_selector = 0;
854
[email protected]4fb66842009-12-04 21:41:00855 SkPaint paint;
856 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05857 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00858 paint.setStrokeWidth(1);
859
860 SkIRect irect;
861 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
862 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29863}
864
[email protected]52ccd0ea2011-02-16 01:09:05865void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30866 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30867 if (!animation_update_pending_) {
868 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59869 return;
[email protected]921244e42011-07-20 16:36:30870 }
[email protected]bd37ae252011-06-03 01:28:18871 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59872 // Record when we fired (according to base::Time::Now()) relative to when
873 // we posted the task to quantify how much the base::Time/base::TimeTicks
874 // skew is affecting animations.
875 base::TimeDelta animation_callback_delay = base::Time::Now() -
876 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
877 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
878 animation_callback_delay,
879 base::TimeDelta::FromMilliseconds(0),
880 base::TimeDelta::FromMilliseconds(30),
881 25);
882 }
[email protected]65225772011-05-12 21:10:24883 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24884}
885
[email protected]52ccd0ea2011-02-16 01:09:05886void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59887 if (!animation_update_pending_)
888 return;
[email protected]bd37ae252011-06-03 01:28:18889
890 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33891 base::TimeDelta animationInterval = IsRenderingVSynced() ?
892 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18893
[email protected]7c4329e2011-02-18 22:02:59894 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45895
896 // animation_floor_time_ is the earliest time that we should animate when
897 // using the dead reckoning software scheduler. If we're using swapbuffers
898 // complete callbacks to rate limit, we can ignore this floor.
899 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30900 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33901 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18902 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59903 // running animation callbacks so that if a callback requests another
904 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38905 animation_timer_.Stop();
906 animation_timer_.Start(FROM_HERE, animationInterval, this,
907 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59908 animation_update_pending_ = false;
[email protected]ffd156732013-01-09 18:29:11909 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59910 return;
[email protected]5f8b1022011-01-21 23:34:50911 }
[email protected]bd37ae252011-06-03 01:28:18912 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38913 if (!animation_timer_.IsRunning()) {
914 // This code uses base::Time::Now() to calculate the floor and next fire
915 // time because javascript's Date object uses base::Time::Now(). The
916 // message loop uses base::TimeTicks, which on windows can have a
917 // different granularity than base::Time.
918 // The upshot of all this is that this function might be called before
919 // base::Time::Now() has advanced past the animation_floor_time_. To
920 // avoid exposing this delay to javascript, we keep posting delayed
921 // tasks until base::Time::Now() has advanced far enough.
922 base::TimeDelta delay = animation_floor_time_ - now;
923 animation_timer_.Start(FROM_HERE, delay, this,
924 &RenderWidget::AnimationCallback);
925 }
[email protected]5f8b1022011-01-21 23:34:50926}
927
[email protected]bd37ae252011-06-03 01:28:18928bool RenderWidget::IsRenderingVSynced() {
929 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
930 // not caught by this check. This will lead to artificially low frame rates
931 // for people who force vsync off at a driver level and expect Chrome to speed
932 // up.
933 return !has_disable_gpu_vsync_switch_;
934}
935
[email protected]65225772011-05-12 21:10:24936void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06937 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24938 invalidation_task_posted_ = false;
939 DoDeferredUpdateAndSendInputAck();
940}
941
942void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05943 DoDeferredUpdate();
944
945 if (pending_input_event_ack_.get())
946 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21947}
948
[email protected]552e6002009-11-19 05:24:57949void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58950 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08951
[email protected]65225772011-05-12 21:10:24952 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29953 return;
[email protected]05a980d7a2012-02-07 22:16:42954
[email protected]fc4404d2012-11-07 19:53:30955 if (!init_complete_) {
956 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:42957 return;
958 }
[email protected]aa4117f2011-12-09 22:19:21959 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24960 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
961 return;
962 }
[email protected]9ca84622011-06-02 23:46:39963 if (is_accelerated_compositing_active_ &&
964 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24965 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
966 return;
967 }
initial.commit09911bf2008-07-26 23:55:29968
[email protected]552e6002009-11-19 05:24:57969 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:05970 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:57971 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29972 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24973 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29974 return;
975 }
976
[email protected]05a980d7a2012-02-07 22:16:42977 if (is_accelerated_compositing_active_)
978 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
979
[email protected]0fb93f52011-05-18 23:13:56980 // Tracking of frame rate jitter
981 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51982 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05983 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50984
[email protected]f98d7e3c2010-09-13 22:30:46985 // Layout may generate more invalidation. It may also enable the
986 // GPU acceleration, so make sure to run layout before we send the
987 // GpuRenderingActivated message.
988 webwidget_->layout();
989
[email protected]dcca3aa92012-02-17 23:03:37990 // The following two can result in further layout and possibly
991 // enable GPU acceleration so they need to be called before any painting
992 // is done.
[email protected]3306f262012-09-21 19:20:42993 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:37994 UpdateSelectionBounds();
995
[email protected]5f8b1022011-01-21 23:34:50996 // Suppress painting if nothing is dirty. This has to be done after updating
997 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:24998 if (!paint_aggregator_.HasPendingUpdate()) {
999 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:511000 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501001 return;
[email protected]65225772011-05-12 21:10:241002 }
[email protected]5f8b1022011-01-21 23:34:501003
[email protected]479b0172012-10-29 19:27:091004 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361005 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091006 ForceCompositingModeEnabled()) {
1007 webwidget_->enterForceCompositingMode(true);
1008 }
1009
[email protected]872ae5b2011-05-26 20:20:501010 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561011 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041012 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561013 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1014 delay,
1015 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411016 base::TimeDelta::FromMilliseconds(120),
1017 60);
[email protected]d0be63772011-12-20 23:18:041018 } else {
[email protected]0fb93f52011-05-18 23:13:561019 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1020 delay,
1021 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411022 base::TimeDelta::FromMilliseconds(120),
1023 60);
[email protected]d0be63772011-12-20 23:18:041024 }
[email protected]872ae5b2011-05-26 20:20:501025
1026 // Calculate filtered time per frame:
1027 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1028 filtered_time_per_frame_ =
1029 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561030 }
1031 last_do_deferred_update_time_ = frame_begin_ticks;
1032
[email protected]fef5e3972012-08-07 03:59:471033 if (!is_accelerated_compositing_active_) {
1034 software_stats_.numAnimationFrames++;
1035 software_stats_.numFramesSentToScreen++;
1036 }
1037
[email protected]552e6002009-11-19 05:24:571038 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291039 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301040 PaintAggregator::PendingUpdate update;
1041 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291042
[email protected]53d3f302009-12-21 04:42:051043 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181044 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291045
[email protected]29ed96a2012-02-04 18:12:161046 // Notify derived classes that we're about to initiate a paint.
1047 WillInitiatePaint();
1048
[email protected]ca4847f2010-09-24 05:39:151049 // A plugin may be able to do an optimized paint. First check this, in which
1050 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461051 // This optimization allows PPAPI plugins that declare themselves on top of
1052 // the page (like a traditional windowed plugin) to be able to animate (think
1053 // movie playing) without repeatedly re-painting the page underneath, or
1054 // copying the plugin backing store (since we can send the plugin's backing
1055 // store directly to the browser).
1056 //
1057 // This optimization only works when the entire invalid region is contained
1058 // within the plugin. There is a related optimization in PaintRect for the
1059 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151060 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151061 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201062 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211063 DCHECK(!pending_update_params_.get());
1064 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551065 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211066 pending_update_params_->scroll_rect = update.scroll_rect;
1067 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211068 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1069 pending_update_params_->flags = next_paint_flags_;
1070 pending_update_params_->scroll_offset = GetScrollOffset();
1071 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091072 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211073 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091074 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211075
[email protected]ca4847f2010-09-24 05:39:151076 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561077 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151078 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201079 &optimized_copy_rect,
1080 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271081 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471082 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211083 pending_update_params_->bitmap = dib->id();
1084 pending_update_params_->bitmap_rect = optimized_copy_location;
1085 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201086 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561087 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461088 // Compute a buffer for painting and cache it.
[email protected]ce112fe2012-10-29 22:52:181089 gfx::Rect pixel_bounds = gfx::ToFlooredRectDeprecated(
1090 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]ca4847f2010-09-24 05:39:151091 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351092 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591093 pixel_bounds));
[email protected]f98d7e3c2010-09-13 22:30:461094 if (!canvas.get()) {
1095 NOTREACHED();
1096 return;
1097 }
[email protected]cef3362f2009-12-21 17:48:451098
[email protected]f98d7e3c2010-09-13 22:30:461099 // We may get back a smaller canvas than we asked for.
1100 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591101 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1102 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1103 pixel_bounds.set_width(canvas->getDevice()->width());
1104 pixel_bounds.set_height(canvas->getDevice()->height());
1105 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1106 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051107
[email protected]f98d7e3c2010-09-13 22:30:461108 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1109
[email protected]aa4117f2011-12-09 22:19:211110 pending_update_params_->bitmap = current_paint_buf_->id();
1111 pending_update_params_->bitmap_rect = bounds;
1112
1113 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461114 // The scroll damage is just another rectangle to paint and copy.
1115 copy_rects.swap(update.paint_rects);
1116 if (!scroll_damage.IsEmpty())
1117 copy_rects.push_back(scroll_damage);
1118
1119 for (size_t i = 0; i < copy_rects.size(); ++i)
[email protected]f1cccb32012-06-06 18:29:591120 PaintRect(copy_rects[i], pixel_bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:351121
1122 // Software FPS tick for performance tests. The accelerated path traces the
1123 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1124 // NOTE: Tests may break if this event is renamed or moved.
1125 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:461126 } else { // Accelerated compositing path
1127 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211128 // If painting is done via the gpu process then we don't set any damage
1129 // rects to save the browser process from doing unecessary work.
1130 pending_update_params_->bitmap_rect = bounds;
1131 pending_update_params_->scroll_rect = gfx::Rect();
1132 // We don't need an ack, because we're not sharing a DIB with the browser.
1133 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1134 // with the browser for the GPU surface.
1135 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:421136 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:461137 }
1138
[email protected]936c6f52011-12-13 01:35:261139 // If we're holding a pending input event ACK, send the ACK before sending the
1140 // UpdateReply message so we can receive another input event before the
1141 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1142 // the UpdateRect IPC message handler.
1143 if (pending_input_event_ack_.get())
1144 Send(pending_input_event_ack_.release());
1145
[email protected]aa4117f2011-12-09 22:19:211146 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
1147 // OnSwapBuffersPosted), meaning a message has been added to the
1148 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1149 // the message now.
1150 if (pending_update_params_.get()) {
1151 // sending an ack to browser process that the paint is complete...
1152 update_reply_pending_ = pending_update_params_->needs_ack;
1153 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1154 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341155 }
[email protected]53d3f302009-12-21 04:42:051156
[email protected]29ed96a2012-02-04 18:12:161157 // If we're software rendering then we're done initiating the paint.
1158 if (!is_accelerated_compositing_active_)
1159 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291160}
1161
1162///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461163// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291164
[email protected]4873c7d2009-07-16 06:36:281165void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091166 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1167 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571168 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481169 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181170 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571171 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291172 return;
1173
[email protected]552e6002009-11-19 05:24:571174 paint_aggregator_.InvalidateRect(damaged_rect);
1175
1176 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241177 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571178 return;
1179 if (!paint_aggregator_.HasPendingUpdate())
1180 return;
[email protected]aa4117f2011-12-09 22:19:211181 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241182 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1183 return;
1184
1185 // When GPU rendering, combine pending animations and invalidations into
1186 // a single update.
[email protected]816edc62012-03-17 01:27:221187 if (is_accelerated_compositing_active_ &&
1188 animation_update_pending_ &&
1189 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571190 return;
1191
1192 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291193 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1194 // on the call stack.
1195 // 2) Allows us to collect more damage rects before painting to help coalesce
1196 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241197 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211198 MessageLoop::current()->PostTask(
1199 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291200}
1201
[email protected]990278ff2012-11-13 02:12:551202void RenderWidget::didScrollRect(int dx, int dy,
1203 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461204 // Drop scrolls on the floor when we are in compositing mode.
1205 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561206 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461207 return;
1208
[email protected]552e6002009-11-19 05:24:571209 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481210 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181211 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571212 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291213 return;
1214
[email protected]990278ff2012-11-13 02:12:551215 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571216
1217 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241218 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571219 return;
1220 if (!paint_aggregator_.HasPendingUpdate())
1221 return;
[email protected]aa4117f2011-12-09 22:19:211222 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241223 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1224 return;
1225
1226 // When GPU rendering, combine pending animations and invalidations into
1227 // a single update.
[email protected]816edc62012-03-17 01:27:221228 if (is_accelerated_compositing_active_ &&
1229 animation_update_pending_ &&
1230 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571231 return;
1232
1233 // Perform updating asynchronously. This serves two purposes:
1234 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1235 // on the call stack.
1236 // 2) Allows us to collect more damage rects before painting to help coalesce
1237 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241238 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211239 MessageLoop::current()->PostTask(
1240 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291241}
1242
[email protected]244ac1892011-12-02 17:04:471243void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091244 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1245 size_ = new_size;
1246 need_update_rect_for_auto_resize_ = true;
[email protected]240b5c32012-11-09 19:17:181247 // If we don't clear PaintAggregator after changing autoResize state, then
1248 // we might end up in a situation where bitmap_rect is larger than the
1249 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1250 // with invalid damage rects.
1251 paint_aggregator_.ClearPendingUpdate();
[email protected]ea3ee0a2012-05-15 03:43:091252 }
[email protected]244ac1892011-12-02 17:04:471253}
1254
[email protected]91acd1c2012-03-14 08:32:391255void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221256 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1257
[email protected]c63b4d42012-04-26 01:01:071258#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211259 if (!is_accelerated_compositing_active_) {
1260 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1261 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1262 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1263 // going to switch to accelerated compositing, the GPU process may need
1264 // round-trips to the browser's UI thread before finishing the frame,
1265 // causing deadlocks if we delay the UpdateRect until we receive the
1266 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071267 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1268 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211269 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1270 }
[email protected]c63b4d42012-04-26 01:01:071271#endif
[email protected]aa4117f2011-12-09 22:19:211272
[email protected]ea162f92011-10-04 23:08:221273 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421274 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241275 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221276}
1277
1278void RenderWidget::didDeactivateCompositor() {
1279 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1280
1281 is_accelerated_compositing_active_ = false;
1282 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1283 routing_id_, is_accelerated_compositing_active_));
1284
[email protected]ea162f92011-10-04 23:08:221285 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241286 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091287
1288 // In single-threaded mode, we exit force compositing mode and re-enter in
1289 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1290 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1291 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361292 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091293 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561294}
1295
[email protected]9cd43a62012-03-26 08:03:561296void RenderWidget::willBeginCompositorFrame() {
1297 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371298
1299 DCHECK(RenderThreadImpl::current()->compositor_thread());
1300
1301 // The following two can result in further layout and possibly
1302 // enable GPU acceleration so they need to be called before any painting
1303 // is done.
[email protected]abe8b3a2012-03-28 21:19:371304 UpdateSelectionBounds();
1305
[email protected]9cd43a62012-03-26 08:03:561306 WillInitiatePaint();
1307}
1308
[email protected]3391a0772012-03-28 00:32:071309void RenderWidget::didBecomeReadyForAdditionalInput() {
1310 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1311 if (pending_input_event_ack_.get())
1312 Send(pending_input_event_ack_.release());
1313}
1314
[email protected]58264a32011-11-17 23:36:151315void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501316 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351317 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1318 // NOTE: Tests may break if this event is renamed or moved.
1319 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161320 // Notify subclasses that we initiated the paint operation.
1321 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151322}
1323
1324void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181325 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1326
1327 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561328 DidFlushPaint();
1329
[email protected]aa4117f2011-12-09 22:19:211330 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151331 return;
1332
[email protected]ea3ee0a2012-05-15 03:43:091333 if (!next_paint_flags_ &&
1334 !need_update_rect_for_auto_resize_ &&
1335 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151336 return;
[email protected]ea3ee0a2012-05-15 03:43:091337 }
[email protected]58264a32011-11-17 23:36:151338
1339 ViewHostMsg_UpdateRect_Params params;
1340 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151341 params.plugin_window_moves.swap(plugin_window_moves_);
1342 params.flags = next_paint_flags_;
1343 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121344 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091345 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151346
1347 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1348 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091349 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151350}
1351
[email protected]f98d7e3c2010-09-13 22:30:461352void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091353 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]d0be63772011-12-20 23:18:041354 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401355 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041356 } else {
[email protected]c3d45532011-10-07 19:20:401357 // TODO(nduca): replace with something a little less hacky. The reason this
1358 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1359 // contains a lot of host-renderer synchronization logic that is still
1360 // important for the accelerated compositing case. The option of simply
1361 // duplicating all that code is less desirable than "faking out" the
1362 // invalidation path using a magical damage rect.
1363 didInvalidateRect(WebRect(0, 0, 1, 1));
1364 }
[email protected]f98d7e3c2010-09-13 22:30:461365}
1366
[email protected]5f8b1022011-01-21 23:34:501367void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201368 if (animation_update_pending_)
1369 return;
1370
[email protected]921244e42011-07-20 16:36:301371 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201372 animation_update_pending_ = true;
1373 if (!animation_timer_.IsRunning()) {
1374 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1375 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211376 }
[email protected]5f8b1022011-01-21 23:34:501377}
1378
[email protected]4873c7d2009-07-16 06:36:281379void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301380 // TODO(darin): Eliminate this temporary.
1381 WebCursor cursor(cursor_info);
1382
initial.commit09911bf2008-07-26 23:55:291383 // Only send a SetCursor message if we need to make a change.
1384 if (!current_cursor_.IsEqual(cursor)) {
1385 current_cursor_ = cursor;
1386 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1387 }
1388}
1389
1390// We are supposed to get a single call to Show for a newly created RenderWidget
1391// that was created via RenderWidget::CreateWebView. So, we wait until this
1392// point to dispatch the ShowWidget message.
1393//
1394// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281395// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291396//
[email protected]4873c7d2009-07-16 06:36:281397void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291398 DCHECK(!did_show_) << "received extraneous Show call";
1399 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1400 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1401
[email protected]8de12d942010-11-17 20:42:441402 if (did_show_)
1403 return;
1404
1405 did_show_ = true;
1406 // NOTE: initial_pos_ may still have its default values at this point, but
1407 // that's okay. It'll be ignored if as_popup is false, or the browser
1408 // process will impose a default position otherwise.
1409 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1410 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291411}
1412
[email protected]4873c7d2009-07-16 06:36:281413void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291414}
1415
[email protected]4873c7d2009-07-16 06:36:281416void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291417}
1418
[email protected]2533ce12009-05-09 00:02:241419void RenderWidget::DoDeferredClose() {
1420 Send(new ViewHostMsg_Close(routing_id_));
1421}
1422
[email protected]4873c7d2009-07-16 06:36:281423void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321424 if (is_swapped_out_) {
1425 // This widget is currently swapped out, and the active widget is in a
1426 // different process. Have the browser route the close request to the
1427 // active widget instead, so that the correct unload handlers are run.
1428 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1429 return;
1430 }
1431
initial.commit09911bf2008-07-26 23:55:291432 // If a page calls window.close() twice, we'll end up here twice, but that's
1433 // OK. It is safe to send multiple Close messages.
1434
[email protected]2533ce12009-05-09 00:02:241435 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1436 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1437 // could be closed before the JS finishes executing. So instead, post a
1438 // message back to the message loop, which won't run until the JS is
1439 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211440 MessageLoop::current()->PostTask(
1441 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291442}
1443
1444void RenderWidget::Close() {
1445 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281446 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291447 webwidget_ = NULL;
1448 }
1449}
1450
[email protected]4873c7d2009-07-16 06:36:281451WebRect RenderWidget::windowRect() {
1452 if (pending_window_rect_count_)
1453 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241454
[email protected]80ad8622012-11-07 16:33:031455 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291456}
1457
[email protected]8a9d6ca32011-06-06 20:11:301458void RenderWidget::setToolTipText(const WebKit::WebString& text,
1459 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541460 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301461}
1462
[email protected]4873c7d2009-07-16 06:36:281463void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291464 if (did_show_) {
1465 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241466 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291467 } else {
1468 initial_pos_ = pos;
1469 }
1470}
1471
[email protected]2533ce12009-05-09 00:02:241472void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1473 pending_window_rect_ = rect;
1474 pending_window_rect_count_++;
1475}
1476
[email protected]4873c7d2009-07-16 06:36:281477WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241478 if (pending_window_rect_count_) {
1479 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1480 // the RootWindowRect is probably going to return wrong results since the
1481 // browser may not have processed the Move yet. There isn't really anything
1482 // good to do in this case, and it shouldn't happen - since this size is
1483 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281484 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241485 }
1486
[email protected]80ad8622012-11-07 16:33:031487 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371488}
1489
[email protected]4873c7d2009-07-16 06:36:281490WebRect RenderWidget::windowResizerRect() {
1491 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191492}
1493
[email protected]fa7b1dc2010-06-23 17:53:041494void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031495 // To prevent this renderer process from sending unnecessary IPC messages to
1496 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041497 // only during the input method attached to the browser process is active.
1498 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291499}
1500
[email protected]58b48a0d2012-06-13 07:01:351501void RenderWidget::UpdateCompositionInfo(
1502 const ui::Range& range,
1503 const std::vector<gfx::Rect>& character_bounds) {
1504 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1505 return;
1506 composition_character_bounds_ = character_bounds;
1507 composition_range_ = range;
1508 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1509 routing_id(), composition_range_, composition_character_bounds_));
1510}
1511
[email protected]fa7b1dc2010-06-23 17:53:041512void RenderWidget::OnImeSetComposition(
1513 const string16& text,
1514 const std::vector<WebCompositionUnderline>& underlines,
1515 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281516 if (!webwidget_)
1517 return;
[email protected]d4cff272011-05-02 15:46:011518 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041519 text, WebVector<WebCompositionUnderline>(underlines),
1520 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011521 // Setting the IME composition was successful. Send the new composition
1522 // range to the browser.
1523 ui::Range range(ui::Range::InvalidRange());
1524 size_t location, length;
1525 if (webwidget_->compositionRange(&location, &length)) {
1526 range.set_start(location);
1527 range.set_end(location + length);
1528 }
1529 // The IME was cancelled via the Esc key, so just send back the caret.
1530 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1531 range.set_start(location);
1532 range.set_end(location + length);
1533 }
[email protected]58b48a0d2012-06-13 07:01:351534 std::vector<gfx::Rect> character_bounds;
1535 GetCompositionCharacterBounds(&character_bounds);
1536 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011537 } else {
[email protected]fa7b1dc2010-06-23 17:53:041538 // If we failed to set the composition text, then we need to let the browser
1539 // process to cancel the input method's ongoing composition session, to make
1540 // sure we are in a consistent state.
1541 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011542
1543 // Send an updated IME range with just the caret range.
1544 ui::Range range(ui::Range::InvalidRange());
1545 size_t location, length;
1546 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1547 range.set_start(location);
1548 range.set_end(location + length);
1549 }
[email protected]58b48a0d2012-06-13 07:01:351550 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261551 }
[email protected]fa7b1dc2010-06-23 17:53:041552}
1553
[email protected]4de6d1692011-10-12 08:45:441554void RenderWidget::OnImeConfirmComposition(
1555 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041556 if (!webwidget_)
1557 return;
1558
1559 handling_input_event_ = true;
1560 webwidget_->confirmComposition(text);
1561 handling_input_event_ = false;
1562
[email protected]d4cff272011-05-02 15:46:011563 // Send an updated IME range with just the caret range.
1564 ui::Range range(ui::Range::InvalidRange());
1565 size_t location, length;
1566 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1567 range.set_start(location);
1568 range.set_end(location + length);
1569 }
[email protected]58b48a0d2012-06-13 07:01:351570 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291571}
1572
[email protected]948f7ab72010-05-28 23:48:081573// This message causes the renderer to render an image of the
1574// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251575void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1576 int tag,
1577 const gfx::Size& page_size,
1578 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001579 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1580 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251581 // Close our unused handle.
1582#if defined(OS_WIN)
1583 ::CloseHandle(dib_handle);
1584#elif defined(OS_MACOSX)
1585 base::SharedMemory::CloseHandle(dib_handle);
1586#endif
1587 }
[email protected]d65adb12010-04-28 17:26:491588 return;
[email protected]45c6aad32010-11-11 04:46:251589 }
[email protected]d65adb12010-04-28 17:26:491590
[email protected]948f7ab72010-05-28 23:48:081591 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491592 // If one of these is empty, then we just return the dib we were
1593 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091594 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491595 return;
1596 }
1597
1598 // Map the given DIB ID into this process, and unmap it at the end
1599 // of this function.
[email protected]45c6aad32010-11-11 04:46:251600 scoped_ptr<TransportDIB> paint_at_size_buffer(
1601 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301602
[email protected]4b01b962012-10-09 23:17:351603 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281604 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351605 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281606 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511607 gfx::Size canvas_size = page_size_in_pixel;
1608 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491609 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511610 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491611 static_cast<float>(canvas_size.height());
1612
[email protected]ee8d6fd2010-05-26 17:05:481613 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491614 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1615 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481616 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491617
[email protected]36808ad2010-10-20 19:18:301618 scoped_ptr<skia::PlatformCanvas> canvas(
1619 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1620 canvas_size.height()));
1621 if (!canvas.get()) {
1622 NOTREACHED();
1623 return;
1624 }
1625
[email protected]d65adb12010-04-28 17:26:491626 // Reset bounds to what we actually received, but they should be the
1627 // same.
1628 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1629 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1630 bounds.set_width(canvas->getDevice()->width());
1631 bounds.set_height(canvas->getDevice()->height());
1632
1633 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081634 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491635 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1636
[email protected]948f7ab72010-05-28 23:48:081637 // Have to make sure we're laid out at the right size before
1638 // rendering.
1639 gfx::Size old_size = webwidget_->size();
1640 webwidget_->resize(page_size);
1641 webwidget_->layout();
1642
[email protected]d65adb12010-04-28 17:26:491643 // Paint the entire thing (using original bounds, not scaled bounds).
1644 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1645 canvas->restore();
1646
[email protected]948f7ab72010-05-28 23:48:081647 // Return the widget to its previous size.
1648 webwidget_->resize(old_size);
1649
[email protected]c88c9442010-07-19 18:55:091650 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491651}
1652
[email protected]3d9ec5052013-01-02 22:05:251653void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121654 // During shutdown we can just ignore this message.
1655 if (!webwidget_)
1656 return;
1657
1658 set_next_paint_is_repaint_ack();
[email protected]b89c90762013-01-06 20:29:301659 if (is_accelerated_compositing_active_) {
[email protected]ffd156732013-01-09 18:29:111660 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461661 scheduleComposite();
1662 } else {
1663 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1664 didInvalidateRect(repaint_rect);
1665 }
[email protected]ec7dc112008-08-06 05:30:121666}
1667
[email protected]3d9ec5052013-01-02 22:05:251668void RenderWidget::OnSmoothScrollCompleted(int gesture_id) {
[email protected]0e241b4b2012-08-18 09:06:271669 PendingSmoothScrollGestureMap::iterator it =
1670 pending_smooth_scroll_gestures_.find(gesture_id);
1671 DCHECK(it != pending_smooth_scroll_gestures_.end());
1672 it->second.Run();
1673 pending_smooth_scroll_gestures_.erase(it);
1674}
1675
[email protected]4873c7d2009-07-16 06:36:281676void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111677 if (!webwidget_)
1678 return;
[email protected]4873c7d2009-07-16 06:36:281679 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111680}
1681
[email protected]6131a642012-06-15 23:26:531682void RenderWidget::OnScreenInfoChanged(
1683 const WebKit::WebScreenInfo& screen_info) {
1684 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191685 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531686}
1687
[email protected]80ad8622012-11-07 16:33:031688void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1689 const gfx::Rect& window_screen_rect) {
1690 view_screen_rect_ = view_screen_rect;
1691 window_screen_rect_ = window_screen_rect;
1692 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1693}
1694
[email protected]468ac582012-11-20 00:53:191695void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1696 if (device_scale_factor_ == device_scale_factor)
1697 return;
1698
1699 device_scale_factor_ = device_scale_factor;
1700
1701 if (!is_accelerated_compositing_active_) {
1702 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1703 } else {
1704 scheduleComposite();
1705 }
1706}
1707
[email protected]719b36f2010-12-22 20:36:461708webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151709 const gfx::Rect& paint_bounds,
1710 TransportDIB** dib,
1711 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201712 gfx::Rect* clip,
1713 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461714 // Bare RenderWidgets don't support optimized plugin painting.
1715 return NULL;
[email protected]ca4847f2010-09-24 05:39:151716}
1717
[email protected]ceb36f7d2012-10-31 18:33:241718gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521719 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241720 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521721}
1722
[email protected]bee16aab2009-08-26 15:55:031723void RenderWidget::SetHidden(bool hidden) {
1724 if (is_hidden_ == hidden)
1725 return;
1726
1727 // The status has changed. Tell the RenderThread about it.
1728 is_hidden_ = hidden;
1729 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271730 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031731 else
[email protected]380244092011-10-07 17:26:271732 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031733}
1734
[email protected]2b624c562011-10-27 22:58:261735void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261736 if (!webwidget_)
1737 return;
1738
1739 if (is_fullscreen_) {
1740 webwidget_->willExitFullScreen();
1741 } else {
1742 webwidget_->willEnterFullScreen();
1743 }
[email protected]2b624c562011-10-27 22:58:261744}
1745
1746void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261747 if (!webwidget_)
1748 return;
1749
1750 if (is_fullscreen_) {
1751 webwidget_->didEnterFullScreen();
1752 } else {
1753 webwidget_->didExitFullScreen();
1754 }
[email protected]2b624c562011-10-27 22:58:261755}
1756
[email protected]699ab0d2009-04-23 23:19:141757void RenderWidget::SetBackground(const SkBitmap& background) {
1758 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461759
[email protected]699ab0d2009-04-23 23:19:141760 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281761 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141762}
1763
[email protected]674741932009-02-04 23:44:461764bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051765 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461766}
1767
1768bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051769 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461770}
1771
1772void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051773 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461774}
1775
1776void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051777 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461778}
1779
1780void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051781 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461782}
1783
[email protected]b18583c2012-12-18 06:55:271784static bool IsDateTimeInput(ui::TextInputType type) {
1785 return type == ui::TEXT_INPUT_TYPE_DATE ||
1786 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1787 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1788 type == ui::TEXT_INPUT_TYPE_MONTH ||
1789 type == ui::TEXT_INPUT_TYPE_TIME ||
1790 type == ui::TEXT_INPUT_TYPE_WEEK;
1791}
1792
1793
[email protected]3306f262012-09-21 19:20:421794void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
1795 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1796 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291797 return;
[email protected]ad26ef42011-06-17 07:59:451798 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271799 if (IsDateTimeInput(new_type))
1800 return; // Not considered as a text input field in WebKit/Chromium.
1801
[email protected]5b739cb2012-08-21 20:35:211802 WebKit::WebTextInputInfo new_info;
1803 if (webwidget_)
1804 new_info = webwidget_->textInputInfo();
1805
[email protected]ad26ef42011-06-17 07:59:451806 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211807
[email protected]3306f262012-09-21 19:20:421808 // Only sends text input params if they are changed or if the ime should be
1809 // shown.
1810 if (show_ime_if_needed || (text_input_type_ != new_type
1811 || text_input_info_ != new_info
1812 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:211813 ViewHostMsg_TextInputState_Params p;
1814 p.type = new_type;
1815 p.value = new_info.value.utf8();
1816 p.selection_start = new_info.selectionStart;
1817 p.selection_end = new_info.selectionEnd;
1818 p.composition_start = new_info.compositionStart;
1819 p.composition_end = new_info.compositionEnd;
1820 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:421821 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:211822 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1823
1824 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041825 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451826 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:291827 }
initial.commit09911bf2008-07-26 23:55:291828}
1829
[email protected]3f783362011-10-21 22:40:501830void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1831 WebRect start_webrect;
1832 WebRect end_webrect;
1833 webwidget_->selectionBounds(start_webrect, end_webrect);
1834 *start = start_webrect;
1835 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321836}
1837
[email protected]e99ef6f2011-10-16 01:13:001838void RenderWidget::UpdateSelectionBounds() {
1839 if (!webwidget_)
1840 return;
1841
[email protected]3f783362011-10-21 22:40:501842 gfx::Rect start_rect;
1843 gfx::Rect end_rect;
1844 GetSelectionBounds(&start_rect, &end_rect);
[email protected]58b48a0d2012-06-13 07:01:351845 if (selection_start_rect_ != start_rect || selection_end_rect_ != end_rect) {
1846 selection_start_rect_ = start_rect;
1847 selection_end_rect_ = end_rect;
[email protected]b556c2e2012-08-10 22:18:271848 WebTextDirection start_dir = WebKit::WebTextDirectionLeftToRight;
1849 WebTextDirection end_dir = WebKit::WebTextDirectionLeftToRight;
1850 webwidget_->selectionTextDirection(start_dir, end_dir);
1851 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_,
1852 selection_start_rect_, start_dir, selection_end_rect_, end_dir));
[email protected]58b48a0d2012-06-13 07:01:351853 }
[email protected]e99ef6f2011-10-16 01:13:001854
[email protected]58b48a0d2012-06-13 07:01:351855 std::vector<gfx::Rect> character_bounds;
1856 GetCompositionCharacterBounds(&character_bounds);
1857 UpdateCompositionInfo(composition_range_, character_bounds);
1858}
1859
1860bool RenderWidget::ShouldUpdateCompositionInfo(
1861 const ui::Range& range,
1862 const std::vector<gfx::Rect>& bounds) {
1863 if (composition_range_ != range)
1864 return true;
1865 if (bounds.size() != composition_character_bounds_.size())
1866 return true;
1867 for (size_t i = 0; i < bounds.size(); ++i) {
1868 if (bounds[i] != composition_character_bounds_[i])
1869 return true;
1870 }
1871 return false;
[email protected]e99ef6f2011-10-16 01:13:001872}
1873
[email protected]73bf95812011-10-12 11:38:321874// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451875COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1876 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1877COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1878 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1879COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1880 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181881COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1882 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1883COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1884 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1885COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1886 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1887COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1888 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1889COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1890 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:001891COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
1892 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
1893COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
1894 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
1895COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
1896 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
1897COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
1898 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
1899COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
1900 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
1901COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
1902 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:011903COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
1904 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
1905COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
1906 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451907
[email protected]5b739cb2012-08-21 20:35:211908ui::TextInputType RenderWidget::WebKitToUiTextInputType(
1909 WebKit::WebTextInputType type) {
1910 // Check the type is in the range representable by ui::TextInputType.
1911 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
1912 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1913 return static_cast<ui::TextInputType>(type);
1914}
1915
[email protected]ad26ef42011-06-17 07:59:451916ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:271917 if (webwidget_)
1918 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:451919 return ui::TEXT_INPUT_TYPE_NONE;
1920}
1921
[email protected]58b48a0d2012-06-13 07:01:351922void RenderWidget::GetCompositionCharacterBounds(
1923 std::vector<gfx::Rect>* bounds) {
1924 DCHECK(bounds);
1925 bounds->clear();
1926}
1927
[email protected]ad26ef42011-06-17 07:59:451928bool RenderWidget::CanComposeInline() {
1929 return true;
[email protected]56ea1a62011-05-30 07:05:571930}
1931
[email protected]4873c7d2009-07-16 06:36:281932WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041933 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281934}
1935
[email protected]f660d9c2012-06-06 18:31:211936float RenderWidget::deviceScaleFactor() {
1937 return device_scale_factor_;
1938}
1939
[email protected]fa7b1dc2010-06-23 17:53:041940void RenderWidget::resetInputMethod() {
1941 if (!input_method_is_active_)
1942 return;
1943
1944 // If the last text input type is not None, then we should finish any
1945 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451946 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041947 // If a composition text exists, then we need to let the browser process
1948 // to cancel the input method's ongoing composition session.
1949 if (webwidget_->confirmComposition())
1950 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1951 }
[email protected]d4cff272011-05-02 15:46:011952
1953 // Send an updated IME range with the current caret rect.
1954 ui::Range range(ui::Range::InvalidRange());
1955 size_t location, length;
1956 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1957 range.set_start(location);
1958 range.set_end(location + length);
1959 }
[email protected]58b48a0d2012-06-13 07:01:351960
1961 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:041962}
1963
[email protected]f103ab72009-09-02 17:10:591964void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501965 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291966 size_t i = 0;
1967 for (; i < plugin_window_moves_.size(); ++i) {
1968 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581969 if (move.rects_valid) {
1970 plugin_window_moves_[i] = move;
1971 } else {
1972 plugin_window_moves_[i].visible = move.visible;
1973 }
initial.commit09911bf2008-07-26 23:55:291974 break;
1975 }
1976 }
1977
1978 if (i == plugin_window_moves_.size())
1979 plugin_window_moves_.push_back(move);
1980}
[email protected]268654772009-08-06 23:02:041981
1982void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1983 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1984 i != plugin_window_moves_.end(); ++i) {
1985 if (i->window == window) {
1986 plugin_window_moves_.erase(i);
1987 break;
1988 }
1989 }
1990}
[email protected]67bfb83f2011-09-22 03:36:371991
[email protected]b63d58d2012-11-26 22:37:441992void RenderWidget::GetRenderingStats(
1993 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ffd156732013-01-09 18:29:111994 webwidget()->renderingStats(stats);
[email protected]b63d58d2012-11-26 22:37:441995
1996 stats.rendering_stats.numAnimationFrames +=
1997 software_stats_.numAnimationFrames;
1998 stats.rendering_stats.numFramesSentToScreen +=
1999 software_stats_.numFramesSentToScreen;
2000 stats.rendering_stats.totalPaintTimeInSeconds +=
2001 software_stats_.totalPaintTimeInSeconds;
2002 stats.rendering_stats.totalPixelsPainted +=
2003 software_stats_.totalPixelsPainted;
2004 stats.rendering_stats.totalRasterizeTimeInSeconds +=
[email protected]63ab54262012-11-09 15:58:452005 software_stats_.totalRasterizeTimeInSeconds;
[email protected]b63d58d2012-11-26 22:37:442006 stats.rendering_stats.totalPixelsRasterized +=
2007 software_stats_.totalPixelsRasterized;
[email protected]fef5e3972012-08-07 03:59:472008}
2009
[email protected]e9ff79c2012-10-19 21:31:262010bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522011 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2012 if (!gpu_channel)
2013 return false;
2014
2015 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2016}
2017
[email protected]0e241b4b2012-08-18 09:06:272018void RenderWidget::BeginSmoothScroll(
2019 bool down,
[email protected]ebd8b562012-10-09 14:44:292020 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192021 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292022 int mouse_event_x,
2023 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272024 DCHECK(!callback.is_null());
2025 int id = next_smooth_scroll_gesture_id_++;
[email protected]267909d2012-10-20 04:36:192026
2027 ViewHostMsg_BeginSmoothScroll_Params params;
2028 params.scroll_down = down;
2029 params.pixels_to_scroll = pixels_to_scroll;
2030 params.mouse_event_x = mouse_event_x;
2031 params.mouse_event_y = mouse_event_y;
2032
2033 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, params));
[email protected]0e241b4b2012-08-18 09:06:272034 pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback));
[email protected]a39ca1652012-07-13 21:30:582035}
2036
[email protected]67bfb83f2011-09-22 03:36:372037bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2038 return false;
2039}
[email protected]c3d45532011-10-07 19:20:402040
[email protected]41d86852012-11-07 12:23:242041bool RenderWidget::WillHandleGestureEvent(
2042 const WebKit::WebGestureEvent& event) {
2043 return false;
2044}
2045
[email protected]c3d45532011-10-07 19:20:402046bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
2047 return false;
2048}
[email protected]e9ff79c2012-10-19 21:31:262049
[email protected]3d5c243b2012-11-30 00:26:012050bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2051 return true;
2052}
2053
[email protected]e9ff79c2012-10-19 21:31:262054} // namespace content