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

Unified Diff: ios/chrome/browser/ui/fancy_ui/tinted_button.mm

Issue 2590473002: Upstream Chrome on iOS source code [5/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
« no previous file with comments | « no previous file | ios/chrome/browser/ui/file_locations_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/fancy_ui/tinted_button.mm
diff --git a/ios/chrome/browser/ui/fancy_ui/tinted_button.mm b/ios/chrome/browser/ui/fancy_ui/tinted_button.mm
new file mode 100644
index 0000000000000000000000000000000000000000..6df8475d9a34664d8726e560f404f22b3efd30b1
--- /dev/null
+++ b/ios/chrome/browser/ui/fancy_ui/tinted_button.mm
@@ -0,0 +1,65 @@
+// Copyright 2016 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.
+
+#include "ios/chrome/browser/ui/fancy_ui/tinted_button.h"
+
+#import "base/mac/scoped_nsobject.h"
+
+@interface TintedButton () {
+ base::scoped_nsobject<UIColor> normalStateTint_;
+ base::scoped_nsobject<UIColor> highlightedTint_;
+}
+
+// Makes the button's tint color reflect its current state.
+- (void)updateTint;
+
+@end
+
+@implementation TintedButton
+
+- (void)setTintColor:(UIColor*)color forState:(UIControlState)state {
+ switch (state) {
+ case UIControlStateNormal:
+ normalStateTint_.reset([color copy]);
+ break;
+ case UIControlStateHighlighted:
+ highlightedTint_.reset([color copy]);
+ break;
+ default:
+ return;
+ }
+
+ if (normalStateTint_ || highlightedTint_)
+ self.adjustsImageWhenHighlighted = NO;
+ else
+ self.adjustsImageWhenHighlighted = YES;
+ [self updateTint];
+}
+
+#pragma mark - UIControl
+
+- (void)setHighlighted:(BOOL)highlighted {
+ [super setHighlighted:highlighted];
+ [self updateTint];
+}
+
+#pragma mark - Private
+
+- (void)updateTint {
+ UIColor* newTint = nil;
+ switch (self.state) {
+ case UIControlStateNormal:
+ newTint = normalStateTint_.get();
+ break;
+ case UIControlStateHighlighted:
+ newTint = highlightedTint_.get();
+ break;
+ default:
+ newTint = normalStateTint_.get();
+ break;
+ }
+ self.tintColor = newTint;
+}
+
+@end
« no previous file with comments | « no previous file | ios/chrome/browser/ui/file_locations_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698