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