mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:27:44 +00:00
LibWeb: Add styleSheets and adoptedStyleSheets attributes in ShadowRoot
Co-authored-by: Simon Wanner <simon+git@skyrising.xyz>
This commit is contained in:
parent
f19c92d78e
commit
8ce8697a66
11 changed files with 138 additions and 37 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/DOM/AdoptedStyleSheets.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/ShadowRoot.h>
|
||||
|
@ -54,4 +55,47 @@ WebIDL::ExceptionOr<void> ShadowRoot::set_inner_html(StringView markup)
|
|||
return {};
|
||||
}
|
||||
|
||||
CSS::StyleSheetList& ShadowRoot::style_sheets()
|
||||
{
|
||||
if (!m_style_sheets)
|
||||
m_style_sheets = CSS::StyleSheetList::create(document());
|
||||
return *m_style_sheets;
|
||||
}
|
||||
|
||||
CSS::StyleSheetList const& ShadowRoot::style_sheets() const
|
||||
{
|
||||
return const_cast<ShadowRoot*>(this)->style_sheets();
|
||||
}
|
||||
|
||||
void ShadowRoot::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_style_sheets);
|
||||
visitor.visit(m_adopted_style_sheets);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<WebIDL::ObservableArray> ShadowRoot::adopted_style_sheets() const
|
||||
{
|
||||
if (!m_adopted_style_sheets)
|
||||
m_adopted_style_sheets = create_adopted_style_sheets_list(const_cast<Document&>(document()));
|
||||
return *m_adopted_style_sheets;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> ShadowRoot::set_adopted_style_sheets(JS::Value new_value)
|
||||
{
|
||||
if (!m_adopted_style_sheets)
|
||||
m_adopted_style_sheets = create_adopted_style_sheets_list(const_cast<Document&>(document()));
|
||||
|
||||
m_adopted_style_sheets->clear();
|
||||
auto iterator_record = TRY(get_iterator(vm(), new_value, JS::IteratorHint::Sync));
|
||||
while (true) {
|
||||
auto next = TRY(iterator_step_value(vm(), iterator_record));
|
||||
if (!next.has_value())
|
||||
break;
|
||||
TRY(m_adopted_style_sheets->append(*next));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue