Chromium Code Reviews| Index: chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| index 9fe0804d70d90ee72dc004027bf3f31a1ff86b0e..0da49892074bff643c994087a3160a9cef730443 100644 |
| --- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| @@ -45,7 +45,6 @@ |
| #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
| -#include "chrome/browser/ui/tabs/tab_utils.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "components/metrics/proto/omnibox_event.pb.h" |
| @@ -251,6 +250,9 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { |
| - (void)setNewTabButtonHoverState:(BOOL)showHover; |
| - (void)themeDidChangeNotification:(NSNotification*)notification; |
| - (void)setNewTabImages; |
| +- (BOOL)isAnyOtherTab:(content::WebContents*)selected |
|
Robert Sesek
2015/11/09 23:41:25
Similarly, "doesAnyOtherWebContents:haveMediaState
|
| + withState:(TabMediaState)state; |
| + |
| @end |
| // A simple view class that contains the traffic light buttons. This class |
| @@ -1274,7 +1276,7 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { |
| [tab setTitle:base::SysUTF16ToNSString(title)]; |
| const base::string16& toolTip = chrome::AssembleTabTooltipText( |
| - title, chrome::GetTabMediaStateForContents(contents)); |
| + title, [self mediaStateForContents:contents]); |
| [tab setToolTip:base::SysUTF16ToNSString(toolTip)]; |
| } |
| @@ -1626,7 +1628,10 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { |
| } |
| } |
| - [tabController setMediaState:chrome::GetTabMediaStateForContents(contents)]; |
| + TabMediaState mediaState = [self mediaStateForContents:contents]; |
| + |
|
Robert Sesek
2015/11/09 23:41:25
nit: remove blank line
|
| + [self updateWindowMediaState:mediaState on:contents]; |
| + [tabController setMediaState:mediaState]; |
| [tabController updateVisibility]; |
| } |
| @@ -2291,6 +2296,57 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { |
| [customWindowControls_ setMouseInside:NO]; |
| } |
| +// Gets the tab and the media state to check whether the window |
| +// media state should be updated or not. If the tab media state is |
| +// AUDIO_PLAYING, the window media state should be set to AUDIO_PLAYING. |
| +// If the tab media state is AUDIO_MUTING, this method would check if the |
| +// window has no other tab with state AUDIO_PLAYING, then the window |
| +// media state will be set to AUDIO_MUTING. If the tab media state is NONE, |
| +// this method checks if the window has no playing or muting tab, then window |
| +// media state will be set as NONE. |
| +- (void)updateWindowMediaState:(TabMediaState)mediaState |
| + on:(content::WebContents*)selected { |
| + NSWindow* window = [tabStripView_ window]; |
| + BrowserWindowController* windowController = |
| + [BrowserWindowController browserWindowControllerForWindow:window]; |
| + if (mediaState == TAB_MEDIA_STATE_NONE) { |
| + if (![self isAnyOtherTab:selected |
| + withState:TAB_MEDIA_STATE_AUDIO_PLAYING] && |
| + ![self isAnyOtherTab:selected withState:TAB_MEDIA_STATE_AUDIO_MUTING]) { |
| + [windowController setMediaState:TAB_MEDIA_STATE_NONE]; |
| + } else if ([self isAnyOtherTab:selected |
| + withState:TAB_MEDIA_STATE_AUDIO_MUTING]) { |
| + [windowController setMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]; |
| + } |
| + } else if (mediaState == TAB_MEDIA_STATE_AUDIO_MUTING) { |
| + if (![self isAnyOtherTab:selected withState:TAB_MEDIA_STATE_AUDIO_PLAYING]) |
| + [windowController setMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]; |
| + } else { |
| + [windowController setMediaState:mediaState]; |
| + } |
| +} |
| + |
| +// Checks if tabs (excluding selected) has media state equals to the second |
| +// parameter. It returns YES when it finds the first tab with the criterion. |
| +- (BOOL)isAnyOtherTab:(content::WebContents*)selected |
| + withState:(TabMediaState)state { |
| + const int existingTabCount = tabStripModel_->count(); |
| + for (int i = 0; i < existingTabCount; ++i) { |
| + content::WebContents* currentContents = tabStripModel_->GetWebContentsAt(i); |
| + if (selected == currentContents) |
| + continue; |
| + TabMediaState currentMediaStateForContents = |
| + [self mediaStateForContents:currentContents]; |
| + if (currentMediaStateForContents == state) |
| + return YES; |
| + } |
| + return NO; |
| +} |
| + |
| +- (TabMediaState)mediaStateForContents:(content::WebContents*)contents { |
| + return chrome::GetTabMediaStateForContents(contents); |
| +} |
| + |
| - (void)themeDidChangeNotification:(NSNotification*)notification { |
| [self setNewTabImages]; |
| } |