Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: cc/layers/layer_impl.cc

Issue 1038173002: Refactor delegated scrolling in LayerImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a new test for Inner/Outer viewport scrolling Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/layer_impl.h ('k') | cc/layers/layer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/layer_impl.h" 5 #include "cc/layers/layer_impl.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "base/trace_event/trace_event_argument.h" 10 #include "base/trace_event/trace_event_argument.h"
11 #include "cc/animation/animation_registrar.h" 11 #include "cc/animation/animation_registrar.h"
12 #include "cc/animation/scrollbar_animation_controller.h" 12 #include "cc/animation/scrollbar_animation_controller.h"
13 #include "cc/base/math_util.h" 13 #include "cc/base/math_util.h"
14 #include "cc/base/simple_enclosed_region.h" 14 #include "cc/base/simple_enclosed_region.h"
15 #include "cc/debug/debug_colors.h" 15 #include "cc/debug/debug_colors.h"
16 #include "cc/debug/layer_tree_debug_state.h" 16 #include "cc/debug/layer_tree_debug_state.h"
17 #include "cc/debug/micro_benchmark_impl.h" 17 #include "cc/debug/micro_benchmark_impl.h"
18 #include "cc/debug/traced_value.h" 18 #include "cc/debug/traced_value.h"
19 #include "cc/input/layer_scroll_offset_delegate.h"
20 #include "cc/layers/layer_utils.h" 19 #include "cc/layers/layer_utils.h"
21 #include "cc/layers/painted_scrollbar_layer_impl.h" 20 #include "cc/layers/painted_scrollbar_layer_impl.h"
22 #include "cc/output/copy_output_request.h" 21 #include "cc/output/copy_output_request.h"
23 #include "cc/quads/debug_border_draw_quad.h" 22 #include "cc/quads/debug_border_draw_quad.h"
24 #include "cc/quads/render_pass.h" 23 #include "cc/quads/render_pass.h"
25 #include "cc/trees/layer_tree_host_common.h" 24 #include "cc/trees/layer_tree_host_common.h"
26 #include "cc/trees/layer_tree_impl.h" 25 #include "cc/trees/layer_tree_impl.h"
27 #include "cc/trees/layer_tree_settings.h" 26 #include "cc/trees/layer_tree_settings.h"
28 #include "cc/trees/proxy.h" 27 #include "cc/trees/proxy.h"
29 #include "ui/gfx/geometry/box_f.h" 28 #include "ui/gfx/geometry/box_f.h"
(...skipping 12 matching lines...) Expand all
42 int id, 41 int id,
43 scoped_refptr<SyncedScrollOffset> scroll_offset) 42 scoped_refptr<SyncedScrollOffset> scroll_offset)
44 : parent_(nullptr), 43 : parent_(nullptr),
45 scroll_parent_(nullptr), 44 scroll_parent_(nullptr),
46 clip_parent_(nullptr), 45 clip_parent_(nullptr),
47 mask_layer_id_(-1), 46 mask_layer_id_(-1),
48 replica_layer_id_(-1), 47 replica_layer_id_(-1),
49 layer_id_(id), 48 layer_id_(id),
50 layer_tree_impl_(tree_impl), 49 layer_tree_impl_(tree_impl),
51 scroll_offset_(scroll_offset), 50 scroll_offset_(scroll_offset),
52 scroll_offset_delegate_(nullptr),
53 scroll_clip_layer_(nullptr), 51 scroll_clip_layer_(nullptr),
54 should_scroll_on_main_thread_(false), 52 should_scroll_on_main_thread_(false),
55 have_wheel_event_handlers_(false), 53 have_wheel_event_handlers_(false),
56 have_scroll_event_handlers_(false), 54 have_scroll_event_handlers_(false),
57 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE), 55 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
58 user_scrollable_horizontal_(true), 56 user_scrollable_horizontal_(true),
59 user_scrollable_vertical_(true), 57 user_scrollable_vertical_(true),
60 stacking_order_changed_(false), 58 stacking_order_changed_(false),
61 double_sided_(true), 59 double_sided_(true),
62 should_flatten_transform_(true), 60 should_flatten_transform_(true),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return true; 155 return true;
158 } 156 }
159 157
160 return false; 158 return false;
161 } 159 }
162 160
163 void LayerImpl::SetScrollParent(LayerImpl* parent) { 161 void LayerImpl::SetScrollParent(LayerImpl* parent) {
164 if (scroll_parent_ == parent) 162 if (scroll_parent_ == parent)
165 return; 163 return;
166 164
167 // Having both a scroll parent and a scroll offset delegate is unsupported.
168 DCHECK(!scroll_offset_delegate_);
169
170 if (parent) 165 if (parent)
171 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent); 166 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent);
172 167
173 scroll_parent_ = parent; 168 scroll_parent_ = parent;
174 SetNeedsPushProperties(); 169 SetNeedsPushProperties();
175 } 170 }
176 171
177 void LayerImpl::SetDebugInfo( 172 void LayerImpl::SetDebugInfo(
178 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) { 173 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) {
179 debug_info_ = other; 174 debug_info_ = other;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 return RenderPassId(0, 0); 373 return RenderPassId(0, 0);
379 } 374 }
380 375
381 void LayerImpl::GetContentsResourceId(ResourceProvider::ResourceId* resource_id, 376 void LayerImpl::GetContentsResourceId(ResourceProvider::ResourceId* resource_id,
382 gfx::Size* resource_size) const { 377 gfx::Size* resource_size) const {
383 NOTREACHED(); 378 NOTREACHED();
384 *resource_id = 0; 379 *resource_id = 0;
385 } 380 }
386 381
387 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { 382 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) {
388 RefreshFromScrollDelegate();
389
390 gfx::ScrollOffset adjusted_scroll(scroll); 383 gfx::ScrollOffset adjusted_scroll(scroll);
391 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) { 384 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) {
392 if (!user_scrollable_horizontal_) 385 if (!user_scrollable_horizontal_)
393 adjusted_scroll.set_x(0); 386 adjusted_scroll.set_x(0);
394 if (!user_scrollable_vertical_) 387 if (!user_scrollable_vertical_)
395 adjusted_scroll.set_y(0); 388 adjusted_scroll.set_y(0);
396 } 389 }
397 DCHECK(scrollable()); 390 DCHECK(scrollable());
398 gfx::ScrollOffset old_offset = CurrentScrollOffset(); 391 gfx::ScrollOffset old_offset = CurrentScrollOffset();
399 gfx::ScrollOffset new_offset = 392 gfx::ScrollOffset new_offset =
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 float contents_scale_y) { 1094 float contents_scale_y) {
1102 if (this->contents_scale_x() == contents_scale_x && 1095 if (this->contents_scale_x() == contents_scale_x &&
1103 this->contents_scale_y() == contents_scale_y) 1096 this->contents_scale_y() == contents_scale_y)
1104 return; 1097 return;
1105 1098
1106 draw_properties_.contents_scale_x = contents_scale_x; 1099 draw_properties_.contents_scale_x = contents_scale_x;
1107 draw_properties_.contents_scale_y = contents_scale_y; 1100 draw_properties_.contents_scale_y = contents_scale_y;
1108 NoteLayerPropertyChanged(); 1101 NoteLayerPropertyChanged();
1109 } 1102 }
1110 1103
1111 void LayerImpl::SetScrollOffsetDelegate(
1112 ScrollOffsetDelegate* scroll_offset_delegate) {
1113 // Having both a scroll parent and a scroll offset delegate is unsupported.
1114 DCHECK(!scroll_parent_);
1115 RefreshFromScrollDelegate();
1116 scroll_offset_delegate_ = scroll_offset_delegate;
1117 if (scroll_offset_delegate_)
1118 scroll_offset_delegate_->SetCurrentScrollOffset(CurrentScrollOffset());
1119 }
1120
1121 bool LayerImpl::IsExternalFlingActive() const { 1104 bool LayerImpl::IsExternalFlingActive() const {
1122 return scroll_offset_delegate_ && 1105 return layer_tree_impl_->IsExternalFlingActive();
1123 scroll_offset_delegate_->IsExternalFlingActive();
1124 } 1106 }
1125 1107
1126 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { 1108 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) {
1127 DCHECK(IsActive()); 1109 DCHECK(IsActive());
1128 if (scroll_offset_->SetCurrent(scroll_offset)) 1110 if (scroll_offset_->SetCurrent(scroll_offset))
1129 DidUpdateScrollOffset(); 1111 DidUpdateScrollOffset(false);
1112 }
1113
1114 void LayerImpl::SetCurrentScrollOffsetFromDelegate(
1115 const gfx::ScrollOffset& scroll_offset) {
1116 DCHECK(IsActive());
1117 if (scroll_offset_->SetCurrent(scroll_offset))
1118 DidUpdateScrollOffset(true);
1130 } 1119 }
1131 1120
1132 void LayerImpl::PushScrollOffsetFromMainThread( 1121 void LayerImpl::PushScrollOffsetFromMainThread(
1133 const gfx::ScrollOffset& scroll_offset) { 1122 const gfx::ScrollOffset& scroll_offset) {
1134 PushScrollOffset(&scroll_offset); 1123 PushScrollOffset(&scroll_offset);
1135 } 1124 }
1136 1125
1137 void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue( 1126 void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1138 const gfx::ScrollOffset& scroll_offset) { 1127 const gfx::ScrollOffset& scroll_offset) {
1139 scroll_offset_->set_clobber_active_value(); 1128 scroll_offset_->set_clobber_active_value();
1140 PushScrollOffset(&scroll_offset); 1129 PushScrollOffset(&scroll_offset);
1141 } 1130 }
1142 1131
1143 gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() { 1132 gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() {
1144 RefreshFromScrollDelegate();
1145
1146 // TODO(miletus): Remove all this temporary flooring machinery when 1133 // TODO(miletus): Remove all this temporary flooring machinery when
1147 // Blink fully supports fractional scrolls. 1134 // Blink fully supports fractional scrolls.
1148 gfx::ScrollOffset current_offset = CurrentScrollOffset(); 1135 gfx::ScrollOffset current_offset = CurrentScrollOffset();
1149 gfx::Vector2dF current_delta = ScrollDelta(); 1136 gfx::Vector2dF current_delta = ScrollDelta();
1150 gfx::Vector2dF floored_delta(floor(current_delta.x()), 1137 gfx::Vector2dF floored_delta(floor(current_delta.x()),
1151 floor(current_delta.y())); 1138 floor(current_delta.y()));
1152 gfx::Vector2dF diff_delta = floored_delta - current_delta; 1139 gfx::Vector2dF diff_delta = floored_delta - current_delta;
1153 gfx::ScrollOffset tmp_offset = ScrollOffsetWithDelta(current_offset, 1140 gfx::ScrollOffset tmp_offset = ScrollOffsetWithDelta(current_offset,
1154 diff_delta); 1141 diff_delta);
1155 scroll_offset_->SetCurrent(tmp_offset); 1142 scroll_offset_->SetCurrent(tmp_offset);
1156 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread(); 1143 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread();
1157 scroll_offset_->SetCurrent(current_offset); 1144 scroll_offset_->SetCurrent(current_offset);
1158 return delta; 1145 return delta;
1159 } 1146 }
1160 1147
1161 void LayerImpl::RefreshFromScrollDelegate() {
1162 if (scroll_offset_delegate_) {
1163 SetCurrentScrollOffset(
1164 gfx::ScrollOffset(scroll_offset_delegate_->GetCurrentScrollOffset()));
1165 }
1166 }
1167
1168 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { 1148 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const {
1169 return scroll_offset_->Current(IsActive()); 1149 return scroll_offset_->Current(IsActive());
1170 } 1150 }
1171 1151
1172 gfx::Vector2dF LayerImpl::ScrollDelta() const { 1152 gfx::Vector2dF LayerImpl::ScrollDelta() const {
1173 if (IsActive()) 1153 if (IsActive())
1174 return gfx::Vector2dF(scroll_offset_->Delta().x(), 1154 return gfx::Vector2dF(scroll_offset_->Delta().x(),
1175 scroll_offset_->Delta().y()); 1155 scroll_offset_->Delta().y());
1176 else 1156 else
1177 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(), 1157 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(),
(...skipping 18 matching lines...) Expand all
1196 bool changed = false; 1176 bool changed = false;
1197 if (scroll_offset) { 1177 if (scroll_offset) {
1198 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id())); 1178 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id()));
1199 changed |= scroll_offset_->PushFromMainThread(*scroll_offset); 1179 changed |= scroll_offset_->PushFromMainThread(*scroll_offset);
1200 } 1180 }
1201 if (IsActive()) { 1181 if (IsActive()) {
1202 changed |= scroll_offset_->PushPendingToActive(); 1182 changed |= scroll_offset_->PushPendingToActive();
1203 } 1183 }
1204 1184
1205 if (changed) 1185 if (changed)
1206 DidUpdateScrollOffset(); 1186 DidUpdateScrollOffset(false);
1207 } 1187 }
1208 1188
1209 void LayerImpl::DidUpdateScrollOffset() { 1189 void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate) {
1210 if (scroll_offset_delegate_) { 1190 if (!is_from_root_delegate)
1211 scroll_offset_delegate_->SetCurrentScrollOffset(CurrentScrollOffset()); 1191 layer_tree_impl()->DidUpdateScrollOffset(id());
1212 scroll_offset_delegate_->Update();
1213 RefreshFromScrollDelegate();
1214 }
1215
1216 NoteLayerPropertyChangedForSubtree(); 1192 NoteLayerPropertyChangedForSubtree();
1217 ScrollbarParametersDidChange(false); 1193 ScrollbarParametersDidChange(false);
1218 } 1194 }
1219 1195
1220 void LayerImpl::SetDoubleSided(bool double_sided) { 1196 void LayerImpl::SetDoubleSided(bool double_sided) {
1221 if (double_sided_ == double_sided) 1197 if (double_sided_ == double_sided)
1222 return; 1198 return;
1223 1199
1224 double_sided_ = double_sided; 1200 double_sided_ = double_sided;
1225 NoteLayerPropertyChangedForSubtree(); 1201 NoteLayerPropertyChangedForSubtree();
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 gfx::Transform scaled_draw_transform = 1605 gfx::Transform scaled_draw_transform =
1630 draw_properties_.target_space_transform; 1606 draw_properties_.target_space_transform;
1631 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); 1607 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
1632 gfx::Size scaled_content_bounds = 1608 gfx::Size scaled_content_bounds =
1633 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), scale)); 1609 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), scale));
1634 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, 1610 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform,
1635 gfx::Rect(scaled_content_bounds)); 1611 gfx::Rect(scaled_content_bounds));
1636 } 1612 }
1637 1613
1638 } // namespace cc 1614 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_impl.h ('k') | cc/layers/layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698