Skip to content

Commit

Permalink
Bug 1040582 - Change nsLayoutUtils.cpp's MULDIV Macro to inline funct…
Browse files Browse the repository at this point in the history
…ion in nsCoord.h. r=dholbert
  • Loading branch information
Sixdsn committed Aug 29, 2014
1 parent 835169b commit 507f505
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
8 changes: 8 additions & 0 deletions gfx/src/nsCoord.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ inline void VERIFY_COORD(nscoord aCoord) {
#endif
}

inline nscoord NSCoordMulDiv(nscoord aMult1, nscoord aMult2, nscoord aDiv) {
#ifdef NS_COORD_IS_FLOAT
return (aMult1 * aMult2 / aDiv);
#else
return (int64_t(aMult1) * int64_t(aMult2) / int64_t(aDiv));
#endif
}

inline nscoord NSToCoordRound(float aValue)
{
#if defined(XP_WIN32) && defined(_M_IX86) && !defined(__GNUC__) && !defined(__clang__)
Expand Down
24 changes: 11 additions & 13 deletions layout/base/nsLayoutUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3706,8 +3706,6 @@ GetIntrinsicCoord(const nsStyleCoord& aStyle,
static int32_t gNoiseIndent = 0;
#endif

#define MULDIV(a,b,c) (nscoord(int64_t(a) * int64_t(b) / int64_t(c)))

/* static */ nscoord
nsLayoutUtils::IntrinsicForContainer(nsRenderingContext *aRenderingContext,
nsIFrame *aFrame,
Expand Down Expand Up @@ -3847,21 +3845,21 @@ nsLayoutUtils::IntrinsicForContainer(nsRenderingContext *aRenderingContext,
if (GetAbsoluteCoord(styleHeight, h) ||
GetPercentHeight(styleHeight, aFrame, h)) {
h = std::max(0, h - heightTakenByBoxSizing);
result = MULDIV(h, ratio.width, ratio.height);
result = NSCoordMulDiv(h, ratio.width, ratio.height);
}

if (GetAbsoluteCoord(styleMaxHeight, h) ||
GetPercentHeight(styleMaxHeight, aFrame, h)) {
h = std::max(0, h - heightTakenByBoxSizing);
nscoord maxWidth = MULDIV(h, ratio.width, ratio.height);
nscoord maxWidth = NSCoordMulDiv(h, ratio.width, ratio.height);
if (maxWidth < result)
result = maxWidth;
}

if (GetAbsoluteCoord(styleMinHeight, h) ||
GetPercentHeight(styleMinHeight, aFrame, h)) {
h = std::max(0, h - heightTakenByBoxSizing);
nscoord minWidth = MULDIV(h, ratio.width, ratio.height);
nscoord minWidth = NSCoordMulDiv(h, ratio.width, ratio.height);
if (minWidth > result)
result = minWidth;
}
Expand Down Expand Up @@ -4318,7 +4316,7 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
if (hasIntrinsicISize) {
tentISize = intrinsicISize;
} else if (hasIntrinsicBSize && logicalRatio.BSize(aWM) > 0) {
tentISize = MULDIV(intrinsicBSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
tentISize = NSCoordMulDiv(intrinsicBSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
} else if (logicalRatio.ISize(aWM) > 0) {
tentISize = aCBSize.ISize(aWM) - boxSizingToMarginEdgeISize; // XXX scrollbar?
if (tentISize < 0) tentISize = 0;
Expand All @@ -4329,7 +4327,7 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
if (hasIntrinsicBSize) {
tentBSize = intrinsicBSize;
} else if (logicalRatio.ISize(aWM) > 0) {
tentBSize = MULDIV(tentISize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
tentBSize = NSCoordMulDiv(tentISize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
} else {
tentBSize = nsPresContext::CSSPixelsToAppUnits(150);
}
Expand All @@ -4348,7 +4346,7 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
// 'auto' iSize, non-'auto' bSize
bSize = NS_CSS_MINMAX(bSize, minBSize, maxBSize);
if (logicalRatio.BSize(aWM) > 0) {
iSize = MULDIV(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
iSize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
} else if (hasIntrinsicISize) {
iSize = intrinsicISize;
} else {
Expand All @@ -4363,7 +4361,7 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
// non-'auto' iSize, 'auto' bSize
iSize = NS_CSS_MINMAX(iSize, minISize, maxISize);
if (logicalRatio.ISize(aWM) > 0) {
bSize = MULDIV(iSize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
bSize = NSCoordMulDiv(iSize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
} else if (hasIntrinsicBSize) {
bSize = intrinsicBSize;
} else {
Expand Down Expand Up @@ -4399,21 +4397,21 @@ nsLayoutUtils::ComputeAutoSizeWithIntrinsicDimensions(nscoord minWidth, nscoord
widthAtMaxHeight, widthAtMinHeight;

if (tentWidth > 0) {
heightAtMaxWidth = MULDIV(maxWidth, tentHeight, tentWidth);
heightAtMaxWidth = NSCoordMulDiv(maxWidth, tentHeight, tentWidth);
if (heightAtMaxWidth < minHeight)
heightAtMaxWidth = minHeight;
heightAtMinWidth = MULDIV(minWidth, tentHeight, tentWidth);
heightAtMinWidth = NSCoordMulDiv(minWidth, tentHeight, tentWidth);
if (heightAtMinWidth > maxHeight)
heightAtMinWidth = maxHeight;
} else {
heightAtMaxWidth = heightAtMinWidth = NS_CSS_MINMAX(tentHeight, minHeight, maxHeight);
}

if (tentHeight > 0) {
widthAtMaxHeight = MULDIV(maxHeight, tentWidth, tentHeight);
widthAtMaxHeight = NSCoordMulDiv(maxHeight, tentWidth, tentHeight);
if (widthAtMaxHeight < minWidth)
widthAtMaxHeight = minWidth;
widthAtMinHeight = MULDIV(minHeight, tentWidth, tentHeight);
widthAtMinHeight = NSCoordMulDiv(minHeight, tentWidth, tentHeight);
if (widthAtMinHeight > maxWidth)
widthAtMinHeight = maxWidth;
} else {
Expand Down
8 changes: 2 additions & 6 deletions layout/generic/nsFlexContainerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,10 +1125,6 @@ CrossSizeToUseWithRatio(const FlexItem& aFlexItem,
return NS_AUTOHEIGHT;
}

// XXX This macro shamelessly stolen from nsLayoutUtils.cpp.
// (Maybe it should be exposed via a nsLayoutUtils method?)
#define MULDIV(a,b,c) (nscoord(int64_t(a) * int64_t(b) / int64_t(c)))

// Convenience function; returns a main-size, given a cross-size and an
// intrinsic ratio. The intrinsic ratio must not have 0 in its cross-axis
// component (or else we'll divide by 0).
Expand All @@ -1142,10 +1138,10 @@ MainSizeFromAspectRatio(nscoord aCrossSize,

if (IsAxisHorizontal(aAxisTracker.GetCrossAxis())) {
// cross axis horiz --> aCrossSize is a width. Converting to height.
return MULDIV(aCrossSize, aIntrinsicRatio.height, aIntrinsicRatio.width);
return NSCoordMulDiv(aCrossSize, aIntrinsicRatio.height, aIntrinsicRatio.width);
}
// cross axis vert --> aCrossSize is a height. Converting to width.
return MULDIV(aCrossSize, aIntrinsicRatio.width, aIntrinsicRatio.height);
return NSCoordMulDiv(aCrossSize, aIntrinsicRatio.width, aIntrinsicRatio.height);
}

// Partially resolves "min-[width|height]:auto" and returns the resulting value.
Expand Down

0 comments on commit 507f505

Please sign in to comment.