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 | #pragma once
|
---|
27 |
|
---|
28 | #include "CSSPrimitiveValue.h"
|
---|
29 | #include "CSSPropertyNames.h"
|
---|
30 | #include "CSSValueKeywords.h"
|
---|
31 | #include "ColorHash.h"
|
---|
32 | #include <utility>
|
---|
33 | #include <wtf/HashMap.h>
|
---|
34 | #include <wtf/NeverDestroyed.h>
|
---|
35 | #include <wtf/RefPtr.h>
|
---|
36 | #include <wtf/text/AtomStringHash.h>
|
---|
37 |
|
---|
38 | namespace WebCore {
|
---|
39 |
|
---|
40 | class CSSValueList;
|
---|
41 | class CSSValuePool;
|
---|
42 |
|
---|
43 | enum class FromSystemFontID { No, Yes };
|
---|
44 |
|
---|
45 | class StaticCSSValuePool {
|
---|
46 | friend class CSSValuePool;
|
---|
47 | friend class LazyNeverDestroyed<StaticCSSValuePool>;
|
---|
48 | public:
|
---|
49 | static void init();
|
---|
50 |
|
---|
51 | private:
|
---|
52 | StaticCSSValuePool();
|
---|
53 |
|
---|
54 | LazyNeverDestroyed<CSSPrimitiveValue> m_implicitInitialValue;
|
---|
55 |
|
---|
56 | LazyNeverDestroyed<CSSPrimitiveValue> m_transparentColor;
|
---|
57 | LazyNeverDestroyed<CSSPrimitiveValue> m_whiteColor;
|
---|
58 | LazyNeverDestroyed<CSSPrimitiveValue> m_blackColor;
|
---|
59 |
|
---|
60 | static constexpr int maximumCacheableIntegerValue = 255;
|
---|
61 |
|
---|
62 | LazyNeverDestroyed<CSSPrimitiveValue> m_pixelValues[maximumCacheableIntegerValue + 1];
|
---|
63 | LazyNeverDestroyed<CSSPrimitiveValue> m_percentValues[maximumCacheableIntegerValue + 1];
|
---|
64 | LazyNeverDestroyed<CSSPrimitiveValue> m_numberValues[maximumCacheableIntegerValue + 1];
|
---|
65 | LazyNeverDestroyed<CSSPrimitiveValue> m_identifierValues[numCSSValueKeywords];
|
---|
66 | };
|
---|
67 |
|
---|
68 | WEBCORE_EXPORT extern LazyNeverDestroyed<StaticCSSValuePool> staticCSSValuePool;
|
---|
69 |
|
---|
70 | class CSSValuePool {
|
---|
71 | WTF_MAKE_FAST_ALLOCATED;
|
---|
72 | WTF_MAKE_NONCOPYABLE(CSSValuePool);
|
---|
73 | public:
|
---|
74 | CSSValuePool();
|
---|
75 |
|
---|
76 | static CSSValuePool& singleton();
|
---|
77 |
|
---|
78 | RefPtr<CSSValueList> createFontFaceValue(const AtomString&);
|
---|
79 | Ref<CSSPrimitiveValue> createFontFamilyValue(const String&, FromSystemFontID = FromSystemFontID::No);
|
---|
80 | Ref<CSSPrimitiveValue> createImplicitInitialValue() { return staticCSSValuePool->m_implicitInitialValue.get(); }
|
---|
81 | Ref<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier);
|
---|
82 | Ref<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier);
|
---|
83 | Ref<CSSPrimitiveValue> createColorValue(const Color&);
|
---|
84 | Ref<CSSPrimitiveValue> createValue(double value, CSSUnitType);
|
---|
85 | Ref<CSSPrimitiveValue> createValue(const String& value, CSSUnitType type) { return CSSPrimitiveValue::create(value, type); }
|
---|
86 | Ref<CSSPrimitiveValue> createValue(const Length& value, const RenderStyle& style) { return CSSPrimitiveValue::create(value, style); }
|
---|
87 | Ref<CSSPrimitiveValue> createValue(const LengthSize& value, const RenderStyle& style) { return CSSPrimitiveValue::create(value, style); }
|
---|
88 | Ref<CSSPrimitiveValue> createCustomIdent(const String& value) { return CSSPrimitiveValue::create(value, CSSUnitType::CustomIdent); }
|
---|
89 | template<typename T> static Ref<CSSPrimitiveValue> createValue(T&& value) { return CSSPrimitiveValue::create(std::forward<T>(value)); }
|
---|
90 | template<typename T> static Ref<CSSPrimitiveValue> createValue(T&& value, CSSPropertyID identifier) { return CSSPrimitiveValue::create(std::forward<T>(value), identifier); }
|
---|
91 |
|
---|
92 | void drain();
|
---|
93 |
|
---|
94 | private:
|
---|
95 | typedef HashMap<Color, RefPtr<CSSPrimitiveValue>> ColorValueCache;
|
---|
96 | ColorValueCache m_colorValueCache;
|
---|
97 |
|
---|
98 | typedef HashMap<AtomString, RefPtr<CSSValueList>> FontFaceValueCache;
|
---|
99 | FontFaceValueCache m_fontFaceValueCache;
|
---|
100 |
|
---|
101 | typedef HashMap<std::pair<String, bool>, RefPtr<CSSPrimitiveValue>> FontFamilyValueCache;
|
---|
102 | FontFamilyValueCache m_fontFamilyValueCache;
|
---|
103 |
|
---|
104 | friend class NeverDestroyed<CSSValuePool>;
|
---|
105 | };
|
---|
106 |
|
---|
107 | } // namespace WebCore
|
---|