Clamp the result to the valid nscoord range. b=541869 r=roc
authorMats Palmgren <matspal@gmail.com>
Wed, 27 Jan 2010 09:35:41 +0100
changeset 26831 3c8ea850ffb44bd74f994d6aa630c31dfa11f6cb
parent 26830 d9d8c0372d4e6f391e93a3b95c6c185eb399b483
child 26832 8c44b703f64a88056b2380454faa036c780db365
push id2306
push usertimeless@mozdev.org
push dateTue, 09 Mar 2010 14:45:02 +0000
reviewersroc
bugs541869
milestone1.9.1.9pre
Clamp the result to the valid nscoord range. b=541869 r=roc a=beltzner
layout/base/nsLayoutUtils.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -2022,17 +2022,18 @@ nsLayoutUtils::ComputeWidthDependentValu
 {
   NS_PRECONDITION(aContainingBlockWidth != NS_UNCONSTRAINEDSIZE,
                   "unconstrained widths no longer supported");
 
   if (eStyleUnit_Coord == aCoord.GetUnit()) {
     return aCoord.GetCoordValue();
   }
   if (eStyleUnit_Percent == aCoord.GetUnit()) {
-    return NSToCoordFloor(aContainingBlockWidth * aCoord.GetPercentValue());
+    return NSToCoordFloorClamped(aContainingBlockWidth *
+                                 aCoord.GetPercentValue());
   }
   NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
                aCoord.GetUnit() == eStyleUnit_Auto,
                "unexpected width value");
   return 0;
 }
 
 /* static */ nscoord
@@ -2053,17 +2054,18 @@ nsLayoutUtils::ComputeWidthValue(
 
   nscoord result;
   if (eStyleUnit_Coord == aCoord.GetUnit()) {
     result = aCoord.GetCoordValue();
     NS_ASSERTION(result >= 0, "width less than zero");
     result -= aContentEdgeToBoxSizing;
   } else if (eStyleUnit_Percent == aCoord.GetUnit()) {
     NS_ASSERTION(aCoord.GetPercentValue() >= 0.0f, "width less than zero");
-    result = NSToCoordFloor(aContainingBlockWidth * aCoord.GetPercentValue()) -
+    result = NSToCoordFloorClamped(aContainingBlockWidth *
+                                   aCoord.GetPercentValue()) -
              aContentEdgeToBoxSizing;
   } else if (eStyleUnit_Enumerated == aCoord.GetUnit()) {
     PRInt32 val = aCoord.GetIntValue();
     switch (val) {
       case NS_STYLE_WIDTH_MAX_CONTENT:
         result = aFrame->GetPrefWidth(aRenderingContext);
         NS_ASSERTION(result >= 0, "width less than zero");
         break;
@@ -2110,17 +2112,18 @@ nsLayoutUtils::ComputeHeightDependentVal
     // be inside the percentage case.  However, it would be much more
     // likely to catch problems if it were at the start of the function.
     // XXXldb Many callers pass a non-'auto' containing block height when
     // according to CSS2.1 they should be passing 'auto'.
     NS_PRECONDITION(NS_AUTOHEIGHT != aContainingBlockHeight,
                     "unexpected 'containing block height'");
 
     if (NS_AUTOHEIGHT != aContainingBlockHeight) {
-      return NSToCoordFloor(aContainingBlockHeight * aCoord.GetPercentValue());
+      return NSToCoordFloorClamped(aContainingBlockHeight *
+                                   aCoord.GetPercentValue());
     }
   }
   NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
                aCoord.GetUnit() == eStyleUnit_Auto,
                "unexpected height value");
   return 0;
 }