summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Layout
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-05-20 16:27:31 +0200
committerAndreas Kling <kling@serenityos.org>2023-05-21 07:44:29 +0200
commit8d3240d633ea7f8fcaf04a41118c02f68c2d94c1 (patch)
tree91850b829ea8f5354b570992d6557296c4d1c752 /Userland/Libraries/LibWeb/Layout
parent4ee1e5b2240bc10f54ede9763c32a26856537a8e (diff)
downloadserenity-8d3240d633ea7f8fcaf04a41118c02f68c2d94c1.zip
LibWeb: Make ImageBox ask ImageProvider for intrinsic size and ratio
This paves the way for ImageProvider to have something vector-based underneath. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout')
-rw-r--r--Userland/Libraries/LibWeb/Layout/ImageBox.cpp15
-rw-r--r--Userland/Libraries/LibWeb/Layout/ImageProvider.h6
2 files changed, 9 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp
index 22770d00e6..5aa621f70b 100644
--- a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp
@@ -23,18 +23,9 @@ ImageBox::~ImageBox() = default;
void ImageBox::prepare_for_replaced_layout()
{
- auto bitmap = m_image_provider.current_image_bitmap();
-
- if (!bitmap) {
- set_intrinsic_width(0);
- set_intrinsic_height(0);
- } else {
- auto width = bitmap->width();
- auto height = bitmap->height();
- set_intrinsic_width(width);
- set_intrinsic_height(height);
- set_intrinsic_aspect_ratio(static_cast<float>(width) / static_cast<float>(height));
- }
+ set_intrinsic_width(m_image_provider.intrinsic_width());
+ set_intrinsic_height(m_image_provider.intrinsic_height());
+ set_intrinsic_aspect_ratio(m_image_provider.intrinsic_aspect_ratio());
if (renders_as_alt_text()) {
auto& image_element = verify_cast<HTML::HTMLImageElement>(dom_node());
diff --git a/Userland/Libraries/LibWeb/Layout/ImageProvider.h b/Userland/Libraries/LibWeb/Layout/ImageProvider.h
index 39537295c2..1a45c3de8b 100644
--- a/Userland/Libraries/LibWeb/Layout/ImageProvider.h
+++ b/Userland/Libraries/LibWeb/Layout/ImageProvider.h
@@ -6,12 +6,18 @@
#pragma once
+#include <LibWeb/PixelUnits.h>
+
namespace Web::Layout {
class ImageProvider {
public:
virtual ~ImageProvider() { }
+ virtual Optional<CSSPixels> intrinsic_width() const = 0;
+ virtual Optional<CSSPixels> intrinsic_height() const = 0;
+ virtual Optional<float> intrinsic_aspect_ratio() const = 0;
+
virtual RefPtr<Gfx::Bitmap const> current_image_bitmap() const = 0;
virtual void set_visible_in_viewport(bool) = 0;
};