| 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 28 matching lines...) Expand all Loading... |
| 39 // The tag for the button that saves the model being edited. Starts at | 39 // The tag for the button that saves the model being edited. Starts at |
| 40 // |kFirstTagValue| not to conflict with tags common to all views. | 40 // |kFirstTagValue| not to conflict with tags common to all views. |
| 41 SAVE_BUTTON = kFirstTagValue, | 41 SAVE_BUTTON = kFirstTagValue, |
| 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( |
| 50 PaymentRequestState* state, | 50 PaymentRequestSpec* spec, |
| 51 PaymentRequestDialogView* dialog) | 51 PaymentRequestState* state, |
| 52 PaymentRequestDialogView* dialog, |
| 53 BackNavigationType back_navigation_type) |
| 52 : PaymentRequestSheetController(spec, state, dialog), | 54 : PaymentRequestSheetController(spec, state, dialog), |
| 53 first_field_view_(nullptr) {} | 55 first_field_view_(nullptr), |
| 56 back_navigation_type_(back_navigation_type) {} |
| 54 | 57 |
| 55 EditorViewController::~EditorViewController() {} | 58 EditorViewController::~EditorViewController() {} |
| 56 | 59 |
| 57 void EditorViewController::DisplayErrorMessageForField( | 60 void EditorViewController::DisplayErrorMessageForField( |
| 58 const EditorField& field, | 61 const EditorField& field, |
| 59 const base::string16& error_message) { | 62 const base::string16& error_message) { |
| 60 const auto& label_it = error_labels_.find(field); | 63 const auto& label_it = error_labels_.find(field); |
| 61 DCHECK(label_it != error_labels_.end()); | 64 DCHECK(label_it != error_labels_.end()); |
| 62 label_it->second->SetText(error_message); | 65 label_it->second->SetText(error_message); |
| 63 label_it->second->SchedulePaint(); | 66 label_it->second->SchedulePaint(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 UpdateContentView(); | 120 UpdateContentView(); |
| 118 // TODO(crbug.com/704254): Find how to update the parent view bounds so that | 121 // TODO(crbug.com/704254): Find how to update the parent view bounds so that |
| 119 // the vertical scrollbar size gets updated. | 122 // the vertical scrollbar size gets updated. |
| 120 dialog()->EditorViewUpdated(); | 123 dialog()->EditorViewUpdated(); |
| 121 } | 124 } |
| 122 | 125 |
| 123 void EditorViewController::ButtonPressed(views::Button* sender, | 126 void EditorViewController::ButtonPressed(views::Button* sender, |
| 124 const ui::Event& event) { | 127 const ui::Event& event) { |
| 125 switch (sender->tag()) { | 128 switch (sender->tag()) { |
| 126 case static_cast<int>(EditorViewControllerTags::SAVE_BUTTON): | 129 case static_cast<int>(EditorViewControllerTags::SAVE_BUTTON): |
| 127 if (ValidateModelAndSave()) | 130 if (ValidateModelAndSave()) { |
| 128 dialog()->GoBackToPaymentSheet(); | 131 switch (back_navigation_type_) { |
| 132 case BackNavigationType::kOneStep: |
| 133 dialog()->GoBack(); |
| 134 break; |
| 135 case BackNavigationType::kPaymentSheet: |
| 136 dialog()->GoBackToPaymentSheet(); |
| 137 break; |
| 138 } |
| 139 } |
| 129 break; | 140 break; |
| 130 default: | 141 default: |
| 131 PaymentRequestSheetController::ButtonPressed(sender, event); | 142 PaymentRequestSheetController::ButtonPressed(sender, event); |
| 132 break; | 143 break; |
| 133 } | 144 } |
| 134 } | 145 } |
| 135 | 146 |
| 136 views::View* EditorViewController::GetFirstFocusedView() { | 147 views::View* EditorViewController::GetFirstFocusedView() { |
| 137 if (first_field_view_) | 148 if (first_field_view_) |
| 138 return first_field_view_; | 149 return first_field_view_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 168 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | 179 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, |
| 169 views::GridLayout::USE_PREF, 0, 0); | 180 views::GridLayout::USE_PREF, 0, 0); |
| 170 | 181 |
| 171 // This is the horizontal padding between the label and the input field. | 182 // This is the horizontal padding between the label and the input field. |
| 172 constexpr int kLabelInputFieldHorizontalPadding = 16; | 183 constexpr int kLabelInputFieldHorizontalPadding = 16; |
| 173 columns->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); | 184 columns->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); |
| 174 | 185 |
| 175 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | 186 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, |
| 176 views::GridLayout::USE_PREF, 0, 0); | 187 views::GridLayout::USE_PREF, 0, 0); |
| 177 | 188 |
| 178 // The LayoutManager needs to be set before input fields are created, so we | |
| 179 // keep a handle to it before we release it to the view. | |
| 180 views::GridLayout* layout_handle = editor_layout.get(); | |
| 181 editor_view->SetLayoutManager(editor_layout.release()); | 189 editor_view->SetLayoutManager(editor_layout.release()); |
| 182 std::vector<EditorField> fields = GetFieldDefinitions(); | 190 std::vector<EditorField> fields = GetFieldDefinitions(); |
| 183 for (const auto& field : fields) { | 191 for (const auto& field : fields) { |
| 184 CreateInputField(layout_handle, field); | 192 CreateInputField( |
| 193 static_cast<views::GridLayout*>(editor_view->GetLayoutManager()), |
| 194 field); |
| 185 } | 195 } |
| 186 | 196 |
| 187 return editor_view; | 197 return editor_view; |
| 188 } | 198 } |
| 189 | 199 |
| 190 // Each input field is a 4-quadrant grid. | 200 // Each input field is a 4-quadrant grid. |
| 191 // +----------------------------------------------------------+ | 201 // +----------------------------------------------------------+ |
| 192 // | Field Label | Input field (textfield/combobox) | | 202 // | Field Label | Input field (textfield/combobox) | |
| 193 // |_______________________|__________________________________| | 203 // |_______________________|__________________________________| |
| 194 // | (empty) | Error label | | 204 // | (empty) | Error label | |
| 195 // +----------------------------------------------------------+ | 205 // +----------------------------------------------------------+ |
| 196 void EditorViewController::CreateInputField(views::GridLayout* layout, | 206 void EditorViewController::CreateInputField(views::GridLayout* layout, |
| 197 const EditorField& field) { | 207 const EditorField& field) { |
| 198 // This is the top padding for every row. | 208 // This is the top padding for every row. |
| 199 constexpr int kInputRowSpacing = 6; | 209 constexpr int kInputRowSpacing = 6; |
| 200 layout->StartRowWithPadding(0, 0, 0, kInputRowSpacing); | 210 layout->StartRowWithPadding(0, 0, 0, kInputRowSpacing); |
| 201 | 211 |
| 202 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( | 212 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( |
| 203 field.required ? field.label + base::ASCIIToUTF16("*") : field.label); | 213 field.required ? field.label + base::ASCIIToUTF16("*") : field.label); |
| 214 |
| 204 // A very long label will wrap. Value picked so that left + right label | 215 // A very long label will wrap. Value picked so that left + right label |
| 205 // padding bring the label to half-way in the dialog (~225). | 216 // padding bring the label to half-way in the dialog (~225). |
| 206 constexpr int kMaximumLabelWidth = 192; | 217 constexpr int kMaximumLabelWidth = 192; |
| 207 label->SetMultiLine(true); | 218 label->SetMultiLine(true); |
| 208 label->SetMaximumWidth(kMaximumLabelWidth); | 219 label->SetMaximumWidth(kMaximumLabelWidth); |
| 209 layout->AddView(label.release()); | 220 layout->AddView(label.release()); |
| 210 | 221 |
| 211 if (field.control_type == EditorField::ControlType::TEXTFIELD) { | 222 if (field.control_type == EditorField::ControlType::TEXTFIELD) { |
| 212 ValidatingTextfield* text_field = | 223 ValidatingTextfield* text_field = |
| 213 new ValidatingTextfield(CreateValidationDelegate(field)); | 224 new ValidatingTextfield(CreateValidationDelegate(field)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 237 combobox->set_id(static_cast<int>(field.type)); | 248 combobox->set_id(static_cast<int>(field.type)); |
| 238 combobox->set_listener(this); | 249 combobox->set_listener(this); |
| 239 comboboxes_.insert(std::make_pair(combobox, field)); | 250 comboboxes_.insert(std::make_pair(combobox, field)); |
| 240 | 251 |
| 241 if (!first_field_view_) | 252 if (!first_field_view_) |
| 242 first_field_view_ = combobox; | 253 first_field_view_ = combobox; |
| 243 | 254 |
| 244 // |combobox| will now be owned by |row|. | 255 // |combobox| will now be owned by |row|. |
| 245 layout->AddView(combobox); | 256 layout->AddView(combobox); |
| 246 } else { | 257 } else { |
| 247 NOTREACHED(); | 258 // Custom field view will now be owned by |row|. |
| 259 layout->AddView(CreateCustomFieldView(field.type).release()); |
| 248 } | 260 } |
| 249 | 261 |
| 250 // This is the vertical space between the input field and its error label. | 262 // This is the vertical space between the input field and its error label. |
| 251 constexpr int kInputErrorLabelPadding = 6; | 263 constexpr int kInputErrorLabelPadding = 6; |
| 252 layout->StartRowWithPadding(0, 0, 0, kInputErrorLabelPadding); | 264 layout->StartRowWithPadding(0, 0, 0, kInputErrorLabelPadding); |
| 253 layout->SkipColumns(1); | 265 layout->SkipColumns(1); |
| 254 // Error label is initially empty. | 266 // Error label is initially empty. |
| 255 std::unique_ptr<views::Label> error_label = | 267 std::unique_ptr<views::Label> error_label = |
| 256 base::MakeUnique<views::Label>(base::ASCIIToUTF16("")); | 268 base::MakeUnique<views::Label>(base::ASCIIToUTF16("")); |
| 257 error_label->set_id(static_cast<int>(DialogViewID::ERROR_LABEL_OFFSET) + | 269 error_label->set_id(static_cast<int>(DialogViewID::ERROR_LABEL_OFFSET) + |
| 258 field.type); | 270 field.type); |
| 259 error_label->SetFontList( | 271 error_label->SetFontList( |
| 260 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1)); | 272 error_label->GetDefaultFontList().DeriveWithSizeDelta(-1)); |
| 261 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor( | 273 error_label->SetEnabledColor(error_label->GetNativeTheme()->GetSystemColor( |
| 262 ui::NativeTheme::kColorId_AlertSeverityHigh)); | 274 ui::NativeTheme::kColorId_AlertSeverityHigh)); |
| 263 error_labels_[field] = error_label.get(); | 275 error_labels_[field] = error_label.get(); |
| 264 | 276 |
| 265 layout->AddView(error_label.release()); | 277 layout->AddView(error_label.release()); |
| 266 } | 278 } |
| 267 | 279 |
| 268 } // namespace payments | 280 } // namespace payments |
| OLD | NEW |