blob: 3b99f822de77d60a2eca962c1f39d8d6c86d7f65 [file] [log] [blame]
[email protected]05d478752009-04-08 23:38:161// Copyright (c) 2009 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]05d478752009-04-08 23:38:165#ifndef CHROME_RENDERER_RENDER_WIDGET_H_
6#define CHROME_RENDERER_RENDER_WIDGET_H_
initial.commit09911bf2008-07-26 23:55:297
8#include <vector>
[email protected]010ea08a2009-10-11 20:21:329
[email protected]d65adb12010-04-28 17:26:4910#include "app/surface/transport_dib.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/ref_counted.h"
[email protected]674741932009-02-04 23:44:4613#include "base/shared_memory.h"
[email protected]552e6002009-11-19 05:24:5714#include "chrome/renderer/paint_aggregator.h"
[email protected]e68e62fa2009-02-20 02:00:0415#include "chrome/renderer/render_process.h"
[email protected]5c7293a2010-03-17 06:40:5716#include "gfx/native_widget_types.h"
[email protected]e0fc2f12010-03-14 23:30:5917#include "gfx/point.h"
18#include "gfx/rect.h"
19#include "gfx/size.h"
[email protected]946d1b22009-07-22 23:57:2120#include "ipc/ipc_channel.h"
[email protected]661eb9d2009-02-03 02:11:4821#include "skia/ext/platform_canvas.h"
[email protected]fa7b1dc2010-06-23 17:53:0422#include "third_party/WebKit/WebKit/chromium/public/WebCompositionUnderline.h"
[email protected]3e2b375b2010-04-07 17:03:1223#include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h"
[email protected]418ed5ab2009-11-12 01:14:4924#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
25#include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h"
[email protected]fa7b1dc2010-06-23 17:53:0426#include "third_party/WebKit/WebKit/chromium/public/WebTextInputType.h"
[email protected]418ed5ab2009-11-12 01:14:4927#include "third_party/WebKit/WebKit/chromium/public/WebWidgetClient.h"
[email protected]d65adb12010-04-28 17:26:4928#include "third_party/skia/include/core/SkBitmap.h"
initial.commit09911bf2008-07-26 23:55:2929#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2930
[email protected]8085dbc82008-09-26 22:53:4431class RenderThreadBase;
[email protected]88efb7ec2009-07-14 16:32:5932struct ViewHostMsg_ShowPopup_Params;
[email protected]8085dbc82008-09-26 22:53:4433
[email protected]88efb7ec2009-07-14 16:32:5934namespace WebKit {
35struct WebPopupMenuInfo;
36}
37
[email protected]f103ab72009-09-02 17:10:5938namespace webkit_glue {
39struct WebPluginGeometry;
40}
41
initial.commit09911bf2008-07-26 23:55:2942// RenderWidget provides a communication bridge between a WebWidget and
43// a RenderWidgetHost, the latter of which lives in a different process.
44class RenderWidget : public IPC::Channel::Listener,
45 public IPC::Message::Sender,
[email protected]4873c7d2009-07-16 06:36:2846 virtual public WebKit::WebWidgetClient,
initial.commit09911bf2008-07-26 23:55:2947 public base::RefCounted<RenderWidget> {
48 public:
49 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]8085dbc82008-09-26 22:53:4450 // RenderView that this widget lives inside. The render_thread is any
[email protected]8930d472009-02-21 08:05:2851 // RenderThreadBase implementation, mostly commonly RenderThread::current().
[email protected]0ebf3872008-11-07 21:35:0352 static RenderWidget* Create(int32 opener_id,
53 RenderThreadBase* render_thread,
[email protected]3e2b375b2010-04-07 17:03:1254 WebKit::WebPopupType popup_type);
initial.commit09911bf2008-07-26 23:55:2955
[email protected]88efb7ec2009-07-14 16:32:5956 // Called after Create to configure a RenderWidget to be rendered by the host
57 // as a popup menu with the given data.
58 void ConfigureAsExternalPopupMenu(const WebKit::WebPopupMenuInfo& info);
59
initial.commit09911bf2008-07-26 23:55:2960 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
61 // not yet assigned a view ID, in which case, the process MUST NOT send
62 // messages with this ID to the parent.
63 int32 routing_id() const {
64 return routing_id_;
65 }
66
67 // May return NULL when the window is closing.
[email protected]4873c7d2009-07-16 06:36:2868 WebKit::WebWidget* webwidget() const {
initial.commit09911bf2008-07-26 23:55:2969 return webwidget_;
70 }
71
[email protected]c1f50aa2010-02-18 03:46:5772 gfx::NativeViewId host_window() const {
73 return host_window_;
74 }
75
initial.commit09911bf2008-07-26 23:55:2976 // IPC::Channel::Listener
77 virtual void OnMessageReceived(const IPC::Message& msg);
78
79 // IPC::Message::Sender
80 virtual bool Send(IPC::Message* msg);
81
[email protected]4873c7d2009-07-16 06:36:2882 // WebKit::WebWidgetClient
83 virtual void didInvalidateRect(const WebKit::WebRect&);
84 virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect);
85 virtual void didFocus();
86 virtual void didBlur();
87 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
88 virtual void closeWidgetSoon();
89 virtual void show(WebKit::WebNavigationPolicy);
90 virtual void runModal() {}
91 virtual WebKit::WebRect windowRect();
92 virtual void setWindowRect(const WebKit::WebRect&);
93 virtual WebKit::WebRect windowResizerRect();
94 virtual WebKit::WebRect rootWindowRect();
95 virtual WebKit::WebScreenInfo screenInfo();
[email protected]fa7b1dc2010-06-23 17:53:0496 virtual void resetInputMethod();
[email protected]4873c7d2009-07-16 06:36:2897
98 // Called when a plugin is moved. These events are queued up and sent with
99 // the next paint or scroll message to the host.
[email protected]f103ab72009-09-02 17:10:59100 void SchedulePluginMove(const webkit_glue::WebPluginGeometry& move);
initial.commit09911bf2008-07-26 23:55:29101
[email protected]268654772009-08-06 23:02:04102 // Called when a plugin window has been destroyed, to make sure the currently
103 // pending moves don't try to reference it.
104 void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
105
[email protected]b4b967e2009-04-22 11:33:05106 // Invalidates entire widget rect to generate a full repaint.
107 void GenerateFullRepaint();
108
initial.commit09911bf2008-07-26 23:55:29109 // Close the underlying WebWidget.
[email protected]60c42a8c72009-10-09 04:08:59110 virtual void Close();
initial.commit09911bf2008-07-26 23:55:29111
112 protected:
[email protected]8085dbc82008-09-26 22:53:44113 // Friend RefCounted so that the dtor can be non-public. Using this class
114 // without ref-counting is an error.
115 friend class base::RefCounted<RenderWidget>;
116
[email protected]3e2b375b2010-04-07 17:03:12117 RenderWidget(RenderThreadBase* render_thread,
118 WebKit::WebPopupType popup_type);
[email protected]8085dbc82008-09-26 22:53:44119 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29120
121 // Initializes this view with the given opener. CompleteInit must be called
122 // later.
123 void Init(int32 opener_id);
124
125 // Finishes creation of a pending view started with Init.
[email protected]18bcc3c2009-01-27 21:39:15126 void CompleteInit(gfx::NativeViewId parent);
initial.commit09911bf2008-07-26 23:55:29127
[email protected]661eb9d2009-02-03 02:11:48128 // Paints the given rectangular region of the WebWidget into canvas (a
129 // shared memory segment returned by AllocPaintBuf on Windows). The caller
130 // must ensure that the given rect fits within the bounds of the WebWidget.
[email protected]4fb66842009-12-04 21:41:00131 void PaintRect(const gfx::Rect& rect, const gfx::Point& canvas_origin,
132 skia::PlatformCanvas* canvas);
133
134 // Paints a border at the given rect for debugging purposes.
135 void PaintDebugBorder(const gfx::Rect& rect, skia::PlatformCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29136
[email protected]552e6002009-11-19 05:24:57137 void CallDoDeferredUpdate();
138 void DoDeferredUpdate();
[email protected]2533ce12009-05-09 00:02:24139 void DoDeferredClose();
140 void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
initial.commit09911bf2008-07-26 23:55:29141
[email protected]699ab0d2009-04-23 23:19:14142 // Set the background of the render widget to a bitmap. The bitmap will be
143 // tiled in both directions if it isn't big enough to fill the area. This is
144 // mainly intended to be used in conjuction with WebView::SetIsTransparent().
145 virtual void SetBackground(const SkBitmap& bitmap);
146
initial.commit09911bf2008-07-26 23:55:29147 // RenderWidget IPC message handlers
148 void OnClose();
[email protected]18bcc3c2009-01-27 21:39:15149 void OnCreatingNewAck(gfx::NativeViewId parent);
[email protected]30f75e62009-02-25 22:01:00150 virtual void OnResize(const gfx::Size& new_size,
151 const gfx::Rect& resizer_rect);
[email protected]941e4552010-02-01 21:23:43152 virtual void OnWasHidden();
153 virtual void OnWasRestored(bool needs_repainting);
[email protected]53d3f302009-12-21 04:42:05154 void OnUpdateRectAck();
[email protected]8400e032010-02-26 18:50:11155 void OnCreateVideoAck(int32 video_id);
156 void OnUpdateVideoAck(int32 video_id);
[email protected]2533ce12009-05-09 00:02:24157 void OnRequestMoveAck();
initial.commit09911bf2008-07-26 23:55:29158 void OnHandleInputEvent(const IPC::Message& message);
159 void OnMouseCaptureLost();
[email protected]1e6e3c992010-02-08 15:52:13160 virtual void OnSetFocus(bool enable);
[email protected]fa7b1dc2010-06-23 17:53:04161 void OnSetInputMethodActive(bool is_active);
162 void OnImeSetComposition(
163 const string16& text,
164 const std::vector<WebKit::WebCompositionUnderline>& underlines,
165 int selection_start,
166 int selection_end);
167 void OnImeConfirmComposition();
[email protected]d65adb12010-04-28 17:26:49168 void OnMsgPaintAtSize(const TransportDIB::Handle& dib_id,
[email protected]c88c9442010-07-19 18:55:09169 int tag,
[email protected]948f7ab72010-05-28 23:48:08170 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:49171 const gfx::Size& desired_size);
[email protected]ec7dc112008-08-06 05:30:12172 void OnMsgRepaint(const gfx::Size& size_to_paint);
[email protected]4873c7d2009-07-16 06:36:28173 void OnSetTextDirection(WebKit::WebTextDirection direction);
initial.commit09911bf2008-07-26 23:55:29174
[email protected]00c39612010-03-06 02:53:28175 // Override point to notify derived classes that a paint has happened.
176 // DidInitiatePaint happens when we've generated a new bitmap and sent it to
177 // the browser. DidFlushPaint happens once we've received the ACK that the
178 // screen has actually been updated.
179 virtual void DidInitiatePaint() {}
180 virtual void DidFlushPaint() {}
[email protected]a2f6bc112009-06-27 16:27:25181
[email protected]bee16aab2009-08-26 15:55:03182 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
183 // use this method so that we can properly inform the RenderThread of our
184 // state.
185 void SetHidden(bool hidden);
186
[email protected]882daa92009-11-05 16:31:31187 bool is_hidden() const { return is_hidden_; }
188
[email protected]53d3f302009-12-21 04:42:05189 // True if an UpdateRect_ACK message is pending.
190 bool update_reply_pending() const {
191 return update_reply_pending_;
initial.commit09911bf2008-07-26 23:55:29192 }
193
[email protected]674741932009-02-04 23:44:46194 bool next_paint_is_resize_ack() const;
195 bool next_paint_is_restore_ack() const;
196 void set_next_paint_is_resize_ack();
197 void set_next_paint_is_restore_ack();
198 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12199
[email protected]fa7b1dc2010-06-23 17:53:04200 // Checks if the input method state and caret position have been changed.
201 // If they are changed, the new value will be sent to the browser process.
202 void UpdateInputMethod();
initial.commit09911bf2008-07-26 23:55:29203
204 // Tells the renderer it does not have focus. Used to prevent us from getting
205 // the focus on our own when the browser did not focus us.
206 void ClearFocus();
207
[email protected]2533ce12009-05-09 00:02:24208 // Set the pending window rect.
209 // Because the real render_widget is hosted in another process, there is
210 // a time period where we may have set a new window rect which has not yet
211 // been processed by the browser. So we maintain a pending window rect
212 // size. If JS code sets the WindowRect, and then immediately calls
213 // GetWindowRect() we'll use this pending window rect as the size.
214 void SetPendingWindowRect(const WebKit::WebRect& r);
215
[email protected]446705872009-09-10 07:22:48216 // Called by OnHandleInputEvent() to notify subclasses that a key event was
217 // just handled.
218 virtual void DidHandleKeyEvent() {}
219
initial.commit09911bf2008-07-26 23:55:29220 // Routing ID that allows us to communicate to the parent browser process
221 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
222 int32 routing_id_;
223
[email protected]c5b3b5e2009-02-13 06:41:11224 // We are responsible for destroying this object via its Close method.
[email protected]4873c7d2009-07-16 06:36:28225 WebKit::WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29226
227 // Set to the ID of the view that initiated creating this view, if any. When
228 // the view was initiated by the browser (the common case), this will be
229 // MSG_ROUTING_NONE. This is used in determining ownership when opening
230 // child tabs. See RenderWidget::createWebViewWithRequest.
231 //
232 // This ID may refer to an invalid view if that view is closed before this
233 // view is.
234 int32 opener_id_;
235
[email protected]8085dbc82008-09-26 22:53:44236 // The thread that does our IPC.
237 RenderThreadBase* render_thread_;
238
initial.commit09911bf2008-07-26 23:55:29239 // The position where this view should be initially shown.
240 gfx::Rect initial_pos_;
241
242 // The window we are embedded within. TODO(darin): kill this.
[email protected]18bcc3c2009-01-27 21:39:15243 gfx::NativeViewId host_window_;
initial.commit09911bf2008-07-26 23:55:29244
245 // We store the current cursor object so we can avoid spamming SetCursor
246 // messages.
247 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59248
initial.commit09911bf2008-07-26 23:55:29249 // The size of the RenderWidget.
250 gfx::Size size_;
251
[email protected]53d3f302009-12-21 04:42:05252 // The TransportDIB that is being used to transfer an image to the browser.
[email protected]e68e62fa2009-02-20 02:00:04253 TransportDIB* current_paint_buf_;
initial.commit09911bf2008-07-26 23:55:29254
[email protected]552e6002009-11-19 05:24:57255 PaintAggregator paint_aggregator_;
initial.commit09911bf2008-07-26 23:55:29256
[email protected]f21c613a2009-02-12 14:46:17257 // The area that must be reserved for drawing the resize corner.
258 gfx::Rect resizer_rect_;
259
[email protected]53d3f302009-12-21 04:42:05260 // Flags for the next ViewHostMsg_UpdateRect message.
initial.commit09911bf2008-07-26 23:55:29261 int next_paint_flags_;
262
[email protected]53d3f302009-12-21 04:42:05263 // True if we are expecting an UpdateRect_ACK message (i.e., that a
264 // UpdateRect message has been sent).
265 bool update_reply_pending_;
initial.commit09911bf2008-07-26 23:55:29266
267 // Set to true if we should ignore RenderWidget::Show calls.
268 bool did_show_;
269
270 // Indicates that we shouldn't bother generated paint events.
271 bool is_hidden_;
272
273 // Indicates that we should be repainted when restored. This flag is set to
274 // true if we receive an invalidation / scroll event from webkit while our
275 // is_hidden_ flag is set to true. This is used to force a repaint once we
276 // restore to account for the fact that our host would not know about the
277 // invalidation / scroll event(s) from webkit while we are hidden.
278 bool needs_repainting_on_restore_;
279
280 // Indicates whether we have been focused/unfocused by the browser.
281 bool has_focus_;
282
[email protected]5dd768212009-08-13 23:34:49283 // Are we currently handling an input event?
284 bool handling_input_event_;
285
initial.commit09911bf2008-07-26 23:55:29286 // True if we have requested this widget be closed. No more messages will
287 // be sent, except for a Close.
288 bool closing_;
289
[email protected]fa7b1dc2010-06-23 17:53:04290 // Indicates if an input method is active in the browser process.
291 bool input_method_is_active_;
initial.commit09911bf2008-07-26 23:55:29292
[email protected]fa7b1dc2010-06-23 17:53:04293 // Stores the current text input type of |webwidget_|.
294 WebKit::WebTextInputType text_input_type_;
295
296 // Stores the current caret bounds of input focus.
297 WebKit::WebRect caret_bounds_;
initial.commit09911bf2008-07-26 23:55:29298
[email protected]3e2b375b2010-04-07 17:03:12299 // The kind of popup this widget represents, NONE if not a popup.
300 WebKit::WebPopupType popup_type_;
[email protected]0ebf3872008-11-07 21:35:03301
initial.commit09911bf2008-07-26 23:55:29302 // Holds all the needed plugin window moves for a scroll.
[email protected]f103ab72009-09-02 17:10:59303 typedef std::vector<webkit_glue::WebPluginGeometry> WebPluginGeometryVector;
[email protected]268654772009-08-06 23:02:04304 WebPluginGeometryVector plugin_window_moves_;
initial.commit09911bf2008-07-26 23:55:29305
[email protected]699ab0d2009-04-23 23:19:14306 // A custom background for the widget.
307 SkBitmap background_;
308
[email protected]2533ce12009-05-09 00:02:24309 // While we are waiting for the browser to update window sizes,
310 // we track the pending size temporarily.
311 int pending_window_rect_count_;
312 WebKit::WebRect pending_window_rect_;
313
[email protected]88efb7ec2009-07-14 16:32:59314 scoped_ptr<ViewHostMsg_ShowPopup_Params> popup_params_;
315
[email protected]12fbad812009-09-01 18:21:24316 scoped_ptr<IPC::Message> pending_input_event_ack_;
317
[email protected]867125a02009-12-10 06:01:48318 // Indicates if the next sequence of Char events should be suppressed or not.
319 bool suppress_next_char_events_;
320
[email protected]edbcde932010-05-07 17:10:46321 // Set to true if painting to the window is handled by the GPU process.
322 bool is_gpu_rendering_active_;
323
[email protected]05d478752009-04-08 23:38:16324 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:29325};
326
[email protected]05d478752009-04-08 23:38:16327#endif // CHROME_RENDERER_RENDER_WIDGET_H_