summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/StyleResolver.h
blob: 4042898b975c07d232da973572a6af73eb0b5c01 (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
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/NonnullRefPtrVector.h>
#include <AK/OwnPtr.h>
#include <LibWeb/CSS/StyleProperties.h>
#include <LibWeb/Forward.h>

namespace Web::CSS {

struct MatchingRule {
    RefPtr<CSSStyleRule> rule;
    size_t style_sheet_index { 0 };
    size_t rule_index { 0 };
    size_t selector_index { 0 };
};

class StyleResolver {
public:
    explicit StyleResolver(DOM::Document&);
    ~StyleResolver();

    DOM::Document& document() { return m_document; }
    const DOM::Document& document() const { return m_document; }

    NonnullRefPtr<StyleProperties> resolve_style(const DOM::Element&) const;

    Vector<MatchingRule> collect_matching_rules(const DOM::Element&) const;
    void sort_matching_rules(Vector<MatchingRule>&) const;

    static bool is_inherited_property(CSS::PropertyID);

private:
    template<typename Callback>
    void for_each_stylesheet(Callback) const;

    DOM::Document& m_document;
};

}