Bug 1267438 - Factor out a helper function to check if a layer is fixed or sticky. r=mstange
MozReview-Commit-ID: A1qrxW3KVVE
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -377,39 +377,45 @@ AsyncTransformShouldBeUnapplied(Layer* a
// don't intend to match.
if (current && current.AsRefLayer() != nullptr) {
break;
}
}
return false;
}
+// If |aLayer| is fixed or sticky, returns the scroll id of the scroll frame
+// that it's fixed or sticky to. Otherwise, returns Nothing().
+static Maybe<FrameMetrics::ViewID>
+IsFixedOrSticky(Layer* aLayer)
+{
+ bool isRootOfFixedSubtree = aLayer->GetIsFixedPosition() &&
+ !aLayer->GetParent()->GetIsFixedPosition();
+ if (isRootOfFixedSubtree) {
+ return Some(aLayer->GetFixedPositionScrollContainerId());
+ }
+ if (aLayer->GetIsStickyPosition()) {
+ return Some(aLayer->GetStickyScrollContainerId());
+ }
+ return Nothing();
+}
+
void
AsyncCompositionManager::AlignFixedAndStickyLayers(Layer* aLayer,
Layer* aTransformedSubtreeRoot,
FrameMetrics::ViewID aTransformScrollId,
const LayerToParentLayerMatrix4x4& aPreviousTransformForRoot,
const LayerToParentLayerMatrix4x4& aCurrentTransformForRoot,
const ScreenMargin& aFixedLayerMargins,
bool aTransformAffectsLayerClip)
{
- FrameMetrics::ViewID fixedTo; // the scroll id of the scroll frame we are fixed/sticky to
- bool isRootOfFixedSubtree = aLayer->GetIsFixedPosition() &&
- !aLayer->GetParent()->GetIsFixedPosition();
- if (isRootOfFixedSubtree) {
- fixedTo = aLayer->GetFixedPositionScrollContainerId();
- }
- bool isSticky = aLayer->GetIsStickyPosition();
- if (isSticky) {
- fixedTo = aLayer->GetStickyScrollContainerId();
- }
bool needsAsyncTransformUnapplied = false;
- if (isRootOfFixedSubtree || isSticky) {
+ if (Maybe<FrameMetrics::ViewID> fixedTo = IsFixedOrSticky(aLayer)) {
needsAsyncTransformUnapplied = AsyncTransformShouldBeUnapplied(aLayer,
- fixedTo, aTransformedSubtreeRoot, aTransformScrollId);
+ *fixedTo, aTransformedSubtreeRoot, aTransformScrollId);
}
// We want to process all the fixed and sticky descendants of
// aTransformedSubtreeRoot. Once we do encounter such a descendant, we don't
// need to recurse any deeper because the adjustment to the fixed or sticky
// layer will apply to its subtree.
if (!needsAsyncTransformUnapplied) {
for (Layer* child = aLayer->GetFirstChild(); child; child = child->GetNextSibling()) {