| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/chrome/browser/ui/stack_view/stack_view_toolbar_controller.h" | 5 #import "ios/chrome/browser/ui/stack_view/stack_view_toolbar_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
| 9 #include "base/metrics/user_metrics_action.h" | 9 #include "base/metrics/user_metrics_action.h" |
| 10 #import "ios/chrome/browser/ui/image_util.h" | 10 #import "ios/chrome/browser/ui/image_util.h" |
| 11 #import "ios/chrome/browser/ui/rtl_geometry.h" | 11 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 12 #include "ios/chrome/browser/ui/toolbar/new_tab_button.h" | 12 #include "ios/chrome/browser/ui/toolbar/new_tab_button.h" |
| 13 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 13 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 14 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 16 #error "This file requires ARC support." | |
| 17 #endif | |
| 18 | |
| 19 using base::UserMetricsAction; | 15 using base::UserMetricsAction; |
| 20 | 16 |
| 21 namespace { | 17 namespace { |
| 22 const CGFloat kNewTabLeadingOffset = 10.0; | 18 const CGFloat kNewTabLeadingOffset = 10.0; |
| 23 const int kBackgroundViewColor = 0x282C32; | 19 const int kBackgroundViewColor = 0x282C32; |
| 24 const CGFloat kBackgroundViewColorAlpha = 0.95; | 20 const CGFloat kBackgroundViewColorAlpha = 0.95; |
| 25 } | 21 } |
| 26 | 22 |
| 27 @implementation StackViewToolbarController { | 23 @implementation StackViewToolbarController { |
| 28 UIView* _stackViewToolbar; | 24 base::scoped_nsobject<UIView> _stackViewToolbar; |
| 29 NewTabButton* _openNewTabButton; | 25 base::scoped_nsobject<NewTabButton> _openNewTabButton; |
| 30 } | 26 } |
| 31 | 27 |
| 32 - (instancetype)initWithStackViewToolbar { | 28 - (instancetype)initWithStackViewToolbar { |
| 33 self = [super initWithStyle:ToolbarControllerStyleDarkMode]; | 29 self = [super initWithStyle:ToolbarControllerStyleDarkMode]; |
| 34 if (self) { | 30 if (self) { |
| 35 _stackViewToolbar = | 31 _stackViewToolbar.reset( |
| 36 [[UIView alloc] initWithFrame:[self specificControlsArea]]; | 32 [[UIView alloc] initWithFrame:[self specificControlsArea]]); |
| 37 [_stackViewToolbar setAutoresizingMask:UIViewAutoresizingFlexibleHeight | | 33 [_stackViewToolbar setAutoresizingMask:UIViewAutoresizingFlexibleHeight | |
| 38 UIViewAutoresizingFlexibleWidth]; | 34 UIViewAutoresizingFlexibleWidth]; |
| 39 | 35 |
| 40 _openNewTabButton = [[NewTabButton alloc] initWithFrame:CGRectZero]; | 36 _openNewTabButton.reset([[NewTabButton alloc] initWithFrame:CGRectZero]); |
| 41 | 37 |
| 42 [_openNewTabButton | 38 [_openNewTabButton |
| 43 setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | | 39 setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | |
| 44 UIViewAutoresizingFlexibleTrailingMargin()]; | 40 UIViewAutoresizingFlexibleTrailingMargin()]; |
| 45 CGFloat buttonSize = [_stackViewToolbar bounds].size.height; | 41 CGFloat buttonSize = [_stackViewToolbar bounds].size.height; |
| 46 // Set the button's position. | 42 // Set the button's position. |
| 47 LayoutRect newTabButtonLayout = LayoutRectMake( | 43 LayoutRect newTabButtonLayout = LayoutRectMake( |
| 48 kNewTabLeadingOffset, [_stackViewToolbar bounds].size.width, 0, | 44 kNewTabLeadingOffset, [_stackViewToolbar bounds].size.width, 0, |
| 49 buttonSize, buttonSize); | 45 buttonSize, buttonSize); |
| 50 [_openNewTabButton setFrame:LayoutRectGetRect(newTabButtonLayout)]; | 46 [_openNewTabButton setFrame:LayoutRectGetRect(newTabButtonLayout)]; |
| 51 // Set additional button action. | 47 // Set additional button action. |
| 52 [_openNewTabButton addTarget:self | 48 [_openNewTabButton addTarget:self |
| 53 action:@selector(recordUserMetrics:) | 49 action:@selector(recordUserMetrics:) |
| 54 forControlEvents:UIControlEventTouchUpInside]; | 50 forControlEvents:UIControlEventTouchUpInside]; |
| 55 | 51 |
| 56 self.shadowView.alpha = 0.0; | 52 self.shadowView.alpha = 0.0; |
| 57 self.backgroundView.image = nil; | 53 self.backgroundView.image = nil; |
| 58 self.backgroundView.backgroundColor = | 54 self.backgroundView.backgroundColor = |
| 59 UIColorFromRGB(kBackgroundViewColor, kBackgroundViewColorAlpha); | 55 UIColorFromRGB(kBackgroundViewColor, kBackgroundViewColorAlpha); |
| 60 | 56 |
| 61 [_stackViewToolbar addSubview:_openNewTabButton]; | 57 [_stackViewToolbar addSubview:_openNewTabButton]; |
| 62 [self.view addSubview:_stackViewToolbar]; | 58 [self.view addSubview:_stackViewToolbar]; |
| 63 } | 59 } |
| 64 return self; | 60 return self; |
| 65 } | 61 } |
| 66 | 62 |
| 67 - (NewTabButton*)openNewTabButton { | 63 - (NewTabButton*)openNewTabButton { |
| 68 return _openNewTabButton; | 64 return _openNewTabButton.get(); |
| 69 } | 65 } |
| 70 | 66 |
| 71 - (IBAction)recordUserMetrics:(id)sender { | 67 - (IBAction)recordUserMetrics:(id)sender { |
| 72 if (sender == _openNewTabButton) | 68 if (sender == _openNewTabButton.get()) |
| 73 base::RecordAction(UserMetricsAction("MobileToolbarStackViewNewTab")); | 69 base::RecordAction(UserMetricsAction("MobileToolbarStackViewNewTab")); |
| 74 else | 70 else |
| 75 [super recordUserMetrics:sender]; | 71 [super recordUserMetrics:sender]; |
| 76 } | 72 } |
| 77 | 73 |
| 78 @end | 74 @end |
| OLD | NEW |