1 /*
2 Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 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 #include "config.h"
22
23 #if ENABLE(SVG)
24 #include "SVGTests.h"
25
26 #include "DOMImplementation.h"
27 #include "Language.h"
28 #include "SVGElement.h"
29 #include "SVGNames.h"
30 #include "SVGStringList.h"
31
32 namespace WebCore {
33
SVGTests()34 SVGTests::SVGTests()
35 {
36 }
37
~SVGTests()38 SVGTests::~SVGTests()
39 {
40 }
41
requiredFeatures() const42 SVGStringList* SVGTests::requiredFeatures() const
43 {
44 if (!m_features)
45 m_features = SVGStringList::create(SVGNames::requiredFeaturesAttr);
46
47 return m_features.get();
48 }
49
requiredExtensions() const50 SVGStringList* SVGTests::requiredExtensions() const
51 {
52 if (!m_extensions)
53 m_extensions = SVGStringList::create(SVGNames::requiredExtensionsAttr);
54
55 return m_extensions.get();
56 }
57
systemLanguage() const58 SVGStringList* SVGTests::systemLanguage() const
59 {
60 if (!m_systemLanguage)
61 m_systemLanguage = SVGStringList::create(SVGNames::systemLanguageAttr);
62
63 return m_systemLanguage.get();
64 }
65
hasExtension(const String &) const66 bool SVGTests::hasExtension(const String&) const
67 {
68 return false;
69 }
70
isValid() const71 bool SVGTests::isValid() const
72 {
73 ExceptionCode ec = 0;
74
75 if (m_features) {
76 for (unsigned long i = 0; i < m_features->numberOfItems(); i++) {
77 String value = m_features->getItem(i, ec);
78 if (value.isEmpty() || !DOMImplementation::hasFeature(value, String()))
79 return false;
80 }
81 }
82
83 if (m_systemLanguage) {
84 for (unsigned long i = 0; i < m_systemLanguage->numberOfItems(); i++)
85 if (m_systemLanguage->getItem(i, ec) != defaultLanguage().substring(0, 2))
86 return false;
87 }
88
89 if (m_extensions && m_extensions->numberOfItems() > 0)
90 return false;
91
92 return true;
93 }
94
parseMappedAttribute(MappedAttribute * attr)95 bool SVGTests::parseMappedAttribute(MappedAttribute* attr)
96 {
97 if (attr->name() == SVGNames::requiredFeaturesAttr) {
98 requiredFeatures()->reset(attr->value());
99 return true;
100 } else if (attr->name() == SVGNames::requiredExtensionsAttr) {
101 requiredExtensions()->reset(attr->value());
102 return true;
103 } else if (attr->name() == SVGNames::systemLanguageAttr) {
104 systemLanguage()->reset(attr->value());
105 return true;
106 }
107
108 return false;
109 }
110
isKnownAttribute(const QualifiedName & attrName)111 bool SVGTests::isKnownAttribute(const QualifiedName& attrName)
112 {
113 return (attrName == SVGNames::requiredFeaturesAttr ||
114 attrName == SVGNames::requiredExtensionsAttr ||
115 attrName == SVGNames::systemLanguageAttr);
116 }
117
118 }
119
120 #endif // ENABLE(SVG)
121