2020-07-31 23:07:00 -03:00
|
|
|
/*
|
2021-04-28 17:46:44 -03:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2026-02-20 22:20:20 -03:00
|
|
|
* Copyright (c) 2026, Gregory Bertilson <gregory@ladybird.org>
|
2020-07-31 23:07:00 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-31 23:07:00 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-04-10 12:52:44 -03:00
|
|
|
#include <AK/Optional.h>
|
2023-04-04 19:32:09 -03:00
|
|
|
#include <LibGfx/Forward.h>
|
2023-04-20 08:00:26 -03:00
|
|
|
#include <LibWeb/DOM/DocumentLoadEventDelayer.h>
|
2023-04-04 19:32:09 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2020-07-31 23:07:00 -03:00
|
|
|
#include <LibWeb/HTML/HTMLMediaElement.h>
|
2023-04-20 08:00:26 -03:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2020-07-31 23:07:00 -03:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2023-04-20 07:40:31 -03:00
|
|
|
struct VideoFrame {
|
|
|
|
|
RefPtr<Gfx::Bitmap> frame;
|
|
|
|
|
double position { 0.0 };
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-31 23:07:00 -03:00
|
|
|
class HTMLVideoElement final : public HTMLMediaElement {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLVideoElement, HTMLMediaElement);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLVideoElement);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2020-07-31 23:07:00 -03:00
|
|
|
public:
|
2025-12-28 21:33:12 -03:00
|
|
|
static constexpr bool OVERRIDES_FINALIZE = true;
|
|
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
virtual ~HTMLVideoElement() override;
|
2020-07-31 23:07:00 -03:00
|
|
|
|
2023-04-04 19:32:09 -03:00
|
|
|
Layout::VideoBox* layout_node();
|
|
|
|
|
Layout::VideoBox const* layout_node() const;
|
|
|
|
|
|
2023-04-04 17:57:56 -03: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 08:00:26 -03:00
|
|
|
RefPtr<Gfx::Bitmap> const& poster_frame() const { return m_poster_frame; }
|
2023-04-04 19:32:09 -03:00
|
|
|
|
2026-02-20 22:27:21 -03: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-04 22:38:33 -03:00
|
|
|
// FIXME: This is a hack for images used as CanvasImageSource. Do something more elegant.
|
2026-01-20 23:10:33 -03:00
|
|
|
RefPtr<Gfx::ImmutableBitmap> bitmap() const;
|
2024-10-04 22:38:33 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
private:
|
2022-02-18 17:00:52 -03:00
|
|
|
HTMLVideoElement(DOM::Document&, DOM::QualifiedName);
|
2023-01-10 08:28:20 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2024-04-25 09:39:19 -03:00
|
|
|
virtual void finalize() override;
|
2023-04-04 19:32:09 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2024-11-14 10:14:16 -03: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 08:00:26 -03:00
|
|
|
|
2024-04-10 21:22:22 -03: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 12:35:12 -03:00
|
|
|
virtual GC::Ptr<Layout::Node> create_layout_node(GC::Ref<CSS::ComputedProperties>) override;
|
2023-04-04 19:32:09 -03:00
|
|
|
|
2023-11-19 02:10:36 -03:00
|
|
|
WebIDL::ExceptionOr<void> determine_element_poster_frame(Optional<String> const& poster);
|
2023-04-20 08:00:26 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<HTML::VideoTrack> m_video_track;
|
2023-04-20 07:40:31 -03:00
|
|
|
VideoFrame m_current_frame;
|
2023-04-20 08:00:26 -03:00
|
|
|
RefPtr<Gfx::Bitmap> m_poster_frame;
|
2023-04-04 17:57:56 -03:00
|
|
|
|
|
|
|
|
u32 m_video_width { 0 };
|
|
|
|
|
u32 m_video_height { 0 };
|
2023-04-10 12:52:44 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Fetch::Infrastructure::FetchController> m_fetch_controller;
|
2023-04-20 08:00:26 -03:00
|
|
|
Optional<DOM::DocumentLoadEventDelayer> m_load_event_delayer;
|
2020-07-31 23:07:00 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|