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

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_section_container.mm

Issue 85863003: Change DetailOutputMap to FieldValueMap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" 5 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 - (void)textfieldEditedOrActivated:(NSControl<AutofillInputField>*)field 83 - (void)textfieldEditedOrActivated:(NSControl<AutofillInputField>*)field
84 edited:(BOOL)edited; 84 edited:(BOOL)edited;
85 85
86 // Convenience method to retrieve a field type via the control's tag. 86 // Convenience method to retrieve a field type via the control's tag.
87 - (autofill::ServerFieldType)fieldTypeForControl:(NSControl*)control; 87 - (autofill::ServerFieldType)fieldTypeForControl:(NSControl*)control;
88 88
89 // Find the DetailInput* associated with a field type. 89 // Find the DetailInput* associated with a field type.
90 - (const autofill::DetailInput*)detailInputForType: 90 - (const autofill::DetailInput*)detailInputForType:
91 (autofill::ServerFieldType)type; 91 (autofill::ServerFieldType)type;
92 92
93 // Takes an NSArray of controls and builds a DetailOutputMap from them. 93 // Takes an NSArray of controls and builds a FieldValueMap from them.
94 // Translates between Cocoa code and delegate, essentially. 94 // Translates between Cocoa code and delegate, essentially.
95 // All controls must inherit from NSControl and conform to AutofillInputView. 95 // All controls must inherit from NSControl and conform to AutofillInputView.
96 - (void)fillDetailOutputs:(autofill::DetailOutputMap*)outputs 96 - (void)fillDetailOutputs:(autofill::FieldValueMap*)outputs
97 fromControls:(NSArray*)controls; 97 fromControls:(NSArray*)controls;
98 98
99 // Updates input fields based on delegate status. If |shouldClobber| is YES, 99 // Updates input fields based on delegate status. If |shouldClobber| is YES,
100 // will clobber existing data and reset fields to the initial values. 100 // will clobber existing data and reset fields to the initial values.
101 - (void)updateAndClobber:(BOOL)shouldClobber; 101 - (void)updateAndClobber:(BOOL)shouldClobber;
102 102
103 // Return YES if this is a section that contains CC info. (And, more 103 // Return YES if this is a section that contains CC info. (And, more
104 // importantly, a potential CVV field) 104 // importantly, a potential CVV field)
105 - (BOOL)isCreditCardSection; 105 - (BOOL)isCreditCardSection;
106 106
(...skipping 18 matching lines...) Expand all
125 125
126 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate 126 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate
127 forSection:(autofill::DialogSection)section { 127 forSection:(autofill::DialogSection)section {
128 if (self = [super init]) { 128 if (self = [super init]) {
129 section_ = section; 129 section_ = section;
130 delegate_ = delegate; 130 delegate_ = delegate;
131 } 131 }
132 return self; 132 return self;
133 } 133 }
134 134
135 - (void)getInputs:(autofill::DetailOutputMap*)output { 135 - (void)getInputs:(autofill::FieldValueMap*)output {
136 [self fillDetailOutputs:output fromControls:[inputs_ subviews]]; 136 [self fillDetailOutputs:output fromControls:[inputs_ subviews]];
137 } 137 }
138 138
139 // Note: This corresponds to Views' "UpdateDetailsGroupState". 139 // Note: This corresponds to Views' "UpdateDetailsGroupState".
140 - (void)modelChanged { 140 - (void)modelChanged {
141 ui::MenuModel* suggestionModel = delegate_->MenuModelForSection(section_); 141 ui::MenuModel* suggestionModel = delegate_->MenuModelForSection(section_);
142 menuController_.reset([[MenuController alloc] initWithModel:suggestionModel 142 menuController_.reset([[MenuController alloc] initWithModel:suggestionModel
143 useWithPopUpButtonCell:YES]); 143 useWithPopUpButtonCell:YES]);
144 NSMenu* menu = [menuController_ menu]; 144 NSMenu* menu = [menuController_ menu];
145 145
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 fields = @[ [suggestContainer_ inputField] ]; 334 fields = @[ [suggestContainer_ inputField] ];
335 } 335 }
336 336
337 // Ensure only editable fields are validated. 337 // Ensure only editable fields are validated.
338 fields = [fields filteredArrayUsingPredicate: 338 fields = [fields filteredArrayUsingPredicate:
339 [NSPredicate predicateWithBlock: 339 [NSPredicate predicateWithBlock:
340 ^BOOL(NSControl<AutofillInputField>* field, NSDictionary* bindings) { 340 ^BOOL(NSControl<AutofillInputField>* field, NSDictionary* bindings) {
341 return [field isEnabled]; 341 return [field isEnabled];
342 }]]; 342 }]];
343 343
344 autofill::DetailOutputMap detailOutputs; 344 autofill::FieldValueMap detailOutputs;
345 [self fillDetailOutputs:&detailOutputs fromControls:fields]; 345 [self fillDetailOutputs:&detailOutputs fromControls:fields];
346 autofill::ValidityMessages messages = delegate_->InputsAreValid( 346 autofill::ValidityMessages messages = delegate_->InputsAreValid(
347 section_, detailOutputs); 347 section_, detailOutputs);
348 348
349 for (NSControl<AutofillInputField>* input in fields) { 349 for (NSControl<AutofillInputField>* input in fields) {
350 const autofill::ServerFieldType type = [self fieldTypeForControl:input];
351 const autofill::ValidityMessage& message = 350 const autofill::ValidityMessage& message =
352 messages.GetMessageOrDefault(type); 351 messages.GetMessageOrDefault([self fieldTypeForControl:input]);
353 if (validationType != autofill::VALIDATE_FINAL && !message.sure) 352 if (validationType != autofill::VALIDATE_FINAL && !message.sure)
354 continue; 353 continue;
355 [input setValidityMessage:base::SysUTF16ToNSString(message.text)]; 354 [input setValidityMessage:base::SysUTF16ToNSString(message.text)];
356 [validationDelegate_ updateMessageForField:input]; 355 [validationDelegate_ updateMessageForField:input];
357 } 356 }
358 357
359 return !messages.HasErrors(); 358 return !messages.HasErrors();
360 } 359 }
361 360
362 - (NSString*)suggestionText { 361 - (NSString*)suggestionText {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 (autofill::ServerFieldType)type { 431 (autofill::ServerFieldType)type {
433 for (size_t i = 0; i < detailInputs_.size(); ++i) { 432 for (size_t i = 0; i < detailInputs_.size(); ++i) {
434 if (detailInputs_[i]->type == type) 433 if (detailInputs_[i]->type == type)
435 return detailInputs_[i]; 434 return detailInputs_[i];
436 } 435 }
437 // TODO(groby): Needs to be NOTREACHED. Can't, due to the fact that tests 436 // TODO(groby): Needs to be NOTREACHED. Can't, due to the fact that tests
438 // blindly call setFieldValue:forInput:, even for non-existing inputs. 437 // blindly call setFieldValue:forInput:, even for non-existing inputs.
439 return NULL; 438 return NULL;
440 } 439 }
441 440
442 - (void)fillDetailOutputs:(autofill::DetailOutputMap*)outputs 441 - (void)fillDetailOutputs:(autofill::FieldValueMap*)outputs
443 fromControls:(NSArray*)controls { 442 fromControls:(NSArray*)controls {
444 for (NSControl<AutofillInputField>* input in controls) { 443 for (NSControl<AutofillInputField>* input in controls) {
445 DCHECK([input isKindOfClass:[NSControl class]]); 444 DCHECK([input isKindOfClass:[NSControl class]]);
446 DCHECK([input conformsToProtocol:@protocol(AutofillInputField)]); 445 DCHECK([input conformsToProtocol:@protocol(AutofillInputField)]);
447 autofill::ServerFieldType fieldType = [self fieldTypeForControl:input]; 446 outputs->insert(std::make_pair(
448 DCHECK([self detailInputForType:fieldType]); 447 [self fieldTypeForControl:input],
449 NSString* value = [input fieldValue]; 448 base::SysNSStringToUTF16([input fieldValue])));
450 outputs->insert(std::make_pair([self detailInputForType:fieldType],
451 base::SysNSStringToUTF16(value)));
452 } 449 }
453 } 450 }
454 451
455 - (NSTextField*)makeDetailSectionLabel:(NSString*)labelText { 452 - (NSTextField*)makeDetailSectionLabel:(NSString*)labelText {
456 base::scoped_nsobject<NSTextField> label([[NSTextField alloc] init]); 453 base::scoped_nsobject<NSTextField> label([[NSTextField alloc] init]);
457 [label setFont: 454 [label setFont:
458 [[NSFontManager sharedFontManager] convertFont:[label font] 455 [[NSFontManager sharedFontManager] convertFont:[label font]
459 toHaveTrait:NSBoldFontMask]]; 456 toHaveTrait:NSBoldFontMask]];
460 [label setStringValue:labelText]; 457 [label setStringValue:labelText];
461 [label setEditable:NO]; 458 [label setEditable:NO];
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 - (void)activateFieldForInput:(const autofill::DetailInput&)input { 635 - (void)activateFieldForInput:(const autofill::DetailInput&)input {
639 if ([self detailInputForType:input.type] != &input) 636 if ([self detailInputForType:input.type] != &input)
640 return; 637 return;
641 638
642 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:input.type]; 639 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:input.type];
643 [[field window] makeFirstResponder:field]; 640 [[field window] makeFirstResponder:field];
644 [self textfieldEditedOrActivated:field edited:NO]; 641 [self textfieldEditedOrActivated:field edited:NO];
645 } 642 }
646 643
647 @end 644 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698