diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/ElementData.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/dom/ElementData.cpp')
-rw-r--r-- | Source/WebCore/dom/ElementData.cpp | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/Source/WebCore/dom/ElementData.cpp b/Source/WebCore/dom/ElementData.cpp index 86f852d05..4b9ebf889 100644 --- a/Source/WebCore/dom/ElementData.cpp +++ b/Source/WebCore/dom/ElementData.cpp @@ -27,16 +27,18 @@ #include "ElementData.h" #include "Attr.h" +#include "HTMLNames.h" #include "StyleProperties.h" +#include "XMLNames.h" namespace WebCore { void ElementData::destroy() { - if (isUnique()) - delete static_cast<UniqueElementData*>(this); + if (is<UniqueElementData>(*this)) + delete downcast<UniqueElementData>(this); else - delete static_cast<ShareableElementData*>(this); + delete downcast<ShareableElementData>(this); } ElementData::ElementData() @@ -61,13 +63,13 @@ static size_t sizeForShareableElementDataWithAttributeCount(unsigned count) return sizeof(ShareableElementData) + sizeof(Attribute) * count; } -PassRef<ShareableElementData> ShareableElementData::createWithAttributes(const Vector<Attribute>& attributes) +Ref<ShareableElementData> ShareableElementData::createWithAttributes(const Vector<Attribute>& attributes) { void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(attributes.size())); return adoptRef(*new (NotNull, slot) ShareableElementData(attributes)); } -PassRef<UniqueElementData> UniqueElementData::create() +Ref<UniqueElementData> UniqueElementData::create() { return adoptRef(*new UniqueElementData); } @@ -140,19 +142,20 @@ UniqueElementData::UniqueElementData(const ShareableElementData& other) ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); m_inlineStyle = other.m_inlineStyle; - m_attributeVector.reserveCapacity(other.length()); - for (unsigned i = 0; i < other.length(); ++i) + unsigned otherLength = other.length(); + m_attributeVector.reserveCapacity(otherLength); + for (unsigned i = 0; i < otherLength; ++i) m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); } -PassRef<UniqueElementData> ElementData::makeUniqueCopy() const +Ref<UniqueElementData> ElementData::makeUniqueCopy() const { if (isUnique()) return adoptRef(*new UniqueElementData(static_cast<const UniqueElementData&>(*this))); return adoptRef(*new UniqueElementData(static_cast<const ShareableElementData&>(*this))); } -PassRef<ShareableElementData> UniqueElementData::makeShareableCopy() const +Ref<ShareableElementData> UniqueElementData::makeShareableCopy() const { void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m_attributeVector.size())); return adoptRef(*new (NotNull, slot) ShareableElementData(*this)); @@ -175,46 +178,32 @@ bool ElementData::isEquivalent(const ElementData* other) const return true; } -unsigned ElementData::findAttributeIndexByNameSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const +Attribute* UniqueElementData::findAttributeByName(const QualifiedName& name) { - // Continue to checking case-insensitively and/or full namespaced names if necessary: - const Attribute* attributes = attributeBase(); - unsigned length = this->length(); - for (unsigned i = 0; i < length; ++i) { - const Attribute& attribute = attributes[i]; - if (!attribute.name().hasPrefix()) { - if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attribute.localName())) - return i; - } else { - // FIXME: Would be faster to do this comparison without calling toString, which - // generates a temporary string by concatenation. But this branch is only reached - // if the attribute name has a prefix, which is rare in HTML. - if (equalPossiblyIgnoringCase(name, attribute.name().toString(), shouldIgnoreAttributeCase)) - return i; - } + for (auto& attribute : m_attributeVector) { + if (attribute.name().matches(name)) + return &attribute; } - return attributeNotFound; + return nullptr; } -unsigned ElementData::findAttributeIndexByNameForAttributeNode(const Attr* attr, bool shouldIgnoreAttributeCase) const +const Attribute* ElementData::findLanguageAttribute() const { - ASSERT(attr); - const Attribute* attributes = attributeBase(); - unsigned count = length(); - for (unsigned i = 0; i < count; ++i) { - if (attributes[i].name().matchesIgnoringCaseForLocalName(attr->qualifiedName(), shouldIgnoreAttributeCase)) - return i; - } - return attributeNotFound; -} + ASSERT(XMLNames::langAttr.localName() == HTMLNames::langAttr.localName()); -Attribute* UniqueElementData::findAttributeByName(const QualifiedName& name) -{ - for (unsigned i = 0, count = m_attributeVector.size(); i < count; ++i) { - if (m_attributeVector.at(i).name().matches(name)) - return &m_attributeVector.at(i); + const Attribute* attributes = attributeBase(); + // Spec: xml:lang takes precedence over html:lang -- http://www.w3.org/TR/xhtml1/#C_7 + const Attribute* languageAttribute = nullptr; + for (unsigned i = 0, count = length(); i < count; ++i) { + const QualifiedName& name = attributes[i].name(); + if (name.localName() != HTMLNames::langAttr.localName()) + continue; + if (name.namespaceURI() == XMLNames::langAttr.namespaceURI()) + return &attributes[i]; + if (name.namespaceURI() == HTMLNames::langAttr.namespaceURI()) + languageAttribute = &attributes[i]; } - return nullptr; + return languageAttribute; } } |