content/base/public/nsViewportInfo.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 /**
    13  * Default values for the nsViewportInfo class.
    14  */
    15 static const mozilla::LayoutDeviceToScreenScale kViewportMinScale(0.0f);
    16 static const mozilla::LayoutDeviceToScreenScale kViewportMaxScale(10.0f);
    17 static const mozilla::CSSIntSize kViewportMinSize(200, 40);
    18 static const mozilla::CSSIntSize kViewportMaxSize(10000, 10000);
    19 static const int32_t  kViewportDefaultScreenWidth = 980;
    21 /**
    22  * Information retrieved from the <meta name="viewport"> tag. See
    23  * nsContentUtils::GetViewportInfo for more information on this functionality.
    24  */
    25 class MOZ_STACK_CLASS nsViewportInfo
    26 {
    27   public:
    28     nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize,
    29                    bool aAllowZoom = true, bool aAllowDoubleTapZoom = true) :
    30       mDefaultZoom(1.0),
    31       mAutoSize(true),
    32       mAllowZoom(aAllowZoom),
    33       mAllowDoubleTapZoom(aAllowDoubleTapZoom)
    34     {
    35         mSize = mozilla::gfx::RoundedToInt(mozilla::ScreenSize(aDisplaySize) / mDefaultZoom);
    36         mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f);
    37         mMinZoom = pixelRatio * kViewportMinScale;
    38         mMaxZoom = pixelRatio * kViewportMaxScale;
    39         ConstrainViewportValues();
    40     }
    42     nsViewportInfo(const mozilla::CSSToScreenScale& aDefaultZoom,
    43                    const mozilla::CSSToScreenScale& aMinZoom,
    44                    const mozilla::CSSToScreenScale& aMaxZoom,
    45                    const mozilla::CSSIntSize& aSize,
    46                    bool aAutoSize,
    47                    bool aAllowZoom,
    48                    bool aAllowDoubleTapZoom) :
    49                      mDefaultZoom(aDefaultZoom),
    50                      mMinZoom(aMinZoom),
    51                      mMaxZoom(aMaxZoom),
    52                      mSize(aSize),
    53                      mAutoSize(aAutoSize),
    54                      mAllowZoom(aAllowZoom),
    55                      mAllowDoubleTapZoom(aAllowDoubleTapZoom)
    56     {
    57       ConstrainViewportValues();
    58     }
    60     mozilla::CSSToScreenScale GetDefaultZoom() { return mDefaultZoom; }
    61     void SetDefaultZoom(const mozilla::CSSToScreenScale& aDefaultZoom);
    62     mozilla::CSSToScreenScale GetMinZoom() { return mMinZoom; }
    63     mozilla::CSSToScreenScale GetMaxZoom() { return mMaxZoom; }
    65     mozilla::CSSIntSize GetSize() { return mSize; }
    67     bool IsAutoSizeEnabled() { return mAutoSize; }
    68     bool IsZoomAllowed() { return mAllowZoom; }
    69     bool IsDoubleTapZoomAllowed() { return mAllowDoubleTapZoom; }
    71     void SetAllowDoubleTapZoom(bool aAllowDoubleTapZoom) { mAllowDoubleTapZoom = aAllowDoubleTapZoom; }
    73   private:
    75     /**
    76      * Constrain the viewport calculations from the
    77      * nsContentUtils::GetViewportInfo() function in order to always return
    78      * sane minimum/maximum values.
    79      */
    80     void ConstrainViewportValues();
    82     // Default zoom indicates the level at which the display is 'zoomed in'
    83     // initially for the user, upon loading of the page.
    84     mozilla::CSSToScreenScale mDefaultZoom;
    86     // The minimum zoom level permitted by the page.
    87     mozilla::CSSToScreenScale mMinZoom;
    89     // The maximum zoom level permitted by the page.
    90     mozilla::CSSToScreenScale mMaxZoom;
    92     // The size of the viewport, specified by the <meta name="viewport"> tag.
    93     mozilla::CSSIntSize mSize;
    95     // Whether or not we should automatically size the viewport to the device's
    96     // width. This is true if the document has been optimized for mobile, and
    97     // the width property of a specified <meta name="viewport"> tag is either
    98     // not specified, or is set to the special value 'device-width'.
    99     bool mAutoSize;
   101     // Whether or not the user can zoom in and out on the page. Default is true.
   102     bool mAllowZoom;
   104     // Whether or not the user can double-tap to zoom in. When this is disabled
   105     // we can dispatch click events faster on a single tap because we don't have
   106     // to wait to detect the double-tap
   107     bool mAllowDoubleTapZoom;
   108 };
   110 #endif

mercurial