Home | History | Annotate | Download | only in svg
      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 "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 // Define custom non-animated property 'requiredFeatures'.
     33 const SVGPropertyInfo* SVGTests::requiredFeaturesPropertyInfo()
     34 {
     35     static const SVGPropertyInfo* s_propertyInfo = 0;
     36     if (!s_propertyInfo) {
     37         s_propertyInfo = new SVGPropertyInfo(AnimatedUnknown,
     38                                              PropertyIsReadWrite,
     39                                              SVGNames::requiredFeaturesAttr,
     40                                              SVGNames::requiredFeaturesAttr.localName(),
     41                                              &SVGElement::synchronizeRequiredFeatures,
     42                                              0);
     43     }
     44     return s_propertyInfo;
     45 }
     46 
     47 // Define custom non-animated property 'requiredExtensions'.
     48 const SVGPropertyInfo* SVGTests::requiredExtensionsPropertyInfo()
     49 {
     50     static const SVGPropertyInfo* s_propertyInfo = 0;
     51     if (!s_propertyInfo) {
     52         s_propertyInfo = new SVGPropertyInfo(AnimatedUnknown,
     53                                              PropertyIsReadWrite,
     54                                              SVGNames::requiredExtensionsAttr,
     55                                              SVGNames::requiredExtensionsAttr.localName(),
     56                                              &SVGElement::synchronizeRequiredExtensions,
     57                                              0);
     58     }
     59     return s_propertyInfo;
     60 }
     61 
     62 // Define custom non-animated property 'systemLanguage'.
     63 const SVGPropertyInfo* SVGTests::systemLanguagePropertyInfo()
     64 {
     65     static const SVGPropertyInfo* s_propertyInfo = 0;
     66     if (!s_propertyInfo) {
     67         s_propertyInfo = new SVGPropertyInfo(AnimatedUnknown,
     68                                              PropertyIsReadWrite,
     69                                              SVGNames::systemLanguageAttr,
     70                                              SVGNames::systemLanguageAttr.localName(),
     71                                              &SVGElement::synchronizeSystemLanguage,
     72                                              0);
     73     }
     74     return s_propertyInfo;
     75 }
     76 
     77 SVGTests::SVGTests()
     78     : m_requiredFeatures(SVGNames::requiredFeaturesAttr)
     79     , m_requiredExtensions(SVGNames::requiredExtensionsAttr)
     80     , m_systemLanguage(SVGNames::systemLanguageAttr)
     81 {
     82 }
     83 
     84 SVGAttributeToPropertyMap& SVGTests::attributeToPropertyMap()
     85 {
     86     DEFINE_STATIC_LOCAL(SVGAttributeToPropertyMap, map, ());
     87     if (!map.isEmpty())
     88         return map;
     89     map.addProperty(requiredFeaturesPropertyInfo());
     90     map.addProperty(requiredExtensionsPropertyInfo());
     91     map.addProperty(systemLanguagePropertyInfo());
     92     return map;
     93 }
     94 
     95 bool SVGTests::hasExtension(const String&) const
     96 {
     97     // FIXME: Implement me!
     98     return false;
     99 }
    100 
    101 bool SVGTests::isValid() const
    102 {
    103     unsigned featuresSize = m_requiredFeatures.value.size();
    104     for (unsigned i = 0; i < featuresSize; ++i) {
    105         String value = m_requiredFeatures.value.at(i);
    106         if (value.isEmpty() || !DOMImplementation::hasFeature(value, String()))
    107             return false;
    108     }
    109 
    110     unsigned systemLanguageSize = m_systemLanguage.value.size();
    111     for (unsigned i = 0; i < systemLanguageSize; ++i) {
    112         String value = m_systemLanguage.value.at(i);
    113         if (value != defaultLanguage().substring(0, 2))
    114             return false;
    115     }
    116 
    117     if (!m_requiredExtensions.value.isEmpty())
    118         return false;
    119 
    120     return true;
    121 }
    122 
    123 bool SVGTests::parseAttribute(const QualifiedName& name, const AtomicString& value)
    124 {
    125     if (name == SVGNames::requiredFeaturesAttr) {
    126         m_requiredFeatures.value.reset(value);
    127         return true;
    128     }
    129     if (name == SVGNames::requiredExtensionsAttr) {
    130         m_requiredExtensions.value.reset(value);
    131         return true;
    132     }
    133     if (name == SVGNames::systemLanguageAttr) {
    134         m_systemLanguage.value.reset(value);
    135         return true;
    136     }
    137 
    138     return false;
    139 }
    140 
    141 bool SVGTests::isKnownAttribute(const QualifiedName& attrName)
    142 {
    143     return attrName == SVGNames::requiredFeaturesAttr
    144         || attrName == SVGNames::requiredExtensionsAttr
    145         || attrName == SVGNames::systemLanguageAttr;
    146 }
    147 
    148 void SVGTests::addSupportedAttributes(HashSet<QualifiedName>& supportedAttributes)
    149 {
    150     supportedAttributes.add(SVGNames::requiredFeaturesAttr);
    151     supportedAttributes.add(SVGNames::requiredExtensionsAttr);
    152     supportedAttributes.add(SVGNames::systemLanguageAttr);
    153 }
    154 
    155 void SVGTests::synchronizeRequiredFeatures(SVGElement* contextElement)
    156 {
    157     ASSERT(contextElement);
    158     if (!m_requiredFeatures.shouldSynchronize)
    159         return;
    160     AtomicString value(m_requiredFeatures.value.valueAsString());
    161     m_requiredFeatures.synchronize(contextElement, requiredFeaturesPropertyInfo()->attributeName, value);
    162 }
    163 
    164 void SVGTests::synchronizeRequiredExtensions(SVGElement* contextElement)
    165 {
    166     ASSERT(contextElement);
    167     if (!m_requiredExtensions.shouldSynchronize)
    168         return;
    169     AtomicString value(m_requiredExtensions.value.valueAsString());
    170     m_requiredExtensions.synchronize(contextElement, requiredExtensionsPropertyInfo()->attributeName, value);
    171 }
    172 
    173 void SVGTests::synchronizeSystemLanguage(SVGElement* contextElement)
    174 {
    175     ASSERT(contextElement);
    176     if (!m_systemLanguage.shouldSynchronize)
    177         return;
    178     AtomicString value(m_systemLanguage.value.valueAsString());
    179     m_systemLanguage.synchronize(contextElement, systemLanguagePropertyInfo()->attributeName, value);
    180 }
    181 
    182 SVGStringList& SVGTests::requiredFeatures()
    183 {
    184     m_requiredFeatures.shouldSynchronize = true;
    185     return m_requiredFeatures.value;
    186 }
    187 
    188 SVGStringList& SVGTests::requiredExtensions()
    189 {
    190     m_requiredExtensions.shouldSynchronize = true;
    191     return m_requiredExtensions.value;
    192 }
    193 
    194 SVGStringList& SVGTests::systemLanguage()
    195 {
    196     m_systemLanguage.shouldSynchronize = true;
    197     return m_systemLanguage.value;
    198 }
    199 
    200 }
    201