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