blob: decdc697e3f8c288b70a65f65edbe8027f684f86 [file] [log] [blame]
[email protected]b9b751f22011-03-25 14:04:121// Copyright (c) 2011 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commit09911bf2008-07-26 23:55:298
9#include <vector>
[email protected]010ea08a2009-10-11 20:21:3210
initial.commit09911bf2008-07-26 23:55:2911#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
[email protected]e68e62fa2009-02-20 02:00:0413#include "chrome/renderer/render_process.h"
[email protected]921f1592011-03-18 00:41:0214#include "content/renderer/paint_aggregator.h"
[email protected]946d1b22009-07-22 23:57:2115#include "ipc/ipc_channel.h"
[email protected]8bd0fe62011-01-17 06:44:3716#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderline.h"
17#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h"
18#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
19#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h"
20#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextInputType.h"
21#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidgetClient.h"
[email protected]d65adb12010-04-28 17:26:4922#include "third_party/skia/include/core/SkBitmap.h"
[email protected]08397d52011-02-05 01:53:3823#include "ui/gfx/native_widget_types.h"
24#include "ui/gfx/rect.h"
25#include "ui/gfx/size.h"
[email protected]b9b751f22011-03-25 14:04:1226#include "ui/gfx/surface/transport_dib.h"
initial.commit09911bf2008-07-26 23:55:2927#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2928
[email protected]8085dbc82008-09-26 22:53:4429class RenderThreadBase;
30
[email protected]46f36a492010-07-28 19:36:4131namespace gfx {
32class Point;
33}
34
[email protected]484955942010-08-19 16:13:1835namespace IPC {
36class SyncMessage;
37}
38
[email protected]46f36a492010-07-28 19:36:4139namespace skia {
40class PlatformCanvas;
41}
42
[email protected]88efb7ec2009-07-14 16:32:5943namespace WebKit {
[email protected]6a8ddba52010-09-05 04:38:0644class WebMouseEvent;
[email protected]484955942010-08-19 16:13:1845class WebWidget;
[email protected]88efb7ec2009-07-14 16:32:5946struct WebPopupMenuInfo;
47}
48
[email protected]191eb3f72010-12-21 06:27:5049namespace webkit {
50namespace npapi {
[email protected]f103ab72009-09-02 17:10:5951struct WebPluginGeometry;
[email protected]719b36f2010-12-22 20:36:4652} // namespace npapi
53
54namespace ppapi {
55class PluginInstance;
56} // namespace ppapi
57} // namespace webkit
[email protected]f103ab72009-09-02 17:10:5958
initial.commit09911bf2008-07-26 23:55:2959// RenderWidget provides a communication bridge between a WebWidget and
60// a RenderWidgetHost, the latter of which lives in a different process.
61class RenderWidget : public IPC::Channel::Listener,
62 public IPC::Message::Sender,
[email protected]4873c7d2009-07-16 06:36:2863 virtual public WebKit::WebWidgetClient,
initial.commit09911bf2008-07-26 23:55:2964 public base::RefCounted<RenderWidget> {
65 public:
66 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]8085dbc82008-09-26 22:53:4467 // RenderView that this widget lives inside. The render_thread is any
[email protected]8930d472009-02-21 08:05:2868 // RenderThreadBase implementation, mostly commonly RenderThread::current().
[email protected]0ebf3872008-11-07 21:35:0369 static RenderWidget* Create(int32 opener_id,
70 RenderThreadBase* render_thread,
[email protected]3e2b375b2010-04-07 17:03:1271 WebKit::WebPopupType popup_type);
initial.commit09911bf2008-07-26 23:55:2972
[email protected]484955942010-08-19 16:13:1873 // Creates a WebWidget based on the popup type.
74 static WebKit::WebWidget* CreateWebWidget(RenderWidget* render_widget);
75
initial.commit09911bf2008-07-26 23:55:2976 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
77 // not yet assigned a view ID, in which case, the process MUST NOT send
78 // messages with this ID to the parent.
79 int32 routing_id() const {
80 return routing_id_;
81 }
82
83 // May return NULL when the window is closing.
[email protected]4873c7d2009-07-16 06:36:2884 WebKit::WebWidget* webwidget() const {
initial.commit09911bf2008-07-26 23:55:2985 return webwidget_;
86 }
87
[email protected]c1f50aa2010-02-18 03:46:5788 gfx::NativeViewId host_window() const {
89 return host_window_;
90 }
91
[email protected]589621b2010-09-23 22:01:0792 bool has_focus() const { return has_focus_; }
93
initial.commit09911bf2008-07-26 23:55:2994 // IPC::Channel::Listener
[email protected]a95986a82010-12-24 06:19:2895 virtual bool OnMessageReceived(const IPC::Message& msg);
initial.commit09911bf2008-07-26 23:55:2996
97 // IPC::Message::Sender
98 virtual bool Send(IPC::Message* msg);
99
[email protected]4873c7d2009-07-16 06:36:28100 // WebKit::WebWidgetClient
101 virtual void didInvalidateRect(const WebKit::WebRect&);
102 virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect);
[email protected]a79d8a632010-11-18 22:35:56103 virtual void didActivateAcceleratedCompositing(bool active);
[email protected]f98d7e3c2010-09-13 22:30:46104 virtual void scheduleComposite();
[email protected]5f8b1022011-01-21 23:34:50105 virtual void scheduleAnimation();
[email protected]4873c7d2009-07-16 06:36:28106 virtual void didFocus();
107 virtual void didBlur();
108 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
109 virtual void closeWidgetSoon();
110 virtual void show(WebKit::WebNavigationPolicy);
111 virtual void runModal() {}
112 virtual WebKit::WebRect windowRect();
113 virtual void setWindowRect(const WebKit::WebRect&);
114 virtual WebKit::WebRect windowResizerRect();
115 virtual WebKit::WebRect rootWindowRect();
116 virtual WebKit::WebScreenInfo screenInfo();
[email protected]fa7b1dc2010-06-23 17:53:04117 virtual void resetInputMethod();
[email protected]4873c7d2009-07-16 06:36:28118
119 // Called when a plugin is moved. These events are queued up and sent with
120 // the next paint or scroll message to the host.
[email protected]191eb3f72010-12-21 06:27:50121 void SchedulePluginMove(const webkit::npapi::WebPluginGeometry& move);
initial.commit09911bf2008-07-26 23:55:29122
[email protected]268654772009-08-06 23:02:04123 // Called when a plugin window has been destroyed, to make sure the currently
124 // pending moves don't try to reference it.
125 void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
126
initial.commit09911bf2008-07-26 23:55:29127 // Close the underlying WebWidget.
[email protected]60c42a8c72009-10-09 04:08:59128 virtual void Close();
initial.commit09911bf2008-07-26 23:55:29129
130 protected:
[email protected]8085dbc82008-09-26 22:53:44131 // Friend RefCounted so that the dtor can be non-public. Using this class
132 // without ref-counting is an error.
133 friend class base::RefCounted<RenderWidget>;
[email protected]7339cd22010-10-27 00:11:20134 // For unit tests.
135 friend class RenderWidgetTest;
[email protected]8085dbc82008-09-26 22:53:44136
[email protected]3e2b375b2010-04-07 17:03:12137 RenderWidget(RenderThreadBase* render_thread,
138 WebKit::WebPopupType popup_type);
[email protected]8085dbc82008-09-26 22:53:44139 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29140
141 // Initializes this view with the given opener. CompleteInit must be called
142 // later.
143 void Init(int32 opener_id);
144
[email protected]484955942010-08-19 16:13:18145 // Called by Init and subclasses to perform initialization.
146 void DoInit(int32 opener_id,
147 WebKit::WebWidget* web_widget,
148 IPC::SyncMessage* create_widget_message);
149
initial.commit09911bf2008-07-26 23:55:29150 // Finishes creation of a pending view started with Init.
[email protected]18bcc3c2009-01-27 21:39:15151 void CompleteInit(gfx::NativeViewId parent);
initial.commit09911bf2008-07-26 23:55:29152
[email protected]661eb9d2009-02-03 02:11:48153 // Paints the given rectangular region of the WebWidget into canvas (a
154 // shared memory segment returned by AllocPaintBuf on Windows). The caller
155 // must ensure that the given rect fits within the bounds of the WebWidget.
[email protected]4fb66842009-12-04 21:41:00156 void PaintRect(const gfx::Rect& rect, const gfx::Point& canvas_origin,
157 skia::PlatformCanvas* canvas);
158
159 // Paints a border at the given rect for debugging purposes.
160 void PaintDebugBorder(const gfx::Rect& rect, skia::PlatformCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29161
[email protected]52ccd0ea2011-02-16 01:09:05162 void AnimationCallback();
163 void AnimateIfNeeded();
[email protected]552e6002009-11-19 05:24:57164 void CallDoDeferredUpdate();
165 void DoDeferredUpdate();
[email protected]2533ce12009-05-09 00:02:24166 void DoDeferredClose();
167 void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
initial.commit09911bf2008-07-26 23:55:29168
[email protected]699ab0d2009-04-23 23:19:14169 // Set the background of the render widget to a bitmap. The bitmap will be
170 // tiled in both directions if it isn't big enough to fill the area. This is
171 // mainly intended to be used in conjuction with WebView::SetIsTransparent().
172 virtual void SetBackground(const SkBitmap& bitmap);
173
initial.commit09911bf2008-07-26 23:55:29174 // RenderWidget IPC message handlers
175 void OnClose();
[email protected]18bcc3c2009-01-27 21:39:15176 void OnCreatingNewAck(gfx::NativeViewId parent);
[email protected]30f75e62009-02-25 22:01:00177 virtual void OnResize(const gfx::Size& new_size,
178 const gfx::Rect& resizer_rect);
[email protected]941e4552010-02-01 21:23:43179 virtual void OnWasHidden();
180 virtual void OnWasRestored(bool needs_repainting);
[email protected]53d3f302009-12-21 04:42:05181 void OnUpdateRectAck();
[email protected]8400e032010-02-26 18:50:11182 void OnCreateVideoAck(int32 video_id);
183 void OnUpdateVideoAck(int32 video_id);
[email protected]2533ce12009-05-09 00:02:24184 void OnRequestMoveAck();
initial.commit09911bf2008-07-26 23:55:29185 void OnHandleInputEvent(const IPC::Message& message);
186 void OnMouseCaptureLost();
[email protected]1e6e3c992010-02-08 15:52:13187 virtual void OnSetFocus(bool enable);
[email protected]fa7b1dc2010-06-23 17:53:04188 void OnSetInputMethodActive(bool is_active);
189 void OnImeSetComposition(
190 const string16& text,
191 const std::vector<WebKit::WebCompositionUnderline>& underlines,
192 int selection_start,
193 int selection_end);
[email protected]6b349652011-01-05 18:36:24194 void OnImeConfirmComposition(const string16& text);
[email protected]d65adb12010-04-28 17:26:49195 void OnMsgPaintAtSize(const TransportDIB::Handle& dib_id,
[email protected]c88c9442010-07-19 18:55:09196 int tag,
[email protected]948f7ab72010-05-28 23:48:08197 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:49198 const gfx::Size& desired_size);
[email protected]ec7dc112008-08-06 05:30:12199 void OnMsgRepaint(const gfx::Size& size_to_paint);
[email protected]4873c7d2009-07-16 06:36:28200 void OnSetTextDirection(WebKit::WebTextDirection direction);
initial.commit09911bf2008-07-26 23:55:29201
[email protected]00c39612010-03-06 02:53:28202 // Override point to notify derived classes that a paint has happened.
203 // DidInitiatePaint happens when we've generated a new bitmap and sent it to
204 // the browser. DidFlushPaint happens once we've received the ACK that the
205 // screen has actually been updated.
206 virtual void DidInitiatePaint() {}
207 virtual void DidFlushPaint() {}
[email protected]a2f6bc112009-06-27 16:27:25208
[email protected]ca4847f2010-09-24 05:39:15209 // Detects if a suitable opaque plugin covers the given paint bounds with no
210 // compositing necessary.
211 //
[email protected]719b36f2010-12-22 20:36:46212 // Returns the plugin instance that's the source of the paint if the paint
213 // can be handled by just blitting the plugin bitmap. In this case, the
214 // location, clipping, and ID of the backing store will be filled into the
215 // given output parameters.
[email protected]ca4847f2010-09-24 05:39:15216 //
[email protected]719b36f2010-12-22 20:36:46217 // A return value of null means optimized painting can not be used and we
[email protected]ca4847f2010-09-24 05:39:15218 // should continue with the normal painting code path.
[email protected]719b36f2010-12-22 20:36:46219 virtual webkit::ppapi::PluginInstance* GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:15220 const gfx::Rect& paint_bounds,
221 TransportDIB** dib,
222 gfx::Rect* location,
223 gfx::Rect* clip);
224
[email protected]d54169e92011-01-21 09:19:52225 // Gets the scroll offset of this widget, if this widget has a notion of
226 // scroll offset.
[email protected]bcaf2272011-02-15 15:29:43227 virtual gfx::Point GetScrollOffset();
[email protected]d54169e92011-01-21 09:19:52228
[email protected]bee16aab2009-08-26 15:55:03229 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
230 // use this method so that we can properly inform the RenderThread of our
231 // state.
232 void SetHidden(bool hidden);
233
[email protected]882daa92009-11-05 16:31:31234 bool is_hidden() const { return is_hidden_; }
235
[email protected]53d3f302009-12-21 04:42:05236 // True if an UpdateRect_ACK message is pending.
237 bool update_reply_pending() const {
238 return update_reply_pending_;
initial.commit09911bf2008-07-26 23:55:29239 }
240
[email protected]674741932009-02-04 23:44:46241 bool next_paint_is_resize_ack() const;
242 bool next_paint_is_restore_ack() const;
243 void set_next_paint_is_resize_ack();
244 void set_next_paint_is_restore_ack();
245 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12246
[email protected]fa7b1dc2010-06-23 17:53:04247 // Checks if the input method state and caret position have been changed.
248 // If they are changed, the new value will be sent to the browser process.
249 void UpdateInputMethod();
initial.commit09911bf2008-07-26 23:55:29250
251 // Tells the renderer it does not have focus. Used to prevent us from getting
252 // the focus on our own when the browser did not focus us.
253 void ClearFocus();
254
[email protected]2533ce12009-05-09 00:02:24255 // Set the pending window rect.
256 // Because the real render_widget is hosted in another process, there is
257 // a time period where we may have set a new window rect which has not yet
258 // been processed by the browser. So we maintain a pending window rect
259 // size. If JS code sets the WindowRect, and then immediately calls
260 // GetWindowRect() we'll use this pending window rect as the size.
261 void SetPendingWindowRect(const WebKit::WebRect& r);
262
[email protected]446705872009-09-10 07:22:48263 // Called by OnHandleInputEvent() to notify subclasses that a key event was
264 // just handled.
265 virtual void DidHandleKeyEvent() {}
266
[email protected]6a8ddba52010-09-05 04:38:06267 // Called by OnHandleInputEvent() to notify subclasses that a mouse event was
268 // just handled.
269 virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {}
270
initial.commit09911bf2008-07-26 23:55:29271 // Routing ID that allows us to communicate to the parent browser process
272 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
273 int32 routing_id_;
274
[email protected]c5b3b5e2009-02-13 06:41:11275 // We are responsible for destroying this object via its Close method.
[email protected]4873c7d2009-07-16 06:36:28276 WebKit::WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29277
278 // Set to the ID of the view that initiated creating this view, if any. When
279 // the view was initiated by the browser (the common case), this will be
280 // MSG_ROUTING_NONE. This is used in determining ownership when opening
281 // child tabs. See RenderWidget::createWebViewWithRequest.
282 //
283 // This ID may refer to an invalid view if that view is closed before this
284 // view is.
285 int32 opener_id_;
286
[email protected]8085dbc82008-09-26 22:53:44287 // The thread that does our IPC.
288 RenderThreadBase* render_thread_;
289
initial.commit09911bf2008-07-26 23:55:29290 // The position where this view should be initially shown.
291 gfx::Rect initial_pos_;
292
293 // The window we are embedded within. TODO(darin): kill this.
[email protected]18bcc3c2009-01-27 21:39:15294 gfx::NativeViewId host_window_;
initial.commit09911bf2008-07-26 23:55:29295
296 // We store the current cursor object so we can avoid spamming SetCursor
297 // messages.
298 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59299
initial.commit09911bf2008-07-26 23:55:29300 // The size of the RenderWidget.
301 gfx::Size size_;
302
[email protected]b4d08452010-10-05 17:34:35303 // The TransportDIB that is being used to transfer an image to the browser.
304 TransportDIB* current_paint_buf_;
initial.commit09911bf2008-07-26 23:55:29305
[email protected]552e6002009-11-19 05:24:57306 PaintAggregator paint_aggregator_;
initial.commit09911bf2008-07-26 23:55:29307
[email protected]f21c613a2009-02-12 14:46:17308 // The area that must be reserved for drawing the resize corner.
309 gfx::Rect resizer_rect_;
310
[email protected]53d3f302009-12-21 04:42:05311 // Flags for the next ViewHostMsg_UpdateRect message.
initial.commit09911bf2008-07-26 23:55:29312 int next_paint_flags_;
313
[email protected]53d3f302009-12-21 04:42:05314 // True if we are expecting an UpdateRect_ACK message (i.e., that a
315 // UpdateRect message has been sent).
316 bool update_reply_pending_;
initial.commit09911bf2008-07-26 23:55:29317
318 // Set to true if we should ignore RenderWidget::Show calls.
319 bool did_show_;
320
321 // Indicates that we shouldn't bother generated paint events.
322 bool is_hidden_;
323
324 // Indicates that we should be repainted when restored. This flag is set to
325 // true if we receive an invalidation / scroll event from webkit while our
326 // is_hidden_ flag is set to true. This is used to force a repaint once we
327 // restore to account for the fact that our host would not know about the
328 // invalidation / scroll event(s) from webkit while we are hidden.
329 bool needs_repainting_on_restore_;
330
331 // Indicates whether we have been focused/unfocused by the browser.
332 bool has_focus_;
333
[email protected]5dd768212009-08-13 23:34:49334 // Are we currently handling an input event?
335 bool handling_input_event_;
336
initial.commit09911bf2008-07-26 23:55:29337 // True if we have requested this widget be closed. No more messages will
338 // be sent, except for a Close.
339 bool closing_;
340
[email protected]fa7b1dc2010-06-23 17:53:04341 // Indicates if an input method is active in the browser process.
342 bool input_method_is_active_;
initial.commit09911bf2008-07-26 23:55:29343
[email protected]fa7b1dc2010-06-23 17:53:04344 // Stores the current text input type of |webwidget_|.
345 WebKit::WebTextInputType text_input_type_;
346
347 // Stores the current caret bounds of input focus.
348 WebKit::WebRect caret_bounds_;
initial.commit09911bf2008-07-26 23:55:29349
[email protected]3e2b375b2010-04-07 17:03:12350 // The kind of popup this widget represents, NONE if not a popup.
351 WebKit::WebPopupType popup_type_;
[email protected]0ebf3872008-11-07 21:35:03352
initial.commit09911bf2008-07-26 23:55:29353 // Holds all the needed plugin window moves for a scroll.
[email protected]191eb3f72010-12-21 06:27:50354 typedef std::vector<webkit::npapi::WebPluginGeometry> WebPluginGeometryVector;
[email protected]268654772009-08-06 23:02:04355 WebPluginGeometryVector plugin_window_moves_;
initial.commit09911bf2008-07-26 23:55:29356
[email protected]699ab0d2009-04-23 23:19:14357 // A custom background for the widget.
358 SkBitmap background_;
359
[email protected]2533ce12009-05-09 00:02:24360 // While we are waiting for the browser to update window sizes,
361 // we track the pending size temporarily.
362 int pending_window_rect_count_;
363 WebKit::WebRect pending_window_rect_;
364
[email protected]12fbad812009-09-01 18:21:24365 scoped_ptr<IPC::Message> pending_input_event_ack_;
366
[email protected]867125a02009-12-10 06:01:48367 // Indicates if the next sequence of Char events should be suppressed or not.
368 bool suppress_next_char_events_;
369
[email protected]a79d8a632010-11-18 22:35:56370 // Set to true if painting to the window is handled by the accelerated
371 // compositor.
372 bool is_accelerated_compositing_active_;
[email protected]edbcde932010-05-07 17:10:46373
[email protected]5f8b1022011-01-21 23:34:50374 base::Time animation_floor_time_;
375 bool animation_update_pending_;
[email protected]52ccd0ea2011-02-16 01:09:05376 bool animation_task_posted_;
[email protected]5f8b1022011-01-21 23:34:50377
[email protected]05d478752009-04-08 23:38:16378 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:29379};
380
[email protected]2cff0052011-03-18 16:51:44381#endif // CONTENT_RENDERER_RENDER_WIDGET_H_