mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:28:11 +00:00
LibWeb: Make StyleSheetList GC-allocated
This commit is contained in:
parent
5d60212076
commit
5366924f11
14 changed files with 68 additions and 37 deletions
|
@ -1,9 +1,10 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/StyleSheetListPrototype.h>
|
||||
#include <LibWeb/CSS/StyleSheetList.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
||||
|
@ -12,7 +13,7 @@ namespace Web::CSS {
|
|||
void StyleSheetList::add_sheet(CSSStyleSheet& sheet)
|
||||
{
|
||||
sheet.set_style_sheet_list({}, this);
|
||||
m_sheets.append(JS::make_handle(sheet));
|
||||
m_sheets.append(sheet);
|
||||
|
||||
m_document.style_computer().invalidate_rule_cache();
|
||||
m_document.style_computer().load_fonts_from_sheet(sheet);
|
||||
|
@ -22,15 +23,30 @@ void StyleSheetList::add_sheet(CSSStyleSheet& sheet)
|
|||
void StyleSheetList::remove_sheet(CSSStyleSheet& sheet)
|
||||
{
|
||||
sheet.set_style_sheet_list({}, nullptr);
|
||||
m_sheets.remove_first_matching([&](auto& entry) { return &*entry == &sheet; });
|
||||
m_sheets.remove_first_matching([&](auto& entry) { return &entry == &sheet; });
|
||||
|
||||
m_document.style_computer().invalidate_rule_cache();
|
||||
m_document.invalidate_style();
|
||||
}
|
||||
|
||||
StyleSheetList::StyleSheetList(DOM::Document& document)
|
||||
: m_document(document)
|
||||
StyleSheetList* StyleSheetList::create(DOM::Document& document)
|
||||
{
|
||||
auto& realm = document.preferred_window_object().realm();
|
||||
return realm.heap().allocate<StyleSheetList>(realm, document);
|
||||
}
|
||||
|
||||
StyleSheetList::StyleSheetList(DOM::Document& document)
|
||||
: Bindings::LegacyPlatformObject(document.preferred_window_object().ensure_web_prototype<Bindings::StyleSheetListPrototype>("StyleSheetList"))
|
||||
, m_document(document)
|
||||
{
|
||||
}
|
||||
|
||||
void StyleSheetList::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_document);
|
||||
for (auto& sheet : m_sheets)
|
||||
visitor.visit(&sheet);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom/#ref-for-dfn-supported-property-indices%E2%91%A1
|
||||
|
@ -44,4 +60,12 @@ bool StyleSheetList::is_supported_property_index(u32 index) const
|
|||
return index < m_sheets.size();
|
||||
}
|
||||
|
||||
JS::Value StyleSheetList::item_value(size_t index) const
|
||||
{
|
||||
if (index >= m_sheets.size())
|
||||
return JS::js_undefined();
|
||||
|
||||
return &m_sheets[index];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue