| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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)doesAnyOtherWebContents:(content::WebContents*)selected |
| 254 haveMediaState:(TabMediaState)state; |
| 254 @end | 255 @end |
| 255 | 256 |
| 256 // A simple view class that contains the traffic light buttons. This class | 257 // 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 | 258 // ensures that the buttons display the icons when the mouse hovers over |
| 258 // them by overriding the _mouseInGroup method. | 259 // them by overriding the _mouseInGroup method. |
| 259 @interface CustomWindowControlsView : NSView { | 260 @interface CustomWindowControlsView : NSView { |
| 260 @private | 261 @private |
| 261 BOOL mouseInside_; | 262 BOOL mouseInside_; |
| 262 } | 263 } |
| 263 | 264 |
| (...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 // a canned string if |contents| is NULL. | 1268 // a canned string if |contents| is NULL. |
| 1268 - (void)setTabTitle:(TabController*)tab withContents:(WebContents*)contents { | 1269 - (void)setTabTitle:(TabController*)tab withContents:(WebContents*)contents { |
| 1269 base::string16 title; | 1270 base::string16 title; |
| 1270 if (contents) | 1271 if (contents) |
| 1271 title = contents->GetTitle(); | 1272 title = contents->GetTitle(); |
| 1272 if (title.empty()) | 1273 if (title.empty()) |
| 1273 title = l10n_util::GetStringUTF16(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED); | 1274 title = l10n_util::GetStringUTF16(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED); |
| 1274 [tab setTitle:base::SysUTF16ToNSString(title)]; | 1275 [tab setTitle:base::SysUTF16ToNSString(title)]; |
| 1275 | 1276 |
| 1276 const base::string16& toolTip = chrome::AssembleTabTooltipText( | 1277 const base::string16& toolTip = chrome::AssembleTabTooltipText( |
| 1277 title, chrome::GetTabMediaStateForContents(contents)); | 1278 title, [self mediaStateForContents:contents]); |
| 1278 [tab setToolTip:base::SysUTF16ToNSString(toolTip)]; | 1279 [tab setToolTip:base::SysUTF16ToNSString(toolTip)]; |
| 1279 } | 1280 } |
| 1280 | 1281 |
| 1281 // Called when a notification is received from the model to insert a new tab | 1282 // Called when a notification is received from the model to insert a new tab |
| 1282 // at |modelIndex|. | 1283 // at |modelIndex|. |
| 1283 - (void)insertTabWithContents:(content::WebContents*)contents | 1284 - (void)insertTabWithContents:(content::WebContents*)contents |
| 1284 atIndex:(NSInteger)modelIndex | 1285 atIndex:(NSInteger)modelIndex |
| 1285 inForeground:(bool)inForeground { | 1286 inForeground:(bool)inForeground { |
| 1286 DCHECK(contents); | 1287 DCHECK(contents); |
| 1287 DCHECK(modelIndex == TabStripModel::kNoTab || | 1288 DCHECK(modelIndex == TabStripModel::kNoTab || |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1619 } else if (newState == kTabCrashed) { | 1620 } else if (newState == kTabCrashed) { |
| 1620 [tabController setIconImage:sadFaviconImage withToastAnimation:YES]; | 1621 [tabController setIconImage:sadFaviconImage withToastAnimation:YES]; |
| 1621 } else { | 1622 } else { |
| 1622 [tabController setIconImage:throbberImage]; | 1623 [tabController setIconImage:throbberImage]; |
| 1623 } | 1624 } |
| 1624 } else { | 1625 } else { |
| 1625 [tabController setIconImage:nil]; | 1626 [tabController setIconImage:nil]; |
| 1626 } | 1627 } |
| 1627 } | 1628 } |
| 1628 | 1629 |
| 1629 [tabController setMediaState:chrome::GetTabMediaStateForContents(contents)]; | 1630 TabMediaState mediaState = [self mediaStateForContents:contents]; |
| 1631 [self updateWindowMediaState:mediaState forWebContents:contents]; |
| 1632 [tabController setMediaState:mediaState]; |
| 1630 | 1633 |
| 1631 [tabController updateVisibility]; | 1634 [tabController updateVisibility]; |
| 1632 } | 1635 } |
| 1633 | 1636 |
| 1634 // Called when a notification is received from the model that the given tab | 1637 // 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 | 1638 // 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. | 1639 // throbber state, not anything else about the (partially) loading tab. |
| 1637 - (void)tabChangedWithContents:(content::WebContents*)contents | 1640 - (void)tabChangedWithContents:(content::WebContents*)contents |
| 1638 atIndex:(NSInteger)modelIndex | 1641 atIndex:(NSInteger)modelIndex |
| 1639 changeType:(TabStripModelObserver::TabChangeType)change { | 1642 changeType:(TabStripModelObserver::TabChangeType)change { |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2284 } | 2287 } |
| 2285 } | 2288 } |
| 2286 | 2289 |
| 2287 - (void)removeCustomWindowControls { | 2290 - (void)removeCustomWindowControls { |
| 2288 if (customWindowControls_) | 2291 if (customWindowControls_) |
| 2289 [permanentSubviews_ removeObject:customWindowControls_]; | 2292 [permanentSubviews_ removeObject:customWindowControls_]; |
| 2290 [self regenerateSubviewList]; | 2293 [self regenerateSubviewList]; |
| 2291 [customWindowControls_ setMouseInside:NO]; | 2294 [customWindowControls_ setMouseInside:NO]; |
| 2292 } | 2295 } |
| 2293 | 2296 |
| 2297 // Gets the tab and the media state to check whether the window |
| 2298 // media state should be updated or not. If the tab media state is |
| 2299 // AUDIO_PLAYING, the window media state should be set to AUDIO_PLAYING. |
| 2300 // If the tab media state is AUDIO_MUTING, this method would check if the |
| 2301 // window has no other tab with state AUDIO_PLAYING, then the window |
| 2302 // media state will be set to AUDIO_MUTING. If the tab media state is NONE, |
| 2303 // this method checks if the window has no playing or muting tab, then window |
| 2304 // media state will be set as NONE. |
| 2305 - (void)updateWindowMediaState:(TabMediaState)mediaState |
| 2306 forWebContents:(content::WebContents*)selected { |
| 2307 NSWindow* window = [tabStripView_ window]; |
| 2308 BrowserWindowController* windowController = |
| 2309 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 2310 if (mediaState == TAB_MEDIA_STATE_NONE) { |
| 2311 if (![self doesAnyOtherWebContents:selected |
| 2312 haveMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING] && |
| 2313 ![self doesAnyOtherWebContents:selected |
| 2314 haveMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]) { |
| 2315 [windowController setMediaState:TAB_MEDIA_STATE_NONE]; |
| 2316 } else if ([self doesAnyOtherWebContents:selected |
| 2317 haveMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]) { |
| 2318 [windowController setMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]; |
| 2319 } |
| 2320 } else if (mediaState == TAB_MEDIA_STATE_AUDIO_MUTING) { |
| 2321 if (![self doesAnyOtherWebContents:selected |
| 2322 haveMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING]) { |
| 2323 [windowController setMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]; |
| 2324 } |
| 2325 } else { |
| 2326 [windowController setMediaState:mediaState]; |
| 2327 } |
| 2328 } |
| 2329 |
| 2330 // Checks if tabs (excluding selected) has media state equals to the second |
| 2331 // parameter. It returns YES when it finds the first tab with the criterion. |
| 2332 - (BOOL)doesAnyOtherWebContents:(content::WebContents*)selected |
| 2333 haveMediaState:(TabMediaState)state { |
| 2334 const int existingTabCount = tabStripModel_->count(); |
| 2335 for (int i = 0; i < existingTabCount; ++i) { |
| 2336 content::WebContents* currentContents = tabStripModel_->GetWebContentsAt(i); |
| 2337 if (selected == currentContents) |
| 2338 continue; |
| 2339 TabMediaState currentMediaStateForContents = |
| 2340 [self mediaStateForContents:currentContents]; |
| 2341 if (currentMediaStateForContents == state) |
| 2342 return YES; |
| 2343 } |
| 2344 return NO; |
| 2345 } |
| 2346 |
| 2347 - (TabMediaState)mediaStateForContents:(content::WebContents*)contents { |
| 2348 return chrome::GetTabMediaStateForContents(contents); |
| 2349 } |
| 2350 |
| 2294 - (void)themeDidChangeNotification:(NSNotification*)notification { | 2351 - (void)themeDidChangeNotification:(NSNotification*)notification { |
| 2295 [self setNewTabImages]; | 2352 [self setNewTabImages]; |
| 2296 } | 2353 } |
| 2297 | 2354 |
| 2298 - (void)setNewTabImages { | 2355 - (void)setNewTabImages { |
| 2299 ThemeService *theme = | 2356 ThemeService *theme = |
| 2300 static_cast<ThemeService*>([[tabStripView_ window] themeProvider]); | 2357 static_cast<ThemeService*>([[tabStripView_ window] themeProvider]); |
| 2301 if (!theme) | 2358 if (!theme) |
| 2302 return; | 2359 return; |
| 2303 | 2360 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2328 forButtonState:image_button_cell::kHoverStateBackground]; | 2385 forButtonState:image_button_cell::kHoverStateBackground]; |
| 2329 } else { | 2386 } else { |
| 2330 [[newTabButton_ cell] setImage:nil | 2387 [[newTabButton_ cell] setImage:nil |
| 2331 forButtonState:image_button_cell::kDefaultStateBackground]; | 2388 forButtonState:image_button_cell::kDefaultStateBackground]; |
| 2332 [[newTabButton_ cell] setImage:nil | 2389 [[newTabButton_ cell] setImage:nil |
| 2333 forButtonState:image_button_cell::kHoverStateBackground]; | 2390 forButtonState:image_button_cell::kHoverStateBackground]; |
| 2334 } | 2391 } |
| 2335 } | 2392 } |
| 2336 | 2393 |
| 2337 @end | 2394 @end |
| OLD | NEW |