Commit 823f3f04 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

cocoa: append sound state icon to items in Tab menu

If an item in the Tab menu either is or recently was playing sound,
append a sound state icon to it to make it stand out as such in the
tab menu. This will help users with a lot of tabs find the ones
making noise.

Bug: 1006624
Change-Id: Ia718f655d25a23731d705b5f6faa7fbb2bb91978
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827502Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700287}
parent d8fe844e
...@@ -9,8 +9,12 @@ ...@@ -9,8 +9,12 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/recently_audible_helper.h"
#include "chrome/browser/ui/tab_ui_helper.h" #include "chrome/browser/ui/tab_ui_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
using MenuItemCallback = base::RepeatingCallback<void(NSMenuItem*)>; using MenuItemCallback = base::RepeatingCallback<void(NSMenuItem*)>;
...@@ -20,7 +24,26 @@ void UpdateItemForWebContents(NSMenuItem* item, ...@@ -20,7 +24,26 @@ void UpdateItemForWebContents(NSMenuItem* item,
content::WebContents* web_contents) { content::WebContents* web_contents) {
TabUIHelper* tab_ui_helper = TabUIHelper::FromWebContents(web_contents); TabUIHelper* tab_ui_helper = TabUIHelper::FromWebContents(web_contents);
item.title = base::SysUTF16ToNSString(tab_ui_helper->GetTitle()); auto* audio_helper = RecentlyAudibleHelper::FromWebContents(web_contents);
if (audio_helper && audio_helper->WasRecentlyAudible()) {
// If this webcontents is or was recently playing audio, append either a
// speaker-playing-sound icon or a muted-speaker icon to its title to make
// it easy to find the tabs playing sound in the Tab menu.
int title_id;
base::string16 emoji;
if (web_contents->IsAudioMuted()) {
title_id = IDS_WINDOW_AUDIO_MUTING_MAC;
emoji = base::WideToUTF16(L"\U0001F507");
} else {
title_id = IDS_WINDOW_AUDIO_PLAYING_MAC;
emoji = base::WideToUTF16(L"\U0001F50A");
}
item.title =
l10n_util::GetNSStringF(title_id, tab_ui_helper->GetTitle(), emoji);
} else {
item.title = base::SysUTF16ToNSString(tab_ui_helper->GetTitle());
}
item.image = tab_ui_helper->GetFavicon().AsNSImage(); item.image = tab_ui_helper->GetFavicon().AsNSImage();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment