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

Unified Diff: third_party/WebKit/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: Force main thread scrolling, set experimental status, and address review comments. 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.h
diff --git a/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.h b/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.h
index 6b3dca6ed15f4f13cb52653d392476c18f874ecc..87ba070f3d7988d5580916e66cec36dbcf370658 100644
--- a/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.h
+++ b/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.h
@@ -26,19 +26,19 @@
#ifndef ScrollingConstraints_h
chrishtr 2015/12/11 02:06:12 Rename this file ViewportConstraints and add a new
flackr 2016/01/19 15:40:48 Done.
#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; }
chrishtr 2015/12/11 02:06:12 Why the change from float to layout units here? Th
flackr 2016/01/19 15:40:48 Undone. At the time I thought it'd made for fewer
- 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;
};
@@ -84,33 +84,76 @@ public:
FixedPositionViewportConstraints(const FixedPositionViewportConstraints& other)
: ViewportConstraints(other)
- , m_viewportRectAtLastLayout(other.m_viewportRectAtLastLayout)
- , m_layerPositionAtLastLayout(other.m_layerPositionAtLastLayout)
{ }
- FloatPoint layerPositionForViewportRect(const FloatRect& viewportRect) const;
-
- const FloatRect& viewportRectAtLastLayout() const { return m_viewportRectAtLastLayout; }
- void setViewportRectAtLastLayout(const FloatRect& rect) { m_viewportRectAtLastLayout = rect; }
-
- const FloatPoint& layerPositionAtLastLayout() const { return m_layerPositionAtLastLayout; }
- void setLayerPositionAtLastLayout(const FloatPoint& point) { m_layerPositionAtLastLayout = point; }
-
bool operator==(const FixedPositionViewportConstraints& other) const
{
return m_alignmentOffset == other.m_alignmentOffset
- && m_anchorEdges == other.m_anchorEdges
- && m_viewportRectAtLastLayout == other.m_viewportRectAtLastLayout
- && m_layerPositionAtLastLayout == other.m_layerPositionAtLastLayout;
+ && m_anchorEdges == other.m_anchorEdges;
}
bool operator!=(const FixedPositionViewportConstraints& other) const { return !(*this == other); }
private:
ConstraintType constraintType() const override { return FixedPositionConstaint; }
+};
+
+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)
+ { }
- FloatRect m_viewportRectAtLastLayout;
- FloatPoint m_layerPositionAtLastLayout;
+ LayoutSize computeStickyOffset(const LayoutRect& viewportRect) const;
+
+ 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; }
+
+ void setAbsoluteContainingBlockRect(const LayoutRect& rect) { m_absoluteContainingBlockRect = rect; }
+
+ 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;
+ }
+
+ 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;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698