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