Selaa lähdekoodia

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.
Timothy Flynn 2 vuotta sitten
vanhempi
commit
720d8889ad
1 muutettua tiedostoa jossa 18 lisäystä ja 0 poistoa
  1. 18 0
      Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp

+ 18 - 0
Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp

@@ -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;
     }