Bug 1794164 - Change nsViewportInfo enums to constexprs and add 'k' prefix. r=dholbert

C++20 deprecates some operations between enums and floating point types:

https://clang.llvm.org/docs/DiagnosticsReference.html#wenum-float-conversion

dom/base/Document.cpp:10408:22 [-Wenum-float-conversion] comparison of floating-point type 'float' with enumeration type 'nsViewportInfo::(unnamed enum at dom/base/nsViewportInfo.h:108:3)'
dom/base/nsViewportInfo.cpp:33:10 [-Wenum-float-conversion] comparison of floating-point type 'float' with enumeration type 'nsViewportInfo::(unnamed enum at dom/base/nsViewportInfo.h:108:3)'
dom/base/nsViewportInfo.cpp:33:48 [-Wenum-float-conversion] comparison of floating-point type 'float' with enumeration type 'nsViewportInfo::(unnamed enum at dom/base/nsViewportInfo.h:108:3)'
dom/base/nsViewportInfo.cpp:34:10 [-Wenum-float-conversion] comparison of floating-point type 'float' with enumeration type 'nsViewportInfo::(unnamed enum at dom/base/nsViewportInfo.h:108:3)'
dom/base/nsViewportInfo.cpp:34:48 [-Wenum-float-conversion] comparison of floating-point type 'float' with enumeration type 'nsViewportInfo::(unnamed enum at dom/base/nsViewportInfo.h:108:3)'
dom/base/nsViewportInfo.cpp:35:10 [-Wenum-float-conversion] comparison of floating-point type 'float' with enumeration type 'nsViewportInfo::(unnamed enum at dom/base/nsViewportInfo.h:108:3)'
dom/base/nsViewportInfo.cpp:38:10 [-Wenum-float-conversion] comparison of floating-point type 'float' with enumeration type 'nsViewportInfo::(unnamed enum at dom/base/nsViewportInfo.h:108:3)'

Differential Revision: https://phabricator.services.mozilla.com/D159918
This commit is contained in:
Chris Peterson 2022-10-28 00:45:11 +00:00
Родитель 66c572f595
Коммит 78bef61580
3 изменённых файлов: 57 добавлений и 56 удалений

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

@ -10153,48 +10153,48 @@ void Document::ParseWidthAndHeightInMetaViewport(const nsAString& aWidthString,
// 2. Negative number values are dropped
// 3. device-width and device-height translate to 100vw and 100vh respectively
// 4. Other keywords and unknown values are also dropped
mMinWidth = nsViewportInfo::Auto;
mMaxWidth = nsViewportInfo::Auto;
mMinWidth = nsViewportInfo::kAuto;
mMaxWidth = nsViewportInfo::kAuto;
if (!aWidthString.IsEmpty()) {
mMinWidth = nsViewportInfo::ExtendToZoom;
mMinWidth = nsViewportInfo::kExtendToZoom;
if (aWidthString.EqualsLiteral("device-width")) {
mMaxWidth = nsViewportInfo::DeviceSize;
mMaxWidth = nsViewportInfo::kDeviceSize;
} else {
nsresult widthErrorCode;
mMaxWidth = aWidthString.ToInteger(&widthErrorCode);
if (NS_FAILED(widthErrorCode)) {
mMaxWidth = nsViewportInfo::Auto;
mMaxWidth = nsViewportInfo::kAuto;
} else if (mMaxWidth >= 0.0f) {
mMaxWidth = clamped(mMaxWidth, CSSCoord(1.0f), CSSCoord(10000.0f));
} else {
mMaxWidth = nsViewportInfo::Auto;
mMaxWidth = nsViewportInfo::kAuto;
}
}
} else if (aHasValidScale) {
if (aHeightString.IsEmpty()) {
mMinWidth = nsViewportInfo::ExtendToZoom;
mMaxWidth = nsViewportInfo::ExtendToZoom;
mMinWidth = nsViewportInfo::kExtendToZoom;
mMaxWidth = nsViewportInfo::kExtendToZoom;
}
} else if (aHeightString.IsEmpty() && UseWidthDeviceWidthFallbackViewport()) {
mMinWidth = nsViewportInfo::ExtendToZoom;
mMaxWidth = nsViewportInfo::DeviceSize;
mMinWidth = nsViewportInfo::kExtendToZoom;
mMaxWidth = nsViewportInfo::kDeviceSize;
}
mMinHeight = nsViewportInfo::Auto;
mMaxHeight = nsViewportInfo::Auto;
mMinHeight = nsViewportInfo::kAuto;
mMaxHeight = nsViewportInfo::kAuto;
if (!aHeightString.IsEmpty()) {
mMinHeight = nsViewportInfo::ExtendToZoom;
mMinHeight = nsViewportInfo::kExtendToZoom;
if (aHeightString.EqualsLiteral("device-height")) {
mMaxHeight = nsViewportInfo::DeviceSize;
mMaxHeight = nsViewportInfo::kDeviceSize;
} else {
nsresult heightErrorCode;
mMaxHeight = aHeightString.ToInteger(&heightErrorCode);
if (NS_FAILED(heightErrorCode)) {
mMaxHeight = nsViewportInfo::Auto;
mMaxHeight = nsViewportInfo::kAuto;
} else if (mMaxHeight >= 0.0f) {
mMaxHeight = clamped(mMaxHeight, CSSCoord(1.0f), CSSCoord(10000.0f));
} else {
mMaxHeight = nsViewportInfo::Auto;
mMaxHeight = nsViewportInfo::kAuto;
}
}
}
@ -10353,7 +10353,7 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
if (effectiveValidMaxScale) {
return effectiveMaxScale.scale;
}
return nsViewportInfo::Auto;
return nsViewportInfo::kAuto;
};
// Resolving 'extend-to-zoom'
@ -10378,7 +10378,7 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
// Chrome does, in order to maintain web compatibility. Since the
// default size has a complicated calculation, we fixup the maxWidth
// value after setting it, above.
if (maxWidth == nsViewportInfo::Auto && !mValidScaleFloat) {
if (maxWidth == nsViewportInfo::kAuto && !mValidScaleFloat) {
if (bc && bc->TouchEventsOverride() == TouchEventsOverride::Enabled &&
bc->InRDMPane()) {
// If RDM and touch simulation are active, then use the simulated
@ -10396,64 +10396,64 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
// We set minWidth to ExtendToZoom, which will cause our later width
// calculation to expand to maxWidth, if scale restrictions allow it.
minWidth = nsViewportInfo::ExtendToZoom;
minWidth = nsViewportInfo::kExtendToZoom;
}
// Resolve device-width and device-height first.
if (maxWidth == nsViewportInfo::DeviceSize) {
if (maxWidth == nsViewportInfo::kDeviceSize) {
maxWidth = displaySize.width;
}
if (maxHeight == nsViewportInfo::DeviceSize) {
if (maxHeight == nsViewportInfo::kDeviceSize) {
maxHeight = displaySize.height;
}
if (extendZoom == nsViewportInfo::Auto) {
if (maxWidth == nsViewportInfo::ExtendToZoom) {
maxWidth = nsViewportInfo::Auto;
if (extendZoom == nsViewportInfo::kAuto) {
if (maxWidth == nsViewportInfo::kExtendToZoom) {
maxWidth = nsViewportInfo::kAuto;
}
if (maxHeight == nsViewportInfo::ExtendToZoom) {
maxHeight = nsViewportInfo::Auto;
if (maxHeight == nsViewportInfo::kExtendToZoom) {
maxHeight = nsViewportInfo::kAuto;
}
if (minWidth == nsViewportInfo::ExtendToZoom) {
if (minWidth == nsViewportInfo::kExtendToZoom) {
minWidth = maxWidth;
}
if (minHeight == nsViewportInfo::ExtendToZoom) {
if (minHeight == nsViewportInfo::kExtendToZoom) {
minHeight = maxHeight;
}
} else {
CSSSize extendSize = displaySize / extendZoom;
if (maxWidth == nsViewportInfo::ExtendToZoom) {
if (maxWidth == nsViewportInfo::kExtendToZoom) {
maxWidth = extendSize.width;
}
if (maxHeight == nsViewportInfo::ExtendToZoom) {
if (maxHeight == nsViewportInfo::kExtendToZoom) {
maxHeight = extendSize.height;
}
if (minWidth == nsViewportInfo::ExtendToZoom) {
if (minWidth == nsViewportInfo::kExtendToZoom) {
minWidth = nsViewportInfo::Max(extendSize.width, maxWidth);
}
if (minHeight == nsViewportInfo::ExtendToZoom) {
if (minHeight == nsViewportInfo::kExtendToZoom) {
minHeight = nsViewportInfo::Max(extendSize.height, maxHeight);
}
}
// Resolve initial width and height from min/max descriptors
// https://drafts.csswg.org/css-device-adapt/#resolve-initial-width-height
CSSCoord width = nsViewportInfo::Auto;
if (minWidth != nsViewportInfo::Auto ||
maxWidth != nsViewportInfo::Auto) {
CSSCoord width = nsViewportInfo::kAuto;
if (minWidth != nsViewportInfo::kAuto ||
maxWidth != nsViewportInfo::kAuto) {
width = nsViewportInfo::Max(
minWidth, nsViewportInfo::Min(maxWidth, displaySize.width));
}
CSSCoord height = nsViewportInfo::Auto;
if (minHeight != nsViewportInfo::Auto ||
maxHeight != nsViewportInfo::Auto) {
CSSCoord height = nsViewportInfo::kAuto;
if (minHeight != nsViewportInfo::kAuto ||
maxHeight != nsViewportInfo::kAuto) {
height = nsViewportInfo::Max(
minHeight, nsViewportInfo::Min(maxHeight, displaySize.height));
}
// Resolve width value
// https://drafts.csswg.org/css-device-adapt/#resolve-width
if (width == nsViewportInfo::Auto) {
if (height == nsViewportInfo::Auto || aDisplaySize.height == 0) {
if (width == nsViewportInfo::kAuto) {
if (height == nsViewportInfo::kAuto || aDisplaySize.height == 0) {
width = displaySize.width;
} else {
width = height * aDisplaySize.width / aDisplaySize.height;
@ -10462,15 +10462,15 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
// Resolve height value
// https://drafts.csswg.org/css-device-adapt/#resolve-height
if (height == nsViewportInfo::Auto) {
if (height == nsViewportInfo::kAuto) {
if (aDisplaySize.width == 0) {
height = displaySize.height;
} else {
height = width * aDisplaySize.height / aDisplaySize.width;
}
}
MOZ_ASSERT(width != nsViewportInfo::Auto &&
height != nsViewportInfo::Auto);
MOZ_ASSERT(width != nsViewportInfo::kAuto &&
height != nsViewportInfo::kAuto);
CSSSize size(width, height);
@ -10480,10 +10480,10 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
nsViewportInfo::AutoSizeFlag sizeFlag =
nsViewportInfo::AutoSizeFlag::FixedSize;
if (mMaxWidth == nsViewportInfo::DeviceSize ||
(mWidthStrEmpty && (mMaxHeight == nsViewportInfo::DeviceSize ||
if (mMaxWidth == nsViewportInfo::kDeviceSize ||
(mWidthStrEmpty && (mMaxHeight == nsViewportInfo::kDeviceSize ||
mScaleFloat.scale == 1.0f)) ||
(!mWidthStrEmpty && mMaxWidth == nsViewportInfo::Auto &&
(!mWidthStrEmpty && mMaxWidth == nsViewportInfo::kAuto &&
mMaxHeight < 0)) {
sizeFlag = nsViewportInfo::AutoSizeFlag::AutoSize;
}

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

@ -29,13 +29,14 @@ void nsViewportInfo::ConstrainViewportValues() {
static const float& MinOrMax(const float& aA, const float& aB,
const float& (*aMinOrMax)(const float&,
const float&)) {
MOZ_ASSERT(
aA != nsViewportInfo::ExtendToZoom && aA != nsViewportInfo::DeviceSize &&
aB != nsViewportInfo::ExtendToZoom && aB != nsViewportInfo::DeviceSize);
if (aA == nsViewportInfo::Auto) {
MOZ_ASSERT(aA != nsViewportInfo::kExtendToZoom &&
aA != nsViewportInfo::kDeviceSize &&
aB != nsViewportInfo::kExtendToZoom &&
aB != nsViewportInfo::kDeviceSize);
if (aA == nsViewportInfo::kAuto) {
return aB;
}
if (aB == nsViewportInfo::Auto) {
if (aB == nsViewportInfo::kAuto) {
return aA;
}
return aMinOrMax(aA, aB);

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

@ -105,11 +105,11 @@ class MOZ_STACK_CLASS nsViewportInfo {
mozilla::dom::ViewportFitType GetViewportFit() const { return mViewportFit; }
enum {
Auto = -1,
ExtendToZoom = -2,
DeviceSize = -3, // for device-width or device-height
};
static constexpr float kAuto = -1.0f;
static constexpr float kExtendToZoom = -2.0f;
static constexpr float kDeviceSize =
-3.0f; // for device-width or device-height
// MIN/MAX computations where one of the arguments is auto resolve to the
// other argument. For instance, MIN(0.25, auto) = 0.25, and
// MAX(5, auto) = 5.