LCOV - code coverage report
Current view: top level - dom/base - nsViewportInfo.h (source / functions) Hit Total Coverage
Test: output.info Lines: 11 21 52.4 %
Date: 2017-07-14 16:53:18 Functions: 3 9 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       4             : 
       5             : #ifndef nsViewportInfo_h___
       6             : #define nsViewportInfo_h___
       7             : 
       8             : #include <stdint.h>
       9             : #include "mozilla/Attributes.h"
      10             : #include "Units.h"
      11             : 
      12             : /**
      13             :  * Default values for the nsViewportInfo class.
      14             :  */
      15             : static const mozilla::LayoutDeviceToScreenScale kViewportMinScale(0.1f);
      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             : 
      20             : /**
      21             :  * Information retrieved from the <meta name="viewport"> tag. See
      22             :  * nsIDocument::GetViewportInfo for more information on this functionality.
      23             :  */
      24             : class MOZ_STACK_CLASS nsViewportInfo
      25             : {
      26             :   public:
      27           1 :     nsViewportInfo(const mozilla::ScreenIntSize& aDisplaySize,
      28             :                    const mozilla::CSSToScreenScale& aDefaultZoom,
      29           1 :                    bool aAllowZoom) :
      30             :       mDefaultZoomValid(true),
      31             :       mDefaultZoom(aDefaultZoom),
      32             :       mAutoSize(true),
      33           1 :       mAllowZoom(aAllowZoom)
      34             :     {
      35           1 :         mSize = mozilla::ScreenSize(aDisplaySize) / mDefaultZoom;
      36           1 :         mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f);
      37           1 :         mMinZoom = pixelRatio * kViewportMinScale;
      38           1 :         mMaxZoom = pixelRatio * kViewportMaxScale;
      39           1 :         ConstrainViewportValues();
      40           1 :     }
      41             : 
      42           0 :     nsViewportInfo(const mozilla::CSSToScreenScale& aDefaultZoom,
      43             :                    const mozilla::CSSToScreenScale& aMinZoom,
      44             :                    const mozilla::CSSToScreenScale& aMaxZoom,
      45             :                    const mozilla::CSSSize& aSize,
      46             :                    bool aAutoSize,
      47           0 :                    bool aAllowZoom) :
      48             :                      mDefaultZoomValid(true),
      49             :                      mDefaultZoom(aDefaultZoom),
      50             :                      mMinZoom(aMinZoom),
      51             :                      mMaxZoom(aMaxZoom),
      52             :                      mSize(aSize),
      53             :                      mAutoSize(aAutoSize),
      54           0 :                      mAllowZoom(aAllowZoom)
      55             :     {
      56           0 :       ConstrainViewportValues();
      57           0 :     }
      58             : 
      59           0 :     bool IsDefaultZoomValid() const { return mDefaultZoomValid; }
      60           2 :     mozilla::CSSToScreenScale GetDefaultZoom() const { return mDefaultZoom; }
      61           0 :     mozilla::CSSToScreenScale GetMinZoom() const { return mMinZoom; }
      62           0 :     mozilla::CSSToScreenScale GetMaxZoom() const { return mMaxZoom; }
      63             : 
      64           0 :     mozilla::CSSSize GetSize() const { return mSize; }
      65             : 
      66           0 :     bool IsAutoSizeEnabled() const { return mAutoSize; }
      67           1 :     bool IsZoomAllowed() const { return mAllowZoom; }
      68             : 
      69             :   private:
      70             : 
      71             :     /**
      72             :      * Constrain the viewport calculations from the
      73             :      * nsIDocument::GetViewportInfo() function in order to always return
      74             :      * sane minimum/maximum values.
      75             :      */
      76             :     void ConstrainViewportValues();
      77             : 
      78             :     // If the default zoom was specified and was between the min and max
      79             :     // zoom values.
      80             :     bool mDefaultZoomValid;
      81             : 
      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;
      85             : 
      86             :     // The minimum zoom level permitted by the page.
      87             :     mozilla::CSSToScreenScale mMinZoom;
      88             : 
      89             :     // The maximum zoom level permitted by the page.
      90             :     mozilla::CSSToScreenScale mMaxZoom;
      91             : 
      92             :     // The size of the viewport, specified by the <meta name="viewport"> tag.
      93             :     mozilla::CSSSize mSize;
      94             : 
      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;
     100             : 
     101             :     // Whether or not the user can zoom in and out on the page. Default is true.
     102             :     bool mAllowZoom;
     103             : };
     104             : 
     105             : #endif
     106             : 

Generated by: LCOV version 1.13