2 * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Intel Corporation. All rights reserved.
5 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
8 * Robert O'Callahan <roc+@cs.cmu.edu>
9 * David Baron <dbaron@fas.harvard.edu>
10 * Christian Biesinger <cbiesinger@web.de>
11 * Randall Jesup <rjesup@wgate.com>
12 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
13 * Josh Soref <timeless@mac.com>
14 * Boris Zbarsky <bzbarsky@mit.edu>
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 * Alternatively, the contents of this file may be used under the terms
31 * of either the Mozilla Public License Version 1.1, found at
32 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
33 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
34 * (the "GPL"), in which case the provisions of the MPL or the GPL are
35 * applicable instead of those above. If you wish to allow use of your
36 * version of this file only under the terms of one of those two
37 * licenses (the MPL or the GPL) and not to allow others to use your
38 * version of this file under the LGPL, indicate your decision by
39 * deletingthe provisions above and replace them with the notice and
40 * other provisions required by the MPL or the GPL, as the case may be.
41 * If you do not delete the provisions above, a recipient may use your
42 * version of this file under any of the LGPL, the MPL or the GPL.
45 #ifndef RenderLayerStackingNode_h
46 #define RenderLayerStackingNode_h
48 #include "core/rendering/RenderLayerModelObject.h"
49 #include "wtf/Noncopyable.h"
50 #include "wtf/OwnPtr.h"
51 #include "wtf/Vector.h"
56 class RenderLayerCompositor;
59 class RenderLayerStackingNode {
60 WTF_MAKE_NONCOPYABLE(RenderLayerStackingNode);
62 explicit RenderLayerStackingNode(RenderLayer*);
63 ~RenderLayerStackingNode();
65 int zIndex() const { return renderer()->style()->zIndex(); }
67 // A stacking context is a layer that has a non-auto z-index.
68 bool isStackingContext() const { return !renderer()->style()->hasAutoZIndex(); }
70 // Update our normal and z-index lists.
71 void updateLayerListsIfNeeded();
73 bool zOrderListsDirty() const { return m_zOrderListsDirty; }
74 void dirtyZOrderLists();
75 void updateZOrderLists();
76 void clearZOrderLists();
77 void dirtyStackingContextZOrderLists();
79 bool hasPositiveZOrderList() const { return posZOrderList() && posZOrderList()->size(); }
80 bool hasNegativeZOrderList() const { return negZOrderList() && negZOrderList()->size(); }
82 // FIXME: should check for dirtiness here?
83 bool isNormalFlowOnly() const { return m_isNormalFlowOnly; }
84 void updateIsNormalFlowOnly();
85 bool normalFlowListDirty() const { return m_normalFlowListDirty; }
86 void dirtyNormalFlowList();
88 void updateStackingNodesAfterStyleChange(const RenderStyle* oldStyle);
90 RenderLayerStackingNode* ancestorStackingContextNode() const;
92 RenderLayer* layer() const { return m_layer; }
95 bool layerListMutationAllowed() const { return m_layerListMutationAllowed; }
96 void setLayerListMutationAllowed(bool flag) { m_layerListMutationAllowed = flag; }
100 friend class RenderLayerStackingNodeIterator;
101 friend class RenderLayerStackingNodeReverseIterator;
102 friend class RenderTreeAsText;
104 Vector<RenderLayerStackingNode*>* posZOrderList() const
106 ASSERT(!m_zOrderListsDirty);
107 ASSERT(isStackingContext() || !m_posZOrderList);
108 return m_posZOrderList.get();
111 Vector<RenderLayerStackingNode*>* normalFlowList() const
113 ASSERT(!m_normalFlowListDirty);
114 return m_normalFlowList.get();
117 Vector<RenderLayerStackingNode*>* negZOrderList() const
119 ASSERT(!m_zOrderListsDirty);
120 ASSERT(isStackingContext() || !m_negZOrderList);
121 return m_negZOrderList.get();
124 void rebuildZOrderLists();
125 void collectLayers(OwnPtr<Vector<RenderLayerStackingNode*> >& posZOrderList, OwnPtr<Vector<RenderLayerStackingNode*> >& negZOrderList);
128 bool isInStackingParentZOrderLists() const;
129 bool isInStackingParentNormalFlowList() const;
130 void updateStackingParentForZOrderLists(RenderLayerStackingNode* stackingParent);
131 void updateStackingParentForNormalFlowList(RenderLayerStackingNode* stackingParent);
132 void setStackingParent(RenderLayerStackingNode* stackingParent) { m_stackingParent = stackingParent; }
135 bool shouldBeNormalFlowOnly() const;
137 void updateNormalFlowList();
139 bool isDirtyStackingContext() const { return m_zOrderListsDirty && isStackingContext(); }
141 RenderLayerCompositor* compositor() const;
142 // FIXME: Investigate changing this to Renderbox.
143 RenderLayerModelObject* renderer() const;
145 RenderLayer* m_layer;
147 // m_posZOrderList holds a sorted list of all the descendant nodes within
148 // that have z-indices of 0 or greater (auto will count as 0).
149 // m_negZOrderList holds descendants within our stacking context with
150 // negative z-indices.
151 OwnPtr<Vector<RenderLayerStackingNode*> > m_posZOrderList;
152 OwnPtr<Vector<RenderLayerStackingNode*> > m_negZOrderList;
154 // This list contains child nodes that cannot create stacking contexts.
155 OwnPtr<Vector<RenderLayerStackingNode*> > m_normalFlowList;
157 unsigned m_zOrderListsDirty : 1;
158 unsigned m_normalFlowListDirty: 1;
159 unsigned m_isNormalFlowOnly : 1;
162 unsigned m_layerListMutationAllowed : 1;
163 RenderLayerStackingNode* m_stackingParent;
167 inline void RenderLayerStackingNode::clearZOrderLists()
169 ASSERT(!isStackingContext());
172 updateStackingParentForZOrderLists(0);
175 m_posZOrderList.clear();
176 m_negZOrderList.clear();
179 inline void RenderLayerStackingNode::updateZOrderLists()
181 if (!m_zOrderListsDirty)
184 if (!isStackingContext()) {
186 m_zOrderListsDirty = false;
190 rebuildZOrderLists();
194 class LayerListMutationDetector {
196 explicit LayerListMutationDetector(RenderLayerStackingNode* stackingNode)
197 : m_stackingNode(stackingNode)
198 , m_previousMutationAllowedState(stackingNode->layerListMutationAllowed())
200 m_stackingNode->setLayerListMutationAllowed(false);
203 ~LayerListMutationDetector()
205 m_stackingNode->setLayerListMutationAllowed(m_previousMutationAllowedState);
209 RenderLayerStackingNode* m_stackingNode;
210 bool m_previousMutationAllowedState;
216 #endif // RenderLayerStackingNode_h