| 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" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 PaymentRequestSheetController::PaymentRequestSheetController( | 80 PaymentRequestSheetController::PaymentRequestSheetController( |
| 81 PaymentRequestSpec* spec, | 81 PaymentRequestSpec* spec, |
| 82 PaymentRequestState* state, | 82 PaymentRequestState* state, |
| 83 PaymentRequestDialogView* dialog) | 83 PaymentRequestDialogView* dialog) |
| 84 : spec_(spec), state_(state), dialog_(dialog) {} | 84 : spec_(spec), state_(state), dialog_(dialog) {} |
| 85 | 85 |
| 86 PaymentRequestSheetController::~PaymentRequestSheetController() {} | 86 PaymentRequestSheetController::~PaymentRequestSheetController() {} |
| 87 | 87 |
| 88 std::unique_ptr<views::View> PaymentRequestSheetController::CreateView() { | 88 std::unique_ptr<views::View> PaymentRequestSheetController::CreateView() { |
| 89 std::unique_ptr<views::View> view = CreatePaymentView(); | |
| 90 UpdateContentView(); | |
| 91 return view; | |
| 92 } | |
| 93 | |
| 94 void PaymentRequestSheetController::UpdateContentView() { | |
| 95 content_view_->RemoveAllChildViews(true); | |
| 96 FillContentView(content_view_); | |
| 97 content_view_->Layout(); | |
| 98 pane_->SizeToPreferredSize(); | |
| 99 // Now that the content and its surrounding pane are updated, force a Layout | |
| 100 // on the ScrollView so that it updates its scroll bars now. | |
| 101 scroll_->Layout(); | |
| 102 } | |
| 103 | |
| 104 std::unique_ptr<views::Button> | |
| 105 PaymentRequestSheetController::CreatePrimaryButton() { | |
| 106 return nullptr; | |
| 107 } | |
| 108 | |
| 109 base::string16 PaymentRequestSheetController::GetSecondaryButtonLabel() { | |
| 110 return l10n_util::GetStringUTF16(IDS_CANCEL); | |
| 111 } | |
| 112 | |
| 113 bool PaymentRequestSheetController::ShouldShowHeaderBackArrow() { | |
| 114 return true; | |
| 115 } | |
| 116 | |
| 117 std::unique_ptr<views::View> | |
| 118 PaymentRequestSheetController::CreateExtraFooterView() { | |
| 119 return nullptr; | |
| 120 } | |
| 121 | |
| 122 void PaymentRequestSheetController::ButtonPressed( | |
| 123 views::Button* sender, const ui::Event& event) { | |
| 124 switch (static_cast<PaymentRequestCommonTags>(sender->tag())) { | |
| 125 case PaymentRequestCommonTags::CLOSE_BUTTON_TAG: | |
| 126 dialog()->CloseDialog(); | |
| 127 break; | |
| 128 case PaymentRequestCommonTags::BACK_BUTTON_TAG: | |
| 129 dialog()->GoBack(); | |
| 130 break; | |
| 131 case PaymentRequestCommonTags::PAY_BUTTON_TAG: | |
| 132 dialog()->Pay(); | |
| 133 break; | |
| 134 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX: | |
| 135 NOTREACHED(); | |
| 136 break; | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 std::unique_ptr<views::View> | |
| 141 PaymentRequestSheetController::CreatePaymentView() { | |
| 142 std::unique_ptr<SheetView> view = base::MakeUnique<SheetView>(); | 89 std::unique_ptr<SheetView> view = base::MakeUnique<SheetView>(); |
| 143 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); | 90 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); |
| 144 | 91 |
| 145 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a | 92 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a |
| 146 // layer) won't do proper clipping. | 93 // layer) won't do proper clipping. |
| 147 view->SetPaintToLayer(); | 94 view->SetPaintToLayer(); |
| 148 | 95 |
| 149 views::GridLayout* layout = new views::GridLayout(view.get()); | 96 views::GridLayout* layout = new views::GridLayout(view.get()); |
| 150 view->SetLayoutManager(layout); | 97 view->SetLayoutManager(layout); |
| 151 | 98 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 181 scroll_ = base::MakeUnique<views::ScrollView>(); | 128 scroll_ = base::MakeUnique<views::ScrollView>(); |
| 182 scroll_->set_owned_by_client(); | 129 scroll_->set_owned_by_client(); |
| 183 scroll_->EnableViewPortLayer(); | 130 scroll_->EnableViewPortLayer(); |
| 184 scroll_->set_hide_horizontal_scrollbar(true); | 131 scroll_->set_hide_horizontal_scrollbar(true); |
| 185 scroll_->SetContents(pane_); | 132 scroll_->SetContents(pane_); |
| 186 layout->AddView(scroll_.get()); | 133 layout->AddView(scroll_.get()); |
| 187 | 134 |
| 188 layout->StartRow(0, 0); | 135 layout->StartRow(0, 0); |
| 189 layout->AddView(CreateFooterView().release()); | 136 layout->AddView(CreateFooterView().release()); |
| 190 | 137 |
| 138 UpdateContentView(); |
| 139 |
| 191 view->SetFirstFocusableView(GetFirstFocusedView()); | 140 view->SetFirstFocusableView(GetFirstFocusedView()); |
| 141 return std::move(view); |
| 142 } |
| 192 | 143 |
| 193 return std::move(view); | 144 void PaymentRequestSheetController::UpdateContentView() { |
| 145 content_view_->RemoveAllChildViews(true); |
| 146 FillContentView(content_view_); |
| 147 content_view_->Layout(); |
| 148 pane_->SizeToPreferredSize(); |
| 149 // Now that the content and its surrounding pane are updated, force a Layout |
| 150 // on the ScrollView so that it updates its scroll bars now. |
| 151 scroll_->Layout(); |
| 152 } |
| 153 |
| 154 std::unique_ptr<views::Button> |
| 155 PaymentRequestSheetController::CreatePrimaryButton() { |
| 156 return nullptr; |
| 157 } |
| 158 |
| 159 base::string16 PaymentRequestSheetController::GetSecondaryButtonLabel() { |
| 160 return l10n_util::GetStringUTF16(IDS_CANCEL); |
| 161 } |
| 162 |
| 163 bool PaymentRequestSheetController::ShouldShowHeaderBackArrow() { |
| 164 return true; |
| 165 } |
| 166 |
| 167 std::unique_ptr<views::View> |
| 168 PaymentRequestSheetController::CreateExtraFooterView() { |
| 169 return nullptr; |
| 170 } |
| 171 |
| 172 void PaymentRequestSheetController::ButtonPressed(views::Button* sender, |
| 173 const ui::Event& event) { |
| 174 switch (static_cast<PaymentRequestCommonTags>(sender->tag())) { |
| 175 case PaymentRequestCommonTags::CLOSE_BUTTON_TAG: |
| 176 dialog()->CloseDialog(); |
| 177 break; |
| 178 case PaymentRequestCommonTags::BACK_BUTTON_TAG: |
| 179 dialog()->GoBack(); |
| 180 break; |
| 181 case PaymentRequestCommonTags::PAY_BUTTON_TAG: |
| 182 dialog()->Pay(); |
| 183 break; |
| 184 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX: |
| 185 NOTREACHED(); |
| 186 break; |
| 187 } |
| 194 } | 188 } |
| 195 | 189 |
| 196 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() { | 190 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() { |
| 197 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); | 191 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 198 | 192 |
| 199 views::GridLayout* layout = new views::GridLayout(container.get()); | 193 views::GridLayout* layout = new views::GridLayout(container.get()); |
| 200 container->SetLayoutManager(layout); | 194 container->SetLayoutManager(layout); |
| 201 | 195 |
| 202 views::ColumnSet* columns = layout->AddColumnSet(0); | 196 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 203 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | 197 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 views::View* PaymentRequestSheetController::GetFirstFocusedView() { | 244 views::View* PaymentRequestSheetController::GetFirstFocusedView() { |
| 251 if (primary_button_ && primary_button_->enabled()) | 245 if (primary_button_ && primary_button_->enabled()) |
| 252 return primary_button_.get(); | 246 return primary_button_.get(); |
| 253 | 247 |
| 254 DCHECK(secondary_button_); | 248 DCHECK(secondary_button_); |
| 255 | 249 |
| 256 return secondary_button_.get(); | 250 return secondary_button_.get(); |
| 257 } | 251 } |
| 258 | 252 |
| 259 } // namespace payments | 253 } // namespace payments |
| OLD | NEW |