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

Unified Diff: Source/core/page/scrolling/ScrollingConstraints.h

Issue 1308273010: Adapt and reland old position sticky implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix style errors and remaining layout tests. Created 5 years, 3 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: Source/core/page/scrolling/ScrollingConstraints.h
diff --git a/Source/core/page/scrolling/ScrollingConstraints.h b/Source/core/page/scrolling/ScrollingConstraints.h
index 6b3dca6ed15f4f13cb52653d392476c18f874ecc..6c786a631e91182fbb8b91ef0699099d0865ada5 100644
--- a/Source/core/page/scrolling/ScrollingConstraints.h
+++ b/Source/core/page/scrolling/ScrollingConstraints.h
@@ -26,19 +26,19 @@
#ifndef ScrollingConstraints_h
#define ScrollingConstraints_h
-#include "platform/geometry/FloatRect.h"
+#include "platform/geometry/LayoutRect.h"
#include "wtf/Allocator.h"
namespace blink {
// ViewportConstraints classes encapsulate data and logic required to reposition elements whose layout
-// depends on the viewport rect (i.e., position fixed), when scrolling and zooming.
+// depends on the viewport rect (positioned fixed and sticky), when scrolling and zooming.
class ViewportConstraints {
STACK_ALLOCATED();
public:
- // FIXME: Simplify this code now that position: sticky doesn't exist.
enum ConstraintType {
FixedPositionConstaint,
+ StickyPositionConstraint,
};
enum AnchorEdgeFlags {
@@ -63,15 +63,15 @@ public:
void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; }
void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; }
- FloatSize alignmentOffset() const { return m_alignmentOffset; }
- void setAlignmentOffset(const FloatSize& offset) { m_alignmentOffset = offset; }
+ LayoutSize alignmentOffset() const { return m_alignmentOffset; }
+ void setAlignmentOffset(const LayoutSize& offset) { m_alignmentOffset = offset; }
protected:
ViewportConstraints()
: m_anchorEdges(0)
{ }
- FloatSize m_alignmentOffset;
+ LayoutSize m_alignmentOffset;
AnchorEdges m_anchorEdges;
};
@@ -88,13 +88,13 @@ public:
, m_layerPositionAtLastLayout(other.m_layerPositionAtLastLayout)
{ }
- FloatPoint layerPositionForViewportRect(const FloatRect& viewportRect) const;
+ LayoutPoint layerPositionForViewportRect(const LayoutRect& viewportRect) const;
- const FloatRect& viewportRectAtLastLayout() const { return m_viewportRectAtLastLayout; }
- void setViewportRectAtLastLayout(const FloatRect& rect) { m_viewportRectAtLastLayout = rect; }
+ const LayoutRect& viewportRectAtLastLayout() const { return m_viewportRectAtLastLayout; }
+ void setViewportRectAtLastLayout(const LayoutRect& rect) { m_viewportRectAtLastLayout = rect; }
- const FloatPoint& layerPositionAtLastLayout() const { return m_layerPositionAtLastLayout; }
- void setLayerPositionAtLastLayout(const FloatPoint& point) { m_layerPositionAtLastLayout = point; }
+ const LayoutPoint& layerPositionAtLastLayout() const { return m_layerPositionAtLastLayout; }
+ void setLayerPositionAtLastLayout(const LayoutPoint& point) { m_layerPositionAtLastLayout = point; }
bool operator==(const FixedPositionViewportConstraints& other) const
{
@@ -109,8 +109,82 @@ public:
private:
ConstraintType constraintType() const override { return FixedPositionConstaint; }
- FloatRect m_viewportRectAtLastLayout;
- FloatPoint m_layerPositionAtLastLayout;
+ LayoutRect m_viewportRectAtLastLayout;
+ LayoutPoint m_layerPositionAtLastLayout;
+};
+
+class StickyPositionViewportConstraints final : public ViewportConstraints {
+public:
+ StickyPositionViewportConstraints()
+ : m_leftOffset(0)
+ , m_rightOffset(0)
+ , m_topOffset(0)
+ , m_bottomOffset(0)
+ { }
+
+ StickyPositionViewportConstraints(const StickyPositionViewportConstraints& other)
+ : ViewportConstraints(other)
+ , m_leftOffset(other.m_leftOffset)
+ , m_rightOffset(other.m_rightOffset)
+ , m_topOffset(other.m_topOffset)
+ , m_bottomOffset(other.m_bottomOffset)
+ , m_absoluteContainingBlockRect(other.m_absoluteContainingBlockRect)
+ , m_absoluteStickyBoxRect(other.m_absoluteStickyBoxRect)
+ , m_stickyOffsetAtLastLayout(other.m_stickyOffsetAtLastLayout)
+ , m_layerPositionAtLastLayout(other.m_layerPositionAtLastLayout)
+ { }
+
+ LayoutSize computeStickyOffset(const LayoutRect& viewportRect) const;
+
+ const LayoutSize stickyOffsetAtLastLayout() const { return m_stickyOffsetAtLastLayout; }
+ void setStickyOffsetAtLastLayout(const LayoutSize& offset) { m_stickyOffsetAtLastLayout = offset; }
+
+ LayoutPoint layerPositionForViewportRect(const LayoutRect& viewportRect) const;
+
+ const LayoutPoint& layerPositionAtLastLayout() const { return m_layerPositionAtLastLayout; }
+ void setLayerPositionAtLastLayout(const LayoutPoint& point) { m_layerPositionAtLastLayout = point; }
+
+ LayoutUnit leftOffset() const { return m_leftOffset; }
+ LayoutUnit rightOffset() const { return m_rightOffset; }
+ LayoutUnit topOffset() const { return m_topOffset; }
+ LayoutUnit bottomOffset() const { return m_bottomOffset; }
+
+ void setLeftOffset(LayoutUnit offset) { m_leftOffset = offset; }
+ void setRightOffset(LayoutUnit offset) { m_rightOffset = offset; }
+ void setTopOffset(LayoutUnit offset) { m_topOffset = offset; }
+ void setBottomOffset(LayoutUnit offset) { m_bottomOffset = offset; }
+
+ LayoutRect absoluteContainingBlockRect() const { return m_absoluteContainingBlockRect; }
+ void setAbsoluteContainingBlockRect(const LayoutRect& rect) { m_absoluteContainingBlockRect = rect; }
+
+ LayoutRect absoluteStickyBoxRect() const { return m_absoluteStickyBoxRect; }
+ void setAbsoluteStickyBoxRect(const LayoutRect& rect) { m_absoluteStickyBoxRect = rect; }
+
+ bool operator==(const StickyPositionViewportConstraints& other) const
+ {
+ return m_leftOffset == other.m_leftOffset
+ && m_rightOffset == other.m_rightOffset
+ && m_topOffset == other.m_topOffset
+ && m_bottomOffset == other.m_bottomOffset
+ && m_absoluteContainingBlockRect == other.m_absoluteContainingBlockRect
+ && m_absoluteStickyBoxRect == other.m_absoluteStickyBoxRect
+ && m_stickyOffsetAtLastLayout == other.m_stickyOffsetAtLastLayout
+ && m_layerPositionAtLastLayout == other.m_layerPositionAtLastLayout;
+ }
+
+ bool operator!=(const StickyPositionViewportConstraints& other) const { return !(*this == other); }
+
+private:
+ ConstraintType constraintType() const override { return StickyPositionConstraint; }
+
+ LayoutUnit m_leftOffset;
+ LayoutUnit m_rightOffset;
+ LayoutUnit m_topOffset;
+ LayoutUnit m_bottomOffset;
+ LayoutRect m_absoluteContainingBlockRect;
+ LayoutRect m_absoluteStickyBoxRect;
+ LayoutSize m_stickyOffsetAtLastLayout;
+ LayoutPoint m_layerPositionAtLastLayout;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698