Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / CSSValuePool.h
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 "CSSPropertyNames.h"
30 #include "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 WebCore {
39
40 class CSSValueList;
41
42 class CSSValuePool :  public NoBaseWillBeGarbageCollected<CSSValuePool> {
43     DECLARE_GC_INFO;
44     WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
45 public:
46     PassRefPtrWillBeRawPtr<CSSValueList> createFontFaceValue(const AtomicString&);
47     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createFontFamilyValue(const String&);
48     PassRefPtrWillBeRawPtr<CSSInheritedValue> createInheritedValue() { return m_inheritedValue; }
49     PassRefPtrWillBeRawPtr<CSSInitialValue> createImplicitInitialValue() { return m_implicitInitialValue; }
50     PassRefPtrWillBeRawPtr<CSSInitialValue> createExplicitInitialValue() { return m_explicitInitialValue; }
51     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier);
52     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier);
53     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColorValue(unsigned rgbValue);
54     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(double value, CSSPrimitiveValue::UnitTypes);
55     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(const String& value, CSSPrimitiveValue::UnitTypes type) { return CSSPrimitiveValue::create(value, type); }
56     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(const Length& value, const RenderStyle&);
57     PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(const Length& value, float zoom) { return CSSPrimitiveValue::create(value, zoom); }
58     template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createValue(T value) { return CSSPrimitiveValue::create(value); }
59
60     void trace(Visitor*);
61
62 private:
63     CSSValuePool();
64
65     RefPtrWillBeMember<CSSInheritedValue> m_inheritedValue;
66     RefPtrWillBeMember<CSSInitialValue> m_implicitInitialValue;
67     RefPtrWillBeMember<CSSInitialValue> m_explicitInitialValue;
68
69     WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>, numCSSValueKeywords> m_identifierValueCache;
70
71     typedef WillBeHeapHashMap<unsigned, RefPtrWillBeMember<CSSPrimitiveValue> > ColorValueCache;
72     ColorValueCache m_colorValueCache;
73     RefPtrWillBeMember<CSSPrimitiveValue> m_colorTransparent;
74     RefPtrWillBeMember<CSSPrimitiveValue> m_colorWhite;
75     RefPtrWillBeMember<CSSPrimitiveValue> m_colorBlack;
76
77     static const int maximumCacheableIntegerValue = 255;
78
79     WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>, maximumCacheableIntegerValue + 1> m_pixelValueCache;
80     WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>, maximumCacheableIntegerValue + 1> m_percentValueCache;
81     WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>, maximumCacheableIntegerValue + 1> m_numberValueCache;
82
83     typedef WillBeHeapHashMap<AtomicString, RefPtrWillBeMember<CSSValueList> > FontFaceValueCache;
84     FontFaceValueCache m_fontFaceValueCache;
85
86     typedef WillBeHeapHashMap<String, RefPtrWillBeMember<CSSPrimitiveValue> > FontFamilyValueCache;
87     FontFamilyValueCache m_fontFamilyValueCache;
88
89     friend CSSValuePool& cssValuePool();
90 };
91
92 CSSValuePool& cssValuePool();
93
94 }
95
96 #endif