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