Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm

Issue 1412083002: Indicate in the Window menu which Chrome window has an active sound playing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modified based on the code reviews Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <limits> 10 #include <limits>
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 - (NSInteger)numberOfOpenPinnedTabs; 244 - (NSInteger)numberOfOpenPinnedTabs;
245 - (NSInteger)numberOfOpenNonPinnedTabs; 245 - (NSInteger)numberOfOpenNonPinnedTabs;
246 - (void)mouseMoved:(NSEvent*)event; 246 - (void)mouseMoved:(NSEvent*)event;
247 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; 247 - (void)setTabTrackingAreasEnabled:(BOOL)enabled;
248 - (void)droppingURLsAt:(NSPoint)point 248 - (void)droppingURLsAt:(NSPoint)point
249 givesIndex:(NSInteger*)index 249 givesIndex:(NSInteger*)index
250 disposition:(WindowOpenDisposition*)disposition; 250 disposition:(WindowOpenDisposition*)disposition;
251 - (void)setNewTabButtonHoverState:(BOOL)showHover; 251 - (void)setNewTabButtonHoverState:(BOOL)showHover;
252 - (void)themeDidChangeNotification:(NSNotification*)notification; 252 - (void)themeDidChangeNotification:(NSNotification*)notification;
253 - (void)setNewTabImages; 253 - (void)setNewTabImages;
254 - (void)updateWindowMediaState:(TabMediaState)mediaState
255 on:(content::WebContents*)changed;
256 - (BOOL)isAnyOtherTab:(content::WebContents*)selected
257 withState:(TabMediaState)state;
258
254 @end 259 @end
255 260
256 // A simple view class that contains the traffic light buttons. This class 261 // A simple view class that contains the traffic light buttons. This class
257 // ensures that the buttons display the icons when the mouse hovers over 262 // ensures that the buttons display the icons when the mouse hovers over
258 // them by overriding the _mouseInGroup method. 263 // them by overriding the _mouseInGroup method.
259 @interface CustomWindowControlsView : NSView { 264 @interface CustomWindowControlsView : NSView {
260 @private 265 @private
261 BOOL mouseInside_; 266 BOOL mouseInside_;
262 } 267 }
263 268
(...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 } else if (newState == kTabCrashed) { 1624 } else if (newState == kTabCrashed) {
1620 [tabController setIconImage:sadFaviconImage withToastAnimation:YES]; 1625 [tabController setIconImage:sadFaviconImage withToastAnimation:YES];
1621 } else { 1626 } else {
1622 [tabController setIconImage:throbberImage]; 1627 [tabController setIconImage:throbberImage];
1623 } 1628 }
1624 } else { 1629 } else {
1625 [tabController setIconImage:nil]; 1630 [tabController setIconImage:nil];
1626 } 1631 }
1627 } 1632 }
1628 1633
1629 [tabController setMediaState:chrome::GetTabMediaStateForContents(contents)]; 1634 TabMediaState mediaState = chrome::GetTabMediaStateForContents(contents);
1635
1636 [self updateWindowMediaState:mediaState on:contents];
1637 [tabController setMediaState:mediaState];
1630 1638
1631 [tabController updateVisibility]; 1639 [tabController updateVisibility];
1632 } 1640 }
1633 1641
1634 // Called when a notification is received from the model that the given tab 1642 // Called when a notification is received from the model that the given tab
1635 // has been updated. |loading| will be YES when we only want to update the 1643 // has been updated. |loading| will be YES when we only want to update the
1636 // throbber state, not anything else about the (partially) loading tab. 1644 // throbber state, not anything else about the (partially) loading tab.
1637 - (void)tabChangedWithContents:(content::WebContents*)contents 1645 - (void)tabChangedWithContents:(content::WebContents*)contents
1638 atIndex:(NSInteger)modelIndex 1646 atIndex:(NSInteger)modelIndex
1639 changeType:(TabStripModelObserver::TabChangeType)change { 1647 changeType:(TabStripModelObserver::TabChangeType)change {
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 [[newTabButton_ cell] setImage:Overlay(background, hover, alpha) 2335 [[newTabButton_ cell] setImage:Overlay(background, hover, alpha)
2328 forButtonState:image_button_cell::kHoverStateBackground]; 2336 forButtonState:image_button_cell::kHoverStateBackground];
2329 } else { 2337 } else {
2330 [[newTabButton_ cell] setImage:nil 2338 [[newTabButton_ cell] setImage:nil
2331 forButtonState:image_button_cell::kDefaultStateBackground]; 2339 forButtonState:image_button_cell::kDefaultStateBackground];
2332 [[newTabButton_ cell] setImage:nil 2340 [[newTabButton_ cell] setImage:nil
2333 forButtonState:image_button_cell::kHoverStateBackground]; 2341 forButtonState:image_button_cell::kHoverStateBackground];
2334 } 2342 }
2335 } 2343 }
2336 2344
2345 // Gets the tab and the media state to check whether the window
2346 // media state should be updated or not. If the tab media state is
2347 // AUDIO_PLAYING, the window media state should be set to AUDIO_PLAYING.
2348 // If the tab media state is AUDIO_MUTING, this method would check if the
2349 // window has no other tab with state AUDIO_PLAYING, then the window
2350 // media state will be set to AUDIO_MUTING. If the tab media state is NONE,
2351 // this method checks if the window has no playing or muting tab, then window
2352 // media state will be set as NONE.
2353 - (void)updateWindowMediaState:(TabMediaState)mediaState
2354 on:(content::WebContents*)selected {
2355 NSWindow* window = [tabStripView_ window];
2356 BrowserWindowController* windowController =
2357 [BrowserWindowController browserWindowControllerForWindow:window];
2358 if (mediaState == TAB_MEDIA_STATE_NONE) {
2359 if (![self isAnyOtherTab:selected
2360 withState:TAB_MEDIA_STATE_AUDIO_PLAYING] &&
Robert Sesek 2015/10/23 14:26:37 nit: align colons
2361 ![self isAnyOtherTab:selected withState:TAB_MEDIA_STATE_AUDIO_MUTING]) {
2362 [windowController setMediaState:TAB_MEDIA_STATE_NONE];
2363 } else if ([self isAnyOtherTab:selected
2364 withState:TAB_MEDIA_STATE_AUDIO_MUTING]) {
Robert Sesek 2015/10/23 14:26:37 nit: align colons
2365 [windowController setMediaState:TAB_MEDIA_STATE_AUDIO_MUTING];
2366 }
2367 }
2368 else if (mediaState == TAB_MEDIA_STATE_AUDIO_MUTING) {
2369 if (![self isAnyOtherTab:selected withState:TAB_MEDIA_STATE_AUDIO_PLAYING])
2370 [windowController setMediaState:TAB_MEDIA_STATE_AUDIO_MUTING];
2371 } else {
2372 [windowController setMediaState:mediaState];
2373 }
2374 }
2375
2376 // Checks if tabs (excluding selected) has media state equals to the second
2377 // parameter. It returns YES when it finds the first tab with the criterion.
2378 - (BOOL)isAnyOtherTab:(content::WebContents*)selected
2379 withState:(TabMediaState)state{
2380 const int existingTabCount = tabStripModel_->count();
2381 for (int i = 0; i < existingTabCount; ++i) {
2382 content::WebContents* currentContents =
2383 tabStripModel_->GetWebContentsAt(i);
Robert Sesek 2015/10/23 14:26:37 nit: over-indented. Only indent 4 spaces from the
2384 if (selected == currentContents)
2385 continue;
2386 TabMediaState currentMediaStateForContents =
2387 chrome::GetTabMediaStateForContents(currentContents);
Robert Sesek 2015/10/23 14:26:37 nit: same comment about over-indented
2388 if (currentMediaStateForContents == state)
2389 return YES;
2390 }
2391 return NO;
2392 }
2393
2337 @end 2394 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698