Commit c3cde884 authored by eric@webkit.org's avatar eric@webkit.org

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:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63045 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent eca7f184
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-09 Tony Chang <tony@chromium.org>
Reviewed by Ojan Vafai.
......@@ -910,10 +910,6 @@ resources/tests10.dat:
15
18
19
22
23
24
25
Test 13 of 25 in resources/tests10.dat failed. Input:
<!DOCTYPE html><body><table><caption><svg><g>foo</g><g>bar</g><p>baz</table><p>quux
......@@ -1071,102 +1067,6 @@ Expected:
| "bar"
| <p>
| "baz"
Test 22 of 25 in resources/tests10.dat failed. Input:
<!DOCTYPE html><body xlink:href=foo><svg xlink:href=foo></svg>
Got:
| <!DOCTYPE html>
| <html>
| <head>
| <body>
| xlink:href="foo"
| <svg svg>
| xlink:href="foo"
Expected:
| <!DOCTYPE html>
| <html>
| <head>
| <body>
| xlink:href="foo"
| <svg svg>
| xlink href="foo"
Test 23 of 25 in resources/tests10.dat failed. Input:
<!DOCTYPE html><body xlink:href=foo xml:lang=en><svg><g xml:lang=en xlink:href=foo></g></svg>
Got:
| <!DOCTYPE html>
| <html>
| <head>
| <body>
| xlink:href="foo"
| xml:lang="en"
| <svg svg>
| <svg g>
| xlink:href="foo"
| xml:lang="en"
Expected:
| <!DOCTYPE html>
| <html>
| <head>
| <body>
| xlink:href="foo"
| xml:lang="en"
| <svg svg>
| <svg g>
| xlink href="foo"
| xml lang="en"
Test 24 of 25 in resources/tests10.dat failed. Input:
<!DOCTYPE html><body xlink:href=foo xml:lang=en><svg><g xml:lang=en xlink:href=foo /></svg>
Got:
| <!DOCTYPE html>
| <html>
| <head>
| <body>
| xlink:href="foo"
| xml:lang="en"
| <svg svg>
| <svg g>
| xlink:href="foo"
| xml:lang="en"
Expected:
| <!DOCTYPE html>
| <html>
| <head>
| <body>
| xlink:href="foo"
| xml:lang="en"
| <svg svg>
| <svg g>
| xlink href="foo"
| xml lang="en"
Test 25 of 25 in resources/tests10.dat failed. Input:
<!DOCTYPE html><body xlink:href=foo xml:lang=en><svg><g xml:lang=en xlink:href=foo />bar</svg>
Got:
| <!DOCTYPE html>
| <html>
| <head>
| <body>
| xlink:href="foo"
| xml:lang="en"
| <svg svg>
| <svg g>
| xlink:href="foo"
| xml:lang="en"
| "bar"
Expected:
| <!DOCTYPE html>
| <html>
| <head>
| <body>
| xlink:href="foo"
| xml:lang="en"
| <svg svg>
| <svg g>
| xlink href="foo"
| xml lang="en"
| "bar"
resources/tests11.dat:
4
8
......
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:
2010-07-10 Rob Buis <rwlbuis@gmail.com>
Reviewed by Darin Adler.
......@@ -78,13 +78,10 @@ public:
void setValue(const AtomicString& value) { m_value = value; }
void setPrefix(const AtomicString& prefix) { m_name.setPrefix(prefix); }
// Note: This API is only for HTMLTreeBuilder. It is not safe to change the name
// of an attribute once parseMappedAttributes has been called as DOM elements
// may placed the Attribute in a hash.
void parserSetLocalName(const AtomicString& localName)
{
m_name = QualifiedName(m_name.prefix(), localName, m_name.namespaceURI());
}
// Note: This API is only for HTMLTreeBuilder. It is not safe to change the
// name of an attribute once parseMappedAttribute has been called as DOM
// elements may have placed the Attribute in a hash by name.
void parserSetName(const QualifiedName& name) { m_name = name; }
bool isMappedAttribute() { return m_isMappedAttribute; }
......
......@@ -51,6 +51,9 @@
#include "ScriptController.h"
#include "Settings.h"
#include "Text.h"
#include "XLinkNames.h"
#include "XMLNSNames.h"
#include "XMLNames.h"
#include <wtf/UnusedParam.h>
namespace WebCore {
......@@ -660,48 +663,20 @@ void HTMLTreeBuilder::processCloseWhenNestedTag(AtomicHTMLToken& token)
namespace {
#if ENABLE(SVG)
typedef HashMap<AtomicString, AtomicString> NameCaseMap;
void addName(NameCaseMap* map, const QualifiedName& attributeName)
{
map->add(attributeName.localName().lower(), attributeName.localName());
}
typedef HashMap<AtomicString, QualifiedName> PrefixedNameToQualifiedNameMap;
NameCaseMap* createCaseMapForNames(QualifiedName** names, size_t length)
void mapLoweredLocalNameToName(PrefixedNameToQualifiedNameMap* map, QualifiedName** names, size_t length)
{
NameCaseMap* caseMap = new NameCaseMap;
for (size_t i = 0; i < length; ++i) {
QualifiedName* name = names[i];
const AtomicString& localName = name->localName();
const QualifiedName& name = *names[i];
const AtomicString& localName = name.localName();
AtomicString loweredLocalName = localName.lower();
if (loweredLocalName != localName)
caseMap->add(loweredLocalName, localName);
map->add(loweredLocalName, name);
}
return caseMap;
}
void adjustSVGAttributes(AtomicHTMLToken& token)
{
static NameCaseMap* caseMap = 0;
if (!caseMap) {
size_t length = 0;
QualifiedName** svgAttrs = SVGNames::getSVGAttrs(&length);
caseMap = createCaseMapForNames(svgAttrs, length);
}
NamedNodeMap* attributes = token.attributes();
if (!attributes)
return;
for (unsigned x = 0; x < attributes->length(); ++x) {
Attribute* attribute = attributes->attributeItem(x);
const AtomicString& casedName = caseMap->get(attribute->localName());
if (!casedName.isNull())
attribute->parserSetLocalName(casedName);
}
}
#if ENABLE(SVG)
// FIXME: This is a hack until we can fix SVGNames to always generate all names.
QualifiedName svgTagNameFor(const AtomicString& localName)
......@@ -709,13 +684,19 @@ QualifiedName svgTagNameFor(const AtomicString& localName)
return QualifiedName(nullAtom, localName, SVGNames::svgNamespaceURI);
}
void addName(PrefixedNameToQualifiedNameMap* map, const QualifiedName& name)
{
map->add(name.localName().lower(), name);
}
void adjustSVGTagNameCase(AtomicHTMLToken& token)
{
static NameCaseMap* caseMap = 0;
static PrefixedNameToQualifiedNameMap* caseMap = 0;
if (!caseMap) {
caseMap = new PrefixedNameToQualifiedNameMap;
size_t length = 0;
QualifiedName** svgTags = SVGNames::getSVGTags(&length);
caseMap = createCaseMapForNames(svgTags, length);
mapLoweredLocalNameToName(caseMap, svgTags, length);
// FIXME: This is a hack around the fact that SVGNames does not
// currently include all values HTML5 expects it to.
addName(caseMap, svgTagNameFor("altGlyphDef"));
......@@ -723,10 +704,32 @@ void adjustSVGTagNameCase(AtomicHTMLToken& token)
addName(caseMap, svgTagNameFor("glyphRef"));
}
const AtomicString& casedName = caseMap->get(token.name());
if (casedName.isNull())
const QualifiedName& casedName = caseMap->get(token.name());
if (casedName.localName().isNull())
return;
token.setName(casedName.localName());
}
void adjustSVGAttributes(AtomicHTMLToken& token)
{
static PrefixedNameToQualifiedNameMap* caseMap = 0;
if (!caseMap) {
caseMap = new PrefixedNameToQualifiedNameMap;
size_t length = 0;
QualifiedName** svgAttrs = SVGNames::getSVGAttrs(&length);
mapLoweredLocalNameToName(caseMap, svgAttrs, length);
}
NamedNodeMap* attributes = token.attributes();
if (!attributes)
return;
token.setName(casedName);
for (unsigned x = 0; x < attributes->length(); ++x) {
Attribute* attribute = attributes->attributeItem(x);
const QualifiedName& casedName = caseMap->get(attribute->localName());
if (!casedName.localName().isNull())
attribute->parserSetName(casedName);
}
}
#endif
......@@ -738,9 +741,43 @@ void adjustMathMLAttributes(AtomicHTMLToken&)
}
#endif
void adjustForeignAttributes(AtomicHTMLToken&)
void addNamesWithPrefix(PrefixedNameToQualifiedNameMap* map, const AtomicString& prefix, QualifiedName** names, size_t length)
{
notImplemented();
for (size_t i = 0; i < length; ++i) {
QualifiedName* name = names[i];
const AtomicString& localName = name->localName();
AtomicString prefixColonLocalName(prefix + ":" + localName);
QualifiedName nameWithPrefix(prefix, localName, name->namespaceURI());
map->add(prefixColonLocalName, nameWithPrefix);
}
}
void adjustForeignAttributes(AtomicHTMLToken& token)
{
static PrefixedNameToQualifiedNameMap* map = 0;
if (!map) {
map = new PrefixedNameToQualifiedNameMap;
size_t length = 0;
QualifiedName** attrs = XLinkNames::getXLinkAttrs(&length);
addNamesWithPrefix(map, "xlink", attrs, length);
attrs = XMLNames::getXMLAttrs(&length);
addNamesWithPrefix(map, "xml", attrs, length);
map->add("xmlns", XMLNSNames::xmlnsAttr);
map->add("xmlns:xlink", QualifiedName("xmlns", "xlink", XMLNSNames::xmlnsNamespaceURI));
}
NamedNodeMap* attributes = token.attributes();
if (!attributes)
return;
for (unsigned x = 0; x < attributes->length(); ++x) {
Attribute* attribute = attributes->attributeItem(x);
const QualifiedName& name = map->get(attribute->localName());
if (!name.localName().isNull())
attribute->parserSetName(name);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment