2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org>
4 * Copyright (C) 2014 Samsung Electronics. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
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
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef SVGFitToViewBox_h
23 #define SVGFitToViewBox_h
25 #include "core/SVGNames.h"
26 #include "core/dom/Document.h"
27 #include "core/dom/QualifiedName.h"
28 #include "core/svg/SVGAnimatedPreserveAspectRatio.h"
29 #include "core/svg/SVGAnimatedRect.h"
30 #include "core/svg/SVGDocumentExtensions.h"
31 #include "core/svg/SVGParsingError.h"
32 #include "core/svg/SVGPreserveAspectRatio.h"
33 #include "core/svg/SVGRect.h"
34 #include "wtf/HashSet.h"
38 class AffineTransform;
41 class SVGFitToViewBox {
43 enum PropertyMapPolicy {
45 PropertyMapPolicySkip,
48 static AffineTransform viewBoxToViewTransform(const FloatRect& viewBoxRect, PassRefPtr<SVGPreserveAspectRatio>, float viewWidth, float viewHeight);
50 static bool isKnownAttribute(const QualifiedName&);
51 static void addSupportedAttributes(HashSet<QualifiedName>&);
53 bool parseAttribute(const QualifiedName& name, const AtomicString& value, Document& document, SVGParsingError& parseError)
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 for ViewBox width is not allowed");
59 m_viewBox->baseValue()->setInvalid();
61 if (m_viewBox->baseValue()->height() < 0.0f) {
62 document.accessSVGExtensions().reportError("A negative value for ViewBox height is not allowed");
63 m_viewBox->baseValue()->setInvalid();
67 if (name == SVGNames::preserveAspectRatioAttr) {
68 m_preserveAspectRatio->setBaseValueAsString(value, parseError);
74 bool hasEmptyViewBox() const { return m_viewBox->currentValue()->isValid() && m_viewBox->currentValue()->value().isEmpty(); }
77 SVGAnimatedRect* viewBox() const { return m_viewBox.get(); }
78 SVGAnimatedPreserveAspectRatio* preserveAspectRatio() const { return m_preserveAspectRatio.get(); }
81 explicit SVGFitToViewBox(SVGElement*, PropertyMapPolicy = PropertyMapPolicyAdd);
82 void updateViewBox(const FloatRect&);
83 void clearViewBox() { m_viewBox = nullptr; }
84 void clearPreserveAspectRatio() { m_preserveAspectRatio = nullptr; }
87 RefPtr<SVGAnimatedRect> m_viewBox;
88 RefPtr<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio;
93 #endif // SVGFitToViewBox_h