Commit f7ef2dca authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Views: Add default constructability to TableView

Bug: None
Change-Id: I59c9d81e6c9a4af56a2770ac854e7809caadda19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359559
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800988}
parent 8f19da69
......@@ -157,36 +157,29 @@ class TableView::HighlightPathGenerator : public views::HighlightPathGenerator {
DISALLOW_COPY_AND_ASSIGN(HighlightPathGenerator);
};
TableView::TableView(ui::TableModel* model,
const std::vector<ui::TableColumn>& columns,
TableTypes table_type,
bool single_selection)
: columns_(columns),
table_type_(table_type),
single_selection_(single_selection) {
TableView::TableView() {
constexpr int kTextContext = style::CONTEXT_TABLE_ROW;
constexpr int kTextStyle = style::STYLE_PRIMARY;
font_list_ = style::GetFont(kTextContext, kTextStyle);
row_height_ = LayoutProvider::GetControlHeightForFont(kTextContext,
kTextStyle, font_list_);
for (const auto& column : columns) {
VisibleColumn visible_column;
visible_column.column = column;
visible_columns_.push_back(visible_column);
}
// Always focusable, even on Mac (consistent with NSTableView).
SetFocusBehavior(FocusBehavior::ALWAYS);
views::HighlightPathGenerator::Install(
this, std::make_unique<TableView::HighlightPathGenerator>());
SetModel(model);
if (model_)
UpdateVirtualAccessibilityChildren();
focus_ring_ = FocusRing::Install(this);
}
TableView::TableView(ui::TableModel* model,
const std::vector<ui::TableColumn>& columns,
TableTypes table_type,
bool single_selection)
: TableView() {
Init(model, std::move(columns), table_type, single_selection);
}
TableView::~TableView() {
if (model_)
model_->SetObserver(nullptr);
......@@ -202,6 +195,25 @@ std::unique_ptr<ScrollView> TableView::CreateScrollViewWithTable(
return scroll_view;
}
void TableView::Init(ui::TableModel* model,
const std::vector<ui::TableColumn>& columns,
TableTypes table_type,
bool single_selection) {
columns_ = columns;
table_type_ = table_type;
single_selection_ = single_selection;
for (const auto& column : columns) {
VisibleColumn visible_column;
visible_column.column = column;
visible_columns_.push_back(visible_column);
}
SetModel(model);
if (model_)
UpdateVirtualAccessibilityChildren();
}
// TODO(sky): this doesn't support arbitrarily changing the model, rename this
// to ClearModel() or something.
void TableView::SetModel(ui::TableModel* model) {
......@@ -303,11 +315,6 @@ bool TableView::IsColumnVisible(int id) const {
ids_match);
}
void TableView::AddColumn(const ui::TableColumn& col) {
DCHECK(!HasColumn(col.id));
columns_.push_back(col);
}
bool TableView::HasColumn(int id) const {
const auto ids_match = [id](const auto& column) { return column.id == id; };
return std::any_of(columns_.cbegin(), columns_.cend(), ids_match);
......
......@@ -104,6 +104,7 @@ class VIEWS_EXPORT TableView : public views::View,
// 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).
TableView();
TableView(ui::TableModel* model,
const std::vector<ui::TableColumn>& columns,
TableTypes table_type,
......@@ -114,6 +115,12 @@ class VIEWS_EXPORT TableView : public views::View,
static std::unique_ptr<ScrollView> CreateScrollViewWithTable(
std::unique_ptr<TableView> table);
// Initialize the table with the appropriate data.
void Init(ui::TableModel* model,
const std::vector<ui::TableColumn>& columns,
TableTypes table_type,
bool single_selection);
// Assigns a new model to the table view, detaching the old one if present.
// If |model| is NULL, the table view cannot be used after this call. This
// should be called in the containing view's destructor to avoid destruction
......@@ -142,9 +149,6 @@ class VIEWS_EXPORT TableView : public views::View,
void SetColumnVisibility(int id, bool is_visible);
bool IsColumnVisible(int id) const;
// Adds the specified column. |col| is not made visible.
void AddColumn(const ui::TableColumn& col);
// Returns true if the column with the specified id is known (either visible
// or not).
bool HasColumn(int id) const;
......@@ -401,9 +405,9 @@ class VIEWS_EXPORT TableView : public views::View,
// the first column has a non-empty title.
TableHeader* header_ = nullptr;
const TableTypes table_type_;
TableTypes table_type_ = TableTypes::TEXT_ONLY;
const bool single_selection_;
bool single_selection_ = true;
// If |select_on_remove_| is true: when a selected item is removed, if the
// removed item is not the last item, select its next one; otherwise select
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment