michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsViewportInfo_h___ michael@0: #define nsViewportInfo_h___ michael@0: michael@0: #include michael@0: #include "mozilla/Attributes.h" michael@0: #include "Units.h" michael@0: michael@0: /** michael@0: * Default values for the nsViewportInfo class. michael@0: */ michael@0: static const mozilla::LayoutDeviceToScreenScale kViewportMinScale(0.0f); michael@0: static const mozilla::LayoutDeviceToScreenScale kViewportMaxScale(10.0f); michael@0: static const mozilla::CSSIntSize kViewportMinSize(200, 40); michael@0: static const mozilla::CSSIntSize kViewportMaxSize(10000, 10000); michael@0: static const int32_t kViewportDefaultScreenWidth = 980; michael@0: michael@0: /** michael@0: * Information retrieved from the tag. See michael@0: * nsContentUtils::GetViewportInfo for more information on this functionality. michael@0: */ michael@0: class MOZ_STACK_CLASS nsViewportInfo michael@0: { michael@0: public: michael@0: nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize, michael@0: bool aAllowZoom = true, bool aAllowDoubleTapZoom = true) : michael@0: mDefaultZoom(1.0), michael@0: mAutoSize(true), michael@0: mAllowZoom(aAllowZoom), michael@0: mAllowDoubleTapZoom(aAllowDoubleTapZoom) michael@0: { michael@0: mSize = mozilla::gfx::RoundedToInt(mozilla::ScreenSize(aDisplaySize) / mDefaultZoom); michael@0: mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f); michael@0: mMinZoom = pixelRatio * kViewportMinScale; michael@0: mMaxZoom = pixelRatio * kViewportMaxScale; michael@0: ConstrainViewportValues(); michael@0: } michael@0: michael@0: nsViewportInfo(const mozilla::CSSToScreenScale& aDefaultZoom, michael@0: const mozilla::CSSToScreenScale& aMinZoom, michael@0: const mozilla::CSSToScreenScale& aMaxZoom, michael@0: const mozilla::CSSIntSize& aSize, michael@0: bool aAutoSize, michael@0: bool aAllowZoom, michael@0: bool aAllowDoubleTapZoom) : michael@0: mDefaultZoom(aDefaultZoom), michael@0: mMinZoom(aMinZoom), michael@0: mMaxZoom(aMaxZoom), michael@0: mSize(aSize), michael@0: mAutoSize(aAutoSize), michael@0: mAllowZoom(aAllowZoom), michael@0: mAllowDoubleTapZoom(aAllowDoubleTapZoom) michael@0: { michael@0: ConstrainViewportValues(); michael@0: } michael@0: michael@0: mozilla::CSSToScreenScale GetDefaultZoom() { return mDefaultZoom; } michael@0: void SetDefaultZoom(const mozilla::CSSToScreenScale& aDefaultZoom); michael@0: mozilla::CSSToScreenScale GetMinZoom() { return mMinZoom; } michael@0: mozilla::CSSToScreenScale GetMaxZoom() { return mMaxZoom; } michael@0: michael@0: mozilla::CSSIntSize GetSize() { return mSize; } michael@0: michael@0: bool IsAutoSizeEnabled() { return mAutoSize; } michael@0: bool IsZoomAllowed() { return mAllowZoom; } michael@0: bool IsDoubleTapZoomAllowed() { return mAllowDoubleTapZoom; } michael@0: michael@0: void SetAllowDoubleTapZoom(bool aAllowDoubleTapZoom) { mAllowDoubleTapZoom = aAllowDoubleTapZoom; } michael@0: michael@0: private: michael@0: michael@0: /** michael@0: * Constrain the viewport calculations from the michael@0: * nsContentUtils::GetViewportInfo() function in order to always return michael@0: * sane minimum/maximum values. michael@0: */ michael@0: void ConstrainViewportValues(); michael@0: michael@0: // Default zoom indicates the level at which the display is 'zoomed in' michael@0: // initially for the user, upon loading of the page. michael@0: mozilla::CSSToScreenScale mDefaultZoom; michael@0: michael@0: // The minimum zoom level permitted by the page. michael@0: mozilla::CSSToScreenScale mMinZoom; michael@0: michael@0: // The maximum zoom level permitted by the page. michael@0: mozilla::CSSToScreenScale mMaxZoom; michael@0: michael@0: // The size of the viewport, specified by the tag. michael@0: mozilla::CSSIntSize mSize; michael@0: michael@0: // Whether or not we should automatically size the viewport to the device's michael@0: // width. This is true if the document has been optimized for mobile, and michael@0: // the width property of a specified tag is either michael@0: // not specified, or is set to the special value 'device-width'. michael@0: bool mAutoSize; michael@0: michael@0: // Whether or not the user can zoom in and out on the page. Default is true. michael@0: bool mAllowZoom; michael@0: michael@0: // Whether or not the user can double-tap to zoom in. When this is disabled michael@0: // we can dispatch click events faster on a single tap because we don't have michael@0: // to wait to detect the double-tap michael@0: bool mAllowDoubleTapZoom; michael@0: }; michael@0: michael@0: #endif michael@0: