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