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