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

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

Issue 2862913002: [Web Payments] Let subsheets define the initial focus (Closed)
Patch Set: Rebase Created 3 years, 7 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
« no previous file with comments | « chrome/browser/ui/views/payments/payment_request_sheet_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 PaymentRequestSheetController::PaymentRequestSheetController( 101 PaymentRequestSheetController::PaymentRequestSheetController(
102 PaymentRequestSpec* spec, 102 PaymentRequestSpec* spec,
103 PaymentRequestState* state, 103 PaymentRequestState* state,
104 PaymentRequestDialogView* dialog) 104 PaymentRequestDialogView* dialog)
105 : spec_(spec), state_(state), dialog_(dialog) {} 105 : spec_(spec), state_(state), dialog_(dialog) {}
106 106
107 PaymentRequestSheetController::~PaymentRequestSheetController() {} 107 PaymentRequestSheetController::~PaymentRequestSheetController() {}
108 108
109 std::unique_ptr<views::View> PaymentRequestSheetController::CreateView() { 109 std::unique_ptr<views::View> PaymentRequestSheetController::CreateView() {
110 std::unique_ptr<views::View> view = CreatePaymentView();
111 UpdateContentView();
112 return view;
113 }
114
115 void PaymentRequestSheetController::UpdateContentView() {
116 content_view_->RemoveAllChildViews(true);
117 FillContentView(content_view_);
118 content_view_->Layout();
119 pane_->SizeToPreferredSize();
120 // Now that the content and its surrounding pane are updated, force a Layout
121 // on the ScrollView so that it updates its scroll bars now.
122 scroll_->Layout();
123 }
124
125 std::unique_ptr<views::Button>
126 PaymentRequestSheetController::CreatePrimaryButton() {
127 return nullptr;
128 }
129
130 base::string16 PaymentRequestSheetController::GetSecondaryButtonLabel() {
131 return l10n_util::GetStringUTF16(IDS_CANCEL);
132 }
133
134 bool PaymentRequestSheetController::ShouldShowHeaderBackArrow() {
135 return true;
136 }
137
138 std::unique_ptr<views::View>
139 PaymentRequestSheetController::CreateExtraFooterView() {
140 return nullptr;
141 }
142
143 void PaymentRequestSheetController::ButtonPressed(
144 views::Button* sender, const ui::Event& event) {
145 switch (static_cast<PaymentRequestCommonTags>(sender->tag())) {
146 case PaymentRequestCommonTags::CLOSE_BUTTON_TAG:
147 dialog()->CloseDialog();
148 break;
149 case PaymentRequestCommonTags::BACK_BUTTON_TAG:
150 dialog()->GoBack();
151 break;
152 case PaymentRequestCommonTags::PAY_BUTTON_TAG:
153 dialog()->Pay();
154 break;
155 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX:
156 NOTREACHED();
157 break;
158 }
159 }
160
161 std::unique_ptr<views::View>
162 PaymentRequestSheetController::CreatePaymentView() {
163 // Create the footer now so that it's known if there's a primary button or not 110 // Create the footer now so that it's known if there's a primary button or not
164 // before creating the sheet view. This way, it's possible to determine 111 // before creating the sheet view. This way, it's possible to determine
165 // whether there's something to do when the user hits enter. 112 // whether there's something to do when the user hits enter.
166 std::unique_ptr<views::View> footer = CreateFooterView(); 113 std::unique_ptr<views::View> footer = CreateFooterView();
167 std::unique_ptr<SheetView> view = base::MakeUnique<SheetView>( 114 std::unique_ptr<SheetView> view = base::MakeUnique<SheetView>(
168 primary_button_ 115 primary_button_
169 ? base::Bind( 116 ? base::Bind(
170 &PaymentRequestSheetController::PerformPrimaryButtonAction, 117 &PaymentRequestSheetController::PerformPrimaryButtonAction,
171 base::Unretained(this)) 118 base::Unretained(this))
172 : base::Callback<bool()>()); 119 : base::Callback<bool()>());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 scroll_ = base::MakeUnique<views::ScrollView>(); 163 scroll_ = base::MakeUnique<views::ScrollView>();
217 scroll_->set_owned_by_client(); 164 scroll_->set_owned_by_client();
218 scroll_->EnableViewPortLayer(); 165 scroll_->EnableViewPortLayer();
219 scroll_->set_hide_horizontal_scrollbar(true); 166 scroll_->set_hide_horizontal_scrollbar(true);
220 scroll_->SetContents(pane_); 167 scroll_->SetContents(pane_);
221 layout->AddView(scroll_.get()); 168 layout->AddView(scroll_.get());
222 169
223 layout->StartRow(0, 0); 170 layout->StartRow(0, 0);
224 layout->AddView(footer.release()); 171 layout->AddView(footer.release());
225 172
173 UpdateContentView();
174
226 view->SetFirstFocusableView(GetFirstFocusedView()); 175 view->SetFirstFocusableView(GetFirstFocusedView());
176 return std::move(view);
177 }
227 178
228 return std::move(view); 179 void PaymentRequestSheetController::UpdateContentView() {
180 content_view_->RemoveAllChildViews(true);
181 FillContentView(content_view_);
182 content_view_->Layout();
183 pane_->SizeToPreferredSize();
184 // Now that the content and its surrounding pane are updated, force a Layout
185 // on the ScrollView so that it updates its scroll bars now.
186 scroll_->Layout();
187 }
188
189 std::unique_ptr<views::Button>
190 PaymentRequestSheetController::CreatePrimaryButton() {
191 return nullptr;
192 }
193
194 base::string16 PaymentRequestSheetController::GetSecondaryButtonLabel() {
195 return l10n_util::GetStringUTF16(IDS_CANCEL);
196 }
197
198 bool PaymentRequestSheetController::ShouldShowHeaderBackArrow() {
199 return true;
200 }
201
202 std::unique_ptr<views::View>
203 PaymentRequestSheetController::CreateExtraFooterView() {
204 return nullptr;
205 }
206
207 void PaymentRequestSheetController::ButtonPressed(views::Button* sender,
208 const ui::Event& event) {
209 switch (static_cast<PaymentRequestCommonTags>(sender->tag())) {
210 case PaymentRequestCommonTags::CLOSE_BUTTON_TAG:
211 dialog()->CloseDialog();
212 break;
213 case PaymentRequestCommonTags::BACK_BUTTON_TAG:
214 dialog()->GoBack();
215 break;
216 case PaymentRequestCommonTags::PAY_BUTTON_TAG:
217 dialog()->Pay();
218 break;
219 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX:
220 NOTREACHED();
221 break;
222 }
229 } 223 }
230 224
231 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() { 225 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() {
232 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 226 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
233 227
234 views::GridLayout* layout = new views::GridLayout(container.get()); 228 views::GridLayout* layout = new views::GridLayout(container.get());
235 container->SetLayoutManager(layout); 229 container->SetLayoutManager(layout);
236 230
237 views::ColumnSet* columns = layout->AddColumnSet(0); 231 views::ColumnSet* columns = layout->AddColumnSet(0);
238 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 232 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 291
298 bool PaymentRequestSheetController::PerformPrimaryButtonAction() { 292 bool PaymentRequestSheetController::PerformPrimaryButtonAction() {
299 if (primary_button_ && primary_button_->enabled()) { 293 if (primary_button_ && primary_button_->enabled()) {
300 ButtonPressed(primary_button_.get(), DummyEvent()); 294 ButtonPressed(primary_button_.get(), DummyEvent());
301 return true; 295 return true;
302 } 296 }
303 return false; 297 return false;
304 } 298 }
305 299
306 } // namespace payments 300 } // namespace payments
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/payment_request_sheet_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698