Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: Source/core/svg/SVGTests.cpp

Issue 148173018: [SVG] SVGAnimatedString{,List} migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove if 0 Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 11 matching lines...) Expand all
22 22
23 #include "core/svg/SVGTests.h" 23 #include "core/svg/SVGTests.h"
24 24
25 #include "SVGNames.h" 25 #include "SVGNames.h"
26 #include "core/dom/DOMImplementation.h" 26 #include "core/dom/DOMImplementation.h"
27 #include "platform/Language.h" 27 #include "platform/Language.h"
28 #include "core/svg/SVGElement.h" 28 #include "core/svg/SVGElement.h"
29 29
30 namespace WebCore { 30 namespace WebCore {
31 31
32 // Define custom non-animated property 'requiredFeatures'. 32 SVGTests::SVGTests(SVGElement* contextElement)
33 const SVGPropertyInfo* SVGTests::requiredFeaturesPropertyInfo() 33 : m_requiredFeatures(SVGStaticStringList::create(contextElement, SVGNames::r equiredFeaturesAttr))
34 , m_requiredExtensions(SVGStaticStringList::create(contextElement, SVGNames: :requiredExtensionsAttr))
35 , m_systemLanguage(SVGStaticStringList::create(contextElement, SVGNames::sys temLanguageAttr))
34 { 36 {
35 static const SVGPropertyInfo* s_propertyInfo = 0; 37 ASSERT(contextElement);
36 if (!s_propertyInfo) {
37 s_propertyInfo = new SVGPropertyInfo(AnimatedUnknown,
38 PropertyIsReadWrite,
39 SVGNames::requiredFeaturesAttr,
40 SVGNames::requiredFeaturesAttr.loca lName(),
41 &SVGElement::synchronizeRequiredFea tures,
42 0);
43 }
44 return s_propertyInfo;
45 }
46 38
47 // Define custom non-animated property 'requiredExtensions'. 39 contextElement->addToPropertyMap(m_requiredFeatures);
48 const SVGPropertyInfo* SVGTests::requiredExtensionsPropertyInfo() 40 contextElement->addToPropertyMap(m_requiredExtensions);
49 { 41 contextElement->addToPropertyMap(m_systemLanguage);
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.lo calName(),
56 &SVGElement::synchronizeRequiredExt ensions,
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.localN ame(),
71 &SVGElement::synchronizeSystemLangu age,
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 } 42 }
94 43
95 bool SVGTests::hasExtension(const String&) const 44 bool SVGTests::hasExtension(const String&) const
96 { 45 {
97 // FIXME: Implement me! 46 // FIXME: Implement me!
98 return false; 47 return false;
99 } 48 }
100 49
101 bool SVGTests::isValid() const 50 bool SVGTests::isValid() const
102 { 51 {
103 unsigned featuresSize = m_requiredFeatures.value.size(); 52 if (m_requiredFeatures->isSpecified()) {
104 for (unsigned i = 0; i < featuresSize; ++i) { 53 m_requiredFeatures->value()->valueAsString().show();
105 String value = m_requiredFeatures.value.at(i); 54 const Vector<String>& requiredFeatures = m_requiredFeatures->value()->va lues();
106 if (value.isEmpty() || !DOMImplementation::hasFeature(value, String())) 55 Vector<String>::const_iterator it = requiredFeatures.begin();
56 Vector<String>::const_iterator itEnd = requiredFeatures.end();
57 for (; it != itEnd; ++it) {
58 if (it->isEmpty() || !DOMImplementation::hasFeature(*it, String()))
59 return false;
60 }
61 }
62
63 if (m_systemLanguage->isSpecified()) {
64 bool matchFound = false;
65
66 const Vector<String>& systemLanguage = m_systemLanguage->value()->values ();
67 Vector<String>::const_iterator it = systemLanguage.begin();
68 Vector<String>::const_iterator itEnd = systemLanguage.end();
69 for (; it != itEnd; ++it) {
70 if (*it == defaultLanguage().string().substring(0, 2)) {
71 matchFound = true;
72 break;
73 }
74 }
75
76 if (!matchFound)
107 return false; 77 return false;
108 } 78 }
109 79
110 unsigned systemLanguageSize = m_systemLanguage.value.size(); 80 if (!m_requiredExtensions->value()->values().isEmpty())
111 for (unsigned i = 0; i < systemLanguageSize; ++i) {
112 String value = m_systemLanguage.value.at(i);
113 if (value != defaultLanguage().string().substring(0, 2))
114 return false;
115 }
116
117 if (!m_requiredExtensions.value.isEmpty())
118 return false; 81 return false;
119 82
120 return true; 83 return true;
121 } 84 }
122 85
123 bool SVGTests::parseAttribute(const QualifiedName& name, const AtomicString& val ue) 86 bool SVGTests::parseAttribute(const QualifiedName& name, const AtomicString& val ue)
124 { 87 {
125 if (name == SVGNames::requiredFeaturesAttr) { 88 // FIXME: Should handle exceptions here.
126 m_requiredFeatures.value.reset(value); 89 // This is safe as of now, as the current impl of SVGStringList::setValueAsS tring never fails.
127 return true; 90 SVGParsingError parseError = NoError;
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 91
138 return false; 92 if (name == SVGNames::requiredFeaturesAttr)
93 m_requiredFeatures->setBaseValueAsString(value, parseError);
94 else if (name == SVGNames::requiredExtensionsAttr)
95 m_requiredExtensions->setBaseValueAsString(value, parseError);
96 else if (name == SVGNames::systemLanguageAttr)
97 m_systemLanguage->setBaseValueAsString(value, parseError);
98 else
99 return false;
100
101 ASSERT(parseError == NoError);
102
103 return true;
139 } 104 }
140 105
141 bool SVGTests::isKnownAttribute(const QualifiedName& attrName) 106 bool SVGTests::isKnownAttribute(const QualifiedName& attrName)
142 { 107 {
143 return attrName == SVGNames::requiredFeaturesAttr 108 return attrName == SVGNames::requiredFeaturesAttr
144 || attrName == SVGNames::requiredExtensionsAttr 109 || attrName == SVGNames::requiredExtensionsAttr
145 || attrName == SVGNames::systemLanguageAttr; 110 || attrName == SVGNames::systemLanguageAttr;
146 } 111 }
147 112
148 void SVGTests::addSupportedAttributes(HashSet<QualifiedName>& supportedAttribute s) 113 void SVGTests::addSupportedAttributes(HashSet<QualifiedName>& supportedAttribute s)
149 { 114 {
150 supportedAttributes.add(SVGNames::requiredFeaturesAttr); 115 supportedAttributes.add(SVGNames::requiredFeaturesAttr);
151 supportedAttributes.add(SVGNames::requiredExtensionsAttr); 116 supportedAttributes.add(SVGNames::requiredExtensionsAttr);
152 supportedAttributes.add(SVGNames::systemLanguageAttr); 117 supportedAttributes.add(SVGNames::systemLanguageAttr);
153 } 118 }
154 119
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 } 120 }
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, requiredExtensionsPropertyI nfo()->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()->a ttributeName, 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698