[email protected] | 60a5007 | 2012-01-11 02:05:35 | [diff] [blame] | 1 | // Copyright (c) 2012 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] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 73 | surface_id_(0), |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 74 | webwidget_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 75 | opener_id_(MSG_ROUTING_NONE), |
[email protected] | 659f73f | 2009-10-13 13:43:42 | [diff] [blame] | 76 | host_window_(0), |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 77 | current_paint_buf_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 78 | next_paint_flags_(0), |
[email protected] | 0cff69e | 2011-11-22 22:26:06 | [diff] [blame] | 79 | filtered_time_per_frame_(0.0f), |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 80 | update_reply_pending_(false), |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 81 | using_asynchronous_swapbuffers_(false), |
| 82 | num_swapbuffers_complete_pending_(0), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 83 | did_show_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 84 | is_hidden_(false), |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 85 | is_fullscreen_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 86 | needs_repainting_on_restore_(false), |
| 87 | has_focus_(false), |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 88 | handling_input_event_(false), |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 89 | closing_(false), |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 90 | is_swapped_out_(false), |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 91 | input_method_is_active_(false), |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 92 | text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 93 | can_compose_inline_(true), |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 94 | popup_type_(popup_type), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 95 | pending_window_rect_count_(0), |
[email protected] | b68a0e5 | 2011-12-08 15:11:12 | [diff] [blame] | 96 | suppress_next_char_events_(false), |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 97 | is_accelerated_compositing_active_(false), |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 98 | animation_update_pending_(false), |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 99 | animation_task_posted_(false), |
| 100 | invalidation_task_posted_(false) { |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 101 | RenderProcess::current()->AddRefProcess(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 102 | DCHECK(RenderThread::Get()); |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 103 | has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 104 | switches::kDisableGpuVsync); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | RenderWidget::~RenderWidget() { |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 108 | DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 109 | STLDeleteElements(&updates_pending_swap_); |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 110 | if (current_paint_buf_) { |
| 111 | RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 112 | current_paint_buf_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 113 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 114 | // If we are swapped out, we have released already. |
| 115 | if (!is_swapped_out_) |
| 116 | RenderProcess::current()->ReleaseProcess(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 119 | // static |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 120 | RenderWidget* RenderWidget::Create(int32 opener_id, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 121 | WebKit::WebPopupType popup_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 122 | DCHECK(opener_id != MSG_ROUTING_NONE); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 123 | scoped_refptr<RenderWidget> widget(new RenderWidget(popup_type)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 124 | widget->Init(opener_id); // adds reference |
| 125 | return widget; |
| 126 | } |
| 127 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 128 | // static |
| 129 | WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) { |
| 130 | switch (render_widget->popup_type_) { |
[email protected] | e235624 | 2010-11-16 22:33:03 | [diff] [blame] | 131 | case WebKit::WebPopupTypeNone: // Nothing to create. |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 132 | break; |
| 133 | case WebKit::WebPopupTypeSelect: |
| 134 | case WebKit::WebPopupTypeSuggestion: |
| 135 | return WebPopupMenu::create(render_widget); |
| 136 | default: |
| 137 | NOTREACHED(); |
| 138 | } |
| 139 | return NULL; |
| 140 | } |
| 141 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 142 | void RenderWidget::Init(int32 opener_id) { |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 143 | DoInit(opener_id, |
| 144 | RenderWidget::CreateWebWidget(this), |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 145 | new ViewHostMsg_CreateWidget(opener_id, popup_type_, |
| 146 | &routing_id_, &surface_id_)); |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 147 | } |
| 148 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 149 | void RenderWidget::DoInit(int32 opener_id, |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 150 | WebWidget* web_widget, |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 151 | IPC::SyncMessage* create_widget_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 152 | DCHECK(!webwidget_); |
| 153 | |
| 154 | if (opener_id != MSG_ROUTING_NONE) |
| 155 | opener_id_ = opener_id; |
| 156 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 157 | webwidget_ = web_widget; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 159 | bool result = RenderThread::Get()->Send(create_widget_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 160 | if (result) { |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 161 | RenderThread::Get()->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 162 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 163 | // when we receive ViewMsg_Close. |
| 164 | AddRef(); |
| 165 | } else { |
| 166 | DCHECK(false); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // This is used to complete pending inits and non-pending inits. For non- |
| 171 | // pending cases, the parent will be the same as the current parent. This |
| 172 | // indicates we do not need to reparent or anything. |
[email protected] | 2d7c855 | 2011-06-27 19:21:55 | [diff] [blame] | 173 | void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 174 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 175 | |
| 176 | host_window_ = parent_hwnd; |
| 177 | |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 178 | Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 179 | } |
| 180 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 181 | void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
| 182 | // We should only toggle between states. |
| 183 | DCHECK(is_swapped_out_ != is_swapped_out); |
| 184 | is_swapped_out_ = is_swapped_out; |
| 185 | |
| 186 | // If we are swapping out, we will call ReleaseProcess, allowing the process |
| 187 | // to exit if all of its RenderViews are swapped out. We wait until the |
| 188 | // WasSwappedOut call to do this, to avoid showing the sad tab. |
| 189 | // If we are swapping in, we call AddRefProcess to prevent the process from |
| 190 | // exiting. |
| 191 | if (!is_swapped_out) |
| 192 | RenderProcess::current()->AddRefProcess(); |
| 193 | } |
| 194 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 195 | bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
| 196 | bool handled = true; |
| 197 | IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) |
| 198 | IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
| 199 | IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) |
| 200 | IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) |
| 201 | IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
| 202 | IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 203 | IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 204 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) |
| 205 | IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) |
| 206 | IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) |
| 207 | IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) |
| 208 | IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive) |
| 209 | IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) |
| 210 | IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition) |
| 211 | IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize) |
| 212 | IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) |
| 213 | IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
| 214 | IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
| 215 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 216 | IPC_END_MESSAGE_MAP() |
| 217 | return handled; |
| 218 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 219 | |
| 220 | bool RenderWidget::Send(IPC::Message* message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 221 | // Don't send any messages after the browser has told us to close, and filter |
| 222 | // most outgoing messages while swapped out. |
| 223 | if ((is_swapped_out_ && |
| 224 | !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) || |
| 225 | closing_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 226 | delete message; |
| 227 | return false; |
| 228 | } |
| 229 | |
| 230 | // If given a messsage without a routing ID, then assign our routing ID. |
| 231 | if (message->routing_id() == MSG_ROUTING_NONE) |
| 232 | message->set_routing_id(routing_id_); |
| 233 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 234 | return RenderThread::Get()->Send(message); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 235 | } |
| 236 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 237 | // Got a response from the browser after the renderer decided to create a new |
| 238 | // view. |
[email protected] | c03a6e7 | 2011-04-19 21:42:06 | [diff] [blame] | 239 | void RenderWidget::OnCreatingNewAck( |
[email protected] | 2d7c855 | 2011-06-27 19:21:55 | [diff] [blame] | 240 | gfx::NativeViewId parent) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 241 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 242 | |
[email protected] | 2d7c855 | 2011-06-27 19:21:55 | [diff] [blame] | 243 | CompleteInit(parent); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void RenderWidget::OnClose() { |
| 247 | if (closing_) |
| 248 | return; |
| 249 | closing_ = true; |
| 250 | |
| 251 | // Browser correspondence is no longer needed at this point. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 252 | if (routing_id_ != MSG_ROUTING_NONE) { |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 253 | RenderThread::Get()->RemoveRoute(routing_id_); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 254 | SetHidden(false); |
| 255 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 256 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 257 | // 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] | 258 | // now. Post a task that only gets invoked when there are no nested message |
| 259 | // loops. |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 260 | MessageLoop::current()->PostNonNestableTask( |
[email protected] | 3a5a782 | 2011-12-23 18:27:29 | [diff] [blame] | 261 | FROM_HERE, base::Bind(&RenderWidget::Close, this)); |
[email protected] | d3fc2565 | 2009-02-24 22:31:25 | [diff] [blame] | 262 | |
| 263 | // Balances the AddRef taken when we called AddRoute. |
| 264 | Release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 267 | void RenderWidget::OnResize(const gfx::Size& new_size, |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 268 | const gfx::Rect& resizer_rect, |
| 269 | bool is_fullscreen) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 270 | // During shutdown we can just ignore this message. |
| 271 | if (!webwidget_) |
| 272 | return; |
| 273 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 274 | // Remember the rect where the resize corner will be drawn. |
| 275 | resizer_rect_ = resizer_rect; |
| 276 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 277 | // NOTE: We may have entered fullscreen mode without changing our size. |
| 278 | bool fullscreen_change = is_fullscreen_ != is_fullscreen; |
| 279 | if (fullscreen_change) |
| 280 | WillToggleFullscreen(); |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 281 | is_fullscreen_ = is_fullscreen; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 282 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 283 | if (size_ != new_size) { |
| 284 | // TODO(darin): We should not need to reset this here. |
| 285 | SetHidden(false); |
| 286 | needs_repainting_on_restore_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 287 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 288 | size_ = new_size; |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 289 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 290 | // We should not be sent a Resize message if we have not ACK'd the previous |
| 291 | DCHECK(!next_paint_is_resize_ack()); |
| 292 | |
| 293 | paint_aggregator_.ClearPendingUpdate(); |
| 294 | |
| 295 | // When resizing, we want to wait to paint before ACK'ing the resize. This |
| 296 | // ensures that we only resize as fast as we can paint. We only need to |
| 297 | // send an ACK if we are resized to a non-empty rect. |
| 298 | webwidget_->resize(new_size); |
| 299 | if (!new_size.IsEmpty()) { |
| 300 | if (!is_accelerated_compositing_active_) { |
| 301 | // Resize should have caused an invalidation of the entire view. |
| 302 | DCHECK(paint_aggregator_.HasPendingUpdate()); |
| 303 | } |
| 304 | |
| 305 | // We will send the Resize_ACK flag once we paint again. |
| 306 | set_next_paint_is_resize_ack(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 307 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 308 | } |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 309 | |
| 310 | if (fullscreen_change) |
| 311 | DidToggleFullscreen(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void RenderWidget::OnWasHidden() { |
[email protected] | 9c3085f | 2011-06-09 02:10:31 | [diff] [blame] | 315 | TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 316 | // Go into a mode where we stop generating paint and scrolling events. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 317 | SetHidden(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void RenderWidget::OnWasRestored(bool needs_repainting) { |
[email protected] | 9c3085f | 2011-06-09 02:10:31 | [diff] [blame] | 321 | TRACE_EVENT0("renderer", "RenderWidget::OnWasRestored"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 322 | // During shutdown we can just ignore this message. |
| 323 | if (!webwidget_) |
| 324 | return; |
| 325 | |
| 326 | // See OnWasHidden |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 327 | SetHidden(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 328 | |
| 329 | if (!needs_repainting && !needs_repainting_on_restore_) |
| 330 | return; |
| 331 | needs_repainting_on_restore_ = false; |
| 332 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 333 | // Tag the next paint as a restore ack, which is picked up by |
| 334 | // DoDeferredUpdate when it sends out the next PaintRect message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 335 | set_next_paint_is_restore_ack(); |
| 336 | |
| 337 | // Generate a full repaint. |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 338 | if (!is_accelerated_compositing_active_) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 339 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
| 340 | } else { |
| 341 | scheduleComposite(); |
| 342 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 343 | } |
| 344 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 345 | void RenderWidget::OnWasSwappedOut() { |
| 346 | // If we have been swapped out and no one else is using this process, |
| 347 | // it's safe to exit now. If we get swapped back in, we will call |
| 348 | // AddRefProcess in SetSwappedOut. |
| 349 | if (is_swapped_out_) |
| 350 | RenderProcess::current()->ReleaseProcess(); |
| 351 | } |
| 352 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 353 | void RenderWidget::OnRequestMoveAck() { |
| 354 | DCHECK(pending_window_rect_count_); |
| 355 | pending_window_rect_count_--; |
| 356 | } |
| 357 | |
| 358 | void RenderWidget::OnUpdateRectAck() { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 359 | TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck"); |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 360 | DCHECK(update_reply_pending_); |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 361 | update_reply_pending_ = false; |
| 362 | |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 363 | // If we sent an UpdateRect message with a zero-sized bitmap, then we should |
| 364 | // have no current paint buffer. |
| 365 | if (current_paint_buf_) { |
| 366 | RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 367 | current_paint_buf_ = NULL; |
| 368 | } |
| 369 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 370 | // If swapbuffers is still pending, then defer the update until the |
| 371 | // swapbuffers occurs. |
| 372 | if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) { |
| 373 | TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending"); |
| 374 | return; |
| 375 | } |
| 376 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame^] | 377 | // Notify subclasses that software rendering was flushed to the screen. |
| 378 | DidFlushPaint(); |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 379 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 380 | // Continue painting if necessary... |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 381 | DoDeferredUpdateAndSendInputAck(); |
| 382 | } |
| 383 | |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 384 | bool RenderWidget::SupportsAsynchronousSwapBuffers() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 385 | return false; |
| 386 | } |
| 387 | |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 388 | void RenderWidget::OnSwapBuffersAborted() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 389 | TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 390 | while (!updates_pending_swap_.empty()) { |
| 391 | ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front(); |
| 392 | updates_pending_swap_.pop_front(); |
| 393 | // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate |
| 394 | // compositing pass, hence doesn't require an UpdateRect message. |
| 395 | if (msg) |
| 396 | Send(msg); |
| 397 | } |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 398 | num_swapbuffers_complete_pending_ = 0; |
| 399 | using_asynchronous_swapbuffers_ = false; |
| 400 | // Schedule another frame so the compositor learns about it. |
| 401 | scheduleComposite(); |
| 402 | } |
| 403 | |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 404 | void RenderWidget::OnSwapBuffersPosted() { |
| 405 | TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 406 | |
| 407 | if (using_asynchronous_swapbuffers_) { |
| 408 | ViewHostMsg_UpdateRect* msg = NULL; |
| 409 | // pending_update_params_ can be NULL if the swap doesn't correspond to an |
| 410 | // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect |
| 411 | // message. |
| 412 | if (pending_update_params_.get()) { |
| 413 | msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_); |
| 414 | pending_update_params_.reset(); |
| 415 | } |
| 416 | updates_pending_swap_.push_back(msg); |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 417 | num_swapbuffers_complete_pending_++; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 418 | } |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void RenderWidget::OnSwapBuffersComplete() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 422 | TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete"); |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame^] | 423 | |
| 424 | // Notify subclasses that composited rendering got flushed to the screen. |
| 425 | DidFlushPaint(); |
| 426 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 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. |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 444 | if (update_reply_pending_) { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 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 || |
[email protected] | d329a91 | 2012-01-27 01:55:01 | [diff] [blame] | 510 | WebInputEvent::isTouchEventType(input_event->type)) && |
[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. |
[email protected] | 02798a98 | 2012-01-27 00:45:33 | [diff] [blame] | 682 | base::TimeDelta animationInterval = IsRenderingVSynced() ? |
| 683 | base::TimeDelta::FromMilliseconds(16) : base::TimeDelta(); |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 684 | |
[email protected] | 7c4329e | 2011-02-18 22:02:59 | [diff] [blame] | 685 | base::Time now = base::Time::Now(); |
[email protected] | 46d8c829 | 2011-12-12 18:15:05 | [diff] [blame] | 686 | if (now >= animation_floor_time_ || is_accelerated_compositing_active_) { |
[email protected] | 921244e4 | 2011-07-20 16:36:30 | [diff] [blame] | 687 | TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") |
[email protected] | 02798a98 | 2012-01-27 00:45:33 | [diff] [blame] | 688 | animation_floor_time_ = now + animationInterval; |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 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. |
[email protected] | 02798a98 | 2012-01-27 00:45:33 | [diff] [blame] | 711 | base::TimeDelta delay = animation_floor_time_ - now; |
[email protected] | 7c4329e | 2011-02-18 22:02:59 | [diff] [blame] | 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_; |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 779 | if (is_accelerated_compositing_active_) { |
[email protected] | 0fb93f5 | 2011-05-18 23:13:56 | [diff] [blame] | 780 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay", |
| 781 | delay, |
| 782 | base::TimeDelta::FromMilliseconds(1), |
| 783 | base::TimeDelta::FromMilliseconds(60), |
| 784 | 30); |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 785 | } else { |
[email protected] | 0fb93f5 | 2011-05-18 23:13:56 | [diff] [blame] | 786 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay", |
| 787 | delay, |
| 788 | base::TimeDelta::FromMilliseconds(1), |
| 789 | base::TimeDelta::FromMilliseconds(60), |
| 790 | 30); |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 791 | } |
[email protected] | 872ae5b | 2011-05-26 20:20:50 | [diff] [blame] | 792 | |
| 793 | // Calculate filtered time per frame: |
| 794 | float frame_time_elapsed = static_cast<float>(delay.InSecondsF()); |
| 795 | filtered_time_per_frame_ = |
| 796 | 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed; |
[email protected] | 0fb93f5 | 2011-05-18 23:13:56 | [diff] [blame] | 797 | } |
| 798 | last_do_deferred_update_time_ = frame_begin_ticks; |
| 799 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 800 | // OK, save the pending update to a local since painting may cause more |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 801 | // invalidation. Some WebCore rendering objects only layout when painted. |
[email protected] | dd01581 | 2010-12-06 23:39:30 | [diff] [blame] | 802 | PaintAggregator::PendingUpdate update; |
| 803 | paint_aggregator_.PopPendingUpdate(&update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 804 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 805 | gfx::Rect scroll_damage = update.GetScrollDamage(); |
| 806 | gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 807 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame^] | 808 | // Notify derived classes that we're about to initiate a paint. |
| 809 | WillInitiatePaint(); |
| 810 | |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 811 | // A plugin may be able to do an optimized paint. First check this, in which |
| 812 | // case we can skip all of the bitmap generation and regular paint code. |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 813 | // This optimization allows PPAPI plugins that declare themselves on top of |
| 814 | // the page (like a traditional windowed plugin) to be able to animate (think |
| 815 | // movie playing) without repeatedly re-painting the page underneath, or |
| 816 | // copying the plugin backing store (since we can send the plugin's backing |
| 817 | // store directly to the browser). |
| 818 | // |
| 819 | // This optimization only works when the entire invalid region is contained |
| 820 | // within the plugin. There is a related optimization in PaintRect for the |
| 821 | // case where there may be multiple invalid regions. |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 822 | TransportDIB* dib = NULL; |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 823 | gfx::Rect optimized_copy_rect, optimized_copy_location; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 824 | DCHECK(!pending_update_params_.get()); |
| 825 | pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params); |
| 826 | pending_update_params_->dx = update.scroll_delta.x(); |
| 827 | pending_update_params_->dy = update.scroll_delta.y(); |
| 828 | pending_update_params_->scroll_rect = update.scroll_rect; |
| 829 | pending_update_params_->view_size = size_; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 830 | pending_update_params_->plugin_window_moves.swap(plugin_window_moves_); |
| 831 | pending_update_params_->flags = next_paint_flags_; |
| 832 | pending_update_params_->scroll_offset = GetScrollOffset(); |
| 833 | pending_update_params_->needs_ack = true; |
| 834 | next_paint_flags_ = 0; |
| 835 | |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 836 | if (update.scroll_rect.IsEmpty() && |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 837 | !is_accelerated_compositing_active_ && |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 838 | GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location, |
| 839 | &optimized_copy_rect)) { |
[email protected] | 2df1b36 | 2011-01-21 21:22:27 | [diff] [blame] | 840 | // Only update the part of the plugin that actually changed. |
| 841 | optimized_copy_rect = optimized_copy_rect.Intersect(bounds); |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 842 | pending_update_params_->bitmap = dib->id(); |
| 843 | pending_update_params_->bitmap_rect = optimized_copy_location; |
| 844 | pending_update_params_->copy_rects.push_back(optimized_copy_rect); |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 845 | } else if (!is_accelerated_compositing_active_) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 846 | // Compute a buffer for painting and cache it. |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 847 | scoped_ptr<skia::PlatformCanvas> canvas( |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 848 | RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, |
| 849 | bounds)); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 850 | if (!canvas.get()) { |
| 851 | NOTREACHED(); |
| 852 | return; |
| 853 | } |
[email protected] | cef3362f | 2009-12-21 17:48:45 | [diff] [blame] | 854 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 855 | // We may get back a smaller canvas than we asked for. |
| 856 | // TODO(darin): This seems like it could cause painting problems! |
| 857 | DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); |
| 858 | DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); |
| 859 | bounds.set_width(canvas->getDevice()->width()); |
| 860 | bounds.set_height(canvas->getDevice()->height()); |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 861 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 862 | HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size()); |
| 863 | |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 864 | pending_update_params_->bitmap = current_paint_buf_->id(); |
| 865 | pending_update_params_->bitmap_rect = bounds; |
| 866 | |
| 867 | std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects; |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 868 | // The scroll damage is just another rectangle to paint and copy. |
| 869 | copy_rects.swap(update.paint_rects); |
| 870 | if (!scroll_damage.IsEmpty()) |
| 871 | copy_rects.push_back(scroll_damage); |
| 872 | |
| 873 | for (size_t i = 0; i < copy_rects.size(); ++i) |
| 874 | PaintRect(copy_rects[i], bounds.origin(), canvas.get()); |
[email protected] | 60a5007 | 2012-01-11 02:05:35 | [diff] [blame] | 875 | |
| 876 | // Software FPS tick for performance tests. The accelerated path traces the |
| 877 | // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc. |
| 878 | // NOTE: Tests may break if this event is renamed or moved. |
| 879 | UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW"); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 880 | } else { // Accelerated compositing path |
| 881 | // Begin painting. |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 882 | // If painting is done via the gpu process then we don't set any damage |
| 883 | // rects to save the browser process from doing unecessary work. |
| 884 | pending_update_params_->bitmap_rect = bounds; |
| 885 | pending_update_params_->scroll_rect = gfx::Rect(); |
| 886 | // We don't need an ack, because we're not sharing a DIB with the browser. |
| 887 | // If it needs to (e.g. composited UI), the GPU process does its own ACK |
| 888 | // with the browser for the GPU surface. |
| 889 | pending_update_params_->needs_ack = false; |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 890 | webwidget_->composite(false); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 891 | } |
| 892 | |
[email protected] | 936c6f5 | 2011-12-13 01:35:26 | [diff] [blame] | 893 | // If we're holding a pending input event ACK, send the ACK before sending the |
| 894 | // UpdateReply message so we can receive another input event before the |
| 895 | // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within |
| 896 | // the UpdateRect IPC message handler. |
| 897 | if (pending_input_event_ack_.get()) |
| 898 | Send(pending_input_event_ack_.release()); |
| 899 | |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 900 | // If composite() called SwapBuffers, pending_update_params_ will be reset (in |
| 901 | // OnSwapBuffersPosted), meaning a message has been added to the |
| 902 | // updates_pending_swap_ queue, that will be sent later. Otherwise, we send |
| 903 | // the message now. |
| 904 | if (pending_update_params_.get()) { |
| 905 | // sending an ack to browser process that the paint is complete... |
| 906 | update_reply_pending_ = pending_update_params_->needs_ack; |
| 907 | Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_)); |
| 908 | pending_update_params_.reset(); |
[email protected] | b167ca66 | 2010-05-14 00:05:34 | [diff] [blame] | 909 | } |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 910 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 911 | UpdateTextInputState(); |
| 912 | UpdateSelectionBounds(); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 913 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame^] | 914 | // If we're software rendering then we're done initiating the paint. |
| 915 | if (!is_accelerated_compositing_active_) |
| 916 | DidInitiatePaint(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 920 | // WebWidgetClient |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 921 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 922 | void RenderWidget::didInvalidateRect(const WebRect& rect) { |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 923 | // The invalidated rect might be outside the bounds of the view. |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 924 | gfx::Rect view_rect(size_); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 925 | gfx::Rect damaged_rect = view_rect.Intersect(rect); |
| 926 | if (damaged_rect.IsEmpty()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 927 | return; |
| 928 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 929 | paint_aggregator_.InvalidateRect(damaged_rect); |
| 930 | |
| 931 | // We may not need to schedule another call to DoDeferredUpdate. |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 932 | if (invalidation_task_posted_) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 933 | return; |
| 934 | if (!paint_aggregator_.HasPendingUpdate()) |
| 935 | return; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 936 | if (update_reply_pending_ || |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 937 | num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) |
| 938 | return; |
| 939 | |
| 940 | // When GPU rendering, combine pending animations and invalidations into |
| 941 | // a single update. |
| 942 | if (is_accelerated_compositing_active_ && animation_task_posted_) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 943 | return; |
| 944 | |
| 945 | // Perform updating asynchronously. This serves two purposes: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 946 | // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 947 | // on the call stack. |
| 948 | // 2) Allows us to collect more damage rects before painting to help coalesce |
| 949 | // the work that we will need to do. |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 950 | invalidation_task_posted_ = true; |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 951 | MessageLoop::current()->PostTask( |
| 952 | FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 953 | } |
| 954 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 955 | void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 956 | // Drop scrolls on the floor when we are in compositing mode. |
| 957 | // TODO(nduca): stop WebViewImpl from sending scrolls in the first place. |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 958 | if (is_accelerated_compositing_active_) |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 959 | return; |
| 960 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 961 | // The scrolled rect might be outside the bounds of the view. |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 962 | gfx::Rect view_rect(size_); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 963 | gfx::Rect damaged_rect = view_rect.Intersect(clip_rect); |
| 964 | if (damaged_rect.IsEmpty()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 965 | return; |
| 966 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 967 | paint_aggregator_.ScrollRect(dx, dy, damaged_rect); |
| 968 | |
| 969 | // We may not need to schedule another call to DoDeferredUpdate. |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 970 | if (invalidation_task_posted_) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 971 | return; |
| 972 | if (!paint_aggregator_.HasPendingUpdate()) |
| 973 | return; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 974 | if (update_reply_pending_ || |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 975 | num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) |
| 976 | return; |
| 977 | |
| 978 | // When GPU rendering, combine pending animations and invalidations into |
| 979 | // a single update. |
| 980 | if (is_accelerated_compositing_active_ && animation_task_posted_) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 981 | return; |
| 982 | |
| 983 | // Perform updating asynchronously. This serves two purposes: |
| 984 | // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 985 | // on the call stack. |
| 986 | // 2) Allows us to collect more damage rects before painting to help coalesce |
| 987 | // the work that we will need to do. |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 988 | invalidation_task_posted_ = true; |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 989 | MessageLoop::current()->PostTask( |
| 990 | FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 991 | } |
| 992 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 993 | void RenderWidget::didAutoResize(const WebSize& new_size) { |
| 994 | size_ = new_size; |
| 995 | } |
| 996 | |
[email protected] | 3da12cb | 2011-10-08 02:25:04 | [diff] [blame] | 997 | void RenderWidget::didActivateCompositor(int compositor_identifier) { |
[email protected] | ea162f9 | 2011-10-04 23:08:22 | [diff] [blame] | 998 | TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor"); |
| 999 | |
[email protected] | f315017 | 2011-10-22 02:28:45 | [diff] [blame] | 1000 | CompositorThread* compositor_thread = |
| 1001 | RenderThreadImpl::current()->compositor_thread(); |
| 1002 | if (compositor_thread) |
| 1003 | compositor_thread->AddCompositor(routing_id_, compositor_identifier); |
[email protected] | 3da12cb | 2011-10-08 02:25:04 | [diff] [blame] | 1004 | |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1005 | if (!is_accelerated_compositing_active_) { |
| 1006 | // When not in accelerated compositing mode, in certain cases (e.g. waiting |
| 1007 | // for a resize or if no backing store) the RenderWidgetHost is blocking the |
| 1008 | // browser's UI thread for some time, waiting for an UpdateRect. If we are |
| 1009 | // going to switch to accelerated compositing, the GPU process may need |
| 1010 | // round-trips to the browser's UI thread before finishing the frame, |
| 1011 | // causing deadlocks if we delay the UpdateRect until we receive the |
| 1012 | // OnSwapBuffersComplete. So send a dummy message that will unblock the |
| 1013 | // browser's UI thread. |
| 1014 | Send(new ViewHostMsg_UpdateIsDelayed(routing_id_)); |
| 1015 | } |
| 1016 | |
[email protected] | ea162f9 | 2011-10-04 23:08:22 | [diff] [blame] | 1017 | is_accelerated_compositing_active_ = true; |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 1018 | Send(new ViewHostMsg_DidActivateAcceleratedCompositing( |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1019 | routing_id_, is_accelerated_compositing_active_)); |
[email protected] | 6d2435e | 2012-02-01 23:29:37 | [diff] [blame] | 1020 | |
| 1021 | // Note: asynchronous swapbuffer support currently only matters if |
| 1022 | // compositing scheduling happens on the RenderWidget. |
| 1023 | using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers(); |
[email protected] | ea162f9 | 2011-10-04 23:08:22 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | void RenderWidget::didDeactivateCompositor() { |
| 1027 | TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor"); |
| 1028 | |
| 1029 | is_accelerated_compositing_active_ = false; |
| 1030 | Send(new ViewHostMsg_DidActivateAcceleratedCompositing( |
| 1031 | routing_id_, is_accelerated_compositing_active_)); |
| 1032 | |
[email protected] | ea162f9 | 2011-10-04 23:08:22 | [diff] [blame] | 1033 | if (using_asynchronous_swapbuffers_) |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1034 | using_asynchronous_swapbuffers_ = false; |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 1035 | } |
| 1036 | |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1037 | void RenderWidget::didCommitAndDrawCompositorFrame() { |
[email protected] | b5db7eb | 2011-11-29 09:11:50 | [diff] [blame] | 1038 | TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); |
[email protected] | 60a5007 | 2012-01-11 02:05:35 | [diff] [blame] | 1039 | // Accelerated FPS tick for performance tests. See throughput_tests.cc. |
| 1040 | // NOTE: Tests may break if this event is renamed or moved. |
| 1041 | UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU"); |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame^] | 1042 | // Notify subclasses that we initiated the paint operation. |
| 1043 | DidInitiatePaint(); |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | void RenderWidget::didCompleteSwapBuffers() { |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1047 | if (update_reply_pending_) |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1048 | return; |
| 1049 | |
| 1050 | if (!next_paint_flags_ && !plugin_window_moves_.size()) |
| 1051 | return; |
| 1052 | |
| 1053 | ViewHostMsg_UpdateRect_Params params; |
| 1054 | params.view_size = size_; |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1055 | params.plugin_window_moves.swap(plugin_window_moves_); |
| 1056 | params.flags = next_paint_flags_; |
| 1057 | params.scroll_offset = GetScrollOffset(); |
[email protected] | b0dda9e2 | 2011-12-13 20:30:12 | [diff] [blame] | 1058 | params.needs_ack = false; |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1059 | |
| 1060 | Send(new ViewHostMsg_UpdateRect(routing_id_, params)); |
| 1061 | next_paint_flags_ = 0; |
| 1062 | } |
| 1063 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1064 | void RenderWidget::scheduleComposite() { |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 1065 | if (WebWidgetHandlesCompositorScheduling()) { |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 1066 | webwidget_->composite(false); |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 1067 | } else { |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 1068 | // TODO(nduca): replace with something a little less hacky. The reason this |
| 1069 | // hack is still used is because the Invalidate-DoDeferredUpdate loop |
| 1070 | // contains a lot of host-renderer synchronization logic that is still |
| 1071 | // important for the accelerated compositing case. The option of simply |
| 1072 | // duplicating all that code is less desirable than "faking out" the |
| 1073 | // invalidation path using a magical damage rect. |
| 1074 | didInvalidateRect(WebRect(0, 0, 1, 1)); |
| 1075 | } |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1076 | } |
| 1077 | |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 1078 | void RenderWidget::scheduleAnimation() { |
[email protected] | 921244e4 | 2011-07-20 16:36:30 | [diff] [blame] | 1079 | TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation"); |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 1080 | if (!animation_update_pending_) { |
| 1081 | animation_update_pending_ = true; |
[email protected] | 52ccd0ea | 2011-02-16 01:09:05 | [diff] [blame] | 1082 | if (!animation_task_posted_) { |
| 1083 | animation_task_posted_ = true; |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 1084 | MessageLoop::current()->PostTask( |
| 1085 | FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this)); |
[email protected] | 52ccd0ea | 2011-02-16 01:09:05 | [diff] [blame] | 1086 | } |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 1087 | } |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 1088 | } |
| 1089 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1090 | void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 1091 | // TODO(darin): Eliminate this temporary. |
| 1092 | WebCursor cursor(cursor_info); |
| 1093 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1094 | // Only send a SetCursor message if we need to make a change. |
| 1095 | if (!current_cursor_.IsEqual(cursor)) { |
| 1096 | current_cursor_ = cursor; |
| 1097 | Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | // We are supposed to get a single call to Show for a newly created RenderWidget |
| 1102 | // that was created via RenderWidget::CreateWebView. So, we wait until this |
| 1103 | // point to dispatch the ShowWidget message. |
| 1104 | // |
| 1105 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 1106 | // created RenderWidget (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1107 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1108 | void RenderWidget::show(WebNavigationPolicy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1109 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 1110 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 1111 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 1112 | |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 1113 | if (did_show_) |
| 1114 | return; |
| 1115 | |
| 1116 | did_show_ = true; |
| 1117 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 1118 | // that's okay. It'll be ignored if as_popup is false, or the browser |
| 1119 | // process will impose a default position otherwise. |
| 1120 | Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_)); |
| 1121 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1122 | } |
| 1123 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1124 | void RenderWidget::didFocus() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1125 | } |
| 1126 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1127 | void RenderWidget::didBlur() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1128 | } |
| 1129 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1130 | void RenderWidget::DoDeferredClose() { |
| 1131 | Send(new ViewHostMsg_Close(routing_id_)); |
| 1132 | } |
| 1133 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1134 | void RenderWidget::closeWidgetSoon() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1135 | // If a page calls window.close() twice, we'll end up here twice, but that's |
| 1136 | // OK. It is safe to send multiple Close messages. |
| 1137 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1138 | // Ask the RenderWidgetHost to initiate close. We could be called from deep |
| 1139 | // in Javascript. If we ask the RendwerWidgetHost to close now, the window |
| 1140 | // could be closed before the JS finishes executing. So instead, post a |
| 1141 | // message back to the message loop, which won't run until the JS is |
| 1142 | // complete, and then the Close message can be sent. |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 1143 | MessageLoop::current()->PostTask( |
| 1144 | FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | void RenderWidget::Close() { |
| 1148 | if (webwidget_) { |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1149 | webwidget_->close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1150 | webwidget_ = NULL; |
| 1151 | } |
| 1152 | } |
| 1153 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1154 | WebRect RenderWidget::windowRect() { |
| 1155 | if (pending_window_rect_count_) |
| 1156 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1157 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 1158 | gfx::Rect rect; |
| 1159 | Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect)); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1160 | return rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1161 | } |
| 1162 | |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1163 | void RenderWidget::setToolTipText(const WebKit::WebString& text, |
| 1164 | WebTextDirection hint) { |
[email protected] | 5a395b7 | 2011-08-08 19:13:54 | [diff] [blame] | 1165 | Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1166 | } |
| 1167 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1168 | void RenderWidget::setWindowRect(const WebRect& pos) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1169 | if (did_show_) { |
| 1170 | Send(new ViewHostMsg_RequestMove(routing_id_, pos)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1171 | SetPendingWindowRect(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1172 | } else { |
| 1173 | initial_pos_ = pos; |
| 1174 | } |
| 1175 | } |
| 1176 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1177 | void RenderWidget::SetPendingWindowRect(const WebRect& rect) { |
| 1178 | pending_window_rect_ = rect; |
| 1179 | pending_window_rect_count_++; |
| 1180 | } |
| 1181 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1182 | WebRect RenderWidget::rootWindowRect() { |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1183 | if (pending_window_rect_count_) { |
| 1184 | // NOTE(mbelshe): If there is a pending_window_rect_, then getting |
| 1185 | // the RootWindowRect is probably going to return wrong results since the |
| 1186 | // browser may not have processed the Move yet. There isn't really anything |
| 1187 | // good to do in this case, and it shouldn't happen - since this size is |
| 1188 | // only really needed for windowToScreen, which is only used for Popups. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1189 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1190 | } |
| 1191 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 1192 | gfx::Rect rect; |
| 1193 | Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect)); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1194 | return rect; |
[email protected] | d454745 | 2008-08-28 18:36:37 | [diff] [blame] | 1195 | } |
| 1196 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1197 | WebRect RenderWidget::windowResizerRect() { |
| 1198 | return resizer_rect_; |
[email protected] | c04b636 | 2008-11-21 18:54:19 | [diff] [blame] | 1199 | } |
| 1200 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1201 | void RenderWidget::OnSetInputMethodActive(bool is_active) { |
[email protected] | c4bb35a | 2008-10-31 17:54:03 | [diff] [blame] | 1202 | // To prevent this renderer process from sending unnecessary IPC messages to |
| 1203 | // a browser process, we permit the renderer process to send IPC messages |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1204 | // only during the input method attached to the browser process is active. |
| 1205 | input_method_is_active_ = is_active; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1206 | } |
| 1207 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1208 | void RenderWidget::OnImeSetComposition( |
| 1209 | const string16& text, |
| 1210 | const std::vector<WebCompositionUnderline>& underlines, |
| 1211 | int selection_start, int selection_end) { |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1212 | if (!webwidget_) |
| 1213 | return; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1214 | if (webwidget_->setComposition( |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1215 | text, WebVector<WebCompositionUnderline>(underlines), |
| 1216 | selection_start, selection_end)) { |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1217 | // Setting the IME composition was successful. Send the new composition |
| 1218 | // range to the browser. |
| 1219 | ui::Range range(ui::Range::InvalidRange()); |
| 1220 | size_t location, length; |
| 1221 | if (webwidget_->compositionRange(&location, &length)) { |
| 1222 | range.set_start(location); |
| 1223 | range.set_end(location + length); |
| 1224 | } |
| 1225 | // The IME was cancelled via the Esc key, so just send back the caret. |
| 1226 | else if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1227 | range.set_start(location); |
| 1228 | range.set_end(location + length); |
| 1229 | } |
| 1230 | Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); |
| 1231 | } else { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1232 | // If we failed to set the composition text, then we need to let the browser |
| 1233 | // process to cancel the input method's ongoing composition session, to make |
| 1234 | // sure we are in a consistent state. |
| 1235 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1236 | |
| 1237 | // Send an updated IME range with just the caret range. |
| 1238 | ui::Range range(ui::Range::InvalidRange()); |
| 1239 | size_t location, length; |
| 1240 | if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1241 | range.set_start(location); |
| 1242 | range.set_end(location + length); |
| 1243 | } |
| 1244 | Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); |
[email protected] | 7f00efa | 2010-04-15 05:01:26 | [diff] [blame] | 1245 | } |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1246 | } |
| 1247 | |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 1248 | void RenderWidget::OnImeConfirmComposition( |
| 1249 | const string16& text, const ui::Range& replacement_range) { |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 1250 | if (!webwidget_) |
| 1251 | return; |
| 1252 | |
| 1253 | handling_input_event_ = true; |
| 1254 | webwidget_->confirmComposition(text); |
| 1255 | handling_input_event_ = false; |
| 1256 | |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1257 | // Send an updated IME range with just the caret range. |
| 1258 | ui::Range range(ui::Range::InvalidRange()); |
| 1259 | size_t location, length; |
| 1260 | if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1261 | range.set_start(location); |
| 1262 | range.set_end(location + length); |
| 1263 | } |
| 1264 | Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1265 | } |
| 1266 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1267 | // This message causes the renderer to render an image of the |
| 1268 | // desired_size, regardless of whether the tab is hidden or not. |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1269 | void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, |
[email protected] | c88c944 | 2010-07-19 18:55:09 | [diff] [blame] | 1270 | int tag, |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1271 | const gfx::Size& page_size, |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1272 | const gfx::Size& desired_size) { |
[email protected] | 2754345 | 2011-03-25 00:14:00 | [diff] [blame] | 1273 | if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) { |
| 1274 | if (TransportDIB::is_valid_handle(dib_handle)) { |
[email protected] | 45c6aad3 | 2010-11-11 04:46:25 | [diff] [blame] | 1275 | // Close our unused handle. |
| 1276 | #if defined(OS_WIN) |
| 1277 | ::CloseHandle(dib_handle); |
| 1278 | #elif defined(OS_MACOSX) |
| 1279 | base::SharedMemory::CloseHandle(dib_handle); |
| 1280 | #endif |
| 1281 | } |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1282 | return; |
[email protected] | 45c6aad3 | 2010-11-11 04:46:25 | [diff] [blame] | 1283 | } |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1284 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1285 | if (page_size.IsEmpty() || desired_size.IsEmpty()) { |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1286 | // If one of these is empty, then we just return the dib we were |
| 1287 | // given, to avoid leaking it. |
[email protected] | c88c944 | 2010-07-19 18:55:09 | [diff] [blame] | 1288 | Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size)); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1289 | return; |
| 1290 | } |
| 1291 | |
| 1292 | // Map the given DIB ID into this process, and unmap it at the end |
| 1293 | // of this function. |
[email protected] | 45c6aad3 | 2010-11-11 04:46:25 | [diff] [blame] | 1294 | scoped_ptr<TransportDIB> paint_at_size_buffer( |
| 1295 | TransportDIB::CreateWithHandle(dib_handle)); |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 1296 | |
| 1297 | gfx::Size canvas_size = page_size; |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1298 | float x_scale = static_cast<float>(desired_size.width()) / |
| 1299 | static_cast<float>(canvas_size.width()); |
| 1300 | float y_scale = static_cast<float>(desired_size.height()) / |
| 1301 | static_cast<float>(canvas_size.height()); |
| 1302 | |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 1303 | gfx::Rect orig_bounds(canvas_size); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1304 | canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale)); |
| 1305 | canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale)); |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 1306 | gfx::Rect bounds(canvas_size); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1307 | |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 1308 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 1309 | paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(), |
| 1310 | canvas_size.height())); |
| 1311 | if (!canvas.get()) { |
| 1312 | NOTREACHED(); |
| 1313 | return; |
| 1314 | } |
| 1315 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1316 | // Reset bounds to what we actually received, but they should be the |
| 1317 | // same. |
| 1318 | DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); |
| 1319 | DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); |
| 1320 | bounds.set_width(canvas->getDevice()->width()); |
| 1321 | bounds.set_height(canvas->getDevice()->height()); |
| 1322 | |
| 1323 | canvas->save(); |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1324 | // 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] | 1325 | canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale)); |
| 1326 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1327 | // Have to make sure we're laid out at the right size before |
| 1328 | // rendering. |
| 1329 | gfx::Size old_size = webwidget_->size(); |
| 1330 | webwidget_->resize(page_size); |
| 1331 | webwidget_->layout(); |
| 1332 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1333 | // Paint the entire thing (using original bounds, not scaled bounds). |
| 1334 | PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); |
| 1335 | canvas->restore(); |
| 1336 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1337 | // Return the widget to its previous size. |
| 1338 | webwidget_->resize(old_size); |
| 1339 | |
[email protected] | c88c944 | 2010-07-19 18:55:09 | [diff] [blame] | 1340 | Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1341 | } |
| 1342 | |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1343 | void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { |
| 1344 | // During shutdown we can just ignore this message. |
| 1345 | if (!webwidget_) |
| 1346 | return; |
| 1347 | |
| 1348 | set_next_paint_is_repaint_ack(); |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 1349 | if (is_accelerated_compositing_active_) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1350 | scheduleComposite(); |
| 1351 | } else { |
| 1352 | gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); |
| 1353 | didInvalidateRect(repaint_rect); |
| 1354 | } |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1355 | } |
| 1356 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1357 | void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 1358 | if (!webwidget_) |
| 1359 | return; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1360 | webwidget_->setTextDirection(direction); |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 1361 | } |
| 1362 | |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 1363 | webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint( |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 1364 | const gfx::Rect& paint_bounds, |
| 1365 | TransportDIB** dib, |
| 1366 | gfx::Rect* location, |
| 1367 | gfx::Rect* clip) { |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 1368 | // Bare RenderWidgets don't support optimized plugin painting. |
| 1369 | return NULL; |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 1370 | } |
| 1371 | |
[email protected] | bcaf227 | 2011-02-15 15:29:43 | [diff] [blame] | 1372 | gfx::Point RenderWidget::GetScrollOffset() { |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 1373 | // Bare RenderWidgets don't support scroll offset. |
[email protected] | bcaf227 | 2011-02-15 15:29:43 | [diff] [blame] | 1374 | return gfx::Point(0, 0); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 1375 | } |
| 1376 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1377 | void RenderWidget::SetHidden(bool hidden) { |
| 1378 | if (is_hidden_ == hidden) |
| 1379 | return; |
| 1380 | |
| 1381 | // The status has changed. Tell the RenderThread about it. |
| 1382 | is_hidden_ = hidden; |
| 1383 | if (is_hidden_) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1384 | RenderThread::Get()->WidgetHidden(); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1385 | else |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1386 | RenderThread::Get()->WidgetRestored(); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1387 | } |
| 1388 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1389 | void RenderWidget::WillToggleFullscreen() { |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1390 | if (!webwidget_) |
| 1391 | return; |
| 1392 | |
| 1393 | if (is_fullscreen_) { |
| 1394 | webwidget_->willExitFullScreen(); |
| 1395 | } else { |
| 1396 | webwidget_->willEnterFullScreen(); |
| 1397 | } |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | void RenderWidget::DidToggleFullscreen() { |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1401 | if (!webwidget_) |
| 1402 | return; |
| 1403 | |
| 1404 | if (is_fullscreen_) { |
| 1405 | webwidget_->didEnterFullScreen(); |
| 1406 | } else { |
| 1407 | webwidget_->didExitFullScreen(); |
| 1408 | } |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1409 | } |
| 1410 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1411 | void RenderWidget::SetBackground(const SkBitmap& background) { |
| 1412 | background_ = background; |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1413 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1414 | // Generate a full repaint. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1415 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1416 | } |
| 1417 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1418 | bool RenderWidget::next_paint_is_resize_ack() const { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1419 | return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | bool RenderWidget::next_paint_is_restore_ack() const { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1423 | return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | void RenderWidget::set_next_paint_is_resize_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1427 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | void RenderWidget::set_next_paint_is_restore_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1431 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | void RenderWidget::set_next_paint_is_repaint_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1435 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1436 | } |
| 1437 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1438 | void RenderWidget::UpdateTextInputState() { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1439 | if (!input_method_is_active_) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1440 | return; |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1441 | |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1442 | ui::TextInputType new_type = GetTextInputType(); |
| 1443 | bool new_can_compose_inline = CanComposeInline(); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1444 | // Only sends text input type and compose inline to the browser process if |
| 1445 | // they are changed. |
| 1446 | if (text_input_type_ != new_type || |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1447 | can_compose_inline_ != new_can_compose_inline) { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1448 | text_input_type_ = new_type; |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1449 | can_compose_inline_ = new_can_compose_inline; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1450 | Send(new ViewHostMsg_TextInputStateChanged( |
| 1451 | routing_id(), new_type, new_can_compose_inline)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1452 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1453 | } |
| 1454 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 1455 | void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
| 1456 | WebRect start_webrect; |
| 1457 | WebRect end_webrect; |
| 1458 | webwidget_->selectionBounds(start_webrect, end_webrect); |
| 1459 | *start = start_webrect; |
| 1460 | *end = end_webrect; |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 1461 | } |
| 1462 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1463 | void RenderWidget::UpdateSelectionBounds() { |
| 1464 | if (!webwidget_) |
| 1465 | return; |
| 1466 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 1467 | gfx::Rect start_rect; |
| 1468 | gfx::Rect end_rect; |
| 1469 | GetSelectionBounds(&start_rect, &end_rect); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1470 | if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect) |
| 1471 | return; |
| 1472 | |
| 1473 | selection_start_rect_ = start_rect; |
| 1474 | selection_end_rect_ = end_rect; |
| 1475 | Send(new ViewHostMsg_SelectionBoundsChanged( |
| 1476 | routing_id_, selection_start_rect_, selection_end_rect_)); |
| 1477 | } |
| 1478 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 1479 | // Check WebKit::WebTextInputType and ui::TextInputType is kept in sync. |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1480 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \ |
| 1481 | int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums); |
| 1482 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \ |
| 1483 | int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums); |
| 1484 | COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \ |
| 1485 | int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums); |
[email protected] | caf38ed | 2011-07-28 13:15:18 | [diff] [blame] | 1486 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \ |
| 1487 | int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums); |
| 1488 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \ |
| 1489 | int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums); |
| 1490 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \ |
| 1491 | int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums); |
| 1492 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \ |
| 1493 | int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums); |
| 1494 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \ |
| 1495 | int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1496 | |
| 1497 | ui::TextInputType RenderWidget::GetTextInputType() { |
| 1498 | if (webwidget_) { |
| 1499 | int type = webwidget_->textInputType(); |
| 1500 | // Check the type is in the range representable by ui::TextInputType. |
[email protected] | caf38ed | 2011-07-28 13:15:18 | [diff] [blame] | 1501 | DCHECK(type <= ui::TEXT_INPUT_TYPE_URL) << |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1502 | "WebKit::WebTextInputType and ui::TextInputType not synchronized"; |
| 1503 | return static_cast<ui::TextInputType>(type); |
| 1504 | } |
| 1505 | return ui::TEXT_INPUT_TYPE_NONE; |
| 1506 | } |
| 1507 | |
| 1508 | bool RenderWidget::CanComposeInline() { |
| 1509 | return true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 1510 | } |
| 1511 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1512 | WebScreenInfo RenderWidget::screenInfo() { |
| 1513 | WebScreenInfo results; |
[email protected] | a8628df | 2012-01-27 23:14:17 | [diff] [blame] | 1514 | if (host_window_) |
| 1515 | Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results)); |
[email protected] | fb200c7 | 2012-01-30 21:22:21 | [diff] [blame] | 1516 | else { |
[email protected] | a8628df | 2012-01-27 23:14:17 | [diff] [blame] | 1517 | DLOG(WARNING) << "Unable to retrieve screen information, no host window"; |
[email protected] | fb200c7 | 2012-01-30 21:22:21 | [diff] [blame] | 1518 | #if defined(USE_AURA) |
| 1519 | // TODO(backer): Remove this a temporary workaround for crbug.com/111929 |
| 1520 | // once we get a proper fix. |
[email protected] | 957e2c3 | 2012-01-31 17:42:20 | [diff] [blame] | 1521 | results.availableRect.width = 1000; |
| 1522 | results.availableRect.height = 1000; |
[email protected] | fb200c7 | 2012-01-30 21:22:21 | [diff] [blame] | 1523 | #endif |
| 1524 | } |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1525 | return results; |
| 1526 | } |
| 1527 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1528 | void RenderWidget::resetInputMethod() { |
| 1529 | if (!input_method_is_active_) |
| 1530 | return; |
| 1531 | |
| 1532 | // If the last text input type is not None, then we should finish any |
| 1533 | // ongoing composition regardless of the new text input type. |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1534 | if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1535 | // If a composition text exists, then we need to let the browser process |
| 1536 | // to cancel the input method's ongoing composition session. |
| 1537 | if (webwidget_->confirmComposition()) |
| 1538 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 1539 | } |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1540 | |
| 1541 | // Send an updated IME range with the current caret rect. |
| 1542 | ui::Range range(ui::Range::InvalidRange()); |
| 1543 | size_t location, length; |
| 1544 | if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1545 | range.set_start(location); |
| 1546 | range.set_end(location + length); |
| 1547 | } |
| 1548 | Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range)); |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1549 | } |
| 1550 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1551 | void RenderWidget::SchedulePluginMove( |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 1552 | const webkit::npapi::WebPluginGeometry& move) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1553 | size_t i = 0; |
| 1554 | for (; i < plugin_window_moves_.size(); ++i) { |
| 1555 | if (plugin_window_moves_[i].window == move.window) { |
[email protected] | 16f89d0 | 2009-08-26 17:17:58 | [diff] [blame] | 1556 | if (move.rects_valid) { |
| 1557 | plugin_window_moves_[i] = move; |
| 1558 | } else { |
| 1559 | plugin_window_moves_[i].visible = move.visible; |
| 1560 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1561 | break; |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | if (i == plugin_window_moves_.size()) |
| 1566 | plugin_window_moves_.push_back(move); |
| 1567 | } |
[email protected] | 26865477 | 2009-08-06 23:02:04 | [diff] [blame] | 1568 | |
| 1569 | void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
| 1570 | for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
| 1571 | i != plugin_window_moves_.end(); ++i) { |
| 1572 | if (i->window == window) { |
| 1573 | plugin_window_moves_.erase(i); |
| 1574 | break; |
| 1575 | } |
| 1576 | } |
| 1577 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 1578 | |
| 1579 | bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 1580 | return false; |
| 1581 | } |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 1582 | |
| 1583 | bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { |
| 1584 | return false; |
| 1585 | } |