1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:58:12 +00:00

LibWeb: Implement HTMLVideoElement's video{Width,Height} attributes

This commit is contained in:
Timothy Flynn 2023-04-04 16:57:56 -04:00 committed by Linus Groh
parent becd70eccb
commit 725d7c3699
4 changed files with 37 additions and 1 deletions

View file

@ -603,7 +603,10 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::process_media_data(Function<void()>
// 5. For video elements, set the videoWidth and videoHeight attributes, and queue a media element task given the media element to fire an event
// named resize at the media element.
if (is<HTMLVideoElement>(*this)) {
// FIXME: Set the videoWidth and videoHeight attributes.
auto& video_element = verify_cast<HTMLVideoElement>(*this);
video_element.set_video_width(video_track->pixel_width());
video_element.set_video_height(video_track->pixel_height());
queue_a_media_element_task([this] {
dispatch_event(DOM::Event::create(this->realm(), HTML::EventNames::resize.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors());
});

View file

@ -24,4 +24,26 @@ JS::ThrowCompletionOr<void> HTMLVideoElement::initialize(JS::Realm& realm)
return {};
}
// 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;
}
}

View file

@ -16,10 +16,19 @@ class HTMLVideoElement final : public HTMLMediaElement {
public:
virtual ~HTMLVideoElement() override;
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;
private:
HTMLVideoElement(DOM::Document&, DOM::QualifiedName);
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
u32 m_video_width { 0 };
u32 m_video_height { 0 };
};
}

View file

@ -6,6 +6,8 @@ interface HTMLVideoElement : HTMLMediaElement {
[HTMLConstructor] constructor();
readonly attribute unsigned long videoWidth;
readonly attribute unsigned long videoHeight;
[CEReactions, Reflect] attribute USVString poster;
[CEReactions, Reflect=playsinline] attribute boolean playsInline;