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

Unified Diff: Source/core/dom/Attr.cpp

Issue 316583002: Correctly handle accessing a replaced Attr object's attribute value. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add setAttributeNode() FIXME Created 6 years, 6 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/Attr.h ('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/Attr.cpp
diff --git a/Source/core/dom/Attr.cpp b/Source/core/dom/Attr.cpp
index d25ebeae29043ade7c71270ffa21eb1bffd7d6e8..7272ef709a93a04c5667ef55225d6f072f8a2261 100644
--- a/Source/core/dom/Attr.cpp
+++ b/Source/core/dom/Attr.cpp
@@ -49,7 +49,7 @@ Attr::Attr(Document& document, const QualifiedName& name, const AtomicString& st
: ContainerNode(&document)
, m_element(nullptr)
, m_name(name)
- , m_standaloneValue(standaloneValue)
+ , m_standaloneValueOrAttachedLocalName(standaloneValue)
, m_ignoreChildrenChanged(0)
{
ScriptWrappable::init(this);
@@ -73,6 +73,19 @@ Attr::~Attr()
{
}
+const QualifiedName Attr::qualifiedName() const
+{
+ if (m_element && !m_standaloneValueOrAttachedLocalName.isNull()) {
+ // In the unlikely case the Element attribute has a local name
+ // that differs by case, construct the qualified name based on
+ // it. This is the qualified name that must be used when
+ // looking up the attribute on the element.
+ return QualifiedName(m_name.prefix(), m_standaloneValueOrAttachedLocalName, m_name.namespaceURI());
+ }
+
+ return m_name;
+}
+
void Attr::createTextChild()
{
#if !ENABLE(OILPAN)
@@ -98,11 +111,12 @@ void Attr::setValue(const AtomicString& value)
if (m_element)
elementAttribute().setValue(value);
else
- m_standaloneValue = value;
+ m_standaloneValueOrAttachedLocalName = value;
createTextChild();
m_ignoreChildrenChanged--;
- invalidateNodeListCachesInAncestors(&m_name, m_element);
+ QualifiedName name = qualifiedName();
+ invalidateNodeListCachesInAncestors(&name, m_element);
}
void Attr::setValueInternal(const AtomicString& value)
@@ -139,7 +153,7 @@ void Attr::setNodeValue(const String& v)
PassRefPtrWillBeRawPtr<Node> Attr::cloneNode(bool /*deep*/)
{
- RefPtrWillBeRawPtr<Attr> clone = adoptRefWillBeRefCountedGarbageCollected(new Attr(document(), qualifiedName(), value()));
+ RefPtrWillBeRawPtr<Attr> clone = adoptRefWillBeRefCountedGarbageCollected(new Attr(document(), m_name, value()));
cloneChildNodes(clone.get());
return clone.release();
}
@@ -155,7 +169,8 @@ void Attr::childrenChanged(bool, Node*, Node*, int)
if (m_ignoreChildrenChanged > 0)
return;
- invalidateNodeListCachesInAncestors(&qualifiedName(), m_element);
+ QualifiedName name = qualifiedName();
+ invalidateNodeListCachesInAncestors(&name, m_element);
StringBuilder valueBuilder;
for (Node *n = firstChild(); n; n = n->nextSibling()) {
@@ -170,7 +185,7 @@ void Attr::childrenChanged(bool, Node*, Node*, int)
if (m_element)
elementAttribute().setValue(newValue);
else
- m_standaloneValue = newValue;
+ m_standaloneValueOrAttachedLocalName = newValue;
if (m_element)
m_element->attributeChanged(qualifiedName(), newValue);
@@ -180,7 +195,7 @@ const AtomicString& Attr::value() const
{
if (m_element)
return m_element->getAttribute(qualifiedName());
- return m_standaloneValue;
+ return m_standaloneValueOrAttachedLocalName;
}
Attribute& Attr::elementAttribute()
@@ -193,16 +208,15 @@ Attribute& Attr::elementAttribute()
void Attr::detachFromElementWithValue(const AtomicString& value)
{
ASSERT(m_element);
- ASSERT(m_standaloneValue.isNull());
- m_standaloneValue = value;
+ m_standaloneValueOrAttachedLocalName = value;
m_element = nullptr;
}
-void Attr::attachToElement(Element* element)
+void Attr::attachToElement(Element* element, const AtomicString& attachedLocalName)
{
ASSERT(!m_element);
m_element = element;
- m_standaloneValue = nullAtom;
+ m_standaloneValueOrAttachedLocalName = attachedLocalName;
}
void Attr::trace(Visitor* visitor)
« no previous file with comments | « Source/core/dom/Attr.h ('k') | Source/core/dom/Element.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698