Changeset 62596 in webkit


Ignore:
Timestamp:
Jul 6, 2010 2:21:37 PM (14 years ago)
Author:
Darin Adler
Message:

2010-07-06 Darin Adler <Darin Adler>

Reviewed by Geoffrey Garen.

Simplify access to element attribute map, removing unneeded functions
https://bugs.webkit.org/show_bug.cgi?id=41703

  • css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::canShareStyleWithElement): Use the attributeMap function instead of the mappedAttributes function. (WebCore::CSSStyleSelector::styleForElement): Ditto.
  • dom/Element.cpp: (WebCore::Element::~Element): Renamed namedAttrMap to m_attributeMap. (WebCore::Element::removeAttribute): Ditto. (WebCore::Element::getAttribute): Ditto. (WebCore::Element::setAttribute): Ditto. (WebCore::Element::setAttributeMap): Ditto. (WebCore::Element::hasAttributes): Ditto. (WebCore::Element::createAttributeMap): Ditto. (WebCore::Element::insertedIntoDocument): Ditto. (WebCore::Element::removedFromDocument): Ditto. (WebCore::Element::getURLAttribute): Ditto.
  • dom/Element.h: Removed unneeded virtual attributes function. Made read-only argument to attributes function default to false. (Later, we'll eliminate this.) Renamed namedAttrMap to m_attributeMap and made it private instead of protected.
  • dom/StyledElement.cpp: (WebCore::StyledElement::attributeChanged): Use attributeMap function instead of namedAttrMap data member or mappedAttributes function. (WebCore::StyledElement::classAttributeChanged): Ditto. (WebCore::StyledElement::parseMappedAttribute): Ditto.
  • dom/StyledElement.h: Removed mappedAttributes function and changed callers to use attributeMap function instead.
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::setInputType): Use attributeMap instead of mappedAttributes.
  • svg/SVGStyledElement.cpp: (WebCore::SVGStyledElement::getPresentationAttribute): Ditto.
Location:
trunk/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r62594 r62596  
     12010-07-06  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Simplify access to element attribute map, removing unneeded functions
     6        https://bugs.webkit.org/show_bug.cgi?id=41703
     7
     8        * css/CSSStyleSelector.cpp:
     9        (WebCore::CSSStyleSelector::canShareStyleWithElement): Use the
     10        attributeMap function instead of the mappedAttributes function.
     11        (WebCore::CSSStyleSelector::styleForElement): Ditto.
     12
     13        * dom/Element.cpp:
     14        (WebCore::Element::~Element): Renamed namedAttrMap to m_attributeMap.
     15        (WebCore::Element::removeAttribute): Ditto.
     16        (WebCore::Element::getAttribute): Ditto.
     17        (WebCore::Element::setAttribute): Ditto.
     18        (WebCore::Element::setAttributeMap): Ditto.
     19        (WebCore::Element::hasAttributes): Ditto.
     20        (WebCore::Element::createAttributeMap): Ditto.
     21        (WebCore::Element::insertedIntoDocument): Ditto.
     22        (WebCore::Element::removedFromDocument): Ditto.
     23        (WebCore::Element::getURLAttribute): Ditto.
     24
     25        * dom/Element.h: Removed unneeded virtual attributes function.
     26        Made read-only argument to attributes function default to false.
     27        (Later, we'll eliminate this.) Renamed namedAttrMap to m_attributeMap
     28        and made it private instead of protected.
     29
     30        * dom/StyledElement.cpp:
     31        (WebCore::StyledElement::attributeChanged): Use attributeMap function
     32        instead of namedAttrMap data member or mappedAttributes function.
     33        (WebCore::StyledElement::classAttributeChanged): Ditto.
     34        (WebCore::StyledElement::parseMappedAttribute): Ditto.
     35
     36        * dom/StyledElement.h: Removed mappedAttributes function and changed
     37        callers to use attributeMap function instead.
     38
     39        * html/HTMLInputElement.cpp:
     40        (WebCore::HTMLInputElement::setInputType): Use attributeMap instead of
     41        mappedAttributes.
     42        * svg/SVGStyledElement.cpp:
     43        (WebCore::SVGStyledElement::getPresentationAttribute): Ditto.
     44
    1452010-07-06  Anders Carlsson  <andersca@apple.com>
    246
  • trunk/WebCore/css/CSSStyleSelector.cpp

    r62513 r62596  
    10391039                bool mappedAttrsMatch = true;
    10401040                if (s->hasMappedAttributes())
    1041                     mappedAttrsMatch = s->mappedAttributes()->mappedMapsEquivalent(m_styledElement->mappedAttributes());
     1041                    mappedAttrsMatch = s->attributeMap()->mappedMapsEquivalent(m_styledElement->attributeMap());
    10421042                if (mappedAttrsMatch) {
    10431043                    if (s->isLink()) {
     
    12591259            if (m_styledElement->hasMappedAttributes()) {
    12601260                // Walk our attribute list and add in each decl.
    1261                 const NamedNodeMap* map = m_styledElement->mappedAttributes();
     1261                const NamedNodeMap* map = m_styledElement->attributeMap();
    12621262                for (unsigned i = 0; i < map->length(); i++) {
    12631263                    Attribute* attr = map->attributeItem(i);
  • trunk/WebCore/dom/Element.cpp

    r62484 r62596  
    7171Element::~Element()
    7272{
    73     if (namedAttrMap)
    74         namedAttrMap->detachFromElement();
     73    if (m_attributeMap)
     74        m_attributeMap->detachFromElement();
    7575}
    7676
     
    166166void Element::removeAttribute(const QualifiedName& name, ExceptionCode& ec)
    167167{
    168     if (namedAttrMap) {
     168    if (m_attributeMap) {
    169169        ec = 0;
    170         namedAttrMap->removeNamedItem(name, ec);
     170        m_attributeMap->removeNamedItem(name, ec);
    171171        if (ec == NOT_FOUND_ERR)
    172172            ec = 0;
     
    194194        removeAttribute(name, ex);
    195195    }
    196 }
    197 
    198 // Virtual function, defined in base class.
    199 NamedNodeMap* Element::attributes() const
    200 {
    201     return attributes(false);
    202196}
    203197
     
    527521#endif
    528522
    529     if (namedAttrMap) {
    530         if (Attribute* attribute = namedAttrMap->getAttributeItem(name, ignoreCase))
     523    if (m_attributeMap) {
     524        if (Attribute* attribute = m_attributeMap->getAttributeItem(name, ignoreCase))
    531525            return attribute->value();
    532526    }
     
    561555
    562556    if (old && value.isNull())
    563         namedAttrMap->removeAttribute(old->name());
     557        m_attributeMap->removeAttribute(old->name());
    564558    else if (!old && !value.isNull())
    565         namedAttrMap->addAttribute(createAttribute(QualifiedName(nullAtom, localName, nullAtom), value));
     559        m_attributeMap->addAttribute(createAttribute(QualifiedName(nullAtom, localName, nullAtom), value));
    566560    else if (old && !value.isNull()) {
    567561        old->setValue(value);
     
    590584
    591585    if (old && value.isNull())
    592         namedAttrMap->removeAttribute(name);
     586        m_attributeMap->removeAttribute(name);
    593587    else if (!old && !value.isNull())
    594         namedAttrMap->addAttribute(createAttribute(name, value));
     588        m_attributeMap->addAttribute(createAttribute(name, value));
    595589    else if (old) {
    596590        old->setValue(value);
     
    671665
    672666    const QualifiedName& idName = document()->idAttributeName();
    673     Attribute* oldId = namedAttrMap ? namedAttrMap->getAttributeItem(idName) : 0;
     667    Attribute* oldId = m_attributeMap ? m_attributeMap->getAttributeItem(idName) : 0;
    674668    Attribute* newId = list ? list->getAttributeItem(idName) : 0;
    675669
     
    677671        updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom);
    678672
    679     if (namedAttrMap)
    680         namedAttrMap->m_element = 0;
    681 
    682     namedAttrMap = list;
    683 
    684     if (namedAttrMap) {
    685         namedAttrMap->m_element = this;
     673    if (m_attributeMap)
     674        m_attributeMap->m_element = 0;
     675
     676    m_attributeMap = list;
     677
     678    if (m_attributeMap) {
     679        m_attributeMap->m_element = this;
    686680        // If the element is created as result of a paste or drag-n-drop operation
    687681        // we want to remove all the script and event handlers.
    688682        if (scriptingPermission == FragmentScriptingNotAllowed) {
    689683            unsigned i = 0;
    690             while (i < namedAttrMap->length()) {
    691                 const QualifiedName& attributeName = namedAttrMap->m_attributes[i]->name();
     684            while (i < m_attributeMap->length()) {
     685                const QualifiedName& attributeName = m_attributeMap->m_attributes[i]->name();
    692686                if (isEventHandlerAttribute(attributeName)) {
    693                     namedAttrMap->m_attributes.remove(i);
     687                    m_attributeMap->m_attributes.remove(i);
    694688                    continue;
    695689                }
    696690
    697                 if (isAttributeToRemove(attributeName, namedAttrMap->m_attributes[i]->value()))
    698                     namedAttrMap->m_attributes[i]->setValue(nullAtom);
     691                if (isAttributeToRemove(attributeName, m_attributeMap->m_attributes[i]->value()))
     692                    m_attributeMap->m_attributes[i]->setValue(nullAtom);
    699693                i++;
    700694            }
    701695        }
    702         unsigned len = namedAttrMap->length();
     696        unsigned len = m_attributeMap->length();
    703697        for (unsigned i = 0; i < len; i++)
    704             attributeChanged(namedAttrMap->m_attributes[i].get());
     698            attributeChanged(m_attributeMap->m_attributes[i].get());
    705699        // FIXME: What about attributes that were in the old map that are not in the new map?
    706700    }
     
    717711#endif
    718712
    719     return namedAttrMap && namedAttrMap->length() > 0;
     713    return m_attributeMap && m_attributeMap->length();
    720714}
    721715
     
    760754void Element::createAttributeMap() const
    761755{
    762     namedAttrMap = NamedNodeMap::create(const_cast<Element*>(this));
     756    m_attributeMap = NamedNodeMap::create(const_cast<Element*>(this));
    763757}
    764758
     
    793787
    794788    if (hasID()) {
    795         if (NamedNodeMap* attrs = namedAttrMap.get()) {
    796             Attribute* idItem = attrs->getAttributeItem(document()->idAttributeName());
     789        if (m_attributeMap) {
     790            Attribute* idItem = m_attributeMap->getAttributeItem(document()->idAttributeName());
    797791            if (idItem && !idItem->isNull())
    798792                updateId(nullAtom, idItem->value());
     
    804798{
    805799    if (hasID()) {
    806         if (NamedNodeMap* attrs = namedAttrMap.get()) {
    807             Attribute* idItem = attrs->getAttributeItem(document()->idAttributeName());
     800        if (m_attributeMap) {
     801            Attribute* idItem = m_attributeMap->getAttributeItem(document()->idAttributeName());
    808802            if (idItem && !idItem->isNull())
    809803                updateId(idItem->value(), nullAtom);
     
    12321226    String localName = shouldIgnoreAttributeCase(this) ? name.lower() : name;
    12331227
    1234     if (namedAttrMap) {
    1235         namedAttrMap->removeNamedItem(localName, ec);
     1228    if (m_attributeMap) {
     1229        m_attributeMap->removeNamedItem(localName, ec);
    12361230        if (ec == NOT_FOUND_ERR)
    12371231            ec = 0;
     
    15331527{
    15341528#if !ASSERT_DISABLED
    1535     if (namedAttrMap) {
    1536         if (Attribute* attribute = namedAttrMap->getAttributeItem(name))
     1529    if (m_attributeMap) {
     1530        if (Attribute* attribute = m_attributeMap->getAttributeItem(name))
    15371531            ASSERT(isURLAttribute(attribute));
    15381532    }
  • trunk/WebCore/dom/Element.h

    r62215 r62596  
    199199    void setCStringAttribute(const QualifiedName&, const char* cStringValue);
    200200
    201     virtual NamedNodeMap* attributes() const;
    202     NamedNodeMap* attributes(bool readonly) const;
     201    NamedNodeMap* attributes(bool readonly = false) const;
    203202
    204203    // This method is called whenever an attribute is added, changed or removed.
    205204    virtual void attributeChanged(Attribute*, bool preserveDecls = false);
    206205
    207     // not part of the DOM
    208206    void setAttributeMap(PassRefPtr<NamedNodeMap>, FragmentScriptingPermission = FragmentScriptingAllowed);
    209     NamedNodeMap* attributeMap() const { return namedAttrMap.get(); }
     207    NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
    210208
    211209    virtual void copyNonAttributeProperties(const Element* /*source*/) { }
     
    349347    ElementRareData* ensureRareData();
    350348   
    351 protected:
    352     mutable RefPtr<NamedNodeMap> namedAttrMap;
     349private:
     350    mutable RefPtr<NamedNodeMap> m_attributeMap;
    353351};
    354352   
     
    384382#endif
    385383
    386     if (!readonly && !namedAttrMap)
     384    if (!readonly && !m_attributeMap)
    387385        createAttributeMap();
    388     return namedAttrMap.get();
     386    return m_attributeMap.get();
    389387}
    390388
     
    406404inline bool Element::fastHasAttribute(const QualifiedName& name) const
    407405{
    408     return namedAttrMap && namedAttrMap->getAttributeItem(name);
     406    return m_attributeMap && m_attributeMap->getAttributeItem(name);
    409407}
    410408
    411409inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
    412410{
    413     if (namedAttrMap) {
    414         if (Attribute* attribute = namedAttrMap->getAttributeItem(name))
     411    if (m_attributeMap) {
     412        if (Attribute* attribute = m_attributeMap->getAttributeItem(name))
    415413            return attribute->value();
    416414    }
     
    421419{
    422420    ASSERT(hasID());
    423     return namedAttrMap->idForStyleResolution();
     421    return m_attributeMap->idForStyleResolution();
    424422}
    425423
  • trunk/WebCore/dom/StyledElement.cpp

    r62514 r62596  
    149149        attr->setDecl(0);
    150150        setNeedsStyleRecalc();
    151         if (namedAttrMap)
    152             mappedAttributes()->declRemoved();
     151        if (attributeMap())
     152            attributeMap()->declRemoved();
    153153    }
    154154
     
    159159        if (attr->decl()) {
    160160            setNeedsStyleRecalc();
    161             if (namedAttrMap)
    162                 mappedAttributes()->declAdded();
     161            if (attributeMap())
     162                attributeMap()->declAdded();
    163163            checkDecl = false;
    164164        }
     
    168168            attr->setDecl(decl);
    169169            setNeedsStyleRecalc();
    170             if (namedAttrMap)
    171                 mappedAttributes()->declAdded();
     170            if (attributeMap())
     171                attributeMap()->declAdded();
    172172            checkDecl = false;
    173173        } else
     
    192192        attr->decl()->setParent(0);
    193193        attr->decl()->setNode(0);
    194         if (namedAttrMap)
    195             mappedAttributes()->declAdded();
     194        if (attributeMap())
     195            attributeMap()->declAdded();
    196196    }
    197197
     
    221221        attributes()->setClass(newClassString);
    222222    else {
    223         if (namedAttrMap)   
    224             namedAttrMap->clearClass();
     223        if (attributeMap())   
     224            attributeMap()->clearClass();
    225225    }
    226226    setNeedsStyleRecalc();
     
    232232    if (isIdAttributeName(attr->name())) {
    233233        setHasID(!attr->isNull());
    234         if (namedAttrMap) {
     234        if (attributeMap()) {
    235235            if (attr->isNull())
    236                 namedAttrMap->setIdForStyleResolution(nullAtom);
     236                attributeMap()->setIdForStyleResolution(nullAtom);
    237237            else if (document()->inCompatMode())
    238                 namedAttrMap->setIdForStyleResolution(attr->value().lower());
     238                attributeMap()->setIdForStyleResolution(attr->value().lower());
    239239            else
    240                 namedAttrMap->setIdForStyleResolution(attr->value());
     240                attributeMap()->setIdForStyleResolution(attr->value());
    241241        }
    242242        setNeedsStyleRecalc();
  • trunk/WebCore/dom/StyledElement.h

    r60052 r62596  
    44 *           (C) 2001 Peter Kelly (pmk@post.com)
    55 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    6  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
    77 *
    88 * This library is free software; you can redistribute it and/or
     
    2727
    2828#include "CSSMutableStyleDeclaration.h"
    29 #include "CSSPrimitiveValue.h"
    3029#include "Element.h"
    3130#include "MappedAttributeEntry.h"
    32 #include "NamedNodeMap.h"
    3331
    3432namespace WebCore {
     
    4139    virtual ~StyledElement();
    4240
    43     NamedNodeMap* mappedAttributes() { return namedAttrMap.get(); }
    44     const NamedNodeMap* mappedAttributes() const { return namedAttrMap.get(); }
    45 
    46     bool hasMappedAttributes() const { return namedAttrMap && mappedAttributes()->hasMappedAttributes(); }
     41    bool hasMappedAttributes() const { return attributeMap() && attributeMap()->hasMappedAttributes(); }
    4742    bool isMappedAttribute(const QualifiedName& name) const { MappedAttributeEntry res = eNone; mapToEntry(name, res); return res != eNone; }
    4843
     
    6257    CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
    6358    virtual bool canHaveAdditionalAttributeStyleDecls() const { return false; }
    64     virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) {};
     59    virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) { }
    6560    CSSMutableStyleDeclaration* getInlineStyleDecl();
    6661    CSSStyleDeclaration* style();
    6762    void invalidateStyleAttribute();
    6863
    69     const SpaceSplitString& classNames() const { ASSERT(hasClass()); ASSERT(mappedAttributes()); return mappedAttributes()->classNames(); }
     64    const SpaceSplitString& classNames() const;
    7065
    7166    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
     
    10297};
    10398
     99inline const SpaceSplitString& StyledElement::classNames() const
     100{
     101    ASSERT(hasClass());
     102    ASSERT(attributeMap());
     103    return attributeMap()->classNames();
     104}
     105
    104106inline void StyledElement::invalidateStyleAttribute()
    105107{
  • trunk/WebCore/html/HTMLInputElement.cpp

    r61963 r62596  
    865865
    866866            if (didRespectHeightAndWidth != willRespectHeightAndWidth) {
    867                 NamedNodeMap* map = mappedAttributes();
     867                NamedNodeMap* map = attributeMap();
    868868                ASSERT(map);
    869869                if (Attribute* height = map->getAttributeItem(heightAttr))
  • trunk/WebCore/svg/SVGStyledElement.cpp

    r62531 r62596  
    326326PassRefPtr<CSSValue> SVGStyledElement::getPresentationAttribute(const String& name)
    327327{
    328     if (!mappedAttributes())
     328    if (!attributeMap())
    329329        return 0;
    330330
    331331    QualifiedName attributeName(nullAtom, name, nullAtom);
    332     Attribute* attr = mappedAttributes()->getAttributeItem(attributeName);
     332    Attribute* attr = attributeMap()->getAttributeItem(attributeName);
    333333    if (!attr || !attr->isMappedAttribute() || !attr->style())
    334334        return 0;
Note: See TracChangeset for help on using the changeset viewer.