Home | History | Annotate | Download | only in dom
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2001 Dirk Mueller (mueller (at) kde.org)
      5  *           (C) 2006 Alexey Proskuryakov (ap (at) webkit.org)
      6  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
      7  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
      8  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
      9  * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
     10  *
     11  * This library is free software; you can redistribute it and/or
     12  * modify it under the terms of the GNU Library General Public
     13  * License as published by the Free Software Foundation; either
     14  * version 2 of the License, or (at your option) any later version.
     15  *
     16  * This library is distributed in the hope that it will be useful,
     17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     19  * Library General Public License for more details.
     20  *
     21  * You should have received a copy of the GNU Library General Public License
     22  * along with this library; see the file COPYING.LIB.  If not, write to
     23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     24  * Boston, MA 02110-1301, USA.
     25  *
     26  */
     27 
     28 #ifndef ViewportDescription_h
     29 #define ViewportDescription_h
     30 
     31 #include "core/page/PageScaleConstraints.h"
     32 #include "platform/Length.h"
     33 #include "platform/geometry/FloatSize.h"
     34 
     35 namespace WebCore {
     36 
     37 class KURL;
     38 class LocalFrame;
     39 
     40 struct ViewportDescription {
     41 
     42     enum Type {
     43         // These are ordered in increasing importance.
     44         UserAgentStyleSheet,
     45         HandheldFriendlyMeta,
     46         MobileOptimizedMeta,
     47         ViewportMeta,
     48         AuthorStyleSheet
     49     } type;
     50 
     51     enum {
     52         ValueAuto = -1,
     53         ValueDeviceWidth = -2,
     54         ValueDeviceHeight = -3,
     55         ValuePortrait = -4,
     56         ValueLandscape = -5,
     57         ValueDeviceDPI = -6,
     58         ValueLowDPI = -7,
     59         ValueMediumDPI = -8,
     60         ValueHighDPI = -9,
     61         ValueExtendToZoom = -10
     62     };
     63 
     64     ViewportDescription(Type type = UserAgentStyleSheet)
     65         : type(type)
     66         , zoom(ValueAuto)
     67         , minZoom(ValueAuto)
     68         , maxZoom(ValueAuto)
     69         , userZoom(true)
     70         , orientation(ValueAuto)
     71         , deprecatedTargetDensityDPI(ValueAuto)
     72         , zoomIsExplicit(false)
     73         , minZoomIsExplicit(false)
     74         , maxZoomIsExplicit(false)
     75         , userZoomIsExplicit(false)
     76     {
     77     }
     78 
     79     // All arguments are in CSS units.
     80     PageScaleConstraints resolve(const FloatSize& initialViewportSize, Length legacyFallbackWidth) const;
     81 
     82     Length minWidth;
     83     Length maxWidth;
     84     Length minHeight;
     85     Length maxHeight;
     86     float zoom;
     87     float minZoom;
     88     float maxZoom;
     89     bool userZoom;
     90     float orientation;
     91     float deprecatedTargetDensityDPI; // Only used for Android WebView
     92 
     93     // Whether the computed value was explicitly specified rather than being
     94     // inferred.
     95     bool zoomIsExplicit;
     96     bool minZoomIsExplicit;
     97     bool maxZoomIsExplicit;
     98     bool userZoomIsExplicit;
     99 
    100     bool operator==(const ViewportDescription& other) const
    101     {
    102         // Used for figuring out whether to reset the viewport or not,
    103         // thus we are not taking type into account.
    104         return minWidth == other.minWidth
    105             && maxWidth == other.maxWidth
    106             && minHeight == other.minHeight
    107             && maxHeight == other.maxHeight
    108             && zoom == other.zoom
    109             && minZoom == other.minZoom
    110             && maxZoom == other.maxZoom
    111             && userZoom == other.userZoom
    112             && orientation == other.orientation
    113             && deprecatedTargetDensityDPI == other.deprecatedTargetDensityDPI
    114             && zoomIsExplicit == other.zoomIsExplicit
    115             && minZoomIsExplicit == other.minZoomIsExplicit
    116             && maxZoomIsExplicit == other.maxZoomIsExplicit
    117             && userZoomIsExplicit == other.userZoomIsExplicit;
    118     }
    119 
    120     bool operator!=(const ViewportDescription& other) const
    121     {
    122         return !(*this == other);
    123     }
    124 
    125     bool isLegacyViewportType() const { return type >= HandheldFriendlyMeta && type <= ViewportMeta; }
    126     bool isMetaViewportType() const { return type == ViewportMeta; }
    127     bool isSpecifiedByAuthor() const { return type != UserAgentStyleSheet; }
    128 
    129     // Reports UMA stat on whether the page is considered mobile or desktop and what kind of
    130     // mobile it is. Applies only to Android, must only be called once per page load.
    131     void reportMobilePageStats(const LocalFrame*) const;
    132 
    133 private:
    134     enum Direction { Horizontal, Vertical };
    135     static float resolveViewportLength(const Length&, const FloatSize& initialViewportSize, Direction);
    136 };
    137 
    138 } // namespace WebCore
    139 
    140 #endif // ViewportDescription_h
    141