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