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 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#pragma once
29
30#include "FloatSize.h"
31#include <wtf/Forward.h>
32
33namespace WebCore {
34
35class Document;
36
37enum ViewportErrorCode {
38 UnrecognizedViewportArgumentKeyError,
39 UnrecognizedViewportArgumentValueError,
40 TruncatedViewportArgumentValueError,
41 MaximumScaleTooLargeError
42};
43
44enum class ViewportFit {
45 Auto,
46 Contain,
47 Cover
48};
49
50struct ViewportAttributes {
51 FloatSize layoutSize;
52
53 float initialScale;
54 float minimumScale;
55 float maximumScale;
56
57 float userScalable;
58 float orientation;
59 float shrinkToFit;
60
61 ViewportFit viewportFit;
62};
63
64struct ViewportArguments {
65
66 enum Type {
67 // These are ordered in increasing importance.
68 Implicit,
69#if PLATFORM(IOS_FAMILY)
70 PluginDocument,
71 ImageDocument,
72#endif
73 ViewportMeta,
74 CSSDeviceAdaptation
75 } type;
76
77 enum {
78 ValueAuto = -1,
79 ValueDeviceWidth = -2,
80 ValueDeviceHeight = -3,
81 ValuePortrait = -4,
82 ValueLandscape = -5
83 };
84
85 explicit ViewportArguments(Type type = Implicit)
86 : type(type)
87 {
88 }
89
90 // All arguments are in CSS units.
91 ViewportAttributes resolve(const FloatSize& initialViewportSize, const FloatSize& deviceSize, int defaultWidth) const;
92
93 float width { ValueAuto };
94 float minWidth { ValueAuto };
95 float maxWidth { ValueAuto };
96 float height { ValueAuto };
97 float minHeight { ValueAuto };
98 float maxHeight { ValueAuto };
99 float zoom { ValueAuto };
100 float minZoom { ValueAuto };
101 float maxZoom { ValueAuto };
102 float userZoom { ValueAuto };
103 float orientation { ValueAuto };
104 float shrinkToFit { ValueAuto };
105 ViewportFit viewportFit { ViewportFit::Auto };
106 bool widthWasExplicit { false };
107
108 bool operator==(const ViewportArguments& other) const
109 {
110 // Used for figuring out whether to reset the viewport or not,
111 // thus we are not taking type into account.
112 return width == other.width
113 && minWidth == other.minWidth
114 && maxWidth == other.maxWidth
115 && height == other.height
116 && minHeight == other.minHeight
117 && maxHeight == other.maxHeight
118 && zoom == other.zoom
119 && minZoom == other.minZoom
120 && maxZoom == other.maxZoom
121 && userZoom == other.userZoom
122 && orientation == other.orientation
123 && shrinkToFit == other.shrinkToFit
124 && viewportFit == other.viewportFit
125 && widthWasExplicit == other.widthWasExplicit;
126 }
127
128 bool operator!=(const ViewportArguments& other) const
129 {
130 return !(*this == other);
131 }
132
133#if PLATFORM(GTK)
134 // FIXME: We're going to keep this constant around until all embedders
135 // refactor their code to no longer need it.
136 static const float deprecatedTargetDPI;
137#endif
138};
139
140WEBCORE_EXPORT ViewportAttributes computeViewportAttributes(ViewportArguments args, int desktopWidth, int deviceWidth, int deviceHeight, float devicePixelRatio, IntSize visibleViewport);
141
142WEBCORE_EXPORT void restrictMinimumScaleFactorToViewportSize(ViewportAttributes& result, IntSize visibleViewport, float devicePixelRatio);
143WEBCORE_EXPORT void restrictScaleFactorToInitialScaleIfNotUserScalable(ViewportAttributes& result);
144WEBCORE_EXPORT float computeMinimumScaleFactorForContentContained(const ViewportAttributes& result, const IntSize& viewportSize, const IntSize& contentSize);
145
146typedef WTF::Function<void(ViewportErrorCode, const String&)> ViewportErrorHandler;
147void setViewportFeature(ViewportArguments&, Document&, StringView key, StringView value);
148WEBCORE_EXPORT void setViewportFeature(ViewportArguments&, StringView key, StringView value, bool viewportFitEnabled, const ViewportErrorHandler&);
149
150WTF::TextStream& operator<<(WTF::TextStream&, const ViewportArguments&);
151
152} // namespace WebCore
153