OLD | NEW |
---|---|
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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 layoutObject.isVideo(); | 166 layoutObject.isVideo(); |
167 } | 167 } |
168 | 168 |
169 // Get the scrolling coordinator in a way that works inside | 169 // Get the scrolling coordinator in a way that works inside |
170 // CompositedLayerMapping's destructor. | 170 // CompositedLayerMapping's destructor. |
171 static ScrollingCoordinator* scrollingCoordinatorFromLayer(PaintLayer& layer) { | 171 static ScrollingCoordinator* scrollingCoordinatorFromLayer(PaintLayer& layer) { |
172 Page* page = layer.layoutObject().frame()->page(); | 172 Page* page = layer.layoutObject().frame()->page(); |
173 return (!page) ? nullptr : page->scrollingCoordinator(); | 173 return (!page) ? nullptr : page->scrollingCoordinator(); |
174 } | 174 } |
175 | 175 |
176 static const LayoutBoxModelObject* nearestCompositedStickyAncestor( | |
chrishtr
2017/03/20 17:24:52
I assume one of the layout tests exercises each of
smcgruer
2017/03/21 13:54:54
Hrm, this is a good question to raise. There are b
smcgruer
2017/03/21 16:01:25
Ok, flackr and I discussed this and realized that
smcgruer
2017/03/21 17:37:48
Done.
| |
177 const StickyConstraintsMap& constraintsMap, | |
178 const StickyPositionScrollingConstraints& constraints) { | |
179 const LayoutBoxModelObject* obj = constraints.nearestStickyAncestor(); | |
180 while (obj && !obj->layer()->compositedLayerMapping()) { | |
181 DCHECK(constraintsMap.contains(obj->layer())); | |
182 obj = constraintsMap.at(obj->layer()).nearestStickyAncestor(); | |
183 } | |
184 return obj; | |
185 } | |
186 | |
187 // Return the id of the nearest composited sticky layer that shifts | |
188 // |constraints| sticky box, or kInvalidLayerId if no such layer exists. | |
189 static int nearestCompositedStickyLayerShiftingStickyBox( | |
190 const StickyConstraintsMap& constraintsMap, | |
191 const StickyPositionScrollingConstraints& constraints) { | |
192 LayoutBoxModelObject* obj = constraints.nearestStickyBoxShiftingStickyBox(); | |
193 while (obj && !obj->layer()->compositedLayerMapping()) { | |
194 DCHECK(constraintsMap.contains(obj->layer())); | |
195 obj = constraintsMap.at(obj->layer()).nearestStickyBoxShiftingStickyBox(); | |
196 } | |
197 | |
198 if (!obj) | |
199 return WebLayer::kInvalidLayerId; | |
200 | |
201 return obj->layer() | |
202 ->compositedLayerMapping() | |
203 ->mainGraphicsLayer() | |
204 ->platformLayer() | |
205 ->id(); | |
206 } | |
207 | |
208 // Return the id of the nearest composited sticky layer that shifts | |
209 // |constraints| containing block, or kInvalidLayerId if no such layer exists. | |
210 static int nearestCompositedStickyLayerShiftingContainingBlock( | |
211 const StickyConstraintsMap& constraintsMap, | |
212 const StickyPositionScrollingConstraints& constraints) { | |
213 LayoutBoxModelObject* obj = | |
214 constraints.nearestStickyBoxShiftingContainingBlock(); | |
215 while (obj && !obj->layer()->compositedLayerMapping()) { | |
216 DCHECK(constraintsMap.contains(obj->layer())); | |
217 obj = constraintsMap.at(obj->layer()) | |
218 .nearestStickyBoxShiftingContainingBlock(); | |
219 } | |
220 | |
221 if (!obj) | |
222 return WebLayer::kInvalidLayerId; | |
223 | |
224 return obj->layer() | |
225 ->compositedLayerMapping() | |
226 ->mainGraphicsLayer() | |
227 ->platformLayer() | |
228 ->id(); | |
229 } | |
230 | |
176 CompositedLayerMapping::CompositedLayerMapping(PaintLayer& layer) | 231 CompositedLayerMapping::CompositedLayerMapping(PaintLayer& layer) |
177 : m_owningLayer(layer), | 232 : m_owningLayer(layer), |
178 m_contentOffsetInCompositingLayerDirty(false), | 233 m_contentOffsetInCompositingLayerDirty(false), |
179 m_pendingUpdateScope(GraphicsLayerUpdateNone), | 234 m_pendingUpdateScope(GraphicsLayerUpdateNone), |
180 m_isMainFrameLayoutViewLayer(false), | 235 m_isMainFrameLayoutViewLayer(false), |
181 m_backgroundLayerPaintsFixedRootBackground(false), | 236 m_backgroundLayerPaintsFixedRootBackground(false), |
182 m_scrollingContentsAreEmpty(false), | 237 m_scrollingContentsAreEmpty(false), |
183 m_backgroundPaintsOntoScrollingContentsLayer(false), | 238 m_backgroundPaintsOntoScrollingContentsLayer(false), |
184 m_backgroundPaintsOntoGraphicsLayer(false), | 239 m_backgroundPaintsOntoGraphicsLayer(false), |
185 m_drawsBackgroundOntoContentLayer(false) { | 240 m_drawsBackgroundOntoContentLayer(false) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 if (sticky) { | 356 if (sticky) { |
302 if (!ancestorOverflowLayer->isRootLayer()) { | 357 if (!ancestorOverflowLayer->isRootLayer()) { |
303 sticky = ancestorOverflowLayer->needsCompositedScrolling(); | 358 sticky = ancestorOverflowLayer->needsCompositedScrolling(); |
304 } else { | 359 } else { |
305 sticky = layoutObject().view()->frameView()->isScrollable(); | 360 sticky = layoutObject().view()->frameView()->isScrollable(); |
306 } | 361 } |
307 } | 362 } |
308 | 363 |
309 WebLayerStickyPositionConstraint webConstraint; | 364 WebLayerStickyPositionConstraint webConstraint; |
310 if (sticky) { | 365 if (sticky) { |
366 const StickyConstraintsMap& constraintsMap = | |
367 ancestorOverflowLayer->getScrollableArea()->stickyConstraintsMap(); | |
311 const StickyPositionScrollingConstraints& constraints = | 368 const StickyPositionScrollingConstraints& constraints = |
312 ancestorOverflowLayer->getScrollableArea()->stickyConstraintsMap().at( | 369 constraintsMap.at(&m_owningLayer); |
313 &m_owningLayer); | |
314 | 370 |
315 // Find the layout offset of the unshifted sticky box within its | 371 // Find the layout offset of the unshifted sticky box within its parent |
316 // compositingContainer. If the enclosing layer is not the scroller, then | 372 // composited layer. This information is used by the compositor side to |
317 // the offset must be adjusted to include the scroll offset to keep it | 373 // compute the additional offset required to keep the element stuck under |
318 // relative to compositingContainer. | 374 // compositor scrolling. |
375 // | |
376 // Starting from the scroll container relative location, removing the | |
377 // enclosing layers offset and the content offset in the composited layer | |
chrishtr
2017/03/20 17:24:52
nit: "layer's"
smcgruer
2017/03/21 13:54:54
Done.
| |
378 // results in the parent-layer relative offset. | |
379 FloatPoint parentRelativeStickyBoxOffset = | |
380 constraints.scrollContainerRelativeStickyBoxRect().location(); | |
381 | |
382 // The enclosing layers offset returned from |convertToLayerCoords| must be | |
383 // adjusted for both scroll and ancestor sticky elements. | |
319 LayoutPoint enclosingLayerOffset; | 384 LayoutPoint enclosingLayerOffset; |
320 compositingContainer->convertToLayerCoords(ancestorOverflowLayer, | 385 compositingContainer->convertToLayerCoords(ancestorOverflowLayer, |
321 enclosingLayerOffset); | 386 enclosingLayerOffset); |
322 if (compositingContainer != ancestorOverflowLayer) { | 387 if (compositingContainer != ancestorOverflowLayer) { |
323 enclosingLayerOffset += LayoutSize( | 388 enclosingLayerOffset += LayoutSize( |
324 ancestorOverflowLayer->getScrollableArea()->getScrollOffset()); | 389 ancestorOverflowLayer->getScrollableArea()->getScrollOffset()); |
325 } | 390 } |
391 if (const LayoutBoxModelObject* ancestor = | |
392 nearestCompositedStickyAncestor(constraintsMap, constraints)) { | |
393 enclosingLayerOffset -= | |
394 roundedIntSize(constraintsMap.at(ancestor->layer()) | |
395 .getTotalContainingBlockStickyOffset()); | |
396 } | |
326 | 397 |
327 FloatPoint stickyBoxOffset = | |
328 constraints.scrollContainerRelativeStickyBoxRect().location(); | |
329 DCHECK(!m_contentOffsetInCompositingLayerDirty); | 398 DCHECK(!m_contentOffsetInCompositingLayerDirty); |
330 stickyBoxOffset.moveBy(FloatPoint(-enclosingLayerOffset) - | 399 parentRelativeStickyBoxOffset.moveBy( |
331 FloatSize(contentOffsetInCompositingLayer())); | 400 FloatPoint(-enclosingLayerOffset) - |
401 FloatSize(contentOffsetInCompositingLayer())); | |
332 | 402 |
333 webConstraint.isSticky = true; | 403 webConstraint.isSticky = true; |
334 webConstraint.isAnchoredLeft = | 404 webConstraint.isAnchoredLeft = |
335 constraints.anchorEdges() & | 405 constraints.anchorEdges() & |
336 StickyPositionScrollingConstraints::AnchorEdgeLeft; | 406 StickyPositionScrollingConstraints::AnchorEdgeLeft; |
337 webConstraint.isAnchoredRight = | 407 webConstraint.isAnchoredRight = |
338 constraints.anchorEdges() & | 408 constraints.anchorEdges() & |
339 StickyPositionScrollingConstraints::AnchorEdgeRight; | 409 StickyPositionScrollingConstraints::AnchorEdgeRight; |
340 webConstraint.isAnchoredTop = | 410 webConstraint.isAnchoredTop = |
341 constraints.anchorEdges() & | 411 constraints.anchorEdges() & |
342 StickyPositionScrollingConstraints::AnchorEdgeTop; | 412 StickyPositionScrollingConstraints::AnchorEdgeTop; |
343 webConstraint.isAnchoredBottom = | 413 webConstraint.isAnchoredBottom = |
344 constraints.anchorEdges() & | 414 constraints.anchorEdges() & |
345 StickyPositionScrollingConstraints::AnchorEdgeBottom; | 415 StickyPositionScrollingConstraints::AnchorEdgeBottom; |
346 webConstraint.leftOffset = constraints.leftOffset(); | 416 webConstraint.leftOffset = constraints.leftOffset(); |
347 webConstraint.rightOffset = constraints.rightOffset(); | 417 webConstraint.rightOffset = constraints.rightOffset(); |
348 webConstraint.topOffset = constraints.topOffset(); | 418 webConstraint.topOffset = constraints.topOffset(); |
349 webConstraint.bottomOffset = constraints.bottomOffset(); | 419 webConstraint.bottomOffset = constraints.bottomOffset(); |
350 webConstraint.parentRelativeStickyBoxOffset = | 420 webConstraint.parentRelativeStickyBoxOffset = parentRelativeStickyBoxOffset; |
351 roundedIntPoint(stickyBoxOffset); | |
352 webConstraint.scrollContainerRelativeStickyBoxRect = | 421 webConstraint.scrollContainerRelativeStickyBoxRect = |
353 enclosingIntRect(constraints.scrollContainerRelativeStickyBoxRect()); | 422 constraints.scrollContainerRelativeStickyBoxRect(); |
354 webConstraint.scrollContainerRelativeContainingBlockRect = enclosingIntRect( | 423 webConstraint.scrollContainerRelativeContainingBlockRect = |
355 constraints.scrollContainerRelativeContainingBlockRect()); | 424 constraints.scrollContainerRelativeContainingBlockRect(); |
356 // TODO(smcgruer): Copy fields for nested sticky in cc (crbug.com/672710) | 425 webConstraint.nearestLayerShiftingStickyBox = |
426 nearestCompositedStickyLayerShiftingStickyBox(constraintsMap, | |
427 constraints); | |
428 webConstraint.nearestLayerShiftingContainingBlock = | |
429 nearestCompositedStickyLayerShiftingContainingBlock(constraintsMap, | |
430 constraints); | |
357 } | 431 } |
358 | 432 |
359 m_graphicsLayer->setStickyPositionConstraint(webConstraint); | 433 m_graphicsLayer->setStickyPositionConstraint(webConstraint); |
360 } | 434 } |
361 | 435 |
362 void CompositedLayerMapping::updateLayerBlendMode(const ComputedStyle& style) { | 436 void CompositedLayerMapping::updateLayerBlendMode(const ComputedStyle& style) { |
363 setBlendMode(style.blendMode()); | 437 setBlendMode(style.blendMode()); |
364 } | 438 } |
365 | 439 |
366 void CompositedLayerMapping::updateIsRootForIsolatedGroup() { | 440 void CompositedLayerMapping::updateIsRootForIsolatedGroup() { |
(...skipping 3131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3498 } else if (graphicsLayer == m_decorationOutlineLayer.get()) { | 3572 } else if (graphicsLayer == m_decorationOutlineLayer.get()) { |
3499 name = "Decoration Layer"; | 3573 name = "Decoration Layer"; |
3500 } else { | 3574 } else { |
3501 ASSERT_NOT_REACHED(); | 3575 ASSERT_NOT_REACHED(); |
3502 } | 3576 } |
3503 | 3577 |
3504 return name; | 3578 return name; |
3505 } | 3579 } |
3506 | 3580 |
3507 } // namespace blink | 3581 } // namespace blink |
OLD | NEW |