[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / tabs / tab_controller.h
blob7c24a27dc881d108544c42f06937cc0bc0b42441
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 "url/gurl.h"
15 // The loading/waiting state of the tab.
16 enum TabLoadingState {
17 kTabDone,
18 kTabLoading,
19 kTabWaiting,
20 kTabCrashed,
23 @class MediaIndicatorView;
24 @class MenuController;
25 namespace TabControllerInternal {
26 class MenuDelegate;
28 @class SpriteView;
29 @class TabView;
30 @protocol TabControllerTarget;
32 // A class that manages a single tab in the tab strip. Set its target/action
33 // to be sent a message when the tab is selected by the user clicking. Setting
34 // the |loading| property to YES visually indicates that this tab is currently
35 // loading content via a spinner.
37 // The tab has the notion of an "icon view" which can be used to display
38 // identifying characteristics such as a favicon, or since it's a full-fledged
39 // view, something with state and animation such as a throbber for illustrating
40 // progress. The default in the nib is an image view so nothing special is
41 // required if that's all you need.
43 @interface TabController : NSViewController<TabDraggingEventTarget> {
44 @private
45 base::scoped_nsobject<SpriteView> iconView_;
46 base::scoped_nsobject<MediaIndicatorView> mediaIndicatorView_;
47 base::scoped_nsobject<HoverCloseButton> closeButton_;
49 NSRect originalIconFrame_; // frame of iconView_ as loaded from nib
50 BOOL isIconShowing_; // last state of iconView_ in updateVisibility
52 BOOL app_;
53 BOOL mini_;
54 BOOL pinned_;
55 BOOL active_;
56 BOOL selected_;
57 GURL url_;
58 TabLoadingState loadingState_;
59 id<TabControllerTarget> target_; // weak, where actions are sent
60 SEL action_; // selector sent when tab is selected by clicking
61 scoped_ptr<ui::SimpleMenuModel> contextMenuModel_;
62 scoped_ptr<TabControllerInternal::MenuDelegate> contextMenuDelegate_;
63 base::scoped_nsobject<MenuController> contextMenuController_;
66 @property(assign, nonatomic) TabLoadingState loadingState;
68 @property(assign, nonatomic) SEL action;
69 @property(assign, nonatomic) BOOL app;
70 @property(assign, nonatomic) BOOL mini;
71 @property(assign, nonatomic) BOOL pinned;
72 @property(assign, nonatomic) NSString* toolTip;
73 // Note that |-selected| will return YES if the controller is |-active|, too.
74 // |-setSelected:| affects the selection, while |-setActive:| affects the key
75 // status/focus of the content.
76 @property(assign, nonatomic) BOOL active;
77 @property(assign, nonatomic) BOOL selected;
78 @property(assign, nonatomic) id target;
79 @property(assign, nonatomic) GURL url;
80 @property(readonly, nonatomic) NSView* iconView;
81 @property(assign, nonatomic) MediaIndicatorView* mediaIndicatorView;
82 @property(readonly, nonatomic) HoverCloseButton* closeButton;
84 // Minimum and maximum allowable tab width. The minimum width does not show
85 // the icon or the close button. The selected tab always has at least a close
86 // button so it has a different minimum width.
87 + (CGFloat)minTabWidth;
88 + (CGFloat)maxTabWidth;
89 + (CGFloat)minSelectedTabWidth;
90 + (CGFloat)miniTabWidth;
91 + (CGFloat)appTabWidth;
93 // The view associated with this controller, pre-casted as a TabView
94 - (TabView*)tabView;
96 // Sets the tab's icon image.
97 // |image| must be 16x16 in size.
98 // |image| can be a horizontal strip of image sprites which will be animated.
99 // Setting |animate| to YES will animate away the old image before animating
100 // the new image back to position.
101 - (void)setIconImage:(NSImage*)image;
102 - (void)setIconImage:(NSImage*)image withToastAnimation:(BOOL)animate;
104 // Closes the associated TabView by relaying the message to |target_| to
105 // perform the close.
106 - (void)closeTab:(id)sender;
108 // Selects the associated TabView by sending |action_| to |target_|.
109 - (void)selectTab:(id)sender;
111 // Called by the tabs to determine whether we are in rapid (tab) closure mode.
112 // In this mode, we handle clicks slightly differently due to animation.
113 // Ideally, tabs would know about their own animation and wouldn't need this.
114 - (BOOL)inRapidClosureMode;
116 // Updates the visibility of certain subviews, such as the icon and close
117 // button, based on criteria such as the tab's selected state and its current
118 // width.
119 - (void)updateVisibility;
121 // Update the title color to match the tabs current state.
122 - (void)updateTitleColor;
123 @end
125 @interface TabController(TestingAPI)
126 - (int)iconCapacity;
127 - (BOOL)shouldShowIcon;
128 - (BOOL)shouldShowMediaIndicator;
129 - (BOOL)shouldShowCloseButton;
130 @end // TabController(TestingAPI)
132 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_CONTROLLER_H_