[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 1 | // Copyright (c) 2010 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 | |
| 5 | #include "chrome/renderer/render_widget.h" |
| 6 | |
[email protected] | 6c077af | 2010-03-19 14:01:33 | [diff] [blame] | 7 | #include "app/surface/transport_dib.h" |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 8 | #include "base/command_line.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | #include "base/logging.h" |
| 10 | #include "base/message_loop.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | #include "base/scoped_ptr.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 12 | #include "build/build_config.h" |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 13 | #include "chrome/common/chrome_switches.h" |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 14 | #include "chrome/common/render_messages.h" |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 15 | #include "chrome/renderer/render_process.h" |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 16 | #include "chrome/renderer/render_thread.h" |
[email protected] | e0fc2f1 | 2010-03-14 23:30:59 | [diff] [blame] | 17 | #include "gfx/point.h" |
| 18 | #include "gfx/size.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 19 | #include "skia/ext/platform_canvas.h" |
[email protected] | d5282e7 | 2009-05-13 13:16:52 | [diff] [blame] | 20 | #include "third_party/skia/include/core/SkShader.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 21 | #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
| 22 | #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h" |
| 23 | #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenuInfo.h" |
| 24 | #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 25 | #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" |
| 26 | #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
[email protected] | 8c89e779 | 2009-08-19 21:18:34 | [diff] [blame] | 27 | #include "webkit/glue/webkit_glue.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 28 | |
| 29 | #if defined(OS_POSIX) |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 30 | #include "ipc/ipc_channel_posix.h" |
[email protected] | d5282e7 | 2009-05-13 13:16:52 | [diff] [blame] | 31 | #include "third_party/skia/include/core/SkPixelRef.h" |
| 32 | #include "third_party/skia/include/core/SkMallocPixelRef.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 33 | #endif // defined(OS_POSIX) |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 34 | |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 35 | #include "third_party/WebKit/WebKit/chromium/public/WebWidget.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 36 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 37 | using WebKit::WebCompositionCommand; |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 38 | using WebKit::WebCursorInfo; |
[email protected] | 62cb33cae | 2009-03-27 23:30:22 | [diff] [blame] | 39 | using WebKit::WebInputEvent; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 40 | using WebKit::WebNavigationPolicy; |
| 41 | using WebKit::WebPopupMenu; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 42 | using WebKit::WebPopupMenuInfo; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 43 | using WebKit::WebRect; |
[email protected] | 12456fa | 2009-04-01 23:07:19 | [diff] [blame] | 44 | using WebKit::WebScreenInfo; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 45 | using WebKit::WebSize; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 46 | using WebKit::WebTextDirection; |
[email protected] | 62cb33cae | 2009-03-27 23:30:22 | [diff] [blame] | 47 | |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 48 | RenderWidget::RenderWidget(RenderThreadBase* render_thread, |
| 49 | WebKit::WebPopupType popup_type) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | : routing_id_(MSG_ROUTING_NONE), |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 51 | webwidget_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 52 | opener_id_(MSG_ROUTING_NONE), |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 53 | render_thread_(render_thread), |
[email protected] | 659f73f | 2009-10-13 13:43:42 | [diff] [blame] | 54 | host_window_(0), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 55 | current_paint_buf_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | next_paint_flags_(0), |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 57 | update_reply_pending_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 58 | did_show_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 59 | is_hidden_(false), |
| 60 | needs_repainting_on_restore_(false), |
| 61 | has_focus_(false), |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 62 | handling_input_event_(false), |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 63 | closing_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | ime_is_active_(false), |
| 65 | ime_control_enable_ime_(true), |
| 66 | ime_control_x_(-1), |
| 67 | ime_control_y_(-1), |
| 68 | ime_control_new_state_(false), |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 69 | ime_control_updated_(false), |
[email protected] | 9f23f59 | 2008-11-17 08:36:34 | [diff] [blame] | 70 | ime_control_busy_(false), |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 71 | popup_type_(popup_type), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 72 | pending_window_rect_count_(0), |
[email protected] | 9d166af | 2010-03-02 22:04:33 | [diff] [blame] | 73 | suppress_next_char_events_(false) { |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 74 | RenderProcess::current()->AddRefProcess(); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 75 | DCHECK(render_thread_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | RenderWidget::~RenderWidget() { |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 79 | DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 80 | if (current_paint_buf_) { |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 81 | RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 82 | current_paint_buf_ = NULL; |
| 83 | } |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 84 | RenderProcess::current()->ReleaseProcess(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /*static*/ |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 88 | RenderWidget* RenderWidget::Create(int32 opener_id, |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 89 | RenderThreadBase* render_thread, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 90 | WebKit::WebPopupType popup_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 91 | DCHECK(opener_id != MSG_ROUTING_NONE); |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 92 | scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 93 | popup_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 94 | widget->Init(opener_id); // adds reference |
| 95 | return widget; |
| 96 | } |
| 97 | |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 98 | void RenderWidget::ConfigureAsExternalPopupMenu(const WebPopupMenuInfo& info) { |
| 99 | popup_params_.reset(new ViewHostMsg_ShowPopup_Params); |
| 100 | popup_params_->item_height = info.itemHeight; |
[email protected] | c9e1979 | 2010-03-17 17:02:59 | [diff] [blame] | 101 | popup_params_->item_font_size = info.itemFontSize; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 102 | popup_params_->selected_item = info.selectedIndex; |
| 103 | for (size_t i = 0; i < info.items.size(); ++i) |
| 104 | popup_params_->popup_items.push_back(WebMenuItem(info.items[i])); |
| 105 | } |
| 106 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 107 | void RenderWidget::Init(int32 opener_id) { |
| 108 | DCHECK(!webwidget_); |
| 109 | |
| 110 | if (opener_id != MSG_ROUTING_NONE) |
| 111 | opener_id_ = opener_id; |
| 112 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 113 | webwidget_ = WebPopupMenu::create(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 114 | |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 115 | bool result = render_thread_->Send( |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 116 | new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 117 | if (result) { |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 118 | render_thread_->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 119 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 120 | // when we receive ViewMsg_Close. |
| 121 | AddRef(); |
| 122 | } else { |
| 123 | DCHECK(false); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // This is used to complete pending inits and non-pending inits. For non- |
| 128 | // pending cases, the parent will be the same as the current parent. This |
| 129 | // indicates we do not need to reparent or anything. |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 130 | void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 132 | |
| 133 | host_window_ = parent_hwnd; |
| 134 | |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 135 | Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | IPC_DEFINE_MESSAGE_MAP(RenderWidget) |
| 139 | IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
| 140 | IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) |
| 141 | IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) |
| 142 | IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
| 143 | IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored) |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 144 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 145 | IPC_MESSAGE_HANDLER(ViewMsg_CreateVideo_ACK, OnCreateVideoAck) |
| 146 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateVideo_ACK, OnUpdateVideoAck) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 147 | IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) |
| 148 | IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) |
| 149 | IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) |
| 150 | IPC_MESSAGE_HANDLER(ViewMsg_ImeSetInputMode, OnImeSetInputMode) |
| 151 | IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 152 | IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 153 | IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 154 | IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 155 | IPC_MESSAGE_UNHANDLED_ERROR() |
| 156 | IPC_END_MESSAGE_MAP() |
| 157 | |
| 158 | bool RenderWidget::Send(IPC::Message* message) { |
| 159 | // Don't send any messages after the browser has told us to close. |
| 160 | if (closing_) { |
| 161 | delete message; |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | // If given a messsage without a routing ID, then assign our routing ID. |
| 166 | if (message->routing_id() == MSG_ROUTING_NONE) |
| 167 | message->set_routing_id(routing_id_); |
| 168 | |
[email protected] | d3fc2565 | 2009-02-24 22:31:25 | [diff] [blame] | 169 | return render_thread_->Send(message); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 170 | } |
| 171 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 172 | // Got a response from the browser after the renderer decided to create a new |
| 173 | // view. |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 174 | void RenderWidget::OnCreatingNewAck(gfx::NativeViewId parent) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 175 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 176 | |
| 177 | CompleteInit(parent); |
| 178 | } |
| 179 | |
| 180 | void RenderWidget::OnClose() { |
| 181 | if (closing_) |
| 182 | return; |
| 183 | closing_ = true; |
| 184 | |
| 185 | // Browser correspondence is no longer needed at this point. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 186 | if (routing_id_ != MSG_ROUTING_NONE) { |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 187 | render_thread_->RemoveRoute(routing_id_); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 188 | SetHidden(false); |
| 189 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 190 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 191 | // If there is a Send call on the stack, then it could be dangerous to close |
[email protected] | d3fc2565 | 2009-02-24 22:31:25 | [diff] [blame] | 192 | // now. Post a task that only gets invoked when there are no nested message |
| 193 | // loops. |
| 194 | MessageLoop::current()->PostNonNestableTask(FROM_HERE, |
| 195 | NewRunnableMethod(this, &RenderWidget::Close)); |
| 196 | |
| 197 | // Balances the AddRef taken when we called AddRoute. |
| 198 | Release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 201 | void RenderWidget::OnResize(const gfx::Size& new_size, |
| 202 | const gfx::Rect& resizer_rect) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 203 | // During shutdown we can just ignore this message. |
| 204 | if (!webwidget_) |
| 205 | return; |
| 206 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 207 | // Remember the rect where the resize corner will be drawn. |
| 208 | resizer_rect_ = resizer_rect; |
| 209 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 210 | // TODO(darin): We should not need to reset this here. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 211 | SetHidden(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 212 | needs_repainting_on_restore_ = false; |
| 213 | |
| 214 | // We shouldn't be asked to resize to our current size. |
| 215 | DCHECK(size_ != new_size); |
| 216 | size_ = new_size; |
| 217 | |
| 218 | // We should not be sent a Resize message if we have not ACK'd the previous |
| 219 | DCHECK(!next_paint_is_resize_ack()); |
| 220 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 221 | paint_aggregator_.ClearPendingUpdate(); |
| 222 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 223 | // When resizing, we want to wait to paint before ACK'ing the resize. This |
| 224 | // ensures that we only resize as fast as we can paint. We only need to send |
| 225 | // an ACK if we are resized to a non-empty rect. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 226 | webwidget_->resize(new_size); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 227 | if (!new_size.IsEmpty()) { |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 228 | // Resize should have caused an invalidation of the entire view. |
| 229 | DCHECK(paint_aggregator_.HasPendingUpdate()); |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 230 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 231 | // We will send the Resize_ACK flag once we paint again. |
| 232 | set_next_paint_is_resize_ack(); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | void RenderWidget::OnWasHidden() { |
| 237 | // Go into a mode where we stop generating paint and scrolling events. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 238 | SetHidden(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | void RenderWidget::OnWasRestored(bool needs_repainting) { |
| 242 | // During shutdown we can just ignore this message. |
| 243 | if (!webwidget_) |
| 244 | return; |
| 245 | |
| 246 | // See OnWasHidden |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 247 | SetHidden(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 248 | |
| 249 | if (!needs_repainting && !needs_repainting_on_restore_) |
| 250 | return; |
| 251 | needs_repainting_on_restore_ = false; |
| 252 | |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 253 | // Tag the next paint as a restore ack, which is picked up by DoDeferredUpdate |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 254 | // when it sends out the next PaintRect message. |
| 255 | set_next_paint_is_restore_ack(); |
| 256 | |
| 257 | // Generate a full repaint. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 258 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 261 | void RenderWidget::OnRequestMoveAck() { |
| 262 | DCHECK(pending_window_rect_count_); |
| 263 | pending_window_rect_count_--; |
| 264 | } |
| 265 | |
| 266 | void RenderWidget::OnUpdateRectAck() { |
| 267 | DCHECK(update_reply_pending()); |
| 268 | update_reply_pending_ = false; |
| 269 | |
| 270 | // If we sent an UpdateRect message with a zero-sized bitmap, then we should |
| 271 | // have no current update buf. |
[email protected] | b7fce1f | 2008-08-14 05:01:07 | [diff] [blame] | 272 | if (current_paint_buf_) { |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 273 | RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
[email protected] | b7fce1f | 2008-08-14 05:01:07 | [diff] [blame] | 274 | current_paint_buf_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 275 | } |
[email protected] | e68e62fa | 2009-02-20 02:00:04 | [diff] [blame] | 276 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 277 | // Notify subclasses. |
| 278 | DidFlushPaint(); |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 279 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 280 | // Continue painting if necessary... |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 281 | CallDoDeferredUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 282 | } |
| 283 | |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 284 | void RenderWidget::OnCreateVideoAck(int32 video_id) { |
| 285 | // TODO(scherkus): handle CreateVideo_ACK with a message filter. |
| 286 | } |
| 287 | |
| 288 | void RenderWidget::OnUpdateVideoAck(int32 video_id) { |
| 289 | // TODO(scherkus): handle UpdateVideo_ACK with a message filter. |
| 290 | } |
| 291 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 292 | void RenderWidget::OnHandleInputEvent(const IPC::Message& message) { |
| 293 | void* iter = NULL; |
| 294 | |
| 295 | const char* data; |
| 296 | int data_length; |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 297 | handling_input_event_ = true; |
| 298 | if (!message.ReadData(&iter, &data, &data_length)) { |
| 299 | handling_input_event_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 300 | return; |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 301 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 302 | |
| 303 | const WebInputEvent* input_event = |
| 304 | reinterpret_cast<const WebInputEvent*>(data); |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 305 | |
| 306 | bool is_keyboard_shortcut = false; |
| 307 | // is_keyboard_shortcut flag is only available for RawKeyDown events. |
| 308 | if (input_event->type == WebInputEvent::RawKeyDown) |
| 309 | message.ReadBool(&iter, &is_keyboard_shortcut); |
| 310 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 311 | bool processed = false; |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 312 | if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { |
| 313 | suppress_next_char_events_ = false; |
| 314 | if (webwidget_) |
| 315 | processed = webwidget_->handleInputEvent(*input_event); |
| 316 | } |
| 317 | |
| 318 | // If this RawKeyDown event corresponds to a browser keyboard shortcut and |
| 319 | // it's not processed by webkit, then we need to suppress the upcoming Char |
| 320 | // events. |
| 321 | if (!processed && is_keyboard_shortcut) |
| 322 | suppress_next_char_events_ = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 323 | |
| 324 | IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_); |
| 325 | response->WriteInt(input_event->type); |
[email protected] | e282441 | 2009-02-27 01:57:05 | [diff] [blame] | 326 | response->WriteBool(processed); |
| 327 | |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 328 | if (input_event->type == WebInputEvent::MouseMove && |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 329 | paint_aggregator_.HasPendingUpdate()) { |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 330 | // We want to rate limit the input events in this case, so we'll wait for |
| 331 | // painting to finish before ACKing this message. |
| 332 | pending_input_event_ack_.reset(response); |
| 333 | } else { |
| 334 | Send(response); |
| 335 | } |
| 336 | |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 337 | handling_input_event_ = false; |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 338 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 339 | if (WebInputEvent::isKeyboardEventType(input_event->type)) |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 340 | DidHandleKeyEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | void RenderWidget::OnMouseCaptureLost() { |
| 344 | if (webwidget_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 345 | webwidget_->mouseCaptureLost(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void RenderWidget::OnSetFocus(bool enable) { |
| 349 | has_focus_ = enable; |
[email protected] | 9d166af | 2010-03-02 22:04:33 | [diff] [blame] | 350 | if (webwidget_) |
| 351 | webwidget_->setFocus(enable); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 352 | if (enable) { |
| 353 | // Force to retrieve the state of the focused widget to determine if we |
| 354 | // should activate IMEs next time when this process calls the UpdateIME() |
| 355 | // function. |
| 356 | ime_control_updated_ = true; |
| 357 | ime_control_new_state_ = true; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | void RenderWidget::ClearFocus() { |
| 362 | // We may have got the focus from the browser before this gets processed, in |
| 363 | // which case we do not want to unfocus ourself. |
| 364 | if (!has_focus_ && webwidget_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 365 | webwidget_->setFocus(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 366 | } |
| 367 | |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 368 | void RenderWidget::PaintRect(const gfx::Rect& rect, |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 369 | const gfx::Point& canvas_origin, |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 370 | skia::PlatformCanvas* canvas) { |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 371 | canvas->save(); |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 372 | |
| 373 | // Bring the canvas into the coordinate system of the paint rect. |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 374 | canvas->translate(static_cast<SkScalar>(-canvas_origin.x()), |
| 375 | static_cast<SkScalar>(-canvas_origin.y())); |
[email protected] | 96c3499a | 2009-05-02 18:31:03 | [diff] [blame] | 376 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 377 | // If there is a custom background, tile it. |
| 378 | if (!background_.empty()) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 379 | SkPaint paint; |
| 380 | SkShader* shader = SkShader::CreateBitmapShader(background_, |
| 381 | SkShader::kRepeat_TileMode, |
| 382 | SkShader::kRepeat_TileMode); |
| 383 | paint.setShader(shader)->unref(); |
[email protected] | 8860e4f5 | 2009-06-25 01:01:52 | [diff] [blame] | 384 | paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 385 | canvas->drawPaint(paint); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 386 | } |
| 387 | |
[email protected] | 8c89e779 | 2009-08-19 21:18:34 | [diff] [blame] | 388 | webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 389 | |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 390 | PaintDebugBorder(rect, canvas); |
| 391 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 392 | // Flush to underlying bitmap. TODO(darin): is this needed? |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 393 | canvas->getTopPlatformDevice().accessBitmap(false); |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 394 | |
| 395 | canvas->restore(); |
| 396 | } |
| 397 | |
| 398 | void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, |
| 399 | skia::PlatformCanvas* canvas) { |
| 400 | static bool kPaintBorder = |
| 401 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects); |
| 402 | if (!kPaintBorder) |
| 403 | return; |
| 404 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 405 | // Cycle through these colors to help distinguish new paint rects. |
| 406 | const SkColor colors[] = { |
| 407 | SkColorSetARGB(0x3F, 0xFF, 0, 0), |
| 408 | SkColorSetARGB(0x3F, 0xFF, 0, 0xFF), |
| 409 | SkColorSetARGB(0x3F, 0, 0, 0xFF), |
| 410 | }; |
| 411 | static int color_selector = 0; |
| 412 | |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 413 | SkPaint paint; |
| 414 | paint.setStyle(SkPaint::kStroke_Style); |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 415 | paint.setColor(colors[color_selector++ % arraysize(colors)]); |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 416 | paint.setStrokeWidth(1); |
| 417 | |
| 418 | SkIRect irect; |
| 419 | irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1); |
| 420 | canvas->drawIRect(irect, paint); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 421 | } |
| 422 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 423 | void RenderWidget::CallDoDeferredUpdate() { |
| 424 | DoDeferredUpdate(); |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 425 | |
| 426 | if (pending_input_event_ack_.get()) { |
| 427 | Send(pending_input_event_ack_.get()); |
| 428 | pending_input_event_ack_.release(); |
| 429 | } |
| 430 | } |
| 431 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 432 | void RenderWidget::DoDeferredUpdate() { |
| 433 | if (!webwidget_ || !paint_aggregator_.HasPendingUpdate() || |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 434 | update_reply_pending()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 435 | return; |
| 436 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 437 | // Suppress updating when we are hidden. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 438 | if (is_hidden_ || size_.IsEmpty()) { |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 439 | paint_aggregator_.ClearPendingUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 440 | needs_repainting_on_restore_ = true; |
| 441 | return; |
| 442 | } |
| 443 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 444 | // Layout may generate more invalidation. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 445 | webwidget_->layout(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 446 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 447 | // OK, save the pending update to a local since painting may cause more |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 448 | // invalidation. Some WebCore rendering objects only layout when painted. |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 449 | PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate(); |
| 450 | paint_aggregator_.ClearPendingUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 451 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 452 | gfx::Rect scroll_damage = update.GetScrollDamage(); |
| 453 | gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 454 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 455 | // Compute a buffer for painting and cache it. |
| 456 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 457 | RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, bounds)); |
| 458 | if (!canvas.get()) { |
| 459 | NOTREACHED(); |
| 460 | return; |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 461 | } |
| 462 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 463 | // We may get back a smaller canvas than we asked for. |
| 464 | // TODO(darin): This seems like it could cause painting problems! |
| 465 | DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); |
| 466 | DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); |
| 467 | bounds.set_width(canvas->getDevice()->width()); |
| 468 | bounds.set_height(canvas->getDevice()->height()); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 469 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 470 | HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size()); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 471 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 472 | // TODO(darin): Re-enable painting multiple damage rects once the |
| 473 | // page-cycler regressions are resolved. See bug 29589. |
| 474 | if (update.scroll_rect.IsEmpty()) { |
| 475 | update.paint_rects.clear(); |
| 476 | update.paint_rects.push_back(bounds); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 477 | } |
| 478 | |
[email protected] | cef3362f | 2009-12-21 17:48:45 | [diff] [blame] | 479 | // The scroll damage is just another rectangle to paint and copy. |
| 480 | std::vector<gfx::Rect> copy_rects; |
| 481 | copy_rects.swap(update.paint_rects); |
| 482 | if (!scroll_damage.IsEmpty()) |
| 483 | copy_rects.push_back(scroll_damage); |
| 484 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 485 | for (size_t i = 0; i < copy_rects.size(); ++i) |
| 486 | PaintRect(copy_rects[i], bounds.origin(), canvas.get()); |
| 487 | |
| 488 | ViewHostMsg_UpdateRect_Params params; |
| 489 | params.bitmap = current_paint_buf_->id(); |
| 490 | params.bitmap_rect = bounds; |
| 491 | params.dx = update.scroll_delta.x(); |
| 492 | params.dy = update.scroll_delta.y(); |
| 493 | params.scroll_rect = update.scroll_rect; |
| 494 | params.copy_rects.swap(copy_rects); // TODO(darin): clip to bounds? |
| 495 | params.view_size = size_; |
| 496 | params.plugin_window_moves.swap(plugin_window_moves_); |
| 497 | params.flags = next_paint_flags_; |
| 498 | |
| 499 | update_reply_pending_ = true; |
| 500 | Send(new ViewHostMsg_UpdateRect(routing_id_, params)); |
| 501 | next_paint_flags_ = 0; |
| 502 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 503 | UpdateIME(); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 504 | |
| 505 | // Let derived classes know we've painted. |
| 506 | DidInitiatePaint(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /////////////////////////////////////////////////////////////////////////////// |
| 510 | // WebWidgetDelegate |
| 511 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 512 | void RenderWidget::didInvalidateRect(const WebRect& rect) { |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 513 | // We only want one pending DoDeferredUpdate call at any time... |
| 514 | bool update_pending = paint_aggregator_.HasPendingUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 515 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 516 | // The invalidated rect might be outside the bounds of the view. |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 517 | gfx::Rect view_rect(0, 0, size_.width(), size_.height()); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 518 | gfx::Rect damaged_rect = view_rect.Intersect(rect); |
| 519 | if (damaged_rect.IsEmpty()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 520 | return; |
| 521 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 522 | paint_aggregator_.InvalidateRect(damaged_rect); |
| 523 | |
| 524 | // We may not need to schedule another call to DoDeferredUpdate. |
| 525 | if (update_pending) |
| 526 | return; |
| 527 | if (!paint_aggregator_.HasPendingUpdate()) |
| 528 | return; |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 529 | if (update_reply_pending()) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 530 | return; |
| 531 | |
| 532 | // Perform updating asynchronously. This serves two purposes: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 533 | // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 534 | // on the call stack. |
| 535 | // 2) Allows us to collect more damage rects before painting to help coalesce |
| 536 | // the work that we will need to do. |
| 537 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 538 | this, &RenderWidget::CallDoDeferredUpdate)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 539 | } |
| 540 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 541 | void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 542 | // We only want one pending DoDeferredUpdate call at any time... |
| 543 | bool update_pending = paint_aggregator_.HasPendingUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 544 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 545 | // The scrolled rect might be outside the bounds of the view. |
| 546 | gfx::Rect view_rect(0, 0, size_.width(), size_.height()); |
| 547 | gfx::Rect damaged_rect = view_rect.Intersect(clip_rect); |
| 548 | if (damaged_rect.IsEmpty()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 549 | return; |
| 550 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 551 | paint_aggregator_.ScrollRect(dx, dy, damaged_rect); |
| 552 | |
| 553 | // We may not need to schedule another call to DoDeferredUpdate. |
| 554 | if (update_pending) |
| 555 | return; |
| 556 | if (!paint_aggregator_.HasPendingUpdate()) |
| 557 | return; |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 558 | if (update_reply_pending()) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 559 | return; |
| 560 | |
| 561 | // Perform updating asynchronously. This serves two purposes: |
| 562 | // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 563 | // on the call stack. |
| 564 | // 2) Allows us to collect more damage rects before painting to help coalesce |
| 565 | // the work that we will need to do. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 566 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 567 | this, &RenderWidget::CallDoDeferredUpdate)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 568 | } |
| 569 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 570 | void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 571 | // TODO(darin): Eliminate this temporary. |
| 572 | WebCursor cursor(cursor_info); |
| 573 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 574 | // Only send a SetCursor message if we need to make a change. |
| 575 | if (!current_cursor_.IsEqual(cursor)) { |
| 576 | current_cursor_ = cursor; |
| 577 | Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | // We are supposed to get a single call to Show for a newly created RenderWidget |
| 582 | // that was created via RenderWidget::CreateWebView. So, we wait until this |
| 583 | // point to dispatch the ShowWidget message. |
| 584 | // |
| 585 | // This method provides us with the information about how to display the newly |
| 586 | // created RenderWidget (i.e., as a constrained popup or as a new tab). |
| 587 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 588 | void RenderWidget::show(WebNavigationPolicy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 589 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 590 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 591 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 592 | |
| 593 | if (!did_show_) { |
| 594 | did_show_ = true; |
| 595 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 596 | // that's okay. It'll be ignored if as_popup is false, or the browser |
| 597 | // process will impose a default position otherwise. |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 598 | if (popup_params_.get()) { |
| 599 | popup_params_->bounds = initial_pos_; |
| 600 | Send(new ViewHostMsg_ShowPopup(routing_id_, *popup_params_)); |
| 601 | popup_params_.reset(); |
| 602 | } else { |
| 603 | Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_)); |
| 604 | } |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 605 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 609 | void RenderWidget::didFocus() { |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 610 | // Note that didFocus() is invoked everytime a new node is focused in the |
| 611 | // page. It could be expected that it would be called only when the widget |
| 612 | // gets the focus. If the current behavior was to change in WebKit for the |
| 613 | // expected one, the following notification would not work anymore. |
| 614 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_)); |
| 615 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 616 | // Prevent the widget from stealing the focus if it does not have focus |
| 617 | // already. We do this by explicitely setting the focus to false again. |
| 618 | // We only let the browser focus the renderer. |
| 619 | if (!has_focus_ && webwidget_) { |
| 620 | MessageLoop::current()->PostTask(FROM_HERE, |
| 621 | NewRunnableMethod(this, &RenderWidget::ClearFocus)); |
| 622 | } |
| 623 | } |
| 624 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 625 | void RenderWidget::didBlur() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 626 | Send(new ViewHostMsg_Blur(routing_id_)); |
| 627 | } |
| 628 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 629 | void RenderWidget::DoDeferredClose() { |
| 630 | Send(new ViewHostMsg_Close(routing_id_)); |
| 631 | } |
| 632 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 633 | void RenderWidget::closeWidgetSoon() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 634 | // If a page calls window.close() twice, we'll end up here twice, but that's |
| 635 | // OK. It is safe to send multiple Close messages. |
| 636 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 637 | // Ask the RenderWidgetHost to initiate close. We could be called from deep |
| 638 | // in Javascript. If we ask the RendwerWidgetHost to close now, the window |
| 639 | // could be closed before the JS finishes executing. So instead, post a |
| 640 | // message back to the message loop, which won't run until the JS is |
| 641 | // complete, and then the Close message can be sent. |
[email protected] | 75ae449 | 2009-07-10 00:05:15 | [diff] [blame] | 642 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 643 | this, &RenderWidget::DoDeferredClose)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 644 | } |
| 645 | |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 646 | void RenderWidget::GenerateFullRepaint() { |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 647 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 648 | } |
| 649 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 650 | void RenderWidget::Close() { |
| 651 | if (webwidget_) { |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 652 | webwidget_->close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 653 | webwidget_ = NULL; |
| 654 | } |
| 655 | } |
| 656 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 657 | WebRect RenderWidget::windowRect() { |
| 658 | if (pending_window_rect_count_) |
| 659 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 660 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 661 | gfx::Rect rect; |
| 662 | Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect)); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 663 | return rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 664 | } |
| 665 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 666 | void RenderWidget::setWindowRect(const WebRect& pos) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 667 | if (did_show_) { |
| 668 | Send(new ViewHostMsg_RequestMove(routing_id_, pos)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 669 | SetPendingWindowRect(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 670 | } else { |
| 671 | initial_pos_ = pos; |
| 672 | } |
| 673 | } |
| 674 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 675 | void RenderWidget::SetPendingWindowRect(const WebRect& rect) { |
| 676 | pending_window_rect_ = rect; |
| 677 | pending_window_rect_count_++; |
| 678 | } |
| 679 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 680 | WebRect RenderWidget::rootWindowRect() { |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 681 | if (pending_window_rect_count_) { |
| 682 | // NOTE(mbelshe): If there is a pending_window_rect_, then getting |
| 683 | // the RootWindowRect is probably going to return wrong results since the |
| 684 | // browser may not have processed the Move yet. There isn't really anything |
| 685 | // good to do in this case, and it shouldn't happen - since this size is |
| 686 | // only really needed for windowToScreen, which is only used for Popups. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 687 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 688 | } |
| 689 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 690 | gfx::Rect rect; |
| 691 | Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect)); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 692 | return rect; |
[email protected] | d454745 | 2008-08-28 18:36:37 | [diff] [blame] | 693 | } |
| 694 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 695 | WebRect RenderWidget::windowResizerRect() { |
| 696 | return resizer_rect_; |
[email protected] | c04b636 | 2008-11-21 18:54:19 | [diff] [blame] | 697 | } |
| 698 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 699 | void RenderWidget::OnImeSetInputMode(bool is_active) { |
[email protected] | c4bb35a | 2008-10-31 17:54:03 | [diff] [blame] | 700 | // To prevent this renderer process from sending unnecessary IPC messages to |
| 701 | // a browser process, we permit the renderer process to send IPC messages |
| 702 | // only during the IME attached to the browser process is active. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 703 | ime_is_active_ = is_active; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 704 | } |
| 705 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 706 | void RenderWidget::OnImeSetComposition(WebCompositionCommand command, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 707 | int cursor_position, |
| 708 | int target_start, int target_end, |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 709 | const string16& ime_string) { |
| 710 | if (!webwidget_) |
| 711 | return; |
| 712 | ime_control_busy_ = true; |
[email protected] | 7f00efa | 2010-04-15 05:01:26 | [diff] [blame^] | 713 | if (!webwidget_->handleCompositionEvent(command, cursor_position, |
| 714 | target_start, target_end, ime_string)) { |
| 715 | // If the composition event can't be handled, let the browser process |
| 716 | // know so it can update it's state. |
| 717 | Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), IME_CANCEL_COMPOSITION, |
| 718 | WebRect())); |
| 719 | } |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 720 | ime_control_busy_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 721 | } |
| 722 | |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 723 | void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { |
| 724 | // During shutdown we can just ignore this message. |
| 725 | if (!webwidget_) |
| 726 | return; |
| 727 | |
| 728 | set_next_paint_is_repaint_ack(); |
| 729 | gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 730 | didInvalidateRect(repaint_rect); |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 731 | } |
| 732 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 733 | void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 734 | if (!webwidget_) |
| 735 | return; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 736 | webwidget_->setTextDirection(direction); |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 737 | } |
| 738 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 739 | void RenderWidget::SetHidden(bool hidden) { |
| 740 | if (is_hidden_ == hidden) |
| 741 | return; |
| 742 | |
| 743 | // The status has changed. Tell the RenderThread about it. |
| 744 | is_hidden_ = hidden; |
| 745 | if (is_hidden_) |
| 746 | render_thread_->WidgetHidden(); |
| 747 | else |
| 748 | render_thread_->WidgetRestored(); |
| 749 | } |
| 750 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 751 | void RenderWidget::SetBackground(const SkBitmap& background) { |
| 752 | background_ = background; |
| 753 | // Generate a full repaint. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 754 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 755 | } |
| 756 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 757 | bool RenderWidget::next_paint_is_resize_ack() const { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 758 | return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | bool RenderWidget::next_paint_is_restore_ack() const { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 762 | return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | void RenderWidget::set_next_paint_is_resize_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 766 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | void RenderWidget::set_next_paint_is_restore_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 770 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | void RenderWidget::set_next_paint_is_repaint_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 774 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 775 | } |
| 776 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 777 | void RenderWidget::UpdateIME() { |
| 778 | // If a browser process does not have IMEs, its IMEs are not active, or there |
| 779 | // are not any attached widgets. |
| 780 | // a renderer process does not have to retrieve information of the focused |
| 781 | // control or send notification messages to a browser process. |
| 782 | if (!ime_is_active_) { |
| 783 | return; |
| 784 | } |
[email protected] | 34f6bc1 | 2008-11-06 07:40:53 | [diff] [blame] | 785 | // Retrieve the caret position from the focused widget and verify we should |
| 786 | // enabled IMEs attached to the browser process. |
| 787 | bool enable_ime = false; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 788 | WebRect caret_rect; |
[email protected] | 34f6bc1 | 2008-11-06 07:40:53 | [diff] [blame] | 789 | if (!webwidget_ || |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 790 | !webwidget_->queryCompositionStatus(&enable_ime, &caret_rect)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 791 | // There are not any editable widgets attached to this process. |
| 792 | // We should disable the IME to prevent it from sending CJK strings to |
| 793 | // non-editable widgets. |
| 794 | ime_control_updated_ = true; |
| 795 | ime_control_new_state_ = false; |
| 796 | } |
[email protected] | 9f23f59 | 2008-11-17 08:36:34 | [diff] [blame] | 797 | if (ime_control_new_state_ != enable_ime) { |
| 798 | ime_control_updated_ = true; |
| 799 | ime_control_new_state_ = enable_ime; |
| 800 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 801 | if (ime_control_updated_) { |
| 802 | // The input focus has been changed. |
| 803 | // Compare the current state with the updated state and choose actions. |
| 804 | if (ime_control_enable_ime_) { |
| 805 | if (ime_control_new_state_) { |
| 806 | // Case 1: a text input -> another text input |
| 807 | // Complete the current composition and notify the caret position. |
[email protected] | 34f6bc1 | 2008-11-06 07:40:53 | [diff] [blame] | 808 | Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), |
| 809 | IME_COMPLETE_COMPOSITION, |
| 810 | caret_rect)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 811 | } else { |
| 812 | // Case 2: a text input -> a password input (or a static control) |
| 813 | // Complete the current composition and disable the IME. |
[email protected] | 34f6bc1 | 2008-11-06 07:40:53 | [diff] [blame] | 814 | Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), IME_DISABLE, |
| 815 | caret_rect)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 816 | } |
| 817 | } else { |
| 818 | if (ime_control_new_state_) { |
| 819 | // Case 3: a password input (or a static control) -> a text input |
| 820 | // Enable the IME and notify the caret position. |
[email protected] | 34f6bc1 | 2008-11-06 07:40:53 | [diff] [blame] | 821 | Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), |
| 822 | IME_COMPLETE_COMPOSITION, |
| 823 | caret_rect)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 824 | } else { |
| 825 | // Case 4: a password input (or a static contol) -> another password |
| 826 | // input (or another static control). |
| 827 | // The IME has been already disabled and we don't have to do anything. |
| 828 | } |
| 829 | } |
| 830 | } else { |
| 831 | // The input focus is not changed. |
| 832 | // Notify the caret position to a browser process only if it is changed. |
| 833 | if (ime_control_enable_ime_) { |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 834 | if (caret_rect.x != ime_control_x_ || |
| 835 | caret_rect.y != ime_control_y_) { |
[email protected] | 34f6bc1 | 2008-11-06 07:40:53 | [diff] [blame] | 836 | Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), IME_MOVE_WINDOWS, |
| 837 | caret_rect)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | } |
| 841 | // Save the updated IME status to prevent from sending the same IPC messages. |
| 842 | ime_control_updated_ = false; |
| 843 | ime_control_enable_ime_ = ime_control_new_state_; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 844 | ime_control_x_ = caret_rect.x; |
| 845 | ime_control_y_ = caret_rect.y; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 846 | } |
| 847 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 848 | WebScreenInfo RenderWidget::screenInfo() { |
| 849 | WebScreenInfo results; |
| 850 | Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results)); |
| 851 | return results; |
| 852 | } |
| 853 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 854 | void RenderWidget::SchedulePluginMove( |
| 855 | const webkit_glue::WebPluginGeometry& move) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 856 | size_t i = 0; |
| 857 | for (; i < plugin_window_moves_.size(); ++i) { |
| 858 | if (plugin_window_moves_[i].window == move.window) { |
[email protected] | 16f89d0 | 2009-08-26 17:17:58 | [diff] [blame] | 859 | if (move.rects_valid) { |
| 860 | plugin_window_moves_[i] = move; |
| 861 | } else { |
| 862 | plugin_window_moves_[i].visible = move.visible; |
| 863 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 864 | break; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | if (i == plugin_window_moves_.size()) |
| 869 | plugin_window_moves_.push_back(move); |
| 870 | } |
[email protected] | 26865477 | 2009-08-06 23:02:04 | [diff] [blame] | 871 | |
| 872 | void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
| 873 | for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
| 874 | i != plugin_window_moves_.end(); ++i) { |
| 875 | if (i->window == window) { |
| 876 | plugin_window_moves_.erase(i); |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | } |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 881 | |