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

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

Issue 2194833002: Overscroll and Elasticity for views::ScrollView Base URL: https://chromium.googlesource.com/chromium/src.git@20160728-MacViews-RouteThroughInputHandler
Patch Set: Restore functionality and fix bugs \o/ Created 4 years, 1 month 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.h ('k') | cc/layers/layer_impl.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 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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.h" 5 #include "cc/layers/layer.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>
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 DCHECK(IsPropertyChangeAllowed()); 765 DCHECK(IsPropertyChangeAllowed());
766 766
767 if (inputs_.scroll_offset == scroll_offset) 767 if (inputs_.scroll_offset == scroll_offset)
768 return; 768 return;
769 inputs_.scroll_offset = scroll_offset; 769 inputs_.scroll_offset = scroll_offset;
770 770
771 if (!layer_tree_host_) 771 if (!layer_tree_host_)
772 return; 772 return;
773 773
774 PropertyTrees* property_trees = layer_tree_->property_trees(); 774 PropertyTrees* property_trees = layer_tree_->property_trees();
775 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) 775 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) {
776 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); 776 property_trees->scroll_tree.SetScrollOffset(id(), inputs_.scroll_offset,
777 inputs_.overscroll);
778 }
777 779
778 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, 780 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM,
779 id())) { 781 id())) {
780 DCHECK_EQ(transform_tree_index(), 782 DCHECK_EQ(transform_tree_index(),
781 property_trees->transform_id_to_index_map[id()]); 783 property_trees->transform_id_to_index_map[id()]);
782 TransformNode* transform_node = 784 TransformNode* transform_node =
783 property_trees->transform_tree.Node(transform_tree_index()); 785 property_trees->transform_tree.Node(transform_tree_index());
784 transform_node->scroll_offset = CurrentScrollOffset(); 786 transform_node->scroll_offset_with_overscroll =
787 inputs_.scroll_offset + inputs_.overscroll;
785 transform_node->needs_local_transform_update = true; 788 transform_node->needs_local_transform_update = true;
786 property_trees->transform_tree.set_needs_update(true); 789 property_trees->transform_tree.set_needs_update(true);
787 SetNeedsCommitNoRebuild(); 790 SetNeedsCommitNoRebuild();
788 return; 791 return;
789 } 792 }
790 793
791 SetNeedsCommit(); 794 SetNeedsCommit();
792 } 795 }
793 796
794 void Layer::SetScrollOffsetFromImplSide( 797 void Layer::SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset,
795 const gfx::ScrollOffset& scroll_offset) { 798 gfx::Vector2dF* overscroll_delta) {
796 DCHECK(IsPropertyChangeAllowed()); 799 DCHECK(IsPropertyChangeAllowed());
797 // This function only gets called during a BeginMainFrame, so there 800 // This function only gets called during a BeginMainFrame, so there
798 // is no need to call SetNeedsUpdate here. 801 // is no need to call SetNeedsUpdate here.
799 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); 802 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested());
800 if (inputs_.scroll_offset == scroll_offset) 803
804 gfx::ScrollOffset overscroll = inputs_.overscroll;
805 if (inputs_.can_overscroll && overscroll_delta) {
806 overscroll = gfx::ScrollOffsetWithDelta(overscroll, *overscroll_delta);
807 *overscroll_delta = gfx::Vector2dF();
808 }
809 if (inputs_.scroll_offset == scroll_offset &&
810 inputs_.overscroll == overscroll)
801 return; 811 return;
812
802 inputs_.scroll_offset = scroll_offset; 813 inputs_.scroll_offset = scroll_offset;
814 inputs_.overscroll = overscroll;
803 SetNeedsPushProperties(); 815 SetNeedsPushProperties();
804 816
805 bool needs_rebuild = true; 817 bool needs_rebuild = true;
806 818
807 PropertyTrees* property_trees = layer_tree_->property_trees(); 819 PropertyTrees* property_trees = layer_tree_->property_trees();
808 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) 820 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) {
809 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); 821 property_trees->scroll_tree.SetScrollOffset(id(), inputs_.scroll_offset,
822 inputs_.overscroll);
823 }
810 824
811 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, 825 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM,
812 id())) { 826 id())) {
813 DCHECK_EQ(transform_tree_index(), 827 DCHECK_EQ(transform_tree_index(),
814 property_trees->transform_id_to_index_map[id()]); 828 property_trees->transform_id_to_index_map[id()]);
815 TransformNode* transform_node = 829 TransformNode* transform_node =
816 property_trees->transform_tree.Node(transform_tree_index()); 830 property_trees->transform_tree.Node(transform_tree_index());
817 transform_node->scroll_offset = CurrentScrollOffset(); 831 transform_node->scroll_offset_with_overscroll =
832 inputs_.scroll_offset + inputs_.overscroll;
818 transform_node->needs_local_transform_update = true; 833 transform_node->needs_local_transform_update = true;
819 property_trees->transform_tree.set_needs_update(true); 834 property_trees->transform_tree.set_needs_update(true);
820 needs_rebuild = false; 835 needs_rebuild = false;
821 } 836 }
822 837
823 if (needs_rebuild) 838 if (needs_rebuild)
824 property_trees->needs_rebuild = true; 839 property_trees->needs_rebuild = true;
825 840
826 if (!inputs_.did_scroll_callback.is_null()) 841 if (!inputs_.did_scroll_callback.is_null())
827 inputs_.did_scroll_callback.Run(); 842 inputs_.did_scroll_callback.Run();
828 // The callback could potentially change the layer structure: 843 // The callback could potentially change the layer structure:
829 // "this" may have been destroyed during the process. 844 // "this" may have been destroyed during the process.
830 } 845 }
831 846
832 void Layer::SetScrollClipLayerId(int clip_layer_id) { 847 void Layer::SetScrollClipAndCanOverscroll(int clip_layer_id,
848 bool can_overscroll) {
833 DCHECK(IsPropertyChangeAllowed()); 849 DCHECK(IsPropertyChangeAllowed());
834 if (inputs_.scroll_clip_layer_id == clip_layer_id) 850 if (inputs_.scroll_clip_layer_id == clip_layer_id &&
851 inputs_.can_overscroll == can_overscroll)
835 return; 852 return;
836 inputs_.scroll_clip_layer_id = clip_layer_id; 853 inputs_.scroll_clip_layer_id = clip_layer_id;
854 inputs_.can_overscroll = can_overscroll;
837 SetNeedsCommit(); 855 SetNeedsCommit();
838 } 856 }
839 857
840 Layer* Layer::scroll_clip_layer() const { 858 Layer* Layer::scroll_clip_layer() const {
841 DCHECK(layer_tree_); 859 DCHECK(layer_tree_);
842 return layer_tree_->LayerById(inputs_.scroll_clip_layer_id); 860 return layer_tree_->LayerById(inputs_.scroll_clip_layer_id);
843 } 861 }
844 862
845 void Layer::SetUserScrollable(bool horizontal, bool vertical) { 863 void Layer::SetUserScrollable(bool horizontal, bool vertical) {
846 DCHECK(IsPropertyChangeAllowed()); 864 DCHECK(IsPropertyChangeAllowed());
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 layer->SetPosition(inputs_.position); 1176 layer->SetPosition(inputs_.position);
1159 layer->set_should_flatten_transform_from_property_tree( 1177 layer->set_should_flatten_transform_from_property_tree(
1160 should_flatten_transform_from_property_tree_); 1178 should_flatten_transform_from_property_tree_);
1161 layer->set_draw_blend_mode(draw_blend_mode_); 1179 layer->set_draw_blend_mode(draw_blend_mode_);
1162 layer->SetUseParentBackfaceVisibility(inputs_.use_parent_backface_visibility); 1180 layer->SetUseParentBackfaceVisibility(inputs_.use_parent_backface_visibility);
1163 layer->SetUseLocalTransformForBackfaceVisibility( 1181 layer->SetUseLocalTransformForBackfaceVisibility(
1164 use_local_transform_for_backface_visibility_); 1182 use_local_transform_for_backface_visibility_);
1165 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); 1183 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_);
1166 layer->Set3dSortingContextId(inputs_.sorting_context_id); 1184 layer->Set3dSortingContextId(inputs_.sorting_context_id);
1167 1185
1168 layer->SetScrollClipLayer(inputs_.scroll_clip_layer_id); 1186 layer->SetScrollClipAndCanOverscroll(inputs_.scroll_clip_layer_id,
1187 inputs_.can_overscroll);
1169 layer->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); 1188 layer->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal);
1170 layer->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); 1189 layer->set_user_scrollable_vertical(inputs_.user_scrollable_vertical);
1171 layer->SetElementId(inputs_.element_id); 1190 layer->SetElementId(inputs_.element_id);
1172 layer->SetMutableProperties(inputs_.mutable_properties); 1191 layer->SetMutableProperties(inputs_.mutable_properties);
1173 1192
1174 // When a scroll offset animation is interrupted the new scroll position on 1193 // When a scroll offset animation is interrupted the new scroll position on
1175 // the pending tree will clobber any impl-side scrolling occuring on the 1194 // the pending tree will clobber any impl-side scrolling occuring on the
1176 // active tree. To do so, avoid scrolling the pending tree along with it 1195 // active tree. To do so, avoid scrolling the pending tree along with it
1177 // instead of trying to undo that scrolling later. 1196 // instead of trying to undo that scrolling later.
1178 if (ScrollOffsetAnimationWasInterrupted()) 1197 if (ScrollOffsetAnimationWasInterrupted())
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 TransformToProto(inputs_.transform, base->mutable_transform()); 1361 TransformToProto(inputs_.transform, base->mutable_transform());
1343 Point3FToProto(inputs_.transform_origin, base->mutable_transform_origin()); 1362 Point3FToProto(inputs_.transform_origin, base->mutable_transform_origin());
1344 base->set_is_drawable(inputs_.is_drawable); 1363 base->set_is_drawable(inputs_.is_drawable);
1345 base->set_double_sided(inputs_.double_sided); 1364 base->set_double_sided(inputs_.double_sided);
1346 base->set_should_flatten_transform(inputs_.should_flatten_transform); 1365 base->set_should_flatten_transform(inputs_.should_flatten_transform);
1347 base->set_sorting_context_id(inputs_.sorting_context_id); 1366 base->set_sorting_context_id(inputs_.sorting_context_id);
1348 base->set_use_parent_backface_visibility( 1367 base->set_use_parent_backface_visibility(
1349 inputs_.use_parent_backface_visibility); 1368 inputs_.use_parent_backface_visibility);
1350 base->set_background_color(inputs_.background_color); 1369 base->set_background_color(inputs_.background_color);
1351 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset()); 1370 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset());
1371 ScrollOffsetToProto(inputs_.overscroll, base->mutable_overscroll());
1352 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id); 1372 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id);
1353 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); 1373 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal);
1354 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); 1374 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical);
1375 base->set_can_overscroll(inputs_.can_overscroll);
1355 base->set_main_thread_scrolling_reasons( 1376 base->set_main_thread_scrolling_reasons(
1356 inputs_.main_thread_scrolling_reasons); 1377 inputs_.main_thread_scrolling_reasons);
1357 RegionToProto(inputs_.non_fast_scrollable_region, 1378 RegionToProto(inputs_.non_fast_scrollable_region,
1358 base->mutable_non_fast_scrollable_region()); 1379 base->mutable_non_fast_scrollable_region());
1359 RegionToProto(inputs_.touch_event_handler_region, 1380 RegionToProto(inputs_.touch_event_handler_region,
1360 base->mutable_touch_event_handler_region()); 1381 base->mutable_touch_event_handler_region());
1361 base->set_is_container_for_fixed_position_layers( 1382 base->set_is_container_for_fixed_position_layers(
1362 inputs_.is_container_for_fixed_position_layers); 1383 inputs_.is_container_for_fixed_position_layers);
1363 inputs_.position_constraint.ToProtobuf(base->mutable_position_constraint()); 1384 inputs_.position_constraint.ToProtobuf(base->mutable_position_constraint());
1364 inputs_.sticky_position_constraint.ToProtobuf( 1385 inputs_.sticky_position_constraint.ToProtobuf(
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); 1501 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode());
1481 inputs_.use_parent_backface_visibility = 1502 inputs_.use_parent_backface_visibility =
1482 base.use_parent_backface_visibility(); 1503 base.use_parent_backface_visibility();
1483 inputs_.transform = ProtoToTransform(base.transform()); 1504 inputs_.transform = ProtoToTransform(base.transform());
1484 inputs_.sorting_context_id = base.sorting_context_id(); 1505 inputs_.sorting_context_id = base.sorting_context_id();
1485 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); 1506 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content();
1486 1507
1487 inputs_.scroll_clip_layer_id = base.scroll_clip_layer_id(); 1508 inputs_.scroll_clip_layer_id = base.scroll_clip_layer_id();
1488 inputs_.user_scrollable_horizontal = base.user_scrollable_horizontal(); 1509 inputs_.user_scrollable_horizontal = base.user_scrollable_horizontal();
1489 inputs_.user_scrollable_vertical = base.user_scrollable_vertical(); 1510 inputs_.user_scrollable_vertical = base.user_scrollable_vertical();
1511 inputs_.can_overscroll = base.can_overscroll();
1490 1512
1491 inputs_.scroll_parent = base.scroll_parent_id() == INVALID_ID 1513 inputs_.scroll_parent = base.scroll_parent_id() == INVALID_ID
1492 ? nullptr 1514 ? nullptr
1493 : layer_tree_->LayerById(base.scroll_parent_id()); 1515 : layer_tree_->LayerById(base.scroll_parent_id());
1494 1516
1495 // If there have been scroll children entries in previous deserializations, 1517 // If there have been scroll children entries in previous deserializations,
1496 // clear out the set. If there have been none, initialize the set of children. 1518 // clear out the set. If there have been none, initialize the set of children.
1497 // After this, the set is in the correct state to only add the new children. 1519 // After this, the set is in the correct state to only add the new children.
1498 // If the set of children has not changed, for now this code still rebuilds 1520 // If the set of children has not changed, for now this code still rebuilds
1499 // the set. 1521 // the set.
(...skipping 20 matching lines...) Expand all
1520 clip_children_->clear(); 1542 clip_children_->clear();
1521 else if (base.clip_children_ids_size() > 0) 1543 else if (base.clip_children_ids_size() > 0)
1522 clip_children_.reset(new std::set<Layer*>); 1544 clip_children_.reset(new std::set<Layer*>);
1523 for (int i = 0; i < base.clip_children_ids_size(); ++i) { 1545 for (int i = 0; i < base.clip_children_ids_size(); ++i) {
1524 int child_id = base.clip_children_ids(i); 1546 int child_id = base.clip_children_ids(i);
1525 scoped_refptr<Layer> child = layer_tree_->LayerById(child_id); 1547 scoped_refptr<Layer> child = layer_tree_->LayerById(child_id);
1526 clip_children_->insert(child.get()); 1548 clip_children_->insert(child.get());
1527 } 1549 }
1528 1550
1529 inputs_.scroll_offset = ProtoToScrollOffset(base.scroll_offset()); 1551 inputs_.scroll_offset = ProtoToScrollOffset(base.scroll_offset());
1552 inputs_.overscroll = ProtoToScrollOffset(base.overscroll());
1530 1553
1531 inputs_.update_rect.Union(ProtoToRect(base.update_rect())); 1554 inputs_.update_rect.Union(ProtoToRect(base.update_rect()));
1532 1555
1533 inputs_.has_will_change_transform_hint = 1556 inputs_.has_will_change_transform_hint =
1534 base.has_will_change_transform_hint(); 1557 base.has_will_change_transform_hint();
1535 } 1558 }
1536 1559
1537 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { 1560 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
1538 return LayerImpl::Create(tree_impl, inputs_.layer_id); 1561 return LayerImpl::Create(tree_impl, inputs_.layer_id);
1539 } 1562 }
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 1912
1890 LayerTree* Layer::GetLayerTree() const { 1913 LayerTree* Layer::GetLayerTree() const {
1891 return layer_tree_; 1914 return layer_tree_;
1892 } 1915 }
1893 1916
1894 void Layer::SetLayerIdForTesting(int id) { 1917 void Layer::SetLayerIdForTesting(int id) {
1895 inputs_.layer_id = id; 1918 inputs_.layer_id = id;
1896 } 1919 }
1897 1920
1898 } // namespace cc 1921 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698