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