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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_TABS_TAB_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_TABS_TAB_CONTROLLER_H_
8 #import <Cocoa/Cocoa.h>
9 #include "base/memory/scoped_ptr.h"
10 #import "chrome/browser/ui/cocoa/hover_close_button.h"
11 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h"
12 #include "chrome/browser/ui/tabs/tab_menu_model.h"
13 #include "chrome/browser/ui/tabs/tab_utils.h"
16 // The loading/waiting state of the tab.
17 enum TabLoadingState
{
24 @
class MediaIndicatorButton
;
25 @
class MenuController
;
26 namespace TabControllerInternal
{
31 @protocol TabControllerTarget
;
33 // A class that manages a single tab in the tab strip. Set its target/action
34 // to be sent a message when the tab is selected by the user clicking. Setting
35 // the |loading| property to YES visually indicates that this tab is currently
36 // loading content via a spinner.
38 // The tab has the notion of an "icon view" which can be used to display
39 // identifying characteristics such as a favicon, or since it's a full-fledged
40 // view, something with state and animation such as a throbber for illustrating
41 // progress. The default in the nib is an image view so nothing special is
42 // required if that's all you need.
44 @interface TabController
: NSViewController
<TabDraggingEventTarget
> {
46 base::scoped_nsobject
<SpriteView
> iconView_
;
47 base::scoped_nsobject
<MediaIndicatorButton
> mediaIndicatorButton_
;
48 base::scoped_nsobject
<HoverCloseButton
> closeButton_
;
50 NSRect originalIconFrame_
; // frame of iconView_ as loaded from nib
51 BOOL isIconShowing_
; // last state of iconView_ in updateVisibility
57 TabLoadingState loadingState_
;
58 id
<TabControllerTarget
> target_
; // weak, where actions are sent
59 SEL action_
; // selector sent when tab is selected by clicking
60 scoped_ptr
<ui::SimpleMenuModel
> contextMenuModel_
;
61 scoped_ptr
<TabControllerInternal::MenuDelegate
> contextMenuDelegate_
;
62 base::scoped_nsobject
<MenuController
> contextMenuController_
;
65 @
property(assign
, nonatomic
) TabLoadingState loadingState
;
67 @
property(assign
, nonatomic
) SEL action
;
68 @
property(assign
, nonatomic
) BOOL pinned
;
69 @
property(assign
, nonatomic
) NSString
* toolTip
;
70 // Note that |-selected| will return YES if the controller is |-active|, too.
71 // |-setSelected:| affects the selection, while |-setActive:| affects the key
72 // status/focus of the content.
73 @
property(assign
, nonatomic
) BOOL active
;
74 @
property(assign
, nonatomic
) BOOL selected
;
75 @
property(assign
, nonatomic
) id target
;
76 @
property(assign
, nonatomic
) GURL url
;
77 @
property(readonly
, nonatomic
) NSView
* iconView
;
78 @
property(readonly
, nonatomic
) MediaIndicatorButton
* mediaIndicatorButton
;
79 @
property(readonly
, nonatomic
) HoverCloseButton
* closeButton
;
81 // Default height for tabs.
82 + (CGFloat
)defaultTabHeight
;
84 // Minimum and maximum allowable tab width. The minimum width does not show
85 // the icon or the close button. The active tab always has at least a close
86 // button so it has a different minimum width.
87 + (CGFloat
)minTabWidth
;
88 + (CGFloat
)maxTabWidth
;
89 + (CGFloat
)minActiveTabWidth
;
90 + (CGFloat
)pinnedTabWidth
;
92 // The view associated with this controller, pre-casted as a TabView
95 // Sets the tab's icon image.
96 // |image| must be 16x16 in size.
97 // |image| can be a horizontal strip of image sprites which will be animated.
98 // Setting |animate| to YES will animate away the old image before animating
99 // the new image back to position.
100 - (void)setIconImage
:(NSImage
*)image
;
101 - (void)setIconImage
:(NSImage
*)image withToastAnimation
:(BOOL
)animate
;
103 // Sets the current tab media state and updates the views.
104 - (void)setMediaState
:(TabMediaState
)mediaState
;
106 // Closes the associated TabView by relaying the message to |target_| to
107 // perform the close.
108 - (void)closeTab
:(id
)sender
;
110 // Selects the associated TabView by sending |action_| to |target_|.
111 - (void)selectTab
:(id
)sender
;
113 // Called by the tabs to determine whether we are in rapid (tab) closure mode.
114 // In this mode, we handle clicks slightly differently due to animation.
115 // Ideally, tabs would know about their own animation and wouldn't need this.
116 - (BOOL
)inRapidClosureMode
;
118 // Updates the visibility of certain subviews, such as the icon and close
119 // button, based on criteria such as the tab's selected state and its current
121 - (void)updateVisibility
;
123 // Update the title color to match the tabs current state.
124 - (void)updateTitleColor
;
127 @interface
TabController(TestingAPI
)
129 - (BOOL
)shouldShowIcon
;
130 - (BOOL
)shouldShowMediaIndicator
;
131 - (BOOL
)shouldShowCloseButton
;
132 @end
// TabController(TestingAPI)
134 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_CONTROLLER_H_