summaryrefslogtreecommitdiffstats
path: root/views/controls
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 08:03:42 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 08:03:42 +0000
commit8ec2dc84ce04328a0760cc2df988ce3fe8a7dd1e (patch)
tree8acdc901f6e67f3c8b36a0b1b4f3e6a6cfdf8f6c /views/controls
parent8467166c0c79b33681d93c12dd2eb23877282d0c (diff)
downloadchromium_src-8ec2dc84ce04328a0760cc2df988ce3fe8a7dd1e.zip
chromium_src-8ec2dc84ce04328a0760cc2df988ce3fe8a7dd1e.tar.gz
chromium_src-8ec2dc84ce04328a0760cc2df988ce3fe8a7dd1e.tar.bz2
Add options for controlling horizontal and vertical lines in TableView2.
For now, this only works on Linux. Along the way, introduce TableView2::Options, so we can add new options without needing to modify the existing call sites. Additional benefit is that this makes client code more descriptive than having boolean parameters like true, true, false. The original motivation of the change is to get rid of horizontal lines from a table in the language configuration dialog in Chromium OS. TEST=view_examples BUG=crosbug.com/2349 Review URL: http://codereview.chromium.org/1528013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43602 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r--views/controls/table/native_table_gtk.cc12
-rw-r--r--views/controls/table/table_view2.cc35
-rw-r--r--views/controls/table/table_view2.h33
3 files changed, 72 insertions, 8 deletions
diff --git a/views/controls/table/native_table_gtk.cc b/views/controls/table/native_table_gtk.cc
index 779308d..4709cf2 100644
--- a/views/controls/table/native_table_gtk.cc
+++ b/views/controls/table/native_table_gtk.cc
@@ -225,8 +225,16 @@ void NativeTableGtk::CreateNativeControl() {
// Don't make the header clickable until we support sorting.
gtk_tree_view_set_headers_clickable(tree_view_, FALSE);
- // Show horizontal separator lines only.
- gtk_tree_view_set_grid_lines(tree_view_, GTK_TREE_VIEW_GRID_LINES_HORIZONTAL);
+ // Show grid lines based on the options.
+ GtkTreeViewGridLines grid_lines = GTK_TREE_VIEW_GRID_LINES_NONE;
+ if (table_->horizontal_lines() && table_->vertical_lines()) {
+ grid_lines = GTK_TREE_VIEW_GRID_LINES_BOTH;
+ } else if (table_->horizontal_lines()) {
+ grid_lines = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL;
+ } else if (table_->vertical_lines()) {
+ grid_lines = GTK_TREE_VIEW_GRID_LINES_VERTICAL;
+ }
+ gtk_tree_view_set_grid_lines(tree_view_, grid_lines);
int gtk_column_index = 0;
size_t column_index = 0;
diff --git a/views/controls/table/table_view2.cc b/views/controls/table/table_view2.cc
index e9bb42b..77d0cff 100644
--- a/views/controls/table/table_view2.cc
+++ b/views/controls/table/table_view2.cc
@@ -28,12 +28,29 @@ TableView2::TableView2(TableModel* model,
single_selection_(single_selection),
resizable_columns_(resizable_columns),
autosize_columns_(autosize_columns),
+ horizontal_lines_(true),
+ vertical_lines_(false),
native_wrapper_(NULL) {
- for (std::vector<TableColumn>::const_iterator i = columns.begin();
- i != columns.end(); ++i) {
- AddColumn(*i);
- visible_columns_.push_back(i->id);
- }
+ Init(columns);
+}
+
+TableView2::TableView2(TableModel* model,
+ const std::vector<TableColumn>& columns,
+ TableTypes table_type,
+ int options)
+ : model_(model),
+ table_type_(table_type),
+ table_view_observer_(NULL),
+ visible_columns_(),
+ all_columns_(),
+ column_count_(static_cast<int>(columns.size())),
+ single_selection_((options & SINGLE_SELECTION) != 0),
+ resizable_columns_((options & RESIZABLE_COLUMNS) != 0),
+ autosize_columns_((options & AUTOSIZE_COLUMNS) != 0),
+ horizontal_lines_((options & HORIZONTAL_LINES) != 0),
+ vertical_lines_((options & VERTICAL_LINES) != 0),
+ native_wrapper_(NULL) {
+ Init(columns);
}
TableView2::~TableView2() {
@@ -322,6 +339,14 @@ void TableView2::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
}
}
+void TableView2::Init(const std::vector<TableColumn>& columns) {
+ for (std::vector<TableColumn>::const_iterator i = columns.begin();
+ i != columns.end(); ++i) {
+ AddColumn(*i);
+ visible_columns_.push_back(i->id);
+ }
+}
+
gfx::NativeView TableView2::GetTestingHandle() {
return native_wrapper_->GetTestingHandle();
}
diff --git a/views/controls/table/table_view2.h b/views/controls/table/table_view2.h
index fb12b06..e70e7f2 100644
--- a/views/controls/table/table_view2.h
+++ b/views/controls/table/table_view2.h
@@ -57,6 +57,17 @@ class TableView2 : public View, public TableModelObserver {
SkColor color;
};
+ // Bitmasks of options for creating an instance of the table view. See
+ // comments next to the corresponding members in TableView2 for details
+ // (ex. SINGLE_SELECTION -> single_selection_).
+ enum Options {
+ SINGLE_SELECTION = 1 << 0,
+ RESIZABLE_COLUMNS = 1 << 1,
+ AUTOSIZE_COLUMNS = 1 << 2,
+ HORIZONTAL_LINES = 1 << 3,
+ VERTICAL_LINES = 1 << 4,
+ };
+
// Creates a new table using the model and columns specified.
// The table type applies to the content of the first column (text, icon and
// text, checkbox and text).
@@ -74,6 +85,10 @@ class TableView2 : public View, public TableModelObserver {
TableView2(TableModel* model, const std::vector<TableColumn>& columns,
TableTypes table_type, bool single_selection,
bool resizable_columns, bool autosize_columns);
+ // |options| is a bitmask of options. See comments at Options.
+ // TODO(satorux): Convert everyone over to this variant.
+ TableView2(TableModel* model, const std::vector<TableColumn>& columns,
+ TableTypes table_type, int options);
virtual ~TableView2();
// Assigns a new model to the table view, detaching the old one if present.
@@ -168,6 +183,14 @@ class TableView2 : public View, public TableModelObserver {
return autosize_columns_;
}
+ bool horizontal_lines() const {
+ return horizontal_lines_;
+ }
+
+ bool vertical_lines() const {
+ return vertical_lines_;
+ }
+
virtual void DidChangeBounds(const gfx::Rect& previous,
const gfx::Rect& current);
virtual void Layout();
@@ -182,6 +205,9 @@ class TableView2 : public View, public TableModelObserver {
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
private:
+ // Used in the constructors.
+ void Init(const std::vector<TableColumn>& columns);
+
// We need this wrapper to pass the table view to the windows proc handler
// when subclassing the list view and list view header, as the reinterpret
// cast from GetWindowLongPtr would break the pointer if it is pointing to a
@@ -224,6 +250,12 @@ class TableView2 : public View, public TableModelObserver {
// the available width when the list view is resized.
bool autosize_columns_;
+ // Whether or not horizontal grid lines should be drawn.
+ bool horizontal_lines_;
+
+ // Whether or not vertical grid lines should be drawn.
+ bool vertical_lines_;
+
// Mappings used when sorted.
// scoped_array<int> view_to_model_;
// scoped_array<int> model_to_view_;
@@ -237,4 +269,3 @@ class TableView2 : public View, public TableModelObserver {
} // namespace views
#endif // VIEWS_CONTROLS_TABLE_TABLE_VIEW2_H_
-