| 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 #include "base/mac/objc_release_properties.h" |
| 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 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const int kButtonColor = 0x333333; | 15 const int kButtonColor = 0x333333; |
| 16 const int kButtonSelectedColor = 0x4285F4; | 16 const int kButtonSelectedColor = 0x4285F4; |
| 17 | 17 |
| 18 } // anonymous namespace | 18 } // anonymous namespace |
| 19 | 19 |
| 20 @interface NewTabPageBarButton () { | 20 @interface NewTabPageBarButton () |
| 21 UIColor* _color; | |
| 22 UIColor* _selectedColor; | |
| 23 UIColor* _incognitoColor; | |
| 24 UIColor* _incognitoSelectedColor; | |
| 25 UIColor* _interpolatedColor; | |
| 26 UIColor* _interpolatedSelectedColor; | |
| 27 | |
| 28 UIImage* _image; | |
| 29 NSString* _title; | |
| 30 base::mac::ObjCPropertyReleaser _propertyReleaser_NewTabPageBarButton; | |
| 31 } | |
| 32 | 21 |
| 33 @property(nonatomic, retain) UIColor* color; | 22 @property(nonatomic, retain) UIColor* color; |
| 34 @property(nonatomic, retain) UIColor* selectedColor; | 23 @property(nonatomic, retain) UIColor* selectedColor; |
| 35 @property(nonatomic, retain) UIColor* incognitoColor; | 24 @property(nonatomic, retain) UIColor* incognitoColor; |
| 36 @property(nonatomic, retain) UIColor* incognitoSelectedColor; | 25 @property(nonatomic, retain) UIColor* incognitoSelectedColor; |
| 37 @property(nonatomic, retain) UIColor* interpolatedColor; | 26 @property(nonatomic, retain) UIColor* interpolatedColor; |
| 38 @property(nonatomic, retain) UIColor* interpolatedSelectedColor; | 27 @property(nonatomic, retain) UIColor* interpolatedSelectedColor; |
| 39 @property(nonatomic, retain) UIImage* image; | 28 @property(nonatomic, retain) UIImage* image; |
| 40 @property(nonatomic, copy) NSString* title; | 29 @property(nonatomic, copy) NSString* title; |
| 41 | 30 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 55 @synthesize interpolatedSelectedColor = _interpolatedSelectedColor; | 44 @synthesize interpolatedSelectedColor = _interpolatedSelectedColor; |
| 56 @synthesize image = _image; | 45 @synthesize image = _image; |
| 57 @synthesize title = _title; | 46 @synthesize title = _title; |
| 58 | 47 |
| 59 + (instancetype)buttonWithItem:(NewTabPageBarItem*)item { | 48 + (instancetype)buttonWithItem:(NewTabPageBarItem*)item { |
| 60 DCHECK(item); | 49 DCHECK(item); |
| 61 DCHECK(item.title); | 50 DCHECK(item.title); |
| 62 DCHECK(item.image); | 51 DCHECK(item.image); |
| 63 NewTabPageBarButton* button = | 52 NewTabPageBarButton* button = |
| 64 [[self class] buttonWithType:UIButtonTypeCustom]; | 53 [[self class] buttonWithType:UIButtonTypeCustom]; |
| 65 button->_propertyReleaser_NewTabPageBarButton.Init( | |
| 66 button, [NewTabPageBarButton class]); | |
| 67 | 54 |
| 68 button.title = item.title; | 55 button.title = item.title; |
| 69 button.image = | 56 button.image = |
| 70 [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; | 57 [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
| 71 button.color = UIColorFromRGB(kButtonColor, 1.0); | 58 button.color = UIColorFromRGB(kButtonColor, 1.0); |
| 72 button.selectedColor = UIColorFromRGB(kButtonSelectedColor, 1.0); | 59 button.selectedColor = UIColorFromRGB(kButtonSelectedColor, 1.0); |
| 73 button.incognitoColor = [UIColor colorWithWhite:1 alpha:0.5]; | 60 button.incognitoColor = [UIColor colorWithWhite:1 alpha:0.5]; |
| 74 button.incognitoSelectedColor = [UIColor whiteColor]; | 61 button.incognitoSelectedColor = [UIColor whiteColor]; |
| 75 | 62 |
| 76 button.autoresizingMask = UIViewAutoresizingFlexibleWidth; | 63 button.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
| 77 button.adjustsImageWhenHighlighted = NO; | 64 button.adjustsImageWhenHighlighted = NO; |
| 78 button.accessibilityLabel = item.title; | 65 button.accessibilityLabel = item.title; |
| 79 button.titleLabel.font = [MDCTypography body2Font]; | 66 button.titleLabel.font = [MDCTypography body2Font]; |
| 80 button.titleLabel.adjustsFontSizeToFitWidth = YES; | 67 button.titleLabel.adjustsFontSizeToFitWidth = YES; |
| 81 button.titleLabel.minimumScaleFactor = 0.6; | 68 button.titleLabel.minimumScaleFactor = 0.6; |
| 82 | 69 |
| 83 [button useIncognitoColorScheme:0]; | 70 [button useIncognitoColorScheme:0]; |
| 84 [button setContentToDisplay:new_tab_page_bar_button::ContentType::TEXT]; | 71 [button setContentToDisplay:new_tab_page_bar_button::ContentType::TEXT]; |
| 85 return button; | 72 return button; |
| 86 } | 73 } |
| 87 | 74 |
| 75 - (void)dealloc { |
| 76 base::mac::ReleaseProperties(self); |
| 77 [super dealloc]; |
| 78 } |
| 79 |
| 88 - (void)useIncognitoColorScheme:(CGFloat)percentage { | 80 - (void)useIncognitoColorScheme:(CGFloat)percentage { |
| 89 DCHECK(percentage >= 0 && percentage <= 1); | 81 DCHECK(percentage >= 0 && percentage <= 1); |
| 90 self.interpolatedColor = | 82 self.interpolatedColor = |
| 91 InterpolateFromColorToColor(_color, _incognitoColor, percentage); | 83 InterpolateFromColorToColor(_color, _incognitoColor, percentage); |
| 92 self.interpolatedSelectedColor = InterpolateFromColorToColor( | 84 self.interpolatedSelectedColor = InterpolateFromColorToColor( |
| 93 _selectedColor, _incognitoSelectedColor, percentage); | 85 _selectedColor, _incognitoSelectedColor, percentage); |
| 94 | 86 |
| 95 [self setTitleColor:_interpolatedColor forState:UIControlStateNormal]; | 87 [self setTitleColor:_interpolatedColor forState:UIControlStateNormal]; |
| 96 [self setTitleColor:_interpolatedSelectedColor | 88 [self setTitleColor:_interpolatedSelectedColor |
| 97 forState:UIControlStateSelected]; | 89 forState:UIControlStateSelected]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 [super setSelected:selected]; | 121 [super setSelected:selected]; |
| 130 [self refreshTintColor]; | 122 [self refreshTintColor]; |
| 131 } | 123 } |
| 132 | 124 |
| 133 - (void)setHighlighted:(BOOL)highlighted { | 125 - (void)setHighlighted:(BOOL)highlighted { |
| 134 [super setHighlighted:highlighted]; | 126 [super setHighlighted:highlighted]; |
| 135 [self refreshTintColor]; | 127 [self refreshTintColor]; |
| 136 } | 128 } |
| 137 | 129 |
| 138 @end | 130 @end |
| OLD | NEW |