Changeset 104872 in webkit


Ignore:
Timestamp:
Jan 12, 2012 3:57:29 PM (12 years ago)
Author:
eric@webkit.org
Message:

Refactor DOMImplementation.hasFeature logic into helper functions.
https://bugs.webkit.org/show_bug.cgi?id=76212

Reviewed by Adam Barth.

This patch should not have any behavior change. The goal was
to move our feature detection towards a more modular architecture
(as that seems to be the current trend in webkit). In a future
patch we could easily move the SVG feature detection into the
SVG directory, for example. I've also added a list of all the
Event3 features (currently commented out) which makes it obvious
how many we're missing.

  • dom/DOMImplementation.cpp:

(WebCore::isSVG10Feature):
(WebCore::isSVG11Feature):
(WebCore::isEvents2Feature):
(WebCore::isEvents3Feature):
(WebCore::DOMImplementation::hasFeature):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r104866 r104872  
     12012-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
    1232012-01-12  Adam Barth  <abarth@webkit.org>
    224
  • trunk/Source/WebCore/dom/DOMImplementation.cpp

    r104746 r104872  
    6161namespace WebCore {
    6262
     63typedef HashSet<String, CaseFoldingHash> FeatureSet;
     64
     65static void addString(FeatureSet& set, const char* string)
     66{
     67    set.add(string);
     68}
     69
    6370#if ENABLE(SVG)
    6471
    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 {
     72static bool isSVG10Feature(const String &feature, const String &version)
     73{
     74    if (!version.isEmpty() && version != "1.0")
     75        return false;
     76
    7477    static bool initialized = false;
    7578    DEFINE_STATIC_LOCAL(FeatureSet, svgFeatures, ());
     
    9295        initialized = true;
    9396    }
    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
     101static bool isSVG11Feature(const String &feature, const String &version)
     102{
     103    if (!version.isEmpty() && version != "1.1")
     104        return false;
     105
    99106    static bool initialized = false;
    100107    DEFINE_STATIC_LOCAL(FeatureSet, svgFeatures, ());
     
    157164        initialized = true;
    158165    }
    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
     171static 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
     189static 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}
    162214
    163215DOMImplementation::DOMImplementation(Document* document)
     
    173225    if (lower == "css"
    174226            || lower == "css2"
    175             || lower == "events"
    176             || lower == "htmlevents"
    177             || lower == "mouseevents"
    178             || lower == "mutationevents"
    179227            || lower == "range"
    180228            || lower == "stylesheets"
    181229            || lower == "traversal"
    182             || lower == "uievents"
    183230            || lower == "views")
    184231        return version.isEmpty() || version == "2.0";
    185     if (lower == "xpath" || lower == "textevents")
     232    if (isEvents2Feature(feature, version))
     233        return true;
     234    if (lower == "xpath")
    186235        return version.isEmpty() || version == "3.0";
     236    if (isEvents3Feature(feature, version))
     237        return true;
    187238
    188239#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
    200246    return false;
    201247}
Note: See TracChangeset for help on using the changeset viewer.