Remove mapped vs non-mapped attribute distinction.
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Feb 2012 09:26:05 +0000 (09:26 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Feb 2012 09:26:05 +0000 (09:26 +0000)
<http://webkit.org/b/77827>

Reviewed by Antti Koivisto.

Removed the isMappedAttribute flag from Attribute as it no longer serves
a practical purpose. Previously, StyledElement would generate mapped
attributes and plain Element would generate non-mapped ones.

The distinction is now made much more clearly by dividing the work between
Element's and StyledElement's attributeChanged() methods. The only thing
that StyledElement wants to do in addition to what Element does is
calling parseMappedAttribute() (which we'll rename in a later patch.)

* dom/Attribute.cpp:
(WebCore::Attribute::clone):
* dom/Attribute.h:
(WebCore::Attribute::create):
(WebCore::Attribute::Attribute):
(Attribute):
* dom/Document.cpp:
(WebCore::Document::createAttributeNS):
* dom/Element.cpp:
(WebCore::Element::attributeChanged):
* dom/Element.h:
(Element):
* dom/Node.cpp:
(WebCore::Node::dumpStatistics):
* dom/StyledElement.cpp:
(WebCore::StyledElement::attributeChanged):
(WebCore::StyledElement::parseMappedAttribute):
* dom/StyledElement.h:
(StyledElement):
* html/parser/HTMLConstructionSite.cpp:
(WebCore):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::attributesForIsindexInput):
* html/parser/TextDocumentParser.cpp:
(WebCore::TextDocumentParser::insertFakePreElement):
* svg/SVGStyledElement.cpp:
(WebCore::SVGStyledElement::getPresentationAttribute):
* xml/parser/MarkupTokenBase.h:
(WebCore::::initializeAttributes):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@106757 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Attribute.cpp
Source/WebCore/dom/Attribute.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/StyledElement.cpp
Source/WebCore/dom/StyledElement.h
Source/WebCore/html/parser/HTMLConstructionSite.cpp
Source/WebCore/html/parser/HTMLTreeBuilder.cpp
Source/WebCore/html/parser/TextDocumentParser.cpp
Source/WebCore/svg/SVGStyledElement.cpp
Source/WebCore/xml/parser/MarkupTokenBase.h

index a7f2944..dc801df 100644 (file)
@@ -1,5 +1,51 @@
 2012-02-05  Andreas Kling  <awesomekling@apple.com>
 
+        Remove mapped vs non-mapped attribute distinction.
+        <http://webkit.org/b/77827>
+
+        Reviewed by Antti Koivisto.
+
+        Removed the isMappedAttribute flag from Attribute as it no longer serves
+        a practical purpose. Previously, StyledElement would generate mapped
+        attributes and plain Element would generate non-mapped ones.
+
+        The distinction is now made much more clearly by dividing the work between
+        Element's and StyledElement's attributeChanged() methods. The only thing
+        that StyledElement wants to do in addition to what Element does is
+        calling parseMappedAttribute() (which we'll rename in a later patch.)
+
+        * dom/Attribute.cpp:
+        (WebCore::Attribute::clone):
+        * dom/Attribute.h:
+        (WebCore::Attribute::create):
+        (WebCore::Attribute::Attribute):
+        (Attribute):
+        * dom/Document.cpp:
+        (WebCore::Document::createAttributeNS):
+        * dom/Element.cpp:
+        (WebCore::Element::attributeChanged):
+        * dom/Element.h:
+        (Element):
+        * dom/Node.cpp:
+        (WebCore::Node::dumpStatistics):
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::attributeChanged):
+        (WebCore::StyledElement::parseMappedAttribute):
+        * dom/StyledElement.h:
+        (StyledElement):
+        * html/parser/HTMLConstructionSite.cpp:
+        (WebCore):
+        * html/parser/HTMLTreeBuilder.cpp:
+        (WebCore::HTMLTreeBuilder::attributesForIsindexInput):
+        * html/parser/TextDocumentParser.cpp:
+        (WebCore::TextDocumentParser::insertFakePreElement):
+        * svg/SVGStyledElement.cpp:
+        (WebCore::SVGStyledElement::getPresentationAttribute):
+        * xml/parser/MarkupTokenBase.h:
+        (WebCore::::initializeAttributes):
+
+2012-02-05  Andreas Kling  <awesomekling@apple.com>
+
         Kill CSSMappedAttributeDeclaration.
         <http://webkit.org/b/77820>
 
index 9eabe58..5164560 100644 (file)
@@ -40,7 +40,7 @@ static AttributeAttrMap& attributeAttrMap()
 
 PassRefPtr<Attribute> Attribute::clone() const
 {
-    return adoptRef(new Attribute(m_name, m_value, m_isMappedAttribute));
+    return adoptRef(new Attribute(m_name, m_value));
 }
 
 Attr* Attribute::attr() const
index 6660989..2f7153d 100644 (file)
@@ -41,15 +41,11 @@ class Attribute : public RefCounted<Attribute> {
 public:
     static PassRefPtr<Attribute> create(const QualifiedName& name, const AtomicString& value)
     {
-        return adoptRef(new Attribute(name, value, false));
+        return adoptRef(new Attribute(name, value));
     }
-    static PassRefPtr<Attribute> createMapped(const QualifiedName& name, const AtomicString& value)
+    static PassRefPtr<Attribute> create(const AtomicString& name, const AtomicString& value)
     {
-        return adoptRef(new Attribute(name, value, true));
-    }
-    static PassRefPtr<Attribute> createMapped(const AtomicString& name, const AtomicString& value)
-    {
-        return adoptRef(new Attribute(name, value, true));
+        return adoptRef(new Attribute(name, value));
     }
 
     const AtomicString& value() const { return m_value; }
@@ -75,20 +71,16 @@ public:
     // elements may have placed the Attribute in a hash by name.
     void parserSetName(const QualifiedName& name) { m_name = name; }
 
-    bool isMappedAttribute() { return m_isMappedAttribute; }
-
 private:
-    Attribute(const QualifiedName& name, const AtomicString& value, bool isMappedAttribute)
-        : m_isMappedAttribute(isMappedAttribute)
-        , m_hasAttr(false)
+    Attribute(const QualifiedName& name, const AtomicString& value)
+        : m_hasAttr(false)
         , m_name(name)
         , m_value(value)
     {
     }
 
-    Attribute(const AtomicString& name, const AtomicString& value, bool isMappedAttribute)
-        : m_isMappedAttribute(isMappedAttribute)
-        , m_hasAttr(false)
+    Attribute(const AtomicString& name, const AtomicString& value)
+        : m_hasAttr(false)
         , m_name(nullAtom, name, nullAtom)
         , m_value(value)
     {
@@ -97,8 +89,7 @@ private:
     void bindAttr(Attr*);
     void unbindAttr(Attr*);
 
-    // These booleans will go into the spare 32-bits of padding from RefCounted in 64-bit.
-    bool m_isMappedAttribute;
+    // This boolean will go into the spare 32-bits of padding from RefCounted in 64-bit.
     bool m_hasAttr;
     
     QualifiedName m_name;
index edbbcdd..b1e8ac4 100644 (file)
@@ -4335,9 +4335,7 @@ PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const S
         return 0;
     }
 
-    // FIXME: Assume this is a mapped attribute, since createAttribute isn't namespace-aware.  There's no harm to XML
-    // documents if we're wrong.
-    return Attr::create(0, this, Attribute::createMapped(qName, StringImpl::empty()));
+    return Attr::create(0, this, Attribute::create(qName, StringImpl::empty()));
 }
 
 #if ENABLE(SVG)
index 99a6d82..f97b5e2 100644 (file)
@@ -659,6 +659,9 @@ void Element::attributeChanged(Attribute* attr)
 {
     if (isIdAttributeName(attr->name()))
         idAttributeChanged(attr);
+    else if (attr->name() == HTMLNames::nameAttr)
+        setHasName(!attr->isNull());
+
     recalcStyleIfNeededAfterAttributeChanged(attr);
     updateAfterAttributeChanged(attr);
 }
index 977949f..ac281c5 100644 (file)
@@ -383,6 +383,8 @@ public:
     
     PassRefPtr<RenderStyle> styleForRenderer();
 
+    PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
+
 protected:
     Element(const QualifiedName& tagName, Document* document, ConstructionType type)
         : ContainerNode(document, type)
@@ -422,8 +424,7 @@ private:
     virtual bool childTypeAllowed(NodeType) const;
 
     void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value);
-    virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
-    
+
 #ifndef NDEBUG
     virtual void formatForDebugger(char* buffer, unsigned length) const;
 #endif
index 738000f..4155c64 100644 (file)
@@ -159,8 +159,6 @@ void Node::dumpStatistics()
     HashMap<String, size_t> perTagCount;
 
     size_t attributes = 0;
-    size_t mappedAttributes = 0;
-    size_t mappedAttributesWithStyleDecl = 0;
     size_t attributesWithAttr = 0;
     size_t attrMaps = 0;
 
@@ -188,11 +186,6 @@ void Node::dumpStatistics()
                         Attribute* attr = attrMap->attributeItem(i);
                         if (attr->attr())
                             ++attributesWithAttr;
-                        if (attr->isMappedAttribute()) {
-                            ++mappedAttributes;
-                            if (attr->style())
-                                ++mappedAttributesWithStyleDecl;
-                        }
                     }
                 }
                 break;
@@ -277,8 +270,6 @@ void Node::dumpStatistics()
 
     printf("Attribute Maps:\n");
     printf("  Number of Attributes (non-Node and Node): %zu [%zu]\n", attributes, sizeof(Attribute));
-    printf("  Number of Attributes that are mapped: %zu\n", mappedAttributes);
-    printf("  Number of Attributes with a StyleDeclaration: %zu\n", mappedAttributesWithStyleDecl);
     printf("  Number of Attributes with an Attr: %zu\n", attributesWithAttr);
     printf("  Number of NamedNodeMaps: %zu [%zu]\n", attrMaps, sizeof(NamedNodeMap));
 #endif
index 04d47cc..9ec3a8a 100644 (file)
@@ -60,26 +60,12 @@ StyledElement::~StyledElement()
     destroyInlineStyleDecl();
 }
 
-PassRefPtr<Attribute> StyledElement::createAttribute(const QualifiedName& name, const AtomicString& value)
-{
-    return Attribute::createMapped(name, value);
-}
-
 void StyledElement::attributeChanged(Attribute* attr)
 {
-    if (attr->name() == HTMLNames::nameAttr)
-        setHasName(!attr->isNull());
-
-    if (!attr->isMappedAttribute()) {
-        Element::attributeChanged(attr);
-        return;
-    }
-
     if (!(attr->name() == styleAttr && isSynchronizingStyleAttribute()))
         parseMappedAttribute(attr);
 
-    recalcStyleIfNeededAfterAttributeChanged(attr);
-    updateAfterAttributeChanged(attr);
+    Element::attributeChanged(attr);
 }
 
 void StyledElement::classAttributeChanged(const AtomicString& newClassString)
@@ -106,9 +92,7 @@ void StyledElement::classAttributeChanged(const AtomicString& newClassString)
 
 void StyledElement::parseMappedAttribute(Attribute* attr)
 {
-    if (isIdAttributeName(attr->name()))
-        idAttributeChanged(attr);
-    else if (attr->name() == classAttr)
+    if (attr->name() == classAttr)
         classAttributeChanged(attr->value());
     else if (attr->name() == styleAttr) {
         if (attr->isNull())
index a36816d..03572c4 100644 (file)
@@ -59,8 +59,6 @@ public:
 
     const SpaceSplitString& classNames() const;
 
-    virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
-
 protected:
     StyledElement(const QualifiedName& name, Document* document, ConstructionType type)
         : Element(name, document, type)
index 0ee89f1..e551c2f 100644 (file)
@@ -432,7 +432,7 @@ inline PassOwnPtr<NamedNodeMap> cloneAttributes(Element* element)
     OwnPtr<NamedNodeMap> newAttributes = NamedNodeMap::create();
     for (size_t i = 0; i < attributes->length(); ++i) {
         Attribute* attribute = attributes->attributeItem(i);
-        RefPtr<Attribute> clone = Attribute::createMapped(attribute->name(), attribute->value());
+        RefPtr<Attribute> clone = Attribute::create(attribute->name(), attribute->value());
         newAttributes->addAttribute(clone);
     }
     return newAttributes.release();
index 09e0a8e..140ad0c 100644 (file)
@@ -571,7 +571,7 @@ PassOwnPtr<NamedNodeMap> HTMLTreeBuilder::attributesForIsindexInput(AtomicHTMLTo
         attributes->removeAttribute(promptAttr);
     }
 
-    RefPtr<Attribute> mappedAttribute = Attribute::createMapped(nameAttr, isindexTag.localName());
+    RefPtr<Attribute> mappedAttribute = Attribute::create(nameAttr, isindexTag.localName());
     attributes->insertAttribute(mappedAttribute.release(), false);
     return attributes.release();
 }
index 1c55fc2..f4601de 100644 (file)
@@ -60,7 +60,7 @@ void TextDocumentParser::insertFakePreElement()
     // sending fake bytes through the front-end of the parser to avoid
     // distrubing the line/column number calculations.
 
-    RefPtr<Attribute> styleAttribute = Attribute::createMapped("style", "word-wrap: break-word; white-space: pre-wrap;");
+    RefPtr<Attribute> styleAttribute = Attribute::create("style", "word-wrap: break-word; white-space: pre-wrap;");
     OwnPtr<NamedNodeMap> attributes = NamedNodeMap::create();
     attributes->insertAttribute(styleAttribute.release(), false);
     AtomicHTMLToken fakePre(HTMLTokenTypes::StartTag, preTag.localName(), attributes.release());
index 719d264..5a1f7f6 100644 (file)
@@ -411,7 +411,7 @@ PassRefPtr<CSSValue> SVGStyledElement::getPresentationAttribute(const String& na
 
     QualifiedName attributeName(nullAtom, name, nullAtom);
     Attribute* attr = attributeMap()->getAttributeItem(attributeName);
-    if (!attr || !attr->isMappedAttribute())
+    if (!attr)
         return 0;
 
     RefPtr<StylePropertySet> style = StylePropertySet::create();
index 0e91913..7a30ed6 100644 (file)
@@ -541,7 +541,7 @@ inline void AtomicMarkupTokenBase<Token>::initializeAttributes(const typename To
         ASSERT(attribute.m_valueRange.m_end);
 
         String value(attribute.m_value.data(), attribute.m_value.size());
-        m_attributes->insertAttribute(Attribute::createMapped(nameForAttribute(attribute), value), false);
+        m_attributes->insertAttribute(Attribute::create(nameForAttribute(attribute), value), false);
     }
 }