From 1fa1de72fd6b4f64c7f91fee69090e11cb1f7ad9 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Fri, 12 Jun 2026 22:23:52 +1200 Subject: [PATCH] LibWeb: Simplify `ImageProvider` frame getters Merge `current_image_frame` and `current_image_frame_sized` into a single method which takes an `Optional`. Rename `default_image_frame_sized` to `default_image_frame` and make it's `Gfx::IntSize` argument `Optional`. --- Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp | 4 ++-- Libraries/LibWeb/Layout/ImageProvider.cpp | 13 ++++--------- Libraries/LibWeb/Layout/ImageProvider.h | 6 ++---- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp index 79983d699e..f94db85a3c 100644 --- a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp +++ b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp @@ -481,9 +481,9 @@ GC::Ref WindowOrWorkerGlobalScopeMixin::create_image_bitmap_imp // the animation. Optional decoded_frame; if (has_natural_dimensions) { - decoded_frame = image_element->default_image_frame_sized(Gfx::IntSize { *image_element->intrinsic_width(), *image_element->intrinsic_height() }); + decoded_frame = image_element->default_image_frame(Gfx::IntSize { *image_element->intrinsic_width(), *image_element->intrinsic_height() }); } else { - decoded_frame = image_element->default_image_frame_sized(Gfx::IntSize { *options->resize_width, *options->resize_height }); + decoded_frame = image_element->default_image_frame(Gfx::IntSize { *options->resize_width, *options->resize_height }); } auto cropped_bitmap_or_error = crop_to_the_source_rectangle_with_formatting(decoded_frame->bitmap(), sx, sy, sw, sh, options); // AD-HOC: Reject promise with an "InvalidStateError" DOMException on allocation failure diff --git a/Libraries/LibWeb/Layout/ImageProvider.cpp b/Libraries/LibWeb/Layout/ImageProvider.cpp index e5c049d18e..5576a41940 100644 --- a/Libraries/LibWeb/Layout/ImageProvider.cpp +++ b/Libraries/LibWeb/Layout/ImageProvider.cpp @@ -47,22 +47,17 @@ Optional ImageProvider::intrinsic_size() const return CSSPixelSize { *width, *height }; } -Optional ImageProvider::current_image_frame() const -{ - return current_image_frame_sized(intrinsic_size().value_or({}).to_type()); -} - -Optional ImageProvider::current_image_frame_sized(Gfx::IntSize size) const +Optional ImageProvider::current_image_frame(Optional size) const { if (auto const& data = decoded_image_data()) - return data->frame(current_frame_index(), size); + return data->frame(current_frame_index(), size.value_or(intrinsic_size().value_or({}).to_type())); return {}; } -Optional ImageProvider::default_image_frame_sized(Gfx::IntSize size) const +Optional ImageProvider::default_image_frame(Optional size) const { if (auto const& data = decoded_image_data()) - return data->frame(0, size); + return data->frame(0, size.value_or(intrinsic_size().value_or({}).to_type())); return {}; } diff --git a/Libraries/LibWeb/Layout/ImageProvider.h b/Libraries/LibWeb/Layout/ImageProvider.h index 4a63e653ef..faea07eb3b 100644 --- a/Libraries/LibWeb/Layout/ImageProvider.h +++ b/Libraries/LibWeb/Layout/ImageProvider.h @@ -30,10 +30,8 @@ public: Optional intrinsic_size() const; Optional intrinsic_aspect_ratio() const; - Optional current_image_frame() const; - Optional current_image_frame_sized(Gfx::IntSize) const; - - Optional default_image_frame_sized(Gfx::IntSize) const; + Optional current_image_frame(Optional size = {}) const; + Optional default_image_frame(Optional size = {}) const; virtual void layout_node_was_detached() const { }