| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_UI_COCOA_AUTOFILL_SIMPLE_GRID_LAYOUT_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_AUTOFILL_SIMPLE_GRID_LAYOUT_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_AUTOFILL_SIMPLE_GRID_LAYOUT_H_ | 6 #define CHROME_BROWSER_UI_COCOA_AUTOFILL_SIMPLE_GRID_LAYOUT_H_ |
| 7 | 7 |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/memory/scoped_vector.h" | 13 #include "base/logging.h" |
| 13 | 14 |
| 14 class Column; | 15 class Column; |
| 15 class ColumnSet; | 16 class ColumnSet; |
| 16 class Row; | 17 class Row; |
| 17 class ViewState; | 18 class ViewState; |
| 18 | 19 |
| 19 // SimpleGridLayout is a layout manager that positions child views in a grid. | 20 // SimpleGridLayout is a layout manager that positions child views in a grid. |
| 20 // Each row has exactly one ColumnSet, ColumnSets can be shared between rows. | 21 // Each row has exactly one ColumnSet, ColumnSets can be shared between rows. |
| 21 // See ui/views/layout/grid_layout.h for more details - this is a very | 22 // See ui/views/layout/grid_layout.h for more details - this is a very |
| 22 // simplified version of the views class. | 23 // simplified version of the views class. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 float GetPreferredHeightForWidth(float with); | 81 float GetPreferredHeightForWidth(float with); |
| 81 | 82 |
| 82 int num_rows() const { return static_cast<int>(rows_.size()); } | 83 int num_rows() const { return static_cast<int>(rows_.size()); } |
| 83 | 84 |
| 84 // These functions are mostly for testing & deviate from Views Layout class. | 85 // These functions are mostly for testing & deviate from Views Layout class. |
| 85 int next_column() { return next_column_; } | 86 int next_column() { return next_column_; } |
| 86 void AdvanceColumn() { next_column_++; } | 87 void AdvanceColumn() { next_column_++; } |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 // Adds a new row, updating associated counters and positions. | 90 // Adds a new row, updating associated counters and positions. |
| 90 void AddRow(Row* row); | 91 void AddRow(std::unique_ptr<Row> row); |
| 91 | 92 |
| 92 // Next column in the current ColumnSet. | 93 // Next column in the current ColumnSet. |
| 93 int next_column_; | 94 int next_column_; |
| 94 | 95 |
| 95 int current_auto_id_; // Starting value for autogenerated columnset ids. | 96 int current_auto_id_; // Starting value for autogenerated columnset ids. |
| 96 ScopedVector<ViewState> view_states_; | 97 std::vector<std::unique_ptr<ViewState>> view_states_; |
| 97 ScopedVector<ColumnSet> column_sets_; | 98 std::vector<std::unique_ptr<ColumnSet>> column_sets_; |
| 98 ScopedVector<Row> rows_; | 99 std::vector<std::unique_ptr<Row>> rows_; |
| 99 | 100 |
| 100 NSView* host_; | 101 NSView* host_; |
| 101 }; | 102 }; |
| 102 | 103 |
| 103 // ColumnSet is used to define a set of columns. | 104 // ColumnSet is used to define a set of columns. |
| 104 // You don't create a ColumnSet directly, instead use the AddRow method | 105 // You don't create a ColumnSet directly, instead use the AddRow method |
| 105 // of SimpleGridLayout. | 106 // of SimpleGridLayout. |
| 106 class ColumnSet { | 107 class ColumnSet { |
| 107 public: | 108 public: |
| 108 explicit ColumnSet(int id); | 109 explicit ColumnSet(int id); |
| 109 ~ColumnSet(); | 110 ~ColumnSet(); |
| 110 | 111 |
| 111 void AddPaddingColumn(int fixed_width); | 112 void AddPaddingColumn(int fixed_width); |
| 112 void AddColumn(float resize_percent); | 113 void AddColumn(float resize_percent); |
| 113 | 114 |
| 114 void CalculateSize(float width); | 115 void CalculateSize(float width); |
| 115 void ResetColumnXCoordinates(); | 116 void ResetColumnXCoordinates(); |
| 116 | 117 |
| 117 // ID of this ColumnSet. | 118 // ID of this ColumnSet. |
| 118 int id() const { return id_; } | 119 int id() const { return id_; } |
| 119 | 120 |
| 120 int num_columns() const { return static_cast<int>(columns_.size()); } | 121 int num_columns() const { return static_cast<int>(columns_.size()); } |
| 121 | 122 |
| 122 // Returns the width of the specified columns. | 123 // Returns the width of the specified columns. |
| 123 float GetColumnWidth(int column); | 124 float GetColumnWidth(int column); |
| 124 | 125 |
| 125 Column* GetColumn(int column_index) { | 126 Column* GetColumn(int column_index) { |
| 126 DCHECK(column_index >=0 && column_index < num_columns()); | 127 DCHECK(column_index >=0 && column_index < num_columns()); |
| 127 return columns_[column_index]; | 128 return columns_[column_index].get(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 // These functions are mostly for testing & deviate from Views Layout class. | 131 // These functions are mostly for testing & deviate from Views Layout class. |
| 131 float ColumnLocation(int column_index); | 132 float ColumnLocation(int column_index); |
| 132 | 133 |
| 133 private: | 134 private: |
| 134 float CalculateRemainingWidth(float width); | 135 float CalculateRemainingWidth(float width); |
| 135 void DistributeRemainingWidth(float width); | 136 void DistributeRemainingWidth(float width); |
| 136 | 137 |
| 137 ScopedVector<Column> columns_; | 138 std::vector<std::unique_ptr<Column>> columns_; |
| 138 int id_; | 139 int id_; |
| 139 }; | 140 }; |
| 140 | 141 |
| 141 #endif // CHROME_BROWSER_UI_COCOA_AUTOFILL_SIMPLE_GRID_LAYOUT_H_ | 142 #endif // CHROME_BROWSER_UI_COCOA_AUTOFILL_SIMPLE_GRID_LAYOUT_H_ |
| OLD | NEW |