mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-08 02:26:10 +00:00
LibWeb: Make SVGImageElement part of CanvasImageSource union
This is very janky at the moment but it also more correct. :^)
This commit is contained in:
parent
902586a21d
commit
cd0e4a49b8
Notes:
github-actions[bot]
2024-10-04 18:02:14 +00:00
Author: https://github.com/awesomekling
Commit: cd0e4a49b8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1629
10 changed files with 69 additions and 12 deletions
|
@ -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)
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Web::HTML {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#canvasimagesource
|
||||
// NOTE: This is the Variant created by the IDL wrapper generator, and needs to be updated accordingly.
|
||||
using CanvasImageSource = Variant<JS::Handle<HTMLImageElement>, JS::Handle<HTMLCanvasElement>, JS::Handle<ImageBitmap>>;
|
||||
using CanvasImageSource = Variant<JS::Handle<HTMLImageElement>, JS::Handle<SVG::SVGImageElement>, JS::Handle<HTMLCanvasElement>, JS::Handle<ImageBitmap>>;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#canvasdrawimage
|
||||
class CanvasDrawImage {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#import <HTML/HTMLCanvasElement.idl>
|
||||
#import <HTML/HTMLImageElement.idl>
|
||||
#import <HTML/ImageBitmap.idl>
|
||||
#import <SVG/SVGImageElement.idl>
|
||||
|
||||
typedef (HTMLImageElement or
|
||||
SVGImageElement or
|
||||
// FIXME: We should use HTMLOrSVGImageElement instead of HTMLImageElement
|
||||
// FIXME: HTMLVideoElement or
|
||||
HTMLCanvasElement or
|
||||
|
|
|
@ -10,6 +10,5 @@ interface mixin CanvasFillStrokeStyles {
|
|||
CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1);
|
||||
CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1);
|
||||
CanvasGradient createConicGradient(double startAngle, double x, double y);
|
||||
// FIXME: 'image' should be a CanvasImageSource
|
||||
CanvasPattern? createPattern((HTMLImageElement or HTMLCanvasElement) image, [LegacyNullToEmptyString] DOMString repetition);
|
||||
CanvasPattern? createPattern(CanvasImageSource image, [LegacyNullToEmptyString] DOMString repetition);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue