Index: Source/core/rendering/RenderLayer.cpp |
diff --git a/Source/core/rendering/RenderLayer.cpp b/Source/core/rendering/RenderLayer.cpp |
index d17c3ed20d8c45fd5551d880393891d6db1df4b9..c5a6424ce9268a42e6c28d08f3a222be3e70b52d 100644 |
--- a/Source/core/rendering/RenderLayer.cpp |
+++ b/Source/core/rendering/RenderLayer.cpp |
@@ -100,6 +100,7 @@ |
#include "Settings.h" |
#include "ShadowRoot.h" |
#include "SourceGraphic.h" |
+#include "StaticHashSetNodeList.h" |
#include "StylePropertySet.h" |
#include "StyleResolver.h" |
#include "TextStream.h" |
@@ -639,6 +640,274 @@ void RenderLayer::updateDescendantsAreContiguousInStackingOrderRecursive(const H |
} |
} |
+static inline bool isPositionedContainer(const RenderLayer* layer) |
+{ |
+ // FIXME: This is not in sync with containingBlock. |
+ // RenderObject::canContainFixedPositionedObject() should probably be used |
+ // instead. |
+ RenderLayerModelObject* layerRenderer = layer->renderer(); |
+ return layer->isRootLayer() || layerRenderer->isPositioned() || layer->hasTransform(); |
+} |
+ |
+enum StackingOrderDirection { FromBackground, FromForeground }; |
+ |
+// We'd like to be able to iterate through a single paint order list, but for |
+// efficiency's sake, we hang onto two lists instead (namely, the pos and neg |
+// z-order lists produced by CollectLayers). This function allows us to index |
+// into these two lists as if they were one. It also allows us to index into |
+// this virtual list either from the start or from the end (i.e., in either |
+// stacking order direction). |
+static const RenderLayer* getStackingOrderElementAt(const Vector<RenderLayer*>* posZOrderList, const Vector<RenderLayer*>* negZOrderList, const StackingOrderDirection direction, const size_t index) |
+{ |
+ size_t negZOrderListSize = negZOrderList ? negZOrderList->size() : 0; |
+ |
+ if (direction == FromBackground) { |
+ if (index < negZOrderListSize) |
+ return negZOrderList->at(index); |
+ |
+ return posZOrderList->at(index - negZOrderListSize); |
+ } |
+ |
+ size_t posZOrderListSize = posZOrderList ? posZOrderList->size() : 0; |
+ |
+ if (index < posZOrderListSize) |
+ return posZOrderList->at(posZOrderListSize - index - 1); |
+ |
+ return negZOrderList->at(negZOrderListSize - (index - posZOrderListSize) - 1); |
+} |
+ |
+// Compute what positive and negative z-order lists would look like before and |
+// after promotion, so we can later ensure that proper stacking order is |
+// preserved between the two sets of lists. |
+// |
+// A few examples: |
+// c = currentLayer |
+// - = negative z-order child of currentLayer |
+// + = positive z-order child of currentLayer |
+// a = positioned ancestor of currentLayer |
+// x = any other RenderLayer in the list |
+// |
+// (a) xxxxx-----++a+++x |
+// (b) xxx-----c++++++xx |
+// |
+// |
+// Normally the current layer would be painted in the normal flow list if it |
+// doesn't already appear in the positive z-order list. However, in the case |
+// that the layer has a positioned ancestor, it will paint directly after the |
+// positioned ancestor. In example (a), the current layer would be painted in |
+// the middle of its own positive z-order children, so promoting would cause a |
+// change in paint order (since a promoted layer will paint all of its positive |
+// z-order children strictly after it paints itself). |
+// |
+// In example (b), it is ok to promote the current layer only if it does not |
+// have a background. If it has a background, the background gets painted before |
+// the layer's negative z-order children, so again, a promotion would cause a |
+// change in paint order (causing the background to get painted after the |
+// negative z-order children instead of before). |
+void RenderLayer::collectBeforePromotionZOrderList( |
Julien - ping for review
2013/04/22 21:49:30
Some of the line breaking are *really* weird (like
hartmanng
2013/04/23 21:32:37
Done.
|
+ RenderLayer* ancestorStackingContext, |
+ OwnPtr<Vector<RenderLayer*> >& posZOrderListBeforePromote, |
+ OwnPtr<Vector<RenderLayer*> >& negZOrderListBeforePromote) |
+{ |
+ // We can't use TemporaryChange<> here since m_needsCompositedScrolling and |
+ // m_isNormalFlowOnly are both bitfields, so we have to do it the |
+ // old-fashioned way. |
+ bool oldNeedsCompositedScrolling = m_needsCompositedScrolling; |
+ bool oldIsNormalFlowOnly = m_isNormalFlowOnly; |
+ |
+ // Set the flag on the current layer, then rebuild ancestor stacking |
+ // context's lists. This way, we can see the exact effects that promoting |
+ // this layer would cause. |
+ m_needsCompositedScrolling = false; |
+ m_isNormalFlowOnly = shouldBeNormalFlowOnly(); |
+ ancestorStackingContext->rebuildZOrderLists(StopAtStackingContexts, posZOrderListBeforePromote, negZOrderListBeforePromote, 0); |
+ |
+ m_needsCompositedScrolling = oldNeedsCompositedScrolling; |
+ m_isNormalFlowOnly = oldIsNormalFlowOnly; |
+ |
+ |
+ size_t posZOrderListSizeBeforePromote = posZOrderListBeforePromote ? posZOrderListBeforePromote->size() : 0; |
+ |
+ const RenderLayer* positionedAncestor = parent(); |
+ while (positionedAncestor && !isPositionedContainer(positionedAncestor) && !positionedAncestor->isStackingContext()) |
+ positionedAncestor = positionedAncestor->parent(); |
+ if (positionedAncestor && (!isPositionedContainer(positionedAncestor) || positionedAncestor->isStackingContext())) |
+ positionedAncestor = 0; |
+ |
+ bool currentLayerIsInPosZOrderListBeforePromote = false; |
+ |
+ for (size_t index = 0; index < posZOrderListSizeBeforePromote; index++) { |
+ if (posZOrderListBeforePromote->at(index) == this) { |
+ currentLayerIsInPosZOrderListBeforePromote = true; |
+ break; |
+ } |
+ } |
+ |
+ // Insert this into the posZOrderistBeforePromote directly after the |
+ // positioned ancestor, if there is one. Otherwise, add it to the very |
+ // beginning. |
+ // |
+ // The current layer will appear in the z-order lists after promotion, so |
+ // for a meaningful comparison, we must insert it in the z-order lists |
+ // before promotion if it does not appear there already. |
+ if (!currentLayerIsInPosZOrderListBeforePromote) { |
+ if (!positionedAncestor) { |
+ if (!posZOrderListBeforePromote) |
+ posZOrderListBeforePromote = adoptPtr(new Vector<RenderLayer*>()); |
+ |
+ posZOrderListBeforePromote->prepend(this); |
+ posZOrderListSizeBeforePromote++; |
+ } else { |
+ for (size_t index = 0; index < posZOrderListSizeBeforePromote; index++) { |
+ if (posZOrderListBeforePromote->at(index) == positionedAncestor) { |
+ posZOrderListBeforePromote->insert(index + 1, this); |
+ posZOrderListSizeBeforePromote++; |
+ break; |
+ } |
+ } |
+ } |
+ } |
+} |
+ |
+void RenderLayer::collectAfterPromotionZOrderList( |
+ RenderLayer* ancestorStackingContext, |
+ OwnPtr<Vector<RenderLayer*> >& posZOrderListAfterPromote, |
+ OwnPtr<Vector<RenderLayer*> >& negZOrderListAfterPromote) |
+{ |
+ // We can't use TemporaryChange<> here since m_needsCompositedScrolling and |
+ // m_isNormalFlowOnly are both bitfields, so we have to do it the |
+ // old-fashioned way. |
+ bool oldNeedsCompositedScrolling = m_needsCompositedScrolling; |
+ bool oldIsNormalFlowOnly = m_isNormalFlowOnly; |
+ |
+ // Set the flag on the current layer, then rebuild ancestor stacking |
+ // context's lists. This way, we can see the exact effects that promoting |
+ // this layer would cause. |
+ m_isNormalFlowOnly = false; |
+ m_needsCompositedScrolling = true; |
+ ancestorStackingContext->rebuildZOrderLists(StopAtStackingContexts, posZOrderListAfterPromote, negZOrderListAfterPromote, this); |
+ |
+ m_needsCompositedScrolling = oldNeedsCompositedScrolling; |
+ m_isNormalFlowOnly = oldIsNormalFlowOnly; |
+} |
+ |
+#ifndef NDEBUG |
+String RenderLayer::paintOrderListsAsText() |
+{ |
+ OwnPtr<Vector<RenderLayer*> > posZOrderListBeforePromote; |
+ OwnPtr<Vector<RenderLayer*> > negZOrderListBeforePromote; |
+ OwnPtr<Vector<RenderLayer*> > posZOrderListAfterPromote; |
+ OwnPtr<Vector<RenderLayer*> > negZOrderListAfterPromote; |
+ |
+ RenderLayer* ancestorStackingContext = this; |
+ |
+ while (ancestorStackingContext) { |
+ if (ancestorStackingContext != this && ancestorStackingContext->isStackingContext()) |
Julien - ping for review
2013/04/22 21:49:30
The 'ancestorStackingContext != this' check is art
hartmanng
2013/04/23 21:32:37
Done.
|
+ break; |
+ ancestorStackingContext = ancestorStackingContext->parent(); |
+ } |
Julien - ping for review
2013/04/22 21:49:30
This should be in its own function really as it is
hartmanng
2013/04/23 21:32:37
Done.
|
+ |
+ if (!ancestorStackingContext) |
+ return String(); |
+ |
+ collectBeforePromotionZOrderList(ancestorStackingContext, posZOrderListBeforePromote, negZOrderListBeforePromote); |
+ collectAfterPromotionZOrderList(ancestorStackingContext, posZOrderListAfterPromote, negZOrderListAfterPromote); |
Julien - ping for review
2013/04/22 21:49:30
The code duplication makes me sad. It seems that i
hartmanng
2013/04/23 21:32:37
I'm not sure I understand your suggestion.
collec
|
+ |
+ size_t posZOrderListSizeBeforePromote = posZOrderListBeforePromote ? posZOrderListBeforePromote->size() : 0; |
+ size_t negZOrderListSizeBeforePromote = negZOrderListBeforePromote ? negZOrderListBeforePromote->size() : 0; |
+ size_t posZOrderListSizeAfterPromote = posZOrderListAfterPromote ? posZOrderListAfterPromote->size() : 0; |
+ size_t negZOrderListSizeAfterPromote = negZOrderListAfterPromote ? negZOrderListAfterPromote->size() : 0; |
+ |
+ size_t sizeBeforePromote = posZOrderListSizeBeforePromote + negZOrderListSizeBeforePromote; |
+ size_t sizeAfterPromote = posZOrderListSizeAfterPromote + negZOrderListSizeAfterPromote; |
+ |
+ TextStream ts; |
+ |
+ ts << "Layer: " << this << " \"" << debugName() << "\", z-index: " << renderer()->style()->zIndex() << "\n"; |
+ |
+ ts << " stacking context's paint order list BEFORE promote:\n"; |
+ for (size_t index = 0; index < sizeBeforePromote; index++) { |
+ const RenderLayer* layerBeforePromote = getStackingOrderElementAt(posZOrderListBeforePromote.get(), negZOrderListBeforePromote.get(), FromBackground, index); |
+ ts << " " << layerBeforePromote << " \"" << layerBeforePromote->debugName() << "\", z-index: " << layerBeforePromote->renderer()->style()->zIndex() << "\n"; |
+ } |
+ |
+ ts << " stacking context's paint order list AFTER promote:\n"; |
+ for (size_t index = 0; index < sizeAfterPromote; index++) { |
+ const RenderLayer* layerAfterPromote = getStackingOrderElementAt(posZOrderListAfterPromote.get(), negZOrderListAfterPromote.get(), FromBackground, index); |
+ ts << " " << layerAfterPromote << " \"" << layerAfterPromote->debugName() << "\", z-index: " << layerAfterPromote->renderer()->style()->zIndex() << "\n"; |
+ } |
+ |
+ return ts.release(); |
+} |
+#endif |
+ |
+PassRefPtr<NodeList> RenderLayer::paintOrderListBeforePromote() |
hartmanng
2013/04/23 21:32:37
I reworked these two functions, and the ones in In
|
+{ |
+ OwnPtr<Vector<RenderLayer*> > posZOrderListBeforePromote; |
+ OwnPtr<Vector<RenderLayer*> > negZOrderListBeforePromote; |
+ |
+ RenderLayer* ancestorStackingContext = this; |
+ |
+ while (ancestorStackingContext) { |
+ if (ancestorStackingContext != this && ancestorStackingContext->isStackingContext()) |
+ break; |
+ ancestorStackingContext = ancestorStackingContext->parent(); |
+ } |
+ |
+ if (!ancestorStackingContext) |
+ return 0; |
+ |
+ collectBeforePromotionZOrderList(ancestorStackingContext, |
+ posZOrderListBeforePromote, negZOrderListBeforePromote); |
+ |
+ size_t posZOrderListSizeBeforePromote = posZOrderListBeforePromote ? posZOrderListBeforePromote->size() : 0; |
+ size_t negZOrderListSizeBeforePromote = negZOrderListBeforePromote ? negZOrderListBeforePromote->size() : 0; |
+ |
+ size_t sizeBeforePromote = posZOrderListSizeBeforePromote + negZOrderListSizeBeforePromote; |
+ |
+ ListHashSet<RefPtr<Node> > listBeforePromote; |
+ for (size_t index = 0; index < sizeBeforePromote; index++) { |
+ const RenderLayer* layerBeforePromote = getStackingOrderElementAt(posZOrderListBeforePromote.get(), negZOrderListBeforePromote.get(), FromBackground, index); |
+ listBeforePromote.add(layerBeforePromote->renderer()->node()); |
+ } |
+ |
+ return StaticHashSetNodeList::adopt(listBeforePromote); |
+} |
+ |
+PassRefPtr<NodeList> RenderLayer::paintOrderListAfterPromote() |
+{ |
+ OwnPtr<Vector<RenderLayer*> > posZOrderListAfterPromote; |
+ OwnPtr<Vector<RenderLayer*> > negZOrderListAfterPromote; |
+ |
+ RenderLayer* ancestorStackingContext = this; |
+ |
+ while (ancestorStackingContext) { |
+ if (ancestorStackingContext != this && ancestorStackingContext->isStackingContext()) |
+ break; |
+ ancestorStackingContext = ancestorStackingContext->parent(); |
+ } |
+ |
+ if (!ancestorStackingContext) |
+ return 0; |
+ |
+ collectAfterPromotionZOrderList(ancestorStackingContext, |
+ posZOrderListAfterPromote, negZOrderListAfterPromote); |
+ |
+ size_t posZOrderListSizeAfterPromote = posZOrderListAfterPromote ? posZOrderListAfterPromote->size() : 0; |
+ size_t negZOrderListSizeAfterPromote = negZOrderListAfterPromote ? negZOrderListAfterPromote->size() : 0; |
+ |
+ size_t sizeAfterPromote = posZOrderListSizeAfterPromote + negZOrderListSizeAfterPromote; |
+ |
+ ListHashSet<RefPtr<Node> > listAfterPromote; |
+ for (size_t index = 0; index < sizeAfterPromote; index++) { |
+ const RenderLayer* layerAfterPromote = getStackingOrderElementAt(posZOrderListAfterPromote.get(), negZOrderListAfterPromote.get(), FromBackground, index); |
+ listAfterPromote.add(layerAfterPromote->renderer()->node()); |
+ } |
+ |
+ return StaticHashSetNodeList::adopt(listAfterPromote); |
+} |
+ |
+ |
void RenderLayer::computeRepaintRects(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap* geometryMap) |
{ |
ASSERT(!m_visibleContentStatusDirty); |
@@ -1273,12 +1542,6 @@ RenderLayer* RenderLayer::stackingContext() const |
return layer; |
} |
-static inline bool isPositionedContainer(RenderLayer* layer) |
-{ |
- RenderLayerModelObject* layerRenderer = layer->renderer(); |
- return layer->isRootLayer() || layerRenderer->isPositioned() || layer->hasTransform(); |
-} |
- |
static inline bool isFixedPositionedContainer(RenderLayer* layer) |
{ |
return layer->isRootLayer() || layer->hasTransform(); |
@@ -5542,12 +5805,12 @@ void RenderLayer::rebuildZOrderLists() |
m_zOrderListsDirty = false; |
} |
-void RenderLayer::rebuildZOrderLists(CollectLayersBehavior behavior, OwnPtr<Vector<RenderLayer*> >& posZOrderList, OwnPtr<Vector<RenderLayer*> >& negZOrderList) |
+void RenderLayer::rebuildZOrderLists(CollectLayersBehavior behavior, OwnPtr<Vector<RenderLayer*> >& posZOrderList, OwnPtr<Vector<RenderLayer*> >& negZOrderList, const RenderLayer* layerToForceAsStackingContainer) |
{ |
bool includeHiddenLayers = compositor()->inCompositingMode(); |
for (RenderLayer* child = firstChild(); child; child = child->nextSibling()) |
if (!m_reflection || reflectionLayer() != child) |
- child->collectLayers(includeHiddenLayers, behavior, posZOrderList, negZOrderList); |
+ child->collectLayers(includeHiddenLayers, behavior, posZOrderList, negZOrderList, layerToForceAsStackingContainer); |
// Sort the two lists. |
if (posZOrderList) |
@@ -5592,7 +5855,7 @@ void RenderLayer::updateNormalFlowList() |
m_normalFlowListDirty = false; |
} |
-void RenderLayer::collectLayers(bool includeHiddenLayers, CollectLayersBehavior behavior, OwnPtr<Vector<RenderLayer*> >& posBuffer, OwnPtr<Vector<RenderLayer*> >& negBuffer) |
+void RenderLayer::collectLayers(bool includeHiddenLayers, CollectLayersBehavior behavior, OwnPtr<Vector<RenderLayer*> >& posBuffer, OwnPtr<Vector<RenderLayer*> >& negBuffer, const RenderLayer* layerToForceAsStackingContainer) |
{ |
#if ENABLE(DIALOG_ELEMENT) |
if (isInTopLayer()) |
@@ -5601,7 +5864,18 @@ void RenderLayer::collectLayers(bool includeHiddenLayers, CollectLayersBehavior |
updateDescendantDependentFlags(); |
- bool isStacking = behavior == StopAtStackingContexts ? isStackingContext() : isStackingContainer(); |
+ bool isStacking = false; |
+ |
+ switch (behavior) { |
+ case StopAtStackingContexts: |
+ isStacking = (this == layerToForceAsStackingContainer) || isStackingContext(); |
+ break; |
+ |
+ case StopAtStackingContainers: |
+ isStacking = (this == layerToForceAsStackingContainer) || isStackingContainer(); |
+ break; |
+ } |
+ |
// Overflow layers are just painted by their enclosing layers, so they don't get put in zorder lists. |
bool includeHiddenLayer = includeHiddenLayers || (m_hasVisibleContent || (m_hasVisibleDescendant && isStacking)); |
if (includeHiddenLayer && !isNormalFlowOnly() && !isOutOfFlowRenderFlowThread()) { |
@@ -5622,7 +5896,7 @@ void RenderLayer::collectLayers(bool includeHiddenLayers, CollectLayersBehavior |
for (RenderLayer* child = firstChild(); child; child = child->nextSibling()) { |
// Ignore reflections. |
if (!m_reflection || reflectionLayer() != child) |
- child->collectLayers(includeHiddenLayers, behavior, posBuffer, negBuffer); |
+ child->collectLayers(includeHiddenLayers, behavior, posBuffer, negBuffer, layerToForceAsStackingContainer); |
} |
} |
} |