Bug 1574307 - Part 1. Parse viewport-fit in meta element. r=smaug

For safe area insets (cutout) support, CSS Round Display Level 1 (https://drafts.csswg.org/css-round-display/#viewport-fit-descriptor) has new viewport value as `viewport-fit`.

To support safe area insets that is notch on display, CSS Environment Variables Module Level 1 (https://drafts.csswg.org/css-env-1/#safe-area-insets) adds `safearea-insets-*` (left, top, right and bottom). Also, `meta` element has `viewport-fit` enum value. (ex `<meta name="viewport" content="viewport-fit=cover>`) whether web browser window cover notch area.

`viewport-fit` has 3 enum value, `auto`, `cover` and `contain`.  GeckoView wants to expose this value to browser application such Fenix. Because Android API (https://developer.android.com/guide/topics/display-cutout) uses window root layout (It is set by Application) to cover notch on display.

Differential Revision: https://phabricator.services.mozilla.com/D55609

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Makoto Kato 2020-01-20 08:40:05 +00:00
parent 600d034817
commit a94e918a29
7 changed files with 49 additions and 4 deletions

View File

@ -1354,6 +1354,7 @@ Document::Document(const char* aContentType)
mStackRefCnt(0),
mUpdateNestLevel(0),
mViewportType(Unknown),
mViewportFit(ViewportFitType::Auto),
mSubDocuments(nullptr),
mHeaderData(nullptr),
mFlashClassification(FlashClassification::Unknown),
@ -9619,6 +9620,21 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
hasValidContents = true;
}
// Resolve viewport-fit value.
// https://drafts.csswg.org/css-round-display/#viewport-fit-descriptor
mViewportFit = ViewportFitType::Auto;
if (!metaData.mViewportFit.IsEmpty()) {
if (metaData.mViewportFit.EqualsLiteral("contain")) {
mViewportFit = ViewportFitType::Contain;
hasValidContents = true;
} else if (metaData.mViewportFit.EqualsLiteral("cover")) {
mViewportFit = ViewportFitType::Cover;
hasValidContents = true;
} else if (metaData.mViewportFit.EqualsLiteral("auto")) {
hasValidContents = true;
}
}
mWidthStrEmpty = metaData.mWidth.IsEmpty();
mViewportType = hasValidContents ? Specified : NoValidContent;
@ -9829,7 +9845,7 @@ nsViewportInfo Document::GetViewportInfo(const ScreenIntSize& aDisplaySize) {
scaleFloat, scaleMinFloat, scaleMaxFloat, size, sizeFlag,
mValidScaleFloat ? nsViewportInfo::AutoScaleFlag::FixedScale
: nsViewportInfo::AutoScaleFlag::AutoScale,
effectiveZoomFlag);
effectiveZoomFlag, mViewportFit);
}
}

View File

@ -213,6 +213,7 @@ class SVGUseElement;
class Touch;
class TouchList;
class TreeWalker;
enum class ViewportFitType : uint8_t;
class XPathEvaluator;
class XPathExpression;
class XPathNSResolver;
@ -5167,6 +5168,10 @@ class Document : public nsINode,
ViewportType mViewportType;
// viewport-fit described by
// https://drafts.csswg.org/css-round-display/#viewport-fit-descriptor
ViewportFitType mViewportFit;
PLDHashTable* mSubDocuments;
DocHeaderData* mHeaderData;

View File

@ -55,6 +55,8 @@ static void ProcessViewportToken(ViewportMetaData& aData,
aData.mMaximumScale.Assign(value);
} else if (key_atom == nsGkAtoms::user_scalable) {
aData.mUserScalable.Assign(value);
} else if (key_atom == nsGkAtoms::viewport_fit) {
aData.mViewportFit.Assign(value);
}
}

View File

@ -20,13 +20,15 @@ struct ViewportMetaData {
nsString mMinimumScale;
nsString mMaximumScale;
nsString mUserScalable;
nsString mViewportFit;
bool operator==(const ViewportMetaData& aOther) const {
return mWidth == aOther.mWidth && mHeight == aOther.mHeight &&
mInitialScale == aOther.mInitialScale &&
mMinimumScale == aOther.mMinimumScale &&
mMaximumScale == aOther.mMaximumScale &&
mUserScalable == aOther.mUserScalable;
mUserScalable == aOther.mUserScalable &&
mViewportFit == aOther.mViewportFit;
}
bool operator!=(const ViewportMetaData& aOther) const {
return !(*this == aOther);

View File

@ -9,6 +9,16 @@
#include "mozilla/Attributes.h"
#include "Units.h"
namespace mozilla {
namespace dom {
enum class ViewportFitType : uint8_t {
Auto,
Contain,
Cover,
};
}
} // namespace mozilla
/**
* Default values for the nsViewportInfo class.
*/
@ -39,6 +49,7 @@ class MOZ_STACK_CLASS nsViewportInfo {
const mozilla::CSSToScreenScale& aDefaultZoom,
ZoomFlag aZoomFlag)
: mDefaultZoom(aDefaultZoom),
mViewportFit(mozilla::dom::ViewportFitType::Auto),
mDefaultZoomValid(true),
mAutoSize(true),
mAllowZoom(aZoomFlag == ZoomFlag::AllowZoom) {
@ -53,11 +64,13 @@ class MOZ_STACK_CLASS nsViewportInfo {
const mozilla::CSSToScreenScale& aMinZoom,
const mozilla::CSSToScreenScale& aMaxZoom,
const mozilla::CSSSize& aSize, AutoSizeFlag aAutoSizeFlag,
AutoScaleFlag aAutoScaleFlag, ZoomFlag aZoomFlag)
AutoScaleFlag aAutoScaleFlag, ZoomFlag aZoomFlag,
mozilla::dom::ViewportFitType aViewportFit)
: mDefaultZoom(aDefaultZoom),
mMinZoom(aMinZoom),
mMaxZoom(aMaxZoom),
mSize(aSize),
mViewportFit(aViewportFit),
mDefaultZoomValid(aAutoScaleFlag != AutoScaleFlag::AutoScale),
mAutoSize(aAutoSizeFlag == AutoSizeFlag::AutoSize),
mAllowZoom(aZoomFlag == ZoomFlag::AllowZoom) {
@ -74,6 +87,8 @@ class MOZ_STACK_CLASS nsViewportInfo {
bool IsAutoSizeEnabled() const { return mAutoSize; }
bool IsZoomAllowed() const { return mAllowZoom; }
mozilla::dom::ViewportFitType GetViewportFit() const { return mViewportFit; }
enum {
Auto = -1,
ExtendToZoom = -2,
@ -107,6 +122,9 @@ class MOZ_STACK_CLASS nsViewportInfo {
// The size of the viewport, specified by the <meta name="viewport"> tag.
mozilla::CSSSize mSize;
// The value of the viewport-fit.
mozilla::dom::ViewportFitType mViewportFit;
// If the default zoom was specified and was between the min and max
// zoom values.
// FIXME: Bug 1504362 - Unify this and mDefaultZoom into

View File

@ -59,7 +59,8 @@ class MockMVMContext : public MVMContext {
mDisplaySize.width));
}
return nsViewportInfo(mDefaultScale, mMinScale, mMaxScale, viewportSize,
mAutoSizeFlag, mAutoScaleFlag, mZoomFlag);
mAutoSizeFlag, mAutoScaleFlag, mZoomFlag,
dom::ViewportFitType::Auto);
}
CSSToLayoutDeviceScale CSSToDevPixelScale() const { return mDeviceScale; }
float GetResolution() const { return mResolution; }

View File

@ -1245,6 +1245,7 @@ STATIC_ATOMS = [
Atom("audio", "audio"),
Atom("video", "video"),
Atom("viewport", "viewport"),
Atom("viewport_fit", "viewport-fit"),
Atom("viewport_height", "viewport-height"),
Atom("viewport_initial_scale", "viewport-initial-scale"),
Atom("viewport_maximum_scale", "viewport-maximum-scale"),