Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/payments/editor_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/editor_view_controller.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 constexpr int kNumCharactersInShortField = 8; | 44 constexpr int kNumCharactersInShortField = 8; |
| 45 constexpr int kNumCharactersInLongField = 20; | 45 constexpr int kNumCharactersInLongField = 20; |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 EditorViewController::EditorViewController(PaymentRequestSpec* spec, | 49 EditorViewController::EditorViewController(PaymentRequestSpec* spec, |
| 50 PaymentRequestState* state, | 50 PaymentRequestState* state, |
| 51 PaymentRequestDialogView* dialog) | 51 PaymentRequestDialogView* dialog) |
| 52 : PaymentRequestSheetController(spec, state, dialog) {} | 52 : PaymentRequestSheetController(spec, state, dialog), |
| 53 first_field_view_(nullptr) {} | |
| 53 | 54 |
| 54 EditorViewController::~EditorViewController() {} | 55 EditorViewController::~EditorViewController() {} |
| 55 | 56 |
| 56 void EditorViewController::DisplayErrorMessageForField( | 57 void EditorViewController::DisplayErrorMessageForField( |
| 57 const EditorField& field, | 58 const EditorField& field, |
| 58 const base::string16& error_message) { | 59 const base::string16& error_message) { |
| 59 const auto& label_it = error_labels_.find(field); | 60 const auto& label_it = error_labels_.find(field); |
| 60 DCHECK(label_it != error_labels_.end()); | 61 DCHECK(label_it != error_labels_.end()); |
| 61 label_it->second->SetText(error_message); | 62 label_it->second->SetText(error_message); |
| 62 label_it->second->SchedulePaint(); | 63 label_it->second->SchedulePaint(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 case static_cast<int>(EditorViewControllerTags::SAVE_BUTTON): | 126 case static_cast<int>(EditorViewControllerTags::SAVE_BUTTON): |
| 126 if (ValidateModelAndSave()) | 127 if (ValidateModelAndSave()) |
| 127 dialog()->GoBackToPaymentSheet(); | 128 dialog()->GoBackToPaymentSheet(); |
| 128 break; | 129 break; |
| 129 default: | 130 default: |
| 130 PaymentRequestSheetController::ButtonPressed(sender, event); | 131 PaymentRequestSheetController::ButtonPressed(sender, event); |
| 131 break; | 132 break; |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 | 135 |
| 136 views::View* EditorViewController::GetFirstFocusedView() { | |
| 137 if (first_field_view_) | |
| 138 return first_field_view_; | |
| 139 return PaymentRequestSheetController::GetFirstFocusedView(); | |
| 140 } | |
| 141 | |
| 135 void EditorViewController::ContentsChanged(views::Textfield* sender, | 142 void EditorViewController::ContentsChanged(views::Textfield* sender, |
| 136 const base::string16& new_contents) { | 143 const base::string16& new_contents) { |
| 137 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged(); | 144 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged(); |
| 138 } | 145 } |
| 139 | 146 |
| 140 void EditorViewController::OnPerformAction(views::Combobox* sender) { | 147 void EditorViewController::OnPerformAction(views::Combobox* sender) { |
| 141 static_cast<ValidatingCombobox*>(sender)->OnContentsChanged(); | 148 static_cast<ValidatingCombobox*>(sender)->OnContentsChanged(); |
| 142 } | 149 } |
| 143 | 150 |
| 144 std::unique_ptr<views::View> EditorViewController::CreateEditorView() { | 151 std::unique_ptr<views::View> EditorViewController::CreateEditorView() { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 text_field->SetText(GetInitialValueForType(field.type)); | 214 text_field->SetText(GetInitialValueForType(field.type)); |
| 208 text_field->set_controller(this); | 215 text_field->set_controller(this); |
| 209 // Using autofill field type as a view ID (for testing). | 216 // Using autofill field type as a view ID (for testing). |
| 210 text_field->set_id(static_cast<int>(field.type)); | 217 text_field->set_id(static_cast<int>(field.type)); |
| 211 text_field->set_default_width_in_chars( | 218 text_field->set_default_width_in_chars( |
| 212 field.length_hint == EditorField::LengthHint::HINT_SHORT | 219 field.length_hint == EditorField::LengthHint::HINT_SHORT |
| 213 ? kNumCharactersInShortField | 220 ? kNumCharactersInShortField |
| 214 : kNumCharactersInLongField); | 221 : kNumCharactersInLongField); |
| 215 | 222 |
| 216 text_fields_.insert(std::make_pair(text_field, field)); | 223 text_fields_.insert(std::make_pair(text_field, field)); |
| 224 | |
| 225 if (!first_field_view_) | |
|
Mathieu
2017/05/04 19:32:34
TODO(crbug.com/xxxxxx): Should be the first view t
anthonyvd
2017/05/04 20:56:59
Done.
| |
| 226 first_field_view_ = text_field; | |
| 227 | |
| 217 // |text_field| will now be owned by |row|. | 228 // |text_field| will now be owned by |row|. |
| 218 layout->AddView(text_field); | 229 layout->AddView(text_field); |
| 219 } else if (field.control_type == EditorField::ControlType::COMBOBOX) { | 230 } else if (field.control_type == EditorField::ControlType::COMBOBOX) { |
| 220 ValidatingCombobox* combobox = new ValidatingCombobox( | 231 ValidatingCombobox* combobox = new ValidatingCombobox( |
| 221 GetComboboxModelForType(field.type), CreateValidationDelegate(field)); | 232 GetComboboxModelForType(field.type), CreateValidationDelegate(field)); |
| 222 combobox->SelectValue(GetInitialValueForType(field.type)); | 233 combobox->SelectValue(GetInitialValueForType(field.type)); |
| 223 // Using autofill field type as a view ID (for testing). | 234 // Using autofill field type as a view ID (for testing). |
| 224 combobox->set_id(static_cast<int>(field.type)); | 235 combobox->set_id(static_cast<int>(field.type)); |
| 225 combobox->set_listener(this); | 236 combobox->set_listener(this); |
| 226 comboboxes_.insert(std::make_pair(combobox, field)); | 237 comboboxes_.insert(std::make_pair(combobox, field)); |
| 238 | |
| 239 if (!first_field_view_) | |
| 240 first_field_view_ = combobox; | |
| 241 | |
| 227 // |combobox| will now be owned by |row|. | 242 // |combobox| will now be owned by |row|. |
| 228 layout->AddView(combobox); | 243 layout->AddView(combobox); |
| 229 } else { | 244 } else { |
| 230 NOTREACHED(); | 245 NOTREACHED(); |
| 231 } | 246 } |
| 232 | 247 |
| 233 // This is the vertical space between the input field and its error label. | 248 // This is the vertical space between the input field and its error label. |
| 234 constexpr int kInputErrorLabelPadding = 6; | 249 constexpr int kInputErrorLabelPadding = 6; |
| 235 layout->StartRowWithPadding(0, 0, 0, kInputErrorLabelPadding); | 250 layout->StartRowWithPadding(0, 0, 0, kInputErrorLabelPadding); |
| 236 layout->SkipColumns(1); | 251 layout->SkipColumns(1); |
| 237 // Error label is initially empty. | 252 // Error label is initially empty. |
| 238 std::unique_ptr<views::Label> error_label = | 253 std::unique_ptr<views::Label> error_label = |
| 239 base::MakeUnique<views::Label>(base::ASCIIToUTF16("")); | 254 base::MakeUnique<views::Label>(base::ASCIIToUTF16("")); |
| 240 error_label->set_id(static_cast<int>(DialogViewID::ERROR_LABEL_OFFSET) + | 255 error_label->set_id(static_cast<int>(DialogViewID::ERROR_LABEL_OFFSET) + |
| 241 field.type); | 256 field.type); |
| 242 error_label->SetFontList( | 257 error_label->SetFontList( |
| 243 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1)); | 258 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1)); |
| 244 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor( | 259 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor( |
| 245 ui::NativeTheme::kColorId_AlertSeverityHigh)); | 260 ui::NativeTheme::kColorId_AlertSeverityHigh)); |
| 246 error_labels_[field] = error_label.get(); | 261 error_labels_[field] = error_label.get(); |
| 247 | 262 |
| 248 layout->AddView(error_label.release()); | 263 layout->AddView(error_label.release()); |
| 249 } | 264 } |
| 250 | 265 |
| 251 } // namespace payments | 266 } // namespace payments |
| OLD | NEW |