LibWeb: Allow changing media volume with keyboard controls

This allows increasing and decreasing the media volume by 10% with the
up and down arrow keys, respectively. This also allows toggling the mute
state with the M key.
This commit is contained in:
Timothy Flynn 2023-07-03 11:13:38 -04:00 committed by Andreas Kling
parent 6a5229c2cb
commit 720d8889ad
Notes: sideshowbarker 2024-07-17 01:04:03 +09:00

View file

@ -1885,6 +1885,24 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::handle_keydown(Badge<Web::EventHandl
break;
}
case KeyCode::Key_Up:
case KeyCode::Key_Down: {
static constexpr double volume_change_per_key_press = 0.1;
auto volume = this->volume();
if (key == KeyCode::Key_Up)
volume = min(1.0, volume + volume_change_per_key_press);
else
volume = max(0.0, volume - volume_change_per_key_press);
TRY(set_volume(volume));
break;
}
case KeyCode::Key_M:
set_muted(!muted());
break;
default:
break;
}