| 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+factory.h" | 5 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h" |
| 6 | 6 |
| 7 #import "ios/chrome/browser/ui/rtl_geometry.h" | 7 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 8 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 8 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 9 #include "ios/chrome/grit/ios_theme_resources.h" | 9 #include "ios/chrome/grit/ios_theme_resources.h" |
| 10 | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) | 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." | 12 #error "This file requires ARC support." |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 namespace { |
| 16 // ToolbarButton fixed width. |
| 17 CGFloat kToolbarButtonWidth = 42.0f; |
| 18 } // namespace |
| 19 |
| 15 @implementation ToolbarButton (Factory) | 20 @implementation ToolbarButton (Factory) |
| 16 | 21 |
| 17 #pragma mark - ToolbarButton Setup | 22 #pragma mark - ToolbarButton Setup |
| 18 | 23 |
| 19 + (instancetype)backToolbarButton { | 24 + (instancetype)backToolbarButton { |
| 20 ToolbarButton* backButton = [self | 25 ToolbarButton* backButton = [self |
| 21 toolbarButtonWithImageForNormalState:NativeReversableImage( | 26 toolbarButtonWithImageForNormalState:NativeReversableImage( |
| 22 IDR_IOS_TOOLBAR_LIGHT_BACK, YES) | 27 IDR_IOS_TOOLBAR_LIGHT_BACK, YES) |
| 23 imageForHighlightedState: | 28 imageForHighlightedState: |
| 24 NativeReversableImage(IDR_IOS_TOOLBAR_LIGHT_BACK_PRESSED, | 29 NativeReversableImage(IDR_IOS_TOOLBAR_LIGHT_BACK_PRESSED, |
| 25 YES) | 30 YES) |
| 26 imageForDisabledState: | 31 imageForDisabledState: |
| 27 NativeReversableImage( | 32 NativeReversableImage( |
| 28 IDR_IOS_TOOLBAR_LIGHT_BACK_DISABLED, YES)]; | 33 IDR_IOS_TOOLBAR_LIGHT_BACK_DISABLED, YES)]; |
| 34 [backButton.widthAnchor constraintEqualToConstant:kToolbarButtonWidth] |
| 35 .active = YES; |
| 29 return backButton; | 36 return backButton; |
| 30 } | 37 } |
| 31 | 38 |
| 32 + (instancetype)forwardToolbarButton { | 39 + (instancetype)forwardToolbarButton { |
| 33 ToolbarButton* forwardButton = [self | 40 ToolbarButton* forwardButton = [self |
| 34 toolbarButtonWithImageForNormalState:NativeReversableImage( | 41 toolbarButtonWithImageForNormalState:NativeReversableImage( |
| 35 IDR_IOS_TOOLBAR_LIGHT_FORWARD, | 42 IDR_IOS_TOOLBAR_LIGHT_FORWARD, |
| 36 YES) | 43 YES) |
| 37 imageForHighlightedState: | 44 imageForHighlightedState: |
| 38 NativeReversableImage( | 45 NativeReversableImage( |
| 39 IDR_IOS_TOOLBAR_LIGHT_FORWARD_PRESSED, YES) | 46 IDR_IOS_TOOLBAR_LIGHT_FORWARD_PRESSED, YES) |
| 40 imageForDisabledState: | 47 imageForDisabledState: |
| 41 NativeReversableImage( | 48 NativeReversableImage( |
| 42 IDR_IOS_TOOLBAR_LIGHT_FORWARD_DISABLED, YES)]; | 49 IDR_IOS_TOOLBAR_LIGHT_FORWARD_DISABLED, YES)]; |
| 50 [forwardButton.widthAnchor constraintEqualToConstant:kToolbarButtonWidth] |
| 51 .active = YES; |
| 43 return forwardButton; | 52 return forwardButton; |
| 44 } | 53 } |
| 45 | 54 |
| 46 + (instancetype)tabSwitcherStripToolbarButton { | 55 + (instancetype)tabSwitcherStripToolbarButton { |
| 47 return [self toolbarButtonWithImageForNormalState: | 56 ToolbarButton* tabSwitcherStripButton = |
| 48 [UIImage imageNamed:@"tabswitcher_open_tabs"] | 57 [self toolbarButtonWithImageForNormalState: |
| 49 imageForHighlightedState:nil | 58 [UIImage imageNamed:@"tabswitcher_open_tabs"] |
| 50 imageForDisabledState:nil]; | 59 imageForHighlightedState:nil |
| 60 imageForDisabledState:nil]; |
| 61 [tabSwitcherStripButton.widthAnchor |
| 62 constraintEqualToConstant:kToolbarButtonWidth] |
| 63 .active = YES; |
| 64 return tabSwitcherStripButton; |
| 51 } | 65 } |
| 52 | 66 |
| 53 + (instancetype)tabSwitcherGridToolbarButton { | 67 + (instancetype)tabSwitcherGridToolbarButton { |
| 54 return [self toolbarButtonWithImageForNormalState: | 68 ToolbarButton* tabSwitcherGridButton = |
| 55 [UIImage imageNamed:@"tabswitcher_tab_switcher_button"] | 69 [self toolbarButtonWithImageForNormalState: |
| 56 imageForHighlightedState:nil | 70 [UIImage imageNamed:@"tabswitcher_tab_switcher_button"] |
| 57 imageForDisabledState:nil]; | 71 imageForHighlightedState:nil |
| 72 imageForDisabledState:nil]; |
| 73 [tabSwitcherGridButton.widthAnchor |
| 74 constraintEqualToConstant:kToolbarButtonWidth] |
| 75 .active = YES; |
| 76 return tabSwitcherGridButton; |
| 58 } | 77 } |
| 59 | 78 |
| 60 + (instancetype)toolsMenuToolbarButton { | 79 + (instancetype)toolsMenuToolbarButton { |
| 61 ToolbarButton* toolsMenuButton = [self | 80 ToolbarButton* toolsMenuButton = [self |
| 62 toolbarButtonWithImageForNormalState:[UIImage | 81 toolbarButtonWithImageForNormalState:[UIImage |
| 63 imageNamed:@"tabswitcher_menu"] | 82 imageNamed:@"tabswitcher_menu"] |
| 64 imageForHighlightedState:nil | 83 imageForHighlightedState:nil |
| 65 imageForDisabledState:nil]; | 84 imageForDisabledState:nil]; |
| 66 [toolsMenuButton setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, -3, 0, 0)]; | 85 [toolsMenuButton setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, -3, 0, 0)]; |
| 86 [toolsMenuButton.widthAnchor constraintEqualToConstant:kToolbarButtonWidth] |
| 87 .active = YES; |
| 67 return toolsMenuButton; | 88 return toolsMenuButton; |
| 68 } | 89 } |
| 69 | 90 |
| 70 + (instancetype)shareToolbarButton { | 91 + (instancetype)shareToolbarButton { |
| 71 ToolbarButton* shareButton = [self | 92 ToolbarButton* shareButton = [self |
| 72 toolbarButtonWithImageForNormalState:NativeImage( | 93 toolbarButtonWithImageForNormalState:NativeImage( |
| 73 IDR_IOS_TOOLBAR_LIGHT_SHARE) | 94 IDR_IOS_TOOLBAR_LIGHT_SHARE) |
| 74 imageForHighlightedState: | 95 imageForHighlightedState: |
| 75 NativeImage(IDR_IOS_TOOLBAR_LIGHT_SHARE_PRESSED) | 96 NativeImage(IDR_IOS_TOOLBAR_LIGHT_SHARE_PRESSED) |
| 76 imageForDisabledState: | 97 imageForDisabledState: |
| 77 NativeImage(IDR_IOS_TOOLBAR_LIGHT_SHARE_DISABLED)]; | 98 NativeImage(IDR_IOS_TOOLBAR_LIGHT_SHARE_DISABLED)]; |
| 99 [shareButton.widthAnchor constraintEqualToConstant:kToolbarButtonWidth] |
| 100 .active = YES; |
| 78 return shareButton; | 101 return shareButton; |
| 79 } | 102 } |
| 80 | 103 |
| 81 + (instancetype)reloadToolbarButton { | 104 + (instancetype)reloadToolbarButton { |
| 82 ToolbarButton* reloadButton = [self | 105 ToolbarButton* reloadButton = [self |
| 83 toolbarButtonWithImageForNormalState:NativeReversableImage( | 106 toolbarButtonWithImageForNormalState:NativeReversableImage( |
| 84 IDR_IOS_TOOLBAR_LIGHT_RELOAD, | 107 IDR_IOS_TOOLBAR_LIGHT_RELOAD, |
| 85 YES) | 108 YES) |
| 86 imageForHighlightedState: | 109 imageForHighlightedState: |
| 87 NativeReversableImage( | 110 NativeReversableImage( |
| 88 IDR_IOS_TOOLBAR_LIGHT_RELOAD_PRESSED, YES) | 111 IDR_IOS_TOOLBAR_LIGHT_RELOAD_PRESSED, YES) |
| 89 imageForDisabledState: | 112 imageForDisabledState: |
| 90 NativeReversableImage( | 113 NativeReversableImage( |
| 91 IDR_IOS_TOOLBAR_LIGHT_RELOAD_DISABLED, YES)]; | 114 IDR_IOS_TOOLBAR_LIGHT_RELOAD_DISABLED, YES)]; |
| 115 [reloadButton.widthAnchor constraintEqualToConstant:kToolbarButtonWidth] |
| 116 .active = YES; |
| 92 return reloadButton; | 117 return reloadButton; |
| 93 } | 118 } |
| 94 | 119 |
| 95 + (instancetype)stopToolbarButton { | 120 + (instancetype)stopToolbarButton { |
| 96 ToolbarButton* stopButton = [self | 121 ToolbarButton* stopButton = [self |
| 97 toolbarButtonWithImageForNormalState:NativeImage( | 122 toolbarButtonWithImageForNormalState:NativeImage( |
| 98 IDR_IOS_TOOLBAR_LIGHT_STOP) | 123 IDR_IOS_TOOLBAR_LIGHT_STOP) |
| 99 imageForHighlightedState: | 124 imageForHighlightedState: |
| 100 NativeImage(IDR_IOS_TOOLBAR_LIGHT_STOP_PRESSED) | 125 NativeImage(IDR_IOS_TOOLBAR_LIGHT_STOP_PRESSED) |
| 101 imageForDisabledState: | 126 imageForDisabledState: |
| 102 NativeImage(IDR_IOS_TOOLBAR_LIGHT_STOP_DISABLED)]; | 127 NativeImage(IDR_IOS_TOOLBAR_LIGHT_STOP_DISABLED)]; |
| 128 [stopButton.widthAnchor constraintEqualToConstant:kToolbarButtonWidth] |
| 129 .active = YES; |
| 103 return stopButton; | 130 return stopButton; |
| 104 } | 131 } |
| 105 | 132 |
| 106 @end | 133 @end |
| OLD | NEW |