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..f025de874bd303a70d01737b18c563ecb87bf1be 100644 |
| --- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| @@ -251,6 +251,11 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { |
| - (void)setNewTabButtonHoverState:(BOOL)showHover; |
| - (void)themeDidChangeNotification:(NSNotification*)notification; |
| - (void)setNewTabImages; |
| +- (void)updateWindowMediaState:(TabMediaState)mediaState |
| + on:(content::WebContents*)changed; |
| +- (BOOL)isAnyOtherTab:(content::WebContents*)selected |
| + withState:(TabMediaState)state; |
| + |
| @end |
| // A simple view class that contains the traffic light buttons. This class |
| @@ -1626,7 +1631,10 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { |
| } |
| } |
| - [tabController setMediaState:chrome::GetTabMediaStateForContents(contents)]; |
| + TabMediaState mediaState = chrome::GetTabMediaStateForContents(contents); |
| + |
| + [self updateWindowMediaState:mediaState on:contents]; |
| + [tabController setMediaState:mediaState]; |
| [tabController updateVisibility]; |
| } |
| @@ -2334,4 +2342,53 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) { |
| } |
| } |
| +// 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] && |
|
Robert Sesek
2015/10/23 14:26:37
nit: align colons
|
| + ![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]) { |
|
Robert Sesek
2015/10/23 14:26:37
nit: align colons
|
| + [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); |
|
Robert Sesek
2015/10/23 14:26:37
nit: over-indented. Only indent 4 spaces from the
|
| + if (selected == currentContents) |
| + continue; |
| + TabMediaState currentMediaStateForContents = |
| + chrome::GetTabMediaStateForContents(currentContents); |
|
Robert Sesek
2015/10/23 14:26:37
nit: same comment about over-indented
|
| + if (currentMediaStateForContents == state) |
| + return YES; |
| + } |
| + return NO; |
| +} |
| + |
| @end |