Skip to content

Commit

Permalink
rAc: restore focus when inputs are rebuilt.
Browse files Browse the repository at this point in the history
R=estade@chromium.org
BUG=346863

Review URL: https://codereview.chromium.org/180203005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253967 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dbeam@chromium.org committed Feb 27, 2014
1 parent f497a12 commit ad3c201
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions chrome/browser/ui/cocoa/autofill/autofill_section_container.mm
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,25 @@ - (NSTextField*)makeDetailSectionLabel:(NSString*)labelText {

- (void)updateAndClobber:(BOOL)shouldClobber {
if (shouldClobber) {
// Remember which one of the inputs was first responder so focus can be
// restored after the inputs are rebuilt.
NSView* firstResponderView =
base::mac::ObjCCast<NSView>([[inputs_ window] firstResponder]);
autofill::ServerFieldType type = autofill::UNKNOWN_TYPE;
for (NSControl* field in [inputs_ subviews]) {
if ([firstResponderView isDescendantOf:field]) {
type = [self fieldTypeForControl:field];
break;
}
}

[self makeInputControls];

if (type != autofill::UNKNOWN_TYPE) {
NSView* view = [inputs_ viewWithTag:type];
if (view)
[[inputs_ window] makeFirstResponder:view];
}
} else {
const autofill::DetailInputs& updatedInputs =
delegate_->RequestedFieldsForSection(section_);
Expand Down
18 changes: 18 additions & 0 deletions chrome/browser/ui/views/autofill/autofill_dialog_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,25 @@ void AutofillDialogViews::UpdateSectionImpl(
DetailsGroup* group = GroupForSection(section);

if (clobber_inputs) {
ServerFieldType type = UNKNOWN_TYPE;
views::View* focused = GetFocusManager()->GetFocusedView();
if (focused && group->container->Contains(focused)) {
// Remember which view was focused before the inputs are clobbered.
if (focused->GetClassName() == DecoratedTextfield::kViewClassName)
type = TypeForTextfield(static_cast<DecoratedTextfield*>(focused));
else if (focused->GetClassName() == views::Combobox::kViewClassName)
type = TypeForCombobox(static_cast<views::Combobox*>(focused));
}

InitInputsView(section);

if (type != UNKNOWN_TYPE) {
// Restore the focus to the input with the previous type (e.g. country).
views::View* to_focus = TextfieldForType(type);
if (!to_focus) to_focus = ComboboxForType(type);
if (to_focus)
to_focus->RequestFocus();
}
} else {
const DetailInputs& updated_inputs =
delegate_->RequestedFieldsForSection(section);
Expand Down

0 comments on commit ad3c201

Please sign in to comment.