summaryrefslogtreecommitdiffstats
path: root/layout/generic/nsFrame.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'layout/generic/nsFrame.cpp')
-rw-r--r--layout/generic/nsFrame.cpp77
1 files changed, 44 insertions, 33 deletions
diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp
index dd7933b03..afbd57f52 100644
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -4641,10 +4641,10 @@ nsFrame::GetIntrinsicSize()
return IntrinsicSize(); // default is width/height set to eStyleUnit_None
}
-/* virtual */ nsSize
+/* virtual */ AspectRatio
nsFrame::GetIntrinsicRatio()
{
- return nsSize(0, 0);
+ return AspectRatio();
}
/* virtual */
@@ -4658,7 +4658,7 @@ nsFrame::ComputeSize(nsRenderingContext* aRenderingContext,
const LogicalSize& aPadding,
ComputeSizeFlags aFlags)
{
- MOZ_ASSERT(GetIntrinsicRatio() == nsSize(0,0),
+ MOZ_ASSERT(!GetIntrinsicRatio(),
"Please override this method and call "
"nsFrame::ComputeSizeWithIntrinsicDimensions instead.");
LogicalSize result = ComputeAutoSize(aRenderingContext, aWM,
@@ -4914,13 +4914,15 @@ LogicalSize
nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingContext,
WritingMode aWM,
const IntrinsicSize& aIntrinsicSize,
- nsSize aIntrinsicRatio,
+ const AspectRatio& aIntrinsicRatio,
const LogicalSize& aCBSize,
const LogicalSize& aMargin,
const LogicalSize& aBorder,
const LogicalSize& aPadding,
ComputeSizeFlags aFlags)
{
+ auto logicalRatio =
+ aWM.IsVertical() ? aIntrinsicRatio.Inverted() : aIntrinsicRatio;
const nsStylePosition* stylePos = StylePosition();
const nsStyleCoord* inlineStyleCoord = &stylePos->ISize(aWM);
const nsStyleCoord* blockStyleCoord = &stylePos->BSize(aWM);
@@ -5181,10 +5183,6 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
intrinsicBSize = 0;
}
- NS_ASSERTION(aIntrinsicRatio.width >= 0 && aIntrinsicRatio.height >= 0,
- "Intrinsic ratio has a negative component!");
- LogicalSize logicalRatio(aWM, aIntrinsicRatio);
-
// Now calculate the used values for iSize and bSize:
if (isAutoISize) {
@@ -5198,9 +5196,29 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
if (hasIntrinsicISize) {
tentISize = intrinsicISize;
- } else if (hasIntrinsicBSize && logicalRatio.BSize(aWM) > 0) {
- tentISize = NSCoordMulDiv(intrinsicBSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
- } else if (logicalRatio.ISize(aWM) > 0) {
+ } else if (hasIntrinsicBSize && logicalRatio) {
+ // (dholbert) <https://phabricator.services.mozilla.com
+ // /D29244#change-5faEkbsohV7O>
+ // This is wrong -- this ApplyTo call (and probably every ApplyTo call
+ // in this function) would only be valid if we're in a horizontal
+ // writing mode. It's not valid in a vertical writing mode. If this
+ // doesn't break tests, that's a bit concerning, and I think it means
+ // we're missing some test coverage. (That, or I'm misreading things.)
+ //
+ // aIntrinsicRatio is stored in terms of physical axes (width/height),
+ // either of which could be I vs. B axis. So any sort of
+ // aIntrinsicRatio.ApplyTo(someBSize) operation will be
+ // potentially-bogus.
+ //
+ // You probably want to bring back a logicalRatio variable
+ // (like the one we used to have here), but now with type AspectRatio.
+ // It would be equal to either aIntrinsicRatio or
+ // aIntrinsicRatio.Invert() depending on whether aWM is horizontal or
+ // vertical. (And hopefully having logical in its name would be a
+ // reminder that it's in terms of Inline/Block and can be used for
+ // these sorts of ApplyTo(intrinsicBSize) operations.
+ tentISize = logicalRatio.ApplyTo(intrinsicBSize);
+ } else if (logicalRatio) {
tentISize = aCBSize.ISize(aWM) - boxSizingToMarginEdgeISize; // XXX scrollbar?
if (tentISize < 0) tentISize = 0;
} else {
@@ -5217,8 +5235,8 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
if (hasIntrinsicBSize) {
tentBSize = intrinsicBSize;
- } else if (logicalRatio.ISize(aWM) > 0) {
- tentBSize = NSCoordMulDiv(tentISize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
+ } else if (logicalRatio) {
+ tentBSize = logicalRatio.Inverted().ApplyTo(tentISize);
} else {
tentBSize = nsPresContext::CSSPixelsToAppUnits(150);
}
@@ -5229,46 +5247,39 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
stretchB = (stretchI == eStretch ? eStretch : eStretchPreservingRatio);
}
- if (aIntrinsicRatio != nsSize(0, 0)) {
+ if (logicalRatio) {
if (stretchI == eStretch) {
tentISize = iSize; // * / 'stretch'
if (stretchB == eStretch) {
tentBSize = bSize; // 'stretch' / 'stretch'
- } else if (stretchB == eStretchPreservingRatio && logicalRatio.ISize(aWM) > 0) {
+ } else if (stretchB == eStretchPreservingRatio) {
// 'normal' / 'stretch'
- tentBSize = NSCoordMulDiv(iSize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
+ tentBSize = logicalRatio.Inverted().ApplyTo(iSize);
}
} else if (stretchB == eStretch) {
tentBSize = bSize; // 'stretch' / * (except 'stretch')
- if (stretchI == eStretchPreservingRatio && logicalRatio.BSize(aWM) > 0) {
+ if (stretchI == eStretchPreservingRatio) {
// 'stretch' / 'normal'
- tentISize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
+ tentISize = logicalRatio.ApplyTo(bSize);
}
} else if (stretchI == eStretchPreservingRatio) {
tentISize = iSize; // * (except 'stretch') / 'normal'
- if (logicalRatio.ISize(aWM) > 0) {
- tentBSize = NSCoordMulDiv(iSize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
- }
+ tentBSize = logicalRatio.Inverted().ApplyTo(iSize);
if (stretchB == eStretchPreservingRatio && tentBSize > bSize) {
// Stretch within the CB size with preserved intrinsic ratio.
tentBSize = bSize; // 'normal' / 'normal'
- if (logicalRatio.BSize(aWM) > 0) {
- tentISize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
- }
+ tentISize = logicalRatio.ApplyTo(bSize);
}
} else if (stretchB == eStretchPreservingRatio) {
tentBSize = bSize; // 'normal' / * (except 'normal' and 'stretch')
- if (logicalRatio.BSize(aWM) > 0) {
- tentISize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
- }
+ tentISize = logicalRatio.ApplyTo(bSize);
}
}
// ComputeAutoSizeWithIntrinsicDimensions preserves the ratio when applying
// the min/max-size. We don't want that when we have 'stretch' in either
// axis because tentISize/tentBSize is likely not according to ratio now.
- if (aIntrinsicRatio != nsSize(0, 0) &&
- stretchI != eStretch && stretchB != eStretch) {
+ if (logicalRatio && stretchI != eStretch && stretchB != eStretch) {
nsSize autoSize = nsLayoutUtils::
ComputeAutoSizeWithIntrinsicDimensions(minISize, minBSize,
maxISize, maxBSize,
@@ -5289,8 +5300,8 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
// 'auto' iSize, non-'auto' bSize
bSize = NS_CSS_MINMAX(bSize, minBSize, maxBSize);
if (stretchI != eStretch) {
- if (logicalRatio.BSize(aWM) > 0) {
- iSize = NSCoordMulDiv(bSize, logicalRatio.ISize(aWM), logicalRatio.BSize(aWM));
+ if (logicalRatio) {
+ iSize = logicalRatio.ApplyTo(bSize);
} else if (hasIntrinsicISize) {
if (!((aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize) &&
intrinsicISize > iSize)) {
@@ -5309,8 +5320,8 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
// non-'auto' iSize, 'auto' bSize
iSize = NS_CSS_MINMAX(iSize, minISize, maxISize);
if (stretchB != eStretch) {
- if (logicalRatio.ISize(aWM) > 0) {
- bSize = NSCoordMulDiv(iSize, logicalRatio.BSize(aWM), logicalRatio.ISize(aWM));
+ if (logicalRatio) {
+ bSize = logicalRatio.Inverted().ApplyTo(iSize);
} else if (hasIntrinsicBSize) {
if (!((aFlags & ComputeSizeFlags::eBClampMarginBoxMinSize) &&
intrinsicBSize > bSize)) {