1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:17:34 +00:00

Ladybird+LibWeb+WebContent: Add context menu controls for muting audio

This commit is contained in:
Timothy Flynn 2023-06-16 11:29:54 -04:00 committed by Andreas Kling
parent b3bbdb1e2c
commit 9e95c9892c
16 changed files with 78 additions and 0 deletions

View file

@ -45,6 +45,8 @@ ErrorOr<IconBag> IconBag::try_create()
icon_bag.rename = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/rename.png"sv));
icon_bag.play = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/play.png"sv));
icon_bag.pause = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/pause.png"sv));
icon_bag.mute = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/audio-volume-muted.png"sv));
icon_bag.unmute = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/audio-volume-high.png"sv));
return icon_bag;
}

View file

@ -47,5 +47,7 @@ struct IconBag final {
RefPtr<Gfx::Bitmap> rename { nullptr };
RefPtr<Gfx::Bitmap> play { nullptr };
RefPtr<Gfx::Bitmap> pause { nullptr };
RefPtr<Gfx::Bitmap> mute { nullptr };
RefPtr<Gfx::Bitmap> unmute { nullptr };
};
}

View file

@ -377,6 +377,9 @@ Tab::Tab(BrowserWindow& window)
m_media_context_menu_play_pause_action = GUI::Action::create("&Play", g_icon_bag.play, [this](auto&) {
view().toggle_media_play_state();
});
m_media_context_menu_mute_unmute_action = GUI::Action::create("&Mute", g_icon_bag.mute, [this](auto&) {
view().toggle_media_mute_state();
});
m_media_context_menu_controls_action = GUI::Action::create_checkable("Show &Controls", [this](auto&) {
view().toggle_media_controls_state();
});
@ -386,6 +389,7 @@ Tab::Tab(BrowserWindow& window)
m_audio_context_menu = GUI::Menu::construct();
m_audio_context_menu->add_action(*m_media_context_menu_play_pause_action);
m_audio_context_menu->add_action(*m_media_context_menu_mute_unmute_action);
m_audio_context_menu->add_action(*m_media_context_menu_controls_action);
m_audio_context_menu->add_action(*m_media_context_menu_loop_action);
m_audio_context_menu->add_separator();
@ -401,6 +405,7 @@ Tab::Tab(BrowserWindow& window)
m_video_context_menu = GUI::Menu::construct();
m_video_context_menu->add_action(*m_media_context_menu_play_pause_action);
m_video_context_menu->add_action(*m_media_context_menu_mute_unmute_action);
m_video_context_menu->add_action(*m_media_context_menu_controls_action);
m_video_context_menu->add_action(*m_media_context_menu_loop_action);
m_video_context_menu->add_separator();
@ -432,6 +437,14 @@ Tab::Tab(BrowserWindow& window)
m_media_context_menu_play_pause_action->set_text("&Play"sv);
}
if (menu.is_muted) {
m_media_context_menu_mute_unmute_action->set_icon(g_icon_bag.unmute);
m_media_context_menu_mute_unmute_action->set_text("Un&mute"sv);
} else {
m_media_context_menu_mute_unmute_action->set_icon(g_icon_bag.mute);
m_media_context_menu_mute_unmute_action->set_text("&Mute"sv);
}
m_media_context_menu_controls_action->set_checked(menu.has_user_agent_controls);
m_media_context_menu_loop_action->set_checked(menu.is_looping);

View file

@ -146,6 +146,7 @@ private:
RefPtr<GUI::Menu> m_audio_context_menu;
RefPtr<GUI::Menu> m_video_context_menu;
RefPtr<GUI::Action> m_media_context_menu_play_pause_action;
RefPtr<GUI::Action> m_media_context_menu_mute_unmute_action;
RefPtr<GUI::Action> m_media_context_menu_controls_action;
RefPtr<GUI::Action> m_media_context_menu_loop_action;
URL m_media_context_menu_url;