OLD | NEW |
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 Loading... |
46 , m_colorTransparent(CSSPrimitiveValue::createColor(Color::transparent)) | 46 , m_colorTransparent(CSSPrimitiveValue::createColor(Color::transparent)) |
47 , m_colorWhite(CSSPrimitiveValue::createColor(Color::white)) | 47 , m_colorWhite(CSSPrimitiveValue::createColor(Color::white)) |
48 , m_colorBlack(CSSPrimitiveValue::createColor(Color::black)) | 48 , m_colorBlack(CSSPrimitiveValue::createColor(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 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CS
SValueID ident) | 56 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ide
nt) |
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 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CS
SPropertyID ident) | 66 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSPropertyID
ident) |
67 { | 67 { |
68 return CSSPrimitiveValue::createIdentifier(ident); | 68 return CSSPrimitiveValue::createIdentifier(ident); |
69 } | 69 } |
70 | 70 |
71 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigne
d rgbValue) | 71 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned 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 // Just wipe out the cache and start rebuilding if it gets too big. | 82 // Just wipe out the cache and start rebuilding if it gets too big. |
83 const unsigned maximumColorCacheSize = 512; | 83 const unsigned maximumColorCacheSize = 512; |
84 if (m_colorValueCache.size() > maximumColorCacheSize) | 84 if (m_colorValueCache.size() > maximumColorCacheSize) |
85 m_colorValueCache.clear(); | 85 m_colorValueCache.clear(); |
86 | 86 |
87 RefPtrWillBeRawPtr<CSSPrimitiveValue> dummyValue = nullptr; | 87 RefPtr<CSSPrimitiveValue> dummyValue = nullptr; |
88 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); | 88 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); |
89 if (entry.isNewEntry) | 89 if (entry.isNewEntry) |
90 entry.storedValue->value = CSSPrimitiveValue::createColor(rgbValue); | 90 entry.storedValue->value = CSSPrimitiveValue::createColor(rgbValue); |
91 return entry.storedValue->value; | 91 return entry.storedValue->value; |
92 } | 92 } |
93 | 93 |
94 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value
, CSSPrimitiveValue::UnitType type) | 94 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimiti
veValue::UnitType type) |
95 { | 95 { |
96 if (std::isinf(value)) | 96 if (std::isinf(value)) |
97 value = 0; | 97 value = 0; |
98 | 98 |
99 if (value < 0 || value > maximumCacheableIntegerValue) | 99 if (value < 0 || value > maximumCacheableIntegerValue) |
100 return CSSPrimitiveValue::create(value, type); | 100 return CSSPrimitiveValue::create(value, type); |
101 | 101 |
102 int intValue = static_cast<int>(value); | 102 int intValue = static_cast<int>(value); |
103 if (value != intValue) | 103 if (value != intValue) |
104 return CSSPrimitiveValue::create(value, type); | 104 return CSSPrimitiveValue::create(value, type); |
105 | 105 |
106 switch (type) { | 106 switch (type) { |
107 case CSSPrimitiveValue::UnitType::Pixels: | 107 case CSSPrimitiveValue::UnitType::Pixels: |
108 if (!m_pixelValueCache[intValue]) | 108 if (!m_pixelValueCache[intValue]) |
109 m_pixelValueCache[intValue] = CSSPrimitiveValue::create(value, type)
; | 109 m_pixelValueCache[intValue] = CSSPrimitiveValue::create(value, type)
; |
110 return m_pixelValueCache[intValue]; | 110 return m_pixelValueCache[intValue]; |
111 case CSSPrimitiveValue::UnitType::Percentage: | 111 case CSSPrimitiveValue::UnitType::Percentage: |
112 if (!m_percentValueCache[intValue]) | 112 if (!m_percentValueCache[intValue]) |
113 m_percentValueCache[intValue] = CSSPrimitiveValue::create(value, typ
e); | 113 m_percentValueCache[intValue] = CSSPrimitiveValue::create(value, typ
e); |
114 return m_percentValueCache[intValue]; | 114 return m_percentValueCache[intValue]; |
115 case CSSPrimitiveValue::UnitType::Number: | 115 case CSSPrimitiveValue::UnitType::Number: |
116 if (!m_numberValueCache[intValue]) | 116 if (!m_numberValueCache[intValue]) |
117 m_numberValueCache[intValue] = CSSPrimitiveValue::create(value, type
); | 117 m_numberValueCache[intValue] = CSSPrimitiveValue::create(value, type
); |
118 return m_numberValueCache[intValue]; | 118 return m_numberValueCache[intValue]; |
119 default: | 119 default: |
120 return CSSPrimitiveValue::create(value, type); | 120 return CSSPrimitiveValue::create(value, type); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(const Length
& value, const ComputedStyle& style) | 124 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createValue(const Length& value, con
st ComputedStyle& style) |
125 { | 125 { |
126 return CSSPrimitiveValue::create(value, style.effectiveZoom()); | 126 return CSSPrimitiveValue::create(value, style.effectiveZoom()); |
127 } | 127 } |
128 | 128 |
129 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(co
nst String& familyName) | 129 PassRefPtr<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(const String&
familyName) |
130 { | 130 { |
131 RefPtrWillBeMember<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add(fa
milyName, nullptr).storedValue->value; | 131 RefPtr<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add(familyName, nu
llptr).storedValue->value; |
132 if (!value) | 132 if (!value) |
133 value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::UnitTyp
e::CustomIdentifier); | 133 value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::UnitTyp
e::CustomIdentifier); |
134 return value; | 134 return value; |
135 } | 135 } |
136 | 136 |
137 PassRefPtrWillBeRawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const Ato
micString& string) | 137 PassRefPtr<CSSValueList> CSSValuePool::createFontFaceValue(const AtomicString& s
tring) |
138 { | 138 { |
139 // Just wipe out the cache and start rebuilding if it gets too big. | 139 // Just wipe out the cache and start rebuilding if it gets too big. |
140 const unsigned maximumFontFaceCacheSize = 128; | 140 const unsigned maximumFontFaceCacheSize = 128; |
141 if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize) | 141 if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize) |
142 m_fontFaceValueCache.clear(); | 142 m_fontFaceValueCache.clear(); |
143 | 143 |
144 RefPtrWillBeMember<CSSValueList>& value = m_fontFaceValueCache.add(string, n
ullptr).storedValue->value; | 144 RefPtr<CSSValueList>& value = m_fontFaceValueCache.add(string, nullptr).stor
edValue->value; |
145 if (!value) { | 145 if (!value) { |
146 RefPtrWillBeRawPtr<CSSValue> parsedValue = CSSParser::parseSingleValue(C
SSPropertyFontFamily, string); | 146 RefPtr<CSSValue> parsedValue = CSSParser::parseSingleValue(CSSPropertyFo
ntFamily, string); |
147 if (parsedValue && parsedValue->isValueList()) | 147 if (parsedValue && parsedValue->isValueList()) |
148 value = toCSSValueList(parsedValue.get()); | 148 value = toCSSValueList(parsedValue.get()); |
149 } | 149 } |
150 return value; | 150 return value; |
151 } | 151 } |
152 | 152 |
153 DEFINE_TRACE(CSSValuePool) | 153 DEFINE_TRACE(CSSValuePool) |
154 { | 154 { |
155 #if ENABLE(OILPAN) | 155 #if ENABLE(OILPAN) |
156 visitor->trace(m_inheritedValue); | |
157 visitor->trace(m_implicitInitialValue); | |
158 visitor->trace(m_explicitInitialValue); | |
159 visitor->trace(m_unsetValue); | |
160 visitor->trace(m_identifierValueCache); | |
161 visitor->trace(m_colorValueCache); | |
162 visitor->trace(m_colorTransparent); | |
163 visitor->trace(m_colorWhite); | |
164 visitor->trace(m_colorBlack); | |
165 visitor->trace(m_pixelValueCache); | |
166 visitor->trace(m_percentValueCache); | |
167 visitor->trace(m_numberValueCache); | |
168 visitor->trace(m_fontFaceValueCache); | 156 visitor->trace(m_fontFaceValueCache); |
169 visitor->trace(m_fontFamilyValueCache); | 157 visitor->trace(m_fontFamilyValueCache); |
170 #endif | 158 #endif |
171 } | 159 } |
172 | 160 |
173 } | 161 } |
OLD | NEW |