Chromium Code Reviews| 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 #if !defined(__has_feature) || !__has_feature(objc_arc) | 7 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 8 #error "This file requires ARC support." | 8 #error "This file requires ARC support." |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 @implementation ToolbarButton | 11 @implementation ToolbarButton |
| 12 @synthesize visibilityMask = _visibilityMask; | 12 @synthesize visibilityMask = _visibilityMask; |
| 13 @synthesize hiddenInCurrentSizeClass = _hiddenInCurrentSizeClass; | 13 @synthesize hiddenInCurrentSizeClass = _hiddenInCurrentSizeClass; |
| 14 @synthesize hiddenInCurrentState = _hiddenInCurrentState; | 14 @synthesize hiddenInCurrentState = _hiddenInCurrentState; |
| 15 | 15 |
| 16 + (instancetype)toolbarButtonWithImageForNormalState:(UIImage*)normalImage | 16 + (instancetype)toolbarButtonWithImageForNormalState:(UIImage*)normalImage |
| 17 imageForHighlightedState:(UIImage*)highlightedImage | 17 imageForHighlightedState:(UIImage*)highlightedImage |
| 18 imageForDisabledState:(UIImage*)disabledImage { | 18 imageForDisabledState:(UIImage*)disabledImage { |
| 19 ToolbarButton* button = [[self class] buttonWithType:UIButtonTypeCustom]; | 19 ToolbarButton* button = [[self class] buttonWithType:UIButtonTypeCustom]; |
| 20 [button setImage:normalImage forState:UIControlStateNormal]; | 20 [button setImage:normalImage forState:UIControlStateNormal]; |
| 21 [button setImage:highlightedImage forState:UIControlStateHighlighted]; | 21 [button setImage:highlightedImage forState:UIControlStateHighlighted]; |
| 22 [button setImage:disabledImage forState:UIControlStateDisabled]; | 22 [button setImage:disabledImage forState:UIControlStateDisabled]; |
| 23 button.titleLabel.textAlignment = NSTextAlignmentCenter; | |
| 24 [[button titleLabel] setFont:[UIFont systemFontOfSize:11]]; | |
|
edchin
2017/05/27 16:25:06
Is there some predefined font size that can be use
marq (ping after 24h)
2017/05/29 11:04:36
We should either duplicate/refactor the logic in
sczs
2017/05/30 00:18:20
Moved this to the VC. Because of the UI constraint
| |
| 23 button.translatesAutoresizingMaskIntoConstraints = NO; | 25 button.translatesAutoresizingMaskIntoConstraints = NO; |
| 24 return button; | 26 return button; |
| 25 } | 27 } |
| 26 | 28 |
| 29 - (void)layoutSubviews { | |
| 30 [super layoutSubviews]; | |
| 31 // If the UIButton title has text it will center it on top of the image, | |
| 32 // this is currently used for the TabStripButton which displays the | |
| 33 // total number of tabs. | |
| 34 if (self.titleLabel.text) { | |
| 35 CGSize size = self.bounds.size; | |
| 36 CGPoint center = CGPointMake(size.width / 2, size.height / 2); | |
| 37 self.imageView.center = center; | |
|
marq (ping after 24h)
2017/05/29 11:04:36
Looks like this is an exact copy of the ToolbarCen
sczs
2017/05/30 00:18:20
Great catch. I missed it somehow.
| |
| 38 self.titleLabel.frame = self.bounds; | |
| 39 } | |
| 40 } | |
| 41 | |
| 27 #pragma mark - Public Methods | 42 #pragma mark - Public Methods |
| 28 | 43 |
| 29 - (void)updateHiddenInCurrentSizeClass { | 44 - (void)updateHiddenInCurrentSizeClass { |
| 30 BOOL newHiddenValue = YES; | 45 BOOL newHiddenValue = YES; |
| 31 switch (self.traitCollection.horizontalSizeClass) { | 46 switch (self.traitCollection.horizontalSizeClass) { |
| 32 case UIUserInterfaceSizeClassRegular: | 47 case UIUserInterfaceSizeClassRegular: |
| 33 newHiddenValue = | 48 newHiddenValue = |
| 34 !(self.visibilityMask & ToolbarComponentVisibilityRegularWidth); | 49 !(self.visibilityMask & ToolbarComponentVisibilityRegularWidth); |
| 35 break; | 50 break; |
| 36 case UIUserInterfaceSizeClassCompact: | 51 case UIUserInterfaceSizeClassCompact: |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 51 self.hiddenInCurrentSizeClass = newHiddenValue; | 66 self.hiddenInCurrentSizeClass = newHiddenValue; |
| 52 [self setHiddenForCurrentStateAndSizeClass]; | 67 [self setHiddenForCurrentStateAndSizeClass]; |
| 53 } | 68 } |
| 54 } | 69 } |
| 55 | 70 |
| 56 - (void)setHiddenForCurrentStateAndSizeClass { | 71 - (void)setHiddenForCurrentStateAndSizeClass { |
| 57 self.hidden = self.hiddenInCurrentState || self.hiddenInCurrentSizeClass; | 72 self.hidden = self.hiddenInCurrentState || self.hiddenInCurrentSizeClass; |
| 58 } | 73 } |
| 59 | 74 |
| 60 @end | 75 @end |
| OLD | NEW |