зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1639963 - Calculate inline size and block size based on aspect-ratio. r=emilio
We calculate the size of ratio-dependent axis by aspect-ratio while initializing its ReflowInput, for most of the basic block cases. This patch doesn't include "Automatic content-based minimum sizes", which will be handled later. Besides, replaced elements will be handled later as well. We don't pass abspos-004.tentative.html because there is still a spec issue: https://github.com/w3c/csswg-drafts/issues/5151. For other tests we didn't pass (e.g. block-aspect-ratio-009.tentative.html, or replaced-element-00x.tentative.html), we fix them later. Besides, in this patch, we don't handle the case if the size of ratio-determining axis uses intrinsic size keywords (which needs to be calculated by its content size). We will fix this in the following bug (Bug 1646100). Differential Revision: https://phabricator.services.mozilla.com/D78964
This commit is contained in:
Родитель
5fa9480158
Коммит
b425a6022b
|
@ -16,6 +16,8 @@
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
class WritingMode;
|
||||
|
||||
struct AspectRatio {
|
||||
AspectRatio() : mRatio(0.0f) {}
|
||||
explicit AspectRatio(float aRatio) : mRatio(std::max(aRatio, 0.0f)) {}
|
||||
|
@ -51,6 +53,9 @@ struct AspectRatio {
|
|||
std::max(std::numeric_limits<float>::epsilon(), 1.0f / mRatio));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline AspectRatio ConvertToWritingMode(
|
||||
const WritingMode& aWM) const;
|
||||
|
||||
bool operator==(const AspectRatio& aOther) const {
|
||||
return mRatio == aOther.mRatio;
|
||||
}
|
||||
|
|
|
@ -2082,6 +2082,11 @@ const T& StyleRect<T>::End(mozilla::LogicalAxis aAxis,
|
|||
: mozilla::eLogicalSideBEnd);
|
||||
}
|
||||
|
||||
inline AspectRatio AspectRatio::ConvertToWritingMode(
|
||||
const WritingMode& aWM) const {
|
||||
return aWM.IsVertical() ? Inverted() : *this;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
// Definitions of inline methods for nsStylePosition, declared in
|
||||
|
|
|
@ -5948,6 +5948,39 @@ IntrinsicSize nsIFrame::GetIntrinsicSize() {
|
|||
/* virtual */
|
||||
AspectRatio nsIFrame::GetIntrinsicRatio() { return AspectRatio(); }
|
||||
|
||||
static nscoord ComputeInlineSizeFromAspectRatio(
|
||||
WritingMode aWM, const StyleAspectRatio& aAspectRatio, nscoord aBlockSize,
|
||||
const LogicalSize& aBoxSizingAdjustment) {
|
||||
MOZ_ASSERT(aAspectRatio.ratio.IsRatio());
|
||||
// FIXME: We have to handle zero and infinity for aspect-ratio later.
|
||||
// https://github.com/w3c/csswg-drafts/issues/4572
|
||||
MOZ_ASSERT(aAspectRatio.HasFiniteRatio(),
|
||||
"Infinite or zero ratio may have undefined behavior when "
|
||||
"computing the size");
|
||||
return aAspectRatio.ratio.AsRatio()
|
||||
.ToLayoutRatio()
|
||||
.ConvertToWritingMode(aWM)
|
||||
.ApplyTo(aBlockSize + aBoxSizingAdjustment.BSize(aWM)) -
|
||||
aBoxSizingAdjustment.ISize(aWM);
|
||||
}
|
||||
|
||||
static nscoord ComputeBlockSizeFromAspectRatio(
|
||||
WritingMode aWM, const StyleAspectRatio& aAspectRatio, nscoord aInlineSize,
|
||||
const LogicalSize& aBoxSizingAdjustment) {
|
||||
MOZ_ASSERT(aAspectRatio.ratio.IsRatio());
|
||||
// FIXME: We have to handle zero and infinity for aspect-ratio later.
|
||||
// https://github.com/w3c/csswg-drafts/issues/4572
|
||||
MOZ_ASSERT(aAspectRatio.HasFiniteRatio(),
|
||||
"Infinite or zero ratio may have undefined behavior when "
|
||||
"computing the size");
|
||||
return aAspectRatio.ratio.AsRatio()
|
||||
.ToLayoutRatio()
|
||||
.ConvertToWritingMode(aWM)
|
||||
.Inverted()
|
||||
.ApplyTo(aInlineSize + aBoxSizingAdjustment.ISize(aWM)) -
|
||||
aBoxSizingAdjustment.BSize(aWM);
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
LogicalSize nsIFrame::ComputeSize(gfxContext* aRenderingContext,
|
||||
WritingMode aWM, const LogicalSize& aCBSize,
|
||||
|
@ -6044,6 +6077,14 @@ LogicalSize nsIFrame::ComputeSize(gfxContext* aRenderingContext,
|
|||
result.ISize(aWM) = ComputeISizeValue(
|
||||
aRenderingContext, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
|
||||
boxSizingToMarginEdgeISize, *inlineStyleCoord, aFlags);
|
||||
} else if (stylePos->mAspectRatio.HasFiniteRatio() &&
|
||||
!nsLayoutUtils::IsAutoBSize(*blockStyleCoord,
|
||||
aCBSize.BSize(aWM))) {
|
||||
auto bSize = nsLayoutUtils::ComputeBSizeValue(
|
||||
aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
|
||||
blockStyleCoord->AsLengthPercentage());
|
||||
result.ISize(aWM) = ComputeInlineSizeFromAspectRatio(
|
||||
aWM, stylePos->mAspectRatio, bSize, boxSizingAdjust);
|
||||
} else if (MOZ_UNLIKELY(isGridItem) && !IS_TRUE_OVERFLOW_CONTAINER(this)) {
|
||||
// 'auto' inline-size for grid-level box - fill the CB for 'stretch' /
|
||||
// 'normal' and clamp it to the CB if requested:
|
||||
|
@ -6124,6 +6165,10 @@ LogicalSize nsIFrame::ComputeSize(gfxContext* aRenderingContext,
|
|||
result.BSize(aWM) = nsLayoutUtils::ComputeBSizeValue(
|
||||
aCBSize.BSize(aWM), boxSizingAdjust.BSize(aWM),
|
||||
blockStyleCoord->AsLengthPercentage());
|
||||
} else if (stylePos->mAspectRatio.HasFiniteRatio() &&
|
||||
result.ISize(aWM) != NS_UNCONSTRAINEDSIZE) {
|
||||
result.BSize(aWM) = ComputeBlockSizeFromAspectRatio(
|
||||
aWM, stylePos->mAspectRatio, result.ISize(aWM), boxSizingAdjust);
|
||||
} else if (MOZ_UNLIKELY(isGridItem) && blockStyleCoord->IsAuto() &&
|
||||
!IS_TRUE_OVERFLOW_CONTAINER(this) &&
|
||||
!alignCB->IsMasonry(isOrthogonal ? eLogicalAxisInline
|
||||
|
|
|
@ -835,6 +835,9 @@ renaming_overrides_prefixing = true
|
|||
|
||||
"GenericAspectRatio" = """
|
||||
bool HasRatio() const { return ratio.IsRatio(); }
|
||||
bool HasFiniteRatio() const {
|
||||
return HasRatio() && ratio.AsRatio().ToLayoutRatio();
|
||||
}
|
||||
bool HasMappedRatio() const { return auto_ && HasRatio(); }
|
||||
|
||||
static StyleGenericAspectRatio Auto() {
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
[abspos-001.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[abspos-002.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[abspos-003.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[abspos-005.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[abspos-006.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[abspos-007.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[abspos-009.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[abspos-010.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[abspos-011.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[auto-margins-001.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-001.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-002.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-003.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-004.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-005.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-006.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-007.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-008.tentative.html]
|
||||
expected: FAIL
|
|
@ -0,0 +1,2 @@
|
|||
[block-aspect-ratio-009.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-010.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-011.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-012.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-013.tentative.html]
|
||||
expected: FAIL
|
|
@ -0,0 +1,2 @@
|
|||
[block-aspect-ratio-014.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-016.tentative.html]
|
||||
expected: FAIL
|
|
@ -0,0 +1,2 @@
|
|||
[block-aspect-ratio-017.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-018.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[block-aspect-ratio-019.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[flex-aspect-ratio-003.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[flex-aspect-ratio-006.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[flex-aspect-ratio-007.tentative.html]
|
||||
expected: FAIL
|
|
@ -0,0 +1,2 @@
|
|||
[flex-aspect-ratio-008.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[intrinsic-size-003.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[percentage-resolution-001.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[percentage-resolution-002.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[percentage-resolution-003.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[percentage-resolution-004.tentative.html]
|
||||
expected: FAIL
|
|
@ -1,4 +0,0 @@
|
|||
[quirks-mode-001.tentative.html]
|
||||
[body height is 100]
|
||||
expected: FAIL
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
[quirks-mode-002.tentative.html]
|
||||
[body height equals width]
|
||||
expected: FAIL
|
||||
|
Загрузка…
Ссылка в новой задаче