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 ViewportArguments_h
     29 #define ViewportArguments_h
     30 
     31 #include "core/page/PageScaleConstraints.h"
     32 #include "core/platform/Length.h"
     33 #include "core/platform/graphics/FloatSize.h"
     34 #include "wtf/Forward.h"
     35 
     36 namespace WebCore {
     37 
     38 class Document;
     39 
     40 enum ViewportErrorCode {
     41     UnrecognizedViewportArgumentKeyError,
     42     UnrecognizedViewportArgumentValueError,
     43     TruncatedViewportArgumentValueError,
     44     MaximumScaleTooLargeError,
     45     TargetDensityDpiUnsupported
     46 };
     47 
     48 struct ViewportArguments {
     49 
     50     enum Type {
     51         // These are ordered in increasing importance.
     52         Implicit,
     53         XHTMLMobileProfile,
     54         HandheldFriendlyMeta,
     55         MobileOptimizedMeta,
     56         ViewportMeta,
     57         ViewportMetaLayoutSizeQuirk,
     58         CSSDeviceAdaptation
     59     } type;
     60 
     61     enum {
     62         ValueAuto = -1,
     63         ValueDeviceWidth = -2,
     64         ValueDeviceHeight = -3,
     65         ValuePortrait = -4,
     66         ValueLandscape = -5,
     67         ValueDeviceDPI = -6,
     68         ValueLowDPI = -7,
     69         ValueMediumDPI = -8,
     70         ValueHighDPI = -9,
     71         ValueExtendToZoom = -10
     72     };
     73 
     74     ViewportArguments(Type type = Implicit)
     75         : type(type)
     76         , width(ValueAuto)
     77         , height(ValueAuto)
     78         , zoom(ValueAuto)
     79         , minZoom(ValueAuto)
     80         , maxZoom(ValueAuto)
     81         , userZoom(ValueAuto)
     82         , orientation(ValueAuto)
     83         , deprecatedTargetDensityDPI(ValueAuto)
     84     {
     85     }
     86 
     87     // All arguments are in CSS units.
     88     PageScaleConstraints resolve(const FloatSize& initialViewportSize, const FloatSize& deviceSize, int defaultWidth) const;
     89 
     90     float width;
     91     Length minWidth;
     92     Length maxWidth;
     93     float height;
     94     Length minHeight;
     95     Length maxHeight;
     96     float zoom;
     97     float minZoom;
     98     float maxZoom;
     99     float userZoom;
    100     float orientation;
    101     float deprecatedTargetDensityDPI; // Only used for Android WebView
    102 
    103     bool operator==(const ViewportArguments& other) const
    104     {
    105         // Used for figuring out whether to reset the viewport or not,
    106         // thus we are not taking type into account.
    107         return width == other.width
    108             && minWidth == other.minWidth
    109             && maxWidth == other.maxWidth
    110             && height == other.height
    111             && minHeight == other.minHeight
    112             && maxHeight == other.maxHeight
    113             && zoom == other.zoom
    114             && minZoom == other.minZoom
    115             && maxZoom == other.maxZoom
    116             && userZoom == other.userZoom
    117             && orientation == other.orientation
    118             && deprecatedTargetDensityDPI == other.deprecatedTargetDensityDPI;
    119     }
    120 
    121     bool operator!=(const ViewportArguments& other) const
    122     {
    123         return !(*this == other);
    124     }
    125 
    126 private:
    127     enum Direction { Horizontal, Vertical };
    128     static float resolveViewportLength(const Length&, const FloatSize& initialViewportSize, Direction);
    129 };
    130 
    131 void setViewportFeature(const String& keyString, const String& valueString, Document*, void* data);
    132 void reportViewportWarning(Document*, ViewportErrorCode, const String& replacement1, const String& replacement2);
    133 
    134 } // namespace WebCore
    135 
    136 #endif // ViewportArguments_h
    137