Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/payment_sheet_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 19 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 19 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 20 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 20 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 21 #include "chrome/grit/chromium_strings.h" | |
| 21 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 23 #include "chrome/grit/theme_resources.h" | |
| 22 #include "components/autofill/core/browser/autofill_type.h" | 24 #include "components/autofill/core/browser/autofill_type.h" |
| 23 #include "components/autofill/core/browser/credit_card.h" | 25 #include "components/autofill/core/browser/credit_card.h" |
| 24 #include "components/autofill/core/browser/field_types.h" | 26 #include "components/autofill/core/browser/field_types.h" |
| 25 #include "components/autofill/core/browser/personal_data_manager.h" | 27 #include "components/autofill/core/browser/personal_data_manager.h" |
| 26 #include "components/payments/core/currency_formatter.h" | 28 #include "components/payments/core/currency_formatter.h" |
| 27 #include "components/strings/grit/components_strings.h" | 29 #include "components/strings/grit/components_strings.h" |
| 28 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/resource/resource_bundle.h" | |
| 30 #include "ui/gfx/color_utils.h" | 33 #include "ui/gfx/color_utils.h" |
| 31 #include "ui/gfx/font.h" | 34 #include "ui/gfx/font.h" |
| 32 #include "ui/gfx/paint_vector_icon.h" | 35 #include "ui/gfx/paint_vector_icon.h" |
| 33 #include "ui/gfx/range/range.h" | 36 #include "ui/gfx/range/range.h" |
| 34 #include "ui/views/controls/button/md_text_button.h" | 37 #include "ui/views/controls/button/md_text_button.h" |
| 35 #include "ui/views/controls/image_view.h" | 38 #include "ui/views/controls/image_view.h" |
| 36 #include "ui/views/controls/label.h" | 39 #include "ui/views/controls/label.h" |
| 37 #include "ui/views/controls/styled_label.h" | 40 #include "ui/views/controls/styled_label.h" |
| 41 #include "ui/views/layout/box_layout.h" | |
| 38 #include "ui/views/layout/fill_layout.h" | 42 #include "ui/views/layout/fill_layout.h" |
| 39 #include "ui/views/layout/grid_layout.h" | 43 #include "ui/views/layout/grid_layout.h" |
| 40 #include "ui/views/vector_icons.h" | 44 #include "ui/views/vector_icons.h" |
| 41 #include "ui/views/view.h" | 45 #include "ui/views/view.h" |
| 42 | 46 |
| 43 namespace payments { | 47 namespace payments { |
| 44 namespace { | 48 namespace { |
| 45 | 49 |
| 46 constexpr int kFirstTagValue = static_cast<int>( | 50 constexpr int kFirstTagValue = static_cast<int>( |
| 47 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); | 51 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 layout->AddView(CreateContactInfoRow().release()); | 196 layout->AddView(CreateContactInfoRow().release()); |
| 193 | 197 |
| 194 return CreatePaymentView( | 198 return CreatePaymentView( |
| 195 CreateSheetHeaderView( | 199 CreateSheetHeaderView( |
| 196 false, | 200 false, |
| 197 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), | 201 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), |
| 198 this), | 202 this), |
| 199 std::move(content_view)); | 203 std::move(content_view)); |
| 200 } | 204 } |
| 201 | 205 |
| 206 void PaymentSheetViewController::OnSelectedInformationChanged() { | |
| 207 UpdatePayButtonState(request()->is_ready_to_pay()); | |
| 208 } | |
| 209 | |
| 202 std::unique_ptr<views::Button> | 210 std::unique_ptr<views::Button> |
| 203 PaymentSheetViewController::CreatePrimaryButton() { | 211 PaymentSheetViewController::CreatePrimaryButton() { |
| 204 std::unique_ptr<views::Button> button( | 212 std::unique_ptr<views::Button> button( |
| 205 views::MdTextButton::CreateSecondaryUiBlueButton( | 213 views::MdTextButton::CreateSecondaryUiBlueButton( |
| 206 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); | 214 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); |
| 207 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); | 215 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); |
| 208 button->set_id(static_cast<int>(DialogViewID::PAYMENT_SHEET_PAY_BUTTON)); | 216 button->set_id(static_cast<int>(DialogViewID::PAYMENT_SHEET_PAY_BUTTON)); |
| 209 pay_button_ = button.get(); | 217 pay_button_ = button.get(); |
| 210 UpdatePayButtonState(request()->is_ready_to_pay()); | 218 UpdatePayButtonState(request()->is_ready_to_pay()); |
| 211 return button; | 219 return button; |
| 212 } | 220 } |
| 213 | 221 |
| 214 void PaymentSheetViewController::OnSelectedInformationChanged() { | 222 // Adds the Chrome logo to the footer. |
|
anthonyvd
2017/03/01 19:58:21
nit: Since this isn't always Chrome, can you make
Mathieu
2017/03/01 20:13:04
well we are in chrome/browser/ui/... Do you mean t
Mathieu
2017/03/02 15:56:06
Reworded even more!
| |
| 215 UpdatePayButtonState(request()->is_ready_to_pay()); | 223 // +---------------------------------------------------------+ |
| 224 // | (•) chrome | PAY | CANCEL | | |
| 225 // +---------------------------------------------------------+ | |
| 226 std::unique_ptr<views::View> | |
| 227 PaymentSheetViewController::CreateExtraFooterView() { | |
| 228 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | |
| 229 | |
| 230 views::BoxLayout* layout = | |
| 231 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
| 232 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
| 233 layout->set_cross_axis_alignment( | |
| 234 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
| 235 content_view->SetLayoutManager(layout); | |
| 236 | |
| 237 // Adds the Chrome logo image. | |
| 238 std::unique_ptr<views::ImageView> chrome_logo = | |
| 239 base::MakeUnique<views::ImageView>(); | |
| 240 chrome_logo->set_can_process_events_within_subtree(false); | |
| 241 chrome_logo->SetImage(ResourceBundle::GetSharedInstance() | |
| 242 .GetImageNamed(IDR_PRODUCT_LOGO_NAME_22) | |
| 243 .AsImageSkia()); | |
| 244 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
| 245 content_view->AddChildView(chrome_logo.release()); | |
| 246 | |
| 247 return content_view; | |
| 216 } | 248 } |
| 217 | 249 |
| 218 void PaymentSheetViewController::ButtonPressed( | 250 void PaymentSheetViewController::ButtonPressed( |
| 219 views::Button* sender, const ui::Event& event) { | 251 views::Button* sender, const ui::Event& event) { |
| 220 switch (sender->tag()) { | 252 switch (sender->tag()) { |
| 221 case static_cast<int>( | 253 case static_cast<int>( |
| 222 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON): | 254 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON): |
| 223 dialog()->ShowOrderSummary(); | 255 dialog()->ShowOrderSummary(); |
| 224 break; | 256 break; |
| 225 | 257 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), | 418 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), |
| 387 widest_name_column_view_width_); | 419 widest_name_column_view_width_); |
| 388 section->set_tag(static_cast<int>( | 420 section->set_tag(static_cast<int>( |
| 389 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 421 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); |
| 390 section->set_id( | 422 section->set_id( |
| 391 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | 423 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); |
| 392 return section; | 424 return section; |
| 393 } | 425 } |
| 394 | 426 |
| 395 } // namespace payments | 427 } // namespace payments |
| OLD | NEW |