1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:28:11 +00:00

LibWeb: Add CSSRuleList

"The CSSRuleList interface represents an ordered collection of CSS style
rules." - https://www.w3.org/TR/cssom-1/#the-cssrulelist-interface
This commit is contained in:
Sam Atkins 2021-09-28 15:17:11 +01:00 committed by Andreas Kling
parent 2758d99bbc
commit 97a78cdd28
4 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Iterator.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <LibWeb/CSS/CSSRule.h>
#include <LibWeb/Forward.h>
namespace Web::CSS {
class CSSRuleList {
public:
explicit CSSRuleList(NonnullRefPtrVector<CSSRule>&&);
virtual ~CSSRuleList();
RefPtr<CSSRule> item(size_t index) const
{
if (index >= length())
return nullptr;
return m_rules[index];
}
size_t length() const { return m_rules.size(); }
using ConstIterator = AK::SimpleIterator<AK::NonnullPtrVector<NonnullRefPtr<CSSRule>> const, CSSRule const>;
using Iterator = AK::SimpleIterator<AK::NonnullPtrVector<NonnullRefPtr<CSSRule>>, CSSRule>;
ConstIterator const begin() const { return m_rules.begin(); }
Iterator begin() { return m_rules.begin(); }
ConstIterator const end() const { return m_rules.end(); }
Iterator end() { return m_rules.end(); }
private:
NonnullRefPtrVector<CSSRule> m_rules;
};
}