Bug 366531 - "deCOMtaminate nsBox.h [BoundsCheck()]" [p=ldx@users.sourceforge.net (Lorenzo Dieryckx) r+sr=roc a1.9=damons]
authorreed@reedloden.com
Fri, 04 Jan 2008 21:49:44 -0800
changeset 9862 6c971bdd25d5bd25453feffede8cf2ad1b3bc860
parent 9861 02817a8791538a8cf9cb41ef62d1a4f6486f76f0
child 9863 5d4177c57cdb56b285e6d33c9a11c0705d4543a9
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs366531
milestone1.9b3pre
Bug 366531 - "deCOMtaminate nsBox.h [BoundsCheck()]" [p=ldx@users.sourceforge.net (Lorenzo Dieryckx) r+sr=roc a1.9=damons]
layout/xul/base/src/grid/nsGrid.cpp
layout/xul/base/src/grid/nsGridRowLeafLayout.cpp
layout/xul/base/src/nsBox.cpp
layout/xul/base/src/nsBox.h
layout/xul/base/src/nsBoxFrame.cpp
layout/xul/base/src/nsImageBoxFrame.cpp
layout/xul/base/src/nsLeafBoxFrame.cpp
layout/xul/base/src/nsMenuFrame.cpp
layout/xul/base/src/nsPopupSetFrame.cpp
layout/xul/base/src/nsSplitterFrame.cpp
layout/xul/base/src/nsSprocketLayout.cpp
layout/xul/base/src/nsStackLayout.cpp
--- a/layout/xul/base/src/grid/nsGrid.cpp
+++ b/layout/xul/base/src/grid/nsGrid.cpp
@@ -1087,20 +1087,18 @@ nsGrid::GetMaxRowHeight(nsBoxLayoutState
     if (aIsHorizontal)
      child = GetCellAt(i,aIndex);
     else
      child = GetCellAt(aIndex,i);
 
     // ignore collapsed children
     if (!child->IsCollapsed(aState))
     {
-      nsSize childSize = child->GetMaxSize(aState);
       nsSize min = child->GetMinSize(aState);
-      nsBox::BoundsCheckMinMax(min, childSize);
-
+      nsSize childSize = nsBox::BoundsCheckMinMax(min, child->GetMaxSize(aState));
       nsSprocketLayout::AddLargestSize(size, childSize, aIsHorizontal);
     }
   }
 
   row->mMax = GET_HEIGHT(size, aIsHorizontal) + top + bottom;
 
   return row->mMax;
 }
--- a/layout/xul/base/src/grid/nsGridRowLeafLayout.cpp
+++ b/layout/xul/base/src/grid/nsGridRowLeafLayout.cpp
@@ -213,17 +213,17 @@ nsGridRowLeafLayout::PopulateBoxSizes(ns
           if (isHorizontal)
            right -= offset.right;
           else
            right -= offset.bottom;
         }
       }
     
      // initialize the box size here 
-     nsBox::BoundsCheck(min, pref, max);
+     pref = nsBox::BoundsCheck(min, pref, max);
    
      current = new (aState) nsBoxSize();
      current->pref = pref;
      current->min = min;
      current->max = max;
      current->flex = flex;
      current->bogus = column->mIsBogus;
      current->left = left + topMargin;
--- a/layout/xul/base/src/nsBox.cpp
+++ b/layout/xul/base/src/nsBox.cpp
@@ -464,19 +464,17 @@ nsBox::GetPrefSize(nsBoxLayoutState& aSt
   if (IsCollapsed(aState))
     return pref;
 
   AddBorderAndPadding(pref);
   nsIBox::AddCSSPrefSize(aState, this, pref);
 
   nsSize minSize = GetMinSize(aState);
   nsSize maxSize = GetMaxSize(aState);
-  BoundsCheck(minSize, pref, maxSize);
-
-  return pref;
+  return BoundsCheck(minSize, pref, maxSize);
 }
 
 nsSize
 nsBox::GetMinSize(nsBoxLayoutState& aState)
 {
   NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context");
 
   nsSize min(0,0);
@@ -986,45 +984,40 @@ nsBox::AddMargin(nsSize& aSize, const ns
 {
   if (aSize.width != NS_INTRINSICSIZE)
     aSize.width += aMargin.left + aMargin.right;
 
   if (aSize.height != NS_INTRINSICSIZE)
      aSize.height += aMargin.top + aMargin.bottom;
 }
 
-void
-nsBox::BoundsCheck(nscoord& aMin, nscoord& aPref, nscoord& aMax)
+nscoord
+nsBox::BoundsCheck(nscoord aMin, nscoord aPref, nscoord aMax)
 {
-   if (aMax < aMin)
-       aMax = aMin;
-
    if (aPref > aMax)
        aPref = aMax;
 
    if (aPref < aMin)
        aPref = aMin;
+
+   return aPref;
 }
 
-void
-nsBox::BoundsCheckMinMax(nsSize& aMinSize, nsSize& aMaxSize)
+nsSize
+nsBox::BoundsCheckMinMax(const nsSize& aMinSize, const nsSize& aMaxSize)
 {
-  if (aMaxSize.width < aMinSize.width) {
-    aMaxSize.width = aMinSize.width;
-  }
-
-  if (aMaxSize.height < aMinSize.height)
-    aMaxSize.height = aMinSize.height;
+  return nsSize(PR_MAX(aMaxSize.width, aMinSize.width),
+                PR_MAX(aMaxSize.height, aMinSize.height));
 }
 
-void
-nsBox::BoundsCheck(nsSize& aMinSize, nsSize& aPrefSize, nsSize& aMaxSize)
+nsSize
+nsBox::BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize, const nsSize& aMaxSize)
 {
-   BoundsCheck(aMinSize.width, aPrefSize.width, aMaxSize.width);
-   BoundsCheck(aMinSize.height, aPrefSize.height, aMaxSize.height);
+  return nsSize(BoundsCheck(aMinSize.width, aPrefSize.width, aMaxSize.width),
+                BoundsCheck(aMinSize.height, aPrefSize.height, aMaxSize.height));
 }
 
 #ifdef DEBUG_LAYOUT
 nsresult
 nsBox::SetDebug(nsBoxLayoutState& aState, PRBool aDebug)
 {
     return NS_OK;
 }
--- a/layout/xul/base/src/nsBox.h
+++ b/layout/xul/base/src/nsBox.h
@@ -112,19 +112,19 @@ rollbox.
 
   void AddBorderAndPadding(nsSize& aSize);
   void AddMargin(nsSize& aSize);
 
   static void AddBorderAndPadding(nsIBox* aBox, nsSize& aSize);
   static void AddMargin(nsIBox* aChild, nsSize& aSize);
   static void AddMargin(nsSize& aSize, const nsMargin& aMargin);
 
-  static void BoundsCheckMinMax(nsSize& aMinSize, nsSize& aMaxSize);
-  static void BoundsCheck(nsSize& aMinSize, nsSize& aPrefSize, nsSize& aMaxSize);
-  static void BoundsCheck(nscoord& aMinSize, nscoord& aPrefSize, nscoord& aMaxSize);
+  static nsSize BoundsCheckMinMax(const nsSize& aMinSize, const nsSize& aMaxSize);
+  static nsSize BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize, const nsSize& aMaxSize);
+  static nscoord BoundsCheck(nscoord aMinSize, nscoord aPrefSize, nscoord aMaxSize);
 
 protected:
 
 #ifdef DEBUG_LAYOUT
   virtual void AppendAttribute(const nsAutoString& aAttribute, const nsAutoString& aValue, nsAutoString& aResult);
 
   virtual void ListBox(nsAutoString& aResult);
 #endif
--- a/layout/xul/base/src/nsBoxFrame.cpp
+++ b/layout/xul/base/src/nsBoxFrame.cpp
@@ -717,17 +717,17 @@ nsBoxFrame::Reflow(nsPresContext*       
 
   // if we are told to layout intrinsic then get our preferred size.
   NS_ASSERTION(computedSize.width != NS_INTRINSICSIZE,
                "computed width should always be computed");
   if (computedSize.height == NS_INTRINSICSIZE) {
     prefSize = GetPrefSize(state);
     nsSize minSize = GetMinSize(state);
     nsSize maxSize = GetMaxSize(state);
-    BoundsCheck(minSize, prefSize, maxSize);
+    prefSize = BoundsCheck(minSize, prefSize, maxSize);
   }
 
   // get our desiredSize
   computedSize.width += m.left + m.right;
 
   if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) {
     computedSize.height = prefSize.height;
   } else {
@@ -816,20 +816,19 @@ nsBoxFrame::GetPrefSize(nsBoxLayoutState
       mLayoutManager->GetPrefSize(this, aBoxLayoutState, size);
       nsIBox::AddCSSPrefSize(aBoxLayoutState, this, size);
     } else
       size = nsBox::GetPrefSize(aBoxLayoutState);
   }
 
   nsSize minSize = GetMinSize(aBoxLayoutState);
   nsSize maxSize = GetMaxSize(aBoxLayoutState);
-  BoundsCheck(minSize, size, maxSize);
-  mPrefSize = size;
+  mPrefSize = BoundsCheck(minSize, size, maxSize);
  
-  return size;
+  return mPrefSize;
 }
 
 nscoord
 nsBoxFrame::GetBoxAscent(nsBoxLayoutState& aBoxLayoutState)
 {
   if (!DoesNeedRecalc(mAscent))
      return mAscent;
 
--- a/layout/xul/base/src/nsImageBoxFrame.cpp
+++ b/layout/xul/base/src/nsImageBoxFrame.cpp
@@ -448,20 +448,19 @@ nsImageBoxFrame::GetPrefSize(nsBoxLayout
   if (!mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0))
     size = nsSize(mSubRect.width, mSubRect.height);
   else
     size = mImageSize;
   AddBorderAndPadding(size);
   nsIBox::AddCSSPrefSize(aState, this, size);
 
   nsSize minSize = GetMinSize(aState);
-  nsSize maxSize = GetMaxSize(aState);
-  BoundsCheck(minSize, size, maxSize);
+  nsSize maxSize = GetMaxSize(aState);  
 
-  return size;
+  return BoundsCheck(minSize, size, maxSize);
 }
 
 nsSize
 nsImageBoxFrame::GetMinSize(nsBoxLayoutState& aState)
 {
   // An image can always scale down to (0,0).
   nsSize size(0,0);
   DISPLAY_MIN_SIZE(this, size);
--- a/layout/xul/base/src/nsLeafBoxFrame.cpp
+++ b/layout/xul/base/src/nsLeafBoxFrame.cpp
@@ -293,17 +293,17 @@ nsLeafBoxFrame::Reflow(nsPresContext*   
 
   nsSize prefSize(0,0);
 
   // if we are told to layout intrinic then get our preferred size.
   if (computedSize.width == NS_INTRINSICSIZE || computedSize.height == NS_INTRINSICSIZE) {
      prefSize = GetPrefSize(state);
      nsSize minSize = GetMinSize(state);
      nsSize maxSize = GetMaxSize(state);
-     BoundsCheck(minSize, prefSize, maxSize);
+     prefSize = BoundsCheck(minSize, prefSize, maxSize);
   }
 
   // get our desiredSize
   if (aReflowState.ComputedWidth() == NS_INTRINSICSIZE) {
     computedSize.width = prefSize.width;
   } else {
     computedSize.width += m.left + m.right;
   }
--- a/layout/xul/base/src/nsMenuFrame.cpp
+++ b/layout/xul/base/src/nsMenuFrame.cpp
@@ -737,17 +737,17 @@ nsMenuFrame::DoLayout(nsBoxLayoutState& 
   // layout the popup. First we need to get it.
   if (mPopupFrame) {
     PRBool sizeToPopup = IsSizedToPopup(mContent, PR_FALSE);
     // then get its preferred size
     nsSize prefSize = mPopupFrame->GetPrefSize(aState);
     nsSize minSize = mPopupFrame->GetMinSize(aState); 
     nsSize maxSize = mPopupFrame->GetMaxSize(aState);
 
-    BoundsCheck(minSize, prefSize, maxSize);
+    prefSize = BoundsCheck(minSize, prefSize, maxSize);
 
     if (sizeToPopup)
         prefSize.width = mRect.width;
 
     // if the pref size changed then set bounds to be the pref size
     PRBool sizeChanged = (mPopupFrame->PreferredSize() != prefSize);
     if (sizeChanged) {
       mPopupFrame->SetPreferredBounds(aState, nsRect(0,0,prefSize.width, prefSize.height));
@@ -1281,17 +1281,17 @@ nsMenuFrame::GetPrefSize(nsBoxLayoutStat
   // If we are using sizetopopup="always" then
   // nsBoxFrame will already have enforced the minimum size
   if (!IsSizedToPopup(mContent, PR_TRUE) &&
       IsSizedToPopup(mContent, PR_FALSE) &&
       SizeToPopup(aState, size)) {
     // We now need to ensure that size is within the min - max range.
     nsSize minSize = nsBoxFrame::GetMinSize(aState);
     nsSize maxSize = GetMaxSize(aState);
-    BoundsCheck(minSize, size, maxSize);
+    size = BoundsCheck(minSize, size, maxSize);
   }
 
   return size;
 }
 
 NS_IMETHODIMP
 nsMenuFrame::GetActiveChild(nsIDOMElement** aResult)
 {
--- a/layout/xul/base/src/nsPopupSetFrame.cpp
+++ b/layout/xul/base/src/nsPopupSetFrame.cpp
@@ -165,17 +165,17 @@ nsPopupSetFrame::DoLayout(nsBoxLayoutSta
   while (currEntry) {
     nsMenuPopupFrame* popupChild = currEntry->mPopupFrame;
     if (popupChild && popupChild->IsOpen()) {
       // then get its preferred size
       nsSize prefSize = popupChild->GetPrefSize(aState);
       nsSize minSize = popupChild->GetMinSize(aState);
       nsSize maxSize = popupChild->GetMaxSize(aState);
 
-      BoundsCheck(minSize, prefSize, maxSize);
+      prefSize = BoundsCheck(minSize, prefSize, maxSize);
 
       popupChild->SetPreferredBounds(aState, nsRect(0,0,prefSize.width, prefSize.height));
       popupChild->SetPopupPosition(nsnull);
 
       // is the new size too small? Make sure we handle scrollbars correctly
       nsIBox* child = popupChild->GetChildBox();
 
       nsRect bounds(popupChild->GetRect());
--- a/layout/xul/base/src/nsSplitterFrame.cpp
+++ b/layout/xul/base/src/nsSplitterFrame.cpp
@@ -787,18 +787,18 @@ nsSplitterFrameInner::MouseDown(nsIDOMEv
     } else {
       atom = content->Tag();
     }
 
     // skip over any splitters
     if (atom != nsGkAtoms::splitter) { 
         nsSize prefSize = childBox->GetPrefSize(state);
         nsSize minSize = childBox->GetMinSize(state);
-        nsSize maxSize = childBox->GetMaxSize(state);
-        nsBox::BoundsCheck(minSize, prefSize, maxSize);
+        nsSize maxSize = nsBox::BoundsCheckMinMax(minSize, childBox->GetMaxSize(state));
+        prefSize = nsBox::BoundsCheck(minSize, prefSize, maxSize);
 
         mOuter->AddMargin(childBox, minSize);
         mOuter->AddMargin(childBox, prefSize);
         mOuter->AddMargin(childBox, maxSize);
 
         nscoord flex = childBox->GetFlex(state);
 
         nsMargin margin(0,0,0,0);
--- a/layout/xul/base/src/nsSprocketLayout.cpp
+++ b/layout/xul/base/src/nsSprocketLayout.cpp
@@ -355,17 +355,17 @@ nsSprocketLayout::Layout(nsIBox* aBox, n
         // We have a valid box size entry.  This entry already contains information about our
         // sizes along the axis of the box (e.g., widths in a horizontal box).  If our default
         // ALIGN is not stretch, however, then we also need to know the child's size along the
         // opposite axis.
         if (!(frameState & NS_STATE_AUTO_STRETCH)) {
            nsSize prefSize = child->GetPrefSize(aState);
            nsSize minSize = child->GetMinSize(aState);
            nsSize maxSize = child->GetMaxSize(aState);
-           nsBox::BoundsCheck(minSize, prefSize, maxSize);
+           prefSize = nsBox::BoundsCheck(minSize, prefSize, maxSize);
        
            AddMargin(child, prefSize);
            width = PR_MIN(prefSize.width, originalClientRect.width);
            height = PR_MIN(prefSize.height, originalClientRect.height);
         }
       }
 
       // Obtain the computed size along the axis of the box for this child from the computedBoxSize entry.  
@@ -491,17 +491,17 @@ nsSprocketLayout::Layout(nsIBox* aBox, n
 
       PRBool possibleRedraw = PR_FALSE;
 
       if (sizeChanged) {
         // Our size is different.  Sanity check against our maximum allowed size to ensure
         // we didn't exceed it.
         nsSize minSize = child->GetMinSize(aState);
         nsSize maxSize = child->GetMaxSize(aState);
-        nsBox::BoundsCheckMinMax(minSize, maxSize);
+        maxSize = nsBox::BoundsCheckMinMax(minSize, maxSize);
 
         // make sure the size is in our max size.
         if (childRect.width > maxSize.width)
           childRect.width = maxSize.width;
 
         if (childRect.height > maxSize.height)
           childRect.height = maxSize.height;
            
@@ -795,24 +795,24 @@ nsSprocketLayout::PopulateBoxSizes(nsIBo
 
     if (!collapsed) {
     // only one flexible child? Cool we will just make its preferred size
     // 0 then and not even have to ask for it.
     //if (flexes != 1)  {
 
       pref = child->GetPrefSize(aState);
       min = child->GetMinSize(aState);
-      max = child->GetMaxSize(aState);
+      max = nsBox::BoundsCheckMinMax(min, child->GetMaxSize(aState));
       ascent = child->GetBoxAscent(aState);
       nsMargin margin;
       child->GetMargin(margin);
       ascent += margin.top;
     //}
 
-      nsBox::BoundsCheck(min, pref, max);
+      pref = nsBox::BoundsCheck(min, pref, max);
 
       AddMargin(child, pref);
       AddMargin(child, min);
       AddMargin(child, max);
     }
 
     if (!currentBox) {
       // create one.
@@ -915,17 +915,17 @@ nsSprocketLayout::PopulateBoxSizes(nsIBo
 #ifdef DEBUG
   else {
     NS_ASSERTION(maxFlex == 0, "How did that happen?");
   }
 #endif
 
   // we specified all our children are equal size;
   if (frameState & NS_STATE_EQUAL_SIZE) {
-    nsBox::BoundsCheck(biggestMinWidth, biggestPrefWidth, smallestMaxWidth);
+    biggestPrefWidth = nsBox::BoundsCheck(biggestMinWidth, biggestPrefWidth, smallestMaxWidth);
 
     currentBox = aBoxSizes;
 
     while(currentBox)
     {
       if (!currentBox->collapsed) {
         currentBox->pref = biggestPrefWidth;
         currentBox->min = biggestMinWidth;
@@ -1048,19 +1048,18 @@ nsSprocketLayout::ChildResized(nsIBox* a
 
       // if we are a horizontal box see if the child will fit inside us.
       if ( childActualHeight > containingHeight) {
             // if we are a horizontal box and the child is bigger than our height
 
             // ok if the height changed then we need to reflow everyone but us at the new height
             // so we will set the changed index to be us. And signal that we need a new pass.
 
-            nsSize max = aChild->GetMaxSize(aState);
-            nsSize min = aChild->GetMinSize(aState);
-            nsBox::BoundsCheckMinMax(min, max);
+            nsSize min = aChild->GetMinSize(aState);            
+            nsSize max = nsBox::BoundsCheckMinMax(min, aChild->GetMaxSize(aState));
             AddMargin(aChild, max);
 
             if (isHorizontal)
               childActualHeight = max.height < childActualHeight ? max.height : childActualHeight;
             else
               childActualHeight = max.width < childActualHeight ? max.width : childActualHeight;
 
             // only set if it changes
@@ -1085,18 +1084,18 @@ nsSprocketLayout::ChildResized(nsIBox* a
                 }
 
               }              
             }
       } 
       
       if (childActualWidth > childLayoutWidth) {
             nsSize min = aChild->GetMinSize(aState);
-            nsSize max = aChild->GetMaxSize(aState);
-            nsBox::BoundsCheckMinMax(min, max);
+            nsSize max = nsBox::BoundsCheckMinMax(min, aChild->GetMaxSize(aState));
+            
             AddMargin(aChild, max);
 
             // our width now becomes the new size
 
             if (isHorizontal)
               childActualWidth = max.width < childActualWidth ? max.width : childActualWidth;
             else
               childActualWidth = max.height < childActualWidth ? max.height : childActualWidth;
@@ -1461,19 +1460,18 @@ nsSprocketLayout::GetMaxSize(nsIBox* aBo
    PRInt32 count = 0;
 
    while (child) 
    {  
       // ignore collapsed children
       if (!child->IsCollapsed(aState))
       {
         // if completely redefined don't even ask our child for its size.
-        nsSize max = child->GetMaxSize(aState);
         nsSize min = child->GetMinSize(aState);
-        nsBox::BoundsCheckMinMax(min, max);
+        nsSize max = nsBox::BoundsCheckMinMax(min, child->GetMaxSize(aState));
 
         AddMargin(child, max);
         AddSmallestSize(aSize, max, isHorizontal);
 
         if (isEqual) {
           if (isHorizontal)
           {
             if (max.width < smallestMax)
--- a/layout/xul/base/src/nsStackLayout.cpp
+++ b/layout/xul/base/src/nsStackLayout.cpp
@@ -131,19 +131,18 @@ nsStackLayout::GetMaxSize(nsIBox* aBox, 
 {
   aSize.width = NS_INTRINSICSIZE;
   aSize.height = NS_INTRINSICSIZE;
 
   // run through all the children and get their min, max, and preferred sizes
 
   nsIBox* child = aBox->GetChildBox();
   while (child) {  
-    nsSize max = child->GetMaxSize(aState);
     nsSize min = child->GetMinSize(aState);
-    nsBox::BoundsCheckMinMax(min, max);
+    nsSize max = nsBox::BoundsCheckMinMax(min, child->GetMaxSize(aState));
 
     AddMargin(child, max);
     AddOffset(aState, child, max);
     AddSmallestSize(aSize, max);
 
     child = child->GetNextBox();
   }