| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 bool animate_; | 135 bool animate_; |
| 136 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup); | 136 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 } // namespace | 139 } // namespace |
| 140 | 140 |
| 141 @interface TabStripController (Private) | 141 @interface TabStripController (Private) |
| 142 - (void)addSubviewToPermanentList:(NSView*)aView; | 142 - (void)addSubviewToPermanentList:(NSView*)aView; |
| 143 - (void)regenerateSubviewList; | 143 - (void)regenerateSubviewList; |
| 144 - (NSInteger)indexForContentsView:(NSView*)view; | 144 - (NSInteger)indexForContentsView:(NSView*)view; |
| 145 - (NSImage*)iconImageForContents:(content::WebContents*)contents; | 145 - (NSImage*)iconImageForContents:(content::WebContents*)contents |
| 146 atIndex:(NSInteger)modelIndex; |
| 146 - (void)updateIconsForContents:(content::WebContents*)contents | 147 - (void)updateIconsForContents:(content::WebContents*)contents |
| 147 atIndex:(NSInteger)modelIndex; | 148 atIndex:(NSInteger)modelIndex; |
| 148 - (void)layoutTabsWithAnimation:(BOOL)animate | 149 - (void)layoutTabsWithAnimation:(BOOL)animate |
| 149 regenerateSubviews:(BOOL)doUpdate; | 150 regenerateSubviews:(BOOL)doUpdate; |
| 150 - (void)animationDidStop:(CAAnimation*)animation | 151 - (void)animationDidStop:(CAAnimation*)animation |
| 151 forController:(TabController*)controller | 152 forController:(TabController*)controller |
| 152 finished:(BOOL)finished; | 153 finished:(BOOL)finished; |
| 153 - (NSInteger)indexFromModelIndex:(NSInteger)index; | 154 - (NSInteger)indexFromModelIndex:(NSInteger)index; |
| 154 - (void)clickNewTabButton:(id)sender; | 155 - (void)clickNewTabButton:(id)sender; |
| 155 - (NSInteger)numberOfOpenTabs; | 156 - (NSInteger)numberOfOpenTabs; |
| (...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 [oldController willBecomeUnselectedTab]; | 1291 [oldController willBecomeUnselectedTab]; |
| 1291 } | 1292 } |
| 1292 } | 1293 } |
| 1293 | 1294 |
| 1294 NSUInteger activeIndex = [self indexFromModelIndex:modelIndex]; | 1295 NSUInteger activeIndex = [self indexFromModelIndex:modelIndex]; |
| 1295 | 1296 |
| 1296 [tabArray_ enumerateObjectsUsingBlock:^(TabController* current, | 1297 [tabArray_ enumerateObjectsUsingBlock:^(TabController* current, |
| 1297 NSUInteger index, | 1298 NSUInteger index, |
| 1298 BOOL* stop) { | 1299 BOOL* stop) { |
| 1299 [current setActive:index == activeIndex]; | 1300 [current setActive:index == activeIndex]; |
| 1301 [self updateIconsForContents:newContents atIndex:modelIndex]; |
| 1300 }]; | 1302 }]; |
| 1301 | 1303 |
| 1302 // Tell the new tab contents it is about to become the selected tab. Here it | 1304 // Tell the new tab contents it is about to become the selected tab. Here it |
| 1303 // can do things like make sure the toolbar is up to date. | 1305 // can do things like make sure the toolbar is up to date. |
| 1304 TabContentsController* newController = | 1306 TabContentsController* newController = |
| 1305 [tabContentsArray_ objectAtIndex:activeIndex]; | 1307 [tabContentsArray_ objectAtIndex:activeIndex]; |
| 1306 [newController willBecomeSelectedTab]; | 1308 [newController willBecomeSelectedTab]; |
| 1307 | 1309 |
| 1308 // Relayout for new tabs and to let the selected tab grow to be larger in | 1310 // Relayout for new tabs and to let the selected tab grow to be larger in |
| 1309 // size than surrounding tabs if the user has many. This also raises the | 1311 // size than surrounding tabs if the user has many. This also raises the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1321 // First get the vector of indices, which is allays sorted in ascending order. | 1323 // First get the vector of indices, which is allays sorted in ascending order. |
| 1322 ui::ListSelectionModel::SelectedIndices selection( | 1324 ui::ListSelectionModel::SelectedIndices selection( |
| 1323 tabStripModel_->selection_model().selected_indices()); | 1325 tabStripModel_->selection_model().selected_indices()); |
| 1324 // Iterate through all of the tabs, selecting each as necessary. | 1326 // Iterate through all of the tabs, selecting each as necessary. |
| 1325 ui::ListSelectionModel::SelectedIndices::iterator iter = selection.begin(); | 1327 ui::ListSelectionModel::SelectedIndices::iterator iter = selection.begin(); |
| 1326 int i = 0; | 1328 int i = 0; |
| 1327 for (TabController* current in tabArray_.get()) { | 1329 for (TabController* current in tabArray_.get()) { |
| 1328 BOOL selected = iter != selection.end() && | 1330 BOOL selected = iter != selection.end() && |
| 1329 [self indexFromModelIndex:*iter] == i; | 1331 [self indexFromModelIndex:*iter] == i; |
| 1330 [current setSelected:selected]; | 1332 [current setSelected:selected]; |
| 1333 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; |
| 1331 if (selected) | 1334 if (selected) |
| 1332 ++iter; | 1335 ++iter; |
| 1333 ++i; | 1336 ++i; |
| 1334 } | 1337 } |
| 1335 } | 1338 } |
| 1336 | 1339 |
| 1337 - (void)tabReplacedWithContents:(content::WebContents*)newContents | 1340 - (void)tabReplacedWithContents:(content::WebContents*)newContents |
| 1338 previousContents:(content::WebContents*)oldContents | 1341 previousContents:(content::WebContents*)oldContents |
| 1339 atIndex:(NSInteger)modelIndex { | 1342 atIndex:(NSInteger)modelIndex { |
| 1340 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1343 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 // tabs. Instead, simply mark it as closing to prevent the tab from | 1470 // tabs. Instead, simply mark it as closing to prevent the tab from |
| 1468 // generating any drags or selections. | 1471 // generating any drags or selections. |
| 1469 [[tab tabView] setClosing:YES]; | 1472 [[tab tabView] setClosing:YES]; |
| 1470 } | 1473 } |
| 1471 | 1474 |
| 1472 [delegate_ onTabDetachedWithContents:contents]; | 1475 [delegate_ onTabDetachedWithContents:contents]; |
| 1473 } | 1476 } |
| 1474 | 1477 |
| 1475 // A helper routine for creating an NSImageView to hold the favicon or app icon | 1478 // A helper routine for creating an NSImageView to hold the favicon or app icon |
| 1476 // for |contents|. | 1479 // for |contents|. |
| 1477 - (NSImage*)iconImageForContents:(content::WebContents*)contents { | 1480 - (NSImage*)iconImageForContents:(content::WebContents*)contents |
| 1481 atIndex:(NSInteger)modelIndex { |
| 1478 extensions::TabHelper* extensions_tab_helper = | 1482 extensions::TabHelper* extensions_tab_helper = |
| 1479 extensions::TabHelper::FromWebContents(contents); | 1483 extensions::TabHelper::FromWebContents(contents); |
| 1480 BOOL isApp = extensions_tab_helper->is_app(); | 1484 BOOL isApp = extensions_tab_helper->is_app(); |
| 1481 NSImage* image = nil; | 1485 NSImage* image = nil; |
| 1482 // Favicons come from the renderer, and the renderer draws everything in the | 1486 // Favicons come from the renderer, and the renderer draws everything in the |
| 1483 // system color space. | 1487 // system color space. |
| 1484 CGColorSpaceRef colorSpace = base::mac::GetSystemColorSpace(); | 1488 CGColorSpaceRef colorSpace = base::mac::GetSystemColorSpace(); |
| 1485 if (isApp) { | 1489 if (isApp) { |
| 1486 SkBitmap* icon = extensions_tab_helper->GetExtensionAppIcon(); | 1490 SkBitmap* icon = extensions_tab_helper->GetExtensionAppIcon(); |
| 1487 if (icon) | 1491 if (icon) |
| 1488 image = skia::SkBitmapToNSImageWithColorSpace(*icon, colorSpace); | 1492 image = skia::SkBitmapToNSImageWithColorSpace(*icon, colorSpace); |
| 1489 } else { | 1493 } else { |
| 1490 TabController* tab = [tabArray_ firstObject]; | 1494 TabController* tab = [tabArray_ objectAtIndex:modelIndex]; |
| 1491 NSColor* titleColor = [[tab tabView] titleColor]; | 1495 image = mac::FaviconForWebContents(contents, [[tab tabView] iconColor]); |
| 1492 NSColor* deviceColor = | |
| 1493 [titleColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; | |
| 1494 image = mac::FaviconForWebContents( | |
| 1495 contents, skia::NSDeviceColorToSkColor(deviceColor)); | |
| 1496 } | 1496 } |
| 1497 | 1497 |
| 1498 // Either we don't have a valid favicon or there was some issue converting it | 1498 // Either we don't have a valid favicon or there was some issue converting it |
| 1499 // from an SkBitmap. Either way, just show the default. | 1499 // from an SkBitmap. Either way, just show the default. |
| 1500 if (!image) | 1500 if (!image) |
| 1501 image = defaultFavicon_.get(); | 1501 image = defaultFavicon_.get(); |
| 1502 | 1502 |
| 1503 return image; | 1503 return image; |
| 1504 } | 1504 } |
| 1505 | 1505 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1564 [tabController setLoadingState:newState]; | 1564 [tabController setLoadingState:newState]; |
| 1565 | 1565 |
| 1566 // While loading, this function is called repeatedly with the same state. | 1566 // While loading, this function is called repeatedly with the same state. |
| 1567 // To avoid expensive unnecessary view manipulation, only make changes when | 1567 // To avoid expensive unnecessary view manipulation, only make changes when |
| 1568 // the state is actually changing. When loading is complete (kTabDone), | 1568 // the state is actually changing. When loading is complete (kTabDone), |
| 1569 // every call to this function is significant. | 1569 // every call to this function is significant. |
| 1570 if (newState == kTabDone || oldState != newState || | 1570 if (newState == kTabDone || oldState != newState || |
| 1571 oldHasIcon != newHasIcon) { | 1571 oldHasIcon != newHasIcon) { |
| 1572 if (newHasIcon) { | 1572 if (newHasIcon) { |
| 1573 if (newState == kTabDone) { | 1573 if (newState == kTabDone) { |
| 1574 [tabController setIconImage:[self iconImageForContents:contents]]; | 1574 [tabController setIconImage:[self iconImageForContents:contents |
| 1575 atIndex:modelIndex]]; |
| 1575 } else if (newState == kTabCrashed) { | 1576 } else if (newState == kTabCrashed) { |
| 1576 [tabController setIconImage:sadFaviconImage withToastAnimation:YES]; | 1577 [tabController setIconImage:sadFaviconImage withToastAnimation:YES]; |
| 1577 } else { | 1578 } else { |
| 1578 [tabController setIconImage:throbberImage]; | 1579 [tabController setIconImage:throbberImage]; |
| 1579 } | 1580 } |
| 1580 } else { | 1581 } else { |
| 1581 [tabController setIconImage:nil]; | 1582 [tabController setIconImage:nil]; |
| 1582 } | 1583 } |
| 1583 } | 1584 } |
| 1584 | 1585 |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2300 } | 2301 } |
| 2301 return NO; | 2302 return NO; |
| 2302 } | 2303 } |
| 2303 | 2304 |
| 2304 - (TabAlertState)alertStateForContents:(content::WebContents*)contents { | 2305 - (TabAlertState)alertStateForContents:(content::WebContents*)contents { |
| 2305 return chrome::GetTabAlertStateForContents(contents); | 2306 return chrome::GetTabAlertStateForContents(contents); |
| 2306 } | 2307 } |
| 2307 | 2308 |
| 2308 - (void)themeDidChangeNotification:(NSNotification*)notification { | 2309 - (void)themeDidChangeNotification:(NSNotification*)notification { |
| 2309 [newTabButton_ setImages]; | 2310 [newTabButton_ setImages]; |
| 2311 for (int i = 0; i < tabStripModel_->count(); i++) { |
| 2312 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; |
| 2313 } |
| 2310 } | 2314 } |
| 2311 | 2315 |
| 2312 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { | 2316 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { |
| 2313 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; | 2317 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; |
| 2314 } | 2318 } |
| 2315 | 2319 |
| 2316 @end | 2320 @end |
| OLD | NEW |