Bug 1674863 Part 2 - Use strong types to define fallback intrinsic width, height, and size. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D95578
This commit is contained in:
Ting-Yu Lin 2020-11-03 19:54:44 +00:00
Родитель 2f869ac046
Коммит 8cd9090bc6
4 изменённых файлов: 17 добавлений и 16 удалений

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

@ -30,7 +30,7 @@ struct BaseCoord {
// Note that '=' isn't defined so we'll get the
// compiler generated default assignment operator
operator T() const { return value; }
constexpr operator T() const { return value; }
friend bool operator==(Sub aA, Sub aB) { return aA.value == aB.value; }
friend bool operator!=(Sub aA, Sub aB) { return aA.value != aB.value; }

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

@ -11,6 +11,7 @@
#include "mozilla/EnumSet.h"
#include "nsSize.h" // for NS_MAXSIZE
#include "Units.h"
/**
* Constant used to indicate an unconstrained size.
@ -29,12 +30,6 @@
#define NS_INTRINSIC_ISIZE_UNKNOWN nscoord_MIN
// The fallback size of width is 300px and the aspect-ratio is 2:1, based on the
// spec definition in CSS2 section 10.3.2:
// https://drafts.csswg.org/css2/visudet.html#inline-replaced-width
#define REPLACED_ELEM_FALLBACK_PX_WIDTH 300
#define REPLACED_ELEM_FALLBACK_PX_HEIGHT 150
namespace mozilla {
/**
@ -84,6 +79,17 @@ enum class ComputeSizeFlag : uint8_t {
};
using ComputeSizeFlags = mozilla::EnumSet<ComputeSizeFlag>;
/**
* The fallback size of width is 300px and the aspect-ratio is 2:1, based on
* CSS2 section 10.3.2 and CSS Sizing Level 3 section 5.1:
* https://drafts.csswg.org/css2/visudet.html#inline-replaced-width
* https://drafts.csswg.org/css-sizing-3/#intrinsic-sizes
*/
inline constexpr CSSIntCoord kFallbackIntrinsicWidthInPixels(300);
inline constexpr CSSIntCoord kFallbackIntrinsicHeightInPixels(150);
inline constexpr CSSIntSize kFallbackIntrinsicSizeInPixels(
kFallbackIntrinsicWidthInPixels, kFallbackIntrinsicHeightInPixels);
/**
* This is used in some nsLayoutUtils functions.
* Declared here so that fewer files need to include nsLayoutUtils.h.

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

@ -634,11 +634,8 @@ IntrinsicSize nsSubDocumentFrame::GetIntrinsicSize() {
return {}; // XUL <iframe> and <browser> have no useful intrinsic size
}
// We must be an HTML <iframe>. Default to size of
// REPLACED_ELEM_FALLBACK_PX_WIDTH x REPLACED_ELEM_FALLBACK_PX_HEIGHT (i.e.
// 300px x 150px), for IE compat (and per CSS2.1 draft)
return IntrinsicSize(CSSPixel::ToAppUnits(REPLACED_ELEM_FALLBACK_PX_WIDTH),
CSSPixel::ToAppUnits(REPLACED_ELEM_FALLBACK_PX_HEIGHT));
// We must be an HTML <iframe>. Return fallback size.
return IntrinsicSize(CSSPixel::ToAppUnits(kFallbackIntrinsicSizeInPixels));
}
/* virtual */

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

@ -648,8 +648,7 @@ AspectRatio nsVideoFrame::GetIntrinsicRatio() const {
}
}
return AspectRatio::FromSize(REPLACED_ELEM_FALLBACK_PX_WIDTH,
REPLACED_ELEM_FALLBACK_PX_HEIGHT);
return AspectRatio::FromSize(kFallbackIntrinsicSizeInPixels);
}
bool nsVideoFrame::ShouldDisplayPoster() const {
@ -692,8 +691,7 @@ nsSize nsVideoFrame::GetVideoIntrinsicSize(gfxContext* aRenderingContext) {
}
}
return CSSPixel::ToAppUnits(CSSIntSize(REPLACED_ELEM_FALLBACK_PX_WIDTH,
REPLACED_ELEM_FALLBACK_PX_HEIGHT));
return CSSPixel::ToAppUnits(kFallbackIntrinsicSizeInPixels);
}
void nsVideoFrame::UpdatePosterSource(bool aNotify) {