Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: ash/common/system/tray/tray_popup_layout_factory.cc

Issue 2414103003: Added common layout framework for system menu rows. (Closed)
Patch Set: Moved |layout_manager_| destruction order in ~View(). Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/system/tray/tray_popup_layout_factory.h ('k') | ui/views/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // TODO(bruthig): views::BoxLayout::SetFlexForView() fails on a DCHECK() if it
49 // has not yet been installed on a View. Evaluate whether this is necessary or
50 // if it can be removed. This would allow us to drop the |host| parameter from
51 // this 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::Container::START);
60 ConfigureDefaultLayout(layout, ThreeViewLayout::Container::CENTER);
61 ConfigureDefaultLayout(layout, ThreeViewLayout::Container::END);
62
63 return layout;
64 }
65
66 void TrayPopupLayoutFactory::ConfigureDefaultLayout(
67 ThreeViewLayout* layout,
68 ThreeViewLayout::Container container) {
69 switch (container) {
70 case ThreeViewLayout::Container::START:
71 layout->SetLayoutManager(ThreeViewLayout::Container::START,
72 CreateDefaultEndsLayoutManager());
73 layout->SetMinSize(
74 ThreeViewLayout::Container::START,
75 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0));
76 break;
77 case ThreeViewLayout::Container::CENTER:
78 layout->SetLayoutManager(ThreeViewLayout::Container::CENTER,
79 CreateDefaultCenterLayoutManager());
80 layout->SetFlexForContainer(ThreeViewLayout::Container::CENTER, 1.f);
81 break;
82 case ThreeViewLayout::Container::END:
83 layout->SetLayoutManager(ThreeViewLayout::Container::END,
84 CreateDefaultEndsLayoutManager());
85 layout->SetMinSize(
86 ThreeViewLayout::Container::END,
87 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0));
88 break;
89 }
90 }
91
92 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/tray_popup_layout_factory.h ('k') | ui/views/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698