summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/Attr.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/Attr.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/dom/Attr.cpp')
-rw-r--r--Source/WebCore/dom/Attr.cpp107
1 files changed, 48 insertions, 59 deletions
diff --git a/Source/WebCore/dom/Attr.cpp b/Source/WebCore/dom/Attr.cpp
index ea9f35716..392f34220 100644
--- a/Source/WebCore/dom/Attr.cpp
+++ b/Source/WebCore/dom/Attr.cpp
@@ -23,7 +23,10 @@
#include "config.h"
#include "Attr.h"
+#include "AttributeChangeInvalidation.h"
+#include "Event.h"
#include "ExceptionCode.h"
+#include "NoEventDispatchAssertion.h"
#include "ScopedEventQueue.h"
#include "StyleProperties.h"
#include "StyledElement.h"
@@ -36,35 +39,32 @@ namespace WebCore {
using namespace HTMLNames;
-Attr::Attr(Element* element, const QualifiedName& name)
- : ContainerNode(&element->document())
- , m_element(element)
+Attr::Attr(Element& element, const QualifiedName& name)
+ : ContainerNode(element.document())
+ , m_element(&element)
, m_name(name)
- , m_ignoreChildrenChanged(0)
{
}
Attr::Attr(Document& document, const QualifiedName& name, const AtomicString& standaloneValue)
- : ContainerNode(&document)
- , m_element(0)
+ : ContainerNode(document)
, m_name(name)
, m_standaloneValue(standaloneValue)
- , m_ignoreChildrenChanged(0)
{
}
-PassRefPtr<Attr> Attr::create(Element* element, const QualifiedName& name)
+Ref<Attr> Attr::create(Element& element, const QualifiedName& name)
{
- RefPtr<Attr> attr = adoptRef(new Attr(element, name));
+ Ref<Attr> attr = adoptRef(*new Attr(element, name));
attr->createTextChild();
- return attr.release();
+ return attr;
}
-PassRefPtr<Attr> Attr::create(Document& document, const QualifiedName& name, const AtomicString& value)
+Ref<Attr> Attr::create(Document& document, const QualifiedName& name, const AtomicString& value)
{
- RefPtr<Attr> attr = adoptRef(new Attr(document, name, value));
+ Ref<Attr> attr = adoptRef(*new Attr(document, name, value));
attr->createTextChild();
- return attr.release();
+ return attr;
}
Attr::~Attr()
@@ -75,34 +75,31 @@ void Attr::createTextChild()
{
ASSERT(refCount());
if (!value().isEmpty()) {
- RefPtr<Text> textNode = document().createTextNode(value().string());
+ auto textNode = document().createTextNode(value().string());
// This does everything appendChild() would do in this situation (assuming m_ignoreChildrenChanged was set),
// but much more efficiently.
textNode->setParentNode(this);
- setFirstChild(textNode.get());
- setLastChild(textNode.get());
+ setFirstChild(textNode.ptr());
+ setLastChild(textNode.ptr());
}
}
-void Attr::setPrefix(const AtomicString& prefix, ExceptionCode& ec)
+ExceptionOr<void> Attr::setPrefix(const AtomicString& prefix)
{
- ec = 0;
- checkSetPrefix(prefix, ec);
- if (ec)
- return;
+ auto result = checkSetPrefix(prefix);
+ if (result.hasException())
+ return result.releaseException();
- if ((prefix == xmlnsAtom && namespaceURI() != XMLNSNames::xmlnsNamespaceURI)
- || static_cast<Attr*>(this)->qualifiedName() == xmlnsAtom) {
- ec = NAMESPACE_ERR;
- return;
- }
+ if ((prefix == xmlnsAtom && namespaceURI() != XMLNSNames::xmlnsNamespaceURI) || qualifiedName() == xmlnsAtom)
+ return Exception { NAMESPACE_ERR };
const AtomicString& newPrefix = prefix.isEmpty() ? nullAtom : prefix;
-
if (m_element)
elementAttribute().setPrefix(newPrefix);
m_name.setPrefix(newPrefix);
+
+ return { };
}
void Attr::setValue(const AtomicString& value)
@@ -110,9 +107,10 @@ void Attr::setValue(const AtomicString& value)
EventQueueScope scope;
m_ignoreChildrenChanged++;
removeChildren();
- if (m_element)
+ if (m_element) {
+ Style::AttributeChangeInvalidation styleInvalidation(*m_element, qualifiedName(), elementAttribute().value(), value);
elementAttribute().setValue(value);
- else
+ } else
m_standaloneValue = value;
createTextChild();
m_ignoreChildrenChanged--;
@@ -120,40 +118,33 @@ void Attr::setValue(const AtomicString& value)
invalidateNodeListAndCollectionCachesInAncestors(&m_name, m_element);
}
-void Attr::setValue(const AtomicString& value, ExceptionCode&)
+void Attr::setValueForBindings(const AtomicString& value)
{
AtomicString oldValue = this->value();
if (m_element)
m_element->willModifyAttribute(qualifiedName(), oldValue, value);
-
setValue(value);
-
if (m_element)
m_element->didModifyAttribute(qualifiedName(), oldValue, value);
}
-void Attr::setNodeValue(const String& v, ExceptionCode& ec)
+ExceptionOr<void> Attr::setNodeValue(const String& value)
{
- setValue(v, ec);
+ setValueForBindings(value);
+ return { };
}
-PassRefPtr<Node> Attr::cloneNode(bool /*deep*/)
+Ref<Node> Attr::cloneNodeInternal(Document& targetDocument, CloningOperation)
{
- RefPtr<Attr> clone = adoptRef(new Attr(document(), qualifiedName(), value()));
- cloneChildNodes(clone.get());
- return clone.release();
+ Ref<Attr> clone = adoptRef(*new Attr(targetDocument, qualifiedName(), value()));
+ cloneChildNodes(clone);
+ return WTFMove(clone);
}
// DOM Section 1.1.1
bool Attr::childTypeAllowed(NodeType type) const
{
- switch (type) {
- case TEXT_NODE:
- case ENTITY_REFERENCE_NODE:
- return true;
- default:
- return false;
- }
+ return type == TEXT_NODE;
}
void Attr::childrenChanged(const ChildChange&)
@@ -164,34 +155,32 @@ void Attr::childrenChanged(const ChildChange&)
invalidateNodeListAndCollectionCachesInAncestors(&qualifiedName(), m_element);
StringBuilder valueBuilder;
- TextNodeTraversal::appendContents(this, valueBuilder);
+ TextNodeTraversal::appendContents(*this, valueBuilder);
AtomicString oldValue = value();
AtomicString newValue = valueBuilder.toAtomicString();
if (m_element)
m_element->willModifyAttribute(qualifiedName(), oldValue, newValue);
- if (m_element)
+ if (m_element) {
+ Style::AttributeChangeInvalidation styleInvalidation(*m_element, qualifiedName(), oldValue, newValue);
elementAttribute().setValue(newValue);
- else
+ } else
m_standaloneValue = newValue;
- if (m_element)
+ if (m_element) {
+ NoEventDispatchAssertion::DisableAssertionsInScope allowedScope;
m_element->attributeChanged(qualifiedName(), oldValue, newValue);
-}
-
-bool Attr::isId() const
-{
- return qualifiedName().matches(document().idAttributeName());
+ }
}
CSSStyleDeclaration* Attr::style()
{
// This function only exists to support the Obj-C bindings.
- if (!m_element || !m_element->isStyledElement())
+ if (!is<StyledElement>(m_element))
return nullptr;
m_style = MutableStyleProperties::create();
- toStyledElement(m_element)->collectStyleForPresentationAttribute(qualifiedName(), value(), *m_style);
+ downcast<StyledElement>(*m_element).collectStyleForPresentationAttribute(qualifiedName(), value(), *m_style);
return m_style->ensureCSSStyleDeclaration();
}
@@ -214,13 +203,13 @@ void Attr::detachFromElementWithValue(const AtomicString& value)
ASSERT(m_element);
ASSERT(m_standaloneValue.isNull());
m_standaloneValue = value;
- m_element = 0;
+ m_element = nullptr;
}
-void Attr::attachToElement(Element* element)
+void Attr::attachToElement(Element& element)
{
ASSERT(!m_element);
- m_element = element;
+ m_element = &element;
m_standaloneValue = nullAtom;
}