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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/toolbar/new_tab_button.mm
diff --git a/ios/chrome/browser/ui/toolbar/new_tab_button.mm b/ios/chrome/browser/ui/toolbar/new_tab_button.mm
new file mode 100644
index 0000000000000000000000000000000000000000..29994c28b8cf94584e65bcf47d75b3c6ca408baf
--- /dev/null
+++ b/ios/chrome/browser/ui/toolbar/new_tab_button.mm
@@ -0,0 +1,84 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/ui/toolbar/new_tab_button.h"
+
+#include "base/logging.h"
+#include "ios/chrome/browser/ui/commands/ios_command_ids.h"
+#import "ios/chrome/browser/ui/image_util.h"
+#import "ios/chrome/browser/ui/rtl_geometry.h"
+#import "ios/chrome/browser/ui/uikit_ui_util.h"
+#import "ios/chrome/common/material_timing.h"
+#include "ios/chrome/grit/ios_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/l10n/l10n_util_mac.h"
+
+namespace {
+// Amount by which to inset the button's content.
+const CGFloat kContentInset = 6.0;
+
+// Duration of transition animation.
+const NSTimeInterval kNewTabButtonTransitionDuration =
+ ios::material::kDuration1;
+}
+
+@implementation NewTabButton
+
+@synthesize incognito = _incognito;
+
+- (instancetype)initWithFrame:(CGRect)frame {
+ if (self = [super initWithFrame:frame]) {
+ self.incognito = NO;
+
+ [self addTarget:self
+ action:@selector(chromeExecuteCommand:)
+ forControlEvents:UIControlEventTouchUpInside];
+
+ [self
+ setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, kContentInset, 0, 0)];
+ [self setContentHorizontalAlignment:
+ UseRTLLayout() ? UIControlContentHorizontalAlignmentRight
+ : UIControlContentHorizontalAlignmentLeft];
+ }
+ return self;
+}
+
+- (void)setIncognito:(BOOL)incognito {
+ self.tag = incognito ? IDC_NEW_INCOGNITO_TAB : IDC_NEW_TAB;
+ NSString* normalImageName = @"toolbar_dark_newtab";
+ NSString* activeImageName = @"toolbar_dark_newtab_active";
+ if (incognito) {
+ SetA11yLabelAndUiAutomationName(self, IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB,
+ @"New Incognito Tab");
+ normalImageName = @"toolbar_dark_newtab_incognito";
+ activeImageName = @"toolbar_dark_newtab_incognito_active";
+ } else {
+ SetA11yLabelAndUiAutomationName(self, IDS_IOS_TOOLS_MENU_NEW_TAB,
+ @"New Tab");
+ }
+ [self setImage:[UIImage imageNamed:normalImageName]
+ forState:UIControlStateNormal];
+ [self setImage:[UIImage imageNamed:activeImageName]
+ forState:UIControlStateHighlighted];
+ _incognito = incognito;
+}
+
+- (void)setIncognito:(BOOL)incognito animated:(BOOL)animated {
+ if (self.isIncognito == incognito)
+ return;
+
+ if (animated) {
+ [UIView transitionWithView:self
+ duration:kNewTabButtonTransitionDuration
+ options:UIViewAnimationOptionTransitionCrossDissolve
+ animations:^{
+ self.incognito = incognito;
+ }
+ completion:nil];
+ } else {
+ self.incognito = incognito;
+ }
+}
+
+@end
« 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