From 6a5229c2cbb63e8cd76c4d0089d15c863d19e7dc Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 2 Jul 2023 22:21:08 -0700 Subject: [PATCH] LibWeb: Allow seeking media elements with keyboard controls This allows seeking backwards and forwards by 5 seconds with the left and right arrow keys, respectively. This also allows seeking to the beginning and end of the media track with the home and end keys. --- .../LibWeb/HTML/HTMLMediaElement.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index b5410a40f68..d1a7432ea25 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -1864,6 +1864,27 @@ WebIDL::ExceptionOr HTMLMediaElement::handle_keydown(Badgecurrent_time(); + + if (key == KeyCode::Key_Left) + current_time = max(0.0, current_time - time_skipped_per_key_press); + else + current_time = min(duration(), current_time + time_skipped_per_key_press); + + set_current_time(current_time); + break; + } + default: break; }