| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 : m_isUnique(false) | 63 : m_isUnique(false) |
| 64 , m_arraySize(arraySize) | 64 , m_arraySize(arraySize) |
| 65 , m_presentationAttributeStyleIsDirty(false) | 65 , m_presentationAttributeStyleIsDirty(false) |
| 66 , m_styleAttributeIsDirty(false) | 66 , m_styleAttributeIsDirty(false) |
| 67 , m_animatedSVGAttributesAreDirty(false) | 67 , m_animatedSVGAttributesAreDirty(false) |
| 68 { | 68 { |
| 69 } | 69 } |
| 70 | 70 |
| 71 ElementData::ElementData(const ElementData& other, bool isUnique) | 71 ElementData::ElementData(const ElementData& other, bool isUnique) |
| 72 : m_isUnique(isUnique) | 72 : m_isUnique(isUnique) |
| 73 , m_arraySize(isUnique ? 0 : other.length()) | 73 , m_arraySize(isUnique ? 0 : other.attributeCount()) |
| 74 , m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDi
rty) | 74 , m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDi
rty) |
| 75 , m_styleAttributeIsDirty(other.m_styleAttributeIsDirty) | 75 , m_styleAttributeIsDirty(other.m_styleAttributeIsDirty) |
| 76 , m_animatedSVGAttributesAreDirty(other.m_animatedSVGAttributesAreDirty) | 76 , m_animatedSVGAttributesAreDirty(other.m_animatedSVGAttributesAreDirty) |
| 77 , m_classNames(other.m_classNames) | 77 , m_classNames(other.m_classNames) |
| 78 , m_idForStyleResolution(other.m_idForStyleResolution) | 78 , m_idForStyleResolution(other.m_idForStyleResolution) |
| 79 { | 79 { |
| 80 // NOTE: The inline style is copied by the subclass copy constructor since w
e don't know what to do with it here. | 80 // NOTE: The inline style is copied by the subclass copy constructor since w
e don't know what to do with it here. |
| 81 } | 81 } |
| 82 | 82 |
| 83 void ElementData::destroy() | 83 void ElementData::destroy() |
| 84 { | 84 { |
| 85 if (m_isUnique) | 85 if (m_isUnique) |
| 86 delete static_cast<UniqueElementData*>(this); | 86 delete static_cast<UniqueElementData*>(this); |
| 87 else | 87 else |
| 88 delete static_cast<ShareableElementData*>(this); | 88 delete static_cast<ShareableElementData*>(this); |
| 89 } | 89 } |
| 90 | 90 |
| 91 PassRefPtr<UniqueElementData> ElementData::makeUniqueCopy() const | 91 PassRefPtr<UniqueElementData> ElementData::makeUniqueCopy() const |
| 92 { | 92 { |
| 93 if (isUnique()) | 93 if (isUnique()) |
| 94 return adoptRef(new UniqueElementData(static_cast<const UniqueElementDat
a&>(*this))); | 94 return adoptRef(new UniqueElementData(static_cast<const UniqueElementDat
a&>(*this))); |
| 95 return adoptRef(new UniqueElementData(static_cast<const ShareableElementData
&>(*this))); | 95 return adoptRef(new UniqueElementData(static_cast<const ShareableElementData
&>(*this))); |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool ElementData::isEquivalent(const ElementData* other) const | 98 bool ElementData::isEquivalent(const ElementData* other) const |
| 99 { | 99 { |
| 100 if (!other) | 100 if (!other) |
| 101 return isEmpty(); | 101 return !hasAttributes(); |
| 102 | 102 |
| 103 AttributeIteratorAccessor attributes = attributesIterator(); | 103 AttributeIteratorAccessor attributes = attributesIterator(); |
| 104 if (attributes.size() != other->length()) | 104 if (attributes.size() != other->attributeCount()) |
| 105 return false; | 105 return false; |
| 106 | 106 |
| 107 AttributeConstIterator end = attributes.end(); | 107 AttributeConstIterator end = attributes.end(); |
| 108 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { | 108 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { |
| 109 const Attribute* otherAttr = other->getAttributeItem(it->name()); | 109 const Attribute* otherAttr = other->findAttributeByName(it->name()); |
| 110 if (!otherAttr || it->value() != otherAttr->value()) | 110 if (!otherAttr || it->value() != otherAttr->value()) |
| 111 return false; | 111 return false; |
| 112 } | 112 } |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 size_t ElementData::getAttrIndex(Attr* attr) const | 116 size_t ElementData::findAttrNodeIndex(Attr* attr) const |
| 117 { | 117 { |
| 118 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. | 118 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. |
| 119 AttributeIteratorAccessor attributes = attributesIterator(); | 119 AttributeIteratorAccessor attributes = attributesIterator(); |
| 120 AttributeConstIterator end = attributes.end(); | 120 AttributeConstIterator end = attributes.end(); |
| 121 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { | 121 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { |
| 122 if (it->name() == attr->qualifiedName()) | 122 if (it->name() == attr->qualifiedName()) |
| 123 return it.index(); | 123 return it.index(); |
| 124 } | 124 } |
| 125 return kNotFound; | 125 return kNotFound; |
| 126 } | 126 } |
| 127 | 127 |
| 128 size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool
shouldIgnoreAttributeCase) const | 128 size_t ElementData::findAttributeIndexByNameSlowCase(const AtomicString& name, b
ool shouldIgnoreAttributeCase) const |
| 129 { | 129 { |
| 130 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: | 130 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: |
| 131 AttributeIteratorAccessor attributes = attributesIterator(); | 131 AttributeIteratorAccessor attributes = attributesIterator(); |
| 132 AttributeConstIterator end = attributes.end(); | 132 AttributeConstIterator end = attributes.end(); |
| 133 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { | 133 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { |
| 134 // FIXME: Why check the prefix? Namespace is all that should matter | 134 // FIXME: Why check the prefix? Namespace is all that should matter |
| 135 // and all HTML/SVG attributes have a null namespace! | 135 // and all HTML/SVG attributes have a null namespace! |
| 136 if (!it->name().hasPrefix()) { | 136 if (!it->name().hasPrefix()) { |
| 137 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localNa
me())) | 137 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localNa
me())) |
| 138 return it.index(); | 138 return it.index(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n
ullptr; | 191 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n
ullptr; |
| 192 } | 192 } |
| 193 | 193 |
| 194 UniqueElementData::UniqueElementData(const ShareableElementData& other) | 194 UniqueElementData::UniqueElementData(const ShareableElementData& other) |
| 195 : ElementData(other, true) | 195 : ElementData(other, true) |
| 196 { | 196 { |
| 197 // An ShareableElementData should never have a mutable inline StylePropertyS
et attached. | 197 // An ShareableElementData should never have a mutable inline StylePropertyS
et attached. |
| 198 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); | 198 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); |
| 199 m_inlineStyle = other.m_inlineStyle; | 199 m_inlineStyle = other.m_inlineStyle; |
| 200 | 200 |
| 201 unsigned length = other.length(); | 201 unsigned length = other.attributeCount(); |
| 202 m_attributeVector.reserveCapacity(length); | 202 m_attributeVector.reserveCapacity(length); |
| 203 for (unsigned i = 0; i < length; ++i) | 203 for (unsigned i = 0; i < length; ++i) |
| 204 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); | 204 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); |
| 205 } | 205 } |
| 206 | 206 |
| 207 PassRefPtr<UniqueElementData> UniqueElementData::create() | 207 PassRefPtr<UniqueElementData> UniqueElementData::create() |
| 208 { | 208 { |
| 209 return adoptRef(new UniqueElementData); | 209 return adoptRef(new UniqueElementData); |
| 210 } | 210 } |
| 211 | 211 |
| 212 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const | 212 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const |
| 213 { | 213 { |
| 214 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m
_attributeVector.size())); | 214 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m
_attributeVector.size())); |
| 215 return adoptRef(new (slot) ShareableElementData(*this)); | 215 return adoptRef(new (slot) ShareableElementData(*this)); |
| 216 } | 216 } |
| 217 | 217 |
| 218 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name) | 218 Attribute* UniqueElementData::findAttributeByName(const QualifiedName& name) |
| 219 { | 219 { |
| 220 unsigned length = m_attributeVector.size(); | 220 unsigned length = m_attributeVector.size(); |
| 221 for (unsigned i = 0; i < length; ++i) { | 221 for (unsigned i = 0; i < length; ++i) { |
| 222 if (m_attributeVector.at(i).name().matches(name)) | 222 if (m_attributeVector.at(i).name().matches(name)) |
| 223 return &m_attributeVector.at(i); | 223 return &m_attributeVector.at(i); |
| 224 } | 224 } |
| 225 return 0; | 225 return 0; |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace WebCore | 228 } // namespace WebCore |
| OLD | NEW |