mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-18 14:09:42 +00:00
Currently, ImageProvider::current_image_bitmap takes a Gfx::IntSize argument which determines the size of the returned bitmap. The default value of this argument is 0x0 which causes the function to return nullptr. This behavior is evidently unintuitive enough that it has lead to incorrect usage in multiple places. For example, the 2D canvas drawImage method will never actually draw anything because it calls current_image_bitmap with no arguments. And the naturalWidth and naturalHeight of an image will always return 0 (even after the image has loaded) for the same reason. To correct this and hopefully avoid similar issues in the future, ImageProvider::current_image_bitmap will be renamed to current_image_bitmap_sized, and the default value for the size argument will be removed. For consistency, a similar change will be made to SVGImageElement::default_image_bitmap. The existing current_image_bitmap function will no longer take a size argument. Instead it will always return a bitmap of the image's intrinsic size. This seems to be what most existing callers had already assumed was the function's behavior.
24 lines
569 B
C++
24 lines
569 B
C++
/*
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/Layout/ImageBox.h>
|
|
#include <LibWeb/Layout/ImageProvider.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
void ImageProvider::did_update_alt_text(ImageBox& layout_node)
|
|
{
|
|
layout_node.dom_node_did_update_alt_text({});
|
|
}
|
|
|
|
RefPtr<Gfx::ImmutableBitmap> ImageProvider::current_image_bitmap() const
|
|
{
|
|
int w = intrinsic_width().value_or({}).to_int();
|
|
int h = intrinsic_height().value_or({}).to_int();
|
|
return current_image_bitmap_sized({ w, h });
|
|
}
|
|
|
|
}
|