Changeset 104872 in webkit
- Timestamp:
- Jan 12, 2012 3:57:29 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r104866 r104872 1 2012-01-12 Eric Seidel <eric@webkit.org> 2 3 Refactor DOMImplementation.hasFeature logic into helper functions. 4 https://bugs.webkit.org/show_bug.cgi?id=76212 5 6 Reviewed by Adam Barth. 7 8 This patch should not have any behavior change. The goal was 9 to move our feature detection towards a more modular architecture 10 (as that seems to be the current trend in webkit). In a future 11 patch we could easily move the SVG feature detection into the 12 SVG directory, for example. I've also added a list of all the 13 Event3 features (currently commented out) which makes it obvious 14 how many we're missing. 15 16 * dom/DOMImplementation.cpp: 17 (WebCore::isSVG10Feature): 18 (WebCore::isSVG11Feature): 19 (WebCore::isEvents2Feature): 20 (WebCore::isEvents3Feature): 21 (WebCore::DOMImplementation::hasFeature): 22 1 23 2012-01-12 Adam Barth <abarth@webkit.org> 2 24 -
trunk/Source/WebCore/dom/DOMImplementation.cpp
r104746 r104872 61 61 namespace WebCore { 62 62 63 typedef HashSet<String, CaseFoldingHash> FeatureSet; 64 65 static void addString(FeatureSet& set, const char* string) 66 { 67 set.add(string); 68 } 69 63 70 #if ENABLE(SVG) 64 71 65 typedef HashSet<String, CaseFoldingHash> FeatureSet; 66 67 static void addString(FeatureSet& set, const char* string) 68 { 69 set.add(string); 70 } 71 72 static bool isSVG10Feature(const String &feature) 73 { 72 static bool isSVG10Feature(const String &feature, const String &version) 73 { 74 if (!version.isEmpty() && version != "1.0") 75 return false; 76 74 77 static bool initialized = false; 75 78 DEFINE_STATIC_LOCAL(FeatureSet, svgFeatures, ()); … … 92 95 initialized = true; 93 96 } 94 return svgFeatures.contains(feature); 95 } 96 97 static bool isSVG11Feature(const String &feature) 98 { 97 return feature.startsWith("org.w3c.", false) 98 && svgFeatures.contains(feature.right(feature.length() - 8)); 99 } 100 101 static bool isSVG11Feature(const String &feature, const String &version) 102 { 103 if (!version.isEmpty() && version != "1.1") 104 return false; 105 99 106 static bool initialized = false; 100 107 DEFINE_STATIC_LOCAL(FeatureSet, svgFeatures, ()); … … 157 164 initialized = true; 158 165 } 159 return svgFeatures.contains(feature); 160 } 161 #endif 166 return feature.startsWith("http://www.w3.org/tr/svg11/feature#", false) 167 && svgFeatures.contains(feature.right(feature.length() - 35)); 168 } 169 #endif 170 171 static bool isEvents2Feature(const String &feature, const String &version) 172 { 173 if (!version.isEmpty() && version != "2.0") 174 return false; 175 176 static bool initialized = false; 177 DEFINE_STATIC_LOCAL(FeatureSet, events2Features, ()); 178 if (!initialized) { 179 addString(events2Features, "Events"); 180 addString(events2Features, "HTMLEvents"); 181 addString(events2Features, "MouseEvents"); 182 addString(events2Features, "MutationEvents"); 183 addString(events2Features, "UIEvents"); 184 initialized = true; 185 } 186 return events2Features.contains(feature); 187 } 188 189 static bool isEvents3Feature(const String &feature, const String &version) 190 { 191 if (!version.isEmpty() && version != "3.0") 192 return false; 193 194 static bool initialized = false; 195 DEFINE_STATIC_LOCAL(FeatureSet, events3Features, ()); 196 if (!initialized) { 197 // FIXME: We probably support many of these features. 198 // addString(events3Features, "CompositionEvents"); 199 // addString(events3Features, "Events"); 200 // addString(events3Features, "FocusEvents"); 201 // addString(events3Features, "HTMLEvents"); 202 // addString(events3Features, "KeyboardEvents"); 203 // addString(events3Features, "MouseEvents"); 204 // addString(events3Features, "MutationEvents"); 205 // addString(events3Features, "MutationNameEvents"); 206 addString(events3Features, "TextEvents"); 207 // addString(events3Features, "UIEvents"); 208 // addString(events3Features, "WheelEvents"); 209 initialized = true; 210 } 211 // FIXME: We do not yet support Events 3 "extended feature strings". 212 return events3Features.contains(feature); 213 } 162 214 163 215 DOMImplementation::DOMImplementation(Document* document) … … 173 225 if (lower == "css" 174 226 || lower == "css2" 175 || lower == "events"176 || lower == "htmlevents"177 || lower == "mouseevents"178 || lower == "mutationevents"179 227 || lower == "range" 180 228 || lower == "stylesheets" 181 229 || lower == "traversal" 182 || lower == "uievents"183 230 || lower == "views") 184 231 return version.isEmpty() || version == "2.0"; 185 if (lower == "xpath" || lower == "textevents") 232 if (isEvents2Feature(feature, version)) 233 return true; 234 if (lower == "xpath") 186 235 return version.isEmpty() || version == "3.0"; 236 if (isEvents3Feature(feature, version)) 237 return true; 187 238 188 239 #if ENABLE(SVG) 189 if ((version.isEmpty() || version == "1.1") && feature.startsWith("http://www.w3.org/tr/svg11/feature#", false)) { 190 if (isSVG11Feature(feature.right(feature.length() - 35))) 191 return true; 192 } 193 194 if ((version.isEmpty() || version == "1.0") && feature.startsWith("org.w3c.", false)) { 195 if (isSVG10Feature(feature.right(feature.length() - 8))) 196 return true; 197 } 198 #endif 199 240 if (isSVG11Feature(feature, version)) 241 return true; 242 if (isSVG10Feature(feature, version)) 243 return true; 244 #endif 245 200 246 return false; 201 247 }
Note: See TracChangeset
for help on using the changeset viewer.