1 /* 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) 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 #include "core/svg/SVGTests.h" 24 25 #include "core/SVGNames.h" 26 #include "core/dom/DOMImplementation.h" 27 #include "platform/Language.h" 28 #include "core/svg/SVGElement.h" 29 30 namespace WebCore { 31 32 SVGTests::SVGTests(SVGElement* contextElement) 33 : m_requiredFeatures(SVGStaticStringList::create(contextElement, SVGNames::requiredFeaturesAttr)) 34 , m_requiredExtensions(SVGStaticStringList::create(contextElement, SVGNames::requiredExtensionsAttr)) 35 , m_systemLanguage(SVGStaticStringList::create(contextElement, SVGNames::systemLanguageAttr)) 36 { 37 ASSERT(contextElement); 38 39 contextElement->addToPropertyMap(m_requiredFeatures); 40 contextElement->addToPropertyMap(m_requiredExtensions); 41 contextElement->addToPropertyMap(m_systemLanguage); 42 } 43 44 bool SVGTests::hasExtension(const String&) 45 { 46 // FIXME: Implement me! 47 return false; 48 } 49 50 bool SVGTests::isValid() const 51 { 52 if (m_requiredFeatures->isSpecified()) { 53 const Vector<String>& requiredFeatures = m_requiredFeatures->value()->values(); 54 Vector<String>::const_iterator it = requiredFeatures.begin(); 55 Vector<String>::const_iterator itEnd = requiredFeatures.end(); 56 for (; it != itEnd; ++it) { 57 if (it->isEmpty() || !DOMImplementation::hasFeature(*it, String())) 58 return false; 59 } 60 } 61 62 if (m_systemLanguage->isSpecified()) { 63 bool matchFound = false; 64 65 const Vector<String>& systemLanguage = m_systemLanguage->value()->values(); 66 Vector<String>::const_iterator it = systemLanguage.begin(); 67 Vector<String>::const_iterator itEnd = systemLanguage.end(); 68 for (; it != itEnd; ++it) { 69 if (*it == defaultLanguage().string().substring(0, 2)) { 70 matchFound = true; 71 break; 72 } 73 } 74 75 if (!matchFound) 76 return false; 77 } 78 79 if (!m_requiredExtensions->value()->values().isEmpty()) 80 return false; 81 82 return true; 83 } 84 85 bool SVGTests::parseAttribute(const QualifiedName& name, const AtomicString& value) 86 { 87 // FIXME: Should handle exceptions here. 88 // This is safe as of now, as the current impl of SVGStringList::setValueAsString never fails. 89 SVGParsingError parseError = NoError; 90 91 if (name == SVGNames::requiredFeaturesAttr) 92 m_requiredFeatures->setBaseValueAsString(value, parseError); 93 else if (name == SVGNames::requiredExtensionsAttr) 94 m_requiredExtensions->setBaseValueAsString(value, parseError); 95 else if (name == SVGNames::systemLanguageAttr) 96 m_systemLanguage->setBaseValueAsString(value, parseError); 97 else 98 return false; 99 100 ASSERT(parseError == NoError); 101 102 return true; 103 } 104 105 bool SVGTests::isKnownAttribute(const QualifiedName& attrName) 106 { 107 return attrName == SVGNames::requiredFeaturesAttr 108 || attrName == SVGNames::requiredExtensionsAttr 109 || attrName == SVGNames::systemLanguageAttr; 110 } 111 112 void SVGTests::addSupportedAttributes(HashSet<QualifiedName>& supportedAttributes) 113 { 114 supportedAttributes.add(SVGNames::requiredFeaturesAttr); 115 supportedAttributes.add(SVGNames::requiredExtensionsAttr); 116 supportedAttributes.add(SVGNames::systemLanguageAttr); 117 } 118 119 } 120