| 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 15 matching lines...) Expand all Loading... |
| 26 #include "core/css/CSSValuePool.h" | 26 #include "core/css/CSSValuePool.h" |
| 27 | 27 |
| 28 #include "core/css/CSSValueList.h" | 28 #include "core/css/CSSValueList.h" |
| 29 #include "core/css/parser/CSSParser.h" | 29 #include "core/css/parser/CSSParser.h" |
| 30 #include "core/style/ComputedStyle.h" | 30 #include "core/style/ComputedStyle.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 CSSValuePool& cssValuePool() | 34 CSSValuePool& cssValuePool() |
| 35 { | 35 { |
| 36 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CSSValuePool>, pool, (adoptPtrWil
lBeNoop(new CSSValuePool()))); | 36 DEFINE_STATIC_LOCAL(Persistent<CSSValuePool>, pool, ((new CSSValuePool()))); |
| 37 return *pool; | 37 return *pool; |
| 38 } | 38 } |
| 39 | 39 |
| 40 CSSValuePool::CSSValuePool() | 40 CSSValuePool::CSSValuePool() |
| 41 : m_inheritedValue(CSSInheritedValue::create()) | 41 : m_inheritedValue(CSSInheritedValue::create()) |
| 42 , m_implicitInitialValue(CSSInitialValue::createImplicit()) | 42 , m_implicitInitialValue(CSSInitialValue::createImplicit()) |
| 43 , m_explicitInitialValue(CSSInitialValue::createExplicit()) | 43 , m_explicitInitialValue(CSSInitialValue::createExplicit()) |
| 44 , m_unsetValue(CSSUnsetValue::create()) | 44 , m_unsetValue(CSSUnsetValue::create()) |
| 45 , m_colorTransparent(CSSColorValue::create(Color::transparent)) | 45 , m_colorTransparent(CSSColorValue::create(Color::transparent)) |
| 46 , m_colorWhite(CSSColorValue::create(Color::white)) | 46 , m_colorWhite(CSSColorValue::create(Color::white)) |
| 47 , m_colorBlack(CSSColorValue::create(Color::black)) | 47 , m_colorBlack(CSSColorValue::create(Color::black)) |
| 48 { | 48 { |
| 49 m_identifierValueCache.resize(numCSSValueKeywords); | 49 m_identifierValueCache.resize(numCSSValueKeywords); |
| 50 m_pixelValueCache.resize(maximumCacheableIntegerValue + 1); | 50 m_pixelValueCache.resize(maximumCacheableIntegerValue + 1); |
| 51 m_percentValueCache.resize(maximumCacheableIntegerValue + 1); | 51 m_percentValueCache.resize(maximumCacheableIntegerValue + 1); |
| 52 m_numberValueCache.resize(maximumCacheableIntegerValue + 1); | 52 m_numberValueCache.resize(maximumCacheableIntegerValue + 1); |
| 53 } | 53 } |
| 54 | 54 |
| 55 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CS
SValueID ident) | 55 RawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ident) |
| 56 { | 56 { |
| 57 if (ident <= 0) | 57 if (ident <= 0) |
| 58 return CSSPrimitiveValue::createIdentifier(ident); | 58 return CSSPrimitiveValue::createIdentifier(ident); |
| 59 | 59 |
| 60 if (!m_identifierValueCache[ident]) | 60 if (!m_identifierValueCache[ident]) |
| 61 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden
t); | 61 m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(iden
t); |
| 62 return m_identifierValueCache[ident]; | 62 return m_identifierValueCache[ident]; |
| 63 } | 63 } |
| 64 | 64 |
| 65 PassRefPtrWillBeRawPtr<CSSCustomIdentValue> CSSValuePool::createIdentifierValue(
CSSPropertyID ident) | 65 RawPtr<CSSCustomIdentValue> CSSValuePool::createIdentifierValue(CSSPropertyID id
ent) |
| 66 { | 66 { |
| 67 return CSSCustomIdentValue::create(ident); | 67 return CSSCustomIdentValue::create(ident); |
| 68 } | 68 } |
| 69 | 69 |
| 70 PassRefPtrWillBeRawPtr<CSSColorValue> CSSValuePool::createColorValue(RGBA32 rgbV
alue) | 70 RawPtr<CSSColorValue> CSSValuePool::createColorValue(RGBA32 rgbValue) |
| 71 { | 71 { |
| 72 // These are the empty and deleted values of the hash table. | 72 // These are the empty and deleted values of the hash table. |
| 73 if (rgbValue == Color::transparent) | 73 if (rgbValue == Color::transparent) |
| 74 return m_colorTransparent; | 74 return m_colorTransparent; |
| 75 if (rgbValue == Color::white) | 75 if (rgbValue == Color::white) |
| 76 return m_colorWhite; | 76 return m_colorWhite; |
| 77 // Just because it is common. | 77 // Just because it is common. |
| 78 if (rgbValue == Color::black) | 78 if (rgbValue == Color::black) |
| 79 return m_colorBlack; | 79 return m_colorBlack; |
| 80 | 80 |
| 81 // Just wipe out the cache and start rebuilding if it gets too big. | 81 // Just wipe out the cache and start rebuilding if it gets too big. |
| 82 const unsigned maximumColorCacheSize = 512; | 82 const unsigned maximumColorCacheSize = 512; |
| 83 if (m_colorValueCache.size() > maximumColorCacheSize) | 83 if (m_colorValueCache.size() > maximumColorCacheSize) |
| 84 m_colorValueCache.clear(); | 84 m_colorValueCache.clear(); |
| 85 | 85 |
| 86 RefPtrWillBeRawPtr<CSSColorValue> dummyValue = nullptr; | 86 RawPtr<CSSColorValue> dummyValue = nullptr; |
| 87 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); | 87 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); |
| 88 if (entry.isNewEntry) | 88 if (entry.isNewEntry) |
| 89 entry.storedValue->value = CSSColorValue::create(rgbValue); | 89 entry.storedValue->value = CSSColorValue::create(rgbValue); |
| 90 return entry.storedValue->value; | 90 return entry.storedValue->value; |
| 91 } | 91 } |
| 92 | 92 |
| 93 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value
, CSSPrimitiveValue::UnitType type) | 93 RawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimitiveVa
lue::UnitType type) |
| 94 { | 94 { |
| 95 if (std::isinf(value)) | 95 if (std::isinf(value)) |
| 96 value = 0; | 96 value = 0; |
| 97 | 97 |
| 98 if (value < 0 || value > maximumCacheableIntegerValue) | 98 if (value < 0 || value > maximumCacheableIntegerValue) |
| 99 return CSSPrimitiveValue::create(value, type); | 99 return CSSPrimitiveValue::create(value, type); |
| 100 | 100 |
| 101 int intValue = static_cast<int>(value); | 101 int intValue = static_cast<int>(value); |
| 102 if (value != intValue) | 102 if (value != intValue) |
| 103 return CSSPrimitiveValue::create(value, type); | 103 return CSSPrimitiveValue::create(value, type); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 114 case CSSPrimitiveValue::UnitType::Number: | 114 case CSSPrimitiveValue::UnitType::Number: |
| 115 case CSSPrimitiveValue::UnitType::Integer: | 115 case CSSPrimitiveValue::UnitType::Integer: |
| 116 if (!m_numberValueCache[intValue]) | 116 if (!m_numberValueCache[intValue]) |
| 117 m_numberValueCache[intValue] = CSSPrimitiveValue::create(value, CSSP
rimitiveValue::UnitType::Integer); | 117 m_numberValueCache[intValue] = CSSPrimitiveValue::create(value, CSSP
rimitiveValue::UnitType::Integer); |
| 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 RawPtr<CSSPrimitiveValue> CSSValuePool::createValue(const Length& value, const C
omputedStyle& style) |
| 125 { | 125 { |
| 126 return CSSPrimitiveValue::create(value, style.effectiveZoom()); | 126 return CSSPrimitiveValue::create(value, style.effectiveZoom()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 PassRefPtrWillBeRawPtr<CSSCustomIdentValue> CSSValuePool::createFontFamilyValue(
const String& familyName) | 129 RawPtr<CSSCustomIdentValue> CSSValuePool::createFontFamilyValue(const String& fa
milyName) |
| 130 { | 130 { |
| 131 RefPtrWillBeMember<CSSCustomIdentValue>& value = m_fontFamilyValueCache.add(
familyName, nullptr).storedValue->value; | 131 Member<CSSCustomIdentValue>& value = m_fontFamilyValueCache.add(familyName,
nullptr).storedValue->value; |
| 132 if (!value) | 132 if (!value) |
| 133 value = CSSCustomIdentValue::create(familyName); | 133 value = CSSCustomIdentValue::create(familyName); |
| 134 return value; | 134 return value; |
| 135 } | 135 } |
| 136 | 136 |
| 137 PassRefPtrWillBeRawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const Ato
micString& string) | 137 RawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const AtomicString& strin
g) |
| 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 Member<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 RawPtr<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); | 156 visitor->trace(m_inheritedValue); |
| 157 visitor->trace(m_implicitInitialValue); | 157 visitor->trace(m_implicitInitialValue); |
| 158 visitor->trace(m_explicitInitialValue); | 158 visitor->trace(m_explicitInitialValue); |
| 159 visitor->trace(m_unsetValue); | 159 visitor->trace(m_unsetValue); |
| 160 visitor->trace(m_identifierValueCache); | 160 visitor->trace(m_identifierValueCache); |
| 161 visitor->trace(m_colorValueCache); | 161 visitor->trace(m_colorValueCache); |
| 162 visitor->trace(m_colorTransparent); | 162 visitor->trace(m_colorTransparent); |
| 163 visitor->trace(m_colorWhite); | 163 visitor->trace(m_colorWhite); |
| 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 } // namespace blink | 173 } // namespace blink |
| OLD | NEW |