Issue #2522 - Part 1: Alias small, large, and dynamic viewport units to base viewport

This commit is contained in:
FranklinDM 2024-03-29 21:25:31 +08:00 committed by roytam1
commit 5c06335c5b
4 changed files with 81 additions and 7 deletions

View file

@ -7758,6 +7758,18 @@ const UnitInfo UnitData[] = {
{ STR_WITH_LEN("vh"), eCSSUnit_ViewportHeight, VARIANT_LENGTH },
{ STR_WITH_LEN("vmin"), eCSSUnit_ViewportMin, VARIANT_LENGTH },
{ STR_WITH_LEN("vmax"), eCSSUnit_ViewportMax, VARIANT_LENGTH },
{ STR_WITH_LEN("svw"), eCSSUnit_SmallViewportWidth, VARIANT_LENGTH },
{ STR_WITH_LEN("svh"), eCSSUnit_SmallViewportHeight, VARIANT_LENGTH },
{ STR_WITH_LEN("svmin"), eCSSUnit_SmallViewportMin, VARIANT_LENGTH },
{ STR_WITH_LEN("svmax"), eCSSUnit_SmallViewportMax, VARIANT_LENGTH },
{ STR_WITH_LEN("lvw"), eCSSUnit_LargeViewportWidth, VARIANT_LENGTH },
{ STR_WITH_LEN("lvh"), eCSSUnit_LargeViewportHeight, VARIANT_LENGTH },
{ STR_WITH_LEN("lvmin"), eCSSUnit_LargeViewportMin, VARIANT_LENGTH },
{ STR_WITH_LEN("lvmax"), eCSSUnit_LargeViewportMax, VARIANT_LENGTH },
{ STR_WITH_LEN("dvw"), eCSSUnit_DynamicViewportWidth, VARIANT_LENGTH },
{ STR_WITH_LEN("dvh"), eCSSUnit_DynamicViewportHeight, VARIANT_LENGTH },
{ STR_WITH_LEN("dvmin"), eCSSUnit_DynamicViewportMin, VARIANT_LENGTH },
{ STR_WITH_LEN("dvmax"), eCSSUnit_DynamicViewportMax, VARIANT_LENGTH },
{ STR_WITH_LEN("pc"), eCSSUnit_Pica, VARIANT_LENGTH },
{ STR_WITH_LEN("q"), eCSSUnit_Quarter, VARIANT_LENGTH },
{ STR_WITH_LEN("deg"), eCSSUnit_Degree, VARIANT_ANGLE },
@ -7797,10 +7809,22 @@ CSSParserImpl::TranslateDimension(nsCSSValue& aValue,
}
if (!mViewportUnitsEnabled &&
(eCSSUnit_ViewportWidth == units ||
(eCSSUnit_ViewportWidth == units ||
eCSSUnit_ViewportHeight == units ||
eCSSUnit_ViewportMin == units ||
eCSSUnit_ViewportMax == units)) {
eCSSUnit_ViewportMin == units ||
eCSSUnit_ViewportMax == units ||
eCSSUnit_SmallViewportWidth == units ||
eCSSUnit_SmallViewportHeight == units ||
eCSSUnit_SmallViewportMin == units ||
eCSSUnit_SmallViewportMax == units ||
eCSSUnit_LargeViewportWidth == units ||
eCSSUnit_LargeViewportHeight == units ||
eCSSUnit_LargeViewportMin == units ||
eCSSUnit_LargeViewportMax == units ||
eCSSUnit_DynamicViewportWidth == units ||
eCSSUnit_DynamicViewportHeight == units ||
eCSSUnit_DynamicViewportMin == units ||
eCSSUnit_DynamicViewportMax == units)) {
// Viewport units aren't allowed right now, probably because we're
// inside an @page declaration. Fail.
return false;

View file

@ -2002,6 +2002,19 @@ nsCSSValue::AppendToString(nsCSSPropertyID aProperty, nsAString& aResult,
case eCSSUnit_ViewportMin: aResult.AppendLiteral("vmin"); break;
case eCSSUnit_ViewportMax: aResult.AppendLiteral("vmax"); break;
case eCSSUnit_SmallViewportWidth: aResult.AppendLiteral("svw"); break;
case eCSSUnit_SmallViewportHeight: aResult.AppendLiteral("svh"); break;
case eCSSUnit_SmallViewportMin: aResult.AppendLiteral("svmin"); break;
case eCSSUnit_SmallViewportMax: aResult.AppendLiteral("svmax"); break;
case eCSSUnit_LargeViewportWidth: aResult.AppendLiteral("lvw"); break;
case eCSSUnit_LargeViewportHeight: aResult.AppendLiteral("lvh"); break;
case eCSSUnit_LargeViewportMin: aResult.AppendLiteral("lvmin"); break;
case eCSSUnit_LargeViewportMax: aResult.AppendLiteral("lvmax"); break;
case eCSSUnit_DynamicViewportWidth: aResult.AppendLiteral("dvw"); break;
case eCSSUnit_DynamicViewportHeight: aResult.AppendLiteral("dvh"); break;
case eCSSUnit_DynamicViewportMin: aResult.AppendLiteral("dvmin"); break;
case eCSSUnit_DynamicViewportMax: aResult.AppendLiteral("dvmax"); break;
case eCSSUnit_EM: aResult.AppendLiteral("em"); break;
case eCSSUnit_XHeight: aResult.AppendLiteral("ex"); break;
case eCSSUnit_Char: aResult.AppendLiteral("ch"); break;
@ -2175,6 +2188,18 @@ nsCSSValue::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
case eCSSUnit_ViewportHeight:
case eCSSUnit_ViewportMin:
case eCSSUnit_ViewportMax:
case eCSSUnit_SmallViewportWidth:
case eCSSUnit_SmallViewportHeight:
case eCSSUnit_SmallViewportMin:
case eCSSUnit_SmallViewportMax:
case eCSSUnit_LargeViewportWidth:
case eCSSUnit_LargeViewportHeight:
case eCSSUnit_LargeViewportMin:
case eCSSUnit_LargeViewportMax:
case eCSSUnit_DynamicViewportWidth:
case eCSSUnit_DynamicViewportHeight:
case eCSSUnit_DynamicViewportMin:
case eCSSUnit_DynamicViewportMax:
case eCSSUnit_EM:
case eCSSUnit_XHeight:
case eCSSUnit_Char:

View file

@ -534,6 +534,19 @@ enum nsCSSUnit {
eCSSUnit_ViewportMin = 702, // (float) smaller of ViewportWidth and ViewportHeight
eCSSUnit_ViewportMax = 703, // (float) larger of ViewportWidth and ViewportHeight
eCSSUnit_SmallViewportWidth = 704, // (float) 1% of the width of the small viewport
eCSSUnit_SmallViewportHeight = 705, // (float) 1% of the height of the small viewport
eCSSUnit_SmallViewportMin = 706, // (float) smaller of SmallViewportWidth and SmallViewportHeight
eCSSUnit_SmallViewportMax = 707, // (float) larger of SmallViewportWidth and SmallViewportHeight
eCSSUnit_LargeViewportWidth = 708, // (float) 1% of the width of the large viewport
eCSSUnit_LargeViewportHeight = 709, // (float) 1% of the height of the large viewport
eCSSUnit_LargeViewportMin = 710, // (float) smaller of LargeViewportWidth and LargeViewportHeight
eCSSUnit_LargeViewportMax = 711, // (float) larger of LargeViewportWidth and LargeViewportHeight
eCSSUnit_DynamicViewportWidth = 712, // (float) 1% of the width of the dynamic viewport
eCSSUnit_DynamicViewportHeight = 713, // (float) 1% of the height of the dynamic viewport
eCSSUnit_DynamicViewportMin = 714, // (float) smaller of DynamicViewportWidth and DynamicViewportHeight
eCSSUnit_DynamicViewportMax = 715, // (float) larger of DynamicViewportWidth and DynamicViewportHeight
// Font relative measure
eCSSUnit_EM = 800, // (float) == current font size
eCSSUnit_XHeight = 801, // (float) distance from top of lower case x to baseline

View file

@ -511,20 +511,32 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue,
// and allows us not to need an additional code path, in exchange
// for an increased cost to dynamic changes to the viewport size
// when viewport units are in use.
case eCSSUnit_ViewportWidth: {
case eCSSUnit_ViewportWidth:
case eCSSUnit_SmallViewportWidth:
case eCSSUnit_LargeViewportWidth:
case eCSSUnit_DynamicViewportWidth: {
nscoord viewportWidth = CalcViewportUnitsScale(aPresContext).width;
return ScaleViewportCoordTrunc(aValue, viewportWidth);
}
case eCSSUnit_ViewportHeight: {
case eCSSUnit_ViewportHeight:
case eCSSUnit_SmallViewportHeight:
case eCSSUnit_LargeViewportHeight:
case eCSSUnit_DynamicViewportHeight: {
nscoord viewportHeight = CalcViewportUnitsScale(aPresContext).height;
return ScaleViewportCoordTrunc(aValue, viewportHeight);
}
case eCSSUnit_ViewportMin: {
case eCSSUnit_ViewportMin:
case eCSSUnit_SmallViewportMin:
case eCSSUnit_LargeViewportMin:
case eCSSUnit_DynamicViewportMin: {
nsSize vuScale(CalcViewportUnitsScale(aPresContext));
nscoord viewportMin = min(vuScale.width, vuScale.height);
return ScaleViewportCoordTrunc(aValue, viewportMin);
}
case eCSSUnit_ViewportMax: {
case eCSSUnit_ViewportMax:
case eCSSUnit_SmallViewportMax:
case eCSSUnit_LargeViewportMax:
case eCSSUnit_DynamicViewportMax: {
nsSize vuScale(CalcViewportUnitsScale(aPresContext));
nscoord viewportMax = max(vuScale.width, vuScale.height);
return ScaleViewportCoordTrunc(aValue, viewportMax);