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

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

Issue 503070: P4a.
Patch Set: Created 11 years 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
« no previous file with comments | « chrome/app/nibs/TabView.xib ('k') | no next file » | 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 "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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_ = NSMinX(originalIconFrame_) - NSMinX([closeButton_ fra me]);
128 128
129 [self internalSetSelected:selected_]; 129 [self internalSetSelected:selected_];
130 } 130 }
131 131
132 // Called when Cocoa wants to display the context menu. Lazily instantiate 132 // 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 133 // 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. 134 // model every time to get the correct labels and enabling.
135 - (NSMenu*)menu { 135 - (NSMenu*)menu {
136 contextMenuDelegate_.reset( 136 contextMenuDelegate_.reset(
137 new TabControllerInternal::MenuDelegate(target_, self)); 137 new TabControllerInternal::MenuDelegate(target_, self));
(...skipping 26 matching lines...) Expand all
164 [self internalSetSelected:selected]; 164 [self internalSetSelected:selected];
165 } 165 }
166 166
167 - (BOOL)selected { 167 - (BOOL)selected {
168 return selected_; 168 return selected_;
169 } 169 }
170 170
171 - (void)setIconView:(NSView*)iconView { 171 - (void)setIconView:(NSView*)iconView {
172 [iconView_ removeFromSuperview]; 172 [iconView_ removeFromSuperview];
173 iconView_ = iconView; 173 iconView_ = iconView;
174
175
176 NSLog(@"original frame: %@", NSStringFromRect(originalIconFrame_));
174 [iconView_ setFrame:originalIconFrame_]; 177 [iconView_ setFrame:originalIconFrame_];
175 178
176 // Ensure that the icon is suppressed if no icon is set or if the tab is too 179 // Ensure that the icon is suppressed if no icon is set or if the tab is too
177 // narrow to display one. 180 // narrow to display one.
178 [self updateVisibility]; 181 [self updateVisibility];
179 182
180 if (iconView_) 183 if (iconView_)
181 [[self view] addSubview:iconView_]; 184 [[self view] addSubview:iconView_];
182 } 185 }
183 186
184 - (NSView*)iconView { 187 - (NSView*)iconView {
185 return iconView_; 188 return iconView_;
186 } 189 }
187 190
188 - (NSString*)toolTip { 191 - (NSString*)toolTip {
189 return [[self view] toolTip]; 192 return [[self view] toolTip];
190 } 193 }
191 194
192 // Return a rough approximation of the number of icons we could fit in the 195 // 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 196 // tab. We never actually do this, but it's a helpful guide for determining
194 // how much space we have available. 197 // how much space we have available.
195 - (int)iconCapacity { 198 - (int)iconCapacity {
196 CGFloat width = NSMaxX([closeButton_ frame]) - NSMinX(originalIconFrame_); 199 CGFloat width = NSMaxX([titleView_ frame]) - NSMinX([closeButton_ frame]);
197 CGFloat iconWidth = NSWidth(originalIconFrame_); 200 CGFloat iconWidth = NSWidth(originalIconFrame_);
198 201
199 return width / iconWidth; 202 return width / iconWidth;
200 } 203 }
201 204
202 // Returns YES if we should show the icon. When tabs get too small, we clip 205 // 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 206 // 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 207 // favicon for unselected tabs. The icon can also be suppressed more directly
205 // by clearing iconView_. 208 // by clearing iconView_.
206 - (BOOL)shouldShowIcon { 209 - (BOOL)shouldShowIcon {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 242
240 BOOL oldShowCloseButton = [closeButton_ isHidden] ? NO : YES; 243 BOOL oldShowCloseButton = [closeButton_ isHidden] ? NO : YES;
241 BOOL newShowCloseButton = [self shouldShowCloseButton] ? YES : NO; 244 BOOL newShowCloseButton = [self shouldShowCloseButton] ? YES : NO;
242 245
243 [closeButton_ setHidden:newShowCloseButton ? NO : YES]; 246 [closeButton_ setHidden:newShowCloseButton ? NO : YES];
244 247
245 // Adjust the title view based on changes to the icon's and close button's 248 // Adjust the title view based on changes to the icon's and close button's
246 // visibility. 249 // visibility.
247 NSRect titleFrame = [titleView_ frame]; 250 NSRect titleFrame = [titleView_ frame];
248 251
252 NSLog(@"r: %@", NSStringFromRect(titleFrame));
253
249 if (oldShowIcon != newShowIcon) { 254 if (oldShowIcon != newShowIcon) {
250 // Adjust the left edge of the title view according to the presence or 255 // Adjust the left edge of the title view according to the presence or
251 // absence of the icon view. 256 // absence of the icon view.
252 257
253 if (newShowIcon) { 258 if (newShowIcon) {
254 titleFrame.origin.x += iconTitleXOffset_; 259 titleFrame.origin.x += iconTitleXOffset_;
255 titleFrame.size.width -= iconTitleXOffset_; 260 titleFrame.size.width -= iconTitleXOffset_;
256 } else { 261 } else {
257 titleFrame.origin.x -= iconTitleXOffset_; 262 titleFrame.origin.x -= iconTitleXOffset_;
258 titleFrame.size.width += iconTitleXOffset_; 263 titleFrame.size.width += iconTitleXOffset_;
259 } 264 }
260 } 265 }
261 266
262 if (oldShowCloseButton != newShowCloseButton) { 267 if (oldShowCloseButton != newShowCloseButton) {
263 // Adjust the right edge of the title view according to the presence or 268 // Adjust the left edge of the title view according to the presence or
264 // absence of the close button. 269 // absence of the close button.
265 if (newShowCloseButton) 270 if (newShowCloseButton) {
271 titleFrame.origin.x += titleCloseWidthOffset_;
266 titleFrame.size.width -= titleCloseWidthOffset_; 272 titleFrame.size.width -= titleCloseWidthOffset_;
267 else 273 } else {
274 titleFrame.origin.x -= titleCloseWidthOffset_;
268 titleFrame.size.width += titleCloseWidthOffset_; 275 titleFrame.size.width += titleCloseWidthOffset_;
276 }
277
278 if (newShowCloseButton) {
279 originalIconFrame_.origin.x += titleCloseWidthOffset_;
280 } else {
281 originalIconFrame_.origin.x -= titleCloseWidthOffset_;
282 }
283 [iconView_ setFrame:originalIconFrame_];
269 } 284 }
285 NSLog(@"r: %@", NSStringFromRect(titleFrame));
270 286
271 [titleView_ setFrame:titleFrame]; 287 [titleView_ setFrame:titleFrame];
272 } 288 }
273 289
274 - (void)updateTitleColor { 290 - (void)updateTitleColor {
275 NSColor* titleColor = nil; 291 NSColor* titleColor = nil;
276 GTMTheme* theme = [[self view] gtm_theme]; 292 GTMTheme* theme = [[self view] gtm_theme];
277 if (![self selected]) { 293 if (![self selected]) {
278 titleColor = [theme textColorForStyle:GTMThemeStyleTabBarDeselected 294 titleColor = [theme textColorForStyle:GTMThemeStyleTabBarDeselected
279 state:GTMThemeStateActiveWindow]; 295 state:GTMThemeStateActiveWindow];
(...skipping 25 matching lines...) Expand all
305 // Called by the tabs to determine whether we are in rapid (tab) closure mode. 321 // Called by the tabs to determine whether we are in rapid (tab) closure mode.
306 - (BOOL)inRapidClosureMode { 322 - (BOOL)inRapidClosureMode {
307 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) { 323 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) {
308 return [[self target] performSelector:@selector(inRapidClosureMode)] ? 324 return [[self target] performSelector:@selector(inRapidClosureMode)] ?
309 YES : NO; 325 YES : NO;
310 } 326 }
311 return NO; 327 return NO;
312 } 328 }
313 329
314 @end 330 @end
OLDNEW
« no previous file with comments | « chrome/app/nibs/TabView.xib ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698