summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/core/css/CSSVariableData.h
blob: 1de3837aefeb6ef8891b4eeafca2a2c766092dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CSSVariableData_h
#define CSSVariableData_h

#include "core/css/StylePropertySet.h"
#include "core/css/parser/CSSParserToken.h"
#include "core/css/parser/CSSParserTokenRange.h"
#include "wtf/RefCounted.h"
#include "wtf/text/WTFString.h"

namespace blink {

class CSSParserTokenRange;

class CSSVariableData : public RefCounted<CSSVariableData> {
    WTF_MAKE_NONCOPYABLE(CSSVariableData);
    USING_FAST_MALLOC(CSSVariableData);
public:
    static PassRefPtr<CSSVariableData> create(const CSSParserTokenRange& range, bool needsVariableResolution = true)
    {
        return adoptRef(new CSSVariableData(range, needsVariableResolution));
    }

    static PassRefPtr<CSSVariableData> createResolved(const Vector<CSSParserToken>& resolvedTokens, const CSSVariableData& unresolvedData)
    {
        return adoptRef(new CSSVariableData(resolvedTokens, unresolvedData.m_backingString));
    }

    CSSParserTokenRange tokenRange() { return m_tokens; }

    const Vector<CSSParserToken>& tokens() const { return m_tokens; }

    bool operator==(const CSSVariableData& other) const;

    bool needsVariableResolution() const { return m_needsVariableResolution; }

    StylePropertySet* propertySet();

private:
    CSSVariableData(const CSSParserTokenRange&, bool needsVariableResolution);

    // We can safely copy the tokens (which have raw pointers to substrings) because
    // StylePropertySets contain references to CSSCustomPropertyDeclarations, which
    // point to the unresolved CSSVariableData values that own the backing strings
    // this will potentially reference.
    CSSVariableData(const Vector<CSSParserToken>& resolvedTokens, String backingString)
        : m_backingString(backingString)
        , m_tokens(resolvedTokens)
        , m_needsVariableResolution(false)
        , m_cachedPropertySet(false)
    { }

    void consumeAndUpdateTokens(const CSSParserTokenRange&);
    template<typename CharacterType> void updateTokens(const CSSParserTokenRange&);

    String m_backingString;
    Vector<CSSParserToken> m_tokens;
    const bool m_needsVariableResolution;

    // Parsed representation for @apply
    bool m_cachedPropertySet;
    RefPtrWillBePersistent<StylePropertySet> m_propertySet;
};

} // namespace blink

#endif // CSSVariableData_h