Chromium Code Reviews| Index: chrome/browser/ui/cocoa/autofill/autofill_section_container.mm |
| diff --git a/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm b/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm |
| index d67a1b3b5fca636ad9ba70ce9bae75476568bdc7..351bf74369331f6d16f784e0095185193259b261 100644 |
| --- a/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm |
| +++ b/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm |
| @@ -104,8 +104,8 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, |
| // Create a button offering input suggestions. |
| - (MenuButton*)makeSuggestionButton; |
| -// Create a view with all inputs requested by |delegate_|. Autoreleased. |
| -- (LayoutView*)makeInputControls; |
| +// Create a view with all inputs requested by |delegate_| and resets |input_|. |
| +- (void)makeInputControls; |
| // Refresh all field icons based on |delegate_| status. |
| - (void)updateFieldIcons; |
| @@ -159,27 +159,8 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, |
| } |
| - (void)loadView { |
| - // Keep a list of weak pointers to DetailInputs. |
| - const autofill::DetailInputs& inputs = |
| - delegate_->RequestedFieldsForSection(section_); |
| - |
| - // Reverse the order of all the inputs. |
| - for (int i = inputs.size() - 1; i >= 0; --i) { |
| - detailInputs_.push_back(&(inputs[i])); |
| - } |
| - |
| - // Then right the reversal in each row. |
| - std::vector<const autofill::DetailInput*>::iterator it; |
| - for (it = detailInputs_.begin(); it < detailInputs_.end(); ++it) { |
| - std::vector<const autofill::DetailInput*>::iterator start = it; |
| - while (it != detailInputs_.end() && |
| - (*it)->length != autofill::DetailInput::LONG) { |
| - ++it; |
| - } |
| - std::reverse(start, it); |
| - } |
| + [self makeInputControls]; |
| - inputs_.reset([[self makeInputControls] retain]); |
| base::string16 labelText = delegate_->LabelForSection(section_); |
| label_.reset( |
| [[self makeDetailSectionLabel:base::SysUTF16ToNSString(labelText)] |
| @@ -303,6 +284,14 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, |
| - (void)didEndEditing:(id)sender { |
| delegate_->FocusMoved(); |
| [validationDelegate_ hideErrorBubble]; |
| + |
| + AutofillPopUpButton* popup = base::mac::ObjCCast<AutofillPopUpButton>(sender); |
| + if (popup) { |
|
groby-ooo-7-16
2014/01/10 01:56:38
If you must get a separate popup notification, I'd
Dan Beam
2014/01/11 04:16:58
see updated code
|
| + // Add one to account for the spacer at the top of the list. |
| + int index = [popup indexOfSelectedItem] + 1; |
| + delegate_->ComboboxItemSelected([self fieldTypeForControl:popup], index); |
| + } |
| + |
| [self validateFor:autofill::VALIDATE_EDIT]; |
| [self updateEditability]; |
| } |
| @@ -514,23 +503,28 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, |
| } |
| - (void)updateAndClobber:(BOOL)shouldClobber { |
| - const autofill::DetailInputs& updatedInputs = |
| - delegate_->RequestedFieldsForSection(section_); |
| + if (shouldClobber) { |
|
groby-ooo-7-16
2014/01/10 01:56:38
I'd prefer to not rebuild the entire layout whenev
Dan Beam
2014/01/11 04:16:58
we talked about this and will wait until it's noti
|
| + [self makeInputControls]; |
|
groby-ooo-7-16
2014/01/10 01:56:38
Also, you presumably want to request a relayout he
Dan Beam
2014/01/11 04:16:58
Done.
|
| + } else { |
| + const autofill::DetailInputs& updatedInputs = |
| + delegate_->RequestedFieldsForSection(section_); |
| - for (autofill::DetailInputs::const_iterator iter = updatedInputs.begin(); |
| - iter != updatedInputs.end(); |
| - ++iter) { |
| - NSControl<AutofillInputField>* field = [inputs_ viewWithTag:iter->type]; |
| - DCHECK(field); |
| + for (autofill::DetailInputs::const_iterator iter = updatedInputs.begin(); |
| + iter != updatedInputs.end(); |
| + ++iter) { |
| + NSControl<AutofillInputField>* field = [inputs_ viewWithTag:iter->type]; |
| + DCHECK(field); |
| - if (shouldClobber || [field isDefault]) { |
| - [field setFieldValue:base::SysUTF16ToNSString(iter->initial_value)]; |
| + if (shouldClobber || [field isDefault]) { |
| + [field setFieldValue:base::SysUTF16ToNSString(iter->initial_value)]; |
| + } |
| + if (shouldClobber) |
|
groby-ooo-7-16
2014/01/10 01:56:38
How could shouldClobber ever be true here? You're
Dan Beam
2014/01/11 04:16:58
copy pasta, removed
|
| + [field setValidityMessage:@""]; |
| } |
| - if (shouldClobber) |
| - [field setValidityMessage:@""]; |
| + [self updateFieldIcons]; |
| } |
| + |
| [self updateEditability]; |
| - [self updateFieldIcons]; |
| [self modelChanged]; |
| } |
| @@ -571,7 +565,29 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, |
| // TODO(estade): we should be using Chrome-style constrained window padding |
| // values. |
| -- (LayoutView*)makeInputControls { |
| +- (void)makeInputControls { |
| + detailInputs_.clear(); |
| + |
| + // Keep a list of weak pointers to DetailInputs. |
| + const autofill::DetailInputs& inputs = |
| + delegate_->RequestedFieldsForSection(section_); |
| + |
| + // Reverse the order of all the inputs. |
| + for (int i = inputs.size() - 1; i >= 0; --i) { |
| + detailInputs_.push_back(&(inputs[i])); |
| + } |
| + |
| + // Then right the reversal in each row. |
| + std::vector<const autofill::DetailInput*>::iterator it; |
| + for (it = detailInputs_.begin(); it < detailInputs_.end(); ++it) { |
| + std::vector<const autofill::DetailInput*>::iterator start = it; |
| + while (it != detailInputs_.end() && |
| + (*it)->length != autofill::DetailInput::LONG) { |
| + ++it; |
| + } |
| + std::reverse(start, it); |
| + } |
| + |
| base::scoped_nsobject<LayoutView> view([[LayoutView alloc] init]); |
| [view setLayoutManager: |
| scoped_ptr<SimpleGridLayout>(new SimpleGridLayout(view))]; |
| @@ -625,11 +641,11 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, |
| NSString* tooltipText = |
| base::SysUTF16ToNSString(delegate_->TooltipForField(input.type)); |
| if ([tooltipText length] > 0) { |
| - DCHECK(!tooltipController_); |
| - DCHECK(!tooltipField_); |
| - tooltipController_.reset( |
| - [[AutofillTooltipController alloc] |
| - initWithArrowLocation:info_bubble::kTopRight]); |
| + if (!tooltipController_) { |
| + tooltipController_.reset( |
| + [[AutofillTooltipController alloc] |
| + initWithArrowLocation:info_bubble::kTopRight]); |
| + } |
| tooltipField_ = field.get(); |
| NSImage* icon = |
| ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| @@ -659,7 +675,11 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, |
| } |
| [self updateFieldIcons]; |
| - return view.autorelease(); |
| + |
| + if (inputs_) |
| + [[self view] replaceSubview:inputs_ with:view]; |
| + |
| + inputs_ = view; |
| } |
| - (void)updateFieldIcons { |
| @@ -682,7 +702,6 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, |
| } |
| - (void)updateEditability { |
| - |
| base::scoped_nsobject<NSMutableArray> controls([[NSMutableArray alloc] init]); |
| [self addInputsToArray:controls]; |
| for (NSControl<AutofillInputField>* control in controls.get()) { |
| @@ -704,8 +723,14 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, |
| - (void)setFieldValue:(NSString*)text |
| forType:(autofill::ServerFieldType)type { |
| NSControl<AutofillInputField>* field = [inputs_ viewWithTag:type]; |
| - if (field) |
| + if (field) { |
| + AutofillPopUpButton* popup = |
|
groby-ooo-7-16
2014/01/10 01:56:38
Please do that in AutofillPopUp, not here.
Dan Beam
2014/01/11 04:16:58
Done.
|
| + base::mac::ObjCCast<AutofillPopUpButton>(field); |
| + int index = popup ? [popup indexOfSelectedItem] : -1; |
| [field setFieldValue:text]; |
| + if (popup && [popup indexOfSelectedItem] != index) |
| + [self didEndEditing:field]; |
| + } |
| } |
| - (void)setSuggestionFieldValue:(NSString*)text { |