| 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 "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 - (id)initWithBrowser:(Browser*)browser { | 33 - (id)initWithBrowser:(Browser*)browser { |
| 34 if ((self = [super initWithBrowser:browser])) { | 34 if ((self = [super initWithBrowser:browser])) { |
| 35 browser_ = browser; | 35 browser_ = browser; |
| 36 | 36 |
| 37 base::scoped_nsobject<NSView> container( | 37 base::scoped_nsobject<NSView> container( |
| 38 [[NSView alloc] initWithFrame:NSMakeRect( | 38 [[NSView alloc] initWithFrame:NSMakeRect( |
| 39 0, 0, profiles::kAvatarIconWidth, profiles::kAvatarIconHeight)]); | 39 0, 0, profiles::kAvatarIconWidth, profiles::kAvatarIconHeight)]); |
| 40 [container setWantsLayer:YES]; | 40 [container setWantsLayer:YES]; |
| 41 [self setView:container]; | 41 [self setView:container]; |
| 42 | 42 |
| 43 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); | |
| 44 NSRect frameRect = NSMakeRect(5, 5, profiles::kAvatarIconWidth, | 43 NSRect frameRect = NSMakeRect(5, 5, profiles::kAvatarIconWidth, |
| 45 profiles::kAvatarIconHeight); | 44 profiles::kAvatarIconHeight); |
| 46 if (!isModeMaterial) { | |
| 47 frameRect.origin = NSZeroPoint; | |
| 48 } | |
| 49 button_.reset([[NSButton alloc] initWithFrame:frameRect]); | 45 button_.reset([[NSButton alloc] initWithFrame:frameRect]); |
| 50 NSButtonCell* cell = [button_ cell]; | 46 NSButtonCell* cell = [button_ cell]; |
| 51 [button_ setButtonType:NSMomentaryLightButton]; | 47 [button_ setButtonType:NSMomentaryLightButton]; |
| 52 | 48 |
| 53 [button_ setImagePosition:NSImageOnly]; | 49 [button_ setImagePosition:NSImageOnly]; |
| 54 [cell setImageScaling:NSImageScaleProportionallyDown]; | 50 [cell setImageScaling:NSImageScaleProportionallyDown]; |
| 55 [cell setImagePosition:NSImageBelow]; | 51 [cell setImagePosition:NSImageBelow]; |
| 56 | 52 |
| 57 // AppKit sets a title for some reason when using |-setImagePosition:|. | 53 // AppKit sets a title for some reason when using |-setImagePosition:|. |
| 58 [button_ setTitle:nil]; | 54 [button_ setTitle:nil]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 [cell accessibilitySetOverrideValue: | 69 [cell accessibilitySetOverrideValue: |
| 74 l10n_util::GetNSString(IDS_PROFILES_BUBBLE_ACCESSIBLE_NAME) | 70 l10n_util::GetNSString(IDS_PROFILES_BUBBLE_ACCESSIBLE_NAME) |
| 75 forAttribute:NSAccessibilityTitleAttribute]; | 71 forAttribute:NSAccessibilityTitleAttribute]; |
| 76 [cell accessibilitySetOverrideValue: | 72 [cell accessibilitySetOverrideValue: |
| 77 l10n_util::GetNSString(IDS_PROFILES_BUBBLE_ACCESSIBLE_DESCRIPTION) | 73 l10n_util::GetNSString(IDS_PROFILES_BUBBLE_ACCESSIBLE_DESCRIPTION) |
| 78 forAttribute:NSAccessibilityHelpAttribute]; | 74 forAttribute:NSAccessibilityHelpAttribute]; |
| 79 [cell accessibilitySetOverrideValue: | 75 [cell accessibilitySetOverrideValue: |
| 80 l10n_util::GetNSString(IDS_PROFILES_BUBBLE_ACCESSIBLE_DESCRIPTION) | 76 l10n_util::GetNSString(IDS_PROFILES_BUBBLE_ACCESSIBLE_DESCRIPTION) |
| 81 forAttribute:NSAccessibilityDescriptionAttribute]; | 77 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 82 | 78 |
| 83 if (isModeMaterial) { | 79 NSImage* icon = NSImageFromImageSkia( |
| 84 NSImage* icon = NSImageFromImageSkia(gfx::CreateVectorIcon( | 80 gfx::CreateVectorIcon(gfx::VectorIconId::INCOGNITO, 24, SK_ColorWHITE)); |
| 85 gfx::VectorIconId::INCOGNITO, 24, SK_ColorWHITE)); | 81 [button_ setImage:icon]; |
| 86 [button_ setImage:icon]; | |
| 87 } else { | |
| 88 NSImage* icon = ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 89 IDR_OTR_ICON).ToNSImage(); | |
| 90 [button_ setImage:[self compositeImageWithShadow:icon]]; | |
| 91 } | |
| 92 [button_ setEnabled:NO]; | 82 [button_ setEnabled:NO]; |
| 93 | 83 |
| 94 [[self view] addSubview:button_]; | 84 [[self view] addSubview:button_]; |
| 95 } | 85 } |
| 96 return self; | 86 return self; |
| 97 } | 87 } |
| 98 | 88 |
| 99 // This will take in an original image and redraw it with a shadow. | 89 // This will take in an original image and redraw it with a shadow. |
| 100 - (NSImage*)compositeImageWithShadow:(NSImage*)image { | 90 - (NSImage*)compositeImageWithShadow:(NSImage*)image { |
| 101 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 91 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 123 hints:nil]; | 113 hints:nil]; |
| 124 | 114 |
| 125 [destination unlockFocus]; | 115 [destination unlockFocus]; |
| 126 | 116 |
| 127 return destination.autorelease(); | 117 return destination.autorelease(); |
| 128 } | 118 } |
| 129 | 119 |
| 130 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {} | 120 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {} |
| 131 | 121 |
| 132 @end | 122 @end |
| OLD | NEW |