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 { ...@@ -246,7 +246,7 @@ ui::TableModel* CertificateSelector::table_model_for_testing() const {
} }
net::ClientCertIdentity* CertificateSelector::GetSelectedCert() const { net::ClientCertIdentity* CertificateSelector::GetSelectedCert() const {
const int selected = table_->FirstSelectedRow(); const int selected = table_->GetFirstSelectedRow();
if (selected < 0) // Nothing is selected in |table_|. if (selected < 0) // Nothing is selected in |table_|.
return nullptr; return nullptr;
DCHECK_LT(static_cast<size_t>(selected), identities_.size()); DCHECK_LT(static_cast<size_t>(selected), identities_.size());
...@@ -254,7 +254,7 @@ net::ClientCertIdentity* CertificateSelector::GetSelectedCert() const { ...@@ -254,7 +254,7 @@ net::ClientCertIdentity* CertificateSelector::GetSelectedCert() const {
} }
bool CertificateSelector::Accept() { bool CertificateSelector::Accept() {
const int selected = table_->FirstSelectedRow(); const int selected = table_->GetFirstSelectedRow();
if (selected < 0) // Nothing is selected in |table_|. if (selected < 0) // Nothing is selected in |table_|.
return false; return false;
......
...@@ -91,7 +91,7 @@ base::Optional<int> DesktopMediaPickerViewsTestApi::GetSelectedSourceId() ...@@ -91,7 +91,7 @@ base::Optional<int> DesktopMediaPickerViewsTestApi::GetSelectedSourceId()
bool DesktopMediaPickerViewsTestApi::HasSourceAtIndex(size_t index) const { bool DesktopMediaPickerViewsTestApi::HasSourceAtIndex(size_t index) const {
const views::TableView* table = GetTableView(); const views::TableView* table = GetTableView();
if (table) if (table)
return base::checked_cast<size_t>(table->RowCount()) > index; return base::checked_cast<size_t>(table->GetRowCount()) > index;
return bool{GetSourceAtIndex(index)}; return bool{GetSourceAtIndex(index)};
} }
......
...@@ -162,7 +162,7 @@ gfx::Size DesktopMediaTabList::CalculatePreferredSize() const { ...@@ -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 // hundreds of tabs, but don't show too few if there's only one tab because
// the UI then looks squished. // the UI then looks squished.
rows = base::ClampToRange(rows, 4, 10); 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 { int DesktopMediaTabList::GetHeightForWidth(int width) const {
...@@ -175,7 +175,7 @@ int DesktopMediaTabList::GetHeightForWidth(int width) const { ...@@ -175,7 +175,7 @@ int DesktopMediaTabList::GetHeightForWidth(int width) const {
} }
base::Optional<content::DesktopMediaID> DesktopMediaTabList::GetSelection() { base::Optional<content::DesktopMediaID> DesktopMediaTabList::GetSelection() {
int row = child_->FirstSelectedRow(); int row = child_->GetFirstSelectedRow();
if (row == -1) if (row == -1)
return base::nullopt; return base::nullopt;
return controller_->GetSource(row).id; return controller_->GetSource(row).id;
......
...@@ -133,7 +133,7 @@ DeviceChooserContentView::DeviceChooserContentView( ...@@ -133,7 +133,7 @@ DeviceChooserContentView::DeviceChooserContentView(
: views::TEXT_ONLY, : views::TEXT_ONLY,
!chooser_controller_->AllowMultipleSelection() /* single_selection */); !chooser_controller_->AllowMultipleSelection() /* single_selection */);
table_view_ = table_view.get(); table_view_ = table_view.get();
table_view->set_select_on_remove(false); table_view->SetSelectOnRemove(false);
table_view->set_observer(table_view_observer); table_view->set_observer(table_view_observer);
table_parent_ = AddChildView( table_parent_ = AddChildView(
......
...@@ -106,7 +106,7 @@ class DeviceChooserContentViewTest : public ChromeViewsTestBase { ...@@ -106,7 +106,7 @@ class DeviceChooserContentViewTest : public ChromeViewsTestBase {
void ExpectNoDevices() { void ExpectNoDevices() {
EXPECT_TRUE(no_options_label()->GetVisible()); 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. // The table should be disabled since there are no (real) options.
EXPECT_FALSE(table_parent()->GetVisible()); EXPECT_FALSE(table_parent()->GetVisible());
EXPECT_FALSE(table_view()->GetEnabled()); EXPECT_FALSE(table_view()->GetEnabled());
...@@ -139,14 +139,14 @@ TEST_F(DeviceChooserContentViewTest, AddOption) { ...@@ -139,14 +139,14 @@ TEST_F(DeviceChooserContentViewTest, AddOption) {
EXPECT_CALL(table_observer(), OnSelectionChanged()).Times(0); EXPECT_CALL(table_observer(), OnSelectionChanged()).Times(0);
AddPairedDevice(); AddPairedDevice();
EXPECT_EQ(1, table_view()->RowCount()); EXPECT_EQ(1, table_view()->GetRowCount());
EXPECT_EQ(GetPairedDeviceTextAtRow(0), table_model()->GetText(0, 0)); EXPECT_EQ(GetPairedDeviceTextAtRow(0), table_model()->GetText(0, 0));
// The table should be enabled now that there's an option. // The table should be enabled now that there's an option.
EXPECT_TRUE(table_view()->GetEnabled()); EXPECT_TRUE(table_view()->GetEnabled());
EXPECT_FALSE(IsDeviceSelected()); EXPECT_FALSE(IsDeviceSelected());
AddUnpairedDevice(); AddUnpairedDevice();
EXPECT_EQ(2, table_view()->RowCount()); EXPECT_EQ(2, table_view()->GetRowCount());
EXPECT_EQ(GetUnpairedDeviceTextAtRow(1), table_model()->GetText(1, 0)); EXPECT_EQ(GetUnpairedDeviceTextAtRow(1), table_model()->GetText(1, 0));
EXPECT_TRUE(table_view()->GetEnabled()); EXPECT_TRUE(table_view()->GetEnabled());
EXPECT_FALSE(IsDeviceSelected()); EXPECT_FALSE(IsDeviceSelected());
...@@ -161,7 +161,7 @@ TEST_F(DeviceChooserContentViewTest, RemoveOption) { ...@@ -161,7 +161,7 @@ TEST_F(DeviceChooserContentViewTest, RemoveOption) {
// Remove the paired device. // Remove the paired device.
controller()->RemoveDevice(0); 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(0), table_model()->GetText(0, 0));
EXPECT_EQ(GetUnpairedDeviceTextAtRow(1), table_model()->GetText(1, 0)); EXPECT_EQ(GetUnpairedDeviceTextAtRow(1), table_model()->GetText(1, 0));
EXPECT_TRUE(table_view()->GetEnabled()); EXPECT_TRUE(table_view()->GetEnabled());
...@@ -185,7 +185,7 @@ TEST_F(DeviceChooserContentViewTest, UpdateOption) { ...@@ -185,7 +185,7 @@ TEST_F(DeviceChooserContentViewTest, UpdateOption) {
1, {"Nice Device", FakeBluetoothChooserController::CONNECTED, 1, {"Nice Device", FakeBluetoothChooserController::CONNECTED,
FakeBluetoothChooserController::PAIRED, FakeBluetoothChooserController::PAIRED,
FakeBluetoothChooserController::kSignalStrengthUnknown}); FakeBluetoothChooserController::kSignalStrengthUnknown});
EXPECT_EQ(3, table_view()->RowCount()); EXPECT_EQ(3, table_view()->GetRowCount());
EXPECT_EQ(GetPairedDeviceTextAtRow(1), table_model()->GetText(1, 0)); EXPECT_EQ(GetPairedDeviceTextAtRow(1), table_model()->GetText(1, 0));
EXPECT_FALSE(IsDeviceSelected()); EXPECT_FALSE(IsDeviceSelected());
} }
...@@ -197,11 +197,11 @@ TEST_F(DeviceChooserContentViewTest, SelectAndDeselectAnOption) { ...@@ -197,11 +197,11 @@ TEST_F(DeviceChooserContentViewTest, SelectAndDeselectAnOption) {
table_view()->Select(0); table_view()->Select(0);
EXPECT_TRUE(IsDeviceSelected()); EXPECT_TRUE(IsDeviceSelected());
EXPECT_EQ(0, table_view()->FirstSelectedRow()); EXPECT_EQ(0, table_view()->GetFirstSelectedRow());
table_view()->Select(-1); table_view()->Select(-1);
EXPECT_FALSE(IsDeviceSelected()); EXPECT_FALSE(IsDeviceSelected());
EXPECT_EQ(-1, table_view()->FirstSelectedRow()); EXPECT_EQ(-1, table_view()->GetFirstSelectedRow());
} }
TEST_F(DeviceChooserContentViewTest, TurnBluetoothOffAndOn) { TEST_F(DeviceChooserContentViewTest, TurnBluetoothOffAndOn) {
...@@ -231,7 +231,7 @@ TEST_F(DeviceChooserContentViewTest, TurnBluetoothOffAndOn) { ...@@ -231,7 +231,7 @@ TEST_F(DeviceChooserContentViewTest, TurnBluetoothOffAndOn) {
TEST_F(DeviceChooserContentViewTest, ScanForDevices) { TEST_F(DeviceChooserContentViewTest, ScanForDevices) {
controller()->SetBluetoothStatus( controller()->SetBluetoothStatus(
FakeBluetoothChooserController::BluetoothStatus::SCANNING); FakeBluetoothChooserController::BluetoothStatus::SCANNING);
EXPECT_EQ(0, table_view()->RowCount()); EXPECT_EQ(0, table_view()->GetRowCount());
EXPECT_FALSE(table_view()->GetEnabled()); EXPECT_FALSE(table_view()->GetEnabled());
EXPECT_FALSE(adapter_off_help_link()->GetVisible()); EXPECT_FALSE(adapter_off_help_link()->GetVisible());
EXPECT_TRUE(throbber()->GetVisible()); EXPECT_TRUE(throbber()->GetVisible());
...@@ -239,7 +239,7 @@ TEST_F(DeviceChooserContentViewTest, ScanForDevices) { ...@@ -239,7 +239,7 @@ TEST_F(DeviceChooserContentViewTest, ScanForDevices) {
EXPECT_FALSE(re_scan_button()->GetVisible()); EXPECT_FALSE(re_scan_button()->GetVisible());
AddUnpairedDevice(); AddUnpairedDevice();
EXPECT_EQ(1, table_view()->RowCount()); EXPECT_EQ(1, table_view()->GetRowCount());
EXPECT_TRUE(table_view()->GetEnabled()); EXPECT_TRUE(table_view()->GetEnabled());
EXPECT_FALSE(adapter_off_help_link()->GetVisible()); EXPECT_FALSE(adapter_off_help_link()->GetVisible());
EXPECT_TRUE(throbber()->GetVisible()); EXPECT_TRUE(throbber()->GetVisible());
...@@ -279,7 +279,7 @@ TEST_F(DeviceChooserContentViewTest, SetTableViewAlwaysDisabled) { ...@@ -279,7 +279,7 @@ TEST_F(DeviceChooserContentViewTest, SetTableViewAlwaysDisabled) {
controller()->set_table_view_always_disabled(true); controller()->set_table_view_always_disabled(true);
EXPECT_FALSE(table_view()->GetEnabled()); EXPECT_FALSE(table_view()->GetEnabled());
AddUnpairedDevice(); 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. // The table should still be disabled even though there's an option.
EXPECT_FALSE(table_view()->GetEnabled()); EXPECT_FALSE(table_view()->GetEnabled());
} }
...@@ -155,7 +155,7 @@ class CollapsibleListView : public views::View, public views::ButtonListener { ...@@ -155,7 +155,7 @@ class CollapsibleListView : public views::View, public views::ButtonListener {
model, std::move(table_columns), views::ICON_AND_TEXT, model, std::move(table_columns), views::ICON_AND_TEXT,
/*single_selection=*/true); /*single_selection=*/true);
table_view->SetEnabled(false); table_view->SetEnabled(false);
int row_height = table_view->row_height(); int row_height = table_view->GetRowHeight();
int table_height = table_view->GetPreferredSize().height(); int table_height = table_view->GetPreferredSize().height();
table_view_parent_ = AddChildView( table_view_parent_ = AddChildView(
views::TableView::CreateScrollViewWithTable(std::move(table_view))); views::TableView::CreateScrollViewWithTable(std::move(table_view)));
......
...@@ -122,7 +122,7 @@ void TaskManagerView::SetColumnVisibility(int column_id, bool new_visibility) { ...@@ -122,7 +122,7 @@ void TaskManagerView::SetColumnVisibility(int column_id, bool new_visibility) {
} }
bool TaskManagerView::IsTableSorted() const { bool TaskManagerView::IsTableSorted() const {
return tab_table_->is_sorted(); return tab_table_->GetIsSorted();
} }
TableSortDescriptor TaskManagerView::GetSortDescriptor() const { TableSortDescriptor TaskManagerView::GetSortDescriptor() const {
...@@ -328,7 +328,7 @@ void TaskManagerView::Init() { ...@@ -328,7 +328,7 @@ void TaskManagerView::Init() {
table_model_.reset(new TaskManagerTableModel(this)); table_model_.reset(new TaskManagerTableModel(this));
tab_table->SetModel(table_model_.get()); tab_table->SetModel(table_model_.get());
tab_table->SetGrouper(this); tab_table->SetGrouper(this);
tab_table->set_sort_on_paint(true); tab_table->SetSortOnPaint(true);
tab_table->set_observer(this); tab_table->set_observer(this);
tab_table->set_context_menu_controller(this); tab_table->set_context_menu_controller(this);
set_context_menu_controller(this); set_context_menu_controller(this);
......
...@@ -139,7 +139,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, TableStartsWithDefaultColumns) { ...@@ -139,7 +139,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, TableStartsWithDefaultColumns) {
views::TableView* table = GetTable(); views::TableView* table = GetTable();
ASSERT_TRUE(table); ASSERT_TRUE(table);
EXPECT_FALSE(table->is_sorted()); EXPECT_FALSE(table->GetIsSorted());
for (size_t i = 0; i < kColumnsSize; ++i) { for (size_t i = 0; i < kColumnsSize; ++i) {
EXPECT_EQ(kColumns[i].default_visibility, EXPECT_EQ(kColumns[i].default_visibility,
table->IsColumnVisible(kColumns[i].id)); table->IsColumnVisible(kColumns[i].id));
...@@ -158,7 +158,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, ColumnsSettingsAreRestored) { ...@@ -158,7 +158,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, ColumnsSettingsAreRestored) {
ASSERT_TRUE(table); ASSERT_TRUE(table);
// Toggle the visibility of all columns. // Toggle the visibility of all columns.
EXPECT_FALSE(table->is_sorted()); EXPECT_FALSE(table->GetIsSorted());
for (size_t i = 0; i < kColumnsSize; ++i) { for (size_t i = 0; i < kColumnsSize; ++i) {
EXPECT_EQ(kColumns[i].default_visibility, EXPECT_EQ(kColumns[i].default_visibility,
table->IsColumnVisible(kColumns[i].id)); table->IsColumnVisible(kColumns[i].id));
...@@ -181,7 +181,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, ColumnsSettingsAreRestored) { ...@@ -181,7 +181,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, ColumnsSettingsAreRestored) {
} }
if (is_sorted) { if (is_sorted) {
EXPECT_TRUE(table->is_sorted()); EXPECT_TRUE(table->GetIsSorted());
EXPECT_FALSE(table->sort_descriptors().front().ascending); EXPECT_FALSE(table->sort_descriptors().front().ascending);
EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id); EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id);
} }
...@@ -198,7 +198,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, ColumnsSettingsAreRestored) { ...@@ -198,7 +198,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, ColumnsSettingsAreRestored) {
ASSERT_TRUE(table); ASSERT_TRUE(table);
if (is_sorted) { if (is_sorted) {
EXPECT_TRUE(table->is_sorted()); EXPECT_TRUE(table->GetIsSorted());
EXPECT_FALSE(table->sort_descriptors().front().ascending); EXPECT_FALSE(table->sort_descriptors().front().ascending);
EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id); EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id);
} }
...@@ -223,14 +223,14 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, InitialSelection) { ...@@ -223,14 +223,14 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, InitialSelection) {
chrome::ShowTaskManager(browser()); chrome::ShowTaskManager(browser());
EXPECT_EQ(1UL, GetTable()->selection_model().size()); EXPECT_EQ(1UL, GetTable()->selection_model().size());
EXPECT_EQ(GetTable()->FirstSelectedRow(), EXPECT_EQ(GetTable()->GetFirstSelectedRow(),
FindRowForTab(browser()->tab_strip_model()->GetWebContentsAt(1))); FindRowForTab(browser()->tab_strip_model()->GetWebContentsAt(1)));
// Activate tab 0. The selection should not change. // Activate tab 0. The selection should not change.
browser()->tab_strip_model()->ActivateTabAt( browser()->tab_strip_model()->ActivateTabAt(
0, {TabStripModel::GestureType::kOther}); 0, {TabStripModel::GestureType::kOther});
EXPECT_EQ(1UL, GetTable()->selection_model().size()); EXPECT_EQ(1UL, GetTable()->selection_model().size());
EXPECT_EQ(GetTable()->FirstSelectedRow(), EXPECT_EQ(GetTable()->GetFirstSelectedRow(),
FindRowForTab(browser()->tab_strip_model()->GetWebContentsAt(1))); FindRowForTab(browser()->tab_strip_model()->GetWebContentsAt(1)));
// If the user re-triggers chrome::ShowTaskManager (e.g. via shift-esc), this // If the user re-triggers chrome::ShowTaskManager (e.g. via shift-esc), this
...@@ -238,7 +238,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, InitialSelection) { ...@@ -238,7 +238,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, InitialSelection) {
chrome::ShowTaskManager(browser()); chrome::ShowTaskManager(browser());
EXPECT_EQ(1UL, GetTable()->selection_model().size()); EXPECT_EQ(1UL, GetTable()->selection_model().size());
EXPECT_EQ(GetTable()->FirstSelectedRow(), EXPECT_EQ(GetTable()->GetFirstSelectedRow(),
FindRowForTab(browser()->tab_strip_model()->GetWebContentsAt(0))); FindRowForTab(browser()->tab_strip_model()->GetWebContentsAt(0)));
} }
...@@ -282,33 +282,33 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, SelectionConsistency) { ...@@ -282,33 +282,33 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, SelectionConsistency) {
// Select the middle row, and store its tab id. // Select the middle row, and store its tab id.
GetTable()->Select(FindRowForTab(tabs[1])); 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()); EXPECT_EQ(1UL, GetTable()->selection_model().size());
// Add 3 rows above the selection. The selected tab should not change. // Add 3 rows above the selection. The selected tab should not change.
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
ASSERT_TRUE(content::ExecuteScript(tabs[0], "window.open('title3.html');")); 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)); 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()); EXPECT_EQ(1UL, GetTable()->selection_model().size());
// Add 2 rows below the selection. The selected tab should not change. // Add 2 rows below the selection. The selected tab should not change.
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
ASSERT_TRUE(content::ExecuteScript(tabs[2], "window.open('title3.html');")); 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)); 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()); EXPECT_EQ(1UL, GetTable()->selection_model().size());
// Add a new row in the same process as the selection. The selected tab should // Add a new row in the same process as the selection. The selected tab should
// not change. // not change.
ASSERT_TRUE(content::ExecuteScript(tabs[1], "window.open('title3.html');")); 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)); 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()); EXPECT_EQ(1UL, GetTable()->selection_model().size());
{ {
...@@ -324,8 +324,8 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, SelectionConsistency) { ...@@ -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 // 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 // rows sharing the tabs[0] process, and it should be at or before
// the tabs[2] row. // the tabs[2] row.
ASSERT_LT(FindRowForTab(tabs[0]) + 3, GetTable()->FirstSelectedRow()); ASSERT_LT(FindRowForTab(tabs[0]) + 3, GetTable()->GetFirstSelectedRow());
ASSERT_LE(GetTable()->FirstSelectedRow(), FindRowForTab(tabs[2])); ASSERT_LE(GetTable()->GetFirstSelectedRow(), FindRowForTab(tabs[2]));
// Now select tabs[2]. // Now select tabs[2].
GetTable()->Select(FindRowForTab(tabs[2])); GetTable()->Select(FindRowForTab(tabs[2]));
...@@ -337,12 +337,12 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, SelectionConsistency) { ...@@ -337,12 +337,12 @@ IN_PROC_BROWSER_TEST_F(TaskManagerViewTest, SelectionConsistency) {
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows((rows += 1), pattern)); ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows((rows += 1), pattern));
// tabs[2] should still be selected. // 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. // Close tabs[0]. The selection should not change.
chrome::CloseWebContents(browser(), tabs[0], false); chrome::CloseWebContents(browser(), tabs[0], false);
ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows((rows -= 1), pattern)); 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. // Make sure the task manager's bounds are saved across instances on Chrome OS.
......
...@@ -133,9 +133,6 @@ TableView::PaintRegion::PaintRegion() = default; ...@@ -133,9 +133,6 @@ TableView::PaintRegion::PaintRegion() = default;
TableView::PaintRegion::~PaintRegion() = default; TableView::PaintRegion::~PaintRegion() = default;
// static
const char TableView::kViewClassName[] = "TableView";
TableView::TableView(ui::TableModel* model, TableView::TableView(ui::TableModel* model,
const std::vector<ui::TableColumn>& columns, const std::vector<ui::TableColumn>& columns,
TableTypes table_type, TableTypes table_type,
...@@ -196,7 +193,7 @@ void TableView::SetGrouper(TableGrouper* grouper) { ...@@ -196,7 +193,7 @@ void TableView::SetGrouper(TableGrouper* grouper) {
SortItemsAndUpdateMapping(/*schedule_paint=*/true); SortItemsAndUpdateMapping(/*schedule_paint=*/true);
} }
int TableView::RowCount() const { int TableView::GetRowCount() const {
return model_ ? model_->RowCount() : 0; return model_ ? model_->RowCount() : 0;
} }
...@@ -207,7 +204,7 @@ void TableView::Select(int model_row) { ...@@ -207,7 +204,7 @@ void TableView::Select(int model_row) {
SelectByViewIndex(model_row == -1 ? -1 : ModelToView(model_row)); SelectByViewIndex(model_row == -1 ? -1 : ModelToView(model_row));
} }
int TableView::FirstSelectedRow() { int TableView::GetFirstSelectedRow() const {
return selection_model_.empty() ? -1 : selection_model_.selected_indices()[0]; return selection_model_.empty() ? -1 : selection_model_.selected_indices()[0];
} }
...@@ -287,7 +284,7 @@ bool TableView::HasColumn(int id) const { ...@@ -287,7 +284,7 @@ bool TableView::HasColumn(int id) const {
return std::any_of(columns_.cbegin(), columns_.cend(), ids_match); return std::any_of(columns_.cbegin(), columns_.cend(), ids_match);
} }
bool TableView::HasFocusIndicator() const { bool TableView::GetHasFocusIndicator() const {
int active_row = selection_model_.active(); int active_row = selection_model_.active();
return active_row != ui::ListSelectionModel::kUnselectedIndex && return active_row != ui::ListSelectionModel::kUnselectedIndex &&
active_visible_column_index_ != active_visible_column_index_ !=
...@@ -298,7 +295,7 @@ void TableView::ResetFocusIndicator() { ...@@ -298,7 +295,7 @@ void TableView::ResetFocusIndicator() {
if (!PlatformStyle::kTableViewSupportsKeyboardNavigationByCell) if (!PlatformStyle::kTableViewSupportsKeyboardNavigationByCell)
return; return;
if (HasFocusIndicator()) { if (GetHasFocusIndicator()) {
// Draw a focus indicator around the active column. // Draw a focus indicator around the active column.
focus_ring_ = FocusRing::Install(this); focus_ring_ = FocusRing::Install(this);
const gfx::Rect cell_bounds(GetCellBounds( const gfx::Rect cell_bounds(GetCellBounds(
...@@ -333,19 +330,47 @@ void TableView::SetVisibleColumnWidth(int index, int width) { ...@@ -333,19 +330,47 @@ void TableView::SetVisibleColumnWidth(int index, int width) {
} }
int TableView::ModelToView(int model_index) const { int TableView::ModelToView(int model_index) const {
if (!is_sorted()) if (!GetIsSorted())
return model_index; return model_index;
DCHECK_GE(model_index, 0) << " negative model_index " << model_index; DCHECK_GE(model_index, 0) << " negative model_index " << model_index;
DCHECK_LT(model_index, RowCount()) << " out of bounds model_index " << DCHECK_LT(model_index, GetRowCount())
model_index; << " out of bounds model_index " << model_index;
return model_to_view_[model_index]; return model_to_view_[model_index];
} }
int TableView::ViewToModel(int view_index) const { int TableView::ViewToModel(int view_index) const {
DCHECK_GE(view_index, 0) << " negative view_index " << view_index; DCHECK_GE(view_index, 0) << " negative view_index " << view_index;
DCHECK_LT(view_index, RowCount()) << " out of bounds view_index " << DCHECK_LT(view_index, GetRowCount())
view_index; << " out of bounds view_index " << view_index;
return is_sorted() ? view_to_model_[view_index] : view_index; return GetIsSorted() ? view_to_model_[view_index] : view_index;
}
bool TableView::GetSelectOnRemove() const {
return select_on_remove_;
}
void TableView::SetSelectOnRemove(bool select_on_remove) {
if (select_on_remove_ == select_on_remove)
return;
select_on_remove_ = select_on_remove;
OnPropertyChanged(&select_on_remove_, kPropertyEffectsNone);
}
TableTypes TableView::GetTableType() const {
return table_type_;
}
bool TableView::GetSortOnPaint() const {
return sort_on_paint_;
}
void TableView::SetSortOnPaint(bool sort_on_paint) {
if (sort_on_paint_ == sort_on_paint)
return;
sort_on_paint_ = sort_on_paint;
OnPropertyChanged(&sort_on_paint_, kPropertyEffectsNone);
} }
void TableView::Layout() { void TableView::Layout() {
...@@ -378,15 +403,11 @@ void TableView::Layout() { ...@@ -378,15 +403,11 @@ void TableView::Layout() {
focus_ring_->Layout(); focus_ring_->Layout();
} }
const char* TableView::GetClassName() const {
return kViewClassName;
}
gfx::Size TableView::CalculatePreferredSize() const { gfx::Size TableView::CalculatePreferredSize() const {
int width = 50; int width = 50;
if (header_ && !visible_columns_.empty()) if (header_ && !visible_columns_.empty())
width = visible_columns_.back().x + visible_columns_.back().width; width = visible_columns_.back().x + visible_columns_.back().width;
return gfx::Size(width, RowCount() * row_height_); return gfx::Size(width, GetRowCount() * row_height_);
} }
bool TableView::OnKeyPressed(const ui::KeyEvent& event) { bool TableView::OnKeyPressed(const ui::KeyEvent& event) {
...@@ -396,10 +417,10 @@ bool TableView::OnKeyPressed(const ui::KeyEvent& event) { ...@@ -396,10 +417,10 @@ bool TableView::OnKeyPressed(const ui::KeyEvent& event) {
switch (event.key_code()) { switch (event.key_code()) {
case ui::VKEY_A: case ui::VKEY_A:
// control-a selects all. // control-a selects all.
if (IsCmdOrCtrl(event) && !single_selection_ && RowCount()) { if (IsCmdOrCtrl(event) && !single_selection_ && GetRowCount()) {
ui::ListSelectionModel selection_model; ui::ListSelectionModel selection_model;
selection_model.SetSelectedIndex(selection_model_.active()); selection_model.SetSelectedIndex(selection_model_.active());
for (int i = 0; i < RowCount(); ++i) for (int i = 0; i < GetRowCount(); ++i)
selection_model.AddIndexToSelection(i); selection_model.AddIndexToSelection(i);
SetSelectionModel(std::move(selection_model)); SetSelectionModel(std::move(selection_model));
return true; return true;
...@@ -407,19 +428,19 @@ bool TableView::OnKeyPressed(const ui::KeyEvent& event) { ...@@ -407,19 +428,19 @@ bool TableView::OnKeyPressed(const ui::KeyEvent& event) {
break; break;
case ui::VKEY_HOME: case ui::VKEY_HOME:
if (RowCount()) if (GetRowCount())
SelectByViewIndex(0); SelectByViewIndex(0);
return true; return true;
case ui::VKEY_END: case ui::VKEY_END:
if (RowCount()) if (GetRowCount())
SelectByViewIndex(RowCount() - 1); SelectByViewIndex(GetRowCount() - 1);
return true; return true;
case ui::VKEY_UP: case ui::VKEY_UP:
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
if (event.IsAltDown()) { if (event.IsAltDown()) {
if (RowCount()) if (GetRowCount())
SelectByViewIndex(0); SelectByViewIndex(0);
} else { } else {
AdvanceSelection(ADVANCE_DECREMENT); AdvanceSelection(ADVANCE_DECREMENT);
...@@ -432,8 +453,8 @@ bool TableView::OnKeyPressed(const ui::KeyEvent& event) { ...@@ -432,8 +453,8 @@ bool TableView::OnKeyPressed(const ui::KeyEvent& event) {
case ui::VKEY_DOWN: case ui::VKEY_DOWN:
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
if (event.IsAltDown()) { if (event.IsAltDown()) {
if (RowCount()) if (GetRowCount())
SelectByViewIndex(RowCount() - 1); SelectByViewIndex(GetRowCount() - 1);
} else { } else {
AdvanceSelection(ADVANCE_INCREMENT); AdvanceSelection(ADVANCE_INCREMENT);
} }
...@@ -499,7 +520,7 @@ bool TableView::OnMousePressed(const ui::MouseEvent& event) { ...@@ -499,7 +520,7 @@ bool TableView::OnMousePressed(const ui::MouseEvent& event) {
return true; return true;
const int row = event.y() / row_height_; const int row = event.y() / row_height_;
if (row < 0 || row >= RowCount()) if (row < 0 || row >= GetRowCount())
return true; return true;
if (event.GetClickCount() == 2) { if (event.GetClickCount() == 2) {
...@@ -522,7 +543,7 @@ void TableView::OnGestureEvent(ui::GestureEvent* event) { ...@@ -522,7 +543,7 @@ void TableView::OnGestureEvent(ui::GestureEvent* event) {
RequestFocus(); RequestFocus();
const int row = event->y() / row_height_; const int row = event->y() / row_height_;
if (row < 0 || row >= RowCount()) if (row < 0 || row >= GetRowCount())
return; return;
event->StopPropagation(); event->StopPropagation();
...@@ -533,7 +554,7 @@ void TableView::OnGestureEvent(ui::GestureEvent* event) { ...@@ -533,7 +554,7 @@ void TableView::OnGestureEvent(ui::GestureEvent* event) {
base::string16 TableView::GetTooltipText(const gfx::Point& p) const { base::string16 TableView::GetTooltipText(const gfx::Point& p) const {
const int row = p.y() / row_height_; const int row = p.y() / row_height_;
if (row < 0 || row >= RowCount() || visible_columns_.empty()) if (row < 0 || row >= GetRowCount() || visible_columns_.empty())
return base::string16(); return base::string16();
const int x = GetMirroredXInView(p.x()); const int x = GetMirroredXInView(p.x());
...@@ -555,14 +576,14 @@ void TableView::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -555,14 +576,14 @@ void TableView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetNameExplicitlyEmpty(); node_data->SetNameExplicitlyEmpty();
node_data->AddIntAttribute(ax::mojom::IntAttribute::kTableRowCount, node_data->AddIntAttribute(ax::mojom::IntAttribute::kTableRowCount,
static_cast<int32_t>(RowCount())); static_cast<int32_t>(GetRowCount()));
node_data->AddIntAttribute(ax::mojom::IntAttribute::kTableColumnCount, node_data->AddIntAttribute(ax::mojom::IntAttribute::kTableColumnCount,
static_cast<int32_t>(visible_columns_.size())); static_cast<int32_t>(visible_columns_.size()));
node_data->relative_bounds.bounds = gfx::RectF(GetVisibleBounds()); node_data->relative_bounds.bounds = gfx::RectF(GetVisibleBounds());
} }
bool TableView::HandleAccessibleAction(const ui::AXActionData& action_data) { bool TableView::HandleAccessibleAction(const ui::AXActionData& action_data) {
if (!RowCount()) if (!GetRowCount())
return false; return false;
int active_row = selection_model_.active(); int active_row = selection_model_.active();
...@@ -645,9 +666,9 @@ void TableView::OnItemsRemoved(int start, int length) { ...@@ -645,9 +666,9 @@ void TableView::OnItemsRemoved(int start, int length) {
// Determine the currently selected index in terms of the view. We inline the // Determine the currently selected index in terms of the view. We inline the
// implementation here since ViewToModel() has DCHECKs that fail since the // implementation here since ViewToModel() has DCHECKs that fail since the
// model has changed but |model_to_view_| has not been updated yet. // model has changed but |model_to_view_| has not been updated yet.
const int previously_selected_model_index = FirstSelectedRow(); const int previously_selected_model_index = GetFirstSelectedRow();
int previously_selected_view_index = previously_selected_model_index; int previously_selected_view_index = previously_selected_model_index;
if (previously_selected_model_index != -1 && is_sorted()) if (previously_selected_model_index != -1 && GetIsSorted())
previously_selected_view_index = previously_selected_view_index =
model_to_view_[previously_selected_model_index]; model_to_view_[previously_selected_model_index];
for (int i = 0; i < length; ++i) for (int i = 0; i < length; ++i)
...@@ -656,21 +677,21 @@ void TableView::OnItemsRemoved(int start, int length) { ...@@ -656,21 +677,21 @@ void TableView::OnItemsRemoved(int start, int length) {
// If the selection was empty and is no longer empty select the same visual // If the selection was empty and is no longer empty select the same visual
// index. // index.
if (selection_model_.empty() && previously_selected_view_index != -1 && if (selection_model_.empty() && previously_selected_view_index != -1 &&
RowCount() && select_on_remove_) { GetRowCount() && select_on_remove_) {
selection_model_.SetSelectedIndex( selection_model_.SetSelectedIndex(ViewToModel(
ViewToModel(std::min(RowCount() - 1, previously_selected_view_index))); std::min(GetRowCount() - 1, previously_selected_view_index)));
} }
if (!selection_model_.empty() && selection_model_.active() == -1) if (!selection_model_.empty() && selection_model_.active() == -1)
selection_model_.set_active(FirstSelectedRow()); selection_model_.set_active(GetFirstSelectedRow());
if (!selection_model_.empty() && selection_model_.anchor() == -1) if (!selection_model_.empty() && selection_model_.anchor() == -1)
selection_model_.set_anchor(FirstSelectedRow()); selection_model_.set_anchor(GetFirstSelectedRow());
NotifyAccessibilityEvent(ax::mojom::Event::kSelection, true); NotifyAccessibilityEvent(ax::mojom::Event::kSelection, true);
if (observer_) if (observer_)
observer_->OnSelectionChanged(); observer_->OnSelectionChanged();
} }
gfx::Point TableView::GetKeyboardContextMenuLocation() { gfx::Point TableView::GetKeyboardContextMenuLocation() {
int first_selected = FirstSelectedRow(); int first_selected = GetFirstSelectedRow();
gfx::Rect vis_bounds(GetVisibleBounds()); gfx::Rect vis_bounds(GetVisibleBounds());
int y = vis_bounds.height() / 2; int y = vis_bounds.height() / 2;
if (first_selected != -1) { if (first_selected != -1) {
...@@ -696,7 +717,7 @@ void TableView::OnPaint(gfx::Canvas* canvas) { ...@@ -696,7 +717,7 @@ void TableView::OnPaint(gfx::Canvas* canvas) {
canvas->DrawColor(GetNativeTheme()->GetSystemColor( canvas->DrawColor(GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_TableBackground)); ui::NativeTheme::kColorId_TableBackground));
if (!RowCount() || visible_columns_.empty()) if (!GetRowCount() || visible_columns_.empty())
return; return;
const PaintRegion region(GetPaintRegion(GetPaintBounds(canvas))); const PaintRegion region(GetPaintRegion(GetPaintBounds(canvas)));
...@@ -827,18 +848,18 @@ void TableView::NumRowsChanged() { ...@@ -827,18 +848,18 @@ void TableView::NumRowsChanged() {
} }
void TableView::SortItemsAndUpdateMapping(bool schedule_paint) { void TableView::SortItemsAndUpdateMapping(bool schedule_paint) {
if (!is_sorted()) { if (!GetIsSorted()) {
view_to_model_.clear(); view_to_model_.clear();
model_to_view_.clear(); model_to_view_.clear();
} else { } else {
const int row_count = RowCount(); const int row_count = GetRowCount();
view_to_model_.resize(row_count); view_to_model_.resize(row_count);
model_to_view_.resize(row_count); model_to_view_.resize(row_count);
for (int i = 0; i < row_count; ++i) for (int i = 0; i < row_count; ++i)
view_to_model_[i] = i; view_to_model_[i] = i;
if (grouper_) { if (grouper_) {
GroupSortHelper sort_helper(this); GroupSortHelper sort_helper(this);
GetModelIndexToRangeStart(grouper_, RowCount(), GetModelIndexToRangeStart(grouper_, GetRowCount(),
&sort_helper.model_index_to_range_start); &sort_helper.model_index_to_range_start);
std::stable_sort(view_to_model_.begin(), view_to_model_.end(), std::stable_sort(view_to_model_.begin(), view_to_model_.end(),
sort_helper); sort_helper);
...@@ -936,15 +957,15 @@ void TableView::UpdateVisibleColumnSizes() { ...@@ -936,15 +957,15 @@ void TableView::UpdateVisibleColumnSizes() {
TableView::PaintRegion TableView::GetPaintRegion( TableView::PaintRegion TableView::GetPaintRegion(
const gfx::Rect& bounds) const { const gfx::Rect& bounds) const {
DCHECK(!visible_columns_.empty()); DCHECK(!visible_columns_.empty());
DCHECK(RowCount()); DCHECK(GetRowCount());
PaintRegion region; PaintRegion region;
region.min_row = std::min(RowCount() - 1, region.min_row =
std::max(0, bounds.y() / row_height_)); std::min(GetRowCount() - 1, std::max(0, bounds.y() / row_height_));
region.max_row = bounds.bottom() / row_height_; region.max_row = bounds.bottom() / row_height_;
if (bounds.bottom() % row_height_ != 0) if (bounds.bottom() % row_height_ != 0)
region.max_row++; region.max_row++;
region.max_row = std::min(region.max_row, RowCount()); region.max_row = std::min(region.max_row, GetRowCount());
if (!header_) { if (!header_) {
region.max_column = 1; region.max_column = 1;
...@@ -976,7 +997,7 @@ gfx::Rect TableView::GetPaintBounds(gfx::Canvas* canvas) const { ...@@ -976,7 +997,7 @@ gfx::Rect TableView::GetPaintBounds(gfx::Canvas* canvas) const {
void TableView::SchedulePaintForSelection() { void TableView::SchedulePaintForSelection() {
if (selection_model_.size() == 1) { if (selection_model_.size() == 1) {
const int first_model_row = FirstSelectedRow(); const int first_model_row = GetFirstSelectedRow();
SchedulePaintInRect(GetRowBounds(ModelToView(first_model_row))); SchedulePaintInRect(GetRowBounds(ModelToView(first_model_row)));
if (first_model_row != selection_model_.active()) if (first_model_row != selection_model_.active())
SchedulePaintInRect(GetRowBounds(ModelToView(selection_model_.active()))); SchedulePaintInRect(GetRowBounds(ModelToView(selection_model_.active())));
...@@ -1031,6 +1052,7 @@ void TableView::SetActiveVisibleColumnIndex(int index) { ...@@ -1031,6 +1052,7 @@ void TableView::SetActiveVisibleColumnIndex(int index) {
ResetFocusIndicator(); ResetFocusIndicator();
UpdateAccessibilityFocus(); UpdateAccessibilityFocus();
OnPropertyChanged(&active_visible_column_index_, kPropertyEffectsNone);
} }
void TableView::SelectByViewIndex(int view_index) { void TableView::SelectByViewIndex(int view_index) {
...@@ -1085,7 +1107,7 @@ void TableView::AdvanceSelection(AdvanceDirection direction) { ...@@ -1085,7 +1107,7 @@ void TableView::AdvanceSelection(AdvanceDirection direction) {
if (direction == ADVANCE_DECREMENT) if (direction == ADVANCE_DECREMENT)
view_index = std::max(0, view_index - 1); view_index = std::max(0, view_index - 1);
else else
view_index = std::min(RowCount() - 1, view_index + 1); view_index = std::min(GetRowCount() - 1, view_index + 1);
SelectByViewIndex(view_index); SelectByViewIndex(view_index);
} }
...@@ -1093,7 +1115,7 @@ void TableView::ConfigureSelectionModelForEvent( ...@@ -1093,7 +1115,7 @@ void TableView::ConfigureSelectionModelForEvent(
const ui::LocatedEvent& event, const ui::LocatedEvent& event,
ui::ListSelectionModel* model) const { ui::ListSelectionModel* model) const {
const int view_index = event.y() / row_height_; const int view_index = event.y() / row_height_;
DCHECK(view_index >= 0 && view_index < RowCount()); DCHECK(view_index >= 0 && view_index < GetRowCount());
if (selection_model_.anchor() == -1 || single_selection_ || if (selection_model_.anchor() == -1 || single_selection_ ||
(!IsCmdOrCtrl(event) && !event.IsShiftDown())) { (!IsCmdOrCtrl(event) && !event.IsShiftDown())) {
...@@ -1155,7 +1177,7 @@ GroupRange TableView::GetGroupRange(int model_index) const { ...@@ -1155,7 +1177,7 @@ GroupRange TableView::GetGroupRange(int model_index) const {
void TableView::UpdateVirtualAccessibilityChildren() { void TableView::UpdateVirtualAccessibilityChildren() {
GetViewAccessibility().RemoveAllVirtualChildViews(); GetViewAccessibility().RemoveAllVirtualChildViews();
if (!RowCount() || visible_columns_.empty()) { if (!GetRowCount() || visible_columns_.empty()) {
NotifyAccessibilityEvent(ax::mojom::Event::kChildrenChanged, true); NotifyAccessibilityEvent(ax::mojom::Event::kChildrenChanged, true);
return; return;
} }
...@@ -1209,7 +1231,7 @@ void TableView::UpdateVirtualAccessibilityChildren() { ...@@ -1209,7 +1231,7 @@ void TableView::UpdateVirtualAccessibilityChildren() {
GetViewAccessibility().AddVirtualChildView(std::move(ax_header)); GetViewAccessibility().AddVirtualChildView(std::move(ax_header));
} }
for (int view_index = 0; view_index < RowCount(); ++view_index) { for (int view_index = 0; view_index < GetRowCount(); ++view_index) {
const int model_index = ViewToModel(view_index); const int model_index = ViewToModel(view_index);
auto ax_row = std::make_unique<AXVirtualView>(); auto ax_row = std::make_unique<AXVirtualView>();
ui::AXNodeData& row_data = ax_row->GetCustomData(); ui::AXNodeData& row_data = ax_row->GetCustomData();
...@@ -1344,7 +1366,7 @@ void TableView::UpdateAccessibilityFocus() { ...@@ -1344,7 +1366,7 @@ void TableView::UpdateAccessibilityFocus() {
AXVirtualView* TableView::GetVirtualAccessibilityRow(int row) { AXVirtualView* TableView::GetVirtualAccessibilityRow(int row) {
DCHECK_GE(row, 0); DCHECK_GE(row, 0);
DCHECK_LT(row, RowCount()); DCHECK_LT(row, GetRowCount());
if (header_) if (header_)
++row; ++row;
if (size_t{row} < GetViewAccessibility().virtual_children().size()) { if (size_t{row} < GetViewAccessibility().virtual_children().size()) {
...@@ -1380,4 +1402,22 @@ AXVirtualView* TableView::GetVirtualAccessibilityCell( ...@@ -1380,4 +1402,22 @@ AXVirtualView* TableView::GetVirtualAccessibilityCell(
return i->get(); return i->get();
} }
DEFINE_ENUM_CONVERTERS(TableTypes,
{TableTypes::TEXT_ONLY, base::ASCIIToUTF16("TEXT_ONLY")},
{TableTypes::ICON_AND_TEXT,
base::ASCIIToUTF16("ICON_AND_TEXT")})
BEGIN_METADATA(TableView)
METADATA_PARENT_CLASS(View)
ADD_READONLY_PROPERTY_METADATA(TableView, int, RowCount)
ADD_READONLY_PROPERTY_METADATA(TableView, int, FirstSelectedRow)
ADD_READONLY_PROPERTY_METADATA(TableView, bool, HasFocusIndicator)
ADD_PROPERTY_METADATA(TableView, int, ActiveVisibleColumnIndex)
ADD_READONLY_PROPERTY_METADATA(TableView, bool, IsSorted)
ADD_READONLY_PROPERTY_METADATA(TableView, int, RowHeight)
ADD_PROPERTY_METADATA(TableView, bool, SelectOnRemove)
ADD_READONLY_PROPERTY_METADATA(TableView, TableTypes, TableType)
ADD_PROPERTY_METADATA(TableView, bool, SortOnPaint)
END_METADATA()
} // namespace views } // namespace views
...@@ -63,8 +63,7 @@ class VIEWS_EXPORT TableView ...@@ -63,8 +63,7 @@ class VIEWS_EXPORT TableView
: public views::View, : public views::View,
public ui::TableModelObserver { public ui::TableModelObserver {
public: public:
// Internal class name. METADATA_HEADER(TableView);
static const char kViewClassName[];
// Used by AdvanceActiveVisibleColumn(), AdvanceSelection() and // Used by AdvanceActiveVisibleColumn(), AdvanceSelection() and
// ResizeColumnViaKeyboard() to determine the direction to change the // ResizeColumnViaKeyboard() to determine the direction to change the
...@@ -130,13 +129,13 @@ class VIEWS_EXPORT TableView ...@@ -130,13 +129,13 @@ class VIEWS_EXPORT TableView
void SetGrouper(TableGrouper* grouper); void SetGrouper(TableGrouper* grouper);
// Returns the number of rows in the TableView. // Returns the number of rows in the TableView.
int RowCount() const; int GetRowCount() const;
// Selects the specified item, making sure it's visible. // Selects the specified item, making sure it's visible.
void Select(int model_row); void Select(int model_row);
// Returns the first selected row in terms of the model. // Returns the first selected row in terms of the model.
int FirstSelectedRow(); int GetFirstSelectedRow() const;
const ui::ListSelectionModel& selection_model() const { const ui::ListSelectionModel& selection_model() const {
return selection_model_; return selection_model_;
...@@ -154,7 +153,7 @@ class VIEWS_EXPORT TableView ...@@ -154,7 +153,7 @@ class VIEWS_EXPORT TableView
bool HasColumn(int id) const; bool HasColumn(int id) const;
// Returns whether an active row and column have been set. // 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 // 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. // hides the focus ring if the table is not focused.
...@@ -187,7 +186,7 @@ class VIEWS_EXPORT TableView ...@@ -187,7 +186,7 @@ class VIEWS_EXPORT TableView
const SortDescriptors& sort_descriptors() const { return sort_descriptors_; } const SortDescriptors& sort_descriptors() const { return sort_descriptors_; }
void SetSortDescriptors(const SortDescriptors& 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. // Maps from the index in terms of the model to that of the view.
int ModelToView(int model_index) const; int ModelToView(int model_index) const;
...@@ -195,11 +194,10 @@ class VIEWS_EXPORT TableView ...@@ -195,11 +194,10 @@ class VIEWS_EXPORT TableView
// Maps from the index in terms of the view to that of the model. // Maps from the index in terms of the view to that of the model.
int ViewToModel(int view_index) const; 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) { bool GetSelectOnRemove() const;
select_on_remove_ = select_on_remove; void SetSelectOnRemove(bool select_on_remove);
}
// WARNING: this function forces a sort on every paint, and is therefore // WARNING: this function forces a sort on every paint, and is therefore
// expensive! It assumes you are calling SchedulePaint() at intervals for // expensive! It assumes you are calling SchedulePaint() at intervals for
...@@ -208,11 +206,13 @@ class VIEWS_EXPORT TableView ...@@ -208,11 +206,13 @@ class VIEWS_EXPORT TableView
// time the SchedulePaint() is called and the paint is processed, the // time the SchedulePaint() is called and the paint is processed, the
// underlying data may change. Also, this only works if the number of rows // underlying data may change. Also, this only works if the number of rows
// remains the same. // 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: // View overrides:
void Layout() override; void Layout() override;
const char* GetClassName() const override;
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
bool OnKeyPressed(const ui::KeyEvent& event) override; bool OnKeyPressed(const ui::KeyEvent& event) override;
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
......
...@@ -191,7 +191,7 @@ int TestTableModel2::CompareValues(int row1, int row2, int column_id) { ...@@ -191,7 +191,7 @@ int TestTableModel2::CompareValues(int row1, int row2, int column_id) {
// Returns the view to model mapping as a string. // Returns the view to model mapping as a string.
std::string GetViewToModelAsString(TableView* table) { std::string GetViewToModelAsString(TableView* table) {
std::string result; std::string result;
for (int i = 0; i < table->RowCount(); ++i) { for (int i = 0; i < table->GetRowCount(); ++i) {
if (i != 0) if (i != 0)
result += " "; result += " ";
result += base::NumberToString(table->ViewToModel(i)); result += base::NumberToString(table->ViewToModel(i));
...@@ -202,7 +202,7 @@ std::string GetViewToModelAsString(TableView* table) { ...@@ -202,7 +202,7 @@ std::string GetViewToModelAsString(TableView* table) {
// Returns the model to view mapping as a string. // Returns the model to view mapping as a string.
std::string GetModelToViewAsString(TableView* table) { std::string GetModelToViewAsString(TableView* table) {
std::string result; std::string result;
for (int i = 0; i < table->RowCount(); ++i) { for (int i = 0; i < table->GetRowCount(); ++i) {
if (i != 0) if (i != 0)
result += " "; result += " ";
result += base::NumberToString(table->ModelToView(i)); result += base::NumberToString(table->ModelToView(i));
...@@ -214,7 +214,7 @@ std::string GetModelToViewAsString(TableView* table) { ...@@ -214,7 +214,7 @@ std::string GetModelToViewAsString(TableView* table) {
// scrolled out of view are included; hidden columns are excluded. // scrolled out of view are included; hidden columns are excluded.
std::string GetRowsInViewOrderAsString(TableView* table) { std::string GetRowsInViewOrderAsString(TableView* table) {
std::string result; std::string result;
for (int i = 0; i < table->RowCount(); ++i) { for (int i = 0; i < table->GetRowCount(); ++i) {
if (i != 0) if (i != 0)
result += ", "; // Comma between each row. result += ", "; // Comma between each row.
...@@ -344,7 +344,7 @@ class TableViewTest : public ViewsTestBase { ...@@ -344,7 +344,7 @@ class TableViewTest : public ViewsTestBase {
private: private:
gfx::Point GetPointForRow(int row) { 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); return table_->GetBoundsInScreen().origin() + gfx::Vector2d(5, y);
} }
...@@ -368,14 +368,15 @@ TEST_F(TableViewTest, UpdateVirtualAccessibilityChildren) { ...@@ -368,14 +368,15 @@ TEST_F(TableViewTest, UpdateVirtualAccessibilityChildren) {
EXPECT_EQ(ax::mojom::Role::kListGrid, data.role); EXPECT_EQ(ax::mojom::Role::kListGrid, data.role);
EXPECT_TRUE(data.HasState(ax::mojom::State::kFocusable)); EXPECT_TRUE(data.HasState(ax::mojom::State::kFocusable));
EXPECT_EQ(ax::mojom::Restriction::kReadOnly, data.GetRestriction()); EXPECT_EQ(ax::mojom::Restriction::kReadOnly, data.GetRestriction());
EXPECT_EQ(table_->RowCount(), static_cast<int>(data.GetIntAttribute( EXPECT_EQ(table_->GetRowCount(),
ax::mojom::IntAttribute::kTableRowCount))); static_cast<int>(
data.GetIntAttribute(ax::mojom::IntAttribute::kTableRowCount)));
EXPECT_EQ(helper_->visible_col_count(), EXPECT_EQ(helper_->visible_col_count(),
static_cast<size_t>(data.GetIntAttribute( static_cast<size_t>(data.GetIntAttribute(
ax::mojom::IntAttribute::kTableColumnCount))); ax::mojom::IntAttribute::kTableColumnCount)));
// The header takes up another row. // 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()); view_accessibility.virtual_children().size());
const auto& header = view_accessibility.virtual_children().front(); const auto& header = view_accessibility.virtual_children().front();
ASSERT_TRUE(header); ASSERT_TRUE(header);
...@@ -393,7 +394,7 @@ TEST_F(TableViewTest, UpdateVirtualAccessibilityChildren) { ...@@ -393,7 +394,7 @@ TEST_F(TableViewTest, UpdateVirtualAccessibilityChildren) {
int i = 0; int i = 0;
for (auto child_iter = view_accessibility.virtual_children().begin() + 1; 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; const auto& row = *child_iter;
ASSERT_TRUE(row); ASSERT_TRUE(row);
const ui::AXNodeData& row_data = row->GetData(); const ui::AXNodeData& row_data = row->GetData();
...@@ -416,7 +417,7 @@ TEST_F(TableViewTest, UpdateVirtualAccessibilityChildren) { ...@@ -416,7 +417,7 @@ TEST_F(TableViewTest, UpdateVirtualAccessibilityChildren) {
} }
TEST_F(TableViewTest, GetVirtualAccessibilityRow) { 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); const AXVirtualView* row = helper_->GetVirtualAccessibilityRow(i);
ASSERT_TRUE(row); ASSERT_TRUE(row);
const ui::AXNodeData& row_data = row->GetData(); const ui::AXNodeData& row_data = row->GetData();
...@@ -427,7 +428,7 @@ TEST_F(TableViewTest, GetVirtualAccessibilityRow) { ...@@ -427,7 +428,7 @@ TEST_F(TableViewTest, GetVirtualAccessibilityRow) {
} }
TEST_F(TableViewTest, GetVirtualAccessibilityCell) { 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) { for (int j = 0; j < static_cast<int>(helper_->visible_col_count()); ++j) {
const AXVirtualView* cell = helper_->GetVirtualAccessibilityCell(i, j); const AXVirtualView* cell = helper_->GetVirtualAccessibilityCell(i, j);
ASSERT_TRUE(cell); ASSERT_TRUE(cell);
...@@ -991,7 +992,7 @@ TEST_F(TableViewTest, RemoveUnselectedRows) { ...@@ -991,7 +992,7 @@ TEST_F(TableViewTest, RemoveUnselectedRows) {
TEST_F(TableViewTest, SelectionNoSelectOnRemove) { TEST_F(TableViewTest, SelectionNoSelectOnRemove) {
TableViewObserverImpl observer; TableViewObserverImpl observer;
table_->set_observer(&observer); table_->set_observer(&observer);
table_->set_select_on_remove(false); table_->SetSelectOnRemove(false);
// Initially no selection. // Initially no selection.
EXPECT_EQ("active=-1 anchor=-1 selection=", SelectionStateAsString()); 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