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

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 debug print 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
« no previous file with comments | « Source/core/svg/SVGTests.h ('k') | Source/core/svg/SVGTextPathElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const Vector<String>& requiredFeatures = m_requiredFeatures->value()->va lues();
105 String value = m_requiredFeatures.value.at(i); 54 Vector<String>::const_iterator it = requiredFeatures.begin();
106 if (value.isEmpty() || !DOMImplementation::hasFeature(value, String())) 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)
107 return false; 76 return false;
108 } 77 }
109 78
110 unsigned systemLanguageSize = m_systemLanguage.value.size(); 79 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; 80 return false;
119 81
120 return true; 82 return true;
121 } 83 }
122 84
123 bool SVGTests::parseAttribute(const QualifiedName& name, const AtomicString& val ue) 85 bool SVGTests::parseAttribute(const QualifiedName& name, const AtomicString& val ue)
124 { 86 {
125 if (name == SVGNames::requiredFeaturesAttr) { 87 // FIXME: Should handle exceptions here.
126 m_requiredFeatures.value.reset(value); 88 // This is safe as of now, as the current impl of SVGStringList::setValueAsS tring never fails.
127 return true; 89 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 90
138 return false; 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;
139 } 103 }
140 104
141 bool SVGTests::isKnownAttribute(const QualifiedName& attrName) 105 bool SVGTests::isKnownAttribute(const QualifiedName& attrName)
142 { 106 {
143 return attrName == SVGNames::requiredFeaturesAttr 107 return attrName == SVGNames::requiredFeaturesAttr
144 || attrName == SVGNames::requiredExtensionsAttr 108 || attrName == SVGNames::requiredExtensionsAttr
145 || attrName == SVGNames::systemLanguageAttr; 109 || attrName == SVGNames::systemLanguageAttr;
146 } 110 }
147 111
148 void SVGTests::addSupportedAttributes(HashSet<QualifiedName>& supportedAttribute s) 112 void SVGTests::addSupportedAttributes(HashSet<QualifiedName>& supportedAttribute s)
149 { 113 {
150 supportedAttributes.add(SVGNames::requiredFeaturesAttr); 114 supportedAttributes.add(SVGNames::requiredFeaturesAttr);
151 supportedAttributes.add(SVGNames::requiredExtensionsAttr); 115 supportedAttributes.add(SVGNames::requiredExtensionsAttr);
152 supportedAttributes.add(SVGNames::systemLanguageAttr); 116 supportedAttributes.add(SVGNames::systemLanguageAttr);
153 } 117 }
154 118
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 } 119 }
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
« no previous file with comments | « Source/core/svg/SVGTests.h ('k') | Source/core/svg/SVGTextPathElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698