OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_views_util.h" | 5 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" |
8 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "ui/gfx/vector_icons/vector_icons.h" |
9 #include "ui/views/background.h" | 11 #include "ui/views/background.h" |
| 12 #include "ui/views/bubble/bubble_frame_view.h" |
| 13 #include "ui/views/controls/button/button.h" |
| 14 #include "ui/views/controls/button/vector_icon_button.h" |
10 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
11 #include "ui/views/layout/grid_layout.h" | 16 #include "ui/views/layout/grid_layout.h" |
12 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
13 | 18 |
14 namespace payments { | 19 namespace payments { |
15 | 20 |
| 21 std::unique_ptr<views::View> CreateSheetHeaderView( |
| 22 bool show_back_arrow, |
| 23 const base::string16& title, |
| 24 views::VectorIconButtonDelegate* delegate) { |
| 25 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 26 views::GridLayout* layout = new views::GridLayout(container.get()); |
| 27 container->SetLayoutManager(layout); |
| 28 |
| 29 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 30 // A column for the optional back arrow. |
| 31 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| 32 0, views::GridLayout::USE_PREF, 0, 0); |
| 33 // A column for the title. |
| 34 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 35 1, views::GridLayout::USE_PREF, 0, 0); |
| 36 // A column for the close button. |
| 37 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| 38 0, views::GridLayout::USE_PREF, 0, 0); |
| 39 |
| 40 layout->StartRow(0, 0); |
| 41 if (!show_back_arrow) { |
| 42 layout->SkipColumns(1); |
| 43 } else { |
| 44 views::VectorIconButton* back_arrow = new views::VectorIconButton(delegate); |
| 45 back_arrow->SetIcon(gfx::VectorIconId::NAVIGATE_BACK); |
| 46 back_arrow->SetSize(back_arrow->GetPreferredSize()); |
| 47 back_arrow->set_tag(static_cast<int>( |
| 48 PaymentRequestCommonTags::BACK_BUTTON_TAG)); |
| 49 layout->AddView(back_arrow); |
| 50 } |
| 51 |
| 52 views::Label* title_label = new views::Label(title); |
| 53 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 54 layout->AddView(title_label); |
| 55 views::Button* close_button = |
| 56 views::BubbleFrameView::CreateCloseButton(delegate); |
| 57 close_button->set_tag(static_cast<int>( |
| 58 PaymentRequestCommonTags::CLOSE_BUTTON_TAG)); |
| 59 layout->AddView(close_button); |
| 60 |
| 61 return container; |
| 62 } |
| 63 |
| 64 |
16 std::unique_ptr<views::View> CreatePaymentView( | 65 std::unique_ptr<views::View> CreatePaymentView( |
17 const base::string16& title, std::unique_ptr<views::View> content_view) { | 66 std::unique_ptr<views::View> header_view, |
| 67 std::unique_ptr<views::View> content_view) { |
18 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); | 68 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); |
19 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); | 69 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); |
20 | 70 |
21 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a | 71 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a |
22 // layer) won't do proper clipping. | 72 // layer) won't do proper clipping. |
23 view->SetPaintToLayer(true); | 73 view->SetPaintToLayer(true); |
24 | 74 |
25 views::GridLayout* layout = new views::GridLayout(view.get()); | 75 views::GridLayout* layout = new views::GridLayout(view.get()); |
26 view->SetLayoutManager(layout); | 76 view->SetLayoutManager(layout); |
| 77 |
| 78 constexpr int kTopInsetSize = 9; |
| 79 constexpr int kBottomInsetSize = 18; |
| 80 constexpr int kSideInsetSize = 14; |
| 81 layout->SetInsets( |
| 82 kTopInsetSize, kSideInsetSize, kBottomInsetSize, kSideInsetSize); |
27 views::ColumnSet* columns = layout->AddColumnSet(0); | 83 views::ColumnSet* columns = layout->AddColumnSet(0); |
28 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 84 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
29 1, views::GridLayout::USE_PREF, 0, 0); | 85 1, views::GridLayout::USE_PREF, 0, 0); |
30 | 86 |
31 layout->StartRow(0, 0); | 87 layout->StartRow(0, 0); |
32 layout->AddView(new views::Label(title)); | 88 // |header_view| will be deleted when |view| is. |
| 89 layout->AddView(header_view.release()); |
33 | 90 |
34 layout->StartRow(0, 0); | 91 layout->StartRow(0, 0); |
35 // |content_view| will be deleted when |view| is. | 92 // |content_view| will be deleted when |view| is. |
36 layout->AddView(content_view.release()); | 93 layout->AddView(content_view.release()); |
37 | 94 |
38 return view; | 95 return view; |
39 } | 96 } |
40 | 97 |
41 } // namespace payments | 98 } // namespace payments |
OLD | NEW |