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

Unified Diff: chrome/browser/ui/cocoa/autofill/simple_grid_layout.h

Issue 14704004: [Autofill] Add Details Section (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/autofill/simple_grid_layout.h
diff --git a/chrome/browser/ui/cocoa/autofill/simple_grid_layout.h b/chrome/browser/ui/cocoa/autofill/simple_grid_layout.h
new file mode 100644
index 0000000000000000000000000000000000000000..77566210206981ad930bd9896ffcd5c6646f2b7b
--- /dev/null
+++ b/chrome/browser/ui/cocoa/autofill/simple_grid_layout.h
@@ -0,0 +1,135 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
sail 2013/05/01 17:12:36 I think it would be better to move this into ui/ba
groby-ooo-7-16 2013/05/01 20:37:44 I proposed this on chromium-dev - there was medium
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_COCOA_AUTOFILL_SIMPLE_GRID_LAYOUT_H_
+#define CHROME_BROWSER_UI_COCOA_AUTOFILL_SIMPLE_GRID_LAYOUT_H_
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+
+class Column;
+class ColumnSet;
+class Row;
+class ViewState;
+
+// SimpleGridLayout is a layout manager that positions child views in a grid.
+// Each row has exactly one ColumnSet, ColumnSets can be shared between rows.
+// See ui/views/layout/grid_layout.h for more details - this is a very
+// simplified version of the views class.
+class SimpleGridLayout {
+ public:
+ SimpleGridLayout(NSView* host);
+ ~SimpleGridLayout();
+
+ // Creates a new column set with the specified id and returns it.
+ // The id is later used when starting a new row.
+ // Layout takes ownership of the ColumnSet and will delete it when
+ // it is deleted.
+ ColumnSet* AddColumnSet(int id);
+
+ // Returns the column set for the specified id, or NULL if one doesn't exist.
+ ColumnSet* GetColumnSet(int id);
+
+ // Adds a padding row. Padding rows typically don't have any views, but are
+ // used to provide vertical white space between views.
+ // |size| specifies the height of the row.
+ void AddPaddingRow(int size);
+
+ // Starts a new row with the specified column set.
+ void StartRow(float vertical_resize, int column_set_id);
+
+ // This is a convenience function that starts a new row,
+ // and returns a new ColumnSet associated with it. All rows created by this
+ // will have a height of 0 and resize_percent set to 1.0.
+ ColumnSet* AddRow();
+
+ // Advances past columns. Use this when the current column should not
+ // contain any views.
+ void SkipColumns(int col_count);
+
+ // TODO(groby): This currently *must* be called after a StartRow for the row
+ // the view is in. At some point, I'd like an AddView that just populates
+ // the next available slot, if possible.
+ void AddView(NSView* view);
+
+ // Layout all contained views according to constraints.
+ void Layout(NSView* superView);
+
+ void SizeRowsAndColumns(float width);
+
+ // Advances next_column_ past any padding columns.
+ void SkipPaddingColumns();
+
+ // Returns the column set of the last non-padding row.
+ ColumnSet* GetLastValidColumnSet();
+
+ // Get the height of a given row.
+ float GetRowHeight(int row);
+
+ // Y-position for a given row.
+ float GetRowLocation(int row_index) const;
+
+ // Get the preferred height for the given width.
+ float GetPreferredHeightForWidth(float with);
+
+ int num_rows() const { return static_cast<int>(rows_.size()); }
+
+ // These functions are mostly for testing & deviate from Views Layout class.
+ int next_column() { return next_column_; }
+ void AdvanceColumn() { next_column_++; }
+
+ private:
+ // Adds a new row, updating associated counters and positions.
+ void AddRow(Row* row);
+
+ // Next column in the current ColumnSet.
+ int next_column_;
+
+ int current_auto_id_; // Starting value for autogenerated columnset ids.
+ ScopedVector<ViewState> view_states_;
+ ScopedVector<ColumnSet> column_sets_;
+ ScopedVector<Row> rows_;
+
+ NSView* host_;
+};
+
+// ColumnSet is used to define a set of columns.
+// You don't create a ColumnSet directly, instead use the AddRow method
+// of SimpleGridLayout.
+class ColumnSet {
+ public:
+ explicit ColumnSet(int id);
+ ~ColumnSet();
+
+ void AddPaddingColumn(int fixed_width);
+ void AddColumn(float resize_percent);
+
+ void CalculateSize(float width);
+ void ResetColumnXCoordinates();
+
+ // ID of this ColumnSet.
+ int id() const { return id_; }
+
+ int num_columns() const { return static_cast<int>(columns_.size()); }
+
+ // Returns the width of the specified columns.
+ float GetColumnWidth(int column);
+
+ Column* GetColumn(int column_index) {
+ DCHECK(column_index >=0 && column_index < num_columns());
+ return columns_[column_index];
+ }
+ // These functions are mostly for testing & deviate from Views Layout class.
+ float ColumnLocation(int column_index);
+ private:
+ float CalculateRemainingWidth(float width);
+ void DistributeRemainingWidth(float width);
+
+ ScopedVector<Column> columns_;
+ int id_;
+};
+
+#endif // CHROME_BROWSER_UI_COCOA_AUTOFILL_SIMPLE_GRID_LAYOUT_H_

Powered by Google App Engine
This is Rietveld 408576698