Commit 6622f151 authored by Kristyn Hamasaki's avatar Kristyn Hamasaki Committed by Commit Bot

Add metadata to TableView and convert fields to properties

Change-Id: I2d2e633ef1867a55a23d27a733454f519af5a4ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1721184Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Commit-Queue: Kristyn Hamasaki <khamasaki@google.com>
Cr-Commit-Position: refs/heads/master@{#682368}
parent ebf94067
......@@ -246,7 +246,7 @@ ui::TableModel* CertificateSelector::table_model_for_testing() const {
}
net::ClientCertIdentity* CertificateSelector::GetSelectedCert() const {
const int selected = table_->FirstSelectedRow();
const int selected = table_->GetFirstSelectedRow();
if (selected < 0) // Nothing is selected in |table_|.
return nullptr;
DCHECK_LT(static_cast<size_t>(selected), identities_.size());
......@@ -254,7 +254,7 @@ net::ClientCertIdentity* CertificateSelector::GetSelectedCert() const {
}
bool CertificateSelector::Accept() {
const int selected = table_->FirstSelectedRow();
const int selected = table_->GetFirstSelectedRow();
if (selected < 0) // Nothing is selected in |table_|.
return false;
......
......@@ -91,7 +91,7 @@ base::Optional<int> DesktopMediaPickerViewsTestApi::GetSelectedSourceId()
bool DesktopMediaPickerViewsTestApi::HasSourceAtIndex(size_t index) const {
const views::TableView* table = GetTableView();
if (table)
return base::checked_cast<size_t>(table->RowCount()) > index;
return base::checked_cast<size_t>(table->GetRowCount()) > index;
return bool{GetSourceAtIndex(index)};
}
......
......@@ -162,7 +162,7 @@ gfx::Size DesktopMediaTabList::CalculatePreferredSize() const {
// hundreds of tabs, but don't show too few if there's only one tab because
// the UI then looks squished.
rows = base::ClampToRange(rows, 4, 10);
return gfx::Size(0, rows * child_->row_height());
return gfx::Size(0, rows * child_->GetRowHeight());
}
int DesktopMediaTabList::GetHeightForWidth(int width) const {
......@@ -175,7 +175,7 @@ int DesktopMediaTabList::GetHeightForWidth(int width) const {
}
base::Optional<content::DesktopMediaID> DesktopMediaTabList::GetSelection() {
int row = child_->FirstSelectedRow();
int row = child_->GetFirstSelectedRow();
if (row == -1)
return base::nullopt;
return controller_->GetSource(row).id;
......
......@@ -133,7 +133,7 @@ DeviceChooserContentView::DeviceChooserContentView(
: views::TEXT_ONLY,
!chooser_controller_->AllowMultipleSelection() /* single_selection */);
table_view_ = table_view.get();
table_view->set_select_on_remove(false);
table_view->SetSelectOnRemove(false);
table_view->set_observer(table_view_observer);
table_parent_ = AddChildView(
......
......@@ -106,7 +106,7 @@ class DeviceChooserContentViewTest : public ChromeViewsTestBase {
void ExpectNoDevices() {
EXPECT_TRUE(no_options_label()->GetVisible());
EXPECT_EQ(0, table_view()->RowCount());
EXPECT_EQ(0, table_view()->GetRowCount());
// The table should be disabled since there are no (real) options.
EXPECT_FALSE(table_parent()->GetVisible());
EXPECT_FALSE(table_view()->GetEnabled());
......@@ -139,14 +139,14 @@ TEST_F(DeviceChooserContentViewTest, AddOption) {
EXPECT_CALL(table_observer(), OnSelectionChanged()).Times(0);
AddPairedDevice();
EXPECT_EQ(1, table_view()->RowCount());
EXPECT_EQ(1, table_view()->GetRowCount());
EXPECT_EQ(GetPairedDeviceTextAtRow(0), table_model()->GetText(0, 0));
// The table should be enabled now that there's an option.
EXPECT_TRUE(table_view()->GetEnabled());
EXPECT_FALSE(IsDeviceSelected());
AddUnpairedDevice();
EXPECT_EQ(2, table_view()->RowCount());
EXPECT_EQ(2, table_view()->GetRowCount());
EXPECT_EQ(GetUnpairedDeviceTextAtRow(1), table_model()->GetText(1, 0));
EXPECT_TRUE(table_view()->GetEnabled());
EXPECT_FALSE(IsDeviceSelected());
......@@ -161,7 +161,7 @@ TEST_F(DeviceChooserContentViewTest, RemoveOption) {
// Remove the paired device.
controller()->RemoveDevice(0);
EXPECT_EQ(2, table_view()->RowCount());
EXPECT_EQ(2, table_view()->GetRowCount());
EXPECT_EQ(GetUnpairedDeviceTextAtRow(0), table_model()->GetText(0, 0));
EXPECT_EQ(GetUnpairedDeviceTextAtRow(1), table_model()->GetText(1, 0));
EXPECT_TRUE(table_view()->GetEnabled());
......@@ -185,7 +185,7 @@ TEST_F(DeviceChooserContentViewTest, UpdateOption) {
1, {"Nice Device", FakeBluetoothChooserController::CONNECTED,
FakeBluetoothChooserController::PAIRED,
FakeBluetoothChooserController::kSignalStrengthUnknown});
EXPECT_EQ(3, table_view()->RowCount());
EXPECT_EQ(3, table_view()->GetRowCount());
EXPECT_EQ(GetPairedDeviceTextAtRow(1), table_model()->GetText(1, 0));
EXPECT_FALSE(IsDeviceSelected());
}
......@@ -197,11 +197,11 @@ TEST_F(DeviceChooserContentViewTest, SelectAndDeselectAnOption) {
table_view()->Select(0);
EXPECT_TRUE(IsDeviceSelected());
EXPECT_EQ(0, table_view()->FirstSelectedRow());
EXPECT_EQ(0, table_view()->GetFirstSelectedRow());
table_view()->Select(-1);
EXPECT_FALSE(IsDeviceSelected());
EXPECT_EQ(-1, table_view()->FirstSelectedRow());
EXPECT_EQ(-1, table_view()->GetFirstSelectedRow());
}
TEST_F(DeviceChooserContentViewTest, TurnBluetoothOffAndOn) {
......@@ -231,7 +231,7 @@ TEST_F(DeviceChooserContentViewTest, TurnBluetoothOffAndOn) {
TEST_F(DeviceChooserContentViewTest, ScanForDevices) {
controller()->SetBluetoothStatus(
FakeBluetoothChooserController::BluetoothStatus::SCANNING);
EXPECT_EQ(0, table_view()->RowCount());
EXPECT_EQ(0, table_view()->GetRowCount());
EXPECT_FALSE(table_view()->GetEnabled());
EXPECT_FALSE(adapter_off_help_link()->GetVisible());
EXPECT_TRUE(throbber()->GetVisible());
......@@ -239,7 +239,7 @@ TEST_F(DeviceChooserContentViewTest, ScanForDevices) {
EXPECT_FALSE(re_scan_button()->GetVisible());
AddUnpairedDevice();
EXPECT_EQ(1, table_view()->RowCount());
EXPECT_EQ(1, table_view()->GetRowCount());
EXPECT_TRUE(table_view()->GetEnabled());
EXPECT_FALSE(adapter_off_help_link()->GetVisible());
EXPECT_TRUE(throbber()->GetVisible());
......@@ -279,7 +279,7 @@ TEST_F(DeviceChooserContentViewTest, SetTableViewAlwaysDisabled) {
controller()->set_table_view_always_disabled(true);
EXPECT_FALSE(table_view()->GetEnabled());
AddUnpairedDevice();
EXPECT_EQ(1, table_view()->RowCount());
EXPECT_EQ(1, table_view()->GetRowCount());
// The table should still be disabled even though there's an option.
EXPECT_FALSE(table_view()->GetEnabled());
}
......@@ -155,7 +155,7 @@ class CollapsibleListView : public views::View, public views::ButtonListener {
model, std::move(table_columns), views::ICON_AND_TEXT,
/*single_selection=*/true);
table_view->SetEnabled(false);
int row_height = table_view->row_height();
int row_height = table_view->GetRowHeight();
int table_height = table_view->GetPreferredSize().height();
table_view_parent_ = AddChildView(
views::TableView::CreateScrollViewWithTable(std::move(table_view)));
......
......@@ -122,7 +122,7 @@ void TaskManagerView::SetColumnVisibility(int column_id, bool new_visibility) {
}
bool TaskManagerView::IsTableSorted() const {
return tab_table_->is_sorted();
return tab_table_->GetIsSorted();
}
TableSortDescriptor TaskManagerView::GetSortDescriptor() const {
......@@ -328,7 +328,7 @@ void TaskManagerView::Init() {
table_model_.reset(new TaskManagerTableModel(this));
tab_table->SetModel(table_model_.get());
tab_table->SetGrouper(this);
tab_table->set_sort_on_paint(true);
tab_table->SetSortOnPaint(true);
tab_table->set_observer(this);
tab_table->set_context_menu_controller(this);
set_context_menu_controller(this);
......
......@@ -139,7 +139,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, TableStartsWithDefaultColumns) {
views::TableView* table = GetTable();
ASSERT_TRUE(table);
EXPECT_FALSE(table->is_sorted());
EXPECT_FALSE(table->GetIsSorted());
for (size_t i = 0; i < kColumnsSize; ++i) {
EXPECT_EQ(kColumns[i].default_visibility,
table->IsColumnVisible(kColumns[i].id));
......@@ -158,7 +158,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, ColumnsSettingsAreRestored) {
ASSERT_TRUE(table);
// Toggle the visibility of all columns.
EXPECT_FALSE(table->is_sorted());
EXPECT_FALSE(table->GetIsSorted());
for (size_t i = 0; i < kColumnsSize; ++i) {
EXPECT_EQ(kColumns[i].default_visibility,
table->IsColumnVisible(kColumns[i].id));
......@@ -181,7 +181,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, ColumnsSettingsAreRestored) {
}
if (is_sorted) {
EXPECT_TRUE(table->is_sorted());
EXPECT_TRUE(table->GetIsSorted());
EXPECT_FALSE(table->sort_descriptors().front().ascending);
EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id);
}
......@@ -198,7 +198,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, ColumnsSettingsAreRestored) {
ASSERT_TRUE(table);
if (is_sorted) {
EXPECT_TRUE(table->is_sorted());
EXPECT_TRUE(table->GetIsSorted());
EXPECT_FALSE(table->sort_descriptors().front().ascending);
EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id);
}
......@@ -223,14 +223,14 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, InitialSelection) {
chrome::ShowTaskManager(browser());
EXPECT_EQ(1UL, GetTable()->selection_model().size());
EXPECT_EQ(GetTable()->FirstSelectedRow(),
EXPECT_EQ(GetTable()->GetFirstSelectedRow(),
FindRowForTab(browser()->tab_strip_model()->GetWebContentsAt(1)));
// Activate tab 0. The selection should not change.
browser()->tab_strip_model()->ActivateTabAt(
0, {TabStripModel::GestureType::kOther});
EXPECT_EQ(1UL, GetTable()->selection_model().size());
EXPECT_EQ(GetTable()->FirstSelectedRow(),
EXPECT_EQ(GetTable()->GetFirstSelectedRow(),
FindRowForTab(browser()->tab_strip_model()->GetWebContentsAt(1)));
// If the user re-triggers chrome::ShowTaskManager (e.g. via shift-esc), this
......@@ -238,7 +238,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, InitialSelection) {
chrome::ShowTaskManager(browser());
EXPECT_EQ(1UL, GetTable()->selection_model().size());
EXPECT_EQ(GetTable()->FirstSelectedRow(),
EXPECT_EQ(GetTable()->GetFirstSelectedRow(),
FindRowForTab(browser()->tab_strip_model()->GetWebContentsAt(0)));
}
......@@ -282,33 +282,33 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, SelectionConsistency) {
// Select the middle row, and store its tab id.
GetTable()->Select(FindRowForTab(tabs[1]));
EXPECT_EQ(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(1UL, GetTable()->selection_model().size());
// Add 3 rows above the selection. The selected tab should not change.
for (int i = 0; i < 3; ++i) {
ASSERT_TRUE(content::ExecuteScript(tabs[0], "window.open('title3.html');"));
EXPECT_EQ(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[1]));
}
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows((rows += 3), pattern));
EXPECT_EQ(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(1UL, GetTable()->selection_model().size());
// Add 2 rows below the selection. The selected tab should not change.
for (int i = 0; i < 2; ++i) {
ASSERT_TRUE(content::ExecuteScript(tabs[2], "window.open('title3.html');"));
EXPECT_EQ(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[1]));
}
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows((rows += 2), pattern));
EXPECT_EQ(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(1UL, GetTable()->selection_model().size());
// Add a new row in the same process as the selection. The selected tab should
// not change.
ASSERT_TRUE(content::ExecuteScript(tabs[1], "window.open('title3.html');"));
EXPECT_EQ(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[1]));
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows((rows += 1), pattern));
EXPECT_EQ(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[1]));
EXPECT_EQ(1UL, GetTable()->selection_model().size());
{
......@@ -324,8 +324,8 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, SelectionConsistency) {
// A later row should now be selected. The selection should be after the 4
// rows sharing the tabs[0] process, and it should be at or before
// the tabs[2] row.
ASSERT_LT(FindRowForTab(tabs[0]) + 3, GetTable()->FirstSelectedRow());
ASSERT_LE(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[2]));
ASSERT_LT(FindRowForTab(tabs[0]) + 3, GetTable()->GetFirstSelectedRow());
ASSERT_LE(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[2]));
// Now select tabs[2].
GetTable()->Select(FindRowForTab(tabs[2]));
......@@ -337,12 +337,12 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, SelectionConsistency) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows((rows += 1), pattern));
// tabs[2] should still be selected.
EXPECT_EQ(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[2]));
EXPECT_EQ(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[2]));
// Close tabs[0]. The selection should not change.
chrome::CloseWebContents(browser(), tabs[0], false);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows((rows -= 1), pattern));
EXPECT_EQ(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[2]));
EXPECT_EQ(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[2]));
}
// Make sure the task manager's bounds are saved across instances on Chrome OS.
......
This diff is collapsed.
......@@ -63,8 +63,7 @@ class VIEWS_EXPORT TableView
: public views::View,
public ui::TableModelObserver {
public:
// Internal class name.
static const char kViewClassName[];
METADATA_HEADER(TableView);
// Used by AdvanceActiveVisibleColumn(), AdvanceSelection() and
// ResizeColumnViaKeyboard() to determine the direction to change the
......@@ -130,13 +129,13 @@ class VIEWS_EXPORT TableView
void SetGrouper(TableGrouper* grouper);
// Returns the number of rows in the TableView.
int RowCount() const;
int GetRowCount() const;
// Selects the specified item, making sure it's visible.
void Select(int model_row);
// Returns the first selected row in terms of the model.
int FirstSelectedRow();
int GetFirstSelectedRow() const;
const ui::ListSelectionModel& selection_model() const {
return selection_model_;
......@@ -154,7 +153,7 @@ class VIEWS_EXPORT TableView
bool HasColumn(int id) const;
// Returns whether an active row and column have been set.
bool HasFocusIndicator() const;
bool GetHasFocusIndicator() const;
// Moves the focus ring to its new location if the active cell has changed, or
// hides the focus ring if the table is not focused.
......@@ -187,7 +186,7 @@ class VIEWS_EXPORT TableView
const SortDescriptors& sort_descriptors() const { return sort_descriptors_; }
void SetSortDescriptors(const SortDescriptors& descriptors);
bool is_sorted() const { return !sort_descriptors_.empty(); }
bool GetIsSorted() const { return !sort_descriptors_.empty(); }
// Maps from the index in terms of the model to that of the view.
int ModelToView(int model_index) const;
......@@ -195,11 +194,10 @@ class VIEWS_EXPORT TableView
// Maps from the index in terms of the view to that of the model.
int ViewToModel(int view_index) const;
int row_height() const { return row_height_; }
int GetRowHeight() const { return row_height_; }
void set_select_on_remove(bool select_on_remove) {
select_on_remove_ = select_on_remove;
}
bool GetSelectOnRemove() const;
void SetSelectOnRemove(bool select_on_remove);
// WARNING: this function forces a sort on every paint, and is therefore
// expensive! It assumes you are calling SchedulePaint() at intervals for
......@@ -208,11 +206,13 @@ class VIEWS_EXPORT TableView
// time the SchedulePaint() is called and the paint is processed, the
// underlying data may change. Also, this only works if the number of rows
// remains the same.
void set_sort_on_paint(bool sort_on_paint) { sort_on_paint_ = sort_on_paint; }
bool GetSortOnPaint() const;
void SetSortOnPaint(bool sort_on_paint);
TableTypes GetTableType() const;
// View overrides:
void Layout() override;
const char* GetClassName() const override;
gfx::Size CalculatePreferredSize() const override;
bool OnKeyPressed(const ui::KeyEvent& event) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
......
......@@ -191,7 +191,7 @@ int TestTableModel2::CompareValues(int row1, int row2, int column_id) {
// Returns the view to model mapping as a string.
std::string GetViewToModelAsString(TableView* table) {
std::string result;
for (int i = 0; i < table->RowCount(); ++i) {
for (int i = 0; i < table->GetRowCount(); ++i) {
if (i != 0)
result += " ";
result += base::NumberToString(table->ViewToModel(i));
......@@ -202,7 +202,7 @@ std::string GetViewToModelAsString(TableView* table) {
// Returns the model to view mapping as a string.
std::string GetModelToViewAsString(TableView* table) {
std::string result;
for (int i = 0; i < table->RowCount(); ++i) {
for (int i = 0; i < table->GetRowCount(); ++i) {
if (i != 0)
result += " ";
result += base::NumberToString(table->ModelToView(i));
......@@ -214,7 +214,7 @@ std::string GetModelToViewAsString(TableView* table) {
// scrolled out of view are included; hidden columns are excluded.
std::string GetRowsInViewOrderAsString(TableView* table) {
std::string result;
for (int i = 0; i < table->RowCount(); ++i) {
for (int i = 0; i < table->GetRowCount(); ++i) {
if (i != 0)
result += ", "; // Comma between each row.
......@@ -344,7 +344,7 @@ class TableViewTest : public ViewsTestBase {
private:
gfx::Point GetPointForRow(int row) {
const int y = (row + 0.5) * table_->row_height();
const int y = (row + 0.5) * table_->GetRowHeight();
return table_->GetBoundsInScreen().origin() + gfx::Vector2d(5, y);
}
......@@ -368,14 +368,15 @@ TEST_F(TableViewTest, UpdateVirtualAccessibilityChildren) {
EXPECT_EQ(ax::mojom::Role::kListGrid, data.role);
EXPECT_TRUE(data.HasState(ax::mojom::State::kFocusable));
EXPECT_EQ(ax::mojom::Restriction::kReadOnly, data.GetRestriction());
EXPECT_EQ(table_->RowCount(), static_cast<int>(data.GetIntAttribute(
ax::mojom::IntAttribute::kTableRowCount)));
EXPECT_EQ(table_->GetRowCount(),
static_cast<int>(
data.GetIntAttribute(ax::mojom::IntAttribute::kTableRowCount)));
EXPECT_EQ(helper_->visible_col_count(),
static_cast<size_t>(data.GetIntAttribute(
ax::mojom::IntAttribute::kTableColumnCount)));
// The header takes up another row.
ASSERT_EQ(size_t{table_->RowCount() + 1},
ASSERT_EQ(size_t{table_->GetRowCount() + 1},
view_accessibility.virtual_children().size());
const auto& header = view_accessibility.virtual_children().front();
ASSERT_TRUE(header);
......@@ -393,7 +394,7 @@ TEST_F(TableViewTest, UpdateVirtualAccessibilityChildren) {
int i = 0;
for (auto child_iter = view_accessibility.virtual_children().begin() + 1;
i < table_->RowCount(); ++child_iter, ++i) {
i < table_->GetRowCount(); ++child_iter, ++i) {
const auto& row = *child_iter;
ASSERT_TRUE(row);
const ui::AXNodeData& row_data = row->GetData();
......@@ -416,7 +417,7 @@ TEST_F(TableViewTest, UpdateVirtualAccessibilityChildren) {
}
TEST_F(TableViewTest, GetVirtualAccessibilityRow) {
for (int i = 0; i < table_->RowCount(); ++i) {
for (int i = 0; i < table_->GetRowCount(); ++i) {
const AXVirtualView* row = helper_->GetVirtualAccessibilityRow(i);
ASSERT_TRUE(row);
const ui::AXNodeData& row_data = row->GetData();
......@@ -427,7 +428,7 @@ TEST_F(TableViewTest, GetVirtualAccessibilityRow) {
}
TEST_F(TableViewTest, GetVirtualAccessibilityCell) {
for (int i = 0; i < table_->RowCount(); ++i) {
for (int i = 0; i < table_->GetRowCount(); ++i) {
for (int j = 0; j < static_cast<int>(helper_->visible_col_count()); ++j) {
const AXVirtualView* cell = helper_->GetVirtualAccessibilityCell(i, j);
ASSERT_TRUE(cell);
......@@ -991,7 +992,7 @@ TEST_F(TableViewTest, RemoveUnselectedRows) {
TEST_F(TableViewTest, SelectionNoSelectOnRemove) {
TableViewObserverImpl observer;
table_->set_observer(&observer);
table_->set_select_on_remove(false);
table_->SetSelectOnRemove(false);
// Initially no selection.
EXPECT_EQ("active=-1 anchor=-1 selection=", SelectionStateAsString());
......
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