Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: Source/core/css/CSSValue.h

Issue 1225553002: CSSValue Immediates: Make CSSPrimitiveValue a container (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_1
Patch Set: Rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/CSSShadowValue.cpp ('k') | Source/core/css/CSSValueObject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
(...skipping 25 matching lines...) Expand all
60 ASSERT(m_data); 61 ASSERT(m_data);
61 } 62 }
62 #endif 63 #endif
63 64
64 CSSValue(const CSSValue& cssValue) 65 CSSValue(const CSSValue& cssValue)
65 : m_data(cssValue.m_data) 66 : m_data(cssValue.m_data)
66 { 67 {
67 ref(); 68 ref();
68 } 69 }
69 70
71 // Implicit conversion from CSSPrimitiveValue.
72 CSSValue(CSSPrimitiveValue cssPrimitiveValue)
73 : m_data(static_cast<CSSValueObject*>(cssPrimitiveValue.get()))
74 {
75 ref();
76 }
77
70 ~CSSValue() 78 ~CSSValue()
71 { 79 {
72 deref(); 80 deref();
73 } 81 }
74 82
75 CSSValue& operator=(const CSSValue& rhs) 83 CSSValue& operator=(const CSSValue& rhs)
76 { 84 {
77 rhs.ref(); 85 rhs.ref();
78 deref(); 86 deref();
79 m_data = rhs.m_data; 87 m_data = rhs.m_data;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 { 222 {
215 ref(); 223 ref();
216 } 224 }
217 225
218 NullableCSSValue(const CSSValue& cssValue) 226 NullableCSSValue(const CSSValue& cssValue)
219 : m_data(cssValue.m_data) 227 : m_data(cssValue.m_data)
220 { 228 {
221 ref(); 229 ref();
222 } 230 }
223 231
232 // Implicit conversion from CSSPrimitiveValue.
233 NullableCSSValue(CSSPrimitiveValue cssPrimitiveValue)
234 : m_data(static_cast<CSSValueObject*>(cssPrimitiveValue.get()))
235 {
236 ref();
237 }
238
224 ~NullableCSSValue() 239 ~NullableCSSValue()
225 { 240 {
226 deref(); 241 deref();
227 }; 242 };
228 243
229 operator bool() const 244 explicit operator bool() const
230 { 245 {
231 return m_data; 246 return m_data;
232 } 247 }
233 248
234 NullableCSSValue& operator=(const NullableCSSValue& rhs) 249 NullableCSSValue& operator=(const NullableCSSValue& rhs)
235 { 250 {
236 rhs.ref(); 251 rhs.ref();
237 deref(); 252 deref();
238 m_data = rhs.m_data; 253 m_data = rhs.m_data;
239 return *this; 254 return *this;
240 } 255 }
241 256
242 bool operator==(const NullableCSSValue& rhs) 257 bool operator==(const NullableCSSValue& rhs) const
243 { 258 {
244 return m_data ? rhs.m_data && m_data->equals(*rhs.m_data) : !bool(rhs.m_ data); 259 return m_data ? rhs.m_data && m_data->equals(*rhs.m_data) : !bool(rhs.m_ data);
245 } 260 }
246 261
247 bool operator!=(const NullableCSSValue& rhs) 262 bool operator!=(const NullableCSSValue& rhs) const
248 { 263 {
249 return !(*this == rhs); 264 return !(*this == rhs);
250 } 265 }
251 266
252 CSSValue& operator*() 267 CSSValue& operator*()
253 { 268 {
254 ASSERT(m_data); 269 ASSERT(m_data);
255 // reinterpret_casts used to avoid ref-churn. 270 // reinterpret_casts used to avoid ref-churn.
256 return *reinterpret_cast<CSSValue*>(this); 271 return *reinterpret_cast<CSSValue*>(this);
257 } 272 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 return *static_cast<thisType*>(value.get()); \ 356 return *static_cast<thisType*>(value.get()); \
342 } \ 357 } \
343 inline thisType* to##thisType(const NullableCSSValue& value) \ 358 inline thisType* to##thisType(const NullableCSSValue& value) \
344 { \ 359 { \
345 if (!value) \ 360 if (!value) \
346 return nullptr; \ 361 return nullptr; \
347 ASSERT_WITH_SECURITY_IMPLICATION(value->predicate); \ 362 ASSERT_WITH_SECURITY_IMPLICATION(value->predicate); \
348 return static_cast<thisType*>(value.get()); \ 363 return static_cast<thisType*>(value.get()); \
349 } 364 }
350 365
366 // Returns by value on purpose.
367 inline CSSPrimitiveValue toCSSPrimitiveValue(const CSSValue& value)
368 {
369 ASSERT_WITH_SECURITY_IMPLICATION(value.isPrimitiveValue());
370 return CSSPrimitiveValue(static_cast<CSSPrimitiveValue::CSSLargePrimitiveVal ue*>(value.get()));
371 }
372
351 } // namespace blink 373 } // namespace blink
352 374
353 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::CSSValue); 375 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::CSSValue);
354 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::NullableCSSValue); 376 WTF_ALLOW_CLEAR_UNUSED_SLOTS_WITH_MEM_FUNCTIONS(blink::NullableCSSValue);
355 377
356 #endif // CSSValue_h 378 #endif // CSSValue_h
OLDNEW
« no previous file with comments | « Source/core/css/CSSShadowValue.cpp ('k') | Source/core/css/CSSValueObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698