blob: 517ba72fd6b057498e7527bdd50dd5a0342f1d49 [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);
[email protected]3ec08ed2013-01-11 15:59:57111 default:
112 // Must include default to let WebKit::WebInputEvent add new event types
113 // before they're added here.
114 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
115 break;
[email protected]6a4d7f62013-01-07 21:32:13116 }
117#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57118 return "";
[email protected]6a4d7f62013-01-07 21:32:13119}
120}
[email protected]e9ff79c2012-10-19 21:31:26121namespace content {
[email protected]62cb33cae2009-03-27 23:30:22122
[email protected]6fd35b72012-03-01 19:46:41123RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04124 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44125 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29126 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56127 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11128 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29129 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30130 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35131 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:29132 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06133 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05134 update_reply_pending_(false),
[email protected]ea3ee0a2012-05-15 03:43:09135 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24136 using_asynchronous_swapbuffers_(false),
137 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29138 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29139 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09140 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29141 needs_repainting_on_restore_(false),
142 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49143 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:48144 closing_(false),
[email protected]14392a52012-05-02 20:28:44145 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04146 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45147 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
148 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12149 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48150 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12151 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50152 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21153 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07154 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04155 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52156 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27157 throttle_input_events_(true),
[email protected]cb6430932012-10-31 00:53:36158 next_smooth_scroll_gesture_id_(0),
159 is_threaded_compositing_enabled_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05160 if (!swapped_out)
161 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27162 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18163 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
164 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36165 is_threaded_compositing_enabled_ =
166 CommandLine::ForCurrentProcess()->HasSwitch(
167 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29168}
169
170RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11171 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21172 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35173 if (current_paint_buf_) {
174 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
175 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29176 }
[email protected]992db4c2011-05-12 15:37:15177 // If we are swapped out, we have released already.
178 if (!is_swapped_out_)
179 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29180}
181
[email protected]484955942010-08-19 16:13:18182// static
[email protected]8085dbc82008-09-26 22:53:44183RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04184 WebKit::WebPopupType popup_type,
185 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29186 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41187 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04188 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29189 if (widget->Init(opener_id)) { // adds reference on success.
190 return widget;
191 }
192 return NULL;
initial.commit09911bf2008-07-26 23:55:29193}
194
[email protected]484955942010-08-19 16:13:18195// static
196WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
197 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03198 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18199 break;
200 case WebKit::WebPopupTypeSelect:
201 case WebKit::WebPopupTypeSuggestion:
202 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44203 case WebKit::WebPopupTypePage:
204 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03205 case WebKit::WebPopupTypeHelperPlugin:
206 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18207 default:
208 NOTREACHED();
209 }
210 return NULL;
211}
212
[email protected]a635f942012-12-07 10:34:29213bool RenderWidget::Init(int32 opener_id) {
214 return DoInit(opener_id,
215 RenderWidget::CreateWebWidget(this),
216 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
217 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18218}
219
[email protected]a635f942012-12-07 10:34:29220bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06221 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18222 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29223 DCHECK(!webwidget_);
224
225 if (opener_id != MSG_ROUTING_NONE)
226 opener_id_ = opener_id;
227
[email protected]484955942010-08-19 16:13:18228 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29229
[email protected]380244092011-10-07 17:26:27230 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29231 if (result) {
[email protected]380244092011-10-07 17:26:27232 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29233 // Take a reference on behalf of the RenderThread. This will be balanced
234 // when we receive ViewMsg_Close.
235 AddRef();
[email protected]a635f942012-12-07 10:34:29236 return true;
initial.commit09911bf2008-07-26 23:55:29237 } else {
[email protected]a635f942012-12-07 10:34:29238 // The above Send can fail when the tab is closing.
239 return false;
initial.commit09911bf2008-07-26 23:55:29240 }
241}
242
[email protected]fc4404d2012-11-07 19:53:30243// This is used to complete pending inits and non-pending inits.
244void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29245 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29246
[email protected]fc4404d2012-11-07 19:53:30247 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42248
[email protected]b774a882013-01-11 06:13:53249 if (webwidget_) {
250 webwidget_->setCompositorSurfaceReady();
251 if (is_threaded_compositing_enabled_)
252 webwidget_->enterForceCompositingMode(true);
[email protected]479b0172012-10-29 19:27:09253 }
[email protected]05a980d7a2012-02-07 22:16:42254 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29255
[email protected]6de74452009-02-25 18:04:59256 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29257}
258
[email protected]992db4c2011-05-12 15:37:15259void RenderWidget::SetSwappedOut(bool is_swapped_out) {
260 // We should only toggle between states.
261 DCHECK(is_swapped_out_ != is_swapped_out);
262 is_swapped_out_ = is_swapped_out;
263
264 // If we are swapping out, we will call ReleaseProcess, allowing the process
265 // to exit if all of its RenderViews are swapped out. We wait until the
266 // WasSwappedOut call to do this, to avoid showing the sad tab.
267 // If we are swapping in, we call AddRefProcess to prevent the process from
268 // exiting.
269 if (!is_swapped_out)
270 RenderProcess::current()->AddRefProcess();
271}
272
[email protected]a95986a82010-12-24 06:19:28273bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
274 bool handled = true;
275 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
276 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
277 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
278 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54279 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28280 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41281 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15282 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28283 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]a7266a92012-06-28 02:11:08284 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK, OnSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28285 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
286 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
287 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
288 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
289 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
290 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25291 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
292 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
293 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28294 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
295 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53296 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03297 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]a95986a82010-12-24 06:19:28298 IPC_MESSAGE_UNHANDLED(handled = false)
299 IPC_END_MESSAGE_MAP()
300 return handled;
301}
initial.commit09911bf2008-07-26 23:55:29302
303bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15304 // Don't send any messages after the browser has told us to close, and filter
305 // most outgoing messages while swapped out.
306 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26307 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11308 closing_) {
initial.commit09911bf2008-07-26 23:55:29309 delete message;
310 return false;
311 }
312
313 // If given a messsage without a routing ID, then assign our routing ID.
314 if (message->routing_id() == MSG_ROUTING_NONE)
315 message->set_routing_id(routing_id_);
316
[email protected]380244092011-10-07 17:26:27317 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44318}
319
[email protected]61e2b3cc2012-03-02 16:13:34320void RenderWidget::Resize(const gfx::Size& new_size,
321 const gfx::Rect& resizer_rect,
322 bool is_fullscreen,
323 ResizeAck resize_ack) {
324 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
325 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
326 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29327
[email protected]61e2b3cc2012-03-02 16:13:34328 // Ignore this during shutdown.
329 if (!webwidget_)
330 return;
331
332 // Remember the rect where the resize corner will be drawn.
333 resizer_rect_ = resizer_rect;
334
335 // NOTE: We may have entered fullscreen mode without changing our size.
336 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
337 if (fullscreen_change)
338 WillToggleFullscreen();
339 is_fullscreen_ = is_fullscreen;
340
341 if (size_ != new_size) {
342 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34343 needs_repainting_on_restore_ = false;
344
345 size_ = new_size;
346
347 paint_aggregator_.ClearPendingUpdate();
348
349 // When resizing, we want to wait to paint before ACK'ing the resize. This
350 // ensures that we only resize as fast as we can paint. We only need to
351 // send an ACK if we are resized to a non-empty rect.
352 webwidget_->resize(new_size);
353 if (!new_size.IsEmpty()) {
354 if (!is_accelerated_compositing_active_) {
355 // Resize should have caused an invalidation of the entire view.
356 DCHECK(paint_aggregator_.HasPendingUpdate());
357 }
358
359 // Send the Resize_ACK flag once we paint again if requested.
360 if (resize_ack == SEND_RESIZE_ACK)
361 set_next_paint_is_resize_ack();
362 }
[email protected]ff475a322012-03-14 00:05:35363 } else {
364 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34365 }
366
367 if (fullscreen_change)
368 DidToggleFullscreen();
369
370 // If a resize ack is requested and it isn't set-up, then no more resizes will
371 // come in and in general things will go wrong.
372 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
373 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29374}
375
376void RenderWidget::OnClose() {
377 if (closing_)
378 return;
379 closing_ = true;
380
381 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03382 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27383 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03384 SetHidden(false);
385 }
initial.commit09911bf2008-07-26 23:55:29386
initial.commit09911bf2008-07-26 23:55:29387 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25388 // now. Post a task that only gets invoked when there are no nested message
389 // loops.
[email protected]32876ae2011-11-15 22:25:21390 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29391 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25392
393 // Balances the AddRef taken when we called AddRoute.
394 Release();
initial.commit09911bf2008-07-26 23:55:29395}
396
[email protected]61e2b3cc2012-03-02 16:13:34397// Got a response from the browser after the renderer decided to create a new
398// view.
[email protected]fc4404d2012-11-07 19:53:30399void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34400 DCHECK(routing_id_ != MSG_ROUTING_NONE);
401
[email protected]fc4404d2012-11-07 19:53:30402 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34403}
404
[email protected]f21c613a2009-02-12 14:46:17405void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09406 const gfx::Rect& resizer_rect,
407 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34408 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29409}
410
[email protected]b5913d72012-02-07 22:26:54411void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
412 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59413 gfx::Rect view_rect(size_);
414
[email protected]ce112fe2012-10-29 22:52:18415 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59416 if (!old_damage_rect.IsEmpty())
417 paint_aggregator_.InvalidateRect(old_damage_rect);
418
[email protected]ce112fe2012-10-29 22:52:18419 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59420 if (!new_damage_rect.IsEmpty())
421 paint_aggregator_.InvalidateRect(new_damage_rect);
422
[email protected]b5913d72012-02-07 22:26:54423 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59424
[email protected]b5913d72012-02-07 22:26:54425 if (webwidget_)
426 webwidget_->didChangeWindowResizerRect();
427 }
428}
429
initial.commit09911bf2008-07-26 23:55:29430void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31431 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29432 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03433 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29434}
435
[email protected]9e2e4632012-07-27 16:38:41436void RenderWidget::OnWasShown(bool needs_repainting) {
437 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29438 // During shutdown we can just ignore this message.
439 if (!webwidget_)
440 return;
441
442 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03443 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29444
445 if (!needs_repainting && !needs_repainting_on_restore_)
446 return;
447 needs_repainting_on_restore_ = false;
448
[email protected]d65adb12010-04-28 17:26:49449 // Tag the next paint as a restore ack, which is picked up by
450 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29451 set_next_paint_is_restore_ack();
452
453 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56454 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46455 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
456 } else {
457 scheduleComposite();
458 }
initial.commit09911bf2008-07-26 23:55:29459}
460
[email protected]992db4c2011-05-12 15:37:15461void RenderWidget::OnWasSwappedOut() {
462 // If we have been swapped out and no one else is using this process,
463 // it's safe to exit now. If we get swapped back in, we will call
464 // AddRefProcess in SetSwappedOut.
465 if (is_swapped_out_)
466 RenderProcess::current()->ReleaseProcess();
467}
468
[email protected]53d3f302009-12-21 04:42:05469void RenderWidget::OnRequestMoveAck() {
470 DCHECK(pending_window_rect_count_);
471 pending_window_rect_count_--;
472}
473
474void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58475 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21476 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05477 update_reply_pending_ = false;
478
[email protected]b4d08452010-10-05 17:34:35479 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
480 // have no current paint buffer.
481 if (current_paint_buf_) {
482 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
483 current_paint_buf_ = NULL;
484 }
485
[email protected]65225772011-05-12 21:10:24486 // If swapbuffers is still pending, then defer the update until the
487 // swapbuffers occurs.
488 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
489 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
490 return;
491 }
492
[email protected]29ed96a2012-02-04 18:12:16493 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18494 if (!is_accelerated_compositing_active_) {
495 DidFlushPaint();
496 }
[email protected]a2f6bc112009-06-27 16:27:25497
initial.commit09911bf2008-07-26 23:55:29498 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24499 DoDeferredUpdateAndSendInputAck();
500}
501
[email protected]d0be63772011-12-20 23:18:04502bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24503 return false;
504}
505
[email protected]479b0172012-10-29 19:27:09506bool RenderWidget::ForceCompositingModeEnabled() {
507 return false;
508}
509
[email protected]d0be63772011-12-20 23:18:04510void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24511 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21512 while (!updates_pending_swap_.empty()) {
513 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
514 updates_pending_swap_.pop_front();
515 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
516 // compositing pass, hence doesn't require an UpdateRect message.
517 if (msg)
518 Send(msg);
519 }
[email protected]65225772011-05-12 21:10:24520 num_swapbuffers_complete_pending_ = 0;
521 using_asynchronous_swapbuffers_ = false;
522 // Schedule another frame so the compositor learns about it.
523 scheduleComposite();
524}
525
[email protected]37a6f302011-07-11 23:43:08526void RenderWidget::OnSwapBuffersPosted() {
527 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21528
529 if (using_asynchronous_swapbuffers_) {
530 ViewHostMsg_UpdateRect* msg = NULL;
531 // pending_update_params_ can be NULL if the swap doesn't correspond to an
532 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
533 // message.
534 if (pending_update_params_.get()) {
535 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
536 pending_update_params_.reset();
537 }
538 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08539 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21540 }
[email protected]37a6f302011-07-11 23:43:08541}
542
543void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24544 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16545
[email protected]404939f2012-06-01 04:06:18546 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16547 DidFlushPaint();
548
[email protected]65225772011-05-12 21:10:24549 // When compositing deactivates, we reset the swapbuffers pending count. The
550 // swapbuffers acks may still arrive, however.
551 if (num_swapbuffers_complete_pending_ == 0) {
552 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
553 return;
554 }
[email protected]aa4117f2011-12-09 22:19:21555 DCHECK(!updates_pending_swap_.empty());
556 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
557 updates_pending_swap_.pop_front();
558 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
559 // compositing pass, hence doesn't require an UpdateRect message.
560 if (msg)
561 Send(msg);
[email protected]65225772011-05-12 21:10:24562 num_swapbuffers_complete_pending_--;
563
564 // If update reply is still pending, then defer the update until that reply
565 // occurs.
[email protected]d0be63772011-12-20 23:18:04566 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24567 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
568 return;
569 }
570
571 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06572 // when we were previously rendering. However, if an invalidation task is not
573 // posted, there may be software rendering work pending. In that case, don't
574 // early out.
575 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24576 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
577 return;
578 }
579
[email protected]cc66e682012-10-02 06:48:18580 // Do not call DoDeferredUpdate unless there's animation work to be done or
581 // a real invalidation. This prevents rendering in response to a swapbuffers
582 // callback coming back after we've navigated away from the page that
583 // generated it.
584 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
585 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
586 return;
587 }
588
[email protected]65225772011-05-12 21:10:24589 // Continue painting if necessary...
590 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29591}
592
[email protected]0dea1652012-12-14 00:09:09593void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
594 bool is_keyboard_shortcut) {
[email protected]65225772011-05-12 21:10:24595 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
initial.commit09911bf2008-07-26 23:55:29596
[email protected]5dd768212009-08-13 23:34:49597 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09598 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49599 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29600 return;
[email protected]5dd768212009-08-13 23:34:49601 }
initial.commit09911bf2008-07-26 23:55:29602
[email protected]6a4d7f62013-01-07 21:32:13603 base::TimeDelta now = base::TimeDelta::FromInternalValue(
604 base::TimeTicks::Now().ToInternalValue());
605
606 int64 delta = static_cast<int64>(
607 (now.InSecondsF() - input_event->timeStampSeconds) *
608 base::Time::kMicrosecondsPerSecond);
609 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
610 std::string name_for_event =
611 base::StringPrintf("Event.Latency.Renderer.%s",
612 GetEventName(input_event->type));
613 base::Histogram* counter_for_type =
614 base::Histogram::FactoryTimeGet(
615 name_for_event,
616 base::TimeDelta::FromMilliseconds(0),
617 base::TimeDelta::FromMilliseconds(1000000),
618 100,
619 base::Histogram::kUmaTargetedHistogramFlag);
620 counter_for_type->AddTime(base::TimeDelta::FromMicroseconds(delta));
621
[email protected]67bfb83f2011-09-22 03:36:37622 bool prevent_default = false;
623 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26624 const WebMouseEvent& mouse_event =
625 *static_cast<const WebMouseEvent*>(input_event);
626 TRACE_EVENT2("renderer", "HandleMouseMove",
627 "x", mouse_event.x, "y", mouse_event.y);
628 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37629 }
630
[email protected]41d86852012-11-07 12:23:24631 if (WebInputEvent::isGestureEventType(input_event->type)) {
632 const WebGestureEvent& gesture_event =
633 *static_cast<const WebGestureEvent*>(input_event);
634 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
635 }
636
[email protected]3ebcc7c2013-01-09 05:34:46637 if (input_event->type == WebInputEvent::GestureTap ||
638 input_event->type == WebInputEvent::GestureLongPress)
639 resetInputMethod();
640
[email protected]67bfb83f2011-09-22 03:36:37641 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12642 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
643 suppress_next_char_events_ = false;
644 if (!processed && webwidget_)
645 processed = webwidget_->handleInputEvent(*input_event);
646 }
647
648 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
649 // it's not processed by webkit, then we need to suppress the upcoming Char
650 // events.
651 if (!processed && is_keyboard_shortcut)
652 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29653
[email protected]3d5c243b2012-11-30 00:26:01654 InputEventAckState ack_result = processed ?
655 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
656 if (!processed && input_event->type == WebInputEvent::TouchStart) {
657 const WebTouchEvent& touch_event =
658 *static_cast<const WebTouchEvent*>(input_event);
659 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
660 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
661 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
662 }
663
[email protected]a9fb30aa2011-10-06 06:58:46664 IPC::Message* response =
665 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
[email protected]3d5c243b2012-11-30 00:26:01666 ack_result);
[email protected]3391a0772012-03-28 00:32:07667 bool event_type_gets_rate_limited =
668 input_event->type == WebInputEvent::MouseMove ||
669 input_event->type == WebInputEvent::MouseWheel ||
670 WebInputEvent::isTouchEventType(input_event->type);
671 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57672 throttle_input_events_ &&
[email protected]b774a882013-01-11 06:13:53673 ((webwidget_ ? webwidget_->isInputThrottled() : false) ||
674 paint_aggregator_.HasPendingUpdate());
[email protected]e2824412009-02-27 01:57:05675
[email protected]f8868d72012-04-27 19:13:03676 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24677 // We want to rate limit the input events in this case, so we'll wait for
678 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17679 if (pending_input_event_ack_.get()) {
680 // As two different kinds of events could cause us to postpone an ack
681 // we send it now, if we have one pending. The Browser should never
682 // send us the same kind of event we are delaying the ack for.
683 Send(pending_input_event_ack_.release());
684 }
[email protected]12fbad812009-09-01 18:21:24685 pending_input_event_ack_.reset(response);
686 } else {
687 Send(response);
688 }
689
[email protected]3306f262012-09-21 19:20:42690#if defined(OS_ANDROID)
691 // Allow the IME to be shown when the focus changes as a consequence
692 // of a processed touch end event.
693 if (input_event->type == WebInputEvent::TouchEnd && processed)
694 UpdateTextInputState(SHOW_IME_IF_NEEDED);
695#endif
696
[email protected]5dd768212009-08-13 23:34:49697 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48698
[email protected]67bfb83f2011-09-22 03:36:37699 if (!prevent_default) {
700 if (WebInputEvent::isKeyboardEventType(input_event->type))
701 DidHandleKeyEvent();
702 if (WebInputEvent::isMouseEventType(input_event->type))
703 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24704 if (WebInputEvent::isTouchEventType(input_event->type))
705 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37706 }
initial.commit09911bf2008-07-26 23:55:29707}
708
709void RenderWidget::OnMouseCaptureLost() {
710 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28711 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29712}
713
714void RenderWidget::OnSetFocus(bool enable) {
715 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33716 if (webwidget_)
717 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29718}
719
720void RenderWidget::ClearFocus() {
721 // We may have got the focus from the browser before this gets processed, in
722 // which case we do not want to unfocus ourself.
723 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28724 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29725}
726
[email protected]2d5d09d52009-06-15 14:29:21727void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00728 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21729 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06730 TRACE_EVENT2("renderer", "PaintRect",
731 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45732
733 const bool kEnableGpuBenchmarking =
734 CommandLine::ForCurrentProcess()->HasSwitch(
735 switches::kEnableGpuBenchmarking);
736 base::TimeTicks rasterize_begin_ticks;
737 if (kEnableGpuBenchmarking)
738 rasterize_begin_ticks = base::TimeTicks::HighResNow();
[email protected]4fb66842009-12-04 21:41:00739 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21740
741 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00742 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
743 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03744
[email protected]699ab0d2009-04-23 23:19:14745 // If there is a custom background, tile it.
746 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14747 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11748 skia::RefPtr<SkShader> shader = skia::AdoptRef(
749 SkShader::CreateBitmapShader(background_,
750 SkShader::kRepeat_TileMode,
751 SkShader::kRepeat_TileMode));
752 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20753
754 // Use kSrc_Mode to handle background_ transparency properly.
755 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
756
757 // Canvas could contain multiple update rects. Clip to given rect so that
758 // we don't accidentally clear other update rects.
759 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48760 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14761 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20762 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14763 }
764
[email protected]719b36f2010-12-22 20:36:46765 // First see if this rect is a plugin that can paint itself faster.
766 TransportDIB* optimized_dib = NULL;
767 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20768 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46769 webkit::ppapi::PluginInstance* optimized_instance =
770 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
771 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20772 &optimized_copy_rect,
773 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46774 if (optimized_instance) {
775 // This plugin can be optimize-painted and we can just ask it to paint
776 // itself. We don't actually need the TransportDIB in this case.
777 //
778 // This is an optimization for PPAPI plugins that know they're on top of
779 // the page content. If this rect is inside such a plugin, we can save some
780 // time and avoid re-rendering the page content which we know will be
781 // covered by the plugin later (this time can be significant, especially
782 // for a playing movie that is invalidating a lot).
783 //
784 // In the plugin movie case, hopefully the similar call to
785 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
786 // painting, because that avoids copying the plugin image to a different
787 // paint rect. Unfortunately, if anything on the page is animating other
788 // than the movie, it break this optimization since the union of the
789 // invalid regions will be larger than the plugin.
790 //
791 // This code optimizes that case, where we can still avoid painting in
792 // WebKit and filling the background (which can be slow) and just painting
793 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
794 // required.
[email protected]63ab54262012-11-09 15:58:45795 base::TimeTicks paint_begin_ticks;
796 if (kEnableGpuBenchmarking)
797 paint_begin_ticks = base::TimeTicks::HighResNow();
798
[email protected]df59dd42012-09-14 22:56:30799 SkAutoCanvasRestore auto_restore(canvas, true);
800 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46801 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27802 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21803 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45804 if (kEnableGpuBenchmarking) {
805 base::TimeDelta paint_time =
806 base::TimeTicks::HighResNow() - paint_begin_ticks;
807 if (!is_accelerated_compositing_active_)
808 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
809 }
[email protected]719b36f2010-12-22 20:36:46810 } else {
811 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45812 base::TimeTicks paint_begin_ticks;
813 if (kEnableGpuBenchmarking)
814 paint_begin_ticks = base::TimeTicks::HighResNow();
815
[email protected]719b36f2010-12-22 20:36:46816 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45817
818 if (kEnableGpuBenchmarking) {
819 base::TimeDelta paint_time =
820 base::TimeTicks::HighResNow() - paint_begin_ticks;
821 if (!is_accelerated_compositing_active_)
822 software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF();
823 }
[email protected]719b36f2010-12-22 20:36:46824
825 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35826 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46827 }
initial.commit09911bf2008-07-26 23:55:29828
[email protected]4fb66842009-12-04 21:41:00829 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00830 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45831
832 if (kEnableGpuBenchmarking) {
833 base::TimeDelta rasterize_time =
834 base::TimeTicks::HighResNow() - rasterize_begin_ticks;
835 software_stats_.totalRasterizeTimeInSeconds += rasterize_time.InSecondsF();
836
837 int64 num_pixels_processed = rect.width() * rect.height();
838 software_stats_.totalPixelsPainted += num_pixels_processed;
839 software_stats_.totalPixelsRasterized += num_pixels_processed;
840 }
[email protected]4fb66842009-12-04 21:41:00841}
842
843void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
844 skia::PlatformCanvas* canvas) {
845 static bool kPaintBorder =
846 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
847 if (!kPaintBorder)
848 return;
849
[email protected]53d3f302009-12-21 04:42:05850 // Cycle through these colors to help distinguish new paint rects.
851 const SkColor colors[] = {
852 SkColorSetARGB(0x3F, 0xFF, 0, 0),
853 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
854 SkColorSetARGB(0x3F, 0, 0, 0xFF),
855 };
856 static int color_selector = 0;
857
[email protected]4fb66842009-12-04 21:41:00858 SkPaint paint;
859 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05860 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00861 paint.setStrokeWidth(1);
862
863 SkIRect irect;
864 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
865 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29866}
867
[email protected]52ccd0ea2011-02-16 01:09:05868void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30869 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30870 if (!animation_update_pending_) {
871 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59872 return;
[email protected]921244e42011-07-20 16:36:30873 }
[email protected]bd37ae252011-06-03 01:28:18874 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59875 // Record when we fired (according to base::Time::Now()) relative to when
876 // we posted the task to quantify how much the base::Time/base::TimeTicks
877 // skew is affecting animations.
878 base::TimeDelta animation_callback_delay = base::Time::Now() -
879 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
880 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
881 animation_callback_delay,
882 base::TimeDelta::FromMilliseconds(0),
883 base::TimeDelta::FromMilliseconds(30),
884 25);
885 }
[email protected]65225772011-05-12 21:10:24886 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24887}
888
[email protected]52ccd0ea2011-02-16 01:09:05889void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59890 if (!animation_update_pending_)
891 return;
[email protected]bd37ae252011-06-03 01:28:18892
893 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33894 base::TimeDelta animationInterval = IsRenderingVSynced() ?
895 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18896
[email protected]7c4329e2011-02-18 22:02:59897 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45898
899 // animation_floor_time_ is the earliest time that we should animate when
900 // using the dead reckoning software scheduler. If we're using swapbuffers
901 // complete callbacks to rate limit, we can ignore this floor.
902 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30903 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33904 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18905 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59906 // running animation callbacks so that if a callback requests another
907 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38908 animation_timer_.Stop();
909 animation_timer_.Start(FROM_HERE, animationInterval, this,
910 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59911 animation_update_pending_ = false;
[email protected]b774a882013-01-11 06:13:53912 webwidget_->animate(0.0);
[email protected]7c4329e2011-02-18 22:02:59913 return;
[email protected]5f8b1022011-01-21 23:34:50914 }
[email protected]bd37ae252011-06-03 01:28:18915 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38916 if (!animation_timer_.IsRunning()) {
917 // This code uses base::Time::Now() to calculate the floor and next fire
918 // time because javascript's Date object uses base::Time::Now(). The
919 // message loop uses base::TimeTicks, which on windows can have a
920 // different granularity than base::Time.
921 // The upshot of all this is that this function might be called before
922 // base::Time::Now() has advanced past the animation_floor_time_. To
923 // avoid exposing this delay to javascript, we keep posting delayed
924 // tasks until base::Time::Now() has advanced far enough.
925 base::TimeDelta delay = animation_floor_time_ - now;
926 animation_timer_.Start(FROM_HERE, delay, this,
927 &RenderWidget::AnimationCallback);
928 }
[email protected]5f8b1022011-01-21 23:34:50929}
930
[email protected]bd37ae252011-06-03 01:28:18931bool RenderWidget::IsRenderingVSynced() {
932 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
933 // not caught by this check. This will lead to artificially low frame rates
934 // for people who force vsync off at a driver level and expect Chrome to speed
935 // up.
936 return !has_disable_gpu_vsync_switch_;
937}
938
[email protected]65225772011-05-12 21:10:24939void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06940 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24941 invalidation_task_posted_ = false;
942 DoDeferredUpdateAndSendInputAck();
943}
944
945void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05946 DoDeferredUpdate();
947
948 if (pending_input_event_ack_.get())
949 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21950}
951
[email protected]552e6002009-11-19 05:24:57952void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58953 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08954
[email protected]65225772011-05-12 21:10:24955 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29956 return;
[email protected]05a980d7a2012-02-07 22:16:42957
[email protected]fc4404d2012-11-07 19:53:30958 if (!init_complete_) {
959 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:42960 return;
961 }
[email protected]aa4117f2011-12-09 22:19:21962 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24963 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
964 return;
965 }
[email protected]9ca84622011-06-02 23:46:39966 if (is_accelerated_compositing_active_ &&
967 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24968 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
969 return;
970 }
initial.commit09911bf2008-07-26 23:55:29971
[email protected]552e6002009-11-19 05:24:57972 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:05973 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:57974 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29975 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24976 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29977 return;
978 }
979
[email protected]05a980d7a2012-02-07 22:16:42980 if (is_accelerated_compositing_active_)
981 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
982
[email protected]0fb93f52011-05-18 23:13:56983 // Tracking of frame rate jitter
984 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51985 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05986 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50987
[email protected]f98d7e3c2010-09-13 22:30:46988 // Layout may generate more invalidation. It may also enable the
989 // GPU acceleration, so make sure to run layout before we send the
990 // GpuRenderingActivated message.
991 webwidget_->layout();
992
[email protected]dcca3aa92012-02-17 23:03:37993 // The following two can result in further layout and possibly
994 // enable GPU acceleration so they need to be called before any painting
995 // is done.
[email protected]3306f262012-09-21 19:20:42996 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:37997 UpdateSelectionBounds();
998
[email protected]5f8b1022011-01-21 23:34:50999 // Suppress painting if nothing is dirty. This has to be done after updating
1000 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241001 if (!paint_aggregator_.HasPendingUpdate()) {
1002 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:511003 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501004 return;
[email protected]65225772011-05-12 21:10:241005 }
[email protected]5f8b1022011-01-21 23:34:501006
[email protected]479b0172012-10-29 19:27:091007 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361008 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091009 ForceCompositingModeEnabled()) {
1010 webwidget_->enterForceCompositingMode(true);
1011 }
1012
[email protected]872ae5b2011-05-26 20:20:501013 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561014 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041015 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561016 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1017 delay,
1018 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411019 base::TimeDelta::FromMilliseconds(120),
1020 60);
[email protected]d0be63772011-12-20 23:18:041021 } else {
[email protected]0fb93f52011-05-18 23:13:561022 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1023 delay,
1024 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411025 base::TimeDelta::FromMilliseconds(120),
1026 60);
[email protected]d0be63772011-12-20 23:18:041027 }
[email protected]872ae5b2011-05-26 20:20:501028
1029 // Calculate filtered time per frame:
1030 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1031 filtered_time_per_frame_ =
1032 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561033 }
1034 last_do_deferred_update_time_ = frame_begin_ticks;
1035
[email protected]fef5e3972012-08-07 03:59:471036 if (!is_accelerated_compositing_active_) {
1037 software_stats_.numAnimationFrames++;
1038 software_stats_.numFramesSentToScreen++;
1039 }
1040
[email protected]552e6002009-11-19 05:24:571041 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291042 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301043 PaintAggregator::PendingUpdate update;
1044 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291045
[email protected]53d3f302009-12-21 04:42:051046 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181047 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291048
[email protected]29ed96a2012-02-04 18:12:161049 // Notify derived classes that we're about to initiate a paint.
1050 WillInitiatePaint();
1051
[email protected]ca4847f2010-09-24 05:39:151052 // A plugin may be able to do an optimized paint. First check this, in which
1053 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461054 // This optimization allows PPAPI plugins that declare themselves on top of
1055 // the page (like a traditional windowed plugin) to be able to animate (think
1056 // movie playing) without repeatedly re-painting the page underneath, or
1057 // copying the plugin backing store (since we can send the plugin's backing
1058 // store directly to the browser).
1059 //
1060 // This optimization only works when the entire invalid region is contained
1061 // within the plugin. There is a related optimization in PaintRect for the
1062 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151063 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151064 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201065 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211066 DCHECK(!pending_update_params_.get());
1067 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551068 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211069 pending_update_params_->scroll_rect = update.scroll_rect;
1070 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211071 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1072 pending_update_params_->flags = next_paint_flags_;
1073 pending_update_params_->scroll_offset = GetScrollOffset();
1074 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091075 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211076 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091077 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211078
[email protected]ca4847f2010-09-24 05:39:151079 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561080 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151081 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201082 &optimized_copy_rect,
1083 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271084 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471085 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211086 pending_update_params_->bitmap = dib->id();
1087 pending_update_params_->bitmap_rect = optimized_copy_location;
1088 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201089 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561090 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461091 // Compute a buffer for painting and cache it.
[email protected]ce112fe2012-10-29 22:52:181092 gfx::Rect pixel_bounds = gfx::ToFlooredRectDeprecated(
1093 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]ca4847f2010-09-24 05:39:151094 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351095 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591096 pixel_bounds));
[email protected]f98d7e3c2010-09-13 22:30:461097 if (!canvas.get()) {
1098 NOTREACHED();
1099 return;
1100 }
[email protected]cef3362f2009-12-21 17:48:451101
[email protected]f98d7e3c2010-09-13 22:30:461102 // We may get back a smaller canvas than we asked for.
1103 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591104 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1105 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1106 pixel_bounds.set_width(canvas->getDevice()->width());
1107 pixel_bounds.set_height(canvas->getDevice()->height());
1108 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1109 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051110
[email protected]f98d7e3c2010-09-13 22:30:461111 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1112
[email protected]aa4117f2011-12-09 22:19:211113 pending_update_params_->bitmap = current_paint_buf_->id();
1114 pending_update_params_->bitmap_rect = bounds;
1115
1116 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461117 // The scroll damage is just another rectangle to paint and copy.
1118 copy_rects.swap(update.paint_rects);
1119 if (!scroll_damage.IsEmpty())
1120 copy_rects.push_back(scroll_damage);
1121
1122 for (size_t i = 0; i < copy_rects.size(); ++i)
[email protected]f1cccb32012-06-06 18:29:591123 PaintRect(copy_rects[i], pixel_bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:351124
1125 // Software FPS tick for performance tests. The accelerated path traces the
1126 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1127 // NOTE: Tests may break if this event is renamed or moved.
1128 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:461129 } else { // Accelerated compositing path
1130 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211131 // If painting is done via the gpu process then we don't set any damage
1132 // rects to save the browser process from doing unecessary work.
1133 pending_update_params_->bitmap_rect = bounds;
1134 pending_update_params_->scroll_rect = gfx::Rect();
1135 // We don't need an ack, because we're not sharing a DIB with the browser.
1136 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1137 // with the browser for the GPU surface.
1138 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:421139 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:461140 }
1141
[email protected]936c6f52011-12-13 01:35:261142 // If we're holding a pending input event ACK, send the ACK before sending the
1143 // UpdateReply message so we can receive another input event before the
1144 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1145 // the UpdateRect IPC message handler.
1146 if (pending_input_event_ack_.get())
1147 Send(pending_input_event_ack_.release());
1148
[email protected]aa4117f2011-12-09 22:19:211149 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
1150 // OnSwapBuffersPosted), meaning a message has been added to the
1151 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1152 // the message now.
1153 if (pending_update_params_.get()) {
1154 // sending an ack to browser process that the paint is complete...
1155 update_reply_pending_ = pending_update_params_->needs_ack;
1156 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1157 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341158 }
[email protected]53d3f302009-12-21 04:42:051159
[email protected]29ed96a2012-02-04 18:12:161160 // If we're software rendering then we're done initiating the paint.
1161 if (!is_accelerated_compositing_active_)
1162 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291163}
1164
1165///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461166// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291167
[email protected]4873c7d2009-07-16 06:36:281168void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091169 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1170 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571171 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481172 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181173 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571174 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291175 return;
1176
[email protected]552e6002009-11-19 05:24:571177 paint_aggregator_.InvalidateRect(damaged_rect);
1178
1179 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241180 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571181 return;
1182 if (!paint_aggregator_.HasPendingUpdate())
1183 return;
[email protected]aa4117f2011-12-09 22:19:211184 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241185 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1186 return;
1187
1188 // When GPU rendering, combine pending animations and invalidations into
1189 // a single update.
[email protected]816edc62012-03-17 01:27:221190 if (is_accelerated_compositing_active_ &&
1191 animation_update_pending_ &&
1192 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571193 return;
1194
1195 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291196 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1197 // on the call stack.
1198 // 2) Allows us to collect more damage rects before painting to help coalesce
1199 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241200 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211201 MessageLoop::current()->PostTask(
1202 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291203}
1204
[email protected]990278ff2012-11-13 02:12:551205void RenderWidget::didScrollRect(int dx, int dy,
1206 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461207 // Drop scrolls on the floor when we are in compositing mode.
1208 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561209 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461210 return;
1211
[email protected]552e6002009-11-19 05:24:571212 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481213 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181214 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571215 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291216 return;
1217
[email protected]990278ff2012-11-13 02:12:551218 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571219
1220 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241221 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571222 return;
1223 if (!paint_aggregator_.HasPendingUpdate())
1224 return;
[email protected]aa4117f2011-12-09 22:19:211225 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241226 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1227 return;
1228
1229 // When GPU rendering, combine pending animations and invalidations into
1230 // a single update.
[email protected]816edc62012-03-17 01:27:221231 if (is_accelerated_compositing_active_ &&
1232 animation_update_pending_ &&
1233 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571234 return;
1235
1236 // Perform updating asynchronously. This serves two purposes:
1237 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1238 // on the call stack.
1239 // 2) Allows us to collect more damage rects before painting to help coalesce
1240 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241241 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211242 MessageLoop::current()->PostTask(
1243 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291244}
1245
[email protected]244ac1892011-12-02 17:04:471246void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091247 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1248 size_ = new_size;
1249 need_update_rect_for_auto_resize_ = true;
[email protected]240b5c32012-11-09 19:17:181250 // If we don't clear PaintAggregator after changing autoResize state, then
1251 // we might end up in a situation where bitmap_rect is larger than the
1252 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1253 // with invalid damage rects.
1254 paint_aggregator_.ClearPendingUpdate();
[email protected]ea3ee0a2012-05-15 03:43:091255 }
[email protected]244ac1892011-12-02 17:04:471256}
1257
[email protected]91acd1c2012-03-14 08:32:391258void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221259 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1260
[email protected]c63b4d42012-04-26 01:01:071261#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211262 if (!is_accelerated_compositing_active_) {
1263 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1264 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1265 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1266 // going to switch to accelerated compositing, the GPU process may need
1267 // round-trips to the browser's UI thread before finishing the frame,
1268 // causing deadlocks if we delay the UpdateRect until we receive the
1269 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071270 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1271 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211272 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1273 }
[email protected]c63b4d42012-04-26 01:01:071274#endif
[email protected]aa4117f2011-12-09 22:19:211275
[email protected]ea162f92011-10-04 23:08:221276 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421277 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241278 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221279}
1280
1281void RenderWidget::didDeactivateCompositor() {
1282 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1283
1284 is_accelerated_compositing_active_ = false;
1285 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1286 routing_id_, is_accelerated_compositing_active_));
1287
[email protected]ea162f92011-10-04 23:08:221288 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241289 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091290
1291 // In single-threaded mode, we exit force compositing mode and re-enter in
1292 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1293 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1294 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361295 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091296 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561297}
1298
[email protected]9cd43a62012-03-26 08:03:561299void RenderWidget::willBeginCompositorFrame() {
1300 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371301
1302 DCHECK(RenderThreadImpl::current()->compositor_thread());
1303
1304 // The following two can result in further layout and possibly
1305 // enable GPU acceleration so they need to be called before any painting
1306 // is done.
[email protected]2d354272013-01-14 00:59:061307#if !defined(OS_ANDROID)
1308 UpdateTextInputState(DO_NOT_SHOW_IME);
1309#endif // OS_ANDROID
[email protected]abe8b3a2012-03-28 21:19:371310 UpdateSelectionBounds();
1311
[email protected]9cd43a62012-03-26 08:03:561312 WillInitiatePaint();
1313}
1314
[email protected]3391a0772012-03-28 00:32:071315void RenderWidget::didBecomeReadyForAdditionalInput() {
1316 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1317 if (pending_input_event_ack_.get())
1318 Send(pending_input_event_ack_.release());
1319}
1320
[email protected]58264a32011-11-17 23:36:151321void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501322 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351323 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1324 // NOTE: Tests may break if this event is renamed or moved.
1325 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161326 // Notify subclasses that we initiated the paint operation.
1327 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151328}
1329
1330void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181331 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1332
1333 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561334 DidFlushPaint();
1335
[email protected]aa4117f2011-12-09 22:19:211336 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151337 return;
1338
[email protected]ea3ee0a2012-05-15 03:43:091339 if (!next_paint_flags_ &&
1340 !need_update_rect_for_auto_resize_ &&
1341 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151342 return;
[email protected]ea3ee0a2012-05-15 03:43:091343 }
[email protected]58264a32011-11-17 23:36:151344
1345 ViewHostMsg_UpdateRect_Params params;
1346 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151347 params.plugin_window_moves.swap(plugin_window_moves_);
1348 params.flags = next_paint_flags_;
1349 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121350 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091351 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151352
1353 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1354 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091355 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151356}
1357
[email protected]f98d7e3c2010-09-13 22:30:461358void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091359 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]d0be63772011-12-20 23:18:041360 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401361 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041362 } else {
[email protected]c3d45532011-10-07 19:20:401363 // TODO(nduca): replace with something a little less hacky. The reason this
1364 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1365 // contains a lot of host-renderer synchronization logic that is still
1366 // important for the accelerated compositing case. The option of simply
1367 // duplicating all that code is less desirable than "faking out" the
1368 // invalidation path using a magical damage rect.
1369 didInvalidateRect(WebRect(0, 0, 1, 1));
1370 }
[email protected]f98d7e3c2010-09-13 22:30:461371}
1372
[email protected]5f8b1022011-01-21 23:34:501373void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201374 if (animation_update_pending_)
1375 return;
1376
[email protected]921244e42011-07-20 16:36:301377 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201378 animation_update_pending_ = true;
1379 if (!animation_timer_.IsRunning()) {
1380 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1381 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211382 }
[email protected]5f8b1022011-01-21 23:34:501383}
1384
[email protected]4873c7d2009-07-16 06:36:281385void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301386 // TODO(darin): Eliminate this temporary.
1387 WebCursor cursor(cursor_info);
1388
initial.commit09911bf2008-07-26 23:55:291389 // Only send a SetCursor message if we need to make a change.
1390 if (!current_cursor_.IsEqual(cursor)) {
1391 current_cursor_ = cursor;
1392 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1393 }
1394}
1395
1396// We are supposed to get a single call to Show for a newly created RenderWidget
1397// that was created via RenderWidget::CreateWebView. So, we wait until this
1398// point to dispatch the ShowWidget message.
1399//
1400// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281401// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291402//
[email protected]4873c7d2009-07-16 06:36:281403void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291404 DCHECK(!did_show_) << "received extraneous Show call";
1405 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1406 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1407
[email protected]8de12d942010-11-17 20:42:441408 if (did_show_)
1409 return;
1410
1411 did_show_ = true;
1412 // NOTE: initial_pos_ may still have its default values at this point, but
1413 // that's okay. It'll be ignored if as_popup is false, or the browser
1414 // process will impose a default position otherwise.
1415 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1416 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291417}
1418
[email protected]4873c7d2009-07-16 06:36:281419void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291420}
1421
[email protected]4873c7d2009-07-16 06:36:281422void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291423}
1424
[email protected]2533ce12009-05-09 00:02:241425void RenderWidget::DoDeferredClose() {
1426 Send(new ViewHostMsg_Close(routing_id_));
1427}
1428
[email protected]4873c7d2009-07-16 06:36:281429void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321430 if (is_swapped_out_) {
1431 // This widget is currently swapped out, and the active widget is in a
1432 // different process. Have the browser route the close request to the
1433 // active widget instead, so that the correct unload handlers are run.
1434 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1435 return;
1436 }
1437
initial.commit09911bf2008-07-26 23:55:291438 // If a page calls window.close() twice, we'll end up here twice, but that's
1439 // OK. It is safe to send multiple Close messages.
1440
[email protected]2533ce12009-05-09 00:02:241441 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1442 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1443 // could be closed before the JS finishes executing. So instead, post a
1444 // message back to the message loop, which won't run until the JS is
1445 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211446 MessageLoop::current()->PostTask(
1447 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291448}
1449
1450void RenderWidget::Close() {
1451 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281452 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291453 webwidget_ = NULL;
1454 }
1455}
1456
[email protected]4873c7d2009-07-16 06:36:281457WebRect RenderWidget::windowRect() {
1458 if (pending_window_rect_count_)
1459 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241460
[email protected]80ad8622012-11-07 16:33:031461 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291462}
1463
[email protected]8a9d6ca32011-06-06 20:11:301464void RenderWidget::setToolTipText(const WebKit::WebString& text,
1465 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541466 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301467}
1468
[email protected]4873c7d2009-07-16 06:36:281469void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291470 if (did_show_) {
1471 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241472 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291473 } else {
1474 initial_pos_ = pos;
1475 }
1476}
1477
[email protected]2533ce12009-05-09 00:02:241478void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1479 pending_window_rect_ = rect;
1480 pending_window_rect_count_++;
1481}
1482
[email protected]4873c7d2009-07-16 06:36:281483WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241484 if (pending_window_rect_count_) {
1485 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1486 // the RootWindowRect is probably going to return wrong results since the
1487 // browser may not have processed the Move yet. There isn't really anything
1488 // good to do in this case, and it shouldn't happen - since this size is
1489 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281490 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241491 }
1492
[email protected]80ad8622012-11-07 16:33:031493 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371494}
1495
[email protected]4873c7d2009-07-16 06:36:281496WebRect RenderWidget::windowResizerRect() {
1497 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191498}
1499
[email protected]fa7b1dc2010-06-23 17:53:041500void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031501 // To prevent this renderer process from sending unnecessary IPC messages to
1502 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041503 // only during the input method attached to the browser process is active.
1504 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291505}
1506
[email protected]58b48a0d2012-06-13 07:01:351507void RenderWidget::UpdateCompositionInfo(
1508 const ui::Range& range,
1509 const std::vector<gfx::Rect>& character_bounds) {
1510 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1511 return;
1512 composition_character_bounds_ = character_bounds;
1513 composition_range_ = range;
1514 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1515 routing_id(), composition_range_, composition_character_bounds_));
1516}
1517
[email protected]fa7b1dc2010-06-23 17:53:041518void RenderWidget::OnImeSetComposition(
1519 const string16& text,
1520 const std::vector<WebCompositionUnderline>& underlines,
1521 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281522 if (!webwidget_)
1523 return;
[email protected]d4cff272011-05-02 15:46:011524 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041525 text, WebVector<WebCompositionUnderline>(underlines),
1526 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011527 // Setting the IME composition was successful. Send the new composition
1528 // range to the browser.
1529 ui::Range range(ui::Range::InvalidRange());
1530 size_t location, length;
1531 if (webwidget_->compositionRange(&location, &length)) {
1532 range.set_start(location);
1533 range.set_end(location + length);
1534 }
1535 // The IME was cancelled via the Esc key, so just send back the caret.
1536 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1537 range.set_start(location);
1538 range.set_end(location + length);
1539 }
[email protected]58b48a0d2012-06-13 07:01:351540 std::vector<gfx::Rect> character_bounds;
1541 GetCompositionCharacterBounds(&character_bounds);
1542 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011543 } else {
[email protected]fa7b1dc2010-06-23 17:53:041544 // If we failed to set the composition text, then we need to let the browser
1545 // process to cancel the input method's ongoing composition session, to make
1546 // sure we are in a consistent state.
1547 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011548
1549 // Send an updated IME range with just the caret range.
1550 ui::Range range(ui::Range::InvalidRange());
1551 size_t location, length;
1552 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1553 range.set_start(location);
1554 range.set_end(location + length);
1555 }
[email protected]58b48a0d2012-06-13 07:01:351556 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261557 }
[email protected]fa7b1dc2010-06-23 17:53:041558}
1559
[email protected]4de6d1692011-10-12 08:45:441560void RenderWidget::OnImeConfirmComposition(
1561 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041562 if (!webwidget_)
1563 return;
1564
1565 handling_input_event_ = true;
1566 webwidget_->confirmComposition(text);
1567 handling_input_event_ = false;
1568
[email protected]d4cff272011-05-02 15:46:011569 // Send an updated IME range with just the caret range.
1570 ui::Range range(ui::Range::InvalidRange());
1571 size_t location, length;
1572 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1573 range.set_start(location);
1574 range.set_end(location + length);
1575 }
[email protected]58b48a0d2012-06-13 07:01:351576 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291577}
1578
[email protected]948f7ab72010-05-28 23:48:081579// This message causes the renderer to render an image of the
1580// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251581void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1582 int tag,
1583 const gfx::Size& page_size,
1584 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001585 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1586 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251587 // Close our unused handle.
1588#if defined(OS_WIN)
1589 ::CloseHandle(dib_handle);
1590#elif defined(OS_MACOSX)
1591 base::SharedMemory::CloseHandle(dib_handle);
1592#endif
1593 }
[email protected]d65adb12010-04-28 17:26:491594 return;
[email protected]45c6aad32010-11-11 04:46:251595 }
[email protected]d65adb12010-04-28 17:26:491596
[email protected]948f7ab72010-05-28 23:48:081597 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491598 // If one of these is empty, then we just return the dib we were
1599 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091600 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491601 return;
1602 }
1603
1604 // Map the given DIB ID into this process, and unmap it at the end
1605 // of this function.
[email protected]45c6aad32010-11-11 04:46:251606 scoped_ptr<TransportDIB> paint_at_size_buffer(
1607 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301608
[email protected]4b01b962012-10-09 23:17:351609 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281610 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351611 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281612 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511613 gfx::Size canvas_size = page_size_in_pixel;
1614 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491615 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511616 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491617 static_cast<float>(canvas_size.height());
1618
[email protected]ee8d6fd2010-05-26 17:05:481619 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491620 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1621 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481622 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491623
[email protected]36808ad2010-10-20 19:18:301624 scoped_ptr<skia::PlatformCanvas> canvas(
1625 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1626 canvas_size.height()));
1627 if (!canvas.get()) {
1628 NOTREACHED();
1629 return;
1630 }
1631
[email protected]d65adb12010-04-28 17:26:491632 // Reset bounds to what we actually received, but they should be the
1633 // same.
1634 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1635 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1636 bounds.set_width(canvas->getDevice()->width());
1637 bounds.set_height(canvas->getDevice()->height());
1638
1639 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081640 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491641 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1642
[email protected]948f7ab72010-05-28 23:48:081643 // Have to make sure we're laid out at the right size before
1644 // rendering.
1645 gfx::Size old_size = webwidget_->size();
1646 webwidget_->resize(page_size);
1647 webwidget_->layout();
1648
[email protected]d65adb12010-04-28 17:26:491649 // Paint the entire thing (using original bounds, not scaled bounds).
1650 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1651 canvas->restore();
1652
[email protected]948f7ab72010-05-28 23:48:081653 // Return the widget to its previous size.
1654 webwidget_->resize(old_size);
1655
[email protected]c88c9442010-07-19 18:55:091656 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491657}
1658
[email protected]3d9ec5052013-01-02 22:05:251659void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121660 // During shutdown we can just ignore this message.
1661 if (!webwidget_)
1662 return;
1663
1664 set_next_paint_is_repaint_ack();
[email protected]b89c90762013-01-06 20:29:301665 if (is_accelerated_compositing_active_) {
[email protected]b774a882013-01-11 06:13:531666 webwidget_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461667 scheduleComposite();
1668 } else {
1669 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1670 didInvalidateRect(repaint_rect);
1671 }
[email protected]ec7dc112008-08-06 05:30:121672}
1673
[email protected]3d9ec5052013-01-02 22:05:251674void RenderWidget::OnSmoothScrollCompleted(int gesture_id) {
[email protected]0e241b4b2012-08-18 09:06:271675 PendingSmoothScrollGestureMap::iterator it =
1676 pending_smooth_scroll_gestures_.find(gesture_id);
1677 DCHECK(it != pending_smooth_scroll_gestures_.end());
1678 it->second.Run();
1679 pending_smooth_scroll_gestures_.erase(it);
1680}
1681
[email protected]4873c7d2009-07-16 06:36:281682void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111683 if (!webwidget_)
1684 return;
[email protected]4873c7d2009-07-16 06:36:281685 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111686}
1687
[email protected]6131a642012-06-15 23:26:531688void RenderWidget::OnScreenInfoChanged(
1689 const WebKit::WebScreenInfo& screen_info) {
1690 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191691 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531692}
1693
[email protected]80ad8622012-11-07 16:33:031694void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1695 const gfx::Rect& window_screen_rect) {
1696 view_screen_rect_ = view_screen_rect;
1697 window_screen_rect_ = window_screen_rect;
1698 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1699}
1700
[email protected]468ac582012-11-20 00:53:191701void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1702 if (device_scale_factor_ == device_scale_factor)
1703 return;
1704
1705 device_scale_factor_ = device_scale_factor;
1706
1707 if (!is_accelerated_compositing_active_) {
1708 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1709 } else {
1710 scheduleComposite();
1711 }
1712}
1713
[email protected]719b36f2010-12-22 20:36:461714webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151715 const gfx::Rect& paint_bounds,
1716 TransportDIB** dib,
1717 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201718 gfx::Rect* clip,
1719 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461720 // Bare RenderWidgets don't support optimized plugin painting.
1721 return NULL;
[email protected]ca4847f2010-09-24 05:39:151722}
1723
[email protected]ceb36f7d2012-10-31 18:33:241724gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521725 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241726 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521727}
1728
[email protected]bee16aab2009-08-26 15:55:031729void RenderWidget::SetHidden(bool hidden) {
1730 if (is_hidden_ == hidden)
1731 return;
1732
1733 // The status has changed. Tell the RenderThread about it.
1734 is_hidden_ = hidden;
1735 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271736 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031737 else
[email protected]380244092011-10-07 17:26:271738 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031739}
1740
[email protected]2b624c562011-10-27 22:58:261741void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261742 if (!webwidget_)
1743 return;
1744
1745 if (is_fullscreen_) {
1746 webwidget_->willExitFullScreen();
1747 } else {
1748 webwidget_->willEnterFullScreen();
1749 }
[email protected]2b624c562011-10-27 22:58:261750}
1751
1752void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261753 if (!webwidget_)
1754 return;
1755
1756 if (is_fullscreen_) {
1757 webwidget_->didEnterFullScreen();
1758 } else {
1759 webwidget_->didExitFullScreen();
1760 }
[email protected]2b624c562011-10-27 22:58:261761}
1762
[email protected]699ab0d2009-04-23 23:19:141763void RenderWidget::SetBackground(const SkBitmap& background) {
1764 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461765
[email protected]699ab0d2009-04-23 23:19:141766 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281767 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141768}
1769
[email protected]674741932009-02-04 23:44:461770bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051771 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461772}
1773
1774bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051775 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461776}
1777
1778void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051779 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461780}
1781
1782void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051783 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461784}
1785
1786void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051787 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461788}
1789
[email protected]b18583c2012-12-18 06:55:271790static bool IsDateTimeInput(ui::TextInputType type) {
1791 return type == ui::TEXT_INPUT_TYPE_DATE ||
1792 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1793 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1794 type == ui::TEXT_INPUT_TYPE_MONTH ||
1795 type == ui::TEXT_INPUT_TYPE_TIME ||
1796 type == ui::TEXT_INPUT_TYPE_WEEK;
1797}
1798
1799
[email protected]3306f262012-09-21 19:20:421800void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
1801 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1802 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291803 return;
[email protected]ad26ef42011-06-17 07:59:451804 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271805 if (IsDateTimeInput(new_type))
1806 return; // Not considered as a text input field in WebKit/Chromium.
1807
[email protected]5b739cb2012-08-21 20:35:211808 WebKit::WebTextInputInfo new_info;
1809 if (webwidget_)
1810 new_info = webwidget_->textInputInfo();
1811
[email protected]ad26ef42011-06-17 07:59:451812 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211813
[email protected]3306f262012-09-21 19:20:421814 // Only sends text input params if they are changed or if the ime should be
1815 // shown.
1816 if (show_ime_if_needed || (text_input_type_ != new_type
1817 || text_input_info_ != new_info
1818 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:211819 ViewHostMsg_TextInputState_Params p;
1820 p.type = new_type;
1821 p.value = new_info.value.utf8();
1822 p.selection_start = new_info.selectionStart;
1823 p.selection_end = new_info.selectionEnd;
1824 p.composition_start = new_info.compositionStart;
1825 p.composition_end = new_info.compositionEnd;
1826 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:421827 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:211828 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1829
1830 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041831 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451832 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:291833 }
initial.commit09911bf2008-07-26 23:55:291834}
1835
[email protected]3f783362011-10-21 22:40:501836void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1837 WebRect start_webrect;
1838 WebRect end_webrect;
1839 webwidget_->selectionBounds(start_webrect, end_webrect);
1840 *start = start_webrect;
1841 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321842}
1843
[email protected]e99ef6f2011-10-16 01:13:001844void RenderWidget::UpdateSelectionBounds() {
1845 if (!webwidget_)
1846 return;
1847
[email protected]3f783362011-10-21 22:40:501848 gfx::Rect start_rect;
1849 gfx::Rect end_rect;
1850 GetSelectionBounds(&start_rect, &end_rect);
[email protected]58b48a0d2012-06-13 07:01:351851 if (selection_start_rect_ != start_rect || selection_end_rect_ != end_rect) {
1852 selection_start_rect_ = start_rect;
1853 selection_end_rect_ = end_rect;
[email protected]b556c2e2012-08-10 22:18:271854 WebTextDirection start_dir = WebKit::WebTextDirectionLeftToRight;
1855 WebTextDirection end_dir = WebKit::WebTextDirectionLeftToRight;
1856 webwidget_->selectionTextDirection(start_dir, end_dir);
1857 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_,
1858 selection_start_rect_, start_dir, selection_end_rect_, end_dir));
[email protected]58b48a0d2012-06-13 07:01:351859 }
[email protected]e99ef6f2011-10-16 01:13:001860
[email protected]58b48a0d2012-06-13 07:01:351861 std::vector<gfx::Rect> character_bounds;
1862 GetCompositionCharacterBounds(&character_bounds);
1863 UpdateCompositionInfo(composition_range_, character_bounds);
1864}
1865
1866bool RenderWidget::ShouldUpdateCompositionInfo(
1867 const ui::Range& range,
1868 const std::vector<gfx::Rect>& bounds) {
1869 if (composition_range_ != range)
1870 return true;
1871 if (bounds.size() != composition_character_bounds_.size())
1872 return true;
1873 for (size_t i = 0; i < bounds.size(); ++i) {
1874 if (bounds[i] != composition_character_bounds_[i])
1875 return true;
1876 }
1877 return false;
[email protected]e99ef6f2011-10-16 01:13:001878}
1879
[email protected]73bf95812011-10-12 11:38:321880// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451881COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1882 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1883COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1884 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1885COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1886 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181887COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1888 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1889COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1890 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1891COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1892 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1893COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1894 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1895COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1896 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:001897COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
1898 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
1899COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
1900 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
1901COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
1902 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
1903COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
1904 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
1905COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
1906 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
1907COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
1908 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:011909COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
1910 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
1911COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
1912 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451913
[email protected]5b739cb2012-08-21 20:35:211914ui::TextInputType RenderWidget::WebKitToUiTextInputType(
1915 WebKit::WebTextInputType type) {
1916 // Check the type is in the range representable by ui::TextInputType.
1917 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
1918 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1919 return static_cast<ui::TextInputType>(type);
1920}
1921
[email protected]ad26ef42011-06-17 07:59:451922ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:271923 if (webwidget_)
1924 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:451925 return ui::TEXT_INPUT_TYPE_NONE;
1926}
1927
[email protected]58b48a0d2012-06-13 07:01:351928void RenderWidget::GetCompositionCharacterBounds(
1929 std::vector<gfx::Rect>* bounds) {
1930 DCHECK(bounds);
1931 bounds->clear();
1932}
1933
[email protected]ad26ef42011-06-17 07:59:451934bool RenderWidget::CanComposeInline() {
1935 return true;
[email protected]56ea1a62011-05-30 07:05:571936}
1937
[email protected]4873c7d2009-07-16 06:36:281938WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041939 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281940}
1941
[email protected]f660d9c2012-06-06 18:31:211942float RenderWidget::deviceScaleFactor() {
1943 return device_scale_factor_;
1944}
1945
[email protected]fa7b1dc2010-06-23 17:53:041946void RenderWidget::resetInputMethod() {
1947 if (!input_method_is_active_)
1948 return;
1949
1950 // If the last text input type is not None, then we should finish any
1951 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451952 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041953 // If a composition text exists, then we need to let the browser process
1954 // to cancel the input method's ongoing composition session.
1955 if (webwidget_->confirmComposition())
1956 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1957 }
[email protected]d4cff272011-05-02 15:46:011958
1959 // Send an updated IME range with the current caret rect.
1960 ui::Range range(ui::Range::InvalidRange());
1961 size_t location, length;
1962 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1963 range.set_start(location);
1964 range.set_end(location + length);
1965 }
[email protected]58b48a0d2012-06-13 07:01:351966
1967 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:041968}
1969
[email protected]f103ab72009-09-02 17:10:591970void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:501971 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:291972 size_t i = 0;
1973 for (; i < plugin_window_moves_.size(); ++i) {
1974 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:581975 if (move.rects_valid) {
1976 plugin_window_moves_[i] = move;
1977 } else {
1978 plugin_window_moves_[i].visible = move.visible;
1979 }
initial.commit09911bf2008-07-26 23:55:291980 break;
1981 }
1982 }
1983
1984 if (i == plugin_window_moves_.size())
1985 plugin_window_moves_.push_back(move);
1986}
[email protected]268654772009-08-06 23:02:041987
1988void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
1989 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
1990 i != plugin_window_moves_.end(); ++i) {
1991 if (i->window == window) {
1992 plugin_window_moves_.erase(i);
1993 break;
1994 }
1995 }
1996}
[email protected]67bfb83f2011-09-22 03:36:371997
[email protected]b63d58d2012-11-26 22:37:441998void RenderWidget::GetRenderingStats(
1999 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]b774a882013-01-11 06:13:532000 webwidget()->renderingStats(stats);
[email protected]b63d58d2012-11-26 22:37:442001
2002 stats.rendering_stats.numAnimationFrames +=
2003 software_stats_.numAnimationFrames;
2004 stats.rendering_stats.numFramesSentToScreen +=
2005 software_stats_.numFramesSentToScreen;
2006 stats.rendering_stats.totalPaintTimeInSeconds +=
2007 software_stats_.totalPaintTimeInSeconds;
2008 stats.rendering_stats.totalPixelsPainted +=
2009 software_stats_.totalPixelsPainted;
2010 stats.rendering_stats.totalRasterizeTimeInSeconds +=
[email protected]63ab54262012-11-09 15:58:452011 software_stats_.totalRasterizeTimeInSeconds;
[email protected]b63d58d2012-11-26 22:37:442012 stats.rendering_stats.totalPixelsRasterized +=
2013 software_stats_.totalPixelsRasterized;
[email protected]fef5e3972012-08-07 03:59:472014}
2015
[email protected]e9ff79c2012-10-19 21:31:262016bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522017 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2018 if (!gpu_channel)
2019 return false;
2020
2021 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2022}
2023
[email protected]0e241b4b2012-08-18 09:06:272024void RenderWidget::BeginSmoothScroll(
2025 bool down,
[email protected]ebd8b562012-10-09 14:44:292026 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192027 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292028 int mouse_event_x,
2029 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272030 DCHECK(!callback.is_null());
2031 int id = next_smooth_scroll_gesture_id_++;
[email protected]267909d2012-10-20 04:36:192032
2033 ViewHostMsg_BeginSmoothScroll_Params params;
2034 params.scroll_down = down;
2035 params.pixels_to_scroll = pixels_to_scroll;
2036 params.mouse_event_x = mouse_event_x;
2037 params.mouse_event_y = mouse_event_y;
2038
2039 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, params));
[email protected]0e241b4b2012-08-18 09:06:272040 pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback));
[email protected]a39ca1652012-07-13 21:30:582041}
2042
[email protected]67bfb83f2011-09-22 03:36:372043bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2044 return false;
2045}
[email protected]c3d45532011-10-07 19:20:402046
[email protected]41d86852012-11-07 12:23:242047bool RenderWidget::WillHandleGestureEvent(
2048 const WebKit::WebGestureEvent& event) {
2049 return false;
2050}
2051
[email protected]c3d45532011-10-07 19:20:402052bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
2053 return false;
2054}
[email protected]e9ff79c2012-10-19 21:31:262055
[email protected]3d5c243b2012-11-30 00:26:012056bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2057 return true;
2058}
2059
[email protected]e9ff79c2012-10-19 21:31:262060} // namespace content