| 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 |
| 15 using base::UserMetricsAction; | 19 using base::UserMetricsAction; |
| 16 | 20 |
| 17 namespace { | 21 namespace { |
| 18 const CGFloat kNewTabLeadingOffset = 10.0; | 22 const CGFloat kNewTabLeadingOffset = 10.0; |
| 19 const int kBackgroundViewColor = 0x282C32; | 23 const int kBackgroundViewColor = 0x282C32; |
| 20 const CGFloat kBackgroundViewColorAlpha = 0.95; | 24 const CGFloat kBackgroundViewColorAlpha = 0.95; |
| 21 } | 25 } |
| 22 | 26 |
| 23 @implementation StackViewToolbarController { | 27 @implementation StackViewToolbarController { |
| 24 base::scoped_nsobject<UIView> _stackViewToolbar; | 28 UIView* _stackViewToolbar; |
| 25 base::scoped_nsobject<NewTabButton> _openNewTabButton; | 29 NewTabButton* _openNewTabButton; |
| 26 } | 30 } |
| 27 | 31 |
| 28 - (instancetype)initWithStackViewToolbar { | 32 - (instancetype)initWithStackViewToolbar { |
| 29 self = [super initWithStyle:ToolbarControllerStyleDarkMode]; | 33 self = [super initWithStyle:ToolbarControllerStyleDarkMode]; |
| 30 if (self) { | 34 if (self) { |
| 31 _stackViewToolbar.reset( | 35 _stackViewToolbar = |
| 32 [[UIView alloc] initWithFrame:[self specificControlsArea]]); | 36 [[UIView alloc] initWithFrame:[self specificControlsArea]]; |
| 33 [_stackViewToolbar setAutoresizingMask:UIViewAutoresizingFlexibleHeight | | 37 [_stackViewToolbar setAutoresizingMask:UIViewAutoresizingFlexibleHeight | |
| 34 UIViewAutoresizingFlexibleWidth]; | 38 UIViewAutoresizingFlexibleWidth]; |
| 35 | 39 |
| 36 _openNewTabButton.reset([[NewTabButton alloc] initWithFrame:CGRectZero]); | 40 _openNewTabButton = [[NewTabButton alloc] initWithFrame:CGRectZero]; |
| 37 | 41 |
| 38 [_openNewTabButton | 42 [_openNewTabButton |
| 39 setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | | 43 setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | |
| 40 UIViewAutoresizingFlexibleTrailingMargin()]; | 44 UIViewAutoresizingFlexibleTrailingMargin()]; |
| 41 CGFloat buttonSize = [_stackViewToolbar bounds].size.height; | 45 CGFloat buttonSize = [_stackViewToolbar bounds].size.height; |
| 42 // Set the button's position. | 46 // Set the button's position. |
| 43 LayoutRect newTabButtonLayout = LayoutRectMake( | 47 LayoutRect newTabButtonLayout = LayoutRectMake( |
| 44 kNewTabLeadingOffset, [_stackViewToolbar bounds].size.width, 0, | 48 kNewTabLeadingOffset, [_stackViewToolbar bounds].size.width, 0, |
| 45 buttonSize, buttonSize); | 49 buttonSize, buttonSize); |
| 46 [_openNewTabButton setFrame:LayoutRectGetRect(newTabButtonLayout)]; | 50 [_openNewTabButton setFrame:LayoutRectGetRect(newTabButtonLayout)]; |
| 47 // Set additional button action. | 51 // Set additional button action. |
| 48 [_openNewTabButton addTarget:self | 52 [_openNewTabButton addTarget:self |
| 49 action:@selector(recordUserMetrics:) | 53 action:@selector(recordUserMetrics:) |
| 50 forControlEvents:UIControlEventTouchUpInside]; | 54 forControlEvents:UIControlEventTouchUpInside]; |
| 51 | 55 |
| 52 self.shadowView.alpha = 0.0; | 56 self.shadowView.alpha = 0.0; |
| 53 self.backgroundView.image = nil; | 57 self.backgroundView.image = nil; |
| 54 self.backgroundView.backgroundColor = | 58 self.backgroundView.backgroundColor = |
| 55 UIColorFromRGB(kBackgroundViewColor, kBackgroundViewColorAlpha); | 59 UIColorFromRGB(kBackgroundViewColor, kBackgroundViewColorAlpha); |
| 56 | 60 |
| 57 [_stackViewToolbar addSubview:_openNewTabButton]; | 61 [_stackViewToolbar addSubview:_openNewTabButton]; |
| 58 [self.view addSubview:_stackViewToolbar]; | 62 [self.view addSubview:_stackViewToolbar]; |
| 59 } | 63 } |
| 60 return self; | 64 return self; |
| 61 } | 65 } |
| 62 | 66 |
| 63 - (NewTabButton*)openNewTabButton { | 67 - (NewTabButton*)openNewTabButton { |
| 64 return _openNewTabButton.get(); | 68 return _openNewTabButton; |
| 65 } | 69 } |
| 66 | 70 |
| 67 - (IBAction)recordUserMetrics:(id)sender { | 71 - (IBAction)recordUserMetrics:(id)sender { |
| 68 if (sender == _openNewTabButton.get()) | 72 if (sender == _openNewTabButton) |
| 69 base::RecordAction(UserMetricsAction("MobileToolbarStackViewNewTab")); | 73 base::RecordAction(UserMetricsAction("MobileToolbarStackViewNewTab")); |
| 70 else | 74 else |
| 71 [super recordUserMetrics:sender]; | 75 [super recordUserMetrics:sender]; |
| 72 } | 76 } |
| 73 | 77 |
| 74 @end | 78 @end |
| OLD | NEW |