• 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 WebCore {
36 
37 struct ViewportDescription {
38 
39     enum Type {
40         // These are ordered in increasing importance.
41         UserAgentStyleSheet,
42         HandheldFriendlyMeta,
43         MobileOptimizedMeta,
44         ViewportMeta,
45         AuthorStyleSheet
46     } type;
47 
48     enum {
49         ValueAuto = -1,
50         ValueDeviceWidth = -2,
51         ValueDeviceHeight = -3,
52         ValuePortrait = -4,
53         ValueLandscape = -5,
54         ValueDeviceDPI = -6,
55         ValueLowDPI = -7,
56         ValueMediumDPI = -8,
57         ValueHighDPI = -9,
58         ValueExtendToZoom = -10
59     };
60 
61     ViewportDescription(Type type = UserAgentStyleSheet)
typeViewportDescription62         : type(type)
63         , zoom(ValueAuto)
64         , minZoom(ValueAuto)
65         , maxZoom(ValueAuto)
66         , userZoom(ValueAuto)
67         , orientation(ValueAuto)
68         , deprecatedTargetDensityDPI(ValueAuto)
69     {
70     }
71 
72     // All arguments are in CSS units.
73     PageScaleConstraints resolve(const FloatSize& initialViewportSize) const;
74 
75     Length minWidth;
76     Length maxWidth;
77     Length minHeight;
78     Length maxHeight;
79     float zoom;
80     float minZoom;
81     float maxZoom;
82     float userZoom;
83     float orientation;
84     float deprecatedTargetDensityDPI; // Only used for Android WebView
85 
86     bool operator==(const ViewportDescription& other) const
87     {
88         // Used for figuring out whether to reset the viewport or not,
89         // thus we are not taking type into account.
90         return minWidth == other.minWidth
91             && maxWidth == other.maxWidth
92             && minHeight == other.minHeight
93             && maxHeight == other.maxHeight
94             && zoom == other.zoom
95             && minZoom == other.minZoom
96             && maxZoom == other.maxZoom
97             && userZoom == other.userZoom
98             && orientation == other.orientation
99             && deprecatedTargetDensityDPI == other.deprecatedTargetDensityDPI;
100     }
101 
102     bool operator!=(const ViewportDescription& other) const
103     {
104         return !(*this == other);
105     }
106 
isLegacyViewportTypeViewportDescription107     bool isLegacyViewportType() const { return type >= HandheldFriendlyMeta && type <= ViewportMeta; }
isMetaViewportTypeViewportDescription108     bool isMetaViewportType() const { return type == ViewportMeta; }
isSpecifiedByAuthorViewportDescription109     bool isSpecifiedByAuthor() const { return type != UserAgentStyleSheet; }
110 
111 private:
112     enum Direction { Horizontal, Vertical };
113     static float resolveViewportLength(const Length&, const FloatSize& initialViewportSize, Direction);
114 };
115 
116 } // namespace WebCore
117 
118 #endif // ViewportDescription_h
119