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 "ash/common/system/tray/tray_popup_layout_factory.h" | 5 #include "ash/common/system/tray/tray_popup_utils.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/system/tray/fixed_sized_image_view.h" |
8 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
9 #include "ash/common/system/tray/tri_view.h" | 10 #include "ash/common/system/tray/tray_popup_label_button.h" |
| 11 #include "ui/views/border.h" |
10 #include "ui/views/controls/button/label_button.h" | 12 #include "ui/views/controls/button/label_button.h" |
| 13 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/controls/label.h" |
11 #include "ui/views/layout/box_layout.h" | 15 #include "ui/views/layout/box_layout.h" |
12 | 16 |
13 namespace ash { | 17 namespace ash { |
14 | 18 |
15 namespace { | 19 namespace { |
16 | 20 |
17 // Creates a layout manager that positions Views vertically. The Views will be | 21 // Creates a layout manager that positions Views vertically. The Views will be |
18 // stretched horizontally and centered vertically. | 22 // stretched horizontally and centered vertically. |
19 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() { | 23 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() { |
20 // TODO(bruthig): Use constants instead of magic numbers. | 24 // TODO(bruthig): Use constants instead of magic numbers. |
(...skipping 13 matching lines...) Expand all Loading... |
34 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 38 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
35 box_layout->set_main_axis_alignment( | 39 box_layout->set_main_axis_alignment( |
36 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 40 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
37 box_layout->set_cross_axis_alignment( | 41 box_layout->set_cross_axis_alignment( |
38 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 42 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
39 return std::unique_ptr<views::LayoutManager>(box_layout); | 43 return std::unique_ptr<views::LayoutManager>(box_layout); |
40 } | 44 } |
41 | 45 |
42 } // namespace | 46 } // namespace |
43 | 47 |
44 TriView* TrayPopupLayoutFactory::CreateDefaultRowView() { | 48 TriView* TrayPopupUtils::CreateDefaultRowView() { |
45 TriView* tri_view = new TriView(0 /* padding_between_items */); | 49 TriView* tri_view = new TriView(0 /* padding_between_items */); |
46 | 50 |
47 tri_view->SetInsets( | 51 tri_view->SetInsets( |
48 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, | 52 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, |
49 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); | 53 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); |
50 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 54 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
51 | 55 |
52 ConfigureDefaultLayout(tri_view, TriView::Container::START); | 56 ConfigureDefaultLayout(tri_view, TriView::Container::START); |
53 ConfigureDefaultLayout(tri_view, TriView::Container::CENTER); | 57 ConfigureDefaultLayout(tri_view, TriView::Container::CENTER); |
54 ConfigureDefaultLayout(tri_view, TriView::Container::END); | 58 ConfigureDefaultLayout(tri_view, TriView::Container::END); |
55 | 59 |
56 return tri_view; | 60 return tri_view; |
57 } | 61 } |
58 | 62 |
59 void TrayPopupLayoutFactory::ConfigureDefaultLayout( | 63 std::unique_ptr<views::LayoutManager> TrayPopupUtils::CreateLayoutManager( |
60 TriView* tri_view, | |
61 TriView::Container container) { | 64 TriView::Container container) { |
62 switch (container) { | 65 switch (container) { |
63 case TriView::Container::START: | 66 case TriView::Container::START: |
64 tri_view->SetContainerLayout(TriView::Container::START, | 67 case TriView::Container::END: |
65 CreateDefaultEndsLayoutManager()); | 68 return CreateDefaultEndsLayoutManager(); |
| 69 case TriView::Container::CENTER: |
| 70 return CreateDefaultCenterLayoutManager(); |
| 71 } |
| 72 // Required by some compilers. |
| 73 NOTREACHED(); |
| 74 return nullptr; |
| 75 } |
| 76 |
| 77 views::Label* TrayPopupUtils::CreateDefaultLabel() { |
| 78 views::Label* label = new views::Label(); |
| 79 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 80 label->SetBorder( |
| 81 views::Border::CreateEmptyBorder(0, kTrayPopupLabelHorizontalPadding, 0, |
| 82 kTrayPopupLabelHorizontalPadding)); |
| 83 return label; |
| 84 } |
| 85 |
| 86 views::ImageView* TrayPopupUtils::CreateMainImageView() { |
| 87 return new FixedSizedImageView( |
| 88 GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH), |
| 89 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
| 90 } |
| 91 |
| 92 views::ImageView* TrayPopupUtils::CreateMoreImageView() { |
| 93 views::ImageView* image = new FixedSizedImageView( |
| 94 GetTrayConstant(TRAY_POPUP_ITEM_MORE_IMAGE_CONTAINER_WIDTH), |
| 95 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
| 96 image->EnableCanvasFlippingForRTLUI(true); |
| 97 return image; |
| 98 } |
| 99 |
| 100 void TrayPopupUtils::ConfigureDefaultLayout(TriView* tri_view, |
| 101 TriView::Container container) { |
| 102 switch (container) { |
| 103 case TriView::Container::START: |
66 tri_view->SetMinSize( | 104 tri_view->SetMinSize( |
67 TriView::Container::START, | 105 TriView::Container::START, |
68 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); | 106 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); |
69 break; | 107 break; |
70 case TriView::Container::CENTER: | 108 case TriView::Container::CENTER: |
71 tri_view->SetContainerLayout(TriView::Container::CENTER, | |
72 CreateDefaultCenterLayoutManager()); | |
73 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); | 109 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); |
74 break; | 110 break; |
75 case TriView::Container::END: | 111 case TriView::Container::END: |
76 tri_view->SetContainerLayout(TriView::Container::END, | |
77 CreateDefaultEndsLayoutManager()); | |
78 tri_view->SetMinSize( | 112 tri_view->SetMinSize( |
79 TriView::Container::END, | 113 TriView::Container::END, |
80 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); | 114 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); |
81 break; | 115 break; |
82 } | 116 } |
| 117 |
| 118 tri_view->SetContainerLayout(container, CreateLayoutManager(container)); |
83 } | 119 } |
84 | 120 |
85 } // namespace ash | 121 } // namespace ash |
OLD | NEW |