Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1025)

Side by Side Diff: chrome/browser/cocoa/tab_controller.mm

Issue 165499: Updates to clean up default theme and add hover states (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/tab_controller.h ('k') | chrome/browser/cocoa/tab_strip_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 11
11 @interface TabController(Private) 12 @interface TabController(Private)
12 - (void)updateVisibility; 13 - (void)updateVisibility;
13 @end 14 @end
14 15
15 @implementation TabController 16 @implementation TabController
16 17
17 @synthesize loadingState = loadingState_; 18 @synthesize loadingState = loadingState_;
18 @synthesize target = target_; 19 @synthesize target = target_;
19 @synthesize action = action_; 20 @synthesize action = action_;
(...skipping 26 matching lines...) Expand all
46 [super dealloc]; 47 [super dealloc];
47 } 48 }
48 49
49 // The internals of |-setSelected:| but doesn't check if we're already set 50 // The internals of |-setSelected:| but doesn't check if we're already set
50 // to |selected|. Pass the selection change to the subviews that need it and 51 // to |selected|. Pass the selection change to the subviews that need it and
51 // mark ourselves as needing a redraw. 52 // mark ourselves as needing a redraw.
52 - (void)internalSetSelected:(BOOL)selected { 53 - (void)internalSetSelected:(BOOL)selected {
53 selected_ = selected; 54 selected_ = selected;
54 [(TabView *)[self view] setState:selected]; 55 [(TabView *)[self view] setState:selected];
55 [self updateVisibility]; 56 [self updateVisibility];
56 [[self view] setNeedsDisplay:YES]; 57 [self applyTheme];
57 } 58 }
58 59
59 // Called when the tab's nib is done loading and all outlets are hooked up. 60 // Called when the tab's nib is done loading and all outlets are hooked up.
60 - (void)awakeFromNib { 61 - (void)awakeFromNib {
61 // Ensure we don't show favicon if the tab is already too small to begin with. 62 // Ensure we don't show favicon if the tab is already too small to begin with.
62 [self updateVisibility]; 63 [self updateVisibility];
63 [(id)iconView_ setImage:nsimage_cache::ImageNamed(@"nav.pdf")]; 64 [(id)iconView_ setImage:nsimage_cache::ImageNamed(@"nav.pdf")];
64 [[self view] addSubview:backgroundButton_
65 positioned:NSWindowBelow
66 relativeTo:nil];
67 [self internalSetSelected:selected_]; 65 [self internalSetSelected:selected_];
68 } 66 }
69 67
70 - (IBAction)closeTab:(id)sender { 68 - (IBAction)closeTab:(id)sender {
71 if ([[self target] respondsToSelector:@selector(closeTab:)]) { 69 if ([[self target] respondsToSelector:@selector(closeTab:)]) {
72 [[self target] performSelector:@selector(closeTab:) 70 [[self target] performSelector:@selector(closeTab:)
73 withObject:[self view]]; 71 withObject:[self view]];
74 } 72 }
75 } 73 }
76 74
77 // Dispatches the command in the tag to the registered target object. 75 // Dispatches the command in the tag to the registered target object.
78 - (IBAction)commandDispatch:(id)sender { 76 - (IBAction)commandDispatch:(id)sender {
79 TabStripModel::ContextMenuCommand command = 77 TabStripModel::ContextMenuCommand command =
80 static_cast<TabStripModel::ContextMenuCommand>([sender tag]); 78 static_cast<TabStripModel::ContextMenuCommand>([sender tag]);
81 [[self target] commandDispatch:command forController:self]; 79 [[self target] commandDispatch:command forController:self];
82 } 80 }
83 81
84 // Called for each menu item on its target, which would be this controller. 82 // Called for each menu item on its target, which would be this controller.
85 // Returns YES if the menu item should be enabled. We ask the tab's 83 // Returns YES if the menu item should be enabled. We ask the tab's
86 // target for the proper answer. 84 // target for the proper answer.
87 - (BOOL)validateMenuItem:(NSMenuItem*)item { 85 - (BOOL)validateMenuItem:(NSMenuItem*)item {
88 TabStripModel::ContextMenuCommand command = 86 TabStripModel::ContextMenuCommand command =
89 static_cast<TabStripModel::ContextMenuCommand>([item tag]); 87 static_cast<TabStripModel::ContextMenuCommand>([item tag]);
90 return [[self target] isCommandEnabled:command forController:self]; 88 return [[self target] isCommandEnabled:command forController:self];
91 } 89 }
92 90
93 - (void)setTitle:(NSString *)title { 91 - (void)setTitle:(NSString *)title {
94 [backgroundButton_ setToolTip:title]; 92 [[self view] setToolTip:title];
95 [super setTitle:title]; 93 [super setTitle:title];
96 } 94 }
97 95
98 - (void)setSelected:(BOOL)selected { 96 - (void)setSelected:(BOOL)selected {
99 if (selected_ != selected) 97 if (selected_ != selected)
100 [self internalSetSelected:selected]; 98 [self internalSetSelected:selected];
101 } 99 }
102 100
103 - (BOOL)selected { 101 - (BOOL)selected {
104 return selected_; 102 return selected_;
105 } 103 }
106 104
107 - (void)setIconView:(NSView*)iconView { 105 - (void)setIconView:(NSView*)iconView {
108 NSRect currentFrame = [iconView_ frame]; 106 NSRect currentFrame = [iconView_ frame];
109 [iconView_ removeFromSuperview]; 107 [iconView_ removeFromSuperview];
110 iconView_ = iconView; 108 iconView_ = iconView;
111 [iconView_ setFrame:currentFrame]; 109 [iconView_ setFrame:currentFrame];
112 // Ensure we don't show favicon if the tab is already too small to begin with. 110 // Ensure we don't show favicon if the tab is already too small to begin with.
113 [self updateVisibility]; 111 [self updateVisibility];
114 [[self view] addSubview:iconView_]; 112 [[self view] addSubview:iconView_];
115 } 113 }
116 114
117 - (NSView*)iconView { 115 - (NSView*)iconView {
118 return iconView_; 116 return iconView_;
119 } 117 }
120 118
121 - (NSString *)toolTip { 119 - (NSString *)toolTip {
122 return [backgroundButton_ toolTip]; 120 return [[self view] toolTip];
123 } 121 }
124 122
125 // Return a rough approximation of the number of icons we could fit in the 123 // Return a rough approximation of the number of icons we could fit in the
126 // tab. We never actually do this, but it's a helpful guide for determining 124 // tab. We never actually do this, but it's a helpful guide for determining
127 // how much space we have available. 125 // how much space we have available.
128 - (int)iconCapacity { 126 - (int)iconCapacity {
129 float width = NSWidth([[self view] frame]); 127 float width = NSWidth([[self view] frame]);
130 float leftPadding = NSMinX([iconView_ frame]); 128 float leftPadding = NSMinX([iconView_ frame]);
131 float rightPadding = width - NSMaxX([closeButton_ frame]); 129 float rightPadding = width - NSMaxX([closeButton_ frame]);
132 float iconWidth = NSWidth([iconView_ frame]); 130 float iconWidth = NSWidth([iconView_ frame]);
(...skipping 28 matching lines...) Expand all
161 } 159 }
162 160
163 // Called when our view is resized. If it gets too small, start by hiding 161 // Called when our view is resized. If it gets too small, start by hiding
164 // the close box and only show it if tab is selected. Eventually, hide the 162 // the close box and only show it if tab is selected. Eventually, hide the
165 // icon as well. We know that this is for our view because we only registered 163 // icon as well. We know that this is for our view because we only registered
166 // for notifications from our specific view. 164 // for notifications from our specific view.
167 - (void)viewResized:(NSNotification*)info { 165 - (void)viewResized:(NSNotification*)info {
168 [self updateVisibility]; 166 [self updateVisibility];
169 } 167 }
170 168
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 }
171 @end 185 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/tab_controller.h ('k') | chrome/browser/cocoa/tab_strip_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698