OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 4 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
20 */ | 20 */ |
21 | 21 |
22 #ifndef SVGFitToViewBox_h | 22 #ifndef SVGFitToViewBox_h |
23 #define SVGFitToViewBox_h | 23 #define SVGFitToViewBox_h |
24 | 24 |
25 #include "core/SVGNames.h" | 25 #include "core/SVGNames.h" |
26 #include "core/dom/Document.h" | |
27 #include "core/dom/QualifiedName.h" | 26 #include "core/dom/QualifiedName.h" |
28 #include "core/svg/SVGAnimatedPreserveAspectRatio.h" | 27 #include "core/svg/SVGAnimatedPreserveAspectRatio.h" |
29 #include "core/svg/SVGAnimatedRect.h" | 28 #include "core/svg/SVGAnimatedRect.h" |
30 #include "core/svg/SVGDocumentExtensions.h" | |
31 #include "core/svg/SVGParsingError.h" | |
32 #include "core/svg/SVGPreserveAspectRatio.h" | 29 #include "core/svg/SVGPreserveAspectRatio.h" |
33 #include "core/svg/SVGRect.h" | 30 #include "core/svg/SVGRect.h" |
34 #include "platform/heap/Handle.h" | 31 #include "platform/heap/Handle.h" |
35 #include "wtf/HashSet.h" | |
36 | 32 |
37 namespace blink { | 33 namespace blink { |
38 | 34 |
39 class AffineTransform; | 35 class AffineTransform; |
40 class Document; | |
41 | 36 |
42 class SVGFitToViewBox : public WillBeGarbageCollectedMixin { | 37 class SVGFitToViewBox : public WillBeGarbageCollectedMixin { |
43 public: | 38 public: |
44 enum PropertyMapPolicy { | 39 enum PropertyMapPolicy { |
45 PropertyMapPolicyAdd, | 40 PropertyMapPolicyAdd, |
46 PropertyMapPolicySkip, | 41 PropertyMapPolicySkip, |
47 }; | 42 }; |
48 | 43 |
49 static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect,
PassRefPtrWillBeRawPtr<SVGPreserveAspectRatio>, float viewWidth, float viewHeigh
t); | 44 static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect,
PassRefPtrWillBeRawPtr<SVGPreserveAspectRatio>, float viewWidth, float viewHeigh
t); |
50 | 45 |
51 static bool isKnownAttribute(const QualifiedName&); | 46 static bool isKnownAttribute(const QualifiedName&); |
52 static void addSupportedAttributes(HashSet<QualifiedName>&); | |
53 | |
54 bool parseAttribute(const QualifiedName& name, const AtomicString& value, Do
cument& document, SVGParsingError& parseError) | |
55 { | |
56 if (name == SVGNames::viewBoxAttr) { | |
57 m_viewBox->setBaseValueAsString(value, parseError); | |
58 return true; | |
59 } | |
60 if (name == SVGNames::preserveAspectRatioAttr) { | |
61 m_preserveAspectRatio->setBaseValueAsString(value, parseError); | |
62 return true; | |
63 } | |
64 return false; | |
65 } | |
66 | 47 |
67 bool hasEmptyViewBox() const { return m_viewBox->currentValue()->isValid() &
& m_viewBox->currentValue()->value().isEmpty(); } | 48 bool hasEmptyViewBox() const { return m_viewBox->currentValue()->isValid() &
& m_viewBox->currentValue()->value().isEmpty(); } |
68 | 49 |
69 // JS API | 50 // JS API |
70 SVGAnimatedRect* viewBox() const { return m_viewBox.get(); } | 51 SVGAnimatedRect* viewBox() const { return m_viewBox.get(); } |
71 SVGAnimatedPreserveAspectRatio* preserveAspectRatio() const { return m_prese
rveAspectRatio.get(); } | 52 SVGAnimatedPreserveAspectRatio* preserveAspectRatio() const { return m_prese
rveAspectRatio.get(); } |
72 | 53 |
73 DECLARE_VIRTUAL_TRACE(); | 54 DECLARE_VIRTUAL_TRACE(); |
74 | 55 |
75 protected: | 56 protected: |
76 explicit SVGFitToViewBox(SVGElement*, PropertyMapPolicy = PropertyMapPolicyA
dd); | 57 explicit SVGFitToViewBox(SVGElement*, PropertyMapPolicy = PropertyMapPolicyA
dd); |
77 void updateViewBox(const FloatRect&); | 58 void updateViewBox(const FloatRect&); |
78 void clearViewBox() { m_viewBox = nullptr; } | 59 void clearViewBox() { m_viewBox = nullptr; } |
79 void clearPreserveAspectRatio() { m_preserveAspectRatio = nullptr; } | 60 void clearPreserveAspectRatio() { m_preserveAspectRatio = nullptr; } |
80 | 61 |
81 private: | 62 private: |
82 RefPtrWillBeMember<SVGAnimatedRect> m_viewBox; | 63 RefPtrWillBeMember<SVGAnimatedRect> m_viewBox; |
83 RefPtrWillBeMember<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio; | 64 RefPtrWillBeMember<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio; |
84 }; | 65 }; |
85 | 66 |
86 } // namespace blink | 67 } // namespace blink |
87 | 68 |
88 #endif // SVGFitToViewBox_h | 69 #endif // SVGFitToViewBox_h |
OLD | NEW |