Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Unified Diff: Source/core/dom/Element.h

Issue 436603003: Make Element::attributes() less error-prone and simplify call sites (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take feedback into consideration Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/DatasetDOMStringMap.cpp ('k') | Source/core/dom/Element.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Element.h
diff --git a/Source/core/dom/Element.h b/Source/core/dom/Element.h
index 241698f723912cca3b6e56c9c4d27b3d77bb786b..8b7f5f42fc6df832c1823d1bc48d5108ab3e9d26 100644
--- a/Source/core/dom/Element.h
+++ b/Source/core/dom/Element.h
@@ -139,9 +139,6 @@ public:
bool hasNamedNodeMap() const;
#endif
bool hasAttributes() const;
- // This variant will not update the potentially invalid attributes. To be used when not interested
- // in style attribute or one of the SVG animation attributes.
- bool hasAttributesWithoutUpdate() const;
bool hasAttribute(const AtomicString& name) const;
bool hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
@@ -167,10 +164,14 @@ public:
// so this function is not suitable for non-style uses.
const AtomicString& idForStyleResolution() const;
- // Internal method that assumes the existence of attribute storage, one should use hasAttributes()
- // before calling it. This is not a trivial getter and its return value should be cached for
- // performance.
+ // This getter takes care of synchronizing all attributes before returning the
+ // AttributeCollection. If the Element has no attributes, an empty AttributeCollection
+ // will be returned. This is not a trivial getter and its return value should be cached
+ // for performance.
AttributeCollection attributes() const;
+ // This variant will not update the potentially invalid attributes. To be used when not interested
+ // in style attribute or one of the SVG animation attributes.
+ AttributeCollection attributesWithoutUpdate() const;
void scrollIntoView(bool alignToTop = true);
void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
@@ -691,14 +692,14 @@ inline Element* Node::parentElement() const
inline bool Element::fastHasAttribute(const QualifiedName& name) const
{
ASSERT(fastAttributeLookupAllowed(name));
- return elementData() && attributes().findIndex(name) != kNotFound;
+ return elementData() && elementData()->attributes().findIndex(name) != kNotFound;
}
inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
{
ASSERT(fastAttributeLookupAllowed(name));
if (elementData()) {
- if (const Attribute* attribute = attributes().find(name))
+ if (const Attribute* attribute = elementData()->attributes().find(name))
return attribute->value();
}
return nullAtom;
@@ -706,13 +707,22 @@ inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name)
inline AttributeCollection Element::attributes() const
{
- ASSERT(elementData());
+ if (!elementData())
+ return AttributeCollection();
+ synchronizeAllAttributes();
+ return elementData()->attributes();
+}
+
+inline AttributeCollection Element::attributesWithoutUpdate() const
+{
+ if (!elementData())
+ return AttributeCollection();
return elementData()->attributes();
}
-inline bool Element::hasAttributesWithoutUpdate() const
+inline bool Element::hasAttributes() const
{
- return elementData() && !elementData()->attributes().isEmpty();
+ return !attributes().isEmpty();
}
inline const AtomicString& Element::idForStyleResolution() const
« no previous file with comments | « Source/core/dom/DatasetDOMStringMap.cpp ('k') | Source/core/dom/Element.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698