Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/passwords/credential_item_button.h" | 5 #import "chrome/browser/ui/cocoa/passwords/credential_item_button.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h" | |
| 10 #include "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" | 11 #include "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" |
| 11 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 12 #include "chrome/grit/theme_resources.h" | 13 #include "chrome/grit/theme_resources.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/color_palette.h" | |
| 14 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
| 15 #include "ui/gfx/image/image_skia_util_mac.h" | 17 #include "ui/gfx/image/image_skia_util_mac.h" |
| 18 #include "ui/gfx/paint_vector_icon.h" | |
| 16 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 20 #include "ui/gfx/vector_icons_public.h" | |
| 17 | 21 |
| 18 namespace { | 22 namespace { |
| 19 constexpr CGFloat kFocusRingInset = 3; | 23 constexpr CGFloat kFocusRingInset = 3; |
| 20 constexpr CGFloat kHorizontalPaddingBetweenAvatarAndLabel = 10; | 24 constexpr CGFloat kHorizontalPaddingBetweenAvatarAndLabel = 10; |
| 21 } // namespace | 25 } // namespace |
| 22 | 26 |
| 23 // Custom button cell that adds a left padding before the avatar, and a custom | 27 // Custom button cell that adds a left padding before the avatar, and a custom |
| 24 // spacing between the avatar and label. | 28 // spacing between the avatar and label. |
| 25 @interface CredentialItemButtonCell : NSButtonCell { | 29 @interface CredentialItemButtonCell : NSButtonCell { |
| 26 @private | 30 @private |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 [[NSBezierPath bezierPathWithRoundedRect:focusRingRect | 90 [[NSBezierPath bezierPathWithRoundedRect:focusRingRect |
| 87 xRadius:2 | 91 xRadius:2 |
| 88 yRadius:2] fill]; | 92 yRadius:2] fill]; |
| 89 } | 93 } |
| 90 | 94 |
| 91 @end | 95 @end |
| 92 | 96 |
| 93 @interface CredentialItemButton () { | 97 @interface CredentialItemButton () { |
| 94 base::scoped_nsobject<NSColor> backgroundColor_; | 98 base::scoped_nsobject<NSColor> backgroundColor_; |
| 95 base::scoped_nsobject<NSColor> hoverColor_; | 99 base::scoped_nsobject<NSColor> hoverColor_; |
| 100 base::scoped_nsobject<AutofillTooltipController> iconController_; | |
| 96 } | 101 } |
| 97 @end | 102 @end |
| 98 | 103 |
| 99 @implementation CredentialItemButton | 104 @implementation CredentialItemButton |
| 100 @synthesize passwordForm = passwordForm_; | 105 @synthesize passwordForm = passwordForm_; |
| 101 @synthesize credentialType = credentialType_; | 106 @synthesize credentialType = credentialType_; |
| 102 | 107 |
| 103 - (id)initWithFrame:(NSRect)frameRect | 108 - (id)initWithFrame:(NSRect)frameRect |
| 104 backgroundColor:(NSColor*)backgroundColor | 109 backgroundColor:(NSColor*)backgroundColor |
| 105 hoverColor:(NSColor*)hoverColor { | 110 hoverColor:(NSColor*)hoverColor { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 120 .GetFontList(ResourceBundle::SmallFont) | 125 .GetFontList(ResourceBundle::SmallFont) |
| 121 .GetPrimaryFont() | 126 .GetPrimaryFont() |
| 122 .GetNativeFont()]; | 127 .GetNativeFont()]; |
| 123 [self setButtonType:NSMomentaryLightButton]; | 128 [self setButtonType:NSMomentaryLightButton]; |
| 124 [self setImagePosition:base::i18n::IsRTL() ? NSImageRight : NSImageLeft]; | 129 [self setImagePosition:base::i18n::IsRTL() ? NSImageRight : NSImageLeft]; |
| 125 [self setAlignment:NSNaturalTextAlignment]; | 130 [self setAlignment:NSNaturalTextAlignment]; |
| 126 } | 131 } |
| 127 return self; | 132 return self; |
| 128 } | 133 } |
| 129 | 134 |
| 135 - (NSView*)enableIcon:(NSString*)tooltip { | |
| 136 iconController_.reset([[AutofillTooltipController alloc] | |
|
groby-ooo-7-16
2017/02/23 00:22:49
Is this supposed to be called multiple times? If n
nsphu.cnht
2017/02/24 15:09:15
On 2017/02/23 00:22:49, groby wrote:
> Is this sup
vasilii
2017/02/24 17:53:01
Done.
| |
| 137 initWithArrowLocation:info_bubble::kTopRight]); | |
| 138 NSImage* image = gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 139 gfx::VectorIconId::INFO_OUTLINE, gfx::kChromeIconGrey)); | |
| 140 [iconController_ setImage:image]; | |
| 141 [iconController_ setMessage:tooltip]; | |
| 142 [self addSubview:[iconController_ view]]; | |
|
groby-ooo-7-16
2017/02/23 00:22:49
This means self already takes ownership - do you r
nsphu.cnht
2017/02/24 15:09:15
Done.
nsphu.cnht
2017/02/24 15:09:15
Acknowledged.
vasilii
2017/02/24 17:53:01
But I own the controller. If I understand correctl
| |
| 143 return [iconController_ view]; | |
| 144 } | |
| 145 | |
| 130 + (NSImage*)defaultAvatar { | 146 + (NSImage*)defaultAvatar { |
| 131 return gfx::NSImageFromImageSkia(ScaleImageForAccountAvatar( | 147 return gfx::NSImageFromImageSkia(ScaleImageForAccountAvatar( |
| 132 *ResourceBundle::GetSharedInstance() | 148 *ResourceBundle::GetSharedInstance() |
| 133 .GetImageNamed(IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE) | 149 .GetImageNamed(IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE) |
| 134 .ToImageSkia())); | 150 .ToImageSkia())); |
| 135 } | 151 } |
| 136 | 152 |
| 137 - (void)setHoverState:(HoverState)state { | 153 - (void)setHoverState:(HoverState)state { |
| 138 [super setHoverState:state]; | 154 [super setHoverState:state]; |
| 139 bool isHighlighted = ([self hoverState] != kHoverStateNone); | 155 bool isHighlighted = ([self hoverState] != kHoverStateNone); |
| 140 | 156 |
| 141 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; | 157 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; |
| 142 [[self cell] setBackgroundColor:backgroundColor]; | 158 [[self cell] setBackgroundColor:backgroundColor]; |
| 143 } | 159 } |
| 144 | 160 |
| 145 - (BOOL)canBecomeKeyView { | 161 - (BOOL)canBecomeKeyView { |
| 146 return YES; | 162 return YES; |
| 147 } | 163 } |
| 148 | 164 |
| 149 @end | 165 @end |
| OLD | NEW |