blob: 4b3d13dddd34b37d60849e80814e8c4dd75393b1 [file] [log] [blame]
[email protected]9f4f3322012-01-18 22:29:561// 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#ifndef CONTENT_RENDERER_RENDER_WIDGET_H_
6#define CONTENT_RENDERER_RENDER_WIDGET_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]aa4117f2011-12-09 22:19:218#include <deque>
[email protected]0e241b4b2012-08-18 09:06:279#include <map>
[email protected]010ea08a2009-10-11 20:21:3210
initial.commit09911bf2008-07-26 23:55:2911#include "base/basictypes.h"
[email protected]f3112a52011-09-30 23:47:4912#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/ref_counted.h"
[email protected]8704f89b2011-04-15 00:30:0514#include "base/memory/scoped_ptr.h"
[email protected]ed7defa2013-03-12 21:29:5915#include "base/memory/weak_ptr.h"
[email protected]8704f89b2011-04-15 00:30:0516#include "base/time.h"
[email protected]350ce8702012-03-09 04:23:3817#include "base/timer.h"
[email protected]6e84de22013-03-18 06:54:2718#include "cc/debug/rendering_stats.h"
[email protected]f3112a52011-09-30 23:47:4919#include "content/common/content_export.h"
[email protected]ed7defa2013-03-12 21:29:5920#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]921f1592011-03-18 00:41:0221#include "content/renderer/paint_aggregator.h"
[email protected]4f86bdb2012-11-10 19:11:1922#include "ipc/ipc_listener.h"
23#include "ipc/ipc_sender.h"
[email protected]debc8e52013-01-15 03:43:1224#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
[email protected]8bd0fe62011-01-17 06:44:3725#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderline.h"
26#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h"
[email protected]8bd0fe62011-01-17 06:44:3727#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h"
[email protected]5b739cb2012-08-21 20:35:2128#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextInputInfo.h"
[email protected]8bd0fe62011-01-17 06:44:3729#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidgetClient.h"
[email protected]d65adb12010-04-28 17:26:4930#include "third_party/skia/include/core/SkBitmap.h"
[email protected]ad26ef42011-06-17 07:59:4531#include "ui/base/ime/text_input_type.h"
[email protected]58b48a0d2012-06-13 07:01:3532#include "ui/base/range/range.h"
[email protected]08397d52011-02-05 01:53:3833#include "ui/gfx/native_widget_types.h"
34#include "ui/gfx/rect.h"
[email protected]990278ff2012-11-13 02:12:5535#include "ui/gfx/vector2d.h"
[email protected]a2b5ded2013-05-20 21:32:5336#include "ui/gfx/vector2d_f.h"
[email protected]d353541f2012-05-03 22:45:4137#include "ui/surface/transport_dib.h"
initial.commit09911bf2008-07-26 23:55:2938#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2939
[email protected]aa4117f2011-12-09 22:19:2140struct ViewHostMsg_UpdateRect_Params;
41class ViewHostMsg_UpdateRect;
42
[email protected]484955942010-08-19 16:13:1843namespace IPC {
44class SyncMessage;
45}
46
[email protected]88efb7ec2009-07-14 16:32:5947namespace WebKit {
[email protected]41d86852012-11-07 12:23:2448class WebGestureEvent;
[email protected]0dea1652012-12-14 00:09:0949class WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0650class WebMouseEvent;
[email protected]2d0f2e92011-10-03 09:02:2451class WebTouchEvent;
[email protected]e195e582013-03-08 01:32:5952struct WebPoint;
53struct WebRenderingStatsImpl;
[email protected]526476902011-10-06 20:34:0654}
55
[email protected]ba91a792013-02-06 09:48:2856namespace cc { class OutputSurface; }
57
[email protected]4de6d1692011-10-12 08:45:4458namespace ui {
59class Range;
60}
61
[email protected]191eb3f72010-12-21 06:27:5062namespace webkit {
63namespace npapi {
[email protected]f103ab72009-09-02 17:10:5964struct WebPluginGeometry;
[email protected]719b36f2010-12-22 20:36:4665} // namespace npapi
66
67namespace ppapi {
68class PluginInstance;
69} // namespace ppapi
70} // namespace webkit
[email protected]f103ab72009-09-02 17:10:5971
[email protected]e9ff79c2012-10-19 21:31:2672namespace content {
73struct GpuRenderingStats;
[email protected]ba91a792013-02-06 09:48:2874class RenderWidgetCompositor;
[email protected]e9ff79c2012-10-19 21:31:2675class RenderWidgetTest;
76
initial.commit09911bf2008-07-26 23:55:2977// RenderWidget provides a communication bridge between a WebWidget and
78// a RenderWidgetHost, the latter of which lives in a different process.
[email protected]f3112a52011-09-30 23:47:4979class CONTENT_EXPORT RenderWidget
[email protected]c47317e2012-06-20 22:35:3180 : public IPC::Listener,
81 public IPC::Sender,
[email protected]f3112a52011-09-30 23:47:4982 NON_EXPORTED_BASE(virtual public WebKit::WebWidgetClient),
[email protected]ed7defa2013-03-12 21:29:5983 NON_EXPORTED_BASE(public WebGraphicsContext3DSwapBuffersClient),
[email protected]f3112a52011-09-30 23:47:4984 public base::RefCounted<RenderWidget> {
initial.commit09911bf2008-07-26 23:55:2985 public:
86 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]380244092011-10-07 17:26:2787 // RenderView that this widget lives inside.
[email protected]0ebf3872008-11-07 21:35:0388 static RenderWidget* Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:0489 WebKit::WebPopupType popup_type,
90 const WebKit::WebScreenInfo& screen_info);
initial.commit09911bf2008-07-26 23:55:2991
[email protected]484955942010-08-19 16:13:1892 // Creates a WebWidget based on the popup type.
93 static WebKit::WebWidget* CreateWebWidget(RenderWidget* render_widget);
94
[email protected]c03a6e72011-04-19 21:42:0695 // The compositing surface assigned by the RenderWidgetHost
96 // (or RenderViewHost). Will be gfx::kNullPluginWindow if not assigned yet,
97 // in which case we should not create any GPU command buffers with it.
initial.commit09911bf2008-07-26 23:55:2998 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
99 // not yet assigned a view ID, in which case, the process MUST NOT send
100 // messages with this ID to the parent.
101 int32 routing_id() const {
102 return routing_id_;
103 }
104
[email protected]9f4f3322012-01-18 22:29:56105 int32 surface_id() const {
106 return surface_id_;
107 }
108
initial.commit09911bf2008-07-26 23:55:29109 // May return NULL when the window is closing.
[email protected]93b9d692011-04-13 00:44:31110 WebKit::WebWidget* webwidget() const { return webwidget_; }
[email protected]ee41e7d22011-10-14 19:34:09111
[email protected]93b9d692011-04-13 00:44:31112 gfx::Size size() const { return size_; }
[email protected]589621b2010-09-23 22:01:07113 bool has_focus() const { return has_focus_; }
[email protected]ee41e7d22011-10-14 19:34:09114 bool is_fullscreen() const { return is_fullscreen_; }
[email protected]204f1df2012-01-04 20:21:13115 bool is_hidden() const { return is_hidden_; }
[email protected]589621b2010-09-23 22:01:07116
[email protected]c47317e2012-06-20 22:35:31117 // IPC::Listener
[email protected]edc64de2011-11-17 20:07:38118 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
initial.commit09911bf2008-07-26 23:55:29119
[email protected]c47317e2012-06-20 22:35:31120 // IPC::Sender
[email protected]edc64de2011-11-17 20:07:38121 virtual bool Send(IPC::Message* msg) OVERRIDE;
initial.commit09911bf2008-07-26 23:55:29122
[email protected]4873c7d2009-07-16 06:36:28123 // WebKit::WebWidgetClient
[email protected]9ed83fe2013-02-27 01:52:28124 virtual void suppressCompositorScheduling(bool enable);
[email protected]9cd43a62012-03-26 08:03:56125 virtual void willBeginCompositorFrame();
[email protected]4873c7d2009-07-16 06:36:28126 virtual void didInvalidateRect(const WebKit::WebRect&);
[email protected]990278ff2012-11-13 02:12:55127 virtual void didScrollRect(int dx, int dy,
128 const WebKit::WebRect& clipRect);
[email protected]244ac1892011-12-02 17:04:47129 virtual void didAutoResize(const WebKit::WebSize& new_size);
[email protected]91acd1c2012-03-14 08:32:39130 virtual void didActivateCompositor(int input_handler_identifier);
[email protected]ea162f92011-10-04 23:08:22131 virtual void didDeactivateCompositor();
[email protected]e195e582013-03-08 01:32:59132 virtual void initializeLayerTreeView();
[email protected]8926c602013-01-23 05:32:06133 virtual WebKit::WebLayerTreeView* layerTreeView();
[email protected]3391a0772012-03-28 00:32:07134 virtual void didBecomeReadyForAdditionalInput();
[email protected]58264a32011-11-17 23:36:15135 virtual void didCommitAndDrawCompositorFrame();
136 virtual void didCompleteSwapBuffers();
[email protected]f98d7e3c2010-09-13 22:30:46137 virtual void scheduleComposite();
[email protected]5f8b1022011-01-21 23:34:50138 virtual void scheduleAnimation();
[email protected]4873c7d2009-07-16 06:36:28139 virtual void didFocus();
140 virtual void didBlur();
141 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
142 virtual void closeWidgetSoon();
143 virtual void show(WebKit::WebNavigationPolicy);
144 virtual void runModal() {}
[email protected]9b003482013-05-21 14:00:17145 virtual void didProgrammaticallyScroll(const WebKit::WebPoint& scroll_point);
[email protected]4873c7d2009-07-16 06:36:28146 virtual WebKit::WebRect windowRect();
[email protected]8a9d6ca32011-06-06 20:11:30147 virtual void setToolTipText(const WebKit::WebString& text,
148 WebKit::WebTextDirection hint);
[email protected]4873c7d2009-07-16 06:36:28149 virtual void setWindowRect(const WebKit::WebRect&);
150 virtual WebKit::WebRect windowResizerRect();
151 virtual WebKit::WebRect rootWindowRect();
152 virtual WebKit::WebScreenInfo screenInfo();
[email protected]f660d9c2012-06-06 18:31:21153 virtual float deviceScaleFactor();
[email protected]fa7b1dc2010-06-23 17:53:04154 virtual void resetInputMethod();
[email protected]c68c3e4e2013-01-24 00:36:56155 virtual void didHandleGestureEvent(const WebKit::WebGestureEvent& event,
156 bool event_cancelled);
[email protected]4873c7d2009-07-16 06:36:28157
158 // Called when a plugin is moved. These events are queued up and sent with
159 // the next paint or scroll message to the host.
[email protected]191eb3f72010-12-21 06:27:50160 void SchedulePluginMove(const webkit::npapi::WebPluginGeometry& move);
initial.commit09911bf2008-07-26 23:55:29161
[email protected]268654772009-08-06 23:02:04162 // Called when a plugin window has been destroyed, to make sure the currently
163 // pending moves don't try to reference it.
164 void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
165
[email protected]b63d58d2012-11-26 22:37:44166 // Fills in a WebRenderingStatsImpl struct containing information about
[email protected]fef5e3972012-08-07 03:59:47167 // rendering, e.g. count of frames rendered, time spent painting.
[email protected]b63d58d2012-11-26 22:37:44168 void GetRenderingStats(WebKit::WebRenderingStatsImpl&) const;
[email protected]fef5e3972012-08-07 03:59:47169
[email protected]63b465922012-09-06 02:04:52170 // Fills in a GpuRenderingStats struct containing information about
171 // GPU rendering, e.g. count of texture uploads performed, time spent
172 // uploading.
173 // This call is relatively expensive as it blocks on the GPU process
[email protected]e9ff79c2012-10-19 21:31:26174 bool GetGpuRenderingStats(GpuRenderingStats*) const;
[email protected]63b465922012-09-06 02:04:52175
[email protected]24ed0432013-04-24 07:50:31176 RenderWidgetCompositor* compositor() const;
177
[email protected]ba91a792013-02-06 09:48:28178 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface();
179
[email protected]0e241b4b2012-08-18 09:06:27180 // Callback for use with BeginSmoothScroll.
181 typedef base::Callback<void()> SmoothScrollCompletionCallback;
182
[email protected]a39ca1652012-07-13 21:30:58183 // Directs the host to begin a smooth scroll. This scroll should have the same
[email protected]0e241b4b2012-08-18 09:06:27184 // performance characteristics as a user-initiated scroll. Returns an ID of
[email protected]53beb772013-03-06 01:57:22185 // the scroll gesture. |mouse_event_x| and |mouse_event_y| are expected to be
186 // in local DIP coordinates.
[email protected]0c2ebef2013-04-03 12:14:10187 void BeginSmoothScroll(bool scroll_down,
[email protected]ebd8b562012-10-09 14:44:29188 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:19189 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:29190 int mouse_event_x,
191 int mouse_event_y);
[email protected]a39ca1652012-07-13 21:30:58192
[email protected]a2b5ded2013-05-20 21:32:53193 // Notifies the host that root scroll layer has overscrolled.
194 void DidOverscroll(gfx::Vector2dF accumulated_overscroll,
195 gfx::Vector2dF current_fling_velocity);
196
initial.commit09911bf2008-07-26 23:55:29197 // Close the underlying WebWidget.
[email protected]60c42a8c72009-10-09 04:08:59198 virtual void Close();
initial.commit09911bf2008-07-26 23:55:29199
[email protected]6fceb912013-02-15 06:24:15200 // Notifies about a compositor frame commit operation having finished.
201 virtual void DidCommitCompositorFrame();
202
[email protected]a1127f82011-09-08 17:27:01203 float filtered_time_per_frame() const {
204 return filtered_time_per_frame_;
205 }
206
[email protected]3306f262012-09-21 19:20:42207 enum ShowIme {
208 DO_NOT_SHOW_IME,
209 SHOW_IME_IF_NEEDED
210 };
211
[email protected]66fca5bc2013-05-23 06:58:29212 // Handle common setup/teardown for handling IME events.
213 void StartHandlingImeEvent();
214 void FinishHandlingImeEvent();
215
[email protected]35134e12013-02-22 20:07:40216 virtual void InstrumentWillBeginFrame() {}
217 virtual void InstrumentDidBeginFrame() {}
218 virtual void InstrumentDidCancelFrame() {}
219 virtual void InstrumentWillComposite() {}
220
[email protected]34bb3ac2013-03-08 02:41:28221 virtual bool AllowPartialSwap() const;
[email protected]ccc1722e2013-05-06 19:43:07222 bool SynchronouslyDisableVSync() const;
[email protected]34bb3ac2013-03-08 02:41:28223
initial.commit09911bf2008-07-26 23:55:29224 protected:
[email protected]8085dbc82008-09-26 22:53:44225 // Friend RefCounted so that the dtor can be non-public. Using this class
226 // without ref-counting is an error.
227 friend class base::RefCounted<RenderWidget>;
[email protected]7339cd22010-10-27 00:11:20228 // For unit tests.
[email protected]e9ff79c2012-10-19 21:31:26229 friend class RenderWidgetTest;
[email protected]8085dbc82008-09-26 22:53:44230
[email protected]61e2b3cc2012-03-02 16:13:34231 enum ResizeAck {
232 SEND_RESIZE_ACK,
233 NO_RESIZE_ACK,
234 };
235
[email protected]6fd35b72012-03-01 19:46:41236 RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04237 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44238 bool swapped_out);
[email protected]ce2b28e2012-08-09 15:53:57239
[email protected]8085dbc82008-09-26 22:53:44240 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29241
242 // Initializes this view with the given opener. CompleteInit must be called
243 // later.
[email protected]a635f942012-12-07 10:34:29244 bool Init(int32 opener_id);
initial.commit09911bf2008-07-26 23:55:29245
[email protected]484955942010-08-19 16:13:18246 // Called by Init and subclasses to perform initialization.
[email protected]a635f942012-12-07 10:34:29247 bool DoInit(int32 opener_id,
[email protected]484955942010-08-19 16:13:18248 WebKit::WebWidget* web_widget,
249 IPC::SyncMessage* create_widget_message);
250
initial.commit09911bf2008-07-26 23:55:29251 // Finishes creation of a pending view started with Init.
[email protected]fc4404d2012-11-07 19:53:30252 void CompleteInit();
initial.commit09911bf2008-07-26 23:55:29253
[email protected]992db4c2011-05-12 15:37:15254 // Sets whether this RenderWidget has been swapped out to be displayed by
255 // a RenderWidget in a different process. If so, no new IPC messages will be
256 // sent (only ACKs) and the process is free to exit when there are no other
257 // active RenderWidgets.
258 void SetSwappedOut(bool is_swapped_out);
259
[email protected]661eb9d2009-02-03 02:11:48260 // Paints the given rectangular region of the WebWidget into canvas (a
261 // shared memory segment returned by AllocPaintBuf on Windows). The caller
262 // must ensure that the given rect fits within the bounds of the WebWidget.
[email protected]4fb66842009-12-04 21:41:00263 void PaintRect(const gfx::Rect& rect, const gfx::Point& canvas_origin,
[email protected]9d611ca2012-11-14 13:46:56264 SkCanvas* canvas);
[email protected]4fb66842009-12-04 21:41:00265
266 // Paints a border at the given rect for debugging purposes.
[email protected]9d611ca2012-11-14 13:46:56267 void PaintDebugBorder(const gfx::Rect& rect, SkCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29268
[email protected]bd37ae252011-06-03 01:28:18269 bool IsRenderingVSynced();
[email protected]52ccd0ea2011-02-16 01:09:05270 void AnimationCallback();
271 void AnimateIfNeeded();
[email protected]65225772011-05-12 21:10:24272 void InvalidationCallback();
273 void DoDeferredUpdateAndSendInputAck();
[email protected]552e6002009-11-19 05:24:57274 void DoDeferredUpdate();
[email protected]2533ce12009-05-09 00:02:24275 void DoDeferredClose();
276 void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
[email protected]f0c2a242013-03-15 19:34:52277 virtual void Composite(base::TimeTicks frame_begin_time);
initial.commit09911bf2008-07-26 23:55:29278
[email protected]699ab0d2009-04-23 23:19:14279 // Set the background of the render widget to a bitmap. The bitmap will be
280 // tiled in both directions if it isn't big enough to fill the area. This is
281 // mainly intended to be used in conjuction with WebView::SetIsTransparent().
282 virtual void SetBackground(const SkBitmap& bitmap);
283
[email protected]61e2b3cc2012-03-02 16:13:34284 // Resizes the render widget.
285 void Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44286 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40287 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34288 const gfx::Rect& resizer_rect,
289 bool is_fullscreen,
290 ResizeAck resize_ack);
291
initial.commit09911bf2008-07-26 23:55:29292 // RenderWidget IPC message handlers
[email protected]c084330e02013-04-27 01:08:15293 void OnHandleInputEvent(const WebKit::WebInputEvent* event,
[email protected]c2eaa8f2013-05-10 02:41:55294 const cc::LatencyInfo& latency_info,
[email protected]c084330e02013-04-27 01:08:15295 bool keyboard_shortcut);
[email protected]34202de2013-05-06 23:36:22296 void OnCursorVisibilityChange(bool is_visible);
[email protected]c084330e02013-04-27 01:08:15297 void OnMouseCaptureLost();
298 virtual void OnSetFocus(bool enable);
initial.commit09911bf2008-07-26 23:55:29299 void OnClose();
[email protected]fc4404d2012-11-07 19:53:30300 void OnCreatingNewAck();
[email protected]30f75e62009-02-25 22:01:00301 virtual void OnResize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44302 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40303 float overdraw_bottom_height,
[email protected]ee41e7d22011-10-14 19:34:09304 const gfx::Rect& resizer_rect,
305 bool is_fullscreen);
[email protected]b5913d72012-02-07 22:26:54306 void OnChangeResizeRect(const gfx::Rect& resizer_rect);
[email protected]941e4552010-02-01 21:23:43307 virtual void OnWasHidden();
[email protected]9e2e4632012-07-27 16:38:41308 virtual void OnWasShown(bool needs_repainting);
[email protected]992db4c2011-05-12 15:37:15309 virtual void OnWasSwappedOut();
[email protected]53d3f302009-12-21 04:42:05310 void OnUpdateRectAck();
[email protected]8400e032010-02-26 18:50:11311 void OnCreateVideoAck(int32 video_id);
312 void OnUpdateVideoAck(int32 video_id);
[email protected]2533ce12009-05-09 00:02:24313 void OnRequestMoveAck();
[email protected]fa7b1dc2010-06-23 17:53:04314 void OnSetInputMethodActive(bool is_active);
[email protected]56ea1a62011-05-30 07:05:57315 virtual void OnImeSetComposition(
[email protected]fa7b1dc2010-06-23 17:53:04316 const string16& text,
317 const std::vector<WebKit::WebCompositionUnderline>& underlines,
318 int selection_start,
319 int selection_end);
[email protected]4de6d1692011-10-12 08:45:44320 virtual void OnImeConfirmComposition(
321 const string16& text, const ui::Range& replacement_range);
[email protected]3d9ec5052013-01-02 22:05:25322 void OnPaintAtSize(const TransportDIB::Handle& dib_id,
323 int tag,
324 const gfx::Size& page_size,
325 const gfx::Size& desired_size);
[email protected]0bc1f572013-04-17 01:46:31326 void OnRepaint(gfx::Size size_to_paint);
[email protected]4a9dba42013-04-29 18:24:22327 void OnSmoothScrollCompleted();
[email protected]4873c7d2009-07-16 06:36:28328 void OnSetTextDirection(WebKit::WebTextDirection direction);
[email protected]872ae5b2011-05-26 20:20:50329 void OnGetFPS();
[email protected]6131a642012-06-15 23:26:53330 void OnScreenInfoChanged(const WebKit::WebScreenInfo& screen_info);
[email protected]80ad8622012-11-07 16:33:03331 void OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
332 const gfx::Rect& window_screen_rect);
[email protected]105dffb42013-02-20 03:46:21333#if defined(OS_ANDROID)
334 void OnImeBatchStateChanged(bool is_begin);
[email protected]2384b6c2013-02-28 23:58:51335 void OnShowImeIfNeeded();
[email protected]105dffb42013-02-20 03:46:21336#endif
[email protected]51a49502013-03-23 01:50:19337 void OnSnapshot(const gfx::Rect& src_subrect);
initial.commit09911bf2008-07-26 23:55:29338
[email protected]847a2582013-03-09 02:29:51339 // Notify the compositor about a change in viewport size. This should be
340 // used only with auto resize mode WebWidgets, as normal WebWidgets should
341 // go through OnResize.
[email protected]97e1bf72013-03-06 14:06:05342 void AutoResizeCompositor();
343
[email protected]468ac582012-11-20 00:53:19344 virtual void SetDeviceScaleFactor(float device_scale_factor);
345
[email protected]29ed96a2012-02-04 18:12:16346 // Override points to notify derived classes that a paint has happened.
347 // WillInitiatePaint happens when we're about to generate a new bitmap and
348 // send it to the browser. DidInitiatePaint happens when that has completed,
349 // and subsequent rendering won't affect the painted content. DidFlushPaint
350 // happens once we've received the ACK that the screen has been updated.
351 // For a given paint operation, these overrides will always be called in the
352 // order WillInitiatePaint, DidInitiatePaint, DidFlushPaint.
353 virtual void WillInitiatePaint() {}
[email protected]00c39612010-03-06 02:53:28354 virtual void DidInitiatePaint() {}
355 virtual void DidFlushPaint() {}
[email protected]a2f6bc112009-06-27 16:27:25356
[email protected]65225772011-05-12 21:10:24357 // Override and return true when the widget is rendered with a graphics
[email protected]37a6f302011-07-11 23:43:08358 // context that supports asynchronous swapbuffers. When returning true, the
359 // subclass must call OnSwapBuffersPosted() when swap is posted,
360 // OnSwapBuffersComplete() when swaps complete, and OnSwapBuffersAborted if
361 // the context is lost.
[email protected]65225772011-05-12 21:10:24362 virtual bool SupportsAsynchronousSwapBuffers();
[email protected]ed7defa2013-03-12 21:29:59363 virtual GURL GetURLForGraphicsContext3D();
[email protected]65225772011-05-12 21:10:24364
[email protected]479b0172012-10-29 19:27:09365 virtual bool ForceCompositingModeEnabled();
366
[email protected]ed7defa2013-03-12 21:29:59367 // WebGraphicsContext3DSwapBuffersClient implementation.
368
369 // Called by a GraphicsContext associated with this view when swapbuffers
370 // is posted, completes or is aborted.
371 virtual void OnViewContextSwapBuffersPosted() OVERRIDE;
372 virtual void OnViewContextSwapBuffersComplete() OVERRIDE;
373 virtual void OnViewContextSwapBuffersAborted() OVERRIDE;
[email protected]65225772011-05-12 21:10:24374
[email protected]ca4847f2010-09-24 05:39:15375 // Detects if a suitable opaque plugin covers the given paint bounds with no
376 // compositing necessary.
377 //
[email protected]719b36f2010-12-22 20:36:46378 // Returns the plugin instance that's the source of the paint if the paint
379 // can be handled by just blitting the plugin bitmap. In this case, the
380 // location, clipping, and ID of the backing store will be filled into the
381 // given output parameters.
[email protected]ca4847f2010-09-24 05:39:15382 //
[email protected]719b36f2010-12-22 20:36:46383 // A return value of null means optimized painting can not be used and we
[email protected]ca4847f2010-09-24 05:39:15384 // should continue with the normal painting code path.
[email protected]719b36f2010-12-22 20:36:46385 virtual webkit::ppapi::PluginInstance* GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:15386 const gfx::Rect& paint_bounds,
387 TransportDIB** dib,
388 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:20389 gfx::Rect* clip,
390 float* scale_factor);
[email protected]ca4847f2010-09-24 05:39:15391
[email protected]d54169e92011-01-21 09:19:52392 // Gets the scroll offset of this widget, if this widget has a notion of
393 // scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:24394 virtual gfx::Vector2d GetScrollOffset();
[email protected]d54169e92011-01-21 09:19:52395
[email protected]bee16aab2009-08-26 15:55:03396 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
397 // use this method so that we can properly inform the RenderThread of our
398 // state.
399 void SetHidden(bool hidden);
400
[email protected]2b624c562011-10-27 22:58:26401 void WillToggleFullscreen();
402 void DidToggleFullscreen();
403
[email protected]674741932009-02-04 23:44:46404 bool next_paint_is_resize_ack() const;
405 bool next_paint_is_restore_ack() const;
406 void set_next_paint_is_resize_ack();
407 void set_next_paint_is_restore_ack();
408 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12409
[email protected]ce2b28e2012-08-09 15:53:57410 void set_throttle_input_events(bool throttle_input_events) {
411 throttle_input_events_ = throttle_input_events;
412 }
413
[email protected]e99ef6f2011-10-16 01:13:00414 // Checks if the text input state and compose inline mode have been changed.
[email protected]fa7b1dc2010-06-23 17:53:04415 // If they are changed, the new value will be sent to the browser process.
[email protected]3306f262012-09-21 19:20:42416 // |show_ime_if_needed| should be SHOW_IME_IF_NEEDED iff the update may cause
417 // the ime to be displayed, e.g. after a tap on an input field on mobile.
418 void UpdateTextInputState(ShowIme show_ime);
[email protected]e99ef6f2011-10-16 01:13:00419
420 // Checks if the selection bounds have been changed. If they are changed,
421 // the new value will be sent to the browser process.
[email protected]58b48a0d2012-06-13 07:01:35422 virtual void UpdateSelectionBounds();
423
424 // Checks if the composition range or composition character bounds have been
425 // changed. If they are changed, the new value will be sent to the browser
426 // process.
427 virtual void UpdateCompositionInfo(
428 const ui::Range& range,
429 const std::vector<gfx::Rect>& character_bounds);
430
[email protected]56ea1a62011-05-30 07:05:57431 // Override point to obtain that the current input method state and caret
432 // position.
[email protected]ad26ef42011-06-17 07:59:45433 virtual ui::TextInputType GetTextInputType();
[email protected]3f783362011-10-21 22:40:50434 virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end);
[email protected]5b739cb2012-08-21 20:35:21435 virtual ui::TextInputType WebKitToUiTextInputType(
436 WebKit::WebTextInputType type);
[email protected]ad26ef42011-06-17 07:59:45437
[email protected]58b48a0d2012-06-13 07:01:35438 // Override point to obtain that the current composition character bounds.
439 // In the case of surrogate pairs, the character is treated as two characters:
440 // the bounds for first character is actual one, and the bounds for second
441 // character is zero width rectangle.
442 virtual void GetCompositionCharacterBounds(
443 std::vector<gfx::Rect>* character_bounds);
444
445 // Returns true if the composition range or composition character bounds
446 // should be sent to the browser process.
447 bool ShouldUpdateCompositionInfo(
448 const ui::Range& range,
449 const std::vector<gfx::Rect>& bounds);
450
[email protected]ad26ef42011-06-17 07:59:45451 // Override point to obtain that the current input method state about
452 // composition text.
453 virtual bool CanComposeInline();
[email protected]56ea1a62011-05-30 07:05:57454
initial.commit09911bf2008-07-26 23:55:29455 // Tells the renderer it does not have focus. Used to prevent us from getting
456 // the focus on our own when the browser did not focus us.
457 void ClearFocus();
458
[email protected]2533ce12009-05-09 00:02:24459 // Set the pending window rect.
460 // Because the real render_widget is hosted in another process, there is
461 // a time period where we may have set a new window rect which has not yet
462 // been processed by the browser. So we maintain a pending window rect
463 // size. If JS code sets the WindowRect, and then immediately calls
464 // GetWindowRect() we'll use this pending window rect as the size.
465 void SetPendingWindowRect(const WebKit::WebRect& r);
466
[email protected]446705872009-09-10 07:22:48467 // Called by OnHandleInputEvent() to notify subclasses that a key event was
468 // just handled.
469 virtual void DidHandleKeyEvent() {}
470
[email protected]67bfb83f2011-09-22 03:36:37471 // Called by OnHandleInputEvent() to notify subclasses that a mouse event is
472 // about to be handled.
473 // Returns true if no further handling is needed. In that case, the event
474 // won't be sent to WebKit or trigger DidHandleMouseEvent().
475 virtual bool WillHandleMouseEvent(const WebKit::WebMouseEvent& event);
476
[email protected]41d86852012-11-07 12:23:24477 // Called by OnHandleInputEvent() to notify subclasses that a gesture event is
478 // about to be handled.
479 // Returns true if no further handling is needed. In that case, the event
480 // won't be sent to WebKit.
481 virtual bool WillHandleGestureEvent(const WebKit::WebGestureEvent& event);
482
[email protected]6a8ddba52010-09-05 04:38:06483 // Called by OnHandleInputEvent() to notify subclasses that a mouse event was
484 // just handled.
485 virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {}
486
[email protected]2d0f2e92011-10-03 09:02:24487 // Called by OnHandleInputEvent() to notify subclasses that a touch event was
488 // just handled.
489 virtual void DidHandleTouchEvent(const WebKit::WebTouchEvent& event) {}
490
[email protected]3d5c243b2012-11-30 00:26:01491 // Check whether the WebWidget has any touch event handlers registered
492 // at the given point.
493 virtual bool HasTouchEventHandlersAt(const gfx::Point& point) const;
494
[email protected]ce6689f2013-03-29 12:52:55495 // Check whether the WebWidget has any touch event handlers registered.
496 virtual void hasTouchEventHandlers(bool has_handlers);
497
[email protected]ed7defa2013-03-12 21:29:59498 // Creates a 3D context associated with this view.
[email protected]3ae68c52013-04-12 06:10:05499 WebGraphicsContext3DCommandBufferImpl* CreateGraphicsContext3D(
[email protected]ed7defa2013-03-12 21:29:59500 const WebKit::WebGraphicsContext3D::Attributes& attributes);
501
[email protected]51a49502013-03-23 01:50:19502 bool OnSnapshotHelper(const gfx::Rect& src_subrect, SkBitmap* bitmap);
503
initial.commit09911bf2008-07-26 23:55:29504 // Routing ID that allows us to communicate to the parent browser process
505 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
506 int32 routing_id_;
507
[email protected]9f4f3322012-01-18 22:29:56508 int32 surface_id_;
509
[email protected]c5b3b5e2009-02-13 06:41:11510 // We are responsible for destroying this object via its Close method.
[email protected]4873c7d2009-07-16 06:36:28511 WebKit::WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29512
[email protected]8926c602013-01-23 05:32:06513 // This is lazily constructed and must not outlive webwidget_.
[email protected]ba91a792013-02-06 09:48:28514 scoped_ptr<RenderWidgetCompositor> compositor_;
[email protected]8926c602013-01-23 05:32:06515
initial.commit09911bf2008-07-26 23:55:29516 // Set to the ID of the view that initiated creating this view, if any. When
517 // the view was initiated by the browser (the common case), this will be
518 // MSG_ROUTING_NONE. This is used in determining ownership when opening
519 // child tabs. See RenderWidget::createWebViewWithRequest.
520 //
521 // This ID may refer to an invalid view if that view is closed before this
522 // view is.
523 int32 opener_id_;
524
525 // The position where this view should be initially shown.
526 gfx::Rect initial_pos_;
527
[email protected]fc4404d2012-11-07 19:53:30528 bool init_complete_;
initial.commit09911bf2008-07-26 23:55:29529
530 // We store the current cursor object so we can avoid spamming SetCursor
531 // messages.
532 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59533
initial.commit09911bf2008-07-26 23:55:29534 // The size of the RenderWidget.
535 gfx::Size size_;
536
[email protected]1f792d52013-05-22 06:52:45537 // When short-circuiting size updates, the browser might not know about the
538 // current size of the RenderWidget. To be able to correctly predict when the
539 // browser expects a resize ack, keep track of the size the browser thinks
540 // this RenderWidget should have.
541 gfx::Size size_browser_expects_;
542
[email protected]b4d08452010-10-05 17:34:35543 // The TransportDIB that is being used to transfer an image to the browser.
544 TransportDIB* current_paint_buf_;
initial.commit09911bf2008-07-26 23:55:29545
[email protected]552e6002009-11-19 05:24:57546 PaintAggregator paint_aggregator_;
initial.commit09911bf2008-07-26 23:55:29547
[email protected]60d47ac2013-03-01 23:42:44548 // The size of the view's backing surface in non-DPI-adjusted pixels.
549 gfx::Size physical_backing_size_;
550
[email protected]d9083762013-03-24 01:36:40551 // The height of the physical backing surface that is overdrawn opaquely in
552 // the browser, for example by an on-screen-keyboard (in DPI-adjusted pixels).
553 float overdraw_bottom_height_;
554
[email protected]f21c613a2009-02-12 14:46:17555 // The area that must be reserved for drawing the resize corner.
556 gfx::Rect resizer_rect_;
557
[email protected]53d3f302009-12-21 04:42:05558 // Flags for the next ViewHostMsg_UpdateRect message.
initial.commit09911bf2008-07-26 23:55:29559 int next_paint_flags_;
560
[email protected]872ae5b2011-05-26 20:20:50561 // Filtered time per frame based on UpdateRect messages.
562 float filtered_time_per_frame_;
563
[email protected]53d3f302009-12-21 04:42:05564 // True if we are expecting an UpdateRect_ACK message (i.e., that a
565 // UpdateRect message has been sent).
566 bool update_reply_pending_;
initial.commit09911bf2008-07-26 23:55:29567
[email protected]847a2582013-03-09 02:29:51568 // Whether the WebWidget is in auto resize mode, which is used for example
569 // by extension popups.
570 bool auto_resize_mode_;
571
[email protected]ea3ee0a2012-05-15 03:43:09572 // True if we need to send an UpdateRect message to notify the browser about
573 // an already-completed auto-resize.
574 bool need_update_rect_for_auto_resize_;
575
[email protected]65225772011-05-12 21:10:24576 // True if the underlying graphics context supports asynchronous swap.
577 // Cached on the RenderWidget because determining support is costly.
578 bool using_asynchronous_swapbuffers_;
579
580 // Number of OnSwapBuffersComplete we are expecting. Incremented each time
581 // WebWidget::composite has been been performed when the RenderWidget subclass
582 // SupportsAsynchronousSwapBuffers. Decremented in OnSwapBuffers. Will block
583 // rendering.
584 int num_swapbuffers_complete_pending_;
585
586 // When accelerated rendering is on, is the maximum number of swapbuffers that
587 // can be outstanding before we start throttling based on
588 // OnSwapBuffersComplete callback.
[email protected]82ca9b92011-09-12 23:33:07589 static const int kMaxSwapBuffersPending = 2;
[email protected]65225772011-05-12 21:10:24590
initial.commit09911bf2008-07-26 23:55:29591 // Set to true if we should ignore RenderWidget::Show calls.
592 bool did_show_;
593
594 // Indicates that we shouldn't bother generated paint events.
595 bool is_hidden_;
596
[email protected]ee41e7d22011-10-14 19:34:09597 // Indicates that we are in fullscreen mode.
598 bool is_fullscreen_;
599
initial.commit09911bf2008-07-26 23:55:29600 // Indicates that we should be repainted when restored. This flag is set to
601 // true if we receive an invalidation / scroll event from webkit while our
602 // is_hidden_ flag is set to true. This is used to force a repaint once we
603 // restore to account for the fact that our host would not know about the
604 // invalidation / scroll event(s) from webkit while we are hidden.
605 bool needs_repainting_on_restore_;
606
607 // Indicates whether we have been focused/unfocused by the browser.
608 bool has_focus_;
609
[email protected]5dd768212009-08-13 23:34:49610 // Are we currently handling an input event?
611 bool handling_input_event_;
612
[email protected]e8f775f2013-02-14 21:00:50613 // Are we currently handling an ime event?
614 bool handling_ime_event_;
615
initial.commit09911bf2008-07-26 23:55:29616 // True if we have requested this widget be closed. No more messages will
617 // be sent, except for a Close.
618 bool closing_;
619
[email protected]992db4c2011-05-12 15:37:15620 // Whether this RenderWidget is currently swapped out, such that the view is
621 // being rendered by another process. If all RenderWidgets in a process are
622 // swapped out, the process can exit.
623 bool is_swapped_out_;
624
[email protected]fa7b1dc2010-06-23 17:53:04625 // Indicates if an input method is active in the browser process.
626 bool input_method_is_active_;
initial.commit09911bf2008-07-26 23:55:29627
[email protected]5b739cb2012-08-21 20:35:21628 // Stores information about the current text input.
629 WebKit::WebTextInputInfo text_input_info_;
630
[email protected]fa7b1dc2010-06-23 17:53:04631 // Stores the current text input type of |webwidget_|.
[email protected]ad26ef42011-06-17 07:59:45632 ui::TextInputType text_input_type_;
633
634 // Stores the current type of composition text rendering of |webwidget_|.
635 bool can_compose_inline_;
[email protected]fa7b1dc2010-06-23 17:53:04636
[email protected]e99ef6f2011-10-16 01:13:00637 // Stores the current selection bounds.
[email protected]7c8873e2013-02-05 08:03:01638 gfx::Rect selection_focus_rect_;
639 gfx::Rect selection_anchor_rect_;
initial.commit09911bf2008-07-26 23:55:29640
[email protected]58b48a0d2012-06-13 07:01:35641 // Stores the current composition character bounds.
642 std::vector<gfx::Rect> composition_character_bounds_;
643
644 // Stores the current composition range.
645 ui::Range composition_range_;
646
[email protected]3e2b375b2010-04-07 17:03:12647 // The kind of popup this widget represents, NONE if not a popup.
648 WebKit::WebPopupType popup_type_;
[email protected]0ebf3872008-11-07 21:35:03649
initial.commit09911bf2008-07-26 23:55:29650 // Holds all the needed plugin window moves for a scroll.
[email protected]191eb3f72010-12-21 06:27:50651 typedef std::vector<webkit::npapi::WebPluginGeometry> WebPluginGeometryVector;
[email protected]268654772009-08-06 23:02:04652 WebPluginGeometryVector plugin_window_moves_;
initial.commit09911bf2008-07-26 23:55:29653
[email protected]699ab0d2009-04-23 23:19:14654 // A custom background for the widget.
655 SkBitmap background_;
656
[email protected]80ad8622012-11-07 16:33:03657 // While we are waiting for the browser to update window sizes, we track the
658 // pending size temporarily.
[email protected]2533ce12009-05-09 00:02:24659 int pending_window_rect_count_;
660 WebKit::WebRect pending_window_rect_;
661
[email protected]80ad8622012-11-07 16:33:03662 // The screen rects of the view and the window that contains it.
663 gfx::Rect view_screen_rect_;
664 gfx::Rect window_screen_rect_;
665
[email protected]12fbad812009-09-01 18:21:24666 scoped_ptr<IPC::Message> pending_input_event_ack_;
667
[email protected]b68a0e52011-12-08 15:11:12668 // Indicates if the next sequence of Char events should be suppressed or not.
669 bool suppress_next_char_events_;
670
[email protected]a79d8a632010-11-18 22:35:56671 // Set to true if painting to the window is handled by the accelerated
672 // compositor.
673 bool is_accelerated_compositing_active_;
[email protected]edbcde932010-05-07 17:10:46674
[email protected]350ce8702012-03-09 04:23:38675 base::OneShotTimer<RenderWidget> animation_timer_;
[email protected]5f8b1022011-01-21 23:34:50676 base::Time animation_floor_time_;
677 bool animation_update_pending_;
[email protected]65225772011-05-12 21:10:24678 bool invalidation_task_posted_;
[email protected]5f8b1022011-01-21 23:34:50679
[email protected]bd37ae252011-06-03 01:28:18680 bool has_disable_gpu_vsync_switch_;
[email protected]0fb93f52011-05-18 23:13:56681 base::TimeTicks last_do_deferred_update_time_;
682
[email protected]b63d58d2012-11-26 22:37:44683 cc::RenderingStats software_stats_;
[email protected]fef5e3972012-08-07 03:59:47684
[email protected]aa4117f2011-12-09 22:19:21685 // UpdateRect parameters for the current compositing pass. This is used to
686 // pass state between DoDeferredUpdate and OnSwapBuffersPosted.
687 scoped_ptr<ViewHostMsg_UpdateRect_Params> pending_update_params_;
688
689 // Queue of UpdateRect messages corresponding to a SwapBuffers. We want to
690 // delay sending of UpdateRect until the corresponding SwapBuffers has been
691 // executed. Since we can have several in flight, we need to keep them in a
692 // queue. Note: some SwapBuffers may not correspond to an update, in which
693 // case NULL is added to the queue.
694 std::deque<ViewHostMsg_UpdateRect*> updates_pending_swap_;
695
[email protected]842f10652012-06-06 01:54:04696 // Properties of the screen hosting this RenderWidget instance.
697 WebKit::WebScreenInfo screen_info_;
698
[email protected]f1cccb32012-06-06 18:29:59699 // The device scale factor. This value is computed from the DPI entries in
700 // |screen_info_| on some platforms, and defaults to 1 on other platforms.
[email protected]faec7b12012-06-19 14:42:13701 float device_scale_factor_;
[email protected]f1cccb32012-06-06 18:29:59702
[email protected]ce2b28e2012-08-09 15:53:57703 // Specifies whether input event throttling is enabled for this widget.
704 bool throttle_input_events_;
705
[email protected]0e241b4b2012-08-18 09:06:27706 // State associated with the BeginSmoothScroll synthetic scrolling function.
[email protected]4a9dba42013-04-29 18:24:22707 SmoothScrollCompletionCallback pending_smooth_scroll_gesture_;
[email protected]0e241b4b2012-08-18 09:06:27708
[email protected]cb6430932012-10-31 00:53:36709 // Specified whether the compositor will run in its own thread.
710 bool is_threaded_compositing_enabled_;
711
[email protected]a2b5ded2013-05-20 21:32:53712 // Specifies whether overscroll notifications are forwarded to the host.
713 bool overscroll_notifications_enabled_;
714
[email protected]ed7defa2013-03-12 21:29:59715 base::WeakPtrFactory<RenderWidget> weak_ptr_factory_;
716
[email protected]05d478752009-04-08 23:38:16717 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:29718};
719
[email protected]e9ff79c2012-10-19 21:31:26720} // namespace content
721
[email protected]2cff0052011-03-18 16:51:44722#endif // CONTENT_RENDERER_RENDER_WIDGET_H_