LibWeb: Update stylesheet media value when changing link media attribute

This commit is contained in:
Colin Reeder 2024-08-10 18:07:02 -06:00 committed by Andreas Kling
parent b92abe5c26
commit 00f75648e5
Notes: github-actions[bot] 2024-08-13 12:13:49 +00:00
5 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1 @@
document background: rgba(0, 0, 0, 0)

View file

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

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="body-background-color-red.css" media="all" onload="this.media='none'">
</head>
<body>
<script src="include.js"></script>
<script>
test(() => {
window.onload = function () {
println("document background: " + getComputedStyle(document.body).backgroundColor);
};
});
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="body-background-color-red.css" media="print" onload="this.media='all'">
</head>
<body>
<script src="include.js"></script>
<script>
test(() => {
window.onload = function () {
println("document background: " + getComputedStyle(document.body).backgroundColor);
};
});
</script>
</body>
</html>

View file

@ -187,6 +187,10 @@ void HTMLLinkElement::attribute_changed(FlyString const& name, Optional<String>
)) {
fetch_and_process_linked_resource();
}
if (name == HTML::AttributeNames::media && m_loaded_style_sheet) {
m_loaded_style_sheet->set_media(value.value_or(String {}));
}
}
}