Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #ifndef CSSValue_h | 21 #ifndef CSSValue_h |
| 22 #define CSSValue_h | 22 #define CSSValue_h |
| 23 | 23 |
| 24 #include "core/CoreExport.h" | 24 #include "core/CoreExport.h" |
| 25 #include "core/css/CSSValueObject.h" | |
| 25 #include "platform/heap/Handle.h" | 26 #include "platform/heap/Handle.h" |
| 26 #include "platform/weborigin/KURL.h" | |
| 27 #include "wtf/HashMap.h" | |
| 28 #include "wtf/ListHashSet.h" | |
| 29 #include "wtf/RefCounted.h" | 27 #include "wtf/RefCounted.h" |
| 30 #include "wtf/RefPtr.h" | 28 #include "wtf/RefPtr.h" |
| 31 | 29 |
| 32 namespace blink { | 30 namespace blink { |
| 33 | 31 |
| 34 class CORE_EXPORT CSSValue : public RefCountedWillBeGarbageCollectedFinalized<CS SValue> { | 32 // A non-nullable container for CSSValueObject. Takes ownership of the passed |
| 33 // CSSValueObject. | |
| 34 class CORE_EXPORT CSSValue { | |
| 35 ALLOW_ONLY_INLINE_ALLOCATION(); | |
| 36 friend class NullableCSSValue; | |
| 35 public: | 37 public: |
| 36 #if ENABLE(OILPAN) | 38 // Not explicit to allow for casting. |
| 37 // Override operator new to allocate CSSValue subtype objects onto | 39 CSSValue(const CSSValueObject& cssValueObject) |
| 38 // a dedicated heap. | 40 : m_data(const_cast<CSSValueObject*>(&cssValueObject)) |
| 39 GC_PLUGIN_IGNORE("crbug.com/443854") | 41 { |
| 40 void* operator new(size_t size) | 42 ASSERT(m_data); |
| 41 { | 43 ref(); |
| 42 return allocateObject(size); | 44 } |
| 43 } | 45 |
| 44 static void* allocateObject(size_t size) | 46 // TODO(sashab): Remove these; construction should only be available with |
| 45 { | 47 // CSSValueObject&. |
| 46 ThreadState* state = ThreadStateFor<ThreadingTrait<CSSValue>::Affinity>: :state(); | 48 template<class T> CSSValue(PassRefPtrWillBeRawPtr<T> cssValueObject) |
| 47 return Heap::allocateOnHeapIndex(state, size, CSSValueHeapIndex, GCInfoT rait<CSSValue>::index()); | 49 : m_data(cssValueObject.leakRef()) |
| 48 } | 50 { |
| 49 #else | 51 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must be a container for CSSValueObject"); |
| 50 // Override RefCounted's deref() to ensure operator delete is called on | 52 ASSERT(m_data); |
| 51 // the appropriate subclass type. | 53 } |
| 52 void deref() | 54 |
| 53 { | 55 #if !ENABLE(OILPAN) |
| 54 if (derefBase()) | 56 template<class T> CSSValue(RefPtrWillBeRawPtr<T> cssValueObject) |
| 55 destroy(); | 57 : m_data(cssValueObject.release().leakRef()) |
| 56 } | 58 { |
| 57 #endif // !ENABLE(OILPAN) | 59 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must be a container for CSSValueObject"); |
| 58 | 60 ASSERT(m_data); |
| 59 String cssText() const; | 61 } |
| 60 | 62 #endif |
| 61 bool isPrimitiveValue() const { return m_classType == PrimitiveClass; } | 63 |
| 62 bool isValueList() const { return m_classType >= ValueListClass; } | 64 CSSValue(const CSSValue& cssValue) |
| 63 | 65 : m_data(cssValue.m_data) |
| 64 bool isBaseValueList() const { return m_classType == ValueListClass; } | 66 { |
| 65 | 67 ref(); |
| 66 bool isBorderImageSliceValue() const { return m_classType == BorderImageSlic eClass; } | 68 } |
| 67 bool isCanvasValue() const { return m_classType == CanvasClass; } | 69 |
| 68 bool isCursorImageValue() const { return m_classType == CursorImageClass; } | 70 ~CSSValue() |
| 69 bool isCrossfadeValue() const { return m_classType == CrossfadeClass; } | 71 { |
| 70 bool isFontFeatureValue() const { return m_classType == FontFeatureClass; } | 72 deref(); |
| 71 bool isFontFaceSrcValue() const { return m_classType == FontFaceSrcClass; } | 73 } |
| 72 bool isFunctionValue() const { return m_classType == FunctionClass; } | 74 |
| 73 bool isImageGeneratorValue() const { return m_classType >= CanvasClass && m_ classType <= RadialGradientClass; } | 75 CSSValue& operator=(const CSSValue& rhs) |
| 74 bool isGradientValue() const { return m_classType >= LinearGradientClass && m_classType <= RadialGradientClass; } | 76 { |
| 75 bool isImageSetValue() const { return m_classType == ImageSetClass; } | 77 rhs.ref(); |
| 76 bool isImageValue() const { return m_classType == ImageClass; } | 78 deref(); |
| 77 bool isImplicitInitialValue() const; | 79 m_data = rhs.m_data; |
| 78 bool isInheritedValue() const { return m_classType == InheritedClass; } | 80 return *this; |
| 79 bool isInitialValue() const { return m_classType == InitialClass; } | 81 } |
| 80 bool isUnsetValue() const { return m_classType == UnsetClass; } | 82 |
| 81 bool isCSSWideKeyword() const { return m_classType >= InheritedClass && m_cl assType <= UnsetClass; } | 83 bool operator==(const CSSValue& other) const |
| 82 bool isLinearGradientValue() const { return m_classType == LinearGradientCla ss; } | 84 { |
| 83 bool isPathValue() const { return m_classType == PathClass; } | 85 return m_data->equals(*other.m_data); |
| 84 bool isRadialGradientValue() const { return m_classType == RadialGradientCla ss; } | 86 } |
| 85 bool isReflectValue() const { return m_classType == ReflectClass; } | 87 |
| 86 bool isShadowValue() const { return m_classType == ShadowClass; } | 88 // TODO: Remove this and update callsites to use operator== instead. |
| 87 bool isCubicBezierTimingFunctionValue() const { return m_classType == CubicB ezierTimingFunctionClass; } | 89 bool equals(const CSSValue& other) const |
| 88 bool isStepsTimingFunctionValue() const { return m_classType == StepsTimingF unctionClass; } | 90 { |
| 89 bool isLineBoxContainValue() const { return m_classType == LineBoxContainCla ss; } | 91 return m_data->equals(*other.m_data); |
| 90 bool isCalcValue() const {return m_classType == CalculationClass; } | 92 } |
| 91 bool isGridTemplateAreasValue() const { return m_classType == GridTemplateAr easClass; } | 93 |
| 92 bool isSVGDocumentValue() const { return m_classType == CSSSVGDocumentClass; } | 94 bool ptrEquals(const CSSValue& other) const |
| 93 bool isContentDistributionValue() const { return m_classType == CSSContentDi stributionClass; } | 95 { |
| 94 bool isUnicodeRangeValue() const { return m_classType == UnicodeRangeClass; } | 96 return m_data == other.m_data; |
| 95 bool isGridLineNamesValue() const { return m_classType == GridLineNamesClass ; } | 97 } |
| 96 | 98 |
| 97 bool hasFailedOrCanceledSubresources() const; | 99 // Methods that proxy to CSSValueObject. |
| 98 | 100 String cssText() const { return m_data->cssText(); } |
| 99 bool equals(const CSSValue&) const; | 101 bool hasFailedOrCanceledSubresources() const { return m_data->hasFailedOrCan celedSubresources(); }; |
| 100 | 102 bool isPrimitiveValue() const { return m_data->isPrimitiveValue(); } |
| 101 void finalizeGarbageCollectedObject(); | 103 bool isValueList() const { return m_data->isValueList(); } |
| 102 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { } | 104 bool isBaseValueList() const { return m_data->isBaseValueList(); } |
| 103 DECLARE_TRACE(); | 105 bool isBorderImageSliceValue() const { return m_data->isBorderImageSliceValu e(); } |
| 104 | 106 bool isCanvasValue() const { return m_data->isCanvasValue(); } |
| 105 // ~CSSValue should be public, because non-public ~CSSValue causes C2248 | 107 bool isCursorImageValue() const { return m_data->isCursorImageValue(); } |
| 106 // error: 'blink::CSSValue::~CSSValue' : cannot access protected member | 108 bool isCrossfadeValue() const { return m_data->isCrossfadeValue(); } |
| 107 // declared in class 'blink::CSSValue' when compiling | 109 bool isFontFeatureValue() const { return m_data->isFontFeatureValue(); } |
| 108 // 'source\wtf\refcounted.h' by using msvc. | 110 bool isFontFaceSrcValue() const { return m_data->isFontFaceSrcValue(); } |
| 109 ~CSSValue() { } | 111 bool isFunctionValue() const { return m_data->isFunctionValue(); } |
| 110 | 112 bool isImageGeneratorValue() const { return m_data->isImageGeneratorValue(); } |
| 111 protected: | 113 bool isGradientValue() const { return m_data->isGradientValue(); } |
| 112 | 114 bool isImageSetValue() const { return m_data->isImageSetValue(); } |
| 113 static const size_t ClassTypeBits = 6; | 115 bool isImageValue() const { return m_data->isImageValue(); } |
| 114 enum ClassType { | 116 bool isImplicitInitialValue() const { return m_data->isImplicitInitialValue( ); }; |
| 115 PrimitiveClass, | 117 bool isInheritedValue() const { return m_data->isInheritedValue(); }; |
| 116 | 118 bool isInitialValue() const { return m_data->isInitialValue(); }; |
| 117 // Image classes. | 119 bool isUnsetValue() const { return m_data->isUnsetValue(); }; |
| 118 ImageClass, | 120 bool isCSSWideKeyword() const { return m_data->isCSSWideKeyword(); }; |
| 119 CursorImageClass, | 121 bool isLinearGradientValue() const { return m_data->isLinearGradientValue(); }; |
| 120 | 122 bool isPathValue() const { return m_data->isPathValue(); }; |
| 121 // Image generator classes. | 123 bool isRadialGradientValue() const { return m_data->isRadialGradientValue(); }; |
| 122 CanvasClass, | 124 bool isReflectValue() const { return m_data->isReflectValue(); }; |
| 123 CrossfadeClass, | 125 bool isShadowValue() const { return m_data->isShadowValue(); }; |
| 124 LinearGradientClass, | 126 bool isCubicBezierTimingFunctionValue() const { return m_data->isCubicBezier TimingFunctionValue(); }; |
| 125 RadialGradientClass, | 127 bool isStepsTimingFunctionValue() const { return m_data->isStepsTimingFuncti onValue(); }; |
| 126 | 128 bool isLineBoxContainValue() const { return m_data->isLineBoxContainValue(); }; |
| 127 // Timing function classes. | 129 bool isCalcValue() const { return m_data->isCalcValue(); }; |
| 128 CubicBezierTimingFunctionClass, | 130 bool isGridTemplateAreasValue() const { return m_data->isGridTemplateAreasVa lue(); }; |
| 129 StepsTimingFunctionClass, | 131 bool isSVGDocumentValue() const { return m_data->isSVGDocumentValue(); }; |
| 130 | 132 bool isContentDistributionValue() const { return m_data->isContentDistributi onValue(); }; |
| 131 // Other class types. | 133 bool isUnicodeRangeValue() const { return m_data->isUnicodeRangeValue(); }; |
| 132 BorderImageSliceClass, | 134 bool isGridLineNamesValue() const { return m_data->isGridLineNamesValue(); } ; |
| 133 FontFeatureClass, | 135 |
| 134 FontFaceSrcClass, | 136 DEFINE_INLINE_TRACE() |
| 135 | 137 { |
| 136 InheritedClass, | 138 ASSERT(m_data); |
| 137 InitialClass, | 139 visitor->trace(m_data); |
| 138 UnsetClass, | 140 } |
| 139 | 141 |
| 140 ReflectClass, | 142 private: |
| 141 ShadowClass, | 143 // To ensure these are never called. Without this, the compiler may accident ally call |
| 142 UnicodeRangeClass, | 144 // CSSValue(nullptr) with the CSSValueObject* constructor to store an interm ediate value. |
| 143 LineBoxContainClass, | 145 // e.g. NullableCSSValue n = x ? CSSValue(foo) : nullptr; |
| 144 CalculationClass, | 146 CSSValue() = delete; |
| 145 GridTemplateAreasClass, | 147 CSSValue(std::nullptr_t) = delete; |
| 146 PathClass, | 148 |
| 147 | 149 void ref() const |
| 148 // SVG classes. | 150 { |
| 149 CSSSVGDocumentClass, | 151 #if !ENABLE(OILPAN) |
| 150 | 152 if (m_data) |
| 151 CSSContentDistributionClass, | 153 m_data->ref(); |
| 152 | 154 #endif |
| 153 // List class types must appear after ValueListClass. | 155 } |
| 154 ValueListClass, | 156 |
| 155 FunctionClass, | 157 void deref() const |
| 156 ImageSetClass, | 158 { |
| 157 GridLineNamesClass, | 159 #if !ENABLE(OILPAN) |
| 158 // Do not append non-list class types here. | 160 if (m_data) |
| 161 m_data->deref(); | |
| 162 #endif | |
| 163 } | |
| 164 | |
| 165 RawPtrWillBeMember<CSSValueObject> m_data; | |
| 166 }; | |
| 167 | |
| 168 // A nullable container for CSSValueObject. Contents are the same as CSSValue. | |
| 169 // Behavior is similar to a CSSValue*. | |
| 170 class CORE_EXPORT NullableCSSValue { | |
| 171 ALLOW_ONLY_INLINE_ALLOCATION(); | |
| 172 public: | |
| 173 // Not explicit to allow for casting. | |
| 174 NullableCSSValue() | |
| 175 : m_data(nullptr) | |
| 176 { | |
| 177 } | |
| 178 | |
| 179 NullableCSSValue(const CSSValueObject* cssValueObject) | |
| 180 : m_data(const_cast<CSSValueObject*>(cssValueObject)) | |
| 181 { | |
| 182 ref(); | |
| 183 } | |
| 184 | |
| 185 NullableCSSValue(const CSSValueObject& cssValueObject) | |
| 186 : m_data(const_cast<CSSValueObject*>(&cssValueObject)) | |
| 187 { | |
| 188 ref(); | |
| 189 } | |
| 190 | |
| 191 // TODO(sashab): Remove these; construction should only be available with | |
| 192 // CSSValueObject& or CSSValueObject*. | |
| 193 template <class T> NullableCSSValue(PassRefPtrWillBeRawPtr<T> cssValueObject ) | |
| 194 : m_data(cssValueObject.leakRef()) | |
| 195 { | |
| 196 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must be a container for CSSValueObject"); | |
| 197 } | |
| 198 | |
| 199 #if !ENABLE(OILPAN) | |
| 200 template <class T> NullableCSSValue(RefPtrWillBeRawPtr<T> cssValueObject) | |
| 201 : m_data(cssValueObject.release().leakRef()) | |
| 202 { | |
| 203 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must be a container for CSSValueObject"); | |
| 204 } | |
| 205 #endif | |
| 206 | |
| 207 NullableCSSValue(const NullableCSSValue& cssValue) | |
| 208 : m_data(cssValue.m_data) | |
| 209 { | |
| 210 ref(); | |
| 211 } | |
| 212 | |
| 213 NullableCSSValue(const CSSValue& cssValue) | |
| 214 : m_data(cssValue.m_data) | |
| 215 { | |
| 216 ref(); | |
| 217 } | |
| 218 | |
| 219 ~NullableCSSValue() | |
| 220 { | |
| 221 deref(); | |
| 159 }; | 222 }; |
| 160 | 223 |
| 161 static const size_t ValueListSeparatorBits = 2; | 224 operator bool() const |
| 162 enum ValueListSeparator { | 225 { |
| 163 SpaceSeparator, | 226 return m_data; |
| 164 CommaSeparator, | 227 } |
| 165 SlashSeparator | 228 |
| 166 }; | 229 NullableCSSValue& operator=(const NullableCSSValue& rhs) |
| 167 | 230 { |
| 168 ClassType classType() const { return static_cast<ClassType>(m_classType); } | 231 rhs.ref(); |
| 169 | 232 deref(); |
| 170 explicit CSSValue(ClassType classType) | 233 m_data = rhs.m_data; |
| 171 : m_primitiveUnitType(0) | 234 return *this; |
| 172 , m_hasCachedCSSText(false) | 235 } |
| 173 , m_isQuirkValue(false) | 236 |
| 174 , m_valueListSeparator(SpaceSeparator) | 237 bool operator==(const NullableCSSValue& rhs) |
| 175 , m_classType(classType) | 238 { |
| 176 { | 239 return m_data ? rhs.m_data && m_data->equals(*rhs.m_data) : bool(rhs.m_d ata); |
| 177 } | 240 } |
| 178 | 241 |
| 179 // NOTE: This class is non-virtual for memory and performance reasons. | 242 bool operator!=(const NullableCSSValue& rhs) |
| 180 // Don't go making it virtual again unless you know exactly what you're doin g! | 243 { |
| 244 return !(*this == rhs); | |
| 245 } | |
| 246 | |
| 247 CSSValue& operator*() | |
| 248 { | |
| 249 ASSERT(m_data); | |
| 250 // reinterpret_casts used to avoid ref-churn. | |
| 251 return *reinterpret_cast<CSSValue*>(this); | |
| 252 } | |
| 253 | |
| 254 const CSSValue& operator*() const | |
| 255 { | |
| 256 ASSERT(m_data); | |
| 257 return *reinterpret_cast<const CSSValue*>(this); | |
| 258 } | |
| 259 | |
| 260 CSSValue* operator->() | |
| 261 { | |
| 262 ASSERT(m_data); | |
| 263 return reinterpret_cast<CSSValue*>(this); | |
| 264 } | |
| 265 | |
| 266 const CSSValue* operator->() const | |
| 267 { | |
| 268 ASSERT(m_data); | |
| 269 return reinterpret_cast<const CSSValue*>(this); | |
| 270 } | |
| 271 | |
| 272 void swap(NullableCSSValue& rhs) | |
| 273 { | |
| 274 std::swap(this->m_data, rhs.m_data); | |
| 275 } | |
| 276 | |
| 277 DEFINE_INLINE_TRACE() | |
| 278 { | |
| 279 visitor->trace(m_data); | |
| 280 } | |
| 181 | 281 |
| 182 private: | 282 private: |
| 183 void destroy(); | 283 void ref() const |
| 184 | 284 { |
| 185 protected: | 285 #if !ENABLE(OILPAN) |
| 186 // The bits in this section are only used by specific subclasses but kept he re | 286 if (m_data) |
| 187 // to maximize struct packing. | 287 m_data->ref(); |
| 188 | 288 #endif |
| 189 // CSSPrimitiveValue bits: | 289 } |
| 190 unsigned m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitType | 290 |
| 191 mutable unsigned m_hasCachedCSSText : 1; | 291 void deref() const |
| 192 unsigned m_isQuirkValue : 1; | 292 { |
| 193 | 293 #if !ENABLE(OILPAN) |
| 194 unsigned m_valueListSeparator : ValueListSeparatorBits; | 294 if (m_data) |
| 195 | 295 m_data->deref(); |
| 196 private: | 296 #endif |
| 197 unsigned m_classType : ClassTypeBits; // ClassType | 297 } |
| 298 | |
| 299 RawPtrWillBeMember<CSSValueObject> m_data; | |
| 198 }; | 300 }; |
| 199 | 301 |
| 200 template<typename CSSValueType, size_t inlineCapacity> | 302 static_assert(sizeof(CSSValue) == sizeof(void*), "CSSValue should be pointer-siz ed"); |
| 201 inline bool compareCSSValueVector(const WillBeHeapVector<RefPtrWillBeMember<CSSV alueType>, inlineCapacity>& firstVector, const WillBeHeapVector<RefPtrWillBeMemb er<CSSValueType>, inlineCapacity>& secondVector) | 303 static_assert(sizeof(NullableCSSValue) == sizeof(void*), "CSSValue should be poi nter-sized"); |
| 304 static_assert(sizeof(CSSValue) == sizeof(NullableCSSValue), "Both CSSValue conta iners must contain the same data"); | |
| 305 | |
| 306 template<size_t inlineCapacity> | |
| 307 inline bool compareCSSValueVector(const WillBeHeapVector<CSSValue, inlineCapacit y>& firstVector, const WillBeHeapVector<CSSValue, inlineCapacity>& secondVector) | |
| 202 { | 308 { |
| 203 size_t size = firstVector.size(); | 309 size_t size = firstVector.size(); |
| 204 if (size != secondVector.size()) | 310 if (size != secondVector.size()) |
| 205 return false; | 311 return false; |
| 206 | 312 |
| 207 for (size_t i = 0; i < size; i++) { | 313 for (size_t i = 0; i < size; i++) { |
| 208 const RefPtrWillBeMember<CSSValueType>& firstPtr = firstVector[i]; | 314 const CSSValue& firstPtr = firstVector[i]; |
| 209 const RefPtrWillBeMember<CSSValueType>& secondPtr = secondVector[i]; | 315 const CSSValue& secondPtr = secondVector[i]; |
| 210 if (firstPtr == secondPtr || (firstPtr && secondPtr && firstPtr->equals( *secondPtr))) | 316 if (firstPtr.ptrEquals(secondPtr) || firstPtr.equals(secondPtr)) |
| 211 continue; | 317 continue; |
| 212 return false; | 318 return false; |
| 213 } | 319 } |
| 214 return true; | 320 return true; |
| 215 } | 321 } |
| 216 | 322 |
| 217 template<typename CSSValueType> | |
| 218 inline bool compareCSSValuePtr(const RefPtr<CSSValueType>& first, const RefPtr<C SSValueType>& second) | |
| 219 { | |
| 220 return first ? second && first->equals(*second) : !second; | |
| 221 } | |
| 222 | |
| 223 template<typename CSSValueType> | |
| 224 inline bool compareCSSValuePtr(const RawPtr<CSSValueType>& first, const RawPtr<C SSValueType>& second) | |
| 225 { | |
| 226 return first ? second && first->equals(*second) : !second; | |
| 227 } | |
| 228 | |
| 229 template<typename CSSValueType> | |
| 230 inline bool compareCSSValuePtr(const Member<CSSValueType>& first, const Member<C SSValueType>& second) | |
| 231 { | |
| 232 return first ? second && first->equals(*second) : !second; | |
| 233 } | |
| 234 | |
| 235 #define DEFINE_CSS_VALUE_TYPE_CASTS(thisType, predicate) \ | 323 #define DEFINE_CSS_VALUE_TYPE_CASTS(thisType, predicate) \ |
| 236 DEFINE_TYPE_CASTS(thisType, CSSValue, value, value->predicate, value.predica te) | 324 DEFINE_TYPE_CASTS(thisType, CSSValueObject, value, value->predicate, value.p redicate); \ |
| 325 inline thisType& to##thisType(CSSValue value) \ | |
| 326 { \ | |
| 327 ASSERT_WITH_SECURITY_IMPLICATION(value.predicate); \ | |
| 328 return **reinterpret_cast<thisType**>(&value); \ | |
| 329 } \ | |
| 330 inline thisType* to##thisType(NullableCSSValue value) \ | |
| 331 { \ | |
| 332 if (!value) \ | |
| 333 return nullptr; \ | |
| 334 ASSERT_WITH_SECURITY_IMPLICATION(value->predicate); \ | |
| 335 return *reinterpret_cast<thisType**>(&value); \ | |
| 336 } | |
| 237 | 337 |
| 238 } // namespace blink | 338 } // namespace blink |
| 239 | 339 |
| 340 | |
| 341 // Mark CSSValue as canInitializeWithMemset due to HeapVector constraints (see c omment in TraceTraits.h). | |
| 342 // This is nasty because CSSValue::m_data cannot be 0, but is safe because no Ve ctor needs to initialize CSSValue with memset. | |
| 343 // TODO(haraken): Remove this hack. | |
| 344 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::CSSValue); | |
|
sof
2015/06/15 06:06:05
WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS()
sashab
2015/06/16 21:26:38
Oh nice; done. I guess the comment/todos aren't ne
haraken
2015/06/16 22:10:00
Yes, you can now remove the comment.
| |
| 345 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::NullableCSSValue); | |
| 346 | |
| 240 #endif // CSSValue_h | 347 #endif // CSSValue_h |
| OLD | NEW |