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

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

Issue 2929873002: Shifting layer position for sticky element to avoid passing unnessary variable to cc (Closed)
Patch Set: nit Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 void CompositedLayerMapping::UpdateFilters(const ComputedStyle& style) { 274 void CompositedLayerMapping::UpdateFilters(const ComputedStyle& style) {
275 graphics_layer_->SetFilters( 275 graphics_layer_->SetFilters(
276 OwningLayer().CreateCompositorFilterOperationsForFilter(style)); 276 OwningLayer().CreateCompositorFilterOperationsForFilter(style));
277 } 277 }
278 278
279 void CompositedLayerMapping::UpdateBackdropFilters(const ComputedStyle& style) { 279 void CompositedLayerMapping::UpdateBackdropFilters(const ComputedStyle& style) {
280 graphics_layer_->SetBackdropFilters( 280 graphics_layer_->SetBackdropFilters(
281 OwningLayer().CreateCompositorFilterOperationsForBackdropFilter(style)); 281 OwningLayer().CreateCompositorFilterOperationsForBackdropFilter(style));
282 } 282 }
283 283
284 bool CompositedLayerMapping::UsesCompositedStickyPosition() const {
285 return GetLayoutObject().Style()->GetPosition() == EPosition::kSticky &&
286 (owning_layer_.AncestorOverflowLayer()->IsRootLayer()
287 ? GetLayoutObject().View()->GetFrameView()->IsScrollable()
288 : owning_layer_.AncestorOverflowLayer()
289 ->NeedsCompositedScrolling());
290 }
291
284 void CompositedLayerMapping::UpdateStickyConstraints( 292 void CompositedLayerMapping::UpdateStickyConstraints(
285 const ComputedStyle& style) { 293 const ComputedStyle& style) {
286 bool sticky = style.GetPosition() == EPosition::kSticky;
287 const PaintLayer* ancestor_overflow_layer = 294 const PaintLayer* ancestor_overflow_layer =
288 owning_layer_.AncestorOverflowLayer(); 295 owning_layer_.AncestorOverflowLayer();
289 // TODO(flackr): Do we still need this?
290 if (sticky) {
291 if (!ancestor_overflow_layer->IsRootLayer()) {
292 sticky = ancestor_overflow_layer->NeedsCompositedScrolling();
293 } else {
294 sticky = GetLayoutObject().View()->GetFrameView()->IsScrollable();
295 }
296 }
297
298 WebLayerStickyPositionConstraint web_constraint; 296 WebLayerStickyPositionConstraint web_constraint;
299 if (sticky) { 297 if (UsesCompositedStickyPosition()) {
trchen 2017/06/09 20:20:36 nits: Prefer shorter branch first, early out first
chrishtr 2017/06/09 20:28:07 Is this if statement just an optimization? If so,
yigu 2017/06/09 20:52:39 It seems that we call UpdateStickyConstraints unco
chrishtr 2017/06/09 20:58:29 I would like to get rid of the UsesCompositedStick
flackr 2017/06/10 00:25:05 We would still have to check UsesCompositedStickyP
300 const StickyConstraintsMap& constraints_map = 298 const StickyConstraintsMap& constraints_map =
301 ancestor_overflow_layer->GetScrollableArea()->GetStickyConstraintsMap(); 299 ancestor_overflow_layer->GetScrollableArea()->GetStickyConstraintsMap();
302 const StickyPositionScrollingConstraints& constraints = 300 const StickyPositionScrollingConstraints& constraints =
303 constraints_map.at(&owning_layer_); 301 constraints_map.at(&owning_layer_);
304 302
305 web_constraint.is_sticky = true; 303 web_constraint.is_sticky = true;
306 web_constraint.is_anchored_left = 304 web_constraint.is_anchored_left =
307 constraints.GetAnchorEdges() & 305 constraints.GetAnchorEdges() &
308 StickyPositionScrollingConstraints::kAnchorEdgeLeft; 306 StickyPositionScrollingConstraints::kAnchorEdgeLeft;
309 web_constraint.is_anchored_right = 307 web_constraint.is_anchored_right =
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 UpdateScrollParent(ScrollParent()); 1119 UpdateScrollParent(ScrollParent());
1122 RegisterScrollingLayers(); 1120 RegisterScrollingLayers();
1123 1121
1124 UpdateCompositingReasons(); 1122 UpdateCompositingReasons();
1125 } 1123 }
1126 1124
1127 void CompositedLayerMapping::UpdateMainGraphicsLayerGeometry( 1125 void CompositedLayerMapping::UpdateMainGraphicsLayerGeometry(
1128 const IntRect& relative_compositing_bounds, 1126 const IntRect& relative_compositing_bounds,
1129 const IntRect& local_compositing_bounds, 1127 const IntRect& local_compositing_bounds,
1130 const IntPoint& graphics_layer_parent_location) { 1128 const IntPoint& graphics_layer_parent_location) {
1131 graphics_layer_->SetPosition(FloatPoint( 1129 // Find and remove the offset applied for sticky position if the compositor
1132 relative_compositing_bounds.Location() - graphics_layer_parent_location)); 1130 // will shift the layer for sticky position to avoid offsetting the layer
1133 graphics_layer_->SetOffsetFromLayoutObject( 1131 // twice.
1134 ToIntSize(local_compositing_bounds.Location())); 1132 FloatSize offset_for_sticky_position;
1135 // Find the layout offset of the unshifted sticky box within its parent 1133 if (UsesCompositedStickyPosition()) {
1136 // composited layer. This information is used by the compositor side to
1137 // compute the additional offset required to keep the element stuck under
1138 // compositor scrolling.
1139 FloatSize main_thread_sticky_offset;
1140 if (GetLayoutObject().Style()->GetPosition() == EPosition::kSticky) {
1141 const StickyConstraintsMap& constraints_map = 1134 const StickyConstraintsMap& constraints_map =
1142 owning_layer_.AncestorOverflowLayer() 1135 owning_layer_.AncestorOverflowLayer()
1143 ->GetScrollableArea() 1136 ->GetScrollableArea()
1144 ->GetStickyConstraintsMap(); 1137 ->GetStickyConstraintsMap();
1145 const StickyPositionScrollingConstraints& constraints = 1138 const StickyPositionScrollingConstraints& constraints =
1146 constraints_map.at(&owning_layer_); 1139 constraints_map.at(&owning_layer_);
1147 1140
1148 main_thread_sticky_offset = 1141 offset_for_sticky_position =
1149 constraints.GetOffsetForStickyPosition(constraints_map); 1142 constraints.GetOffsetForStickyPosition(constraints_map);
1150 } 1143 }
1151 graphics_layer_->SetOffsetForStickyPosition( 1144 graphics_layer_->SetPosition(
1152 RoundedIntSize(main_thread_sticky_offset)); 1145 FloatPoint(relative_compositing_bounds.Location() -
1146 graphics_layer_parent_location) -
1147 offset_for_sticky_position);
1148 graphics_layer_->SetOffsetFromLayoutObject(
1149 ToIntSize(local_compositing_bounds.Location()));
1153 1150
1154 FloatSize old_size = graphics_layer_->Size(); 1151 FloatSize old_size = graphics_layer_->Size();
1155 const FloatSize contents_size(relative_compositing_bounds.Size()); 1152 const FloatSize contents_size(relative_compositing_bounds.Size());
1156 if (old_size != contents_size) 1153 if (old_size != contents_size)
1157 graphics_layer_->SetSize(contents_size); 1154 graphics_layer_->SetSize(contents_size);
1158 1155
1159 // m_graphicsLayer is the corresponding GraphicsLayer for this PaintLayer and 1156 // m_graphicsLayer is the corresponding GraphicsLayer for this PaintLayer and
1160 // its non-compositing descendants. So, the visibility flag for 1157 // its non-compositing descendants. So, the visibility flag for
1161 // m_graphicsLayer should be true if there are any non-compositing visible 1158 // m_graphicsLayer should be true if there are any non-compositing visible
1162 // layers. 1159 // layers.
(...skipping 2477 matching lines...) Expand 10 before | Expand all | Expand 10 after
3640 } else if (graphics_layer == decoration_outline_layer_.get()) { 3637 } else if (graphics_layer == decoration_outline_layer_.get()) {
3641 name = "Decoration Layer"; 3638 name = "Decoration Layer";
3642 } else { 3639 } else {
3643 NOTREACHED(); 3640 NOTREACHED();
3644 } 3641 }
3645 3642
3646 return name; 3643 return name;
3647 } 3644 }
3648 3645
3649 } // namespace blink 3646 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698