mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
Ladybird/AppKit: Display an audio button on tabs that are playing audio
When audio begins playing, add a button as an accessory view with a speaker icon to indicate which tab is playing audio. This button is currently disabled, but in the future may be used to mute the tab.
This commit is contained in:
parent
18821d3509
commit
8d765f1084
Notes:
sideshowbarker
2024-07-17 05:00:08 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/8d765f1084 Pull-request: https://github.com/SerenityOS/serenity/pull/23739
3 changed files with 27 additions and 0 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <LibURL/Forward.h>
|
||||
#include <LibWeb/CSS/PreferredColorScheme.h>
|
||||
#include <LibWeb/HTML/ActivateTab.h>
|
||||
#include <LibWeb/HTML/AudioPlayState.h>
|
||||
#include <LibWebView/Forward.h>
|
||||
|
||||
#import <System/Cocoa.h>
|
||||
|
@ -30,6 +31,7 @@
|
|||
|
||||
- (void)onTitleChange:(ByteString const&)title;
|
||||
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap;
|
||||
- (void)onAudioPlayStateChange:(Web::HTML::AudioPlayState)play_state;
|
||||
|
||||
- (void)onNavigateBack;
|
||||
- (void)onNavigateForward;
|
||||
|
|
|
@ -809,6 +809,10 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
|
|||
if (pasteboard_type)
|
||||
copy_data_to_clipboard(data, pasteboard_type);
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_audio_play_state_changed = [self](auto play_state) {
|
||||
[self.observer onAudioPlayStateChange:play_state];
|
||||
};
|
||||
}
|
||||
|
||||
- (void)selectDropdownAdd:(NSMenu*)menu item:(Web::HTML::SelectItem const&)item
|
||||
|
|
|
@ -275,6 +275,27 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
|
|||
[self updateTabTitleAndFavicon];
|
||||
}
|
||||
|
||||
- (void)onAudioPlayStateChange:(Web::HTML::AudioPlayState)play_state
|
||||
{
|
||||
switch (play_state) {
|
||||
case Web::HTML::AudioPlayState::Paused:
|
||||
[[self tab] setAccessoryView:nil];
|
||||
break;
|
||||
|
||||
case Web::HTML::AudioPlayState::Playing:
|
||||
auto* icon = [NSImage imageNamed:NSImageNameTouchBarAudioOutputVolumeHighTemplate];
|
||||
auto* button = [NSButton buttonWithImage:icon target:nil action:nil];
|
||||
|
||||
// FIXME: Add a click handler to mute the tab.
|
||||
NSButtonCell* cell = [button cell];
|
||||
[cell setImageDimsWhenDisabled:NO];
|
||||
[button setEnabled:NO];
|
||||
|
||||
[[self tab] setAccessoryView:button];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onNavigateBack
|
||||
{
|
||||
[[self tabController] navigateBack:nil];
|
||||
|
|
Loading…
Add table
Reference in a new issue