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

Unified Diff: third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.cpp

Issue 2911463002: Unify the calculation of main thread offset of sticky element (Closed)
Patch Set: Move sticky offset computation into method in StickyPositionScrollingConstraints Created 3 years, 7 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/layout/compositing/CompositedLayerMapping.cpp
diff --git a/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.cpp b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.cpp
index 096496646d08d65e0cdb5cfd35bebedfa4fe21d3..351c2c8bbf92a664e14a715a2edc92a5aa78bc2a 100644
--- a/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.cpp
+++ b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.cpp
@@ -282,8 +282,7 @@ void CompositedLayerMapping::UpdateBackdropFilters(const ComputedStyle& style) {
}
void CompositedLayerMapping::UpdateStickyConstraints(
- const ComputedStyle& style,
- const PaintLayer* compositing_container) {
+ const ComputedStyle& style) {
bool sticky = style.GetPosition() == EPosition::kSticky;
const PaintLayer* ancestor_overflow_layer =
owning_layer_.AncestorOverflowLayer();
@@ -303,47 +302,6 @@ void CompositedLayerMapping::UpdateStickyConstraints(
const StickyPositionScrollingConstraints& constraints =
constraints_map.at(&owning_layer_);
- // Find the layout offset of the unshifted sticky box within its parent
- // composited layer. This information is used by the compositor side to
- // compute the additional offset required to keep the element stuck under
- // compositor scrolling.
- //
- // Starting from the scroll container relative location, removing the
- // enclosing layer's offset and the content offset in the composited layer
- // results in the parent-layer relative offset.
- FloatPoint parent_relative_sticky_box_offset =
- constraints.ScrollContainerRelativeStickyBoxRect().Location();
-
- // The enclosing layers offset returned from |convertToLayerCoords| must be
- // adjusted for both scroll and ancestor sticky elements.
- LayoutPoint enclosing_layer_offset;
- compositing_container->ConvertToLayerCoords(ancestor_overflow_layer,
- enclosing_layer_offset);
- DCHECK(!ScrollParent() || ScrollParent() == ancestor_overflow_layer);
- if (!ScrollParent() && compositing_container != ancestor_overflow_layer) {
- enclosing_layer_offset += LayoutSize(
- ancestor_overflow_layer->GetScrollableArea()->GetScrollOffset());
- }
- // TODO(smcgruer): Until http://crbug.com/702229 is fixed, the nearest
- // sticky ancestor may be non-composited which will make this offset wrong.
- if (const LayoutBoxModelObject* ancestor =
- constraints.NearestStickyAncestor()) {
- enclosing_layer_offset -=
- RoundedIntSize(constraints_map.at(ancestor->Layer())
- .GetTotalContainingBlockStickyOffset());
- }
-
- DCHECK(!content_offset_in_compositing_layer_dirty_);
- parent_relative_sticky_box_offset.MoveBy(
- FloatPoint(-enclosing_layer_offset) -
- FloatSize(ContentOffsetInCompositingLayer()));
-
- if (compositing_container != ancestor_overflow_layer) {
- parent_relative_sticky_box_offset.MoveBy(
- FloatPoint(compositing_container->GetCompositedLayerMapping()
- ->ContentOffsetInCompositingLayer()));
- }
-
web_constraint.is_sticky = true;
web_constraint.is_anchored_left =
constraints.GetAnchorEdges() &
@@ -361,8 +319,6 @@ void CompositedLayerMapping::UpdateStickyConstraints(
web_constraint.right_offset = constraints.RightOffset();
web_constraint.top_offset = constraints.TopOffset();
web_constraint.bottom_offset = constraints.BottomOffset();
- web_constraint.parent_relative_sticky_box_offset =
- RoundedIntPoint(parent_relative_sticky_box_offset);
web_constraint.scroll_container_relative_sticky_box_rect =
EnclosingIntRect(constraints.ScrollContainerRelativeStickyBoxRect());
web_constraint.scroll_container_relative_containing_block_rect =
@@ -1113,7 +1069,7 @@ void CompositedLayerMapping::UpdateGraphicsLayerGeometry(
graphics_layer_parent_location);
UpdateContentsOffsetInCompositingLayer(
snapped_offset_from_composited_ancestor, graphics_layer_parent_location);
- UpdateStickyConstraints(GetLayoutObject().StyleRef(), compositing_container);
+ UpdateStickyConstraints(GetLayoutObject().StyleRef());
UpdateSquashingLayerGeometry(
graphics_layer_parent_location, compositing_container, squashed_layers_,
squashing_layer_.get(),
@@ -1175,6 +1131,23 @@ void CompositedLayerMapping::UpdateMainGraphicsLayerGeometry(
relative_compositing_bounds.Location() - graphics_layer_parent_location));
graphics_layer_->SetOffsetFromLayoutObject(
ToIntSize(local_compositing_bounds.Location()));
+ // Find the layout offset of the unshifted sticky box within its parent
+ // composited layer. This information is used by the compositor side to
+ // compute the additional offset required to keep the element stuck under
+ // compositor scrolling.
+ FloatSize main_thread_sticky_offset;
+ if (GetLayoutObject().Style()->GetPosition() == EPosition::kSticky) {
+ const StickyPositionScrollingConstraints& constraints =
+ owning_layer_.AncestorOverflowLayer()
+ ->GetScrollableArea()
+ ->GetStickyConstraintsMap()
+ .at(&owning_layer_);
+
+ main_thread_sticky_offset = constraints.ComputeMainThreadStickyOffset(
+ *GetLayoutObject().Layer()->AncestorOverflowLayer());
flackr 2017/06/02 15:33:58 This can just be owning_layer_.AncestorOverflowLay
yigu 2017/06/02 17:59:56 Done.
+ }
+ graphics_layer_->SetStickyMainThreadOffset(
+ RoundedIntSize(main_thread_sticky_offset));
FloatSize old_size = graphics_layer_->Size();
const FloatSize contents_size(relative_compositing_bounds.Size());

Powered by Google App Engine
This is Rietveld 408576698