• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2001 Dirk Mueller (mueller@kde.org)
5  *           (C) 2006 Alexey Proskuryakov (ap@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 blink {
36 
37 class LocalFrame;
38 
39 struct ViewportDescription {
40 
41     enum Type {
42         // These are ordered in increasing importance.
43         UserAgentStyleSheet,
44         HandheldFriendlyMeta,
45         MobileOptimizedMeta,
46         ViewportMeta,
47         AuthorStyleSheet
48     } type;
49 
50     enum {
51         ValueAuto = -1,
52         ValueDeviceWidth = -2,
53         ValueDeviceHeight = -3,
54         ValuePortrait = -4,
55         ValueLandscape = -5,
56         ValueDeviceDPI = -6,
57         ValueLowDPI = -7,
58         ValueMediumDPI = -8,
59         ValueHighDPI = -9,
60         ValueExtendToZoom = -10
61     };
62 
63     ViewportDescription(Type type = UserAgentStyleSheet)
typeViewportDescription64         : type(type)
65         , zoom(ValueAuto)
66         , minZoom(ValueAuto)
67         , maxZoom(ValueAuto)
68         , userZoom(true)
69         , orientation(ValueAuto)
70         , deprecatedTargetDensityDPI(ValueAuto)
71         , zoomIsExplicit(false)
72         , minZoomIsExplicit(false)
73         , maxZoomIsExplicit(false)
74         , userZoomIsExplicit(false)
75     {
76     }
77 
78     // All arguments are in CSS units.
79     PageScaleConstraints resolve(const FloatSize& initialViewportSize, Length legacyFallbackWidth) const;
80 
81     Length minWidth;
82     Length maxWidth;
83     Length minHeight;
84     Length maxHeight;
85     float zoom;
86     float minZoom;
87     float maxZoom;
88     bool userZoom;
89     float orientation;
90     float deprecatedTargetDensityDPI; // Only used for Android WebView
91 
92     // Whether the computed value was explicitly specified rather than being
93     // inferred.
94     bool zoomIsExplicit;
95     bool minZoomIsExplicit;
96     bool maxZoomIsExplicit;
97     bool userZoomIsExplicit;
98 
99     bool operator==(const ViewportDescription& other) const
100     {
101         // Used for figuring out whether to reset the viewport or not,
102         // thus we are not taking type into account.
103         return minWidth == other.minWidth
104             && maxWidth == other.maxWidth
105             && minHeight == other.minHeight
106             && maxHeight == other.maxHeight
107             && zoom == other.zoom
108             && minZoom == other.minZoom
109             && maxZoom == other.maxZoom
110             && userZoom == other.userZoom
111             && orientation == other.orientation
112             && deprecatedTargetDensityDPI == other.deprecatedTargetDensityDPI
113             && zoomIsExplicit == other.zoomIsExplicit
114             && minZoomIsExplicit == other.minZoomIsExplicit
115             && maxZoomIsExplicit == other.maxZoomIsExplicit
116             && userZoomIsExplicit == other.userZoomIsExplicit;
117     }
118 
119     bool operator!=(const ViewportDescription& other) const
120     {
121         return !(*this == other);
122     }
123 
isLegacyViewportTypeViewportDescription124     bool isLegacyViewportType() const { return type >= HandheldFriendlyMeta && type <= ViewportMeta; }
isMetaViewportTypeViewportDescription125     bool isMetaViewportType() const { return type == ViewportMeta; }
isSpecifiedByAuthorViewportDescription126     bool isSpecifiedByAuthor() const { return type != UserAgentStyleSheet; }
127 
128     // Reports UMA stat on whether the page is considered mobile or desktop and what kind of
129     // mobile it is. Applies only to Android, must only be called once per page load.
130     void reportMobilePageStats(const LocalFrame*) const;
131 
132 private:
133     enum Direction { Horizontal, Vertical };
134     static float resolveViewportLength(const Length&, const FloatSize& initialViewportSize, Direction);
135 };
136 
137 } // namespace blink
138 
139 #endif // ViewportDescription_h
140