diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index a66a9e429313..ba5c49ed7bae 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -2805,6 +2805,28 @@ nsCSSRendering::PaintBackground(nsPresContext* aPresContext, aBorder, aPadding, aUsePrintSettings, aBGClipRect); } +inline nscoord IntDivFloor(nscoord aDividend, nscoord aDivisor) +{ + NS_PRECONDITION(aDivisor > 0, + "this function only works for positive divisors"); + // ANSI C, ISO 9899:1999 section 6.5.5 defines integer division as + // truncation of the result towards zero. Earlier C standards, as + // well as the C++ standards (1998 and 2003) do not, but we depend + // on it elsewhere. + return (aDividend < 0 ? (aDividend - aDivisor + 1) : aDividend) / aDivisor; +} + +inline nscoord IntDivCeil(nscoord aDividend, nscoord aDivisor) +{ + NS_PRECONDITION(aDivisor > 0, + "this function only works for positive divisors"); + // ANSI C, ISO 9899:1999 section 6.5.5 defines integer division as + // truncation of the result towards zero. Earlier C standards, as + // well as the C++ standards (1998 and 2003) do not, but we depend + // on it elsewhere. + return (aDividend > 0 ? (aDividend + aDivisor - 1) : aDividend) / aDivisor; +} + /** * Return the largest 'v' such that v = aTileOffset + N*aTileSize, for some * integer N, and v <= aDirtyStart. @@ -2813,8 +2835,8 @@ static nscoord FindTileStart(nscoord aDirtyStart, nscoord aTileOffset, nscoord aTileSize) { // Find largest integer N such that aTileOffset + N*aTileSize <= aDirtyStart - PRInt32 n = NSToIntFloor((aDirtyStart*1.0f - aTileOffset)/aTileSize); - return aTileOffset + n*aTileSize; + return aTileOffset + + IntDivFloor(aDirtyStart - aTileOffset, aTileSize) * aTileSize; } /** @@ -2825,8 +2847,8 @@ static nscoord FindTileEnd(nscoord aDirtyEnd, nscoord aTileOffset, nscoord aTileSize) { // Find smallest integer N such that aTileOffset + N*aTileSize >= aDirtyEnd - PRInt32 n = NSToIntCeil((aDirtyEnd*1.0f - aTileOffset)/aTileSize); - return aTileOffset + n*aTileSize; + return aTileOffset + + IntDivCeil(aDirtyEnd - aTileOffset, aTileSize) * aTileSize; } void