1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibWeb: Improve media document styling to center image

This commit is contained in:
Bastiaan van der Plaat 2024-01-06 17:32:22 +01:00 committed by Andreas Kling
parent 042d3b79c2
commit e33ae9a58b

View file

@ -335,6 +335,24 @@ static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOM::Document>> load_media_document(
return {};
};
auto style_element = TRY(DOM::create_element(document, HTML::TagNames::style, Namespace::HTML));
style_element->set_text_content(R"~~~(
:root {
background-color: #222;
}
img, video, audio {
position: absolute;
inset: 0;
max-width: 100vw;
max-height: 100vh;
margin: auto;
}
img {
background-color: #fff;
}
)~~~"_string);
TRY(document->head()->append_child(style_element));
auto url_string = document->url_string();
if (type.is_image()) {
auto img_element = TRY(DOM::create_element(document, HTML::TagNames::img, Namespace::HTML));