diff options
author | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 17:57:53 +0000 |
---|---|---|
committer | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 17:57:53 +0000 |
commit | 14e336a1b5a8ffe8512c63837599b449fa5540ee (patch) | |
tree | a0046049e053a00f3428dc0d7dbb8aacd59c11e7 /chrome/browser/cocoa/tab_strip_controller.mm | |
parent | 33bd60f508a0eaa7ddfefb497b35c1627a6ff0be (diff) | |
download | chromium_src-14e336a1b5a8ffe8512c63837599b449fa5540ee.zip chromium_src-14e336a1b5a8ffe8512c63837599b449fa5540ee.tar.gz chromium_src-14e336a1b5a8ffe8512c63837599b449fa5540ee.tar.bz2 |
[Mac] Initial implementation of app tabs. Loads the app and displays the correct icon (http://cl.ly/97c1b5e22eb32075d497).
Still to be done:
o there should be a much smaller overlap of app tabs with other tabs.
o The toolbar should hide when necessary.
o The context menu for the tab should have the option of hiding/showing the toolbar on a per-app basis.
TEST=none
BUG=45539
Review URL: http://codereview.chromium.org/2847052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51737 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/tab_strip_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 7930da7..ee4f9bf 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -35,6 +35,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/tabs/tab_strip_model.h" +#include "chrome/common/extensions/extension.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -57,6 +58,9 @@ const CGFloat kUseFullAvailableWidth = -1.0; // The amount by which tabs overlap. const CGFloat kTabOverlap = 20.0; +// The amount by which app tabs overlap with themselves and normal tabs. +const CGFloat kAppTabOverlap = 5.0; + // The amount by which the new tab button is offset (from the tabs). const CGFloat kNewTabButtonOffset = 8.0; @@ -687,6 +691,7 @@ private: const CGFloat kMinTabWidth = [TabController minTabWidth]; const CGFloat kMinSelectedTabWidth = [TabController minSelectedTabWidth]; const CGFloat kMiniTabWidth = [TabController miniTabWidth]; + const CGFloat kAppTabWidth = [TabController appTabWidth]; NSRect enclosingRect = NSZeroRect; ScopedNSAnimationContextGroup mainAnimationGroup(animate); @@ -813,7 +818,8 @@ private: // Set the width. Selected tabs are slightly wider when things get really // small and thus we enforce a different minimum width. - tabFrame.size.width = [tab mini] ? kMiniTabWidth : nonMiniTabWidth; + tabFrame.size.width = [tab mini] ? + ([tab app] ? kAppTabWidth : kMiniTabWidth) : nonMiniTabWidth; if ([tab selected]) tabFrame.size.width = MAX(tabFrame.size.width, kMinSelectedTabWidth); @@ -949,6 +955,7 @@ private: TabController* newController = [self newTab]; [newController setMini:tabStripModel_->IsMiniTab(modelIndex)]; [newController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; + [newController setApp:tabStripModel_->IsAppTab(modelIndex)]; [tabArray_ insertObject:newController atIndex:index]; NSView* newView = [newController view]; @@ -1145,28 +1152,23 @@ private: object:self]; } -// A helper routine for creating an NSImageView to hold the fav icon for -// |contents|. -- (NSImageView*)favIconImageViewForContents:(TabContents*)contents { - NSRect iconFrame = NSMakeRect(0, 0, 16, 16); - NSImageView* view = [[[NSImageView alloc] initWithFrame:iconFrame] - autorelease]; +// A helper routine for creating an NSImageView to hold the fav icon or app icon +// for |contents|. +- (NSImageView*)iconImageViewForContents:(TabContents*)contents { + BOOL isApp = contents->is_app(); - NSImage* image = nil; - - NavigationEntry* navEntry = contents->controller().GetLastCommittedEntry(); - if (navEntry != NULL) { - NavigationEntry::FaviconStatus favIcon = navEntry->favicon(); - const SkBitmap& bitmap = favIcon.bitmap(); - if (favIcon.is_valid() && !bitmap.isNull()) - image = gfx::SkBitmapToNSImage(bitmap); - } + NSImage* image = gfx::SkBitmapToNSImage( + isApp ? *(contents->GetExtensionAppIcon()) : contents->GetFavIcon()); // Either we don't have a valid favicon or there was some issue converting it // from an SkBitmap. Either way, just show the default. if (!image) image = defaultFavIcon_.get(); + CGFloat iconWidthAndHeight = isApp ? Extension::EXTENSION_ICON_SMALLISH : 16; + NSRect iconFrame = NSMakeRect(0, 0, iconWidthAndHeight, iconWidthAndHeight); + NSImageView* view = [[[NSImageView alloc] initWithFrame:iconFrame] + autorelease]; [view setImage:image]; return view; } @@ -1229,9 +1231,9 @@ private: NSView* iconView = nil; if (newHasIcon) { if (newState == kTabDone) { - iconView = [self favIconImageViewForContents:contents]; + iconView = [self iconImageViewForContents:contents]; } else if (newState == kTabCrashed) { - NSImage* oldImage = [[self favIconImageViewForContents:contents] image]; + NSImage* oldImage = [[self iconImageViewForContents:contents] image]; NSRect frame = NSMakeRect(0, 0, 16, 16); iconView = [ThrobberView toastThrobberViewWithFrame:frame beforeImage:oldImage @@ -1315,6 +1317,7 @@ private: DCHECK([tabController isKindOfClass:[TabController class]]); [tabController setMini:tabStripModel_->IsMiniTab(modelIndex)]; [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; + [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; [self updateFavIconForContents:contents atIndex:modelIndex]; // If the tab is being restored and it's pinned, the mini state is set after // the tab has already been rendered, so re-layout the tabstrip. In all other |