Bug 1700051: part 35) Reduce accessibility of `mSoftText.mDOMMapping` to `private...
[gecko.git] / dom / base / nsViewportInfo.h
blobe6ecf56e89b4a78ef86aa647b779a985a3f050f0
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsViewportInfo_h___
6 #define nsViewportInfo_h___
8 #include <stdint.h>
9 #include "mozilla/Attributes.h"
10 #include "Units.h"
12 namespace mozilla {
13 namespace dom {
14 enum class ViewportFitType : uint8_t {
15 Auto,
16 Contain,
17 Cover,
20 } // namespace mozilla
22 /**
23 * Default values for the nsViewportInfo class.
25 static const mozilla::LayoutDeviceToScreenScale kViewportMinScale(0.25f);
26 static const mozilla::LayoutDeviceToScreenScale kViewportMaxScale(10.0f);
27 static const mozilla::CSSIntSize kViewportMinSize(200, 40);
28 static const mozilla::CSSIntSize kViewportMaxSize(10000, 10000);
30 /**
31 * Information retrieved from the <meta name="viewport"> tag. See
32 * Document::GetViewportInfo for more information on this functionality.
34 class MOZ_STACK_CLASS nsViewportInfo {
35 public:
36 enum class AutoSizeFlag {
37 AutoSize,
38 FixedSize,
40 enum class AutoScaleFlag {
41 AutoScale,
42 FixedScale,
44 enum class ZoomFlag {
45 AllowZoom,
46 DisallowZoom,
48 enum class ZoomBehaviour {
49 Mobile,
50 Desktop, // disallows zooming out past default zoom
52 nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize,
53 const mozilla::CSSToScreenScale& aDefaultZoom,
54 ZoomFlag aZoomFlag, ZoomBehaviour aBehaviour)
55 : mDefaultZoom(aDefaultZoom),
56 mViewportFit(mozilla::dom::ViewportFitType::Auto),
57 mDefaultZoomValid(true),
58 mAutoSize(true),
59 mAllowZoom(aZoomFlag == ZoomFlag::AllowZoom) {
60 mSize = mozilla::ScreenSize(aDisplaySize) / mDefaultZoom;
61 mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f);
62 if (aBehaviour == ZoomBehaviour::Desktop) {
63 mMinZoom = aDefaultZoom;
64 } else {
65 mMinZoom = pixelRatio * kViewportMinScale;
67 mMaxZoom = pixelRatio * kViewportMaxScale;
68 ConstrainViewportValues();
71 nsViewportInfo(const mozilla::CSSToScreenScale& aDefaultZoom,
72 const mozilla::CSSToScreenScale& aMinZoom,
73 const mozilla::CSSToScreenScale& aMaxZoom,
74 const mozilla::CSSSize& aSize, AutoSizeFlag aAutoSizeFlag,
75 AutoScaleFlag aAutoScaleFlag, ZoomFlag aZoomFlag,
76 mozilla::dom::ViewportFitType aViewportFit)
77 : mDefaultZoom(aDefaultZoom),
78 mMinZoom(aMinZoom),
79 mMaxZoom(aMaxZoom),
80 mSize(aSize),
81 mViewportFit(aViewportFit),
82 mDefaultZoomValid(aAutoScaleFlag != AutoScaleFlag::AutoScale),
83 mAutoSize(aAutoSizeFlag == AutoSizeFlag::AutoSize),
84 mAllowZoom(aZoomFlag == ZoomFlag::AllowZoom) {
85 ConstrainViewportValues();
88 bool IsDefaultZoomValid() const { return mDefaultZoomValid; }
89 mozilla::CSSToScreenScale GetDefaultZoom() const { return mDefaultZoom; }
90 mozilla::CSSToScreenScale GetMinZoom() const { return mMinZoom; }
91 mozilla::CSSToScreenScale GetMaxZoom() const { return mMaxZoom; }
93 mozilla::CSSSize GetSize() const { return mSize; }
95 bool IsAutoSizeEnabled() const { return mAutoSize; }
96 bool IsZoomAllowed() const { return mAllowZoom; }
98 mozilla::dom::ViewportFitType GetViewportFit() const { return mViewportFit; }
100 enum {
101 Auto = -1,
102 ExtendToZoom = -2,
103 DeviceSize = -3, // for device-width or device-height
105 // MIN/MAX computations where one of the arguments is auto resolve to the
106 // other argument. For instance, MIN(0.25, auto) = 0.25, and
107 // MAX(5, auto) = 5.
108 // https://drafts.csswg.org/css-device-adapt/#constraining-defs
109 static const float& Max(const float& aA, const float& aB);
110 static const float& Min(const float& aA, const float& aB);
112 private:
114 * Constrain the viewport calculations from the
115 * Document::GetViewportInfo() function in order to always return
116 * sane minimum/maximum values.
118 void ConstrainViewportValues();
120 // Default zoom indicates the level at which the display is 'zoomed in'
121 // initially for the user, upon loading of the page.
122 mozilla::CSSToScreenScale mDefaultZoom;
124 // The minimum zoom level permitted by the page.
125 mozilla::CSSToScreenScale mMinZoom;
127 // The maximum zoom level permitted by the page.
128 mozilla::CSSToScreenScale mMaxZoom;
130 // The size of the viewport, specified by the <meta name="viewport"> tag.
131 mozilla::CSSSize mSize;
133 // The value of the viewport-fit.
134 mozilla::dom::ViewportFitType mViewportFit;
136 // If the default zoom was specified and was between the min and max
137 // zoom values.
138 // FIXME: Bug 1504362 - Unify this and mDefaultZoom into
139 // Maybe<CSSToScreenScale>.
140 bool mDefaultZoomValid;
142 // Whether or not we should automatically size the viewport to the device's
143 // width. This is true if the document has been optimized for mobile, and
144 // the width property of a specified <meta name="viewport"> tag is either
145 // not specified, or is set to the special value 'device-width'.
146 bool mAutoSize;
148 // Whether or not the user can zoom in and out on the page. Default is true.
149 bool mAllowZoom;
152 #endif