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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 void setIdForStyleResolution(const AtomicString& newId) const { m_idForStyle
Resolution = newId; } | 59 void setIdForStyleResolution(const AtomicString& newId) const { m_idForStyle
Resolution = newId; } |
60 | 60 |
61 const StylePropertySet* inlineStyle() const { return m_inlineStyle.get(); } | 61 const StylePropertySet* inlineStyle() const { return m_inlineStyle.get(); } |
62 | 62 |
63 const StylePropertySet* presentationAttributeStyle() const; | 63 const StylePropertySet* presentationAttributeStyle() const; |
64 | 64 |
65 // This is not a trivial getter and its return value should be cached for pe
rformance. | 65 // This is not a trivial getter and its return value should be cached for pe
rformance. |
66 size_t length() const; | 66 size_t length() const; |
67 bool isEmpty() const { return !length(); } | 67 bool isEmpty() const { return !length(); } |
68 | 68 |
69 const Attribute* attributeItem(unsigned index) const; | 69 const Attribute& attributeItem(unsigned index) const; |
70 const Attribute* getAttributeItem(const QualifiedName&) const; | 70 const Attribute* getAttributeItem(const QualifiedName&) const; |
71 size_t getAttributeItemIndex(const QualifiedName&, bool shouldIgnoreCase = f
alse) const; | 71 size_t getAttributeItemIndex(const QualifiedName&, bool shouldIgnoreCase = f
alse) const; |
72 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttr
ibuteCase) const; | 72 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttr
ibuteCase) const; |
73 size_t getAttrIndex(Attr*) const; | 73 size_t getAttrIndex(Attr*) const; |
74 | 74 |
75 bool hasID() const { return !m_idForStyleResolution.isNull(); } | 75 bool hasID() const { return !m_idForStyleResolution.isNull(); } |
76 bool hasClass() const { return !m_classNames.isNull(); } | 76 bool hasClass() const { return !m_classNames.isNull(); } |
77 | 77 |
78 bool isEquivalent(const ElementData* other) const; | 78 bool isEquivalent(const ElementData* other) const; |
79 | 79 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // attribute will have the same inline style. | 142 // attribute will have the same inline style. |
143 class UniqueElementData FINAL : public ElementData { | 143 class UniqueElementData FINAL : public ElementData { |
144 public: | 144 public: |
145 static PassRefPtr<UniqueElementData> create(); | 145 static PassRefPtr<UniqueElementData> create(); |
146 PassRefPtr<ShareableElementData> makeShareableCopy() const; | 146 PassRefPtr<ShareableElementData> makeShareableCopy() const; |
147 | 147 |
148 // These functions do no error/duplicate checking. | 148 // These functions do no error/duplicate checking. |
149 void addAttribute(const QualifiedName&, const AtomicString&); | 149 void addAttribute(const QualifiedName&, const AtomicString&); |
150 void removeAttribute(size_t index); | 150 void removeAttribute(size_t index); |
151 | 151 |
152 Attribute* attributeItem(unsigned index); | 152 Attribute& attributeItem(unsigned index); |
153 Attribute* getAttributeItem(const QualifiedName&); | 153 Attribute* getAttributeItem(const QualifiedName&); |
154 | 154 |
155 UniqueElementData(); | 155 UniqueElementData(); |
156 explicit UniqueElementData(const ShareableElementData&); | 156 explicit UniqueElementData(const ShareableElementData&); |
157 explicit UniqueElementData(const UniqueElementData&); | 157 explicit UniqueElementData(const UniqueElementData&); |
158 | 158 |
159 // FIXME: We might want to support sharing element data for elements with | 159 // FIXME: We might want to support sharing element data for elements with |
160 // presentation attribute style. Lots of table cells likely have the same | 160 // presentation attribute style. Lots of table cells likely have the same |
161 // attributes. Most modern pages don't use presentation attributes though | 161 // attributes. Most modern pages don't use presentation attributes though |
162 // so this might not make sense. | 162 // so this might not make sense. |
(...skipping 19 matching lines...) Expand all Loading... |
182 { | 182 { |
183 if (!m_isUnique) | 183 if (!m_isUnique) |
184 return 0; | 184 return 0; |
185 return static_cast<const UniqueElementData*>(this)->m_presentationAttributeS
tyle.get(); | 185 return static_cast<const UniqueElementData*>(this)->m_presentationAttributeS
tyle.get(); |
186 } | 186 } |
187 | 187 |
188 inline const Attribute* ElementData::getAttributeItem(const AtomicString& name,
bool shouldIgnoreAttributeCase) const | 188 inline const Attribute* ElementData::getAttributeItem(const AtomicString& name,
bool shouldIgnoreAttributeCase) const |
189 { | 189 { |
190 size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase); | 190 size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase); |
191 if (index != kNotFound) | 191 if (index != kNotFound) |
192 return attributeItem(index); | 192 return &attributeItem(index); |
193 return 0; | 193 return 0; |
194 } | 194 } |
195 | 195 |
196 inline const Attribute* ElementData::attributeBase() const | 196 inline const Attribute* ElementData::attributeBase() const |
197 { | 197 { |
198 if (m_isUnique) | 198 if (m_isUnique) |
199 return static_cast<const UniqueElementData*>(this)->m_attributeVector.be
gin(); | 199 return static_cast<const UniqueElementData*>(this)->m_attributeVector.be
gin(); |
200 return static_cast<const ShareableElementData*>(this)->m_attributeArray; | 200 return static_cast<const ShareableElementData*>(this)->m_attributeArray; |
201 } | 201 } |
202 | 202 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 const Attribute* begin = attributeBase(); | 245 const Attribute* begin = attributeBase(); |
246 unsigned length = this->length(); | 246 unsigned length = this->length(); |
247 for (unsigned i = 0; i < length; ++i) { | 247 for (unsigned i = 0; i < length; ++i) { |
248 const Attribute& attribute = begin[i]; | 248 const Attribute& attribute = begin[i]; |
249 if (attribute.name().matches(name)) | 249 if (attribute.name().matches(name)) |
250 return &attribute; | 250 return &attribute; |
251 } | 251 } |
252 return 0; | 252 return 0; |
253 } | 253 } |
254 | 254 |
255 inline const Attribute* ElementData::attributeItem(unsigned index) const | 255 inline const Attribute& ElementData::attributeItem(unsigned index) const |
256 { | 256 { |
257 RELEASE_ASSERT(index < length()); | 257 RELEASE_ASSERT(index < length()); |
258 return attributeBase() + index; | 258 ASSERT(attributeBase() + index); |
| 259 return *(attributeBase() + index); |
259 } | 260 } |
260 | 261 |
261 inline void UniqueElementData::addAttribute(const QualifiedName& attributeName,
const AtomicString& value) | 262 inline void UniqueElementData::addAttribute(const QualifiedName& attributeName,
const AtomicString& value) |
262 { | 263 { |
263 m_attributeVector.append(Attribute(attributeName, value)); | 264 m_attributeVector.append(Attribute(attributeName, value)); |
264 } | 265 } |
265 | 266 |
266 inline void UniqueElementData::removeAttribute(size_t index) | 267 inline void UniqueElementData::removeAttribute(size_t index) |
267 { | 268 { |
268 m_attributeVector.remove(index); | 269 m_attributeVector.remove(index); |
269 } | 270 } |
270 | 271 |
271 inline Attribute* UniqueElementData::attributeItem(unsigned index) | 272 inline Attribute& UniqueElementData::attributeItem(unsigned index) |
272 { | 273 { |
273 return &m_attributeVector.at(index); | 274 return m_attributeVector.at(index); |
274 } | 275 } |
275 | 276 |
276 } // namespace WebCore | 277 } // namespace WebCore |
277 | 278 |
278 #endif // ElementData_h | 279 #endif // ElementData_h |
OLD | NEW |