OLD | NEW |
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_GRID_LAYOUT_H_ | 5 #ifndef UI_VIEWS_LAYOUT_GRID_LAYOUT_H_ |
6 #define UI_VIEWS_LAYOUT_GRID_LAYOUT_H_ | 6 #define UI_VIEWS_LAYOUT_GRID_LAYOUT_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "ui/gfx/geometry/insets.h" | 14 #include "ui/gfx/geometry/insets.h" |
14 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
15 #include "ui/views/layout/layout_manager.h" | 16 #include "ui/views/layout/layout_manager.h" |
16 | 17 |
17 // GridLayout is a LayoutManager that positions child Views in a grid. You | 18 // GridLayout is a LayoutManager that positions child Views in a grid. You |
18 // define the structure of the Grid first, then add the Views. | 19 // define the structure of the Grid first, then add the Views. |
19 // The following creates a trivial grid with two columns separated by | 20 // The following creates a trivial grid with two columns separated by |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 int width, | 191 int width, |
191 int height, | 192 int height, |
192 gfx::Size* pref) const; | 193 gfx::Size* pref) const; |
193 | 194 |
194 // Calculates the master columns of all the column sets. See Column for | 195 // Calculates the master columns of all the column sets. See Column for |
195 // a description of what a master column is. | 196 // a description of what a master column is. |
196 void CalculateMasterColumnsIfNecessary() const; | 197 void CalculateMasterColumnsIfNecessary() const; |
197 | 198 |
198 // This is called internally from AddView. It adds the ViewState to the | 199 // This is called internally from AddView. It adds the ViewState to the |
199 // appropriate structures, and updates internal fields such as next_column_. | 200 // appropriate structures, and updates internal fields such as next_column_. |
200 void AddViewState(ViewState* view_state); | 201 void AddViewState(std::unique_ptr<ViewState> view_state); |
201 | 202 |
202 // Adds the Row to rows_, as well as updating next_column_, | 203 // Adds the Row to rows_, as well as updating next_column_, |
203 // current_row_col_set ... | 204 // current_row_col_set ... |
204 void AddRow(Row* row); | 205 void AddRow(std::unique_ptr<Row> row); |
205 | 206 |
206 // As the name says, updates the remaining_height of the ViewState for | 207 // As the name says, updates the remaining_height of the ViewState for |
207 // all Rows the supplied ViewState touches. | 208 // all Rows the supplied ViewState touches. |
208 void UpdateRemainingHeightFromRows(ViewState* state) const; | 209 void UpdateRemainingHeightFromRows(ViewState* state) const; |
209 | 210 |
210 // If the view state's remaining height is > 0, it is distributed among | 211 // If the view state's remaining height is > 0, it is distributed among |
211 // the rows the view state touches. This is used during layout to make | 212 // the rows the view state touches. This is used during layout to make |
212 // sure the Rows can accommodate a view. | 213 // sure the Rows can accommodate a view. |
213 void DistributeRemainingHeight(ViewState* state) const; | 214 void DistributeRemainingHeight(ViewState* state) const; |
214 | 215 |
(...skipping 22 matching lines...) Expand all Loading... |
237 // Column set for the current row. This is null for padding rows. | 238 // Column set for the current row. This is null for padding rows. |
238 ColumnSet* current_row_col_set_; | 239 ColumnSet* current_row_col_set_; |
239 | 240 |
240 // Insets. | 241 // Insets. |
241 gfx::Insets insets_; | 242 gfx::Insets insets_; |
242 | 243 |
243 // Set to true when adding a View. | 244 // Set to true when adding a View. |
244 bool adding_view_; | 245 bool adding_view_; |
245 | 246 |
246 // ViewStates. This is ordered by row_span in ascending order. | 247 // ViewStates. This is ordered by row_span in ascending order. |
247 mutable std::vector<ViewState*> view_states_; | 248 mutable std::vector<std::unique_ptr<ViewState>> view_states_; |
248 | 249 |
249 // ColumnSets. | 250 // ColumnSets. |
250 mutable std::vector<ColumnSet*> column_sets_; | 251 mutable std::vector<std::unique_ptr<ColumnSet>> column_sets_; |
251 | 252 |
252 // Rows. | 253 // Rows. |
253 mutable std::vector<Row*> rows_; | 254 mutable std::vector<std::unique_ptr<Row>> rows_; |
254 | 255 |
255 // Minimum preferred size. | 256 // Minimum preferred size. |
256 gfx::Size minimum_size_; | 257 gfx::Size minimum_size_; |
257 | 258 |
258 DISALLOW_COPY_AND_ASSIGN(GridLayout); | 259 DISALLOW_COPY_AND_ASSIGN(GridLayout); |
259 }; | 260 }; |
260 | 261 |
261 // ColumnSet is used to define a set of columns. GridLayout may have any | 262 // ColumnSet is used to define a set of columns. GridLayout may have any |
262 // number of ColumnSets. You don't create a ColumnSet directly, instead | 263 // number of ColumnSets. You don't create a ColumnSet directly, instead |
263 // use the AddColumnSet method of GridLayout. | 264 // use the AddColumnSet method of GridLayout. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 int GetColumnWidth(int start_col, int col_span); | 341 int GetColumnWidth(int start_col, int col_span); |
341 | 342 |
342 // Updates the x coordinate of each column from the previous ones. | 343 // Updates the x coordinate of each column from the previous ones. |
343 // NOTE: this doesn't include the insets. | 344 // NOTE: this doesn't include the insets. |
344 void ResetColumnXCoordinates(); | 345 void ResetColumnXCoordinates(); |
345 | 346 |
346 // Calculate the preferred width of each view in this column set, as well | 347 // Calculate the preferred width of each view in this column set, as well |
347 // as updating the remaining_width. | 348 // as updating the remaining_width. |
348 void CalculateSize(); | 349 void CalculateSize(); |
349 | 350 |
350 // Distributes delta amoung the resizable columns. | 351 // Distributes delta among the resizable columns. |
351 void Resize(int delta); | 352 void Resize(int delta); |
352 | 353 |
353 // ID for this columnset. | 354 // ID for this columnset. |
354 const int id_; | 355 const int id_; |
355 | 356 |
356 // The columns. | 357 // The columns. |
357 std::vector<Column*> columns_; | 358 std::vector<std::unique_ptr<Column>> columns_; |
358 | 359 |
359 // The ViewStates. This is sorted based on column_span in ascending | 360 // The ViewStates. This is sorted based on column_span in ascending |
360 // order. | 361 // order. |
361 std::vector<ViewState*> view_states_; | 362 std::vector<ViewState*> view_states_; |
362 | 363 |
363 // The master column of those columns that are linked. See Column | 364 // The master column of those columns that are linked. See Column |
364 // for a description of what the master column is. | 365 // for a description of what the master column is. |
365 std::vector<Column*> master_columns_; | 366 std::vector<Column*> master_columns_; |
366 | 367 |
367 DISALLOW_COPY_AND_ASSIGN(ColumnSet); | 368 DISALLOW_COPY_AND_ASSIGN(ColumnSet); |
368 }; | 369 }; |
369 | 370 |
370 } // namespace views | 371 } // namespace views |
371 | 372 |
372 #endif // UI_VIEWS_LAYOUT_GRID_LAYOUT_H_ | 373 #endif // UI_VIEWS_LAYOUT_GRID_LAYOUT_H_ |
OLD | NEW |