tab_controller.h revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_COCOA_TABS_TAB_CONTROLLER_H_ 6#define CHROME_BROWSER_UI_COCOA_TABS_TAB_CONTROLLER_H_ 7#pragma once 8 9#import <Cocoa/Cocoa.h> 10#import "chrome/browser/ui/cocoa/hover_close_button.h" 11#include "chrome/browser/ui/tabs/tab_menu_model.h" 12 13// The loading/waiting state of the tab. 14enum TabLoadingState { 15 kTabDone, 16 kTabLoading, 17 kTabWaiting, 18 kTabCrashed, 19}; 20 21@class MenuController; 22namespace TabControllerInternal { 23class MenuDelegate; 24} 25@class TabView; 26@protocol TabControllerTarget; 27 28// A class that manages a single tab in the tab strip. Set its target/action 29// to be sent a message when the tab is selected by the user clicking. Setting 30// the |loading| property to YES visually indicates that this tab is currently 31// loading content via a spinner. 32// 33// The tab has the notion of an "icon view" which can be used to display 34// identifying characteristics such as a favicon, or since it's a full-fledged 35// view, something with state and animation such as a throbber for illustrating 36// progress. The default in the nib is an image view so nothing special is 37// required if that's all you need. 38 39@interface TabController : NSViewController { 40 @private 41 IBOutlet NSView* iconView_; 42 IBOutlet NSTextField* titleView_; 43 IBOutlet HoverCloseButton* closeButton_; 44 45 NSRect originalIconFrame_; // frame of iconView_ as loaded from nib 46 BOOL isIconShowing_; // last state of iconView_ in updateVisibility 47 48 BOOL app_; 49 BOOL mini_; 50 BOOL pinned_; 51 BOOL selected_; 52 TabLoadingState loadingState_; 53 CGFloat iconTitleXOffset_; // between left edges of icon and title 54 id<TabControllerTarget> target_; // weak, where actions are sent 55 SEL action_; // selector sent when tab is selected by clicking 56 scoped_ptr<TabMenuModel> contextMenuModel_; 57 scoped_ptr<TabControllerInternal::MenuDelegate> contextMenuDelegate_; 58 scoped_nsobject<MenuController> contextMenuController_; 59} 60 61@property(assign, nonatomic) TabLoadingState loadingState; 62 63@property(assign, nonatomic) SEL action; 64@property(assign, nonatomic) BOOL app; 65@property(assign, nonatomic) BOOL mini; 66@property(assign, nonatomic) BOOL pinned; 67@property(assign, nonatomic) BOOL selected; 68@property(assign, nonatomic) id target; 69@property(assign, nonatomic) NSView* iconView; 70@property(assign, nonatomic) NSTextField* titleView; 71@property(assign, nonatomic) HoverCloseButton* closeButton; 72 73// Minimum and maximum allowable tab width. The minimum width does not show 74// the icon or the close button. The selected tab always has at least a close 75// button so it has a different minimum width. 76+ (CGFloat)minTabWidth; 77+ (CGFloat)maxTabWidth; 78+ (CGFloat)minSelectedTabWidth; 79+ (CGFloat)miniTabWidth; 80+ (CGFloat)appTabWidth; 81 82// The view associated with this controller, pre-casted as a TabView 83- (TabView*)tabView; 84 85// Closes the associated TabView by relaying the message to |target_| to 86// perform the close. 87- (IBAction)closeTab:(id)sender; 88 89// Replace the current icon view with the given view. |iconView| will be 90// resized to the size of the current icon view. 91- (void)setIconView:(NSView*)iconView; 92- (NSView*)iconView; 93 94// Called by the tabs to determine whether we are in rapid (tab) closure mode. 95// In this mode, we handle clicks slightly differently due to animation. 96// Ideally, tabs would know about their own animation and wouldn't need this. 97- (BOOL)inRapidClosureMode; 98 99// Updates the visibility of certain subviews, such as the icon and close 100// button, based on criteria such as the tab's selected state and its current 101// width. 102- (void)updateVisibility; 103 104// Update the title color to match the tabs current state. 105- (void)updateTitleColor; 106@end 107 108@interface TabController(TestingAPI) 109- (NSString*)toolTip; 110- (int)iconCapacity; 111- (BOOL)shouldShowIcon; 112- (BOOL)shouldShowCloseButton; 113@end // TabController(TestingAPI) 114 115#endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_CONTROLLER_H_ 116