LibWeb: Add CanvasImageSource to ImageBitmapSource typedef

This commit is contained in:
Totto16 2024-11-14 16:25:38 +01:00
parent 2c925244fd
commit ad2bce7fa0
No known key found for this signature in database
GPG key ID: 155BC43A4236B885
8 changed files with 36 additions and 15 deletions

View file

@ -1,3 +1,5 @@
#import <HTML/DOMStringMap.idl>
// https://html.spec.whatwg.org/#htmlorsvgelement // https://html.spec.whatwg.org/#htmlorsvgelement
interface mixin HTMLOrSVGElement { interface mixin HTMLOrSVGElement {
[SameObject] readonly attribute DOMStringMap dataset; [SameObject] readonly attribute DOMStringMap dataset;

View file

@ -16,7 +16,7 @@
namespace Web::HTML { namespace Web::HTML {
using ImageBitmapSource = Variant<CanvasImageSource, GC::Root<FileAPI::Blob>, GC::Root<ImageData>>; using ImageBitmapSource = FlattenVariant<CanvasImageSource, Variant<GC::Root<FileAPI::Blob>, GC::Root<ImageData>>>;
// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagebitmapoptions // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagebitmapoptions
struct ImageBitmapOptions { struct ImageBitmapOptions {

View file

@ -1,5 +1,7 @@
#import <FileAPI/Blob.idl> #import <FileAPI/Blob.idl>
#import <HTML/ImageData.idl> #import <HTML/ImageData.idl>
#import <HTML/CanvasRenderingContext2D.idl>
#import <HTML/Canvas/CanvasDrawImage.idl>
// https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#images-2 // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#images-2
[Exposed=(Window,Worker), Serializable, Transferable] [Exposed=(Window,Worker), Serializable, Transferable]
@ -9,8 +11,10 @@ interface ImageBitmap {
undefined close(); undefined close();
}; };
// FIXME: This should also includes CanvasImageSource
typedef (Blob or // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagebitmapsource
typedef (CanvasImageSource or
Blob or
ImageData) ImageBitmapSource; ImageData) ImageBitmapSource;
enum ImageOrientation { "from-image", "flipY" }; enum ImageOrientation { "from-image", "flipY" };

View file

@ -133,12 +133,25 @@ GC::Ref<WebIDL::Promise> WindowOrWorkerGlobalScopeMixin::create_image_bitmap_imp
(void)options; (void)options;
// 3. Check the usability of the image argument. If this throws an exception or returns bad, then return a promise rejected with an "InvalidStateError" DOMException. // 3. Check the usability of the image argument. If this throws an exception or returns bad, then return a promise rejected with an "InvalidStateError" DOMException.
// FIXME: "Check the usability of the image argument" is only defined for CanvasImageSource, let's skip it for other types auto error_promise = image.visit(
if (image.has<CanvasImageSource>()) { [](GC::Root<FileAPI::Blob>&) -> Optional<GC::Ref<WebIDL::Promise>> {
if (auto usability = check_usability_of_image(image.get<CanvasImageSource>()); usability.is_error() or usability.value() == CanvasImageSourceUsability::Bad) { return {};
auto error = WebIDL::InvalidStateError::create(this_impl().realm(), "image argument is not usable"_string); },
return WebIDL::create_rejected_promise_from_exception(realm, error); [](GC::Root<ImageData>&) -> Optional<GC::Ref<WebIDL::Promise>> {
} return {};
},
[&](auto& canvas_image_source) -> Optional<GC::Ref<WebIDL::Promise>> {
// Note: "Check the usability of the image argument" is only defined for CanvasImageSource
if (auto usability = check_usability_of_image(canvas_image_source); usability.is_error() or usability.value() == CanvasImageSourceUsability::Bad) {
auto error = WebIDL::InvalidStateError::create(this_impl().realm(), "image argument is not usable"_string);
return WebIDL::create_rejected_promise_from_exception(realm, error);
}
return {};
});
if (error_promise.has_value()) {
return error_promise.release_value();
} }
// 4. Let p be a new promise. // 4. Let p be a new promise.

View file

@ -3,6 +3,7 @@
#import <DOM/EventHandler.idl> #import <DOM/EventHandler.idl>
#import <HTML/MessagePort.idl> #import <HTML/MessagePort.idl>
#import <HTML/UniversalGlobalScope.idl> #import <HTML/UniversalGlobalScope.idl>
#import <HTML/Window.idl>
#import <HTML/WindowOrWorkerGlobalScope.idl> #import <HTML/WindowOrWorkerGlobalScope.idl>
#import <HTML/WorkerLocation.idl> #import <HTML/WorkerLocation.idl>
#import <HTML/WorkerNavigator.idl> #import <HTML/WorkerNavigator.idl>

View file

@ -1,6 +1,7 @@
#import <CSS/ElementCSSInlineStyle.idl> #import <CSS/ElementCSSInlineStyle.idl>
#import <DOM/Element.idl> #import <DOM/Element.idl>
#import <HTML/HTMLElement.idl> #import <DOM/EventHandler.idl>
#import <HTML/HTMLOrSVGElement.idl>
#import <HTML/DOMStringMap.idl> #import <HTML/DOMStringMap.idl>
#import <SVG/SVGAnimatedString.idl> #import <SVG/SVGAnimatedString.idl>
#import <SVG/SVGSVGElement.idl> #import <SVG/SVGSVGElement.idl>

View file

@ -1,7 +1,7 @@
Blob [Success]: [object ImageBitmap] Blob [Success]: [object ImageBitmap]
ImageData [ Error ]: Error: Not Implemented: createImageBitmap() for non-blob types ImageData [ Error ]: Error: Not Implemented: createImageBitmap() for non-blob types
HTMLImageElement [ Error ]: TypeError: No union types matched HTMLImageElement [ Error ]: InvalidStateError: image argument is not usable
SVGImageElement [ Error ]: TypeError: No union types matched SVGImageElement [ Error ]: InvalidStateError: image argument is not usable
HTMLCanvasElement [ Error ]: TypeError: No union types matched HTMLCanvasElement [ Error ]: Error: Not Implemented: createImageBitmap() for non-blob types
ImageBitmap [ Error ]: TypeError: No union types matched ImageBitmap [ Error ]: TypeError: No union types matched
HTMLVideoElement [ Error ]: TypeError: No union types matched HTMLVideoElement [ Error ]: InvalidStateError: image argument is not usable

View file

@ -22,7 +22,7 @@
255, 10, 8, 16, 0, 9, 8, 6, 1, 0, 40, 0, 75, 56, 73, 152, 108, 128, 253, 145, 96, 0, 255, 10, 8, 16, 0, 9, 8, 6, 1, 0, 40, 0, 75, 56, 73, 152, 108, 128, 253, 145, 96, 0,
]), ]),
]); ]);
let imageBitmap = createImageBitmap(file, 0, 0, 0, 0); let imageBitmap = createImageBitmap(file, 0, 0, 20, 20);
const types = [ const types = [
[file, "Blob"], [file, "Blob"],