Bug 1660122 Part 5 - Add nsIFrame::GetAspectRatio() skeleton, and adapt existing callers. r=emilio

For now, GetAspectRatio() is just an alias for GetIntrinicRatio(). In
Part 7, we're going to have GetAspectRatio() consider aspect-ratio
property so that each replaced elements only need to report their
intrinsic ratio via GetIntrinicRatio(). Non-replaced element can also
call GetAspectRatio() to get the ratio suitable to calculate layout
size.

As of this patch, all the replaced elements'
GetIntrinsicRatio() (including nsImageFrame::mIntrinsicRatio) consider
aspect-ratio properties (added in bug 1639963). This is wrong, because
it affects replaced element's content ratio. So we adapt only callers
[1] involving the computation of the frame's external sizes to retain
the behavior after Part 7.

This change shouldn't change behavior.

[1] Exceptions include 1) a caller in nsIFrame::ComputeSize() checking
the frame has no intrinsic ratio; 2) other frame classes implementing
nsIFrame::GetIntrinsicRatio() by calling their parent's
GetIntrinicRatio(). nsSubDocumentFrame::GetIntrinicRatio() is an
example.

Differential Revision: https://phabricator.services.mozilla.com/D91227
This commit is contained in:
Ting-Yu Lin 2020-09-29 22:32:50 +00:00
Родитель 648c3ab60f
Коммит e0c2b95d53
9 изменённых файлов: 25 добавлений и 12 удалений

Просмотреть файл

@ -5776,7 +5776,7 @@ nscoord nsLayoutUtils::IntrinsicForAxis(
!(styleMinBSize.IsAuto() || (styleMinBSize.ConvertsToLength() &&
styleMinBSize.ToLength() == 0)) ||
!styleMaxBSize.IsNone()) {
if (AspectRatio ratio = aFrame->GetIntrinsicRatio()) {
if (AspectRatio ratio = aFrame->GetAspectRatio()) {
// Convert 'ratio' if necessary, so that it's storing ISize/BSize:
if (!horizontalAxis) {
ratio = ratio.Inverted();

Просмотреть файл

@ -2053,7 +2053,7 @@ FlexItem::FlexItem(ReflowInput& aFlexItemReflowInput, float aFlexGrow,
: mFrame(aFlexItemReflowInput.mFrame),
mFlexGrow(aFlexGrow),
mFlexShrink(aFlexShrink),
mIntrinsicRatio(mFrame->GetIntrinsicRatio()),
mIntrinsicRatio(mFrame->GetAspectRatio()),
mWM(aFlexItemReflowInput.GetWritingMode()),
mCBWM(aAxisTracker.GetWritingMode()),
mMainAxis(aAxisTracker.MainAxis()),

Просмотреть файл

@ -5962,6 +5962,11 @@ IntrinsicSize nsIFrame::GetIntrinsicSize() {
return IntrinsicSize(); // default is width/height set to eStyleUnit_None
}
AspectRatio nsIFrame::GetAspectRatio() const {
// TODO: Consider aspect-ratio property.
return GetIntrinsicRatio();
}
/* virtual */
AspectRatio nsIFrame::GetIntrinsicRatio() const { return AspectRatio(); }

Просмотреть файл

@ -2663,12 +2663,21 @@ class nsIFrame : public nsQueryFrame {
virtual mozilla::IntrinsicSize GetIntrinsicSize();
/**
* Get the intrinsic ratio of this element, or a default-constructed
* Get the preferred aspect ratio of this frame, or a default-constructed
* AspectRatio if it has none.
*
* https://drafts.csswg.org/css-sizing-4/#preferred-aspect-ratio
*/
mozilla::AspectRatio GetAspectRatio() const;
/**
* Get the intrinsic aspect ratio of this frame, or a default-constructed
* AspectRatio if it has no intrinsic ratio.
*
* The intrinsic ratio is the ratio of the width/height of a box with an
* intrinsic size or the intrinsic aspect ratio of a scalable vector image
* without an intrinsic size.
* without an intrinsic size. A frame class implementing a replaced element
* should override this method if it has a intrinsic ratio.
*/
virtual mozilla::AspectRatio GetIntrinsicRatio() const;

Просмотреть файл

@ -947,7 +947,7 @@ nsIFrame::SizeComputationResult nsImageFrame::ComputeSize(
const LogicalSize& aBorderPadding, ComputeSizeFlags aFlags) {
EnsureIntrinsicSizeAndRatio();
return {ComputeSizeWithIntrinsicDimensions(
aRenderingContext, aWM, mIntrinsicSize, mIntrinsicRatio, aCBSize,
aRenderingContext, aWM, mIntrinsicSize, GetAspectRatio(), aCBSize,
aMargin, aBorderPadding, aFlags),
AspectRatioUsage::None};
}

Просмотреть файл

@ -728,7 +728,7 @@ static bool IsPercentageAware(const nsIFrame* aFrame, WritingMode aWM) {
// is calculated from the constraint equation used for
// block-level, non-replaced elements in normal flow.
nsIFrame* f = const_cast<nsIFrame*>(aFrame);
if (f->GetIntrinsicRatio() &&
if (f->GetAspectRatio() &&
// Some percents are treated like 'auto', so check != coord
!pos->BSize(aWM).ConvertsToLength()) {
const IntrinsicSize& intrinsicSize = f->GetIntrinsicSize();

Просмотреть файл

@ -688,7 +688,7 @@ nsIFrame::SizeComputationResult nsSubDocumentFrame::ComputeSize(
nscoord aAvailableISize, const LogicalSize& aMargin,
const LogicalSize& aBorderPadding, ComputeSizeFlags aFlags) {
return {ComputeSizeWithIntrinsicDimensions(
aRenderingContext, aWM, GetIntrinsicSize(), GetIntrinsicRatio(),
aRenderingContext, aWM, GetIntrinsicSize(), GetAspectRatio(),
aCBSize, aMargin, aBorderPadding, aFlags),
AspectRatioUsage::None};
}

Просмотреть файл

@ -576,9 +576,8 @@ nsIFrame::SizeComputationResult nsVideoFrame::ComputeSize(
nsSize size = GetVideoIntrinsicSize(aRenderingContext);
IntrinsicSize intrinsicSize(size.width, size.height);
auto intrinsicRatio = GetIntrinsicRatio();
return {ComputeSizeWithIntrinsicDimensions(
aRenderingContext, aWM, intrinsicSize, intrinsicRatio, aCBSize,
aRenderingContext, aWM, intrinsicSize, GetAspectRatio(), aCBSize,
aMargin, aBorderPadding, aFlags),
AspectRatioUsage::None};
}

Просмотреть файл

@ -362,8 +362,8 @@ nsIFrame::SizeComputationResult SVGOuterSVGFrame::ComputeSize(
}
return {ComputeSizeWithIntrinsicDimensions(
aRenderingContext, aWritingMode, intrinsicSize,
GetIntrinsicRatio(), cbSize, aMargin, aBorderPadding, aFlags),
aRenderingContext, aWritingMode, intrinsicSize, GetAspectRatio(),
cbSize, aMargin, aBorderPadding, aFlags),
AspectRatioUsage::None};
}
@ -914,7 +914,7 @@ void SVGOuterSVGFrame::AppendDirectlyOwnedAnonBoxes(
void SVGOuterSVGFrame::MaybeSendIntrinsicSizeAndRatioToEmbedder() {
MaybeSendIntrinsicSizeAndRatioToEmbedder(Some(GetIntrinsicSize()),
Some(GetIntrinsicRatio()));
Some(GetAspectRatio()));
}
void SVGOuterSVGFrame::MaybeSendIntrinsicSizeAndRatioToEmbedder(