ladybird/Libraries/LibWeb/DOM/StyleElementBase.h
Sam Atkins 873680a504 LibWeb: Delay the load event until critical style subresources load
Previously, `<link rel=stylesheet>` would delay the load event until its
style sheet loaded, but not care about its subresources. `<style>`
would not delay the load event at all. Instead, each `@import` would
delay the load event.

Now, both `<style>` and `<link>` delay the load event until their style
sheet and its critical subresources have loaded or failed. This means
that CSSImportRules no longer need to delay the load event themselves,
because they do so implicitly as a critical subresource of their parent
style sheet.

This doesn't directly affect behavior, but means that any other critical
style resources we add will automatically delay the load event.

One wrinkle here is that the spec for the `<link>` element requires that
we wait for the style sheet's critical subresources *before* we create
a CSSStyleSheet, which means we don't yet know what those are.
https://html.spec.whatwg.org/multipage/semantics.html#fetching-and-processing-a-resource-from-a-link-element:critical-subresources
For now we simply ignore this, as we did before. That means we continue
to not delay the `<link>`'s load event.
2026-02-12 16:23:12 +01:00

47 lines
1.2 KiB
C++

/*
* Copyright (c) 2023, Preston Taylor <PrestonLeeTaylor@proton.me>
* Copyright (c) 2026, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/CSSStyleSheet.h>
#include <LibWeb/DOM/DocumentLoadEventDelayer.h>
#include <LibWeb/Forward.h>
namespace Web::DOM {
class StyleElementBase {
public:
virtual ~StyleElementBase() = default;
void update_a_style_block();
CSS::CSSStyleSheet* sheet();
CSS::CSSStyleSheet const* sheet() const;
[[nodiscard]] GC::Ptr<CSS::StyleSheetList> style_sheet_list() { return m_style_sheet_list; }
[[nodiscard]] GC::Ptr<CSS::StyleSheetList const> style_sheet_list() const { return m_style_sheet_list; }
enum class AnyFailed : u8 {
No,
Yes,
};
void finished_loading_critical_subresources(AnyFailed);
void visit_style_element_edges(JS::Cell::Visitor&);
virtual Element& as_element() = 0;
private:
// https://www.w3.org/TR/cssom/#associated-css-style-sheet
GC::Ptr<CSS::CSSStyleSheet> m_associated_css_style_sheet;
GC::Ptr<CSS::StyleSheetList> m_style_sheet_list;
Optional<DocumentLoadEventDelayer> m_document_load_event_delayer;
};
}