mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Ladybird: Add an audio context menu to the AppKit chrome
This commit is contained in:
parent
2cb816ad69
commit
e8f14f8cd0
1 changed files with 55 additions and 10 deletions
|
@ -55,6 +55,7 @@ struct HideCursor {
|
|||
@property (nonatomic, strong) NSMenu* page_context_menu;
|
||||
@property (nonatomic, strong) NSMenu* link_context_menu;
|
||||
@property (nonatomic, strong) NSMenu* image_context_menu;
|
||||
@property (nonatomic, strong) NSMenu* audio_context_menu;
|
||||
@property (nonatomic, strong) NSMenu* video_context_menu;
|
||||
@property (nonatomic, strong) NSTextField* status_label;
|
||||
@property (nonatomic, strong) NSAlert* dialog;
|
||||
|
@ -66,6 +67,7 @@ struct HideCursor {
|
|||
@synthesize page_context_menu = _page_context_menu;
|
||||
@synthesize link_context_menu = _link_context_menu;
|
||||
@synthesize image_context_menu = _image_context_menu;
|
||||
@synthesize audio_context_menu = _audio_context_menu;
|
||||
@synthesize video_context_menu = _video_context_menu;
|
||||
@synthesize status_label = _status_label;
|
||||
|
||||
|
@ -393,17 +395,13 @@ struct HideCursor {
|
|||
};
|
||||
|
||||
m_web_view_bridge->on_media_context_menu_request = [self](auto position, auto const& menu) {
|
||||
if (!menu.is_video) {
|
||||
NSLog(@"TODO: Implement audio context menu once audio elements are supported");
|
||||
return;
|
||||
}
|
||||
|
||||
TemporaryChange change_url { m_context_menu_url, menu.media_url };
|
||||
|
||||
auto* play_pause_menu_item = [self.video_context_menu itemWithTag:CONTEXT_MENU_PLAY_PAUSE_TAG];
|
||||
auto* mute_unmute_menu_item = [self.video_context_menu itemWithTag:CONTEXT_MENU_MUTE_UNMUTE_TAG];
|
||||
auto* controls_menu_item = [self.video_context_menu itemWithTag:CONTEXT_MENU_CONTROLS_TAG];
|
||||
auto* loop_menu_item = [self.video_context_menu itemWithTag:CONTEXT_MENU_LOOP_TAG];
|
||||
auto* context_menu = menu.is_video ? self.video_context_menu : self.audio_context_menu;
|
||||
auto* play_pause_menu_item = [context_menu itemWithTag:CONTEXT_MENU_PLAY_PAUSE_TAG];
|
||||
auto* mute_unmute_menu_item = [context_menu itemWithTag:CONTEXT_MENU_MUTE_UNMUTE_TAG];
|
||||
auto* controls_menu_item = [context_menu itemWithTag:CONTEXT_MENU_CONTROLS_TAG];
|
||||
auto* loop_menu_item = [context_menu itemWithTag:CONTEXT_MENU_LOOP_TAG];
|
||||
|
||||
if (menu.is_playing) {
|
||||
[play_pause_menu_item setTitle:@"Pause"];
|
||||
|
@ -424,7 +422,7 @@ struct HideCursor {
|
|||
[loop_menu_item setState:loop_state];
|
||||
|
||||
auto* event = Ladybird::create_context_menu_mouse_event(self, position);
|
||||
[NSMenu popUpContextMenu:self.video_context_menu withEvent:event forView:self];
|
||||
[NSMenu popUpContextMenu:context_menu withEvent:event forView:self];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_request_alert = [self](auto const& message) {
|
||||
|
@ -765,6 +763,53 @@ static void copy_text_to_clipboard(StringView text)
|
|||
return _image_context_menu;
|
||||
}
|
||||
|
||||
- (NSMenu*)audio_context_menu
|
||||
{
|
||||
if (!_audio_context_menu) {
|
||||
_audio_context_menu = [[NSMenu alloc] initWithTitle:@"Audio Context Menu"];
|
||||
|
||||
auto* play_pause_menu_item = [[NSMenuItem alloc] initWithTitle:@"Play"
|
||||
action:@selector(toggleMediaPlayState:)
|
||||
keyEquivalent:@""];
|
||||
[play_pause_menu_item setTag:CONTEXT_MENU_PLAY_PAUSE_TAG];
|
||||
|
||||
auto* mute_unmute_menu_item = [[NSMenuItem alloc] initWithTitle:@"Mute"
|
||||
action:@selector(toggleMediaMuteState:)
|
||||
keyEquivalent:@""];
|
||||
[mute_unmute_menu_item setTag:CONTEXT_MENU_MUTE_UNMUTE_TAG];
|
||||
|
||||
auto* controls_menu_item = [[NSMenuItem alloc] initWithTitle:@"Controls"
|
||||
action:@selector(toggleMediaControlsState:)
|
||||
keyEquivalent:@""];
|
||||
[controls_menu_item setTag:CONTEXT_MENU_CONTROLS_TAG];
|
||||
|
||||
auto* loop_menu_item = [[NSMenuItem alloc] initWithTitle:@"Loop"
|
||||
action:@selector(toggleMediaLoopState:)
|
||||
keyEquivalent:@""];
|
||||
[loop_menu_item setTag:CONTEXT_MENU_LOOP_TAG];
|
||||
|
||||
[_audio_context_menu addItem:play_pause_menu_item];
|
||||
[_audio_context_menu addItem:mute_unmute_menu_item];
|
||||
[_audio_context_menu addItem:controls_menu_item];
|
||||
[_audio_context_menu addItem:loop_menu_item];
|
||||
[_audio_context_menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
[_audio_context_menu addItem:[[NSMenuItem alloc] initWithTitle:@"Open Audio"
|
||||
action:@selector(openLink:)
|
||||
keyEquivalent:@""]];
|
||||
[_audio_context_menu addItem:[[NSMenuItem alloc] initWithTitle:@"Open Audio in New Tab"
|
||||
action:@selector(openLinkInNewTab:)
|
||||
keyEquivalent:@""]];
|
||||
[_audio_context_menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
[_audio_context_menu addItem:[[NSMenuItem alloc] initWithTitle:@"Copy Audio URL"
|
||||
action:@selector(copyLink:)
|
||||
keyEquivalent:@""]];
|
||||
}
|
||||
|
||||
return _audio_context_menu;
|
||||
}
|
||||
|
||||
- (NSMenu*)video_context_menu
|
||||
{
|
||||
if (!_video_context_menu) {
|
||||
|
|
Loading…
Add table
Reference in a new issue