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 "app/l10n_util_mac.h" | 5 #include "app/l10n_util_mac.h" |
6 #include "base/mac_util.h" | 6 #include "base/mac_util.h" |
7 #import "chrome/browser/cocoa/menu_controller.h" | 7 #import "chrome/browser/cocoa/menu_controller.h" |
8 #import "chrome/browser/cocoa/tab_controller.h" | 8 #import "chrome/browser/cocoa/tab_controller.h" |
9 #import "chrome/browser/cocoa/tab_controller_target.h" | 9 #import "chrome/browser/cocoa/tab_controller_target.h" |
10 #import "chrome/browser/cocoa/tab_view.h" | 10 #import "chrome/browser/cocoa/tab_view.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 [tabView setState:selected]; | 109 [tabView setState:selected]; |
110 [tabView cancelAlert]; | 110 [tabView cancelAlert]; |
111 [self updateVisibility]; | 111 [self updateVisibility]; |
112 [self updateTitleColor]; | 112 [self updateTitleColor]; |
113 } | 113 } |
114 | 114 |
115 // Called when the tab's nib is done loading and all outlets are hooked up. | 115 // Called when the tab's nib is done loading and all outlets are hooked up. |
116 - (void)awakeFromNib { | 116 - (void)awakeFromNib { |
117 // Remember the icon's frame, so that if the icon is ever removed, a new | 117 // Remember the icon's frame, so that if the icon is ever removed, a new |
118 // one can later replace it in the proper location. | 118 // one can later replace it in the proper location. |
119 originalIconFrame_ = [iconView_ frame]; | 119 // originalIconFrame_ = [iconView_ frame]; |
120 | 120 |
121 // When the icon is removed, the title expands to the left to fill the space | 121 // When the icon is removed, the title expands to the left to fill the space |
122 // left by the icon. When the close button is removed, the title expands to | 122 // left by the icon. When the close button is removed, the title expands to |
123 // the right to fill its space. These are the amounts to expand and contract | 123 // the right to fill its space. These are the amounts to expand and contract |
124 // titleView_ under those conditions. | 124 // titleView_ under those conditions. |
125 NSRect titleFrame = [titleView_ frame]; | 125 NSRect titleFrame = [titleView_ frame]; |
126 iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_); | 126 // iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_); |
127 titleCloseWidthOffset_ = NSMaxX([closeButton_ frame]) - NSMaxX(titleFrame); | 127 // titleCloseWidthOffset_ = NSMaxX([closeButton_ frame]) - NSMaxX(titleFrame); |
| 128 titleCloseWidthOffset_ = NSMinX(titleFrame) - NSMinX([closeButton_ frame]); |
| 129 iconTitleXOffset_ = NSMaxX([iconView_ frame]) - NSMaxX(titleFrame); |
128 | 130 |
129 [self internalSetSelected:selected_]; | 131 [self internalSetSelected:selected_]; |
130 } | 132 } |
131 | 133 |
132 // Called when Cocoa wants to display the context menu. Lazily instantiate | 134 // Called when Cocoa wants to display the context menu. Lazily instantiate |
133 // the menu based off of the cross-platform model. Re-create the menu and | 135 // the menu based off of the cross-platform model. Re-create the menu and |
134 // model every time to get the correct labels and enabling. | 136 // model every time to get the correct labels and enabling. |
135 - (NSMenu*)menu { | 137 - (NSMenu*)menu { |
136 contextMenuDelegate_.reset( | 138 contextMenuDelegate_.reset( |
137 new TabControllerInternal::MenuDelegate(target_, self)); | 139 new TabControllerInternal::MenuDelegate(target_, self)); |
(...skipping 24 matching lines...) Expand all Loading... |
162 - (void)setSelected:(BOOL)selected { | 164 - (void)setSelected:(BOOL)selected { |
163 if (selected_ != selected) | 165 if (selected_ != selected) |
164 [self internalSetSelected:selected]; | 166 [self internalSetSelected:selected]; |
165 } | 167 } |
166 | 168 |
167 - (BOOL)selected { | 169 - (BOOL)selected { |
168 return selected_; | 170 return selected_; |
169 } | 171 } |
170 | 172 |
171 - (void)setIconView:(NSView*)iconView { | 173 - (void)setIconView:(NSView*)iconView { |
| 174 [iconView setAutoresizingMask:[iconView_ autoresizingMask]]; |
| 175 |
| 176 NSRect originalIconFrame = [iconView_ frame]; |
172 [iconView_ removeFromSuperview]; | 177 [iconView_ removeFromSuperview]; |
173 iconView_ = iconView; | 178 iconView_ = iconView; |
174 [iconView_ setFrame:originalIconFrame_]; | 179 [iconView_ setFrame:originalIconFrame]; |
| 180 |
| 181 NSLog(@"Frame: %@\n", NSStringFromRect(originalIconFrame)); |
175 | 182 |
176 // Ensure that the icon is suppressed if no icon is set or if the tab is too | 183 // Ensure that the icon is suppressed if no icon is set or if the tab is too |
177 // narrow to display one. | 184 // narrow to display one. |
178 [self updateVisibility]; | 185 [self updateVisibility]; |
179 | 186 |
180 if (iconView_) | 187 if (iconView_) |
181 [[self view] addSubview:iconView_]; | 188 [[self view] addSubview:iconView_]; |
182 } | 189 } |
183 | 190 |
184 - (NSView*)iconView { | 191 - (NSView*)iconView { |
185 return iconView_; | 192 return iconView_; |
186 } | 193 } |
187 | 194 |
188 - (NSString*)toolTip { | 195 - (NSString*)toolTip { |
189 return [[self view] toolTip]; | 196 return [[self view] toolTip]; |
190 } | 197 } |
191 | 198 |
192 // Return a rough approximation of the number of icons we could fit in the | 199 // Return a rough approximation of the number of icons we could fit in the |
193 // tab. We never actually do this, but it's a helpful guide for determining | 200 // tab. We never actually do this, but it's a helpful guide for determining |
194 // how much space we have available. | 201 // how much space we have available. |
195 - (int)iconCapacity { | 202 - (int)iconCapacity { |
196 CGFloat width = NSMaxX([closeButton_ frame]) - NSMinX(originalIconFrame_); | 203 // CGFloat width = NSMaxX([closeButton_ frame]) - NSMinX(originalIconFrame_); |
197 CGFloat iconWidth = NSWidth(originalIconFrame_); | 204 CGFloat width = NSMaxX([iconView_ frame]) - NSMinX([closeButton_ frame]); |
| 205 CGFloat iconWidth = NSWidth([iconView_ frame]); |
198 | 206 |
199 return width / iconWidth; | 207 return width / iconWidth; |
200 } | 208 } |
201 | 209 |
202 // Returns YES if we should show the icon. When tabs get too small, we clip | 210 // Returns YES if we should show the icon. When tabs get too small, we clip |
203 // the favicon before the close button for selected tabs, and prefer the | 211 // the favicon before the close button for selected tabs, and prefer the |
204 // favicon for unselected tabs. The icon can also be suppressed more directly | 212 // favicon for unselected tabs. The icon can also be suppressed more directly |
205 // by clearing iconView_. | 213 // by clearing iconView_. |
206 - (BOOL)shouldShowIcon { | 214 - (BOOL)shouldShowIcon { |
207 if (!iconView_) | 215 if (!iconView_) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 BOOL oldShowCloseButton = [closeButton_ isHidden] ? NO : YES; | 248 BOOL oldShowCloseButton = [closeButton_ isHidden] ? NO : YES; |
241 BOOL newShowCloseButton = [self shouldShowCloseButton] ? YES : NO; | 249 BOOL newShowCloseButton = [self shouldShowCloseButton] ? YES : NO; |
242 | 250 |
243 [closeButton_ setHidden:newShowCloseButton ? NO : YES]; | 251 [closeButton_ setHidden:newShowCloseButton ? NO : YES]; |
244 | 252 |
245 // Adjust the title view based on changes to the icon's and close button's | 253 // Adjust the title view based on changes to the icon's and close button's |
246 // visibility. | 254 // visibility. |
247 NSRect titleFrame = [titleView_ frame]; | 255 NSRect titleFrame = [titleView_ frame]; |
248 | 256 |
249 if (oldShowIcon != newShowIcon) { | 257 if (oldShowIcon != newShowIcon) { |
250 // Adjust the left edge of the title view according to the presence or | 258 // Adjust the right edge of the title view according to the presence or |
251 // absence of the icon view. | 259 // absence of the icon view. |
252 | 260 |
253 if (newShowIcon) { | 261 if (newShowIcon) |
254 titleFrame.origin.x += iconTitleXOffset_; | |
255 titleFrame.size.width -= iconTitleXOffset_; | 262 titleFrame.size.width -= iconTitleXOffset_; |
| 263 else |
| 264 titleFrame.size.width += iconTitleXOffset_; |
| 265 } |
| 266 |
| 267 if (oldShowCloseButton != newShowCloseButton) { |
| 268 // Adjust the left edge of the title view according to the presence or |
| 269 // absence of the close button. |
| 270 if (newShowCloseButton) { |
| 271 titleFrame.origin.x += titleCloseWidthOffset_; |
| 272 titleFrame.size.width -= titleCloseWidthOffset_; |
256 } else { | 273 } else { |
257 titleFrame.origin.x -= iconTitleXOffset_; | 274 titleFrame.origin.x -= titleCloseWidthOffset_; |
258 titleFrame.size.width += iconTitleXOffset_; | 275 titleFrame.size.width += titleCloseWidthOffset_; |
259 } | 276 } |
260 } | 277 } |
261 | 278 |
262 if (oldShowCloseButton != newShowCloseButton) { | |
263 // Adjust the right edge of the title view according to the presence or | |
264 // absence of the close button. | |
265 if (newShowCloseButton) | |
266 titleFrame.size.width -= titleCloseWidthOffset_; | |
267 else | |
268 titleFrame.size.width += titleCloseWidthOffset_; | |
269 } | |
270 | |
271 [titleView_ setFrame:titleFrame]; | 279 [titleView_ setFrame:titleFrame]; |
272 } | 280 } |
273 | 281 |
274 - (void)updateTitleColor { | 282 - (void)updateTitleColor { |
275 NSColor* titleColor = nil; | 283 NSColor* titleColor = nil; |
276 GTMTheme* theme = [[self view] gtm_theme]; | 284 GTMTheme* theme = [[self view] gtm_theme]; |
277 if (![self selected]) { | 285 if (![self selected]) { |
278 titleColor = [theme textColorForStyle:GTMThemeStyleTabBarDeselected | 286 titleColor = [theme textColorForStyle:GTMThemeStyleTabBarDeselected |
279 state:GTMThemeStateActiveWindow]; | 287 state:GTMThemeStateActiveWindow]; |
280 } | 288 } |
(...skipping 24 matching lines...) Expand all Loading... |
305 // Called by the tabs to determine whether we are in rapid (tab) closure mode. | 313 // Called by the tabs to determine whether we are in rapid (tab) closure mode. |
306 - (BOOL)inRapidClosureMode { | 314 - (BOOL)inRapidClosureMode { |
307 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) { | 315 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) { |
308 return [[self target] performSelector:@selector(inRapidClosureMode)] ? | 316 return [[self target] performSelector:@selector(inRapidClosureMode)] ? |
309 YES : NO; | 317 YES : NO; |
310 } | 318 } |
311 return NO; | 319 return NO; |
312 } | 320 } |
313 | 321 |
314 @end | 322 @end |
OLD | NEW |