| 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 "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 9 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
| 10 #import "chrome/browser/ui/cocoa/autofill/autofill_pop_up_button.h" |
| 10 #import "chrome/browser/ui/cocoa/autofill/autofill_section_view.h" | 11 #import "chrome/browser/ui/cocoa/autofill/autofill_section_view.h" |
| 11 #import "chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h" | 12 #import "chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h" |
| 12 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" | 13 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" |
| 13 #import "chrome/browser/ui/cocoa/autofill/layout_view.h" | 14 #import "chrome/browser/ui/cocoa/autofill/layout_view.h" |
| 14 #include "chrome/browser/ui/cocoa/autofill/simple_grid_layout.h" | 15 #include "chrome/browser/ui/cocoa/autofill/simple_grid_layout.h" |
| 15 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 16 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
| 16 #import "chrome/browser/ui/cocoa/menu_button.h" | 17 #import "chrome/browser/ui/cocoa/menu_button.h" |
| 17 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 18 #import "ui/base/cocoa/menu_controller.h" | 19 #import "ui/base/cocoa/menu_controller.h" |
| 19 #include "ui/base/l10n/l10n_util_mac.h" | 20 #include "ui/base/l10n/l10n_util_mac.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 - (id)initWithController:(autofill::AutofillDialogController*)controller | 85 - (id)initWithController:(autofill::AutofillDialogController*)controller |
| 85 forSection:(autofill::DialogSection)section { | 86 forSection:(autofill::DialogSection)section { |
| 86 if (self = [super init]) { | 87 if (self = [super init]) { |
| 87 section_ = section; | 88 section_ = section; |
| 88 controller_ = controller; | 89 controller_ = controller; |
| 89 } | 90 } |
| 90 return self; | 91 return self; |
| 91 } | 92 } |
| 92 | 93 |
| 93 - (void)getInputs:(autofill::DetailOutputMap*)output { | 94 - (void)getInputs:(autofill::DetailOutputMap*)output { |
| 94 for (id input in [inputs_ subviews]) { | 95 for (NSControl<AutofillInputField>* input in [inputs_ subviews]) { |
| 95 const autofill::DetailInput* detailInput = | 96 const autofill::DetailInput* detailInput = |
| 96 reinterpret_cast<autofill::DetailInput*>([input tag]); | 97 reinterpret_cast<autofill::DetailInput*>([input tag]); |
| 97 DCHECK(detailInput); | 98 DCHECK(detailInput); |
| 98 NSString* value = [input isKindOfClass:[NSPopUpButton class]] ? | 99 NSString* value = [input fieldValue]; |
| 99 [input titleOfSelectedItem] : [input stringValue]; | |
| 100 output->insert( | 100 output->insert( |
| 101 std::make_pair(detailInput,base::SysNSStringToUTF16(value))); | 101 std::make_pair(detailInput,base::SysNSStringToUTF16(value))); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 - (void)modelChanged { | 105 - (void)modelChanged { |
| 106 ui::MenuModel* suggestionModel = controller_->MenuModelForSection(section_); | 106 ui::MenuModel* suggestionModel = controller_->MenuModelForSection(section_); |
| 107 menuController_.reset([[MenuController alloc] initWithModel:suggestionModel | 107 menuController_.reset([[MenuController alloc] initWithModel:suggestionModel |
| 108 useWithPopUpButtonCell:YES]); | 108 useWithPopUpButtonCell:YES]); |
| 109 NSMenu* menu = [menuController_ menu]; | 109 NSMenu* menu = [menuController_ menu]; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 column_set->AddPaddingColumn(kRelatedControlHorizontalSpacing); | 266 column_set->AddPaddingColumn(kRelatedControlHorizontalSpacing); |
| 267 // Must explicitly skip the padding column since we've already started | 267 // Must explicitly skip the padding column since we've already started |
| 268 // adding views. | 268 // adding views. |
| 269 layout->SkipColumns(1); | 269 layout->SkipColumns(1); |
| 270 } | 270 } |
| 271 | 271 |
| 272 column_set->AddColumn(input.expand_weight ? input.expand_weight : 1.0f); | 272 column_set->AddColumn(input.expand_weight ? input.expand_weight : 1.0f); |
| 273 | 273 |
| 274 ui::ComboboxModel* input_model = | 274 ui::ComboboxModel* input_model = |
| 275 controller_->ComboboxModelForAutofillType(input.type); | 275 controller_->ComboboxModelForAutofillType(input.type); |
| 276 base::scoped_nsprotocol<NSControl<AutofillInputField>*> control; |
| 276 if (input_model) { | 277 if (input_model) { |
| 277 base::scoped_nsobject<NSPopUpButton> popup( | 278 base::scoped_nsobject<AutofillPopUpButton> popup( |
| 278 [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:YES]); | 279 [[AutofillPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO]); |
| 279 for (int i = 0; i < input_model->GetItemCount(); ++i) { | 280 for (int i = 0; i < input_model->GetItemCount(); ++i) { |
| 280 [popup addItemWithTitle: | 281 [popup addItemWithTitle: |
| 281 base::SysUTF16ToNSString(input_model->GetItemAt(i))]; | 282 base::SysUTF16ToNSString(input_model->GetItemAt(i))]; |
| 282 } | 283 } |
| 283 [popup selectItemWithTitle:base::SysUTF16ToNSString(input.initial_value)]; | 284 control.reset(popup.release()); |
| 284 [popup sizeToFit]; | |
| 285 [popup setTag:reinterpret_cast<NSInteger>(&input)]; | |
| 286 layout->AddView(popup); | |
| 287 } else { | 285 } else { |
| 288 base::scoped_nsobject<AutofillTextField> field( | 286 base::scoped_nsobject<AutofillTextField> field( |
| 289 [[AutofillTextField alloc] init]); | 287 [[AutofillTextField alloc] init]); |
| 290 [[field cell] setPlaceholderString: | 288 [[field cell] setPlaceholderString: |
| 291 l10n_util::GetNSStringWithFixup(input.placeholder_text_rid)]; | 289 l10n_util::GetNSStringWithFixup(input.placeholder_text_rid)]; |
| 292 [[field cell] setIcon: | 290 [[field cell] setIcon: |
| 293 controller_->IconForField( | 291 controller_->IconForField( |
| 294 input.type, input.initial_value).AsNSImage()]; | 292 input.type, input.initial_value).AsNSImage()]; |
| 295 [[field cell] setInvalid:YES]; | 293 control.reset(field.release()); |
| 296 [field sizeToFit]; | |
| 297 [field setTag:reinterpret_cast<NSInteger>(&input)]; | |
| 298 layout->AddView(field); | |
| 299 } | 294 } |
| 295 [control setFieldValue:base::SysUTF16ToNSString(input.initial_value)]; |
| 296 [control setInvalid:YES]; |
| 297 [control sizeToFit]; |
| 298 [control setTag:reinterpret_cast<NSInteger>(&input)]; |
| 299 layout->AddView(control); |
| 300 } | 300 } |
| 301 | 301 |
| 302 return view.autorelease(); | 302 return view.autorelease(); |
| 303 } | 303 } |
| 304 | 304 |
| 305 - (void)updateSuggestionState { | 305 - (void)updateSuggestionState { |
| 306 const autofill::SuggestionState& suggestionState = | 306 const autofill::SuggestionState& suggestionState = |
| 307 controller_->SuggestionStateForSection(section_); | 307 controller_->SuggestionStateForSection(section_); |
| 308 bool showSuggestions = !suggestionState.text.empty(); | 308 bool showSuggestions = !suggestionState.text.empty(); |
| 309 | 309 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 const autofill::DetailInput* detailInput = | 351 const autofill::DetailInput* detailInput = |
| 352 reinterpret_cast<autofill::DetailInput*>([control tag]); | 352 reinterpret_cast<autofill::DetailInput*>([control tag]); |
| 353 DCHECK(detailInput); | 353 DCHECK(detailInput); |
| 354 if (detailInput->type == type) | 354 if (detailInput->type == type) |
| 355 return control; | 355 return control; |
| 356 } | 356 } |
| 357 return nil; | 357 return nil; |
| 358 } | 358 } |
| 359 | 359 |
| 360 @end | 360 @end |
| OLD | NEW |