address dbaron review comments: remove "const nscoord&", and move away from Get/Set pattern for top-level static functions "MarginComponentForSide()".
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 09 Aug 2012 15:38:01 -0700
changeset 1683 940e4c991083b154f9b481179fb535241111846d
parent 1682 6aa5b70542d69f6b5370b6be13559a5368cd4fe2
child 1684 c3a862732e2ac3a150cb62741f9eb023db852ebf
push id1369
push userdholbert@mozilla.com
push dateThu, 09 Aug 2012 22:38:05 +0000
address dbaron review comments: remove "const nscoord&", and move away from Get/Set pattern for top-level static functions "MarginComponentForSide()".
flexbox-mainImpl.patch
--- a/flexbox-mainImpl.patch
+++ b/flexbox-mainImpl.patch
@@ -1,17 +1,17 @@
 # HG changeset patch
 # Parent 0899d8780b25c7e23d3c849db70288af17b8f63b
 # User Daniel Holbert <dholbert@cs.stanford.edu>
 Bug 666041 patch 7: implementation of flex container class for CSS3 flexbox. r?dbaron
 
 diff --git a/layout/generic/nsFlexContainerFrame.cpp b/layout/generic/nsFlexContainerFrame.cpp
 --- a/layout/generic/nsFlexContainerFrame.cpp
 +++ b/layout/generic/nsFlexContainerFrame.cpp
-@@ -3,56 +3,2053 @@
+@@ -3,56 +3,2050 @@
  
  /* This Source Code is subject to the terms of the Mozilla Public License
   * version 2.0 (the "License"). You can obtain a copy of the License at
   * http://mozilla.org/MPL/2.0/. */
  
  /* rendering object for CSS display: -moz-flex */
  
  #include "nsFlexContainerFrame.h"
@@ -90,18 +90,18 @@ diff --git a/layout/generic/nsFlexContai
 +{
 +  const nsStylePosition* stylePos = aFrame->GetStylePosition();
 +
 +  return IsAxisHorizontal(aAxis) ?
 +    stylePos->mWidth :
 +    stylePos->mHeight;
 +}
 +
-+static const nscoord&
-+GetMarginComponentForSideInternal(const nsMargin& aMargin, Side aSide)
++static nscoord
++MarginComponentForSide(const nsMargin& aMargin, Side aSide)
 +{
 +  switch (aSide) {
 +    case eSideLeft:
 +      return aMargin.left;
 +    case eSideRight:
 +      return aMargin.right;
 +    case eSideTop:
 +      return aMargin.top;
@@ -109,36 +109,33 @@ diff --git a/layout/generic/nsFlexContai
 +      return aMargin.bottom;
 +  }
 +
 +  NS_NOTREACHED("unexpected Side enum");
 +  return aMargin.left; // have to return something
 +                       // (but something's busted if we got here)
 +}
 +
-+static void
-+SetMarginComponentForSideInternal(nsMargin& aMargin, Side aSide,
-+                                  nscoord aLength)
++static nscoord&
++MarginComponentForSide(nsMargin& aMargin, Side aSide)
 +{
 +  switch (aSide) {
 +    case eSideLeft:
-+      aMargin.left = aLength;
-+      return;
++      return aMargin.left;
 +    case eSideRight:
-+      aMargin.right = aLength;
-+      return;
++      return aMargin.right;
 +    case eSideTop:
-+      aMargin.top = aLength;
-+      return;
++      return aMargin.top;
 +    case eSideBottom:
-+      aMargin.bottom = aLength;
-+      return;
++      return aMargin.bottom;
 +  }
 +
 +  NS_NOTREACHED("unexpected Side enum");
++  return aMargin.left; // have to return something
++                       // (but something's busted if we got here)
 +}
 +
 +// Encapsulates our flex container's main & cross axes.
 +NS_STACK_CLASS class FlexboxAxisTracker {
 +public:
 +  FlexboxAxisTracker(nsFlexContainerFrame* aFlexContainerFrame);
 +
 +  // Accessors:
@@ -284,33 +281,33 @@ diff --git a/layout/generic/nsFlexContai
 +      mFlexShrink * mFlexBaseSize;
 +  }
 +
 +  // Getters for margin:
 +  // ===================
 +  const nsMargin& GetMargin() const { return mMargin; }
 +
 +  // Returns the margin component for a given mozilla::css::Side
-+  const nscoord& GetMarginComponentForSide(Side aSide) const
-+  { return GetMarginComponentForSideInternal(mMargin, aSide); }
++  nscoord GetMarginComponentForSide(Side aSide) const
++  { return MarginComponentForSide(mMargin, aSide); }
 +
 +  // Returns the total space occupied by this item's margins in the given axis
 +  nscoord GetMarginSizeInAxis(AxisOrientationType aAxis) const
 +  {
 +    Side startSide = kAxisOrientationToSidesMap[aAxis][eAxisEdge_Start];
 +    Side endSide = kAxisOrientationToSidesMap[aAxis][eAxisEdge_End];
 +    return GetMarginComponentForSide(startSide) +
 +      GetMarginComponentForSide(endSide);
 +  }
 +
 +  // Getters for border/padding
 +  // ==========================
 +  // Returns the border+padding component for a given mozilla::css::Side
-+  const nscoord& GetBorderPaddingComponentForSide(Side aSide) const
-+  { return GetMarginComponentForSideInternal(mBorderPadding, aSide); }
++  nscoord GetBorderPaddingComponentForSide(Side aSide) const
++  { return MarginComponentForSide(mBorderPadding, aSide); }
 +
 +  // Returns the total space occupied by this item's borders and padding in
 +  // the given axis
 +  nscoord GetBorderPaddingSizeInAxis(AxisOrientationType aAxis) const
 +  {
 +    Side startSide = kAxisOrientationToSidesMap[aAxis][eAxisEdge_Start];
 +    Side endSide = kAxisOrientationToSidesMap[aAxis][eAxisEdge_End];
 +    return GetBorderPaddingComponentForSide(startSide) +
@@ -346,17 +343,17 @@ diff --git a/layout/generic/nsFlexContai
 +  void SetMainPosition(nscoord aPosn)     { mMainPosn  = aPosn; }
 +  void SetCrossSize(nscoord aCrossSize)   { mCrossSize = aCrossSize; }
 +  void SetCrossPosition(nscoord aPosn)    { mCrossPosn = aPosn; }
 +  void SetAscent(nscoord aAscent)         { mAscent = aAscent; }
 +  void SetIsStretched()                   { mIsStretched = true; }
 +
 +  // Setter for margin components (for resolving "auto" margins)
 +  void SetMarginComponentForSide(Side aSide, nscoord aLength)
-+  { SetMarginComponentForSideInternal(mMargin, aSide, aLength); }
++  { MarginComponentForSide(mMargin, aSide) = aLength; }
 +
 +  // Returns the (two-dimensional) available space to be given to this flex
 +  // item when it's reflowed.
 +  nsSize GetAvailableSpaceForReflowState(FlexboxAxisTracker aAxisTracker) const
 +  {
 +    if (IsAxisHorizontal(aAxisTracker.GetMainAxis())) {
 +      return nsSize(mMainSize, NS_UNCONSTRAINEDSIZE);
 +    } else {
@@ -642,26 +639,26 @@ diff --git a/layout/generic/nsFlexContai
 +  inline AxisOrientationType GetAxis() const { return mAxis; }
 +
 +  // Advances our position across the start edge of the given margin, in the
 +  // axis we're tracking.
 +  void EnterMargin(const nsMargin& aMargin)
 +  {
 +    Side side =
 +      kAxisOrientationToSidesMap[mAxis][eAxisEdge_Start];
-+    mPosition += GetMarginComponentForSideInternal(aMargin, side);
++    mPosition += MarginComponentForSide(aMargin, side);
 +  }
 +
 +  // Advances our position across the end edge of the given margin, in the axis
 +  // we're tracking.
 +  void ExitMargin(const nsMargin& aMargin)
 +  {
 +    Side side =
 +      kAxisOrientationToSidesMap[mAxis][eAxisEdge_End];
-+    mPosition += GetMarginComponentForSideInternal(aMargin, side);
++    mPosition += MarginComponentForSide(aMargin, side);
 +  }
 +
 +  // Advances our current position from the start side of a child frame's
 +  // border-box to the frame's upper or left edge (depending on our axis).
 +  // (Note that this is a no-op if our axis grows in positive direction.)
 +  void EnterChildFrame(nscoord aChildFrameSize)
 +  {
 +    if (!DoesAxisGrowInPositiveDirection(mAxis))