blob: c25c99a400ef1e673509a8b76bf08c75cb006472 [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"
initial.commit09911bf2008-07-26 23:55:2912#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]552e6002009-11-19 05:24:5717#include "chrome/renderer/paint_aggregator.h"
[email protected]e68e62fa2009-02-20 02:00:0418#include "chrome/renderer/render_process.h"
[email protected]946d1b22009-07-22 23:57:2119#include "ipc/ipc_channel.h"
[email protected]661eb9d2009-02-03 02:11:4820#include "skia/ext/platform_canvas.h"
[email protected]d5282e72009-05-13 13:16:5221#include "third_party/skia/include/core/SkBitmap.h"
[email protected]418ed5ab2009-11-12 01:14:4922#include "third_party/WebKit/WebKit/chromium/public/WebCompositionCommand.h"
23#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
24#include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h"
25#include "third_party/WebKit/WebKit/chromium/public/WebWidgetClient.h"
initial.commit09911bf2008-07-26 23:55:2926#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2927
[email protected]8085dbc82008-09-26 22:53:4428class RenderThreadBase;
[email protected]88efb7ec2009-07-14 16:32:5929struct ViewHostMsg_ShowPopup_Params;
[email protected]8085dbc82008-09-26 22:53:4430
[email protected]88efb7ec2009-07-14 16:32:5931namespace WebKit {
32struct WebPopupMenuInfo;
33}
34
[email protected]f103ab72009-09-02 17:10:5935namespace webkit_glue {
36struct WebPluginGeometry;
37}
38
initial.commit09911bf2008-07-26 23:55:2939// RenderWidget provides a communication bridge between a WebWidget and
40// a RenderWidgetHost, the latter of which lives in a different process.
41class RenderWidget : public IPC::Channel::Listener,
42 public IPC::Message::Sender,
[email protected]4873c7d2009-07-16 06:36:2843 virtual public WebKit::WebWidgetClient,
initial.commit09911bf2008-07-26 23:55:2944 public base::RefCounted<RenderWidget> {
45 public:
46 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]8085dbc82008-09-26 22:53:4447 // RenderView that this widget lives inside. The render_thread is any
[email protected]8930d472009-02-21 08:05:2848 // RenderThreadBase implementation, mostly commonly RenderThread::current().
[email protected]0ebf3872008-11-07 21:35:0349 static RenderWidget* Create(int32 opener_id,
50 RenderThreadBase* render_thread,
[email protected]cfd727f2009-01-09 20:21:1151 bool activatable);
initial.commit09911bf2008-07-26 23:55:2952
[email protected]88efb7ec2009-07-14 16:32:5953 // Called after Create to configure a RenderWidget to be rendered by the host
54 // as a popup menu with the given data.
55 void ConfigureAsExternalPopupMenu(const WebKit::WebPopupMenuInfo& info);
56
initial.commit09911bf2008-07-26 23:55:2957 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
58 // not yet assigned a view ID, in which case, the process MUST NOT send
59 // messages with this ID to the parent.
60 int32 routing_id() const {
61 return routing_id_;
62 }
63
64 // May return NULL when the window is closing.
[email protected]4873c7d2009-07-16 06:36:2865 WebKit::WebWidget* webwidget() const {
initial.commit09911bf2008-07-26 23:55:2966 return webwidget_;
67 }
68
initial.commit09911bf2008-07-26 23:55:2969 // IPC::Channel::Listener
70 virtual void OnMessageReceived(const IPC::Message& msg);
71
72 // IPC::Message::Sender
73 virtual bool Send(IPC::Message* msg);
74
[email protected]4873c7d2009-07-16 06:36:2875 // WebKit::WebWidgetClient
76 virtual void didInvalidateRect(const WebKit::WebRect&);
77 virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect);
78 virtual void didFocus();
79 virtual void didBlur();
80 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
81 virtual void closeWidgetSoon();
82 virtual void show(WebKit::WebNavigationPolicy);
83 virtual void runModal() {}
84 virtual WebKit::WebRect windowRect();
85 virtual void setWindowRect(const WebKit::WebRect&);
86 virtual WebKit::WebRect windowResizerRect();
87 virtual WebKit::WebRect rootWindowRect();
88 virtual WebKit::WebScreenInfo screenInfo();
89
90 // Called when a plugin is moved. These events are queued up and sent with
91 // the next paint or scroll message to the host.
[email protected]f103ab72009-09-02 17:10:5992 void SchedulePluginMove(const webkit_glue::WebPluginGeometry& move);
initial.commit09911bf2008-07-26 23:55:2993
[email protected]268654772009-08-06 23:02:0494 // Called when a plugin window has been destroyed, to make sure the currently
95 // pending moves don't try to reference it.
96 void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
97
[email protected]b4b967e2009-04-22 11:33:0598 // Invalidates entire widget rect to generate a full repaint.
99 void GenerateFullRepaint();
100
initial.commit09911bf2008-07-26 23:55:29101 // Close the underlying WebWidget.
[email protected]60c42a8c72009-10-09 04:08:59102 virtual void Close();
initial.commit09911bf2008-07-26 23:55:29103
104 protected:
[email protected]8085dbc82008-09-26 22:53:44105 // Friend RefCounted so that the dtor can be non-public. Using this class
106 // without ref-counting is an error.
107 friend class base::RefCounted<RenderWidget>;
108
[email protected]cfd727f2009-01-09 20:21:11109 RenderWidget(RenderThreadBase* render_thread, bool activatable);
[email protected]8085dbc82008-09-26 22:53:44110 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29111
112 // Initializes this view with the given opener. CompleteInit must be called
113 // later.
114 void Init(int32 opener_id);
115
116 // Finishes creation of a pending view started with Init.
[email protected]18bcc3c2009-01-27 21:39:15117 void CompleteInit(gfx::NativeViewId parent);
initial.commit09911bf2008-07-26 23:55:29118
[email protected]661eb9d2009-02-03 02:11:48119 // Paints the given rectangular region of the WebWidget into canvas (a
120 // shared memory segment returned by AllocPaintBuf on Windows). The caller
121 // must ensure that the given rect fits within the bounds of the WebWidget.
[email protected]4fb66842009-12-04 21:41:00122 void PaintRect(const gfx::Rect& rect, const gfx::Point& canvas_origin,
123 skia::PlatformCanvas* canvas);
124
125 // Paints a border at the given rect for debugging purposes.
126 void PaintDebugBorder(const gfx::Rect& rect, skia::PlatformCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29127
[email protected]552e6002009-11-19 05:24:57128 void CallDoDeferredUpdate();
129 void DoDeferredUpdate();
[email protected]2533ce12009-05-09 00:02:24130 void DoDeferredClose();
131 void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
initial.commit09911bf2008-07-26 23:55:29132
[email protected]699ab0d2009-04-23 23:19:14133 // Set the background of the render widget to a bitmap. The bitmap will be
134 // tiled in both directions if it isn't big enough to fill the area. This is
135 // mainly intended to be used in conjuction with WebView::SetIsTransparent().
136 virtual void SetBackground(const SkBitmap& bitmap);
137
initial.commit09911bf2008-07-26 23:55:29138 // RenderWidget IPC message handlers
139 void OnClose();
[email protected]18bcc3c2009-01-27 21:39:15140 void OnCreatingNewAck(gfx::NativeViewId parent);
[email protected]30f75e62009-02-25 22:01:00141 virtual void OnResize(const gfx::Size& new_size,
142 const gfx::Rect& resizer_rect);
initial.commit09911bf2008-07-26 23:55:29143 void OnWasHidden();
144 void OnWasRestored(bool needs_repainting);
[email protected]b7fce1f2008-08-14 05:01:07145 void OnPaintRectAck();
initial.commit09911bf2008-07-26 23:55:29146 void OnScrollRectAck();
[email protected]2533ce12009-05-09 00:02:24147 void OnRequestMoveAck();
initial.commit09911bf2008-07-26 23:55:29148 void OnHandleInputEvent(const IPC::Message& message);
149 void OnMouseCaptureLost();
150 void OnSetFocus(bool enable);
151 void OnImeSetInputMode(bool is_active);
[email protected]4873c7d2009-07-16 06:36:28152 void OnImeSetComposition(WebKit::WebCompositionCommand command,
153 int cursor_position,
initial.commit09911bf2008-07-26 23:55:29154 int target_start, int target_end,
[email protected]4873c7d2009-07-16 06:36:28155 const string16& ime_string);
[email protected]ec7dc112008-08-06 05:30:12156 void OnMsgRepaint(const gfx::Size& size_to_paint);
[email protected]4873c7d2009-07-16 06:36:28157 void OnSetTextDirection(WebKit::WebTextDirection direction);
initial.commit09911bf2008-07-26 23:55:29158
[email protected]a2f6bc112009-06-27 16:27:25159 // Override point to notify that a paint has happened. This fires after the
160 // browser side has updated the screen for a newly painted region.
161 virtual void DidPaint() {}
162
[email protected]bee16aab2009-08-26 15:55:03163 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
164 // use this method so that we can properly inform the RenderThread of our
165 // state.
166 void SetHidden(bool hidden);
167
[email protected]882daa92009-11-05 16:31:31168 bool is_hidden() const { return is_hidden_; }
169
initial.commit09911bf2008-07-26 23:55:29170 // True if a PaintRect_ACK message is pending.
171 bool paint_reply_pending() const {
172 return paint_reply_pending_;
173 }
174
175 // True if a ScrollRect_ACK message is pending.
176 bool scroll_reply_pending() const {
177 return current_scroll_buf_ != NULL;
178 }
179
[email protected]674741932009-02-04 23:44:46180 bool next_paint_is_resize_ack() const;
181 bool next_paint_is_restore_ack() const;
182 void set_next_paint_is_resize_ack();
183 void set_next_paint_is_restore_ack();
184 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12185
initial.commit09911bf2008-07-26 23:55:29186 // Called when a renderer process moves an input focus or updates the
187 // position of its caret.
188 // This function compares them with the previous values, and send them to
189 // the browser process only if they are updated.
190 // The browser process moves IME windows and context.
191 void UpdateIME();
192
193 // Tells the renderer it does not have focus. Used to prevent us from getting
194 // the focus on our own when the browser did not focus us.
195 void ClearFocus();
196
[email protected]2533ce12009-05-09 00:02:24197 // Set the pending window rect.
198 // Because the real render_widget is hosted in another process, there is
199 // a time period where we may have set a new window rect which has not yet
200 // been processed by the browser. So we maintain a pending window rect
201 // size. If JS code sets the WindowRect, and then immediately calls
202 // GetWindowRect() we'll use this pending window rect as the size.
203 void SetPendingWindowRect(const WebKit::WebRect& r);
204
[email protected]446705872009-09-10 07:22:48205 // Called by OnHandleInputEvent() to notify subclasses that a key event was
206 // just handled.
207 virtual void DidHandleKeyEvent() {}
208
initial.commit09911bf2008-07-26 23:55:29209 // Routing ID that allows us to communicate to the parent browser process
210 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
211 int32 routing_id_;
212
[email protected]c5b3b5e2009-02-13 06:41:11213 // We are responsible for destroying this object via its Close method.
[email protected]4873c7d2009-07-16 06:36:28214 WebKit::WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29215
216 // Set to the ID of the view that initiated creating this view, if any. When
217 // the view was initiated by the browser (the common case), this will be
218 // MSG_ROUTING_NONE. This is used in determining ownership when opening
219 // child tabs. See RenderWidget::createWebViewWithRequest.
220 //
221 // This ID may refer to an invalid view if that view is closed before this
222 // view is.
223 int32 opener_id_;
224
[email protected]8085dbc82008-09-26 22:53:44225 // The thread that does our IPC.
226 RenderThreadBase* render_thread_;
227
initial.commit09911bf2008-07-26 23:55:29228 // The position where this view should be initially shown.
229 gfx::Rect initial_pos_;
230
231 // The window we are embedded within. TODO(darin): kill this.
[email protected]18bcc3c2009-01-27 21:39:15232 gfx::NativeViewId host_window_;
initial.commit09911bf2008-07-26 23:55:29233
234 // We store the current cursor object so we can avoid spamming SetCursor
235 // messages.
236 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59237
initial.commit09911bf2008-07-26 23:55:29238 // The size of the RenderWidget.
239 gfx::Size size_;
240
[email protected]e68e62fa2009-02-20 02:00:04241 // Transport DIBs that are currently in use to transfer an image to the
242 // browser.
243 TransportDIB* current_paint_buf_;
244 TransportDIB* current_scroll_buf_;
initial.commit09911bf2008-07-26 23:55:29245
[email protected]552e6002009-11-19 05:24:57246 PaintAggregator paint_aggregator_;
initial.commit09911bf2008-07-26 23:55:29247
[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 // Flags for the next ViewHostMsg_PaintRect message.
252 int next_paint_flags_;
253
254 // True if we are expecting a PaintRect_ACK message (i.e., that a PaintRect
255 // message has been sent).
256 bool paint_reply_pending_;
257
258 // Set to true if we should ignore RenderWidget::Show calls.
259 bool did_show_;
260
261 // Indicates that we shouldn't bother generated paint events.
262 bool is_hidden_;
263
264 // Indicates that we should be repainted when restored. This flag is set to
265 // true if we receive an invalidation / scroll event from webkit while our
266 // is_hidden_ flag is set to true. This is used to force a repaint once we
267 // restore to account for the fact that our host would not know about the
268 // invalidation / scroll event(s) from webkit while we are hidden.
269 bool needs_repainting_on_restore_;
270
271 // Indicates whether we have been focused/unfocused by the browser.
272 bool has_focus_;
273
[email protected]5dd768212009-08-13 23:34:49274 // Are we currently handling an input event?
275 bool handling_input_event_;
276
initial.commit09911bf2008-07-26 23:55:29277 // True if we have requested this widget be closed. No more messages will
278 // be sent, except for a Close.
279 bool closing_;
280
281 // Represents whether or not the IME of a browser process is active.
282 bool ime_is_active_;
283
284 // Represents the status of the selected edit control sent to a browser
285 // process last time.
286 // When a renderer process finishes rendering a region, it retrieves:
287 // * The identifier of the selected edit control;
288 // * Whether or not the selected edit control requires IME, and;
289 // * The position of the caret (or cursor).
290 // If the above values is updated, a renderer process sends an IPC message
291 // to a browser process. A browser process uses these values to
292 // activate/deactivate IME and set the position of IME windows.
293 bool ime_control_enable_ime_;
294 int ime_control_x_;
295 int ime_control_y_;
296 bool ime_control_new_state_;
297 bool ime_control_updated_;
[email protected]9f23f592008-11-17 08:36:34298 bool ime_control_busy_;
initial.commit09911bf2008-07-26 23:55:29299
[email protected]cfd727f2009-01-09 20:21:11300 // Whether the window for this RenderWidget can be activated.
301 bool activatable_;
[email protected]0ebf3872008-11-07 21:35:03302
initial.commit09911bf2008-07-26 23:55:29303 // Holds all the needed plugin window moves for a scroll.
[email protected]f103ab72009-09-02 17:10:59304 typedef std::vector<webkit_glue::WebPluginGeometry> WebPluginGeometryVector;
[email protected]268654772009-08-06 23:02:04305 WebPluginGeometryVector plugin_window_moves_;
initial.commit09911bf2008-07-26 23:55:29306
[email protected]699ab0d2009-04-23 23:19:14307 // A custom background for the widget.
308 SkBitmap background_;
309
[email protected]2533ce12009-05-09 00:02:24310 // While we are waiting for the browser to update window sizes,
311 // we track the pending size temporarily.
312 int pending_window_rect_count_;
313 WebKit::WebRect pending_window_rect_;
314
[email protected]88efb7ec2009-07-14 16:32:59315 scoped_ptr<ViewHostMsg_ShowPopup_Params> popup_params_;
316
[email protected]12fbad812009-09-01 18:21:24317 scoped_ptr<IPC::Message> pending_input_event_ack_;
318
[email protected]867125a02009-12-10 06:01:48319 // Indicates if the next sequence of Char events should be suppressed or not.
320 bool suppress_next_char_events_;
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_