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

Side by Side Diff: ui/views/layout/box_layout.h

Issue 2836313002: BoxLayout now suports per-view margins. (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | ui/views/layout/box_layout.cc » ('j') | ui/views/layout/box_layout.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ 5 #ifndef UI_VIEWS_LAYOUT_BOX_LAYOUT_H_
6 #define UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ 6 #define UI_VIEWS_LAYOUT_BOX_LAYOUT_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // negative. 90 // negative.
91 void SetFlexForView(const View* view, int flex); 91 void SetFlexForView(const View* view, int flex);
92 92
93 // Clears the flex for the given |view|, causing it to use the default 93 // Clears the flex for the given |view|, causing it to use the default
94 // flex. 94 // flex.
95 void ClearFlexForView(const View* view); 95 void ClearFlexForView(const View* view);
96 96
97 // Sets the flex for views to use when none is specified. 97 // Sets the flex for views to use when none is specified.
98 void SetDefaultFlex(int default_flex); 98 void SetDefaultFlex(int default_flex);
99 99
100 // Clears the margins for the given |view|.
101 void ClearMarginsForView(const View* view);
102
103 // Sets the margins for a specific |view|. The margins are the area around
104 // the outside of the given view into which no other view is placed. This is
105 // in addition to any other horizontal or vertical spacing.
106 void SetViewMargins(const View* view, const gfx::Insets& margins);
sky 2017/04/25 17:28:58 Is there a reason you aren't using a UI property f
107
100 // Overridden from views::LayoutManager: 108 // Overridden from views::LayoutManager:
101 void Installed(View* host) override; 109 void Installed(View* host) override;
102 void ViewRemoved(View* host, View* view) override; 110 void ViewRemoved(View* host, View* view) override;
103 void Layout(View* host) override; 111 void Layout(View* host) override;
104 gfx::Size GetPreferredSize(const View* host) const override; 112 gfx::Size GetPreferredSize(const View* host) const override;
105 int GetPreferredHeightForWidth(const View* host, int width) const override; 113 int GetPreferredHeightForWidth(const View* host, int width) const override;
106 114
107 private: 115 private:
116 struct ViewWrapper {
sky 2017/04/25 17:28:59 Please add a description of this.
117 ViewWrapper();
118 ViewWrapper(const BoxLayout* layout, const View* view);
119 ViewWrapper(const ViewWrapper& wrapper);
120 ~ViewWrapper();
121 gfx::Size GetPreferredSize() const;
122 void SetBoundsRect(const gfx::Rect& bounds);
123 const View* view() const { return view_; }
124 bool visible() const;
125
126 private:
127 const View* view_;
128 const BoxLayout* layout_;
129 gfx::Insets margins_;
130 };
131 using MarginMap = std::map<const View*, gfx::Insets>;
132 using FlexMap = std::map<const View*, int>;
133 friend struct ViewWrappper;
134
108 // Returns the flex for the specified |view|. 135 // Returns the flex for the specified |view|.
109 int GetFlexForView(const View* view) const; 136 int GetFlexForView(const View* view) const;
110 137
111 // Returns the size and position along the main axis of |rect|. 138 // Returns the size and position along the main axis of |rect|.
112 int MainAxisSize(const gfx::Rect& rect) const; 139 int MainAxisSize(const gfx::Rect& rect) const;
113 int MainAxisPosition(const gfx::Rect& rect) const; 140 int MainAxisPosition(const gfx::Rect& rect) const;
114 141
115 // Sets the size and position along the main axis of |rect|. 142 // Sets the size and position along the main axis of |rect|.
116 void SetMainAxisSize(int size, gfx::Rect* rect) const; 143 void SetMainAxisSize(int size, gfx::Rect* rect) const;
117 void SetMainAxisPosition(int position, gfx::Rect* rect) const; 144 void SetMainAxisPosition(int position, gfx::Rect* rect) const;
(...skipping 14 matching lines...) Expand all
132 int CrossAxisSizeForView(const View* view) const; 159 int CrossAxisSizeForView(const View* view) const;
133 160
134 // The preferred size for the dialog given the width of the child area. 161 // The preferred size for the dialog given the width of the child area.
135 gfx::Size GetPreferredSizeForChildWidth(const View* host, 162 gfx::Size GetPreferredSizeForChildWidth(const View* host,
136 int child_area_width) const; 163 int child_area_width) const;
137 164
138 // The amount of space the layout requires in addition to any space for the 165 // The amount of space the layout requires in addition to any space for the
139 // child views. 166 // child views.
140 gfx::Size NonChildSize(const View* host) const; 167 gfx::Size NonChildSize(const View* host) const;
141 168
169 // Returns the margins for the specified |view|.
170 gfx::Insets GetViewMargins(const View* view) const;
171
142 const Orientation orientation_; 172 const Orientation orientation_;
143 173
144 // Spacing between child views and host view border. 174 // Spacing between child views and host view border.
145 gfx::Insets inside_border_insets_; 175 gfx::Insets inside_border_insets_;
146 176
147 // Spacing to put in between child views. 177 // Spacing to put in between child views.
148 const int between_child_spacing_; 178 const int between_child_spacing_;
149 179
150 // The alignment of children in the main axis. This is 180 // The alignment of children in the main axis. This is
151 // MAIN_AXIS_ALIGNMENT_START by default. 181 // MAIN_AXIS_ALIGNMENT_START by default.
152 MainAxisAlignment main_axis_alignment_; 182 MainAxisAlignment main_axis_alignment_;
153 183
154 // The alignment of children in the cross axis. This is 184 // The alignment of children in the cross axis. This is
155 // CROSS_AXIS_ALIGNMENT_STRETCH by default. 185 // CROSS_AXIS_ALIGNMENT_STRETCH by default.
156 CrossAxisAlignment cross_axis_alignment_; 186 CrossAxisAlignment cross_axis_alignment_;
157 187
158 // A map of views to their flex weights. 188 // A map of views to their flex weights.
159 std::map<const View*, int> flex_map_; 189 FlexMap flex_map_;
160 190
161 // The flex weight for views if none is set. Defaults to 0. 191 // The flex weight for views if none is set. Defaults to 0.
162 int default_flex_; 192 int default_flex_;
163 193
164 // The minimum cross axis size for the layout. 194 // The minimum cross axis size for the layout.
165 int minimum_cross_axis_size_; 195 int minimum_cross_axis_size_;
166 196
167 // The view that this BoxLayout is managing the layout for. 197 // The view that this BoxLayout is managing the layout for.
168 views::View* host_; 198 views::View* host_;
169 199
200 // Unique margins around specific views.
201 MarginMap margin_map_;
202
170 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); 203 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout);
171 }; 204 };
172 205
173 } // namespace views 206 } // namespace views
174 207
175 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ 208 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_
OLDNEW
« no previous file with comments | « no previous file | ui/views/layout/box_layout.cc » ('j') | ui/views/layout/box_layout.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698