OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/common/system/tray/tray_popup_layout_factory.h" | |
6 | |
7 #include "ash/common/material_design/material_design_controller.h" | |
8 #include "ash/common/system/tray/tray_constants.h" | |
9 #include "ash/common/system/tray/tri_view.h" | |
10 #include "ui/views/controls/button/label_button.h" | |
11 #include "ui/views/layout/box_layout.h" | |
12 | |
13 namespace ash { | |
14 | |
15 namespace { | |
16 | |
17 // Creates a layout manager that positions Views vertically. The Views will be | |
18 // stretched horizontally and centered vertically. | |
19 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() { | |
20 // TODO(bruthig): Use constants instead of magic numbers. | |
21 views::BoxLayout* box_layout = | |
22 new views::BoxLayout(views::BoxLayout::kVertical, 4, 8, 4); | |
23 box_layout->set_main_axis_alignment( | |
24 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
25 box_layout->set_cross_axis_alignment( | |
26 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | |
27 return std::unique_ptr<views::LayoutManager>(box_layout); | |
28 } | |
29 | |
30 // Creates a layout manager that positions Views horizontally. The Views will be | |
31 // centered along the horizontal and vertical axis. | |
32 std::unique_ptr<views::LayoutManager> CreateDefaultEndsLayoutManager() { | |
33 views::BoxLayout* box_layout = | |
34 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
35 box_layout->set_main_axis_alignment( | |
36 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
37 box_layout->set_cross_axis_alignment( | |
38 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
39 return std::unique_ptr<views::LayoutManager>(box_layout); | |
40 } | |
41 | |
42 } // namespace | |
43 | |
44 TriView* TrayPopupLayoutFactory::CreateDefaultRowView() { | |
45 TriView* tri_view = new TriView(0 /* padding_between_items */); | |
46 | |
47 tri_view->SetInsets( | |
48 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, | |
49 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); | |
50 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | |
51 | |
52 ConfigureDefaultLayout(tri_view, TriView::Container::START); | |
53 ConfigureDefaultLayout(tri_view, TriView::Container::CENTER); | |
54 ConfigureDefaultLayout(tri_view, TriView::Container::END); | |
55 | |
56 return tri_view; | |
57 } | |
58 | |
59 void TrayPopupLayoutFactory::ConfigureDefaultLayout( | |
60 TriView* tri_view, | |
61 TriView::Container container) { | |
62 switch (container) { | |
63 case TriView::Container::START: | |
64 tri_view->SetContainerLayout(TriView::Container::START, | |
65 CreateDefaultEndsLayoutManager()); | |
66 tri_view->SetMinSize( | |
67 TriView::Container::START, | |
68 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); | |
69 break; | |
70 case TriView::Container::CENTER: | |
71 tri_view->SetContainerLayout(TriView::Container::CENTER, | |
72 CreateDefaultCenterLayoutManager()); | |
73 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); | |
74 break; | |
75 case TriView::Container::END: | |
76 tri_view->SetContainerLayout(TriView::Container::END, | |
77 CreateDefaultEndsLayoutManager()); | |
78 tri_view->SetMinSize( | |
79 TriView::Container::END, | |
80 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); | |
81 break; | |
82 } | |
83 } | |
84 | |
85 } // namespace ash | |
OLD | NEW |