| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/dom/ElementData.h" | 32 #include "core/dom/ElementData.h" |
| 33 | 33 |
| 34 #include "core/css/StylePropertySet.h" | 34 #include "core/css/StylePropertySet.h" |
| 35 #include "core/dom/Attr.h" | |
| 36 #include "core/dom/QualifiedName.h" | 35 #include "core/dom/QualifiedName.h" |
| 37 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
| 38 | 37 |
| 39 namespace WebCore { | 38 namespace WebCore { |
| 40 | 39 |
| 41 struct SameSizeAsElementData : public RefCountedWillBeGarbageCollectedFinalized<
SameSizeAsElementData> { | 40 struct SameSizeAsElementData : public RefCountedWillBeGarbageCollectedFinalized<
SameSizeAsElementData> { |
| 42 unsigned bitfield; | 41 unsigned bitfield; |
| 43 void* pointers[3]; | 42 void* pointers[3]; |
| 44 }; | 43 }; |
| 45 | 44 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 63 : m_isUnique(false) | 62 : m_isUnique(false) |
| 64 , m_arraySize(arraySize) | 63 , m_arraySize(arraySize) |
| 65 , m_presentationAttributeStyleIsDirty(false) | 64 , m_presentationAttributeStyleIsDirty(false) |
| 66 , m_styleAttributeIsDirty(false) | 65 , m_styleAttributeIsDirty(false) |
| 67 , m_animatedSVGAttributesAreDirty(false) | 66 , m_animatedSVGAttributesAreDirty(false) |
| 68 { | 67 { |
| 69 } | 68 } |
| 70 | 69 |
| 71 ElementData::ElementData(const ElementData& other, bool isUnique) | 70 ElementData::ElementData(const ElementData& other, bool isUnique) |
| 72 : m_isUnique(isUnique) | 71 : m_isUnique(isUnique) |
| 73 , m_arraySize(isUnique ? 0 : other.attributeCount()) | 72 , m_arraySize(isUnique ? 0 : other.attributes().size()) |
| 74 , m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDi
rty) | 73 , m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDi
rty) |
| 75 , m_styleAttributeIsDirty(other.m_styleAttributeIsDirty) | 74 , m_styleAttributeIsDirty(other.m_styleAttributeIsDirty) |
| 76 , m_animatedSVGAttributesAreDirty(other.m_animatedSVGAttributesAreDirty) | 75 , m_animatedSVGAttributesAreDirty(other.m_animatedSVGAttributesAreDirty) |
| 77 , m_classNames(other.m_classNames) | 76 , m_classNames(other.m_classNames) |
| 78 , m_idForStyleResolution(other.m_idForStyleResolution) | 77 , m_idForStyleResolution(other.m_idForStyleResolution) |
| 79 { | 78 { |
| 80 // NOTE: The inline style is copied by the subclass copy constructor since w
e don't know what to do with it here. | 79 // NOTE: The inline style is copied by the subclass copy constructor since w
e don't know what to do with it here. |
| 81 } | 80 } |
| 82 | 81 |
| 83 #if ENABLE(OILPAN) | 82 #if ENABLE(OILPAN) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 100 | 99 |
| 101 PassRefPtrWillBeRawPtr<UniqueElementData> ElementData::makeUniqueCopy() const | 100 PassRefPtrWillBeRawPtr<UniqueElementData> ElementData::makeUniqueCopy() const |
| 102 { | 101 { |
| 103 if (isUnique()) | 102 if (isUnique()) |
| 104 return adoptRefWillBeNoop(new UniqueElementData(static_cast<const Unique
ElementData&>(*this))); | 103 return adoptRefWillBeNoop(new UniqueElementData(static_cast<const Unique
ElementData&>(*this))); |
| 105 return adoptRefWillBeNoop(new UniqueElementData(static_cast<const ShareableE
lementData&>(*this))); | 104 return adoptRefWillBeNoop(new UniqueElementData(static_cast<const ShareableE
lementData&>(*this))); |
| 106 } | 105 } |
| 107 | 106 |
| 108 bool ElementData::isEquivalent(const ElementData* other) const | 107 bool ElementData::isEquivalent(const ElementData* other) const |
| 109 { | 108 { |
| 109 AttributeCollection attributes = this->attributes(); |
| 110 if (!other) | 110 if (!other) |
| 111 return !hasAttributes(); | 111 return attributes.isEmpty(); |
| 112 | 112 |
| 113 AttributeCollection attributes = this->attributes(); | 113 AttributeCollection otherAttributes = other->attributes(); |
| 114 if (attributes.size() != other->attributeCount()) | 114 if (attributes.size() != otherAttributes.size()) |
| 115 return false; | 115 return false; |
| 116 | 116 |
| 117 AttributeCollection::const_iterator end = attributes.end(); | 117 AttributeCollection::const_iterator end = attributes.end(); |
| 118 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it) { | 118 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it) { |
| 119 const Attribute* otherAttr = other->findAttributeByName(it->name()); | 119 const Attribute* otherAttr = otherAttributes.find(it->name()); |
| 120 if (!otherAttr || it->value() != otherAttr->value()) | 120 if (!otherAttr || it->value() != otherAttr->value()) |
| 121 return false; | 121 return false; |
| 122 } | 122 } |
| 123 return true; | 123 return true; |
| 124 } | 124 } |
| 125 | 125 |
| 126 size_t ElementData::findAttrNodeIndex(Attr* attr) const | |
| 127 { | |
| 128 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. | |
| 129 AttributeCollection attributes = this->attributes(); | |
| 130 AttributeCollection::const_iterator end = attributes.end(); | |
| 131 unsigned index = 0; | |
| 132 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it, ++index) { | |
| 133 if (it->name() == attr->qualifiedName()) | |
| 134 return index; | |
| 135 } | |
| 136 return kNotFound; | |
| 137 } | |
| 138 | |
| 139 size_t ElementData::findAttributeIndexByNameSlowCase(const AtomicString& name, b
ool shouldIgnoreAttributeCase) const | |
| 140 { | |
| 141 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: | |
| 142 AttributeCollection attributes = this->attributes(); | |
| 143 AttributeCollection::const_iterator end = attributes.end(); | |
| 144 unsigned index = 0; | |
| 145 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it, ++index) { | |
| 146 // FIXME: Why check the prefix? Namespace is all that should matter | |
| 147 // and all HTML/SVG attributes have a null namespace! | |
| 148 if (!it->name().hasPrefix()) { | |
| 149 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, it->localNa
me())) | |
| 150 return index; | |
| 151 } else { | |
| 152 // FIXME: Would be faster to do this comparison without calling toSt
ring, which | |
| 153 // generates a temporary string by concatenation. But this branch is
only reached | |
| 154 // if the attribute name has a prefix, which is rare in HTML. | |
| 155 if (equalPossiblyIgnoringCase(name, it->name().toString(), shouldIgn
oreAttributeCase)) | |
| 156 return index; | |
| 157 } | |
| 158 } | |
| 159 return kNotFound; | |
| 160 } | |
| 161 | |
| 162 void ElementData::trace(Visitor* visitor) | 126 void ElementData::trace(Visitor* visitor) |
| 163 { | 127 { |
| 164 if (m_isUnique) | 128 if (m_isUnique) |
| 165 static_cast<UniqueElementData*>(this)->traceAfterDispatch(visitor); | 129 static_cast<UniqueElementData*>(this)->traceAfterDispatch(visitor); |
| 166 else | 130 else |
| 167 static_cast<ShareableElementData*>(this)->traceAfterDispatch(visitor); | 131 static_cast<ShareableElementData*>(this)->traceAfterDispatch(visitor); |
| 168 } | 132 } |
| 169 | 133 |
| 170 void ElementData::traceAfterDispatch(Visitor* visitor) | 134 void ElementData::traceAfterDispatch(Visitor* visitor) |
| 171 { | 135 { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n
ullptr; | 184 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : n
ullptr; |
| 221 } | 185 } |
| 222 | 186 |
| 223 UniqueElementData::UniqueElementData(const ShareableElementData& other) | 187 UniqueElementData::UniqueElementData(const ShareableElementData& other) |
| 224 : ElementData(other, true) | 188 : ElementData(other, true) |
| 225 { | 189 { |
| 226 // An ShareableElementData should never have a mutable inline StylePropertyS
et attached. | 190 // An ShareableElementData should never have a mutable inline StylePropertyS
et attached. |
| 227 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); | 191 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); |
| 228 m_inlineStyle = other.m_inlineStyle; | 192 m_inlineStyle = other.m_inlineStyle; |
| 229 | 193 |
| 230 unsigned length = other.attributeCount(); | 194 unsigned length = other.attributes().size(); |
| 231 m_attributeVector.reserveCapacity(length); | 195 m_attributeVector.reserveCapacity(length); |
| 232 for (unsigned i = 0; i < length; ++i) | 196 for (unsigned i = 0; i < length; ++i) |
| 233 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); | 197 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); |
| 234 } | 198 } |
| 235 | 199 |
| 236 PassRefPtrWillBeRawPtr<UniqueElementData> UniqueElementData::create() | 200 PassRefPtrWillBeRawPtr<UniqueElementData> UniqueElementData::create() |
| 237 { | 201 { |
| 238 return adoptRefWillBeNoop(new UniqueElementData); | 202 return adoptRefWillBeNoop(new UniqueElementData); |
| 239 } | 203 } |
| 240 | 204 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 258 return 0; | 222 return 0; |
| 259 } | 223 } |
| 260 | 224 |
| 261 void UniqueElementData::traceAfterDispatch(Visitor* visitor) | 225 void UniqueElementData::traceAfterDispatch(Visitor* visitor) |
| 262 { | 226 { |
| 263 visitor->trace(m_presentationAttributeStyle); | 227 visitor->trace(m_presentationAttributeStyle); |
| 264 ElementData::traceAfterDispatch(visitor); | 228 ElementData::traceAfterDispatch(visitor); |
| 265 } | 229 } |
| 266 | 230 |
| 267 } // namespace WebCore | 231 } // namespace WebCore |
| OLD | NEW |