| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2014 Apple Inc. All rights reserved. | 3 * Copyright (C) 2014 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 friend class UniqueElementData; | 104 friend class UniqueElementData; |
| 105 friend class SVGElement; | 105 friend class SVGElement; |
| 106 | 106 |
| 107 #if !ENABLE(OILPAN) | 107 #if !ENABLE(OILPAN) |
| 108 void destroy(); | 108 void destroy(); |
| 109 #endif | 109 #endif |
| 110 | 110 |
| 111 PassRefPtrWillBeRawPtr<UniqueElementData> makeUniqueCopy() const; | 111 PassRefPtrWillBeRawPtr<UniqueElementData> makeUniqueCopy() const; |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 #define DEFINE_ELEMENT_DATA_TYPE_CASTS(thisType, pointerPredicate, referencePre
dicate) \ |
| 115 template<typename T> inline thisType* to##thisType(const RefPtr<T>& data) {
return to##thisType(data.get()); } \ |
| 116 DEFINE_TYPE_CASTS(thisType, ElementData, data, pointerPredicate, referencePr
edicate) |
| 117 |
| 114 #if COMPILER(MSVC) | 118 #if COMPILER(MSVC) |
| 115 #pragma warning(push) | 119 #pragma warning(push) |
| 116 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war
ning | 120 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war
ning |
| 117 #endif | 121 #endif |
| 118 | 122 |
| 119 // SharableElementData is managed by ElementDataCache and is produced by | 123 // SharableElementData is managed by ElementDataCache and is produced by |
| 120 // the parser during page load for elements that have identical attributes. This | 124 // the parser during page load for elements that have identical attributes. This |
| 121 // is a memory optimization since it's very common for many elements to have | 125 // is a memory optimization since it's very common for many elements to have |
| 122 // duplicate sets of attributes (ex. the same classes). | 126 // duplicate sets of attributes (ex. the same classes). |
| 123 class ShareableElementData FINAL : public ElementData { | 127 class ShareableElementData FINAL : public ElementData { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 138 void* operator new(std::size_t, void* location) | 142 void* operator new(std::size_t, void* location) |
| 139 { | 143 { |
| 140 return location; | 144 return location; |
| 141 } | 145 } |
| 142 | 146 |
| 143 AttributeCollection attributes() const; | 147 AttributeCollection attributes() const; |
| 144 | 148 |
| 145 Attribute m_attributeArray[0]; | 149 Attribute m_attributeArray[0]; |
| 146 }; | 150 }; |
| 147 | 151 |
| 152 DEFINE_ELEMENT_DATA_TYPE_CASTS(ShareableElementData, !data->isUnique(), !data.is
Unique()); |
| 153 |
| 148 #if COMPILER(MSVC) | 154 #if COMPILER(MSVC) |
| 149 #pragma warning(pop) | 155 #pragma warning(pop) |
| 150 #endif | 156 #endif |
| 151 | 157 |
| 152 // UniqueElementData is created when an element needs to mutate its attributes | 158 // UniqueElementData is created when an element needs to mutate its attributes |
| 153 // or gains presentation attribute style (ex. width="10"). It does not need to | 159 // or gains presentation attribute style (ex. width="10"). It does not need to |
| 154 // be created to fill in values in the ElementData that are derived from | 160 // be created to fill in values in the ElementData that are derived from |
| 155 // attributes. For example populating the m_inlineStyle from the style attribute | 161 // attributes. For example populating the m_inlineStyle from the style attribute |
| 156 // doesn't require a UniqueElementData as all elements with the same style | 162 // doesn't require a UniqueElementData as all elements with the same style |
| 157 // attribute will have the same inline style. | 163 // attribute will have the same inline style. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 176 void traceAfterDispatch(Visitor*); | 182 void traceAfterDispatch(Visitor*); |
| 177 | 183 |
| 178 // FIXME: We might want to support sharing element data for elements with | 184 // FIXME: We might want to support sharing element data for elements with |
| 179 // presentation attribute style. Lots of table cells likely have the same | 185 // presentation attribute style. Lots of table cells likely have the same |
| 180 // attributes. Most modern pages don't use presentation attributes though | 186 // attributes. Most modern pages don't use presentation attributes though |
| 181 // so this might not make sense. | 187 // so this might not make sense. |
| 182 mutable RefPtrWillBeMember<StylePropertySet> m_presentationAttributeStyle; | 188 mutable RefPtrWillBeMember<StylePropertySet> m_presentationAttributeStyle; |
| 183 Vector<Attribute, 4> m_attributeVector; | 189 Vector<Attribute, 4> m_attributeVector; |
| 184 }; | 190 }; |
| 185 | 191 |
| 192 DEFINE_ELEMENT_DATA_TYPE_CASTS(UniqueElementData, data->isUnique(), data.isUniqu
e()); |
| 193 |
| 186 #if !ENABLE(OILPAN) | 194 #if !ENABLE(OILPAN) |
| 187 inline void ElementData::deref() | 195 inline void ElementData::deref() |
| 188 { | 196 { |
| 189 if (!derefBase()) | 197 if (!derefBase()) |
| 190 return; | 198 return; |
| 191 destroy(); | 199 destroy(); |
| 192 } | 200 } |
| 193 #endif | 201 #endif |
| 194 | 202 |
| 195 inline const StylePropertySet* ElementData::presentationAttributeStyle() const | 203 inline const StylePropertySet* ElementData::presentationAttributeStyle() const |
| 196 { | 204 { |
| 197 if (!m_isUnique) | 205 if (!m_isUnique) |
| 198 return 0; | 206 return 0; |
| 199 return static_cast<const UniqueElementData*>(this)->m_presentationAttributeS
tyle.get(); | 207 return toUniqueElementData(this)->m_presentationAttributeStyle.get(); |
| 200 } | 208 } |
| 201 | 209 |
| 202 inline AttributeCollection ElementData::attributes() const | 210 inline AttributeCollection ElementData::attributes() const |
| 203 { | 211 { |
| 204 if (isUnique()) | 212 if (isUnique()) |
| 205 return static_cast<const UniqueElementData*>(this)->attributes(); | 213 return toUniqueElementData(this)->attributes(); |
| 206 return static_cast<const ShareableElementData*>(this)->attributes(); | 214 return toShareableElementData(this)->attributes(); |
| 207 } | 215 } |
| 208 | 216 |
| 209 inline AttributeCollection ShareableElementData::attributes() const | 217 inline AttributeCollection ShareableElementData::attributes() const |
| 210 { | 218 { |
| 211 return AttributeCollection(m_attributeArray, m_arraySize); | 219 return AttributeCollection(m_attributeArray, m_arraySize); |
| 212 } | 220 } |
| 213 | 221 |
| 214 inline AttributeCollection UniqueElementData::attributes() const | 222 inline AttributeCollection UniqueElementData::attributes() const |
| 215 { | 223 { |
| 216 return AttributeCollection(m_attributeVector.data(), m_attributeVector.size(
)); | 224 return AttributeCollection(m_attributeVector.data(), m_attributeVector.size(
)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 227 } | 235 } |
| 228 | 236 |
| 229 inline Attribute& UniqueElementData::attributeAt(unsigned index) | 237 inline Attribute& UniqueElementData::attributeAt(unsigned index) |
| 230 { | 238 { |
| 231 return m_attributeVector.at(index); | 239 return m_attributeVector.at(index); |
| 232 } | 240 } |
| 233 | 241 |
| 234 } // namespace blink | 242 } // namespace blink |
| 235 | 243 |
| 236 #endif // ElementData_h | 244 #endif // ElementData_h |
| OLD | NEW |