2012-12-17 21:24:41 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef nsViewportInfo_h___
|
|
|
|
#define nsViewportInfo_h___
|
|
|
|
|
2013-07-30 14:25:31 +00:00
|
|
|
#include <stdint.h>
|
2013-10-21 21:23:33 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-03 19:12:23 +00:00
|
|
|
#include "Units.h"
|
2012-12-17 21:24:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default values for the nsViewportInfo class.
|
|
|
|
*/
|
2015-10-03 03:08:18 +00:00
|
|
|
static const mozilla::LayoutDeviceToScreenScale kViewportMinScale(0.1f);
|
2013-09-03 19:12:23 +00:00
|
|
|
static const mozilla::LayoutDeviceToScreenScale kViewportMaxScale(10.0f);
|
2013-12-05 15:15:35 +00:00
|
|
|
static const mozilla::CSSIntSize kViewportMinSize(200, 40);
|
2013-09-03 19:12:24 +00:00
|
|
|
static const mozilla::CSSIntSize kViewportMaxSize(10000, 10000);
|
2012-12-17 21:24:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Information retrieved from the <meta name="viewport"> tag. See
|
2015-10-23 17:21:57 +00:00
|
|
|
* nsIDocument::GetViewportInfo for more information on this functionality.
|
2012-12-17 21:24:41 +00:00
|
|
|
*/
|
2013-04-12 03:20:09 +00:00
|
|
|
class MOZ_STACK_CLASS nsViewportInfo
|
2012-12-17 21:24:41 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-11-20 01:24:57 +00:00
|
|
|
enum class AutoSizeFlag {
|
|
|
|
AutoSize,
|
|
|
|
FixedSize,
|
|
|
|
};
|
2018-11-20 03:55:56 +00:00
|
|
|
enum class AutoScaleFlag {
|
|
|
|
AutoScale,
|
|
|
|
FixedScale,
|
|
|
|
};
|
2018-11-20 01:24:57 +00:00
|
|
|
enum class ZoomFlag {
|
|
|
|
AllowZoom,
|
|
|
|
DisallowZoom,
|
|
|
|
};
|
2013-12-03 15:10:26 +00:00
|
|
|
nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize,
|
2014-08-09 18:50:07 +00:00
|
|
|
const mozilla::CSSToScreenScale& aDefaultZoom,
|
2018-11-20 01:24:57 +00:00
|
|
|
ZoomFlag aZoomFlag) :
|
2014-08-09 18:50:07 +00:00
|
|
|
mDefaultZoom(aDefaultZoom),
|
2018-10-15 23:53:42 +00:00
|
|
|
mDefaultZoomValid(true),
|
2012-12-17 21:24:41 +00:00
|
|
|
mAutoSize(true),
|
2018-11-20 01:24:57 +00:00
|
|
|
mAllowZoom(aZoomFlag == ZoomFlag::AllowZoom)
|
2012-12-17 21:24:41 +00:00
|
|
|
{
|
2014-05-28 20:27:38 +00:00
|
|
|
mSize = mozilla::ScreenSize(aDisplaySize) / mDefaultZoom;
|
2013-09-03 19:12:23 +00:00
|
|
|
mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f);
|
|
|
|
mMinZoom = pixelRatio * kViewportMinScale;
|
|
|
|
mMaxZoom = pixelRatio * kViewportMaxScale;
|
2012-12-17 21:24:41 +00:00
|
|
|
ConstrainViewportValues();
|
|
|
|
}
|
|
|
|
|
2013-09-03 19:12:23 +00:00
|
|
|
nsViewportInfo(const mozilla::CSSToScreenScale& aDefaultZoom,
|
|
|
|
const mozilla::CSSToScreenScale& aMinZoom,
|
|
|
|
const mozilla::CSSToScreenScale& aMaxZoom,
|
2014-05-28 20:27:38 +00:00
|
|
|
const mozilla::CSSSize& aSize,
|
2018-11-20 01:24:57 +00:00
|
|
|
AutoSizeFlag aAutoSizeFlag,
|
2018-11-20 03:55:56 +00:00
|
|
|
AutoScaleFlag aAutoScaleFlag,
|
2018-11-20 01:24:57 +00:00
|
|
|
ZoomFlag aZoomFlag) :
|
2012-12-17 21:24:41 +00:00
|
|
|
mDefaultZoom(aDefaultZoom),
|
|
|
|
mMinZoom(aMinZoom),
|
|
|
|
mMaxZoom(aMaxZoom),
|
2013-09-03 19:12:24 +00:00
|
|
|
mSize(aSize),
|
2018-11-20 03:55:56 +00:00
|
|
|
mDefaultZoomValid(aAutoScaleFlag != AutoScaleFlag::AutoScale),
|
2018-11-20 01:24:57 +00:00
|
|
|
mAutoSize(aAutoSizeFlag == AutoSizeFlag::AutoSize),
|
|
|
|
mAllowZoom(aZoomFlag == ZoomFlag::AllowZoom)
|
2012-12-17 21:24:41 +00:00
|
|
|
{
|
|
|
|
ConstrainViewportValues();
|
|
|
|
}
|
|
|
|
|
2015-10-03 03:08:18 +00:00
|
|
|
bool IsDefaultZoomValid() const { return mDefaultZoomValid; }
|
2015-06-17 16:32:42 +00:00
|
|
|
mozilla::CSSToScreenScale GetDefaultZoom() const { return mDefaultZoom; }
|
|
|
|
mozilla::CSSToScreenScale GetMinZoom() const { return mMinZoom; }
|
|
|
|
mozilla::CSSToScreenScale GetMaxZoom() const { return mMaxZoom; }
|
2012-12-17 21:24:41 +00:00
|
|
|
|
2015-06-17 16:32:42 +00:00
|
|
|
mozilla::CSSSize GetSize() const { return mSize; }
|
2012-12-17 21:24:41 +00:00
|
|
|
|
2015-06-17 16:32:42 +00:00
|
|
|
bool IsAutoSizeEnabled() const { return mAutoSize; }
|
|
|
|
bool IsZoomAllowed() const { return mAllowZoom; }
|
2012-12-17 21:24:41 +00:00
|
|
|
|
2018-10-19 04:19:21 +00:00
|
|
|
enum {
|
|
|
|
Auto = -1,
|
|
|
|
ExtendToZoom = -2,
|
|
|
|
DeviceSize = -3, // 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.
|
|
|
|
// https://drafts.csswg.org/css-device-adapt/#constraining-defs
|
|
|
|
static const float& Max(const float& aA, const float& aB);
|
|
|
|
static const float& Min(const float& aA, const float& aB);
|
|
|
|
|
2012-12-17 21:24:41 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constrain the viewport calculations from the
|
2015-10-23 17:21:57 +00:00
|
|
|
* nsIDocument::GetViewportInfo() function in order to always return
|
2012-12-17 21:24:41 +00:00
|
|
|
* sane minimum/maximum values.
|
|
|
|
*/
|
|
|
|
void ConstrainViewportValues();
|
|
|
|
|
|
|
|
// Default zoom indicates the level at which the display is 'zoomed in'
|
|
|
|
// initially for the user, upon loading of the page.
|
2013-09-03 19:12:23 +00:00
|
|
|
mozilla::CSSToScreenScale mDefaultZoom;
|
2012-12-17 21:24:41 +00:00
|
|
|
|
|
|
|
// The minimum zoom level permitted by the page.
|
2013-09-03 19:12:23 +00:00
|
|
|
mozilla::CSSToScreenScale mMinZoom;
|
2012-12-17 21:24:41 +00:00
|
|
|
|
|
|
|
// The maximum zoom level permitted by the page.
|
2013-09-03 19:12:23 +00:00
|
|
|
mozilla::CSSToScreenScale mMaxZoom;
|
2012-12-17 21:24:41 +00:00
|
|
|
|
2013-09-03 19:12:24 +00:00
|
|
|
// The size of the viewport, specified by the <meta name="viewport"> tag.
|
2014-05-28 20:27:38 +00:00
|
|
|
mozilla::CSSSize mSize;
|
2012-12-17 21:24:41 +00:00
|
|
|
|
2018-10-15 23:53:42 +00:00
|
|
|
// If the default zoom was specified and was between the min and max
|
|
|
|
// zoom values.
|
2018-11-20 03:55:56 +00:00
|
|
|
// FIXME: Bug 1504362 - Unify this and mDefaultZoom into
|
|
|
|
// Maybe<CSSToScreenScale>.
|
2018-10-15 23:53:42 +00:00
|
|
|
bool mDefaultZoomValid;
|
|
|
|
|
2012-12-17 21:24:41 +00:00
|
|
|
// Whether or not we should automatically size the viewport to the device's
|
|
|
|
// width. This is true if the document has been optimized for mobile, and
|
|
|
|
// the width property of a specified <meta name="viewport"> tag is either
|
|
|
|
// not specified, or is set to the special value 'device-width'.
|
|
|
|
bool mAutoSize;
|
|
|
|
|
|
|
|
// Whether or not the user can zoom in and out on the page. Default is true.
|
|
|
|
bool mAllowZoom;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|