LibWeb: Simplify ImageProvider frame getters
Merge `current_image_frame` and `current_image_frame_sized` into a single method which takes an `Optional<Gfx::IntSize>`. Rename `default_image_frame_sized` to `default_image_frame` and make it's `Gfx::IntSize` argument `Optional`.
This commit is contained in:
parent
a40b1183ad
commit
1fa1de72fd
3 changed files with 8 additions and 15 deletions
|
|
@ -481,9 +481,9 @@ GC::Ref<WebIDL::Promise> WindowOrWorkerGlobalScopeMixin::create_image_bitmap_imp
|
|||
// the animation.
|
||||
Optional<Gfx::DecodedImageFrame> 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
|
||||
|
|
|
|||
|
|
@ -47,22 +47,17 @@ Optional<CSSPixelSize> ImageProvider::intrinsic_size() const
|
|||
return CSSPixelSize { *width, *height };
|
||||
}
|
||||
|
||||
Optional<Gfx::DecodedImageFrame> ImageProvider::current_image_frame() const
|
||||
{
|
||||
return current_image_frame_sized(intrinsic_size().value_or({}).to_type<int>());
|
||||
}
|
||||
|
||||
Optional<Gfx::DecodedImageFrame> ImageProvider::current_image_frame_sized(Gfx::IntSize size) const
|
||||
Optional<Gfx::DecodedImageFrame> ImageProvider::current_image_frame(Optional<Gfx::IntSize> 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<int>()));
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<Gfx::DecodedImageFrame> ImageProvider::default_image_frame_sized(Gfx::IntSize size) const
|
||||
Optional<Gfx::DecodedImageFrame> ImageProvider::default_image_frame(Optional<Gfx::IntSize> 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<int>()));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,10 +30,8 @@ public:
|
|||
Optional<CSSPixelSize> intrinsic_size() const;
|
||||
Optional<CSSPixelFraction> intrinsic_aspect_ratio() const;
|
||||
|
||||
Optional<Gfx::DecodedImageFrame> current_image_frame() const;
|
||||
Optional<Gfx::DecodedImageFrame> current_image_frame_sized(Gfx::IntSize) const;
|
||||
|
||||
Optional<Gfx::DecodedImageFrame> default_image_frame_sized(Gfx::IntSize) const;
|
||||
Optional<Gfx::DecodedImageFrame> current_image_frame(Optional<Gfx::IntSize> size = {}) const;
|
||||
Optional<Gfx::DecodedImageFrame> default_image_frame(Optional<Gfx::IntSize> size = {}) const;
|
||||
|
||||
virtual void layout_node_was_detached() const { }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue