| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/table/table_view.h" | 5 #include "ui/views/controls/table/table_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 columns[1].sortable = true; | 217 columns[1].sortable = true; |
| 218 table_ = new TestTableView(model_.get(), columns); | 218 table_ = new TestTableView(model_.get(), columns); |
| 219 parent_.reset(table_->CreateParentIfNecessary()); | 219 parent_.reset(table_->CreateParentIfNecessary()); |
| 220 parent_->SetBounds(0, 0, 10000, 10000); | 220 parent_->SetBounds(0, 0, 10000, 10000); |
| 221 parent_->Layout(); | 221 parent_->Layout(); |
| 222 helper_.reset(new TableViewTestHelper(table_)); | 222 helper_.reset(new TableViewTestHelper(table_)); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void ClickOnRow(int row, int flags) { | 225 void ClickOnRow(int row, int flags) { |
| 226 const int y = row * table_->row_height(); | 226 const int y = row * table_->row_height(); |
| 227 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, y), | 227 const ui::MouseEvent pressed( |
| 228 gfx::Point(0, y), ui::EventTimeForNow(), | 228 ui::ET_MOUSE_PRESSED, gfx::Point(0, y), gfx::Point(0, y), |
| 229 ui::EF_LEFT_MOUSE_BUTTON | flags, | 229 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON | flags, |
| 230 ui::EF_LEFT_MOUSE_BUTTON); | 230 ui::EF_LEFT_MOUSE_BUTTON, |
| 231 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 231 table_->OnMousePressed(pressed); | 232 table_->OnMousePressed(pressed); |
| 232 } | 233 } |
| 233 | 234 |
| 234 void TapOnRow(int row) { | 235 void TapOnRow(int row) { |
| 235 const int y = row * table_->row_height(); | 236 const int y = row * table_->row_height(); |
| 236 const ui::GestureEventDetails event_details(ui::ET_GESTURE_TAP); | 237 const ui::GestureEventDetails event_details(ui::ET_GESTURE_TAP); |
| 237 ui::GestureEvent tap(0, y, 0, base::TimeTicks(), event_details); | 238 ui::GestureEvent tap(0, y, 0, base::TimeTicks(), event_details); |
| 238 table_->OnGestureEvent(&tap); | 239 table_->OnGestureEvent(&tap); |
| 239 } | 240 } |
| 240 | 241 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 EXPECT_EQ(1, table_->visible_columns()[0].column.id); | 316 EXPECT_EQ(1, table_->visible_columns()[0].column.id); |
| 316 EXPECT_EQ(0, table_->visible_columns()[1].column.id); | 317 EXPECT_EQ(0, table_->visible_columns()[1].column.id); |
| 317 EXPECT_EQ("rows=0 4 cols=0 2", helper_->GetPaintRegion(table_->bounds())); | 318 EXPECT_EQ("rows=0 4 cols=0 2", helper_->GetPaintRegion(table_->bounds())); |
| 318 } | 319 } |
| 319 | 320 |
| 320 // Verifies resizing a column works. | 321 // Verifies resizing a column works. |
| 321 TEST_F(TableViewTest, Resize) { | 322 TEST_F(TableViewTest, Resize) { |
| 322 const int x = table_->visible_columns()[0].width; | 323 const int x = table_->visible_columns()[0].width; |
| 323 EXPECT_NE(0, x); | 324 EXPECT_NE(0, x); |
| 324 // Drag the mouse 1 pixel to the left. | 325 // Drag the mouse 1 pixel to the left. |
| 325 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), | 326 const ui::MouseEvent pressed( |
| 326 gfx::Point(x, 0), ui::EventTimeForNow(), | 327 ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), gfx::Point(x, 0), |
| 327 ui::EF_LEFT_MOUSE_BUTTON, | 328 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 328 ui::EF_LEFT_MOUSE_BUTTON); | 329 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 329 helper_->header()->OnMousePressed(pressed); | 330 helper_->header()->OnMousePressed(pressed); |
| 330 const ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, gfx::Point(x - 1, 0), | 331 const ui::MouseEvent dragged( |
| 331 gfx::Point(x - 1, 0), ui::EventTimeForNow(), | 332 ui::ET_MOUSE_DRAGGED, gfx::Point(x - 1, 0), gfx::Point(x - 1, 0), |
| 332 ui::EF_LEFT_MOUSE_BUTTON, 0); | 333 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0, |
| 334 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 333 helper_->header()->OnMouseDragged(dragged); | 335 helper_->header()->OnMouseDragged(dragged); |
| 334 | 336 |
| 335 // This should shrink the first column and pull the second column in. | 337 // This should shrink the first column and pull the second column in. |
| 336 EXPECT_EQ(x - 1, table_->visible_columns()[0].width); | 338 EXPECT_EQ(x - 1, table_->visible_columns()[0].width); |
| 337 EXPECT_EQ(x - 1, table_->visible_columns()[1].x); | 339 EXPECT_EQ(x - 1, table_->visible_columns()[1].x); |
| 338 } | 340 } |
| 339 | 341 |
| 340 // Verifies resizing a column works with a gesture. | 342 // Verifies resizing a column works with a gesture. |
| 341 TEST_F(TableViewTest, ResizeViaGesture) { | 343 TEST_F(TableViewTest, ResizeViaGesture) { |
| 342 const int x = table_->visible_columns()[0].width; | 344 const int x = table_->visible_columns()[0].width; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 GetRowsInViewOrderAsString(table_)); | 489 GetRowsInViewOrderAsString(table_)); |
| 488 } | 490 } |
| 489 | 491 |
| 490 // Verfies clicking on the header sorts. | 492 // Verfies clicking on the header sorts. |
| 491 TEST_F(TableViewTest, SortOnMouse) { | 493 TEST_F(TableViewTest, SortOnMouse) { |
| 492 EXPECT_TRUE(table_->sort_descriptors().empty()); | 494 EXPECT_TRUE(table_->sort_descriptors().empty()); |
| 493 | 495 |
| 494 const int x = table_->visible_columns()[0].width / 2; | 496 const int x = table_->visible_columns()[0].width / 2; |
| 495 EXPECT_NE(0, x); | 497 EXPECT_NE(0, x); |
| 496 // Press and release the mouse. | 498 // Press and release the mouse. |
| 497 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), | 499 const ui::MouseEvent pressed( |
| 498 gfx::Point(x, 0), ui::EventTimeForNow(), | 500 ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), gfx::Point(x, 0), |
| 499 ui::EF_LEFT_MOUSE_BUTTON, | 501 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 500 ui::EF_LEFT_MOUSE_BUTTON); | 502 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 501 // The header must return true, else it won't normally get the release. | 503 // The header must return true, else it won't normally get the release. |
| 502 EXPECT_TRUE(helper_->header()->OnMousePressed(pressed)); | 504 EXPECT_TRUE(helper_->header()->OnMousePressed(pressed)); |
| 503 const ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(x, 0), | 505 const ui::MouseEvent release( |
| 504 gfx::Point(x, 0), ui::EventTimeForNow(), | 506 ui::ET_MOUSE_RELEASED, gfx::Point(x, 0), gfx::Point(x, 0), |
| 505 ui::EF_LEFT_MOUSE_BUTTON, | 507 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 506 ui::EF_LEFT_MOUSE_BUTTON); | 508 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 507 helper_->header()->OnMouseReleased(release); | 509 helper_->header()->OnMouseReleased(release); |
| 508 | 510 |
| 509 ASSERT_EQ(1u, table_->sort_descriptors().size()); | 511 ASSERT_EQ(1u, table_->sort_descriptors().size()); |
| 510 EXPECT_EQ(0, table_->sort_descriptors()[0].column_id); | 512 EXPECT_EQ(0, table_->sort_descriptors()[0].column_id); |
| 511 EXPECT_TRUE(table_->sort_descriptors()[0].ascending); | 513 EXPECT_TRUE(table_->sort_descriptors()[0].ascending); |
| 512 } | 514 } |
| 513 | 515 |
| 514 namespace { | 516 namespace { |
| 515 | 517 |
| 516 class TableGrouperImpl : public TableGrouper { | 518 class TableGrouperImpl : public TableGrouper { |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 while (model_->RowCount()) | 1043 while (model_->RowCount()) |
| 1042 model_->RemoveRow(0); | 1044 model_->RemoveRow(0); |
| 1043 | 1045 |
| 1044 new_selection.set_active(-1); | 1046 new_selection.set_active(-1); |
| 1045 helper_->SetSelectionModel(new_selection); | 1047 helper_->SetSelectionModel(new_selection); |
| 1046 helper_->OnFocus(); | 1048 helper_->OnFocus(); |
| 1047 EXPECT_EQ(-1, table_->selection_model().active()); | 1049 EXPECT_EQ(-1, table_->selection_model().active()); |
| 1048 } | 1050 } |
| 1049 | 1051 |
| 1050 } // namespace views | 1052 } // namespace views |
| OLD | NEW |