2020-08-01 03:07:00 +01:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2023-04-07 11:10:57 -04:00
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.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
|
|
|
*/
|
|
|
|
|
2023-04-04 18:32:09 -04:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2022-09-30 17:16:16 -06:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2023-04-04 18:32:09 -04:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
#include <LibWeb/HTML/HTMLVideoElement.h>
|
2023-04-04 18:32:09 -04:00
|
|
|
#include <LibWeb/HTML/VideoTrack.h>
|
|
|
|
#include <LibWeb/Layout/VideoBox.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLVideoElement::HTMLVideoElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 11:20:15 +01:00
|
|
|
: HTMLMediaElement(document, move(qualified_name))
|
2020-08-01 03:07:00 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
HTMLVideoElement::~HTMLVideoElement() = default;
|
2020-08-01 03:07:00 +01:00
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
JS::ThrowCompletionOr<void> HTMLVideoElement::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2023-01-28 12:33:35 -05:00
|
|
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
2023-01-10 06:28:20 -05:00
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLVideoElementPrototype>(realm, "HTMLVideoElement"));
|
2023-01-28 12:33:35 -05:00
|
|
|
|
|
|
|
return {};
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2023-04-04 18:32:09 -04:00
|
|
|
void HTMLVideoElement::visit_edges(Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
visitor.visit(m_video_track);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::GCPtr<Layout::Node> HTMLVideoElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
|
|
|
|
{
|
|
|
|
return heap().allocate_without_realm<Layout::VideoBox>(document(), *this, move(style));
|
|
|
|
}
|
|
|
|
|
|
|
|
Layout::VideoBox* HTMLVideoElement::layout_node()
|
|
|
|
{
|
|
|
|
return static_cast<Layout::VideoBox*>(Node::layout_node());
|
|
|
|
}
|
|
|
|
|
|
|
|
Layout::VideoBox const* HTMLVideoElement::layout_node() const
|
|
|
|
{
|
|
|
|
return static_cast<Layout::VideoBox const*>(Node::layout_node());
|
|
|
|
}
|
|
|
|
|
2023-04-04 16:57:56 -04:00
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#dom-video-videowidth
|
|
|
|
u32 HTMLVideoElement::video_width() const
|
|
|
|
{
|
|
|
|
// The videoWidth IDL attribute must return the intrinsic width of the video in CSS pixels. The videoHeight IDL
|
|
|
|
// attribute must return the intrinsic height of the video in CSS pixels. If the element's readyState attribute
|
|
|
|
// is HAVE_NOTHING, then the attributes must return 0.
|
|
|
|
if (ready_state() == ReadyState::HaveNothing)
|
|
|
|
return 0;
|
|
|
|
return m_video_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#dom-video-videoheight
|
|
|
|
u32 HTMLVideoElement::video_height() const
|
|
|
|
{
|
|
|
|
// The videoWidth IDL attribute must return the intrinsic width of the video in CSS pixels. The videoHeight IDL
|
|
|
|
// attribute must return the intrinsic height of the video in CSS pixels. If the element's readyState attribute
|
|
|
|
// is HAVE_NOTHING, then the attributes must return 0.
|
|
|
|
if (ready_state() == ReadyState::HaveNothing)
|
|
|
|
return 0;
|
|
|
|
return m_video_height;
|
|
|
|
}
|
|
|
|
|
2023-04-04 18:32:09 -04:00
|
|
|
void HTMLVideoElement::set_video_track(JS::GCPtr<HTML::VideoTrack> video_track)
|
|
|
|
{
|
|
|
|
set_needs_style_update(true);
|
|
|
|
document().set_needs_layout();
|
|
|
|
|
2023-04-09 12:08:49 -04:00
|
|
|
if (m_video_track)
|
|
|
|
m_video_track->pause_video({});
|
2023-04-04 18:32:09 -04:00
|
|
|
|
|
|
|
m_video_track = video_track;
|
2023-04-07 11:10:57 -04:00
|
|
|
}
|
2023-04-04 18:32:09 -04:00
|
|
|
|
2023-04-09 12:08:49 -04:00
|
|
|
void HTMLVideoElement::set_current_frame(Badge<VideoTrack>, RefPtr<Gfx::Bitmap> frame)
|
|
|
|
{
|
|
|
|
m_current_frame = move(frame);
|
|
|
|
layout_node()->set_needs_display();
|
|
|
|
}
|
|
|
|
|
2023-04-07 11:10:57 -04:00
|
|
|
void HTMLVideoElement::on_playing()
|
|
|
|
{
|
2023-04-09 12:08:49 -04:00
|
|
|
if (m_video_track)
|
|
|
|
m_video_track->play_video({});
|
2023-04-04 18:32:09 -04:00
|
|
|
}
|
|
|
|
|
2023-04-07 11:10:57 -04:00
|
|
|
void HTMLVideoElement::on_paused()
|
|
|
|
{
|
2023-04-09 12:08:49 -04:00
|
|
|
if (m_video_track)
|
|
|
|
m_video_track->pause_video({});
|
2023-04-07 11:10:57 -04:00
|
|
|
}
|
|
|
|
|
2023-04-11 18:37:00 -04:00
|
|
|
void HTMLVideoElement::on_seek(double position, MediaSeekMode seek_mode)
|
|
|
|
{
|
|
|
|
if (m_video_track)
|
|
|
|
m_video_track->seek(Time::from_milliseconds(position * 1000.0), seek_mode);
|
|
|
|
}
|
|
|
|
|
2020-08-01 03:07:00 +01:00
|
|
|
}
|