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

Unified Diff: third_party/WebKit/Source/core/paint/PaintLayer.cpp

Issue 2716583005: Do not promote position sticky or fixed elements unless they move with scroll. (Closed)
Patch Set: Avoid computing constraints for non-anchored sticky and add/update tests. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/paint/PaintLayer.cpp
diff --git a/third_party/WebKit/Source/core/paint/PaintLayer.cpp b/third_party/WebKit/Source/core/paint/PaintLayer.cpp
index abd609c8f6e5c374e79065e6f3e944837b4054fa..50f607fbc06c6831b00e0a8408a7e1b500d04c54 100644
--- a/third_party/WebKit/Source/core/paint/PaintLayer.cpp
+++ b/third_party/WebKit/Source/core/paint/PaintLayer.cpp
@@ -69,6 +69,7 @@
#include "core/layout/svg/LayoutSVGRoot.h"
#include "core/page/Page.h"
#include "core/page/scrolling/ScrollingCoordinator.h"
+#include "core/page/scrolling/StickyPositionScrollingConstraints.h"
#include "core/paint/BoxReflectionUtils.h"
#include "core/paint/FilterEffectBuilder.h"
#include "core/paint/ObjectPaintInvalidator.h"
@@ -327,9 +328,17 @@ void PaintLayer::dirtyAncestorChainHasSelfPaintingLayerDescendantStatus() {
}
}
-bool PaintLayer::sticksToViewport() const {
- if (layoutObject().style()->position() != EPosition::kFixed &&
- layoutObject().style()->position() != EPosition::kSticky)
+bool PaintLayer::sticksToScroller() const {
+ return layoutObject().style()->position() == EPosition::kSticky &&
+ ancestorOverflowLayer()
+ ->getScrollableArea()
+ ->stickyConstraintsMap()
+ .at(const_cast<PaintLayer*>(this))
+ .anchorEdges();
+}
+
+bool PaintLayer::fixedToViewport() const {
+ if (layoutObject().style()->position() != EPosition::kFixed)
return false;
// TODO(pdr): This approach of calculating the nearest scroll node is O(n).
@@ -338,30 +347,24 @@ bool PaintLayer::sticksToViewport() const {
if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
const auto* viewProperties = layoutObject().view()->paintProperties();
const ScrollPaintPropertyNode* ancestorTargetScrollNode;
- if (layoutObject().style()->position() == EPosition::kFixed) {
- ancestorTargetScrollNode = viewProperties->localBorderBoxProperties()
- ->transform()
- ->findEnclosingScrollNode();
- } else {
- ancestorTargetScrollNode = viewProperties->contentsProperties()
- ->transform()
- ->findEnclosingScrollNode();
- }
+ ancestorTargetScrollNode = viewProperties->localBorderBoxProperties()
+ ->transform()
+ ->findEnclosingScrollNode();
const auto* properties = layoutObject().paintProperties();
const auto* transform = properties->localBorderBoxProperties()->transform();
return transform->findEnclosingScrollNode() == ancestorTargetScrollNode;
}
- return (layoutObject().style()->position() == EPosition::kFixed &&
- layoutObject().containerForFixedPosition() ==
- layoutObject().view()) ||
- (layoutObject().style()->position() == EPosition::kSticky &&
- (!ancestorScrollingLayer() || ancestorScrollingLayer() == root()));
+ return layoutObject().containerForFixedPosition() == layoutObject().view();
}
bool PaintLayer::scrollsWithRespectTo(const PaintLayer* other) const {
- if (sticksToViewport() != other->sticksToViewport())
+ if (fixedToViewport() != other->fixedToViewport())
+ return true;
+ // If either element sticks we cannot trivially determine that the layers do
+ // not scroll with respect to each other.
+ if (sticksToScroller() || other->sticksToScroller())
return true;
return ancestorScrollingLayer() != other->ancestorScrollingLayer();
}

Powered by Google App Engine
This is Rietveld 408576698