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