| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #import "chrome/browser/ui/cocoa/profile_menu_button.h" | 5 #import "chrome/browser/ui/cocoa/profile_menu_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/ui/profile_menu_model.h" |
| 10 #import "third_party/GTM/AppKit/GTMFadeTruncatingTextFieldCell.h" | 11 #import "third_party/GTM/AppKit/GTMFadeTruncatingTextFieldCell.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 const CGFloat kTabWidth = 24; | 15 const CGFloat kTabWidth = 24; |
| 15 const CGFloat kTabHeight = 13; | 16 const CGFloat kTabHeight = 13; |
| 16 const CGFloat kTabArrowWidth = 7; | 17 const CGFloat kTabArrowWidth = 7; |
| 17 const CGFloat kTabArrowHeight = 4; | 18 const CGFloat kTabArrowHeight = 4; |
| 18 const CGFloat kTabRoundRectRadius = 5; | 19 const CGFloat kTabRoundRectRadius = 5; |
| 19 const CGFloat kTabDisplayNameMarginY = 3; | 20 const CGFloat kTabDisplayNameMarginY = 3; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 45 | 46 |
| 46 @synthesize shouldShowProfileDisplayName = shouldShowProfileDisplayName_; | 47 @synthesize shouldShowProfileDisplayName = shouldShowProfileDisplayName_; |
| 47 | 48 |
| 48 - (void)commonInit { | 49 - (void)commonInit { |
| 49 textFieldCell_.reset( | 50 textFieldCell_.reset( |
| 50 [[GTMFadeTruncatingTextFieldCell alloc] initTextCell:@""]); | 51 [[GTMFadeTruncatingTextFieldCell alloc] initTextCell:@""]); |
| 51 [textFieldCell_ setBackgroundStyle:NSBackgroundStyleRaised]; | 52 [textFieldCell_ setBackgroundStyle:NSBackgroundStyleRaised]; |
| 52 [textFieldCell_ setAlignment:NSRightTextAlignment]; | 53 [textFieldCell_ setAlignment:NSRightTextAlignment]; |
| 53 [textFieldCell_ setFont:[NSFont systemFontOfSize: | 54 [textFieldCell_ setFont:[NSFont systemFontOfSize: |
| 54 [NSFont smallSystemFontSize]]]; | 55 [NSFont smallSystemFontSize]]]; |
| 56 |
| 57 profile_menu_model_.reset(new ProfileMenuModel); |
| 58 menu_.reset([[MenuController alloc] initWithModel:profile_menu_model_.get() |
| 59 useWithPopUpButtonCell:NO]); |
| 55 } | 60 } |
| 56 | 61 |
| 57 - (id)initWithFrame:(NSRect)frame | 62 - (id)initWithFrame:(NSRect)frame |
| 58 pullsDown:(BOOL)flag { | 63 pullsDown:(BOOL)flag { |
| 59 if ((self = [super initWithFrame:frame pullsDown:flag])) | 64 if ((self = [super initWithFrame:frame pullsDown:flag])) |
| 60 [self commonInit]; | 65 [self commonInit]; |
| 61 return self; | 66 return self; |
| 62 } | 67 } |
| 63 | 68 |
| 64 - (id)initWithCoder:(NSCoder*)decoder { | 69 - (id)initWithCoder:(NSCoder*)decoder { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 324 |
| 320 if (shouldShowProfileDisplayName_) { | 325 if (shouldShowProfileDisplayName_) { |
| 321 NSColor* textColor = [[self window] isMainWindow] ? | 326 NSColor* textColor = [[self window] isMainWindow] ? |
| 322 GetBlackWithAlpha(0.6) : GetBlackWithAlpha(0.4); | 327 GetBlackWithAlpha(0.6) : GetBlackWithAlpha(0.4); |
| 323 if (![[textFieldCell_ textColor] isEqual:textColor]) | 328 if (![[textFieldCell_ textColor] isEqual:textColor]) |
| 324 [textFieldCell_ setTextColor:textColor]; | 329 [textFieldCell_ setTextColor:textColor]; |
| 325 [textFieldCell_ drawWithFrame:[self textFieldRect] inView:self]; | 330 [textFieldCell_ drawWithFrame:[self textFieldRect] inView:self]; |
| 326 } | 331 } |
| 327 } | 332 } |
| 328 | 333 |
| 334 - (NSMenu *)menu { |
| 335 return [menu_.get() menu]; |
| 336 } |
| 337 |
| 329 - (NSPoint)popUpMenuPosition { | 338 - (NSPoint)popUpMenuPosition { |
| 330 NSPoint menuPos = [self tabRect].origin; | 339 NSPoint menuPos = [self tabRect].origin; |
| 331 // By default popUpContextMenu: causes the menu to show up a few pixels above | 340 // By default popUpContextMenu: causes the menu to show up a few pixels above |
| 332 // the point you give it. We need to shift it down a bit so that it lines up | 341 // the point you give it. We need to shift it down a bit so that it lines up |
| 333 // with the bottom of the tab. | 342 // with the bottom of the tab. |
| 334 menuPos.y -= 6; | 343 menuPos.y -= 6; |
| 335 return [self convertPoint:menuPos toView:nil]; | 344 return [self convertPoint:menuPos toView:nil]; |
| 336 } | 345 } |
| 337 | 346 |
| 338 - (void) mouseDown:(NSEvent*)event | 347 - (void) mouseDown:(NSEvent*)event |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 size.width = ceil(size.width); | 395 size.width = ceil(size.width); |
| 387 size.height = ceil(size.height); | 396 size.height = ceil(size.height); |
| 388 return size; | 397 return size; |
| 389 } | 398 } |
| 390 | 399 |
| 391 - (NSSize)minControlSize { | 400 - (NSSize)minControlSize { |
| 392 return [self tabRect].size; | 401 return [self tabRect].size; |
| 393 } | 402 } |
| 394 | 403 |
| 395 @end | 404 @end |
| OLD | NEW |