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

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: Add comments. 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 // This will be owned by its encompassing ScrollView.
31 content_view_ = new views::View;
32
33 FillContentView(content_view_);
34
35 return CreatePaymentView();
36 }
37
38 void PaymentRequestSheetController::UpdateContentView() {
39 content_view_->RemoveAllChildViews(true);
40 FillContentView(content_view_);
41 content_view_->Layout();
42 }
43
26 std::unique_ptr<views::Button> 44 std::unique_ptr<views::Button>
27 PaymentRequestSheetController::CreatePrimaryButton() { 45 PaymentRequestSheetController::CreatePrimaryButton() {
28 return nullptr; 46 return nullptr;
29 } 47 }
30 48
49 bool PaymentRequestSheetController::ShouldShowHeaderBackArrow() {
50 return true;
51 }
52
31 std::unique_ptr<views::View> 53 std::unique_ptr<views::View>
32 PaymentRequestSheetController::CreateExtraFooterView() { 54 PaymentRequestSheetController::CreateExtraFooterView() {
33 return nullptr; 55 return nullptr;
34 } 56 }
35 57
36 void PaymentRequestSheetController::ButtonPressed( 58 void PaymentRequestSheetController::ButtonPressed(
37 views::Button* sender, const ui::Event& event) { 59 views::Button* sender, const ui::Event& event) {
38 switch (static_cast<PaymentRequestCommonTags>(sender->tag())) { 60 switch (static_cast<PaymentRequestCommonTags>(sender->tag())) {
39 case PaymentRequestCommonTags::CLOSE_BUTTON_TAG: 61 case PaymentRequestCommonTags::CLOSE_BUTTON_TAG:
40 dialog()->CloseDialog(); 62 dialog()->CloseDialog();
41 break; 63 break;
42 case PaymentRequestCommonTags::BACK_BUTTON_TAG: 64 case PaymentRequestCommonTags::BACK_BUTTON_TAG:
43 dialog()->GoBack(); 65 dialog()->GoBack();
44 break; 66 break;
45 case PaymentRequestCommonTags::PAY_BUTTON_TAG: 67 case PaymentRequestCommonTags::PAY_BUTTON_TAG:
46 dialog()->Pay(); 68 dialog()->Pay();
47 break; 69 break;
48 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX: 70 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX:
49 NOTREACHED(); 71 NOTREACHED();
50 break; 72 break;
51 } 73 }
52 } 74 }
53 75
54 std::unique_ptr<views::View> PaymentRequestSheetController::CreatePaymentView( 76 std::unique_ptr<views::View>
55 std::unique_ptr<views::View> header_view, 77 PaymentRequestSheetController::CreatePaymentView() {
56 std::unique_ptr<views::View> content_view) {
57 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); 78 std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
58 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); 79 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE));
59 80
60 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a 81 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a
61 // layer) won't do proper clipping. 82 // layer) won't do proper clipping.
62 view->SetPaintToLayer(); 83 view->SetPaintToLayer();
63 84
64 views::GridLayout* layout = new views::GridLayout(view.get()); 85 views::GridLayout* layout = new views::GridLayout(view.get());
65 view->SetLayoutManager(layout); 86 view->SetLayoutManager(layout);
66 87
67 // Note: each view is responsible for its own padding (insets). 88 // Note: each view is responsible for its own padding (insets).
68 views::ColumnSet* columns = layout->AddColumnSet(0); 89 views::ColumnSet* columns = layout->AddColumnSet(0);
69 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 90 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
70 views::GridLayout::USE_PREF, 0, 0); 91 views::GridLayout::USE_PREF, 0, 0);
71 92
72 layout->StartRow(0, 0); 93 layout->StartRow(0, 0);
73 // |header_view| will be deleted when |view| is. 94 // |header_view| will be deleted when |view| is.
74 layout->AddView(header_view.release()); 95 layout->AddView(
96 CreateSheetHeaderView(ShouldShowHeaderBackArrow(), GetSheetTitle(), this)
97 .release());
75 98
76 layout->StartRow(1, 0); 99 layout->StartRow(1, 0);
77 // |content_view| will go into a views::ScrollView so it needs to be sized now 100 // |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 101 // otherwise it'll be sized to the ScrollView's viewport height, preventing
79 // the scroll bar from ever being shown. 102 // the scroll bar from ever being shown.
80 content_view->SizeToPreferredSize(); 103 content_view_->SizeToPreferredSize();
81 104
82 std::unique_ptr<views::ScrollView> scroll = 105 std::unique_ptr<views::ScrollView> scroll =
83 base::MakeUnique<views::ScrollView>(); 106 base::MakeUnique<views::ScrollView>();
84 scroll->EnableViewPortLayer(); 107 scroll->EnableViewPortLayer();
85 scroll->set_hide_horizontal_scrollbar(true); 108 scroll->set_hide_horizontal_scrollbar(true);
86 scroll->SetContents(content_view.release()); 109 scroll->SetContents(content_view_);
87 layout->AddView(scroll.release()); 110 layout->AddView(scroll.release());
88 111
89 layout->StartRow(0, 0); 112 layout->StartRow(0, 0);
90 layout->AddView(CreateFooterView().release()); 113 layout->AddView(CreateFooterView().release());
91 114
92 return view; 115 return view;
93 } 116 }
94 117
95 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() { 118 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() {
96 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 119 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)); 157 this, l10n_util::GetStringUTF16(IDS_CANCEL));
135 button->set_tag(static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG)); 158 button->set_tag(static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG));
136 trailing_buttons_container->AddChildView(button); 159 trailing_buttons_container->AddChildView(button);
137 160
138 layout->AddView(trailing_buttons_container.release()); 161 layout->AddView(trailing_buttons_container.release());
139 162
140 return container; 163 return container;
141 } 164 }
142 165
143 } // namespace payments 166 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698