2021-02-21 13:45:26 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2021-02-21 13:45:26 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-21 13:45:26 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-12-01 16:55:52 +00:00
|
|
|
#include <AK/String.h>
|
2022-08-07 15:46:44 +02:00
|
|
|
#include <LibJS/Heap/GCPtr.h>
|
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2021-03-13 20:11:33 +01:00
|
|
|
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
2021-02-21 13:45:26 +02:00
|
|
|
#include <LibWeb/CSS/Selector.h>
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
class CSSRule : public Bindings::PlatformObject {
|
2022-09-24 16:34:04 -06:00
|
|
|
WEB_PLATFORM_OBJECT(CSSRule, Bindings::PlatformObject);
|
2021-09-29 19:41:46 +02:00
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
public:
|
2022-03-14 13:21:51 -06:00
|
|
|
virtual ~CSSRule() = default;
|
2021-02-21 13:45:26 +02:00
|
|
|
|
2022-04-11 21:04:47 +02:00
|
|
|
// https://drafts.csswg.org/cssom/#dom-cssrule-type
|
|
|
|
enum class Type : u16 {
|
|
|
|
Style = 1,
|
|
|
|
Import = 3,
|
|
|
|
Media = 4,
|
|
|
|
FontFace = 5,
|
2023-05-26 23:30:54 +03:30
|
|
|
Keyframes = 7,
|
|
|
|
Keyframe = 8,
|
2023-07-29 11:51:15 -05:00
|
|
|
Namespace = 10,
|
2022-04-11 21:04:47 +02:00
|
|
|
Supports = 12,
|
2024-09-02 16:45:25 +01:00
|
|
|
// AD-HOC: These are not included in the spec, but we need them internally. So, their numbers are arbitrary.
|
|
|
|
LayerBlock = 100,
|
|
|
|
LayerStatement = 101,
|
2024-10-15 15:59:31 +01:00
|
|
|
NestedDeclarations = 102,
|
2024-10-17 23:28:09 +01:00
|
|
|
Property = 103, // FIXME: This should return `0` as a type, but type is used for a lot of dispatching
|
2021-02-21 13:45:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual Type type() const = 0;
|
|
|
|
|
2023-11-20 23:16:39 +13:00
|
|
|
String css_text() const;
|
2021-10-01 19:57:45 +02:00
|
|
|
void set_css_text(StringView);
|
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
CSSRule* parent_rule() { return m_parent_rule.ptr(); }
|
2024-09-02 16:45:25 +01:00
|
|
|
CSSRule const* parent_rule() const { return m_parent_rule.ptr(); }
|
2022-04-22 19:56:22 +01:00
|
|
|
void set_parent_rule(CSSRule*);
|
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
CSSStyleSheet* parent_style_sheet() { return m_parent_style_sheet.ptr(); }
|
2022-04-22 19:56:22 +01:00
|
|
|
virtual void set_parent_style_sheet(CSSStyleSheet*);
|
|
|
|
|
2021-03-18 21:50:52 +01:00
|
|
|
template<typename T>
|
|
|
|
bool fast_is() const = delete;
|
|
|
|
|
2024-10-08 12:06:53 +01:00
|
|
|
// https://drafts.csswg.org/cssom-1/#serialize-a-css-rule
|
|
|
|
virtual String serialized() const = 0;
|
|
|
|
|
2021-10-01 19:57:45 +02:00
|
|
|
protected:
|
2022-09-24 16:34:04 -06:00
|
|
|
explicit CSSRule(JS::Realm&);
|
2022-08-07 15:46:44 +02:00
|
|
|
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2024-10-16 14:10:59 +01:00
|
|
|
virtual void clear_caches();
|
|
|
|
|
2024-09-09 17:35:13 +02:00
|
|
|
[[nodiscard]] FlyString const& parent_layer_internal_qualified_name() const
|
|
|
|
{
|
|
|
|
if (!m_cached_layer_name.has_value())
|
|
|
|
return parent_layer_internal_qualified_name_slow_case();
|
|
|
|
return m_cached_layer_name.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] FlyString const& parent_layer_internal_qualified_name_slow_case() const;
|
2024-09-02 16:45:25 +01:00
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
JS::GCPtr<CSSRule> m_parent_rule;
|
|
|
|
JS::GCPtr<CSSStyleSheet> m_parent_style_sheet;
|
2024-09-07 11:45:50 +02:00
|
|
|
|
|
|
|
mutable Optional<FlyString> m_cached_layer_name;
|
2021-02-21 13:45:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|