blob: 4086137a752b5b93b3069fa246d9da7d3805e836 [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]418ed5ab2009-11-12 01:14:4922#include "third_party/WebKit/WebKit/chromium/public/WebCompositionCommand.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"
26#include "third_party/WebKit/WebKit/chromium/public/WebWidgetClient.h"
[email protected]d65adb12010-04-28 17:26:4927#include "third_party/skia/include/core/SkBitmap.h"
initial.commit09911bf2008-07-26 23:55:2928#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2929
[email protected]8085dbc82008-09-26 22:53:4430class RenderThreadBase;
[email protected]88efb7ec2009-07-14 16:32:5931struct ViewHostMsg_ShowPopup_Params;
[email protected]8085dbc82008-09-26 22:53:4432
[email protected]88efb7ec2009-07-14 16:32:5933namespace WebKit {
34struct WebPopupMenuInfo;
35}
36
[email protected]f103ab72009-09-02 17:10:5937namespace webkit_glue {
38struct WebPluginGeometry;
39}
40
initial.commit09911bf2008-07-26 23:55:2941// RenderWidget provides a communication bridge between a WebWidget and
42// a RenderWidgetHost, the latter of which lives in a different process.
43class RenderWidget : public IPC::Channel::Listener,
44 public IPC::Message::Sender,
[email protected]4873c7d2009-07-16 06:36:2845 virtual public WebKit::WebWidgetClient,
initial.commit09911bf2008-07-26 23:55:2946 public base::RefCounted<RenderWidget> {
47 public:
48 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]8085dbc82008-09-26 22:53:4449 // RenderView that this widget lives inside. The render_thread is any
[email protected]8930d472009-02-21 08:05:2850 // RenderThreadBase implementation, mostly commonly RenderThread::current().
[email protected]0ebf3872008-11-07 21:35:0351 static RenderWidget* Create(int32 opener_id,
52 RenderThreadBase* render_thread,
[email protected]3e2b375b2010-04-07 17:03:1253 WebKit::WebPopupType popup_type);
initial.commit09911bf2008-07-26 23:55:2954
[email protected]88efb7ec2009-07-14 16:32:5955 // Called after Create to configure a RenderWidget to be rendered by the host
56 // as a popup menu with the given data.
57 void ConfigureAsExternalPopupMenu(const WebKit::WebPopupMenuInfo& info);
58
initial.commit09911bf2008-07-26 23:55:2959 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
60 // not yet assigned a view ID, in which case, the process MUST NOT send
61 // messages with this ID to the parent.
62 int32 routing_id() const {
63 return routing_id_;
64 }
65
66 // May return NULL when the window is closing.
[email protected]4873c7d2009-07-16 06:36:2867 WebKit::WebWidget* webwidget() const {
initial.commit09911bf2008-07-26 23:55:2968 return webwidget_;
69 }
70
[email protected]c1f50aa2010-02-18 03:46:5771 gfx::NativeViewId host_window() const {
72 return host_window_;
73 }
74
initial.commit09911bf2008-07-26 23:55:2975 // IPC::Channel::Listener
76 virtual void OnMessageReceived(const IPC::Message& msg);
77
78 // IPC::Message::Sender
79 virtual bool Send(IPC::Message* msg);
80
[email protected]4873c7d2009-07-16 06:36:2881 // WebKit::WebWidgetClient
82 virtual void didInvalidateRect(const WebKit::WebRect&);
83 virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect);
84 virtual void didFocus();
85 virtual void didBlur();
86 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
87 virtual void closeWidgetSoon();
88 virtual void show(WebKit::WebNavigationPolicy);
89 virtual void runModal() {}
90 virtual WebKit::WebRect windowRect();
91 virtual void setWindowRect(const WebKit::WebRect&);
92 virtual WebKit::WebRect windowResizerRect();
93 virtual WebKit::WebRect rootWindowRect();
94 virtual WebKit::WebScreenInfo screenInfo();
95
96 // Called when a plugin is moved. These events are queued up and sent with
97 // the next paint or scroll message to the host.
[email protected]f103ab72009-09-02 17:10:5998 void SchedulePluginMove(const webkit_glue::WebPluginGeometry& move);
initial.commit09911bf2008-07-26 23:55:2999
[email protected]268654772009-08-06 23:02:04100 // Called when a plugin window has been destroyed, to make sure the currently
101 // pending moves don't try to reference it.
102 void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
103
[email protected]b4b967e2009-04-22 11:33:05104 // Invalidates entire widget rect to generate a full repaint.
105 void GenerateFullRepaint();
106
initial.commit09911bf2008-07-26 23:55:29107 // Close the underlying WebWidget.
[email protected]60c42a8c72009-10-09 04:08:59108 virtual void Close();
initial.commit09911bf2008-07-26 23:55:29109
110 protected:
[email protected]8085dbc82008-09-26 22:53:44111 // Friend RefCounted so that the dtor can be non-public. Using this class
112 // without ref-counting is an error.
113 friend class base::RefCounted<RenderWidget>;
114
[email protected]3e2b375b2010-04-07 17:03:12115 RenderWidget(RenderThreadBase* render_thread,
116 WebKit::WebPopupType popup_type);
[email protected]8085dbc82008-09-26 22:53:44117 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29118
119 // Initializes this view with the given opener. CompleteInit must be called
120 // later.
121 void Init(int32 opener_id);
122
123 // Finishes creation of a pending view started with Init.
[email protected]18bcc3c2009-01-27 21:39:15124 void CompleteInit(gfx::NativeViewId parent);
initial.commit09911bf2008-07-26 23:55:29125
[email protected]661eb9d2009-02-03 02:11:48126 // Paints the given rectangular region of the WebWidget into canvas (a
127 // shared memory segment returned by AllocPaintBuf on Windows). The caller
128 // must ensure that the given rect fits within the bounds of the WebWidget.
[email protected]4fb66842009-12-04 21:41:00129 void PaintRect(const gfx::Rect& rect, const gfx::Point& canvas_origin,
130 skia::PlatformCanvas* canvas);
131
132 // Paints a border at the given rect for debugging purposes.
133 void PaintDebugBorder(const gfx::Rect& rect, skia::PlatformCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29134
[email protected]552e6002009-11-19 05:24:57135 void CallDoDeferredUpdate();
136 void DoDeferredUpdate();
[email protected]2533ce12009-05-09 00:02:24137 void DoDeferredClose();
138 void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
initial.commit09911bf2008-07-26 23:55:29139
[email protected]699ab0d2009-04-23 23:19:14140 // Set the background of the render widget to a bitmap. The bitmap will be
141 // tiled in both directions if it isn't big enough to fill the area. This is
142 // mainly intended to be used in conjuction with WebView::SetIsTransparent().
143 virtual void SetBackground(const SkBitmap& bitmap);
144
initial.commit09911bf2008-07-26 23:55:29145 // RenderWidget IPC message handlers
146 void OnClose();
[email protected]18bcc3c2009-01-27 21:39:15147 void OnCreatingNewAck(gfx::NativeViewId parent);
[email protected]30f75e62009-02-25 22:01:00148 virtual void OnResize(const gfx::Size& new_size,
149 const gfx::Rect& resizer_rect);
[email protected]941e4552010-02-01 21:23:43150 virtual void OnWasHidden();
151 virtual void OnWasRestored(bool needs_repainting);
[email protected]53d3f302009-12-21 04:42:05152 void OnUpdateRectAck();
[email protected]8400e032010-02-26 18:50:11153 void OnCreateVideoAck(int32 video_id);
154 void OnUpdateVideoAck(int32 video_id);
[email protected]2533ce12009-05-09 00:02:24155 void OnRequestMoveAck();
initial.commit09911bf2008-07-26 23:55:29156 void OnHandleInputEvent(const IPC::Message& message);
157 void OnMouseCaptureLost();
[email protected]1e6e3c992010-02-08 15:52:13158 virtual void OnSetFocus(bool enable);
initial.commit09911bf2008-07-26 23:55:29159 void OnImeSetInputMode(bool is_active);
[email protected]4873c7d2009-07-16 06:36:28160 void OnImeSetComposition(WebKit::WebCompositionCommand command,
161 int cursor_position,
initial.commit09911bf2008-07-26 23:55:29162 int target_start, int target_end,
[email protected]4873c7d2009-07-16 06:36:28163 const string16& ime_string);
[email protected]d65adb12010-04-28 17:26:49164 void OnMsgPaintAtSize(const TransportDIB::Handle& dib_id,
[email protected]948f7ab72010-05-28 23:48:08165 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:49166 const gfx::Size& desired_size);
[email protected]ec7dc112008-08-06 05:30:12167 void OnMsgRepaint(const gfx::Size& size_to_paint);
[email protected]4873c7d2009-07-16 06:36:28168 void OnSetTextDirection(WebKit::WebTextDirection direction);
initial.commit09911bf2008-07-26 23:55:29169
[email protected]00c39612010-03-06 02:53:28170 // Override point to notify derived classes that a paint has happened.
171 // DidInitiatePaint happens when we've generated a new bitmap and sent it to
172 // the browser. DidFlushPaint happens once we've received the ACK that the
173 // screen has actually been updated.
174 virtual void DidInitiatePaint() {}
175 virtual void DidFlushPaint() {}
[email protected]a2f6bc112009-06-27 16:27:25176
[email protected]bee16aab2009-08-26 15:55:03177 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
178 // use this method so that we can properly inform the RenderThread of our
179 // state.
180 void SetHidden(bool hidden);
181
[email protected]882daa92009-11-05 16:31:31182 bool is_hidden() const { return is_hidden_; }
183
[email protected]53d3f302009-12-21 04:42:05184 // True if an UpdateRect_ACK message is pending.
185 bool update_reply_pending() const {
186 return update_reply_pending_;
initial.commit09911bf2008-07-26 23:55:29187 }
188
[email protected]674741932009-02-04 23:44:46189 bool next_paint_is_resize_ack() const;
190 bool next_paint_is_restore_ack() const;
191 void set_next_paint_is_resize_ack();
192 void set_next_paint_is_restore_ack();
193 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12194
initial.commit09911bf2008-07-26 23:55:29195 // Called when a renderer process moves an input focus or updates the
196 // position of its caret.
197 // This function compares them with the previous values, and send them to
198 // the browser process only if they are updated.
199 // The browser process moves IME windows and context.
200 void UpdateIME();
201
202 // Tells the renderer it does not have focus. Used to prevent us from getting
203 // the focus on our own when the browser did not focus us.
204 void ClearFocus();
205
[email protected]2533ce12009-05-09 00:02:24206 // Set the pending window rect.
207 // Because the real render_widget is hosted in another process, there is
208 // a time period where we may have set a new window rect which has not yet
209 // been processed by the browser. So we maintain a pending window rect
210 // size. If JS code sets the WindowRect, and then immediately calls
211 // GetWindowRect() we'll use this pending window rect as the size.
212 void SetPendingWindowRect(const WebKit::WebRect& r);
213
[email protected]446705872009-09-10 07:22:48214 // Called by OnHandleInputEvent() to notify subclasses that a key event was
215 // just handled.
216 virtual void DidHandleKeyEvent() {}
217
initial.commit09911bf2008-07-26 23:55:29218 // Routing ID that allows us to communicate to the parent browser process
219 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
220 int32 routing_id_;
221
[email protected]c5b3b5e2009-02-13 06:41:11222 // We are responsible for destroying this object via its Close method.
[email protected]4873c7d2009-07-16 06:36:28223 WebKit::WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29224
225 // Set to the ID of the view that initiated creating this view, if any. When
226 // the view was initiated by the browser (the common case), this will be
227 // MSG_ROUTING_NONE. This is used in determining ownership when opening
228 // child tabs. See RenderWidget::createWebViewWithRequest.
229 //
230 // This ID may refer to an invalid view if that view is closed before this
231 // view is.
232 int32 opener_id_;
233
[email protected]8085dbc82008-09-26 22:53:44234 // The thread that does our IPC.
235 RenderThreadBase* render_thread_;
236
initial.commit09911bf2008-07-26 23:55:29237 // The position where this view should be initially shown.
238 gfx::Rect initial_pos_;
239
240 // The window we are embedded within. TODO(darin): kill this.
[email protected]18bcc3c2009-01-27 21:39:15241 gfx::NativeViewId host_window_;
initial.commit09911bf2008-07-26 23:55:29242
243 // We store the current cursor object so we can avoid spamming SetCursor
244 // messages.
245 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59246
initial.commit09911bf2008-07-26 23:55:29247 // The size of the RenderWidget.
248 gfx::Size size_;
249
[email protected]53d3f302009-12-21 04:42:05250 // The TransportDIB that is being used to transfer an image to the browser.
[email protected]e68e62fa2009-02-20 02:00:04251 TransportDIB* current_paint_buf_;
initial.commit09911bf2008-07-26 23:55:29252
[email protected]552e6002009-11-19 05:24:57253 PaintAggregator paint_aggregator_;
initial.commit09911bf2008-07-26 23:55:29254
[email protected]f21c613a2009-02-12 14:46:17255 // The area that must be reserved for drawing the resize corner.
256 gfx::Rect resizer_rect_;
257
[email protected]53d3f302009-12-21 04:42:05258 // Flags for the next ViewHostMsg_UpdateRect message.
initial.commit09911bf2008-07-26 23:55:29259 int next_paint_flags_;
260
[email protected]53d3f302009-12-21 04:42:05261 // True if we are expecting an UpdateRect_ACK message (i.e., that a
262 // UpdateRect message has been sent).
263 bool update_reply_pending_;
initial.commit09911bf2008-07-26 23:55:29264
265 // Set to true if we should ignore RenderWidget::Show calls.
266 bool did_show_;
267
268 // Indicates that we shouldn't bother generated paint events.
269 bool is_hidden_;
270
271 // Indicates that we should be repainted when restored. This flag is set to
272 // true if we receive an invalidation / scroll event from webkit while our
273 // is_hidden_ flag is set to true. This is used to force a repaint once we
274 // restore to account for the fact that our host would not know about the
275 // invalidation / scroll event(s) from webkit while we are hidden.
276 bool needs_repainting_on_restore_;
277
278 // Indicates whether we have been focused/unfocused by the browser.
279 bool has_focus_;
280
[email protected]5dd768212009-08-13 23:34:49281 // Are we currently handling an input event?
282 bool handling_input_event_;
283
initial.commit09911bf2008-07-26 23:55:29284 // True if we have requested this widget be closed. No more messages will
285 // be sent, except for a Close.
286 bool closing_;
287
288 // Represents whether or not the IME of a browser process is active.
289 bool ime_is_active_;
290
291 // Represents the status of the selected edit control sent to a browser
292 // process last time.
293 // When a renderer process finishes rendering a region, it retrieves:
294 // * The identifier of the selected edit control;
295 // * Whether or not the selected edit control requires IME, and;
296 // * The position of the caret (or cursor).
297 // If the above values is updated, a renderer process sends an IPC message
298 // to a browser process. A browser process uses these values to
299 // activate/deactivate IME and set the position of IME windows.
300 bool ime_control_enable_ime_;
301 int ime_control_x_;
302 int ime_control_y_;
303 bool ime_control_new_state_;
304 bool ime_control_updated_;
[email protected]9f23f592008-11-17 08:36:34305 bool ime_control_busy_;
initial.commit09911bf2008-07-26 23:55:29306
[email protected]3e2b375b2010-04-07 17:03:12307 // The kind of popup this widget represents, NONE if not a popup.
308 WebKit::WebPopupType popup_type_;
[email protected]0ebf3872008-11-07 21:35:03309
initial.commit09911bf2008-07-26 23:55:29310 // Holds all the needed plugin window moves for a scroll.
[email protected]f103ab72009-09-02 17:10:59311 typedef std::vector<webkit_glue::WebPluginGeometry> WebPluginGeometryVector;
[email protected]268654772009-08-06 23:02:04312 WebPluginGeometryVector plugin_window_moves_;
initial.commit09911bf2008-07-26 23:55:29313
[email protected]699ab0d2009-04-23 23:19:14314 // A custom background for the widget.
315 SkBitmap background_;
316
[email protected]2533ce12009-05-09 00:02:24317 // While we are waiting for the browser to update window sizes,
318 // we track the pending size temporarily.
319 int pending_window_rect_count_;
320 WebKit::WebRect pending_window_rect_;
321
[email protected]88efb7ec2009-07-14 16:32:59322 scoped_ptr<ViewHostMsg_ShowPopup_Params> popup_params_;
323
[email protected]12fbad812009-09-01 18:21:24324 scoped_ptr<IPC::Message> pending_input_event_ack_;
325
[email protected]867125a02009-12-10 06:01:48326 // Indicates if the next sequence of Char events should be suppressed or not.
327 bool suppress_next_char_events_;
328
[email protected]edbcde932010-05-07 17:10:46329 // Set to true if painting to the window is handled by the GPU process.
330 bool is_gpu_rendering_active_;
331
[email protected]05d478752009-04-08 23:38:16332 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:29333};
334
[email protected]05d478752009-04-08 23:38:16335#endif // CHROME_RENDERER_RENDER_WIDGET_H_