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/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_dialog_view_ids.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
9 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 9 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
10 #include "components/payments/content/payment_request.h" | 10 #include "components/payments/content/payment_request.h" |
11 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
13 #include "ui/views/background.h" | 13 #include "ui/views/background.h" |
14 #include "ui/views/controls/button/md_text_button.h" | 14 #include "ui/views/controls/button/md_text_button.h" |
15 #include "ui/views/controls/scroll_view.h" | 15 #include "ui/views/controls/scroll_view.h" |
16 #include "ui/views/focus/focus_search.h" | |
16 #include "ui/views/layout/box_layout.h" | 17 #include "ui/views/layout/box_layout.h" |
17 #include "ui/views/layout/fill_layout.h" | 18 #include "ui/views/layout/fill_layout.h" |
18 #include "ui/views/layout/grid_layout.h" | 19 #include "ui/views/layout/grid_layout.h" |
19 | 20 |
20 namespace payments { | 21 namespace payments { |
21 | 22 |
23 namespace { | |
24 | |
25 class SheetView : public views::View, public views::FocusTraversable { | |
Mathieu
2017/05/02 13:16:10
If you die, we have no idea what this does (please
anthonyvd
2017/05/02 13:43:32
Done.
| |
26 public: | |
27 SheetView() | |
28 : first_focusable_(nullptr), | |
29 focus_search_(base::MakeUnique<views::FocusSearch>(this, true, false)) { | |
30 } | |
31 | |
32 // Sets |view| as the first focusable view in this pane. If it's nullptr, the | |
33 // fallback is to use focus_search_ to find the first focusable view. | |
34 void SetFirstFocusableView(views::View* view) { first_focusable_ = view; } | |
35 | |
36 private: | |
37 // views::FocusTraversable: | |
38 views::FocusSearch* GetFocusSearch() override { return focus_search_.get(); } | |
39 | |
40 views::FocusTraversable* GetFocusTraversableParent() override { | |
41 return parent()->GetFocusTraversable(); | |
42 } | |
43 | |
44 views::View* GetFocusTraversableParentView() override { return this; } | |
45 | |
46 // views::View: | |
47 views::FocusTraversable* GetPaneFocusTraversable() override { return this; } | |
48 | |
49 void RequestFocus() override { | |
50 views::View* first_focusable = first_focusable_; | |
51 | |
52 if (!first_focusable) { | |
53 views::FocusTraversable* dummy_focus_traversable; | |
54 views::View* dummy_focus_traversable_view; | |
55 first_focusable = focus_search_->FindNextFocusableView( | |
56 nullptr, false, views::FocusSearch::DOWN, false, | |
57 &dummy_focus_traversable, &dummy_focus_traversable_view); | |
58 } | |
59 | |
60 if (first_focusable) | |
61 first_focusable->RequestFocus(); | |
62 } | |
63 | |
64 views::View* first_focusable_; | |
65 std::unique_ptr<views::FocusSearch> focus_search_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(SheetView); | |
68 }; | |
69 | |
70 } // namespace | |
71 | |
22 PaymentRequestSheetController::PaymentRequestSheetController( | 72 PaymentRequestSheetController::PaymentRequestSheetController( |
23 PaymentRequestSpec* spec, | 73 PaymentRequestSpec* spec, |
24 PaymentRequestState* state, | 74 PaymentRequestState* state, |
25 PaymentRequestDialogView* dialog) | 75 PaymentRequestDialogView* dialog) |
26 : spec_(spec), state_(state), dialog_(dialog) {} | 76 : spec_(spec), state_(state), dialog_(dialog) {} |
27 | 77 |
28 PaymentRequestSheetController::~PaymentRequestSheetController() {} | 78 PaymentRequestSheetController::~PaymentRequestSheetController() {} |
29 | 79 |
30 std::unique_ptr<views::View> PaymentRequestSheetController::CreateView() { | 80 std::unique_ptr<views::View> PaymentRequestSheetController::CreateView() { |
31 std::unique_ptr<views::View> view = CreatePaymentView(); | 81 std::unique_ptr<views::View> view = CreatePaymentView(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 dialog()->Pay(); | 124 dialog()->Pay(); |
75 break; | 125 break; |
76 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX: | 126 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX: |
77 NOTREACHED(); | 127 NOTREACHED(); |
78 break; | 128 break; |
79 } | 129 } |
80 } | 130 } |
81 | 131 |
82 std::unique_ptr<views::View> | 132 std::unique_ptr<views::View> |
83 PaymentRequestSheetController::CreatePaymentView() { | 133 PaymentRequestSheetController::CreatePaymentView() { |
84 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); | 134 std::unique_ptr<SheetView> view = base::MakeUnique<SheetView>(); |
85 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); | 135 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); |
86 | 136 |
87 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a | 137 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a |
88 // layer) won't do proper clipping. | 138 // layer) won't do proper clipping. |
89 view->SetPaintToLayer(); | 139 view->SetPaintToLayer(); |
90 | 140 |
91 views::GridLayout* layout = new views::GridLayout(view.get()); | 141 views::GridLayout* layout = new views::GridLayout(view.get()); |
92 view->SetLayoutManager(layout); | 142 view->SetLayoutManager(layout); |
93 | 143 |
94 // Note: each view is responsible for its own padding (insets). | 144 // Note: each view is responsible for its own padding (insets). |
(...skipping 28 matching lines...) Expand all Loading... | |
123 scroll_ = base::MakeUnique<views::ScrollView>(); | 173 scroll_ = base::MakeUnique<views::ScrollView>(); |
124 scroll_->set_owned_by_client(); | 174 scroll_->set_owned_by_client(); |
125 scroll_->EnableViewPortLayer(); | 175 scroll_->EnableViewPortLayer(); |
126 scroll_->set_hide_horizontal_scrollbar(true); | 176 scroll_->set_hide_horizontal_scrollbar(true); |
127 scroll_->SetContents(pane_); | 177 scroll_->SetContents(pane_); |
128 layout->AddView(scroll_.get()); | 178 layout->AddView(scroll_.get()); |
129 | 179 |
130 layout->StartRow(0, 0); | 180 layout->StartRow(0, 0); |
131 layout->AddView(CreateFooterView().release()); | 181 layout->AddView(CreateFooterView().release()); |
132 | 182 |
183 view->SetFirstFocusableView(GetFirstFocusedView()); | |
184 | |
133 return view; | 185 return view; |
134 } | 186 } |
135 | 187 |
136 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() { | 188 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() { |
137 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); | 189 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
138 | 190 |
139 views::GridLayout* layout = new views::GridLayout(container.get()); | 191 views::GridLayout* layout = new views::GridLayout(container.get()); |
140 container->SetLayoutManager(layout); | 192 container->SetLayoutManager(layout); |
141 | 193 |
142 views::ColumnSet* columns = layout->AddColumnSet(0); | 194 views::ColumnSet* columns = layout->AddColumnSet(0); |
(...skipping 17 matching lines...) Expand all Loading... | |
160 layout->AddView(extra_view.release()); | 212 layout->AddView(extra_view.release()); |
161 else | 213 else |
162 layout->SkipColumns(1); | 214 layout->SkipColumns(1); |
163 | 215 |
164 std::unique_ptr<views::View> trailing_buttons_container = | 216 std::unique_ptr<views::View> trailing_buttons_container = |
165 base::MakeUnique<views::View>(); | 217 base::MakeUnique<views::View>(); |
166 | 218 |
167 trailing_buttons_container->SetLayoutManager(new views::BoxLayout( | 219 trailing_buttons_container->SetLayoutManager(new views::BoxLayout( |
168 views::BoxLayout::kHorizontal, 0, 0, kPaymentRequestButtonSpacing)); | 220 views::BoxLayout::kHorizontal, 0, 0, kPaymentRequestButtonSpacing)); |
169 | 221 |
170 std::unique_ptr<views::Button> primary_button = CreatePrimaryButton(); | 222 primary_button_ = CreatePrimaryButton(); |
171 if (primary_button) | 223 if (primary_button_) { |
172 trailing_buttons_container->AddChildView(primary_button.release()); | 224 primary_button_->set_owned_by_client(); |
225 trailing_buttons_container->AddChildView(primary_button_.get()); | |
226 } | |
173 | 227 |
174 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton( | 228 secondary_button_ = std::unique_ptr<views::Button>( |
175 this, GetSecondaryButtonLabel()); | 229 views::MdTextButton::CreateSecondaryUiButton(this, |
176 button->set_tag(static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG)); | 230 GetSecondaryButtonLabel())); |
177 button->set_id(static_cast<int>(DialogViewID::CANCEL_BUTTON)); | 231 secondary_button_->set_owned_by_client(); |
178 trailing_buttons_container->AddChildView(button); | 232 secondary_button_->set_tag( |
233 static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG)); | |
234 secondary_button_->set_id(static_cast<int>(DialogViewID::CANCEL_BUTTON)); | |
235 trailing_buttons_container->AddChildView(secondary_button_.get()); | |
179 | 236 |
180 layout->AddView(trailing_buttons_container.release()); | 237 layout->AddView(trailing_buttons_container.release()); |
181 | 238 |
182 return container; | 239 return container; |
183 } | 240 } |
184 | 241 |
242 views::View* PaymentRequestSheetController::GetFirstFocusedView() { | |
243 if (primary_button_ && primary_button_->enabled()) | |
244 return primary_button_.get(); | |
245 | |
246 DCHECK(secondary_button_); | |
247 | |
248 return secondary_button_.get(); | |
249 } | |
250 | |
185 } // namespace payments | 251 } // namespace payments |
OLD | NEW |