1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:17:36 +00:00

LibWeb: Allow toggling playback of media elements with keyboard controls

This allows pausing/playing media elements with the space bar.
This commit is contained in:
Timothy Flynn 2023-07-02 21:40:46 -07:00 committed by Andreas Kling
parent 2c5c815f44
commit a4070b1452
3 changed files with 22 additions and 0 deletions

View file

@ -1857,6 +1857,20 @@ void HTMLMediaElement::reject_pending_play_promises(ReadonlySpan<JS::NonnullGCPt
environment_settings.clean_up_after_running_script();
}
WebIDL::ExceptionOr<void> HTMLMediaElement::handle_keydown(Badge<Web::EventHandler>, KeyCode key)
{
switch (key) {
case KeyCode::Key_Space:
TRY(toggle_playback());
break;
default:
break;
}
return {};
}
void HTMLMediaElement::set_layout_display_time(Badge<Painting::MediaPaintable>, Optional<double> display_time)
{
if (display_time.has_value() && !m_display_time.has_value()) {

View file

@ -11,6 +11,7 @@
#include <AK/Optional.h>
#include <AK/Time.h>
#include <AK/Variant.h>
#include <Kernel/API/KeyCode.h>
#include <LibGfx/Rect.h>
#include <LibJS/Heap/MarkedVector.h>
#include <LibJS/SafeFunction.h>
@ -99,6 +100,8 @@ public:
JS::NonnullGCPtr<AudioTrackList> audio_tracks() const { return *m_audio_tracks; }
JS::NonnullGCPtr<VideoTrackList> video_tracks() const { return *m_video_tracks; }
WebIDL::ExceptionOr<void> handle_keydown(Badge<Web::EventHandler>, KeyCode);
enum class MouseTrackingComponent {
Timeline,
Volume,