Commit bffe6bc6 authored by Tien-Ren Chen's avatar Tien-Ren Chen Committed by Commit Bot

[Blink] Change StickyPositionScrollingConstraints to struct type

This CL changes StickyPositionScrollingConstraints to a struct type.
It is a POD type anyway, and this allows us to remove tons of
boilerplate getter/setters.

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ie3bee752aceab1334919613df84e25167fb9c759
Reviewed-on: https://chromium-review.googlesource.com/1184231Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Reviewed-by: default avatarStephen McGruer <smcgruer@chromium.org>
Commit-Queue: Tien-Ren Chen <trchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585296}
parent 3033516b
...@@ -802,6 +802,8 @@ LayoutSize LayoutBoxModelObject::RelativePositionOffset() const { ...@@ -802,6 +802,8 @@ LayoutSize LayoutBoxModelObject::RelativePositionOffset() const {
} }
void LayoutBoxModelObject::UpdateStickyPositionConstraints() const { void LayoutBoxModelObject::UpdateStickyPositionConstraints() const {
DCHECK(StyleRef().HasStickyConstrainedPosition());
const FloatSize constraining_size = ComputeStickyConstrainingRect().Size(); const FloatSize constraining_size = ComputeStickyConstrainingRect().Size();
StickyPositionScrollingConstraints constraints; StickyPositionScrollingConstraints constraints;
...@@ -878,8 +880,8 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const { ...@@ -878,8 +880,8 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const {
max_container_width) + max_container_width) +
MinimumValueForLength(Style()->MarginLeft(), max_width)); MinimumValueForLength(Style()->MarginLeft(), max_width));
constraints.SetScrollContainerRelativeContainingBlockRect( constraints.scroll_container_relative_containing_block_rect =
FloatRect(scroll_container_relative_containing_block_rect)); FloatRect(scroll_container_relative_containing_block_rect);
FloatRect sticky_box_rect = FloatRect sticky_box_rect =
IsLayoutInline() ? FloatRect(ToLayoutInline(this)->LinesBoundingBox()) IsLayoutInline() ? FloatRect(ToLayoutInline(this)->LinesBoundingBox())
...@@ -898,10 +900,10 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const { ...@@ -898,10 +900,10 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const {
FloatSize container_border_offset(containing_block->BorderLeft(), FloatSize container_border_offset(containing_block->BorderLeft(),
containing_block->BorderTop()); containing_block->BorderTop());
sticky_location -= container_border_offset; sticky_location -= container_border_offset;
constraints.SetScrollContainerRelativeStickyBoxRect( constraints.scroll_container_relative_sticky_box_rect =
FloatRect(scroll_container_relative_padding_box_rect.Location() + FloatRect(scroll_container_relative_padding_box_rect.Location() +
ToFloatSize(sticky_location), ToFloatSize(sticky_location),
flipped_sticky_box_rect.Size())); flipped_sticky_box_rect.Size());
// To correctly compute the offsets, the constraints need to know about any // To correctly compute the offsets, the constraints need to know about any
// nested position:sticky elements between themselves and their // nested position:sticky elements between themselves and their
...@@ -909,14 +911,14 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const { ...@@ -909,14 +911,14 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const {
// //
// The respective search ranges are [container, containingBlock) and // The respective search ranges are [container, containingBlock) and
// [containingBlock, scrollAncestor). // [containingBlock, scrollAncestor).
constraints.SetNearestStickyLayerShiftingStickyBox( constraints.nearest_sticky_layer_shifting_sticky_box =
FindFirstStickyBetween(location_container, containing_block)); FindFirstStickyBetween(location_container, containing_block);
// We cannot use |scrollAncestor| here as it disregards the root // We cannot use |scrollAncestor| here as it disregards the root
// ancestorOverflowLayer(), which we should include. // ancestorOverflowLayer(), which we should include.
constraints.SetNearestStickyLayerShiftingContainingBlock( constraints.nearest_sticky_layer_shifting_containing_block =
FindFirstStickyBetween( FindFirstStickyBetween(
containing_block, containing_block,
&Layer()->AncestorOverflowLayer()->GetLayoutObject())); &Layer()->AncestorOverflowLayer()->GetLayoutObject());
// We skip the right or top sticky offset if there is not enough space to // We skip the right or top sticky offset if there is not enough space to
// honor both the left/right or top/bottom offsets. // honor both the left/right or top/bottom offsets.
...@@ -938,17 +940,15 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const { ...@@ -938,17 +940,15 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const {
} }
if (!Style()->Left().IsAuto() && !skip_left) { if (!Style()->Left().IsAuto() && !skip_left) {
constraints.SetLeftOffset(MinimumValueForLength( constraints.left_offset = MinimumValueForLength(
Style()->Left(), LayoutUnit(constraining_size.Width()))); Style()->Left(), LayoutUnit(constraining_size.Width()));
constraints.AddAnchorEdge( constraints.is_anchored_left = true;
StickyPositionScrollingConstraints::kAnchorEdgeLeft);
} }
if (!Style()->Right().IsAuto() && !skip_right) { if (!Style()->Right().IsAuto() && !skip_right) {
constraints.SetRightOffset(MinimumValueForLength( constraints.right_offset = MinimumValueForLength(
Style()->Right(), LayoutUnit(constraining_size.Width()))); Style()->Right(), LayoutUnit(constraining_size.Width()));
constraints.AddAnchorEdge( constraints.is_anchored_right = true;
StickyPositionScrollingConstraints::kAnchorEdgeRight);
} }
bool skip_bottom = false; bool skip_bottom = false;
...@@ -970,20 +970,16 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const { ...@@ -970,20 +970,16 @@ void LayoutBoxModelObject::UpdateStickyPositionConstraints() const {
} }
if (!Style()->Top().IsAuto()) { if (!Style()->Top().IsAuto()) {
constraints.SetTopOffset(MinimumValueForLength( constraints.top_offset = MinimumValueForLength(
Style()->Top(), LayoutUnit(constraining_size.Height()))); Style()->Top(), LayoutUnit(constraining_size.Height()));
constraints.AddAnchorEdge( constraints.is_anchored_top = true;
StickyPositionScrollingConstraints::kAnchorEdgeTop);
} }
if (!Style()->Bottom().IsAuto() && !skip_bottom) { if (!Style()->Bottom().IsAuto() && !skip_bottom) {
constraints.SetBottomOffset(MinimumValueForLength( constraints.bottom_offset = MinimumValueForLength(
Style()->Bottom(), LayoutUnit(constraining_size.Height()))); Style()->Bottom(), LayoutUnit(constraining_size.Height()));
constraints.AddAnchorEdge( constraints.is_anchored_bottom = true;
StickyPositionScrollingConstraints::kAnchorEdgeBottom);
} }
// At least one edge should be anchored if we are calculating constraints.
DCHECK(constraints.GetAnchorEdges());
PaintLayerScrollableArea* scrollable_area = PaintLayerScrollableArea* scrollable_area =
Layer()->AncestorOverflowLayer()->GetScrollableArea(); Layer()->AncestorOverflowLayer()->GetScrollableArea();
scrollable_area->GetStickyConstraintsMap().Set(Layer(), constraints); scrollable_area->GetStickyConstraintsMap().Set(Layer(), constraints);
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
namespace blink { namespace blink {
FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset( FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset(
const FloatRect& overflow_clip_rect, const FloatRect& content_box_rect,
const StickyConstraintsMap& constraints_map) { const StickyConstraintsMap& constraints_map) {
FloatRect sticky_box_rect = scroll_container_relative_sticky_box_rect_; FloatRect sticky_box_rect = scroll_container_relative_sticky_box_rect;
FloatRect containing_block_rect = FloatRect containing_block_rect =
scroll_container_relative_containing_block_rect_; scroll_container_relative_containing_block_rect;
FloatSize ancestor_sticky_box_offset = FloatSize ancestor_sticky_box_offset =
AncestorStickyBoxOffset(constraints_map); AncestorStickyBoxOffset(constraints_map);
FloatSize ancestor_containing_block_offset = FloatSize ancestor_containing_block_offset =
...@@ -21,10 +21,10 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset( ...@@ -21,10 +21,10 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset(
// Adjust the cached rect locations for any sticky ancestor elements. The // Adjust the cached rect locations for any sticky ancestor elements. The
// sticky offset applied to those ancestors affects us as follows: // sticky offset applied to those ancestors affects us as follows:
// //
// 1. |nearest_sticky_layer_shifting_sticky_box_| is a sticky layer between // 1. |nearest_sticky_layer_shifting_sticky_box| is a sticky layer between
// ourselves and our containing block, e.g. a nested inline parent. // ourselves and our containing block, e.g. a nested inline parent.
// It shifts only the sticky_box_rect and not the containing_block_rect. // It shifts only the sticky_box_rect and not the containing_block_rect.
// 2. |nearest_sticky_layer_shifting_containing_block_| is a sticky layer // 2. |nearest_sticky_layer_shifting_containing_block| is a sticky layer
// between our containing block (inclusive) and our scroll ancestor // between our containing block (inclusive) and our scroll ancestor
// (exclusive). As such, it shifts both the sticky_box_rect and the // (exclusive). As such, it shifts both the sticky_box_rect and the
// containing_block_rect. // containing_block_rect.
...@@ -43,8 +43,8 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset( ...@@ -43,8 +43,8 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset(
// As per the spec, 'left' overrides 'right' and 'top' overrides 'bottom'. // As per the spec, 'left' overrides 'right' and 'top' overrides 'bottom'.
FloatRect box_rect = sticky_box_rect; FloatRect box_rect = sticky_box_rect;
if (HasAnchorEdge(kAnchorEdgeRight)) { if (is_anchored_right) {
float right_limit = overflow_clip_rect.MaxX() - right_offset_; float right_limit = content_box_rect.MaxX() - right_offset;
float right_delta = float right_delta =
std::min<float>(0, right_limit - sticky_box_rect.MaxX()); std::min<float>(0, right_limit - sticky_box_rect.MaxX());
float available_space = float available_space =
...@@ -55,8 +55,8 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset( ...@@ -55,8 +55,8 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset(
box_rect.Move(right_delta, 0); box_rect.Move(right_delta, 0);
} }
if (HasAnchorEdge(kAnchorEdgeLeft)) { if (is_anchored_left) {
float left_limit = overflow_clip_rect.X() + left_offset_; float left_limit = content_box_rect.X() + left_offset;
float left_delta = std::max<float>(0, left_limit - sticky_box_rect.X()); float left_delta = std::max<float>(0, left_limit - sticky_box_rect.X());
float available_space = std::max<float>( float available_space = std::max<float>(
0, containing_block_rect.MaxX() - sticky_box_rect.MaxX()); 0, containing_block_rect.MaxX() - sticky_box_rect.MaxX());
...@@ -66,8 +66,8 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset( ...@@ -66,8 +66,8 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset(
box_rect.Move(left_delta, 0); box_rect.Move(left_delta, 0);
} }
if (HasAnchorEdge(kAnchorEdgeBottom)) { if (is_anchored_bottom) {
float bottom_limit = overflow_clip_rect.MaxY() - bottom_offset_; float bottom_limit = content_box_rect.MaxY() - bottom_offset;
float bottom_delta = float bottom_delta =
std::min<float>(0, bottom_limit - sticky_box_rect.MaxY()); std::min<float>(0, bottom_limit - sticky_box_rect.MaxY());
float available_space = float available_space =
...@@ -78,8 +78,8 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset( ...@@ -78,8 +78,8 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset(
box_rect.Move(0, bottom_delta); box_rect.Move(0, bottom_delta);
} }
if (HasAnchorEdge(kAnchorEdgeTop)) { if (is_anchored_top) {
float top_limit = overflow_clip_rect.Y() + top_offset_; float top_limit = content_box_rect.Y() + top_offset;
float top_delta = std::max<float>(0, top_limit - sticky_box_rect.Y()); float top_delta = std::max<float>(0, top_limit - sticky_box_rect.Y());
float available_space = std::max<float>( float available_space = std::max<float>(
0, containing_block_rect.MaxY() - sticky_box_rect.MaxY()); 0, containing_block_rect.MaxY() - sticky_box_rect.MaxY());
...@@ -93,44 +93,38 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset( ...@@ -93,44 +93,38 @@ FloatSize StickyPositionScrollingConstraints::ComputeStickyOffset(
// Now that we have computed our current sticky offset, update the cached // Now that we have computed our current sticky offset, update the cached
// accumulated sticky offsets. // accumulated sticky offsets.
total_sticky_box_sticky_offset_ = ancestor_sticky_box_offset + sticky_offset; total_sticky_box_sticky_offset = ancestor_sticky_box_offset + sticky_offset;
total_containing_block_sticky_offset_ = ancestor_sticky_box_offset + total_containing_block_sticky_offset = ancestor_sticky_box_offset +
ancestor_containing_block_offset + ancestor_containing_block_offset +
sticky_offset; sticky_offset;
return sticky_offset; return sticky_offset;
} }
FloatSize StickyPositionScrollingConstraints::GetOffsetForStickyPosition( FloatSize StickyPositionScrollingConstraints::GetOffsetForStickyPosition(
const StickyConstraintsMap& constraints_map) const { const StickyConstraintsMap& constraints_map) const {
FloatSize nearest_sticky_layer_shifting_sticky_box_constraints_offset; return total_sticky_box_sticky_offset -
if (nearest_sticky_layer_shifting_sticky_box_) { AncestorStickyBoxOffset(constraints_map);
nearest_sticky_layer_shifting_sticky_box_constraints_offset =
constraints_map.at(nearest_sticky_layer_shifting_sticky_box_)
.total_sticky_box_sticky_offset_;
}
return total_sticky_box_sticky_offset_ -
nearest_sticky_layer_shifting_sticky_box_constraints_offset;
} }
FloatSize StickyPositionScrollingConstraints::AncestorStickyBoxOffset( FloatSize StickyPositionScrollingConstraints::AncestorStickyBoxOffset(
const StickyConstraintsMap& constraints_map) { const StickyConstraintsMap& constraints_map) const {
if (!nearest_sticky_layer_shifting_sticky_box_) if (!nearest_sticky_layer_shifting_sticky_box)
return FloatSize(); return FloatSize();
DCHECK(constraints_map.Contains(nearest_sticky_layer_shifting_sticky_box_)); DCHECK(constraints_map.Contains(nearest_sticky_layer_shifting_sticky_box));
return constraints_map.at(nearest_sticky_layer_shifting_sticky_box_) return constraints_map.at(nearest_sticky_layer_shifting_sticky_box)
.total_sticky_box_sticky_offset_; .total_sticky_box_sticky_offset;
} }
FloatSize StickyPositionScrollingConstraints::AncestorContainingBlockOffset( FloatSize StickyPositionScrollingConstraints::AncestorContainingBlockOffset(
const StickyConstraintsMap& constraints_map) { const StickyConstraintsMap& constraints_map) const {
if (!nearest_sticky_layer_shifting_containing_block_) { if (!nearest_sticky_layer_shifting_containing_block) {
return FloatSize(); return FloatSize();
} }
DCHECK(constraints_map.Contains( DCHECK(
nearest_sticky_layer_shifting_containing_block_)); constraints_map.Contains(nearest_sticky_layer_shifting_containing_block));
return constraints_map.at(nearest_sticky_layer_shifting_containing_block_) return constraints_map.at(nearest_sticky_layer_shifting_containing_block)
.total_containing_block_sticky_offset_; .total_containing_block_sticky_offset;
} }
} // namespace blink } // namespace blink
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace blink { namespace blink {
class PaintLayer; class PaintLayer;
class StickyPositionScrollingConstraints; struct StickyPositionScrollingConstraints;
typedef WTF::HashMap<PaintLayer*, StickyPositionScrollingConstraints> typedef WTF::HashMap<PaintLayer*, StickyPositionScrollingConstraints>
StickyConstraintsMap; StickyConstraintsMap;
...@@ -71,25 +71,13 @@ typedef WTF::HashMap<PaintLayer*, StickyPositionScrollingConstraints> ...@@ -71,25 +71,13 @@ typedef WTF::HashMap<PaintLayer*, StickyPositionScrollingConstraints>
// already being shifted by its ancestor. To correctly handle such situations we // already being shifted by its ancestor. To correctly handle such situations we
// apply more complicated logic which is explained in the implementation of // apply more complicated logic which is explained in the implementation of
// |ComputeStickyOffset|. // |ComputeStickyOffset|.
class StickyPositionScrollingConstraints final { struct StickyPositionScrollingConstraints final {
public: public:
enum AnchorEdgeFlags {
kAnchorEdgeLeft = 1 << 0,
kAnchorEdgeRight = 1 << 1,
kAnchorEdgeTop = 1 << 2,
kAnchorEdgeBottom = 1 << 3
};
typedef unsigned AnchorEdges;
StickyPositionScrollingConstraints() StickyPositionScrollingConstraints()
: anchor_edges_(0), : is_anchored_left(false),
left_offset_(0), is_anchored_right(false),
right_offset_(0), is_anchored_top(false),
top_offset_(0), is_anchored_bottom(false) {}
bottom_offset_(0),
nearest_sticky_layer_shifting_sticky_box_(nullptr),
nearest_sticky_layer_shifting_containing_block_(nullptr) {}
StickyPositionScrollingConstraints( StickyPositionScrollingConstraints(
const StickyPositionScrollingConstraints& other) = default; const StickyPositionScrollingConstraints& other) = default;
...@@ -97,7 +85,7 @@ class StickyPositionScrollingConstraints final { ...@@ -97,7 +85,7 @@ class StickyPositionScrollingConstraints final {
// //
// This method is non-const as we cache internal state for performance; see // This method is non-const as we cache internal state for performance; see
// documentation in the implementation for details. // documentation in the implementation for details.
FloatSize ComputeStickyOffset(const FloatRect& overflow_clip_rect, FloatSize ComputeStickyOffset(const FloatRect& content_box_rect,
const StickyConstraintsMap&); const StickyConstraintsMap&);
// Returns the last-computed offset of the sticky box from its original // Returns the last-computed offset of the sticky box from its original
...@@ -108,87 +96,15 @@ class StickyPositionScrollingConstraints final { ...@@ -108,87 +96,15 @@ class StickyPositionScrollingConstraints final {
// element. (Or after prepaint for SlimmingPaintV2). // element. (Or after prepaint for SlimmingPaintV2).
FloatSize GetOffsetForStickyPosition(const StickyConstraintsMap&) const; FloatSize GetOffsetForStickyPosition(const StickyConstraintsMap&) const;
bool HasAncestorStickyElement() const { bool is_anchored_left : 1;
return nearest_sticky_layer_shifting_sticky_box_ || bool is_anchored_right : 1;
nearest_sticky_layer_shifting_containing_block_; bool is_anchored_top : 1;
} bool is_anchored_bottom : 1;
AnchorEdges GetAnchorEdges() const { return anchor_edges_; }
bool HasAnchorEdge(AnchorEdgeFlags flag) const {
return anchor_edges_ & flag;
}
void AddAnchorEdge(AnchorEdgeFlags edge_flag) { anchor_edges_ |= edge_flag; }
float LeftOffset() const { return left_offset_; }
float RightOffset() const { return right_offset_; }
float TopOffset() const { return top_offset_; }
float BottomOffset() const { return bottom_offset_; }
void SetLeftOffset(float offset) { left_offset_ = offset; }
void SetRightOffset(float offset) { right_offset_ = offset; }
void SetTopOffset(float offset) { top_offset_ = offset; }
void SetBottomOffset(float offset) { bottom_offset_ = offset; }
void SetScrollContainerRelativeContainingBlockRect(const FloatRect& rect) {
scroll_container_relative_containing_block_rect_ = rect;
}
const FloatRect& ScrollContainerRelativeContainingBlockRect() const {
return scroll_container_relative_containing_block_rect_;
}
void SetScrollContainerRelativeStickyBoxRect(const FloatRect& rect) {
scroll_container_relative_sticky_box_rect_ = rect;
}
const FloatRect& ScrollContainerRelativeStickyBoxRect() const {
return scroll_container_relative_sticky_box_rect_;
}
void SetNearestStickyLayerShiftingStickyBox(PaintLayer* layer) {
nearest_sticky_layer_shifting_sticky_box_ = layer;
}
PaintLayer* NearestStickyLayerShiftingStickyBox() const {
return nearest_sticky_layer_shifting_sticky_box_;
}
void SetNearestStickyLayerShiftingContainingBlock(PaintLayer* layer) {
nearest_sticky_layer_shifting_containing_block_ = layer;
}
PaintLayer* NearestStickyLayerShiftingContainingBlock() const {
return nearest_sticky_layer_shifting_containing_block_;
}
bool operator==(const StickyPositionScrollingConstraints& other) const {
return left_offset_ == other.left_offset_ &&
right_offset_ == other.right_offset_ &&
top_offset_ == other.top_offset_ &&
bottom_offset_ == other.bottom_offset_ &&
scroll_container_relative_containing_block_rect_ ==
other.scroll_container_relative_containing_block_rect_ &&
scroll_container_relative_sticky_box_rect_ ==
other.scroll_container_relative_sticky_box_rect_ &&
nearest_sticky_layer_shifting_sticky_box_ ==
other.nearest_sticky_layer_shifting_sticky_box_ &&
nearest_sticky_layer_shifting_containing_block_ ==
other.nearest_sticky_layer_shifting_containing_block_ &&
total_sticky_box_sticky_offset_ ==
other.total_sticky_box_sticky_offset_ &&
total_containing_block_sticky_offset_ ==
other.total_containing_block_sticky_offset_;
}
bool operator!=(const StickyPositionScrollingConstraints& other) const {
return !(*this == other);
}
private:
FloatSize AncestorStickyBoxOffset(const StickyConstraintsMap&);
FloatSize AncestorContainingBlockOffset(const StickyConstraintsMap&);
AnchorEdges anchor_edges_; float left_offset = 0.f;
float left_offset_; float right_offset = 0.f;
float right_offset_; float top_offset = 0.f;
float top_offset_; float bottom_offset = 0.f;
float bottom_offset_;
// The containing block rect and sticky box rect are the basic components // The containing block rect and sticky box rect are the basic components
// for calculating the sticky offset to apply after a scroll. Consider the // for calculating the sticky offset to apply after a scroll. Consider the
...@@ -203,12 +119,12 @@ class StickyPositionScrollingConstraints final { ...@@ -203,12 +119,12 @@ class StickyPositionScrollingConstraints final {
// The layout position of the containing block relative to the scroll // The layout position of the containing block relative to the scroll
// container. When calculating the sticky offset it is used to ensure the // container. When calculating the sticky offset it is used to ensure the
// sticky element stays bounded by its containing block. // sticky element stays bounded by its containing block.
FloatRect scroll_container_relative_containing_block_rect_; FloatRect scroll_container_relative_containing_block_rect;
// The layout position of the sticky element relative to the scroll container. // The layout position of the sticky element relative to the scroll container.
// When calculating the sticky offset it is used to determine how large the // When calculating the sticky offset it is used to determine how large the
// offset needs to be to satisfy the sticky constraints. // offset needs to be to satisfy the sticky constraints.
FloatRect scroll_container_relative_sticky_box_rect_; FloatRect scroll_container_relative_sticky_box_rect;
// In the case of nested sticky elements the layout position of the sticky // In the case of nested sticky elements the layout position of the sticky
// element and its containing block are not accurate (as they are affected by // element and its containing block are not accurate (as they are affected by
...@@ -219,9 +135,10 @@ class StickyPositionScrollingConstraints final { ...@@ -219,9 +135,10 @@ class StickyPositionScrollingConstraints final {
// //
// See the implementation of |ComputeStickyOffset| for documentation on how // See the implementation of |ComputeStickyOffset| for documentation on how
// these ancestors are used to correct the offset calculation. // these ancestors are used to correct the offset calculation.
PaintLayer* nearest_sticky_layer_shifting_sticky_box_; PaintLayer* nearest_sticky_layer_shifting_sticky_box = nullptr;
PaintLayer* nearest_sticky_layer_shifting_containing_block_; PaintLayer* nearest_sticky_layer_shifting_containing_block = nullptr;
private:
// For performance we cache our accumulated sticky offset to allow descendant // For performance we cache our accumulated sticky offset to allow descendant
// sticky elements to offset their constraint rects. Because we can either // sticky elements to offset their constraint rects. Because we can either
// affect a descendant element's sticky box constraint rect or containing // affect a descendant element's sticky box constraint rect or containing
...@@ -229,8 +146,8 @@ class StickyPositionScrollingConstraints final { ...@@ -229,8 +146,8 @@ class StickyPositionScrollingConstraints final {
// The sticky box offset accumulates the chain of sticky elements that are // The sticky box offset accumulates the chain of sticky elements that are
// between this sticky element and its containing block. Any descendant using // between this sticky element and its containing block. Any descendant using
// |total_sticky_box_sticky_offset_| has the same containing block as this // |total_sticky_box_sticky_offset| has the same containing block as this
// element, so |total_sticky_box_sticky_offset_| does not accumulate // element, so |total_sticky_box_sticky_offset| does not accumulate
// containing block sticky offsets. For example, consider the following chain: // containing block sticky offsets. For example, consider the following chain:
// //
// <div style="position: sticky;"> // <div style="position: sticky;">
...@@ -241,13 +158,16 @@ class StickyPositionScrollingConstraints final { ...@@ -241,13 +158,16 @@ class StickyPositionScrollingConstraints final {
// //
// In the above example, both outerInline and innerInline have the same // In the above example, both outerInline and innerInline have the same
// containing block - the outermost <div>. // containing block - the outermost <div>.
FloatSize total_sticky_box_sticky_offset_; FloatSize total_sticky_box_sticky_offset;
// The containing block offset accumulates all sticky-related offsets between // The containing block offset accumulates all sticky-related offsets between
// this element and the ancestor scroller. If this element is a containing // this element and the ancestor scroller. If this element is a containing
// block shifting ancestor for some descendant, it shifts the descendant's // block shifting ancestor for some descendant, it shifts the descendant's
// constraint rects by its entire offset. // constraint rects by its entire offset.
FloatSize total_containing_block_sticky_offset_; FloatSize total_containing_block_sticky_offset;
FloatSize AncestorStickyBoxOffset(const StickyConstraintsMap&) const;
FloatSize AncestorContainingBlockOffset(const StickyConstraintsMap&) const;
}; };
} // namespace blink } // namespace blink
......
...@@ -351,28 +351,20 @@ void CompositedLayerMapping::UpdateStickyConstraints( ...@@ -351,28 +351,20 @@ void CompositedLayerMapping::UpdateStickyConstraints(
constraints_map.at(&owning_layer_); constraints_map.at(&owning_layer_);
constraint.is_sticky = true; constraint.is_sticky = true;
constraint.is_anchored_left = constraint.is_anchored_left = constraints.is_anchored_left;
constraints.GetAnchorEdges() & constraint.is_anchored_right = constraints.is_anchored_right;
StickyPositionScrollingConstraints::kAnchorEdgeLeft; constraint.is_anchored_top = constraints.is_anchored_top;
constraint.is_anchored_right = constraint.is_anchored_bottom = constraints.is_anchored_bottom;
constraints.GetAnchorEdges() & constraint.left_offset = constraints.left_offset;
StickyPositionScrollingConstraints::kAnchorEdgeRight; constraint.right_offset = constraints.right_offset;
constraint.is_anchored_top = constraint.top_offset = constraints.top_offset;
constraints.GetAnchorEdges() & constraint.bottom_offset = constraints.bottom_offset;
StickyPositionScrollingConstraints::kAnchorEdgeTop;
constraint.is_anchored_bottom =
constraints.GetAnchorEdges() &
StickyPositionScrollingConstraints::kAnchorEdgeBottom;
constraint.left_offset = constraints.LeftOffset();
constraint.right_offset = constraints.RightOffset();
constraint.top_offset = constraints.TopOffset();
constraint.bottom_offset = constraints.BottomOffset();
constraint.scroll_container_relative_sticky_box_rect = constraint.scroll_container_relative_sticky_box_rect =
RoundedIntRect(constraints.ScrollContainerRelativeStickyBoxRect()); RoundedIntRect(constraints.scroll_container_relative_sticky_box_rect);
constraint.scroll_container_relative_containing_block_rect = constraint.scroll_container_relative_containing_block_rect = RoundedIntRect(
RoundedIntRect(constraints.ScrollContainerRelativeContainingBlockRect()); constraints.scroll_container_relative_containing_block_rect);
PaintLayer* sticky_box_shifting_ancestor = PaintLayer* sticky_box_shifting_ancestor =
constraints.NearestStickyLayerShiftingStickyBox(); constraints.nearest_sticky_layer_shifting_sticky_box;
if (sticky_box_shifting_ancestor && if (sticky_box_shifting_ancestor &&
sticky_box_shifting_ancestor->GetCompositedLayerMapping()) { sticky_box_shifting_ancestor->GetCompositedLayerMapping()) {
constraint.nearest_element_shifting_sticky_box = constraint.nearest_element_shifting_sticky_box =
...@@ -381,7 +373,7 @@ void CompositedLayerMapping::UpdateStickyConstraints( ...@@ -381,7 +373,7 @@ void CompositedLayerMapping::UpdateStickyConstraints(
->GetElementId(); ->GetElementId();
} }
PaintLayer* containing_block_shifting_ancestor = PaintLayer* containing_block_shifting_ancestor =
constraints.NearestStickyLayerShiftingContainingBlock(); constraints.nearest_sticky_layer_shifting_containing_block;
if (containing_block_shifting_ancestor && if (containing_block_shifting_ancestor &&
containing_block_shifting_ancestor->GetCompositedLayerMapping()) { containing_block_shifting_ancestor->GetCompositedLayerMapping()) {
constraint.nearest_element_shifting_containing_block = constraint.nearest_element_shifting_containing_block =
......
...@@ -351,15 +351,9 @@ void PaintLayer::UpdateLayerPositionRecursive( ...@@ -351,15 +351,9 @@ void PaintLayer::UpdateLayerPositionRecursive(
} }
bool PaintLayer::SticksToScroller() const { bool PaintLayer::SticksToScroller() const {
if (GetLayoutObject().StyleRef().GetPosition() != EPosition::kSticky) if (!GetLayoutObject().StyleRef().HasStickyConstrainedPosition())
return false; return false;
if (auto* ancestor_scrollable_area = return AncestorOverflowLayer()->GetScrollableArea();
AncestorOverflowLayer()->GetScrollableArea()) {
return ancestor_scrollable_area->GetStickyConstraintsMap()
.at(const_cast<PaintLayer*>(this))
.GetAnchorEdges();
}
return false;
} }
bool PaintLayer::FixedToViewport() const { bool PaintLayer::FixedToViewport() const {
......
...@@ -65,7 +65,6 @@ class LayoutScrollbarPart; ...@@ -65,7 +65,6 @@ class LayoutScrollbarPart;
struct PaintInvalidatorContext; struct PaintInvalidatorContext;
class PaintLayer; class PaintLayer;
class ScrollingCoordinator; class ScrollingCoordinator;
class StickyPositionScrollingConstraints;
class SubtreeLayoutScope; class SubtreeLayoutScope;
struct CORE_EXPORT PaintLayerScrollableAreaRareData { struct CORE_EXPORT PaintLayerScrollableAreaRareData {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment