/src/serenity/Userland/Libraries/LibWeb/CSS/CSSRule.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, the SerenityOS developers. |
3 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <AK/String.h> |
11 | | #include <LibJS/Heap/GCPtr.h> |
12 | | #include <LibWeb/Bindings/PlatformObject.h> |
13 | | #include <LibWeb/CSS/CSSStyleDeclaration.h> |
14 | | #include <LibWeb/CSS/Selector.h> |
15 | | |
16 | | namespace Web::CSS { |
17 | | |
18 | | class CSSRule : public Bindings::PlatformObject { |
19 | | WEB_PLATFORM_OBJECT(CSSRule, Bindings::PlatformObject); |
20 | | |
21 | | public: |
22 | 0 | virtual ~CSSRule() = default; |
23 | | |
24 | | // https://drafts.csswg.org/cssom/#dom-cssrule-type |
25 | | enum class Type : u16 { |
26 | | Style = 1, |
27 | | Import = 3, |
28 | | Media = 4, |
29 | | FontFace = 5, |
30 | | Keyframes = 7, |
31 | | Keyframe = 8, |
32 | | Namespace = 10, |
33 | | Supports = 12, |
34 | | // AD-HOC: These are not included in the spec, but we need them internally. So, their numbers are arbitrary. |
35 | | LayerBlock = 100, |
36 | | LayerStatement = 101, |
37 | | NestedDeclarations = 102, |
38 | | }; |
39 | | |
40 | | virtual Type type() const = 0; |
41 | | |
42 | | String css_text() const; |
43 | | void set_css_text(StringView); |
44 | | |
45 | 0 | CSSRule* parent_rule() { return m_parent_rule.ptr(); } |
46 | 0 | CSSRule const* parent_rule() const { return m_parent_rule.ptr(); } |
47 | | void set_parent_rule(CSSRule*); |
48 | | |
49 | 0 | CSSStyleSheet* parent_style_sheet() { return m_parent_style_sheet.ptr(); } |
50 | | virtual void set_parent_style_sheet(CSSStyleSheet*); |
51 | | |
52 | | template<typename T> |
53 | | bool fast_is() const = delete; |
54 | | |
55 | | // https://drafts.csswg.org/cssom-1/#serialize-a-css-rule |
56 | | virtual String serialized() const = 0; |
57 | | |
58 | | protected: |
59 | | explicit CSSRule(JS::Realm&); |
60 | | |
61 | | virtual void visit_edges(Cell::Visitor&) override; |
62 | | |
63 | | virtual void clear_caches(); |
64 | | |
65 | | [[nodiscard]] FlyString const& parent_layer_internal_qualified_name() const |
66 | 0 | { |
67 | 0 | if (!m_cached_layer_name.has_value()) |
68 | 0 | return parent_layer_internal_qualified_name_slow_case(); |
69 | 0 | return m_cached_layer_name.value(); |
70 | 0 | } |
71 | | |
72 | | [[nodiscard]] FlyString const& parent_layer_internal_qualified_name_slow_case() const; |
73 | | |
74 | | JS::GCPtr<CSSRule> m_parent_rule; |
75 | | JS::GCPtr<CSSStyleSheet> m_parent_style_sheet; |
76 | | |
77 | | mutable Optional<FlyString> m_cached_layer_name; |
78 | | }; |
79 | | |
80 | | } |