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/toolbar/toolbar_tools_menu_button.h" |
| 6 |
| 7 #include "ios/chrome/browser/ui/toolbar/toolbar_button_tints.h" |
| 8 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 9 |
| 10 @interface ToolbarToolsMenuButton () |
| 11 // Updates the tint configuration based on the button's situation, e.g. whether |
| 12 // the tools menu is visible or not. |
| 13 - (void)updateTintOfButton; |
| 14 @end |
| 15 |
| 16 @interface ToolbarToolsMenuButton () { |
| 17 // The style of the toolbar the button is in. |
| 18 ToolbarControllerStyle style_; |
| 19 // Whether the tools menu is visible. |
| 20 BOOL toolsMenuVisible_; |
| 21 // Whether the reading list contains unread items. |
| 22 BOOL readingListContainsUnreadItems_; |
| 23 } |
| 24 @end |
| 25 |
| 26 @implementation ToolbarToolsMenuButton |
| 27 |
| 28 - (instancetype)initWithFrame:(CGRect)frame |
| 29 style:(ToolbarControllerStyle)style { |
| 30 if (self = [super initWithFrame:frame]) { |
| 31 style_ = style; |
| 32 |
| 33 [self setTintColor:toolbar::NormalButtonTint(style_) |
| 34 forState:UIControlStateNormal]; |
| 35 [self setTintColor:toolbar::HighlighButtonTint(style_) |
| 36 forState:UIControlStateHighlighted]; |
| 37 |
| 38 [self setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, -3, 0, 0)]; |
| 39 UIImage* image = [UIImage imageNamed:@"toolbar_tools"]; |
| 40 image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
| 41 [self setImage:image forState:UIControlStateNormal]; |
| 42 } |
| 43 return self; |
| 44 } |
| 45 |
| 46 - (void)setToolsMenuIsVisible:(BOOL)toolsMenuVisible { |
| 47 toolsMenuVisible_ = toolsMenuVisible; |
| 48 [self updateTintOfButton]; |
| 49 } |
| 50 |
| 51 - (void)setReadingListContainsUnreadItems:(BOOL)readingListContainsUnreadItems { |
| 52 readingListContainsUnreadItems_ = readingListContainsUnreadItems; |
| 53 [self updateTintOfButton]; |
| 54 } |
| 55 |
| 56 #pragma mark - Private |
| 57 |
| 58 - (void)updateTintOfButton { |
| 59 if (toolsMenuVisible_ || readingListContainsUnreadItems_) { |
| 60 [self setTintColor:toolbar::HighlighButtonTint(style_) |
| 61 forState:UIControlStateNormal]; |
| 62 } else { |
| 63 [self setTintColor:toolbar::NormalButtonTint(style_) |
| 64 forState:UIControlStateNormal]; |
| 65 } |
| 66 } |
| 67 |
| 68 @end |
OLD | NEW |