content/base/public/nsViewportInfo.h

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsViewportInfo_h___
michael@0 6 #define nsViewportInfo_h___
michael@0 7
michael@0 8 #include <stdint.h>
michael@0 9 #include "mozilla/Attributes.h"
michael@0 10 #include "Units.h"
michael@0 11
michael@0 12 /**
michael@0 13 * Default values for the nsViewportInfo class.
michael@0 14 */
michael@0 15 static const mozilla::LayoutDeviceToScreenScale kViewportMinScale(0.0f);
michael@0 16 static const mozilla::LayoutDeviceToScreenScale kViewportMaxScale(10.0f);
michael@0 17 static const mozilla::CSSIntSize kViewportMinSize(200, 40);
michael@0 18 static const mozilla::CSSIntSize kViewportMaxSize(10000, 10000);
michael@0 19 static const int32_t kViewportDefaultScreenWidth = 980;
michael@0 20
michael@0 21 /**
michael@0 22 * Information retrieved from the <meta name="viewport"> tag. See
michael@0 23 * nsContentUtils::GetViewportInfo for more information on this functionality.
michael@0 24 */
michael@0 25 class MOZ_STACK_CLASS nsViewportInfo
michael@0 26 {
michael@0 27 public:
michael@0 28 nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize,
michael@0 29 bool aAllowZoom = true, bool aAllowDoubleTapZoom = true) :
michael@0 30 mDefaultZoom(1.0),
michael@0 31 mAutoSize(true),
michael@0 32 mAllowZoom(aAllowZoom),
michael@0 33 mAllowDoubleTapZoom(aAllowDoubleTapZoom)
michael@0 34 {
michael@0 35 mSize = mozilla::gfx::RoundedToInt(mozilla::ScreenSize(aDisplaySize) / mDefaultZoom);
michael@0 36 mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f);
michael@0 37 mMinZoom = pixelRatio * kViewportMinScale;
michael@0 38 mMaxZoom = pixelRatio * kViewportMaxScale;
michael@0 39 ConstrainViewportValues();
michael@0 40 }
michael@0 41
michael@0 42 nsViewportInfo(const mozilla::CSSToScreenScale& aDefaultZoom,
michael@0 43 const mozilla::CSSToScreenScale& aMinZoom,
michael@0 44 const mozilla::CSSToScreenScale& aMaxZoom,
michael@0 45 const mozilla::CSSIntSize& aSize,
michael@0 46 bool aAutoSize,
michael@0 47 bool aAllowZoom,
michael@0 48 bool aAllowDoubleTapZoom) :
michael@0 49 mDefaultZoom(aDefaultZoom),
michael@0 50 mMinZoom(aMinZoom),
michael@0 51 mMaxZoom(aMaxZoom),
michael@0 52 mSize(aSize),
michael@0 53 mAutoSize(aAutoSize),
michael@0 54 mAllowZoom(aAllowZoom),
michael@0 55 mAllowDoubleTapZoom(aAllowDoubleTapZoom)
michael@0 56 {
michael@0 57 ConstrainViewportValues();
michael@0 58 }
michael@0 59
michael@0 60 mozilla::CSSToScreenScale GetDefaultZoom() { return mDefaultZoom; }
michael@0 61 void SetDefaultZoom(const mozilla::CSSToScreenScale& aDefaultZoom);
michael@0 62 mozilla::CSSToScreenScale GetMinZoom() { return mMinZoom; }
michael@0 63 mozilla::CSSToScreenScale GetMaxZoom() { return mMaxZoom; }
michael@0 64
michael@0 65 mozilla::CSSIntSize GetSize() { return mSize; }
michael@0 66
michael@0 67 bool IsAutoSizeEnabled() { return mAutoSize; }
michael@0 68 bool IsZoomAllowed() { return mAllowZoom; }
michael@0 69 bool IsDoubleTapZoomAllowed() { return mAllowDoubleTapZoom; }
michael@0 70
michael@0 71 void SetAllowDoubleTapZoom(bool aAllowDoubleTapZoom) { mAllowDoubleTapZoom = aAllowDoubleTapZoom; }
michael@0 72
michael@0 73 private:
michael@0 74
michael@0 75 /**
michael@0 76 * Constrain the viewport calculations from the
michael@0 77 * nsContentUtils::GetViewportInfo() function in order to always return
michael@0 78 * sane minimum/maximum values.
michael@0 79 */
michael@0 80 void ConstrainViewportValues();
michael@0 81
michael@0 82 // Default zoom indicates the level at which the display is 'zoomed in'
michael@0 83 // initially for the user, upon loading of the page.
michael@0 84 mozilla::CSSToScreenScale mDefaultZoom;
michael@0 85
michael@0 86 // The minimum zoom level permitted by the page.
michael@0 87 mozilla::CSSToScreenScale mMinZoom;
michael@0 88
michael@0 89 // The maximum zoom level permitted by the page.
michael@0 90 mozilla::CSSToScreenScale mMaxZoom;
michael@0 91
michael@0 92 // The size of the viewport, specified by the <meta name="viewport"> tag.
michael@0 93 mozilla::CSSIntSize mSize;
michael@0 94
michael@0 95 // Whether or not we should automatically size the viewport to the device's
michael@0 96 // width. This is true if the document has been optimized for mobile, and
michael@0 97 // the width property of a specified <meta name="viewport"> tag is either
michael@0 98 // not specified, or is set to the special value 'device-width'.
michael@0 99 bool mAutoSize;
michael@0 100
michael@0 101 // Whether or not the user can zoom in and out on the page. Default is true.
michael@0 102 bool mAllowZoom;
michael@0 103
michael@0 104 // Whether or not the user can double-tap to zoom in. When this is disabled
michael@0 105 // we can dispatch click events faster on a single tap because we don't have
michael@0 106 // to wait to detect the double-tap
michael@0 107 bool mAllowDoubleTapZoom;
michael@0 108 };
michael@0 109
michael@0 110 #endif
michael@0 111

mercurial