mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Merge ad2bce7fa0
into 001df24935
This commit is contained in:
commit
5488861e87
10 changed files with 67 additions and 15 deletions
15
AK/Variant.h
15
AK/Variant.h
|
@ -499,9 +499,24 @@ private:
|
|||
template<typename... Ts>
|
||||
struct TypeList<Variant<Ts...>> : TypeList<Ts...> { };
|
||||
|
||||
namespace Detail {
|
||||
template<typename T1, typename T2>
|
||||
struct FlattenVariant;
|
||||
|
||||
template<typename... Ts1, typename... Ts2>
|
||||
struct FlattenVariant<::AK::Variant<Ts1...>, ::AK::Variant<Ts2...>> {
|
||||
using type = ::AK::Variant<Ts1..., Ts2...>;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
using FlattenVariant = Detail::FlattenVariant<T1, T2>::type;
|
||||
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
using AK::Empty;
|
||||
using AK::FlattenVariant;
|
||||
using AK::Variant;
|
||||
#endif
|
||||
|
|
|
@ -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 = WebIDL::InvalidStateError::create(this_impl().realm(), "image argument is not usable"_string);
|
||||
return WebIDL::create_rejected_promise_from_exception(realm, error);
|
||||
}
|
||||
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>
|
||||
|
|
|
@ -302,3 +302,19 @@ TEST_CASE(variant_equality)
|
|||
EXPECT_EQ(variant1, variant2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(flatten_variant)
|
||||
{
|
||||
using InnerVariant = Variant<Empty, int>;
|
||||
using OuterVariant = FlattenVariant<InnerVariant, Variant<float>>;
|
||||
using MyVariant = Variant<Empty, int, float>;
|
||||
|
||||
EXPECT_EQ((TypeList<MyVariant>::size), 3u);
|
||||
EXPECT_EQ((TypeList<OuterVariant>::size), 3u);
|
||||
EXPECT((IsSame<OuterVariant, MyVariant>));
|
||||
|
||||
using OuterList = TypeList<OuterVariant>;
|
||||
EXPECT((IsSame<typename OuterList::template Type<0>, Empty>));
|
||||
EXPECT((IsSame<typename OuterList::template Type<1>, int>));
|
||||
EXPECT((IsSame<typename OuterList::template Type<2>, float>));
|
||||
}
|
||||
|
|
|
@ -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