mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:07:45 +00:00
LibWeb: Reimplement the <style> element following the spec
We now follow the "update a style block" algorithm from the HTML spec instead of using the ad-hoc CSSLoader mechanism. This necessitated improving our StyleSheet and CSSStyleSheet classes as well, so that's baked into this commit.
This commit is contained in:
parent
6cda24097b
commit
d462a6720a
7 changed files with 163 additions and 24 deletions
|
@ -27,6 +27,8 @@ public:
|
|||
|
||||
virtual ~CSSStyleSheet() override;
|
||||
|
||||
void set_owner_css_rule(CSSRule* rule) { m_owner_css_rule = rule; }
|
||||
|
||||
virtual String type() const override { return "text/css"; }
|
||||
|
||||
CSSRuleList const& rules() const { return m_rules; }
|
||||
|
@ -76,6 +78,9 @@ private:
|
|||
explicit CSSStyleSheet(NonnullRefPtrVector<CSSRule>);
|
||||
|
||||
NonnullRefPtr<CSSRuleList> m_rules;
|
||||
|
||||
// FIXME: Use WeakPtr.
|
||||
CSSRule* m_owner_css_rule { nullptr };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,11 +26,39 @@ public:
|
|||
DOM::Element* owner_node() { return m_owner_node; }
|
||||
void set_owner_node(DOM::Element*);
|
||||
|
||||
String title() const { return m_title; }
|
||||
void set_title(String title) { m_title = move(title); }
|
||||
|
||||
void set_type(String type) { m_type_string = move(type); }
|
||||
void set_media(String media) { m_media_string = move(media); }
|
||||
|
||||
bool is_alternate() const { return m_alternate; }
|
||||
void set_alternate(bool alternate) { m_alternate = alternate; }
|
||||
|
||||
void set_origin_clean(bool origin_clean) { m_origin_clean = origin_clean; }
|
||||
|
||||
bool disabled() const { return m_disabled; }
|
||||
void set_disabled(bool disabled) { m_disabled = disabled; }
|
||||
|
||||
CSSStyleSheet* parent_style_sheet() { return m_parent_style_sheet; }
|
||||
void set_parent_css_style_sheet(CSSStyleSheet* sheet) { m_parent_style_sheet = sheet; }
|
||||
|
||||
protected:
|
||||
StyleSheet() = default;
|
||||
|
||||
private:
|
||||
WeakPtr<DOM::Element> m_owner_node;
|
||||
|
||||
// FIXME: Use WeakPtr.
|
||||
CSSStyleSheet* m_parent_style_sheet { nullptr };
|
||||
|
||||
String m_title;
|
||||
String m_type_string;
|
||||
String m_media_string;
|
||||
|
||||
bool m_disabled { false };
|
||||
bool m_alternate { false };
|
||||
bool m_origin_clean { true };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ interface StyleSheet {
|
|||
readonly attribute CSSOMString type;
|
||||
|
||||
// readonly attribute USVString? href;
|
||||
// readonly attribute CSSStyleSheet? parentStyleSheet;
|
||||
// readonly attribute DOMString? title;
|
||||
readonly attribute CSSStyleSheet? parentStyleSheet;
|
||||
readonly attribute DOMString? title;
|
||||
// [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
|
||||
// attribute boolean disabled;
|
||||
attribute boolean disabled;
|
||||
|
||||
};
|
||||
|
|
|
@ -10,9 +10,15 @@ namespace Web::CSS {
|
|||
|
||||
void StyleSheetList::add_sheet(NonnullRefPtr<CSSStyleSheet> sheet)
|
||||
{
|
||||
VERIFY(!m_sheets.contains_slow(sheet));
|
||||
m_sheets.append(move(sheet));
|
||||
}
|
||||
|
||||
void StyleSheetList::remove_sheet(CSSStyleSheet& sheet)
|
||||
{
|
||||
m_sheets.remove_first_matching([&](auto& entry) { return &*entry == &sheet; });
|
||||
}
|
||||
|
||||
StyleSheetList::StyleSheetList(DOM::Document& document)
|
||||
: m_document(document)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,8 @@ public:
|
|||
}
|
||||
|
||||
void add_sheet(NonnullRefPtr<CSSStyleSheet>);
|
||||
void remove_sheet(CSSStyleSheet&);
|
||||
|
||||
const NonnullRefPtrVector<CSSStyleSheet>& sheets() const { return m_sheets; }
|
||||
|
||||
RefPtr<CSSStyleSheet> item(size_t index) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue