| 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/CSSPrimitiveValue.h" |
| 25 #include "core/css/CSSValueObject.h" | 26 #include "core/css/CSSValueObject.h" |
| 26 #include "platform/heap/Handle.h" | 27 #include "platform/heap/Handle.h" |
| 27 #include "wtf/RefCounted.h" | 28 #include "wtf/RefCounted.h" |
| 28 #include "wtf/RefPtr.h" | 29 #include "wtf/RefPtr.h" |
| 29 | 30 |
| 30 namespace blink { | 31 namespace blink { |
| 31 | 32 |
| 32 // A non-nullable container for CSSValueObject. Takes ownership of the passed | 33 // A non-nullable container for CSSValueObject. Takes ownership of the passed |
| 33 // CSSValueObject. | 34 // CSSValueObject. |
| 34 class CORE_EXPORT CSSValue { | 35 class CORE_EXPORT CSSValue { |
| 35 ALLOW_ONLY_INLINE_ALLOCATION(); | 36 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 36 friend class NullableCSSValue; | 37 friend class NullableCSSValue; |
| 37 public: | 38 public: |
| 38 // Not explicit to allow for casting. | 39 // Not explicit to allow for casting. |
| 39 CSSValue(const CSSValueObject& cssValueObject) | 40 CSSValue(const CSSValueObject& cssValueObject) |
| 40 : m_data(const_cast<CSSValueObject*>(&cssValueObject)) | 41 : m_data(const_cast<CSSValueObject*>(&cssValueObject)) |
| 41 { | 42 { |
| 42 ASSERT(m_data); | 43 ASSERT(m_data); |
| 44 ASSERT(isObject()); |
| 43 ref(); | 45 ref(); |
| 44 } | 46 } |
| 45 | 47 |
| 46 // TODO(sashab): Remove these; construction should only be available with | 48 // TODO(sashab): Remove these; construction should only be available with |
| 47 // CSSValueObject&. | 49 // CSSValueObject&. |
| 48 template<class T> CSSValue(PassRefPtrWillBeRawPtr<T> cssValueObject) | 50 template<class T> CSSValue(PassRefPtrWillBeRawPtr<T> cssValueObject) |
| 49 : m_data(cssValueObject.leakRef()) | 51 : m_data(cssValueObject.leakRef()) |
| 50 { | 52 { |
| 51 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must
be a container for CSSValueObject"); | 53 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must
be a container for CSSValueObject"); |
| 54 ASSERT(isObject()); |
| 52 ASSERT(m_data); | 55 ASSERT(m_data); |
| 53 } | 56 } |
| 54 | 57 |
| 55 #if !ENABLE(OILPAN) | 58 #if !ENABLE(OILPAN) |
| 56 template<class T> CSSValue(RefPtrWillBeRawPtr<T> cssValueObject) | 59 template<class T> CSSValue(RefPtrWillBeRawPtr<T> cssValueObject) |
| 57 : m_data(cssValueObject.release().leakRef()) | 60 : m_data(cssValueObject.release().leakRef()) |
| 58 { | 61 { |
| 59 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must
be a container for CSSValueObject"); | 62 static_assert(WTF::IsSubclass<T, CSSValueObject>::value, "Parameter must
be a container for CSSValueObject"); |
| 63 ASSERT(isObject()); |
| 60 ASSERT(m_data); | 64 ASSERT(m_data); |
| 61 } | 65 } |
| 62 #endif | 66 #endif |
| 63 | 67 |
| 64 CSSValue(const CSSValue& cssValue) | 68 CSSValue(const CSSValue& cssValue) |
| 65 : m_data(cssValue.m_data) | 69 : m_data(cssValue.m_data) |
| 66 { | 70 { |
| 67 ref(); | 71 ref(); |
| 68 } | 72 } |
| 69 | 73 |
| 74 // Implicit conversion from CSSPrimitiveValue. |
| 75 CSSValue(const CSSPrimitiveValue& cssPrimitiveValue) |
| 76 : m_data(static_cast<CSSValueObject*>(cssPrimitiveValue.get())) |
| 77 { |
| 78 ref(); |
| 79 } |
| 80 |
| 70 ~CSSValue() | 81 ~CSSValue() |
| 71 { | 82 { |
| 72 // Although m_data can't be null, a move constructor from NullableCSSVal
ue | 83 // Although m_data can't be null, a move constructor from NullableCSSVal
ue |
| 73 // could make it null for a short time. | 84 // could make it null for a short time. |
| 74 if (m_data) | 85 if (m_data) |
| 75 deref(); | 86 deref(); |
| 76 | 87 |
| 77 } | 88 } |
| 78 | 89 |
| 79 CSSValue& operator=(const CSSValue& rhs) | 90 CSSValue& operator=(const CSSValue& rhs) |
| 80 { | 91 { |
| 81 rhs.ref(); | 92 rhs.ref(); |
| 82 deref(); | 93 deref(); |
| 83 m_data = rhs.m_data; | 94 m_data = rhs.m_data; |
| 84 return *this; | 95 return *this; |
| 85 } | 96 } |
| 86 | 97 |
| 87 CSSValue& operator=(CSSValue&& rhs) | 98 CSSValue& operator=(CSSValue&& rhs) |
| 88 { | 99 { |
| 89 m_data = rhs.m_data; | 100 m_data = rhs.m_data; |
| 90 rhs.m_data.clear(); | 101 rhs.m_data.clear(); |
| 91 return *this; | 102 return *this; |
| 92 } | 103 } |
| 93 | 104 |
| 94 CSSValue(CSSValue&& rhs) | 105 CSSValue(CSSValue&& rhs) |
| 106 : m_data(rhs.m_data) |
| 95 { | 107 { |
| 96 m_data = rhs.m_data; | 108 rhs.m_data.clear(); |
| 97 } | 109 } |
| 98 | 110 |
| 99 bool operator==(const CSSValue& other) const | 111 bool operator==(const CSSValue& other) const |
| 100 { | 112 { |
| 113 if (m_data == other.m_data) |
| 114 return true; |
| 115 if (!isObject() || !other.isObject()) |
| 116 return false; |
| 101 return m_data->equals(*other.m_data); | 117 return m_data->equals(*other.m_data); |
| 102 } | 118 } |
| 103 | 119 |
| 104 // TODO: Remove this and update callsites to use operator== instead. | 120 // TODO: Remove this and update callsites to use operator== instead. |
| 105 bool equals(const CSSValue& other) const | 121 bool equals(const CSSValue& other) const |
| 106 { | 122 { |
| 123 if (m_data == other.m_data) |
| 124 return true; |
| 125 if (!isObject() || !other.isObject()) |
| 126 return false; |
| 107 return m_data->equals(*other.m_data); | 127 return m_data->equals(*other.m_data); |
| 108 } | 128 } |
| 109 | 129 |
| 110 bool ptrEquals(const CSSValue& other) const | 130 bool ptrEquals(const CSSValue& other) const |
| 111 { | 131 { |
| 112 return m_data == other.m_data; | 132 return m_data == other.m_data; |
| 113 } | 133 } |
| 114 | 134 |
| 115 // Methods that proxy to CSSValueObject. | 135 // Methods that proxy to CSSValueObject. |
| 116 String cssText() const { return m_data->cssText(); } | 136 String cssText() const |
| 117 bool hasFailedOrCanceledSubresources() const { return m_data->hasFailedOrCan
celedSubresources(); }; | 137 { |
| 118 bool isPrimitiveValue() const { return m_data->isPrimitiveValue(); } | 138 if (isObject()) |
| 119 bool isValueList() const { return m_data->isValueList(); } | 139 return m_data->cssText(); |
| 120 bool isBaseValueList() const { return m_data->isBaseValueList(); } | 140 return CSSPrimitiveValue(reinterpret_cast<CSSPrimitiveValue::CSSLargePri
mitiveValue*>(m_data.get())).cssText(); |
| 121 bool isBorderImageSliceValue() const { return m_data->isBorderImageSliceValu
e(); } | 141 } |
| 122 bool isCanvasValue() const { return m_data->isCanvasValue(); } | 142 |
| 123 bool isCursorImageValue() const { return m_data->isCursorImageValue(); } | 143 bool hasFailedOrCanceledSubresources() const { return isObject() ? m_data->h
asFailedOrCanceledSubresources() : false; }; |
| 124 bool isCrossfadeValue() const { return m_data->isCrossfadeValue(); } | 144 bool isPrimitiveValue() const { return isObject() ? m_data->isPrimitiveValue
() : true; } |
| 125 bool isFontFeatureValue() const { return m_data->isFontFeatureValue(); } | 145 bool isValueList() const { return isObject() ? m_data->isValueList() : false
; } |
| 126 bool isFontFaceSrcValue() const { return m_data->isFontFaceSrcValue(); } | 146 bool isBaseValueList() const { return isObject() ? m_data->isBaseValueList()
: false; } |
| 127 bool isFunctionValue() const { return m_data->isFunctionValue(); } | 147 bool isBorderImageSliceValue() const { return isObject() ? m_data->isBorderI
mageSliceValue() : false; } |
| 128 bool isImageGeneratorValue() const { return m_data->isImageGeneratorValue();
} | 148 bool isCanvasValue() const { return isObject() ? m_data->isCanvasValue() : f
alse; } |
| 129 bool isGradientValue() const { return m_data->isGradientValue(); } | 149 bool isCursorImageValue() const { return isObject() ? m_data->isCursorImageV
alue() : false; } |
| 130 bool isImageSetValue() const { return m_data->isImageSetValue(); } | 150 bool isCrossfadeValue() const { return isObject() ? m_data->isCrossfadeValue
() : false; } |
| 131 bool isImageValue() const { return m_data->isImageValue(); } | 151 bool isFontFeatureValue() const { return isObject() ? m_data->isFontFeatureV
alue(): false; } |
| 132 bool isImplicitInitialValue() const { return m_data->isImplicitInitialValue(
); }; | 152 bool isFontFaceSrcValue() const { return isObject() ? m_data->isFontFaceSrcV
alue(): false; } |
| 133 bool isInheritedValue() const { return m_data->isInheritedValue(); }; | 153 bool isFunctionValue() const { return isObject() ? m_data->isFunctionValue()
: false; } |
| 134 bool isInitialValue() const { return m_data->isInitialValue(); }; | 154 bool isImageGeneratorValue() const { return isObject() ? m_data->isImageGene
ratorValue(): false; } |
| 135 bool isUnsetValue() const { return m_data->isUnsetValue(); }; | 155 bool isGradientValue() const { return isObject() ? m_data->isGradientValue()
: false; } |
| 136 bool isCSSWideKeyword() const { return m_data->isCSSWideKeyword(); }; | 156 bool isImageSetValue() const { return isObject() ? m_data->isImageSetValue()
: false; } |
| 137 bool isLinearGradientValue() const { return m_data->isLinearGradientValue();
}; | 157 bool isImageValue() const { return isObject() ? m_data->isImageValue(): fals
e; } |
| 138 bool isPathValue() const { return m_data->isPathValue(); }; | 158 bool isImplicitInitialValue() const { return isObject() ? m_data->isImplicit
InitialValue(): false; } |
| 139 bool isRadialGradientValue() const { return m_data->isRadialGradientValue();
}; | 159 bool isInheritedValue() const { return isObject() ? m_data->isInheritedValue
(): false; } |
| 140 bool isReflectValue() const { return m_data->isReflectValue(); }; | 160 bool isInitialValue() const { return isObject() ? m_data->isInitialValue():
false; } |
| 141 bool isShadowValue() const { return m_data->isShadowValue(); }; | 161 bool isUnsetValue() const { return isObject() ? m_data->isUnsetValue(): fals
e; } |
| 142 bool isCubicBezierTimingFunctionValue() const { return m_data->isCubicBezier
TimingFunctionValue(); }; | 162 bool isCSSWideKeyword() const { return isObject() ? m_data->isCSSWideKeyword
(): false; } |
| 143 bool isStepsTimingFunctionValue() const { return m_data->isStepsTimingFuncti
onValue(); }; | 163 bool isLinearGradientValue() const { return isObject() ? m_data->isLinearGra
dientValue(): false; } |
| 144 bool isLineBoxContainValue() const { return m_data->isLineBoxContainValue();
}; | 164 bool isPathValue() const { return isObject() ? m_data->isPathValue(): false;
} |
| 145 bool isCalcValue() const { return m_data->isCalcValue(); }; | 165 bool isRadialGradientValue() const { return isObject() ? m_data->isRadialGra
dientValue(): false; } |
| 146 bool isGridTemplateAreasValue() const { return m_data->isGridTemplateAreasVa
lue(); }; | 166 bool isReflectValue() const { return isObject() ? m_data->isReflectValue():
false; } |
| 147 bool isSVGDocumentValue() const { return m_data->isSVGDocumentValue(); }; | 167 bool isShadowValue() const { return isObject() ? m_data->isShadowValue(): fa
lse; } |
| 148 bool isContentDistributionValue() const { return m_data->isContentDistributi
onValue(); }; | 168 bool isCubicBezierTimingFunctionValue() const { return isObject() ? m_data->
isCubicBezierTimingFunctionValue(): false; } |
| 149 bool isUnicodeRangeValue() const { return m_data->isUnicodeRangeValue(); }; | 169 bool isStepsTimingFunctionValue() const { return isObject() ? m_data->isStep
sTimingFunctionValue(): false; } |
| 150 bool isGridLineNamesValue() const { return m_data->isGridLineNamesValue(); }
; | 170 bool isLineBoxContainValue() const { return isObject() ? m_data->isLineBoxCo
ntainValue(): false; } |
| 171 bool isCalcValue() const { return isObject() ? m_data->isCalcValue(): false;
} |
| 172 bool isGridTemplateAreasValue() const { return isObject() ? m_data->isGridTe
mplateAreasValue(): false; } |
| 173 bool isSVGDocumentValue() const { return isObject() ? m_data->isSVGDocumentV
alue(): false; } |
| 174 bool isContentDistributionValue() const { return isObject() ? m_data->isCont
entDistributionValue(): false; } |
| 175 bool isUnicodeRangeValue() const { return isObject() ? m_data->isUnicodeRang
eValue(): false; } |
| 176 bool isGridLineNamesValue() const { return isObject() ? m_data->isGridLineNa
mesValue(): false; } |
| 151 | 177 |
| 152 DEFINE_INLINE_TRACE() | 178 DEFINE_INLINE_TRACE() |
| 153 { | 179 { |
| 154 ASSERT(m_data); | 180 ASSERT(m_data); |
| 155 visitor->trace(m_data); | 181 if (isObject()) |
| 182 visitor->trace(m_data); |
| 156 } | 183 } |
| 157 | 184 |
| 158 // Only for use by the toFooCSSValue() macros. Don't use this. | 185 // Only for use by the toFooCSSValue() macros. Don't use this. |
| 159 // TODO(sashab): Remove this and use value.to<Type> and value.isValid<Type> | 186 // TODO(sashab): Remove this and use value.to<Type> and value.isValid<Type> |
| 160 // like WebNode. | 187 // like WebNode. |
| 161 CSSValueObject* get() const | 188 CSSValueObject* get() const |
| 162 { | 189 { |
| 163 return m_data.get(); | 190 return m_data.get(); |
| 164 } | 191 } |
| 165 | 192 |
| 166 private: | 193 private: |
| 167 CSSValue() = delete; // compile-time guard | 194 CSSValue() = delete; // compile-time guard |
| 168 CSSValue(std::nullptr_t) = delete; // compile-time guard | 195 CSSValue(std::nullptr_t) = delete; // compile-time guard |
| 169 | 196 |
| 170 void ref() const | 197 void ref() const |
| 171 { | 198 { |
| 172 #if !ENABLE(OILPAN) | 199 #if !ENABLE(OILPAN) |
| 173 if (m_data) | 200 if (m_data && isObject()) |
| 174 m_data->ref(); | 201 m_data->ref(); |
| 175 #endif | 202 #endif |
| 176 } | 203 } |
| 177 | 204 |
| 178 void deref() const | 205 void deref() const |
| 179 { | 206 { |
| 180 #if !ENABLE(OILPAN) | 207 #if !ENABLE(OILPAN) |
| 181 if (m_data) | 208 if (m_data && isObject()) |
| 182 m_data->deref(); | 209 m_data->deref(); |
| 183 #endif | 210 #endif |
| 184 } | 211 } |
| 185 | 212 |
| 213 bool isObject() const |
| 214 { |
| 215 return !(*reinterpret_cast<const uintptr_t*>(&m_data) & 1); |
| 216 } |
| 217 |
| 186 RawPtrWillBeMember<CSSValueObject> m_data; | 218 RawPtrWillBeMember<CSSValueObject> m_data; |
| 187 }; | 219 }; |
| 188 | 220 |
| 189 // A nullable container for CSSValueObject. Contents are the same as CSSValue. | 221 // A nullable container for CSSValueObject. Contents are the same as CSSValue. |
| 190 // Behavior is similar to a CSSValue*. | 222 // Behavior is similar to a CSSValue*. |
| 191 class CORE_EXPORT NullableCSSValue { | 223 class CORE_EXPORT NullableCSSValue { |
| 192 ALLOW_ONLY_INLINE_ALLOCATION(); | 224 ALLOW_ONLY_INLINE_ALLOCATION(); |
| 193 public: | 225 public: |
| 194 // Not explicit to allow for casting. | 226 // Not explicit to allow for casting. |
| 195 NullableCSSValue() | 227 NullableCSSValue() |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 ref(); | 263 ref(); |
| 232 } | 264 } |
| 233 | 265 |
| 234 NullableCSSValue(const CSSValue& cssValue) | 266 NullableCSSValue(const CSSValue& cssValue) |
| 235 : m_data(cssValue.m_data) | 267 : m_data(cssValue.m_data) |
| 236 { | 268 { |
| 237 ref(); | 269 ref(); |
| 238 } | 270 } |
| 239 | 271 |
| 240 NullableCSSValue(NullableCSSValue&& rhs) | 272 NullableCSSValue(NullableCSSValue&& rhs) |
| 273 : m_data(rhs.m_data) |
| 241 { | 274 { |
| 242 m_data = rhs.m_data; | 275 rhs.m_data.clear(); |
| 243 rhs.m_data = nullptr; | |
| 244 } | 276 } |
| 245 | 277 |
| 278 // Implicit conversion from CSSPrimitiveValue. |
| 279 NullableCSSValue(const CSSPrimitiveValue& cssPrimitiveValue) |
| 280 : m_data(static_cast<CSSValueObject*>(cssPrimitiveValue.get())) |
| 281 { |
| 282 ref(); |
| 283 } |
| 246 | 284 |
| 247 ~NullableCSSValue() | 285 ~NullableCSSValue() |
| 248 { | 286 { |
| 249 deref(); | 287 deref(); |
| 250 }; | 288 }; |
| 251 | 289 |
| 252 operator bool() const | 290 explicit operator bool() const |
| 253 { | 291 { |
| 254 return m_data; | 292 return m_data; |
| 255 } | 293 } |
| 256 | 294 |
| 257 NullableCSSValue& operator=(const NullableCSSValue& rhs) | 295 NullableCSSValue& operator=(const NullableCSSValue& rhs) |
| 258 { | 296 { |
| 259 rhs.ref(); | 297 rhs.ref(); |
| 260 deref(); | 298 deref(); |
| 261 m_data = rhs.m_data; | 299 m_data = rhs.m_data; |
| 262 return *this; | 300 return *this; |
| 263 } | 301 } |
| 264 | 302 |
| 265 NullableCSSValue& operator=(NullableCSSValue&& rhs) | 303 NullableCSSValue& operator=(NullableCSSValue&& rhs) |
| 266 { | 304 { |
| 267 m_data = rhs.m_data; | 305 m_data = rhs.m_data; |
| 268 rhs.m_data.clear(); | 306 rhs.m_data.clear(); |
| 269 return *this; | 307 return *this; |
| 270 } | 308 } |
| 271 | 309 |
| 272 bool operator==(const NullableCSSValue& rhs) const | 310 bool operator==(const NullableCSSValue& rhs) const |
| 273 { | 311 { |
| 312 if (m_data == rhs.m_data) |
| 313 return true; |
| 314 if (!isObject() || (rhs && !rhs.isObject())) |
| 315 return false; |
| 274 return m_data ? rhs.m_data && m_data->equals(*rhs.m_data) : !bool(rhs.m_
data); | 316 return m_data ? rhs.m_data && m_data->equals(*rhs.m_data) : !bool(rhs.m_
data); |
| 275 } | 317 } |
| 276 | 318 |
| 277 bool operator!=(const NullableCSSValue& rhs) | 319 bool operator!=(const NullableCSSValue& rhs) const |
| 278 { | 320 { |
| 279 return !(*this == rhs); | 321 return !(*this == rhs); |
| 280 } | 322 } |
| 281 | 323 |
| 282 CSSValue& operator*() | 324 CSSValue& operator*() |
| 283 { | 325 { |
| 284 ASSERT(m_data); | 326 ASSERT(m_data); |
| 285 // reinterpret_casts used to avoid ref-churn. | 327 // reinterpret_casts used to avoid ref-churn. |
| 286 return *reinterpret_cast<CSSValue*>(this); | 328 return *reinterpret_cast<CSSValue*>(this); |
| 287 } | 329 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 304 return reinterpret_cast<const CSSValue*>(this); | 346 return reinterpret_cast<const CSSValue*>(this); |
| 305 } | 347 } |
| 306 | 348 |
| 307 void swap(NullableCSSValue& rhs) | 349 void swap(NullableCSSValue& rhs) |
| 308 { | 350 { |
| 309 std::swap(this->m_data, rhs.m_data); | 351 std::swap(this->m_data, rhs.m_data); |
| 310 } | 352 } |
| 311 | 353 |
| 312 DEFINE_INLINE_TRACE() | 354 DEFINE_INLINE_TRACE() |
| 313 { | 355 { |
| 314 visitor->trace(m_data); | 356 if (isObject()) |
| 357 visitor->trace(m_data); |
| 315 } | 358 } |
| 316 | 359 |
| 317 // Only for use by the toFooCSSValue() macros. Don't use this. | 360 // Only for use by the toFooCSSValue() macros. Don't use this. |
| 318 // TODO(sashab): Remove this and use value.to<Type> and value.isValid<Type> | 361 // TODO(sashab): Remove this and use value.to<Type> and value.isValid<Type> |
| 319 // like WebNode. | 362 // like WebNode. |
| 320 CSSValueObject* get() const | 363 CSSValueObject* get() const |
| 321 { | 364 { |
| 322 return m_data.get(); | 365 return m_data.get(); |
| 323 } | 366 } |
| 324 | 367 |
| 325 private: | 368 private: |
| 326 void ref() const | 369 void ref() const |
| 327 { | 370 { |
| 328 #if !ENABLE(OILPAN) | 371 #if !ENABLE(OILPAN) |
| 329 if (m_data) | 372 if (m_data && isObject()) |
| 330 m_data->ref(); | 373 m_data->ref(); |
| 331 #endif | 374 #endif |
| 332 } | 375 } |
| 333 | 376 |
| 334 void deref() const | 377 void deref() const |
| 335 { | 378 { |
| 336 #if !ENABLE(OILPAN) | 379 #if !ENABLE(OILPAN) |
| 337 if (m_data) | 380 if (m_data && isObject()) |
| 338 m_data->deref(); | 381 m_data->deref(); |
| 339 #endif | 382 #endif |
| 340 } | 383 } |
| 341 | 384 |
| 385 bool isObject() const |
| 386 { |
| 387 return !(*reinterpret_cast<const uintptr_t*>(&m_data) & 1); |
| 388 } |
| 389 |
| 342 RawPtrWillBeMember<CSSValueObject> m_data; | 390 RawPtrWillBeMember<CSSValueObject> m_data; |
| 343 }; | 391 }; |
| 344 | 392 |
| 345 static_assert(sizeof(CSSValue) == sizeof(void*), "CSSValue should be pointer-siz
ed"); | 393 static_assert(sizeof(CSSValue) == sizeof(void*), "CSSValue should be pointer-siz
ed"); |
| 346 static_assert(sizeof(NullableCSSValue) == sizeof(void*), "CSSValue should be poi
nter-sized"); | 394 static_assert(sizeof(NullableCSSValue) == sizeof(void*), "CSSValue should be poi
nter-sized"); |
| 347 static_assert(sizeof(CSSValue) == sizeof(NullableCSSValue), "Both CSSValue conta
iners must contain the same data"); | 395 static_assert(sizeof(CSSValue) == sizeof(NullableCSSValue), "Both CSSValue conta
iners must contain the same data"); |
| 396 static_assert(sizeof(CSSValue) == sizeof(CSSPrimitiveValue), "Both CSSValue and
CSSPrimitiveValue must contain the same data"); |
| 348 | 397 |
| 349 template<size_t inlineCapacity> | 398 template<size_t inlineCapacity> |
| 350 inline bool compareCSSValueVector(const WillBeHeapVector<CSSValue, inlineCapacit
y>& firstVector, const WillBeHeapVector<CSSValue, inlineCapacity>& secondVector) | 399 inline bool compareCSSValueVector(const WillBeHeapVector<CSSValue, inlineCapacit
y>& firstVector, const WillBeHeapVector<CSSValue, inlineCapacity>& secondVector) |
| 351 { | 400 { |
| 352 size_t size = firstVector.size(); | 401 size_t size = firstVector.size(); |
| 353 if (size != secondVector.size()) | 402 if (size != secondVector.size()) |
| 354 return false; | 403 return false; |
| 355 | 404 |
| 356 for (size_t i = 0; i < size; i++) { | 405 for (size_t i = 0; i < size; i++) { |
| 357 const CSSValue& firstPtr = firstVector[i]; | 406 const CSSValue& firstPtr = firstVector[i]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 371 return *static_cast<thisType*>(value.get()); \ | 420 return *static_cast<thisType*>(value.get()); \ |
| 372 } \ | 421 } \ |
| 373 inline thisType* to##thisType(const NullableCSSValue& value) \ | 422 inline thisType* to##thisType(const NullableCSSValue& value) \ |
| 374 { \ | 423 { \ |
| 375 if (!value) \ | 424 if (!value) \ |
| 376 return nullptr; \ | 425 return nullptr; \ |
| 377 ASSERT_WITH_SECURITY_IMPLICATION(value->predicate); \ | 426 ASSERT_WITH_SECURITY_IMPLICATION(value->predicate); \ |
| 378 return static_cast<thisType*>(value.get()); \ | 427 return static_cast<thisType*>(value.get()); \ |
| 379 } | 428 } |
| 380 | 429 |
| 430 inline const CSSPrimitiveValue& toCSSPrimitiveValue(const CSSValue& value) |
| 431 { |
| 432 ASSERT_WITH_SECURITY_IMPLICATION(value.isPrimitiveValue()); |
| 433 return *reinterpret_cast<const CSSPrimitiveValue*>(&value); |
| 434 } |
| 435 inline const CSSPrimitiveValue& toCSSPrimitiveValue(const NullableCSSValue& valu
e) |
| 436 { |
| 437 ASSERT_WITH_SECURITY_IMPLICATION(value && value->isPrimitiveValue()); |
| 438 return *reinterpret_cast<const CSSPrimitiveValue*>(&value); |
| 439 } |
| 440 /* |
| 441 inline CSSPrimitiveValue& toCSSPrimitiveValue(const CSSValue& value) |
| 442 { |
| 443 ASSERT_WITH_SECURITY_IMPLICATION(value.isPrimitiveValue()); |
| 444 return *const_cast<CSSPrimitiveValue*>(reinterpret_cast<const CSSPrimitiveVa
lue*>(&value)); |
| 445 } |
| 446 */ |
| 447 |
| 381 } // namespace blink | 448 } // namespace blink |
| 382 | 449 |
| 383 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::CSSValue); | 450 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::CSSValue); |
| 384 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::NullableCSSValue); | 451 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::NullableCSSValue); |
| 385 | 452 |
| 386 #endif // CSSValue_h | 453 #endif // CSSValue_h |
| OLD | NEW |