| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/ui/ntp/new_tab_page_bar_button.h" | 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_button.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/objc_property_releaser.h" | 8 |
| 9 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" | 9 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" |
| 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 11 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 11 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 12 | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
| 13 namespace { | 17 namespace { |
| 14 | 18 |
| 15 const int kButtonColor = 0x333333; | 19 const int kButtonColor = 0x333333; |
| 16 const int kButtonSelectedColor = 0x4285F4; | 20 const int kButtonSelectedColor = 0x4285F4; |
| 17 | 21 |
| 18 } // anonymous namespace | 22 } // anonymous namespace |
| 19 | 23 |
| 20 @interface NewTabPageBarButton () { | 24 @interface NewTabPageBarButton () |
| 21 UIColor* _color; | |
| 22 UIColor* _selectedColor; | |
| 23 UIColor* _incognitoColor; | |
| 24 UIColor* _incognitoSelectedColor; | |
| 25 UIColor* _interpolatedColor; | |
| 26 UIColor* _interpolatedSelectedColor; | |
| 27 | 25 |
| 28 UIImage* _image; | 26 @property(nonatomic, strong) UIColor* color; |
| 29 NSString* _title; | 27 @property(nonatomic, strong) UIColor* selectedColor; |
| 30 base::mac::ObjCPropertyReleaser _propertyReleaser_NewTabPageBarButton; | 28 @property(nonatomic, strong) UIColor* incognitoColor; |
| 31 } | 29 @property(nonatomic, strong) UIColor* incognitoSelectedColor; |
| 32 | 30 @property(nonatomic, strong) UIColor* interpolatedColor; |
| 33 @property(nonatomic, retain) UIColor* color; | 31 @property(nonatomic, strong) UIColor* interpolatedSelectedColor; |
| 34 @property(nonatomic, retain) UIColor* selectedColor; | 32 @property(nonatomic, strong) UIImage* image; |
| 35 @property(nonatomic, retain) UIColor* incognitoColor; | |
| 36 @property(nonatomic, retain) UIColor* incognitoSelectedColor; | |
| 37 @property(nonatomic, retain) UIColor* interpolatedColor; | |
| 38 @property(nonatomic, retain) UIColor* interpolatedSelectedColor; | |
| 39 @property(nonatomic, retain) UIImage* image; | |
| 40 @property(nonatomic, copy) NSString* title; | 33 @property(nonatomic, copy) NSString* title; |
| 41 | 34 |
| 42 // Sets the tint color of the button to |interpolatedColor| or | 35 // Sets the tint color of the button to |interpolatedColor| or |
| 43 // |interpolatedSelectedColor|, depending on the state of the button. | 36 // |interpolatedSelectedColor|, depending on the state of the button. |
| 44 - (void)refreshTintColor; | 37 - (void)refreshTintColor; |
| 45 | 38 |
| 46 @end | 39 @end |
| 47 | 40 |
| 48 @implementation NewTabPageBarButton | 41 @implementation NewTabPageBarButton |
| 49 | 42 |
| 50 @synthesize color = _color; | 43 @synthesize color = _color; |
| 51 @synthesize selectedColor = _selectedColor; | 44 @synthesize selectedColor = _selectedColor; |
| 52 @synthesize incognitoColor = _incognitoColor; | 45 @synthesize incognitoColor = _incognitoColor; |
| 53 @synthesize incognitoSelectedColor = _incognitoSelectedColor; | 46 @synthesize incognitoSelectedColor = _incognitoSelectedColor; |
| 54 @synthesize interpolatedColor = _interpolatedColor; | 47 @synthesize interpolatedColor = _interpolatedColor; |
| 55 @synthesize interpolatedSelectedColor = _interpolatedSelectedColor; | 48 @synthesize interpolatedSelectedColor = _interpolatedSelectedColor; |
| 56 @synthesize image = _image; | 49 @synthesize image = _image; |
| 57 @synthesize title = _title; | 50 @synthesize title = _title; |
| 58 | 51 |
| 59 + (instancetype)buttonWithItem:(NewTabPageBarItem*)item { | 52 + (instancetype)buttonWithItem:(NewTabPageBarItem*)item { |
| 60 DCHECK(item); | 53 DCHECK(item); |
| 61 DCHECK(item.title); | 54 DCHECK(item.title); |
| 62 DCHECK(item.image); | 55 DCHECK(item.image); |
| 63 NewTabPageBarButton* button = | 56 NewTabPageBarButton* button = |
| 64 [[self class] buttonWithType:UIButtonTypeCustom]; | 57 [[self class] buttonWithType:UIButtonTypeCustom]; |
| 65 button->_propertyReleaser_NewTabPageBarButton.Init( | |
| 66 button, [NewTabPageBarButton class]); | |
| 67 | 58 |
| 68 button.title = item.title; | 59 button.title = item.title; |
| 69 button.image = | 60 button.image = |
| 70 [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; | 61 [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
| 71 button.color = UIColorFromRGB(kButtonColor, 1.0); | 62 button.color = UIColorFromRGB(kButtonColor, 1.0); |
| 72 button.selectedColor = UIColorFromRGB(kButtonSelectedColor, 1.0); | 63 button.selectedColor = UIColorFromRGB(kButtonSelectedColor, 1.0); |
| 73 button.incognitoColor = [UIColor colorWithWhite:1 alpha:0.5]; | 64 button.incognitoColor = [UIColor colorWithWhite:1 alpha:0.5]; |
| 74 button.incognitoSelectedColor = [UIColor whiteColor]; | 65 button.incognitoSelectedColor = [UIColor whiteColor]; |
| 75 | 66 |
| 76 button.autoresizingMask = UIViewAutoresizingFlexibleWidth; | 67 button.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 [super setSelected:selected]; | 120 [super setSelected:selected]; |
| 130 [self refreshTintColor]; | 121 [self refreshTintColor]; |
| 131 } | 122 } |
| 132 | 123 |
| 133 - (void)setHighlighted:(BOOL)highlighted { | 124 - (void)setHighlighted:(BOOL)highlighted { |
| 134 [super setHighlighted:highlighted]; | 125 [super setHighlighted:highlighted]; |
| 135 [self refreshTintColor]; | 126 [self refreshTintColor]; |
| 136 } | 127 } |
| 137 | 128 |
| 138 @end | 129 @end |
| OLD | NEW |