/* * Copyright (c) 2019-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Web::CSS { class CSSStyleSheet final : public StyleSheet { public: using WrapperType = Bindings::CSSStyleSheetWrapper; static NonnullRefPtr create(NonnullRefPtrVector rules) { return adopt_ref(*new CSSStyleSheet(move(rules))); } virtual ~CSSStyleSheet() override; virtual String type() const override { return "text/css"; } const NonnullRefPtrVector& rules() const { return m_rules; } NonnullRefPtrVector& rules() { return m_rules; } template void for_each_effective_style_rule(Callback callback) const { for (auto& rule : m_rules) if (rule.type() == CSSRule::Type::Style) { callback(verify_cast(rule)); } else if (rule.type() == CSSRule::Type::Import) { const auto& import_rule = verify_cast(rule); if (import_rule.has_import_result()) import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback); } } template bool for_first_not_loaded_import_rule(Callback callback) { for (auto& rule : m_rules) if (rule.type() == CSSRule::Type::Import) { auto& import_rule = verify_cast(rule); if (!import_rule.has_import_result()) { callback(import_rule); return true; } if (import_rule.loaded_style_sheet()->for_first_not_loaded_import_rule(callback)) { return true; } } return false; } private: explicit CSSStyleSheet(NonnullRefPtrVector); NonnullRefPtrVector m_rules; }; } namespace Web::Bindings { CSSStyleSheetWrapper* wrap(JS::GlobalObject&, CSS::CSSStyleSheet&); }