Bug 930419 - Make position:sticky frames an active scrolled root. r=roc
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 24 Oct 2013 16:35:30 +0200
changeset 166741 a6cad3e7ba5bc1718d4f94504809463ec025514a
parent 166740 89c119add8920a5d15a2459c75bb43ba375a0807
child 166742 20feee5f3866cc9cc09e04034b5704f2738c00c8
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs930419
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 930419 - Make position:sticky frames an active scrolled root. r=roc
layout/base/nsLayoutUtils.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1161,25 +1161,43 @@ nsLayoutUtils::GetScrollableFrameFor(con
   return sf;
 }
 
 nsIFrame*
 nsLayoutUtils::GetActiveScrolledRootFor(nsIFrame* aFrame,
                                         const nsIFrame* aStopAtAncestor)
 {
   nsIFrame* f = aFrame;
+  nsIFrame* stickyFrame = nullptr;
   while (f != aStopAtAncestor) {
     if (IsPopup(f))
       break;
     nsIFrame* parent = GetCrossDocParentFrame(f);
     if (!parent)
       break;
+    // Sticky frames are active if their nearest scrollable frame
+    // is also active, just keep a record of sticky frames that we
+    // encounter for now.
+    if (f->StyleDisplay()->mPosition == NS_STYLE_POSITION_STICKY &&
+        !stickyFrame) {
+      stickyFrame = f;
+    }
     nsIScrollableFrame* sf = do_QueryFrame(parent);
-    if (sf && sf->IsScrollingActive() && sf->GetScrolledFrame() == f)
-      break;
+    if (sf) {
+      if (sf->IsScrollingActive() && sf->GetScrolledFrame() == f) {
+        // If we found a sticky frame inside this active scroll frame,
+        // then use that. Otherwise use the scroll frame.
+        if (stickyFrame) {
+          return stickyFrame;
+        }
+        return f;
+      } else {
+        stickyFrame = nullptr;
+      }
+    }
     f = parent;
   }
   return f;
 }
 
 nsIFrame*
 nsLayoutUtils::GetActiveScrolledRootFor(nsDisplayItem* aItem,
                                         nsDisplayListBuilder* aBuilder,