mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +00:00
LibWeb: Create base class CSSRule for all CSS rules
This is a foundation for handling other ("at") CSS rules.
This commit is contained in:
parent
b807d51598
commit
04d67d0239
12 changed files with 147 additions and 17 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -27,26 +28,37 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <LibWeb/CSS/StyleRule.h>
|
||||
#include <AK/TypeCasts.h>
|
||||
#include <LibWeb/CSS/CSSRule.h>
|
||||
#include <LibWeb/Loader/Resource.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class StyleSheet : public RefCounted<StyleSheet> {
|
||||
public:
|
||||
static NonnullRefPtr<StyleSheet> create(NonnullRefPtrVector<StyleRule>&& rules)
|
||||
static NonnullRefPtr<StyleSheet> create(NonnullRefPtrVector<CSSRule>&& rules)
|
||||
{
|
||||
return adopt(*new StyleSheet(move(rules)));
|
||||
}
|
||||
|
||||
~StyleSheet();
|
||||
|
||||
const NonnullRefPtrVector<StyleRule>& rules() const { return m_rules; }
|
||||
NonnullRefPtrVector<StyleRule>& rules() { return m_rules; }
|
||||
const NonnullRefPtrVector<CSSRule>& rules() const { return m_rules; }
|
||||
NonnullRefPtrVector<CSSRule>& rules() { return m_rules; }
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_effective_style_rule(Callback callback) const
|
||||
{
|
||||
for (auto& rule : m_rules)
|
||||
if (rule.type() == CSSRule::Type::Style) {
|
||||
callback(downcast<StyleRule>(rule));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
explicit StyleSheet(NonnullRefPtrVector<StyleRule>&&);
|
||||
explicit StyleSheet(NonnullRefPtrVector<CSSRule>&&);
|
||||
|
||||
NonnullRefPtrVector<StyleRule> m_rules;
|
||||
NonnullRefPtrVector<CSSRule> m_rules;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue