Bug 281630 Support ch width units in XUL r+sr=bz
authorneil@parkwaycc.co.uk
Wed, 09 May 2007 01:48:38 -0700
changeset 1307 37e175cfe51213d41f527ec05e2c85062f60fa68
parent 1306 67881af3a91e7135ae1ef8fe8bc675c463ae58ef
child 1308 df0fc8a849e19ea9dbafbd551e90a8d18af27477
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)
bugs281630
milestone1.9a5pre
Bug 281630 Support ch width units in XUL r+sr=bz
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/xul/base/src/nsBox.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1227,20 +1227,21 @@ static nscoord AddPercents(nsLayoutUtils
     if (aPercent >= 1.0f)
       result = nscoord_MAX;
     else
       result = NSToCoordRound(float(result) / (1.0f - aPercent));
   }
   return result;
 }
 
-static PRBool GetAbsoluteCoord(const nsStyleCoord& aStyle,
-                               nsIRenderingContext* aRenderingContext,
-                               nsIFrame* aFrame,
-                               nscoord& aResult)
+/* static */ PRBool
+nsLayoutUtils::GetAbsoluteCoord(const nsStyleCoord& aStyle,
+                                nsIRenderingContext* aRenderingContext,
+                                nsIFrame* aFrame,
+                                nscoord& aResult)
 {
   nsStyleUnit unit = aStyle.GetUnit();
   if (eStyleUnit_Coord == unit) {
     aResult = aStyle.GetCoordValue();
     return PR_TRUE;
   }
   if (eStyleUnit_Chars == unit) {
     aResult = nsLayoutUtils::CharsToCoord(aStyle, aRenderingContext,
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -512,16 +512,29 @@ public:
    * the root content.
    * @param aFrame the checking frame
    * @return if TRUE, the frame is a part of the scrollbar or scrollcorner of
    *         the root content.
    */
   static PRBool IsViewportScrollbarFrame(nsIFrame* aFrame);
 
   /**
+   * Return the value of aStyle as an nscoord if it can be determined without
+   * reference to ancestors or children (e.g. is not a percentage width)
+   * @param aStyle the style coord
+   * @param aRenderingContext the rendering context to use for font measurement
+   * @param aFrame the frame whose style context should be used for font information
+   * @param aResult the nscoord value of the style coord
+   * @return TRUE if the unit is eStyleUnit_Coord or eStyleUnit_Chars
+   */
+  static PRBool GetAbsoluteCoord(const nsStyleCoord& aStyle,
+                                 nsIRenderingContext* aRenderingContext,
+                                 nsIFrame* aFrame,
+                                 nscoord& aResult);
+  /**
    * Get the contribution of aFrame to its containing block's intrinsic
    * width.  This considers the child's intrinsic width, its 'width',
    * 'min-width', and 'max-width' properties, and its padding, border,
    * and margin.
    */
   enum IntrinsicWidthType { MIN_WIDTH, PREF_WIDTH };
   static nscoord IntrinsicForContainer(nsIRenderingContext* aRenderingContext,
                                        nsIFrame* aFrame,
--- a/layout/xul/base/src/nsBox.cpp
+++ b/layout/xul/base/src/nsBox.cpp
@@ -668,28 +668,27 @@ nsIFrame::Redraw(nsBoxLayoutState& aStat
   Invalidate(damageRect, aImmediate);
 
   return NS_OK;
 }
 
 PRBool 
 nsIBox::AddCSSPrefSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize)
 {
-    PRBool widthSet = PR_FALSE;
     PRBool heightSet = PR_FALSE;
 
     // add in the css min, max, pref
     const nsStylePosition* position = aBox->GetStylePosition();
 
     // see if the width or height was specifically set
-    if (position->mWidth.GetUnit() == eStyleUnit_Coord)  {
-        aSize.width = position->mWidth.GetCoordValue();
-        widthSet = PR_TRUE;
-    }
-    // XXX Handle eStyleUnit_Chars, eStyleUnit_Enumerated?
+    PRBool widthSet = 
+      nsLayoutUtils::GetAbsoluteCoord(position->mWidth,
+                                      aState.GetRenderingContext(),
+                                      aBox, aSize.width);
+    // XXX Handle eStyleUnit_Enumerated?
     // (Handling the eStyleUnit_Enumerated types requires
     // GetPrefSize/GetMinSize methods that don't consider
     // (min-/max-/)(width/height) properties.
 
     if (position->mHeight.GetUnit() == eStyleUnit_Coord) {
         aSize.height = position->mHeight.GetCoordValue();     
         heightSet = PR_TRUE;
     }
@@ -756,29 +755,31 @@ nsIBox::AddCSSMinSize(nsBoxLayoutState& 
       }
     }
 
     // add in the css min, max, pref
     const nsStylePosition* position = aBox->GetStylePosition();
 
     // same for min size. Unfortunately min size is always set to 0. So for now
     // we will assume 0 means not set.
-    if (position->mMinWidth.GetUnit() == eStyleUnit_Coord) {
-        nscoord min = position->mMinWidth.GetCoordValue();
+    nscoord min;
+    if (nsLayoutUtils::GetAbsoluteCoord(position->mMinWidth,
+                                        aState.GetRenderingContext(),
+                                        aBox, min)) {
         if (min && (!widthSet || (min > aSize.width && canOverride))) {
            aSize.width = min;
            widthSet = PR_TRUE;
         }
     } else if (position->mMinWidth.GetUnit() == eStyleUnit_Percent) {
         float min = position->mMinWidth.GetPercentValue();
         NS_ASSERTION(min == 0.0f, "Non-zero percentage values not currently supported");
         aSize.width = 0;
         widthSet = PR_TRUE;
     }
-    // XXX Handle eStyleUnit_Chars, eStyleUnit_Enumerated?
+    // XXX Handle eStyleUnit_Enumerated?
     // (Handling the eStyleUnit_Enumerated types requires
     // GetPrefSize/GetMinSize methods that don't consider
     // (min-/max-/)(width/height) properties.
 
     if (position->mMinHeight.GetUnit() == eStyleUnit_Coord) {
         nscoord min = position->mMinHeight.GetCoordValue();
         if (min && (!heightSet || (min > aSize.height && canOverride))) {
            aSize.height = min;
@@ -824,30 +825,27 @@ nsIBox::AddCSSMinSize(nsBoxLayoutState& 
     }
 
     return (widthSet && heightSet);
 }
 
 PRBool 
 nsIBox::AddCSSMaxSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize)
 {  
-
-    PRBool widthSet = PR_FALSE;
     PRBool heightSet = PR_FALSE;
 
     // add in the css min, max, pref
     const nsStylePosition* position = aBox->GetStylePosition();
 
     // and max
-    if (position->mMaxWidth.GetUnit() == eStyleUnit_Coord) {
-        nscoord max = position->mMaxWidth.GetCoordValue();
-        aSize.width = max;
-        widthSet = PR_TRUE;
-    }
-    // XXX Handle eStyleUnit_Chars, eStyleUnit_Enumerated?
+    PRBool widthSet = 
+      nsLayoutUtils::GetAbsoluteCoord(position->mMaxWidth,
+                                      aState.GetRenderingContext(),
+                                      aBox, aSize.width);
+    // XXX Handle eStyleUnit_Enumerated?
     // (Handling the eStyleUnit_Enumerated types requires
     // GetPrefSize/GetMinSize methods that don't consider
     // (min-/max-/)(width/height) properties.
 
     if (position->mMaxHeight.GetUnit() == eStyleUnit_Coord) {
         nscoord max = position->mMaxHeight.GetCoordValue();
         aSize.height = max;
         heightSet = PR_TRUE;