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