Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: chrome/browser/ui/views/payments/payment_request_sheet_controller.cc

Issue 2768133002: [Web Payments] Refactor sheet display to allow updating view content (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/payment_request_sheet_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
6 6
7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
9 #include "components/payments/content/payment_request.h" 9 #include "components/payments/content/payment_request.h"
10 #include "components/strings/grit/components_strings.h" 10 #include "components/strings/grit/components_strings.h"
11 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/views/background.h" 12 #include "ui/views/background.h"
13 #include "ui/views/controls/button/md_text_button.h" 13 #include "ui/views/controls/button/md_text_button.h"
14 #include "ui/views/controls/scroll_view.h" 14 #include "ui/views/controls/scroll_view.h"
15 #include "ui/views/layout/box_layout.h" 15 #include "ui/views/layout/box_layout.h"
16 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/layout/grid_layout.h" 17 #include "ui/views/layout/grid_layout.h"
17 18
18 namespace payments { 19 namespace payments {
19 20
20 PaymentRequestSheetController::PaymentRequestSheetController( 21 PaymentRequestSheetController::PaymentRequestSheetController(
21 PaymentRequestSpec* spec, 22 PaymentRequestSpec* spec,
22 PaymentRequestState* state, 23 PaymentRequestState* state,
23 PaymentRequestDialogView* dialog) 24 PaymentRequestDialogView* dialog)
24 : spec_(spec), state_(state), dialog_(dialog) {} 25 : spec_(spec), state_(state), dialog_(dialog) {}
25 26
27 PaymentRequestSheetController::~PaymentRequestSheetController() {}
28
29 std::unique_ptr<views::View> PaymentRequestSheetController::CreateView() {
30 content_view_ = base::MakeUnique<views::View>();
31 content_view_->set_owned_by_client();
32 content_view_->SetLayoutManager(new views::FillLayout);
33
34 FillContentView(content_view_.get());
35
36 return CreatePaymentView();
37 }
38
39 void PaymentRequestSheetController::UpdateContentView() {
Mathieu 2017/03/23 11:36:45 very neat!
anthonyvd 2017/03/23 16:18:11 Thanks!
40 content_view_->RemoveAllChildViews(true);
41 FillContentView(content_view_.get());
42 content_view_->Layout();
43 }
44
26 std::unique_ptr<views::Button> 45 std::unique_ptr<views::Button>
27 PaymentRequestSheetController::CreatePrimaryButton() { 46 PaymentRequestSheetController::CreatePrimaryButton() {
28 return nullptr; 47 return nullptr;
29 } 48 }
30 49
50 bool PaymentRequestSheetController::ShouldShowHeaderBackArrow() {
51 return true;
52 }
53
31 std::unique_ptr<views::View> 54 std::unique_ptr<views::View>
32 PaymentRequestSheetController::CreateExtraFooterView() { 55 PaymentRequestSheetController::CreateExtraFooterView() {
33 return nullptr; 56 return nullptr;
34 } 57 }
35 58
36 void PaymentRequestSheetController::ButtonPressed( 59 void PaymentRequestSheetController::ButtonPressed(
37 views::Button* sender, const ui::Event& event) { 60 views::Button* sender, const ui::Event& event) {
38 switch (static_cast<PaymentRequestCommonTags>(sender->tag())) { 61 switch (static_cast<PaymentRequestCommonTags>(sender->tag())) {
39 case PaymentRequestCommonTags::CLOSE_BUTTON_TAG: 62 case PaymentRequestCommonTags::CLOSE_BUTTON_TAG:
40 dialog()->CloseDialog(); 63 dialog()->CloseDialog();
41 break; 64 break;
42 case PaymentRequestCommonTags::BACK_BUTTON_TAG: 65 case PaymentRequestCommonTags::BACK_BUTTON_TAG:
43 dialog()->GoBack(); 66 dialog()->GoBack();
44 break; 67 break;
45 case PaymentRequestCommonTags::PAY_BUTTON_TAG: 68 case PaymentRequestCommonTags::PAY_BUTTON_TAG:
46 dialog()->Pay(); 69 dialog()->Pay();
47 break; 70 break;
48 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX: 71 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX:
49 NOTREACHED(); 72 NOTREACHED();
50 break; 73 break;
51 } 74 }
52 } 75 }
53 76
54 std::unique_ptr<views::View> PaymentRequestSheetController::CreatePaymentView( 77 std::unique_ptr<views::View>
55 std::unique_ptr<views::View> header_view, 78 PaymentRequestSheetController::CreatePaymentView() {
56 std::unique_ptr<views::View> content_view) {
57 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); 79 std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
58 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); 80 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE));
59 81
60 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a 82 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a
61 // layer) won't do proper clipping. 83 // layer) won't do proper clipping.
62 view->SetPaintToLayer(); 84 view->SetPaintToLayer();
63 85
64 views::GridLayout* layout = new views::GridLayout(view.get()); 86 views::GridLayout* layout = new views::GridLayout(view.get());
65 view->SetLayoutManager(layout); 87 view->SetLayoutManager(layout);
66 88
67 // Note: each view is responsible for its own padding (insets). 89 // Note: each view is responsible for its own padding (insets).
68 views::ColumnSet* columns = layout->AddColumnSet(0); 90 views::ColumnSet* columns = layout->AddColumnSet(0);
69 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 91 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
70 views::GridLayout::USE_PREF, 0, 0); 92 views::GridLayout::USE_PREF, 0, 0);
71 93
72 layout->StartRow(0, 0); 94 layout->StartRow(0, 0);
73 // |header_view| will be deleted when |view| is. 95 // |header_view| will be deleted when |view| is.
74 layout->AddView(header_view.release()); 96 layout->AddView(
97 CreateSheetHeaderView(ShouldShowHeaderBackArrow(), GetSheetTitle(), this)
98 .release());
75 99
76 layout->StartRow(1, 0); 100 layout->StartRow(1, 0);
77 // |content_view| will go into a views::ScrollView so it needs to be sized now 101 // |content_view| will go into a views::ScrollView so it needs to be sized now
78 // otherwise it'll be sized to the ScrollView's viewport height, preventing 102 // otherwise it'll be sized to the ScrollView's viewport height, preventing
79 // the scroll bar from ever being shown. 103 // the scroll bar from ever being shown.
80 content_view->SizeToPreferredSize(); 104 content_view_->SizeToPreferredSize();
81 105
82 std::unique_ptr<views::ScrollView> scroll = 106 std::unique_ptr<views::ScrollView> scroll =
83 base::MakeUnique<views::ScrollView>(); 107 base::MakeUnique<views::ScrollView>();
84 scroll->EnableViewPortLayer(); 108 scroll->EnableViewPortLayer();
85 scroll->set_hide_horizontal_scrollbar(true); 109 scroll->set_hide_horizontal_scrollbar(true);
86 scroll->SetContents(content_view.release()); 110 scroll->SetContents(content_view_.get());
87 layout->AddView(scroll.release()); 111 layout->AddView(scroll.release());
88 112
89 layout->StartRow(0, 0); 113 layout->StartRow(0, 0);
90 layout->AddView(CreateFooterView().release()); 114 layout->AddView(CreateFooterView().release());
91 115
92 return view; 116 return view;
93 } 117 }
94 118
95 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() { 119 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() {
96 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 120 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 this, l10n_util::GetStringUTF16(IDS_CANCEL)); 158 this, l10n_util::GetStringUTF16(IDS_CANCEL));
135 button->set_tag(static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG)); 159 button->set_tag(static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG));
136 trailing_buttons_container->AddChildView(button); 160 trailing_buttons_container->AddChildView(button);
137 161
138 layout->AddView(trailing_buttons_container.release()); 162 layout->AddView(trailing_buttons_container.release());
139 163
140 return container; 164 return container;
141 } 165 }
142 166
143 } // namespace payments 167 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698