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