mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb: Add loading event to style element
This commit is contained in:
parent
ce2c4a3417
commit
7260159b8f
Notes:
github-actions[bot]
2025-11-30 18:23:06 +00:00
Author: https://github.com/lpas
Commit: 7260159b8f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6479
7 changed files with 87 additions and 40 deletions
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Preston Taylor <PrestonLeeTaylor@proton.me>
|
||||
* Copyright (c) 2025, Lorenz Ackermann <me@lorenzackermann.xyz>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
|
@ -8,6 +9,7 @@
|
|||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/ShadowRoot.h>
|
||||
#include <LibWeb/DOM/StyleElementUtils.h>
|
||||
#include <LibWeb/Infra/Strings.h>
|
||||
|
|
@ -97,6 +99,38 @@ void StyleElementUtils::update_a_style_block(DOM::Element& style_element)
|
|||
style_element.document().script_blocking_style_sheet_set().set(style_element);
|
||||
|
||||
// FIXME: 8. If element's media attribute's value matches the environment and element is potentially render-blocking, then block rendering on element.
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/semantics.html#the-style-element:critical-subresources
|
||||
auto attempts_to_fetch_subresources_finished = [](GC::Ptr<CSS::CSSStyleSheet> style_sheet) {
|
||||
// 1. Let element be the style element associated with the style sheet in question.
|
||||
auto& element = *style_sheet->owner_node();
|
||||
// 2. Let success be true.
|
||||
auto success = true;
|
||||
// FIXME: 3. If the attempts to obtain any of the style sheet's critical subresources failed for any reason
|
||||
// (e.g., DNS error, HTTP 404 response, a connection being prematurely closed, unsupported Content-Type), set success to false.
|
||||
// Note: that content-specific errors, e.g., CSS parse errors or PNG decoding errors, do not affect success.
|
||||
// 4. Queue an element task on the networking task source given element and the following steps:
|
||||
element.queue_an_element_task(HTML::Task::Source::UserInteraction, [&element, success] {
|
||||
// 1. If success is true, fire an event named load at element.
|
||||
// AD-HOC: these should call fire an event this is not implemented anywhere so we dispatch ourself
|
||||
if (success)
|
||||
element.dispatch_event(DOM::Event::create(element.realm(), HTML::EventNames::load));
|
||||
// 2. Otherwise, fire an event named error at element.
|
||||
else
|
||||
element.dispatch_event(DOM::Event::create(element.realm(), HTML::EventNames::error));
|
||||
// 3. If element contributes a script-blocking style sheet:
|
||||
if (element.contributes_a_script_blocking_style_sheet()) {
|
||||
// 1. Assert: element's node document's script-blocking style sheet set contains element.
|
||||
VERIFY(element.document().script_blocking_style_sheet_set().contains(element));
|
||||
// 2. Remove element from its node document's script-blocking style sheet set.
|
||||
element.document().script_blocking_style_sheet_set().remove(element);
|
||||
}
|
||||
// 4. Unblock rendering on element.
|
||||
element.unblock_rendering();
|
||||
});
|
||||
};
|
||||
// FIXME: The element must delay the load event of the element's node document until all the attempts to obtain the style sheet's critical subresources, if any, are complete.
|
||||
attempts_to_fetch_subresources_finished(m_associated_css_style_sheet);
|
||||
}
|
||||
|
||||
void StyleElementUtils::visit_edges(JS::Cell::Visitor& visitor)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue