Bug 1321698 part 3: Fold nsFlexContainerFrame's old IsLegacyBox() function into its only remaining caller, nsFlexContainerFrame::Init(). r?mats draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Fri, 02 Dec 2016 10:44:07 -0800
changeset 447132 0e31d268dd118daebd1c86875b7a7c0b14ea5d02
parent 447131 0a9e41868f9a01758956834b925a6c1f92543126
child 538977 00957420740a3ec60bc42dfcc5570e570ea5f5bf
push id37996
push userdholbert@mozilla.com
push dateFri, 02 Dec 2016 18:51:22 +0000
reviewersmats
bugs1321698
milestone53.0a1
Bug 1321698 part 3: Fold nsFlexContainerFrame's old IsLegacyBox() function into its only remaining caller, nsFlexContainerFrame::Init(). r?mats This patch is to prevent any new callers of this API, since we can now rely on the new frame state bit (NS_STATE_FLEX_IS_LEGACY_WEBKIT_BOX) to test for this. MozReview-Commit-ID: BONaqPC30Cn
layout/generic/nsFlexContainerFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -94,47 +94,16 @@ IsDisplayValueLegacyBox(const nsStyleDis
 static bool
 IsLegacyBox(const nsIFrame* aFlexContainer)
 {
   MOZ_ASSERT(aFlexContainer->GetType() == nsGkAtoms::flexContainerFrame,
              "only flex containers may be passed to this function");
   return aFlexContainer->HasAnyStateBits(NS_STATE_FLEX_IS_LEGACY_WEBKIT_BOX);
 }
 
-// XXXdholbert This will be merged into Init(), in a later patch in this series
-// (after all callers have been converted to check frame state bit).
-static bool
-IsLegacyBoxFOLD_ME(const nsIFrame* aFrame)
-{
-  nsStyleContext* styleContext = aFrame->StyleContext();
-  const nsStyleDisplay* styleDisp = styleContext->StyleDisplay();
-
-  // Trivial case: just check "display" directly.
-  bool isLegacyBox = IsDisplayValueLegacyBox(styleDisp);
-
-  // If this frame is for a scrollable element, then it will actually have
-  // "display:block", and its *parent* will have the real flex-flavored display
-  // value. So in that case, check the parent to find out if we're legacy.
-  if (!isLegacyBox && styleDisp->mDisplay == mozilla::StyleDisplay::Block) {
-    nsStyleContext* parentStyleContext = styleContext->GetParent();
-    NS_ASSERTION(parentStyleContext &&
-                 (styleContext->GetPseudo() == nsCSSAnonBoxes::buttonContent ||
-                  styleContext->GetPseudo() == nsCSSAnonBoxes::scrolledContent),
-                 "The only way a nsFlexContainerFrame can have 'display:block' "
-                 "should be if it's the inner part of a scrollable or button "
-                 "element");
-    isLegacyBox = IsDisplayValueLegacyBox(parentStyleContext->StyleDisplay());
-  }
-
-  NS_ASSERTION(!isLegacyBox ||
-               aFrame->GetType() == nsGkAtoms::flexContainerFrame,
-               "legacy box with unexpected frame type");
-  return isLegacyBox;
-}
-
 // Returns the "align-items" value that's equivalent to the legacy "box-align"
 // value in the given style struct.
 static uint8_t
 ConvertLegacyStyleToAlignItems(const nsStyleXUL* aStyleXUL)
 {
   // -[moz|webkit]-box-align corresponds to modern "align-items"
   switch (aStyleXUL->mBoxAlign) {
     case StyleBoxAlign::Stretch:
@@ -2291,19 +2260,38 @@ nsFlexContainerFrame::~nsFlexContainerFr
 /* virtual */
 void
 nsFlexContainerFrame::Init(nsIContent*       aContent,
                            nsContainerFrame* aParent,
                            nsIFrame*         aPrevInFlow)
 {
   nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
 
-  if (IsLegacyBoxFOLD_ME(this)) {
-    // Toggle frame state bit to indicate that this frame represents a
-    // legacy -webkit-{inline-}box container:
+  const nsStyleDisplay* styleDisp = StyleContext()->StyleDisplay();
+
+  // Figure out if we should set a frame state bit to indicate that this frame
+  // represents a legacy -webkit-{inline-}box container.
+  // First, the trivial case: just check "display" directly.
+  bool isLegacyBox = IsDisplayValueLegacyBox(styleDisp);
+
+  // If this frame is for a scrollable element, then it will actually have
+  // "display:block", and its *parent* will have the real flex-flavored display
+  // value. So in that case, check the parent to find out if we're legacy.
+  if (!isLegacyBox && styleDisp->mDisplay == mozilla::StyleDisplay::Block) {
+    nsStyleContext* parentStyleContext = mStyleContext->GetParent();
+    NS_ASSERTION(parentStyleContext &&
+                 (mStyleContext->GetPseudo() == nsCSSAnonBoxes::buttonContent ||
+                  mStyleContext->GetPseudo() == nsCSSAnonBoxes::scrolledContent),
+                 "The only way a nsFlexContainerFrame can have 'display:block' "
+                 "should be if it's the inner part of a scrollable or button "
+                 "element");
+    isLegacyBox = IsDisplayValueLegacyBox(parentStyleContext->StyleDisplay());
+  }
+
+  if (isLegacyBox) {
     AddStateBits(NS_STATE_FLEX_IS_LEGACY_WEBKIT_BOX);
   }
 }
 
 template<bool IsLessThanOrEqual(nsIFrame*, nsIFrame*)>
 /* static */ bool
 nsFlexContainerFrame::SortChildrenIfNeeded()
 {