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

Side by Side Diff: cc/trees/layer_tree_impl.cc

Issue 1680613002: Adding momentum/overscroll to views:: ScrollViews Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Tableview layout. aaaand I think we are done Created 4 years, 4 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/trees/layer_tree_impl.h ('k') | cc/trees/property_tree.h » ('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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/trees/layer_tree_impl.h" 5 #include "cc/trees/layer_tree_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <limits> 11 #include <limits>
12 #include <set> 12 #include <set>
13 13
14 #include "base/containers/adapters.h" 14 #include "base/containers/adapters.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/timer/elapsed_timer.h" 16 #include "base/timer/elapsed_timer.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "base/trace_event/trace_event_argument.h" 18 #include "base/trace_event/trace_event_argument.h"
19 #include "cc/animation/animation_host.h" 19 #include "cc/animation/animation_host.h"
20 #include "cc/base/histograms.h" 20 #include "cc/base/histograms.h"
21 #include "cc/base/math_util.h" 21 #include "cc/base/math_util.h"
22 #include "cc/base/synced_property.h" 22 #include "cc/base/synced_property.h"
23 #include "cc/debug/devtools_instrumentation.h" 23 #include "cc/debug/devtools_instrumentation.h"
24 #include "cc/debug/traced_value.h" 24 #include "cc/debug/traced_value.h"
25 #include "cc/input/page_scale_animation.h" 25 #include "cc/input/page_scale_animation.h"
26 #include "cc/input/scroll_elasticity_helper.h"
26 #include "cc/input/scrollbar_animation_controller.h" 27 #include "cc/input/scrollbar_animation_controller.h"
27 #include "cc/input/scrollbar_animation_controller_linear_fade.h" 28 #include "cc/input/scrollbar_animation_controller_linear_fade.h"
28 #include "cc/input/scrollbar_animation_controller_thinning.h" 29 #include "cc/input/scrollbar_animation_controller_thinning.h"
29 #include "cc/layers/heads_up_display_layer_impl.h" 30 #include "cc/layers/heads_up_display_layer_impl.h"
30 #include "cc/layers/layer.h" 31 #include "cc/layers/layer.h"
31 #include "cc/layers/layer_iterator.h" 32 #include "cc/layers/layer_iterator.h"
32 #include "cc/layers/layer_list_iterator.h" 33 #include "cc/layers/layer_list_iterator.h"
33 #include "cc/layers/render_surface_impl.h" 34 #include "cc/layers/render_surface_impl.h"
34 #include "cc/layers/scrollbar_layer_impl_base.h" 35 #include "cc/layers/scrollbar_layer_impl_base.h"
35 #include "cc/resources/ui_resource_request.h" 36 #include "cc/resources/ui_resource_request.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // trees, use the transform_id parameter instead of looking for indices from 147 // trees, use the transform_id parameter instead of looking for indices from
147 // LayerImpls. 148 // LayerImpls.
148 void LayerTreeImpl::DidUpdateScrollOffset(int layer_id, int transform_id) { 149 void LayerTreeImpl::DidUpdateScrollOffset(int layer_id, int transform_id) {
149 DidUpdateScrollState(layer_id); 150 DidUpdateScrollState(layer_id);
150 TransformTree& transform_tree = property_trees()->transform_tree; 151 TransformTree& transform_tree = property_trees()->transform_tree;
151 ScrollTree& scroll_tree = property_trees()->scroll_tree; 152 ScrollTree& scroll_tree = property_trees()->scroll_tree;
152 153
153 // If pending tree topology changed and we still want to notify the pending 154 // If pending tree topology changed and we still want to notify the pending
154 // tree about scroll offset in the active tree, we may not find the 155 // tree about scroll offset in the active tree, we may not find the
155 // corresponding pending layer. 156 // corresponding pending layer.
156 if (LayerById(layer_id)) { 157 if (LayerImpl* layer = LayerById(layer_id)) {
157 transform_id = LayerById(layer_id)->transform_tree_index(); 158 transform_id = layer->transform_tree_index();
158 } else { 159 } else {
159 DCHECK(!IsActiveTree()); 160 DCHECK(!IsActiveTree());
160 return; 161 return;
161 } 162 }
162 163
163 if (transform_id != -1) { 164 if (transform_id != -1) {
164 TransformNode* node = transform_tree.Node(transform_id); 165 TransformNode* node = transform_tree.Node(transform_id);
165 if (node->scroll_offset != scroll_tree.current_scroll_offset(layer_id)) { 166 gfx::ScrollOffset scroll_offset_with_overscroll =
166 node->scroll_offset = scroll_tree.current_scroll_offset(layer_id); 167 scroll_tree.current_scroll_offset(layer_id) +
168 scroll_tree.current_overscroll(layer_id);
169 if (node->scroll_offset_with_overscroll != scroll_offset_with_overscroll) {
170 node->scroll_offset_with_overscroll = scroll_offset_with_overscroll;
167 node->needs_local_transform_update = true; 171 node->needs_local_transform_update = true;
168 transform_tree.set_needs_update(true); 172 transform_tree.set_needs_update(true);
169 } 173 }
170 node->transform_changed = true; 174 node->transform_changed = true;
171 property_trees()->changed = true; 175 property_trees()->changed = true;
172 set_needs_update_draw_properties(); 176 set_needs_update_draw_properties();
173 } 177 }
174 178
175 if (IsActiveTree() && layer_tree_host_impl_->pending_tree()) 179 if (IsActiveTree() && layer_tree_host_impl_->pending_tree())
176 layer_tree_host_impl_->pending_tree()->DidUpdateScrollOffset(layer_id, 180 layer_tree_host_impl_->pending_tree()->DidUpdateScrollOffset(layer_id,
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 int new_id = layer ? layer->id() : Layer::INVALID_ID; 592 int new_id = layer ? layer->id() : Layer::INVALID_ID;
589 int new_scroll_node_id = layer ? layer->scroll_tree_index() : -1; 593 int new_scroll_node_id = layer ? layer->scroll_tree_index() : -1;
590 if (layer) 594 if (layer)
591 last_scrolled_layer_id_ = new_id; 595 last_scrolled_layer_id_ = new_id;
592 596
593 if (old_id == new_id) 597 if (old_id == new_id)
594 return; 598 return;
595 599
596 ScrollbarAnimationController* old_animation_controller = 600 ScrollbarAnimationController* old_animation_controller =
597 layer_tree_host_impl_->ScrollbarAnimationControllerForId(old_id); 601 layer_tree_host_impl_->ScrollbarAnimationControllerForId(old_id);
602 ScrollElasticityHelper* old_elasticity_helper =
603 layer_tree_host_impl_->ScrollElasticityHelperForId(old_id);
598 ScrollbarAnimationController* new_animation_controller = 604 ScrollbarAnimationController* new_animation_controller =
599 layer_tree_host_impl_->ScrollbarAnimationControllerForId(new_id); 605 layer_tree_host_impl_->ScrollbarAnimationControllerForId(new_id);
606 ScrollElasticityHelper* new_elasticity_helper =
607 layer_tree_host_impl_->ScrollElasticityHelperForId(new_id);
608 if (old_elasticity_helper == new_elasticity_helper)
609 old_elasticity_helper = new_elasticity_helper = nullptr;
600 610
601 if (old_animation_controller) 611 if (old_animation_controller)
602 old_animation_controller->DidScrollEnd(); 612 old_animation_controller->DidScrollEnd();
613
603 scroll_tree.set_currently_scrolling_node(new_scroll_node_id); 614 scroll_tree.set_currently_scrolling_node(new_scroll_node_id);
615
604 if (new_animation_controller) 616 if (new_animation_controller)
605 new_animation_controller->DidScrollBegin(); 617 new_animation_controller->DidScrollBegin();
606 } 618 }
607 619
608 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { 620 void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
609 SetCurrentlyScrollingLayer(NULL); 621 SetCurrentlyScrollingLayer(NULL);
610 } 622 }
611 623
612 float LayerTreeImpl::ClampPageScaleFactorToLimits( 624 float LayerTreeImpl::ClampPageScaleFactorToLimits(
613 float page_scale_factor) const { 625 float page_scale_factor) const {
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 scroll_layer_id, layer_tree_host_impl_, delay, resize_delay, 1376 scroll_layer_id, layer_tree_host_impl_, delay, resize_delay,
1365 duration); 1377 duration);
1366 } 1378 }
1367 case LayerTreeSettings::NO_ANIMATOR: 1379 case LayerTreeSettings::NO_ANIMATOR:
1368 NOTREACHED(); 1380 NOTREACHED();
1369 break; 1381 break;
1370 } 1382 }
1371 return nullptr; 1383 return nullptr;
1372 } 1384 }
1373 1385
1386 std::unique_ptr<ScrollElasticityHelper>
1387 LayerTreeImpl::CreateScrollElasticityHelper(int scroll_layer_id) {
1388 DCHECK(settings().enable_elastic_overscroll);
1389 return ScrollElasticityHelper::CreateForLayer(scroll_layer_id,
1390 layer_tree_host_impl_);
1391 }
1392
1374 void LayerTreeImpl::DidAnimateScrollOffset() { 1393 void LayerTreeImpl::DidAnimateScrollOffset() {
1375 layer_tree_host_impl_->DidAnimateScrollOffset(); 1394 layer_tree_host_impl_->DidAnimateScrollOffset();
1376 } 1395 }
1377 1396
1378 bool LayerTreeImpl::use_gpu_rasterization() const { 1397 bool LayerTreeImpl::use_gpu_rasterization() const {
1379 return layer_tree_host_impl_->use_gpu_rasterization(); 1398 return layer_tree_host_impl_->use_gpu_rasterization();
1380 } 1399 }
1381 1400
1382 GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const { 1401 GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const {
1383 return layer_tree_host_impl_->gpu_rasterization_status(); 1402 return layer_tree_host_impl_->gpu_rasterization_status();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 return scrollbars; 1617 return scrollbars;
1599 } 1618 }
1600 1619
1601 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) { 1620 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) {
1602 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) 1621 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID)
1603 return; 1622 return;
1604 1623
1605 clip_scroll_map_.insert( 1624 clip_scroll_map_.insert(
1606 std::pair<int, int>(layer->scroll_clip_layer_id(), layer->id())); 1625 std::pair<int, int>(layer->scroll_clip_layer_id(), layer->id()));
1607 1626
1627 bool can_overscroll = layer->can_overscroll();
1628 if (can_overscroll && settings().enable_elastic_overscroll &&
1629 (layer->user_scrollable_horizontal() ||
1630 layer->user_scrollable_vertical())) {
1631 layer_tree_host_impl_->RegisterScrollElasticityHelper(layer->id());
1632 }
1633
1608 DidUpdateScrollState(layer->id()); 1634 DidUpdateScrollState(layer->id());
1609 } 1635 }
1610 1636
1611 void LayerTreeImpl::UnregisterScrollLayer(LayerImpl* layer) { 1637 void LayerTreeImpl::UnregisterScrollLayer(LayerImpl* layer) {
1612 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) 1638 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID)
1613 return; 1639 return;
1614 1640
1641 layer_tree_host_impl_->UnregisterScrollElasticityHelper(layer->id());
1615 clip_scroll_map_.erase(layer->scroll_clip_layer_id()); 1642 clip_scroll_map_.erase(layer->scroll_clip_layer_id());
1616 } 1643 }
1617 1644
1618 void LayerTreeImpl::AddSurfaceLayer(LayerImpl* layer) { 1645 void LayerTreeImpl::AddSurfaceLayer(LayerImpl* layer) {
1619 DCHECK(std::find(surface_layers_.begin(), surface_layers_.end(), layer) == 1646 DCHECK(std::find(surface_layers_.begin(), surface_layers_.end(), layer) ==
1620 surface_layers_.end()); 1647 surface_layers_.end());
1621 surface_layers_.push_back(layer); 1648 surface_layers_.push_back(layer);
1622 } 1649 }
1623 1650
1624 void LayerTreeImpl::RemoveSurfaceLayer(LayerImpl* layer) { 1651 void LayerTreeImpl::RemoveSurfaceLayer(LayerImpl* layer) {
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 2059
2033 void LayerTreeImpl::ResetAllChangeTracking() { 2060 void LayerTreeImpl::ResetAllChangeTracking() {
2034 layers_that_should_push_properties_.clear(); 2061 layers_that_should_push_properties_.clear();
2035 // Iterate over all layers, including masks and replicas. 2062 // Iterate over all layers, including masks and replicas.
2036 for (auto& layer : *layers_) 2063 for (auto& layer : *layers_)
2037 layer->ResetChangeTracking(); 2064 layer->ResetChangeTracking();
2038 property_trees_.ResetAllChangeTracking(); 2065 property_trees_.ResetAllChangeTracking();
2039 } 2066 }
2040 2067
2041 } // namespace cc 2068 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_impl.h ('k') | cc/trees/property_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698