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/three_view_layout.h" | |
9 #include "ash/common/system/tray/tray_constants.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 ThreeViewLayout* TrayPopupLayoutFactory::InstallDefaultLayout( | |
45 views::View* host) { | |
46 ThreeViewLayout* layout = new ThreeViewLayout(0 /* padding_between_items */); | |
47 | |
48 // views::BoxLayout::SetFlexForView() fails on a DCHECK() if it has not yet | |
49 // been installed on a View. Evaluate whether this is necessary or if it can | |
50 // be removed. This would allow us to drop the |host| parameter from this | |
tdanderson
2016/10/19 18:31:00
nit: wrap this in a TODO
bruthig
2016/10/20 04:40:13
Done.
| |
51 // function. | |
52 host->SetLayoutManager(layout); | |
53 | |
54 layout->SetInsets(gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), | |
55 0, | |
56 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); | |
57 layout->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | |
58 | |
59 ConfigureDefaultLayout(layout, ThreeViewLayout::START); | |
60 ConfigureDefaultLayout(layout, ThreeViewLayout::CENTER); | |
61 ConfigureDefaultLayout(layout, ThreeViewLayout::END); | |
62 | |
63 return layout; | |
64 } | |
65 | |
66 void TrayPopupLayoutFactory::ConfigureDefaultLayout( | |
67 ThreeViewLayout* layout, | |
68 ThreeViewLayout::Container container) { | |
69 switch (container) { | |
70 case ThreeViewLayout::START: | |
71 layout->SetLayoutManager(ThreeViewLayout::START, | |
72 CreateDefaultEndsLayoutManager()); | |
73 layout->SetMinSize( | |
74 ThreeViewLayout::START, | |
75 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); | |
76 break; | |
77 case ThreeViewLayout::CENTER: | |
78 layout->SetLayoutManager(ThreeViewLayout::CENTER, | |
79 CreateDefaultCenterLayoutManager()); | |
80 layout->SetFlexForContainer(ThreeViewLayout::CENTER, 1.f); | |
81 break; | |
82 case ThreeViewLayout::END: | |
83 layout->SetLayoutManager(ThreeViewLayout::END, | |
84 CreateDefaultEndsLayoutManager()); | |
85 layout->SetMinSize( | |
86 ThreeViewLayout::END, | |
87 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); | |
88 break; | |
89 } | |
90 } | |
91 | |
92 } // namespace ash | |
OLD | NEW |