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

Unified Diff: third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.h

Issue 2636253002: Handle nested position:sticky elements (Closed)
Patch Set: Use ancestorOverflowLayer instead of stickyAncestor + test fixing Created 3 years, 11 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/page/scrolling/StickyPositionScrollingConstraints.h
diff --git a/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.h b/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.h
index e37687262edcd4a096f127a3a5054eeb78330e66..1f7bfa17c25069c50e1d8227292194964a6e1820 100644
--- a/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.h
+++ b/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.h
@@ -6,9 +6,12 @@
#define StickyPositionScrollingConstraints_h
#include "platform/geometry/FloatRect.h"
+#include "platform/geometry/FloatSize.h"
namespace blink {
+class LayoutBoxModelObject;
+
class StickyPositionScrollingConstraints final {
public:
enum AnchorEdgeFlags {
@@ -24,7 +27,9 @@ class StickyPositionScrollingConstraints final {
m_leftOffset(0),
m_rightOffset(0),
m_topOffset(0),
- m_bottomOffset(0) {}
+ m_bottomOffset(0),
+ m_nearestStickyElementShiftingStickyBox(nullptr),
+ m_nearestStickyElementShiftingContainingBlock(nullptr) {}
StickyPositionScrollingConstraints(
const StickyPositionScrollingConstraints& other)
@@ -36,9 +41,23 @@ class StickyPositionScrollingConstraints final {
m_scrollContainerRelativeContainingBlockRect(
other.m_scrollContainerRelativeContainingBlockRect),
m_scrollContainerRelativeStickyBoxRect(
- other.m_scrollContainerRelativeStickyBoxRect) {}
-
- FloatSize computeStickyOffset(const FloatRect& viewportRect) const;
+ other.m_scrollContainerRelativeStickyBoxRect),
+ m_nearestStickyElementShiftingStickyBox(
+ other.m_nearestStickyElementShiftingStickyBox),
+ m_nearestStickyElementShiftingContainingBlock(
+ other.m_nearestStickyElementShiftingContainingBlock),
+ m_totalStickyBoxStickyOffset(other.m_totalStickyBoxStickyOffset),
+ m_totalContainingBlockStickyOffset(
+ other.m_totalContainingBlockStickyOffset) {}
+
+ FloatSize computeStickyOffset(const FloatRect& viewportRect,
+ const FloatSize& ancestorStickyBoxOffset,
+ const FloatSize& ancestorContainingBlockOffset);
+
+ bool hasAncestorStickyElement() {
+ return m_nearestStickyElementShiftingStickyBox ||
+ m_nearestStickyElementShiftingContainingBlock;
+ }
AnchorEdges anchorEdges() const { return m_anchorEdges; }
bool hasAnchorEdge(AnchorEdgeFlags flag) const {
@@ -71,6 +90,28 @@ class StickyPositionScrollingConstraints final {
return m_scrollContainerRelativeStickyBoxRect;
}
+ void setNearestStickyElementShiftingStickyBox(LayoutBoxModelObject* layer) {
+ m_nearestStickyElementShiftingStickyBox = layer;
+ }
+ const LayoutBoxModelObject* nearestStickyElementShiftingStickyBox() {
+ return m_nearestStickyElementShiftingStickyBox;
+ }
+
+ void setNearestStickyElementShiftingContainingBlock(
+ LayoutBoxModelObject* layer) {
+ m_nearestStickyElementShiftingContainingBlock = layer;
+ }
+ const LayoutBoxModelObject* nearestStickyElementShiftingContainingBlock() {
+ return m_nearestStickyElementShiftingContainingBlock;
+ }
+
+ const FloatSize& getTotalStickyBoxStickyOffset() {
+ return m_totalStickyBoxStickyOffset;
+ }
+ const FloatSize& getTotalContainingBlockStickyOffset() {
+ return m_totalContainingBlockStickyOffset;
+ }
+
bool operator==(const StickyPositionScrollingConstraints& other) const {
return m_leftOffset == other.m_leftOffset &&
m_rightOffset == other.m_rightOffset &&
@@ -79,7 +120,14 @@ class StickyPositionScrollingConstraints final {
m_scrollContainerRelativeContainingBlockRect ==
other.m_scrollContainerRelativeContainingBlockRect &&
m_scrollContainerRelativeStickyBoxRect ==
- other.m_scrollContainerRelativeStickyBoxRect;
+ other.m_scrollContainerRelativeStickyBoxRect &&
+ m_nearestStickyElementShiftingStickyBox ==
+ other.m_nearestStickyElementShiftingStickyBox &&
+ m_nearestStickyElementShiftingContainingBlock ==
+ other.m_nearestStickyElementShiftingContainingBlock &&
+ m_totalStickyBoxStickyOffset == other.m_totalStickyBoxStickyOffset &&
+ m_totalContainingBlockStickyOffset ==
+ other.m_totalContainingBlockStickyOffset;
}
bool operator!=(const StickyPositionScrollingConstraints& other) const {
@@ -94,6 +142,26 @@ class StickyPositionScrollingConstraints final {
float m_bottomOffset;
FloatRect m_scrollContainerRelativeContainingBlockRect;
FloatRect m_scrollContainerRelativeStickyBoxRect;
+
+ // In order to properly compute the stickyOffset, we need to know if we have
+ // any sticky ancestors both between ourselves and our containing block and
+ // between our containing block and the viewport. These ancestors are needed
+ // to properly shift our constraining rects with regards to the containing
+ // block and viewport.
+ LayoutBoxModelObject* m_nearestStickyElementShiftingStickyBox;
+ LayoutBoxModelObject* m_nearestStickyElementShiftingContainingBlock;
+
+ // For performance we cache our accumulated sticky offset to allow descendant
+ // sticky elements to offset their constraint rects. Because we can either
+ // affect the sticky box constraint rect or the containing block constraint
+ // rect, we need to accumulate both.
+ //
+ // NOTE(smcgruer): The case where we can affect both the sticky box constraint
+ // rect and the constraining block constriant rect for different sticky
+ // descendants is quite complex. See the StickyPositionComplexTableNesting
+ // test in LayoutBoxModelObjectTest.cpp.
+ FloatSize m_totalStickyBoxStickyOffset;
+ FloatSize m_totalContainingBlockStickyOffset;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698