| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/tab_strip_controller.h" | 5 #import "chrome/browser/cocoa/tab_strip_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" | 28 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" |
| 29 #import "chrome/browser/cocoa/tab_view.h" | 29 #import "chrome/browser/cocoa/tab_view.h" |
| 30 #import "chrome/browser/cocoa/throbber_view.h" | 30 #import "chrome/browser/cocoa/throbber_view.h" |
| 31 #include "chrome/browser/debugger/devtools_window.h" | 31 #include "chrome/browser/debugger/devtools_window.h" |
| 32 #include "chrome/browser/net/url_fixer_upper.h" | 32 #include "chrome/browser/net/url_fixer_upper.h" |
| 33 #include "chrome/browser/tab_contents/navigation_controller.h" | 33 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 34 #include "chrome/browser/tab_contents/navigation_entry.h" | 34 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 35 #include "chrome/browser/tab_contents/tab_contents.h" | 35 #include "chrome/browser/tab_contents/tab_contents.h" |
| 36 #include "chrome/browser/tab_contents/tab_contents_view.h" | 36 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 37 #include "chrome/browser/tabs/tab_strip_model.h" | 37 #include "chrome/browser/tabs/tab_strip_model.h" |
| 38 #include "chrome/common/extensions/extension.h" | |
| 39 #include "grit/app_resources.h" | 38 #include "grit/app_resources.h" |
| 40 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| 41 #include "grit/theme_resources.h" | 40 #include "grit/theme_resources.h" |
| 42 #include "skia/ext/skia_utils_mac.h" | 41 #include "skia/ext/skia_utils_mac.h" |
| 43 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 42 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
| 44 | 43 |
| 45 NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged"; | 44 NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged"; |
| 46 | 45 |
| 47 namespace { | 46 namespace { |
| 48 | 47 |
| 49 // The images names used for different states of the new tab button. | 48 // The images names used for different states of the new tab button. |
| 50 NSString* const kNewTabHoverImage = @"newtab_h.pdf"; | 49 NSString* const kNewTabHoverImage = @"newtab_h.pdf"; |
| 51 NSString* const kNewTabImage = @"newtab.pdf"; | 50 NSString* const kNewTabImage = @"newtab.pdf"; |
| 52 NSString* const kNewTabPressedImage = @"newtab_p.pdf"; | 51 NSString* const kNewTabPressedImage = @"newtab_p.pdf"; |
| 53 | 52 |
| 54 // A value to indicate tab layout should use the full available width of the | 53 // A value to indicate tab layout should use the full available width of the |
| 55 // view. | 54 // view. |
| 56 const CGFloat kUseFullAvailableWidth = -1.0; | 55 const CGFloat kUseFullAvailableWidth = -1.0; |
| 57 | 56 |
| 58 // The amount by which tabs overlap. | 57 // The amount by which tabs overlap. |
| 59 const CGFloat kTabOverlap = 20.0; | 58 const CGFloat kTabOverlap = 20.0; |
| 60 | 59 |
| 61 // The amount by which app tabs overlap with themselves and normal tabs. | 60 // The width and height for a tab's icon. |
| 62 const CGFloat kAppTabOverlap = 5.0; | 61 const CGFloat kIconWidthAndHeight = 16.0; |
| 63 | 62 |
| 64 // The amount by which the new tab button is offset (from the tabs). | 63 // The amount by which the new tab button is offset (from the tabs). |
| 65 const CGFloat kNewTabButtonOffset = 8.0; | 64 const CGFloat kNewTabButtonOffset = 8.0; |
| 66 | 65 |
| 67 // The amount by which to shrink the tab strip (on the right) when the | 66 // The amount by which to shrink the tab strip (on the right) when the |
| 68 // incognito badge is present. | 67 // incognito badge is present. |
| 69 const CGFloat kIncognitoBadgeTabStripShrink = 18; | 68 const CGFloat kIncognitoBadgeTabStripShrink = 18; |
| 70 | 69 |
| 71 // Time (in seconds) in which tabs animate to their final position. | 70 // Time (in seconds) in which tabs animate to their final position. |
| 72 const NSTimeInterval kAnimationDuration = 0.125; | 71 const NSTimeInterval kAnimationDuration = 0.125; |
| (...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 // Send a broadcast that the number of tabs have changed. | 1148 // Send a broadcast that the number of tabs have changed. |
| 1150 [[NSNotificationCenter defaultCenter] | 1149 [[NSNotificationCenter defaultCenter] |
| 1151 postNotificationName:kTabStripNumberOfTabsChanged | 1150 postNotificationName:kTabStripNumberOfTabsChanged |
| 1152 object:self]; | 1151 object:self]; |
| 1153 } | 1152 } |
| 1154 | 1153 |
| 1155 // A helper routine for creating an NSImageView to hold the fav icon or app icon | 1154 // A helper routine for creating an NSImageView to hold the fav icon or app icon |
| 1156 // for |contents|. | 1155 // for |contents|. |
| 1157 - (NSImageView*)iconImageViewForContents:(TabContents*)contents { | 1156 - (NSImageView*)iconImageViewForContents:(TabContents*)contents { |
| 1158 BOOL isApp = contents->is_app(); | 1157 BOOL isApp = contents->is_app(); |
| 1159 | 1158 NSImage* image = nil; |
| 1160 NSImage* image = gfx::SkBitmapToNSImage( | 1159 if (isApp) { |
| 1161 isApp ? *(contents->GetExtensionAppIcon()) : contents->GetFavIcon()); | 1160 SkBitmap* icon = contents->GetExtensionAppIcon(); |
| 1161 if (icon) |
| 1162 image = gfx::SkBitmapToNSImage(*icon); |
| 1163 } else { |
| 1164 image = gfx::SkBitmapToNSImage(contents->GetFavIcon()); |
| 1165 } |
| 1162 | 1166 |
| 1163 // Either we don't have a valid favicon or there was some issue converting it | 1167 // Either we don't have a valid favicon or there was some issue converting it |
| 1164 // from an SkBitmap. Either way, just show the default. | 1168 // from an SkBitmap. Either way, just show the default. |
| 1165 if (!image) | 1169 if (!image) |
| 1166 image = defaultFavIcon_.get(); | 1170 image = defaultFavIcon_.get(); |
| 1167 | 1171 NSRect frame = NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight); |
| 1168 CGFloat iconWidthAndHeight = isApp ? Extension::EXTENSION_ICON_SMALLISH : 16; | 1172 NSImageView* view = [[[NSImageView alloc] initWithFrame:frame] autorelease]; |
| 1169 NSRect iconFrame = NSMakeRect(0, 0, iconWidthAndHeight, iconWidthAndHeight); | |
| 1170 NSImageView* view = [[[NSImageView alloc] initWithFrame:iconFrame] | |
| 1171 autorelease]; | |
| 1172 [view setImage:image]; | 1173 [view setImage:image]; |
| 1173 return view; | 1174 return view; |
| 1174 } | 1175 } |
| 1175 | 1176 |
| 1176 // Updates the current loading state, replacing the icon view with a favicon, | 1177 // Updates the current loading state, replacing the icon view with a favicon, |
| 1177 // a throbber, the default icon, or nothing at all. | 1178 // a throbber, the default icon, or nothing at all. |
| 1178 - (void)updateFavIconForContents:(TabContents*)contents | 1179 - (void)updateFavIconForContents:(TabContents*)contents |
| 1179 atIndex:(NSInteger)modelIndex { | 1180 atIndex:(NSInteger)modelIndex { |
| 1180 if (!contents) | 1181 if (!contents) |
| 1181 return; | 1182 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 // the state is actually changing. When loading is complete (kTabDone), | 1228 // the state is actually changing. When loading is complete (kTabDone), |
| 1228 // every call to this function is significant. | 1229 // every call to this function is significant. |
| 1229 if (newState == kTabDone || oldState != newState || | 1230 if (newState == kTabDone || oldState != newState || |
| 1230 oldHasIcon != newHasIcon) { | 1231 oldHasIcon != newHasIcon) { |
| 1231 NSView* iconView = nil; | 1232 NSView* iconView = nil; |
| 1232 if (newHasIcon) { | 1233 if (newHasIcon) { |
| 1233 if (newState == kTabDone) { | 1234 if (newState == kTabDone) { |
| 1234 iconView = [self iconImageViewForContents:contents]; | 1235 iconView = [self iconImageViewForContents:contents]; |
| 1235 } else if (newState == kTabCrashed) { | 1236 } else if (newState == kTabCrashed) { |
| 1236 NSImage* oldImage = [[self iconImageViewForContents:contents] image]; | 1237 NSImage* oldImage = [[self iconImageViewForContents:contents] image]; |
| 1237 NSRect frame = NSMakeRect(0, 0, 16, 16); | 1238 NSRect frame = |
| 1239 NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight); |
| 1238 iconView = [ThrobberView toastThrobberViewWithFrame:frame | 1240 iconView = [ThrobberView toastThrobberViewWithFrame:frame |
| 1239 beforeImage:oldImage | 1241 beforeImage:oldImage |
| 1240 afterImage:sadFaviconImage]; | 1242 afterImage:sadFaviconImage]; |
| 1241 } else { | 1243 } else { |
| 1242 NSRect frame = NSMakeRect(0, 0, 16, 16); | 1244 NSRect frame = |
| 1245 NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight); |
| 1243 iconView = [ThrobberView filmstripThrobberViewWithFrame:frame | 1246 iconView = [ThrobberView filmstripThrobberViewWithFrame:frame |
| 1244 image:throbberImage]; | 1247 image:throbberImage]; |
| 1245 } | 1248 } |
| 1246 } | 1249 } |
| 1247 | 1250 |
| 1248 [tabController setIconView:iconView]; | 1251 [tabController setIconView:iconView]; |
| 1249 } | 1252 } |
| 1250 } | 1253 } |
| 1251 | 1254 |
| 1252 // Called when a notification is received from the model that the given tab | 1255 // Called when a notification is received from the model that the given tab |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 return; | 1811 return; |
| 1809 | 1812 |
| 1810 TabContentsController* tabController = | 1813 TabContentsController* tabController = |
| 1811 [tabContentsArray_ objectAtIndex:index]; | 1814 [tabContentsArray_ objectAtIndex:index]; |
| 1812 TabContents* devtoolsContents = contents ? | 1815 TabContents* devtoolsContents = contents ? |
| 1813 DevToolsWindow::GetDevToolsContents(contents) : NULL; | 1816 DevToolsWindow::GetDevToolsContents(contents) : NULL; |
| 1814 [tabController showDevToolsContents:devtoolsContents]; | 1817 [tabController showDevToolsContents:devtoolsContents]; |
| 1815 } | 1818 } |
| 1816 | 1819 |
| 1817 @end | 1820 @end |
| OLD | NEW |