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

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: Bug fix 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? 296 WebLayerStickyPositionConstraint web_constraint;
290 if (sticky) { 297 const StickyConstraintsMap& constraints_map =
291 if (!ancestor_overflow_layer->IsRootLayer()) { 298 ancestor_overflow_layer->GetScrollableArea()->GetStickyConstraintsMap();
292 sticky = ancestor_overflow_layer->NeedsCompositedScrolling(); 299 const StickyPositionScrollingConstraints& constraints =
293 } else { 300 constraints_map.at(&owning_layer_);
294 sticky = GetLayoutObject().View()->GetFrameView()->IsScrollable(); 301
295 } 302 web_constraint.is_sticky = true;
303 web_constraint.is_anchored_left =
304 constraints.GetAnchorEdges() &
305 StickyPositionScrollingConstraints::kAnchorEdgeLeft;
306 web_constraint.is_anchored_right =
307 constraints.GetAnchorEdges() &
308 StickyPositionScrollingConstraints::kAnchorEdgeRight;
309 web_constraint.is_anchored_top =
310 constraints.GetAnchorEdges() &
311 StickyPositionScrollingConstraints::kAnchorEdgeTop;
312 web_constraint.is_anchored_bottom =
313 constraints.GetAnchorEdges() &
314 StickyPositionScrollingConstraints::kAnchorEdgeBottom;
315 web_constraint.left_offset = constraints.LeftOffset();
316 web_constraint.right_offset = constraints.RightOffset();
317 web_constraint.top_offset = constraints.TopOffset();
318 web_constraint.bottom_offset = constraints.BottomOffset();
319 web_constraint.scroll_container_relative_sticky_box_rect =
320 EnclosingIntRect(constraints.ScrollContainerRelativeStickyBoxRect());
321 web_constraint.scroll_container_relative_containing_block_rect =
322 EnclosingIntRect(
323 constraints.ScrollContainerRelativeContainingBlockRect());
324 // TODO(smcgruer): Until http://crbug.com/702229 is fixed, the nearest
325 // sticky layers may not be composited and we may incorrectly end up with
326 // invalid layer IDs.
327 LayoutBoxModelObject* sticky_box_shifting_ancestor =
328 constraints.NearestStickyBoxShiftingStickyBox();
329 if (sticky_box_shifting_ancestor &&
330 sticky_box_shifting_ancestor->Layer()->GetCompositedLayerMapping()) {
331 web_constraint.nearest_layer_shifting_sticky_box =
332 sticky_box_shifting_ancestor->Layer()
333 ->GetCompositedLayerMapping()
334 ->MainGraphicsLayer()
335 ->PlatformLayer()
336 ->Id();
296 } 337 }
297 338 LayoutBoxModelObject* containing_block_shifting_ancestor =
298 WebLayerStickyPositionConstraint web_constraint; 339 constraints.NearestStickyBoxShiftingContainingBlock();
299 if (sticky) { 340 if (containing_block_shifting_ancestor &&
300 const StickyConstraintsMap& constraints_map = 341 containing_block_shifting_ancestor->Layer()
301 ancestor_overflow_layer->GetScrollableArea()->GetStickyConstraintsMap(); 342 ->GetCompositedLayerMapping()) {
302 const StickyPositionScrollingConstraints& constraints = 343 web_constraint.nearest_layer_shifting_containing_block =
303 constraints_map.at(&owning_layer_);
304
305 web_constraint.is_sticky = true;
306 web_constraint.is_anchored_left =
307 constraints.GetAnchorEdges() &
308 StickyPositionScrollingConstraints::kAnchorEdgeLeft;
309 web_constraint.is_anchored_right =
310 constraints.GetAnchorEdges() &
311 StickyPositionScrollingConstraints::kAnchorEdgeRight;
312 web_constraint.is_anchored_top =
313 constraints.GetAnchorEdges() &
314 StickyPositionScrollingConstraints::kAnchorEdgeTop;
315 web_constraint.is_anchored_bottom =
316 constraints.GetAnchorEdges() &
317 StickyPositionScrollingConstraints::kAnchorEdgeBottom;
318 web_constraint.left_offset = constraints.LeftOffset();
319 web_constraint.right_offset = constraints.RightOffset();
320 web_constraint.top_offset = constraints.TopOffset();
321 web_constraint.bottom_offset = constraints.BottomOffset();
322 web_constraint.scroll_container_relative_sticky_box_rect =
323 EnclosingIntRect(constraints.ScrollContainerRelativeStickyBoxRect());
324 web_constraint.scroll_container_relative_containing_block_rect =
325 EnclosingIntRect(
326 constraints.ScrollContainerRelativeContainingBlockRect());
327 // TODO(smcgruer): Until http://crbug.com/702229 is fixed, the nearest
328 // sticky layers may not be composited and we may incorrectly end up with
329 // invalid layer IDs.
330 LayoutBoxModelObject* sticky_box_shifting_ancestor =
331 constraints.NearestStickyBoxShiftingStickyBox();
332 if (sticky_box_shifting_ancestor &&
333 sticky_box_shifting_ancestor->Layer()->GetCompositedLayerMapping()) {
334 web_constraint.nearest_layer_shifting_sticky_box =
335 sticky_box_shifting_ancestor->Layer()
336 ->GetCompositedLayerMapping()
337 ->MainGraphicsLayer()
338 ->PlatformLayer()
339 ->Id();
340 }
341 LayoutBoxModelObject* containing_block_shifting_ancestor =
342 constraints.NearestStickyBoxShiftingContainingBlock();
343 if (containing_block_shifting_ancestor &&
344 containing_block_shifting_ancestor->Layer() 344 containing_block_shifting_ancestor->Layer()
345 ->GetCompositedLayerMapping()) { 345 ->GetCompositedLayerMapping()
346 web_constraint.nearest_layer_shifting_containing_block = 346 ->MainGraphicsLayer()
347 containing_block_shifting_ancestor->Layer() 347 ->PlatformLayer()
348 ->GetCompositedLayerMapping() 348 ->Id();
349 ->MainGraphicsLayer()
350 ->PlatformLayer()
351 ->Id();
352 }
353 } 349 }
354 350
355 graphics_layer_->SetStickyPositionConstraint(web_constraint); 351 graphics_layer_->SetStickyPositionConstraint(web_constraint);
356 } 352 }
357 353
358 void CompositedLayerMapping::UpdateLayerBlendMode(const ComputedStyle& style) { 354 void CompositedLayerMapping::UpdateLayerBlendMode(const ComputedStyle& style) {
359 SetBlendMode(style.BlendMode()); 355 SetBlendMode(style.BlendMode());
360 } 356 }
361 357
362 void CompositedLayerMapping::UpdateIsRootForIsolatedGroup() { 358 void CompositedLayerMapping::UpdateIsRootForIsolatedGroup() {
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 FloatSize contents_size(relative_compositing_bounds.Size()); 1059 FloatSize contents_size(relative_compositing_bounds.Size());
1064 1060
1065 UpdateMainGraphicsLayerGeometry(relative_compositing_bounds, 1061 UpdateMainGraphicsLayerGeometry(relative_compositing_bounds,
1066 local_compositing_bounds, 1062 local_compositing_bounds,
1067 graphics_layer_parent_location); 1063 graphics_layer_parent_location);
1068 UpdateOverflowControlsHostLayerGeometry(compositing_stacking_context, 1064 UpdateOverflowControlsHostLayerGeometry(compositing_stacking_context,
1069 compositing_container, 1065 compositing_container,
1070 graphics_layer_parent_location); 1066 graphics_layer_parent_location);
1071 UpdateContentsOffsetInCompositingLayer( 1067 UpdateContentsOffsetInCompositingLayer(
1072 snapped_offset_from_composited_ancestor, graphics_layer_parent_location); 1068 snapped_offset_from_composited_ancestor, graphics_layer_parent_location);
1073 UpdateStickyConstraints(GetLayoutObject().StyleRef()); 1069 if (UsesCompositedStickyPosition())
1070 UpdateStickyConstraints(GetLayoutObject().StyleRef());
1074 UpdateSquashingLayerGeometry( 1071 UpdateSquashingLayerGeometry(
1075 graphics_layer_parent_location, compositing_container, squashed_layers_, 1072 graphics_layer_parent_location, compositing_container, squashed_layers_,
1076 squashing_layer_.get(), 1073 squashing_layer_.get(),
1077 &squashing_layer_offset_from_transformed_ancestor_, 1074 &squashing_layer_offset_from_transformed_ancestor_,
1078 layers_needing_paint_invalidation); 1075 layers_needing_paint_invalidation);
1079 1076
1080 // If we have a layer that clips children, position it. 1077 // If we have a layer that clips children, position it.
1081 IntRect clipping_box; 1078 IntRect clipping_box;
1082 if (child_containment_layer_ && GetLayoutObject().IsBox()) 1079 if (child_containment_layer_ && GetLayoutObject().IsBox())
1083 clipping_box = ClipBox(ToLayoutBox(GetLayoutObject())); 1080 clipping_box = ClipBox(ToLayoutBox(GetLayoutObject()));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 UpdateScrollParent(ScrollParent()); 1118 UpdateScrollParent(ScrollParent());
1122 RegisterScrollingLayers(); 1119 RegisterScrollingLayers();
1123 1120
1124 UpdateCompositingReasons(); 1121 UpdateCompositingReasons();
1125 } 1122 }
1126 1123
1127 void CompositedLayerMapping::UpdateMainGraphicsLayerGeometry( 1124 void CompositedLayerMapping::UpdateMainGraphicsLayerGeometry(
1128 const IntRect& relative_compositing_bounds, 1125 const IntRect& relative_compositing_bounds,
1129 const IntRect& local_compositing_bounds, 1126 const IntRect& local_compositing_bounds,
1130 const IntPoint& graphics_layer_parent_location) { 1127 const IntPoint& graphics_layer_parent_location) {
1131 graphics_layer_->SetPosition(FloatPoint( 1128 // Find and remove the offset applied for sticky position if the compositor
1132 relative_compositing_bounds.Location() - graphics_layer_parent_location)); 1129 // will shift the layer for sticky position to avoid offsetting the layer
1133 graphics_layer_->SetOffsetFromLayoutObject( 1130 // twice.
1134 ToIntSize(local_compositing_bounds.Location())); 1131 FloatSize offset_for_sticky_position;
1135 // Find the layout offset of the unshifted sticky box within its parent 1132 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 = 1133 const StickyConstraintsMap& constraints_map =
1142 owning_layer_.AncestorOverflowLayer() 1134 owning_layer_.AncestorOverflowLayer()
1143 ->GetScrollableArea() 1135 ->GetScrollableArea()
1144 ->GetStickyConstraintsMap(); 1136 ->GetStickyConstraintsMap();
1145 const StickyPositionScrollingConstraints& constraints = 1137 const StickyPositionScrollingConstraints& constraints =
1146 constraints_map.at(&owning_layer_); 1138 constraints_map.at(&owning_layer_);
1147 1139
1148 main_thread_sticky_offset = 1140 offset_for_sticky_position =
1149 constraints.GetOffsetForStickyPosition(constraints_map); 1141 constraints.GetOffsetForStickyPosition(constraints_map);
1150 } 1142 }
1151 graphics_layer_->SetOffsetForStickyPosition( 1143 graphics_layer_->SetPosition(
1152 RoundedIntSize(main_thread_sticky_offset)); 1144 FloatPoint(relative_compositing_bounds.Location() -
1145 graphics_layer_parent_location) -
1146 offset_for_sticky_position);
1147 graphics_layer_->SetOffsetFromLayoutObject(
1148 ToIntSize(local_compositing_bounds.Location()));
1153 1149
1154 FloatSize old_size = graphics_layer_->Size(); 1150 FloatSize old_size = graphics_layer_->Size();
1155 const FloatSize contents_size(relative_compositing_bounds.Size()); 1151 const FloatSize contents_size(relative_compositing_bounds.Size());
1156 if (old_size != contents_size) 1152 if (old_size != contents_size)
1157 graphics_layer_->SetSize(contents_size); 1153 graphics_layer_->SetSize(contents_size);
1158 1154
1159 // m_graphicsLayer is the corresponding GraphicsLayer for this PaintLayer and 1155 // m_graphicsLayer is the corresponding GraphicsLayer for this PaintLayer and
1160 // its non-compositing descendants. So, the visibility flag for 1156 // its non-compositing descendants. So, the visibility flag for
1161 // m_graphicsLayer should be true if there are any non-compositing visible 1157 // m_graphicsLayer should be true if there are any non-compositing visible
1162 // layers. 1158 // layers.
(...skipping 2477 matching lines...) Expand 10 before | Expand all | Expand 10 after
3640 } else if (graphics_layer == decoration_outline_layer_.get()) { 3636 } else if (graphics_layer == decoration_outline_layer_.get()) {
3641 name = "Decoration Layer"; 3637 name = "Decoration Layer";
3642 } else { 3638 } else {
3643 NOTREACHED(); 3639 NOTREACHED();
3644 } 3640 }
3645 3641
3646 return name; 3642 return name;
3647 } 3643 }
3648 3644
3649 } // namespace blink 3645 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698