| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights
reserved. |
| 3 * | 3 * |
| 4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. | 4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. |
| 5 * | 5 * |
| 6 * Other contributors: | 6 * Other contributors: |
| 7 * Robert O'Callahan <roc+@cs.cmu.edu> | 7 * Robert O'Callahan <roc+@cs.cmu.edu> |
| 8 * David Baron <dbaron@fas.harvard.edu> | 8 * David Baron <dbaron@fas.harvard.edu> |
| 9 * Christian Biesinger <cbiesinger@web.de> | 9 * Christian Biesinger <cbiesinger@web.de> |
| 10 * Randall Jesup <rjesup@wgate.com> | 10 * Randall Jesup <rjesup@wgate.com> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 * version of this file under the LGPL, indicate your decision by | 37 * version of this file under the LGPL, indicate your decision by |
| 38 * deletingthe provisions above and replace them with the notice and | 38 * deletingthe provisions above and replace them with the notice and |
| 39 * other provisions required by the MPL or the GPL, as the case may be. | 39 * other provisions required by the MPL or the GPL, as the case may be. |
| 40 * If you do not delete the provisions above, a recipient may use your | 40 * If you do not delete the provisions above, a recipient may use your |
| 41 * version of this file under any of the LGPL, the MPL or the GPL. | 41 * version of this file under any of the LGPL, the MPL or the GPL. |
| 42 */ | 42 */ |
| 43 | 43 |
| 44 #include "config.h" | 44 #include "config.h" |
| 45 #include "core/paint/DeprecatedPaintLayerStackingNode.h" | 45 #include "core/paint/DeprecatedPaintLayerStackingNode.h" |
| 46 | 46 |
| 47 #include "core/dom/Node.h" | |
| 48 #include "core/layout/LayoutView.h" | 47 #include "core/layout/LayoutView.h" |
| 49 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h" | 48 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h" |
| 50 #include "core/paint/DeprecatedPaintLayer.h" | 49 #include "core/paint/DeprecatedPaintLayer.h" |
| 51 #include "public/platform/Platform.h" | 50 #include "public/platform/Platform.h" |
| 52 | 51 |
| 53 namespace blink { | 52 namespace blink { |
| 54 | 53 |
| 55 // FIXME: This should not require DeprecatedPaintLayer. There is currently a cyc
le where | 54 // FIXME: This should not require DeprecatedPaintLayer. There is currently a cyc
le where |
| 56 // in order to determine if we shoulBeTreatedAsStackingContext() we have to ask
the paint | 55 // in order to determine if we shoulBeTreatedAsStackingContext() we have to ask
the paint |
| 57 // layer about some of its state. | 56 // layer about some of its state. |
| 58 DeprecatedPaintLayerStackingNode::DeprecatedPaintLayerStackingNode(LayoutBoxMode
lObject& layoutObject) | 57 DeprecatedPaintLayerStackingNode::DeprecatedPaintLayerStackingNode(DeprecatedPai
ntLayer* layer) |
| 59 : m_layoutObject(layoutObject) | 58 : m_layer(layer) |
| 60 #if ENABLE(ASSERT) | 59 #if ENABLE(ASSERT) |
| 61 , m_layerListMutationAllowed(true) | 60 , m_layerListMutationAllowed(true) |
| 62 , m_stackingParent(0) | 61 , m_stackingParent(0) |
| 63 #endif | 62 #endif |
| 64 { | 63 { |
| 65 m_isTreatedAsOrStackingContext = shouldBeTreatedAsOrStackingContext(); | 64 m_isTreatedAsOrStackingContext = shouldBeTreatedAsOrStackingContext(); |
| 66 | 65 |
| 67 // Non-stacking contexts should have empty z-order lists. As this is already
the case, | 66 // Non-stacking contexts should have empty z-order lists. As this is already
the case, |
| 68 // there is no need to dirty / recompute these lists. | 67 // there is no need to dirty / recompute these lists. |
| 69 m_zOrderListsDirty = isStackingContext(); | 68 m_zOrderListsDirty = isStackingContext(); |
| 70 } | 69 } |
| 71 | 70 |
| 72 DeprecatedPaintLayerStackingNode::~DeprecatedPaintLayerStackingNode() | 71 DeprecatedPaintLayerStackingNode::~DeprecatedPaintLayerStackingNode() |
| 73 { | 72 { |
| 74 #if ENABLE(ASSERT) | 73 #if ENABLE(ASSERT) |
| 75 if (!layoutObject().documentBeingDestroyed()) { | 74 if (!layoutObject()->documentBeingDestroyed()) { |
| 76 ASSERT(!isInStackingParentZOrderLists()); | 75 ASSERT(!isInStackingParentZOrderLists()); |
| 77 | 76 |
| 78 updateStackingParentForZOrderLists(0); | 77 updateStackingParentForZOrderLists(0); |
| 79 } | 78 } |
| 80 #endif | 79 #endif |
| 81 } | 80 } |
| 82 | 81 |
| 83 // Helper for the sorting of layers by z-index. | 82 // Helper for the sorting of layers by z-index. |
| 84 static inline bool compareZIndex(DeprecatedPaintLayerStackingNode* first, Deprec
atedPaintLayerStackingNode* second) | 83 static inline bool compareZIndex(DeprecatedPaintLayerStackingNode* first, Deprec
atedPaintLayerStackingNode* second) |
| 85 { | 84 { |
| 86 return first->zIndex() < second->zIndex(); | 85 return first->zIndex() < second->zIndex(); |
| 87 } | 86 } |
| 88 | 87 |
| 89 DeprecatedPaintLayerCompositor* DeprecatedPaintLayerStackingNode::compositor() c
onst | 88 DeprecatedPaintLayerCompositor* DeprecatedPaintLayerStackingNode::compositor() c
onst |
| 90 { | 89 { |
| 91 ASSERT(layoutObject().view()); | 90 ASSERT(layoutObject()->view()); |
| 92 return layoutObject().view()->compositor(); | 91 return layoutObject()->view()->compositor(); |
| 93 } | 92 } |
| 94 | 93 |
| 95 void DeprecatedPaintLayerStackingNode::dirtyZOrderLists() | 94 void DeprecatedPaintLayerStackingNode::dirtyZOrderLists() |
| 96 { | 95 { |
| 97 ASSERT(m_layerListMutationAllowed); | 96 ASSERT(m_layerListMutationAllowed); |
| 98 ASSERT(isStackingContext()); | 97 ASSERT(isStackingContext()); |
| 99 | 98 |
| 100 #if ENABLE(ASSERT) | 99 #if ENABLE(ASSERT) |
| 101 updateStackingParentForZOrderLists(0); | 100 updateStackingParentForZOrderLists(0); |
| 102 #endif | 101 #endif |
| 103 | 102 |
| 104 if (m_posZOrderList) | 103 if (m_posZOrderList) |
| 105 m_posZOrderList->clear(); | 104 m_posZOrderList->clear(); |
| 106 if (m_negZOrderList) | 105 if (m_negZOrderList) |
| 107 m_negZOrderList->clear(); | 106 m_negZOrderList->clear(); |
| 108 m_zOrderListsDirty = true; | 107 m_zOrderListsDirty = true; |
| 109 | 108 |
| 110 if (!layoutObject().documentBeingDestroyed()) | 109 if (!layoutObject()->documentBeingDestroyed()) |
| 111 compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); | 110 compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); |
| 112 } | 111 } |
| 113 | 112 |
| 114 void DeprecatedPaintLayerStackingNode::dirtyStackingContextZOrderLists() | 113 void DeprecatedPaintLayerStackingNode::dirtyStackingContextZOrderLists() |
| 115 { | 114 { |
| 116 if (DeprecatedPaintLayerStackingNode* stackingNode = ancestorStackingContext
Node()) | 115 if (DeprecatedPaintLayerStackingNode* stackingNode = ancestorStackingContext
Node()) |
| 117 stackingNode->dirtyZOrderLists(); | 116 stackingNode->dirtyZOrderLists(); |
| 118 } | 117 } |
| 119 | 118 |
| 120 static bool isInTopLayer(const LayoutObject& layoutObject) | |
| 121 { | |
| 122 const Node* node = layoutObject.node(); | |
| 123 return node && node->isElementNode() && toElement(node)->isInTopLayer(); | |
| 124 } | |
| 125 | |
| 126 void DeprecatedPaintLayerStackingNode::rebuildZOrderLists() | 119 void DeprecatedPaintLayerStackingNode::rebuildZOrderLists() |
| 127 { | 120 { |
| 128 ASSERT(m_layerListMutationAllowed); | 121 ASSERT(m_layerListMutationAllowed); |
| 129 ASSERT(isDirtyStackingContext()); | 122 ASSERT(isDirtyStackingContext()); |
| 130 | 123 |
| 131 for (LayoutObject* descendant = layoutObject().slowFirstChild(); descendant;
) { | 124 for (DeprecatedPaintLayer* child = layer()->firstChild(); child; child = chi
ld->nextSibling()) { |
| 132 if (isInTopLayer(*descendant)) { | 125 if (!layer()->reflectionInfo() || layer()->reflectionInfo()->reflectionL
ayer() != child) |
| 133 // Top layer objects are handled below. | 126 child->stackingNode()->collectLayers(m_posZOrderList, m_negZOrderLis
t); |
| 134 descendant = descendant->nextInPreOrderAfterChildren(&layoutObject()
); | |
| 135 continue; | |
| 136 } | |
| 137 | |
| 138 // FIXME: Some non-LayoutBoxModeObject can have position != static and t
hus would be treated like | |
| 139 // stacking context. However we can't store them in the lists unless the
y have a DeprecatedPaintLayer. | |
| 140 if (descendant->styleRef().isTreatedAsOrStackingContext() && descendant-
>hasLayer()) { | |
| 141 OwnPtr<Vector<DeprecatedPaintLayerStackingNode*>>& buffer = (descend
ant->style()->zIndex() >= 0) ? m_posZOrderList : m_negZOrderList; | |
| 142 if (!buffer) | |
| 143 buffer = adoptPtr(new Vector<DeprecatedPaintLayerStackingNode*>)
; | |
| 144 buffer->append(toLayoutBoxModelObject(descendant)->layer()->stacking
Node()); | |
| 145 } | |
| 146 | |
| 147 if (descendant->styleRef().isStackingContext()) { | |
| 148 // We found a stacking context, just continue walking the other subt
rees. | |
| 149 // They will collect their own descendant stacking contexts. | |
| 150 descendant = descendant->nextInPreOrderAfterChildren(&layoutObject()
); | |
| 151 } else { | |
| 152 // Not stacking context, continue deeper. | |
| 153 descendant = descendant->nextInPreOrder(&layoutObject()); | |
| 154 } | |
| 155 } | 127 } |
| 156 | 128 |
| 157 // Sort the two lists. | 129 // Sort the two lists. |
| 158 if (m_posZOrderList) | 130 if (m_posZOrderList) |
| 159 std::stable_sort(m_posZOrderList->begin(), m_posZOrderList->end(), compa
reZIndex); | 131 std::stable_sort(m_posZOrderList->begin(), m_posZOrderList->end(), compa
reZIndex); |
| 160 | 132 |
| 161 if (m_negZOrderList) | 133 if (m_negZOrderList) |
| 162 std::stable_sort(m_negZOrderList->begin(), m_negZOrderList->end(), compa
reZIndex); | 134 std::stable_sort(m_negZOrderList->begin(), m_negZOrderList->end(), compa
reZIndex); |
| 163 | 135 |
| 164 // Append stacking contexts for top layer elements after normal layer collec
tion, to ensure they are on top regardless of z-indexes. | 136 // Append layers for top layer elements after normal layer collection, to en
sure they are on top regardless of z-indexes. |
| 165 // The layoutObjects of top layer elements are children of the view, sorted
in top layer stacking order. | 137 // The layoutObjects of top layer elements are children of the view, sorted
in top layer stacking order. |
| 166 if (layoutObject().isLayoutView()) { | 138 if (layer()->isRootLayer()) { |
| 167 LayoutView& view = toLayoutView(layoutObject()); | 139 LayoutView* view = layoutObject()->view(); |
| 168 for (LayoutObject* child = view.firstChild(); child; child = child->next
Sibling()) { | 140 for (LayoutObject* child = view->firstChild(); child; child = child->nex
tSibling()) { |
| 169 if (!isInTopLayer(*child)) | 141 Element* childElement = (child->node() && child->node()->isElementNo
de()) ? toElement(child->node()) : 0; |
| 170 continue; | 142 if (childElement && childElement->isInTopLayer()) { |
| 171 | 143 DeprecatedPaintLayer* layer = toLayoutBoxModelObject(child)->lay
er(); |
| 172 // Create the buffer if it doesn't exist yet. | 144 // Create the buffer if it doesn't exist yet. |
| 173 if (!m_posZOrderList) | 145 if (!m_posZOrderList) |
| 174 m_posZOrderList = adoptPtr(new Vector<DeprecatedPaintLayerStacki
ngNode*>); | 146 m_posZOrderList = adoptPtr(new Vector<DeprecatedPaintLayerSt
ackingNode*>); |
| 175 ASSERT(child->style()->isStackingContext()); | 147 m_posZOrderList->append(layer->stackingNode()); |
| 176 m_posZOrderList->append(toLayoutBoxModelObject(child)->layer()->stac
kingNode()); | 148 } |
| 177 } | 149 } |
| 178 } | 150 } |
| 179 | 151 |
| 180 #if ENABLE(ASSERT) | 152 #if ENABLE(ASSERT) |
| 181 updateStackingParentForZOrderLists(this); | 153 updateStackingParentForZOrderLists(this); |
| 182 #endif | 154 #endif |
| 183 | 155 |
| 184 m_zOrderListsDirty = false; | 156 m_zOrderListsDirty = false; |
| 185 } | 157 } |
| 186 | 158 |
| 159 void DeprecatedPaintLayerStackingNode::collectLayers(OwnPtr<Vector<DeprecatedPai
ntLayerStackingNode*>>& posBuffer, OwnPtr<Vector<DeprecatedPaintLayerStackingNod
e*>>& negBuffer) |
| 160 { |
| 161 if (layer()->isInTopLayer()) |
| 162 return; |
| 163 |
| 164 if (isTreatedAsOrStackingContext()) { |
| 165 OwnPtr<Vector<DeprecatedPaintLayerStackingNode*>>& buffer = (zIndex() >=
0) ? posBuffer : negBuffer; |
| 166 if (!buffer) |
| 167 buffer = adoptPtr(new Vector<DeprecatedPaintLayerStackingNode*>); |
| 168 buffer->append(this); |
| 169 } |
| 170 |
| 171 if (!isStackingContext()) { |
| 172 for (DeprecatedPaintLayer* child = layer()->firstChild(); child; child =
child->nextSibling()) { |
| 173 if (!layer()->reflectionInfo() || layer()->reflectionInfo()->reflect
ionLayer() != child) |
| 174 child->stackingNode()->collectLayers(posBuffer, negBuffer); |
| 175 } |
| 176 } |
| 177 } |
| 178 |
| 187 #if ENABLE(ASSERT) | 179 #if ENABLE(ASSERT) |
| 188 bool DeprecatedPaintLayerStackingNode::isInStackingParentZOrderLists() const | 180 bool DeprecatedPaintLayerStackingNode::isInStackingParentZOrderLists() const |
| 189 { | 181 { |
| 190 if (!m_stackingParent || m_stackingParent->zOrderListsDirty()) | 182 if (!m_stackingParent || m_stackingParent->zOrderListsDirty()) |
| 191 return false; | 183 return false; |
| 192 | 184 |
| 193 if (m_stackingParent->posZOrderList() && m_stackingParent->posZOrderList()->
find(this) != kNotFound) | 185 if (m_stackingParent->posZOrderList() && m_stackingParent->posZOrderList()->
find(this) != kNotFound) |
| 194 return true; | 186 return true; |
| 195 | 187 |
| 196 if (m_stackingParent->negZOrderList() && m_stackingParent->negZOrderList()->
find(this) != kNotFound) | 188 if (m_stackingParent->negZOrderList() && m_stackingParent->negZOrderList()->
find(this) != kNotFound) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 clearZOrderLists(); | 234 clearZOrderLists(); |
| 243 } | 235 } |
| 244 | 236 |
| 245 void DeprecatedPaintLayerStackingNode::updateIsTreatedAsStackingContext() | 237 void DeprecatedPaintLayerStackingNode::updateIsTreatedAsStackingContext() |
| 246 { | 238 { |
| 247 bool isTreatedAsOrStackingContext = shouldBeTreatedAsOrStackingContext(); | 239 bool isTreatedAsOrStackingContext = shouldBeTreatedAsOrStackingContext(); |
| 248 if (isTreatedAsOrStackingContext == this->isTreatedAsOrStackingContext()) | 240 if (isTreatedAsOrStackingContext == this->isTreatedAsOrStackingContext()) |
| 249 return; | 241 return; |
| 250 | 242 |
| 251 m_isTreatedAsOrStackingContext = isTreatedAsOrStackingContext; | 243 m_isTreatedAsOrStackingContext = isTreatedAsOrStackingContext; |
| 252 if (!layoutObject().documentBeingDestroyed() && !layer()->isRootLayer()) | 244 if (!layoutObject()->documentBeingDestroyed() && !layer()->isRootLayer()) |
| 253 compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); | 245 compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); |
| 254 dirtyStackingContextZOrderLists(); | 246 dirtyStackingContextZOrderLists(); |
| 255 } | 247 } |
| 256 | 248 |
| 257 DeprecatedPaintLayerStackingNode* DeprecatedPaintLayerStackingNode::ancestorStac
kingContextNode() const | 249 DeprecatedPaintLayerStackingNode* DeprecatedPaintLayerStackingNode::ancestorStac
kingContextNode() const |
| 258 { | 250 { |
| 259 for (DeprecatedPaintLayer* ancestor = layer()->parent(); ancestor; ancestor
= ancestor->parent()) { | 251 for (DeprecatedPaintLayer* ancestor = layer()->parent(); ancestor; ancestor
= ancestor->parent()) { |
| 260 DeprecatedPaintLayerStackingNode* stackingNode = ancestor->stackingNode(
); | 252 DeprecatedPaintLayerStackingNode* stackingNode = ancestor->stackingNode(
); |
| 261 if (stackingNode->isStackingContext()) | 253 if (stackingNode->isStackingContext()) |
| 262 return stackingNode; | 254 return stackingNode; |
| 263 } | 255 } |
| 264 return 0; | 256 return 0; |
| 265 } | 257 } |
| 266 | 258 |
| 267 DeprecatedPaintLayer* DeprecatedPaintLayerStackingNode::layer() const | 259 LayoutBoxModelObject* DeprecatedPaintLayerStackingNode::layoutObject() const |
| 268 { | 260 { |
| 269 return layoutObject().layer(); | 261 return m_layer->layoutObject(); |
| 270 } | 262 } |
| 271 | 263 |
| 272 } // namespace blink | 264 } // namespace blink |
| OLD | NEW |