| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 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/no_tabs/no_tabs_toolbar_controller.h" | |
| 6 | |
| 7 #include "base/mac/scoped_nsobject.h" | |
| 8 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | |
| 9 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | |
| 10 #import "ios/chrome/browser/ui/rtl_geometry.h" | |
| 11 #include "ios/chrome/browser/ui/toolbar/new_tab_button.h" | |
| 12 #import "ios/chrome/browser/ui/uikit_ui_util.h" | |
| 13 #import "ui/gfx/ios/uikit_util.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const CGFloat kNewTabButtonLeading = 8; | |
| 18 const CGFloat kModeToggleWidth = 34; | |
| 19 const CGFloat kModeToggleHeight = 38; | |
| 20 | |
| 21 } // end namespace | |
| 22 | |
| 23 @interface NoTabsToolbarController () { | |
| 24 // Top-level view for notabs-specific content. | |
| 25 base::scoped_nsobject<UIView> _noTabsToolbar; | |
| 26 base::scoped_nsobject<UIButton> _buttonNewTab; | |
| 27 base::scoped_nsobject<UIButton> _modeToggleButton; | |
| 28 } | |
| 29 | |
| 30 @end | |
| 31 | |
| 32 @implementation NoTabsToolbarController | |
| 33 | |
| 34 - (instancetype)initWithNoTabs { | |
| 35 self = [super initWithStyle:ToolbarControllerStyleDarkMode]; | |
| 36 if (self) { | |
| 37 _noTabsToolbar.reset([[UIView alloc] initWithFrame:self.view.bounds]); | |
| 38 [_noTabsToolbar setBackgroundColor:[UIColor clearColor]]; | |
| 39 [_noTabsToolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | |
| 40 UIViewAutoresizingFlexibleBottomMargin]; | |
| 41 | |
| 42 // Resize the container to match the available area. | |
| 43 // Do this before the layouts of subviews are computed. | |
| 44 [_noTabsToolbar setFrame:[self specificControlsArea]]; | |
| 45 | |
| 46 CGFloat boundingHeight = [_noTabsToolbar bounds].size.height; | |
| 47 CGFloat boundingWidth = [_noTabsToolbar bounds].size.width; | |
| 48 LayoutRect newTabButtonLayout = LayoutRectMake( | |
| 49 kNewTabButtonLeading, boundingWidth, 0, boundingHeight, boundingHeight); | |
| 50 _buttonNewTab.reset([[NewTabButton alloc] | |
| 51 initWithFrame:LayoutRectGetRect(newTabButtonLayout)]); | |
| 52 [_buttonNewTab | |
| 53 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin()]; | |
| 54 | |
| 55 LayoutRect modeToggleButtonLayout = LayoutRectMake( | |
| 56 boundingWidth - kModeToggleWidth - boundingHeight, boundingWidth, | |
| 57 ui::AlignValueToUpperPixel((boundingHeight - kModeToggleHeight) / 2), | |
| 58 kModeToggleWidth, kModeToggleHeight); | |
| 59 | |
| 60 _modeToggleButton.reset([[UIButton alloc] | |
| 61 initWithFrame:LayoutRectGetRect(modeToggleButtonLayout)]); | |
| 62 [_modeToggleButton setHidden:YES]; | |
| 63 [_modeToggleButton | |
| 64 setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin()]; | |
| 65 [_modeToggleButton setImageEdgeInsets:UIEdgeInsetsMakeDirected(7, 5, 7, 5)]; | |
| 66 [_modeToggleButton setImage:[UIImage imageNamed:@"tabstrip_switch"] | |
| 67 forState:UIControlStateNormal]; | |
| 68 [_modeToggleButton setTag:IDC_SWITCH_BROWSER_MODES]; | |
| 69 [_modeToggleButton addTarget:self | |
| 70 action:@selector(recordUserMetrics:) | |
| 71 forControlEvents:UIControlEventTouchUpInside]; | |
| 72 [_modeToggleButton addTarget:_modeToggleButton | |
| 73 action:@selector(chromeExecuteCommand:) | |
| 74 forControlEvents:UIControlEventTouchUpInside]; | |
| 75 | |
| 76 // The toolbar background is not supposed to show in the no-tabs UI. | |
| 77 [self.backgroundView setHidden:YES]; | |
| 78 | |
| 79 [self.view addSubview:_noTabsToolbar]; | |
| 80 [_noTabsToolbar addSubview:_buttonNewTab]; | |
| 81 [_noTabsToolbar addSubview:_modeToggleButton]; | |
| 82 | |
| 83 self.shadowView.hidden = YES; | |
| 84 } | |
| 85 return self; | |
| 86 } | |
| 87 | |
| 88 // Applies the given transform to this toolbar's controls. | |
| 89 - (void)setControlsTransform:(CGAffineTransform)transform { | |
| 90 [self setStandardControlsTransform:transform]; | |
| 91 [_buttonNewTab setTransform:transform]; | |
| 92 [_modeToggleButton setTransform:transform]; | |
| 93 } | |
| 94 | |
| 95 // Shows or hides the mode toggle switch. | |
| 96 - (void)setHasModeToggleSwitch:(BOOL)hasModeToggle { | |
| 97 [_modeToggleButton setHidden:!hasModeToggle]; | |
| 98 } | |
| 99 | |
| 100 // Called when a button is pressed. | |
| 101 - (void)recordUserMetrics:(id)sender { | |
| 102 if (sender == _buttonNewTab.get()) { | |
| 103 // TODO(rohitrao): Record metrics. http://crbug.com/437418 | |
| 104 } else if (sender == _modeToggleButton.get()) { | |
| 105 // TODO(rohitrao): Record metrics. http://crbug.com/437418 | |
| 106 } else { | |
| 107 [super recordUserMetrics:sender]; | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 - (UIButton*)modeToggleButton { | |
| 112 return _modeToggleButton; | |
| 113 } | |
| 114 | |
| 115 @end | |
| OLD | NEW |