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

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

Issue 2836313002: BoxLayout now suports per-view margins. (Closed)
Patch Set: BoxLayout now uses Margins property on the view 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/view.h » ('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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 void SetDefaultFlex(int default_flex); 98 void SetDefaultFlex(int default_flex);
99 99
100 // Overridden from views::LayoutManager: 100 // Overridden from views::LayoutManager:
101 void Installed(View* host) override; 101 void Installed(View* host) override;
102 void ViewRemoved(View* host, View* view) override; 102 void ViewRemoved(View* host, View* view) override;
103 void Layout(View* host) override; 103 void Layout(View* host) override;
104 gfx::Size GetPreferredSize(const View* host) const override; 104 gfx::Size GetPreferredSize(const View* host) const override;
105 int GetPreferredHeightForWidth(const View* host, int width) const override; 105 int GetPreferredHeightForWidth(const View* host, int width) const override;
106 106
107 private: 107 private:
108 // This struct is used internally to "wrap" a child view in order to obviate
109 // the need for the main layout logic to be aware of the per-view margins.
110 // Since each view is a rectangle of a certain size, this wrapper, coupled
111 // with any margins set will increase the apparent size of the view. All
112 // necessary view size/position methods required for the layout logic add or
113 // subtract the margins where appropriate to ensure the actual visible size
114 // of the view doesn't include the margins.
115 struct ViewWrapper {
116 ViewWrapper();
117 ViewWrapper(View* view);
118 ViewWrapper(const ViewWrapper& wrapper) = delete;
119 ~ViewWrapper();
120 int GetHeightForWidth(int width) const;
121 gfx::Size GetPreferredSize() const;
122 void SetBoundsRect(const gfx::Rect& bounds);
123 View* view() const { return view_; }
124 bool visible() const;
125
126 private:
127 View* view_;
128 gfx::Insets margins_;
129 };
130
131 using FlexMap = std::map<const View*, int>;
132
108 // Returns the flex for the specified |view|. 133 // Returns the flex for the specified |view|.
109 int GetFlexForView(const View* view) const; 134 int GetFlexForView(const View* view) const;
110 135
111 // Returns the size and position along the main axis of |rect|. 136 // Returns the size and position along the main axis of |rect|.
112 int MainAxisSize(const gfx::Rect& rect) const; 137 int MainAxisSize(const gfx::Rect& rect) const;
113 int MainAxisPosition(const gfx::Rect& rect) const; 138 int MainAxisPosition(const gfx::Rect& rect) const;
114 139
115 // Sets the size and position along the main axis of |rect|. 140 // Sets the size and position along the main axis of |rect|.
116 void SetMainAxisSize(int size, gfx::Rect* rect) const; 141 void SetMainAxisSize(int size, gfx::Rect* rect) const;
117 void SetMainAxisPosition(int position, gfx::Rect* rect) const; 142 void SetMainAxisPosition(int position, gfx::Rect* rect) const;
118 143
119 // Returns the size and position along the cross axis of |rect|. 144 // Returns the size and position along the cross axis of |rect|.
120 int CrossAxisSize(const gfx::Rect& rect) const; 145 int CrossAxisSize(const gfx::Rect& rect) const;
121 int CrossAxisPosition(const gfx::Rect& rect) const; 146 int CrossAxisPosition(const gfx::Rect& rect) const;
122 147
123 // Sets the size and position along the cross axis of |rect|. 148 // Sets the size and position along the cross axis of |rect|.
124 void SetCrossAxisSize(int size, gfx::Rect* rect) const; 149 void SetCrossAxisSize(int size, gfx::Rect* rect) const;
125 void SetCrossAxisPosition(int size, gfx::Rect* rect) const; 150 void SetCrossAxisPosition(int size, gfx::Rect* rect) const;
126 151
127 // Returns the main axis size for the given view. |child_area_width| is needed 152 // Returns the main axis size for the given view. |child_area_width| is needed
128 // to calculate the height of the view when the orientation is vertical. 153 // to calculate the height of the view when the orientation is vertical.
129 int MainAxisSizeForView(const View* view, int child_area_width) const; 154 int MainAxisSizeForView(const ViewWrapper& view, int child_area_width) const;
130 155
131 // Returns the cross axis size for the given view. 156 // Returns the cross axis size for the given view.
132 int CrossAxisSizeForView(const View* view) const; 157 int CrossAxisSizeForView(const ViewWrapper& view) const;
133 158
134 // The preferred size for the dialog given the width of the child area. 159 // The preferred size for the dialog given the width of the child area.
135 gfx::Size GetPreferredSizeForChildWidth(const View* host, 160 gfx::Size GetPreferredSizeForChildWidth(const View* host,
136 int child_area_width) const; 161 int child_area_width) const;
137 162
138 // The amount of space the layout requires in addition to any space for the 163 // The amount of space the layout requires in addition to any space for the
139 // child views. 164 // child views.
140 gfx::Size NonChildSize(const View* host) const; 165 gfx::Size NonChildSize(const View* host) const;
141 166
142 const Orientation orientation_; 167 const Orientation orientation_;
143 168
144 // Spacing between child views and host view border. 169 // Spacing between child views and host view border.
145 gfx::Insets inside_border_insets_; 170 gfx::Insets inside_border_insets_;
146 171
147 // Spacing to put in between child views. 172 // Spacing to put in between child views.
148 const int between_child_spacing_; 173 const int between_child_spacing_;
149 174
150 // The alignment of children in the main axis. This is 175 // The alignment of children in the main axis. This is
151 // MAIN_AXIS_ALIGNMENT_START by default. 176 // MAIN_AXIS_ALIGNMENT_START by default.
152 MainAxisAlignment main_axis_alignment_; 177 MainAxisAlignment main_axis_alignment_;
153 178
154 // The alignment of children in the cross axis. This is 179 // The alignment of children in the cross axis. This is
155 // CROSS_AXIS_ALIGNMENT_STRETCH by default. 180 // CROSS_AXIS_ALIGNMENT_STRETCH by default.
156 CrossAxisAlignment cross_axis_alignment_; 181 CrossAxisAlignment cross_axis_alignment_;
157 182
158 // A map of views to their flex weights. 183 // A map of views to their flex weights.
159 std::map<const View*, int> flex_map_; 184 FlexMap flex_map_;
160 185
161 // The flex weight for views if none is set. Defaults to 0. 186 // The flex weight for views if none is set. Defaults to 0.
162 int default_flex_; 187 int default_flex_;
163 188
164 // The minimum cross axis size for the layout. 189 // The minimum cross axis size for the layout.
165 int minimum_cross_axis_size_; 190 int minimum_cross_axis_size_;
166 191
167 // The view that this BoxLayout is managing the layout for. 192 // The view that this BoxLayout is managing the layout for.
168 views::View* host_; 193 views::View* host_;
169 194
170 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout); 195 DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout);
171 }; 196 };
172 197
173 } // namespace views 198 } // namespace views
174 199
175 #endif // UI_VIEWS_LAYOUT_BOX_LAYOUT_H_ 200 #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/view.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698