Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | |
| 7 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 9 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
| 9 #include "chrome/browser/ui/views/constrained_window_views.h" | 10 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 10 #include "ui/views/border.h" | 11 #include "ui/views/border.h" |
| 11 #include "ui/views/controls/button/checkbox.h" | 12 #include "ui/views/controls/button/checkbox.h" |
| 12 #include "ui/views/controls/combobox/combobox.h" | 13 #include "ui/views/controls/combobox/combobox.h" |
| 13 #include "ui/views/controls/label.h" | 14 #include "ui/views/controls/label.h" |
| 14 #include "ui/views/controls/separator.h" | 15 #include "ui/views/controls/separator.h" |
| 15 #include "ui/views/controls/textfield/textfield.h" | 16 #include "ui/views/controls/textfield/textfield.h" |
| 16 #include "ui/views/layout/box_layout.h" | 17 #include "ui/views/layout/box_layout.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 return GroupForSection(section)->suggested_input->selected_index(); | 99 return GroupForSection(section)->suggested_input->selected_index(); |
| 99 } | 100 } |
| 100 | 101 |
| 101 void AutofillDialogViews::GetUserInput(DialogSection section, | 102 void AutofillDialogViews::GetUserInput(DialogSection section, |
| 102 DetailOutputMap* output) { | 103 DetailOutputMap* output) { |
| 103 DetailsGroup* group = GroupForSection(section); | 104 DetailsGroup* group = GroupForSection(section); |
| 104 for (TextfieldMap::iterator it = group->textfields.begin(); | 105 for (TextfieldMap::iterator it = group->textfields.begin(); |
| 105 it != group->textfields.end(); ++it) { | 106 it != group->textfields.end(); ++it) { |
| 106 output->insert(std::make_pair(it->first, it->second->text())); | 107 output->insert(std::make_pair(it->first, it->second->text())); |
| 107 } | 108 } |
| 109 for (ComboboxMap::iterator it = group->comboboxes.begin(); | |
| 110 it != group->comboboxes.end(); ++it) { | |
| 111 views::Combobox* combobox = it->second; | |
| 112 output->insert(std::make_pair( | |
| 113 it->first, | |
| 114 combobox->model()->GetItemAt(combobox->selected_index()))); | |
| 115 } | |
| 108 } | 116 } |
| 109 | 117 |
| 110 bool AutofillDialogViews::UseBillingForShipping() { | 118 bool AutofillDialogViews::UseBillingForShipping() { |
| 111 return use_billing_for_shipping_->checked(); | 119 return use_billing_for_shipping_->checked(); |
| 112 } | 120 } |
| 113 | 121 |
| 114 string16 AutofillDialogViews::GetWindowTitle() const { | 122 string16 AutofillDialogViews::GetWindowTitle() const { |
| 115 return controller_->DialogTitle(); | 123 return controller_->DialogTitle(); |
| 116 } | 124 } |
| 117 | 125 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 141 | 149 |
| 142 bool AutofillDialogViews::IsDialogButtonEnabled(ui::DialogButton button) const { | 150 bool AutofillDialogViews::IsDialogButtonEnabled(ui::DialogButton button) const { |
| 143 return button == ui::DIALOG_BUTTON_OK ? | 151 return button == ui::DIALOG_BUTTON_OK ? |
| 144 controller_->ConfirmButtonEnabled() : true; | 152 controller_->ConfirmButtonEnabled() : true; |
| 145 } | 153 } |
| 146 | 154 |
| 147 bool AutofillDialogViews::UseChromeStyle() const { | 155 bool AutofillDialogViews::UseChromeStyle() const { |
| 148 return true; | 156 return true; |
| 149 } | 157 } |
| 150 | 158 |
| 151 ui::ModalType AutofillDialogViews::GetModalType() const { | |
| 152 #if defined(USE_ASH) | |
| 153 return ui::MODAL_TYPE_CHILD; | |
| 154 #else | |
| 155 return views::WidgetDelegate::GetModalType(); | |
| 156 #endif | |
| 157 } | |
| 158 | |
| 159 bool AutofillDialogViews::Cancel() { | 159 bool AutofillDialogViews::Cancel() { |
| 160 return true; | 160 return true; |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool AutofillDialogViews::Accept() { | 163 bool AutofillDialogViews::Accept() { |
| 164 did_submit_ = true; | 164 did_submit_ = true; |
| 165 return true; | 165 return true; |
| 166 } | 166 } |
| 167 | 167 |
| 168 void AutofillDialogViews::ButtonPressed(views::Button* sender, | 168 void AutofillDialogViews::ButtonPressed(views::Button* sender, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 group->manual_input = manual_inputs; | 293 group->manual_input = manual_inputs; |
| 294 UpdateDetailsGroupState(*group); | 294 UpdateDetailsGroupState(*group); |
| 295 return inputs_container; | 295 return inputs_container; |
| 296 } | 296 } |
| 297 | 297 |
| 298 // TODO(estade): we should be using Chrome-style constrained window padding | 298 // TODO(estade): we should be using Chrome-style constrained window padding |
| 299 // values. | 299 // values. |
| 300 views::View* AutofillDialogViews::InitInputsView(DialogSection section) { | 300 views::View* AutofillDialogViews::InitInputsView(DialogSection section) { |
| 301 const DetailInputs& inputs = controller_->RequestedFieldsForSection(section); | 301 const DetailInputs& inputs = controller_->RequestedFieldsForSection(section); |
| 302 TextfieldMap* textfields = &GroupForSection(section)->textfields; | 302 TextfieldMap* textfields = &GroupForSection(section)->textfields; |
| 303 ComboboxMap* comboboxes = &GroupForSection(section)->comboboxes; | |
| 303 | 304 |
| 304 views::View* view = new views::View(); | 305 views::View* view = new views::View(); |
| 305 views::GridLayout* layout = new views::GridLayout(view); | 306 views::GridLayout* layout = new views::GridLayout(view); |
| 306 view->SetLayoutManager(layout); | 307 view->SetLayoutManager(layout); |
| 307 | 308 |
| 308 for (DetailInputs::const_iterator it = inputs.begin(); | 309 for (DetailInputs::const_iterator it = inputs.begin(); |
| 309 it != inputs.end(); ++it) { | 310 it != inputs.end(); ++it) { |
| 310 const DetailInput& input = *it; | 311 const DetailInput& input = *it; |
| 311 if (!controller_->ShouldShowInput(input)) | 312 if (!controller_->ShouldShowInput(input)) |
| 312 continue; | 313 continue; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 328 } | 329 } |
| 329 | 330 |
| 330 float expand = input.expand_weight; | 331 float expand = input.expand_weight; |
| 331 column_set->AddColumn(views::GridLayout::FILL, | 332 column_set->AddColumn(views::GridLayout::FILL, |
| 332 views::GridLayout::BASELINE, | 333 views::GridLayout::BASELINE, |
| 333 expand ? expand : 1, | 334 expand ? expand : 1, |
| 334 views::GridLayout::USE_PREF, | 335 views::GridLayout::USE_PREF, |
| 335 0, | 336 0, |
| 336 0); | 337 0); |
| 337 | 338 |
| 338 views::Textfield* field = new views::Textfield(); | 339 ui::ComboboxModel* input_model = |
| 339 field->set_placeholder_text(ASCIIToUTF16(input.placeholder_text)); | 340 controller_->ComboboxModelForAutofillType(input.type); |
| 340 field->SetText(input.starting_value); | 341 // TODO(estade): TextFields and Comboboxes need to be the same height. |
| 341 textfields->insert(std::make_pair(&input, field)); | 342 if (input_model) { |
| 342 layout->AddView(field); | 343 views::Combobox* combobox = new views::Combobox(input_model); |
| 344 int starting_value; | |
| 345 if (base::StringToInt(input.starting_value, &starting_value)) | |
| 346 combobox->SetSelectedIndex(starting_value); | |
|
Ilya Sherman
2012/11/30 01:01:32
This looks like it will try to use values like "20
Evan Stade
2012/11/30 22:55:25
no, you're not.
| |
| 347 comboboxes->insert(std::make_pair(&input, combobox)); | |
| 348 layout->AddView(combobox); | |
| 349 } else { | |
| 350 views::Textfield* field = new views::Textfield(); | |
| 351 field->set_placeholder_text(ASCIIToUTF16(input.placeholder_text)); | |
| 352 field->SetText(input.starting_value); | |
| 353 textfields->insert(std::make_pair(&input, field)); | |
| 354 layout->AddView(field); | |
| 355 } | |
| 343 } | 356 } |
| 344 | 357 |
| 345 return view; | 358 return view; |
| 346 } | 359 } |
| 347 | 360 |
| 348 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { | 361 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { |
| 349 views::Combobox* combobox = group.suggested_input; | 362 views::Combobox* combobox = group.suggested_input; |
| 350 int suggestion_count = combobox->model()->GetItemCount(); | 363 int suggestion_count = combobox->model()->GetItemCount(); |
| 351 bool show_combobox = suggestion_count > 1 && | 364 bool show_combobox = suggestion_count > 1 && |
| 352 combobox->selected_index() != suggestion_count - 1; | 365 combobox->selected_index() != suggestion_count - 1; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 373 } | 386 } |
| 374 | 387 |
| 375 AutofillDialogViews::DetailsGroup::DetailsGroup() | 388 AutofillDialogViews::DetailsGroup::DetailsGroup() |
| 376 : container(NULL), | 389 : container(NULL), |
| 377 suggested_input(NULL), | 390 suggested_input(NULL), |
| 378 manual_input(NULL) {} | 391 manual_input(NULL) {} |
| 379 | 392 |
| 380 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 393 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
| 381 | 394 |
| 382 } // namespace autofill | 395 } // namespace autofill |
| OLD | NEW |