license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 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] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 10 | #include "base/gfx/native_widget_types.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | #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] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 15 | #include "base/shared_memory.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "chrome/common/ipc_channel.h" |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame^] | 17 | #include "chrome/renderer/render_process.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 18 | #include "skia/ext/platform_canvas.h" |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 19 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | #include "webkit/glue/webwidget_delegate.h" |
| 21 | #include "webkit/glue/webcursor.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 23 | class RenderThreadBase; |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 24 | struct WebPluginGeometry; |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 25 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 26 | // RenderWidget provides a communication bridge between a WebWidget and |
| 27 | // a RenderWidgetHost, the latter of which lives in a different process. |
| 28 | class 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] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 34 | // RenderView that this widget lives inside. The render_thread is any |
[email protected] | 1d97d2e | 2008-12-18 23:39:02 | [diff] [blame] | 35 | // RenderThreadBase implementation, mostly commonly g_render_thread. |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 36 | static RenderWidget* Create(int32 opener_id, |
| 37 | RenderThreadBase* render_thread, |
[email protected] | cfd727f | 2009-01-09 20:21:11 | [diff] [blame] | 38 | bool activatable); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | |
| 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] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 54 | base::RefCounted<RenderWidget>::AddRef(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 55 | } |
| 56 | virtual void Release() { |
[email protected] | 037fce0 | 2009-01-22 01:42:15 | [diff] [blame] | 57 | base::RefCounted<RenderWidget>::Release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 58 | } |
| 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 | |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 66 | // True if the underlying IPC is currently sending data. |
| 67 | bool InSend() const; |
| 68 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 69 | // WebWidgetDelegate |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 70 | virtual gfx::NativeViewId GetContainingView(WebWidget* webwidget); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 71 | virtual void DidInvalidateRect(WebWidget* webwidget, const gfx::Rect& rect); |
| 72 | virtual void DidScrollRect(WebWidget* webwidget, int dx, int dy, |
| 73 | const gfx::Rect& clip_rect); |
| 74 | virtual void SetCursor(WebWidget* webwidget, const WebCursor& cursor); |
| 75 | virtual void Show(WebWidget* webwidget, WindowOpenDisposition disposition); |
| 76 | virtual void CloseWidgetSoon(WebWidget* webwidget); |
| 77 | virtual void Focus(WebWidget* webwidget); |
| 78 | virtual void Blur(WebWidget* webwidget); |
[email protected] | 63bf66f | 2008-08-21 21:13:01 | [diff] [blame] | 79 | virtual void GetWindowRect(WebWidget* webwidget, gfx::Rect* rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 80 | virtual void SetWindowRect(WebWidget* webwidget, const gfx::Rect& rect); |
[email protected] | d454745 | 2008-08-28 18:36:37 | [diff] [blame] | 81 | virtual void GetRootWindowRect(WebWidget* webwidget, gfx::Rect* rect); |
[email protected] | c04b636 | 2008-11-21 18:54:19 | [diff] [blame] | 82 | virtual void GetRootWindowResizerRect(WebWidget* webwidget, gfx::Rect* rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 83 | virtual void DidMove(WebWidget* webwidget, const WebPluginGeometry& move); |
| 84 | virtual void RunModal(WebWidget* webwidget) {} |
[email protected] | cec8588 | 2008-10-09 23:02:42 | [diff] [blame] | 85 | virtual bool IsHidden() { return is_hidden_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 86 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 87 | // Close the underlying WebWidget. |
| 88 | void Close(); |
| 89 | |
| 90 | protected: |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 91 | // Friend RefCounted so that the dtor can be non-public. Using this class |
| 92 | // without ref-counting is an error. |
| 93 | friend class base::RefCounted<RenderWidget>; |
| 94 | |
[email protected] | cfd727f | 2009-01-09 20:21:11 | [diff] [blame] | 95 | RenderWidget(RenderThreadBase* render_thread, bool activatable); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 96 | virtual ~RenderWidget(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 97 | |
| 98 | // Initializes this view with the given opener. CompleteInit must be called |
| 99 | // later. |
| 100 | void Init(int32 opener_id); |
| 101 | |
| 102 | // Finishes creation of a pending view started with Init. |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 103 | void CompleteInit(gfx::NativeViewId parent); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 104 | |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 105 | // Paints the given rectangular region of the WebWidget into canvas (a |
| 106 | // shared memory segment returned by AllocPaintBuf on Windows). The caller |
| 107 | // must ensure that the given rect fits within the bounds of the WebWidget. |
| 108 | void PaintRect(const gfx::Rect& rect, skia::PlatformCanvas* canvas); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 109 | |
| 110 | void DoDeferredPaint(); |
| 111 | void DoDeferredScroll(); |
| 112 | |
| 113 | // This method is called immediately after PaintRect but before the |
| 114 | // corresponding paint or scroll message is send to the widget host. |
| 115 | virtual void DidPaint() {} |
| 116 | |
| 117 | // RenderWidget IPC message handlers |
| 118 | void OnClose(); |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 119 | void OnCreatingNewAck(gfx::NativeViewId parent); |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 120 | void OnResize(const gfx::Size& new_size, const gfx::Rect& resizer_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 121 | void OnWasHidden(); |
| 122 | void OnWasRestored(bool needs_repainting); |
[email protected] | b7fce1f | 2008-08-14 05:01:07 | [diff] [blame] | 123 | void OnPaintRectAck(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 124 | void OnScrollRectAck(); |
| 125 | void OnHandleInputEvent(const IPC::Message& message); |
| 126 | void OnMouseCaptureLost(); |
| 127 | void OnSetFocus(bool enable); |
| 128 | void OnImeSetInputMode(bool is_active); |
| 129 | void OnImeSetComposition(int string_type, int cursor_position, |
| 130 | int target_start, int target_end, |
| 131 | const std::wstring& ime_string); |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 132 | void OnMsgRepaint(const gfx::Size& size_to_paint); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 133 | |
| 134 | // True if a PaintRect_ACK message is pending. |
| 135 | bool paint_reply_pending() const { |
| 136 | return paint_reply_pending_; |
| 137 | } |
| 138 | |
| 139 | // True if a ScrollRect_ACK message is pending. |
| 140 | bool scroll_reply_pending() const { |
| 141 | return current_scroll_buf_ != NULL; |
| 142 | } |
| 143 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 144 | bool next_paint_is_resize_ack() const; |
| 145 | bool next_paint_is_restore_ack() const; |
| 146 | void set_next_paint_is_resize_ack(); |
| 147 | void set_next_paint_is_restore_ack(); |
| 148 | void set_next_paint_is_repaint_ack(); |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 149 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 150 | // Called when a renderer process moves an input focus or updates the |
| 151 | // position of its caret. |
| 152 | // This function compares them with the previous values, and send them to |
| 153 | // the browser process only if they are updated. |
| 154 | // The browser process moves IME windows and context. |
| 155 | void UpdateIME(); |
| 156 | |
| 157 | // Tells the renderer it does not have focus. Used to prevent us from getting |
| 158 | // the focus on our own when the browser did not focus us. |
| 159 | void ClearFocus(); |
| 160 | |
| 161 | // Routing ID that allows us to communicate to the parent browser process |
| 162 | // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent. |
| 163 | int32 routing_id_; |
| 164 | |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 165 | // We are responsible for destroying this object via its Close method. |
| 166 | WebWidget* webwidget_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 167 | |
| 168 | // Set to the ID of the view that initiated creating this view, if any. When |
| 169 | // the view was initiated by the browser (the common case), this will be |
| 170 | // MSG_ROUTING_NONE. This is used in determining ownership when opening |
| 171 | // child tabs. See RenderWidget::createWebViewWithRequest. |
| 172 | // |
| 173 | // This ID may refer to an invalid view if that view is closed before this |
| 174 | // view is. |
| 175 | int32 opener_id_; |
| 176 | |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 177 | // The thread that does our IPC. |
| 178 | RenderThreadBase* render_thread_; |
| 179 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 180 | // The position where this view should be initially shown. |
| 181 | gfx::Rect initial_pos_; |
| 182 | |
| 183 | // The window we are embedded within. TODO(darin): kill this. |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 184 | gfx::NativeViewId host_window_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 185 | |
| 186 | // We store the current cursor object so we can avoid spamming SetCursor |
| 187 | // messages. |
| 188 | WebCursor current_cursor_; |
| 189 | // The size of the RenderWidget. |
| 190 | gfx::Size size_; |
| 191 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame^] | 192 | // Transport DIBs that are currently in use to transfer an image to the |
| 193 | // browser. |
| 194 | TransportDIB* current_paint_buf_; |
| 195 | TransportDIB* current_scroll_buf_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 196 | |
| 197 | // The smallest bounding rectangle that needs to be re-painted. This is non- |
| 198 | // empty if a paint event is pending. |
| 199 | gfx::Rect paint_rect_; |
| 200 | |
| 201 | // The clip rect for the pending scroll event. This is non-empty if a |
| 202 | // scroll event is pending. |
| 203 | gfx::Rect scroll_rect_; |
| 204 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 205 | // The area that must be reserved for drawing the resize corner. |
| 206 | gfx::Rect resizer_rect_; |
| 207 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 208 | // The scroll delta for a pending scroll event. |
| 209 | gfx::Point scroll_delta_; |
| 210 | |
| 211 | // Flags for the next ViewHostMsg_PaintRect message. |
| 212 | int next_paint_flags_; |
| 213 | |
| 214 | // True if we are expecting a PaintRect_ACK message (i.e., that a PaintRect |
| 215 | // message has been sent). |
| 216 | bool paint_reply_pending_; |
| 217 | |
| 218 | // Set to true if we should ignore RenderWidget::Show calls. |
| 219 | bool did_show_; |
| 220 | |
| 221 | // Indicates that we shouldn't bother generated paint events. |
| 222 | bool is_hidden_; |
| 223 | |
| 224 | // Indicates that we should be repainted when restored. This flag is set to |
| 225 | // true if we receive an invalidation / scroll event from webkit while our |
| 226 | // is_hidden_ flag is set to true. This is used to force a repaint once we |
| 227 | // restore to account for the fact that our host would not know about the |
| 228 | // invalidation / scroll event(s) from webkit while we are hidden. |
| 229 | bool needs_repainting_on_restore_; |
| 230 | |
| 231 | // Indicates whether we have been focused/unfocused by the browser. |
| 232 | bool has_focus_; |
| 233 | |
| 234 | // True if we have requested this widget be closed. No more messages will |
| 235 | // be sent, except for a Close. |
| 236 | bool closing_; |
| 237 | |
| 238 | // Represents whether or not the IME of a browser process is active. |
| 239 | bool ime_is_active_; |
| 240 | |
| 241 | // Represents the status of the selected edit control sent to a browser |
| 242 | // process last time. |
| 243 | // When a renderer process finishes rendering a region, it retrieves: |
| 244 | // * The identifier of the selected edit control; |
| 245 | // * Whether or not the selected edit control requires IME, and; |
| 246 | // * The position of the caret (or cursor). |
| 247 | // If the above values is updated, a renderer process sends an IPC message |
| 248 | // to a browser process. A browser process uses these values to |
| 249 | // activate/deactivate IME and set the position of IME windows. |
| 250 | bool ime_control_enable_ime_; |
| 251 | int ime_control_x_; |
| 252 | int ime_control_y_; |
| 253 | bool ime_control_new_state_; |
| 254 | bool ime_control_updated_; |
[email protected] | 9f23f59 | 2008-11-17 08:36:34 | [diff] [blame] | 255 | bool ime_control_busy_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 256 | |
[email protected] | cfd727f | 2009-01-09 20:21:11 | [diff] [blame] | 257 | // Whether the window for this RenderWidget can be activated. |
| 258 | bool activatable_; |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 259 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 260 | // Holds all the needed plugin window moves for a scroll. |
| 261 | std::vector<WebPluginGeometry> plugin_window_moves_; |
| 262 | |
| 263 | DISALLOW_EVIL_CONSTRUCTORS(RenderWidget); |
| 264 | }; |
| 265 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 266 | #endif // CHROME_RENDERER_RENDER_WIDGET_H__ |