Changeset 63045 in webkit


Ignore:
Timestamp:
Jul 10, 2010 2:01:35 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-07-10 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

HTMLTreeBuilder needs adjustForeignAttributes support
https://bugs.webkit.org/show_bug.cgi?id=42022

  • html5lib/runner-expected-html5.txt:
    • We now pass 3 more tests.

2010-07-10 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

HTMLTreeBuilder needs adjustForeignAttributes support
https://bugs.webkit.org/show_bug.cgi?id=42022

To add adjust foreign attributes support I had to add an
AtomicString (prefixed name) to QualifiedName hash. Once I had
done that, I decided it would be best for the other "adjust" functions
to share the same hash logic, so I moved them to using the same
AtomicString -> QualifiedName hash as well.

Tested by html5lib/runner.html

  • dom/Attribute.h: (WebCore::Attribute::parserSetName):
  • html/HTMLTreeBuilder.cpp:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r63039 r63045  
     12010-07-10  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        HTMLTreeBuilder needs adjustForeignAttributes support
     6        https://bugs.webkit.org/show_bug.cgi?id=42022
     7
     8        * html5lib/runner-expected-html5.txt:
     9         - We now pass 3 more tests.
     10
    1112010-07-09  Tony Chang  <tony@chromium.org>
    212
  • trunk/LayoutTests/html5lib/runner-expected-html5.txt

    r63003 r63045  
    91191118
    91291219
    913 22
    914 23
    915 24
    916 25
    917913
    918914Test 13 of 25 in resources/tests10.dat failed. Input:
     
    10721068|     <p>
    10731069|       "baz"
    1074 
    1075 Test 22 of 25 in resources/tests10.dat failed. Input:
    1076 <!DOCTYPE html><body xlink:href=foo><svg xlink:href=foo></svg>
    1077 Got:
    1078 | <!DOCTYPE html>
    1079 | <html>
    1080 |   <head>
    1081 |   <body>
    1082 |     xlink:href="foo"
    1083 |     <svg svg>
    1084 |       xlink:href="foo"
    1085 Expected:
    1086 | <!DOCTYPE html>
    1087 | <html>
    1088 |   <head>
    1089 |   <body>
    1090 |     xlink:href="foo"
    1091 |     <svg svg>
    1092 |       xlink href="foo"
    1093 
    1094 Test 23 of 25 in resources/tests10.dat failed. Input:
    1095 <!DOCTYPE html><body xlink:href=foo xml:lang=en><svg><g xml:lang=en xlink:href=foo></g></svg>
    1096 Got:
    1097 | <!DOCTYPE html>
    1098 | <html>
    1099 |   <head>
    1100 |   <body>
    1101 |     xlink:href="foo"
    1102 |     xml:lang="en"
    1103 |     <svg svg>
    1104 |       <svg g>
    1105 |         xlink:href="foo"
    1106 |         xml:lang="en"
    1107 Expected:
    1108 | <!DOCTYPE html>
    1109 | <html>
    1110 |   <head>
    1111 |   <body>
    1112 |     xlink:href="foo"
    1113 |     xml:lang="en"
    1114 |     <svg svg>
    1115 |       <svg g>
    1116 |         xlink href="foo"
    1117 |         xml lang="en"
    1118 
    1119 Test 24 of 25 in resources/tests10.dat failed. Input:
    1120 <!DOCTYPE html><body xlink:href=foo xml:lang=en><svg><g xml:lang=en xlink:href=foo /></svg>
    1121 Got:
    1122 | <!DOCTYPE html>
    1123 | <html>
    1124 |   <head>
    1125 |   <body>
    1126 |     xlink:href="foo"
    1127 |     xml:lang="en"
    1128 |     <svg svg>
    1129 |       <svg g>
    1130 |         xlink:href="foo"
    1131 |         xml:lang="en"
    1132 Expected:
    1133 | <!DOCTYPE html>
    1134 | <html>
    1135 |   <head>
    1136 |   <body>
    1137 |     xlink:href="foo"
    1138 |     xml:lang="en"
    1139 |     <svg svg>
    1140 |       <svg g>
    1141 |         xlink href="foo"
    1142 |         xml lang="en"
    1143 
    1144 Test 25 of 25 in resources/tests10.dat failed. Input:
    1145 <!DOCTYPE html><body xlink:href=foo xml:lang=en><svg><g xml:lang=en xlink:href=foo />bar</svg>
    1146 Got:
    1147 | <!DOCTYPE html>
    1148 | <html>
    1149 |   <head>
    1150 |   <body>
    1151 |     xlink:href="foo"
    1152 |     xml:lang="en"
    1153 |     <svg svg>
    1154 |       <svg g>
    1155 |         xlink:href="foo"
    1156 |         xml:lang="en"
    1157 |       "bar"
    1158 Expected:
    1159 | <!DOCTYPE html>
    1160 | <html>
    1161 |   <head>
    1162 |   <body>
    1163 |     xlink:href="foo"
    1164 |     xml:lang="en"
    1165 |     <svg svg>
    1166 |       <svg g>
    1167 |         xlink href="foo"
    1168 |         xml lang="en"
    1169 |       "bar"
    11701070resources/tests11.dat:
    117110714
  • trunk/WebCore/ChangeLog

    r63044 r63045  
     12010-07-10  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        HTMLTreeBuilder needs adjustForeignAttributes support
     6        https://bugs.webkit.org/show_bug.cgi?id=42022
     7
     8        To add adjust foreign attributes support I had to add an
     9        AtomicString (prefixed name) to QualifiedName hash.  Once I had
     10        done that, I decided it would be best for the other "adjust" functions
     11        to share the same hash logic, so I moved them to using the same
     12        AtomicString -> QualifiedName hash as well.
     13
     14        Tested by html5lib/runner.html
     15
     16        * dom/Attribute.h:
     17        (WebCore::Attribute::parserSetName):
     18        * html/HTMLTreeBuilder.cpp:
     19
    1202010-07-10  Rob Buis  <rwlbuis@gmail.com>
    221
  • trunk/WebCore/dom/Attribute.h

    r62994 r63045  
    7979    void setPrefix(const AtomicString& prefix) { m_name.setPrefix(prefix); }
    8080
    81     // Note: This API is only for HTMLTreeBuilder.  It is not safe to change the name
    82     // of an attribute once parseMappedAttributes has been called as DOM elements
    83     // may placed the Attribute in a hash.
    84     void parserSetLocalName(const AtomicString& localName)
    85     {
    86         m_name = QualifiedName(m_name.prefix(), localName, m_name.namespaceURI());
    87     }
     81    // Note: This API is only for HTMLTreeBuilder.  It is not safe to change the
     82    // name of an attribute once parseMappedAttribute has been called as DOM
     83    // elements may have placed the Attribute in a hash by name.
     84    void parserSetName(const QualifiedName& name) { m_name = name; }
    8885
    8986    bool isMappedAttribute() { return m_isMappedAttribute; }
  • trunk/WebCore/html/HTMLTreeBuilder.cpp

    r63013 r63045  
    5252#include "Settings.h"
    5353#include "Text.h"
     54#include "XLinkNames.h"
     55#include "XMLNSNames.h"
     56#include "XMLNames.h"
    5457#include <wtf/UnusedParam.h>
    5558
     
    661664namespace {
    662665
    663 #if ENABLE(SVG)
    664 
    665 typedef HashMap<AtomicString, AtomicString> NameCaseMap;
    666 
    667 void addName(NameCaseMap* map, const QualifiedName& attributeName)
    668 {
    669     map->add(attributeName.localName().lower(), attributeName.localName());
    670 }
    671 
    672 NameCaseMap* createCaseMapForNames(QualifiedName** names, size_t length)
    673 {
    674     NameCaseMap* caseMap = new NameCaseMap;
     666typedef HashMap<AtomicString, QualifiedName> PrefixedNameToQualifiedNameMap;
     667
     668void mapLoweredLocalNameToName(PrefixedNameToQualifiedNameMap* map, QualifiedName** names, size_t length)
     669{
    675670    for (size_t i = 0; i < length; ++i) {
    676         QualifiedName* name = names[i];
    677         const AtomicString& localName = name->localName();
     671        const QualifiedName& name = *names[i];
     672        const AtomicString& localName = name.localName();
    678673        AtomicString loweredLocalName = localName.lower();
    679674        if (loweredLocalName != localName)
    680             caseMap->add(loweredLocalName, localName);
    681     }
    682     return caseMap;
    683 }
    684 
    685 void adjustSVGAttributes(AtomicHTMLToken& token)
    686 {
    687     static NameCaseMap* caseMap = 0;
    688     if (!caseMap) {
    689         size_t length = 0;
    690         QualifiedName** svgAttrs = SVGNames::getSVGAttrs(&length);
    691         caseMap = createCaseMapForNames(svgAttrs, length);
    692     }
    693 
    694     NamedNodeMap* attributes = token.attributes();
    695     if (!attributes)
    696         return;
    697 
    698     for (unsigned x = 0; x < attributes->length(); ++x) {
    699         Attribute* attribute = attributes->attributeItem(x);
    700         const AtomicString& casedName = caseMap->get(attribute->localName());
    701         if (!casedName.isNull())
    702             attribute->parserSetLocalName(casedName);
    703     }
    704 }
     675            map->add(loweredLocalName, name);
     676    }
     677}
     678
     679#if ENABLE(SVG)
    705680
    706681// FIXME: This is a hack until we can fix SVGNames to always generate all names.
     
    710685}
    711686
     687void addName(PrefixedNameToQualifiedNameMap* map, const QualifiedName& name)
     688{
     689    map->add(name.localName().lower(), name);
     690}
     691
    712692void adjustSVGTagNameCase(AtomicHTMLToken& token)
    713693{
    714     static NameCaseMap* caseMap = 0;
     694    static PrefixedNameToQualifiedNameMap* caseMap = 0;
    715695    if (!caseMap) {
     696        caseMap = new PrefixedNameToQualifiedNameMap;
    716697        size_t length = 0;
    717698        QualifiedName** svgTags = SVGNames::getSVGTags(&length);
    718         caseMap = createCaseMapForNames(svgTags, length);
     699        mapLoweredLocalNameToName(caseMap, svgTags, length);
    719700        // FIXME: This is a hack around the fact that SVGNames does not
    720701        // currently include all values HTML5 expects it to.
     
    724705    }
    725706
    726     const AtomicString& casedName = caseMap->get(token.name());
    727     if (casedName.isNull())
    728         return;
    729     token.setName(casedName);
     707    const QualifiedName& casedName = caseMap->get(token.name());
     708    if (casedName.localName().isNull())
     709        return;
     710    token.setName(casedName.localName());
     711}
     712
     713void adjustSVGAttributes(AtomicHTMLToken& token)
     714{
     715    static PrefixedNameToQualifiedNameMap* caseMap = 0;
     716    if (!caseMap) {
     717        caseMap = new PrefixedNameToQualifiedNameMap;
     718        size_t length = 0;
     719        QualifiedName** svgAttrs = SVGNames::getSVGAttrs(&length);
     720        mapLoweredLocalNameToName(caseMap, svgAttrs, length);
     721    }
     722
     723    NamedNodeMap* attributes = token.attributes();
     724    if (!attributes)
     725        return;
     726
     727    for (unsigned x = 0; x < attributes->length(); ++x) {
     728        Attribute* attribute = attributes->attributeItem(x);
     729        const QualifiedName& casedName = caseMap->get(attribute->localName());
     730        if (!casedName.localName().isNull())
     731            attribute->parserSetName(casedName);
     732    }
    730733}
    731734
     
    739742#endif
    740743
    741 void adjustForeignAttributes(AtomicHTMLToken&)
    742 {
    743     notImplemented();
     744void addNamesWithPrefix(PrefixedNameToQualifiedNameMap* map, const AtomicString& prefix, QualifiedName** names, size_t length)
     745{
     746    for (size_t i = 0; i < length; ++i) {
     747        QualifiedName* name = names[i];
     748        const AtomicString& localName = name->localName();
     749        AtomicString prefixColonLocalName(prefix + ":" + localName);
     750        QualifiedName nameWithPrefix(prefix, localName, name->namespaceURI());
     751        map->add(prefixColonLocalName, nameWithPrefix);
     752    }
     753}
     754
     755void adjustForeignAttributes(AtomicHTMLToken& token)
     756{
     757    static PrefixedNameToQualifiedNameMap* map = 0;
     758    if (!map) {
     759        map = new PrefixedNameToQualifiedNameMap;
     760        size_t length = 0;
     761        QualifiedName** attrs = XLinkNames::getXLinkAttrs(&length);
     762        addNamesWithPrefix(map, "xlink", attrs, length);
     763
     764        attrs = XMLNames::getXMLAttrs(&length);
     765        addNamesWithPrefix(map, "xml", attrs, length);
     766
     767        map->add("xmlns", XMLNSNames::xmlnsAttr);
     768        map->add("xmlns:xlink", QualifiedName("xmlns", "xlink", XMLNSNames::xmlnsNamespaceURI));
     769    }
     770
     771    NamedNodeMap* attributes = token.attributes();
     772    if (!attributes)
     773        return;
     774
     775    for (unsigned x = 0; x < attributes->length(); ++x) {
     776        Attribute* attribute = attributes->attributeItem(x);
     777        const QualifiedName& name = map->get(attribute->localName());
     778        if (!name.localName().isNull())
     779            attribute->parserSetName(name);
     780    }
    744781}
    745782
Note: See TracChangeset for help on using the changeset viewer.