mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:27:35 +00:00
LibHTML: Use NonnullRefPtrVector in LibHTML.
This commit is contained in:
parent
48108ec474
commit
7cc9ce8380
5 changed files with 15 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
||||||
#include <LibHTML/CSS/StyleRule.h>
|
#include <LibHTML/CSS/StyleRule.h>
|
||||||
|
|
||||||
StyleRule::StyleRule(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDeclaration>>&& declarations)
|
StyleRule::StyleRule(Vector<Selector>&& selectors, NonnullRefPtrVector<StyleDeclaration>&& declarations)
|
||||||
: m_selectors(move(selectors))
|
: m_selectors(move(selectors))
|
||||||
, m_declarations(move(declarations))
|
, m_declarations(move(declarations))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Vector.h>
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
#include <LibHTML/CSS/Selector.h>
|
#include <LibHTML/CSS/Selector.h>
|
||||||
#include <LibHTML/CSS/StyleDeclaration.h>
|
#include <LibHTML/CSS/StyleDeclaration.h>
|
||||||
|
|
||||||
class StyleRule : public RefCounted<StyleRule> {
|
class StyleRule : public RefCounted<StyleRule> {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<StyleRule> create(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDeclaration>>&& declarations)
|
static NonnullRefPtr<StyleRule> create(Vector<Selector>&& selectors, NonnullRefPtrVector<StyleDeclaration>&& declarations)
|
||||||
{
|
{
|
||||||
return adopt(*new StyleRule(move(selectors), move(declarations)));
|
return adopt(*new StyleRule(move(selectors), move(declarations)));
|
||||||
}
|
}
|
||||||
|
@ -14,18 +14,18 @@ public:
|
||||||
~StyleRule();
|
~StyleRule();
|
||||||
|
|
||||||
const Vector<Selector>& selectors() const { return m_selectors; }
|
const Vector<Selector>& selectors() const { return m_selectors; }
|
||||||
const Vector<NonnullRefPtr<StyleDeclaration>>& declarations() const { return m_declarations; }
|
const NonnullRefPtrVector<StyleDeclaration>& declarations() const { return m_declarations; }
|
||||||
|
|
||||||
template<typename C>
|
template<typename C>
|
||||||
void for_each_declaration(C callback) const
|
void for_each_declaration(C callback) const
|
||||||
{
|
{
|
||||||
for (auto& declaration : m_declarations)
|
for (auto& declaration : m_declarations)
|
||||||
callback(*declaration);
|
callback(declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StyleRule(Vector<Selector>&&, Vector<NonnullRefPtr<StyleDeclaration>>&&);
|
StyleRule(Vector<Selector>&&, NonnullRefPtrVector<StyleDeclaration>&&);
|
||||||
|
|
||||||
Vector<Selector> m_selectors;
|
Vector<Selector> m_selectors;
|
||||||
Vector<NonnullRefPtr<StyleDeclaration>> m_declarations;
|
NonnullRefPtrVector<StyleDeclaration> m_declarations;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <LibHTML/CSS/StyleSheet.h>
|
#include <LibHTML/CSS/StyleSheet.h>
|
||||||
|
|
||||||
StyleSheet::StyleSheet(Vector<NonnullRefPtr<StyleRule>>&& rules)
|
StyleSheet::StyleSheet(NonnullRefPtrVector<StyleRule>&& rules)
|
||||||
: m_rules(move(rules))
|
: m_rules(move(rules))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Vector.h>
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
#include <LibHTML/CSS/StyleRule.h>
|
#include <LibHTML/CSS/StyleRule.h>
|
||||||
|
|
||||||
class StyleSheet : public RefCounted<StyleSheet> {
|
class StyleSheet : public RefCounted<StyleSheet> {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<StyleSheet> create(Vector<NonnullRefPtr<StyleRule>>&& rules)
|
static NonnullRefPtr<StyleSheet> create(NonnullRefPtrVector<StyleRule>&& rules)
|
||||||
{
|
{
|
||||||
return adopt(*new StyleSheet(move(rules)));
|
return adopt(*new StyleSheet(move(rules)));
|
||||||
}
|
}
|
||||||
|
|
||||||
~StyleSheet();
|
~StyleSheet();
|
||||||
|
|
||||||
const Vector<NonnullRefPtr<StyleRule>>& rules() const { return m_rules; }
|
const NonnullRefPtrVector<StyleRule>& rules() const { return m_rules; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit StyleSheet(Vector<NonnullRefPtr<StyleRule>>&&);
|
explicit StyleSheet(NonnullRefPtrVector<StyleRule>&&);
|
||||||
|
|
||||||
Vector<NonnullRefPtr<StyleRule>> m_rules;
|
NonnullRefPtrVector<StyleRule> m_rules;
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,7 +73,7 @@ void dump_sheet(const StyleSheet& sheet)
|
||||||
|
|
||||||
for (auto& rule : sheet.rules()) {
|
for (auto& rule : sheet.rules()) {
|
||||||
printf("Rule:\n");
|
printf("Rule:\n");
|
||||||
for (auto& selector : rule->selectors()) {
|
for (auto& selector : rule.selectors()) {
|
||||||
printf(" Selector:\n");
|
printf(" Selector:\n");
|
||||||
for (auto& component : selector.components()) {
|
for (auto& component : selector.components()) {
|
||||||
const char* type_description = "Unknown";
|
const char* type_description = "Unknown";
|
||||||
|
@ -95,7 +95,7 @@ void dump_sheet(const StyleSheet& sheet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf(" Declarations:\n");
|
printf(" Declarations:\n");
|
||||||
rule->for_each_declaration([](auto& declaration) {
|
rule.for_each_declaration([](auto& declaration) {
|
||||||
printf(" '%s': '%s'\n", declaration.property_name().characters(), declaration.value().to_string().characters());
|
printf(" '%s': '%s'\n", declaration.property_name().characters(), declaration.value().to_string().characters());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue