1/*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB.  If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef SVGPreserveAspectRatio_h
22#define SVGPreserveAspectRatio_h
23
24#include "core/svg/properties/SVGPropertyHelper.h"
25
26namespace blink {
27
28class AffineTransform;
29class FloatRect;
30class SVGPreserveAspectRatioTearOff;
31
32class SVGPreserveAspectRatio : public SVGPropertyHelper<SVGPreserveAspectRatio> {
33public:
34    enum SVGPreserveAspectRatioType {
35        SVG_PRESERVEASPECTRATIO_UNKNOWN = 0,
36        SVG_PRESERVEASPECTRATIO_NONE = 1,
37        SVG_PRESERVEASPECTRATIO_XMINYMIN = 2,
38        SVG_PRESERVEASPECTRATIO_XMIDYMIN = 3,
39        SVG_PRESERVEASPECTRATIO_XMAXYMIN = 4,
40        SVG_PRESERVEASPECTRATIO_XMINYMID = 5,
41        SVG_PRESERVEASPECTRATIO_XMIDYMID = 6,
42        SVG_PRESERVEASPECTRATIO_XMAXYMID = 7,
43        SVG_PRESERVEASPECTRATIO_XMINYMAX = 8,
44        SVG_PRESERVEASPECTRATIO_XMIDYMAX = 9,
45        SVG_PRESERVEASPECTRATIO_XMAXYMAX = 10
46    };
47
48    enum SVGMeetOrSliceType {
49        SVG_MEETORSLICE_UNKNOWN = 0,
50        SVG_MEETORSLICE_MEET = 1,
51        SVG_MEETORSLICE_SLICE = 2
52    };
53
54    typedef SVGPreserveAspectRatioTearOff TearOffType;
55
56    static PassRefPtr<SVGPreserveAspectRatio> create()
57    {
58        return adoptRef(new SVGPreserveAspectRatio());
59    }
60
61    virtual PassRefPtr<SVGPreserveAspectRatio> clone() const;
62
63    bool operator==(const SVGPreserveAspectRatio&) const;
64    bool operator!=(const SVGPreserveAspectRatio& other) const { return !operator==(other); }
65
66    void setAlign(SVGPreserveAspectRatioType align) { m_align = align; }
67    SVGPreserveAspectRatioType align() const { return m_align; }
68
69    void setMeetOrSlice(SVGMeetOrSliceType meetOrSlice) { m_meetOrSlice = meetOrSlice; }
70    SVGMeetOrSliceType meetOrSlice() const { return m_meetOrSlice; }
71
72    void transformRect(FloatRect& destRect, FloatRect& srcRect);
73
74    AffineTransform getCTM(float logicX, float logicY,
75                           float logicWidth, float logicHeight,
76                           float physWidth, float physHeight) const;
77
78    virtual String valueAsString() const OVERRIDE;
79    virtual void setValueAsString(const String&, ExceptionState&);
80    bool parse(const UChar*& ptr, const UChar* end, bool validate);
81    bool parse(const LChar*& ptr, const LChar* end, bool validate);
82
83    virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) OVERRIDE;
84    virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) OVERRIDE;
85    virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement* contextElement) OVERRIDE;
86
87    static AnimatedPropertyType classType() { return AnimatedPreserveAspectRatio; }
88
89private:
90    SVGPreserveAspectRatio();
91
92    void setDefault();
93    template<typename CharType>
94    bool parseInternal(const CharType*& ptr, const CharType* end, bool validate);
95
96    SVGPreserveAspectRatioType m_align;
97    SVGMeetOrSliceType m_meetOrSlice;
98};
99
100inline PassRefPtr<SVGPreserveAspectRatio> toSVGPreserveAspectRatio(PassRefPtr<SVGPropertyBase> passBase)
101{
102    RefPtr<SVGPropertyBase> base = passBase;
103    ASSERT(base->type() == SVGPreserveAspectRatio::classType());
104    return static_pointer_cast<SVGPreserveAspectRatio>(base.release());
105}
106
107} // namespace blink
108
109#endif // SVGPreserveAspectRatio_h
110