1/*
2 * Copyright (C) 2007 Rob Buis <buis@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#ifndef SVGViewSpec_h
21#define SVGViewSpec_h
22
23#include "bindings/v8/ScriptWrappable.h"
24#include "core/svg/SVGAnimatedPreserveAspectRatio.h"
25#include "core/svg/SVGAnimatedRect.h"
26#include "core/svg/SVGFitToViewBox.h"
27#include "core/svg/SVGSVGElement.h"
28#include "core/svg/SVGTransformList.h"
29#include "core/svg/SVGZoomAndPan.h"
30#include "wtf/WeakPtr.h"
31
32namespace WebCore {
33
34class ExceptionState;
35class SVGTransformListPropertyTearOff;
36
37class SVGViewSpec FINAL : public RefCounted<SVGViewSpec>, public ScriptWrappable, public SVGZoomAndPan, public SVGFitToViewBox {
38public:
39    using RefCounted<SVGViewSpec>::ref;
40    using RefCounted<SVGViewSpec>::deref;
41
42    static PassRefPtr<SVGViewSpec> create(WeakPtr<SVGSVGElement> contextElement)
43    {
44        return adoptRef(new SVGViewSpec(contextElement));
45    }
46
47    bool parseViewSpec(const String&);
48    void reset();
49
50    SVGElement* viewTarget() const;
51    String viewBoxString() const;
52
53    String preserveAspectRatioString() const;
54
55    void setTransformString(const String&);
56    String transformString() const;
57
58    void setViewTargetString(const String& string) { m_viewTargetString = string; }
59    String viewTargetString() const { return m_viewTargetString; }
60
61    SVGZoomAndPanType zoomAndPan() const { return m_zoomAndPan; }
62    void setZoomAndPan(unsigned short zoomAndPan) { setZoomAndPanBaseValue(zoomAndPan); }
63    void setZoomAndPan(unsigned short, ExceptionState&);
64    void setZoomAndPanBaseValue(unsigned short zoomAndPan) { m_zoomAndPan = SVGZoomAndPan::parseFromNumber(zoomAndPan); }
65
66    SVGElement* contextElement() const { return m_contextElement.get(); }
67
68    // Custom non-animated 'transform' property.
69    SVGTransformListPropertyTearOff* transform();
70    SVGTransformList transformBaseValue() const { return m_transform; }
71
72    // Custom animated 'viewBox' property.
73    PassRefPtr<SVGAnimatedRect> viewBox();
74    SVGRect& viewBoxCurrentValue() { return m_viewBox; }
75    SVGRect viewBoxBaseValue() const { return m_viewBox; }
76    void setViewBoxBaseValue(const SVGRect& viewBox) { m_viewBox = viewBox; }
77
78    // Custom animated 'preserveAspectRatio' property.
79    PassRefPtr<SVGAnimatedPreserveAspectRatio> preserveAspectRatio();
80    SVGPreserveAspectRatio& preserveAspectRatioCurrentValue() { return m_preserveAspectRatio; }
81    SVGPreserveAspectRatio preserveAspectRatioBaseValue() const { return m_preserveAspectRatio; }
82    void setPreserveAspectRatioBaseValue(const SVGPreserveAspectRatio& preserveAspectRatio) { m_preserveAspectRatio = preserveAspectRatio; }
83
84private:
85    explicit SVGViewSpec(WeakPtr<SVGSVGElement>);
86
87    static const SVGPropertyInfo* transformPropertyInfo();
88    static const SVGPropertyInfo* viewBoxPropertyInfo();
89    static const SVGPropertyInfo* preserveAspectRatioPropertyInfo();
90
91    static const AtomicString& transformIdentifier();
92    static const AtomicString& viewBoxIdentifier();
93    static const AtomicString& preserveAspectRatioIdentifier();
94
95    static PassRefPtr<SVGAnimatedProperty> lookupOrCreateTransformWrapper(SVGViewSpec* contextElement);
96    static PassRefPtr<SVGAnimatedProperty> lookupOrCreateViewBoxWrapper(SVGViewSpec* contextElement);
97    static PassRefPtr<SVGAnimatedProperty> lookupOrCreatePreserveAspectRatioWrapper(SVGViewSpec* contextElement);
98
99    template<typename CharType>
100    bool parseViewSpecInternal(const CharType* ptr, const CharType* end);
101
102    WeakPtr<SVGSVGElement> m_contextElement;
103
104    SVGZoomAndPanType m_zoomAndPan;
105    SVGTransformList m_transform;
106    SVGRect m_viewBox;
107    SVGPreserveAspectRatio m_preserveAspectRatio;
108    String m_viewTargetString;
109};
110
111} // namespace WebCore
112
113#endif
114