| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 TableView* table_; | 47 TableView* table_; |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(TableViewTestHelper); | 49 DISALLOW_COPY_AND_ASSIGN(TableViewTestHelper); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 #if defined(OS_MACOSX) |
| 55 constexpr int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN; |
| 56 #else |
| 57 constexpr int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN; |
| 58 #endif |
| 59 |
| 54 // TestTableModel2 ------------------------------------------------------------- | 60 // TestTableModel2 ------------------------------------------------------------- |
| 55 | 61 |
| 56 // Trivial TableModel implementation that is backed by a vector of vectors. | 62 // Trivial TableModel implementation that is backed by a vector of vectors. |
| 57 // Provides methods for adding/removing/changing the contents that notify the | 63 // Provides methods for adding/removing/changing the contents that notify the |
| 58 // observer appropriately. | 64 // observer appropriately. |
| 59 // | 65 // |
| 60 // Initial contents are: | 66 // Initial contents are: |
| 61 // 0, 1 | 67 // 0, 1 |
| 62 // 1, 1 | 68 // 1, 1 |
| 63 // 2, 2 | 69 // 2, 2 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 columns[0].sortable = true; | 203 columns[0].sortable = true; |
| 198 columns[1].title = base::ASCIIToUTF16("Title Column 1"); | 204 columns[1].title = base::ASCIIToUTF16("Title Column 1"); |
| 199 columns[1].id = 1; | 205 columns[1].id = 1; |
| 200 columns[1].sortable = true; | 206 columns[1].sortable = true; |
| 201 table_ = new TableView(model_.get(), columns, TEXT_ONLY, false); | 207 table_ = new TableView(model_.get(), columns, TEXT_ONLY, false); |
| 202 View* parent = table_->CreateParentIfNecessary(); | 208 View* parent = table_->CreateParentIfNecessary(); |
| 203 parent->SetBounds(0, 0, 10000, 10000); | 209 parent->SetBounds(0, 0, 10000, 10000); |
| 204 parent->Layout(); | 210 parent->Layout(); |
| 205 helper_.reset(new TableViewTestHelper(table_)); | 211 helper_.reset(new TableViewTestHelper(table_)); |
| 206 | 212 |
| 207 Widget::InitParams params = | 213 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 208 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 209 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 214 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 210 params.bounds = gfx::Rect(0, 0, 650, 650); | 215 params.bounds = gfx::Rect(0, 0, 650, 650); |
| 211 widget_.reset(new Widget); | 216 widget_.reset(new Widget); |
| 212 widget_->Init(params); | 217 widget_->Init(params); |
| 213 widget_->GetContentsView()->AddChildView(parent); | 218 widget_->GetContentsView()->AddChildView(parent); |
| 214 widget_->Show(); | 219 widget_->Show(); |
| 215 } | 220 } |
| 216 | 221 |
| 217 void TearDown() override { | 222 void TearDown() override { |
| 218 widget_.reset(); | 223 widget_.reset(); |
| 219 ViewsTestBase::TearDown(); | 224 ViewsTestBase::TearDown(); |
| 220 } | 225 } |
| 221 | 226 |
| 222 void ClickOnRow(int row, int flags) { | 227 void ClickOnRow(int row, int flags) { |
| 223 ui::test::EventGenerator generator(widget_->GetNativeWindow()); | 228 ui::test::EventGenerator generator(widget_->GetNativeWindow()); |
| 229 generator.set_assume_window_at_origin(false); |
| 224 generator.set_flags(flags); | 230 generator.set_flags(flags); |
| 225 generator.set_current_location(GetPointForRow(row)); | 231 generator.set_current_location(GetPointForRow(row)); |
| 226 generator.PressLeftButton(); | 232 generator.PressLeftButton(); |
| 227 } | 233 } |
| 228 | 234 |
| 229 void TapOnRow(int row) { | 235 void TapOnRow(int row) { |
| 230 ui::test::EventGenerator generator(widget_->GetNativeWindow()); | 236 ui::test::EventGenerator generator(widget_->GetNativeWindow()); |
| 231 generator.GestureTapAt(GetPointForRow(row)); | 237 generator.GestureTapAt(GetPointForRow(row)); |
| 232 } | 238 } |
| 233 | 239 |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 ClickOnRow(4, 0); | 952 ClickOnRow(4, 0); |
| 947 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 953 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 948 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); | 954 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); |
| 949 | 955 |
| 950 // Shift click on the third row, should extend selection to it. | 956 // Shift click on the third row, should extend selection to it. |
| 951 ClickOnRow(2, ui::EF_SHIFT_DOWN); | 957 ClickOnRow(2, ui::EF_SHIFT_DOWN); |
| 952 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 958 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 953 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); | 959 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); |
| 954 | 960 |
| 955 // Control click on third row, should toggle it. | 961 // Control click on third row, should toggle it. |
| 956 ClickOnRow(2, ui::EF_CONTROL_DOWN); | 962 ClickOnRow(2, kCtrlOrCmdMask); |
| 957 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 963 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 958 EXPECT_EQ("active=2 anchor=2 selection=3 4", SelectionStateAsString()); | 964 EXPECT_EQ("active=2 anchor=2 selection=3 4", SelectionStateAsString()); |
| 959 | 965 |
| 960 // Control-shift click on second row, should extend selection to it. | 966 // Control-shift click on second row, should extend selection to it. |
| 961 ClickOnRow(1, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); | 967 ClickOnRow(1, kCtrlOrCmdMask | ui::EF_SHIFT_DOWN); |
| 962 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 968 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 963 EXPECT_EQ("active=1 anchor=2 selection=0 1 2 3 4", SelectionStateAsString()); | 969 EXPECT_EQ("active=1 anchor=2 selection=0 1 2 3 4", SelectionStateAsString()); |
| 964 | 970 |
| 965 // Click on last row again. | 971 // Click on last row again. |
| 966 ClickOnRow(4, 0); | 972 ClickOnRow(4, 0); |
| 967 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 973 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 968 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); | 974 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); |
| 969 | 975 |
| 970 table_->set_observer(NULL); | 976 table_->set_observer(NULL); |
| 971 } | 977 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 new_selection.AddIndexToSelection(0); | 1030 new_selection.AddIndexToSelection(0); |
| 1025 new_selection.AddIndexToSelection(1); | 1031 new_selection.AddIndexToSelection(1); |
| 1026 new_selection.set_active(0); | 1032 new_selection.set_active(0); |
| 1027 new_selection.set_anchor(0); | 1033 new_selection.set_anchor(0); |
| 1028 helper_->SetSelectionModel(new_selection); | 1034 helper_->SetSelectionModel(new_selection); |
| 1029 model_->RemoveRow(0); | 1035 model_->RemoveRow(0); |
| 1030 table_->RequestFocus(); | 1036 table_->RequestFocus(); |
| 1031 } | 1037 } |
| 1032 | 1038 |
| 1033 } // namespace views | 1039 } // namespace views |
| OLD | NEW |