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

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: Removed emojis from generated_resources.grd Created 5 years, 1 month 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 27 matching lines...) Expand all
38 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" 38 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h"
39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" 39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
41 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 41 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
42 #include "chrome/browser/ui/find_bar/find_bar.h" 42 #include "chrome/browser/ui/find_bar/find_bar.h"
43 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 43 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
44 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 44 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
45 #include "chrome/browser/ui/tabs/tab_menu_model.h" 45 #include "chrome/browser/ui/tabs/tab_menu_model.h"
46 #include "chrome/browser/ui/tabs/tab_strip_model.h" 46 #include "chrome/browser/ui/tabs/tab_strip_model.h"
47 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 47 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
48 #include "chrome/browser/ui/tabs/tab_utils.h"
49 #include "chrome/common/chrome_switches.h" 48 #include "chrome/common/chrome_switches.h"
50 #include "chrome/grit/generated_resources.h" 49 #include "chrome/grit/generated_resources.h"
51 #include "components/metrics/proto/omnibox_event.pb.h" 50 #include "components/metrics/proto/omnibox_event.pb.h"
52 #include "components/omnibox/browser/autocomplete_classifier.h" 51 #include "components/omnibox/browser/autocomplete_classifier.h"
53 #include "components/omnibox/browser/autocomplete_match.h" 52 #include "components/omnibox/browser/autocomplete_match.h"
54 #include "components/url_formatter/url_fixer.h" 53 #include "components/url_formatter/url_fixer.h"
55 #include "components/web_modal/web_contents_modal_dialog_manager.h" 54 #include "components/web_modal/web_contents_modal_dialog_manager.h"
56 #include "content/public/browser/navigation_controller.h" 55 #include "content/public/browser/navigation_controller.h"
57 #include "content/public/browser/user_metrics.h" 56 #include "content/public/browser/user_metrics.h"
58 #include "content/public/browser/web_contents.h" 57 #include "content/public/browser/web_contents.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 - (NSInteger)numberOfOpenPinnedTabs; 243 - (NSInteger)numberOfOpenPinnedTabs;
245 - (NSInteger)numberOfOpenNonPinnedTabs; 244 - (NSInteger)numberOfOpenNonPinnedTabs;
246 - (void)mouseMoved:(NSEvent*)event; 245 - (void)mouseMoved:(NSEvent*)event;
247 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; 246 - (void)setTabTrackingAreasEnabled:(BOOL)enabled;
248 - (void)droppingURLsAt:(NSPoint)point 247 - (void)droppingURLsAt:(NSPoint)point
249 givesIndex:(NSInteger*)index 248 givesIndex:(NSInteger*)index
250 disposition:(WindowOpenDisposition*)disposition; 249 disposition:(WindowOpenDisposition*)disposition;
251 - (void)setNewTabButtonHoverState:(BOOL)showHover; 250 - (void)setNewTabButtonHoverState:(BOOL)showHover;
252 - (void)themeDidChangeNotification:(NSNotification*)notification; 251 - (void)themeDidChangeNotification:(NSNotification*)notification;
253 - (void)setNewTabImages; 252 - (void)setNewTabImages;
253 - (BOOL)isAnyOtherTab:(content::WebContents*)selected
254 withState:(TabMediaState)state;
255
254 @end 256 @end
255 257
256 // A simple view class that contains the traffic light buttons. This class 258 // 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 259 // ensures that the buttons display the icons when the mouse hovers over
258 // them by overriding the _mouseInGroup method. 260 // them by overriding the _mouseInGroup method.
259 @interface CustomWindowControlsView : NSView { 261 @interface CustomWindowControlsView : NSView {
260 @private 262 @private
261 BOOL mouseInside_; 263 BOOL mouseInside_;
262 } 264 }
263 265
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 // a canned string if |contents| is NULL. 1269 // a canned string if |contents| is NULL.
1268 - (void)setTabTitle:(TabController*)tab withContents:(WebContents*)contents { 1270 - (void)setTabTitle:(TabController*)tab withContents:(WebContents*)contents {
1269 base::string16 title; 1271 base::string16 title;
1270 if (contents) 1272 if (contents)
1271 title = contents->GetTitle(); 1273 title = contents->GetTitle();
1272 if (title.empty()) 1274 if (title.empty())
1273 title = l10n_util::GetStringUTF16(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED); 1275 title = l10n_util::GetStringUTF16(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED);
1274 [tab setTitle:base::SysUTF16ToNSString(title)]; 1276 [tab setTitle:base::SysUTF16ToNSString(title)];
1275 1277
1276 const base::string16& toolTip = chrome::AssembleTabTooltipText( 1278 const base::string16& toolTip = chrome::AssembleTabTooltipText(
1277 title, chrome::GetTabMediaStateForContents(contents)); 1279 title, [self mediaStateForContents:contents]);
1278 [tab setToolTip:base::SysUTF16ToNSString(toolTip)]; 1280 [tab setToolTip:base::SysUTF16ToNSString(toolTip)];
1279 } 1281 }
1280 1282
1281 // Called when a notification is received from the model to insert a new tab 1283 // Called when a notification is received from the model to insert a new tab
1282 // at |modelIndex|. 1284 // at |modelIndex|.
1283 - (void)insertTabWithContents:(content::WebContents*)contents 1285 - (void)insertTabWithContents:(content::WebContents*)contents
1284 atIndex:(NSInteger)modelIndex 1286 atIndex:(NSInteger)modelIndex
1285 inForeground:(bool)inForeground { 1287 inForeground:(bool)inForeground {
1286 DCHECK(contents); 1288 DCHECK(contents);
1287 DCHECK(modelIndex == TabStripModel::kNoTab || 1289 DCHECK(modelIndex == TabStripModel::kNoTab ||
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 } else if (newState == kTabCrashed) { 1621 } else if (newState == kTabCrashed) {
1620 [tabController setIconImage:sadFaviconImage withToastAnimation:YES]; 1622 [tabController setIconImage:sadFaviconImage withToastAnimation:YES];
1621 } else { 1623 } else {
1622 [tabController setIconImage:throbberImage]; 1624 [tabController setIconImage:throbberImage];
1623 } 1625 }
1624 } else { 1626 } else {
1625 [tabController setIconImage:nil]; 1627 [tabController setIconImage:nil];
1626 } 1628 }
1627 } 1629 }
1628 1630
1629 [tabController setMediaState:chrome::GetTabMediaStateForContents(contents)]; 1631 TabMediaState mediaState = [self mediaStateForContents:contents];
1632
1633 [self updateWindowMediaState:mediaState on:contents];
1634 [tabController setMediaState:mediaState];
1630 1635
1631 [tabController updateVisibility]; 1636 [tabController updateVisibility];
1632 } 1637 }
1633 1638
1634 // Called when a notification is received from the model that the given tab 1639 // 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 1640 // 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. 1641 // throbber state, not anything else about the (partially) loading tab.
1637 - (void)tabChangedWithContents:(content::WebContents*)contents 1642 - (void)tabChangedWithContents:(content::WebContents*)contents
1638 atIndex:(NSInteger)modelIndex 1643 atIndex:(NSInteger)modelIndex
1639 changeType:(TabStripModelObserver::TabChangeType)change { 1644 changeType:(TabStripModelObserver::TabChangeType)change {
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
2284 } 2289 }
2285 } 2290 }
2286 2291
2287 - (void)removeCustomWindowControls { 2292 - (void)removeCustomWindowControls {
2288 if (customWindowControls_) 2293 if (customWindowControls_)
2289 [permanentSubviews_ removeObject:customWindowControls_]; 2294 [permanentSubviews_ removeObject:customWindowControls_];
2290 [self regenerateSubviewList]; 2295 [self regenerateSubviewList];
2291 [customWindowControls_ setMouseInside:NO]; 2296 [customWindowControls_ setMouseInside:NO];
2292 } 2297 }
2293 2298
2299 // Gets the tab and the media state to check whether the window
2300 // media state should be updated or not. If the tab media state is
2301 // AUDIO_PLAYING, the window media state should be set to AUDIO_PLAYING.
2302 // If the tab media state is AUDIO_MUTING, this method would check if the
2303 // window has no other tab with state AUDIO_PLAYING, then the window
2304 // media state will be set to AUDIO_MUTING. If the tab media state is NONE,
2305 // this method checks if the window has no playing or muting tab, then window
2306 // media state will be set as NONE.
2307 - (void)updateWindowMediaState:(TabMediaState)mediaState
2308 on:(content::WebContents*)selected {
2309 NSWindow* window = [tabStripView_ window];
2310 BrowserWindowController* windowController =
2311 [BrowserWindowController browserWindowControllerForWindow:window];
2312 if (mediaState == TAB_MEDIA_STATE_NONE) {
2313 if (![self isAnyOtherTab:selected
2314 withState:TAB_MEDIA_STATE_AUDIO_PLAYING] &&
2315 ![self isAnyOtherTab:selected withState:TAB_MEDIA_STATE_AUDIO_MUTING]) {
2316 [windowController setMediaState:TAB_MEDIA_STATE_NONE];
2317 } else if ([self isAnyOtherTab:selected
2318 withState:TAB_MEDIA_STATE_AUDIO_MUTING]) {
2319 [windowController setMediaState:TAB_MEDIA_STATE_AUDIO_MUTING];
2320 }
2321 } else if (mediaState == TAB_MEDIA_STATE_AUDIO_MUTING) {
2322 if (![self isAnyOtherTab:selected withState:TAB_MEDIA_STATE_AUDIO_PLAYING])
2323 [windowController setMediaState:TAB_MEDIA_STATE_AUDIO_MUTING];
2324 } else {
2325 [windowController setMediaState:mediaState];
2326 }
2327 }
2328
2329 // Checks if tabs (excluding selected) has media state equals to the second
2330 // parameter. It returns YES when it finds the first tab with the criterion.
2331 - (BOOL)isAnyOtherTab:(content::WebContents*)selected
2332 withState:(TabMediaState)state {
2333 const int existingTabCount = tabStripModel_->count();
2334 for (int i = 0; i < existingTabCount; ++i) {
2335 content::WebContents* currentContents = tabStripModel_->GetWebContentsAt(i);
2336 if (selected == currentContents)
2337 continue;
2338 TabMediaState currentMediaStateForContents =
2339 [self mediaStateForContents:currentContents];
2340 if (currentMediaStateForContents == state)
2341 return YES;
2342 }
2343 return NO;
2344 }
2345
2346 - (TabMediaState)mediaStateForContents:(content::WebContents*)contents {
2347 return chrome::GetTabMediaStateForContents(contents);
2348 }
2349
2294 - (void)themeDidChangeNotification:(NSNotification*)notification { 2350 - (void)themeDidChangeNotification:(NSNotification*)notification {
2295 [self setNewTabImages]; 2351 [self setNewTabImages];
2296 } 2352 }
2297 2353
2298 - (void)setNewTabImages { 2354 - (void)setNewTabImages {
2299 ThemeService *theme = 2355 ThemeService *theme =
2300 static_cast<ThemeService*>([[tabStripView_ window] themeProvider]); 2356 static_cast<ThemeService*>([[tabStripView_ window] themeProvider]);
2301 if (!theme) 2357 if (!theme)
2302 return; 2358 return;
2303 2359
(...skipping 24 matching lines...) Expand all
2328 forButtonState:image_button_cell::kHoverStateBackground]; 2384 forButtonState:image_button_cell::kHoverStateBackground];
2329 } else { 2385 } else {
2330 [[newTabButton_ cell] setImage:nil 2386 [[newTabButton_ cell] setImage:nil
2331 forButtonState:image_button_cell::kDefaultStateBackground]; 2387 forButtonState:image_button_cell::kDefaultStateBackground];
2332 [[newTabButton_ cell] setImage:nil 2388 [[newTabButton_ cell] setImage:nil
2333 forButtonState:image_button_cell::kHoverStateBackground]; 2389 forButtonState:image_button_cell::kHoverStateBackground];
2334 } 2390 }
2335 } 2391 }
2336 2392
2337 @end 2393 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_strip_controller.h ('k') | chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698