• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef CSSValuePool_h
27 #define CSSValuePool_h
28 
29 #include "core/CSSPropertyNames.h"
30 #include "core/CSSValueKeywords.h"
31 #include "core/css/CSSInheritedValue.h"
32 #include "core/css/CSSInitialValue.h"
33 #include "core/css/CSSPrimitiveValue.h"
34 #include "wtf/HashMap.h"
35 #include "wtf/RefPtr.h"
36 #include "wtf/text/AtomicStringHash.h"
37 
38 namespace blink {
39 
40 class CSSValueList;
41 
42 class CSSValuePool :  public NoBaseWillBeGarbageCollected<CSSValuePool> {
43     WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
44 public:
45     PassRefPtrWillBeRawPtr<CSSValueList> createFontFaceValue(const AtomicString&);
46     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createFontFamilyValue(const String&);
createInheritedValue()47     PassRefPtrWillBeRawPtr<CSSInheritedValue> createInheritedValue() { return m_inheritedValue; }
createImplicitInitialValue()48     PassRefPtrWillBeRawPtr<CSSInitialValue> createImplicitInitialValue() { return m_implicitInitialValue; }
createExplicitInitialValue()49     PassRefPtrWillBeRawPtr<CSSInitialValue> createExplicitInitialValue() { return m_explicitInitialValue; }
50     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier);
51     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier);
52     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColorValue(unsigned rgbValue);
53     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(double value, CSSPrimitiveValue::UnitType);
createValue(const String & value,CSSPrimitiveValue::UnitType type)54     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(const String& value, CSSPrimitiveValue::UnitType type) { return CSSPrimitiveValue::create(value, type); }
55     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(const Length& value, const RenderStyle&);
createValue(const Length & value,float zoom)56     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(const Length& value, float zoom) { return CSSPrimitiveValue::create(value, zoom); }
createValue(T value)57     template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(T value) { return CSSPrimitiveValue::create(value); }
58 
59     void trace(Visitor*);
60 
61 private:
62     CSSValuePool();
63 
64     RefPtrWillBeMember<CSSInheritedValue> m_inheritedValue;
65     RefPtrWillBeMember<CSSInitialValue> m_implicitInitialValue;
66     RefPtrWillBeMember<CSSInitialValue> m_explicitInitialValue;
67 
68     WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>, numCSSValueKeywords> m_identifierValueCache;
69 
70     typedef WillBeHeapHashMap<unsigned, RefPtrWillBeMember<CSSPrimitiveValue> > ColorValueCache;
71     ColorValueCache m_colorValueCache;
72     RefPtrWillBeMember<CSSPrimitiveValue> m_colorTransparent;
73     RefPtrWillBeMember<CSSPrimitiveValue> m_colorWhite;
74     RefPtrWillBeMember<CSSPrimitiveValue> m_colorBlack;
75 
76     static const int maximumCacheableIntegerValue = 255;
77 
78     WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>, maximumCacheableIntegerValue + 1> m_pixelValueCache;
79     WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>, maximumCacheableIntegerValue + 1> m_percentValueCache;
80     WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>, maximumCacheableIntegerValue + 1> m_numberValueCache;
81 
82     typedef WillBeHeapHashMap<AtomicString, RefPtrWillBeMember<CSSValueList> > FontFaceValueCache;
83     FontFaceValueCache m_fontFaceValueCache;
84 
85     typedef WillBeHeapHashMap<String, RefPtrWillBeMember<CSSPrimitiveValue> > FontFamilyValueCache;
86     FontFamilyValueCache m_fontFamilyValueCache;
87 
88     friend CSSValuePool& cssValuePool();
89 };
90 
91 CSSValuePool& cssValuePool();
92 
93 }
94 
95 #endif
96