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

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintLayer.cpp

Issue 1490063002: Implement Paint Containment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename layer method, add inline tests, address comments, bribe chrishtr, lather, rinse, repeat. Created 5 years 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 /* 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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 } 740 }
741 curr = curr->parent(); 741 curr = curr->parent();
742 } 742 }
743 if (curr->isBox() && curr->isTableRow()) { 743 if (curr->isBox() && curr->isTableRow()) {
744 // Put ourselves into the row coordinate space. 744 // Put ourselves into the row coordinate space.
745 localPoint.moveBy(-toLayoutBox(curr)->topLeftLocation()); 745 localPoint.moveBy(-toLayoutBox(curr)->topLeftLocation());
746 } 746 }
747 } 747 }
748 748
749 // Subtract our parent's scroll offset. 749 // Subtract our parent's scroll offset.
750 if (PaintLayer* positionedParent = layoutObject()->isOutOfFlowPositioned() ? enclosingPositionedAncestor() : nullptr) { 750 if (PaintLayer* containingLayer = layoutObject()->isOutOfFlowPositioned() ? containingLayerForOutOfFlowPositioned() : nullptr) {
751 // For positioned layers, we subtract out the enclosing positioned layer 's scroll offset. 751 // For positioned layers, we subtract out the enclosing positioned layer 's scroll offset.
752 if (positionedParent->layoutObject()->hasOverflowClip()) { 752 if (containingLayer->layoutObject()->hasOverflowClip()) {
753 IntSize offset = positionedParent->layoutBox()->scrolledContentOffse t(); 753 IntSize offset = containingLayer->layoutBox()->scrolledContentOffset ();
754 localPoint -= offset; 754 localPoint -= offset;
755 } 755 }
756 756
757 if (positionedParent->layoutObject()->isInFlowPositioned() && positioned Parent->layoutObject()->isLayoutInline()) { 757 if (containingLayer->layoutObject()->isInFlowPositioned() && containingL ayer->layoutObject()->isLayoutInline()) {
758 LayoutSize offset = toLayoutInline(positionedParent->layoutObject()) ->offsetForInFlowPositionedInline(*toLayoutBox(layoutObject())); 758 LayoutSize offset = toLayoutInline(containingLayer->layoutObject())- >offsetForInFlowPositionedInline(*toLayoutBox(layoutObject()));
759 localPoint += offset; 759 localPoint += offset;
760 } 760 }
761 } else if (parent() && parent()->layoutObject()->hasOverflowClip()) { 761 } else if (parent() && parent()->layoutObject()->hasOverflowClip()) {
762 IntSize scrollOffset = parent()->layoutBox()->scrolledContentOffset(); 762 IntSize scrollOffset = parent()->layoutBox()->scrolledContentOffset();
763 localPoint -= scrollOffset; 763 localPoint -= scrollOffset;
764 } 764 }
765 765
766 bool positionOrOffsetChanged = false; 766 bool positionOrOffsetChanged = false;
767 if (layoutObject()->isInFlowPositioned()) { 767 if (layoutObject()->isInFlowPositioned()) {
768 LayoutSize newOffset = layoutObject()->offsetForInFlowPosition(); 768 LayoutSize newOffset = layoutObject()->offsetForInFlowPosition();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 { 806 {
807 if (!layoutObject()->hasTransformRelatedProperty()) 807 if (!layoutObject()->hasTransformRelatedProperty())
808 return FloatPoint(); 808 return FloatPoint();
809 809
810 const LayoutRect borderBox = toLayoutBox(layoutObject())->borderBoxRect(); 810 const LayoutRect borderBox = toLayoutBox(layoutObject())->borderBoxRect();
811 const ComputedStyle& style = layoutObject()->styleRef(); 811 const ComputedStyle& style = layoutObject()->styleRef();
812 812
813 return FloatPoint(floatValueForLength(style.perspectiveOriginX(), borderBox. width().toFloat()), floatValueForLength(style.perspectiveOriginY(), borderBox.he ight().toFloat())); 813 return FloatPoint(floatValueForLength(style.perspectiveOriginX(), borderBox. width().toFloat()), floatValueForLength(style.perspectiveOriginY(), borderBox.he ight().toFloat()));
814 } 814 }
815 815
816 static inline bool isFixedPositionedContainer(PaintLayer* layer) 816 static inline bool isContainerForFixedPositioned(PaintLayer* layer)
817 { 817 {
818 return layer->isRootLayer() || layer->hasTransformRelatedProperty(); 818 return layer->isRootLayer() || layer->hasTransformRelatedProperty();
819 } 819 }
820 820
821 PaintLayer* PaintLayer::enclosingPositionedAncestor(const PaintLayer* ancestor, bool* skippedAncestor) const 821 static inline bool isContainerForPositioned(PaintLayer* layer)
822 {
823 // FIXME: This is not in sync with containingBlock.
824 // LayoutObject::canContainFixedPositionObjects() should probably be used
825 // instead.
826 LayoutBoxModelObject* layerlayoutObject = layer->layoutObject();
827 return layer->isRootLayer() || layerlayoutObject->isPositioned() || layer->h asTransformRelatedProperty() || layerlayoutObject->style()->containsPaint();
828 }
829
830 PaintLayer* PaintLayer::containingLayerForOutOfFlowPositioned(const PaintLayer* ancestor, bool* skippedAncestor) const
822 { 831 {
823 ASSERT(!ancestor || skippedAncestor); // If we have specified an ancestor, s urely the caller needs to know whether we skipped it. 832 ASSERT(!ancestor || skippedAncestor); // If we have specified an ancestor, s urely the caller needs to know whether we skipped it.
824 if (skippedAncestor) 833 if (skippedAncestor)
825 *skippedAncestor = false; 834 *skippedAncestor = false;
826 if (layoutObject()->style()->position() == FixedPosition) { 835 if (layoutObject()->style()->position() == FixedPosition) {
827 PaintLayer* curr = parent(); 836 PaintLayer* curr = parent();
828 while (curr && !isFixedPositionedContainer(curr)) { 837 while (curr && !isContainerForFixedPositioned(curr)) {
829 if (skippedAncestor && curr == ancestor) 838 if (skippedAncestor && curr == ancestor)
830 *skippedAncestor = true; 839 *skippedAncestor = true;
831 curr = curr->parent(); 840 curr = curr->parent();
832 } 841 }
833 842
834 return curr; 843 return curr;
835 } 844 }
836 845
837 PaintLayer* curr = parent(); 846 PaintLayer* curr = parent();
838 while (curr && !curr->isPositionedContainer()) { 847 while (curr && !isContainerForPositioned(curr)) {
839 if (skippedAncestor && curr == ancestor) 848 if (skippedAncestor && curr == ancestor)
840 *skippedAncestor = true; 849 *skippedAncestor = true;
841 curr = curr->parent(); 850 curr = curr->parent();
842 } 851 }
843 852
844 return curr; 853 return curr;
845 } 854 }
846 855
847 PaintLayer* PaintLayer::enclosingTransformedAncestor() const 856 PaintLayer* PaintLayer::enclosingTransformedAncestor() const
848 { 857 {
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 // If the fixed layer's container is the root, just add in the offset of the view. We can obtain this by calling 1274 // If the fixed layer's container is the root, just add in the offset of the view. We can obtain this by calling
1266 // localToAbsolute() on the LayoutView. 1275 // localToAbsolute() on the LayoutView.
1267 FloatPoint absPos = layoutObject->localToAbsolute(FloatPoint(), IsFixed) ; 1276 FloatPoint absPos = layoutObject->localToAbsolute(FloatPoint(), IsFixed) ;
1268 location += LayoutSize(absPos.x(), absPos.y()); 1277 location += LayoutSize(absPos.x(), absPos.y());
1269 return ancestorLayer; 1278 return ancestorLayer;
1270 } 1279 }
1271 1280
1272 PaintLayer* parentLayer; 1281 PaintLayer* parentLayer;
1273 if (position == AbsolutePosition || position == FixedPosition) { 1282 if (position == AbsolutePosition || position == FixedPosition) {
1274 bool foundAncestorFirst; 1283 bool foundAncestorFirst;
1275 parentLayer = layer->enclosingPositionedAncestor(ancestorLayer, &foundAn cestorFirst); 1284 parentLayer = layer->containingLayerForOutOfFlowPositioned(ancestorLayer , &foundAncestorFirst);
1276 1285
1277 if (foundAncestorFirst) { 1286 if (foundAncestorFirst) {
1278 // Found ancestorLayer before the container of the out-of-flow objec t, so compute offset 1287 // Found ancestorLayer before the container of the out-of-flow objec t, so compute offset
1279 // of both relative to the container and subtract. 1288 // of both relative to the container and subtract.
1280 1289
1281 LayoutPoint thisCoords; 1290 LayoutPoint thisCoords;
1282 layer->convertToLayerCoords(parentLayer, thisCoords); 1291 layer->convertToLayerCoords(parentLayer, thisCoords);
1283 1292
1284 LayoutPoint ancestorCoords; 1293 LayoutPoint ancestorCoords;
1285 ancestorLayer->convertToLayerCoords(parentLayer, ancestorCoords); 1294 ancestorLayer->convertToLayerCoords(parentLayer, ancestorCoords);
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
2351 if (m_stackingNode->zOrderListsDirty()) 2360 if (m_stackingNode->zOrderListsDirty())
2352 return false; 2361 return false;
2353 2362
2354 // FIXME: We currently only check the immediate layoutObject, 2363 // FIXME: We currently only check the immediate layoutObject,
2355 // which will miss many cases. 2364 // which will miss many cases.
2356 if (layoutObject()->backgroundIsKnownToBeOpaqueInRect(localRect)) 2365 if (layoutObject()->backgroundIsKnownToBeOpaqueInRect(localRect))
2357 return true; 2366 return true;
2358 2367
2359 // We can't consult child layers if we clip, since they might cover 2368 // We can't consult child layers if we clip, since they might cover
2360 // parts of the rect that are clipped out. 2369 // parts of the rect that are clipped out.
2361 if (layoutObject()->hasOverflowClip()) 2370 if (layoutObject()->hasOverflowClip() || layoutObject()->style()->containsPa int())
2362 return false; 2371 return false;
2363 2372
2364 return childBackgroundIsKnownToBeOpaqueInRect(localRect); 2373 return childBackgroundIsKnownToBeOpaqueInRect(localRect);
2365 } 2374 }
2366 2375
2367 bool PaintLayer::childBackgroundIsKnownToBeOpaqueInRect(const LayoutRect& localR ect) const 2376 bool PaintLayer::childBackgroundIsKnownToBeOpaqueInRect(const LayoutRect& localR ect) const
2368 { 2377 {
2369 PaintLayerStackingNodeReverseIterator revertseIterator(*m_stackingNode, Posi tiveZOrderChildren | NormalFlowChildren | NegativeZOrderChildren); 2378 PaintLayerStackingNodeReverseIterator revertseIterator(*m_stackingNode, Posi tiveZOrderChildren | NormalFlowChildren | NegativeZOrderChildren);
2370 while (PaintLayerStackingNode* child = revertseIterator.next()) { 2379 while (PaintLayerStackingNode* child = revertseIterator.next()) {
2371 const PaintLayer* childLayer = child->layer(); 2380 const PaintLayer* childLayer = child->layer();
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
2780 2789
2781 void showLayerTree(const blink::LayoutObject* layoutObject) 2790 void showLayerTree(const blink::LayoutObject* layoutObject)
2782 { 2791 {
2783 if (!layoutObject) { 2792 if (!layoutObject) {
2784 fprintf(stderr, "Cannot showLayerTree. Root is (nil)\n"); 2793 fprintf(stderr, "Cannot showLayerTree. Root is (nil)\n");
2785 return; 2794 return;
2786 } 2795 }
2787 showLayerTree(layoutObject->enclosingLayer()); 2796 showLayerTree(layoutObject->enclosingLayer());
2788 } 2797 }
2789 #endif 2798 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698