| 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 28 matching lines...) Expand all Loading... |
| 39 #include "wtf/text/AtomicString.h" | 39 #include "wtf/text/AtomicString.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 class ShareableElementData; | 43 class ShareableElementData; |
| 44 class StylePropertySet; | 44 class StylePropertySet; |
| 45 class UniqueElementData; | 45 class UniqueElementData; |
| 46 | 46 |
| 47 // ElementData represents very common, but not necessarily unique to an element, | 47 // ElementData represents very common, but not necessarily unique to an element, |
| 48 // data such as attributes, inline style, and parsed class names and ids. | 48 // data such as attributes, inline style, and parsed class names and ids. |
| 49 class ElementData : public RefCountedWillBeGarbageCollectedFinalized<ElementData
> { | 49 class ElementData : public GarbageCollectedFinalized<ElementData> { |
| 50 USING_FAST_MALLOC_WILL_BE_REMOVED(ElementData); | |
| 51 public: | 50 public: |
| 52 #if ENABLE(OILPAN) | 51 #if ENABLE(OILPAN) |
| 53 // Override GarbageCollectedFinalized's finalizeGarbageCollectedObject to | 52 // Override GarbageCollectedFinalized's finalizeGarbageCollectedObject to |
| 54 // dispatch to the correct subclass destructor. | 53 // dispatch to the correct subclass destructor. |
| 55 void finalizeGarbageCollectedObject(); | 54 void finalizeGarbageCollectedObject(); |
| 56 #else | 55 #else |
| 57 // Override RefCounted's deref() to ensure operator delete is called on | 56 // Override RefCounted's deref() to ensure operator delete is called on |
| 58 // the appropriate subclass type. | 57 // the appropriate subclass type. |
| 59 void deref(); | 58 void deref(); |
| 60 #endif | 59 #endif |
| (...skipping 26 matching lines...) Expand all Loading... |
| 87 explicit ElementData(unsigned arraySize); | 86 explicit ElementData(unsigned arraySize); |
| 88 ElementData(const ElementData&, bool isUnique); | 87 ElementData(const ElementData&, bool isUnique); |
| 89 | 88 |
| 90 // Keep the type in a bitfield instead of using virtual destructors to avoid
adding a vtable. | 89 // Keep the type in a bitfield instead of using virtual destructors to avoid
adding a vtable. |
| 91 unsigned m_isUnique : 1; | 90 unsigned m_isUnique : 1; |
| 92 unsigned m_arraySize : 28; | 91 unsigned m_arraySize : 28; |
| 93 mutable unsigned m_presentationAttributeStyleIsDirty : 1; | 92 mutable unsigned m_presentationAttributeStyleIsDirty : 1; |
| 94 mutable unsigned m_styleAttributeIsDirty : 1; | 93 mutable unsigned m_styleAttributeIsDirty : 1; |
| 95 mutable unsigned m_animatedSVGAttributesAreDirty : 1; | 94 mutable unsigned m_animatedSVGAttributesAreDirty : 1; |
| 96 | 95 |
| 97 mutable RefPtrWillBeMember<StylePropertySet> m_inlineStyle; | 96 mutable Member<StylePropertySet> m_inlineStyle; |
| 98 mutable SpaceSplitString m_classNames; | 97 mutable SpaceSplitString m_classNames; |
| 99 mutable AtomicString m_idForStyleResolution; | 98 mutable AtomicString m_idForStyleResolution; |
| 100 | 99 |
| 101 private: | 100 private: |
| 102 friend class Element; | 101 friend class Element; |
| 103 friend class ShareableElementData; | 102 friend class ShareableElementData; |
| 104 friend class UniqueElementData; | 103 friend class UniqueElementData; |
| 105 friend class SVGElement; | 104 friend class SVGElement; |
| 106 | 105 |
| 107 #if !ENABLE(OILPAN) | 106 #if !ENABLE(OILPAN) |
| 108 void destroy(); | 107 void destroy(); |
| 109 #endif | 108 #endif |
| 110 | 109 |
| 111 PassRefPtrWillBeRawPtr<UniqueElementData> makeUniqueCopy() const; | 110 RawPtr<UniqueElementData> makeUniqueCopy() const; |
| 112 }; | 111 }; |
| 113 | 112 |
| 114 #define DEFINE_ELEMENT_DATA_TYPE_CASTS(thisType, pointerPredicate, referencePre
dicate) \ | 113 #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()); } \ | 114 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) | 115 DEFINE_TYPE_CASTS(thisType, ElementData, data, pointerPredicate, referencePr
edicate) |
| 117 | 116 |
| 118 #if COMPILER(MSVC) | 117 #if COMPILER(MSVC) |
| 119 #pragma warning(push) | 118 #pragma warning(push) |
| 120 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war
ning | 119 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" war
ning |
| 121 #endif | 120 #endif |
| 122 | 121 |
| 123 // SharableElementData is managed by ElementDataCache and is produced by | 122 // SharableElementData is managed by ElementDataCache and is produced by |
| 124 // the parser during page load for elements that have identical attributes. This | 123 // the parser during page load for elements that have identical attributes. This |
| 125 // is a memory optimization since it's very common for many elements to have | 124 // is a memory optimization since it's very common for many elements to have |
| 126 // duplicate sets of attributes (ex. the same classes). | 125 // duplicate sets of attributes (ex. the same classes). |
| 127 class ShareableElementData final : public ElementData { | 126 class ShareableElementData final : public ElementData { |
| 128 public: | 127 public: |
| 129 static PassRefPtrWillBeRawPtr<ShareableElementData> createWithAttributes(con
st Vector<Attribute>&); | 128 static RawPtr<ShareableElementData> createWithAttributes(const Vector<Attrib
ute>&); |
| 130 | 129 |
| 131 explicit ShareableElementData(const Vector<Attribute>&); | 130 explicit ShareableElementData(const Vector<Attribute>&); |
| 132 explicit ShareableElementData(const UniqueElementData&); | 131 explicit ShareableElementData(const UniqueElementData&); |
| 133 ~ShareableElementData(); | 132 ~ShareableElementData(); |
| 134 | 133 |
| 135 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { ElementData::traceAfterDispatch(visit
or); } | 134 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { ElementData::traceAfterDispatch(visit
or); } |
| 136 | 135 |
| 137 // Add support for placement new as ShareableElementData is not allocated | 136 // Add support for placement new as ShareableElementData is not allocated |
| 138 // with a fixed size. Instead the allocated memory size is computed based on | 137 // with a fixed size. Instead the allocated memory size is computed based on |
| 139 // the number of attributes. This requires us to use Heap::allocate directly | 138 // the number of attributes. This requires us to use Heap::allocate directly |
| (...skipping 16 matching lines...) Expand all Loading... |
| 156 #endif | 155 #endif |
| 157 | 156 |
| 158 // UniqueElementData is created when an element needs to mutate its attributes | 157 // UniqueElementData is created when an element needs to mutate its attributes |
| 159 // or gains presentation attribute style (ex. width="10"). It does not need to | 158 // or gains presentation attribute style (ex. width="10"). It does not need to |
| 160 // be created to fill in values in the ElementData that are derived from | 159 // be created to fill in values in the ElementData that are derived from |
| 161 // attributes. For example populating the m_inlineStyle from the style attribute | 160 // attributes. For example populating the m_inlineStyle from the style attribute |
| 162 // doesn't require a UniqueElementData as all elements with the same style | 161 // doesn't require a UniqueElementData as all elements with the same style |
| 163 // attribute will have the same inline style. | 162 // attribute will have the same inline style. |
| 164 class UniqueElementData final : public ElementData { | 163 class UniqueElementData final : public ElementData { |
| 165 public: | 164 public: |
| 166 static PassRefPtrWillBeRawPtr<UniqueElementData> create(); | 165 static RawPtr<UniqueElementData> create(); |
| 167 PassRefPtrWillBeRawPtr<ShareableElementData> makeShareableCopy() const; | 166 RawPtr<ShareableElementData> makeShareableCopy() const; |
| 168 | 167 |
| 169 MutableAttributeCollection attributes(); | 168 MutableAttributeCollection attributes(); |
| 170 AttributeCollection attributes() const; | 169 AttributeCollection attributes() const; |
| 171 | 170 |
| 172 UniqueElementData(); | 171 UniqueElementData(); |
| 173 explicit UniqueElementData(const ShareableElementData&); | 172 explicit UniqueElementData(const ShareableElementData&); |
| 174 explicit UniqueElementData(const UniqueElementData&); | 173 explicit UniqueElementData(const UniqueElementData&); |
| 175 | 174 |
| 176 DECLARE_TRACE_AFTER_DISPATCH(); | 175 DECLARE_TRACE_AFTER_DISPATCH(); |
| 177 | 176 |
| 178 // FIXME: We might want to support sharing element data for elements with | 177 // FIXME: We might want to support sharing element data for elements with |
| 179 // presentation attribute style. Lots of table cells likely have the same | 178 // presentation attribute style. Lots of table cells likely have the same |
| 180 // attributes. Most modern pages don't use presentation attributes though | 179 // attributes. Most modern pages don't use presentation attributes though |
| 181 // so this might not make sense. | 180 // so this might not make sense. |
| 182 mutable RefPtrWillBeMember<StylePropertySet> m_presentationAttributeStyle; | 181 mutable Member<StylePropertySet> m_presentationAttributeStyle; |
| 183 AttributeVector m_attributeVector; | 182 AttributeVector m_attributeVector; |
| 184 }; | 183 }; |
| 185 | 184 |
| 186 DEFINE_ELEMENT_DATA_TYPE_CASTS(UniqueElementData, data->isUnique(), data.isUniqu
e()); | 185 DEFINE_ELEMENT_DATA_TYPE_CASTS(UniqueElementData, data->isUnique(), data.isUniqu
e()); |
| 187 | 186 |
| 188 #if !ENABLE(OILPAN) | 187 #if !ENABLE(OILPAN) |
| 189 inline void ElementData::deref() | 188 inline void ElementData::deref() |
| 190 { | 189 { |
| 191 if (!derefBase()) | 190 if (!derefBase()) |
| 192 return; | 191 return; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 219 } | 218 } |
| 220 | 219 |
| 221 inline MutableAttributeCollection UniqueElementData::attributes() | 220 inline MutableAttributeCollection UniqueElementData::attributes() |
| 222 { | 221 { |
| 223 return MutableAttributeCollection(m_attributeVector); | 222 return MutableAttributeCollection(m_attributeVector); |
| 224 } | 223 } |
| 225 | 224 |
| 226 } // namespace blink | 225 } // namespace blink |
| 227 | 226 |
| 228 #endif // ElementData_h | 227 #endif // ElementData_h |
| OLD | NEW |