| OLD | NEW |
| (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_address_view_controller_mac.h" | |
| 6 #include "base/mac_util.h" | |
| 7 #include "base/sys_string_conversions.h" | |
| 8 #import "chrome/browser/autofill/autofill_address_model_mac.h" | |
| 9 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" | |
| 10 #include "chrome/browser/autofill/autofill_profile.h" | |
| 11 #import "third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.h" | |
| 12 | |
| 13 @interface AutoFillAddressViewController (PrivateMethods) | |
| 14 - (void)labelChanged:(GTMKeyValueChangeNotification*)notification; | |
| 15 @end | |
| 16 | |
| 17 @implementation AutoFillAddressViewController | |
| 18 | |
| 19 @synthesize addressModel = addressModel_; | |
| 20 | |
| 21 - (id)initWithProfile:(const AutoFillProfile&)profile | |
| 22 disclosure:(NSCellStateValue)disclosureState | |
| 23 controller:(AutoFillDialogController*) parentController { | |
| 24 self = [super initWithNibName:@"AutoFillAddressFormView" | |
| 25 bundle:mac_util::MainAppBundle() | |
| 26 disclosure:disclosureState]; | |
| 27 if (self) { | |
| 28 // Pull in the view for initialization. | |
| 29 [self view]; | |
| 30 | |
| 31 // Create the model. | |
| 32 [self setAddressModel:[[[AutoFillAddressModel alloc] | |
| 33 initWithProfile:profile] autorelease]]; | |
| 34 | |
| 35 // We keep track of our parent controller for model-update purposes. | |
| 36 parentController_ = parentController; | |
| 37 | |
| 38 // Register |self| as observer so we can notify parent controller. See | |
| 39 // |labelChanged:| for details. | |
| 40 [addressModel_ gtm_addObserver:self | |
| 41 forKeyPath:@"label" | |
| 42 selector:@selector(labelChanged:) | |
| 43 userInfo:nil | |
| 44 options:0]; | |
| 45 } | |
| 46 return self; | |
| 47 } | |
| 48 | |
| 49 - (void)dealloc { | |
| 50 [addressModel_ gtm_removeObserver:self | |
| 51 forKeyPath:@"label" | |
| 52 selector:@selector(labelChanged:)]; | |
| 53 [addressModel_ release]; | |
| 54 [super dealloc]; | |
| 55 } | |
| 56 | |
| 57 // Override KVO method to notify parent controller when the address "label" | |
| 58 // changes. Credit card UI updates accordingly. | |
| 59 - (void)labelChanged:(GTMKeyValueChangeNotification*)notification { | |
| 60 [parentController_ notifyAddressChange:self]; | |
| 61 } | |
| 62 | |
| 63 - (IBAction)deleteAddress:(id)sender { | |
| 64 [parentController_ deleteAddress:self]; | |
| 65 } | |
| 66 | |
| 67 - (void)copyModelToProfile:(AutoFillProfile*)profile { | |
| 68 [addressModel_ copyModelToProfile:profile]; | |
| 69 } | |
| 70 | |
| 71 @end | |
| 72 | |
| 73 | |
| OLD | NEW |