| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // Notification that a view has been added. | 171 // Notification that a view has been added. |
| 172 virtual void ViewAdded(View* host, View* view) OVERRIDE; | 172 virtual void ViewAdded(View* host, View* view) OVERRIDE; |
| 173 | 173 |
| 174 // Notification that a view has been removed. | 174 // Notification that a view has been removed. |
| 175 virtual void ViewRemoved(View* host, View* view) OVERRIDE; | 175 virtual void ViewRemoved(View* host, View* view) OVERRIDE; |
| 176 | 176 |
| 177 // Layouts out the components. | 177 // Layouts out the components. |
| 178 virtual void Layout(View* host) OVERRIDE; | 178 virtual void Layout(View* host) OVERRIDE; |
| 179 | 179 |
| 180 // Returns the preferred size for the GridLayout. | 180 // Returns the preferred size for the GridLayout. |
| 181 virtual gfx::Size GetPreferredSize(View* host) OVERRIDE; | 181 virtual gfx::Size GetPreferredSize(const View* host) const OVERRIDE; |
| 182 | 182 |
| 183 virtual int GetPreferredHeightForWidth(View* host, int width) OVERRIDE; | 183 virtual int GetPreferredHeightForWidth(const View* host, |
| 184 int width) const OVERRIDE; |
| 184 | 185 |
| 185 void set_minimum_size(const gfx::Size& size) { minimum_size_ = size; } | 186 void set_minimum_size(const gfx::Size& size) { minimum_size_ = size; } |
| 186 | 187 |
| 187 private: | 188 private: |
| 188 // As both Layout and GetPreferredSize need to do nearly the same thing, | 189 // As both Layout and GetPreferredSize need to do nearly the same thing, |
| 189 // they both call into this method. This sizes the Columns/Rows as | 190 // they both call into this method. This sizes the Columns/Rows as |
| 190 // appropriate. If layout is true, width/height give the width/height the | 191 // appropriate. If layout is true, width/height give the width/height the |
| 191 // of the host, otherwise they are ignored. | 192 // of the host, otherwise they are ignored. |
| 192 void SizeRowsAndColumns(bool layout, int width, int height, gfx::Size* pref); | 193 void SizeRowsAndColumns(bool layout, |
| 194 int width, |
| 195 int height, |
| 196 gfx::Size* pref) const; |
| 193 | 197 |
| 194 // Calculates the master columns of all the column sets. See Column for | 198 // Calculates the master columns of all the column sets. See Column for |
| 195 // a description of what a master column is. | 199 // a description of what a master column is. |
| 196 void CalculateMasterColumnsIfNecessary(); | 200 void CalculateMasterColumnsIfNecessary() const; |
| 197 | 201 |
| 198 // This is called internally from AddView. It adds the ViewState to the | 202 // This is called internally from AddView. It adds the ViewState to the |
| 199 // appropriate structures, and updates internal fields such as next_column_. | 203 // appropriate structures, and updates internal fields such as next_column_. |
| 200 void AddViewState(ViewState* view_state); | 204 void AddViewState(ViewState* view_state); |
| 201 | 205 |
| 202 // Adds the Row to rows_, as well as updating next_column_, | 206 // Adds the Row to rows_, as well as updating next_column_, |
| 203 // current_row_col_set ... | 207 // current_row_col_set ... |
| 204 void AddRow(Row* row); | 208 void AddRow(Row* row); |
| 205 | 209 |
| 206 // As the name says, updates the remaining_height of the ViewState for | 210 // As the name says, updates the remaining_height of the ViewState for |
| 207 // all Rows the supplied ViewState touches. | 211 // all Rows the supplied ViewState touches. |
| 208 void UpdateRemainingHeightFromRows(ViewState* state); | 212 void UpdateRemainingHeightFromRows(ViewState* state) const; |
| 209 | 213 |
| 210 // If the view state's remaining height is > 0, it is distributed among | 214 // 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 | 215 // the rows the view state touches. This is used during layout to make |
| 212 // sure the Rows can accommodate a view. | 216 // sure the Rows can accommodate a view. |
| 213 void DistributeRemainingHeight(ViewState* state); | 217 void DistributeRemainingHeight(ViewState* state) const; |
| 214 | 218 |
| 215 // Advances next_column_ past any padding columns. | 219 // Advances next_column_ past any padding columns. |
| 216 void SkipPaddingColumns(); | 220 void SkipPaddingColumns(); |
| 217 | 221 |
| 218 // Returns the column set of the last non-padding row. | 222 // Returns the column set of the last non-padding row. |
| 219 ColumnSet* GetLastValidColumnSet(); | 223 ColumnSet* GetLastValidColumnSet(); |
| 220 | 224 |
| 221 // The view we were created with. We don't own this. | 225 // The view we were created with. We don't own this. |
| 222 View* const host_; | 226 View* const host_; |
| 223 | 227 |
| 224 // Whether or not we've calculated the master/linked columns. | 228 // Whether or not we've calculated the master/linked columns. |
| 225 bool calculated_master_columns_; | 229 mutable bool calculated_master_columns_; |
| 226 | 230 |
| 227 // Used to verify a view isn't added with a row span that expands into | 231 // Used to verify a view isn't added with a row span that expands into |
| 228 // another column structure. | 232 // another column structure. |
| 229 int remaining_row_span_; | 233 int remaining_row_span_; |
| 230 | 234 |
| 231 // Current row. | 235 // Current row. |
| 232 int current_row_; | 236 int current_row_; |
| 233 | 237 |
| 234 // Current column. | 238 // Current column. |
| 235 int next_column_; | 239 int next_column_; |
| 236 | 240 |
| 237 // Column set for the current row. This is null for padding rows. | 241 // Column set for the current row. This is null for padding rows. |
| 238 ColumnSet* current_row_col_set_; | 242 ColumnSet* current_row_col_set_; |
| 239 | 243 |
| 240 // Insets. | 244 // Insets. |
| 241 gfx::Insets insets_; | 245 gfx::Insets insets_; |
| 242 | 246 |
| 243 // Set to true when adding a View. | 247 // Set to true when adding a View. |
| 244 bool adding_view_; | 248 bool adding_view_; |
| 245 | 249 |
| 246 // ViewStates. This is ordered by row_span in ascending order. | 250 // ViewStates. This is ordered by row_span in ascending order. |
| 247 std::vector<ViewState*> view_states_; | 251 mutable std::vector<ViewState*> view_states_; |
| 248 | 252 |
| 249 // ColumnSets. | 253 // ColumnSets. |
| 250 std::vector<ColumnSet*> column_sets_; | 254 mutable std::vector<ColumnSet*> column_sets_; |
| 251 | 255 |
| 252 // Rows. | 256 // Rows. |
| 253 std::vector<Row*> rows_; | 257 mutable std::vector<Row*> rows_; |
| 254 | 258 |
| 255 // Minimum preferred size. | 259 // Minimum preferred size. |
| 256 gfx::Size minimum_size_; | 260 gfx::Size minimum_size_; |
| 257 | 261 |
| 258 DISALLOW_COPY_AND_ASSIGN(GridLayout); | 262 DISALLOW_COPY_AND_ASSIGN(GridLayout); |
| 259 }; | 263 }; |
| 260 | 264 |
| 261 // ColumnSet is used to define a set of columns. GridLayout may have any | 265 // 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 | 266 // number of ColumnSets. You don't create a ColumnSet directly, instead |
| 263 // use the AddColumnSet method of GridLayout. | 267 // use the AddColumnSet method of GridLayout. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 // The master column of those columns that are linked. See Column | 367 // The master column of those columns that are linked. See Column |
| 364 // for a description of what the master column is. | 368 // for a description of what the master column is. |
| 365 std::vector<Column*> master_columns_; | 369 std::vector<Column*> master_columns_; |
| 366 | 370 |
| 367 DISALLOW_COPY_AND_ASSIGN(ColumnSet); | 371 DISALLOW_COPY_AND_ASSIGN(ColumnSet); |
| 368 }; | 372 }; |
| 369 | 373 |
| 370 } // namespace views | 374 } // namespace views |
| 371 | 375 |
| 372 #endif // UI_VIEWS_LAYOUT_GRID_LAYOUT_H_ | 376 #endif // UI_VIEWS_LAYOUT_GRID_LAYOUT_H_ |
| OLD | NEW |