bug 735577 - pt 3.1 - make width/height/offset/margin fields in nsHTMLReflowState private, and provide accessor functions. r=smontagu
authorJonathan Kew <jkew@mozilla.com>
Fri, 27 Dec 2013 17:59:02 +0000
changeset 161813 bcba7f58a8e759e8ce85af0d5a707b81783fc362
parent 161812 d3bccb687bd0195549a46cf09912290e6651d75e
child 161814 c73264fcffc344dbede024b64667dc31a9ac9043
push id37993
push userjkew@mozilla.com
push dateFri, 27 Dec 2013 18:02:20 +0000
treeherdermozilla-inbound@07f8896db19c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmontagu
bugs735577
milestone29.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 735577 - pt 3.1 - make width/height/offset/margin fields in nsHTMLReflowState private, and provide accessor functions. r=smontagu
layout/generic/nsHTMLReflowState.cpp
layout/generic/nsHTMLReflowState.h
--- a/layout/generic/nsHTMLReflowState.cpp
+++ b/layout/generic/nsHTMLReflowState.cpp
@@ -58,18 +58,18 @@ nsHTMLReflowState::nsHTMLReflowState(nsP
   : nsCSSOffsetState(aFrame, aRenderingContext)
   , mBlockDelta(0)
   , mReflowDepth(0)
 {
   NS_PRECONDITION(aPresContext, "no pres context");
   NS_PRECONDITION(aRenderingContext, "no rendering context");
   NS_PRECONDITION(aFrame, "no frame");
   parentReflowState = nullptr;
-  availableWidth = aAvailableSpace.width;
-  availableHeight = aAvailableSpace.height;
+  mAvailableWidth = aAvailableSpace.width;
+  mAvailableHeight = aAvailableSpace.height;
   mFloatManager = nullptr;
   mLineLayout = nullptr;
   memset(&mFlags, 0, sizeof(mFlags));
   mDiscoveredClearance = nullptr;
   mPercentHeightObserver = nullptr;
 
   if (aFlags & DUMMY_PARENT_REFLOW_STATE) {
     mFlags.mDummyParentReflowState = true;
@@ -155,18 +155,18 @@ nsHTMLReflowState::nsHTMLReflowState(nsP
 
   // If the parent is dirty, then the child is as well.
   // XXX Are the other cases where the parent reflows a child a second
   // time, as a resize?
   if (!mFlags.mSpecialHeightReflow)
     frame->AddStateBits(parentReflowState->frame->GetStateBits() &
                         NS_FRAME_IS_DIRTY);
 
-  availableWidth = aAvailableSpace.width;
-  availableHeight = aAvailableSpace.height;
+  mAvailableWidth = aAvailableSpace.width;
+  mAvailableHeight = aAvailableSpace.height;
 
   mFloatManager = aParentReflowState.mFloatManager;
   if (frame->IsFrameOfType(nsIFrame::eLineParticipant))
     mLineLayout = aParentReflowState.mLineLayout;
   else
     mLineLayout = nullptr;
 
   // Note: mFlags was initialized as a copy of aParentReflowState.mFlags up in
@@ -295,17 +295,17 @@ nsHTMLReflowState::SetComputedHeight(nsc
 
 void
 nsHTMLReflowState::Init(nsPresContext* aPresContext,
                         nscoord         aContainingBlockWidth,
                         nscoord         aContainingBlockHeight,
                         const nsMargin* aBorder,
                         const nsMargin* aPadding)
 {
-  NS_WARN_IF_FALSE(availableWidth != NS_UNCONSTRAINEDSIZE,
+  NS_WARN_IF_FALSE(mAvailableWidth != NS_UNCONSTRAINEDSIZE,
                    "have unconstrained width; this should only result from "
                    "very large sizes, not attempts at intrinsic width "
                    "calculation");
 
   mStylePosition = frame->StylePosition();
   mStyleDisplay = frame->StyleDisplay();
   mStyleVisibility = frame->StyleVisibility();
   mStyleBorder = frame->StyleBorder();
@@ -1422,17 +1422,17 @@ nsHTMLReflowState::InitAbsoluteConstrain
 
   {
     AutoMaybeDisableFontInflation an(frame);
 
     nsSize size =
       frame->ComputeSize(rendContext,
                          nsSize(containingBlockWidth,
                                 containingBlockHeight),
-                         containingBlockWidth, // XXX or availableWidth?
+                         containingBlockWidth, // XXX or mAvailableWidth?
                          nsSize(mComputedMargin.LeftRight() +
                                   mComputedOffsets.LeftRight(),
                                 mComputedMargin.TopBottom() +
                                   mComputedOffsets.TopBottom()),
                          nsSize(mComputedBorderPadding.LeftRight() -
                                   mComputedPadding.LeftRight(),
                                 mComputedBorderPadding.TopBottom() -
                                   mComputedPadding.TopBottom()),
@@ -1886,21 +1886,21 @@ nsHTMLReflowState::InitConstraints(nsPre
                 VerticalOffsetPercentBasis(frame, aContainingBlockWidth,
                                            aContainingBlockHeight),
                 aFrameType, aBorder, aPadding);
     // Override mComputedMargin since reflow roots start from the
     // frame's boundary, which is inside the margin.
     mComputedMargin.SizeTo(0, 0, 0, 0);
     mComputedOffsets.SizeTo(0, 0, 0, 0);
 
-    mComputedWidth = availableWidth - mComputedBorderPadding.LeftRight();
+    mComputedWidth = mAvailableWidth - mComputedBorderPadding.LeftRight();
     if (mComputedWidth < 0)
       mComputedWidth = 0;
-    if (availableHeight != NS_UNCONSTRAINEDSIZE) {
-      mComputedHeight = availableHeight - mComputedBorderPadding.TopBottom();
+    if (mAvailableHeight != NS_UNCONSTRAINEDSIZE) {
+      mComputedHeight = mAvailableHeight - mComputedBorderPadding.TopBottom();
       if (mComputedHeight < 0)
         mComputedHeight = 0;
     } else {
       mComputedHeight = NS_UNCONSTRAINEDSIZE;
     }
 
     mComputedMinWidth = mComputedMinHeight = 0;
     mComputedMaxWidth = mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
@@ -2020,17 +2020,17 @@ nsHTMLReflowState::InitConstraints(nsPre
         // 'width' property doesn't apply to table rows and row groups
         widthUnit = eStyleUnit_Auto;
         rowOrRowGroup = true;
       }
 
       // calc() with percentages acts like auto on internal table elements
       if (eStyleUnit_Auto == widthUnit ||
           (width.IsCalcUnit() && width.CalcHasPercent())) {
-        mComputedWidth = availableWidth;
+        mComputedWidth = mAvailableWidth;
 
         if ((mComputedWidth != NS_UNCONSTRAINEDSIZE) && !rowOrRowGroup){
           // Internal table elements don't have margins. Only tables and
           // cells have border and padding
           mComputedWidth -= mComputedBorderPadding.left +
             mComputedBorderPadding.right;
           if (mComputedWidth < 0)
             mComputedWidth = 0;
@@ -2101,17 +2101,17 @@ nsHTMLReflowState::InitConstraints(nsPre
                    "We're not in a flex container, so the flag "
                    "'mIsFlexContainerMeasuringHeight' shouldn't be set");
       }
 
       nsSize size =
         frame->ComputeSize(rendContext,
                            nsSize(aContainingBlockWidth,
                                   aContainingBlockHeight),
-                           availableWidth,
+                           mAvailableWidth,
                            nsSize(mComputedMargin.LeftRight(),
                                   mComputedMargin.TopBottom()),
                            nsSize(mComputedBorderPadding.LeftRight() -
                                     mComputedPadding.LeftRight(),
                                   mComputedBorderPadding.TopBottom() -
                                     mComputedPadding.TopBottom()),
                            nsSize(mComputedPadding.LeftRight(),
                                   mComputedPadding.TopBottom()),
@@ -2123,17 +2123,17 @@ nsHTMLReflowState::InitConstraints(nsPre
       NS_ASSERTION(mComputedHeight == NS_UNCONSTRAINEDSIZE ||
                    mComputedHeight >= 0, "Bogus height");
 
       // Exclude inline tables and flex items from the block margin calculations
       if (isBlock &&
           !IsSideCaption(frame, mStyleDisplay) &&
           mStyleDisplay->mDisplay != NS_STYLE_DISPLAY_INLINE_TABLE &&
           !flexContainerFrame) {
-        CalculateBlockSideMargins(availableWidth, mComputedWidth, aFrameType);
+        CalculateBlockSideMargins(mAvailableWidth, mComputedWidth, aFrameType);
       }
     }
   }
 }
 
 static void
 UpdateProp(FrameProperties& aProps,
            const FramePropertyDescriptor* aProperty,
@@ -2620,18 +2620,18 @@ nsHTMLReflowState::ComputeMinMaxValues(n
     mComputedMaxHeight = mComputedMinHeight;
   }
 }
 
 void
 nsHTMLReflowState::SetTruncated(const nsHTMLReflowMetrics& aMetrics,
                                 nsReflowStatus* aStatus) const
 {
-  if (availableHeight != NS_UNCONSTRAINEDSIZE &&
-      availableHeight < aMetrics.height &&
+  if (mAvailableHeight != NS_UNCONSTRAINEDSIZE &&
+      mAvailableHeight < aMetrics.height &&
       !mFlags.mIsTopOfPage) {
     *aStatus |= NS_FRAME_TRUNCATED;
   } else {
     *aStatus &= ~NS_FRAME_TRUNCATED;
   }
 }
 
 bool
--- a/layout/generic/nsHTMLReflowState.h
+++ b/layout/generic/nsHTMLReflowState.h
@@ -100,25 +100,37 @@ typedef uint32_t  nsCSSFrameType;
 struct nsCSSOffsetState {
 public:
   // the frame being reflowed
   nsIFrame*           frame;
 
   // rendering context to use for measurement
   nsRenderingContext* rendContext;
 
+  const nsMargin& ComputedPhysicalMargin() const { return mComputedMargin; }
+  const nsMargin& ComputedPhysicalBorderPadding() const { return mComputedBorderPadding; }
+  const nsMargin& ComputedPhysicalPadding() const { return mComputedPadding; }
+
+  // We may need to eliminate the (few) users of these writable-reference accessors
+  // as part of migrating to logical coordinates.
+  nsMargin& ComputedPhysicalMargin() { return mComputedMargin; }
+  nsMargin& ComputedPhysicalBorderPadding() { return mComputedBorderPadding; }
+  nsMargin& ComputedPhysicalPadding() { return mComputedPadding; }
+
+protected:
   // Computed margin values
   nsMargin         mComputedMargin;
 
   // Cached copy of the border + padding values
   nsMargin         mComputedBorderPadding;
 
   // Computed padding values
   nsMargin         mComputedPadding;
 
+public:
   // Callers using this constructor must call InitOffsets on their own.
   nsCSSOffsetState(nsIFrame *aFrame, nsRenderingContext *aRenderingContext)
     : frame(aFrame)
     , rendContext(aRenderingContext)
   {
   }
 
   // NOTE: If we ever want to use nsCSSOffsetState for a flex item or a grid
@@ -229,47 +241,72 @@ struct nsHTMLReflowState : public nsCSSO
 
   // LineLayout object (only for inline reflow; set to nullptr otherwise)
   nsLineLayout*    mLineLayout;
 
   // The appropriate reflow state for the containing block (for
   // percentage widths, etc.) of this reflow state's frame.
   const nsHTMLReflowState *mCBReflowState;
 
-  // the available width in which to reflow the frame. The space
-  // represents the amount of room for the frame's margin, border,
-  // padding, and content area. The frame size you choose should fit
-  // within the available width.
-  nscoord              availableWidth;
-
-  // A value of NS_UNCONSTRAINEDSIZE for the available height means
-  // you can choose whatever size you want. In galley mode the
-  // available height is always NS_UNCONSTRAINEDSIZE, and only page
-  // mode or multi-column layout involves a constrained height. The
-  // element's the top border and padding, and content, must fit. If the
-  // element is complete after reflow then its bottom border, padding
-  // and margin (and similar for its complete ancestors) will need to
-  // fit in this height.
-  nscoord              availableHeight;
-
   // The type of frame, from css's perspective. This value is
   // initialized by the Init method below.
   nsCSSFrameType   mFrameType;
 
   // The amount the in-flow position of the block is moving vertically relative
   // to its previous in-flow position (i.e. the amount the line containing the
   // block is moving).
   // This should be zero for anything which is not a block outside, and it
   // should be zero for anything which has a non-block parent.
   // The intended use of this value is to allow the accurate determination
   // of the potential impact of a float
   // This takes on an arbitrary value the first time a block is reflowed
   nscoord mBlockDelta;
 
+  // Accessors for the private fields below. Forcing all callers to use these
+  // will allow us to introduce logical-coordinate versions and gradually
+  // change clients from physical to logical as needed; and potentially switch
+  // the internal fields from physical to logical coordinates in due course,
+  // while maintaining compatibility with not-yet-updated code.
+  nscoord AvailableWidth() const { return mAvailableWidth; }
+  nscoord AvailableHeight() const { return mAvailableHeight; }
+  nscoord ComputedWidth() const { return mComputedWidth; }
+  nscoord ComputedHeight() const { return mComputedHeight; }
+  nscoord ComputedMinWidth() const { return mComputedMinWidth; }
+  nscoord ComputedMaxWidth() const { return mComputedMaxWidth; }
+  nscoord ComputedMinHeight() const { return mComputedMinHeight; }
+  nscoord ComputedMaxHeight() const { return mComputedMaxHeight; }
+  const nsMargin& ComputedPhysicalOffsets() const { return mComputedOffsets; }
+
+  nscoord& AvailableWidth() { return mAvailableWidth; }
+  nscoord& AvailableHeight() { return mAvailableHeight; }
+  nscoord& ComputedWidth() { return mComputedWidth; }
+  nscoord& ComputedHeight() { return mComputedHeight; }
+  nscoord& ComputedMinWidth() { return mComputedMinWidth; }
+  nscoord& ComputedMaxWidth() { return mComputedMaxWidth; }
+  nscoord& ComputedMinHeight() { return mComputedMinHeight; }
+  nscoord& ComputedMaxHeight() { return mComputedMaxHeight; }
+  nsMargin& ComputedPhysicalOffsets() { return mComputedOffsets; }
+
 private:
+  // the available width in which to reflow the frame. The space
+  // represents the amount of room for the frame's margin, border,
+  // padding, and content area. The frame size you choose should fit
+  // within the available width.
+  nscoord              mAvailableWidth;
+
+  // A value of NS_UNCONSTRAINEDSIZE for the available height means
+  // you can choose whatever size you want. In galley mode the
+  // available height is always NS_UNCONSTRAINEDSIZE, and only page
+  // mode or multi-column layout involves a constrained height. The
+  // element's the top border and padding, and content, must fit. If the
+  // element is complete after reflow then its bottom border, padding
+  // and margin (and similar for its complete ancestors) will need to
+  // fit in this height.
+  nscoord              mAvailableHeight;
+
   // The computed width specifies the frame's content area width, and it does
   // not apply to inline non-replaced elements
   //
   // For replaced inline frames, a value of NS_INTRINSICSIZE means you should
   // use your intrinsic width as the computed width
   //
   // For block-level frames, the computed width is based on the width of the
   // containing block, the margin/border/padding areas, and the min/max width.
@@ -285,27 +322,27 @@ private:
   // NS_AUTOHEIGHT means you choose a height to shrink wrap around the normal
   // flow child frames. The height must be within the limit of the min/max
   // height if there is such a limit
   //
   // For replaced block-level frames, a value of NS_INTRINSICSIZE
   // means you use your intrinsic height as the computed height
   nscoord          mComputedHeight;
 
-public:
   // Computed values for 'left/top/right/bottom' offsets. Only applies to
   // 'positioned' elements
   nsMargin         mComputedOffsets;
 
   // Computed values for 'min-width/max-width' and 'min-height/max-height'
   // XXXldb The width ones here should go; they should be needed only
   // internally.
   nscoord          mComputedMinWidth, mComputedMaxWidth;
   nscoord          mComputedMinHeight, mComputedMaxHeight;
 
+public:
   // Cached pointers to the various style structs used during intialization
   const nsStyleDisplay*    mStyleDisplay;
   const nsStyleVisibility* mStyleVisibility;
   const nsStylePosition*   mStylePosition;
   const nsStyleBorder*     mStyleBorder;
   const nsStyleMargin*     mStyleMargin;
   const nsStylePadding*    mStylePadding;
   const nsStyleText*       mStyleText;
@@ -513,21 +550,19 @@ public:
     // This would need to be combined with a slight change in which
     // frames NS_FRAME_CONTAINS_RELATIVE_HEIGHT is marked on.
     return (frame->GetStateBits() & NS_FRAME_IS_DIRTY) ||
            mFlags.mHResize ||
            (mFlags.mVResize && 
             (frame->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT));
   }
 
-  nscoord ComputedWidth() const { return mComputedWidth; }
   // This method doesn't apply min/max computed widths to the value passed in.
   void SetComputedWidth(nscoord aComputedWidth);
 
-  nscoord ComputedHeight() const { return mComputedHeight; }
   // This method doesn't apply min/max computed heights to the value passed in.
   void SetComputedHeight(nscoord aComputedHeight);
 
   void SetComputedHeightWithoutResettingResizeFlags(nscoord aComputedHeight) {
     // Viewport frames reset the computed height on a copy of their reflow
     // state when reflowing fixed-pos kids.  In that case we actually don't
     // want to mess with the resize flags, because comparing the frame's rect
     // to the munged computed width is pointless.