2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/paint/DeprecatedPaintLayerStackingNodeIterator.h"
34 // FIXME: We should build our primitive on top of
35 // DeprecatedLayerStackingNode and remove this include.
36 #include "core/paint/DeprecatedPaintLayer.h"
37 #include "core/paint/DeprecatedPaintLayerStackingNode.h"
41 DeprecatedPaintLayerStackingNodeIterator::DeprecatedPaintLayerStackingNodeIterator(const DeprecatedPaintLayerStackingNode
& root
, unsigned whichChildren
)
43 , m_remainingChildren(whichChildren
)
46 m_currentNormalFlowChild
= root
.layer()->firstChild();
49 DeprecatedPaintLayerStackingNode
* DeprecatedPaintLayerStackingNodeIterator::next()
51 if (m_remainingChildren
& NegativeZOrderChildren
) {
52 Vector
<DeprecatedPaintLayerStackingNode
*>* negZOrderList
= m_root
.negZOrderList();
53 if (negZOrderList
&& m_index
< negZOrderList
->size())
54 return negZOrderList
->at(m_index
++);
57 m_remainingChildren
&= ~NegativeZOrderChildren
;
60 if (m_remainingChildren
& NormalFlowChildren
) {
61 for (; m_currentNormalFlowChild
; m_currentNormalFlowChild
= m_currentNormalFlowChild
->nextSibling()) {
62 if (!m_currentNormalFlowChild
->stackingNode()->isTreatedAsOrStackingContext() && !m_currentNormalFlowChild
->isReflection()) {
63 DeprecatedPaintLayer
* normalFlowChild
= m_currentNormalFlowChild
;
64 m_currentNormalFlowChild
= m_currentNormalFlowChild
->nextSibling();
65 return normalFlowChild
->stackingNode();
69 // We reset the iterator in case we reuse it.
70 m_currentNormalFlowChild
= m_root
.layer()->firstChild();
71 m_remainingChildren
&= ~NormalFlowChildren
;
74 if (m_remainingChildren
& PositiveZOrderChildren
) {
75 Vector
<DeprecatedPaintLayerStackingNode
*>* posZOrderList
= m_root
.posZOrderList();
76 if (posZOrderList
&& m_index
< posZOrderList
->size())
77 return posZOrderList
->at(m_index
++);
80 m_remainingChildren
&= ~PositiveZOrderChildren
;
86 DeprecatedPaintLayerStackingNode
* DeprecatedPaintLayerStackingNodeReverseIterator::next()
88 if (m_remainingChildren
& NegativeZOrderChildren
) {
89 Vector
<DeprecatedPaintLayerStackingNode
*>* negZOrderList
= m_root
.negZOrderList();
90 if (negZOrderList
&& m_index
>= 0)
91 return negZOrderList
->at(m_index
--);
93 m_remainingChildren
&= ~NegativeZOrderChildren
;
97 if (m_remainingChildren
& NormalFlowChildren
) {
98 for (; m_currentNormalFlowChild
; m_currentNormalFlowChild
= m_currentNormalFlowChild
->previousSibling()) {
99 if (!m_currentNormalFlowChild
->stackingNode()->isTreatedAsOrStackingContext() && !m_currentNormalFlowChild
->isReflection()) {
100 DeprecatedPaintLayer
* normalFlowChild
= m_currentNormalFlowChild
;
101 m_currentNormalFlowChild
= m_currentNormalFlowChild
->previousSibling();
102 return normalFlowChild
->stackingNode();
106 m_remainingChildren
&= ~NormalFlowChildren
;
107 setIndexToLastItem();
110 if (m_remainingChildren
& PositiveZOrderChildren
) {
111 Vector
<DeprecatedPaintLayerStackingNode
*>* posZOrderList
= m_root
.posZOrderList();
112 if (posZOrderList
&& m_index
>= 0)
113 return posZOrderList
->at(m_index
--);
115 m_remainingChildren
&= ~PositiveZOrderChildren
;
116 setIndexToLastItem();
122 void DeprecatedPaintLayerStackingNodeReverseIterator::setIndexToLastItem()
124 if (m_remainingChildren
& NegativeZOrderChildren
) {
125 Vector
<DeprecatedPaintLayerStackingNode
*>* negZOrderList
= m_root
.negZOrderList();
127 m_index
= negZOrderList
->size() - 1;
131 m_remainingChildren
&= ~NegativeZOrderChildren
;
134 if (m_remainingChildren
& NormalFlowChildren
) {
135 m_currentNormalFlowChild
= m_root
.layer()->lastChild();
139 if (m_remainingChildren
& PositiveZOrderChildren
) {
140 Vector
<DeprecatedPaintLayerStackingNode
*>* posZOrderList
= m_root
.posZOrderList();
142 m_index
= posZOrderList
->size() - 1;
146 m_remainingChildren
&= ~PositiveZOrderChildren
;
149 // No more list to visit.
150 ASSERT(!m_remainingChildren
);