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_VIEW_H_ 6 #define CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_ 7 8 #include <ApplicationServices/ApplicationServices.h> 9 #import <Cocoa/Cocoa.h> 10 11 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_nsobject.h" 13 #import "chrome/browser/ui/cocoa/hover_close_button.h" 14 15 namespace tabs { 16 17 // Nomenclature: 18 // Tabs _glow_ under two different circumstances, when they are _hovered_ (by 19 // the mouse) and when they are _alerted_ (to show that the tab's title has 20 // changed). 21 22 // The state of alerting (to show a title change on an unselected, pinned tab). 23 // This is more complicated than a simple on/off since we want to allow the 24 // alert glow to go through a full rise-hold-fall cycle to avoid flickering (or 25 // always holding). 26 enum AlertState { 27 kAlertNone = 0, // Obj-C initializes to this. 28 kAlertRising, 29 kAlertHolding, 30 kAlertFalling 31 }; 32 33 // When the window doesn't have focus then we want to draw the button with a 34 // slightly lighter color. We do this by just reducing the alpha. 35 const CGFloat kImageNoFocusAlpha = 0.65; 36 37 } // namespace tabs 38 39 @class TabController, TabWindowController, GTMFadeTruncatingTextFieldCell; 40 41 // A view that handles the event tracking (clicking and dragging) for a tab 42 // on the tab strip. Relies on an associated TabController to provide a 43 // target/action for selecting the tab. 44 45 @interface TabView : NSView { 46 @private 47 TabController* controller_; 48 base::scoped_nsobject<NSTextField> titleView_; 49 GTMFadeTruncatingTextFieldCell* titleViewCell_; // weak 50 51 // TODO(rohitrao): Add this button to a CoreAnimation layer so we can fade it 52 // in and out on mouseovers. 53 HoverCloseButton* closeButton_; // Weak. 54 55 BOOL closing_; 56 57 BOOL isMouseInside_; // Is the mouse hovering over? 58 tabs::AlertState alertState_; 59 60 CGFloat hoverAlpha_; // How strong the hover glow is. 61 NSTimeInterval hoverHoldEndTime_; // When the hover glow will begin dimming. 62 63 CGFloat alertAlpha_; // How strong the alert glow is. 64 NSTimeInterval alertHoldEndTime_; // When the hover glow will begin dimming. 65 66 NSTimeInterval lastGlowUpdate_; // Time either glow was last updated. 67 68 NSPoint hoverPoint_; // Current location of hover in view coords. 69 70 // The location of the current mouseDown event in window coordinates. 71 NSPoint mouseDownPoint_; 72 73 NSCellStateValue state_; 74 75 // The tool tip text for this tab view. 76 base::scoped_nsobject<NSString> toolTipText_; 77 78 // A one-element mask image cache. This cache makes drawing roughly 16% 79 // faster. 80 base::ScopedCFTypeRef<CGImageRef> maskCache_; 81 CGFloat maskCacheWidth_; 82 CGFloat maskCacheScale_; 83 } 84 85 @property(retain, nonatomic) NSString* title; 86 @property(assign, nonatomic) NSRect titleFrame; 87 @property(retain, nonatomic) NSColor* titleColor; 88 @property(assign, nonatomic) BOOL titleHidden; 89 90 // The state affects how the tab will be drawn. 91 // NSOnState -> active 92 // NSMixedState -> selected 93 // NSOffState -> none 94 @property(assign, nonatomic) NSCellStateValue state; 95 96 @property(assign, nonatomic) CGFloat hoverAlpha; 97 @property(assign, nonatomic) CGFloat alertAlpha; 98 99 // Determines if the tab is in the process of animating closed. It may still 100 // be visible on-screen, but should not respond to/initiate any events. Upon 101 // setting to NO, clears the target/action of the close button to prevent 102 // clicks inside it from sending messages. 103 @property(assign, nonatomic, getter=isClosing) BOOL closing; 104 105 // Designated initializer. 106 - (id)initWithFrame:(NSRect)frame 107 controller:(TabController*)controller 108 closeButton:(HoverCloseButton*)closeButton; 109 110 // Returns the inset multiplier used to compute the inset of the top of the tab. 111 + (CGFloat)insetMultiplier; 112 113 // Enables/Disables tracking regions for the tab. 114 - (void)setTrackingEnabled:(BOOL)enabled; 115 116 // Begin showing an "alert" glow (shown to call attention to an unselected 117 // pinned tab whose title changed). 118 - (void)startAlert; 119 120 // Stop showing the "alert" glow; this won't immediately wipe out any glow, but 121 // will make it fade away. 122 - (void)cancelAlert; 123 124 // Returns the tool tip text for this tab view. 125 - (NSString*)toolTipText; 126 127 @end 128 129 // The TabController |controller_| is not the only owner of this view. If the 130 // controller is released before this view, then we could be hanging onto a 131 // garbage pointer. To prevent this, the TabController uses this interface to 132 // clear the |controller_| pointer when it is dying. 133 @interface TabView (TabControllerInterface) 134 - (void)setController:(TabController*)controller; 135 @end 136 137 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_ 138