blob: f4270cc71c9c5d86c05cd7c1a1ae6beb986dde86 [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
10#include "app/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/basictypes.h"
12#include "base/gfx/point.h"
13#include "base/gfx/rect.h"
14#include "base/gfx/size.h"
15#include "base/ref_counted.h"
[email protected]674741932009-02-04 23:44:4616#include "base/shared_memory.h"
[email protected]e68e62fa2009-02-20 02:00:0417#include "chrome/renderer/render_process.h"
[email protected]946d1b22009-07-22 23:57:2118#include "ipc/ipc_channel.h"
[email protected]661eb9d2009-02-03 02:11:4819#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5220#include "third_party/skia/include/core/SkBitmap.h"
[email protected]4873c7d2009-07-16 06:36:2821#include "webkit/api/public/WebCompositionCommand.h"
[email protected]afdcf5c2009-05-10 20:30:4122#include "webkit/api/public/WebRect.h"
[email protected]4873c7d2009-07-16 06:36:2823#include "webkit/api/public/WebTextDirection.h"
24#include "webkit/api/public/WebWidgetClient.h"
initial.commit09911bf2008-07-26 23:55:2925#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2926
[email protected]8085dbc82008-09-26 22:53:4427class RenderThreadBase;
[email protected]88efb7ec2009-07-14 16:32:5928struct ViewHostMsg_ShowPopup_Params;
[email protected]8085dbc82008-09-26 22:53:4429
[email protected]88efb7ec2009-07-14 16:32:5930namespace WebKit {
31struct WebPopupMenuInfo;
32}
33
[email protected]f103ab72009-09-02 17:10:5934namespace webkit_glue {
35struct WebPluginGeometry;
36}
37
initial.commit09911bf2008-07-26 23:55:2938// RenderWidget provides a communication bridge between a WebWidget and
39// a RenderWidgetHost, the latter of which lives in a different process.
40class RenderWidget : public IPC::Channel::Listener,
41 public IPC::Message::Sender,
[email protected]4873c7d2009-07-16 06:36:2842 virtual public WebKit::WebWidgetClient,
initial.commit09911bf2008-07-26 23:55:2943 public base::RefCounted<RenderWidget> {
44 public:
45 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]8085dbc82008-09-26 22:53:4446 // RenderView that this widget lives inside. The render_thread is any
[email protected]8930d472009-02-21 08:05:2847 // RenderThreadBase implementation, mostly commonly RenderThread::current().
[email protected]0ebf3872008-11-07 21:35:0348 static RenderWidget* Create(int32 opener_id,
49 RenderThreadBase* render_thread,
[email protected]cfd727f2009-01-09 20:21:1150 bool activatable);
initial.commit09911bf2008-07-26 23:55:2951
[email protected]88efb7ec2009-07-14 16:32:5952 // Called after Create to configure a RenderWidget to be rendered by the host
53 // as a popup menu with the given data.
54 void ConfigureAsExternalPopupMenu(const WebKit::WebPopupMenuInfo& info);
55
initial.commit09911bf2008-07-26 23:55:2956 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
57 // not yet assigned a view ID, in which case, the process MUST NOT send
58 // messages with this ID to the parent.
59 int32 routing_id() const {
60 return routing_id_;
61 }
62
63 // May return NULL when the window is closing.
[email protected]4873c7d2009-07-16 06:36:2864 WebKit::WebWidget* webwidget() const {
initial.commit09911bf2008-07-26 23:55:2965 return webwidget_;
66 }
67
initial.commit09911bf2008-07-26 23:55:2968 // IPC::Channel::Listener
69 virtual void OnMessageReceived(const IPC::Message& msg);
70
71 // IPC::Message::Sender
72 virtual bool Send(IPC::Message* msg);
73
[email protected]4873c7d2009-07-16 06:36:2874 // WebKit::WebWidgetClient
75 virtual void didInvalidateRect(const WebKit::WebRect&);
76 virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect);
77 virtual void didFocus();
78 virtual void didBlur();
79 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
80 virtual void closeWidgetSoon();
81 virtual void show(WebKit::WebNavigationPolicy);
82 virtual void runModal() {}
83 virtual WebKit::WebRect windowRect();
84 virtual void setWindowRect(const WebKit::WebRect&);
85 virtual WebKit::WebRect windowResizerRect();
86 virtual WebKit::WebRect rootWindowRect();
87 virtual WebKit::WebScreenInfo screenInfo();
88
89 // Called when a plugin is moved. These events are queued up and sent with
90 // the next paint or scroll message to the host.
[email protected]f103ab72009-09-02 17:10:5991 void SchedulePluginMove(const webkit_glue::WebPluginGeometry& move);
initial.commit09911bf2008-07-26 23:55:2992
[email protected]268654772009-08-06 23:02:0493 // Called when a plugin window has been destroyed, to make sure the currently
94 // pending moves don't try to reference it.
95 void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
96
[email protected]b4b967e2009-04-22 11:33:0597 // Invalidates entire widget rect to generate a full repaint.
98 void GenerateFullRepaint();
99
initial.commit09911bf2008-07-26 23:55:29100 // Close the underlying WebWidget.
[email protected]60c42a8c72009-10-09 04:08:59101 virtual void Close();
initial.commit09911bf2008-07-26 23:55:29102
103 protected:
[email protected]8085dbc82008-09-26 22:53:44104 // Friend RefCounted so that the dtor can be non-public. Using this class
105 // without ref-counting is an error.
106 friend class base::RefCounted<RenderWidget>;
107
[email protected]cfd727f2009-01-09 20:21:11108 RenderWidget(RenderThreadBase* render_thread, bool activatable);
[email protected]8085dbc82008-09-26 22:53:44109 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29110
111 // Initializes this view with the given opener. CompleteInit must be called
112 // later.
113 void Init(int32 opener_id);
114
115 // Finishes creation of a pending view started with Init.
[email protected]18bcc3c2009-01-27 21:39:15116 void CompleteInit(gfx::NativeViewId parent);
initial.commit09911bf2008-07-26 23:55:29117
[email protected]661eb9d2009-02-03 02:11:48118 // Paints the given rectangular region of the WebWidget into canvas (a
119 // shared memory segment returned by AllocPaintBuf on Windows). The caller
120 // must ensure that the given rect fits within the bounds of the WebWidget.
121 void PaintRect(const gfx::Rect& rect, skia::PlatformCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29122
[email protected]12fbad812009-09-01 18:21:24123 void CallDoDeferredPaint();
initial.commit09911bf2008-07-26 23:55:29124 void DoDeferredPaint();
[email protected]12fbad812009-09-01 18:21:24125 void CallDoDeferredScroll();
initial.commit09911bf2008-07-26 23:55:29126 void DoDeferredScroll();
[email protected]2533ce12009-05-09 00:02:24127 void DoDeferredClose();
128 void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
initial.commit09911bf2008-07-26 23:55:29129
[email protected]699ab0d2009-04-23 23:19:14130 // Set the background of the render widget to a bitmap. The bitmap will be
131 // tiled in both directions if it isn't big enough to fill the area. This is
132 // mainly intended to be used in conjuction with WebView::SetIsTransparent().
133 virtual void SetBackground(const SkBitmap& bitmap);
134
initial.commit09911bf2008-07-26 23:55:29135 // RenderWidget IPC message handlers
136 void OnClose();
[email protected]18bcc3c2009-01-27 21:39:15137 void OnCreatingNewAck(gfx::NativeViewId parent);
[email protected]30f75e62009-02-25 22:01:00138 virtual void OnResize(const gfx::Size& new_size,
139 const gfx::Rect& resizer_rect);
initial.commit09911bf2008-07-26 23:55:29140 void OnWasHidden();
141 void OnWasRestored(bool needs_repainting);
[email protected]b7fce1f2008-08-14 05:01:07142 void OnPaintRectAck();
initial.commit09911bf2008-07-26 23:55:29143 void OnScrollRectAck();
[email protected]2533ce12009-05-09 00:02:24144 void OnRequestMoveAck();
initial.commit09911bf2008-07-26 23:55:29145 void OnHandleInputEvent(const IPC::Message& message);
146 void OnMouseCaptureLost();
147 void OnSetFocus(bool enable);
148 void OnImeSetInputMode(bool is_active);
[email protected]4873c7d2009-07-16 06:36:28149 void OnImeSetComposition(WebKit::WebCompositionCommand command,
150 int cursor_position,
initial.commit09911bf2008-07-26 23:55:29151 int target_start, int target_end,
[email protected]4873c7d2009-07-16 06:36:28152 const string16& ime_string);
[email protected]ec7dc112008-08-06 05:30:12153 void OnMsgRepaint(const gfx::Size& size_to_paint);
[email protected]4873c7d2009-07-16 06:36:28154 void OnSetTextDirection(WebKit::WebTextDirection direction);
initial.commit09911bf2008-07-26 23:55:29155
[email protected]a2f6bc112009-06-27 16:27:25156 // Override point to notify that a paint has happened. This fires after the
157 // browser side has updated the screen for a newly painted region.
158 virtual void DidPaint() {}
159
[email protected]bee16aab2009-08-26 15:55:03160 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
161 // use this method so that we can properly inform the RenderThread of our
162 // state.
163 void SetHidden(bool hidden);
164
initial.commit09911bf2008-07-26 23:55:29165 // True if a PaintRect_ACK message is pending.
166 bool paint_reply_pending() const {
167 return paint_reply_pending_;
168 }
169
170 // True if a ScrollRect_ACK message is pending.
171 bool scroll_reply_pending() const {
172 return current_scroll_buf_ != NULL;
173 }
174
[email protected]674741932009-02-04 23:44:46175 bool next_paint_is_resize_ack() const;
176 bool next_paint_is_restore_ack() const;
177 void set_next_paint_is_resize_ack();
178 void set_next_paint_is_restore_ack();
179 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12180
initial.commit09911bf2008-07-26 23:55:29181 // Called when a renderer process moves an input focus or updates the
182 // position of its caret.
183 // This function compares them with the previous values, and send them to
184 // the browser process only if they are updated.
185 // The browser process moves IME windows and context.
186 void UpdateIME();
187
188 // Tells the renderer it does not have focus. Used to prevent us from getting
189 // the focus on our own when the browser did not focus us.
190 void ClearFocus();
191
[email protected]2533ce12009-05-09 00:02:24192 // Set the pending window rect.
193 // Because the real render_widget is hosted in another process, there is
194 // a time period where we may have set a new window rect which has not yet
195 // been processed by the browser. So we maintain a pending window rect
196 // size. If JS code sets the WindowRect, and then immediately calls
197 // GetWindowRect() we'll use this pending window rect as the size.
198 void SetPendingWindowRect(const WebKit::WebRect& r);
199
[email protected]446705872009-09-10 07:22:48200 // Called by OnHandleInputEvent() to notify subclasses that a key event was
201 // just handled.
202 virtual void DidHandleKeyEvent() {}
203
initial.commit09911bf2008-07-26 23:55:29204 // Routing ID that allows us to communicate to the parent browser process
205 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
206 int32 routing_id_;
207
[email protected]c5b3b5e2009-02-13 06:41:11208 // We are responsible for destroying this object via its Close method.
[email protected]4873c7d2009-07-16 06:36:28209 WebKit::WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29210
211 // Set to the ID of the view that initiated creating this view, if any. When
212 // the view was initiated by the browser (the common case), this will be
213 // MSG_ROUTING_NONE. This is used in determining ownership when opening
214 // child tabs. See RenderWidget::createWebViewWithRequest.
215 //
216 // This ID may refer to an invalid view if that view is closed before this
217 // view is.
218 int32 opener_id_;
219
[email protected]8085dbc82008-09-26 22:53:44220 // The thread that does our IPC.
221 RenderThreadBase* render_thread_;
222
initial.commit09911bf2008-07-26 23:55:29223 // The position where this view should be initially shown.
224 gfx::Rect initial_pos_;
225
226 // The window we are embedded within. TODO(darin): kill this.
[email protected]18bcc3c2009-01-27 21:39:15227 gfx::NativeViewId host_window_;
initial.commit09911bf2008-07-26 23:55:29228
229 // We store the current cursor object so we can avoid spamming SetCursor
230 // messages.
231 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59232
initial.commit09911bf2008-07-26 23:55:29233 // The size of the RenderWidget.
234 gfx::Size size_;
235
[email protected]e68e62fa2009-02-20 02:00:04236 // Transport DIBs that are currently in use to transfer an image to the
237 // browser.
238 TransportDIB* current_paint_buf_;
239 TransportDIB* current_scroll_buf_;
initial.commit09911bf2008-07-26 23:55:29240
241 // The smallest bounding rectangle that needs to be re-painted. This is non-
242 // empty if a paint event is pending.
[email protected]2d5d09d52009-06-15 14:29:21243 gfx::Rect paint_rect_;
initial.commit09911bf2008-07-26 23:55:29244
245 // The clip rect for the pending scroll event. This is non-empty if a
246 // scroll event is pending.
247 gfx::Rect scroll_rect_;
248
[email protected]f21c613a2009-02-12 14:46:17249 // The area that must be reserved for drawing the resize corner.
250 gfx::Rect resizer_rect_;
251
initial.commit09911bf2008-07-26 23:55:29252 // The scroll delta for a pending scroll event.
253 gfx::Point scroll_delta_;
254
255 // Flags for the next ViewHostMsg_PaintRect message.
256 int next_paint_flags_;
257
258 // True if we are expecting a PaintRect_ACK message (i.e., that a PaintRect
259 // message has been sent).
260 bool paint_reply_pending_;
261
262 // Set to true if we should ignore RenderWidget::Show calls.
263 bool did_show_;
264
265 // Indicates that we shouldn't bother generated paint events.
266 bool is_hidden_;
267
268 // Indicates that we should be repainted when restored. This flag is set to
269 // true if we receive an invalidation / scroll event from webkit while our
270 // is_hidden_ flag is set to true. This is used to force a repaint once we
271 // restore to account for the fact that our host would not know about the
272 // invalidation / scroll event(s) from webkit while we are hidden.
273 bool needs_repainting_on_restore_;
274
275 // Indicates whether we have been focused/unfocused by the browser.
276 bool has_focus_;
277
[email protected]5dd768212009-08-13 23:34:49278 // Are we currently handling an input event?
279 bool handling_input_event_;
280
initial.commit09911bf2008-07-26 23:55:29281 // True if we have requested this widget be closed. No more messages will
282 // be sent, except for a Close.
283 bool closing_;
284
285 // Represents whether or not the IME of a browser process is active.
286 bool ime_is_active_;
287
288 // Represents the status of the selected edit control sent to a browser
289 // process last time.
290 // When a renderer process finishes rendering a region, it retrieves:
291 // * The identifier of the selected edit control;
292 // * Whether or not the selected edit control requires IME, and;
293 // * The position of the caret (or cursor).
294 // If the above values is updated, a renderer process sends an IPC message
295 // to a browser process. A browser process uses these values to
296 // activate/deactivate IME and set the position of IME windows.
297 bool ime_control_enable_ime_;
298 int ime_control_x_;
299 int ime_control_y_;
300 bool ime_control_new_state_;
301 bool ime_control_updated_;
[email protected]9f23f592008-11-17 08:36:34302 bool ime_control_busy_;
initial.commit09911bf2008-07-26 23:55:29303
[email protected]cfd727f2009-01-09 20:21:11304 // Whether the window for this RenderWidget can be activated.
305 bool activatable_;
[email protected]0ebf3872008-11-07 21:35:03306
initial.commit09911bf2008-07-26 23:55:29307 // Holds all the needed plugin window moves for a scroll.
[email protected]f103ab72009-09-02 17:10:59308 typedef std::vector<webkit_glue::WebPluginGeometry> WebPluginGeometryVector;
[email protected]268654772009-08-06 23:02:04309 WebPluginGeometryVector plugin_window_moves_;
initial.commit09911bf2008-07-26 23:55:29310
[email protected]699ab0d2009-04-23 23:19:14311 // A custom background for the widget.
312 SkBitmap background_;
313
[email protected]2533ce12009-05-09 00:02:24314 // While we are waiting for the browser to update window sizes,
315 // we track the pending size temporarily.
316 int pending_window_rect_count_;
317 WebKit::WebRect pending_window_rect_;
318
[email protected]88efb7ec2009-07-14 16:32:59319 scoped_ptr<ViewHostMsg_ShowPopup_Params> popup_params_;
320
[email protected]12fbad812009-09-01 18:21:24321 scoped_ptr<IPC::Message> pending_input_event_ack_;
322
[email protected]05d478752009-04-08 23:38:16323 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:29324};
325
[email protected]05d478752009-04-08 23:38:16326#endif // CHROME_RENDERER_RENDER_WIDGET_H_