LibWeb: Make SVGImageElement part of CanvasImageSource union

This is very janky at the moment but it also more correct. :^)
This commit is contained in:
Andreas Kling 2024-10-04 14:39:04 +02:00 committed by Andreas Kling
commit cd0e4a49b8
Notes: github-actions[bot] 2024-10-04 18:02:14 +00:00
10 changed files with 69 additions and 12 deletions

View file

@ -6,20 +6,32 @@
#include <LibWeb/HTML/Canvas/CanvasDrawImage.h>
#include <LibWeb/HTML/ImageBitmap.h>
#include <LibWeb/SVG/SVGImageElement.h>
namespace Web::HTML {
static void default_source_size(CanvasImageSource const& image, float& source_width, float& source_height)
{
image.visit([&source_width, &source_height](auto const& source) {
if (source->bitmap()) {
source_width = source->bitmap()->width();
source_height = source->bitmap()->height();
} else {
source_width = source->width();
source_height = source->height();
}
});
image.visit(
[&source_width, &source_height](JS::Handle<SVG::SVGImageElement> const& source) {
if (source->bitmap()) {
source_width = source->bitmap()->width();
source_height = source->bitmap()->height();
} else {
// FIXME: This is very janky and not correct.
source_width = source->width()->anim_val()->value();
source_height = source->height()->anim_val()->value();
}
},
[&source_width, &source_height](auto const& source) {
if (source->bitmap()) {
source_width = source->bitmap()->width();
source_height = source->bitmap()->height();
} else {
source_width = source->width();
source_height = source->height();
}
});
}
WebIDL::ExceptionOr<void> CanvasDrawImage::draw_image(Web::HTML::CanvasImageSource const& image, float destination_x, float destination_y)