mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-07 20:31:04 +03:00
LibWeb: Make CSSStyleRule::declaration() return a more specific type
This removes the need for some hot verify_casts in StyleComputer.
This commit is contained in:
parent
7c9368f402
commit
ce2bfb4a12
Notes:
sideshowbarker
2024-07-17 01:55:29 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ce2bfb4a12 Pull-request: https://github.com/SerenityOS/serenity/pull/23637
@ -14,12 +14,12 @@ namespace Web::CSS {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(CSSStyleRule);
|
||||
|
||||
JS::NonnullGCPtr<CSSStyleRule> CSSStyleRule::create(JS::Realm& realm, Vector<NonnullRefPtr<Web::CSS::Selector>>&& selectors, CSSStyleDeclaration& declaration)
|
||||
JS::NonnullGCPtr<CSSStyleRule> CSSStyleRule::create(JS::Realm& realm, Vector<NonnullRefPtr<Web::CSS::Selector>>&& selectors, PropertyOwningCSSStyleDeclaration& declaration)
|
||||
{
|
||||
return realm.heap().allocate<CSSStyleRule>(realm, realm, move(selectors), declaration);
|
||||
}
|
||||
|
||||
CSSStyleRule::CSSStyleRule(JS::Realm& realm, Vector<NonnullRefPtr<Selector>>&& selectors, CSSStyleDeclaration& declaration)
|
||||
CSSStyleRule::CSSStyleRule(JS::Realm& realm, Vector<NonnullRefPtr<Selector>>&& selectors, PropertyOwningCSSStyleDeclaration& declaration)
|
||||
: CSSRule(realm)
|
||||
, m_selectors(move(selectors))
|
||||
, m_declaration(declaration)
|
||||
|
@ -19,12 +19,12 @@ class CSSStyleRule final : public CSSRule {
|
||||
JS_DECLARE_ALLOCATOR(CSSStyleRule);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static JS::NonnullGCPtr<CSSStyleRule> create(JS::Realm&, Vector<NonnullRefPtr<Selector>>&&, CSSStyleDeclaration&);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<CSSStyleRule> create(JS::Realm&, Vector<NonnullRefPtr<Selector>>&&, PropertyOwningCSSStyleDeclaration&);
|
||||
|
||||
virtual ~CSSStyleRule() override = default;
|
||||
|
||||
Vector<NonnullRefPtr<Selector>> const& selectors() const { return m_selectors; }
|
||||
CSSStyleDeclaration const& declaration() const { return m_declaration; }
|
||||
PropertyOwningCSSStyleDeclaration const& declaration() const { return m_declaration; }
|
||||
|
||||
virtual Type type() const override { return Type::Style; }
|
||||
|
||||
@ -34,14 +34,14 @@ public:
|
||||
CSSStyleDeclaration* style();
|
||||
|
||||
private:
|
||||
CSSStyleRule(JS::Realm&, Vector<NonnullRefPtr<Selector>>&&, CSSStyleDeclaration&);
|
||||
CSSStyleRule(JS::Realm&, Vector<NonnullRefPtr<Selector>>&&, PropertyOwningCSSStyleDeclaration&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
virtual String serialized() const override;
|
||||
|
||||
Vector<NonnullRefPtr<Selector>> m_selectors;
|
||||
JS::NonnullGCPtr<CSSStyleDeclaration> m_declaration;
|
||||
JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration> m_declaration;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
@ -730,7 +730,7 @@ void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& e
|
||||
auto properties_for_revert = style.properties();
|
||||
|
||||
for (auto const& match : matching_rules) {
|
||||
for (auto const& property : verify_cast<PropertyOwningCSSStyleDeclaration>(match.rule->declaration()).properties()) {
|
||||
for (auto const& property : match.rule->declaration().properties()) {
|
||||
if (important != property.important)
|
||||
continue;
|
||||
|
||||
@ -772,7 +772,7 @@ static void cascade_custom_properties(DOM::Element& element, Optional<CSS::Selec
|
||||
{
|
||||
size_t needed_capacity = 0;
|
||||
for (auto const& matching_rule : matching_rules)
|
||||
needed_capacity += verify_cast<PropertyOwningCSSStyleDeclaration>(matching_rule.rule->declaration()).custom_properties().size();
|
||||
needed_capacity += matching_rule.rule->declaration().custom_properties().size();
|
||||
|
||||
if (!pseudo_element.has_value()) {
|
||||
if (auto const inline_style = element.inline_style())
|
||||
@ -783,7 +783,7 @@ static void cascade_custom_properties(DOM::Element& element, Optional<CSS::Selec
|
||||
custom_properties.ensure_capacity(needed_capacity);
|
||||
|
||||
for (auto const& matching_rule : matching_rules) {
|
||||
for (auto const& it : verify_cast<PropertyOwningCSSStyleDeclaration>(matching_rule.rule->declaration()).custom_properties())
|
||||
for (auto const& it : matching_rule.rule->declaration().custom_properties())
|
||||
custom_properties.set(it.key, it.value);
|
||||
}
|
||||
|
||||
|
@ -694,15 +694,14 @@ ErrorOr<void> dump_style_rule(StringBuilder& builder, CSS::CSSStyleRule const& r
|
||||
}
|
||||
indent(builder, indent_levels);
|
||||
builder.append(" Declarations:\n"sv);
|
||||
auto& style_declaration = verify_cast<CSS::PropertyOwningCSSStyleDeclaration>(rule.declaration());
|
||||
for (auto& property : style_declaration.properties()) {
|
||||
for (auto& property : rule.declaration().properties()) {
|
||||
indent(builder, indent_levels);
|
||||
builder.appendff(" {}: '{}'", CSS::string_from_property_id(property.property_id), property.value->to_string());
|
||||
if (property.important == CSS::Important::Yes)
|
||||
builder.append(" \033[31;1m!important\033[0m"sv);
|
||||
builder.append('\n');
|
||||
}
|
||||
for (auto& property : style_declaration.custom_properties()) {
|
||||
for (auto& property : rule.declaration().custom_properties()) {
|
||||
indent(builder, indent_levels);
|
||||
builder.appendff(" {}: '{}'", property.key, property.value.value->to_string());
|
||||
if (property.value.important == CSS::Important::Yes)
|
||||
|
Loading…
Reference in New Issue
Block a user