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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 m_numberValueCache.resize(maximumCacheableIntegerValue + 1); | 53 m_numberValueCache.resize(maximumCacheableIntegerValue + 1); |
54 } | 54 } |
55 | 55 |
56 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 toCSSPrimitiveValue(*m_identifierValueCache[ident]); | 63 return toCSSPrimitiveValue(m_identifierValueCache[ident]); |
64 } | 64 } |
65 | 65 |
66 CSSPrimitiveValue CSSValuePool::createIdentifierValue(CSSPropertyID ident) | 66 CSSPrimitiveValue CSSValuePool::createIdentifierValue(CSSPropertyID ident) |
67 { | 67 { |
68 return CSSPrimitiveValue::createIdentifier(ident); | 68 return CSSPrimitiveValue::createIdentifier(ident); |
69 } | 69 } |
70 | 70 |
71 CSSPrimitiveValue CSSValuePool::createColorValue(unsigned rgbValue) | 71 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 toCSSPrimitiveValue(m_colorTransparent); | 75 return toCSSPrimitiveValue(m_colorTransparent); |
76 if (rgbValue == Color::white) | 76 if (rgbValue == Color::white) |
77 return toCSSPrimitiveValue(m_colorWhite); | 77 return toCSSPrimitiveValue(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 toCSSPrimitiveValue(m_colorBlack); | 80 return toCSSPrimitiveValue(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 NullableCSSValue dummyValue; | 87 NullableCSSValue dummyValue; |
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 toCSSPrimitiveValue(*entry.storedValue->value); | 91 return toCSSPrimitiveValue(entry.storedValue->value); |
92 } | 92 } |
93 | 93 |
94 CSSPrimitiveValue CSSValuePool::createValue(double value, CSSPrimitiveValue::Uni
tType type) | 94 CSSPrimitiveValue CSSValuePool::createValue(double value, CSSPrimitiveValue::Uni
tType 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::CSS_PX: | 107 case CSSPrimitiveValue::CSS_PX: |
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 toCSSPrimitiveValue(*m_pixelValueCache[intValue]); | 110 return toCSSPrimitiveValue(m_pixelValueCache[intValue]); |
111 case CSSPrimitiveValue::CSS_PERCENTAGE: | 111 case CSSPrimitiveValue::CSS_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 toCSSPrimitiveValue(*m_percentValueCache[intValue]); | 114 return toCSSPrimitiveValue(m_percentValueCache[intValue]); |
115 case CSSPrimitiveValue::CSS_NUMBER: | 115 case CSSPrimitiveValue::CSS_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 toCSSPrimitiveValue(*m_numberValueCache[intValue]); | 118 return toCSSPrimitiveValue(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 CSSPrimitiveValue CSSValuePool::createValue(const Length& value, const ComputedS
tyle& style) | 124 CSSPrimitiveValue CSSValuePool::createValue(const Length& value, const ComputedS
tyle& style) |
125 { | 125 { |
126 return CSSPrimitiveValue::create(value, style.effectiveZoom()); | 126 return CSSPrimitiveValue::create(value, style.effectiveZoom()); |
127 } | 127 } |
128 | 128 |
129 CSSPrimitiveValue CSSValuePool::createFontFamilyValue(const String& familyName) | 129 CSSPrimitiveValue CSSValuePool::createFontFamilyValue(const String& familyName) |
130 { | 130 { |
131 NullableCSSValue& value = m_fontFamilyValueCache.add(familyName, nullptr).st
oredValue->value; | 131 NullableCSSValue& value = m_fontFamilyValueCache.add(familyName, nullptr).st
oredValue->value; |
132 if (!value) | 132 if (!value) |
133 value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_CUS
TOM_IDENT); | 133 value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_CUS
TOM_IDENT); |
134 return toCSSPrimitiveValue(*value); | 134 return toCSSPrimitiveValue(value); |
135 } | 135 } |
136 | 136 |
137 PassRefPtrWillBeRawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const Ato
micString& string) | 137 PassRefPtrWillBeRawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const Ato
micString& string) |
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 RefPtrWillBeMember<CSSValueList>& value = m_fontFaceValueCache.add(string, n
ullptr).storedValue->value; |
(...skipping 19 matching lines...) Expand all Loading... |
164 visitor->trace(m_colorBlack); | 164 visitor->trace(m_colorBlack); |
165 visitor->trace(m_pixelValueCache); | 165 visitor->trace(m_pixelValueCache); |
166 visitor->trace(m_percentValueCache); | 166 visitor->trace(m_percentValueCache); |
167 visitor->trace(m_numberValueCache); | 167 visitor->trace(m_numberValueCache); |
168 visitor->trace(m_fontFaceValueCache); | 168 visitor->trace(m_fontFaceValueCache); |
169 visitor->trace(m_fontFamilyValueCache); | 169 visitor->trace(m_fontFamilyValueCache); |
170 #endif | 170 #endif |
171 } | 171 } |
172 | 172 |
173 } | 173 } |
OLD | NEW |