Bug 1267438 - Factor out a helper function to check if a layer is fixed or sticky. r=mstange draft
authorBotond Ballo <botond@mozilla.com>
Wed, 04 May 2016 17:32:12 -0400
changeset 364618 d3ad1e0ab2690bb9e55a593ea6d979e234e71e9f
parent 364617 cda1645407959eb39ff3e880078836d35686a8d8
child 364619 4746e1cebf87e6eeda886041c745cfcce985db80
push id17504
push userbballo@mozilla.com
push dateFri, 06 May 2016 23:44:30 +0000
reviewersmstange
bugs1267438
milestone49.0a1
Bug 1267438 - Factor out a helper function to check if a layer is fixed or sticky. r=mstange MozReview-Commit-ID: A1qrxW3KVVE
gfx/layers/composite/AsyncCompositionManager.cpp
--- 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()) {