This source file includes following definitions.
- cssValuePool
- m_colorBlack
- createIdentifierValue
- createIdentifierValue
- createColorValue
- createValue
- createValue
- createFontFamilyValue
- createFontFaceValue
- trace
#include "config.h"
#include "core/css/CSSValuePool.h"
#include "core/css/parser/BisonCSSParser.h"
#include "core/css/CSSValueList.h"
#include "core/rendering/style/RenderStyle.h"
namespace WebCore {
CSSValuePool& cssValuePool()
{
#if ENABLE(OILPAN)
DEFINE_STATIC_LOCAL(Persistent<CSSValuePool>, pool, (new CSSValuePool()));
return *pool;
#else
DEFINE_STATIC_LOCAL(CSSValuePool, pool, ());
return pool;
#endif
}
CSSValuePool::CSSValuePool()
: m_inheritedValue(CSSInheritedValue::create())
, m_implicitInitialValue(CSSInitialValue::createImplicit())
, m_explicitInitialValue(CSSInitialValue::createExplicit())
, m_colorTransparent(CSSPrimitiveValue::createColor(Color::transparent))
, m_colorWhite(CSSPrimitiveValue::createColor(Color::white))
, m_colorBlack(CSSPrimitiveValue::createColor(Color::black))
{
m_identifierValueCache.resize(numCSSValueKeywords);
m_pixelValueCache.resize(maximumCacheableIntegerValue + 1);
m_percentValueCache.resize(maximumCacheableIntegerValue + 1);
m_numberValueCache.resize(maximumCacheableIntegerValue + 1);
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ident)
{
if (ident <= 0)
return CSSPrimitiveValue::createIdentifier(ident);
if (!m_identifierValueCache[ident])
m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(ident);
return m_identifierValueCache[ident];
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSPropertyID ident)
{
return CSSPrimitiveValue::createIdentifier(ident);
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue)
{
if (rgbValue == Color::transparent)
return m_colorTransparent;
if (rgbValue == Color::white)
return m_colorWhite;
if (rgbValue == Color::black)
return m_colorBlack;
const unsigned maximumColorCacheSize = 512;
if (m_colorValueCache.size() > maximumColorCacheSize)
m_colorValueCache.clear();
RefPtrWillBeRawPtr<CSSPrimitiveValue> dummyValue = nullptr;
ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValue);
if (entry.isNewEntry)
entry.storedValue->value = CSSPrimitiveValue::createColor(rgbValue);
return entry.storedValue->value;
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimitiveValue::UnitTypes type)
{
if (value < 0 || value > maximumCacheableIntegerValue)
return CSSPrimitiveValue::create(value, type);
int intValue = static_cast<int>(value);
if (value != intValue)
return CSSPrimitiveValue::create(value, type);
switch (type) {
case CSSPrimitiveValue::CSS_PX:
if (!m_pixelValueCache[intValue])
m_pixelValueCache[intValue] = CSSPrimitiveValue::create(value, type);
return m_pixelValueCache[intValue];
case CSSPrimitiveValue::CSS_PERCENTAGE:
if (!m_percentValueCache[intValue])
m_percentValueCache[intValue] = CSSPrimitiveValue::create(value, type);
return m_percentValueCache[intValue];
case CSSPrimitiveValue::CSS_NUMBER:
if (!m_numberValueCache[intValue])
m_numberValueCache[intValue] = CSSPrimitiveValue::create(value, type);
return m_numberValueCache[intValue];
default:
return CSSPrimitiveValue::create(value, type);
}
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(const Length& value, const RenderStyle& style)
{
return CSSPrimitiveValue::create(value, style.effectiveZoom());
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(const String& familyName)
{
RefPtrWillBeMember<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add(familyName, nullptr).storedValue->value;
if (!value)
value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_STRING);
return value;
}
PassRefPtrWillBeRawPtr<CSSValueList> CSSValuePool::createFontFaceValue(const AtomicString& string)
{
const unsigned maximumFontFaceCacheSize = 128;
if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize)
m_fontFaceValueCache.clear();
RefPtrWillBeMember<CSSValueList>& value = m_fontFaceValueCache.add(string, nullptr).storedValue->value;
if (!value)
value = BisonCSSParser::parseFontFaceValue(string);
return value;
}
void CSSValuePool::trace(Visitor* visitor)
{
visitor->trace(m_inheritedValue);
visitor->trace(m_implicitInitialValue);
visitor->trace(m_explicitInitialValue);
visitor->trace(m_identifierValueCache);
visitor->trace(m_colorValueCache);
visitor->trace(m_colorTransparent);
visitor->trace(m_colorWhite);
visitor->trace(m_colorBlack);
visitor->trace(m_pixelValueCache);
visitor->trace(m_percentValueCache);
visitor->trace(m_numberValueCache);
visitor->trace(m_fontFaceValueCache);
visitor->trace(m_fontFamilyValueCache);
}
}