mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
LibWeb: Add CanvasImageSource to ImageBitmapSource typedef
This commit is contained in:
parent
2c925244fd
commit
ad2bce7fa0
8 changed files with 36 additions and 15 deletions
|
@ -1,3 +1,5 @@
|
|||
#import <HTML/DOMStringMap.idl>
|
||||
|
||||
// https://html.spec.whatwg.org/#htmlorsvgelement
|
||||
interface mixin HTMLOrSVGElement {
|
||||
[SameObject] readonly attribute DOMStringMap dataset;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
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
|
||||
struct ImageBitmapOptions {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#import <FileAPI/Blob.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
|
||||
[Exposed=(Window,Worker), Serializable, Transferable]
|
||||
|
@ -9,8 +11,10 @@ interface ImageBitmap {
|
|||
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;
|
||||
|
||||
enum ImageOrientation { "from-image", "flipY" };
|
||||
|
|
|
@ -133,12 +133,25 @@ GC::Ref<WebIDL::Promise> WindowOrWorkerGlobalScopeMixin::create_image_bitmap_imp
|
|||
(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.
|
||||
// FIXME: "Check the usability of the image argument" is only defined for CanvasImageSource, let's skip it for other types
|
||||
if (image.has<CanvasImageSource>()) {
|
||||
if (auto usability = check_usability_of_image(image.get<CanvasImageSource>()); usability.is_error() or usability.value() == CanvasImageSourceUsability::Bad) {
|
||||
auto error_promise = image.visit(
|
||||
[](GC::Root<FileAPI::Blob>&) -> Optional<GC::Ref<WebIDL::Promise>> {
|
||||
return {};
|
||||
},
|
||||
[](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.
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#import <DOM/EventHandler.idl>
|
||||
#import <HTML/MessagePort.idl>
|
||||
#import <HTML/UniversalGlobalScope.idl>
|
||||
#import <HTML/Window.idl>
|
||||
#import <HTML/WindowOrWorkerGlobalScope.idl>
|
||||
#import <HTML/WorkerLocation.idl>
|
||||
#import <HTML/WorkerNavigator.idl>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#import <CSS/ElementCSSInlineStyle.idl>
|
||||
#import <DOM/Element.idl>
|
||||
#import <HTML/HTMLElement.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
#import <HTML/HTMLOrSVGElement.idl>
|
||||
#import <HTML/DOMStringMap.idl>
|
||||
#import <SVG/SVGAnimatedString.idl>
|
||||
#import <SVG/SVGSVGElement.idl>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Blob [Success]: [object ImageBitmap]
|
||||
ImageData [ Error ]: Error: Not Implemented: createImageBitmap() for non-blob types
|
||||
HTMLImageElement [ Error ]: TypeError: No union types matched
|
||||
SVGImageElement [ Error ]: TypeError: No union types matched
|
||||
HTMLCanvasElement [ Error ]: TypeError: No union types matched
|
||||
HTMLImageElement [ Error ]: InvalidStateError: image argument is not usable
|
||||
SVGImageElement [ Error ]: InvalidStateError: image argument is not usable
|
||||
HTMLCanvasElement [ Error ]: Error: Not Implemented: createImageBitmap() for non-blob types
|
||||
ImageBitmap [ Error ]: TypeError: No union types matched
|
||||
HTMLVideoElement [ Error ]: TypeError: No union types matched
|
||||
HTMLVideoElement [ Error ]: InvalidStateError: image argument is not usable
|
||||
|
|
|
@ -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,
|
||||
]),
|
||||
]);
|
||||
let imageBitmap = createImageBitmap(file, 0, 0, 0, 0);
|
||||
let imageBitmap = createImageBitmap(file, 0, 0, 20, 20);
|
||||
|
||||
const types = [
|
||||
[file, "Blob"],
|
||||
|
|
Loading…
Reference in a new issue