Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: ios/chrome/browser/ui/toolbar/new_tab_button.mm

Issue 2588733002: Upstream Chrome on iOS source code [9/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/toolbar/new_tab_button.h"
6
7 #include "base/logging.h"
8 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
9 #import "ios/chrome/browser/ui/image_util.h"
10 #import "ios/chrome/browser/ui/rtl_geometry.h"
11 #import "ios/chrome/browser/ui/uikit_ui_util.h"
12 #import "ios/chrome/common/material_timing.h"
13 #include "ios/chrome/grit/ios_strings.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/l10n/l10n_util_mac.h"
16
17 namespace {
18 // Amount by which to inset the button's content.
19 const CGFloat kContentInset = 6.0;
20
21 // Duration of transition animation.
22 const NSTimeInterval kNewTabButtonTransitionDuration =
23 ios::material::kDuration1;
24 }
25
26 @implementation NewTabButton
27
28 @synthesize incognito = _incognito;
29
30 - (instancetype)initWithFrame:(CGRect)frame {
31 if (self = [super initWithFrame:frame]) {
32 self.incognito = NO;
33
34 [self addTarget:self
35 action:@selector(chromeExecuteCommand:)
36 forControlEvents:UIControlEventTouchUpInside];
37
38 [self
39 setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, kContentInset, 0, 0)];
40 [self setContentHorizontalAlignment:
41 UseRTLLayout() ? UIControlContentHorizontalAlignmentRight
42 : UIControlContentHorizontalAlignmentLeft];
43 }
44 return self;
45 }
46
47 - (void)setIncognito:(BOOL)incognito {
48 self.tag = incognito ? IDC_NEW_INCOGNITO_TAB : IDC_NEW_TAB;
49 NSString* normalImageName = @"toolbar_dark_newtab";
50 NSString* activeImageName = @"toolbar_dark_newtab_active";
51 if (incognito) {
52 SetA11yLabelAndUiAutomationName(self, IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB,
53 @"New Incognito Tab");
54 normalImageName = @"toolbar_dark_newtab_incognito";
55 activeImageName = @"toolbar_dark_newtab_incognito_active";
56 } else {
57 SetA11yLabelAndUiAutomationName(self, IDS_IOS_TOOLS_MENU_NEW_TAB,
58 @"New Tab");
59 }
60 [self setImage:[UIImage imageNamed:normalImageName]
61 forState:UIControlStateNormal];
62 [self setImage:[UIImage imageNamed:activeImageName]
63 forState:UIControlStateHighlighted];
64 _incognito = incognito;
65 }
66
67 - (void)setIncognito:(BOOL)incognito animated:(BOOL)animated {
68 if (self.isIncognito == incognito)
69 return;
70
71 if (animated) {
72 [UIView transitionWithView:self
73 duration:kNewTabButtonTransitionDuration
74 options:UIViewAnimationOptionTransitionCrossDissolve
75 animations:^{
76 self.incognito = incognito;
77 }
78 completion:nil];
79 } else {
80 self.incognito = incognito;
81 }
82 }
83
84 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/toolbar/new_tab_button.h ('k') | ios/chrome/browser/ui/toolbar/test_toolbar_model_ios.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698