| 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 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 9 #include "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" | 10 #include "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" |
| 10 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 11 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 11 #include "chrome/grit/theme_resources.h" | 12 #include "chrome/grit/theme_resources.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
| 14 #include "ui/gfx/image/image_skia_util_mac.h" | 15 #include "ui/gfx/image/image_skia_util_mac.h" |
| 15 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 16 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 16 | 17 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 43 return self; | 44 return self; |
| 44 } | 45 } |
| 45 | 46 |
| 46 - (NSRect)drawTitle:(NSAttributedString*)title | 47 - (NSRect)drawTitle:(NSAttributedString*)title |
| 47 withFrame:(NSRect)frame | 48 withFrame:(NSRect)frame |
| 48 inView:(NSView*)controlView { | 49 inView:(NSView*)controlView { |
| 49 // The title frame origin isn't aware of the left margin spacing added | 50 // The title frame origin isn't aware of the left margin spacing added |
| 50 // in -drawImage, so it must be added when drawing the title. | 51 // in -drawImage, so it must be added when drawing the title. |
| 51 NSRect marginRect; | 52 NSRect marginRect; |
| 52 NSDivideRect(frame, &marginRect, &frame, marginSpacing_, NSMinXEdge); | 53 NSDivideRect(frame, &marginRect, &frame, marginSpacing_, NSMinXEdge); |
| 53 NSDivideRect(frame, &marginRect, &frame, imageTitleSpacing_, NSMinXEdge); | 54 NSDivideRect(frame, &marginRect, &frame, imageTitleSpacing_, |
| 55 base::i18n::IsRTL() ? NSMaxXEdge : NSMinXEdge); |
| 54 NSDivideRect(frame, &marginRect, &frame, marginSpacing_, NSMaxXEdge); | 56 NSDivideRect(frame, &marginRect, &frame, marginSpacing_, NSMaxXEdge); |
| 55 | 57 |
| 56 return [super drawTitle:title withFrame:frame inView:controlView]; | 58 return [super drawTitle:title withFrame:frame inView:controlView]; |
| 57 } | 59 } |
| 58 | 60 |
| 59 - (void)drawImage:(NSImage*)image | 61 - (void)drawImage:(NSImage*)image |
| 60 withFrame:(NSRect)frame | 62 withFrame:(NSRect)frame |
| 61 inView:(NSView*)controlView { | 63 inView:(NSView*)controlView { |
| 62 frame.origin.x = marginSpacing_; | 64 if (base::i18n::IsRTL()) |
| 65 frame.origin.x -= marginSpacing_; |
| 66 else |
| 67 frame.origin.x += marginSpacing_; |
| 63 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 68 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
| 64 NSBezierPath* path = [NSBezierPath bezierPathWithOvalInRect:frame]; | 69 NSBezierPath* path = [NSBezierPath bezierPathWithOvalInRect:frame]; |
| 65 [path addClip]; | 70 [path addClip]; |
| 66 [super drawImage:image withFrame:frame inView:controlView]; | 71 [super drawImage:image withFrame:frame inView:controlView]; |
| 67 } | 72 } |
| 68 | 73 |
| 69 - (NSSize)cellSize { | 74 - (NSSize)cellSize { |
| 70 NSSize buttonSize = [super cellSize]; | 75 NSSize buttonSize = [super cellSize]; |
| 71 buttonSize.width += imageTitleSpacing_; | 76 buttonSize.width += imageTitleSpacing_; |
| 72 buttonSize.width += 2 * marginSpacing_; | 77 buttonSize.width += 2 * marginSpacing_; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; | 114 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 110 [cell setHighlightsBy:NSChangeGrayCellMask]; | 115 [cell setHighlightsBy:NSChangeGrayCellMask]; |
| 111 [self setCell:cell.get()]; | 116 [self setCell:cell.get()]; |
| 112 | 117 |
| 113 [self setBordered:NO]; | 118 [self setBordered:NO]; |
| 114 [self setFont:ResourceBundle::GetSharedInstance() | 119 [self setFont:ResourceBundle::GetSharedInstance() |
| 115 .GetFontList(ResourceBundle::SmallFont) | 120 .GetFontList(ResourceBundle::SmallFont) |
| 116 .GetPrimaryFont() | 121 .GetPrimaryFont() |
| 117 .GetNativeFont()]; | 122 .GetNativeFont()]; |
| 118 [self setButtonType:NSMomentaryLightButton]; | 123 [self setButtonType:NSMomentaryLightButton]; |
| 119 [self setImagePosition:NSImageLeft]; | 124 [self setImagePosition:base::i18n::IsRTL() ? NSImageRight : NSImageLeft]; |
| 120 [self setAlignment:NSLeftTextAlignment]; | |
| 121 } | 125 } |
| 122 return self; | 126 return self; |
| 123 } | 127 } |
| 124 | 128 |
| 125 + (NSImage*)defaultAvatar { | 129 + (NSImage*)defaultAvatar { |
| 126 return gfx::NSImageFromImageSkia(ScaleImageForAccountAvatar( | 130 return gfx::NSImageFromImageSkia(ScaleImageForAccountAvatar( |
| 127 *ResourceBundle::GetSharedInstance() | 131 *ResourceBundle::GetSharedInstance() |
| 128 .GetImageNamed(IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE) | 132 .GetImageNamed(IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE) |
| 129 .ToImageSkia())); | 133 .ToImageSkia())); |
| 130 } | 134 } |
| 131 | 135 |
| 132 - (void)setHoverState:(HoverState)state { | 136 - (void)setHoverState:(HoverState)state { |
| 133 [super setHoverState:state]; | 137 [super setHoverState:state]; |
| 134 bool isHighlighted = ([self hoverState] != kHoverStateNone); | 138 bool isHighlighted = ([self hoverState] != kHoverStateNone); |
| 135 | 139 |
| 136 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; | 140 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; |
| 137 [[self cell] setBackgroundColor:backgroundColor]; | 141 [[self cell] setBackgroundColor:backgroundColor]; |
| 138 } | 142 } |
| 139 | 143 |
| 140 - (BOOL)canBecomeKeyView { | 144 - (BOOL)canBecomeKeyView { |
| 141 return YES; | 145 return YES; |
| 142 } | 146 } |
| 143 | 147 |
| 144 @end | 148 @end |
| OLD | NEW |