mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Make CanvasImageSource also be an ImageBitmap
This commit is contained in:
parent
af3a73c0a4
commit
94128fe027
Notes:
sideshowbarker
2024-07-17 02:39:10 +09:00
Author: https://github.com/LucasChollet
Commit: 94128fe027
Pull-request: https://github.com/SerenityOS/serenity/pull/23850
Reviewed-by: https://github.com/shannonbooth ✅
8 changed files with 24 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/HTML/Canvas/CanvasDrawImage.h>
|
||||
#include <LibWeb/HTML/ImageBitmap.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/HTMLCanvasElement.h>
|
||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
@ -14,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>>;
|
||||
using CanvasImageSource = Variant<JS::Handle<HTMLImageElement>, JS::Handle<HTMLCanvasElement>, JS::Handle<ImageBitmap>>;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#canvasdrawimage
|
||||
class CanvasDrawImage {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#import <HTML/HTMLCanvasElement.idl>
|
||||
#import <HTML/HTMLImageElement.idl>
|
||||
#import <HTML/ImageBitmap.idl>
|
||||
|
||||
typedef (HTMLImageElement or
|
||||
// FIXME: We should use HTMLOrSVGImageElement instead of HTMLImageElement
|
||||
// FIXME: HTMLVideoElement or
|
||||
HTMLCanvasElement
|
||||
// FIXME: ImageBitmap
|
||||
HTMLCanvasElement or
|
||||
ImageBitmap
|
||||
// FIXME: OffscreenCanvas
|
||||
// FIXME: VideoFrame
|
||||
) CanvasImageSource;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/HTML/CanvasPattern.h>
|
||||
#include <LibWeb/HTML/CanvasRenderingContext2D.h>
|
||||
#include <LibWeb/HTML/ImageBitmap.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibWeb/HTML/CanvasRenderingContext2D.h>
|
||||
#include <LibWeb/HTML/HTMLCanvasElement.h>
|
||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||
#include <LibWeb/HTML/ImageBitmap.h>
|
||||
#include <LibWeb/HTML/ImageData.h>
|
||||
#include <LibWeb/HTML/Path2D.h>
|
||||
#include <LibWeb/HTML/TextMetrics.h>
|
||||
|
@ -636,6 +637,14 @@ WebIDL::ExceptionOr<CanvasImageSourceUsability> check_usability_of_image(CanvasI
|
|||
if (canvas_element->width() == 0 || canvas_element->height() == 0)
|
||||
return WebIDL::InvalidStateError::create(canvas_element->realm(), "Canvas width or height is zero"_fly_string);
|
||||
return Optional<CanvasImageSourceUsability> {};
|
||||
},
|
||||
|
||||
// ImageBitmap
|
||||
// FIXME: VideoFrame
|
||||
[](JS::Handle<ImageBitmap> const& image_bitmap) -> WebIDL::ExceptionOr<Optional<CanvasImageSourceUsability>> {
|
||||
if (image_bitmap->is_detached())
|
||||
return WebIDL::InvalidStateError::create(image_bitmap->realm(), "Image bitmap is detached"_fly_string);
|
||||
return Optional<CanvasImageSourceUsability> {};
|
||||
}));
|
||||
if (usability.has_value())
|
||||
return usability.release_value();
|
||||
|
@ -659,8 +668,7 @@ bool image_is_not_origin_clean(CanvasImageSource const& image)
|
|||
// image's media data is CORS-cross-origin.
|
||||
|
||||
// HTMLCanvasElement
|
||||
// FIXME: ImageBitmap
|
||||
[](JS::Handle<HTMLCanvasElement> const&) {
|
||||
[](OneOf<JS::Handle<HTMLCanvasElement>, JS::Handle<ImageBitmap>> auto const&) {
|
||||
// FIXME: image's bitmap's origin-clean flag is false.
|
||||
return false;
|
||||
});
|
||||
|
|
|
@ -104,4 +104,9 @@ void ImageBitmap::set_bitmap(RefPtr<Gfx::Bitmap> bitmap)
|
|||
m_height = m_bitmap->height();
|
||||
}
|
||||
|
||||
Gfx::Bitmap* ImageBitmap::bitmap() const
|
||||
{
|
||||
return m_bitmap.ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
|
||||
// Implementation specific:
|
||||
void set_bitmap(RefPtr<Gfx::Bitmap>);
|
||||
Gfx::Bitmap* bitmap() const;
|
||||
|
||||
private:
|
||||
explicit ImageBitmap(JS::Realm&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue