~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/WebCore/style/PropertyCascade.h

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2019 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 "CascadeLevel.h"
 
29
#include "ElementRuleCollector.h"
 
30
#include "StyleBuilderState.h"
 
31
#include <bitset>
 
32
 
 
33
namespace WebCore {
 
34
 
 
35
class StyleResolver;
 
36
 
 
37
namespace Style {
 
38
 
 
39
class PropertyCascade {
 
40
    WTF_MAKE_FAST_ALLOCATED;
 
41
public:
 
42
    enum IncludedProperties { All, InheritedOnly };
 
43
 
 
44
    struct Direction {
 
45
        TextDirection textDirection;
 
46
        WritingMode writingMode;
 
47
    };
 
48
 
 
49
    PropertyCascade(const MatchResult&, OptionSet<CascadeLevel>, IncludedProperties, Direction);
 
50
    PropertyCascade(const PropertyCascade&, OptionSet<CascadeLevel>);
 
51
 
 
52
    ~PropertyCascade();
 
53
 
 
54
    struct Property {
 
55
        CSSPropertyID id;
 
56
        CascadeLevel level;
 
57
        ScopeOrdinal styleScopeOrdinal;
 
58
        CSSValue* cssValue[3]; // Values for link match states MatchDefault, MatchLink and MatchVisited
 
59
    };
 
60
 
 
61
    bool hasProperty(CSSPropertyID) const;
 
62
    const Property& property(CSSPropertyID) const;
 
63
 
 
64
    bool hasCustomProperty(const String&) const;
 
65
    Property customProperty(const String&) const;
 
66
 
 
67
    const Vector<Property, 8>& deferredProperties() const { return m_deferredProperties; }
 
68
    const HashMap<AtomString, Property>& customProperties() const { return m_customProperties; }
 
69
 
 
70
    Direction direction() const { return m_direction; }
 
71
 
 
72
    const PropertyCascade* propertyCascadeForRollback(CascadeLevel) const;
 
73
 
 
74
private:
 
75
    void buildCascade(OptionSet<CascadeLevel>);
 
76
    bool addNormalMatches(CascadeLevel);
 
77
    void addImportantMatches(CascadeLevel);
 
78
    bool addMatch(const MatchedProperties&, CascadeLevel, bool important);
 
79
 
 
80
    void set(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
 
81
    void setDeferred(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
 
82
    static void setPropertyInternal(Property&, CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
 
83
 
 
84
    Direction resolveDirectionAndWritingMode(Direction inheritedDirection) const;
 
85
 
 
86
    const MatchResult& m_matchResult;
 
87
    const IncludedProperties m_includedProperties;
 
88
    const Direction m_direction;
 
89
 
 
90
    Property m_properties[numCSSProperties + 2];
 
91
    std::bitset<numCSSProperties + 2> m_propertyIsPresent;
 
92
 
 
93
    Vector<Property, 8> m_deferredProperties;
 
94
    HashMap<AtomString, Property> m_customProperties;
 
95
 
 
96
    mutable std::unique_ptr<const PropertyCascade> m_authorRollbackCascade;
 
97
    mutable std::unique_ptr<const PropertyCascade> m_userRollbackCascade;
 
98
};
 
99
 
 
100
inline bool PropertyCascade::hasProperty(CSSPropertyID id) const
 
101
{
 
102
    ASSERT(id < m_propertyIsPresent.size());
 
103
    return m_propertyIsPresent[id];
 
104
}
 
105
 
 
106
inline const PropertyCascade::Property& PropertyCascade::property(CSSPropertyID id) const
 
107
{
 
108
    return m_properties[id];
 
109
}
 
110
 
 
111
inline bool PropertyCascade::hasCustomProperty(const String& name) const
 
112
{
 
113
    return m_customProperties.contains(name);
 
114
}
 
115
 
 
116
inline PropertyCascade::Property PropertyCascade::customProperty(const String& name) const
 
117
{
 
118
    return m_customProperties.get(name);
 
119
}
 
120
 
 
121
}
 
122
}