2020-08-01 03:07:00 +01:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2026-02-20 19:20:20 -06:00
|
|
|
* Copyright (c) 2026, Gregory Bertilson <gregory@ladybird.org>
|
2020-08-01 03:07:00 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 03:07:00 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-04-10 11:52:44 -04:00
|
|
|
#include <AK/Optional.h>
|
2023-04-04 18:32:09 -04:00
|
|
|
#include <LibGfx/Forward.h>
|
2023-04-20 07:00:26 -04:00
|
|
|
#include <LibWeb/DOM/DocumentLoadEventDelayer.h>
|
2023-04-04 18:32:09 -04:00
|
|
|
#include <LibWeb/Forward.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
#include <LibWeb/HTML/HTMLMediaElement.h>
|
2023-04-20 07:00:26 -04:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2023-04-20 06:40:31 -04:00
|
|
|
struct VideoFrame {
|
|
|
|
|
RefPtr<Gfx::Bitmap> frame;
|
|
|
|
|
double position { 0.0 };
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-01 03:07:00 +01:00
|
|
|
class HTMLVideoElement final : public HTMLMediaElement {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLVideoElement, HTMLMediaElement);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLVideoElement);
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2020-08-01 03:07:00 +01:00
|
|
|
public:
|
2025-12-29 01:33:12 +01:00
|
|
|
static constexpr bool OVERRIDES_FINALIZE = true;
|
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
virtual ~HTMLVideoElement() override;
|
2020-08-01 03:07:00 +01:00
|
|
|
|
2023-04-04 18:32:09 -04:00
|
|
|
Layout::VideoBox* layout_node();
|
|
|
|
|
Layout::VideoBox const* layout_node() const;
|
|
|
|
|
|
2023-04-04 16:57:56 -04:00
|
|
|
void set_video_width(u32 video_width) { m_video_width = video_width; }
|
|
|
|
|
u32 video_width() const;
|
|
|
|
|
|
|
|
|
|
void set_video_height(u32 video_height) { m_video_height = video_height; }
|
|
|
|
|
u32 video_height() const;
|
|
|
|
|
|
2023-04-20 07:00:26 -04:00
|
|
|
RefPtr<Gfx::Bitmap> const& poster_frame() const { return m_poster_frame; }
|
2023-04-04 18:32:09 -04:00
|
|
|
|
2026-02-20 19:27:21 -06:00
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#the-video-element:the-video-element-7
|
|
|
|
|
// NB: We combine the values of...
|
|
|
|
|
// - The last frame of the video to have been rendered
|
|
|
|
|
// - The frame of video corresponding to the current playback position
|
|
|
|
|
// ...into the value of VideoFrame below, as the playback system itself implements
|
|
|
|
|
// the details of the selection of a video frame to match the specification in this
|
|
|
|
|
// respect.
|
|
|
|
|
enum class Representation : u8 {
|
|
|
|
|
VideoFrame,
|
|
|
|
|
FirstVideoFrame,
|
|
|
|
|
PosterFrame,
|
|
|
|
|
TransparentBlack,
|
|
|
|
|
};
|
|
|
|
|
Representation current_representation() const;
|
|
|
|
|
|
2024-10-05 03:38:33 +02:00
|
|
|
// FIXME: This is a hack for images used as CanvasImageSource. Do something more elegant.
|
2026-01-20 20:10:33 -06:00
|
|
|
RefPtr<Gfx::ImmutableBitmap> bitmap() const;
|
2024-10-05 03:38:33 +02:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
private:
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLVideoElement(DOM::Document&, DOM::QualifiedName);
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2024-04-25 08:39:19 -04:00
|
|
|
virtual void finalize() override;
|
2023-04-04 18:32:09 -04:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2024-11-14 08:14:16 -05:00
|
|
|
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
2023-04-20 07:00:26 -04:00
|
|
|
|
2024-04-10 20:22:22 -04:00
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#the-video-element:dimension-attributes
|
|
|
|
|
virtual bool supports_dimension_attributes() const override { return true; }
|
|
|
|
|
|
2024-12-20 16:35:12 +01:00
|
|
|
virtual GC::Ptr<Layout::Node> create_layout_node(GC::Ref<CSS::ComputedProperties>) override;
|
2023-04-04 18:32:09 -04:00
|
|
|
|
2023-11-19 18:10:36 +13:00
|
|
|
WebIDL::ExceptionOr<void> determine_element_poster_frame(Optional<String> const& poster);
|
2023-04-20 07:00:26 -04:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<HTML::VideoTrack> m_video_track;
|
2023-04-20 06:40:31 -04:00
|
|
|
VideoFrame m_current_frame;
|
2023-04-20 07:00:26 -04:00
|
|
|
RefPtr<Gfx::Bitmap> m_poster_frame;
|
2023-04-04 16:57:56 -04:00
|
|
|
|
|
|
|
|
u32 m_video_width { 0 };
|
|
|
|
|
u32 m_video_height { 0 };
|
2023-04-10 11:52:44 -04:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Fetch::Infrastructure::FetchController> m_fetch_controller;
|
2023-04-20 07:00:26 -04:00
|
|
|
Optional<DOM::DocumentLoadEventDelayer> m_load_event_delayer;
|
2020-08-01 03:07:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|