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

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

Issue 2650873002: Refactor PaintLayer location and offset calculation especially for floats (Closed)
Patch Set: - Created 3 years, 10 months 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 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Portions are Copyright (C) 1998 Netscape Communications Corporation. 5 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
6 * 6 *
7 * Other contributors: 7 * Other contributors:
8 * Robert O'Callahan <roc+@cs.cmu.edu> 8 * Robert O'Callahan <roc+@cs.cmu.edu>
9 * David Baron <dbaron@fas.harvard.edu> 9 * David Baron <dbaron@fas.harvard.edu>
10 * Christian Biesinger <cbiesinger@web.de> 10 * Christian Biesinger <cbiesinger@web.de>
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 localPoint.moveBy(toLayoutBox(curr)->physicalLocation()); 793 localPoint.moveBy(toLayoutBox(curr)->physicalLocation());
794 } 794 }
795 curr = curr->container(); 795 curr = curr->container();
796 } 796 }
797 if (curr && curr->isTableRow()) { 797 if (curr && curr->isTableRow()) {
798 // Put ourselves into the row coordinate space. 798 // Put ourselves into the row coordinate space.
799 localPoint.moveBy(-toLayoutBox(curr)->physicalLocation()); 799 localPoint.moveBy(-toLayoutBox(curr)->physicalLocation());
800 } 800 }
801 } 801 }
802 802
803 // Subtract our parent's scroll offset. 803 if (PaintLayer* containingLayer = this->containingLayer()) {
804 if (PaintLayer* containingLayer =
805 layoutObject()->isOutOfFlowPositioned()
806 ? containingLayerForOutOfFlowPositioned()
807 : nullptr) {
808 // For positioned layers, we subtract out the enclosing positioned layer's
809 // scroll offset.
810 if (containingLayer->layoutObject()->hasOverflowClip()) { 804 if (containingLayer->layoutObject()->hasOverflowClip()) {
805 // Subtract our container's scroll offset.
811 IntSize offset = containingLayer->layoutBox()->scrolledContentOffset(); 806 IntSize offset = containingLayer->layoutBox()->scrolledContentOffset();
812 localPoint -= offset; 807 localPoint -= offset;
813 } 808 } else if (layoutObject()->isAbsolutePositioned() &&
814 809 containingLayer->layoutObject()->isInFlowPositioned() &&
815 if (containingLayer->layoutObject()->isInFlowPositioned() && 810 containingLayer->layoutObject()->isLayoutInline()) {
816 containingLayer->layoutObject()->isLayoutInline()) { 811 // Adjust offset for absolute under in-flow positioned inline.
817 LayoutSize offset = 812 LayoutSize offset =
818 toLayoutInline(containingLayer->layoutObject()) 813 toLayoutInline(containingLayer->layoutObject())
819 ->offsetForInFlowPositionedInline(*toLayoutBox(layoutObject())); 814 ->offsetForInFlowPositionedInline(*toLayoutBox(layoutObject()));
820 localPoint += offset; 815 localPoint += offset;
821 } 816 }
822 } else if (parent() && parent()->layoutObject()->hasOverflowClip()) {
823 IntSize scrollOffset = parent()->layoutBox()->scrolledContentOffset();
824 localPoint -= scrollOffset;
825 } 817 }
826 818
827 if (layoutObject()->isInFlowPositioned()) { 819 if (layoutObject()->isInFlowPositioned()) {
828 LayoutSize newOffset = layoutObject()->offsetForInFlowPosition(); 820 LayoutSize newOffset = layoutObject()->offsetForInFlowPosition();
829 if (m_rareData || !newOffset.isZero()) 821 if (m_rareData || !newOffset.isZero())
830 ensureRareData().offsetForInFlowPosition = newOffset; 822 ensureRareData().offsetForInFlowPosition = newOffset;
831 localPoint.move(newOffset); 823 localPoint.move(newOffset);
832 } else if (m_rareData) { 824 } else if (m_rareData) {
833 m_rareData->offsetForInFlowPosition = LayoutSize(); 825 m_rareData->offsetForInFlowPosition = LayoutSize();
834 } 826 }
(...skipping 27 matching lines...) Expand all
862 854
863 const LayoutRect borderBox = toLayoutBox(layoutObject())->borderBoxRect(); 855 const LayoutRect borderBox = toLayoutBox(layoutObject())->borderBoxRect();
864 const ComputedStyle& style = layoutObject()->styleRef(); 856 const ComputedStyle& style = layoutObject()->styleRef();
865 857
866 return FloatPoint(floatValueForLength(style.perspectiveOriginX(), 858 return FloatPoint(floatValueForLength(style.perspectiveOriginX(),
867 borderBox.width().toFloat()), 859 borderBox.width().toFloat()),
868 floatValueForLength(style.perspectiveOriginY(), 860 floatValueForLength(style.perspectiveOriginY(),
869 borderBox.height().toFloat())); 861 borderBox.height().toFloat()));
870 } 862 }
871 863
872 PaintLayer* PaintLayer::containingLayerForOutOfFlowPositioned( 864 PaintLayer* PaintLayer::containingLayer(const PaintLayer* ancestor,
873 const PaintLayer* ancestor, 865 bool* skippedAncestor) const {
874 bool* skippedAncestor) const {
875 // If we have specified an ancestor, surely the caller needs to know whether 866 // If we have specified an ancestor, surely the caller needs to know whether
876 // we skipped it. 867 // we skipped it.
877 DCHECK(!ancestor || skippedAncestor); 868 DCHECK(!ancestor || skippedAncestor);
878 if (skippedAncestor) 869 if (skippedAncestor)
879 *skippedAncestor = false; 870 *skippedAncestor = false;
880 if (layoutObject()->style()->position() == FixedPosition) { 871
872 LayoutObject* layoutObject = this->layoutObject();
chrishtr 2017/01/25 21:06:40 Are the changes here just refactoring? It seems to
Xianzhu 2017/01/25 22:03:00 This changes old lines 822-824 for floating and co
873 if (layoutObject->isColumnSpanAll() ||
874 layoutObject->isFloatingWithNonContainingBlockParent()) {
875 Optional<LayoutObject::AncestorSkipInfo> skipInfo;
876 if (skippedAncestor)
877 skipInfo.emplace(ancestor->layoutObject());
878 if (auto containingBlock = layoutObject->containingBlock(
879 skippedAncestor ? &*skipInfo : nullptr)) {
880 if (skippedAncestor && skipInfo->ancestorSkipped())
881 *skippedAncestor = true;
882 return containingBlock->enclosingLayer();
883 }
884 return nullptr;
885 }
886
887 if (layoutObject->isOutOfFlowPositioned()) {
888 auto canContainThisLayer =
889 layoutObject->isFixedPositioned()
890 ? &LayoutObject::canContainFixedPositionObjects
891 : &LayoutObject::canContainAbsolutePositionObjects;
892
881 PaintLayer* curr = parent(); 893 PaintLayer* curr = parent();
882 while (curr && !curr->layoutObject()->canContainFixedPositionObjects()) { 894 while (curr && !(curr->layoutObject()->*canContainThisLayer)()) {
883 if (skippedAncestor && curr == ancestor) 895 if (skippedAncestor && curr == ancestor)
884 *skippedAncestor = true; 896 *skippedAncestor = true;
885 curr = curr->parent(); 897 curr = curr->parent();
886 } 898 }
887
888 return curr; 899 return curr;
889 } 900 }
890 901
891 PaintLayer* curr = parent(); 902 return parent();
892 while (curr && !curr->layoutObject()->canContainAbsolutePositionObjects()) {
893 if (skippedAncestor && curr == ancestor)
894 *skippedAncestor = true;
895 curr = curr->parent();
896 }
897
898 return curr;
899 } 903 }
900 904
901 PaintLayer* PaintLayer::enclosingTransformedAncestor() const { 905 PaintLayer* PaintLayer::enclosingTransformedAncestor() const {
902 PaintLayer* curr = parent(); 906 PaintLayer* curr = parent();
903 while (curr && !curr->isRootLayer() && !curr->transform()) 907 while (curr && !curr->isRootLayer() && !curr->transform())
904 curr = curr->parent(); 908 curr = curr->parent();
905 909
906 return curr; 910 return curr;
907 } 911 }
908 912
909 LayoutPoint PaintLayer::computeOffsetFromTransformedAncestor() const { 913 LayoutPoint PaintLayer::computeOffsetFromTransformedAncestor() const {
910 TransformState transformState(TransformState::ApplyTransformDirection, 914 TransformState transformState(TransformState::ApplyTransformDirection,
911 FloatPoint()); 915 FloatPoint());
912 layoutObject()->mapLocalToAncestor( 916 layoutObject()->mapLocalToAncestor(
913 transformAncestor() ? transformAncestor()->layoutObject() : nullptr, 917 transformAncestor() ? transformAncestor()->layoutObject() : nullptr,
914 transformState, 0); 918 transformState, 0);
915 transformState.flatten(); 919 transformState.flatten();
916 return LayoutPoint(transformState.lastPlanarPoint()); 920 return LayoutPoint(transformState.lastPlanarPoint());
917 } 921 }
918 922
919 PaintLayer* PaintLayer::compositingContainer() const { 923 PaintLayer* PaintLayer::compositingContainer() const {
920 if (!stackingNode()->isStacked()) { 924 if (!stackingNode()->isStacked())
921 // Floats have special painting order, which has complicated semantics. 925 return containingLayer();
922 // See the comments around FloatObject::setShouldPaint.
923 if (m_layoutObject->isFloating() && m_layoutObject->parent() &&
924 !m_layoutObject->parent()->isLayoutBlockFlow())
925 return m_layoutObject->containingBlock()->enclosingLayer();
926
927 return parent();
928 }
929 if (PaintLayerStackingNode* ancestorStackingNode = 926 if (PaintLayerStackingNode* ancestorStackingNode =
930 stackingNode()->ancestorStackingContextNode()) 927 stackingNode()->ancestorStackingContextNode())
931 return ancestorStackingNode->layer(); 928 return ancestorStackingNode->layer();
932 return nullptr; 929 return nullptr;
933 } 930 }
934 931
935 bool PaintLayer::isPaintInvalidationContainer() const { 932 bool PaintLayer::isPaintInvalidationContainer() const {
936 return compositingState() == PaintsIntoOwnBacking || 933 return compositingState() == PaintsIntoOwnBacking ||
937 compositingState() == PaintsIntoGroupedBacking; 934 compositingState() == PaintsIntoGroupedBacking;
938 } 935 }
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 } 1397 }
1401 1398
1402 // Returns the layer reached on the walk up towards the ancestor. 1399 // Returns the layer reached on the walk up towards the ancestor.
1403 static inline const PaintLayer* accumulateOffsetTowardsAncestor( 1400 static inline const PaintLayer* accumulateOffsetTowardsAncestor(
1404 const PaintLayer* layer, 1401 const PaintLayer* layer,
1405 const PaintLayer* ancestorLayer, 1402 const PaintLayer* ancestorLayer,
1406 LayoutPoint& location) { 1403 LayoutPoint& location) {
1407 DCHECK(ancestorLayer != layer); 1404 DCHECK(ancestorLayer != layer);
1408 1405
1409 const LayoutBoxModelObject* layoutObject = layer->layoutObject(); 1406 const LayoutBoxModelObject* layoutObject = layer->layoutObject();
1410 EPosition position = layoutObject->style()->position();
1411 1407
1412 if (position == FixedPosition && 1408 if (layoutObject->isFixedPositioned() &&
1413 (!ancestorLayer || ancestorLayer == layoutObject->view()->layer())) { 1409 (!ancestorLayer || ancestorLayer == layoutObject->view()->layer())) {
1414 // If the fixed layer's container is the root, just add in the offset of the 1410 // If the fixed layer's container is the root, just add in the offset of the
1415 // view. We can obtain this by calling localToAbsolute() on the LayoutView. 1411 // view. We can obtain this by calling localToAbsolute() on the LayoutView.
1416 FloatPoint absPos = layoutObject->localToAbsolute(); 1412 FloatPoint absPos = layoutObject->localToAbsolute();
1417 location += LayoutSize(absPos.x(), absPos.y()); 1413 location += LayoutSize(absPos.x(), absPos.y());
1418 return ancestorLayer; 1414 return ancestorLayer;
1419 } 1415 }
1420 1416
1421 PaintLayer* parentLayer = nullptr; 1417 bool foundAncestorFirst;
1422 if (position == AbsolutePosition || position == FixedPosition || 1418 PaintLayer* containingLayer =
1423 (layoutObject->isFloating() && layoutObject->parent() && 1419 layer->containingLayer(ancestorLayer, &foundAncestorFirst);
1424 !layoutObject->parent()->isLayoutBlockFlow())) {
1425 bool foundAncestorFirst = false;
1426 if (layoutObject->isFloating()) {
1427 Optional<LayoutObject::AncestorSkipInfo> skipInfo;
1428 if (ancestorLayer)
1429 skipInfo.emplace(ancestorLayer->layoutObject());
1430 if (auto* containingBlock = layoutObject->containingBlock(
1431 ancestorLayer ? &*skipInfo : nullptr)) {
1432 parentLayer = containingBlock->enclosingLayer();
1433 foundAncestorFirst = ancestorLayer && skipInfo->ancestorSkipped();
1434 }
1435 } else {
1436 parentLayer = layer->containingLayerForOutOfFlowPositioned(
1437 ancestorLayer, &foundAncestorFirst);
1438 }
1439 1420
1440 if (foundAncestorFirst) { 1421 if (foundAncestorFirst) {
1441 // Found ancestorLayer before the container of the out-of-flow object, so 1422 // Found ancestorLayer before the containing layer, so compute offset of
1442 // compute offset of both relative to the container and subtract. 1423 // both relative to the container and subtract.
1424 LayoutPoint thisCoords;
1425 layer->convertToLayerCoords(containingLayer, thisCoords);
1443 1426
1444 LayoutPoint thisCoords; 1427 LayoutPoint ancestorCoords;
1445 layer->convertToLayerCoords(parentLayer, thisCoords); 1428 ancestorLayer->convertToLayerCoords(containingLayer, ancestorCoords);
1446 1429
1447 LayoutPoint ancestorCoords; 1430 location += (thisCoords - ancestorCoords);
1448 ancestorLayer->convertToLayerCoords(parentLayer, ancestorCoords); 1431 return ancestorLayer;
1449
1450 location += (thisCoords - ancestorCoords);
1451 return ancestorLayer;
1452 }
1453 } else if (layoutObject->isColumnSpanAll()) {
1454 LayoutBlock* multicolContainer = layoutObject->containingBlock();
1455 DCHECK(toLayoutBlockFlow(multicolContainer)->multiColumnFlowThread());
1456 parentLayer = multicolContainer->layer();
1457 DCHECK(parentLayer);
1458 } else {
1459 parentLayer = layer->parent();
1460 } 1432 }
1461 1433
1462 if (!parentLayer) 1434 if (!containingLayer)
1463 return nullptr; 1435 return nullptr;
1464 1436
1465 location += layer->location(); 1437 location += layer->location();
1466 return parentLayer; 1438 return containingLayer;
1467 } 1439 }
1468 1440
1469 void PaintLayer::convertToLayerCoords(const PaintLayer* ancestorLayer, 1441 void PaintLayer::convertToLayerCoords(const PaintLayer* ancestorLayer,
1470 LayoutPoint& location) const { 1442 LayoutPoint& location) const {
1471 if (ancestorLayer == this) 1443 if (ancestorLayer == this)
1472 return; 1444 return;
1473 1445
1474 const PaintLayer* currLayer = this; 1446 const PaintLayer* currLayer = this;
1475 while (currLayer && currLayer != ancestorLayer) 1447 while (currLayer && currLayer != ancestorLayer)
1476 currLayer = 1448 currLayer =
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after
3235 } 3207 }
3236 3208
3237 void showLayerTree(const blink::LayoutObject* layoutObject) { 3209 void showLayerTree(const blink::LayoutObject* layoutObject) {
3238 if (!layoutObject) { 3210 if (!layoutObject) {
3239 LOG(INFO) << "Cannot showLayerTree. Root is (nil)"; 3211 LOG(INFO) << "Cannot showLayerTree. Root is (nil)";
3240 return; 3212 return;
3241 } 3213 }
3242 showLayerTree(layoutObject->enclosingLayer()); 3214 showLayerTree(layoutObject->enclosingLayer());
3243 } 3215 }
3244 #endif 3216 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698