ladybird/Userland/Libraries/LibWeb/CSS/StyleSheet.cpp
Tim Ledbetter 84193f2746 LibWeb: Align StyleSheet title getter with the specification
The CSSOM specification says that StyleSheet.title should return null
if the title field is empty.
2024-04-29 08:10:38 +02:00

50 lines
1.1 KiB
C++

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/StyleSheetPrototype.h>
#include <LibWeb/CSS/CSSStyleSheet.h>
#include <LibWeb/CSS/StyleSheet.h>
#include <LibWeb/DOM/Element.h>
namespace Web::CSS {
StyleSheet::StyleSheet(JS::Realm& realm, MediaList& media)
: PlatformObject(realm)
, m_media(media)
{
}
void StyleSheet::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_owner_node);
visitor.visit(m_parent_style_sheet);
visitor.visit(m_media);
}
void StyleSheet::set_owner_node(DOM::Element* element)
{
m_owner_node = element;
}
void StyleSheet::set_parent_css_style_sheet(CSSStyleSheet* parent)
{
m_parent_style_sheet = parent;
}
// 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;
}
}