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

Side by Side Diff: chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.mm

Issue 6621076: [Mac] Remove native/Cocoa preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase switch removal Created 9 years, 9 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h"
6
7 #include "base/mac/mac_util.h"
8 #include "base/sys_string_conversions.h"
9 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h"
10 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h"
11 #include "chrome/browser/autofill/credit_card.h"
12 #include "grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util.h"
14
15 // Interface exposed for unit testing.
16 @implementation AutoFillCreditCardSheetController (ExposedForUnitTests)
17 - (NSTextField*)creditCardNumberField {
18 return creditCardNumberField_;
19 }
20 @end
21
22 // Private methods for the |AutoFillCreditCardSheetController| class.
23 @interface AutoFillCreditCardSheetController (PrivateMethods)
24 - (void)buildExpirationMonthContents;
25 - (void)buildExpirationYearContents;
26 @end
27
28 @implementation AutoFillCreditCardSheetController
29
30 @synthesize creditCardModel = creditCardModel_;
31 @synthesize expirationMonthContents = expirationMonthContents_;
32 @synthesize expirationYearContents = expirationYearContents_;
33
34 - (id)initWithCreditCard:(const CreditCard&)creditCard
35 mode:(AutoFillCreditCardMode)mode {
36 NSString* nibPath = [base::mac::MainAppBundle()
37 pathForResource:@"AutoFillCreditCardSheet"
38 ofType:@"nib"];
39 self = [super initWithWindowNibPath:nibPath owner:self];
40 if (self) {
41 // Create the model. We use setter here for KVO.
42 [self setCreditCardModel:[[[AutoFillCreditCardModel alloc]
43 initWithCreditCard:creditCard] autorelease]];
44
45 mode_ = mode;
46 }
47 return self;
48 }
49
50 - (void)dealloc {
51 [creditCardModel_ release];
52 [expirationMonthContents_ release];
53 [expirationYearContents_ release];
54 [super dealloc];
55 }
56
57 - (void)awakeFromNib {
58 // Setup initial state of popups.
59 [self buildExpirationMonthContents];
60 [self buildExpirationYearContents];
61
62 // Turn menu autoenable off. We manually govern this.
63 [expirationMonthPopup_ setAutoenablesItems:NO];
64 [expirationYearPopup_ setAutoenablesItems:NO];
65
66 // Set the caption based on the mode.
67 NSString* caption = @"";
68 if (mode_ == kAutoFillCreditCardAddMode)
69 caption = l10n_util::GetNSString(IDS_AUTOFILL_ADD_CREDITCARD_CAPTION);
70 else if (mode_ == kAutoFillCreditCardEditMode)
71 caption = l10n_util::GetNSString(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION);
72 else
73 NOTREACHED();
74 [caption_ setStringValue:caption];
75 }
76
77 - (IBAction)save:(id)sender {
78 // Call |makeFirstResponder:| to commit pending text field edits.
79 [[self window] makeFirstResponder:[self window]];
80
81 [NSApp endSheet:[self window] returnCode:1];
82 }
83
84 - (IBAction)cancel:(id)sender {
85 [NSApp endSheet:[self window] returnCode:0];
86 }
87
88 - (void)copyModelToCreditCard:(CreditCard*)creditCard {
89 // The model copies the popup values blindly. We need to clear the strings
90 // in the case that our special menus are in effect.
91 if ([expirationMonthPopup_ indexOfSelectedItem] <= 0)
92 [creditCardModel_ setExpirationMonth:@""];
93 if ([expirationYearPopup_ indexOfSelectedItem] <= 0)
94 [creditCardModel_ setExpirationYear:@""];
95
96 [creditCardModel_ copyModelToCreditCard:creditCard];
97 }
98
99 // Builds array of valid months. Uses special @" " to indicate no selection.
100 - (void)buildExpirationMonthContents {
101 NSArray* newArray = [NSArray arrayWithObjects:@" ",
102 @"01", @"02", @"03", @"04", @"05", @"06",
103 @"07", @"08", @"09", @"10", @"11", @"12", nil ];
104
105 [self setExpirationMonthContents:newArray];
106
107 // If the value from the model is not found in the array then set to the empty
108 // item @" ".
109 if ([newArray
110 indexOfObject:[creditCardModel_ expirationMonth]] == NSNotFound) {
111 [creditCardModel_ setExpirationMonth:@" "];
112 }
113
114 // Disable first item in menu. @" " is a non-item.
115 [[expirationMonthPopup_ itemAtIndex:0] setEnabled:NO];
116 }
117
118 // Builds array of valid years. Uses special @" " to indicate no selection.
119 - (void)buildExpirationYearContents {
120 NSArray* newArray = [NSArray arrayWithObjects:@" ",
121 @"2010", @"2011", @"2012", @"2013", @"2014", @"2015",
122 @"2016", @"2017", @"2018", @"2019", @"2020", nil ];
123
124 [self setExpirationYearContents:newArray];
125
126 // If the value from the model is not found in the array then set to the empty
127 // item @" ".
128 if ([newArray
129 indexOfObject:[creditCardModel_ expirationYear]] == NSNotFound) {
130 [creditCardModel_ setExpirationYear:@" "];
131 }
132
133 // Disable first item in menu. @" " is a non-item.
134 [[expirationYearPopup_ itemAtIndex:0] setEnabled:NO];
135 }
136
137 @end
138
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698