blob: 0bf203c9bd076c66c8448a272f7583105ce38d5e [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]8926c602013-01-23 05:32:0617#include "cc/layer_tree_host.h"
18#include "cc/thread.h"
19#include "cc/thread_impl.h"
[email protected]992db4c2011-05-12 15:37:1520#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5021#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2922#include "content/public/common/content_switches.h"
[email protected]8926c602013-01-23 05:32:0623#include "content/renderer/gpu/compositor_thread.h"
[email protected]8704f89b2011-04-15 00:30:0524#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4425#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1926#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1827#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4828#include "skia/ext/platform_canvas.h"
[email protected]debc8e52013-01-15 03:43:1229#include "third_party/WebKit/Source/Platform/chromium/public/WebPoint.h"
30#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
31#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
32#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
[email protected]8bd0fe62011-01-17 06:44:3733#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]4b1146bc2012-07-10 18:46:0334#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]a7547fb2012-03-08 04:43:4435#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3736#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
37#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0138#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3739#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4140#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1341#include "ui/base/ui_base_switches.h"
[email protected]a25e25b2012-09-28 14:32:3742#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3543#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4844#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2745#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4146#include "ui/surface/transport_dib.h"
[email protected]b63d58d2012-11-26 22:37:4447#include "webkit/compositor_bindings/web_rendering_stats_impl.h"
[email protected]8c89e7792009-08-19 21:18:3448#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5049#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4650#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4851
52#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4953#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5254#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4155#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4856#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4457
[email protected]8bd0fe62011-01-17 06:44:3758#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2959
[email protected]fa7b1dc2010-06-23 17:53:0460using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3061using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2462using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2263using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0664using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2865using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4466using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0067using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2868using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5969using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1870using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0171using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5272using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1973using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5274using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2875using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2476using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0477using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1878using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2679
[email protected]6a4d7f62013-01-07 21:32:1380namespace {
81const char* GetEventName(WebInputEvent::Type type) {
82#define CASE_TYPE(t) case WebInputEvent::t: return #t
83 switch(type) {
84 CASE_TYPE(Undefined);
85 CASE_TYPE(MouseDown);
86 CASE_TYPE(MouseUp);
87 CASE_TYPE(MouseMove);
88 CASE_TYPE(MouseEnter);
89 CASE_TYPE(MouseLeave);
90 CASE_TYPE(ContextMenu);
91 CASE_TYPE(MouseWheel);
92 CASE_TYPE(RawKeyDown);
93 CASE_TYPE(KeyDown);
94 CASE_TYPE(KeyUp);
95 CASE_TYPE(Char);
96 CASE_TYPE(GestureScrollBegin);
97 CASE_TYPE(GestureScrollEnd);
98 CASE_TYPE(GestureScrollUpdate);
99 CASE_TYPE(GestureFlingStart);
100 CASE_TYPE(GestureFlingCancel);
101 CASE_TYPE(GestureTap);
102 CASE_TYPE(GestureTapDown);
103 CASE_TYPE(GestureTapCancel);
104 CASE_TYPE(GestureDoubleTap);
105 CASE_TYPE(GestureTwoFingerTap);
106 CASE_TYPE(GestureLongPress);
107 CASE_TYPE(GestureLongTap);
108 CASE_TYPE(GesturePinchBegin);
109 CASE_TYPE(GesturePinchEnd);
110 CASE_TYPE(GesturePinchUpdate);
111 CASE_TYPE(TouchStart);
112 CASE_TYPE(TouchMove);
113 CASE_TYPE(TouchEnd);
114 CASE_TYPE(TouchCancel);
[email protected]3ec08ed2013-01-11 15:59:57115 default:
116 // Must include default to let WebKit::WebInputEvent add new event types
117 // before they're added here.
118 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
119 break;
[email protected]6a4d7f62013-01-07 21:32:13120 }
121#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57122 return "";
[email protected]6a4d7f62013-01-07 21:32:13123}
124}
[email protected]e9ff79c2012-10-19 21:31:26125namespace content {
[email protected]62cb33cae2009-03-27 23:30:22126
[email protected]6fd35b72012-03-01 19:46:41127RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04128 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44129 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29130 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56131 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11132 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29133 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30134 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35135 current_paint_buf_(NULL),
initial.commit09911bf2008-07-26 23:55:29136 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06137 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05138 update_reply_pending_(false),
[email protected]ea3ee0a2012-05-15 03:43:09139 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24140 using_asynchronous_swapbuffers_(false),
141 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29142 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29143 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09144 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29145 needs_repainting_on_restore_(false),
146 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49147 handling_input_event_(false),
[email protected]661eb9d2009-02-03 02:11:48148 closing_(false),
[email protected]14392a52012-05-02 20:28:44149 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04150 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45151 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
152 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12153 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48154 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12155 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50156 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21157 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07158 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04159 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52160 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27161 throttle_input_events_(true),
[email protected]cb6430932012-10-31 00:53:36162 next_smooth_scroll_gesture_id_(0),
163 is_threaded_compositing_enabled_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05164 if (!swapped_out)
165 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27166 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18167 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
168 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36169 is_threaded_compositing_enabled_ =
170 CommandLine::ForCurrentProcess()->HasSwitch(
171 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29172}
173
174RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11175 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21176 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35177 if (current_paint_buf_) {
178 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
179 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29180 }
[email protected]992db4c2011-05-12 15:37:15181 // If we are swapped out, we have released already.
182 if (!is_swapped_out_)
183 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29184}
185
[email protected]484955942010-08-19 16:13:18186// static
[email protected]8085dbc82008-09-26 22:53:44187RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04188 WebKit::WebPopupType popup_type,
189 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29190 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41191 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04192 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29193 if (widget->Init(opener_id)) { // adds reference on success.
194 return widget;
195 }
196 return NULL;
initial.commit09911bf2008-07-26 23:55:29197}
198
[email protected]484955942010-08-19 16:13:18199// static
200WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
201 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03202 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18203 break;
204 case WebKit::WebPopupTypeSelect:
205 case WebKit::WebPopupTypeSuggestion:
206 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44207 case WebKit::WebPopupTypePage:
208 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03209 case WebKit::WebPopupTypeHelperPlugin:
210 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18211 default:
212 NOTREACHED();
213 }
214 return NULL;
215}
216
[email protected]a635f942012-12-07 10:34:29217bool RenderWidget::Init(int32 opener_id) {
218 return DoInit(opener_id,
219 RenderWidget::CreateWebWidget(this),
220 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
221 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18222}
223
[email protected]a635f942012-12-07 10:34:29224bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06225 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18226 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29227 DCHECK(!webwidget_);
228
229 if (opener_id != MSG_ROUTING_NONE)
230 opener_id_ = opener_id;
231
[email protected]484955942010-08-19 16:13:18232 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29233
[email protected]380244092011-10-07 17:26:27234 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29235 if (result) {
[email protected]380244092011-10-07 17:26:27236 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29237 // Take a reference on behalf of the RenderThread. This will be balanced
238 // when we receive ViewMsg_Close.
239 AddRef();
[email protected]a635f942012-12-07 10:34:29240 return true;
initial.commit09911bf2008-07-26 23:55:29241 } else {
[email protected]a635f942012-12-07 10:34:29242 // The above Send can fail when the tab is closing.
243 return false;
initial.commit09911bf2008-07-26 23:55:29244 }
245}
246
[email protected]fc4404d2012-11-07 19:53:30247// This is used to complete pending inits and non-pending inits.
248void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29249 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29250
[email protected]fc4404d2012-11-07 19:53:30251 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42252
[email protected]8926c602013-01-23 05:32:06253 if (webwidget_ && is_threaded_compositing_enabled_) {
254 webwidget_->enterForceCompositingMode(true);
255 }
256 if (web_layer_tree_view_) {
257 web_layer_tree_view_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09258 }
[email protected]05a980d7a2012-02-07 22:16:42259 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29260
[email protected]6de74452009-02-25 18:04:59261 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29262}
263
[email protected]992db4c2011-05-12 15:37:15264void RenderWidget::SetSwappedOut(bool is_swapped_out) {
265 // We should only toggle between states.
266 DCHECK(is_swapped_out_ != is_swapped_out);
267 is_swapped_out_ = is_swapped_out;
268
269 // If we are swapping out, we will call ReleaseProcess, allowing the process
270 // to exit if all of its RenderViews are swapped out. We wait until the
271 // WasSwappedOut call to do this, to avoid showing the sad tab.
272 // If we are swapping in, we call AddRefProcess to prevent the process from
273 // exiting.
274 if (!is_swapped_out)
275 RenderProcess::current()->AddRefProcess();
276}
277
[email protected]a95986a82010-12-24 06:19:28278bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
279 bool handled = true;
280 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
281 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
282 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
283 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54284 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28285 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41286 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15287 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28288 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]a7266a92012-06-28 02:11:08289 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK, OnSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28290 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
291 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
292 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
293 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
294 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
295 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25296 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
297 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
298 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28299 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
300 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53301 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03302 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]a95986a82010-12-24 06:19:28303 IPC_MESSAGE_UNHANDLED(handled = false)
304 IPC_END_MESSAGE_MAP()
305 return handled;
306}
initial.commit09911bf2008-07-26 23:55:29307
308bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15309 // Don't send any messages after the browser has told us to close, and filter
310 // most outgoing messages while swapped out.
311 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26312 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11313 closing_) {
initial.commit09911bf2008-07-26 23:55:29314 delete message;
315 return false;
316 }
317
318 // If given a messsage without a routing ID, then assign our routing ID.
319 if (message->routing_id() == MSG_ROUTING_NONE)
320 message->set_routing_id(routing_id_);
321
[email protected]380244092011-10-07 17:26:27322 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44323}
324
[email protected]61e2b3cc2012-03-02 16:13:34325void RenderWidget::Resize(const gfx::Size& new_size,
326 const gfx::Rect& resizer_rect,
327 bool is_fullscreen,
328 ResizeAck resize_ack) {
329 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
330 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
331 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29332
[email protected]61e2b3cc2012-03-02 16:13:34333 // Ignore this during shutdown.
334 if (!webwidget_)
335 return;
336
337 // Remember the rect where the resize corner will be drawn.
338 resizer_rect_ = resizer_rect;
339
340 // NOTE: We may have entered fullscreen mode without changing our size.
341 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
342 if (fullscreen_change)
343 WillToggleFullscreen();
344 is_fullscreen_ = is_fullscreen;
345
346 if (size_ != new_size) {
347 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34348 needs_repainting_on_restore_ = false;
349
350 size_ = new_size;
351
352 paint_aggregator_.ClearPendingUpdate();
353
354 // When resizing, we want to wait to paint before ACK'ing the resize. This
355 // ensures that we only resize as fast as we can paint. We only need to
356 // send an ACK if we are resized to a non-empty rect.
357 webwidget_->resize(new_size);
358 if (!new_size.IsEmpty()) {
359 if (!is_accelerated_compositing_active_) {
360 // Resize should have caused an invalidation of the entire view.
361 DCHECK(paint_aggregator_.HasPendingUpdate());
362 }
363
364 // Send the Resize_ACK flag once we paint again if requested.
365 if (resize_ack == SEND_RESIZE_ACK)
366 set_next_paint_is_resize_ack();
367 }
[email protected]ff475a322012-03-14 00:05:35368 } else {
369 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34370 }
371
372 if (fullscreen_change)
373 DidToggleFullscreen();
374
375 // If a resize ack is requested and it isn't set-up, then no more resizes will
376 // come in and in general things will go wrong.
377 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
378 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29379}
380
381void RenderWidget::OnClose() {
382 if (closing_)
383 return;
384 closing_ = true;
385
386 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03387 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27388 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03389 SetHidden(false);
390 }
initial.commit09911bf2008-07-26 23:55:29391
initial.commit09911bf2008-07-26 23:55:29392 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25393 // now. Post a task that only gets invoked when there are no nested message
394 // loops.
[email protected]32876ae2011-11-15 22:25:21395 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29396 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25397
398 // Balances the AddRef taken when we called AddRoute.
399 Release();
initial.commit09911bf2008-07-26 23:55:29400}
401
[email protected]61e2b3cc2012-03-02 16:13:34402// Got a response from the browser after the renderer decided to create a new
403// view.
[email protected]fc4404d2012-11-07 19:53:30404void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34405 DCHECK(routing_id_ != MSG_ROUTING_NONE);
406
[email protected]fc4404d2012-11-07 19:53:30407 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34408}
409
[email protected]f21c613a2009-02-12 14:46:17410void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:09411 const gfx::Rect& resizer_rect,
412 bool is_fullscreen) {
[email protected]61e2b3cc2012-03-02 16:13:34413 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29414}
415
[email protected]b5913d72012-02-07 22:26:54416void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
417 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59418 gfx::Rect view_rect(size_);
419
[email protected]ce112fe2012-10-29 22:52:18420 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59421 if (!old_damage_rect.IsEmpty())
422 paint_aggregator_.InvalidateRect(old_damage_rect);
423
[email protected]ce112fe2012-10-29 22:52:18424 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59425 if (!new_damage_rect.IsEmpty())
426 paint_aggregator_.InvalidateRect(new_damage_rect);
427
[email protected]b5913d72012-02-07 22:26:54428 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59429
[email protected]b5913d72012-02-07 22:26:54430 if (webwidget_)
431 webwidget_->didChangeWindowResizerRect();
432 }
433}
434
initial.commit09911bf2008-07-26 23:55:29435void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31436 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29437 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03438 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29439}
440
[email protected]9e2e4632012-07-27 16:38:41441void RenderWidget::OnWasShown(bool needs_repainting) {
442 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29443 // During shutdown we can just ignore this message.
444 if (!webwidget_)
445 return;
446
447 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03448 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29449
450 if (!needs_repainting && !needs_repainting_on_restore_)
451 return;
452 needs_repainting_on_restore_ = false;
453
[email protected]d65adb12010-04-28 17:26:49454 // Tag the next paint as a restore ack, which is picked up by
455 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29456 set_next_paint_is_restore_ack();
457
458 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56459 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46460 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
461 } else {
462 scheduleComposite();
463 }
initial.commit09911bf2008-07-26 23:55:29464}
465
[email protected]992db4c2011-05-12 15:37:15466void RenderWidget::OnWasSwappedOut() {
467 // If we have been swapped out and no one else is using this process,
468 // it's safe to exit now. If we get swapped back in, we will call
469 // AddRefProcess in SetSwappedOut.
470 if (is_swapped_out_)
471 RenderProcess::current()->ReleaseProcess();
472}
473
[email protected]53d3f302009-12-21 04:42:05474void RenderWidget::OnRequestMoveAck() {
475 DCHECK(pending_window_rect_count_);
476 pending_window_rect_count_--;
477}
478
479void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58480 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21481 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05482 update_reply_pending_ = false;
483
[email protected]b4d08452010-10-05 17:34:35484 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
485 // have no current paint buffer.
486 if (current_paint_buf_) {
487 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
488 current_paint_buf_ = NULL;
489 }
490
[email protected]65225772011-05-12 21:10:24491 // If swapbuffers is still pending, then defer the update until the
492 // swapbuffers occurs.
493 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
494 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
495 return;
496 }
497
[email protected]29ed96a2012-02-04 18:12:16498 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18499 if (!is_accelerated_compositing_active_) {
500 DidFlushPaint();
501 }
[email protected]a2f6bc112009-06-27 16:27:25502
initial.commit09911bf2008-07-26 23:55:29503 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24504 DoDeferredUpdateAndSendInputAck();
505}
506
[email protected]d0be63772011-12-20 23:18:04507bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]65225772011-05-12 21:10:24508 return false;
509}
510
[email protected]479b0172012-10-29 19:27:09511bool RenderWidget::ForceCompositingModeEnabled() {
512 return false;
513}
514
[email protected]d0be63772011-12-20 23:18:04515void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24516 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21517 while (!updates_pending_swap_.empty()) {
518 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
519 updates_pending_swap_.pop_front();
520 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
521 // compositing pass, hence doesn't require an UpdateRect message.
522 if (msg)
523 Send(msg);
524 }
[email protected]65225772011-05-12 21:10:24525 num_swapbuffers_complete_pending_ = 0;
526 using_asynchronous_swapbuffers_ = false;
527 // Schedule another frame so the compositor learns about it.
528 scheduleComposite();
529}
530
[email protected]37a6f302011-07-11 23:43:08531void RenderWidget::OnSwapBuffersPosted() {
532 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21533
534 if (using_asynchronous_swapbuffers_) {
535 ViewHostMsg_UpdateRect* msg = NULL;
536 // pending_update_params_ can be NULL if the swap doesn't correspond to an
537 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
538 // message.
539 if (pending_update_params_.get()) {
540 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
541 pending_update_params_.reset();
542 }
543 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08544 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21545 }
[email protected]37a6f302011-07-11 23:43:08546}
547
548void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24549 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16550
[email protected]404939f2012-06-01 04:06:18551 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16552 DidFlushPaint();
553
[email protected]65225772011-05-12 21:10:24554 // When compositing deactivates, we reset the swapbuffers pending count. The
555 // swapbuffers acks may still arrive, however.
556 if (num_swapbuffers_complete_pending_ == 0) {
557 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
558 return;
559 }
[email protected]aa4117f2011-12-09 22:19:21560 DCHECK(!updates_pending_swap_.empty());
561 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
562 updates_pending_swap_.pop_front();
563 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
564 // compositing pass, hence doesn't require an UpdateRect message.
565 if (msg)
566 Send(msg);
[email protected]65225772011-05-12 21:10:24567 num_swapbuffers_complete_pending_--;
568
569 // If update reply is still pending, then defer the update until that reply
570 // occurs.
[email protected]d0be63772011-12-20 23:18:04571 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24572 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
573 return;
574 }
575
576 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06577 // when we were previously rendering. However, if an invalidation task is not
578 // posted, there may be software rendering work pending. In that case, don't
579 // early out.
580 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24581 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
582 return;
583 }
584
[email protected]cc66e682012-10-02 06:48:18585 // Do not call DoDeferredUpdate unless there's animation work to be done or
586 // a real invalidation. This prevents rendering in response to a swapbuffers
587 // callback coming back after we've navigated away from the page that
588 // generated it.
589 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
590 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
591 return;
592 }
593
[email protected]65225772011-05-12 21:10:24594 // Continue painting if necessary...
595 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29596}
597
[email protected]0dea1652012-12-14 00:09:09598void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
599 bool is_keyboard_shortcut) {
[email protected]65225772011-05-12 21:10:24600 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
initial.commit09911bf2008-07-26 23:55:29601
[email protected]5dd768212009-08-13 23:34:49602 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09603 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49604 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29605 return;
[email protected]5dd768212009-08-13 23:34:49606 }
initial.commit09911bf2008-07-26 23:55:29607
[email protected]6a4d7f62013-01-07 21:32:13608 base::TimeDelta now = base::TimeDelta::FromInternalValue(
609 base::TimeTicks::Now().ToInternalValue());
610
611 int64 delta = static_cast<int64>(
612 (now.InSecondsF() - input_event->timeStampSeconds) *
613 base::Time::kMicrosecondsPerSecond);
614 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
615 std::string name_for_event =
616 base::StringPrintf("Event.Latency.Renderer.%s",
617 GetEventName(input_event->type));
[email protected]de415552013-01-23 04:12:17618 base::HistogramBase* counter_for_type =
[email protected]6a4d7f62013-01-07 21:32:13619 base::Histogram::FactoryTimeGet(
620 name_for_event,
621 base::TimeDelta::FromMilliseconds(0),
622 base::TimeDelta::FromMilliseconds(1000000),
623 100,
[email protected]de415552013-01-23 04:12:17624 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]6a4d7f62013-01-07 21:32:13625 counter_for_type->AddTime(base::TimeDelta::FromMicroseconds(delta));
626
[email protected]67bfb83f2011-09-22 03:36:37627 bool prevent_default = false;
628 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26629 const WebMouseEvent& mouse_event =
630 *static_cast<const WebMouseEvent*>(input_event);
631 TRACE_EVENT2("renderer", "HandleMouseMove",
632 "x", mouse_event.x, "y", mouse_event.y);
633 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37634 }
635
[email protected]41d86852012-11-07 12:23:24636 if (WebInputEvent::isGestureEventType(input_event->type)) {
637 const WebGestureEvent& gesture_event =
638 *static_cast<const WebGestureEvent*>(input_event);
639 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
640 }
641
[email protected]3ebcc7c2013-01-09 05:34:46642 if (input_event->type == WebInputEvent::GestureTap ||
643 input_event->type == WebInputEvent::GestureLongPress)
644 resetInputMethod();
645
[email protected]67bfb83f2011-09-22 03:36:37646 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12647 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
648 suppress_next_char_events_ = false;
649 if (!processed && webwidget_)
650 processed = webwidget_->handleInputEvent(*input_event);
651 }
652
653 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
654 // it's not processed by webkit, then we need to suppress the upcoming Char
655 // events.
656 if (!processed && is_keyboard_shortcut)
657 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29658
[email protected]3d5c243b2012-11-30 00:26:01659 InputEventAckState ack_result = processed ?
660 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
661 if (!processed && input_event->type == WebInputEvent::TouchStart) {
662 const WebTouchEvent& touch_event =
663 *static_cast<const WebTouchEvent*>(input_event);
664 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
665 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
666 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
667 }
668
[email protected]a9fb30aa2011-10-06 06:58:46669 IPC::Message* response =
670 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
[email protected]3d5c243b2012-11-30 00:26:01671 ack_result);
[email protected]3391a0772012-03-28 00:32:07672 bool event_type_gets_rate_limited =
673 input_event->type == WebInputEvent::MouseMove ||
674 input_event->type == WebInputEvent::MouseWheel ||
675 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06676
677 bool frame_pending = paint_aggregator_.HasPendingUpdate();
678 if (is_accelerated_compositing_active_) {
679 frame_pending = web_layer_tree_view_ &&
680 web_layer_tree_view_->commitRequested();
681 }
682
[email protected]3391a0772012-03-28 00:32:07683 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57684 throttle_input_events_ &&
[email protected]8926c602013-01-23 05:32:06685 frame_pending;
[email protected]e2824412009-02-27 01:57:05686
[email protected]f8868d72012-04-27 19:13:03687 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24688 // We want to rate limit the input events in this case, so we'll wait for
689 // painting to finish before ACKing this message.
[email protected]353a34c2010-05-28 23:35:17690 if (pending_input_event_ack_.get()) {
691 // As two different kinds of events could cause us to postpone an ack
692 // we send it now, if we have one pending. The Browser should never
693 // send us the same kind of event we are delaying the ack for.
694 Send(pending_input_event_ack_.release());
695 }
[email protected]12fbad812009-09-01 18:21:24696 pending_input_event_ack_.reset(response);
697 } else {
698 Send(response);
699 }
700
[email protected]3306f262012-09-21 19:20:42701#if defined(OS_ANDROID)
702 // Allow the IME to be shown when the focus changes as a consequence
703 // of a processed touch end event.
704 if (input_event->type == WebInputEvent::TouchEnd && processed)
705 UpdateTextInputState(SHOW_IME_IF_NEEDED);
706#endif
707
[email protected]5dd768212009-08-13 23:34:49708 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48709
[email protected]67bfb83f2011-09-22 03:36:37710 if (!prevent_default) {
711 if (WebInputEvent::isKeyboardEventType(input_event->type))
712 DidHandleKeyEvent();
713 if (WebInputEvent::isMouseEventType(input_event->type))
714 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24715 if (WebInputEvent::isTouchEventType(input_event->type))
716 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37717 }
initial.commit09911bf2008-07-26 23:55:29718}
719
720void RenderWidget::OnMouseCaptureLost() {
721 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28722 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29723}
724
725void RenderWidget::OnSetFocus(bool enable) {
726 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33727 if (webwidget_)
728 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29729}
730
731void RenderWidget::ClearFocus() {
732 // We may have got the focus from the browser before this gets processed, in
733 // which case we do not want to unfocus ourself.
734 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28735 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29736}
737
[email protected]2d5d09d52009-06-15 14:29:21738void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00739 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21740 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06741 TRACE_EVENT2("renderer", "PaintRect",
742 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45743
744 const bool kEnableGpuBenchmarking =
745 CommandLine::ForCurrentProcess()->HasSwitch(
746 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00747 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21748
749 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00750 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
751 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03752
[email protected]699ab0d2009-04-23 23:19:14753 // If there is a custom background, tile it.
754 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14755 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11756 skia::RefPtr<SkShader> shader = skia::AdoptRef(
757 SkShader::CreateBitmapShader(background_,
758 SkShader::kRepeat_TileMode,
759 SkShader::kRepeat_TileMode));
760 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20761
762 // Use kSrc_Mode to handle background_ transparency properly.
763 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
764
765 // Canvas could contain multiple update rects. Clip to given rect so that
766 // we don't accidentally clear other update rects.
767 canvas->save();
[email protected]1835b9e2012-02-28 13:12:48768 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14769 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20770 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14771 }
772
[email protected]719b36f2010-12-22 20:36:46773 // First see if this rect is a plugin that can paint itself faster.
774 TransportDIB* optimized_dib = NULL;
775 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20776 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46777 webkit::ppapi::PluginInstance* optimized_instance =
778 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
779 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20780 &optimized_copy_rect,
781 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46782 if (optimized_instance) {
783 // This plugin can be optimize-painted and we can just ask it to paint
784 // itself. We don't actually need the TransportDIB in this case.
785 //
786 // This is an optimization for PPAPI plugins that know they're on top of
787 // the page content. If this rect is inside such a plugin, we can save some
788 // time and avoid re-rendering the page content which we know will be
789 // covered by the plugin later (this time can be significant, especially
790 // for a playing movie that is invalidating a lot).
791 //
792 // In the plugin movie case, hopefully the similar call to
793 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
794 // painting, because that avoids copying the plugin image to a different
795 // paint rect. Unfortunately, if anything on the page is animating other
796 // than the movie, it break this optimization since the union of the
797 // invalid regions will be larger than the plugin.
798 //
799 // This code optimizes that case, where we can still avoid painting in
800 // WebKit and filling the background (which can be slow) and just painting
801 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
802 // required.
[email protected]63ab54262012-11-09 15:58:45803 base::TimeTicks paint_begin_ticks;
804 if (kEnableGpuBenchmarking)
805 paint_begin_ticks = base::TimeTicks::HighResNow();
806
[email protected]df59dd42012-09-14 22:56:30807 SkAutoCanvasRestore auto_restore(canvas, true);
808 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46809 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27810 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21811 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45812 if (kEnableGpuBenchmarking) {
813 base::TimeDelta paint_time =
814 base::TimeTicks::HighResNow() - paint_begin_ticks;
815 if (!is_accelerated_compositing_active_)
[email protected]121cc752013-01-16 09:12:45816 software_stats_.totalPaintTime += paint_time;
[email protected]63ab54262012-11-09 15:58:45817 }
[email protected]719b36f2010-12-22 20:36:46818 } else {
819 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45820 base::TimeTicks paint_begin_ticks;
821 if (kEnableGpuBenchmarking)
822 paint_begin_ticks = base::TimeTicks::HighResNow();
823
[email protected]719b36f2010-12-22 20:36:46824 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45825
826 if (kEnableGpuBenchmarking) {
827 base::TimeDelta paint_time =
828 base::TimeTicks::HighResNow() - paint_begin_ticks;
829 if (!is_accelerated_compositing_active_)
[email protected]121cc752013-01-16 09:12:45830 software_stats_.totalPaintTime += paint_time;
[email protected]63ab54262012-11-09 15:58:45831 }
[email protected]719b36f2010-12-22 20:36:46832
833 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35834 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46835 }
initial.commit09911bf2008-07-26 23:55:29836
[email protected]4fb66842009-12-04 21:41:00837 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00838 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45839
840 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45841 int64 num_pixels_processed = rect.width() * rect.height();
842 software_stats_.totalPixelsPainted += num_pixels_processed;
843 software_stats_.totalPixelsRasterized += num_pixels_processed;
844 }
[email protected]4fb66842009-12-04 21:41:00845}
846
847void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
848 skia::PlatformCanvas* canvas) {
849 static bool kPaintBorder =
850 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
851 if (!kPaintBorder)
852 return;
853
[email protected]53d3f302009-12-21 04:42:05854 // Cycle through these colors to help distinguish new paint rects.
855 const SkColor colors[] = {
856 SkColorSetARGB(0x3F, 0xFF, 0, 0),
857 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
858 SkColorSetARGB(0x3F, 0, 0, 0xFF),
859 };
860 static int color_selector = 0;
861
[email protected]4fb66842009-12-04 21:41:00862 SkPaint paint;
863 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05864 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00865 paint.setStrokeWidth(1);
866
867 SkIRect irect;
868 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
869 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29870}
871
[email protected]52ccd0ea2011-02-16 01:09:05872void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30873 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30874 if (!animation_update_pending_) {
875 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59876 return;
[email protected]921244e42011-07-20 16:36:30877 }
[email protected]bd37ae252011-06-03 01:28:18878 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59879 // Record when we fired (according to base::Time::Now()) relative to when
880 // we posted the task to quantify how much the base::Time/base::TimeTicks
881 // skew is affecting animations.
882 base::TimeDelta animation_callback_delay = base::Time::Now() -
883 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
884 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
885 animation_callback_delay,
886 base::TimeDelta::FromMilliseconds(0),
887 base::TimeDelta::FromMilliseconds(30),
888 25);
889 }
[email protected]65225772011-05-12 21:10:24890 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24891}
892
[email protected]52ccd0ea2011-02-16 01:09:05893void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59894 if (!animation_update_pending_)
895 return;
[email protected]bd37ae252011-06-03 01:28:18896
897 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33898 base::TimeDelta animationInterval = IsRenderingVSynced() ?
899 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18900
[email protected]7c4329e2011-02-18 22:02:59901 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45902
903 // animation_floor_time_ is the earliest time that we should animate when
904 // using the dead reckoning software scheduler. If we're using swapbuffers
905 // complete callbacks to rate limit, we can ignore this floor.
906 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30907 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33908 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18909 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59910 // running animation callbacks so that if a callback requests another
911 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38912 animation_timer_.Stop();
913 animation_timer_.Start(FROM_HERE, animationInterval, this,
914 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59915 animation_update_pending_ = false;
[email protected]8926c602013-01-23 05:32:06916 if (is_accelerated_compositing_active_ && web_layer_tree_view_) {
917 web_layer_tree_view_->layer_tree_host()->updateAnimations(
918 base::TimeTicks::Now());
919 } else {
920 webwidget_->animate(0.0);
921 }
[email protected]7c4329e2011-02-18 22:02:59922 return;
[email protected]5f8b1022011-01-21 23:34:50923 }
[email protected]bd37ae252011-06-03 01:28:18924 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:38925 if (!animation_timer_.IsRunning()) {
926 // This code uses base::Time::Now() to calculate the floor and next fire
927 // time because javascript's Date object uses base::Time::Now(). The
928 // message loop uses base::TimeTicks, which on windows can have a
929 // different granularity than base::Time.
930 // The upshot of all this is that this function might be called before
931 // base::Time::Now() has advanced past the animation_floor_time_. To
932 // avoid exposing this delay to javascript, we keep posting delayed
933 // tasks until base::Time::Now() has advanced far enough.
934 base::TimeDelta delay = animation_floor_time_ - now;
935 animation_timer_.Start(FROM_HERE, delay, this,
936 &RenderWidget::AnimationCallback);
937 }
[email protected]5f8b1022011-01-21 23:34:50938}
939
[email protected]bd37ae252011-06-03 01:28:18940bool RenderWidget::IsRenderingVSynced() {
941 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
942 // not caught by this check. This will lead to artificially low frame rates
943 // for people who force vsync off at a driver level and expect Chrome to speed
944 // up.
945 return !has_disable_gpu_vsync_switch_;
946}
947
[email protected]65225772011-05-12 21:10:24948void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:06949 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:24950 invalidation_task_posted_ = false;
951 DoDeferredUpdateAndSendInputAck();
952}
953
954void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:05955 DoDeferredUpdate();
956
957 if (pending_input_event_ack_.get())
958 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:21959}
960
[email protected]552e6002009-11-19 05:24:57961void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:58962 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:08963
[email protected]65225772011-05-12 21:10:24964 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:29965 return;
[email protected]05a980d7a2012-02-07 22:16:42966
[email protected]fc4404d2012-11-07 19:53:30967 if (!init_complete_) {
968 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:42969 return;
970 }
[email protected]aa4117f2011-12-09 22:19:21971 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24972 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
973 return;
974 }
[email protected]9ca84622011-06-02 23:46:39975 if (is_accelerated_compositing_active_ &&
976 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:24977 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
978 return;
979 }
initial.commit09911bf2008-07-26 23:55:29980
[email protected]552e6002009-11-19 05:24:57981 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:05982 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:57983 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:29984 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:24985 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:29986 return;
987 }
988
[email protected]05a980d7a2012-02-07 22:16:42989 if (is_accelerated_compositing_active_)
990 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
991
[email protected]0fb93f52011-05-18 23:13:56992 // Tracking of frame rate jitter
993 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]541dcd52012-03-15 15:57:51994 webwidget_->instrumentBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:05995 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:50996
[email protected]f98d7e3c2010-09-13 22:30:46997 // Layout may generate more invalidation. It may also enable the
998 // GPU acceleration, so make sure to run layout before we send the
999 // GpuRenderingActivated message.
1000 webwidget_->layout();
1001
[email protected]dcca3aa92012-02-17 23:03:371002 // The following two can result in further layout and possibly
1003 // enable GPU acceleration so they need to be called before any painting
1004 // is done.
[email protected]3306f262012-09-21 19:20:421005 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371006 UpdateSelectionBounds();
1007
[email protected]5f8b1022011-01-21 23:34:501008 // Suppress painting if nothing is dirty. This has to be done after updating
1009 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241010 if (!paint_aggregator_.HasPendingUpdate()) {
1011 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]541dcd52012-03-15 15:57:511012 webwidget_->instrumentCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501013 return;
[email protected]65225772011-05-12 21:10:241014 }
[email protected]5f8b1022011-01-21 23:34:501015
[email protected]479b0172012-10-29 19:27:091016 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361017 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091018 ForceCompositingModeEnabled()) {
1019 webwidget_->enterForceCompositingMode(true);
1020 }
1021
[email protected]872ae5b2011-05-26 20:20:501022 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561023 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041024 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561025 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1026 delay,
1027 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411028 base::TimeDelta::FromMilliseconds(120),
1029 60);
[email protected]d0be63772011-12-20 23:18:041030 } else {
[email protected]0fb93f52011-05-18 23:13:561031 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1032 delay,
1033 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411034 base::TimeDelta::FromMilliseconds(120),
1035 60);
[email protected]d0be63772011-12-20 23:18:041036 }
[email protected]872ae5b2011-05-26 20:20:501037
1038 // Calculate filtered time per frame:
1039 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1040 filtered_time_per_frame_ =
1041 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561042 }
1043 last_do_deferred_update_time_ = frame_begin_ticks;
1044
[email protected]fef5e3972012-08-07 03:59:471045 if (!is_accelerated_compositing_active_) {
1046 software_stats_.numAnimationFrames++;
1047 software_stats_.numFramesSentToScreen++;
1048 }
1049
[email protected]552e6002009-11-19 05:24:571050 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291051 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301052 PaintAggregator::PendingUpdate update;
1053 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291054
[email protected]53d3f302009-12-21 04:42:051055 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181056 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291057
[email protected]29ed96a2012-02-04 18:12:161058 // Notify derived classes that we're about to initiate a paint.
1059 WillInitiatePaint();
1060
[email protected]ca4847f2010-09-24 05:39:151061 // A plugin may be able to do an optimized paint. First check this, in which
1062 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461063 // This optimization allows PPAPI plugins that declare themselves on top of
1064 // the page (like a traditional windowed plugin) to be able to animate (think
1065 // movie playing) without repeatedly re-painting the page underneath, or
1066 // copying the plugin backing store (since we can send the plugin's backing
1067 // store directly to the browser).
1068 //
1069 // This optimization only works when the entire invalid region is contained
1070 // within the plugin. There is a related optimization in PaintRect for the
1071 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151072 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151073 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201074 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211075 DCHECK(!pending_update_params_.get());
1076 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551077 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211078 pending_update_params_->scroll_rect = update.scroll_rect;
1079 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211080 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1081 pending_update_params_->flags = next_paint_flags_;
1082 pending_update_params_->scroll_offset = GetScrollOffset();
1083 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091084 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211085 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091086 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211087
[email protected]ca4847f2010-09-24 05:39:151088 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561089 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151090 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201091 &optimized_copy_rect,
1092 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271093 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471094 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211095 pending_update_params_->bitmap = dib->id();
1096 pending_update_params_->bitmap_rect = optimized_copy_location;
1097 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201098 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561099 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461100 // Compute a buffer for painting and cache it.
[email protected]ce112fe2012-10-29 22:52:181101 gfx::Rect pixel_bounds = gfx::ToFlooredRectDeprecated(
1102 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]ca4847f2010-09-24 05:39:151103 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351104 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591105 pixel_bounds));
[email protected]f98d7e3c2010-09-13 22:30:461106 if (!canvas.get()) {
1107 NOTREACHED();
1108 return;
1109 }
[email protected]cef3362f2009-12-21 17:48:451110
[email protected]f98d7e3c2010-09-13 22:30:461111 // We may get back a smaller canvas than we asked for.
1112 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591113 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1114 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1115 pixel_bounds.set_width(canvas->getDevice()->width());
1116 pixel_bounds.set_height(canvas->getDevice()->height());
1117 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1118 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051119
[email protected]f98d7e3c2010-09-13 22:30:461120 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1121
[email protected]aa4117f2011-12-09 22:19:211122 pending_update_params_->bitmap = current_paint_buf_->id();
1123 pending_update_params_->bitmap_rect = bounds;
1124
1125 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461126 // The scroll damage is just another rectangle to paint and copy.
1127 copy_rects.swap(update.paint_rects);
1128 if (!scroll_damage.IsEmpty())
1129 copy_rects.push_back(scroll_damage);
1130
1131 for (size_t i = 0; i < copy_rects.size(); ++i)
[email protected]f1cccb32012-06-06 18:29:591132 PaintRect(copy_rects[i], pixel_bounds.origin(), canvas.get());
[email protected]60a50072012-01-11 02:05:351133
1134 // Software FPS tick for performance tests. The accelerated path traces the
1135 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1136 // NOTE: Tests may break if this event is renamed or moved.
1137 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW");
[email protected]f98d7e3c2010-09-13 22:30:461138 } else { // Accelerated compositing path
1139 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211140 // If painting is done via the gpu process then we don't set any damage
1141 // rects to save the browser process from doing unecessary work.
1142 pending_update_params_->bitmap_rect = bounds;
1143 pending_update_params_->scroll_rect = gfx::Rect();
1144 // We don't need an ack, because we're not sharing a DIB with the browser.
1145 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1146 // with the browser for the GPU surface.
1147 pending_update_params_->needs_ack = false;
[email protected]50bd6452010-11-27 19:39:421148 webwidget_->composite(false);
[email protected]f98d7e3c2010-09-13 22:30:461149 }
1150
[email protected]936c6f52011-12-13 01:35:261151 // If we're holding a pending input event ACK, send the ACK before sending the
1152 // UpdateReply message so we can receive another input event before the
1153 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1154 // the UpdateRect IPC message handler.
1155 if (pending_input_event_ack_.get())
1156 Send(pending_input_event_ack_.release());
1157
[email protected]aa4117f2011-12-09 22:19:211158 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
1159 // OnSwapBuffersPosted), meaning a message has been added to the
1160 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1161 // the message now.
1162 if (pending_update_params_.get()) {
1163 // sending an ack to browser process that the paint is complete...
1164 update_reply_pending_ = pending_update_params_->needs_ack;
1165 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1166 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341167 }
[email protected]53d3f302009-12-21 04:42:051168
[email protected]29ed96a2012-02-04 18:12:161169 // If we're software rendering then we're done initiating the paint.
1170 if (!is_accelerated_compositing_active_)
1171 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291172}
1173
1174///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461175// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291176
[email protected]4873c7d2009-07-16 06:36:281177void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091178 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1179 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571180 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481181 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181182 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571183 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291184 return;
1185
[email protected]552e6002009-11-19 05:24:571186 paint_aggregator_.InvalidateRect(damaged_rect);
1187
1188 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241189 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571190 return;
1191 if (!paint_aggregator_.HasPendingUpdate())
1192 return;
[email protected]aa4117f2011-12-09 22:19:211193 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241194 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1195 return;
1196
1197 // When GPU rendering, combine pending animations and invalidations into
1198 // a single update.
[email protected]816edc62012-03-17 01:27:221199 if (is_accelerated_compositing_active_ &&
1200 animation_update_pending_ &&
1201 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571202 return;
1203
1204 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291205 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1206 // on the call stack.
1207 // 2) Allows us to collect more damage rects before painting to help coalesce
1208 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241209 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211210 MessageLoop::current()->PostTask(
1211 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291212}
1213
[email protected]990278ff2012-11-13 02:12:551214void RenderWidget::didScrollRect(int dx, int dy,
1215 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461216 // Drop scrolls on the floor when we are in compositing mode.
1217 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561218 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461219 return;
1220
[email protected]552e6002009-11-19 05:24:571221 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481222 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181223 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571224 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291225 return;
1226
[email protected]990278ff2012-11-13 02:12:551227 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571228
1229 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241230 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571231 return;
1232 if (!paint_aggregator_.HasPendingUpdate())
1233 return;
[email protected]aa4117f2011-12-09 22:19:211234 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241235 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1236 return;
1237
1238 // When GPU rendering, combine pending animations and invalidations into
1239 // a single update.
[email protected]816edc62012-03-17 01:27:221240 if (is_accelerated_compositing_active_ &&
1241 animation_update_pending_ &&
1242 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571243 return;
1244
1245 // Perform updating asynchronously. This serves two purposes:
1246 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1247 // on the call stack.
1248 // 2) Allows us to collect more damage rects before painting to help coalesce
1249 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241250 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211251 MessageLoop::current()->PostTask(
1252 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291253}
1254
[email protected]244ac1892011-12-02 17:04:471255void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091256 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1257 size_ = new_size;
1258 need_update_rect_for_auto_resize_ = true;
[email protected]240b5c32012-11-09 19:17:181259 // If we don't clear PaintAggregator after changing autoResize state, then
1260 // we might end up in a situation where bitmap_rect is larger than the
1261 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1262 // with invalid damage rects.
1263 paint_aggregator_.ClearPendingUpdate();
[email protected]ea3ee0a2012-05-15 03:43:091264 }
[email protected]244ac1892011-12-02 17:04:471265}
1266
[email protected]91acd1c2012-03-14 08:32:391267void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221268 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1269
[email protected]c63b4d42012-04-26 01:01:071270#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211271 if (!is_accelerated_compositing_active_) {
1272 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1273 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1274 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1275 // going to switch to accelerated compositing, the GPU process may need
1276 // round-trips to the browser's UI thread before finishing the frame,
1277 // causing deadlocks if we delay the UpdateRect until we receive the
1278 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071279 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1280 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211281 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1282 }
[email protected]c63b4d42012-04-26 01:01:071283#endif
[email protected]aa4117f2011-12-09 22:19:211284
[email protected]ea162f92011-10-04 23:08:221285 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421286 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241287 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221288}
1289
1290void RenderWidget::didDeactivateCompositor() {
1291 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1292
1293 is_accelerated_compositing_active_ = false;
1294 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1295 routing_id_, is_accelerated_compositing_active_));
1296
[email protected]ea162f92011-10-04 23:08:221297 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241298 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091299
1300 // In single-threaded mode, we exit force compositing mode and re-enter in
1301 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1302 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1303 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361304 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091305 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561306}
1307
[email protected]8926c602013-01-23 05:32:061308void RenderWidget::initializeLayerTreeView(
1309 WebKit::WebLayerTreeViewClient* client,
1310 const WebKit::WebLayer& root_layer,
1311 const WebKit::WebLayerTreeView::Settings& settings) {
1312 DCHECK(!web_layer_tree_view_);
1313 web_layer_tree_view_.reset(new WebKit::WebLayerTreeViewImpl(client));
1314
1315 scoped_ptr<cc::Thread> impl_thread;
1316 CompositorThread* compositor_thread =
1317 RenderThreadImpl::current()->compositor_thread();
1318 if (compositor_thread)
1319 impl_thread = cc::ThreadImpl::createForDifferentThread(
1320 compositor_thread->message_loop()->message_loop_proxy());
1321 if (!web_layer_tree_view_->initialize(settings, impl_thread.Pass())) {
1322 web_layer_tree_view_.reset();
1323 return;
1324 }
1325 web_layer_tree_view_->setRootLayer(root_layer);
1326 if (init_complete_) {
1327 web_layer_tree_view_->setSurfaceReady();
1328 }
1329}
1330
1331WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
1332 return web_layer_tree_view_.get();
1333}
1334
[email protected]9cd43a62012-03-26 08:03:561335void RenderWidget::willBeginCompositorFrame() {
1336 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371337
1338 DCHECK(RenderThreadImpl::current()->compositor_thread());
1339
1340 // The following two can result in further layout and possibly
1341 // enable GPU acceleration so they need to be called before any painting
1342 // is done.
[email protected]2d354272013-01-14 00:59:061343#if !defined(OS_ANDROID)
1344 UpdateTextInputState(DO_NOT_SHOW_IME);
1345#endif // OS_ANDROID
[email protected]abe8b3a2012-03-28 21:19:371346 UpdateSelectionBounds();
1347
[email protected]9cd43a62012-03-26 08:03:561348 WillInitiatePaint();
1349}
1350
[email protected]3391a0772012-03-28 00:32:071351void RenderWidget::didBecomeReadyForAdditionalInput() {
1352 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1353 if (pending_input_event_ack_.get())
1354 Send(pending_input_event_ack_.release());
1355}
1356
[email protected]58264a32011-11-17 23:36:151357void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501358 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351359 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1360 // NOTE: Tests may break if this event is renamed or moved.
1361 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU");
[email protected]29ed96a2012-02-04 18:12:161362 // Notify subclasses that we initiated the paint operation.
1363 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151364}
1365
1366void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181367 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1368
1369 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561370 DidFlushPaint();
1371
[email protected]aa4117f2011-12-09 22:19:211372 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151373 return;
1374
[email protected]ea3ee0a2012-05-15 03:43:091375 if (!next_paint_flags_ &&
1376 !need_update_rect_for_auto_resize_ &&
1377 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151378 return;
[email protected]ea3ee0a2012-05-15 03:43:091379 }
[email protected]58264a32011-11-17 23:36:151380
1381 ViewHostMsg_UpdateRect_Params params;
1382 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151383 params.plugin_window_moves.swap(plugin_window_moves_);
1384 params.flags = next_paint_flags_;
1385 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121386 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091387 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151388
1389 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1390 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091391 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151392}
1393
[email protected]f98d7e3c2010-09-13 22:30:461394void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091395 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]d0be63772011-12-20 23:18:041396 if (WebWidgetHandlesCompositorScheduling()) {
[email protected]c3d45532011-10-07 19:20:401397 webwidget_->composite(false);
[email protected]d0be63772011-12-20 23:18:041398 } else {
[email protected]c3d45532011-10-07 19:20:401399 // TODO(nduca): replace with something a little less hacky. The reason this
1400 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1401 // contains a lot of host-renderer synchronization logic that is still
1402 // important for the accelerated compositing case. The option of simply
1403 // duplicating all that code is less desirable than "faking out" the
1404 // invalidation path using a magical damage rect.
1405 didInvalidateRect(WebRect(0, 0, 1, 1));
1406 }
[email protected]f98d7e3c2010-09-13 22:30:461407}
1408
[email protected]5f8b1022011-01-21 23:34:501409void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201410 if (animation_update_pending_)
1411 return;
1412
[email protected]921244e42011-07-20 16:36:301413 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201414 animation_update_pending_ = true;
1415 if (!animation_timer_.IsRunning()) {
1416 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1417 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211418 }
[email protected]5f8b1022011-01-21 23:34:501419}
1420
[email protected]4873c7d2009-07-16 06:36:281421void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301422 // TODO(darin): Eliminate this temporary.
1423 WebCursor cursor(cursor_info);
1424
initial.commit09911bf2008-07-26 23:55:291425 // Only send a SetCursor message if we need to make a change.
1426 if (!current_cursor_.IsEqual(cursor)) {
1427 current_cursor_ = cursor;
1428 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1429 }
1430}
1431
1432// We are supposed to get a single call to Show for a newly created RenderWidget
1433// that was created via RenderWidget::CreateWebView. So, we wait until this
1434// point to dispatch the ShowWidget message.
1435//
1436// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281437// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291438//
[email protected]4873c7d2009-07-16 06:36:281439void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291440 DCHECK(!did_show_) << "received extraneous Show call";
1441 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1442 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1443
[email protected]8de12d942010-11-17 20:42:441444 if (did_show_)
1445 return;
1446
1447 did_show_ = true;
1448 // NOTE: initial_pos_ may still have its default values at this point, but
1449 // that's okay. It'll be ignored if as_popup is false, or the browser
1450 // process will impose a default position otherwise.
1451 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1452 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291453}
1454
[email protected]4873c7d2009-07-16 06:36:281455void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291456}
1457
[email protected]4873c7d2009-07-16 06:36:281458void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291459}
1460
[email protected]2533ce12009-05-09 00:02:241461void RenderWidget::DoDeferredClose() {
1462 Send(new ViewHostMsg_Close(routing_id_));
1463}
1464
[email protected]4873c7d2009-07-16 06:36:281465void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321466 if (is_swapped_out_) {
1467 // This widget is currently swapped out, and the active widget is in a
1468 // different process. Have the browser route the close request to the
1469 // active widget instead, so that the correct unload handlers are run.
1470 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1471 return;
1472 }
1473
initial.commit09911bf2008-07-26 23:55:291474 // If a page calls window.close() twice, we'll end up here twice, but that's
1475 // OK. It is safe to send multiple Close messages.
1476
[email protected]2533ce12009-05-09 00:02:241477 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1478 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1479 // could be closed before the JS finishes executing. So instead, post a
1480 // message back to the message loop, which won't run until the JS is
1481 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211482 MessageLoop::current()->PostTask(
1483 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291484}
1485
1486void RenderWidget::Close() {
1487 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061488 webwidget_->willCloseLayerTreeView();
1489 web_layer_tree_view_.reset();
[email protected]4873c7d2009-07-16 06:36:281490 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291491 webwidget_ = NULL;
1492 }
1493}
1494
[email protected]4873c7d2009-07-16 06:36:281495WebRect RenderWidget::windowRect() {
1496 if (pending_window_rect_count_)
1497 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241498
[email protected]80ad8622012-11-07 16:33:031499 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291500}
1501
[email protected]8a9d6ca32011-06-06 20:11:301502void RenderWidget::setToolTipText(const WebKit::WebString& text,
1503 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541504 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301505}
1506
[email protected]4873c7d2009-07-16 06:36:281507void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291508 if (did_show_) {
1509 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
[email protected]2533ce12009-05-09 00:02:241510 SetPendingWindowRect(pos);
initial.commit09911bf2008-07-26 23:55:291511 } else {
1512 initial_pos_ = pos;
1513 }
1514}
1515
[email protected]2533ce12009-05-09 00:02:241516void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1517 pending_window_rect_ = rect;
1518 pending_window_rect_count_++;
1519}
1520
[email protected]4873c7d2009-07-16 06:36:281521WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241522 if (pending_window_rect_count_) {
1523 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1524 // the RootWindowRect is probably going to return wrong results since the
1525 // browser may not have processed the Move yet. There isn't really anything
1526 // good to do in this case, and it shouldn't happen - since this size is
1527 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281528 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241529 }
1530
[email protected]80ad8622012-11-07 16:33:031531 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371532}
1533
[email protected]4873c7d2009-07-16 06:36:281534WebRect RenderWidget::windowResizerRect() {
1535 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191536}
1537
[email protected]fa7b1dc2010-06-23 17:53:041538void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031539 // To prevent this renderer process from sending unnecessary IPC messages to
1540 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041541 // only during the input method attached to the browser process is active.
1542 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291543}
1544
[email protected]58b48a0d2012-06-13 07:01:351545void RenderWidget::UpdateCompositionInfo(
1546 const ui::Range& range,
1547 const std::vector<gfx::Rect>& character_bounds) {
1548 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1549 return;
1550 composition_character_bounds_ = character_bounds;
1551 composition_range_ = range;
1552 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1553 routing_id(), composition_range_, composition_character_bounds_));
1554}
1555
[email protected]fa7b1dc2010-06-23 17:53:041556void RenderWidget::OnImeSetComposition(
1557 const string16& text,
1558 const std::vector<WebCompositionUnderline>& underlines,
1559 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281560 if (!webwidget_)
1561 return;
[email protected]d4cff272011-05-02 15:46:011562 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041563 text, WebVector<WebCompositionUnderline>(underlines),
1564 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011565 // Setting the IME composition was successful. Send the new composition
1566 // range to the browser.
1567 ui::Range range(ui::Range::InvalidRange());
1568 size_t location, length;
1569 if (webwidget_->compositionRange(&location, &length)) {
1570 range.set_start(location);
1571 range.set_end(location + length);
1572 }
1573 // The IME was cancelled via the Esc key, so just send back the caret.
1574 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1575 range.set_start(location);
1576 range.set_end(location + length);
1577 }
[email protected]58b48a0d2012-06-13 07:01:351578 std::vector<gfx::Rect> character_bounds;
1579 GetCompositionCharacterBounds(&character_bounds);
1580 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011581 } else {
[email protected]fa7b1dc2010-06-23 17:53:041582 // If we failed to set the composition text, then we need to let the browser
1583 // process to cancel the input method's ongoing composition session, to make
1584 // sure we are in a consistent state.
1585 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011586
1587 // Send an updated IME range with just the caret range.
1588 ui::Range range(ui::Range::InvalidRange());
1589 size_t location, length;
1590 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1591 range.set_start(location);
1592 range.set_end(location + length);
1593 }
[email protected]58b48a0d2012-06-13 07:01:351594 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261595 }
[email protected]fa7b1dc2010-06-23 17:53:041596}
1597
[email protected]4de6d1692011-10-12 08:45:441598void RenderWidget::OnImeConfirmComposition(
1599 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041600 if (!webwidget_)
1601 return;
1602
1603 handling_input_event_ = true;
1604 webwidget_->confirmComposition(text);
1605 handling_input_event_ = false;
1606
[email protected]d4cff272011-05-02 15:46:011607 // Send an updated IME range with just the caret range.
1608 ui::Range range(ui::Range::InvalidRange());
1609 size_t location, length;
1610 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1611 range.set_start(location);
1612 range.set_end(location + length);
1613 }
[email protected]58b48a0d2012-06-13 07:01:351614 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291615}
1616
[email protected]948f7ab72010-05-28 23:48:081617// This message causes the renderer to render an image of the
1618// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251619void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1620 int tag,
1621 const gfx::Size& page_size,
1622 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001623 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1624 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251625 // Close our unused handle.
1626#if defined(OS_WIN)
1627 ::CloseHandle(dib_handle);
1628#elif defined(OS_MACOSX)
1629 base::SharedMemory::CloseHandle(dib_handle);
1630#endif
1631 }
[email protected]d65adb12010-04-28 17:26:491632 return;
[email protected]45c6aad32010-11-11 04:46:251633 }
[email protected]d65adb12010-04-28 17:26:491634
[email protected]948f7ab72010-05-28 23:48:081635 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491636 // If one of these is empty, then we just return the dib we were
1637 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091638 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491639 return;
1640 }
1641
1642 // Map the given DIB ID into this process, and unmap it at the end
1643 // of this function.
[email protected]45c6aad32010-11-11 04:46:251644 scoped_ptr<TransportDIB> paint_at_size_buffer(
1645 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301646
[email protected]4b01b962012-10-09 23:17:351647 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281648 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351649 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281650 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511651 gfx::Size canvas_size = page_size_in_pixel;
1652 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491653 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511654 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491655 static_cast<float>(canvas_size.height());
1656
[email protected]ee8d6fd2010-05-26 17:05:481657 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491658 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1659 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481660 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491661
[email protected]36808ad2010-10-20 19:18:301662 scoped_ptr<skia::PlatformCanvas> canvas(
1663 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1664 canvas_size.height()));
1665 if (!canvas.get()) {
1666 NOTREACHED();
1667 return;
1668 }
1669
[email protected]d65adb12010-04-28 17:26:491670 // Reset bounds to what we actually received, but they should be the
1671 // same.
1672 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1673 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1674 bounds.set_width(canvas->getDevice()->width());
1675 bounds.set_height(canvas->getDevice()->height());
1676
1677 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081678 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491679 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1680
[email protected]948f7ab72010-05-28 23:48:081681 // Have to make sure we're laid out at the right size before
1682 // rendering.
1683 gfx::Size old_size = webwidget_->size();
1684 webwidget_->resize(page_size);
1685 webwidget_->layout();
1686
[email protected]d65adb12010-04-28 17:26:491687 // Paint the entire thing (using original bounds, not scaled bounds).
1688 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1689 canvas->restore();
1690
[email protected]948f7ab72010-05-28 23:48:081691 // Return the widget to its previous size.
1692 webwidget_->resize(old_size);
1693
[email protected]c88c9442010-07-19 18:55:091694 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491695}
1696
[email protected]3d9ec5052013-01-02 22:05:251697void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121698 // During shutdown we can just ignore this message.
1699 if (!webwidget_)
1700 return;
1701
1702 set_next_paint_is_repaint_ack();
[email protected]b89c90762013-01-06 20:29:301703 if (is_accelerated_compositing_active_) {
[email protected]8926c602013-01-23 05:32:061704 if (web_layer_tree_view_)
1705 web_layer_tree_view_->setNeedsRedraw();
[email protected]f98d7e3c2010-09-13 22:30:461706 scheduleComposite();
1707 } else {
1708 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1709 didInvalidateRect(repaint_rect);
1710 }
[email protected]ec7dc112008-08-06 05:30:121711}
1712
[email protected]3d9ec5052013-01-02 22:05:251713void RenderWidget::OnSmoothScrollCompleted(int gesture_id) {
[email protected]0e241b4b2012-08-18 09:06:271714 PendingSmoothScrollGestureMap::iterator it =
1715 pending_smooth_scroll_gestures_.find(gesture_id);
1716 DCHECK(it != pending_smooth_scroll_gestures_.end());
1717 it->second.Run();
1718 pending_smooth_scroll_gestures_.erase(it);
1719}
1720
[email protected]4873c7d2009-07-16 06:36:281721void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111722 if (!webwidget_)
1723 return;
[email protected]4873c7d2009-07-16 06:36:281724 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111725}
1726
[email protected]6131a642012-06-15 23:26:531727void RenderWidget::OnScreenInfoChanged(
1728 const WebKit::WebScreenInfo& screen_info) {
1729 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191730 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531731}
1732
[email protected]80ad8622012-11-07 16:33:031733void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1734 const gfx::Rect& window_screen_rect) {
1735 view_screen_rect_ = view_screen_rect;
1736 window_screen_rect_ = window_screen_rect;
1737 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1738}
1739
[email protected]468ac582012-11-20 00:53:191740void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1741 if (device_scale_factor_ == device_scale_factor)
1742 return;
1743
1744 device_scale_factor_ = device_scale_factor;
1745
1746 if (!is_accelerated_compositing_active_) {
1747 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1748 } else {
1749 scheduleComposite();
1750 }
1751}
1752
[email protected]719b36f2010-12-22 20:36:461753webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151754 const gfx::Rect& paint_bounds,
1755 TransportDIB** dib,
1756 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201757 gfx::Rect* clip,
1758 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461759 // Bare RenderWidgets don't support optimized plugin painting.
1760 return NULL;
[email protected]ca4847f2010-09-24 05:39:151761}
1762
[email protected]ceb36f7d2012-10-31 18:33:241763gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521764 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241765 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521766}
1767
[email protected]bee16aab2009-08-26 15:55:031768void RenderWidget::SetHidden(bool hidden) {
1769 if (is_hidden_ == hidden)
1770 return;
1771
1772 // The status has changed. Tell the RenderThread about it.
1773 is_hidden_ = hidden;
1774 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271775 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031776 else
[email protected]380244092011-10-07 17:26:271777 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031778}
1779
[email protected]2b624c562011-10-27 22:58:261780void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261781 if (!webwidget_)
1782 return;
1783
1784 if (is_fullscreen_) {
1785 webwidget_->willExitFullScreen();
1786 } else {
1787 webwidget_->willEnterFullScreen();
1788 }
[email protected]2b624c562011-10-27 22:58:261789}
1790
1791void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261792 if (!webwidget_)
1793 return;
1794
1795 if (is_fullscreen_) {
1796 webwidget_->didEnterFullScreen();
1797 } else {
1798 webwidget_->didExitFullScreen();
1799 }
[email protected]2b624c562011-10-27 22:58:261800}
1801
[email protected]699ab0d2009-04-23 23:19:141802void RenderWidget::SetBackground(const SkBitmap& background) {
1803 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461804
[email protected]699ab0d2009-04-23 23:19:141805 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281806 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141807}
1808
[email protected]674741932009-02-04 23:44:461809bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051810 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461811}
1812
1813bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:051814 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461815}
1816
1817void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051818 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461819}
1820
1821void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:051822 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:461823}
1824
1825void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051826 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461827}
1828
[email protected]b18583c2012-12-18 06:55:271829static bool IsDateTimeInput(ui::TextInputType type) {
1830 return type == ui::TEXT_INPUT_TYPE_DATE ||
1831 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1832 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1833 type == ui::TEXT_INPUT_TYPE_MONTH ||
1834 type == ui::TEXT_INPUT_TYPE_TIME ||
1835 type == ui::TEXT_INPUT_TYPE_WEEK;
1836}
1837
1838
[email protected]3306f262012-09-21 19:20:421839void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
1840 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1841 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291842 return;
[email protected]ad26ef42011-06-17 07:59:451843 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271844 if (IsDateTimeInput(new_type))
1845 return; // Not considered as a text input field in WebKit/Chromium.
1846
[email protected]5b739cb2012-08-21 20:35:211847 WebKit::WebTextInputInfo new_info;
1848 if (webwidget_)
1849 new_info = webwidget_->textInputInfo();
1850
[email protected]ad26ef42011-06-17 07:59:451851 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211852
[email protected]3306f262012-09-21 19:20:421853 // Only sends text input params if they are changed or if the ime should be
1854 // shown.
1855 if (show_ime_if_needed || (text_input_type_ != new_type
1856 || text_input_info_ != new_info
1857 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:211858 ViewHostMsg_TextInputState_Params p;
1859 p.type = new_type;
1860 p.value = new_info.value.utf8();
1861 p.selection_start = new_info.selectionStart;
1862 p.selection_end = new_info.selectionEnd;
1863 p.composition_start = new_info.compositionStart;
1864 p.composition_end = new_info.compositionEnd;
1865 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:421866 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:211867 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1868
1869 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041870 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451871 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:291872 }
initial.commit09911bf2008-07-26 23:55:291873}
1874
[email protected]3f783362011-10-21 22:40:501875void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
1876 WebRect start_webrect;
1877 WebRect end_webrect;
1878 webwidget_->selectionBounds(start_webrect, end_webrect);
1879 *start = start_webrect;
1880 *end = end_webrect;
[email protected]73bf95812011-10-12 11:38:321881}
1882
[email protected]e99ef6f2011-10-16 01:13:001883void RenderWidget::UpdateSelectionBounds() {
1884 if (!webwidget_)
1885 return;
1886
[email protected]3f783362011-10-21 22:40:501887 gfx::Rect start_rect;
1888 gfx::Rect end_rect;
1889 GetSelectionBounds(&start_rect, &end_rect);
[email protected]58b48a0d2012-06-13 07:01:351890 if (selection_start_rect_ != start_rect || selection_end_rect_ != end_rect) {
1891 selection_start_rect_ = start_rect;
1892 selection_end_rect_ = end_rect;
[email protected]b556c2e2012-08-10 22:18:271893 WebTextDirection start_dir = WebKit::WebTextDirectionLeftToRight;
1894 WebTextDirection end_dir = WebKit::WebTextDirectionLeftToRight;
1895 webwidget_->selectionTextDirection(start_dir, end_dir);
1896 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_,
1897 selection_start_rect_, start_dir, selection_end_rect_, end_dir));
[email protected]58b48a0d2012-06-13 07:01:351898 }
[email protected]e99ef6f2011-10-16 01:13:001899
[email protected]58b48a0d2012-06-13 07:01:351900 std::vector<gfx::Rect> character_bounds;
1901 GetCompositionCharacterBounds(&character_bounds);
1902 UpdateCompositionInfo(composition_range_, character_bounds);
1903}
1904
1905bool RenderWidget::ShouldUpdateCompositionInfo(
1906 const ui::Range& range,
1907 const std::vector<gfx::Rect>& bounds) {
1908 if (composition_range_ != range)
1909 return true;
1910 if (bounds.size() != composition_character_bounds_.size())
1911 return true;
1912 for (size_t i = 0; i < bounds.size(); ++i) {
1913 if (bounds[i] != composition_character_bounds_[i])
1914 return true;
1915 }
1916 return false;
[email protected]e99ef6f2011-10-16 01:13:001917}
1918
[email protected]73bf95812011-10-12 11:38:321919// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:451920COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
1921 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
1922COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
1923 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
1924COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
1925 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:181926COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
1927 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
1928COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
1929 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
1930COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
1931 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
1932COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
1933 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
1934COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
1935 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:001936COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
1937 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
1938COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
1939 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
1940COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
1941 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
1942COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
1943 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
1944COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
1945 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
1946COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
1947 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:011948COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
1949 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
1950COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
1951 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451952
[email protected]5b739cb2012-08-21 20:35:211953ui::TextInputType RenderWidget::WebKitToUiTextInputType(
1954 WebKit::WebTextInputType type) {
1955 // Check the type is in the range representable by ui::TextInputType.
1956 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
1957 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
1958 return static_cast<ui::TextInputType>(type);
1959}
1960
[email protected]ad26ef42011-06-17 07:59:451961ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:271962 if (webwidget_)
1963 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:451964 return ui::TEXT_INPUT_TYPE_NONE;
1965}
1966
[email protected]58b48a0d2012-06-13 07:01:351967void RenderWidget::GetCompositionCharacterBounds(
1968 std::vector<gfx::Rect>* bounds) {
1969 DCHECK(bounds);
1970 bounds->clear();
1971}
1972
[email protected]ad26ef42011-06-17 07:59:451973bool RenderWidget::CanComposeInline() {
1974 return true;
[email protected]56ea1a62011-05-30 07:05:571975}
1976
[email protected]4873c7d2009-07-16 06:36:281977WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041978 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281979}
1980
[email protected]f660d9c2012-06-06 18:31:211981float RenderWidget::deviceScaleFactor() {
1982 return device_scale_factor_;
1983}
1984
[email protected]fa7b1dc2010-06-23 17:53:041985void RenderWidget::resetInputMethod() {
1986 if (!input_method_is_active_)
1987 return;
1988
1989 // If the last text input type is not None, then we should finish any
1990 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451991 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041992 // If a composition text exists, then we need to let the browser process
1993 // to cancel the input method's ongoing composition session.
1994 if (webwidget_->confirmComposition())
1995 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1996 }
[email protected]d4cff272011-05-02 15:46:011997
1998 // Send an updated IME range with the current caret rect.
1999 ui::Range range(ui::Range::InvalidRange());
2000 size_t location, length;
2001 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2002 range.set_start(location);
2003 range.set_end(location + length);
2004 }
[email protected]58b48a0d2012-06-13 07:01:352005
2006 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042007}
2008
[email protected]c68c3e4e2013-01-24 00:36:562009void RenderWidget::didHandleGestureEvent(
2010 const WebGestureEvent& event,
2011 bool event_cancelled) {
2012#if defined(OS_ANDROID)
2013 if (event_cancelled)
2014 return;
2015 if (event.type == WebInputEvent::GestureTap ||
2016 event.type == WebInputEvent::GestureLongPress) {
2017 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2018 }
2019#endif
2020}
2021
[email protected]f103ab72009-09-02 17:10:592022void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502023 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292024 size_t i = 0;
2025 for (; i < plugin_window_moves_.size(); ++i) {
2026 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582027 if (move.rects_valid) {
2028 plugin_window_moves_[i] = move;
2029 } else {
2030 plugin_window_moves_[i].visible = move.visible;
2031 }
initial.commit09911bf2008-07-26 23:55:292032 break;
2033 }
2034 }
2035
2036 if (i == plugin_window_moves_.size())
2037 plugin_window_moves_.push_back(move);
2038}
[email protected]268654772009-08-06 23:02:042039
2040void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2041 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2042 i != plugin_window_moves_.end(); ++i) {
2043 if (i->window == window) {
2044 plugin_window_moves_.erase(i);
2045 break;
2046 }
2047 }
2048}
[email protected]67bfb83f2011-09-22 03:36:372049
[email protected]b63d58d2012-11-26 22:37:442050void RenderWidget::GetRenderingStats(
2051 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]8926c602013-01-23 05:32:062052 if (web_layer_tree_view_)
2053 web_layer_tree_view_->renderingStats(stats);
[email protected]b63d58d2012-11-26 22:37:442054
2055 stats.rendering_stats.numAnimationFrames +=
2056 software_stats_.numAnimationFrames;
2057 stats.rendering_stats.numFramesSentToScreen +=
2058 software_stats_.numFramesSentToScreen;
[email protected]121cc752013-01-16 09:12:452059 stats.rendering_stats.totalPaintTime +=
2060 software_stats_.totalPaintTime;
[email protected]b63d58d2012-11-26 22:37:442061 stats.rendering_stats.totalPixelsPainted +=
2062 software_stats_.totalPixelsPainted;
[email protected]121cc752013-01-16 09:12:452063 stats.rendering_stats.totalRasterizeTime +=
2064 software_stats_.totalRasterizeTime;
[email protected]b63d58d2012-11-26 22:37:442065 stats.rendering_stats.totalPixelsRasterized +=
2066 software_stats_.totalPixelsRasterized;
[email protected]fef5e3972012-08-07 03:59:472067}
2068
[email protected]e9ff79c2012-10-19 21:31:262069bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522070 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2071 if (!gpu_channel)
2072 return false;
2073
2074 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2075}
2076
[email protected]0e241b4b2012-08-18 09:06:272077void RenderWidget::BeginSmoothScroll(
2078 bool down,
[email protected]ebd8b562012-10-09 14:44:292079 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192080 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292081 int mouse_event_x,
2082 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272083 DCHECK(!callback.is_null());
2084 int id = next_smooth_scroll_gesture_id_++;
[email protected]267909d2012-10-20 04:36:192085
2086 ViewHostMsg_BeginSmoothScroll_Params params;
2087 params.scroll_down = down;
2088 params.pixels_to_scroll = pixels_to_scroll;
2089 params.mouse_event_x = mouse_event_x;
2090 params.mouse_event_y = mouse_event_y;
2091
2092 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, params));
[email protected]0e241b4b2012-08-18 09:06:272093 pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback));
[email protected]a39ca1652012-07-13 21:30:582094}
2095
[email protected]67bfb83f2011-09-22 03:36:372096bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2097 return false;
2098}
[email protected]c3d45532011-10-07 19:20:402099
[email protected]41d86852012-11-07 12:23:242100bool RenderWidget::WillHandleGestureEvent(
2101 const WebKit::WebGestureEvent& event) {
2102 return false;
2103}
2104
[email protected]c3d45532011-10-07 19:20:402105bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
2106 return false;
2107}
[email protected]e9ff79c2012-10-19 21:31:262108
[email protected]3d5c243b2012-11-30 00:26:012109bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2110 return true;
2111}
2112
[email protected]e9ff79c2012-10-19 21:31:262113} // namespace content