2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <andreas@ladybird.org>
|
2021-02-21 08:45:26 -03:00
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2026-05-06 03:36:34 -03:00
|
|
|
#include <LibJS/Runtime/ExternalMemory.h>
|
2026-04-18 05:54:06 -03:00
|
|
|
#include <LibWeb/Bindings/StyleSheet.h>
|
2021-12-05 11:33:49 -03:00
|
|
|
#include <LibWeb/CSS/CSSStyleSheet.h>
|
2020-03-07 06:32:51 -03:00
|
|
|
#include <LibWeb/CSS/StyleSheet.h>
|
2021-03-08 09:40:53 -03:00
|
|
|
#include <LibWeb/DOM/Element.h>
|
2019-06-20 18:25:25 -03:00
|
|
|
|
2020-07-26 15:01:35 -03:00
|
|
|
namespace Web::CSS {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2022-10-23 15:05:34 -03:00
|
|
|
StyleSheet::StyleSheet(JS::Realm& realm, MediaList& media)
|
2022-09-24 19:34:04 -03:00
|
|
|
: PlatformObject(realm)
|
2022-10-23 15:05:34 -03:00
|
|
|
, m_media(media)
|
2022-08-07 08:14:54 -03:00
|
|
|
{
|
2025-03-04 10:50:11 -03:00
|
|
|
m_media->set_associated_style_sheet(*this);
|
2022-08-07 08:14:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StyleSheet::visit_edges(Cell::Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
2022-09-03 10:44:44 -03:00
|
|
|
visitor.visit(m_owner_node);
|
2022-08-07 08:14:54 -03:00
|
|
|
visitor.visit(m_parent_style_sheet);
|
2022-10-23 15:05:34 -03:00
|
|
|
visitor.visit(m_media);
|
2022-08-07 08:14:54 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-06 03:36:34 -03:00
|
|
|
size_t StyleSheet::external_memory_size() const
|
|
|
|
|
{
|
|
|
|
|
auto size = Base::external_memory_size();
|
|
|
|
|
size = JS::saturating_add_external_memory_size(size, JS::string_external_memory_size(m_title));
|
|
|
|
|
size = JS::saturating_add_external_memory_size(size, JS::string_external_memory_size(m_type_string));
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-08 09:18:56 -03:00
|
|
|
Optional<String> StyleSheet::href() const
|
|
|
|
|
{
|
|
|
|
|
if (m_location.has_value())
|
|
|
|
|
return m_location->to_string();
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 09:40:53 -03:00
|
|
|
void StyleSheet::set_owner_node(DOM::Element* element)
|
|
|
|
|
{
|
2022-09-03 10:44:44 -03:00
|
|
|
m_owner_node = element;
|
2021-03-08 09:40:53 -03:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 11:33:49 -03:00
|
|
|
void StyleSheet::set_parent_css_style_sheet(CSSStyleSheet* parent)
|
|
|
|
|
{
|
|
|
|
|
m_parent_style_sheet = parent;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 10:32:52 -03:00
|
|
|
// https://drafts.csswg.org/cssom/#dom-stylesheet-title
|
|
|
|
|
Optional<String> StyleSheet::title_for_bindings() const
|
|
|
|
|
{
|
|
|
|
|
// The title attribute must return the title or null if title is the empty string.
|
|
|
|
|
if (m_title.is_empty())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
return m_title;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|