OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
| 6 |
| 7 #import <CoreGraphics/CoreGraphics.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #import "base/mac/scoped_nsobject.h" |
| 11 #include "ios/chrome/grit/ios_strings.h" |
| 12 #include "ui/base/l10n/l10n_util_mac.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 NSString* AccessibilityLabelForIconNamed(NSString* name) { |
| 17 if ([name isEqualToString:@"ic_arrow_back"]) |
| 18 return l10n_util::GetNSString(IDS_IOS_ICON_ARROW_BACK); |
| 19 if ([name isEqualToString:@"ic_close"]) |
| 20 return l10n_util::GetNSString(IDS_IOS_ICON_CLOSE); |
| 21 if ([name isEqualToString:@"ic_info"]) |
| 22 return l10n_util::GetNSString(IDS_IOS_ICON_INFO); |
| 23 if ([name isEqualToString:@"ic_search"]) |
| 24 return l10n_util::GetNSString(IDS_IOS_ICON_SEARCH); |
| 25 return nil; |
| 26 } |
| 27 |
| 28 UIImage* IconNamed(NSString* name) { |
| 29 UIImage* image = [UIImage imageNamed:name]; |
| 30 DCHECK(image); |
| 31 image.accessibilityIdentifier = name; |
| 32 image.accessibilityLabel = AccessibilityLabelForIconNamed(name); |
| 33 return image; |
| 34 } |
| 35 |
| 36 // Wraps -[UIImage imageFlippedForRightToLeftLayoutDirection] to also support |
| 37 // porting accessibility properties. |
| 38 // TODO(crbug.com/622543): remove this workaround if Apple fixes rdar://26962660 |
| 39 UIImage* ImageFlippedForRightToLeftLayoutDirection(UIImage* image) { |
| 40 UIImage* imageFlipped = [image imageFlippedForRightToLeftLayoutDirection]; |
| 41 imageFlipped.accessibilityIdentifier = image.accessibilityIdentifier; |
| 42 imageFlipped.accessibilityLabel = image.accessibilityLabel; |
| 43 return imageFlipped; |
| 44 } |
| 45 |
| 46 } // namespace |
| 47 |
| 48 @implementation ChromeIcon |
| 49 |
| 50 + (UIImage*)backIcon { |
| 51 return ImageFlippedForRightToLeftLayoutDirection(IconNamed(@"ic_arrow_back")); |
| 52 } |
| 53 |
| 54 + (UIImage*)closeIcon { |
| 55 return IconNamed(@"ic_close"); |
| 56 } |
| 57 |
| 58 + (UIImage*)infoIcon { |
| 59 return IconNamed(@"ic_info"); |
| 60 } |
| 61 |
| 62 + (UIImage*)searchIcon { |
| 63 return IconNamed(@"ic_search"); |
| 64 } |
| 65 |
| 66 + (UIImage*)chevronIcon { |
| 67 return ImageFlippedForRightToLeftLayoutDirection( |
| 68 IconNamed(@"ic_chevron_right")); |
| 69 } |
| 70 |
| 71 + (UIBarButtonItem*)templateBarButtonItemWithImage:(UIImage*)image |
| 72 target:(id)target |
| 73 action:(SEL)action { |
| 74 UIImage* templateImage = |
| 75 [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
| 76 base::scoped_nsobject<UIBarButtonItem> barButtonItem([[UIBarButtonItem alloc] |
| 77 initWithImage:templateImage |
| 78 style:UIBarButtonItemStylePlain |
| 79 target:target |
| 80 action:action]); |
| 81 [barButtonItem setAccessibilityIdentifier:image.accessibilityIdentifier]; |
| 82 [barButtonItem setAccessibilityLabel:image.accessibilityLabel]; |
| 83 return barButtonItem.autorelease(); |
| 84 } |
| 85 |
| 86 @end |
OLD | NEW |