Changeset 62596 in webkit
- Timestamp:
- Jul 6, 2010 2:21:37 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r62594 r62596 1 2010-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 1 45 2010-07-06 Anders Carlsson <andersca@apple.com> 2 46 -
trunk/WebCore/css/CSSStyleSelector.cpp
r62513 r62596 1039 1039 bool mappedAttrsMatch = true; 1040 1040 if (s->hasMappedAttributes()) 1041 mappedAttrsMatch = s-> mappedAttributes()->mappedMapsEquivalent(m_styledElement->mappedAttributes());1041 mappedAttrsMatch = s->attributeMap()->mappedMapsEquivalent(m_styledElement->attributeMap()); 1042 1042 if (mappedAttrsMatch) { 1043 1043 if (s->isLink()) { … … 1259 1259 if (m_styledElement->hasMappedAttributes()) { 1260 1260 // Walk our attribute list and add in each decl. 1261 const NamedNodeMap* map = m_styledElement-> mappedAttributes();1261 const NamedNodeMap* map = m_styledElement->attributeMap(); 1262 1262 for (unsigned i = 0; i < map->length(); i++) { 1263 1263 Attribute* attr = map->attributeItem(i); -
trunk/WebCore/dom/Element.cpp
r62484 r62596 71 71 Element::~Element() 72 72 { 73 if ( namedAttrMap)74 namedAttrMap->detachFromElement();73 if (m_attributeMap) 74 m_attributeMap->detachFromElement(); 75 75 } 76 76 … … 166 166 void Element::removeAttribute(const QualifiedName& name, ExceptionCode& ec) 167 167 { 168 if ( namedAttrMap) {168 if (m_attributeMap) { 169 169 ec = 0; 170 namedAttrMap->removeNamedItem(name, ec);170 m_attributeMap->removeNamedItem(name, ec); 171 171 if (ec == NOT_FOUND_ERR) 172 172 ec = 0; … … 194 194 removeAttribute(name, ex); 195 195 } 196 }197 198 // Virtual function, defined in base class.199 NamedNodeMap* Element::attributes() const200 {201 return attributes(false);202 196 } 203 197 … … 527 521 #endif 528 522 529 if ( namedAttrMap) {530 if (Attribute* attribute = namedAttrMap->getAttributeItem(name, ignoreCase))523 if (m_attributeMap) { 524 if (Attribute* attribute = m_attributeMap->getAttributeItem(name, ignoreCase)) 531 525 return attribute->value(); 532 526 } … … 561 555 562 556 if (old && value.isNull()) 563 namedAttrMap->removeAttribute(old->name());557 m_attributeMap->removeAttribute(old->name()); 564 558 else if (!old && !value.isNull()) 565 namedAttrMap->addAttribute(createAttribute(QualifiedName(nullAtom, localName, nullAtom), value));559 m_attributeMap->addAttribute(createAttribute(QualifiedName(nullAtom, localName, nullAtom), value)); 566 560 else if (old && !value.isNull()) { 567 561 old->setValue(value); … … 590 584 591 585 if (old && value.isNull()) 592 namedAttrMap->removeAttribute(name);586 m_attributeMap->removeAttribute(name); 593 587 else if (!old && !value.isNull()) 594 namedAttrMap->addAttribute(createAttribute(name, value));588 m_attributeMap->addAttribute(createAttribute(name, value)); 595 589 else if (old) { 596 590 old->setValue(value); … … 671 665 672 666 const QualifiedName& idName = document()->idAttributeName(); 673 Attribute* oldId = namedAttrMap ? namedAttrMap->getAttributeItem(idName) : 0;667 Attribute* oldId = m_attributeMap ? m_attributeMap->getAttributeItem(idName) : 0; 674 668 Attribute* newId = list ? list->getAttributeItem(idName) : 0; 675 669 … … 677 671 updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom); 678 672 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; 686 680 // If the element is created as result of a paste or drag-n-drop operation 687 681 // we want to remove all the script and event handlers. 688 682 if (scriptingPermission == FragmentScriptingNotAllowed) { 689 683 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(); 692 686 if (isEventHandlerAttribute(attributeName)) { 693 namedAttrMap->m_attributes.remove(i);687 m_attributeMap->m_attributes.remove(i); 694 688 continue; 695 689 } 696 690 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); 699 693 i++; 700 694 } 701 695 } 702 unsigned len = namedAttrMap->length();696 unsigned len = m_attributeMap->length(); 703 697 for (unsigned i = 0; i < len; i++) 704 attributeChanged( namedAttrMap->m_attributes[i].get());698 attributeChanged(m_attributeMap->m_attributes[i].get()); 705 699 // FIXME: What about attributes that were in the old map that are not in the new map? 706 700 } … … 717 711 #endif 718 712 719 return namedAttrMap && namedAttrMap->length() > 0;713 return m_attributeMap && m_attributeMap->length(); 720 714 } 721 715 … … 760 754 void Element::createAttributeMap() const 761 755 { 762 namedAttrMap = NamedNodeMap::create(const_cast<Element*>(this));756 m_attributeMap = NamedNodeMap::create(const_cast<Element*>(this)); 763 757 } 764 758 … … 793 787 794 788 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()); 797 791 if (idItem && !idItem->isNull()) 798 792 updateId(nullAtom, idItem->value()); … … 804 798 { 805 799 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()); 808 802 if (idItem && !idItem->isNull()) 809 803 updateId(idItem->value(), nullAtom); … … 1232 1226 String localName = shouldIgnoreAttributeCase(this) ? name.lower() : name; 1233 1227 1234 if ( namedAttrMap) {1235 namedAttrMap->removeNamedItem(localName, ec);1228 if (m_attributeMap) { 1229 m_attributeMap->removeNamedItem(localName, ec); 1236 1230 if (ec == NOT_FOUND_ERR) 1237 1231 ec = 0; … … 1533 1527 { 1534 1528 #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)) 1537 1531 ASSERT(isURLAttribute(attribute)); 1538 1532 } -
trunk/WebCore/dom/Element.h
r62215 r62596 199 199 void setCStringAttribute(const QualifiedName&, const char* cStringValue); 200 200 201 virtual NamedNodeMap* attributes() const; 202 NamedNodeMap* attributes(bool readonly) const; 201 NamedNodeMap* attributes(bool readonly = false) const; 203 202 204 203 // This method is called whenever an attribute is added, changed or removed. 205 204 virtual void attributeChanged(Attribute*, bool preserveDecls = false); 206 205 207 // not part of the DOM208 206 void setAttributeMap(PassRefPtr<NamedNodeMap>, FragmentScriptingPermission = FragmentScriptingAllowed); 209 NamedNodeMap* attributeMap() const { return namedAttrMap.get(); }207 NamedNodeMap* attributeMap() const { return m_attributeMap.get(); } 210 208 211 209 virtual void copyNonAttributeProperties(const Element* /*source*/) { } … … 349 347 ElementRareData* ensureRareData(); 350 348 351 pr otected:352 mutable RefPtr<NamedNodeMap> namedAttrMap;349 private: 350 mutable RefPtr<NamedNodeMap> m_attributeMap; 353 351 }; 354 352 … … 384 382 #endif 385 383 386 if (!readonly && ! namedAttrMap)384 if (!readonly && !m_attributeMap) 387 385 createAttributeMap(); 388 return namedAttrMap.get();386 return m_attributeMap.get(); 389 387 } 390 388 … … 406 404 inline bool Element::fastHasAttribute(const QualifiedName& name) const 407 405 { 408 return namedAttrMap && namedAttrMap->getAttributeItem(name);406 return m_attributeMap && m_attributeMap->getAttributeItem(name); 409 407 } 410 408 411 409 inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const 412 410 { 413 if ( namedAttrMap) {414 if (Attribute* attribute = namedAttrMap->getAttributeItem(name))411 if (m_attributeMap) { 412 if (Attribute* attribute = m_attributeMap->getAttributeItem(name)) 415 413 return attribute->value(); 416 414 } … … 421 419 { 422 420 ASSERT(hasID()); 423 return namedAttrMap->idForStyleResolution();421 return m_attributeMap->idForStyleResolution(); 424 422 } 425 423 -
trunk/WebCore/dom/StyledElement.cpp
r62514 r62596 149 149 attr->setDecl(0); 150 150 setNeedsStyleRecalc(); 151 if ( namedAttrMap)152 mappedAttributes()->declRemoved();151 if (attributeMap()) 152 attributeMap()->declRemoved(); 153 153 } 154 154 … … 159 159 if (attr->decl()) { 160 160 setNeedsStyleRecalc(); 161 if ( namedAttrMap)162 mappedAttributes()->declAdded();161 if (attributeMap()) 162 attributeMap()->declAdded(); 163 163 checkDecl = false; 164 164 } … … 168 168 attr->setDecl(decl); 169 169 setNeedsStyleRecalc(); 170 if ( namedAttrMap)171 mappedAttributes()->declAdded();170 if (attributeMap()) 171 attributeMap()->declAdded(); 172 172 checkDecl = false; 173 173 } else … … 192 192 attr->decl()->setParent(0); 193 193 attr->decl()->setNode(0); 194 if ( namedAttrMap)195 mappedAttributes()->declAdded();194 if (attributeMap()) 195 attributeMap()->declAdded(); 196 196 } 197 197 … … 221 221 attributes()->setClass(newClassString); 222 222 else { 223 if ( namedAttrMap)224 namedAttrMap->clearClass();223 if (attributeMap()) 224 attributeMap()->clearClass(); 225 225 } 226 226 setNeedsStyleRecalc(); … … 232 232 if (isIdAttributeName(attr->name())) { 233 233 setHasID(!attr->isNull()); 234 if ( namedAttrMap) {234 if (attributeMap()) { 235 235 if (attr->isNull()) 236 namedAttrMap->setIdForStyleResolution(nullAtom);236 attributeMap()->setIdForStyleResolution(nullAtom); 237 237 else if (document()->inCompatMode()) 238 namedAttrMap->setIdForStyleResolution(attr->value().lower());238 attributeMap()->setIdForStyleResolution(attr->value().lower()); 239 239 else 240 namedAttrMap->setIdForStyleResolution(attr->value());240 attributeMap()->setIdForStyleResolution(attr->value()); 241 241 } 242 242 setNeedsStyleRecalc(); -
trunk/WebCore/dom/StyledElement.h
r60052 r62596 4 4 * (C) 2001 Peter Kelly (pmk@post.com) 5 5 * (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. 7 7 * 8 8 * This library is free software; you can redistribute it and/or … … 27 27 28 28 #include "CSSMutableStyleDeclaration.h" 29 #include "CSSPrimitiveValue.h"30 29 #include "Element.h" 31 30 #include "MappedAttributeEntry.h" 32 #include "NamedNodeMap.h"33 31 34 32 namespace WebCore { … … 41 39 virtual ~StyledElement(); 42 40 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(); } 47 42 bool isMappedAttribute(const QualifiedName& name) const { MappedAttributeEntry res = eNone; mapToEntry(name, res); return res != eNone; } 48 43 … … 62 57 CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); } 63 58 virtual bool canHaveAdditionalAttributeStyleDecls() const { return false; } 64 virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) { };59 virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) { } 65 60 CSSMutableStyleDeclaration* getInlineStyleDecl(); 66 61 CSSStyleDeclaration* style(); 67 62 void invalidateStyleAttribute(); 68 63 69 const SpaceSplitString& classNames() const { ASSERT(hasClass()); ASSERT(mappedAttributes()); return mappedAttributes()->classNames(); }64 const SpaceSplitString& classNames() const; 70 65 71 66 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; … … 102 97 }; 103 98 99 inline const SpaceSplitString& StyledElement::classNames() const 100 { 101 ASSERT(hasClass()); 102 ASSERT(attributeMap()); 103 return attributeMap()->classNames(); 104 } 105 104 106 inline void StyledElement::invalidateStyleAttribute() 105 107 { -
trunk/WebCore/html/HTMLInputElement.cpp
r61963 r62596 865 865 866 866 if (didRespectHeightAndWidth != willRespectHeightAndWidth) { 867 NamedNodeMap* map = mappedAttributes();867 NamedNodeMap* map = attributeMap(); 868 868 ASSERT(map); 869 869 if (Attribute* height = map->getAttributeItem(heightAttr)) -
trunk/WebCore/svg/SVGStyledElement.cpp
r62531 r62596 326 326 PassRefPtr<CSSValue> SVGStyledElement::getPresentationAttribute(const String& name) 327 327 { 328 if (! mappedAttributes())328 if (!attributeMap()) 329 329 return 0; 330 330 331 331 QualifiedName attributeName(nullAtom, name, nullAtom); 332 Attribute* attr = mappedAttributes()->getAttributeItem(attributeName);332 Attribute* attr = attributeMap()->getAttributeItem(attributeName); 333 333 if (!attr || !attr->isMappedAttribute() || !attr->style()) 334 334 return 0;
Note: See TracChangeset
for help on using the changeset viewer.