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