blob: 7c6e59239b6f0d976e25ffd605410cd16da0d7c2 [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>
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]e68e62fa2009-02-20 02:00:0416#include "chrome/renderer/render_process.h"
[email protected]946d1b22009-07-22 23:57:2117#include "ipc/ipc_channel.h"
[email protected]661eb9d2009-02-03 02:11:4818#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5219#include "third_party/skia/include/core/SkBitmap.h"
[email protected]4873c7d2009-07-16 06:36:2820#include "webkit/api/public/WebCompositionCommand.h"
[email protected]afdcf5c2009-05-10 20:30:4121#include "webkit/api/public/WebRect.h"
[email protected]4873c7d2009-07-16 06:36:2822#include "webkit/api/public/WebTextDirection.h"
23#include "webkit/api/public/WebWidgetClient.h"
initial.commit09911bf2008-07-26 23:55:2924#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2925
[email protected]8085dbc82008-09-26 22:53:4426class RenderThreadBase;
[email protected]88efb7ec2009-07-14 16:32:5927struct ViewHostMsg_ShowPopup_Params;
[email protected]39008c02009-02-11 23:59:2528struct WebPluginGeometry;
[email protected]8085dbc82008-09-26 22:53:4429
[email protected]88efb7ec2009-07-14 16:32:5930namespace WebKit {
31struct WebPopupMenuInfo;
32}
33
initial.commit09911bf2008-07-26 23:55:2934// RenderWidget provides a communication bridge between a WebWidget and
35// a RenderWidgetHost, the latter of which lives in a different process.
36class RenderWidget : public IPC::Channel::Listener,
37 public IPC::Message::Sender,
[email protected]4873c7d2009-07-16 06:36:2838 virtual public WebKit::WebWidgetClient,
initial.commit09911bf2008-07-26 23:55:2939 public base::RefCounted<RenderWidget> {
40 public:
41 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]8085dbc82008-09-26 22:53:4442 // RenderView that this widget lives inside. The render_thread is any
[email protected]8930d472009-02-21 08:05:2843 // RenderThreadBase implementation, mostly commonly RenderThread::current().
[email protected]0ebf3872008-11-07 21:35:0344 static RenderWidget* Create(int32 opener_id,
45 RenderThreadBase* render_thread,
[email protected]cfd727f2009-01-09 20:21:1146 bool activatable);
initial.commit09911bf2008-07-26 23:55:2947
[email protected]88efb7ec2009-07-14 16:32:5948 // Called after Create to configure a RenderWidget to be rendered by the host
49 // as a popup menu with the given data.
50 void ConfigureAsExternalPopupMenu(const WebKit::WebPopupMenuInfo& info);
51
initial.commit09911bf2008-07-26 23:55:2952 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
53 // not yet assigned a view ID, in which case, the process MUST NOT send
54 // messages with this ID to the parent.
55 int32 routing_id() const {
56 return routing_id_;
57 }
58
59 // May return NULL when the window is closing.
[email protected]4873c7d2009-07-16 06:36:2860 WebKit::WebWidget* webwidget() const {
initial.commit09911bf2008-07-26 23:55:2961 return webwidget_;
62 }
63
initial.commit09911bf2008-07-26 23:55:2964 // IPC::Channel::Listener
65 virtual void OnMessageReceived(const IPC::Message& msg);
66
67 // IPC::Message::Sender
68 virtual bool Send(IPC::Message* msg);
69
[email protected]4873c7d2009-07-16 06:36:2870 // WebKit::WebWidgetClient
71 virtual void didInvalidateRect(const WebKit::WebRect&);
72 virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect);
73 virtual void didFocus();
74 virtual void didBlur();
75 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
76 virtual void closeWidgetSoon();
77 virtual void show(WebKit::WebNavigationPolicy);
78 virtual void runModal() {}
79 virtual WebKit::WebRect windowRect();
80 virtual void setWindowRect(const WebKit::WebRect&);
81 virtual WebKit::WebRect windowResizerRect();
82 virtual WebKit::WebRect rootWindowRect();
83 virtual WebKit::WebScreenInfo screenInfo();
84
85 // Called when a plugin is moved. These events are queued up and sent with
86 // the next paint or scroll message to the host.
87 void SchedulePluginMove(const WebPluginGeometry& move);
initial.commit09911bf2008-07-26 23:55:2988
[email protected]b4b967e2009-04-22 11:33:0589 // Invalidates entire widget rect to generate a full repaint.
90 void GenerateFullRepaint();
91
initial.commit09911bf2008-07-26 23:55:2992 // Close the underlying WebWidget.
[email protected]d02982242009-06-19 02:51:4293 void Close();
initial.commit09911bf2008-07-26 23:55:2994
95 protected:
[email protected]8085dbc82008-09-26 22:53:4496 // Friend RefCounted so that the dtor can be non-public. Using this class
97 // without ref-counting is an error.
98 friend class base::RefCounted<RenderWidget>;
99
[email protected]cfd727f2009-01-09 20:21:11100 RenderWidget(RenderThreadBase* render_thread, bool activatable);
[email protected]8085dbc82008-09-26 22:53:44101 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29102
103 // Initializes this view with the given opener. CompleteInit must be called
104 // later.
105 void Init(int32 opener_id);
106
107 // Finishes creation of a pending view started with Init.
[email protected]18bcc3c2009-01-27 21:39:15108 void CompleteInit(gfx::NativeViewId parent);
initial.commit09911bf2008-07-26 23:55:29109
[email protected]661eb9d2009-02-03 02:11:48110 // Paints the given rectangular region of the WebWidget into canvas (a
111 // shared memory segment returned by AllocPaintBuf on Windows). The caller
112 // must ensure that the given rect fits within the bounds of the WebWidget.
113 void PaintRect(const gfx::Rect& rect, skia::PlatformCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29114
115 void DoDeferredPaint();
116 void DoDeferredScroll();
[email protected]2533ce12009-05-09 00:02:24117 void DoDeferredClose();
118 void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
initial.commit09911bf2008-07-26 23:55:29119
[email protected]699ab0d2009-04-23 23:19:14120 // Set the background of the render widget to a bitmap. The bitmap will be
121 // tiled in both directions if it isn't big enough to fill the area. This is
122 // mainly intended to be used in conjuction with WebView::SetIsTransparent().
123 virtual void SetBackground(const SkBitmap& bitmap);
124
initial.commit09911bf2008-07-26 23:55:29125 // RenderWidget IPC message handlers
126 void OnClose();
[email protected]18bcc3c2009-01-27 21:39:15127 void OnCreatingNewAck(gfx::NativeViewId parent);
[email protected]30f75e62009-02-25 22:01:00128 virtual void OnResize(const gfx::Size& new_size,
129 const gfx::Rect& resizer_rect);
initial.commit09911bf2008-07-26 23:55:29130 void OnWasHidden();
131 void OnWasRestored(bool needs_repainting);
[email protected]b7fce1f2008-08-14 05:01:07132 void OnPaintRectAck();
initial.commit09911bf2008-07-26 23:55:29133 void OnScrollRectAck();
[email protected]2533ce12009-05-09 00:02:24134 void OnRequestMoveAck();
initial.commit09911bf2008-07-26 23:55:29135 void OnHandleInputEvent(const IPC::Message& message);
136 void OnMouseCaptureLost();
137 void OnSetFocus(bool enable);
138 void OnImeSetInputMode(bool is_active);
[email protected]4873c7d2009-07-16 06:36:28139 void OnImeSetComposition(WebKit::WebCompositionCommand command,
140 int cursor_position,
initial.commit09911bf2008-07-26 23:55:29141 int target_start, int target_end,
[email protected]4873c7d2009-07-16 06:36:28142 const string16& ime_string);
[email protected]ec7dc112008-08-06 05:30:12143 void OnMsgRepaint(const gfx::Size& size_to_paint);
[email protected]4873c7d2009-07-16 06:36:28144 void OnSetTextDirection(WebKit::WebTextDirection direction);
initial.commit09911bf2008-07-26 23:55:29145
[email protected]a2f6bc112009-06-27 16:27:25146 // Override point to notify that a paint has happened. This fires after the
147 // browser side has updated the screen for a newly painted region.
148 virtual void DidPaint() {}
149
initial.commit09911bf2008-07-26 23:55:29150 // True if a PaintRect_ACK message is pending.
151 bool paint_reply_pending() const {
152 return paint_reply_pending_;
153 }
154
155 // True if a ScrollRect_ACK message is pending.
156 bool scroll_reply_pending() const {
157 return current_scroll_buf_ != NULL;
158 }
159
[email protected]674741932009-02-04 23:44:46160 bool next_paint_is_resize_ack() const;
161 bool next_paint_is_restore_ack() const;
162 void set_next_paint_is_resize_ack();
163 void set_next_paint_is_restore_ack();
164 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12165
initial.commit09911bf2008-07-26 23:55:29166 // Called when a renderer process moves an input focus or updates the
167 // position of its caret.
168 // This function compares them with the previous values, and send them to
169 // the browser process only if they are updated.
170 // The browser process moves IME windows and context.
171 void UpdateIME();
172
173 // Tells the renderer it does not have focus. Used to prevent us from getting
174 // the focus on our own when the browser did not focus us.
175 void ClearFocus();
176
[email protected]2533ce12009-05-09 00:02:24177 // Set the pending window rect.
178 // Because the real render_widget is hosted in another process, there is
179 // a time period where we may have set a new window rect which has not yet
180 // been processed by the browser. So we maintain a pending window rect
181 // size. If JS code sets the WindowRect, and then immediately calls
182 // GetWindowRect() we'll use this pending window rect as the size.
183 void SetPendingWindowRect(const WebKit::WebRect& r);
184
initial.commit09911bf2008-07-26 23:55:29185 // Routing ID that allows us to communicate to the parent browser process
186 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
187 int32 routing_id_;
188
[email protected]c5b3b5e2009-02-13 06:41:11189 // We are responsible for destroying this object via its Close method.
[email protected]4873c7d2009-07-16 06:36:28190 WebKit::WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29191
192 // Set to the ID of the view that initiated creating this view, if any. When
193 // the view was initiated by the browser (the common case), this will be
194 // MSG_ROUTING_NONE. This is used in determining ownership when opening
195 // child tabs. See RenderWidget::createWebViewWithRequest.
196 //
197 // This ID may refer to an invalid view if that view is closed before this
198 // view is.
199 int32 opener_id_;
200
[email protected]8085dbc82008-09-26 22:53:44201 // The thread that does our IPC.
202 RenderThreadBase* render_thread_;
203
initial.commit09911bf2008-07-26 23:55:29204 // The position where this view should be initially shown.
205 gfx::Rect initial_pos_;
206
207 // The window we are embedded within. TODO(darin): kill this.
[email protected]18bcc3c2009-01-27 21:39:15208 gfx::NativeViewId host_window_;
initial.commit09911bf2008-07-26 23:55:29209
210 // We store the current cursor object so we can avoid spamming SetCursor
211 // messages.
212 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59213
initial.commit09911bf2008-07-26 23:55:29214 // The size of the RenderWidget.
215 gfx::Size size_;
216
[email protected]e68e62fa2009-02-20 02:00:04217 // Transport DIBs that are currently in use to transfer an image to the
218 // browser.
219 TransportDIB* current_paint_buf_;
220 TransportDIB* current_scroll_buf_;
initial.commit09911bf2008-07-26 23:55:29221
222 // The smallest bounding rectangle that needs to be re-painted. This is non-
223 // empty if a paint event is pending.
[email protected]2d5d09d52009-06-15 14:29:21224 gfx::Rect paint_rect_;
initial.commit09911bf2008-07-26 23:55:29225
226 // The clip rect for the pending scroll event. This is non-empty if a
227 // scroll event is pending.
228 gfx::Rect scroll_rect_;
229
[email protected]f21c613a2009-02-12 14:46:17230 // The area that must be reserved for drawing the resize corner.
231 gfx::Rect resizer_rect_;
232
initial.commit09911bf2008-07-26 23:55:29233 // The scroll delta for a pending scroll event.
234 gfx::Point scroll_delta_;
235
236 // Flags for the next ViewHostMsg_PaintRect message.
237 int next_paint_flags_;
238
239 // True if we are expecting a PaintRect_ACK message (i.e., that a PaintRect
240 // message has been sent).
241 bool paint_reply_pending_;
242
243 // Set to true if we should ignore RenderWidget::Show calls.
244 bool did_show_;
245
246 // Indicates that we shouldn't bother generated paint events.
247 bool is_hidden_;
248
249 // Indicates that we should be repainted when restored. This flag is set to
250 // true if we receive an invalidation / scroll event from webkit while our
251 // is_hidden_ flag is set to true. This is used to force a repaint once we
252 // restore to account for the fact that our host would not know about the
253 // invalidation / scroll event(s) from webkit while we are hidden.
254 bool needs_repainting_on_restore_;
255
256 // Indicates whether we have been focused/unfocused by the browser.
257 bool has_focus_;
258
259 // True if we have requested this widget be closed. No more messages will
260 // be sent, except for a Close.
261 bool closing_;
262
263 // Represents whether or not the IME of a browser process is active.
264 bool ime_is_active_;
265
266 // Represents the status of the selected edit control sent to a browser
267 // process last time.
268 // When a renderer process finishes rendering a region, it retrieves:
269 // * The identifier of the selected edit control;
270 // * Whether or not the selected edit control requires IME, and;
271 // * The position of the caret (or cursor).
272 // If the above values is updated, a renderer process sends an IPC message
273 // to a browser process. A browser process uses these values to
274 // activate/deactivate IME and set the position of IME windows.
275 bool ime_control_enable_ime_;
276 int ime_control_x_;
277 int ime_control_y_;
278 bool ime_control_new_state_;
279 bool ime_control_updated_;
[email protected]9f23f592008-11-17 08:36:34280 bool ime_control_busy_;
initial.commit09911bf2008-07-26 23:55:29281
[email protected]cfd727f2009-01-09 20:21:11282 // Whether the window for this RenderWidget can be activated.
283 bool activatable_;
[email protected]0ebf3872008-11-07 21:35:03284
initial.commit09911bf2008-07-26 23:55:29285 // Holds all the needed plugin window moves for a scroll.
286 std::vector<WebPluginGeometry> plugin_window_moves_;
287
[email protected]699ab0d2009-04-23 23:19:14288 // A custom background for the widget.
289 SkBitmap background_;
290
[email protected]2533ce12009-05-09 00:02:24291 // While we are waiting for the browser to update window sizes,
292 // we track the pending size temporarily.
293 int pending_window_rect_count_;
294 WebKit::WebRect pending_window_rect_;
295
[email protected]88efb7ec2009-07-14 16:32:59296 scoped_ptr<ViewHostMsg_ShowPopup_Params> popup_params_;
297
[email protected]05d478752009-04-08 23:38:16298 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:29299};
300
[email protected]05d478752009-04-08 23:38:16301#endif // CHROME_RENDERER_RENDER_WIDGET_H_