diff --git a/Tests/LibWeb/Text/expected/canvas/pattern-from-image.txt b/Tests/LibWeb/Text/expected/canvas/pattern-from-image.txt
new file mode 100644
index 00000000000..546f2cdabb4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/canvas/pattern-from-image.txt
@@ -0,0 +1,3 @@
+null
+null
+PASS (didn't throw!)
diff --git a/Tests/LibWeb/Text/input/canvas/pattern-from-image.html b/Tests/LibWeb/Text/input/canvas/pattern-from-image.html
new file mode 100644
index 00000000000..7b680d57539
--- /dev/null
+++ b/Tests/LibWeb/Text/input/canvas/pattern-from-image.html
@@ -0,0 +1,12 @@
+
+
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index eda2116cf03..cf565a45914 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -707,6 +707,7 @@ class SVGEllipseElement;
class SVGForeignObjectElement;
class SVGGeometryElement;
class SVGGraphicsElement;
+class SVGImageElement;
class SVGLength;
class SVGLineElement;
class SVGMaskElement;
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp
index 5cfe17501ee..3c93d18c52e 100644
--- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp
@@ -6,20 +6,32 @@
#include
#include
+#include
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 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 CanvasDrawImage::draw_image(Web::HTML::CanvasImageSource const& image, float destination_x, float destination_y)
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h
index b274c490762..cfe4aa0c315 100644
--- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h
@@ -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, JS::Handle>;
+using CanvasImageSource = Variant, JS::Handle, JS::Handle, JS::Handle>;
// https://html.spec.whatwg.org/multipage/canvas.html#canvasdrawimage
class CanvasDrawImage {
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.idl b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.idl
index aef9653c3ec..f3da18fef4f 100644
--- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.idl
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.idl
@@ -1,8 +1,10 @@
#import
#import
#import
+#import