blob: 0fd66348f55a5ff62d5d0afa619cc84ac24a2507 [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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commit09911bf2008-07-26 23:55:298
9#include <vector>
[email protected]010ea08a2009-10-11 20:21:3210
[email protected]d65adb12010-04-28 17:26:4911#include "app/surface/transport_dib.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/ref_counted.h"
[email protected]552e6002009-11-19 05:24:5714#include "chrome/renderer/paint_aggregator.h"
[email protected]e68e62fa2009-02-20 02:00:0415#include "chrome/renderer/render_process.h"
[email protected]5c7293a2010-03-17 06:40:5716#include "gfx/native_widget_types.h"
[email protected]e0fc2f12010-03-14 23:30:5917#include "gfx/rect.h"
18#include "gfx/size.h"
[email protected]946d1b22009-07-22 23:57:2119#include "ipc/ipc_channel.h"
[email protected]fa7b1dc2010-06-23 17:53:0420#include "third_party/WebKit/WebKit/chromium/public/WebCompositionUnderline.h"
[email protected]3e2b375b2010-04-07 17:03:1221#include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h"
[email protected]418ed5ab2009-11-12 01:14:4922#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
23#include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h"
[email protected]fa7b1dc2010-06-23 17:53:0424#include "third_party/WebKit/WebKit/chromium/public/WebTextInputType.h"
[email protected]418ed5ab2009-11-12 01:14:4925#include "third_party/WebKit/WebKit/chromium/public/WebWidgetClient.h"
[email protected]d65adb12010-04-28 17:26:4926#include "third_party/skia/include/core/SkBitmap.h"
initial.commit09911bf2008-07-26 23:55:2927#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2928
[email protected]8085dbc82008-09-26 22:53:4429class RenderThreadBase;
[email protected]8085dbc82008-09-26 22:53:4430
[email protected]46f36a492010-07-28 19:36:4131namespace gfx {
32class Point;
33}
34
[email protected]484955942010-08-19 16:13:1835namespace IPC {
36class SyncMessage;
37}
38
[email protected]46f36a492010-07-28 19:36:4139namespace skia {
40class PlatformCanvas;
41}
42
[email protected]88efb7ec2009-07-14 16:32:5943namespace WebKit {
[email protected]6a8ddba52010-09-05 04:38:0644class WebMouseEvent;
[email protected]484955942010-08-19 16:13:1845class WebWidget;
[email protected]88efb7ec2009-07-14 16:32:5946struct WebPopupMenuInfo;
47}
48
[email protected]f103ab72009-09-02 17:10:5949namespace webkit_glue {
50struct WebPluginGeometry;
51}
52
initial.commit09911bf2008-07-26 23:55:2953// RenderWidget provides a communication bridge between a WebWidget and
54// a RenderWidgetHost, the latter of which lives in a different process.
55class RenderWidget : public IPC::Channel::Listener,
56 public IPC::Message::Sender,
[email protected]4873c7d2009-07-16 06:36:2857 virtual public WebKit::WebWidgetClient,
initial.commit09911bf2008-07-26 23:55:2958 public base::RefCounted<RenderWidget> {
59 public:
60 // Creates a new RenderWidget. The opener_id is the routing ID of the
[email protected]8085dbc82008-09-26 22:53:4461 // RenderView that this widget lives inside. The render_thread is any
[email protected]8930d472009-02-21 08:05:2862 // RenderThreadBase implementation, mostly commonly RenderThread::current().
[email protected]0ebf3872008-11-07 21:35:0363 static RenderWidget* Create(int32 opener_id,
64 RenderThreadBase* render_thread,
[email protected]3e2b375b2010-04-07 17:03:1265 WebKit::WebPopupType popup_type);
initial.commit09911bf2008-07-26 23:55:2966
[email protected]484955942010-08-19 16:13:1867 // Creates a WebWidget based on the popup type.
68 static WebKit::WebWidget* CreateWebWidget(RenderWidget* render_widget);
69
initial.commit09911bf2008-07-26 23:55:2970 // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if
71 // not yet assigned a view ID, in which case, the process MUST NOT send
72 // messages with this ID to the parent.
73 int32 routing_id() const {
74 return routing_id_;
75 }
76
77 // May return NULL when the window is closing.
[email protected]4873c7d2009-07-16 06:36:2878 WebKit::WebWidget* webwidget() const {
initial.commit09911bf2008-07-26 23:55:2979 return webwidget_;
80 }
81
[email protected]c1f50aa2010-02-18 03:46:5782 gfx::NativeViewId host_window() const {
83 return host_window_;
84 }
85
[email protected]589621b2010-09-23 22:01:0786 bool has_focus() const { return has_focus_; }
87
initial.commit09911bf2008-07-26 23:55:2988 // IPC::Channel::Listener
89 virtual void OnMessageReceived(const IPC::Message& msg);
90
91 // IPC::Message::Sender
92 virtual bool Send(IPC::Message* msg);
93
[email protected]4873c7d2009-07-16 06:36:2894 // WebKit::WebWidgetClient
95 virtual void didInvalidateRect(const WebKit::WebRect&);
96 virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect);
[email protected]a79d8a632010-11-18 22:35:5697 virtual void didActivateAcceleratedCompositing(bool active);
[email protected]f98d7e3c2010-09-13 22:30:4698 virtual void scheduleComposite();
[email protected]4873c7d2009-07-16 06:36:2899 virtual void didFocus();
100 virtual void didBlur();
101 virtual void didChangeCursor(const WebKit::WebCursorInfo&);
102 virtual void closeWidgetSoon();
103 virtual void show(WebKit::WebNavigationPolicy);
104 virtual void runModal() {}
105 virtual WebKit::WebRect windowRect();
106 virtual void setWindowRect(const WebKit::WebRect&);
107 virtual WebKit::WebRect windowResizerRect();
108 virtual WebKit::WebRect rootWindowRect();
109 virtual WebKit::WebScreenInfo screenInfo();
[email protected]fa7b1dc2010-06-23 17:53:04110 virtual void resetInputMethod();
[email protected]4873c7d2009-07-16 06:36:28111
112 // Called when a plugin is moved. These events are queued up and sent with
113 // the next paint or scroll message to the host.
[email protected]f103ab72009-09-02 17:10:59114 void SchedulePluginMove(const webkit_glue::WebPluginGeometry& move);
initial.commit09911bf2008-07-26 23:55:29115
[email protected]268654772009-08-06 23:02:04116 // Called when a plugin window has been destroyed, to make sure the currently
117 // pending moves don't try to reference it.
118 void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window);
119
initial.commit09911bf2008-07-26 23:55:29120 // Close the underlying WebWidget.
[email protected]60c42a8c72009-10-09 04:08:59121 virtual void Close();
initial.commit09911bf2008-07-26 23:55:29122
123 protected:
[email protected]8085dbc82008-09-26 22:53:44124 // Friend RefCounted so that the dtor can be non-public. Using this class
125 // without ref-counting is an error.
126 friend class base::RefCounted<RenderWidget>;
[email protected]7339cd22010-10-27 00:11:20127 // For unit tests.
128 friend class RenderWidgetTest;
[email protected]8085dbc82008-09-26 22:53:44129
[email protected]3e2b375b2010-04-07 17:03:12130 RenderWidget(RenderThreadBase* render_thread,
131 WebKit::WebPopupType popup_type);
[email protected]8085dbc82008-09-26 22:53:44132 virtual ~RenderWidget();
initial.commit09911bf2008-07-26 23:55:29133
134 // Initializes this view with the given opener. CompleteInit must be called
135 // later.
136 void Init(int32 opener_id);
137
[email protected]484955942010-08-19 16:13:18138 // Called by Init and subclasses to perform initialization.
139 void DoInit(int32 opener_id,
140 WebKit::WebWidget* web_widget,
141 IPC::SyncMessage* create_widget_message);
142
initial.commit09911bf2008-07-26 23:55:29143 // Finishes creation of a pending view started with Init.
[email protected]18bcc3c2009-01-27 21:39:15144 void CompleteInit(gfx::NativeViewId parent);
initial.commit09911bf2008-07-26 23:55:29145
[email protected]661eb9d2009-02-03 02:11:48146 // Paints the given rectangular region of the WebWidget into canvas (a
147 // shared memory segment returned by AllocPaintBuf on Windows). The caller
148 // must ensure that the given rect fits within the bounds of the WebWidget.
[email protected]4fb66842009-12-04 21:41:00149 void PaintRect(const gfx::Rect& rect, const gfx::Point& canvas_origin,
150 skia::PlatformCanvas* canvas);
151
152 // Paints a border at the given rect for debugging purposes.
153 void PaintDebugBorder(const gfx::Rect& rect, skia::PlatformCanvas* canvas);
initial.commit09911bf2008-07-26 23:55:29154
[email protected]552e6002009-11-19 05:24:57155 void CallDoDeferredUpdate();
156 void DoDeferredUpdate();
[email protected]2533ce12009-05-09 00:02:24157 void DoDeferredClose();
158 void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
initial.commit09911bf2008-07-26 23:55:29159
[email protected]699ab0d2009-04-23 23:19:14160 // Set the background of the render widget to a bitmap. The bitmap will be
161 // tiled in both directions if it isn't big enough to fill the area. This is
162 // mainly intended to be used in conjuction with WebView::SetIsTransparent().
163 virtual void SetBackground(const SkBitmap& bitmap);
164
initial.commit09911bf2008-07-26 23:55:29165 // RenderWidget IPC message handlers
166 void OnClose();
[email protected]18bcc3c2009-01-27 21:39:15167 void OnCreatingNewAck(gfx::NativeViewId parent);
[email protected]30f75e62009-02-25 22:01:00168 virtual void OnResize(const gfx::Size& new_size,
169 const gfx::Rect& resizer_rect);
[email protected]941e4552010-02-01 21:23:43170 virtual void OnWasHidden();
171 virtual void OnWasRestored(bool needs_repainting);
[email protected]53d3f302009-12-21 04:42:05172 void OnUpdateRectAck();
[email protected]8400e032010-02-26 18:50:11173 void OnCreateVideoAck(int32 video_id);
174 void OnUpdateVideoAck(int32 video_id);
[email protected]2533ce12009-05-09 00:02:24175 void OnRequestMoveAck();
initial.commit09911bf2008-07-26 23:55:29176 void OnHandleInputEvent(const IPC::Message& message);
177 void OnMouseCaptureLost();
[email protected]1e6e3c992010-02-08 15:52:13178 virtual void OnSetFocus(bool enable);
[email protected]fa7b1dc2010-06-23 17:53:04179 void OnSetInputMethodActive(bool is_active);
180 void OnImeSetComposition(
181 const string16& text,
182 const std::vector<WebKit::WebCompositionUnderline>& underlines,
183 int selection_start,
184 int selection_end);
185 void OnImeConfirmComposition();
[email protected]d65adb12010-04-28 17:26:49186 void OnMsgPaintAtSize(const TransportDIB::Handle& dib_id,
[email protected]c88c9442010-07-19 18:55:09187 int tag,
[email protected]948f7ab72010-05-28 23:48:08188 const gfx::Size& page_size,
[email protected]d65adb12010-04-28 17:26:49189 const gfx::Size& desired_size);
[email protected]ec7dc112008-08-06 05:30:12190 void OnMsgRepaint(const gfx::Size& size_to_paint);
[email protected]4873c7d2009-07-16 06:36:28191 void OnSetTextDirection(WebKit::WebTextDirection direction);
initial.commit09911bf2008-07-26 23:55:29192
[email protected]00c39612010-03-06 02:53:28193 // Override point to notify derived classes that a paint has happened.
194 // DidInitiatePaint happens when we've generated a new bitmap and sent it to
195 // the browser. DidFlushPaint happens once we've received the ACK that the
196 // screen has actually been updated.
197 virtual void DidInitiatePaint() {}
198 virtual void DidFlushPaint() {}
[email protected]a2f6bc112009-06-27 16:27:25199
[email protected]ca4847f2010-09-24 05:39:15200 // Detects if a suitable opaque plugin covers the given paint bounds with no
201 // compositing necessary.
202 //
203 // Returns true if the paint can be handled by just blitting the plugin
204 // bitmap. In this case, the location, clipping, and ID of the backing store
205 // will be filled into the given output parameters.
206 //
207 // A return value of false means optimized painting can not be used and we
208 // should continue with the normal painting code path.
209 virtual bool GetBitmapForOptimizedPluginPaint(
210 const gfx::Rect& paint_bounds,
211 TransportDIB** dib,
212 gfx::Rect* location,
213 gfx::Rect* clip);
214
[email protected]bee16aab2009-08-26 15:55:03215 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
216 // use this method so that we can properly inform the RenderThread of our
217 // state.
218 void SetHidden(bool hidden);
219
[email protected]882daa92009-11-05 16:31:31220 bool is_hidden() const { return is_hidden_; }
221
[email protected]53d3f302009-12-21 04:42:05222 // True if an UpdateRect_ACK message is pending.
223 bool update_reply_pending() const {
224 return update_reply_pending_;
initial.commit09911bf2008-07-26 23:55:29225 }
226
[email protected]674741932009-02-04 23:44:46227 bool next_paint_is_resize_ack() const;
228 bool next_paint_is_restore_ack() const;
229 void set_next_paint_is_resize_ack();
230 void set_next_paint_is_restore_ack();
231 void set_next_paint_is_repaint_ack();
[email protected]ec7dc112008-08-06 05:30:12232
[email protected]fa7b1dc2010-06-23 17:53:04233 // Checks if the input method state and caret position have been changed.
234 // If they are changed, the new value will be sent to the browser process.
235 void UpdateInputMethod();
initial.commit09911bf2008-07-26 23:55:29236
237 // Tells the renderer it does not have focus. Used to prevent us from getting
238 // the focus on our own when the browser did not focus us.
239 void ClearFocus();
240
[email protected]2533ce12009-05-09 00:02:24241 // Set the pending window rect.
242 // Because the real render_widget is hosted in another process, there is
243 // a time period where we may have set a new window rect which has not yet
244 // been processed by the browser. So we maintain a pending window rect
245 // size. If JS code sets the WindowRect, and then immediately calls
246 // GetWindowRect() we'll use this pending window rect as the size.
247 void SetPendingWindowRect(const WebKit::WebRect& r);
248
[email protected]446705872009-09-10 07:22:48249 // Called by OnHandleInputEvent() to notify subclasses that a key event was
250 // just handled.
251 virtual void DidHandleKeyEvent() {}
252
[email protected]6a8ddba52010-09-05 04:38:06253 // Called by OnHandleInputEvent() to notify subclasses that a mouse event was
254 // just handled.
255 virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {}
256
initial.commit09911bf2008-07-26 23:55:29257 // Routing ID that allows us to communicate to the parent browser process
258 // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
259 int32 routing_id_;
260
[email protected]c5b3b5e2009-02-13 06:41:11261 // We are responsible for destroying this object via its Close method.
[email protected]4873c7d2009-07-16 06:36:28262 WebKit::WebWidget* webwidget_;
initial.commit09911bf2008-07-26 23:55:29263
264 // Set to the ID of the view that initiated creating this view, if any. When
265 // the view was initiated by the browser (the common case), this will be
266 // MSG_ROUTING_NONE. This is used in determining ownership when opening
267 // child tabs. See RenderWidget::createWebViewWithRequest.
268 //
269 // This ID may refer to an invalid view if that view is closed before this
270 // view is.
271 int32 opener_id_;
272
[email protected]8085dbc82008-09-26 22:53:44273 // The thread that does our IPC.
274 RenderThreadBase* render_thread_;
275
initial.commit09911bf2008-07-26 23:55:29276 // The position where this view should be initially shown.
277 gfx::Rect initial_pos_;
278
279 // The window we are embedded within. TODO(darin): kill this.
[email protected]18bcc3c2009-01-27 21:39:15280 gfx::NativeViewId host_window_;
initial.commit09911bf2008-07-26 23:55:29281
282 // We store the current cursor object so we can avoid spamming SetCursor
283 // messages.
284 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59285
initial.commit09911bf2008-07-26 23:55:29286 // The size of the RenderWidget.
287 gfx::Size size_;
288
[email protected]b4d08452010-10-05 17:34:35289 // The TransportDIB that is being used to transfer an image to the browser.
290 TransportDIB* current_paint_buf_;
initial.commit09911bf2008-07-26 23:55:29291
[email protected]552e6002009-11-19 05:24:57292 PaintAggregator paint_aggregator_;
initial.commit09911bf2008-07-26 23:55:29293
[email protected]f21c613a2009-02-12 14:46:17294 // The area that must be reserved for drawing the resize corner.
295 gfx::Rect resizer_rect_;
296
[email protected]53d3f302009-12-21 04:42:05297 // Flags for the next ViewHostMsg_UpdateRect message.
initial.commit09911bf2008-07-26 23:55:29298 int next_paint_flags_;
299
[email protected]53d3f302009-12-21 04:42:05300 // True if we are expecting an UpdateRect_ACK message (i.e., that a
301 // UpdateRect message has been sent).
302 bool update_reply_pending_;
initial.commit09911bf2008-07-26 23:55:29303
304 // Set to true if we should ignore RenderWidget::Show calls.
305 bool did_show_;
306
307 // Indicates that we shouldn't bother generated paint events.
308 bool is_hidden_;
309
310 // Indicates that we should be repainted when restored. This flag is set to
311 // true if we receive an invalidation / scroll event from webkit while our
312 // is_hidden_ flag is set to true. This is used to force a repaint once we
313 // restore to account for the fact that our host would not know about the
314 // invalidation / scroll event(s) from webkit while we are hidden.
315 bool needs_repainting_on_restore_;
316
317 // Indicates whether we have been focused/unfocused by the browser.
318 bool has_focus_;
319
[email protected]5dd768212009-08-13 23:34:49320 // Are we currently handling an input event?
321 bool handling_input_event_;
322
initial.commit09911bf2008-07-26 23:55:29323 // True if we have requested this widget be closed. No more messages will
324 // be sent, except for a Close.
325 bool closing_;
326
[email protected]fa7b1dc2010-06-23 17:53:04327 // Indicates if an input method is active in the browser process.
328 bool input_method_is_active_;
initial.commit09911bf2008-07-26 23:55:29329
[email protected]fa7b1dc2010-06-23 17:53:04330 // Stores the current text input type of |webwidget_|.
331 WebKit::WebTextInputType text_input_type_;
332
333 // Stores the current caret bounds of input focus.
334 WebKit::WebRect caret_bounds_;
initial.commit09911bf2008-07-26 23:55:29335
[email protected]3e2b375b2010-04-07 17:03:12336 // The kind of popup this widget represents, NONE if not a popup.
337 WebKit::WebPopupType popup_type_;
[email protected]0ebf3872008-11-07 21:35:03338
initial.commit09911bf2008-07-26 23:55:29339 // Holds all the needed plugin window moves for a scroll.
[email protected]f103ab72009-09-02 17:10:59340 typedef std::vector<webkit_glue::WebPluginGeometry> WebPluginGeometryVector;
[email protected]268654772009-08-06 23:02:04341 WebPluginGeometryVector plugin_window_moves_;
initial.commit09911bf2008-07-26 23:55:29342
[email protected]699ab0d2009-04-23 23:19:14343 // A custom background for the widget.
344 SkBitmap background_;
345
[email protected]2533ce12009-05-09 00:02:24346 // While we are waiting for the browser to update window sizes,
347 // we track the pending size temporarily.
348 int pending_window_rect_count_;
349 WebKit::WebRect pending_window_rect_;
350
[email protected]12fbad812009-09-01 18:21:24351 scoped_ptr<IPC::Message> pending_input_event_ack_;
352
[email protected]867125a02009-12-10 06:01:48353 // Indicates if the next sequence of Char events should be suppressed or not.
354 bool suppress_next_char_events_;
355
[email protected]a79d8a632010-11-18 22:35:56356 // Set to true if painting to the window is handled by the accelerated
357 // compositor.
358 bool is_accelerated_compositing_active_;
[email protected]edbcde932010-05-07 17:10:46359
[email protected]05d478752009-04-08 23:38:16360 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:29361};
362
[email protected]05d478752009-04-08 23:38:16363#endif // CHROME_RENDERER_RENDER_WIDGET_H_