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

Side by Side Diff: ash/common/system/tray/three_view_layout.h

Issue 2414103003: Added common layout framework for system menu rows. (Closed)
Patch Set: Merge branch 'master' into md_system_menu_layout_mgr 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
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 #ifndef ASH_COMMON_SYSTEM_TRAY_THREE_VIEW_LAYOUT_H_
6 #define ASH_COMMON_SYSTEM_TRAY_THREE_VIEW_LAYOUT_H_
7
8 #include <memory>
9
10 #include "ash/ash_export.h"
11 #include "base/macros.h"
12 #include "ui/gfx/geometry/insets.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/views/layout/layout_manager.h"
15
16 namespace views {
17 class Border;
18 class BoxLayout;
19 class View;
20 } // namespace views
21
22 namespace ash {
23 class SizeRangeLayout;
24
25 // A layout manager that has 3 child containers (START, CENTER, END) which can
26 // be arranged vertically or horizontally. The child containers can have
27 // minimum and/or maximum preferred size defined as well as a flex weight that
28 // is used to distribute excess space across the main axis, i.e. flexible width
29 // for the horizontal orientation. By default all the containers have a flex
30 // weight of 0, meaning no flexibility, and no minimum or maximum size.
31 //
32 // Views are laid out within each container as per the LayoutManager that has
33 // been installed on that container. By default a BoxLayout manager is installed
34 // on each container with the same orientation as this has been created with.
tdanderson 2016/10/19 18:30:59 nit: |this|
bruthig 2016/10/20 04:40:12 Done.
35 // The default BoxLayout will use a center alignment for both the main axis and
36 // cross axis alignment.
37 class ASH_EXPORT ThreeViewLayout : public views::LayoutManager {
38 public:
39 enum Orientation {
40 HORIZONTAL,
41 VERTICAL,
42 };
43
44 // The different containers that child Views can be added to.
45 enum Container { START, CENTER, END };
tdanderson 2016/10/19 18:30:59 Using enum class is preferred to enum (ditto for O
bruthig 2016/10/20 04:40:12 Done.
46
47 // Constructs a layout with horizontal orientation and 0 padding between
48 // containers.
49 ThreeViewLayout();
50
51 // Constructs a layout with Horizontal orientation and the specified padding
52 // between containers.
53 //
54 // TODO(bruthig): The |padding_between_containers| can only be set on
55 // BoxLayouts during construction. Investigate whether this can be a mutable
56 // property of BoxLayouts and if so consider dropping it as a constructor
57 // parameter here.
58 explicit ThreeViewLayout(int padding_between_containers);
59
60 // Constructs a layout with the specified orientation and 0 padding between
61 // containers.
62 explicit ThreeViewLayout(Orientation orientation);
63
64 // Constructs a layout with the specified orientation and padding between
65 // containers.
66 ThreeViewLayout(Orientation orientation, int padding_between_containers);
67
68 ~ThreeViewLayout() override;
69
70 // Set the minimum cross axis size for the layout, i.e. the minimum height for
71 // a horizontal orientation.
72 void SetMinCrossAxisSize(int min_size);
73
74 // Set the minimum size for the given |container|.
75 void SetMinSize(Container container, const gfx::Size& size);
76
77 // Set the maximum size for the given |container|.
78 void SetMaxSize(Container container, const gfx::Size& size);
79
80 // Adds the child |view| to the specified |container|.
81 void AddView(Container container, views::View* view);
82
83 // Removes all current children from the specified |container| and adds the
84 // child |view| to it.
85 void SetView(Container container, views::View* view);
86
87 // Sets the |insets| that all of the container spaces will be laid out within.
tdanderson 2016/10/19 18:30:59 Just reading the documentation here I find it a bi
bruthig 2016/10/20 04:40:12 Updated, WDYT?
tdanderson 2016/10/20 18:16:49 New description is much clearer, thanks
88 void SetInsets(const gfx::Insets& insets);
89
90 // Sets the border for the given |container|.
91 void SetBorder(Container container, std::unique_ptr<views::Border> border);
92
93 // Sets wither the |container| is visible. When a container is set to
94 // not-visible its space will be distributed to the other visible containers.
tdanderson 2016/10/19 18:30:59 And I assume that if a container transitions from
bruthig 2016/10/20 04:40:12 Updated. WDYT?
tdanderson 2016/10/20 18:16:48 Looks good
95 void SetContainerVisible(Container container, bool visible);
96
97 // Sets the flex weight for the given |container|. Using the preferred size as
98 // the basis, free space along the main axis is distributed to views in the
99 // ratio of their flex weights. Similarly, if the views will overflow the
100 // parent, space is subtracted in these ratios.
101 //
102 // A flex of 0 means this view is not resized. Flex values must not be
103 // negative.
104 void SetFlexForContainer(Container container, int flex);
105
106 // Sets the |layout_manager| used by the given |container|.
107 void SetLayoutManager(Container container,
108 std::unique_ptr<LayoutManager> layout_manager);
109
110 // LayoutManager:
111 void Installed(views::View* host) override;
112 void Layout(views::View* host) override;
113 gfx::Size GetPreferredSize(const views::View* host) const override;
114 int GetPreferredHeightForWidth(const views::View* host,
115 int width) const override;
116 void ViewAdded(views::View* host, views::View* view) override;
117 void ViewRemoved(views::View* host, views::View* view) override;
118
119 private:
120 friend class ThreeViewLayoutTest;
121
122 // Creates a default LayoutManager for the given |orientation|.
123 std::unique_ptr<views::LayoutManager> CreateDefaultLayoutManager(
124 Orientation orientation) const;
125
126 // Returns the View for the given |container|.
127 views::View* GetContainer(Container container) const;
128
129 // Returns the layout manager for the given |container|.
130 SizeRangeLayout* GetLayoutManager(Container container) const;
131
132 // The layout manager that lays out the different Container Views.
133 std::unique_ptr<views::BoxLayout> box_layout_;
134
135 // The host View that this layout manager has been installed on.
136 views::View* host_ = nullptr;
137
138 views::View* start_container_ = nullptr;
139 SizeRangeLayout* start_container_layout_manager_ = nullptr;
140
141 views::View* center_container_ = nullptr;
142 SizeRangeLayout* center_container_layout_manager_ = nullptr;
143
144 views::View* end_container_ = nullptr;
145 SizeRangeLayout* end_container_layout_manager_ = nullptr;
146
147 DISALLOW_COPY_AND_ASSIGN(ThreeViewLayout);
148 };
149
150 } // namespace ash
151
152 #endif // ASH_COMMON_SYSTEM_TRAY_THREE_VIEW_LAYOUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698