LibWeb: Forward media attribute from link element to loaded style sheet

Otherwise, we will treat the loaded style sheet as if it had media="all"
which is not always appropriate.
This commit is contained in:
Andreas Kling 2023-06-10 19:53:36 +02:00
parent a6c6c24428
commit 8a43f5a64a
Notes: sideshowbarker 2024-07-17 06:51:40 +09:00
4 changed files with 22 additions and 0 deletions

View file

@ -0,0 +1 @@
document background: rgb(0, 128, 0)

View file

@ -0,0 +1,3 @@
body {
background-color: red;
}

View file

@ -0,0 +1,17 @@
<style>
body {
background: green;
}
</style>
<script src="include.js"></script>
<script>
let link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("href", "body-background-color-red.css");
link.setAttribute("media", "print")
document.head.appendChild(link)
window.onload = function() {
println("document background: " + getComputedStyle(document.body).backgroundColor)
}
</script>

View file

@ -364,6 +364,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru
if (m_loaded_style_sheet) {
m_loaded_style_sheet->set_owner_node(this);
m_loaded_style_sheet->set_media(attribute(HTML::AttributeNames::media));
document().style_sheets().add_sheet(*m_loaded_style_sheet);
} else {
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Failed to parse stylesheet: {}", resource()->url());