content/base/public/nsViewportInfo.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/public/nsViewportInfo.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef nsViewportInfo_h___
     1.9 +#define nsViewportInfo_h___
    1.10 +
    1.11 +#include <stdint.h>
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "Units.h"
    1.14 +
    1.15 +/**
    1.16 + * Default values for the nsViewportInfo class.
    1.17 + */
    1.18 +static const mozilla::LayoutDeviceToScreenScale kViewportMinScale(0.0f);
    1.19 +static const mozilla::LayoutDeviceToScreenScale kViewportMaxScale(10.0f);
    1.20 +static const mozilla::CSSIntSize kViewportMinSize(200, 40);
    1.21 +static const mozilla::CSSIntSize kViewportMaxSize(10000, 10000);
    1.22 +static const int32_t  kViewportDefaultScreenWidth = 980;
    1.23 +
    1.24 +/**
    1.25 + * Information retrieved from the <meta name="viewport"> tag. See
    1.26 + * nsContentUtils::GetViewportInfo for more information on this functionality.
    1.27 + */
    1.28 +class MOZ_STACK_CLASS nsViewportInfo
    1.29 +{
    1.30 +  public:
    1.31 +    nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize,
    1.32 +                   bool aAllowZoom = true, bool aAllowDoubleTapZoom = true) :
    1.33 +      mDefaultZoom(1.0),
    1.34 +      mAutoSize(true),
    1.35 +      mAllowZoom(aAllowZoom),
    1.36 +      mAllowDoubleTapZoom(aAllowDoubleTapZoom)
    1.37 +    {
    1.38 +        mSize = mozilla::gfx::RoundedToInt(mozilla::ScreenSize(aDisplaySize) / mDefaultZoom);
    1.39 +        mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f);
    1.40 +        mMinZoom = pixelRatio * kViewportMinScale;
    1.41 +        mMaxZoom = pixelRatio * kViewportMaxScale;
    1.42 +        ConstrainViewportValues();
    1.43 +    }
    1.44 +
    1.45 +    nsViewportInfo(const mozilla::CSSToScreenScale& aDefaultZoom,
    1.46 +                   const mozilla::CSSToScreenScale& aMinZoom,
    1.47 +                   const mozilla::CSSToScreenScale& aMaxZoom,
    1.48 +                   const mozilla::CSSIntSize& aSize,
    1.49 +                   bool aAutoSize,
    1.50 +                   bool aAllowZoom,
    1.51 +                   bool aAllowDoubleTapZoom) :
    1.52 +                     mDefaultZoom(aDefaultZoom),
    1.53 +                     mMinZoom(aMinZoom),
    1.54 +                     mMaxZoom(aMaxZoom),
    1.55 +                     mSize(aSize),
    1.56 +                     mAutoSize(aAutoSize),
    1.57 +                     mAllowZoom(aAllowZoom),
    1.58 +                     mAllowDoubleTapZoom(aAllowDoubleTapZoom)
    1.59 +    {
    1.60 +      ConstrainViewportValues();
    1.61 +    }
    1.62 +
    1.63 +    mozilla::CSSToScreenScale GetDefaultZoom() { return mDefaultZoom; }
    1.64 +    void SetDefaultZoom(const mozilla::CSSToScreenScale& aDefaultZoom);
    1.65 +    mozilla::CSSToScreenScale GetMinZoom() { return mMinZoom; }
    1.66 +    mozilla::CSSToScreenScale GetMaxZoom() { return mMaxZoom; }
    1.67 +
    1.68 +    mozilla::CSSIntSize GetSize() { return mSize; }
    1.69 +
    1.70 +    bool IsAutoSizeEnabled() { return mAutoSize; }
    1.71 +    bool IsZoomAllowed() { return mAllowZoom; }
    1.72 +    bool IsDoubleTapZoomAllowed() { return mAllowDoubleTapZoom; }
    1.73 +
    1.74 +    void SetAllowDoubleTapZoom(bool aAllowDoubleTapZoom) { mAllowDoubleTapZoom = aAllowDoubleTapZoom; }
    1.75 +
    1.76 +  private:
    1.77 +
    1.78 +    /**
    1.79 +     * Constrain the viewport calculations from the
    1.80 +     * nsContentUtils::GetViewportInfo() function in order to always return
    1.81 +     * sane minimum/maximum values.
    1.82 +     */
    1.83 +    void ConstrainViewportValues();
    1.84 +
    1.85 +    // Default zoom indicates the level at which the display is 'zoomed in'
    1.86 +    // initially for the user, upon loading of the page.
    1.87 +    mozilla::CSSToScreenScale mDefaultZoom;
    1.88 +
    1.89 +    // The minimum zoom level permitted by the page.
    1.90 +    mozilla::CSSToScreenScale mMinZoom;
    1.91 +
    1.92 +    // The maximum zoom level permitted by the page.
    1.93 +    mozilla::CSSToScreenScale mMaxZoom;
    1.94 +
    1.95 +    // The size of the viewport, specified by the <meta name="viewport"> tag.
    1.96 +    mozilla::CSSIntSize mSize;
    1.97 +
    1.98 +    // Whether or not we should automatically size the viewport to the device's
    1.99 +    // width. This is true if the document has been optimized for mobile, and
   1.100 +    // the width property of a specified <meta name="viewport"> tag is either
   1.101 +    // not specified, or is set to the special value 'device-width'.
   1.102 +    bool mAutoSize;
   1.103 +
   1.104 +    // Whether or not the user can zoom in and out on the page. Default is true.
   1.105 +    bool mAllowZoom;
   1.106 +
   1.107 +    // Whether or not the user can double-tap to zoom in. When this is disabled
   1.108 +    // we can dispatch click events faster on a single tap because we don't have
   1.109 +    // to wait to detect the double-tap
   1.110 +    bool mAllowDoubleTapZoom;
   1.111 +};
   1.112 +
   1.113 +#endif
   1.114 +

mercurial