blob: 7ee2c046e2b0164565c64bb005e6c2def4a12b9f [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// 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
5#ifndef CHROME_RENDERER_RENDER_WIDGET_H__
6#define CHROME_RENDERER_RENDER_WIDGET_H__
7
8#include <vector>
9#include "base/basictypes.h"
[email protected]18bcc3c2009-01-27 21:39:1510#include "base/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/gfx/point.h"
12#include "base/gfx/rect.h"
13#include "base/gfx/size.h"
14#include "base/ref_counted.h"
[email protected]674741932009-02-04 23:44:4615#include "base/shared_memory.h"
[email protected]82e5ee82009-04-03 02:29:4516#include "chrome/common/ipc_channel.h"
[email protected]e68e62fa2009-02-20 02:00:0417#include "chrome/renderer/render_process.h"
[email protected]661eb9d2009-02-03 02:11:4818#include "skia/ext/platform_canvas.h"
[email protected]8085dbc82008-09-26 22:53:4419
initial.commit09911bf2008-07-26 23:55:2920#include "webkit/glue/webwidget_delegate.h"
21#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2922
[email protected]8085dbc82008-09-26 22:53:4423class RenderThreadBase;
[email protected]39008c02009-02-11 23:59:2524struct WebPluginGeometry;
[email protected]8085dbc82008-09-26 22:53:4425
initial.commit09911bf2008-07-26 23:55:2926// RenderWidget provides a communication bridge between a WebWidget and
27// a RenderWidgetHost, the latter of which lives in a different process.
28class RenderWidget : public IPC::Channel::Listener,
29 public IPC::Message::Sender,
30 virtual public WebWidgetDelegate,
31 public base::RefCounted<RenderWidget> {
32 public:
33 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]8085dbc82008-09-26 22:53:4434 // RenderView that this widget lives inside. The render_thread is any
[email protected]8930d472009-02-21 08:05:2835 // RenderThreadBase implementation, mostly commonly RenderThread::current().
[email protected]0ebf3872008-11-07 21:35:0336 static RenderWidget* Create(int32 opener_id,
37 RenderThreadBase* render_thread,
[email protected]cfd727f2009-01-09 20:21:1138 bool activatable);
initial.commit09911bf2008-07-26 23:55:2939
40 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
41 // not yet assigned a view ID, in which case, the process MUST NOT send
42 // messages with this ID to the parent.
43 int32 routing_id() const {
44 return routing_id_;
45 }
46
47 // May return NULL when the window is closing.
48 WebWidget* webwidget() const {
49 return webwidget_;
50 }
51
52 // Implementing RefCounting required for WebWidgetDelegate
53 virtual void AddRef() {
[email protected]037fce02009-01-22 01:42:1554 base::RefCounted<RenderWidget>::AddRef();
initial.commit09911bf2008-07-26 23:55:2955 }
56 virtual void Release() {
[email protected]037fce02009-01-22 01:42:1557 base::RefCounted<RenderWidget>::Release();
initial.commit09911bf2008-07-26 23:55:2958 }
59
60 // IPC::Channel::Listener
61 virtual void OnMessageReceived(const IPC::Message& msg);
62
63 // IPC::Message::Sender
64 virtual bool Send(IPC::Message* msg);
65
initial.commit09911bf2008-07-26 23:55:2966 // WebWidgetDelegate
[email protected]18bcc3c2009-01-27 21:39:1567 virtual gfx::NativeViewId GetContainingView(WebWidget* webwidget);
initial.commit09911bf2008-07-26 23:55:2968 virtual void DidInvalidateRect(WebWidget* webwidget, const gfx::Rect& rect);
69 virtual void DidScrollRect(WebWidget* webwidget, int dx, int dy,
70 const gfx::Rect& clip_rect);
71 virtual void SetCursor(WebWidget* webwidget, const WebCursor& cursor);
72 virtual void Show(WebWidget* webwidget, WindowOpenDisposition disposition);
[email protected]12456fa2009-04-01 23:07:1973 virtual void ShowWithItems(WebWidget* webwidget,
74 const gfx::Rect& bounds,
75 int item_height,
76 int selected_index,
77 const std::vector<MenuItem>& items);
initial.commit09911bf2008-07-26 23:55:2978 virtual void CloseWidgetSoon(WebWidget* webwidget);
79 virtual void Focus(WebWidget* webwidget);
80 virtual void Blur(WebWidget* webwidget);
[email protected]63bf66f2008-08-21 21:13:0181 virtual void GetWindowRect(WebWidget* webwidget, gfx::Rect* rect);
initial.commit09911bf2008-07-26 23:55:2982 virtual void SetWindowRect(WebWidget* webwidget, const gfx::Rect& rect);
[email protected]d4547452008-08-28 18:36:3783 virtual void GetRootWindowRect(WebWidget* webwidget, gfx::Rect* rect);
[email protected]c04b6362008-11-21 18:54:1984 virtual void GetRootWindowResizerRect(WebWidget* webwidget, gfx::Rect* rect);
initial.commit09911bf2008-07-26 23:55:2985 virtual void DidMove(WebWidget* webwidget, const WebPluginGeometry& move);
86 virtual void RunModal(WebWidget* webwidget) {}
[email protected]12456fa2009-04-01 23:07:1987 virtual bool IsHidden(WebWidget* webwidget) { return is_hidden_; }
88 virtual WebKit::WebScreenInfo GetScreenInfo(WebWidget* webwidget);
initial.commit09911bf2008-07-26 23:55:2989
initial.commit09911bf2008-07-26 23:55:2990 // Close the underlying WebWidget.
91 void Close();
92
initial.commit09911bf2008-07-26 23:55:2993 protected:
[email protected]8085dbc82008-09-26 22:53:4494 // Friend RefCounted so that the dtor can be non-public. Using this class
95 // without ref-counting is an error.
96 friend class base::RefCounted<RenderWidget>;
97
[email protected]cfd727f2009-01-09 20:21:1198 RenderWidget(RenderThreadBase* render_thread, bool activatable);
[email protected]8085dbc82008-09-26 22:53:4499 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29100
101 // Initializes this view with the given opener. CompleteInit must be called
102 // later.
103 void Init(int32 opener_id);
104
105 // Finishes creation of a pending view started with Init.
[email protected]18bcc3c2009-01-27 21:39:15106 void CompleteInit(gfx::NativeViewId parent);
initial.commit09911bf2008-07-26 23:55:29107
[email protected]661eb9d2009-02-03 02:11:48108 // Paints the given rectangular region of the WebWidget into canvas (a
109 // shared memory segment returned by AllocPaintBuf on Windows). The caller
110 // must ensure that the given rect fits within the bounds of the WebWidget.
111 void PaintRect(const gfx::Rect& rect, skia::PlatformCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29112
113 void DoDeferredPaint();
114 void DoDeferredScroll();
115
116 // This method is called immediately after PaintRect but before the
117 // corresponding paint or scroll message is send to the widget host.
118 virtual void DidPaint() {}
119
120 // RenderWidget IPC message handlers
121 void OnClose();
[email protected]18bcc3c2009-01-27 21:39:15122 void OnCreatingNewAck(gfx::NativeViewId parent);
[email protected]30f75e62009-02-25 22:01:00123 virtual void OnResize(const gfx::Size& new_size,
124 const gfx::Rect& resizer_rect);
initial.commit09911bf2008-07-26 23:55:29125 void OnWasHidden();
126 void OnWasRestored(bool needs_repainting);
[email protected]b7fce1f2008-08-14 05:01:07127 void OnPaintRectAck();
initial.commit09911bf2008-07-26 23:55:29128 void OnScrollRectAck();
129 void OnHandleInputEvent(const IPC::Message& message);
130 void OnMouseCaptureLost();
131 void OnSetFocus(bool enable);
132 void OnImeSetInputMode(bool is_active);
133 void OnImeSetComposition(int string_type, int cursor_position,
134 int target_start, int target_end,
135 const std::wstring& ime_string);
[email protected]ec7dc112008-08-06 05:30:12136 void OnMsgRepaint(const gfx::Size& size_to_paint);
[email protected]07f953332009-03-25 04:31:11137 void OnSetTextDirection(int direction);
initial.commit09911bf2008-07-26 23:55:29138
139 // True if a PaintRect_ACK message is pending.
140 bool paint_reply_pending() const {
141 return paint_reply_pending_;
142 }
143
144 // True if a ScrollRect_ACK message is pending.
145 bool scroll_reply_pending() const {
146 return current_scroll_buf_ != NULL;
147 }
148
[email protected]674741932009-02-04 23:44:46149 bool next_paint_is_resize_ack() const;
150 bool next_paint_is_restore_ack() const;
151 void set_next_paint_is_resize_ack();
152 void set_next_paint_is_restore_ack();
153 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12154
initial.commit09911bf2008-07-26 23:55:29155 // Called when a renderer process moves an input focus or updates the
156 // position of its caret.
157 // This function compares them with the previous values, and send them to
158 // the browser process only if they are updated.
159 // The browser process moves IME windows and context.
160 void UpdateIME();
161
162 // Tells the renderer it does not have focus. Used to prevent us from getting
163 // the focus on our own when the browser did not focus us.
164 void ClearFocus();
165
166 // Routing ID that allows us to communicate to the parent browser process
167 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
168 int32 routing_id_;
169
[email protected]c5b3b5e2009-02-13 06:41:11170 // We are responsible for destroying this object via its Close method.
171 WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29172
173 // Set to the ID of the view that initiated creating this view, if any. When
174 // the view was initiated by the browser (the common case), this will be
175 // MSG_ROUTING_NONE. This is used in determining ownership when opening
176 // child tabs. See RenderWidget::createWebViewWithRequest.
177 //
178 // This ID may refer to an invalid view if that view is closed before this
179 // view is.
180 int32 opener_id_;
181
[email protected]8085dbc82008-09-26 22:53:44182 // The thread that does our IPC.
183 RenderThreadBase* render_thread_;
184
initial.commit09911bf2008-07-26 23:55:29185 // The position where this view should be initially shown.
186 gfx::Rect initial_pos_;
187
188 // The window we are embedded within. TODO(darin): kill this.
[email protected]18bcc3c2009-01-27 21:39:15189 gfx::NativeViewId host_window_;
initial.commit09911bf2008-07-26 23:55:29190
191 // We store the current cursor object so we can avoid spamming SetCursor
192 // messages.
193 WebCursor current_cursor_;
194 // The size of the RenderWidget.
195 gfx::Size size_;
196
[email protected]e68e62fa2009-02-20 02:00:04197 // Transport DIBs that are currently in use to transfer an image to the
198 // browser.
199 TransportDIB* current_paint_buf_;
200 TransportDIB* current_scroll_buf_;
initial.commit09911bf2008-07-26 23:55:29201
202 // The smallest bounding rectangle that needs to be re-painted. This is non-
203 // empty if a paint event is pending.
204 gfx::Rect paint_rect_;
205
206 // The clip rect for the pending scroll event. This is non-empty if a
207 // scroll event is pending.
208 gfx::Rect scroll_rect_;
209
[email protected]f21c613a2009-02-12 14:46:17210 // The area that must be reserved for drawing the resize corner.
211 gfx::Rect resizer_rect_;
212
initial.commit09911bf2008-07-26 23:55:29213 // The scroll delta for a pending scroll event.
214 gfx::Point scroll_delta_;
215
216 // Flags for the next ViewHostMsg_PaintRect message.
217 int next_paint_flags_;
218
219 // True if we are expecting a PaintRect_ACK message (i.e., that a PaintRect
220 // message has been sent).
221 bool paint_reply_pending_;
222
223 // Set to true if we should ignore RenderWidget::Show calls.
224 bool did_show_;
225
226 // Indicates that we shouldn't bother generated paint events.
227 bool is_hidden_;
228
229 // Indicates that we should be repainted when restored. This flag is set to
230 // true if we receive an invalidation / scroll event from webkit while our
231 // is_hidden_ flag is set to true. This is used to force a repaint once we
232 // restore to account for the fact that our host would not know about the
233 // invalidation / scroll event(s) from webkit while we are hidden.
234 bool needs_repainting_on_restore_;
235
236 // Indicates whether we have been focused/unfocused by the browser.
237 bool has_focus_;
238
239 // True if we have requested this widget be closed. No more messages will
240 // be sent, except for a Close.
241 bool closing_;
242
243 // Represents whether or not the IME of a browser process is active.
244 bool ime_is_active_;
245
246 // Represents the status of the selected edit control sent to a browser
247 // process last time.
248 // When a renderer process finishes rendering a region, it retrieves:
249 // * The identifier of the selected edit control;
250 // * Whether or not the selected edit control requires IME, and;
251 // * The position of the caret (or cursor).
252 // If the above values is updated, a renderer process sends an IPC message
253 // to a browser process. A browser process uses these values to
254 // activate/deactivate IME and set the position of IME windows.
255 bool ime_control_enable_ime_;
256 int ime_control_x_;
257 int ime_control_y_;
258 bool ime_control_new_state_;
259 bool ime_control_updated_;
[email protected]9f23f592008-11-17 08:36:34260 bool ime_control_busy_;
initial.commit09911bf2008-07-26 23:55:29261
[email protected]cfd727f2009-01-09 20:21:11262 // Whether the window for this RenderWidget can be activated.
263 bool activatable_;
[email protected]0ebf3872008-11-07 21:35:03264
initial.commit09911bf2008-07-26 23:55:29265 // Holds all the needed plugin window moves for a scroll.
266 std::vector<WebPluginGeometry> plugin_window_moves_;
267
268 DISALLOW_EVIL_CONSTRUCTORS(RenderWidget);
269};
270
[email protected]f21c613a2009-02-12 14:46:17271#endif // CHROME_RENDERER_RENDER_WIDGET_H__