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 #if ENABLE(SVG) 24 #include "SVGTests.h" 25 26 #include "Attribute.h" 27 #include "DOMImplementation.h" 28 #include "Language.h" 29 #include "SVGElement.h" 30 #include "SVGNames.h" 31 #include "SVGStringList.h" 32 33 namespace WebCore { 34 35 SVGTests::SVGTests() 36 : m_requiredFeatures(SVGNames::requiredFeaturesAttr) 37 , m_requiredExtensions(SVGNames::requiredExtensionsAttr) 38 , m_systemLanguage(SVGNames::systemLanguageAttr) 39 { 40 } 41 42 bool SVGTests::hasExtension(const String&) const 43 { 44 // FIXME: Implement me! 45 return false; 46 } 47 48 bool SVGTests::isValid() const 49 { 50 unsigned featuresSize = m_requiredFeatures.value.size(); 51 for (unsigned i = 0; i < featuresSize; ++i) { 52 String value = m_requiredFeatures.value.at(i); 53 if (value.isEmpty() || !DOMImplementation::hasFeature(value, String())) 54 return false; 55 } 56 57 unsigned systemLanguageSize = m_systemLanguage.value.size(); 58 for (unsigned i = 0; i < systemLanguageSize; ++i) { 59 String value = m_systemLanguage.value.at(i); 60 if (value != defaultLanguage().substring(0, 2)) 61 return false; 62 } 63 64 if (!m_requiredExtensions.value.isEmpty()) 65 return false; 66 67 return true; 68 } 69 70 bool SVGTests::parseMappedAttribute(Attribute* attr) 71 { 72 if (attr->name() == SVGNames::requiredFeaturesAttr) { 73 m_requiredFeatures.value.reset(attr->value()); 74 return true; 75 } 76 if (attr->name() == SVGNames::requiredExtensionsAttr) { 77 m_requiredExtensions.value.reset(attr->value()); 78 return true; 79 } 80 if (attr->name() == SVGNames::systemLanguageAttr) { 81 m_systemLanguage.value.reset(attr->value()); 82 return true; 83 } 84 85 return false; 86 } 87 88 bool SVGTests::isKnownAttribute(const QualifiedName& attrName) 89 { 90 return attrName == SVGNames::requiredFeaturesAttr 91 || attrName == SVGNames::requiredExtensionsAttr 92 || attrName == SVGNames::systemLanguageAttr; 93 } 94 95 bool SVGTests::handleAttributeChange(const SVGElement* targetElement, const QualifiedName& attrName) 96 { 97 if (!isKnownAttribute(attrName)) 98 return false; 99 if (!targetElement->inDocument()) 100 return false; 101 SVGElement* svgElement = const_cast<SVGElement*>(targetElement); 102 ASSERT(svgElement); 103 bool valid = svgElement->isValid(); 104 if (valid && !svgElement->attached()) 105 svgElement->attach(); 106 if (!valid && svgElement->attached()) 107 svgElement->detach(); 108 return true; 109 } 110 111 void SVGTests::synchronizeProperties(SVGElement* contextElement, const QualifiedName& attrName) 112 { 113 if (attrName == anyQName()) { 114 synchronizeRequiredFeatures(contextElement); 115 synchronizeRequiredExtensions(contextElement); 116 synchronizeSystemLanguage(contextElement); 117 return; 118 } 119 120 if (attrName == SVGNames::requiredFeaturesAttr) 121 synchronizeRequiredFeatures(contextElement); 122 else if (attrName == SVGNames::requiredExtensionsAttr) 123 synchronizeRequiredExtensions(contextElement); 124 else if (attrName == SVGNames::systemLanguageAttr) 125 synchronizeSystemLanguage(contextElement); 126 } 127 128 void SVGTests::synchronizeRequiredFeatures(SVGElement* contextElement) 129 { 130 if (!m_requiredFeatures.shouldSynchronize) 131 return; 132 AtomicString value(m_requiredFeatures.value.valueAsString()); 133 SVGAnimatedPropertySynchronizer<true>::synchronize(contextElement, SVGNames::requiredFeaturesAttr, value); 134 } 135 136 void SVGTests::synchronizeRequiredExtensions(SVGElement* contextElement) 137 { 138 if (!m_requiredExtensions.shouldSynchronize) 139 return; 140 AtomicString value(m_requiredExtensions.value.valueAsString()); 141 SVGAnimatedPropertySynchronizer<true>::synchronize(contextElement, SVGNames::requiredExtensionsAttr, value); 142 } 143 144 void SVGTests::synchronizeSystemLanguage(SVGElement* contextElement) 145 { 146 if (!m_systemLanguage.shouldSynchronize) 147 return; 148 AtomicString value(m_systemLanguage.value.valueAsString()); 149 SVGAnimatedPropertySynchronizer<true>::synchronize(contextElement, SVGNames::systemLanguageAttr, value); 150 } 151 152 SVGStringList& SVGTests::requiredFeatures() 153 { 154 m_requiredFeatures.shouldSynchronize = true; 155 return m_requiredFeatures.value; 156 } 157 158 SVGStringList& SVGTests::requiredExtensions() 159 { 160 m_requiredExtensions.shouldSynchronize = true; 161 return m_requiredExtensions.value; 162 } 163 164 SVGStringList& SVGTests::systemLanguage() 165 { 166 m_systemLanguage.shouldSynchronize = true; 167 return m_systemLanguage.value; 168 } 169 170 } 171 172 #endif // ENABLE(SVG) 173