| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/clean/chrome/browser/ui/toolbar/toolbar_button.h" | 5 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h" |
| 6 | 6 |
| 7 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 8 |
| 7 #if !defined(__has_feature) || !__has_feature(objc_arc) | 9 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 8 #error "This file requires ARC support." | 10 #error "This file requires ARC support." |
| 9 #endif | 11 #endif |
| 10 | 12 |
| 11 @implementation ToolbarButton | 13 @implementation ToolbarButton |
| 12 @synthesize visibilityMask = _visibilityMask; | 14 @synthesize visibilityMask = _visibilityMask; |
| 13 @synthesize hiddenInCurrentSizeClass = _hiddenInCurrentSizeClass; | 15 @synthesize hiddenInCurrentSizeClass = _hiddenInCurrentSizeClass; |
| 14 @synthesize hiddenInCurrentState = _hiddenInCurrentState; | 16 @synthesize hiddenInCurrentState = _hiddenInCurrentState; |
| 15 | 17 |
| 16 + (instancetype)toolbarButtonWithImageForNormalState:(UIImage*)normalImage | 18 + (instancetype)toolbarButtonWithImageForNormalState:(UIImage*)normalImage |
| 17 imageForHighlightedState:(UIImage*)highlightedImage | 19 imageForHighlightedState:(UIImage*)highlightedImage |
| 18 imageForDisabledState:(UIImage*)disabledImage { | 20 imageForDisabledState:(UIImage*)disabledImage { |
| 19 ToolbarButton* button = [[self class] buttonWithType:UIButtonTypeCustom]; | 21 ToolbarButton* button = [[self class] buttonWithType:UIButtonTypeCustom]; |
| 20 [button setImage:normalImage forState:UIControlStateNormal]; | 22 [button setImage:normalImage forState:UIControlStateNormal]; |
| 21 [button setImage:highlightedImage forState:UIControlStateHighlighted]; | 23 [button setImage:highlightedImage forState:UIControlStateHighlighted]; |
| 22 [button setImage:disabledImage forState:UIControlStateDisabled]; | 24 [button setImage:disabledImage forState:UIControlStateDisabled]; |
| 25 button.titleLabel.textAlignment = NSTextAlignmentCenter; |
| 23 button.translatesAutoresizingMaskIntoConstraints = NO; | 26 button.translatesAutoresizingMaskIntoConstraints = NO; |
| 24 return button; | 27 return button; |
| 25 } | 28 } |
| 26 | 29 |
| 30 - (void)layoutSubviews { |
| 31 [super layoutSubviews]; |
| 32 // If the UIButton title has text it will center it on top of the image, |
| 33 // this is currently used for the TabStripButton which displays the |
| 34 // total number of tabs. |
| 35 if (self.titleLabel.text) { |
| 36 CGSize size = self.bounds.size; |
| 37 CGPoint center = CGPointMake(size.width / 2, size.height / 2); |
| 38 self.imageView.center = center; |
| 39 self.imageView.frame = AlignRectToPixel(self.imageView.frame); |
| 40 self.titleLabel.frame = self.bounds; |
| 41 } |
| 42 } |
| 43 |
| 27 #pragma mark - Public Methods | 44 #pragma mark - Public Methods |
| 28 | 45 |
| 29 - (void)updateHiddenInCurrentSizeClass { | 46 - (void)updateHiddenInCurrentSizeClass { |
| 30 BOOL newHiddenValue = YES; | 47 BOOL newHiddenValue = YES; |
| 31 switch (self.traitCollection.horizontalSizeClass) { | 48 switch (self.traitCollection.horizontalSizeClass) { |
| 32 case UIUserInterfaceSizeClassRegular: | 49 case UIUserInterfaceSizeClassRegular: |
| 33 newHiddenValue = | 50 newHiddenValue = |
| 34 !(self.visibilityMask & ToolbarComponentVisibilityRegularWidth); | 51 !(self.visibilityMask & ToolbarComponentVisibilityRegularWidth); |
| 35 break; | 52 break; |
| 36 case UIUserInterfaceSizeClassCompact: | 53 case UIUserInterfaceSizeClassCompact: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 51 self.hiddenInCurrentSizeClass = newHiddenValue; | 68 self.hiddenInCurrentSizeClass = newHiddenValue; |
| 52 [self setHiddenForCurrentStateAndSizeClass]; | 69 [self setHiddenForCurrentStateAndSizeClass]; |
| 53 } | 70 } |
| 54 } | 71 } |
| 55 | 72 |
| 56 - (void)setHiddenForCurrentStateAndSizeClass { | 73 - (void)setHiddenForCurrentStateAndSizeClass { |
| 57 self.hidden = self.hiddenInCurrentState || self.hiddenInCurrentSizeClass; | 74 self.hidden = self.hiddenInCurrentState || self.hiddenInCurrentSizeClass; |
| 58 } | 75 } |
| 59 | 76 |
| 60 @end | 77 @end |
| OLD | NEW |