blob: 3df61470fd60c9f1355d69e887432527cb9c1407 [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]8085dbc82008-09-26 22:53:4428
[email protected]88efb7ec2009-07-14 16:32:5929namespace WebKit {
30struct WebPopupMenuInfo;
31}
32
[email protected]f103ab72009-09-02 17:10:5933namespace webkit_glue {
34struct WebPluginGeometry;
35}
36
initial.commit09911bf2008-07-26 23:55:2937// RenderWidget provides a communication bridge between a WebWidget and
38// a RenderWidgetHost, the latter of which lives in a different process.
39class RenderWidget : public IPC::Channel::Listener,
40 public IPC::Message::Sender,
[email protected]4873c7d2009-07-16 06:36:2841 virtual public WebKit::WebWidgetClient,
initial.commit09911bf2008-07-26 23:55:2942 public base::RefCounted<RenderWidget> {
43 public:
44 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]8085dbc82008-09-26 22:53:4445 // RenderView that this widget lives inside. The render_thread is any
[email protected]8930d472009-02-21 08:05:2846 // RenderThreadBase implementation, mostly commonly RenderThread::current().
[email protected]0ebf3872008-11-07 21:35:0347 static RenderWidget* Create(int32 opener_id,
48 RenderThreadBase* render_thread,
[email protected]cfd727f2009-01-09 20:21:1149 bool activatable);
initial.commit09911bf2008-07-26 23:55:2950
[email protected]88efb7ec2009-07-14 16:32:5951 // Called after Create to configure a RenderWidget to be rendered by the host
52 // as a popup menu with the given data.
53 void ConfigureAsExternalPopupMenu(const WebKit::WebPopupMenuInfo& info);
54
initial.commit09911bf2008-07-26 23:55:2955 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
56 // not yet assigned a view ID, in which case, the process MUST NOT send
57 // messages with this ID to the parent.
58 int32 routing_id() const {
59 return routing_id_;
60 }
61
62 // May return NULL when the window is closing.
[email protected]4873c7d2009-07-16 06:36:2863 WebKit::WebWidget* webwidget() const {
initial.commit09911bf2008-07-26 23:55:2964 return webwidget_;
65 }
66
initial.commit09911bf2008-07-26 23:55:2967 // IPC::Channel::Listener
68 virtual void OnMessageReceived(const IPC::Message& msg);
69
70 // IPC::Message::Sender
71 virtual bool Send(IPC::Message* msg);
72
[email protected]4873c7d2009-07-16 06:36:2873 // WebKit::WebWidgetClient
74 virtual void didInvalidateRect(const WebKit::WebRect&);
75 virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect);
76 virtual void didFocus();
77 virtual void didBlur();
78 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
79 virtual void closeWidgetSoon();
80 virtual void show(WebKit::WebNavigationPolicy);
81 virtual void runModal() {}
82 virtual WebKit::WebRect windowRect();
83 virtual void setWindowRect(const WebKit::WebRect&);
84 virtual WebKit::WebRect windowResizerRect();
85 virtual WebKit::WebRect rootWindowRect();
86 virtual WebKit::WebScreenInfo screenInfo();
87
88 // Called when a plugin is moved. These events are queued up and sent with
89 // the next paint or scroll message to the host.
[email protected]f103ab72009-09-02 17:10:5990 void SchedulePluginMove(const webkit_glue::WebPluginGeometry& move);
initial.commit09911bf2008-07-26 23:55:2991
[email protected]268654772009-08-06 23:02:0492 // Called when a plugin window has been destroyed, to make sure the currently
93 // pending moves don't try to reference it.
94 void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
95
[email protected]b4b967e2009-04-22 11:33:0596 // Invalidates entire widget rect to generate a full repaint.
97 void GenerateFullRepaint();
98
initial.commit09911bf2008-07-26 23:55:2999 // Close the underlying WebWidget.
[email protected]60c42a8c72009-10-09 04:08:59100 virtual void Close();
initial.commit09911bf2008-07-26 23:55:29101
102 protected:
[email protected]8085dbc82008-09-26 22:53:44103 // Friend RefCounted so that the dtor can be non-public. Using this class
104 // without ref-counting is an error.
105 friend class base::RefCounted<RenderWidget>;
106
[email protected]cfd727f2009-01-09 20:21:11107 RenderWidget(RenderThreadBase* render_thread, bool activatable);
[email protected]8085dbc82008-09-26 22:53:44108 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29109
110 // Initializes this view with the given opener. CompleteInit must be called
111 // later.
112 void Init(int32 opener_id);
113
114 // Finishes creation of a pending view started with Init.
[email protected]18bcc3c2009-01-27 21:39:15115 void CompleteInit(gfx::NativeViewId parent);
initial.commit09911bf2008-07-26 23:55:29116
[email protected]661eb9d2009-02-03 02:11:48117 // Paints the given rectangular region of the WebWidget into canvas (a
118 // shared memory segment returned by AllocPaintBuf on Windows). The caller
119 // must ensure that the given rect fits within the bounds of the WebWidget.
120 void PaintRect(const gfx::Rect& rect, skia::PlatformCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29121
[email protected]12fbad812009-09-01 18:21:24122 void CallDoDeferredPaint();
initial.commit09911bf2008-07-26 23:55:29123 void DoDeferredPaint();
[email protected]12fbad812009-09-01 18:21:24124 void CallDoDeferredScroll();
initial.commit09911bf2008-07-26 23:55:29125 void DoDeferredScroll();
[email protected]2533ce12009-05-09 00:02:24126 void DoDeferredClose();
127 void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
initial.commit09911bf2008-07-26 23:55:29128
[email protected]699ab0d2009-04-23 23:19:14129 // Set the background of the render widget to a bitmap. The bitmap will be
130 // tiled in both directions if it isn't big enough to fill the area. This is
131 // mainly intended to be used in conjuction with WebView::SetIsTransparent().
132 virtual void SetBackground(const SkBitmap& bitmap);
133
initial.commit09911bf2008-07-26 23:55:29134 // RenderWidget IPC message handlers
135 void OnClose();
[email protected]18bcc3c2009-01-27 21:39:15136 void OnCreatingNewAck(gfx::NativeViewId parent);
[email protected]30f75e62009-02-25 22:01:00137 virtual void OnResize(const gfx::Size& new_size,
138 const gfx::Rect& resizer_rect);
initial.commit09911bf2008-07-26 23:55:29139 void OnWasHidden();
140 void OnWasRestored(bool needs_repainting);
[email protected]b7fce1f2008-08-14 05:01:07141 void OnPaintRectAck();
initial.commit09911bf2008-07-26 23:55:29142 void OnScrollRectAck();
[email protected]2533ce12009-05-09 00:02:24143 void OnRequestMoveAck();
initial.commit09911bf2008-07-26 23:55:29144 void OnHandleInputEvent(const IPC::Message& message);
145 void OnMouseCaptureLost();
146 void OnSetFocus(bool enable);
147 void OnImeSetInputMode(bool is_active);
[email protected]4873c7d2009-07-16 06:36:28148 void OnImeSetComposition(WebKit::WebCompositionCommand command,
149 int cursor_position,
initial.commit09911bf2008-07-26 23:55:29150 int target_start, int target_end,
[email protected]4873c7d2009-07-16 06:36:28151 const string16& ime_string);
[email protected]ec7dc112008-08-06 05:30:12152 void OnMsgRepaint(const gfx::Size& size_to_paint);
[email protected]4873c7d2009-07-16 06:36:28153 void OnSetTextDirection(WebKit::WebTextDirection direction);
initial.commit09911bf2008-07-26 23:55:29154
[email protected]a2f6bc112009-06-27 16:27:25155 // Override point to notify that a paint has happened. This fires after the
156 // browser side has updated the screen for a newly painted region.
157 virtual void DidPaint() {}
158
[email protected]bee16aab2009-08-26 15:55:03159 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
160 // use this method so that we can properly inform the RenderThread of our
161 // state.
162 void SetHidden(bool hidden);
163
initial.commit09911bf2008-07-26 23:55:29164 // True if a PaintRect_ACK message is pending.
165 bool paint_reply_pending() const {
166 return paint_reply_pending_;
167 }
168
169 // True if a ScrollRect_ACK message is pending.
170 bool scroll_reply_pending() const {
171 return current_scroll_buf_ != NULL;
172 }
173
[email protected]674741932009-02-04 23:44:46174 bool next_paint_is_resize_ack() const;
175 bool next_paint_is_restore_ack() const;
176 void set_next_paint_is_resize_ack();
177 void set_next_paint_is_restore_ack();
178 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12179
initial.commit09911bf2008-07-26 23:55:29180 // Called when a renderer process moves an input focus or updates the
181 // position of its caret.
182 // This function compares them with the previous values, and send them to
183 // the browser process only if they are updated.
184 // The browser process moves IME windows and context.
185 void UpdateIME();
186
187 // Tells the renderer it does not have focus. Used to prevent us from getting
188 // the focus on our own when the browser did not focus us.
189 void ClearFocus();
190
[email protected]2533ce12009-05-09 00:02:24191 // Set the pending window rect.
192 // Because the real render_widget is hosted in another process, there is
193 // a time period where we may have set a new window rect which has not yet
194 // been processed by the browser. So we maintain a pending window rect
195 // size. If JS code sets the WindowRect, and then immediately calls
196 // GetWindowRect() we'll use this pending window rect as the size.
197 void SetPendingWindowRect(const WebKit::WebRect& r);
198
[email protected]446705872009-09-10 07:22:48199 // Called by OnHandleInputEvent() to notify subclasses that a key event was
200 // just handled.
201 virtual void DidHandleKeyEvent() {}
202
initial.commit09911bf2008-07-26 23:55:29203 // Routing ID that allows us to communicate to the parent browser process
204 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
205 int32 routing_id_;
206
[email protected]c5b3b5e2009-02-13 06:41:11207 // We are responsible for destroying this object via its Close method.
[email protected]4873c7d2009-07-16 06:36:28208 WebKit::WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29209
210 // Set to the ID of the view that initiated creating this view, if any. When
211 // the view was initiated by the browser (the common case), this will be
212 // MSG_ROUTING_NONE. This is used in determining ownership when opening
213 // child tabs. See RenderWidget::createWebViewWithRequest.
214 //
215 // This ID may refer to an invalid view if that view is closed before this
216 // view is.
217 int32 opener_id_;
218
[email protected]8085dbc82008-09-26 22:53:44219 // The thread that does our IPC.
220 RenderThreadBase* render_thread_;
221
initial.commit09911bf2008-07-26 23:55:29222 // The position where this view should be initially shown.
223 gfx::Rect initial_pos_;
224
225 // The window we are embedded within. TODO(darin): kill this.
[email protected]18bcc3c2009-01-27 21:39:15226 gfx::NativeViewId host_window_;
initial.commit09911bf2008-07-26 23:55:29227
228 // We store the current cursor object so we can avoid spamming SetCursor
229 // messages.
230 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59231
initial.commit09911bf2008-07-26 23:55:29232 // The size of the RenderWidget.
233 gfx::Size size_;
234
[email protected]e68e62fa2009-02-20 02:00:04235 // Transport DIBs that are currently in use to transfer an image to the
236 // browser.
237 TransportDIB* current_paint_buf_;
238 TransportDIB* current_scroll_buf_;
initial.commit09911bf2008-07-26 23:55:29239
240 // The smallest bounding rectangle that needs to be re-painted. This is non-
241 // empty if a paint event is pending.
[email protected]2d5d09d52009-06-15 14:29:21242 gfx::Rect paint_rect_;
initial.commit09911bf2008-07-26 23:55:29243
244 // The clip rect for the pending scroll event. This is non-empty if a
245 // scroll event is pending.
246 gfx::Rect scroll_rect_;
247
[email protected]f21c613a2009-02-12 14:46:17248 // The area that must be reserved for drawing the resize corner.
249 gfx::Rect resizer_rect_;
250
initial.commit09911bf2008-07-26 23:55:29251 // The scroll delta for a pending scroll event.
252 gfx::Point scroll_delta_;
253
254 // Flags for the next ViewHostMsg_PaintRect message.
255 int next_paint_flags_;
256
257 // True if we are expecting a PaintRect_ACK message (i.e., that a PaintRect
258 // message has been sent).
259 bool paint_reply_pending_;
260
261 // Set to true if we should ignore RenderWidget::Show calls.
262 bool did_show_;
263
264 // Indicates that we shouldn't bother generated paint events.
265 bool is_hidden_;
266
267 // Indicates that we should be repainted when restored. This flag is set to
268 // true if we receive an invalidation / scroll event from webkit while our
269 // is_hidden_ flag is set to true. This is used to force a repaint once we
270 // restore to account for the fact that our host would not know about the
271 // invalidation / scroll event(s) from webkit while we are hidden.
272 bool needs_repainting_on_restore_;
273
274 // Indicates whether we have been focused/unfocused by the browser.
275 bool has_focus_;
276
[email protected]5dd768212009-08-13 23:34:49277 // Are we currently handling an input event?
278 bool handling_input_event_;
279
initial.commit09911bf2008-07-26 23:55:29280 // True if we have requested this widget be closed. No more messages will
281 // be sent, except for a Close.
282 bool closing_;
283
284 // Represents whether or not the IME of a browser process is active.
285 bool ime_is_active_;
286
287 // Represents the status of the selected edit control sent to a browser
288 // process last time.
289 // When a renderer process finishes rendering a region, it retrieves:
290 // * The identifier of the selected edit control;
291 // * Whether or not the selected edit control requires IME, and;
292 // * The position of the caret (or cursor).
293 // If the above values is updated, a renderer process sends an IPC message
294 // to a browser process. A browser process uses these values to
295 // activate/deactivate IME and set the position of IME windows.
296 bool ime_control_enable_ime_;
297 int ime_control_x_;
298 int ime_control_y_;
299 bool ime_control_new_state_;
300 bool ime_control_updated_;
[email protected]9f23f592008-11-17 08:36:34301 bool ime_control_busy_;
initial.commit09911bf2008-07-26 23:55:29302
[email protected]cfd727f2009-01-09 20:21:11303 // Whether the window for this RenderWidget can be activated.
304 bool activatable_;
[email protected]0ebf3872008-11-07 21:35:03305
initial.commit09911bf2008-07-26 23:55:29306 // Holds all the needed plugin window moves for a scroll.
[email protected]f103ab72009-09-02 17:10:59307 typedef std::vector<webkit_glue::WebPluginGeometry> WebPluginGeometryVector;
[email protected]268654772009-08-06 23:02:04308 WebPluginGeometryVector plugin_window_moves_;
initial.commit09911bf2008-07-26 23:55:29309
[email protected]699ab0d2009-04-23 23:19:14310 // A custom background for the widget.
311 SkBitmap background_;
312
[email protected]2533ce12009-05-09 00:02:24313 // While we are waiting for the browser to update window sizes,
314 // we track the pending size temporarily.
315 int pending_window_rect_count_;
316 WebKit::WebRect pending_window_rect_;
317
[email protected]88efb7ec2009-07-14 16:32:59318 scoped_ptr<ViewHostMsg_ShowPopup_Params> popup_params_;
319
[email protected]12fbad812009-09-01 18:21:24320 scoped_ptr<IPC::Message> pending_input_event_ack_;
321
[email protected]05d478752009-04-08 23:38:16322 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:29323};
324
[email protected]05d478752009-04-08 23:38:16325#endif // CHROME_RENDERER_RENDER_WIDGET_H_