[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" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 11 | #include "base/metrics/histogram.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "base/scoped_ptr.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 14 | #include "chrome/common/chrome_switches.h" |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 15 | #include "chrome/common/render_messages.h" |
[email protected] | 939856a | 2010-08-24 20:29:02 | [diff] [blame] | 16 | #include "chrome/common/render_messages_params.h" |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 17 | #include "chrome/renderer/render_process.h" |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 18 | #include "chrome/renderer/render_thread.h" |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 19 | #include "ipc/ipc_sync_message.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 20 | #include "skia/ext/platform_canvas.h" |
[email protected] | d5282e7 | 2009-05-13 13:16:52 | [diff] [blame] | 21 | #include "third_party/skia/include/core/SkShader.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 22 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 23 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
| 24 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" |
| 25 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
| 26 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
| 27 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 28 | #include "ui/gfx/point.h" |
| 29 | #include "ui/gfx/size.h" |
[email protected] | 8c89e779 | 2009-08-19 21:18:34 | [diff] [blame] | 30 | #include "webkit/glue/webkit_glue.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 31 | #include "webkit/plugins/npapi/webplugin.h" |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 32 | #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 33 | |
| 34 | #if defined(OS_POSIX) |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 35 | #include "ipc/ipc_channel_posix.h" |
[email protected] | d5282e7 | 2009-05-13 13:16:52 | [diff] [blame] | 36 | #include "third_party/skia/include/core/SkPixelRef.h" |
| 37 | #include "third_party/skia/include/core/SkMallocPixelRef.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 38 | #endif // defined(OS_POSIX) |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 39 | |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 40 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 42 | using WebKit::WebCompositionUnderline; |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 43 | using WebKit::WebCursorInfo; |
[email protected] | 62cb33cae | 2009-03-27 23:30:22 | [diff] [blame] | 44 | using WebKit::WebInputEvent; |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 45 | using WebKit::WebMouseEvent; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 46 | using WebKit::WebNavigationPolicy; |
| 47 | using WebKit::WebPopupMenu; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 48 | using WebKit::WebPopupMenuInfo; |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 49 | using WebKit::WebPopupType; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 50 | using WebKit::WebRect; |
[email protected] | 12456fa | 2009-04-01 23:07:19 | [diff] [blame] | 51 | using WebKit::WebScreenInfo; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 52 | using WebKit::WebSize; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 53 | using WebKit::WebTextDirection; |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 54 | using WebKit::WebTextInputType; |
| 55 | using WebKit::WebVector; |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 56 | using WebKit::WebWidget; |
[email protected] | 62cb33cae | 2009-03-27 23:30:22 | [diff] [blame] | 57 | |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 58 | RenderWidget::RenderWidget(RenderThreadBase* render_thread, |
| 59 | WebKit::WebPopupType popup_type) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 60 | : routing_id_(MSG_ROUTING_NONE), |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 61 | webwidget_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 62 | opener_id_(MSG_ROUTING_NONE), |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 63 | render_thread_(render_thread), |
[email protected] | 659f73f | 2009-10-13 13:43:42 | [diff] [blame] | 64 | host_window_(0), |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 65 | current_paint_buf_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 66 | next_paint_flags_(0), |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 67 | update_reply_pending_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | did_show_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 69 | is_hidden_(false), |
| 70 | needs_repainting_on_restore_(false), |
| 71 | has_focus_(false), |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 72 | handling_input_event_(false), |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 73 | closing_(false), |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 74 | input_method_is_active_(false), |
| 75 | text_input_type_(WebKit::WebTextInputTypeNone), |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 76 | popup_type_(popup_type), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 77 | pending_window_rect_count_(0), |
[email protected] | edbcde93 | 2010-05-07 17:10:46 | [diff] [blame] | 78 | suppress_next_char_events_(false), |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 79 | is_accelerated_compositing_active_(false), |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 80 | animation_update_pending_(false), |
| 81 | animation_waiting_for_paint_(false) { |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 82 | RenderProcess::current()->AddRefProcess(); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 83 | DCHECK(render_thread_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | RenderWidget::~RenderWidget() { |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 87 | DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 88 | if (current_paint_buf_) { |
| 89 | RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 90 | current_paint_buf_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 91 | } |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 92 | RenderProcess::current()->ReleaseProcess(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 93 | } |
| 94 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 95 | // static |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 96 | RenderWidget* RenderWidget::Create(int32 opener_id, |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 97 | RenderThreadBase* render_thread, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 98 | WebKit::WebPopupType popup_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | DCHECK(opener_id != MSG_ROUTING_NONE); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 100 | scoped_refptr<RenderWidget> widget(new RenderWidget(render_thread, |
| 101 | popup_type)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 102 | widget->Init(opener_id); // adds reference |
| 103 | return widget; |
| 104 | } |
| 105 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 106 | // static |
| 107 | WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) { |
| 108 | switch (render_widget->popup_type_) { |
[email protected] | e235624 | 2010-11-16 22:33:03 | [diff] [blame] | 109 | case WebKit::WebPopupTypeNone: // Nothing to create. |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 110 | break; |
| 111 | case WebKit::WebPopupTypeSelect: |
| 112 | case WebKit::WebPopupTypeSuggestion: |
| 113 | return WebPopupMenu::create(render_widget); |
| 114 | default: |
| 115 | NOTREACHED(); |
| 116 | } |
| 117 | return NULL; |
| 118 | } |
| 119 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 120 | void RenderWidget::Init(int32 opener_id) { |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 121 | DoInit(opener_id, |
| 122 | RenderWidget::CreateWebWidget(this), |
| 123 | new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_)); |
| 124 | } |
| 125 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 126 | void RenderWidget::DoInit(int32 opener_id, |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 127 | WebWidget* web_widget, |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 128 | IPC::SyncMessage* create_widget_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | DCHECK(!webwidget_); |
| 130 | |
| 131 | if (opener_id != MSG_ROUTING_NONE) |
| 132 | opener_id_ = opener_id; |
| 133 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 134 | webwidget_ = web_widget; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 135 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 136 | bool result = render_thread_->Send(create_widget_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 137 | if (result) { |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 138 | render_thread_->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 139 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 140 | // when we receive ViewMsg_Close. |
| 141 | AddRef(); |
| 142 | } else { |
| 143 | DCHECK(false); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // This is used to complete pending inits and non-pending inits. For non- |
| 148 | // pending cases, the parent will be the same as the current parent. This |
| 149 | // indicates we do not need to reparent or anything. |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 150 | void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 152 | |
| 153 | host_window_ = parent_hwnd; |
| 154 | |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 155 | Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 158 | bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
| 159 | bool handled = true; |
| 160 | IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) |
| 161 | IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
| 162 | IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) |
| 163 | IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) |
| 164 | IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
| 165 | IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored) |
| 166 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) |
| 167 | IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) |
| 168 | IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) |
| 169 | IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) |
| 170 | IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive) |
| 171 | IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) |
| 172 | IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition) |
| 173 | IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize) |
| 174 | IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) |
| 175 | IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
| 176 | IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
| 177 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 178 | IPC_END_MESSAGE_MAP() |
| 179 | return handled; |
| 180 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 181 | |
| 182 | bool RenderWidget::Send(IPC::Message* message) { |
| 183 | // Don't send any messages after the browser has told us to close. |
| 184 | if (closing_) { |
| 185 | delete message; |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | // If given a messsage without a routing ID, then assign our routing ID. |
| 190 | if (message->routing_id() == MSG_ROUTING_NONE) |
| 191 | message->set_routing_id(routing_id_); |
| 192 | |
[email protected] | d3fc2565 | 2009-02-24 22:31:25 | [diff] [blame] | 193 | return render_thread_->Send(message); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 194 | } |
| 195 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 196 | // Got a response from the browser after the renderer decided to create a new |
| 197 | // view. |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 198 | void RenderWidget::OnCreatingNewAck(gfx::NativeViewId parent) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 199 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 200 | |
| 201 | CompleteInit(parent); |
| 202 | } |
| 203 | |
| 204 | void RenderWidget::OnClose() { |
| 205 | if (closing_) |
| 206 | return; |
| 207 | closing_ = true; |
| 208 | |
| 209 | // Browser correspondence is no longer needed at this point. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 210 | if (routing_id_ != MSG_ROUTING_NONE) { |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 211 | render_thread_->RemoveRoute(routing_id_); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 212 | SetHidden(false); |
| 213 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 214 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 215 | // 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] | 216 | // now. Post a task that only gets invoked when there are no nested message |
| 217 | // loops. |
| 218 | MessageLoop::current()->PostNonNestableTask(FROM_HERE, |
| 219 | NewRunnableMethod(this, &RenderWidget::Close)); |
| 220 | |
| 221 | // Balances the AddRef taken when we called AddRoute. |
| 222 | Release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 223 | } |
| 224 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 225 | void RenderWidget::OnResize(const gfx::Size& new_size, |
| 226 | const gfx::Rect& resizer_rect) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 227 | // During shutdown we can just ignore this message. |
| 228 | if (!webwidget_) |
| 229 | return; |
| 230 | |
[email protected] | e235624 | 2010-11-16 22:33:03 | [diff] [blame] | 231 | // We shouldn't be asked to resize to our current size. |
| 232 | DCHECK(size_ != new_size || resizer_rect_ != resizer_rect); |
| 233 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 234 | // Remember the rect where the resize corner will be drawn. |
| 235 | resizer_rect_ = resizer_rect; |
| 236 | |
[email protected] | e235624 | 2010-11-16 22:33:03 | [diff] [blame] | 237 | if (size_ == new_size) |
| 238 | return; |
| 239 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 240 | // TODO(darin): We should not need to reset this here. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 241 | SetHidden(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 242 | needs_repainting_on_restore_ = false; |
| 243 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 244 | size_ = new_size; |
| 245 | |
| 246 | // We should not be sent a Resize message if we have not ACK'd the previous |
| 247 | DCHECK(!next_paint_is_resize_ack()); |
| 248 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 249 | paint_aggregator_.ClearPendingUpdate(); |
| 250 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 251 | // When resizing, we want to wait to paint before ACK'ing the resize. This |
| 252 | // ensures that we only resize as fast as we can paint. We only need to send |
| 253 | // an ACK if we are resized to a non-empty rect. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 254 | webwidget_->resize(new_size); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 255 | if (!new_size.IsEmpty()) { |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 256 | if (!is_accelerated_compositing_active_) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 257 | // Resize should have caused an invalidation of the entire view. |
| 258 | DCHECK(paint_aggregator_.HasPendingUpdate()); |
| 259 | } |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 260 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 261 | // We will send the Resize_ACK flag once we paint again. |
| 262 | set_next_paint_is_resize_ack(); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | void RenderWidget::OnWasHidden() { |
| 267 | // Go into a mode where we stop generating paint and scrolling events. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 268 | SetHidden(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void RenderWidget::OnWasRestored(bool needs_repainting) { |
| 272 | // During shutdown we can just ignore this message. |
| 273 | if (!webwidget_) |
| 274 | return; |
| 275 | |
| 276 | // See OnWasHidden |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 277 | SetHidden(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 278 | |
| 279 | if (!needs_repainting && !needs_repainting_on_restore_) |
| 280 | return; |
| 281 | needs_repainting_on_restore_ = false; |
| 282 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 283 | // Tag the next paint as a restore ack, which is picked up by |
| 284 | // DoDeferredUpdate when it sends out the next PaintRect message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 285 | set_next_paint_is_restore_ack(); |
| 286 | |
| 287 | // Generate a full repaint. |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 288 | if (!is_accelerated_compositing_active_) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 289 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
| 290 | } else { |
| 291 | scheduleComposite(); |
| 292 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 295 | void RenderWidget::OnRequestMoveAck() { |
| 296 | DCHECK(pending_window_rect_count_); |
| 297 | pending_window_rect_count_--; |
| 298 | } |
| 299 | |
| 300 | void RenderWidget::OnUpdateRectAck() { |
| 301 | DCHECK(update_reply_pending()); |
| 302 | update_reply_pending_ = false; |
| 303 | |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 304 | // If we sent an UpdateRect message with a zero-sized bitmap, then we should |
| 305 | // have no current paint buffer. |
| 306 | if (current_paint_buf_) { |
| 307 | RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 308 | current_paint_buf_ = NULL; |
| 309 | } |
| 310 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 311 | // Notify subclasses. |
| 312 | DidFlushPaint(); |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 313 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 314 | // Continue painting if necessary... |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 315 | CallDoDeferredUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 316 | } |
| 317 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 318 | void RenderWidget::OnHandleInputEvent(const IPC::Message& message) { |
| 319 | void* iter = NULL; |
| 320 | |
| 321 | const char* data; |
| 322 | int data_length; |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 323 | handling_input_event_ = true; |
| 324 | if (!message.ReadData(&iter, &data, &data_length)) { |
| 325 | handling_input_event_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 326 | return; |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 327 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 328 | |
| 329 | const WebInputEvent* input_event = |
| 330 | reinterpret_cast<const WebInputEvent*>(data); |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 331 | |
| 332 | bool is_keyboard_shortcut = false; |
| 333 | // is_keyboard_shortcut flag is only available for RawKeyDown events. |
| 334 | if (input_event->type == WebInputEvent::RawKeyDown) |
| 335 | message.ReadBool(&iter, &is_keyboard_shortcut); |
| 336 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 337 | bool processed = false; |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 338 | if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { |
| 339 | suppress_next_char_events_ = false; |
| 340 | if (webwidget_) |
| 341 | processed = webwidget_->handleInputEvent(*input_event); |
| 342 | } |
| 343 | |
| 344 | // If this RawKeyDown event corresponds to a browser keyboard shortcut and |
| 345 | // it's not processed by webkit, then we need to suppress the upcoming Char |
| 346 | // events. |
| 347 | if (!processed && is_keyboard_shortcut) |
| 348 | suppress_next_char_events_ = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 349 | |
| 350 | IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_); |
| 351 | response->WriteInt(input_event->type); |
[email protected] | e282441 | 2009-02-27 01:57:05 | [diff] [blame] | 352 | response->WriteBool(processed); |
| 353 | |
[email protected] | 353a34c | 2010-05-28 23:35:17 | [diff] [blame] | 354 | if ((input_event->type == WebInputEvent::MouseMove || |
| 355 | input_event->type == WebInputEvent::MouseWheel) && |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 356 | paint_aggregator_.HasPendingUpdate()) { |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 357 | // We want to rate limit the input events in this case, so we'll wait for |
| 358 | // painting to finish before ACKing this message. |
[email protected] | 353a34c | 2010-05-28 23:35:17 | [diff] [blame] | 359 | if (pending_input_event_ack_.get()) { |
| 360 | // As two different kinds of events could cause us to postpone an ack |
| 361 | // we send it now, if we have one pending. The Browser should never |
| 362 | // send us the same kind of event we are delaying the ack for. |
| 363 | Send(pending_input_event_ack_.release()); |
| 364 | } |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 365 | pending_input_event_ack_.reset(response); |
| 366 | } else { |
| 367 | Send(response); |
| 368 | } |
| 369 | |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 370 | handling_input_event_ = false; |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 371 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 372 | if (WebInputEvent::isKeyboardEventType(input_event->type)) |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 373 | DidHandleKeyEvent(); |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 374 | if (WebInputEvent::isMouseEventType(input_event->type)) |
| 375 | DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | void RenderWidget::OnMouseCaptureLost() { |
| 379 | if (webwidget_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 380 | webwidget_->mouseCaptureLost(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void RenderWidget::OnSetFocus(bool enable) { |
| 384 | has_focus_ = enable; |
[email protected] | 9d166af | 2010-03-02 22:04:33 | [diff] [blame] | 385 | if (webwidget_) |
| 386 | webwidget_->setFocus(enable); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | void RenderWidget::ClearFocus() { |
| 390 | // We may have got the focus from the browser before this gets processed, in |
| 391 | // which case we do not want to unfocus ourself. |
| 392 | if (!has_focus_ && webwidget_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 393 | webwidget_->setFocus(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 396 | void RenderWidget::PaintRect(const gfx::Rect& rect, |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 397 | const gfx::Point& canvas_origin, |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 398 | skia::PlatformCanvas* canvas) { |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 399 | |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 400 | canvas->save(); |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 401 | |
| 402 | // Bring the canvas into the coordinate system of the paint rect. |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 403 | canvas->translate(static_cast<SkScalar>(-canvas_origin.x()), |
| 404 | static_cast<SkScalar>(-canvas_origin.y())); |
[email protected] | 96c3499a | 2009-05-02 18:31:03 | [diff] [blame] | 405 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 406 | // If there is a custom background, tile it. |
| 407 | if (!background_.empty()) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 408 | SkPaint paint; |
| 409 | SkShader* shader = SkShader::CreateBitmapShader(background_, |
| 410 | SkShader::kRepeat_TileMode, |
| 411 | SkShader::kRepeat_TileMode); |
| 412 | paint.setShader(shader)->unref(); |
[email protected] | 8860e4f5 | 2009-06-25 01:01:52 | [diff] [blame] | 413 | paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 414 | canvas->drawPaint(paint); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 417 | // First see if this rect is a plugin that can paint itself faster. |
| 418 | TransportDIB* optimized_dib = NULL; |
| 419 | gfx::Rect optimized_copy_rect, optimized_copy_location; |
| 420 | webkit::ppapi::PluginInstance* optimized_instance = |
| 421 | GetBitmapForOptimizedPluginPaint(rect, &optimized_dib, |
| 422 | &optimized_copy_location, |
| 423 | &optimized_copy_rect); |
| 424 | if (optimized_instance) { |
| 425 | // This plugin can be optimize-painted and we can just ask it to paint |
| 426 | // itself. We don't actually need the TransportDIB in this case. |
| 427 | // |
| 428 | // This is an optimization for PPAPI plugins that know they're on top of |
| 429 | // the page content. If this rect is inside such a plugin, we can save some |
| 430 | // time and avoid re-rendering the page content which we know will be |
| 431 | // covered by the plugin later (this time can be significant, especially |
| 432 | // for a playing movie that is invalidating a lot). |
| 433 | // |
| 434 | // In the plugin movie case, hopefully the similar call to |
| 435 | // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the |
| 436 | // painting, because that avoids copying the plugin image to a different |
| 437 | // paint rect. Unfortunately, if anything on the page is animating other |
| 438 | // than the movie, it break this optimization since the union of the |
| 439 | // invalid regions will be larger than the plugin. |
| 440 | // |
| 441 | // This code optimizes that case, where we can still avoid painting in |
| 442 | // WebKit and filling the background (which can be slow) and just painting |
| 443 | // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still |
| 444 | // required. |
| 445 | optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas), |
[email protected] | 2df1b36 | 2011-01-21 21:22:27 | [diff] [blame] | 446 | optimized_copy_location, rect); |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 447 | } else { |
| 448 | // Normal painting case. |
| 449 | webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); |
| 450 | |
| 451 | // Flush to underlying bitmap. TODO(darin): is this needed? |
| 452 | canvas->getTopPlatformDevice().accessBitmap(false); |
| 453 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 454 | |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 455 | PaintDebugBorder(rect, canvas); |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 456 | canvas->restore(); |
| 457 | } |
| 458 | |
| 459 | void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, |
| 460 | skia::PlatformCanvas* canvas) { |
| 461 | static bool kPaintBorder = |
| 462 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects); |
| 463 | if (!kPaintBorder) |
| 464 | return; |
| 465 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 466 | // Cycle through these colors to help distinguish new paint rects. |
| 467 | const SkColor colors[] = { |
| 468 | SkColorSetARGB(0x3F, 0xFF, 0, 0), |
| 469 | SkColorSetARGB(0x3F, 0xFF, 0, 0xFF), |
| 470 | SkColorSetARGB(0x3F, 0, 0, 0xFF), |
| 471 | }; |
| 472 | static int color_selector = 0; |
| 473 | |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 474 | SkPaint paint; |
| 475 | paint.setStyle(SkPaint::kStroke_Style); |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 476 | paint.setColor(colors[color_selector++ % arraysize(colors)]); |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 477 | paint.setStrokeWidth(1); |
| 478 | |
| 479 | SkIRect irect; |
| 480 | irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1); |
| 481 | canvas->drawIRect(irect, paint); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 482 | } |
| 483 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 484 | void RenderWidget::CallDoDeferredUpdate() { |
| 485 | DoDeferredUpdate(); |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 486 | |
[email protected] | d22d873 | 2010-05-04 19:24:42 | [diff] [blame] | 487 | if (pending_input_event_ack_.get()) |
| 488 | Send(pending_input_event_ack_.release()); |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 489 | } |
| 490 | |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 491 | void RenderWidget::UpdateAnimationsIfNeeded() { |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 492 | if (webwidget_ && !is_hidden() && animation_update_pending_ && |
| 493 | !animation_waiting_for_paint_) { |
[email protected] | 134fb6e | 2011-01-29 00:56:57 | [diff] [blame] | 494 | base::Time now = base::Time::Now(); |
| 495 | if (now >= animation_floor_time_) { |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 496 | UpdateAnimationsAndFloorTime(); |
| 497 | // If updating the animation caused invalidations, make sure that we paint |
| 498 | // at least once before we call animate() again. |
| 499 | // Update layout first as that might cause further invalidations. |
| 500 | webwidget_->layout(); |
| 501 | if (paint_aggregator_.HasPendingUpdate()) |
| 502 | animation_waiting_for_paint_ = true; |
[email protected] | 134fb6e | 2011-01-29 00:56:57 | [diff] [blame] | 503 | } else { |
| 504 | // This code uses base::Time::Now() to calculate the floor and next fire |
| 505 | // time because javascript's Date object uses base::Time::Now(). The |
| 506 | // message loop uses base::TimeTicks, which on windows can have a |
| 507 | // different granularity than base::Time. |
| 508 | // The upshot of all this is that this function might be called before |
| 509 | // base::Time::Now() has advanced past the animation_floor_time_. To |
| 510 | // avoid exposing this delay to javascript, we keep posting delayed |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 511 | // tasks until base::Time::Now() has advanced far enough. |
[email protected] | 134fb6e | 2011-01-29 00:56:57 | [diff] [blame] | 512 | int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp(); |
| 513 | MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
| 514 | this, &RenderWidget::UpdateAnimationsIfNeeded), delay); |
| 515 | } |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 519 | void RenderWidget::UpdateAnimationsAndFloorTime() { |
| 520 | animation_update_pending_ = false; |
| 521 | animation_floor_time_ = |
| 522 | base::Time::Now() + base::TimeDelta::FromMilliseconds(16); |
| 523 | webwidget_->animate(); |
| 524 | } |
| 525 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 526 | void RenderWidget::DoDeferredUpdate() { |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 527 | if (!webwidget_ || update_reply_pending()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 528 | return; |
| 529 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 530 | // Suppress updating when we are hidden. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 531 | if (is_hidden_ || size_.IsEmpty()) { |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 532 | paint_aggregator_.ClearPendingUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 533 | needs_repainting_on_restore_ = true; |
| 534 | return; |
| 535 | } |
| 536 | |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 537 | if (animation_update_pending_) { |
| 538 | if (animation_waiting_for_paint_) { |
| 539 | // If we have pending animation updates but need to paint before updating |
| 540 | // them, post a task to UpdateAnimationsIfNeeded that will either update |
| 541 | // animations directly (if the animation floor time has passed by the time |
| 542 | // the function runs) or post a delayed task if the floor time is not yet |
| 543 | // reached. |
| 544 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 545 | this, &RenderWidget::UpdateAnimationsIfNeeded)); |
| 546 | } else if (base::Time::Now() > animation_floor_time_) { |
| 547 | // Otherwise, if it's time to update the animations go ahead. |
| 548 | UpdateAnimationsAndFloorTime(); |
| 549 | } |
| 550 | } |
| 551 | animation_waiting_for_paint_ = false; |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 552 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 553 | // Layout may generate more invalidation. It may also enable the |
| 554 | // GPU acceleration, so make sure to run layout before we send the |
| 555 | // GpuRenderingActivated message. |
| 556 | webwidget_->layout(); |
| 557 | |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 558 | // Suppress painting if nothing is dirty. This has to be done after updating |
| 559 | // animations running layout as these may generate further invalidations. |
| 560 | if (!paint_aggregator_.HasPendingUpdate()) |
| 561 | return; |
| 562 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 563 | // OK, save the pending update to a local since painting may cause more |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 564 | // invalidation. Some WebCore rendering objects only layout when painted. |
[email protected] | dd01581 | 2010-12-06 23:39:30 | [diff] [blame] | 565 | PaintAggregator::PendingUpdate update; |
| 566 | paint_aggregator_.PopPendingUpdate(&update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 567 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 568 | gfx::Rect scroll_damage = update.GetScrollDamage(); |
| 569 | gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 570 | |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 571 | // A plugin may be able to do an optimized paint. First check this, in which |
| 572 | // case we can skip all of the bitmap generation and regular paint code. |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 573 | // This optimization allows PPAPI plugins that declare themselves on top of |
| 574 | // the page (like a traditional windowed plugin) to be able to animate (think |
| 575 | // movie playing) without repeatedly re-painting the page underneath, or |
| 576 | // copying the plugin backing store (since we can send the plugin's backing |
| 577 | // store directly to the browser). |
| 578 | // |
| 579 | // This optimization only works when the entire invalid region is contained |
| 580 | // within the plugin. There is a related optimization in PaintRect for the |
| 581 | // case where there may be multiple invalid regions. |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 582 | TransportDIB::Id dib_id = TransportDIB::Id(); |
| 583 | TransportDIB* dib = NULL; |
[email protected] | cef3362f | 2009-12-21 17:48:45 | [diff] [blame] | 584 | std::vector<gfx::Rect> copy_rects; |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 585 | gfx::Rect optimized_copy_rect, optimized_copy_location; |
| 586 | if (update.scroll_rect.IsEmpty() && |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 587 | !is_accelerated_compositing_active_ && |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 588 | GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location, |
| 589 | &optimized_copy_rect)) { |
[email protected] | 2df1b36 | 2011-01-21 21:22:27 | [diff] [blame] | 590 | // Only update the part of the plugin that actually changed. |
| 591 | optimized_copy_rect = optimized_copy_rect.Intersect(bounds); |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 592 | bounds = optimized_copy_location; |
| 593 | copy_rects.push_back(optimized_copy_rect); |
| 594 | dib_id = dib->id(); |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 595 | } else if (!is_accelerated_compositing_active_) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 596 | // Compute a buffer for painting and cache it. |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 597 | scoped_ptr<skia::PlatformCanvas> canvas( |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 598 | RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, |
| 599 | bounds)); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 600 | if (!canvas.get()) { |
| 601 | NOTREACHED(); |
| 602 | return; |
| 603 | } |
[email protected] | cef3362f | 2009-12-21 17:48:45 | [diff] [blame] | 604 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 605 | // We may get back a smaller canvas than we asked for. |
| 606 | // TODO(darin): This seems like it could cause painting problems! |
| 607 | DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); |
| 608 | DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); |
| 609 | bounds.set_width(canvas->getDevice()->width()); |
| 610 | bounds.set_height(canvas->getDevice()->height()); |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 611 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 612 | HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size()); |
| 613 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 614 | // The scroll damage is just another rectangle to paint and copy. |
| 615 | copy_rects.swap(update.paint_rects); |
| 616 | if (!scroll_damage.IsEmpty()) |
| 617 | copy_rects.push_back(scroll_damage); |
| 618 | |
| 619 | for (size_t i = 0; i < copy_rects.size(); ++i) |
| 620 | PaintRect(copy_rects[i], bounds.origin(), canvas.get()); |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 621 | |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 622 | dib_id = current_paint_buf_->id(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 623 | } else { // Accelerated compositing path |
| 624 | // Begin painting. |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 625 | webwidget_->composite(false); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | // sending an ack to browser process that the paint is complete... |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 629 | ViewHostMsg_UpdateRect_Params params; |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 630 | params.bitmap = dib_id; |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 631 | params.bitmap_rect = bounds; |
| 632 | params.dx = update.scroll_delta.x(); |
| 633 | params.dy = update.scroll_delta.y(); |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 634 | if (is_accelerated_compositing_active_) { |
[email protected] | b167ca66 | 2010-05-14 00:05:34 | [diff] [blame] | 635 | // If painting is done via the gpu process then we clear out all damage |
| 636 | // rects to save the browser process from doing unecessary work. |
| 637 | params.scroll_rect = gfx::Rect(); |
| 638 | params.copy_rects.clear(); |
| 639 | } else { |
| 640 | params.scroll_rect = update.scroll_rect; |
| 641 | params.copy_rects.swap(copy_rects); // TODO(darin): clip to bounds? |
| 642 | } |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 643 | params.view_size = size_; |
[email protected] | e235624 | 2010-11-16 22:33:03 | [diff] [blame] | 644 | params.resizer_rect = resizer_rect_; |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 645 | params.plugin_window_moves.swap(plugin_window_moves_); |
| 646 | params.flags = next_paint_flags_; |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 647 | params.scroll_offset = GetScrollOffset(); |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 648 | |
| 649 | update_reply_pending_ = true; |
| 650 | Send(new ViewHostMsg_UpdateRect(routing_id_, params)); |
| 651 | next_paint_flags_ = 0; |
| 652 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 653 | UpdateInputMethod(); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 654 | |
| 655 | // Let derived classes know we've painted. |
| 656 | DidInitiatePaint(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 660 | // WebWidgetClient |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 661 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 662 | void RenderWidget::didInvalidateRect(const WebRect& rect) { |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 663 | DCHECK(!is_accelerated_compositing_active_ || |
| 664 | (rect.x == 0 && rect.y == 0 && rect.width == 1 && rect.height == 1)); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 665 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 666 | // We only want one pending DoDeferredUpdate call at any time... |
| 667 | bool update_pending = paint_aggregator_.HasPendingUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 668 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 669 | // The invalidated rect might be outside the bounds of the view. |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 670 | gfx::Rect view_rect(size_); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 671 | gfx::Rect damaged_rect = view_rect.Intersect(rect); |
| 672 | if (damaged_rect.IsEmpty()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 673 | return; |
| 674 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 675 | paint_aggregator_.InvalidateRect(damaged_rect); |
| 676 | |
| 677 | // We may not need to schedule another call to DoDeferredUpdate. |
| 678 | if (update_pending) |
| 679 | return; |
| 680 | if (!paint_aggregator_.HasPendingUpdate()) |
| 681 | return; |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 682 | if (update_reply_pending()) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 683 | return; |
| 684 | |
| 685 | // Perform updating asynchronously. This serves two purposes: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 686 | // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 687 | // on the call stack. |
| 688 | // 2) Allows us to collect more damage rects before painting to help coalesce |
| 689 | // the work that we will need to do. |
| 690 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 691 | this, &RenderWidget::CallDoDeferredUpdate)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 692 | } |
| 693 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 694 | void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 695 | // Drop scrolls on the floor when we are in compositing mode. |
| 696 | // TODO(nduca): stop WebViewImpl from sending scrolls in the first place. |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 697 | if (is_accelerated_compositing_active_) |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 698 | return; |
| 699 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 700 | // We only want one pending DoDeferredUpdate call at any time... |
| 701 | bool update_pending = paint_aggregator_.HasPendingUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 702 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 703 | // The scrolled rect might be outside the bounds of the view. |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 704 | gfx::Rect view_rect(size_); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 705 | gfx::Rect damaged_rect = view_rect.Intersect(clip_rect); |
| 706 | if (damaged_rect.IsEmpty()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 707 | return; |
| 708 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 709 | paint_aggregator_.ScrollRect(dx, dy, damaged_rect); |
| 710 | |
| 711 | // We may not need to schedule another call to DoDeferredUpdate. |
| 712 | if (update_pending) |
| 713 | return; |
| 714 | if (!paint_aggregator_.HasPendingUpdate()) |
| 715 | return; |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 716 | if (update_reply_pending()) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 717 | return; |
| 718 | |
| 719 | // Perform updating asynchronously. This serves two purposes: |
| 720 | // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 721 | // on the call stack. |
| 722 | // 2) Allows us to collect more damage rects before painting to help coalesce |
| 723 | // the work that we will need to do. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 724 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 725 | this, &RenderWidget::CallDoDeferredUpdate)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 726 | } |
| 727 | |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 728 | void RenderWidget::didActivateAcceleratedCompositing(bool active) { |
| 729 | is_accelerated_compositing_active_ = active; |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 730 | Send(new ViewHostMsg_DidActivateAcceleratedCompositing( |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 731 | routing_id_, is_accelerated_compositing_active_)); |
| 732 | } |
| 733 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 734 | void RenderWidget::scheduleComposite() { |
| 735 | // TODO(nduca): replace with something a little less hacky. The reason this |
| 736 | // hack is still used is because the Invalidate-DoDeferredUpdate loop |
| 737 | // contains a lot of host-renderer synchronization logic that is still |
| 738 | // important for the accelerated compositing case. The option of simply |
| 739 | // duplicating all that code is less desirable than "faking out" the |
| 740 | // invalidation path using a magical damage rect. |
[email protected] | e235624 | 2010-11-16 22:33:03 | [diff] [blame] | 741 | didInvalidateRect(WebRect(0, 0, 1, 1)); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 742 | } |
| 743 | |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 744 | void RenderWidget::scheduleAnimation() { |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 745 | if (!animation_update_pending_) { |
| 746 | animation_update_pending_ = true; |
| 747 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 748 | this, &RenderWidget::UpdateAnimationsIfNeeded)); |
| 749 | } |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 750 | } |
| 751 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 752 | void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 753 | // TODO(darin): Eliminate this temporary. |
| 754 | WebCursor cursor(cursor_info); |
| 755 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 756 | // Only send a SetCursor message if we need to make a change. |
| 757 | if (!current_cursor_.IsEqual(cursor)) { |
| 758 | current_cursor_ = cursor; |
| 759 | Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | // We are supposed to get a single call to Show for a newly created RenderWidget |
| 764 | // that was created via RenderWidget::CreateWebView. So, we wait until this |
| 765 | // point to dispatch the ShowWidget message. |
| 766 | // |
| 767 | // This method provides us with the information about how to display the newly |
| 768 | // created RenderWidget (i.e., as a constrained popup or as a new tab). |
| 769 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 770 | void RenderWidget::show(WebNavigationPolicy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 771 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 772 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 773 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 774 | |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 775 | if (did_show_) |
| 776 | return; |
| 777 | |
| 778 | did_show_ = true; |
| 779 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 780 | // that's okay. It'll be ignored if as_popup is false, or the browser |
| 781 | // process will impose a default position otherwise. |
| 782 | Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_)); |
| 783 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 784 | } |
| 785 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 786 | void RenderWidget::didFocus() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 787 | } |
| 788 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 789 | void RenderWidget::didBlur() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 790 | } |
| 791 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 792 | void RenderWidget::DoDeferredClose() { |
| 793 | Send(new ViewHostMsg_Close(routing_id_)); |
| 794 | } |
| 795 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 796 | void RenderWidget::closeWidgetSoon() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 797 | // If a page calls window.close() twice, we'll end up here twice, but that's |
| 798 | // OK. It is safe to send multiple Close messages. |
| 799 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 800 | // Ask the RenderWidgetHost to initiate close. We could be called from deep |
| 801 | // in Javascript. If we ask the RendwerWidgetHost to close now, the window |
| 802 | // could be closed before the JS finishes executing. So instead, post a |
| 803 | // message back to the message loop, which won't run until the JS is |
| 804 | // complete, and then the Close message can be sent. |
[email protected] | 75ae449 | 2009-07-10 00:05:15 | [diff] [blame] | 805 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 806 | this, &RenderWidget::DoDeferredClose)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | void RenderWidget::Close() { |
| 810 | if (webwidget_) { |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 811 | webwidget_->close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 812 | webwidget_ = NULL; |
| 813 | } |
| 814 | } |
| 815 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 816 | WebRect RenderWidget::windowRect() { |
| 817 | if (pending_window_rect_count_) |
| 818 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 819 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 820 | gfx::Rect rect; |
| 821 | Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect)); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 822 | return rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 823 | } |
| 824 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 825 | void RenderWidget::setWindowRect(const WebRect& pos) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 826 | if (did_show_) { |
| 827 | Send(new ViewHostMsg_RequestMove(routing_id_, pos)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 828 | SetPendingWindowRect(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 829 | } else { |
| 830 | initial_pos_ = pos; |
| 831 | } |
| 832 | } |
| 833 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 834 | void RenderWidget::SetPendingWindowRect(const WebRect& rect) { |
| 835 | pending_window_rect_ = rect; |
| 836 | pending_window_rect_count_++; |
| 837 | } |
| 838 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 839 | WebRect RenderWidget::rootWindowRect() { |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 840 | if (pending_window_rect_count_) { |
| 841 | // NOTE(mbelshe): If there is a pending_window_rect_, then getting |
| 842 | // the RootWindowRect is probably going to return wrong results since the |
| 843 | // browser may not have processed the Move yet. There isn't really anything |
| 844 | // good to do in this case, and it shouldn't happen - since this size is |
| 845 | // only really needed for windowToScreen, which is only used for Popups. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 846 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 847 | } |
| 848 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 849 | gfx::Rect rect; |
| 850 | Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect)); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 851 | return rect; |
[email protected] | d454745 | 2008-08-28 18:36:37 | [diff] [blame] | 852 | } |
| 853 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 854 | WebRect RenderWidget::windowResizerRect() { |
| 855 | return resizer_rect_; |
[email protected] | c04b636 | 2008-11-21 18:54:19 | [diff] [blame] | 856 | } |
| 857 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 858 | void RenderWidget::OnSetInputMethodActive(bool is_active) { |
[email protected] | c4bb35a | 2008-10-31 17:54:03 | [diff] [blame] | 859 | // To prevent this renderer process from sending unnecessary IPC messages to |
| 860 | // a browser process, we permit the renderer process to send IPC messages |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 861 | // only during the input method attached to the browser process is active. |
| 862 | input_method_is_active_ = is_active; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 863 | } |
| 864 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 865 | void RenderWidget::OnImeSetComposition( |
| 866 | const string16& text, |
| 867 | const std::vector<WebCompositionUnderline>& underlines, |
| 868 | int selection_start, int selection_end) { |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 869 | if (!webwidget_) |
| 870 | return; |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 871 | if (!webwidget_->setComposition( |
| 872 | text, WebVector<WebCompositionUnderline>(underlines), |
| 873 | selection_start, selection_end)) { |
| 874 | // If we failed to set the composition text, then we need to let the browser |
| 875 | // process to cancel the input method's ongoing composition session, to make |
| 876 | // sure we are in a consistent state. |
| 877 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
[email protected] | 7f00efa | 2010-04-15 05:01:26 | [diff] [blame] | 878 | } |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 879 | } |
| 880 | |
[email protected] | 6b34965 | 2011-01-05 18:36:24 | [diff] [blame] | 881 | void RenderWidget::OnImeConfirmComposition(const string16& text) { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 882 | if (webwidget_) |
[email protected] | 6b34965 | 2011-01-05 18:36:24 | [diff] [blame] | 883 | webwidget_->confirmComposition(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 884 | } |
| 885 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 886 | // This message causes the renderer to render an image of the |
| 887 | // desired_size, regardless of whether the tab is hidden or not. |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 888 | void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, |
[email protected] | c88c944 | 2010-07-19 18:55:09 | [diff] [blame] | 889 | int tag, |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 890 | const gfx::Size& page_size, |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 891 | const gfx::Size& desired_size) { |
[email protected] | 45c6aad3 | 2010-11-11 04:46:25 | [diff] [blame] | 892 | if (!webwidget_ || !TransportDIB::is_valid(dib_handle)) { |
| 893 | if (TransportDIB::is_valid(dib_handle)) { |
| 894 | // Close our unused handle. |
| 895 | #if defined(OS_WIN) |
| 896 | ::CloseHandle(dib_handle); |
| 897 | #elif defined(OS_MACOSX) |
| 898 | base::SharedMemory::CloseHandle(dib_handle); |
| 899 | #endif |
| 900 | } |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 901 | return; |
[email protected] | 45c6aad3 | 2010-11-11 04:46:25 | [diff] [blame] | 902 | } |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 903 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 904 | if (page_size.IsEmpty() || desired_size.IsEmpty()) { |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 905 | // If one of these is empty, then we just return the dib we were |
| 906 | // given, to avoid leaking it. |
[email protected] | c88c944 | 2010-07-19 18:55:09 | [diff] [blame] | 907 | Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size)); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 908 | return; |
| 909 | } |
| 910 | |
| 911 | // Map the given DIB ID into this process, and unmap it at the end |
| 912 | // of this function. |
[email protected] | 45c6aad3 | 2010-11-11 04:46:25 | [diff] [blame] | 913 | scoped_ptr<TransportDIB> paint_at_size_buffer( |
| 914 | TransportDIB::CreateWithHandle(dib_handle)); |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 915 | |
| 916 | gfx::Size canvas_size = page_size; |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 917 | float x_scale = static_cast<float>(desired_size.width()) / |
| 918 | static_cast<float>(canvas_size.width()); |
| 919 | float y_scale = static_cast<float>(desired_size.height()) / |
| 920 | static_cast<float>(canvas_size.height()); |
| 921 | |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 922 | gfx::Rect orig_bounds(canvas_size); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 923 | canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale)); |
| 924 | canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale)); |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 925 | gfx::Rect bounds(canvas_size); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 926 | |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 927 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 928 | paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(), |
| 929 | canvas_size.height())); |
| 930 | if (!canvas.get()) { |
| 931 | NOTREACHED(); |
| 932 | return; |
| 933 | } |
| 934 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 935 | // Reset bounds to what we actually received, but they should be the |
| 936 | // same. |
| 937 | DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); |
| 938 | DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); |
| 939 | bounds.set_width(canvas->getDevice()->width()); |
| 940 | bounds.set_height(canvas->getDevice()->height()); |
| 941 | |
| 942 | canvas->save(); |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 943 | // Add the scale factor to the canvas, so that we'll get the desired size. |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 944 | canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale)); |
| 945 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 946 | // Have to make sure we're laid out at the right size before |
| 947 | // rendering. |
| 948 | gfx::Size old_size = webwidget_->size(); |
| 949 | webwidget_->resize(page_size); |
| 950 | webwidget_->layout(); |
| 951 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 952 | // Paint the entire thing (using original bounds, not scaled bounds). |
| 953 | PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); |
| 954 | canvas->restore(); |
| 955 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 956 | // Return the widget to its previous size. |
| 957 | webwidget_->resize(old_size); |
| 958 | |
[email protected] | c88c944 | 2010-07-19 18:55:09 | [diff] [blame] | 959 | Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 960 | } |
| 961 | |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 962 | void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { |
| 963 | // During shutdown we can just ignore this message. |
| 964 | if (!webwidget_) |
| 965 | return; |
| 966 | |
| 967 | set_next_paint_is_repaint_ack(); |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 968 | if (is_accelerated_compositing_active_) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 969 | scheduleComposite(); |
| 970 | } else { |
| 971 | gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); |
| 972 | didInvalidateRect(repaint_rect); |
| 973 | } |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 974 | } |
| 975 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 976 | void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 977 | if (!webwidget_) |
| 978 | return; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 979 | webwidget_->setTextDirection(direction); |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 980 | } |
| 981 | |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 982 | webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint( |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 983 | const gfx::Rect& paint_bounds, |
| 984 | TransportDIB** dib, |
| 985 | gfx::Rect* location, |
| 986 | gfx::Rect* clip) { |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 987 | // Bare RenderWidgets don't support optimized plugin painting. |
| 988 | return NULL; |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 989 | } |
| 990 | |
[email protected] | bcaf227 | 2011-02-15 15:29:43 | [diff] [blame^] | 991 | gfx::Point RenderWidget::GetScrollOffset() { |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 992 | // Bare RenderWidgets don't support scroll offset. |
[email protected] | bcaf227 | 2011-02-15 15:29:43 | [diff] [blame^] | 993 | return gfx::Point(0, 0); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 994 | } |
| 995 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 996 | void RenderWidget::SetHidden(bool hidden) { |
| 997 | if (is_hidden_ == hidden) |
| 998 | return; |
| 999 | |
| 1000 | // The status has changed. Tell the RenderThread about it. |
| 1001 | is_hidden_ = hidden; |
| 1002 | if (is_hidden_) |
| 1003 | render_thread_->WidgetHidden(); |
| 1004 | else |
| 1005 | render_thread_->WidgetRestored(); |
| 1006 | } |
| 1007 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1008 | void RenderWidget::SetBackground(const SkBitmap& background) { |
| 1009 | background_ = background; |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1010 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1011 | // Generate a full repaint. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1012 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1013 | } |
| 1014 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1015 | bool RenderWidget::next_paint_is_resize_ack() const { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1016 | return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | bool RenderWidget::next_paint_is_restore_ack() const { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1020 | return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | void RenderWidget::set_next_paint_is_resize_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1024 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | void RenderWidget::set_next_paint_is_restore_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1028 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | void RenderWidget::set_next_paint_is_repaint_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1032 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1033 | } |
| 1034 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1035 | void RenderWidget::UpdateInputMethod() { |
| 1036 | if (!input_method_is_active_) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1037 | return; |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1038 | |
| 1039 | WebTextInputType new_type = WebKit::WebTextInputTypeNone; |
| 1040 | WebRect new_caret_bounds; |
| 1041 | |
| 1042 | if (webwidget_) { |
| 1043 | new_type = webwidget_->textInputType(); |
| 1044 | new_caret_bounds = webwidget_->caretOrSelectionBounds(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1045 | } |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1046 | |
| 1047 | // Only sends text input type and caret bounds to the browser process if they |
| 1048 | // are changed. |
| 1049 | if (text_input_type_ != new_type || caret_bounds_ != new_caret_bounds) { |
| 1050 | text_input_type_ = new_type; |
| 1051 | caret_bounds_ = new_caret_bounds; |
| 1052 | Send(new ViewHostMsg_ImeUpdateTextInputState( |
| 1053 | routing_id(), new_type, new_caret_bounds)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1054 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1055 | } |
| 1056 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1057 | WebScreenInfo RenderWidget::screenInfo() { |
| 1058 | WebScreenInfo results; |
| 1059 | Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results)); |
| 1060 | return results; |
| 1061 | } |
| 1062 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1063 | void RenderWidget::resetInputMethod() { |
| 1064 | if (!input_method_is_active_) |
| 1065 | return; |
| 1066 | |
| 1067 | // If the last text input type is not None, then we should finish any |
| 1068 | // ongoing composition regardless of the new text input type. |
| 1069 | if (text_input_type_ != WebKit::WebTextInputTypeNone) { |
| 1070 | // If a composition text exists, then we need to let the browser process |
| 1071 | // to cancel the input method's ongoing composition session. |
| 1072 | if (webwidget_->confirmComposition()) |
| 1073 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 1074 | } |
| 1075 | } |
| 1076 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1077 | void RenderWidget::SchedulePluginMove( |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 1078 | const webkit::npapi::WebPluginGeometry& move) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1079 | size_t i = 0; |
| 1080 | for (; i < plugin_window_moves_.size(); ++i) { |
| 1081 | if (plugin_window_moves_[i].window == move.window) { |
[email protected] | 16f89d0 | 2009-08-26 17:17:58 | [diff] [blame] | 1082 | if (move.rects_valid) { |
| 1083 | plugin_window_moves_[i] = move; |
| 1084 | } else { |
| 1085 | plugin_window_moves_[i].visible = move.visible; |
| 1086 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1087 | break; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | if (i == plugin_window_moves_.size()) |
| 1092 | plugin_window_moves_.push_back(move); |
| 1093 | } |
[email protected] | 26865477 | 2009-08-06 23:02:04 | [diff] [blame] | 1094 | |
| 1095 | void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
| 1096 | for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
| 1097 | i != plugin_window_moves_.end(); ++i) { |
| 1098 | if (i->window == window) { |
| 1099 | plugin_window_moves_.erase(i); |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | } |