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

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

Issue 2053193002: cc : Move LayerImpl::children to test properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_list_iterator.h" 5 #include "cc/layers/layer_list_iterator.h"
6 6
7 #include "cc/layers/layer.h" 7 #include "cc/layers/layer.h"
8 #include "cc/layers/layer_impl.h" 8 #include "cc/layers/layer_impl.h"
9 9
10 namespace cc { 10 namespace cc {
11 11
12 template <typename LayerType> 12 template <typename LayerType>
13 LayerListIterator<LayerType>::LayerListIterator(LayerType* root_layer) 13 LayerListIterator<LayerType>::LayerListIterator(LayerType* root_layer)
14 : current_layer_(root_layer) { 14 : current_layer_(root_layer) {
15 DCHECK(!root_layer || !root_layer->parent()); 15 DCHECK(!root_layer || !root_layer->parent());
16 list_indices_.push_back(0); 16 list_indices_.push_back(0);
17 } 17 }
18 18
19 static LayerImplList& Children(LayerImpl* layer) {
20 return layer->test_properties()->children;
21 }
22
23 static const LayerList& Children(Layer* layer) {
24 return layer->children();
25 }
26
27 static LayerImpl* ChildAt(LayerImpl* layer, int index) {
28 return layer->test_properties()->children[index];
29 }
30
31 static Layer* ChildAt(Layer* layer, int index) {
32 return layer->child_at(index);
33 }
34
19 template <typename LayerType> 35 template <typename LayerType>
20 LayerListIterator<LayerType>::LayerListIterator( 36 LayerListIterator<LayerType>::LayerListIterator(
21 const LayerListIterator<LayerType>& other) = default; 37 const LayerListIterator<LayerType>& other) = default;
22 38
23 template <typename LayerType> 39 template <typename LayerType>
24 LayerListIterator<LayerType>::~LayerListIterator() {} 40 LayerListIterator<LayerType>::~LayerListIterator() {}
25 41
26 template <typename LayerType> 42 template <typename LayerType>
27 LayerListIterator<LayerType>& LayerListIterator<LayerType>::operator++() { 43 LayerListIterator<LayerType>& LayerListIterator<LayerType>::operator++() {
28 // case 0: done 44 // case 0: done
29 if (!current_layer_) 45 if (!current_layer_)
30 return *this; 46 return *this;
31 47
32 // case 1: descend. 48 // case 1: descend.
33 if (!current_layer_->children().empty()) { 49 if (!Children(current_layer_).empty()) {
34 current_layer_ = current_layer_->child_at(0); 50 current_layer_ = ChildAt(current_layer_, 0);
35 list_indices_.push_back(0); 51 list_indices_.push_back(0);
36 return *this; 52 return *this;
37 } 53 }
38 54
39 for (LayerType* parent = current_layer_->parent(); parent; 55 for (LayerType* parent = current_layer_->parent(); parent;
40 parent = parent->parent()) { 56 parent = parent->parent()) {
41 // We now try and advance in some list of siblings. 57 // We now try and advance in some list of siblings.
42 // case 2: Advance to a sibling. 58 // case 2: Advance to a sibling.
43 if (list_indices_.back() + 1 < parent->children().size()) { 59 if (list_indices_.back() + 1 < Children(parent).size()) {
44 ++list_indices_.back(); 60 ++list_indices_.back();
45 current_layer_ = parent->child_at(list_indices_.back()); 61 current_layer_ = ChildAt(parent, list_indices_.back());
46 return *this; 62 return *this;
47 } 63 }
48 64
49 // We need to ascend. We will pop an index off the stack. 65 // We need to ascend. We will pop an index off the stack.
50 list_indices_.pop_back(); 66 list_indices_.pop_back();
51 } 67 }
52 68
53 current_layer_ = nullptr; 69 current_layer_ = nullptr;
54 return *this; 70 return *this;
55 } 71 }
(...skipping 21 matching lines...) Expand all
77 list_indices().pop_back(); 93 list_indices().pop_back();
78 this->current_layer_ = current_layer()->parent(); 94 this->current_layer_ = current_layer()->parent();
79 return *this; 95 return *this;
80 } 96 }
81 97
82 // case 2: we're not the leftmost sibling. In this case, we want to move one 98 // case 2: we're not the leftmost sibling. In this case, we want to move one
83 // sibling over, and then descend to the rightmost descendant in that subtree. 99 // sibling over, and then descend to the rightmost descendant in that subtree.
84 CHECK(current_layer()->parent()); 100 CHECK(current_layer()->parent());
85 --list_indices().back(); 101 --list_indices().back();
86 this->current_layer_ = 102 this->current_layer_ =
87 current_layer()->parent()->child_at(list_indices().back()); 103 ChildAt(current_layer()->parent(), list_indices().back());
88 DescendToRightmostInSubtree(); 104 DescendToRightmostInSubtree();
89 return *this; 105 return *this;
90 } 106 }
91 107
92 template <typename LayerType> 108 template <typename LayerType>
93 void LayerListReverseIterator<LayerType>::DescendToRightmostInSubtree() { 109 void LayerListReverseIterator<LayerType>::DescendToRightmostInSubtree() {
94 if (!current_layer()) 110 if (!current_layer())
95 return; 111 return;
96 112
97 if (current_layer()->children().empty()) 113 if (Children(current_layer()).empty())
98 return; 114 return;
99 115
100 size_t last_index = current_layer()->children().size() - 1; 116 size_t last_index = Children(current_layer()).size() - 1;
101 this->current_layer_ = current_layer()->child_at(last_index); 117 this->current_layer_ = ChildAt(current_layer(), last_index);
102 list_indices().push_back(last_index); 118 list_indices().push_back(last_index);
103 DescendToRightmostInSubtree(); 119 DescendToRightmostInSubtree();
104 } 120 }
105 121
106 template class LayerListIterator<Layer>; 122 template class LayerListIterator<Layer>;
107 template class LayerListIterator<LayerImpl>; 123 template class LayerListIterator<LayerImpl>;
108 template class LayerListReverseIterator<Layer>; 124 template class LayerListReverseIterator<Layer>;
109 template class LayerListReverseIterator<LayerImpl>; 125 template class LayerListReverseIterator<LayerImpl>;
110 126
111 } // namespace cc 127 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698