| 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 * | 5 * |
| 5 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 8 * 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. |
| 9 * | 10 * |
| 10 * 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, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 14 * | 15 * |
| 15 * 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 |
| 16 * 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 |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 19 */ | 20 */ |
| 20 | 21 |
| 21 #ifndef SVGFitToViewBox_h | 22 #ifndef SVGFitToViewBox_h |
| 22 #define SVGFitToViewBox_h | 23 #define SVGFitToViewBox_h |
| 23 | 24 |
| 24 #include "SVGNames.h" | 25 #include "SVGNames.h" |
| 26 #include "core/dom/Document.h" |
| 25 #include "core/dom/QualifiedName.h" | 27 #include "core/dom/QualifiedName.h" |
| 28 #include "core/svg/SVGAnimatedPreserveAspectRatio.h" |
| 29 #include "core/svg/SVGAnimatedRect.h" |
| 26 #include "core/svg/SVGDocumentExtensions.h" | 30 #include "core/svg/SVGDocumentExtensions.h" |
| 27 #include "core/svg/SVGParsingError.h" | 31 #include "core/svg/SVGParsingError.h" |
| 28 #include "core/svg/SVGPreserveAspectRatio.h" | 32 #include "core/svg/SVGPreserveAspectRatio.h" |
| 29 #include "core/svg/SVGRect.h" | 33 #include "core/svg/SVGRect.h" |
| 30 #include "wtf/HashSet.h" | 34 #include "wtf/HashSet.h" |
| 31 | 35 |
| 32 namespace WebCore { | 36 namespace WebCore { |
| 33 | 37 |
| 34 class AffineTransform; | 38 class AffineTransform; |
| 35 class Document; | 39 class Document; |
| 36 | 40 |
| 37 class SVGFitToViewBox { | 41 class SVGFitToViewBox { |
| 38 public: | 42 public: |
| 43 enum PropertyMapPolicy { |
| 44 PropertyMapPolicyAdd, |
| 45 PropertyMapPolicySkip, |
| 46 }; |
| 47 |
| 39 static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect,
PassRefPtr<SVGPreserveAspectRatio>, float viewWidth, float viewHeight); | 48 static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect,
PassRefPtr<SVGPreserveAspectRatio>, float viewWidth, float viewHeight); |
| 40 | 49 |
| 41 static bool isKnownAttribute(const QualifiedName&); | 50 static bool isKnownAttribute(const QualifiedName&); |
| 42 static void addSupportedAttributes(HashSet<QualifiedName>&); | 51 static void addSupportedAttributes(HashSet<QualifiedName>&); |
| 43 | 52 |
| 44 template<class SVGElementTarget> | 53 bool parseAttribute(const QualifiedName& name, const AtomicString& value, Do
cument& document, SVGParsingError& parseError) |
| 45 static bool parseAttribute(SVGElementTarget* target, const QualifiedName& na
me, const AtomicString& value) | |
| 46 { | 54 { |
| 47 ASSERT(target); | 55 if (name == SVGNames::viewBoxAttr) { |
| 56 m_viewBox->setBaseValueAsString(value, parseError); |
| 57 if (m_viewBox->baseValue()->width() < 0.0f) { |
| 58 document.accessSVGExtensions()->reportError("A negative value fo
r ViewBox width is not allowed"); |
| 59 m_viewBox->baseValue()->setInvalid(); |
| 60 } |
| 61 if (m_viewBox->baseValue()->height() < 0.0f) { |
| 62 document.accessSVGExtensions()->reportError("A negative value fo
r ViewBox height is not allowed"); |
| 63 m_viewBox->baseValue()->setInvalid(); |
| 64 } |
| 65 return true; |
| 66 } |
| 67 if (name == SVGNames::preserveAspectRatioAttr) { |
| 68 m_preserveAspectRatio->setBaseValueAsString(value, parseError); |
| 69 return true; |
| 70 } |
| 71 return false; |
| 72 } |
| 48 | 73 |
| 49 SVGParsingError parseError = NoError; | 74 // SVGFitToViewBox JS API. |
| 75 static SVGAnimatedRect* viewBox(SVGFitToViewBox* object) { return object->vi
ewBox(); } |
| 76 static SVGAnimatedPreserveAspectRatio* preserveAspectRatio(SVGFitToViewBox*
object) { return object->preserveAspectRatio(); } |
| 50 | 77 |
| 51 if (name == SVGNames::viewBoxAttr) { | 78 SVGAnimatedRect* viewBox() const { return m_viewBox.get(); } |
| 52 target->viewBox()->setBaseValueAsString(value, parseError); | 79 bool hasEmptyViewBox() const { return m_viewBox->currentValue()->isValid() &
& m_viewBox->currentValue()->value().isEmpty(); } |
| 53 if (target->viewBox()->baseValue()->width() < 0.0f) { | 80 SVGAnimatedPreserveAspectRatio* preserveAspectRatio() const { return m_prese
rveAspectRatio.get(); } |
| 54 target->document().accessSVGExtensions()->reportError("A negativ
e value for ViewBox width is not allowed"); | |
| 55 target->viewBox()->baseValue()->setInvalid(); | |
| 56 } | |
| 57 if (target->viewBox()->baseValue()->height() < 0.0f) { | |
| 58 target->document().accessSVGExtensions()->reportError("A negativ
e value for ViewBox height is not allowed"); | |
| 59 target->viewBox()->baseValue()->setInvalid(); | |
| 60 } | |
| 61 } else if (name == SVGNames::preserveAspectRatioAttr) { | |
| 62 target->preserveAspectRatio()->setBaseValueAsString(value, parseErro
r); | |
| 63 } else { | |
| 64 return false; | |
| 65 } | |
| 66 | 81 |
| 67 target->reportAttributeParsingError(parseError, name, value); | 82 protected: |
| 68 return true; | 83 explicit SVGFitToViewBox(SVGElement*, PropertyMapPolicy = PropertyMapPolicyA
dd); |
| 69 } | 84 void updateViewBox(const FloatRect&); |
| 85 void clearViewBox() { m_viewBox = 0; } |
| 86 void clearPreserveAspectRatio() { m_preserveAspectRatio = 0; } |
| 87 |
| 88 private: |
| 89 RefPtr<SVGAnimatedRect> m_viewBox; |
| 90 RefPtr<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio; |
| 70 }; | 91 }; |
| 71 | 92 |
| 72 } // namespace WebCore | 93 } // namespace WebCore |
| 73 | 94 |
| 74 #endif // SVGFitToViewBox_h | 95 #endif // SVGFitToViewBox_h |
| OLD | NEW |