Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
| 8 | 8 |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | 51 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" |
| 52 #import "ui/base/cocoa/cocoa_base_utils.h" | 52 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 53 #import "ui/base/cocoa/controls/blue_label_button.h" | 53 #import "ui/base/cocoa/controls/blue_label_button.h" |
| 54 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 54 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 55 #import "ui/base/cocoa/hover_image_button.h" | 55 #import "ui/base/cocoa/hover_image_button.h" |
| 56 #include "ui/base/cocoa/window_size_constants.h" | 56 #include "ui/base/cocoa/window_size_constants.h" |
| 57 #include "ui/base/l10n/l10n_util.h" | 57 #include "ui/base/l10n/l10n_util.h" |
| 58 #include "ui/base/l10n/l10n_util_mac.h" | 58 #include "ui/base/l10n/l10n_util_mac.h" |
| 59 #include "ui/base/resource/resource_bundle.h" | 59 #include "ui/base/resource/resource_bundle.h" |
| 60 #include "ui/gfx/image/image.h" | 60 #include "ui/gfx/image/image.h" |
| 61 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | |
| 61 #include "ui/gfx/text_elider.h" | 62 #include "ui/gfx/text_elider.h" |
| 62 #include "ui/native_theme/native_theme.h" | 63 #include "ui/native_theme/native_theme.h" |
| 63 | 64 |
| 64 namespace { | 65 namespace { |
| 65 | 66 |
| 66 // Constants taken from the Windows/Views implementation at: | 67 // Constants taken from the Windows/Views implementation at: |
| 67 // chrome/browser/ui/views/profile_chooser_view.cc | 68 // chrome/browser/ui/views/profile_chooser_view.cc |
| 68 const int kLargeImageSide = 88; | 69 const int kLargeImageSide = 88; |
| 69 const int kSmallImageSide = 32; | 70 const int kSmallImageSide = 32; |
| 70 const CGFloat kFixedMenuWidth = 250; | 71 const CGFloat kFixedMenuWidth = 250; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 [self addTrackingArea:trackingArea_.get()]; | 404 [self addTrackingArea:trackingArea_.get()]; |
| 404 | 405 |
| 405 NSRect bounds = NSMakeRect(0, 0, kLargeImageSide, kLargeImageSide); | 406 NSRect bounds = NSMakeRect(0, 0, kLargeImageSide, kLargeImageSide); |
| 406 if (editingAllowed) { | 407 if (editingAllowed) { |
| 407 changePhotoButton_.reset([self changePhotoButtonWithRect:bounds]); | 408 changePhotoButton_.reset([self changePhotoButtonWithRect:bounds]); |
| 408 [self addSubview:changePhotoButton_]; | 409 [self addSubview:changePhotoButton_]; |
| 409 | 410 |
| 410 // Hide the button until the image is hovered over. | 411 // Hide the button until the image is hovered over. |
| 411 [changePhotoButton_ setHidden:YES]; | 412 [changePhotoButton_ setHidden:YES]; |
| 412 } | 413 } |
| 413 | |
| 414 // Add the frame overlay last, so that both the photo and the button | |
| 415 // look like circles. | |
| 416 base::scoped_nsobject<NSImageView> frameOverlay( | |
| 417 [[NSImageView alloc] initWithFrame:bounds]); | |
| 418 [frameOverlay setImage:ui::ResourceBundle::GetSharedInstance(). | |
| 419 GetNativeImageNamed(IDR_ICON_PROFILES_AVATAR_PHOTO_FRAME).AsNSImage()]; | |
|
groby-ooo-7-16
2014/05/23 17:33:42
Can you get rid of the image resource, too?
noms (inactive)
2014/05/23 19:32:13
Not yet -- until it lands, it's still being used o
| |
| 420 [self addSubview:frameOverlay]; | |
| 421 } | 414 } |
| 422 return self; | 415 return self; |
| 423 } | 416 } |
| 424 | 417 |
| 418 - (void)drawRect:(NSRect)dirtyRect { | |
| 419 NSRect bounds = [self bounds]; | |
| 420 | |
| 421 // Display the profile picture as a circle. | |
| 422 NSBezierPath* path = [NSBezierPath bezierPathWithOvalInRect:bounds]; | |
| 423 { | |
|
groby-ooo-7-16
2014/05/23 17:33:42
You can kill the scoped state - Cocoa automaticall
noms (inactive)
2014/05/23 19:32:13
Nice! Done.
On 2014/05/23 17:33:42, groby wrote:
| |
| 424 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | |
| 425 [path addClip]; | |
| 426 [self.image drawAtPoint:bounds.origin | |
| 427 fromRect:bounds | |
| 428 operation:NSCompositeSourceOver | |
| 429 fraction:1.0]; | |
| 430 } | |
| 431 } | |
| 432 | |
| 425 - (void)editPhoto:(id)sender { | 433 - (void)editPhoto:(id)sender { |
| 426 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex()); | 434 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex()); |
| 427 } | 435 } |
| 428 | 436 |
| 429 - (void)mouseEntered:(NSEvent*)event { | 437 - (void)mouseEntered:(NSEvent*)event { |
| 430 [changePhotoButton_ setHidden:NO]; | 438 [changePhotoButton_ setHidden:NO]; |
| 431 } | 439 } |
| 432 | 440 |
| 433 - (void)mouseExited:(NSEvent*)event { | 441 - (void)mouseExited:(NSEvent*)event { |
| 434 [changePhotoButton_ setHidden:YES]; | 442 [changePhotoButton_ setHidden:YES]; |
| (...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1683 IDR_CLOSE_1_P).ToNSImage()]; | 1691 IDR_CLOSE_1_P).ToNSImage()]; |
| 1684 [deleteButton setTarget:self]; | 1692 [deleteButton setTarget:self]; |
| 1685 [deleteButton setAction:@selector(showAccountRemovalView:)]; | 1693 [deleteButton setAction:@selector(showAccountRemovalView:)]; |
| 1686 [deleteButton setTag:tag]; | 1694 [deleteButton setTag:tag]; |
| 1687 | 1695 |
| 1688 [button addSubview:deleteButton]; | 1696 [button addSubview:deleteButton]; |
| 1689 return button.autorelease(); | 1697 return button.autorelease(); |
| 1690 } | 1698 } |
| 1691 | 1699 |
| 1692 @end | 1700 @end |
| OLD | NEW |