[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 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 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 5 | #ifndef CHROME_RENDERER_RENDER_WIDGET_H_ |
| 6 | #define CHROME_RENDERER_RENDER_WIDGET_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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" |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 16 | #include "chrome/renderer/render_process.h" |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 17 | #include "ipc/ipc_channel.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 18 | #include "skia/ext/platform_canvas.h" |
[email protected] | d5282e7 | 2009-05-13 13:16:52 | [diff] [blame] | 19 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 20 | #include "webkit/api/public/WebCompositionCommand.h" |
[email protected] | afdcf5c | 2009-05-10 20:30:41 | [diff] [blame] | 21 | #include "webkit/api/public/WebRect.h" |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 22 | #include "webkit/api/public/WebTextDirection.h" |
| 23 | #include "webkit/api/public/WebWidgetClient.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | #include "webkit/glue/webcursor.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 26 | class RenderThreadBase; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 27 | struct ViewHostMsg_ShowPopup_Params; |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 28 | struct WebPluginGeometry; |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 29 | |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 30 | namespace WebKit { |
| 31 | struct WebPopupMenuInfo; |
| 32 | } |
| 33 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | // RenderWidget provides a communication bridge between a WebWidget and |
| 35 | // a RenderWidgetHost, the latter of which lives in a different process. |
| 36 | class RenderWidget : public IPC::Channel::Listener, |
| 37 | public IPC::Message::Sender, |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 38 | virtual public WebKit::WebWidgetClient, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | public base::RefCounted<RenderWidget> { |
| 40 | public: |
| 41 | // Creates a new RenderWidget. The opener_id is the routing ID of the |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 42 | // RenderView that this widget lives inside. The render_thread is any |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 43 | // RenderThreadBase implementation, mostly commonly RenderThread::current(). |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 44 | static RenderWidget* Create(int32 opener_id, |
| 45 | RenderThreadBase* render_thread, |
[email protected] | cfd727f | 2009-01-09 20:21:11 | [diff] [blame] | 46 | bool activatable); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 47 | |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 48 | // Called after Create to configure a RenderWidget to be rendered by the host |
| 49 | // as a popup menu with the given data. |
| 50 | void ConfigureAsExternalPopupMenu(const WebKit::WebPopupMenuInfo& info); |
| 51 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 52 | // The routing ID assigned by the RenderProcess. Will be MSG_ROUTING_NONE if |
| 53 | // not yet assigned a view ID, in which case, the process MUST NOT send |
| 54 | // messages with this ID to the parent. |
| 55 | int32 routing_id() const { |
| 56 | return routing_id_; |
| 57 | } |
| 58 | |
| 59 | // May return NULL when the window is closing. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 60 | WebKit::WebWidget* webwidget() const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 61 | return webwidget_; |
| 62 | } |
| 63 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | // IPC::Channel::Listener |
| 65 | virtual void OnMessageReceived(const IPC::Message& msg); |
| 66 | |
| 67 | // IPC::Message::Sender |
| 68 | virtual bool Send(IPC::Message* msg); |
| 69 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 70 | // WebKit::WebWidgetClient |
| 71 | virtual void didInvalidateRect(const WebKit::WebRect&); |
| 72 | virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect); |
| 73 | virtual void didFocus(); |
| 74 | virtual void didBlur(); |
| 75 | virtual void didChangeCursor(const WebKit::WebCursorInfo&); |
| 76 | virtual void closeWidgetSoon(); |
| 77 | virtual void show(WebKit::WebNavigationPolicy); |
| 78 | virtual void runModal() {} |
| 79 | virtual WebKit::WebRect windowRect(); |
| 80 | virtual void setWindowRect(const WebKit::WebRect&); |
| 81 | virtual WebKit::WebRect windowResizerRect(); |
| 82 | virtual WebKit::WebRect rootWindowRect(); |
| 83 | virtual WebKit::WebScreenInfo screenInfo(); |
| 84 | |
| 85 | // Called when a plugin is moved. These events are queued up and sent with |
| 86 | // the next paint or scroll message to the host. |
| 87 | void SchedulePluginMove(const WebPluginGeometry& move); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 88 | |
[email protected] | 26865477 | 2009-08-06 23:02:04 | [diff] [blame^] | 89 | // Called when a plugin window has been destroyed, to make sure the currently |
| 90 | // pending moves don't try to reference it. |
| 91 | void CleanupWindowInPluginMoves(gfx::PluginWindowHandle window); |
| 92 | |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 93 | // Invalidates entire widget rect to generate a full repaint. |
| 94 | void GenerateFullRepaint(); |
| 95 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | // Close the underlying WebWidget. |
[email protected] | d0298224 | 2009-06-19 02:51:42 | [diff] [blame] | 97 | void Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 98 | |
| 99 | protected: |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 100 | // Friend RefCounted so that the dtor can be non-public. Using this class |
| 101 | // without ref-counting is an error. |
| 102 | friend class base::RefCounted<RenderWidget>; |
| 103 | |
[email protected] | cfd727f | 2009-01-09 20:21:11 | [diff] [blame] | 104 | RenderWidget(RenderThreadBase* render_thread, bool activatable); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 105 | virtual ~RenderWidget(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 106 | |
| 107 | // Initializes this view with the given opener. CompleteInit must be called |
| 108 | // later. |
| 109 | void Init(int32 opener_id); |
| 110 | |
| 111 | // Finishes creation of a pending view started with Init. |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 112 | void CompleteInit(gfx::NativeViewId parent); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 113 | |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 114 | // Paints the given rectangular region of the WebWidget into canvas (a |
| 115 | // shared memory segment returned by AllocPaintBuf on Windows). The caller |
| 116 | // must ensure that the given rect fits within the bounds of the WebWidget. |
| 117 | void PaintRect(const gfx::Rect& rect, skia::PlatformCanvas* canvas); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 118 | |
| 119 | void DoDeferredPaint(); |
| 120 | void DoDeferredScroll(); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 121 | void DoDeferredClose(); |
| 122 | void DoDeferredSetWindowRect(const WebKit::WebRect& pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 124 | // Set the background of the render widget to a bitmap. The bitmap will be |
| 125 | // tiled in both directions if it isn't big enough to fill the area. This is |
| 126 | // mainly intended to be used in conjuction with WebView::SetIsTransparent(). |
| 127 | virtual void SetBackground(const SkBitmap& bitmap); |
| 128 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | // RenderWidget IPC message handlers |
| 130 | void OnClose(); |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 131 | void OnCreatingNewAck(gfx::NativeViewId parent); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 132 | virtual void OnResize(const gfx::Size& new_size, |
| 133 | const gfx::Rect& resizer_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 134 | void OnWasHidden(); |
| 135 | void OnWasRestored(bool needs_repainting); |
[email protected] | b7fce1f | 2008-08-14 05:01:07 | [diff] [blame] | 136 | void OnPaintRectAck(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 137 | void OnScrollRectAck(); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 138 | void OnRequestMoveAck(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 139 | void OnHandleInputEvent(const IPC::Message& message); |
| 140 | void OnMouseCaptureLost(); |
| 141 | void OnSetFocus(bool enable); |
| 142 | void OnImeSetInputMode(bool is_active); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 143 | void OnImeSetComposition(WebKit::WebCompositionCommand command, |
| 144 | int cursor_position, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 145 | int target_start, int target_end, |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 146 | const string16& ime_string); |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 147 | void OnMsgRepaint(const gfx::Size& size_to_paint); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 148 | void OnSetTextDirection(WebKit::WebTextDirection direction); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 149 | |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 150 | // Override point to notify that a paint has happened. This fires after the |
| 151 | // browser side has updated the screen for a newly painted region. |
| 152 | virtual void DidPaint() {} |
| 153 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 154 | // True if a PaintRect_ACK message is pending. |
| 155 | bool paint_reply_pending() const { |
| 156 | return paint_reply_pending_; |
| 157 | } |
| 158 | |
| 159 | // True if a ScrollRect_ACK message is pending. |
| 160 | bool scroll_reply_pending() const { |
| 161 | return current_scroll_buf_ != NULL; |
| 162 | } |
| 163 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 164 | bool next_paint_is_resize_ack() const; |
| 165 | bool next_paint_is_restore_ack() const; |
| 166 | void set_next_paint_is_resize_ack(); |
| 167 | void set_next_paint_is_restore_ack(); |
| 168 | void set_next_paint_is_repaint_ack(); |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 169 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 170 | // Called when a renderer process moves an input focus or updates the |
| 171 | // position of its caret. |
| 172 | // This function compares them with the previous values, and send them to |
| 173 | // the browser process only if they are updated. |
| 174 | // The browser process moves IME windows and context. |
| 175 | void UpdateIME(); |
| 176 | |
| 177 | // Tells the renderer it does not have focus. Used to prevent us from getting |
| 178 | // the focus on our own when the browser did not focus us. |
| 179 | void ClearFocus(); |
| 180 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 181 | // Set the pending window rect. |
| 182 | // Because the real render_widget is hosted in another process, there is |
| 183 | // a time period where we may have set a new window rect which has not yet |
| 184 | // been processed by the browser. So we maintain a pending window rect |
| 185 | // size. If JS code sets the WindowRect, and then immediately calls |
| 186 | // GetWindowRect() we'll use this pending window rect as the size. |
| 187 | void SetPendingWindowRect(const WebKit::WebRect& r); |
| 188 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 189 | // Routing ID that allows us to communicate to the parent browser process |
| 190 | // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent. |
| 191 | int32 routing_id_; |
| 192 | |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 193 | // We are responsible for destroying this object via its Close method. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 194 | WebKit::WebWidget* webwidget_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 195 | |
| 196 | // Set to the ID of the view that initiated creating this view, if any. When |
| 197 | // the view was initiated by the browser (the common case), this will be |
| 198 | // MSG_ROUTING_NONE. This is used in determining ownership when opening |
| 199 | // child tabs. See RenderWidget::createWebViewWithRequest. |
| 200 | // |
| 201 | // This ID may refer to an invalid view if that view is closed before this |
| 202 | // view is. |
| 203 | int32 opener_id_; |
| 204 | |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 205 | // The thread that does our IPC. |
| 206 | RenderThreadBase* render_thread_; |
| 207 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 208 | // The position where this view should be initially shown. |
| 209 | gfx::Rect initial_pos_; |
| 210 | |
| 211 | // The window we are embedded within. TODO(darin): kill this. |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 212 | gfx::NativeViewId host_window_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 213 | |
| 214 | // We store the current cursor object so we can avoid spamming SetCursor |
| 215 | // messages. |
| 216 | WebCursor current_cursor_; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 217 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 218 | // The size of the RenderWidget. |
| 219 | gfx::Size size_; |
| 220 | |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 221 | // Transport DIBs that are currently in use to transfer an image to the |
| 222 | // browser. |
| 223 | TransportDIB* current_paint_buf_; |
| 224 | TransportDIB* current_scroll_buf_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | |
| 226 | // The smallest bounding rectangle that needs to be re-painted. This is non- |
| 227 | // empty if a paint event is pending. |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 228 | gfx::Rect paint_rect_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 229 | |
| 230 | // The clip rect for the pending scroll event. This is non-empty if a |
| 231 | // scroll event is pending. |
| 232 | gfx::Rect scroll_rect_; |
| 233 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 234 | // The area that must be reserved for drawing the resize corner. |
| 235 | gfx::Rect resizer_rect_; |
| 236 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 237 | // The scroll delta for a pending scroll event. |
| 238 | gfx::Point scroll_delta_; |
| 239 | |
| 240 | // Flags for the next ViewHostMsg_PaintRect message. |
| 241 | int next_paint_flags_; |
| 242 | |
| 243 | // True if we are expecting a PaintRect_ACK message (i.e., that a PaintRect |
| 244 | // message has been sent). |
| 245 | bool paint_reply_pending_; |
| 246 | |
| 247 | // Set to true if we should ignore RenderWidget::Show calls. |
| 248 | bool did_show_; |
| 249 | |
| 250 | // Indicates that we shouldn't bother generated paint events. |
| 251 | bool is_hidden_; |
| 252 | |
| 253 | // Indicates that we should be repainted when restored. This flag is set to |
| 254 | // true if we receive an invalidation / scroll event from webkit while our |
| 255 | // is_hidden_ flag is set to true. This is used to force a repaint once we |
| 256 | // restore to account for the fact that our host would not know about the |
| 257 | // invalidation / scroll event(s) from webkit while we are hidden. |
| 258 | bool needs_repainting_on_restore_; |
| 259 | |
| 260 | // Indicates whether we have been focused/unfocused by the browser. |
| 261 | bool has_focus_; |
| 262 | |
| 263 | // True if we have requested this widget be closed. No more messages will |
| 264 | // be sent, except for a Close. |
| 265 | bool closing_; |
| 266 | |
| 267 | // Represents whether or not the IME of a browser process is active. |
| 268 | bool ime_is_active_; |
| 269 | |
| 270 | // Represents the status of the selected edit control sent to a browser |
| 271 | // process last time. |
| 272 | // When a renderer process finishes rendering a region, it retrieves: |
| 273 | // * The identifier of the selected edit control; |
| 274 | // * Whether or not the selected edit control requires IME, and; |
| 275 | // * The position of the caret (or cursor). |
| 276 | // If the above values is updated, a renderer process sends an IPC message |
| 277 | // to a browser process. A browser process uses these values to |
| 278 | // activate/deactivate IME and set the position of IME windows. |
| 279 | bool ime_control_enable_ime_; |
| 280 | int ime_control_x_; |
| 281 | int ime_control_y_; |
| 282 | bool ime_control_new_state_; |
| 283 | bool ime_control_updated_; |
[email protected] | 9f23f59 | 2008-11-17 08:36:34 | [diff] [blame] | 284 | bool ime_control_busy_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 285 | |
[email protected] | cfd727f | 2009-01-09 20:21:11 | [diff] [blame] | 286 | // Whether the window for this RenderWidget can be activated. |
| 287 | bool activatable_; |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 288 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 289 | // Holds all the needed plugin window moves for a scroll. |
[email protected] | 26865477 | 2009-08-06 23:02:04 | [diff] [blame^] | 290 | typedef std::vector<WebPluginGeometry> WebPluginGeometryVector; |
| 291 | WebPluginGeometryVector plugin_window_moves_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 292 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 293 | // A custom background for the widget. |
| 294 | SkBitmap background_; |
| 295 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 296 | // While we are waiting for the browser to update window sizes, |
| 297 | // we track the pending size temporarily. |
| 298 | int pending_window_rect_count_; |
| 299 | WebKit::WebRect pending_window_rect_; |
| 300 | |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 301 | scoped_ptr<ViewHostMsg_ShowPopup_Params> popup_params_; |
| 302 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 303 | DISALLOW_COPY_AND_ASSIGN(RenderWidget); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 304 | }; |
| 305 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 306 | #endif // CHROME_RENDERER_RENDER_WIDGET_H_ |