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