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