| OLD | NEW |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 - (void)textfieldEditedOrActivated:(NSControl<AutofillInputField>*)field | 84 - (void)textfieldEditedOrActivated:(NSControl<AutofillInputField>*)field |
| 85 edited:(BOOL)edited; | 85 edited:(BOOL)edited; |
| 86 | 86 |
| 87 // Convenience method to retrieve a field type via the control's tag. | 87 // Convenience method to retrieve a field type via the control's tag. |
| 88 - (autofill::ServerFieldType)fieldTypeForControl:(NSControl*)control; | 88 - (autofill::ServerFieldType)fieldTypeForControl:(NSControl*)control; |
| 89 | 89 |
| 90 // Find the DetailInput* associated with a field type. | 90 // Find the DetailInput* associated with a field type. |
| 91 - (const autofill::DetailInput*)detailInputForType: | 91 - (const autofill::DetailInput*)detailInputForType: |
| 92 (autofill::ServerFieldType)type; | 92 (autofill::ServerFieldType)type; |
| 93 | 93 |
| 94 // Takes an NSArray of controls and builds a DetailOutputMap from them. | 94 // Takes an NSArray of controls and builds a FieldValueMap from them. |
| 95 // Translates between Cocoa code and delegate, essentially. | 95 // Translates between Cocoa code and delegate, essentially. |
| 96 // All controls must inherit from NSControl and conform to AutofillInputView. | 96 // All controls must inherit from NSControl and conform to AutofillInputView. |
| 97 - (void)fillDetailOutputs:(autofill::DetailOutputMap*)outputs | 97 - (void)fillDetailOutputs:(autofill::FieldValueMap*)outputs |
| 98 fromControls:(NSArray*)controls; | 98 fromControls:(NSArray*)controls; |
| 99 | 99 |
| 100 // Updates input fields based on delegate status. If |shouldClobber| is YES, | 100 // Updates input fields based on delegate status. If |shouldClobber| is YES, |
| 101 // will clobber existing data and reset fields to the initial values. | 101 // will clobber existing data and reset fields to the initial values. |
| 102 - (void)updateAndClobber:(BOOL)shouldClobber; | 102 - (void)updateAndClobber:(BOOL)shouldClobber; |
| 103 | 103 |
| 104 // Return YES if this is a section that contains CC info. (And, more | 104 // Return YES if this is a section that contains CC info. (And, more |
| 105 // importantly, a potential CVV field) | 105 // importantly, a potential CVV field) |
| 106 - (BOOL)isCreditCardSection; | 106 - (BOOL)isCreditCardSection; |
| 107 | 107 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 126 | 126 |
| 127 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate | 127 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate |
| 128 forSection:(autofill::DialogSection)section { | 128 forSection:(autofill::DialogSection)section { |
| 129 if (self = [super init]) { | 129 if (self = [super init]) { |
| 130 section_ = section; | 130 section_ = section; |
| 131 delegate_ = delegate; | 131 delegate_ = delegate; |
| 132 } | 132 } |
| 133 return self; | 133 return self; |
| 134 } | 134 } |
| 135 | 135 |
| 136 - (void)getInputs:(autofill::DetailOutputMap*)output { | 136 - (void)getInputs:(autofill::FieldValueMap*)output { |
| 137 [self fillDetailOutputs:output fromControls:[inputs_ subviews]]; | 137 [self fillDetailOutputs:output fromControls:[inputs_ subviews]]; |
| 138 } | 138 } |
| 139 | 139 |
| 140 // Note: This corresponds to Views' "UpdateDetailsGroupState". | 140 // Note: This corresponds to Views' "UpdateDetailsGroupState". |
| 141 - (void)modelChanged { | 141 - (void)modelChanged { |
| 142 ui::MenuModel* suggestionModel = delegate_->MenuModelForSection(section_); | 142 ui::MenuModel* suggestionModel = delegate_->MenuModelForSection(section_); |
| 143 menuController_.reset([[MenuController alloc] initWithModel:suggestionModel | 143 menuController_.reset([[MenuController alloc] initWithModel:suggestionModel |
| 144 useWithPopUpButtonCell:YES]); | 144 useWithPopUpButtonCell:YES]); |
| 145 NSMenu* menu = [menuController_ menu]; | 145 NSMenu* menu = [menuController_ menu]; |
| 146 | 146 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 fields = @[ [suggestContainer_ inputField] ]; | 348 fields = @[ [suggestContainer_ inputField] ]; |
| 349 } | 349 } |
| 350 | 350 |
| 351 // Ensure only editable fields are validated. | 351 // Ensure only editable fields are validated. |
| 352 fields = [fields filteredArrayUsingPredicate: | 352 fields = [fields filteredArrayUsingPredicate: |
| 353 [NSPredicate predicateWithBlock: | 353 [NSPredicate predicateWithBlock: |
| 354 ^BOOL(NSControl<AutofillInputField>* field, NSDictionary* bindings) { | 354 ^BOOL(NSControl<AutofillInputField>* field, NSDictionary* bindings) { |
| 355 return [field isEnabled]; | 355 return [field isEnabled]; |
| 356 }]]; | 356 }]]; |
| 357 | 357 |
| 358 autofill::DetailOutputMap detailOutputs; | 358 autofill::FieldValueMap detailOutputs; |
| 359 [self fillDetailOutputs:&detailOutputs fromControls:fields]; | 359 [self fillDetailOutputs:&detailOutputs fromControls:fields]; |
| 360 autofill::ValidityMessages messages = delegate_->InputsAreValid( | 360 autofill::ValidityMessages messages = delegate_->InputsAreValid( |
| 361 section_, detailOutputs); | 361 section_, detailOutputs); |
| 362 | 362 |
| 363 for (NSControl<AutofillInputField>* input in fields) { | 363 for (NSControl<AutofillInputField>* input in fields) { |
| 364 const autofill::ServerFieldType type = [self fieldTypeForControl:input]; | |
| 365 const autofill::ValidityMessage& message = | 364 const autofill::ValidityMessage& message = |
| 366 messages.GetMessageOrDefault(type); | 365 messages.GetMessageOrDefault([self fieldTypeForControl:input]); |
| 367 if (validationType != autofill::VALIDATE_FINAL && !message.sure) | 366 if (validationType != autofill::VALIDATE_FINAL && !message.sure) |
| 368 continue; | 367 continue; |
| 369 [input setValidityMessage:base::SysUTF16ToNSString(message.text)]; | 368 [input setValidityMessage:base::SysUTF16ToNSString(message.text)]; |
| 370 [validationDelegate_ updateMessageForField:input]; | 369 [validationDelegate_ updateMessageForField:input]; |
| 371 } | 370 } |
| 372 | 371 |
| 373 return !messages.HasErrors(); | 372 return !messages.HasErrors(); |
| 374 } | 373 } |
| 375 | 374 |
| 376 - (NSString*)suggestionText { | 375 - (NSString*)suggestionText { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 401 textFrameInScreen.origin = | 400 textFrameInScreen.origin = |
| 402 [[field window] convertBaseToScreen:textFrameInScreen.origin]; | 401 [[field window] convertBaseToScreen:textFrameInScreen.origin]; |
| 403 | 402 |
| 404 // And adjust for gfx::Rect being flipped compared to OSX coordinates. | 403 // And adjust for gfx::Rect being flipped compared to OSX coordinates. |
| 405 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 404 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 406 textFrameInScreen.origin.y = | 405 textFrameInScreen.origin.y = |
| 407 NSMaxY([screen frame]) - NSMaxY(textFrameInScreen); | 406 NSMaxY([screen frame]) - NSMaxY(textFrameInScreen); |
| 408 gfx::Rect textFrameRect(NSRectToCGRect(textFrameInScreen)); | 407 gfx::Rect textFrameRect(NSRectToCGRect(textFrameInScreen)); |
| 409 | 408 |
| 410 delegate_->UserEditedOrActivatedInput(section_, | 409 delegate_->UserEditedOrActivatedInput(section_, |
| 411 [self detailInputForType:type], | 410 type, |
| 412 [self view], | 411 [self view], |
| 413 textFrameRect, | 412 textFrameRect, |
| 414 fieldValue, | 413 fieldValue, |
| 415 edited); | 414 edited); |
| 416 | 415 |
| 417 // If the field is marked as invalid, check if the text is now valid. | 416 // If the field is marked as invalid, check if the text is now valid. |
| 418 // Many fields (i.e. CC#) are invalid for most of the duration of editing, | 417 // Many fields (i.e. CC#) are invalid for most of the duration of editing, |
| 419 // so flagging them as invalid prematurely is not helpful. However, | 418 // so flagging them as invalid prematurely is not helpful. However, |
| 420 // correcting a minor mistake (i.e. a wrong CC digit) should immediately | 419 // correcting a minor mistake (i.e. a wrong CC digit) should immediately |
| 421 // result in validation - positive user feedback. | 420 // result in validation - positive user feedback. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 446 (autofill::ServerFieldType)type { | 445 (autofill::ServerFieldType)type { |
| 447 for (size_t i = 0; i < detailInputs_.size(); ++i) { | 446 for (size_t i = 0; i < detailInputs_.size(); ++i) { |
| 448 if (detailInputs_[i]->type == type) | 447 if (detailInputs_[i]->type == type) |
| 449 return detailInputs_[i]; | 448 return detailInputs_[i]; |
| 450 } | 449 } |
| 451 // TODO(groby): Needs to be NOTREACHED. Can't, due to the fact that tests | 450 // TODO(groby): Needs to be NOTREACHED. Can't, due to the fact that tests |
| 452 // blindly call setFieldValue:forInput:, even for non-existing inputs. | 451 // blindly call setFieldValue:forInput:, even for non-existing inputs. |
| 453 return NULL; | 452 return NULL; |
| 454 } | 453 } |
| 455 | 454 |
| 456 - (void)fillDetailOutputs:(autofill::DetailOutputMap*)outputs | 455 - (void)fillDetailOutputs:(autofill::FieldValueMap*)outputs |
| 457 fromControls:(NSArray*)controls { | 456 fromControls:(NSArray*)controls { |
| 458 for (NSControl<AutofillInputField>* input in controls) { | 457 for (NSControl<AutofillInputField>* input in controls) { |
| 459 DCHECK([input isKindOfClass:[NSControl class]]); | 458 DCHECK([input isKindOfClass:[NSControl class]]); |
| 460 DCHECK([input conformsToProtocol:@protocol(AutofillInputField)]); | 459 DCHECK([input conformsToProtocol:@protocol(AutofillInputField)]); |
| 461 autofill::ServerFieldType fieldType = [self fieldTypeForControl:input]; | 460 outputs->insert(std::make_pair( |
| 462 DCHECK([self detailInputForType:fieldType]); | 461 [self fieldTypeForControl:input], |
| 463 NSString* value = [input fieldValue]; | 462 base::SysNSStringToUTF16([input fieldValue]))); |
| 464 outputs->insert(std::make_pair([self detailInputForType:fieldType], | |
| 465 base::SysNSStringToUTF16(value))); | |
| 466 } | 463 } |
| 467 } | 464 } |
| 468 | 465 |
| 469 - (NSTextField*)makeDetailSectionLabel:(NSString*)labelText { | 466 - (NSTextField*)makeDetailSectionLabel:(NSString*)labelText { |
| 470 base::scoped_nsobject<NSTextField> label([[NSTextField alloc] init]); | 467 base::scoped_nsobject<NSTextField> label([[NSTextField alloc] init]); |
| 471 [label setFont: | 468 [label setFont: |
| 472 [[NSFontManager sharedFontManager] convertFont:[label font] | 469 [[NSFontManager sharedFontManager] convertFont:[label font] |
| 473 toHaveTrait:NSBoldFontMask]]; | 470 toHaveTrait:NSBoldFontMask]]; |
| 474 [label setStringValue:labelText]; | 471 [label setStringValue:labelText]; |
| 475 [label setEditable:NO]; | 472 [label setEditable:NO]; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 - (void)activateFieldForInput:(const autofill::DetailInput&)input { | 649 - (void)activateFieldForInput:(const autofill::DetailInput&)input { |
| 653 if ([self detailInputForType:input.type] != &input) | 650 if ([self detailInputForType:input.type] != &input) |
| 654 return; | 651 return; |
| 655 | 652 |
| 656 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:input.type]; | 653 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:input.type]; |
| 657 [[field window] makeFirstResponder:field]; | 654 [[field window] makeFirstResponder:field]; |
| 658 [self textfieldEditedOrActivated:field edited:NO]; | 655 [self textfieldEditedOrActivated:field edited:NO]; |
| 659 } | 656 } |
| 660 | 657 |
| 661 @end | 658 @end |
| OLD | NEW |