Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 CHROME_BROWSER_UI_COCOA_SIMPLE_GRID_LAYOUT_H_ | |
| 6 #define CHROME_BROWSER_UI_COCOA_SIMPLE_GRID_LAYOUT_H_ | |
| 7 | |
| 8 #import <Cocoa/Cocoa.h> | |
| 9 | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/scoped_vector.h" | |
| 12 | |
| 13 class Column; | |
| 14 class ColumnSet; | |
| 15 class Row; | |
| 16 class ViewState; | |
| 17 | |
| 18 // SimpleGridLayout is a layout manager that positions child views in a grid. | |
| 19 // Each row has exactly one ColumnSet, ColumnSets can be shared between rows. | |
| 20 // See ui/views/layout/grid_layout.h for more details - this is a very | |
| 21 // simplified version of the views class. | |
| 22 class SimpleGridLayout { | |
| 23 public: | |
| 24 SimpleGridLayout(NSView* host); | |
| 25 ~SimpleGridLayout(); | |
| 26 | |
| 27 // Creates a new column set with the specified id and returns it. | |
| 28 // The id is later used when starting a new row. | |
| 29 // Layout takes ownership of the ColumnSet and will delete it when | |
| 30 // it is deleted. | |
| 31 ColumnSet* AddColumnSet(int id); | |
| 32 | |
| 33 // Returns the column set for the specified id, or NULL if one doesn't exist. | |
| 34 ColumnSet* GetColumnSet(int id); | |
| 35 | |
| 36 // Adds a padding row. Padding rows typically don't have any views, but are | |
| 37 // used to provide vertical white space between views. | |
| 38 // |size| specifies the height of the row. | |
| 39 void AddPaddingRow(int size); | |
| 40 | |
| 41 // Starts a new row with the specified column set. | |
| 42 void StartRow(float vertical_resize, int column_set_id); | |
| 43 | |
| 44 // This is a convenience function that starts a new row, | |
| 45 // and returns a new ColumnSet associated with it. All rows created by this | |
| 46 // will have a height of 0 and resize_percent set to 1.0. | |
| 47 ColumnSet* AddRow(); | |
| 48 | |
| 49 // Advances past columns. Use this when the current column should not | |
| 50 // contain any views. | |
| 51 void SkipColumns(int col_count); | |
| 52 | |
| 53 // TODO(groby): This currently *must* be called after a StartRow for the row | |
| 54 // the view is in. At some point, I'd like an AddView that just populates | |
| 55 // the next available slot, if possible. | |
| 56 void AddView(NSView* view); | |
| 57 | |
| 58 // Layout all contained views according to constraints. | |
| 59 void Layout(NSView* superView); | |
| 60 | |
| 61 void SizeRowsAndColumns(float width); | |
| 62 | |
| 63 // Advances next_column_ past any padding columns. | |
| 64 void SkipPaddingColumns(); | |
| 65 | |
| 66 // Returns the column set of the last non-padding row. | |
| 67 ColumnSet* GetLastValidColumnSet(); | |
| 68 | |
| 69 // Get the height of a given row. | |
| 70 float GetRowHeight(int row); | |
| 71 | |
| 72 // Y-position for a given row. | |
| 73 float GetRowLocation(int row_index) const; | |
| 74 | |
| 75 // Get the preferred height for the given width. | |
| 76 float GetPreferredHeightForWidth(float with); | |
| 77 | |
| 78 int num_rows() const { return static_cast<int>(rows_.size()); } | |
| 79 | |
| 80 // These functions are mostly for testing & deviate from Views Layout class. | |
| 81 int next_column() { return next_column_; } | |
| 82 void AdvanceColumn() { next_column_++; } | |
| 83 | |
| 84 private: | |
| 85 // Adds a new row, updating associated counters and positions. | |
| 86 void AddRow(Row* row); | |
| 87 | |
| 88 // Next column in the current ColumnSet. | |
| 89 int next_column_; | |
| 90 | |
| 91 int current_auto_id_; // Starting value for autogenerated columnset ids. | |
| 92 ScopedVector<ViewState> view_states_; | |
| 93 ScopedVector<ColumnSet> column_sets_; | |
| 94 ScopedVector<Row> rows_; | |
| 95 | |
| 96 NSView* host_; | |
| 97 }; | |
| 98 | |
| 99 // ColumnSet is used to define a set of columns. | |
| 100 // You don't create a ColumnSet directly, instead use the AddRow method | |
| 101 // of SimpleGridLayout. | |
| 102 class ColumnSet { | |
| 103 public: | |
| 104 explicit ColumnSet(int id); | |
| 105 ~ColumnSet(); | |
| 106 | |
| 107 void AddPaddingColumn(int fixed_width); | |
| 108 void AddColumn(float resize_percent); | |
| 109 | |
| 110 void CalculateSize(float width); | |
| 111 void ResetColumnXCoordinates(); | |
| 112 | |
| 113 // ID of this ColumnSet. | |
| 114 int id() const { return id_; } | |
| 115 | |
| 116 int num_columns() const { return static_cast<int>(columns_.size()); } | |
| 117 | |
| 118 // Returns the width of the specified columns. | |
| 119 float GetColumnWidth(int column); | |
| 120 | |
| 121 Column* GetColumn(int column_index) { | |
| 122 DCHECK(column_index >=0 && column_index < num_columns()); | |
| 123 return columns_[column_index]; | |
| 124 } | |
|
Robert Sesek
2013/05/02 20:16:46
nit: blank line after
groby-ooo-7-16
2013/05/03 04:31:46
Done.
| |
| 125 // These functions are mostly for testing & deviate from Views Layout class. | |
| 126 float ColumnLocation(int column_index); | |
|
Robert Sesek
2013/05/02 20:16:46
nit: blank line after
groby-ooo-7-16
2013/05/03 04:31:46
Done.
| |
| 127 private: | |
| 128 float CalculateRemainingWidth(float width); | |
| 129 void DistributeRemainingWidth(float width); | |
| 130 | |
| 131 ScopedVector<Column> columns_; | |
| 132 int id_; | |
| 133 }; | |
| 134 | |
| 135 #endif // CHROME_BROWSER_UI_COCOA_SIMPLE_GRID_LAYOUT_H_ | |
| OLD | NEW |