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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSValuePool.cpp

Issue 1858753003: Remove RawPtr from core/css (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 , m_colorTransparent(CSSColorValue::create(Color::transparent)) 46 , m_colorTransparent(CSSColorValue::create(Color::transparent))
47 , m_colorWhite(CSSColorValue::create(Color::white)) 47 , m_colorWhite(CSSColorValue::create(Color::white))
48 , m_colorBlack(CSSColorValue::create(Color::black)) 48 , m_colorBlack(CSSColorValue::create(Color::black))
49 { 49 {
50 m_identifierValueCache.resize(numCSSValueKeywords); 50 m_identifierValueCache.resize(numCSSValueKeywords);
51 m_pixelValueCache.resize(maximumCacheableIntegerValue + 1); 51 m_pixelValueCache.resize(maximumCacheableIntegerValue + 1);
52 m_percentValueCache.resize(maximumCacheableIntegerValue + 1); 52 m_percentValueCache.resize(maximumCacheableIntegerValue + 1);
53 m_numberValueCache.resize(maximumCacheableIntegerValue + 1); 53 m_numberValueCache.resize(maximumCacheableIntegerValue + 1);
54 } 54 }
55 55
56 RawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ident) 56 CSSPrimitiveValue* CSSValuePool::createIdentifierValue(CSSValueID ident)
57 { 57 {
58 if (ident <= 0) 58 if (ident <= 0)
59 return CSSPrimitiveValue::createIdentifier(ident); 59 return CSSPrimitiveValue::createIdentifier(ident);
60 60
61 if (!m_identifierValueCache[ident]) 61 if (!m_identifierValueCache[ident])
62 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden t); 62 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden t);
63 return m_identifierValueCache[ident]; 63 return m_identifierValueCache[ident];
64 } 64 }
65 65
66 RawPtr<CSSCustomIdentValue> CSSValuePool::createIdentifierValue(CSSPropertyID id ent) 66 CSSCustomIdentValue* CSSValuePool::createIdentifierValue(CSSPropertyID ident)
67 { 67 {
68 return CSSCustomIdentValue::create(ident); 68 return CSSCustomIdentValue::create(ident);
69 } 69 }
70 70
71 RawPtr<CSSColorValue> CSSValuePool::createColorValue(RGBA32 rgbValue) 71 CSSColorValue* CSSValuePool::createColorValue(RGBA32 rgbValue)
72 { 72 {
73 // These are the empty and deleted values of the hash table. 73 // These are the empty and deleted values of the hash table.
74 if (rgbValue == Color::transparent) 74 if (rgbValue == Color::transparent)
75 return m_colorTransparent; 75 return m_colorTransparent;
76 if (rgbValue == Color::white) 76 if (rgbValue == Color::white)
77 return m_colorWhite; 77 return m_colorWhite;
78 // Just because it is common. 78 // Just because it is common.
79 if (rgbValue == Color::black) 79 if (rgbValue == Color::black)
80 return m_colorBlack; 80 return m_colorBlack;
81 81
82 if (!isMainThread()) { 82 if (!isMainThread()) {
83 // TODO (crbug.com/599659): Make CSS color parsing work properly in a 83 // TODO (crbug.com/599659): Make CSS color parsing work properly in a
84 // worker thread. 84 // worker thread.
85 // Currently, ColorValueCache is not thread-safe; so we avoid interactin g 85 // Currently, ColorValueCache is not thread-safe; so we avoid interactin g
86 // with it on a non-main thread. 86 // with it on a non-main thread.
87 return CSSColorValue::create(rgbValue); 87 return CSSColorValue::create(rgbValue);
88 } 88 }
89 89
90 // Just wipe out the cache and start rebuilding if it gets too big. 90 // Just wipe out the cache and start rebuilding if it gets too big.
91 const unsigned maximumColorCacheSize = 512; 91 const unsigned maximumColorCacheSize = 512;
92 if (m_colorValueCache.size() > maximumColorCacheSize) 92 if (m_colorValueCache.size() > maximumColorCacheSize)
93 m_colorValueCache.clear(); 93 m_colorValueCache.clear();
94 94
95 RawPtr<CSSColorValue> dummyValue = nullptr; 95 CSSColorValue* dummyValue = nullptr;
96 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu e); 96 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu e);
97 if (entry.isNewEntry) 97 if (entry.isNewEntry)
98 entry.storedValue->value = CSSColorValue::create(rgbValue); 98 entry.storedValue->value = CSSColorValue::create(rgbValue);
99 99
100 return entry.storedValue->value; 100 return entry.storedValue->value;
101 } 101 }
102 102
103 RawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimitiveVa lue::UnitType type) 103 CSSPrimitiveValue* CSSValuePool::createValue(double value, CSSPrimitiveValue::Un itType type)
104 { 104 {
105 if (std::isinf(value)) 105 if (std::isinf(value))
106 value = 0; 106 value = 0;
107 107
108 if (value < 0 || value > maximumCacheableIntegerValue) 108 if (value < 0 || value > maximumCacheableIntegerValue)
109 return CSSPrimitiveValue::create(value, type); 109 return CSSPrimitiveValue::create(value, type);
110 110
111 int intValue = static_cast<int>(value); 111 int intValue = static_cast<int>(value);
112 if (value != intValue) 112 if (value != intValue)
113 return CSSPrimitiveValue::create(value, type); 113 return CSSPrimitiveValue::create(value, type);
(...skipping 10 matching lines...) Expand all
124 case CSSPrimitiveValue::UnitType::Number: 124 case CSSPrimitiveValue::UnitType::Number:
125 case CSSPrimitiveValue::UnitType::Integer: 125 case CSSPrimitiveValue::UnitType::Integer:
126 if (!m_numberValueCache[intValue]) 126 if (!m_numberValueCache[intValue])
127 m_numberValueCache[intValue] = CSSPrimitiveValue::create(value, CSSP rimitiveValue::UnitType::Integer); 127 m_numberValueCache[intValue] = CSSPrimitiveValue::create(value, CSSP rimitiveValue::UnitType::Integer);
128 return m_numberValueCache[intValue]; 128 return m_numberValueCache[intValue];
129 default: 129 default:
130 return CSSPrimitiveValue::create(value, type); 130 return CSSPrimitiveValue::create(value, type);
131 } 131 }
132 } 132 }
133 133
134 RawPtr<CSSPrimitiveValue> CSSValuePool::createValue(const Length& value, const C omputedStyle& style) 134 CSSPrimitiveValue* CSSValuePool::createValue(const Length& value, const Computed Style& style)
135 { 135 {
136 return CSSPrimitiveValue::create(value, style.effectiveZoom()); 136 return CSSPrimitiveValue::create(value, style.effectiveZoom());
137 } 137 }
138 138
139 RawPtr<CSSFontFamilyValue> CSSValuePool::createFontFamilyValue(const String& fam ilyName) 139 CSSFontFamilyValue* CSSValuePool::createFontFamilyValue(const String& familyName )
140 { 140 {
141 if (familyName.isNull()) 141 if (familyName.isNull())
142 return CSSFontFamilyValue::create(familyName); 142 return CSSFontFamilyValue::create(familyName);
143 Member<CSSFontFamilyValue>& value = m_fontFamilyValueCache.add(familyName, n ullptr).storedValue->value; 143 Member<CSSFontFamilyValue>& value = m_fontFamilyValueCache.add(familyName, n ullptr).storedValue->value;
144 if (!value) 144 if (!value)
145 value = CSSFontFamilyValue::create(familyName); 145 value = CSSFontFamilyValue::create(familyName);
146 return value; 146 return value;
147 } 147 }
148 148
149 RawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const AtomicString& strin g) 149 CSSValueList* CSSValuePool::createFontFaceValue(const AtomicString& string)
150 { 150 {
151 // Just wipe out the cache and start rebuilding if it gets too big. 151 // Just wipe out the cache and start rebuilding if it gets too big.
152 const unsigned maximumFontFaceCacheSize = 128; 152 const unsigned maximumFontFaceCacheSize = 128;
153 if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize) 153 if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize)
154 m_fontFaceValueCache.clear(); 154 m_fontFaceValueCache.clear();
155 155
156 Member<CSSValueList>& value = m_fontFaceValueCache.add(string, nullptr).stor edValue->value; 156 Member<CSSValueList>& value = m_fontFaceValueCache.add(string, nullptr).stor edValue->value;
157 if (!value) { 157 if (!value) {
158 RawPtr<CSSValue> parsedValue = CSSParser::parseSingleValue(CSSPropertyFo ntFamily, string); 158 CSSValue* parsedValue = CSSParser::parseSingleValue(CSSPropertyFontFamil y, string);
159 if (parsedValue && parsedValue->isValueList()) 159 if (parsedValue && parsedValue->isValueList())
160 value = toCSSValueList(parsedValue.get()); 160 value = toCSSValueList(parsedValue);
161 } 161 }
162 return value; 162 return value;
163 } 163 }
164 164
165 DEFINE_TRACE(CSSValuePool) 165 DEFINE_TRACE(CSSValuePool)
166 { 166 {
167 visitor->trace(m_inheritedValue); 167 visitor->trace(m_inheritedValue);
168 visitor->trace(m_implicitInitialValue); 168 visitor->trace(m_implicitInitialValue);
169 visitor->trace(m_explicitInitialValue); 169 visitor->trace(m_explicitInitialValue);
170 visitor->trace(m_unsetValue); 170 visitor->trace(m_unsetValue);
171 visitor->trace(m_identifierValueCache); 171 visitor->trace(m_identifierValueCache);
172 visitor->trace(m_colorValueCache); 172 visitor->trace(m_colorValueCache);
173 visitor->trace(m_colorTransparent); 173 visitor->trace(m_colorTransparent);
174 visitor->trace(m_colorWhite); 174 visitor->trace(m_colorWhite);
175 visitor->trace(m_colorBlack); 175 visitor->trace(m_colorBlack);
176 visitor->trace(m_pixelValueCache); 176 visitor->trace(m_pixelValueCache);
177 visitor->trace(m_percentValueCache); 177 visitor->trace(m_percentValueCache);
178 visitor->trace(m_numberValueCache); 178 visitor->trace(m_numberValueCache);
179 visitor->trace(m_fontFaceValueCache); 179 visitor->trace(m_fontFaceValueCache);
180 visitor->trace(m_fontFamilyValueCache); 180 visitor->trace(m_fontFamilyValueCache);
181 } 181 }
182 182
183 } // namespace blink 183 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSValuePool.h ('k') | third_party/WebKit/Source/core/css/CSSVariableReferenceValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698