| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/mac_util.h" | 5 #include "base/mac_util.h" |
| 6 #include "chrome/browser/cocoa/nsimage_cache.h" | 6 #include "chrome/browser/cocoa/nsimage_cache.h" |
| 7 #import "chrome/browser/cocoa/tab_controller.h" | 7 #import "chrome/browser/cocoa/tab_controller.h" |
| 8 #import "chrome/browser/cocoa/tab_controller_target.h" | 8 #import "chrome/browser/cocoa/tab_controller_target.h" |
| 9 #import "chrome/browser/cocoa/tab_view.h" | 9 #import "chrome/browser/cocoa/tab_view.h" |
| 10 #import "third_party/GTM/AppKit/GTMTheme.h" | |
| 11 | 10 |
| 12 @interface TabController(Private) | 11 @interface TabController(Private) |
| 13 - (void)updateVisibility; | 12 - (void)updateVisibility; |
| 14 @end | 13 @end |
| 15 | 14 |
| 16 @implementation TabController | 15 @implementation TabController |
| 17 | 16 |
| 18 @synthesize loadingState = loadingState_; | 17 @synthesize loadingState = loadingState_; |
| 19 @synthesize target = target_; | 18 @synthesize target = target_; |
| 20 @synthesize action = action_; | 19 @synthesize action = action_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 [super dealloc]; | 46 [super dealloc]; |
| 48 } | 47 } |
| 49 | 48 |
| 50 // The internals of |-setSelected:| but doesn't check if we're already set | 49 // The internals of |-setSelected:| but doesn't check if we're already set |
| 51 // to |selected|. Pass the selection change to the subviews that need it and | 50 // to |selected|. Pass the selection change to the subviews that need it and |
| 52 // mark ourselves as needing a redraw. | 51 // mark ourselves as needing a redraw. |
| 53 - (void)internalSetSelected:(BOOL)selected { | 52 - (void)internalSetSelected:(BOOL)selected { |
| 54 selected_ = selected; | 53 selected_ = selected; |
| 55 [(TabView *)[self view] setState:selected]; | 54 [(TabView *)[self view] setState:selected]; |
| 56 [self updateVisibility]; | 55 [self updateVisibility]; |
| 57 [self applyTheme]; | 56 [[self view] setNeedsDisplay:YES]; |
| 58 } | 57 } |
| 59 | 58 |
| 60 // Called when the tab's nib is done loading and all outlets are hooked up. | 59 // Called when the tab's nib is done loading and all outlets are hooked up. |
| 61 - (void)awakeFromNib { | 60 - (void)awakeFromNib { |
| 62 // Ensure we don't show favicon if the tab is already too small to begin with. | 61 // Ensure we don't show favicon if the tab is already too small to begin with. |
| 63 [self updateVisibility]; | 62 [self updateVisibility]; |
| 64 [(id)iconView_ setImage:nsimage_cache::ImageNamed(@"nav.pdf")]; | 63 [(id)iconView_ setImage:nsimage_cache::ImageNamed(@"nav.pdf")]; |
| 64 [[self view] addSubview:backgroundButton_ |
| 65 positioned:NSWindowBelow |
| 66 relativeTo:nil]; |
| 65 [self internalSetSelected:selected_]; | 67 [self internalSetSelected:selected_]; |
| 66 } | 68 } |
| 67 | 69 |
| 68 - (IBAction)closeTab:(id)sender { | 70 - (IBAction)closeTab:(id)sender { |
| 69 if ([[self target] respondsToSelector:@selector(closeTab:)]) { | 71 if ([[self target] respondsToSelector:@selector(closeTab:)]) { |
| 70 [[self target] performSelector:@selector(closeTab:) | 72 [[self target] performSelector:@selector(closeTab:) |
| 71 withObject:[self view]]; | 73 withObject:[self view]]; |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 | 76 |
| 75 // Dispatches the command in the tag to the registered target object. | 77 // Dispatches the command in the tag to the registered target object. |
| 76 - (IBAction)commandDispatch:(id)sender { | 78 - (IBAction)commandDispatch:(id)sender { |
| 77 TabStripModel::ContextMenuCommand command = | 79 TabStripModel::ContextMenuCommand command = |
| 78 static_cast<TabStripModel::ContextMenuCommand>([sender tag]); | 80 static_cast<TabStripModel::ContextMenuCommand>([sender tag]); |
| 79 [[self target] commandDispatch:command forController:self]; | 81 [[self target] commandDispatch:command forController:self]; |
| 80 } | 82 } |
| 81 | 83 |
| 82 // Called for each menu item on its target, which would be this controller. | 84 // Called for each menu item on its target, which would be this controller. |
| 83 // Returns YES if the menu item should be enabled. We ask the tab's | 85 // Returns YES if the menu item should be enabled. We ask the tab's |
| 84 // target for the proper answer. | 86 // target for the proper answer. |
| 85 - (BOOL)validateMenuItem:(NSMenuItem*)item { | 87 - (BOOL)validateMenuItem:(NSMenuItem*)item { |
| 86 TabStripModel::ContextMenuCommand command = | 88 TabStripModel::ContextMenuCommand command = |
| 87 static_cast<TabStripModel::ContextMenuCommand>([item tag]); | 89 static_cast<TabStripModel::ContextMenuCommand>([item tag]); |
| 88 return [[self target] isCommandEnabled:command forController:self]; | 90 return [[self target] isCommandEnabled:command forController:self]; |
| 89 } | 91 } |
| 90 | 92 |
| 91 - (void)setTitle:(NSString *)title { | 93 - (void)setTitle:(NSString *)title { |
| 92 [[self view] setToolTip:title]; | 94 [backgroundButton_ setToolTip:title]; |
| 93 [super setTitle:title]; | 95 [super setTitle:title]; |
| 94 } | 96 } |
| 95 | 97 |
| 96 - (void)setSelected:(BOOL)selected { | 98 - (void)setSelected:(BOOL)selected { |
| 97 if (selected_ != selected) | 99 if (selected_ != selected) |
| 98 [self internalSetSelected:selected]; | 100 [self internalSetSelected:selected]; |
| 99 } | 101 } |
| 100 | 102 |
| 101 - (BOOL)selected { | 103 - (BOOL)selected { |
| 102 return selected_; | 104 return selected_; |
| 103 } | 105 } |
| 104 | 106 |
| 105 - (void)setIconView:(NSView*)iconView { | 107 - (void)setIconView:(NSView*)iconView { |
| 106 NSRect currentFrame = [iconView_ frame]; | 108 NSRect currentFrame = [iconView_ frame]; |
| 107 [iconView_ removeFromSuperview]; | 109 [iconView_ removeFromSuperview]; |
| 108 iconView_ = iconView; | 110 iconView_ = iconView; |
| 109 [iconView_ setFrame:currentFrame]; | 111 [iconView_ setFrame:currentFrame]; |
| 110 // Ensure we don't show favicon if the tab is already too small to begin with. | 112 // Ensure we don't show favicon if the tab is already too small to begin with. |
| 111 [self updateVisibility]; | 113 [self updateVisibility]; |
| 112 [[self view] addSubview:iconView_]; | 114 [[self view] addSubview:iconView_]; |
| 113 } | 115 } |
| 114 | 116 |
| 115 - (NSView*)iconView { | 117 - (NSView*)iconView { |
| 116 return iconView_; | 118 return iconView_; |
| 117 } | 119 } |
| 118 | 120 |
| 119 - (NSString *)toolTip { | 121 - (NSString *)toolTip { |
| 120 return [[self view] toolTip]; | 122 return [backgroundButton_ toolTip]; |
| 121 } | 123 } |
| 122 | 124 |
| 123 // Return a rough approximation of the number of icons we could fit in the | 125 // Return a rough approximation of the number of icons we could fit in the |
| 124 // tab. We never actually do this, but it's a helpful guide for determining | 126 // tab. We never actually do this, but it's a helpful guide for determining |
| 125 // how much space we have available. | 127 // how much space we have available. |
| 126 - (int)iconCapacity { | 128 - (int)iconCapacity { |
| 127 float width = NSWidth([[self view] frame]); | 129 float width = NSWidth([[self view] frame]); |
| 128 float leftPadding = NSMinX([iconView_ frame]); | 130 float leftPadding = NSMinX([iconView_ frame]); |
| 129 float rightPadding = width - NSMaxX([closeButton_ frame]); | 131 float rightPadding = width - NSMaxX([closeButton_ frame]); |
| 130 float iconWidth = NSWidth([iconView_ frame]); | 132 float iconWidth = NSWidth([iconView_ frame]); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 159 } | 161 } |
| 160 | 162 |
| 161 // Called when our view is resized. If it gets too small, start by hiding | 163 // Called when our view is resized. If it gets too small, start by hiding |
| 162 // the close box and only show it if tab is selected. Eventually, hide the | 164 // the close box and only show it if tab is selected. Eventually, hide the |
| 163 // icon as well. We know that this is for our view because we only registered | 165 // icon as well. We know that this is for our view because we only registered |
| 164 // for notifications from our specific view. | 166 // for notifications from our specific view. |
| 165 - (void)viewResized:(NSNotification*)info { | 167 - (void)viewResized:(NSNotification*)info { |
| 166 [self updateVisibility]; | 168 [self updateVisibility]; |
| 167 } | 169 } |
| 168 | 170 |
| 169 - (void)applyTheme { | |
| 170 GTMTheme* theme = [[self view] gtm_theme]; | |
| 171 NSColor* color = nil; | |
| 172 if (!selected_) { | |
| 173 color = [theme textColorForStyle:GTMThemeStyleTabBarDeselected | |
| 174 state:GTMThemeStateActiveWindow]; | |
| 175 } | |
| 176 // Default to the selected text color unless told otherwise. | |
| 177 if (!color) { | |
| 178 color = [theme textColorForStyle:GTMThemeStyleToolBar | |
| 179 state:GTMThemeStateActiveWindow]; | |
| 180 } | |
| 181 | |
| 182 [titleView_ setTextColor:color ? color : [NSColor textColor]]; | |
| 183 [[self view] setNeedsDisplay:YES]; | |
| 184 } | |
| 185 @end | 171 @end |
| OLD | NEW |