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