mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibWeb: Align StyleSheet title getter with the specification
The CSSOM specification says that StyleSheet.title should return null if the title field is empty.
This commit is contained in:
parent
b9df8deba2
commit
84193f2746
Notes:
sideshowbarker
2024-07-17 06:28:38 +09:00
Author: https://github.com/tcl3
Commit: 84193f2746
Pull-request: https://github.com/SerenityOS/serenity/pull/24150
6 changed files with 22 additions and 13 deletions
|
@ -36,4 +36,14 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,8 +29,9 @@ public:
|
|||
Optional<String> location() const { return m_location; }
|
||||
void set_location(Optional<String> location) { m_location = move(location); }
|
||||
|
||||
Optional<String> title() const { return m_title; }
|
||||
void set_title(Optional<String> title) { m_title = move(title); }
|
||||
String title() const { return m_title; }
|
||||
Optional<String> title_for_bindings() const;
|
||||
void set_title(String title) { m_title = move(title); }
|
||||
|
||||
void set_type(String type) { m_type_string = move(type); }
|
||||
|
||||
|
@ -66,7 +67,7 @@ private:
|
|||
JS::GCPtr<CSSStyleSheet> m_parent_style_sheet;
|
||||
|
||||
Optional<String> m_location;
|
||||
Optional<String> m_title;
|
||||
String m_title;
|
||||
String m_type_string;
|
||||
|
||||
bool m_disabled { false };
|
||||
|
|
|
@ -13,7 +13,7 @@ interface StyleSheet {
|
|||
readonly attribute Element? ownerNode;
|
||||
|
||||
readonly attribute CSSStyleSheet? parentStyleSheet;
|
||||
readonly attribute DOMString? title;
|
||||
[ImplementedAs=title_for_bindings] readonly attribute DOMString? title;
|
||||
[SameObject, PutForwards=mediaText] readonly attribute MediaList media;
|
||||
attribute boolean disabled;
|
||||
|
||||
|
|
|
@ -36,11 +36,9 @@ void StyleSheetList::add_a_css_style_sheet(CSS::CSSStyleSheet& sheet)
|
|||
if (sheet.disabled())
|
||||
return;
|
||||
|
||||
VERIFY(sheet.title().has_value());
|
||||
|
||||
// 3. If the title is not the empty string, the alternate flag is unset, and preferred CSS style sheet set name is the empty string change the preferred CSS style sheet set name to the title.
|
||||
if (!sheet.title()->is_empty() && !sheet.is_alternate() && m_preferred_css_style_sheet_set_name.is_empty()) {
|
||||
m_preferred_css_style_sheet_set_name = sheet.title().value();
|
||||
if (!sheet.title().is_empty() && !sheet.is_alternate() && m_preferred_css_style_sheet_set_name.is_empty()) {
|
||||
m_preferred_css_style_sheet_set_name = sheet.title();
|
||||
}
|
||||
|
||||
// 4. If any of the following is true, then unset the disabled flag and return:
|
||||
|
@ -50,9 +48,9 @@ void StyleSheetList::add_a_css_style_sheet(CSS::CSSStyleSheet& sheet)
|
|||
// NOTE: We don't enable alternate sheets with an empty title. This isn't directly mentioned in the algorithm steps, but the
|
||||
// HTML specification says that the title element must be specified with a non-empty value for alternative style sheets.
|
||||
// See: https://html.spec.whatwg.org/multipage/links.html#the-link-is-an-alternative-stylesheet
|
||||
if ((sheet.title()->is_empty() && !sheet.is_alternate())
|
||||
|| (!m_last_css_style_sheet_set_name.has_value() && sheet.title().value().equals_ignoring_case(m_preferred_css_style_sheet_set_name))
|
||||
|| (m_last_css_style_sheet_set_name.has_value() && sheet.title().value().equals_ignoring_case(m_last_css_style_sheet_set_name.value()))) {
|
||||
if ((sheet.title().is_empty() && !sheet.is_alternate())
|
||||
|| (!m_last_css_style_sheet_set_name.has_value() && sheet.title().equals_ignoring_case(m_preferred_css_style_sheet_set_name))
|
||||
|| (m_last_css_style_sheet_set_name.has_value() && sheet.title().equals_ignoring_case(m_last_css_style_sheet_set_name.value()))) {
|
||||
sheet.set_disabled(false);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue