~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/WebCore/style/RuleFeature.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) 1999 Lars Knoll (knoll@kde.org)
 
3
 * Copyright (C) 2003-2011, 2014 Apple Inc. All rights reserved.
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Library General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Library General Public License
 
16
 * along with this library; see the file COPYING.LIB.  If not, write to
 
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
 *
 
20
 */
 
21
 
 
22
#pragma once
 
23
 
 
24
#include "CSSSelector.h"
 
25
#include <wtf/Forward.h>
 
26
#include <wtf/HashMap.h>
 
27
#include <wtf/HashSet.h>
 
28
#include <wtf/text/AtomString.h>
 
29
#include <wtf/text/AtomStringHash.h>
 
30
 
 
31
namespace WebCore {
 
32
 
 
33
class StyleRule;
 
34
 
 
35
namespace Style {
 
36
 
 
37
class RuleData;
 
38
 
 
39
enum class MatchElement : uint8_t { Subject, Parent, Ancestor, DirectSibling, IndirectSibling, AnySibling, ParentSibling, AncestorSibling, Host };
 
40
constexpr unsigned matchElementCount = static_cast<unsigned>(MatchElement::Host) + 1;
 
41
 
 
42
struct RuleFeature {
 
43
    RuleFeature(const RuleData&, Optional<MatchElement> = WTF::nullopt);
 
44
 
 
45
    RefPtr<const StyleRule> styleRule;
 
46
    uint16_t selectorIndex; // Keep in sync with RuleData's selectorIndex size.
 
47
    uint16_t selectorListIndex; // Keep in sync with RuleData's selectorListIndex size.
 
48
    Optional<MatchElement> matchElement { };
 
49
};
 
50
static_assert(sizeof(RuleFeature) <= 16, "RuleFeature is a frquently alocated object. Keep it small.");
 
51
 
 
52
struct RuleFeatureWithInvalidationSelector : public RuleFeature {
 
53
    RuleFeatureWithInvalidationSelector(const RuleData& data, Optional<MatchElement> matchElement = WTF::nullopt, const CSSSelector* invalidationSelector = nullptr)
 
54
        : RuleFeature(data, WTFMove(matchElement))
 
55
        , invalidationSelector(invalidationSelector)
 
56
    { }
 
57
 
 
58
    const CSSSelector* invalidationSelector { nullptr };
 
59
};
 
60
 
 
61
struct RuleFeatureSet {
 
62
    void add(const RuleFeatureSet&);
 
63
    void clear();
 
64
    void shrinkToFit();
 
65
    void collectFeatures(const RuleData&);
 
66
    void registerContentAttribute(const AtomString&);
 
67
 
 
68
    HashSet<AtomString> idsInRules;
 
69
    HashSet<AtomString> idsMatchingAncestorsInRules;
 
70
    HashSet<AtomString> attributeCanonicalLocalNamesInRules;
 
71
    HashSet<AtomString> attributeLocalNamesInRules;
 
72
    HashSet<AtomString> contentAttributeNamesInRules;
 
73
    Vector<RuleFeature> siblingRules;
 
74
    Vector<RuleFeature> uncommonAttributeRules;
 
75
    
 
76
    HashMap<AtomString, std::unique_ptr<Vector<RuleFeature>>> classRules;
 
77
    HashMap<AtomString, std::unique_ptr<Vector<RuleFeatureWithInvalidationSelector>>> attributeRules;
 
78
    HashSet<AtomString> classesAffectingHost;
 
79
    HashSet<AtomString> attributesAffectingHost;
 
80
 
 
81
    bool usesFirstLineRules { false };
 
82
    bool usesFirstLetterRules { false };
 
83
 
 
84
private:
 
85
    static MatchElement computeNextMatchElement(MatchElement, CSSSelector::RelationType);
 
86
    static MatchElement computeSubSelectorMatchElement(MatchElement, const CSSSelector&);
 
87
 
 
88
    struct SelectorFeatures {
 
89
        bool hasSiblingSelector { false };
 
90
 
 
91
        Vector<std::pair<AtomString, MatchElement>, 32> classes;
 
92
        Vector<std::pair<const CSSSelector*, MatchElement>, 32> attributes;
 
93
    };
 
94
    void recursivelyCollectFeaturesFromSelector(SelectorFeatures&, const CSSSelector&, MatchElement = MatchElement::Subject);
 
95
};
 
96
 
 
97
} // namespace Style
 
98
} // namespace WebCore