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