OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/string16.h" | 6 #include "base/string16.h" |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
10 #include "ui/base/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 content_view_->AddChildView(button); | 971 content_view_->AddChildView(button); |
972 button->SetBounds(10, 10, 200, 30); | 972 button->SetBounds(10, 10, 200, 30); |
973 content_view_->AddChildView(view); | 973 content_view_->AddChildView(view); |
974 RunPendingMessages(); | 974 RunPendingMessages(); |
975 | 975 |
976 TestFocusChangeListener listener; | 976 TestFocusChangeListener listener; |
977 AddFocusChangeListener(&listener); | 977 AddFocusChangeListener(&listener); |
978 | 978 |
979 view->RequestFocus(); | 979 view->RequestFocus(); |
980 RunPendingMessages(); | 980 RunPendingMessages(); |
981 // MessageLoopForUI::current()->Run(new AcceleratorHandler()); | 981 // MessageLoopForUI::current()->RunWithDispatcher(new AcceleratorHandler()); |
982 | 982 |
983 // Visual Studio 2010 has problems converting NULL to the null pointer for | 983 // Visual Studio 2010 has problems converting NULL to the null pointer for |
984 // std::pair. See http://connect.microsoft.com/VisualStudio/feedback/details/
520043/error-converting-from-null-to-a-pointer-type-in-std-pair | 984 // std::pair. See http://connect.microsoft.com/VisualStudio/feedback/details/
520043/error-converting-from-null-to-a-pointer-type-in-std-pair |
985 // It will work if we pass nullptr. | 985 // It will work if we pass nullptr. |
986 #if defined(_MSC_VER) && _MSC_VER >= 1600 | 986 #if defined(_MSC_VER) && _MSC_VER >= 1600 |
987 views::View* null_view = nullptr; | 987 views::View* null_view = nullptr; |
988 #else | 988 #else |
989 views::View* null_view = NULL; | 989 views::View* null_view = NULL; |
990 #endif | 990 #endif |
991 | 991 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 kDinerGameLinkID, kRidiculeLinkID, kClosetLinkID, kVisitingLinkID, | 1071 kDinerGameLinkID, kRidiculeLinkID, kClosetLinkID, kVisitingLinkID, |
1072 kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID, | 1072 kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID, |
1073 kTaxiLinkID, kAsterixLinkID, kOKButtonID, kCancelButtonID, kHelpButtonID, | 1073 kTaxiLinkID, kAsterixLinkID, kOKButtonID, kCancelButtonID, kHelpButtonID, |
1074 kStyleContainerID, kBoldCheckBoxID, kItalicCheckBoxID, | 1074 kStyleContainerID, kBoldCheckBoxID, kItalicCheckBoxID, |
1075 kUnderlinedCheckBoxID, kStyleHelpLinkID, kStyleTextEditID, | 1075 kUnderlinedCheckBoxID, kStyleHelpLinkID, kStyleTextEditID, |
1076 kSearchTextfieldID, kSearchButtonID, kHelpLinkID, | 1076 kSearchTextfieldID, kSearchButtonID, kHelpLinkID, |
1077 kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID }; | 1077 kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID }; |
1078 | 1078 |
1079 // Uncomment the following line if you want to test manually the UI of this | 1079 // Uncomment the following line if you want to test manually the UI of this |
1080 // test. | 1080 // test. |
1081 // MessageLoopForUI::current()->Run(new AcceleratorHandler()); | 1081 // MessageLoopForUI::current()->RunWithDispatcher(new AcceleratorHandler()); |
1082 | 1082 |
1083 // Let's traverse the whole focus hierarchy (several times, to make sure it | 1083 // Let's traverse the whole focus hierarchy (several times, to make sure it |
1084 // loops OK). | 1084 // loops OK). |
1085 GetFocusManager()->ClearFocus(); | 1085 GetFocusManager()->ClearFocus(); |
1086 for (int i = 0; i < 3; ++i) { | 1086 for (int i = 0; i < 3; ++i) { |
1087 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { | 1087 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { |
1088 GetFocusManager()->AdvanceFocus(false); | 1088 GetFocusManager()->AdvanceFocus(false); |
1089 View* focused_view = GetFocusManager()->GetFocusedView(); | 1089 View* focused_view = GetFocusManager()->GetFocusedView(); |
1090 EXPECT_TRUE(focused_view != NULL); | 1090 EXPECT_TRUE(focused_view != NULL); |
1091 if (focused_view) | 1091 if (focused_view) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 | 1124 |
1125 // Let's disable some views. | 1125 // Let's disable some views. |
1126 for (size_t i = 0; i < arraysize(kDisabledIDs); i++) { | 1126 for (size_t i = 0; i < arraysize(kDisabledIDs); i++) { |
1127 View* v = FindViewByID(kDisabledIDs[i]); | 1127 View* v = FindViewByID(kDisabledIDs[i]); |
1128 ASSERT_TRUE(v != NULL); | 1128 ASSERT_TRUE(v != NULL); |
1129 v->SetEnabled(false); | 1129 v->SetEnabled(false); |
1130 } | 1130 } |
1131 | 1131 |
1132 // Uncomment the following line if you want to test manually the UI of this | 1132 // Uncomment the following line if you want to test manually the UI of this |
1133 // test. | 1133 // test. |
1134 // MessageLoopForUI::current()->Run(new AcceleratorHandler()); | 1134 // MessageLoopForUI::current()->RunWithDispatcher(new AcceleratorHandler()); |
1135 | 1135 |
1136 View* focused_view; | 1136 View* focused_view; |
1137 // Let's do one traversal (several times, to make sure it loops ok). | 1137 // Let's do one traversal (several times, to make sure it loops ok). |
1138 GetFocusManager()->ClearFocus(); | 1138 GetFocusManager()->ClearFocus(); |
1139 for (int i = 0; i < 3; ++i) { | 1139 for (int i = 0; i < 3; ++i) { |
1140 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { | 1140 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { |
1141 GetFocusManager()->AdvanceFocus(false); | 1141 GetFocusManager()->AdvanceFocus(false); |
1142 focused_view = GetFocusManager()->GetFocusedView(); | 1142 focused_view = GetFocusManager()->GetFocusedView(); |
1143 EXPECT_TRUE(focused_view != NULL); | 1143 EXPECT_TRUE(focused_view != NULL); |
1144 if (focused_view) | 1144 if (focused_view) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 | 1176 |
1177 // Let's make some views invisible. | 1177 // Let's make some views invisible. |
1178 for (size_t i = 0; i < arraysize(kInvisibleIDs); i++) { | 1178 for (size_t i = 0; i < arraysize(kInvisibleIDs); i++) { |
1179 View* v = FindViewByID(kInvisibleIDs[i]); | 1179 View* v = FindViewByID(kInvisibleIDs[i]); |
1180 ASSERT_TRUE(v != NULL); | 1180 ASSERT_TRUE(v != NULL); |
1181 v->SetVisible(false); | 1181 v->SetVisible(false); |
1182 } | 1182 } |
1183 | 1183 |
1184 // Uncomment the following line if you want to test manually the UI of this | 1184 // Uncomment the following line if you want to test manually the UI of this |
1185 // test. | 1185 // test. |
1186 // MessageLoopForUI::current()->Run(new AcceleratorHandler()); | 1186 // MessageLoopForUI::current()->RunWithDispatcher(new AcceleratorHandler()); |
1187 | 1187 |
1188 View* focused_view; | 1188 View* focused_view; |
1189 // Let's do one traversal (several times, to make sure it loops ok). | 1189 // Let's do one traversal (several times, to make sure it loops ok). |
1190 GetFocusManager()->ClearFocus(); | 1190 GetFocusManager()->ClearFocus(); |
1191 for (int i = 0; i < 3; ++i) { | 1191 for (int i = 0; i < 3; ++i) { |
1192 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { | 1192 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { |
1193 GetFocusManager()->AdvanceFocus(false); | 1193 GetFocusManager()->AdvanceFocus(false); |
1194 focused_view = GetFocusManager()->GetFocusedView(); | 1194 focused_view = GetFocusManager()->GetFocusedView(); |
1195 EXPECT_TRUE(focused_view != NULL); | 1195 EXPECT_TRUE(focused_view != NULL); |
1196 if (focused_view) | 1196 if (focused_view) |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 mtv->AddAccelerator(Accelerator(ui::VKEY_0, false, false, false)); | 1507 mtv->AddAccelerator(Accelerator(ui::VKEY_0, false, false, false)); |
1508 mtv->AddAccelerator(Accelerator(ui::VKEY_1, false, false, false)); | 1508 mtv->AddAccelerator(Accelerator(ui::VKEY_1, false, false, false)); |
1509 content_view_->AddChildView(mtv); | 1509 content_view_->AddChildView(mtv); |
1510 focus_manager->SetFocusedView(mtv); | 1510 focus_manager->SetFocusedView(mtv); |
1511 | 1511 |
1512 // First send a non-accelerator key sequence. | 1512 // First send a non-accelerator key sequence. |
1513 PostKeyDown(ui::VKEY_9); | 1513 PostKeyDown(ui::VKEY_9); |
1514 PostKeyUp(ui::VKEY_9); | 1514 PostKeyUp(ui::VKEY_9); |
1515 AcceleratorHandler accelerator_handler; | 1515 AcceleratorHandler accelerator_handler; |
1516 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 1516 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
1517 MessageLoopForUI::current()->Run(&accelerator_handler); | 1517 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); |
1518 // Make sure we get a key-up and key-down. | 1518 // Make sure we get a key-up and key-down. |
1519 ASSERT_EQ(1U, mtv->keys_pressed().size()); | 1519 ASSERT_EQ(1U, mtv->keys_pressed().size()); |
1520 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[0]); | 1520 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[0]); |
1521 ASSERT_EQ(1U, mtv->keys_released().size()); | 1521 ASSERT_EQ(1U, mtv->keys_released().size()); |
1522 EXPECT_EQ(ui::VKEY_9, mtv->keys_released()[0]); | 1522 EXPECT_EQ(ui::VKEY_9, mtv->keys_released()[0]); |
1523 EXPECT_FALSE(mtv->accelerator_pressed()); | 1523 EXPECT_FALSE(mtv->accelerator_pressed()); |
1524 mtv->Reset(); | 1524 mtv->Reset(); |
1525 | 1525 |
1526 // Same thing with repeat and more than one key at once. | 1526 // Same thing with repeat and more than one key at once. |
1527 PostKeyDown(ui::VKEY_9); | 1527 PostKeyDown(ui::VKEY_9); |
1528 PostKeyDown(ui::VKEY_9); | 1528 PostKeyDown(ui::VKEY_9); |
1529 PostKeyDown(ui::VKEY_8); | 1529 PostKeyDown(ui::VKEY_8); |
1530 PostKeyDown(ui::VKEY_9); | 1530 PostKeyDown(ui::VKEY_9); |
1531 PostKeyDown(ui::VKEY_7); | 1531 PostKeyDown(ui::VKEY_7); |
1532 PostKeyUp(ui::VKEY_9); | 1532 PostKeyUp(ui::VKEY_9); |
1533 PostKeyUp(ui::VKEY_7); | 1533 PostKeyUp(ui::VKEY_7); |
1534 PostKeyUp(ui::VKEY_8); | 1534 PostKeyUp(ui::VKEY_8); |
1535 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 1535 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
1536 MessageLoopForUI::current()->Run(&accelerator_handler); | 1536 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); |
1537 // Make sure we get a key-up and key-down. | 1537 // Make sure we get a key-up and key-down. |
1538 ASSERT_EQ(5U, mtv->keys_pressed().size()); | 1538 ASSERT_EQ(5U, mtv->keys_pressed().size()); |
1539 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[0]); | 1539 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[0]); |
1540 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[1]); | 1540 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[1]); |
1541 EXPECT_EQ(ui::VKEY_8, mtv->keys_pressed()[2]); | 1541 EXPECT_EQ(ui::VKEY_8, mtv->keys_pressed()[2]); |
1542 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[3]); | 1542 EXPECT_EQ(ui::VKEY_9, mtv->keys_pressed()[3]); |
1543 EXPECT_EQ(ui::VKEY_7, mtv->keys_pressed()[4]); | 1543 EXPECT_EQ(ui::VKEY_7, mtv->keys_pressed()[4]); |
1544 ASSERT_EQ(3U, mtv->keys_released().size()); | 1544 ASSERT_EQ(3U, mtv->keys_released().size()); |
1545 EXPECT_EQ(ui::VKEY_9, mtv->keys_released()[0]); | 1545 EXPECT_EQ(ui::VKEY_9, mtv->keys_released()[0]); |
1546 EXPECT_EQ(ui::VKEY_7, mtv->keys_released()[1]); | 1546 EXPECT_EQ(ui::VKEY_7, mtv->keys_released()[1]); |
1547 EXPECT_EQ(ui::VKEY_8, mtv->keys_released()[2]); | 1547 EXPECT_EQ(ui::VKEY_8, mtv->keys_released()[2]); |
1548 EXPECT_FALSE(mtv->accelerator_pressed()); | 1548 EXPECT_FALSE(mtv->accelerator_pressed()); |
1549 mtv->Reset(); | 1549 mtv->Reset(); |
1550 | 1550 |
1551 // Now send an accelerator key sequence. | 1551 // Now send an accelerator key sequence. |
1552 PostKeyDown(ui::VKEY_0); | 1552 PostKeyDown(ui::VKEY_0); |
1553 PostKeyUp(ui::VKEY_0); | 1553 PostKeyUp(ui::VKEY_0); |
1554 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 1554 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
1555 MessageLoopForUI::current()->Run(&accelerator_handler); | 1555 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); |
1556 EXPECT_TRUE(mtv->keys_pressed().empty()); | 1556 EXPECT_TRUE(mtv->keys_pressed().empty()); |
1557 EXPECT_TRUE(mtv->keys_released().empty()); | 1557 EXPECT_TRUE(mtv->keys_released().empty()); |
1558 EXPECT_TRUE(mtv->accelerator_pressed()); | 1558 EXPECT_TRUE(mtv->accelerator_pressed()); |
1559 mtv->Reset(); | 1559 mtv->Reset(); |
1560 | 1560 |
1561 // Same thing with repeat and more than one key at once. | 1561 // Same thing with repeat and more than one key at once. |
1562 PostKeyDown(ui::VKEY_0); | 1562 PostKeyDown(ui::VKEY_0); |
1563 PostKeyDown(ui::VKEY_1); | 1563 PostKeyDown(ui::VKEY_1); |
1564 PostKeyDown(ui::VKEY_1); | 1564 PostKeyDown(ui::VKEY_1); |
1565 PostKeyDown(ui::VKEY_0); | 1565 PostKeyDown(ui::VKEY_0); |
1566 PostKeyDown(ui::VKEY_0); | 1566 PostKeyDown(ui::VKEY_0); |
1567 PostKeyUp(ui::VKEY_1); | 1567 PostKeyUp(ui::VKEY_1); |
1568 PostKeyUp(ui::VKEY_0); | 1568 PostKeyUp(ui::VKEY_0); |
1569 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 1569 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
1570 MessageLoopForUI::current()->Run(&accelerator_handler); | 1570 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); |
1571 EXPECT_TRUE(mtv->keys_pressed().empty()); | 1571 EXPECT_TRUE(mtv->keys_pressed().empty()); |
1572 EXPECT_TRUE(mtv->keys_released().empty()); | 1572 EXPECT_TRUE(mtv->keys_released().empty()); |
1573 EXPECT_TRUE(mtv->accelerator_pressed()); | 1573 EXPECT_TRUE(mtv->accelerator_pressed()); |
1574 mtv->Reset(); | 1574 mtv->Reset(); |
1575 } | 1575 } |
1576 #endif | 1576 #endif |
1577 | 1577 |
1578 #if defined(OS_WIN) && !defined(USE_AURA) | 1578 #if defined(OS_WIN) && !defined(USE_AURA) |
1579 // Test that the focus manager is created successfully for the first view | 1579 // Test that the focus manager is created successfully for the first view |
1580 // window parented to a native dialog. | 1580 // window parented to a native dialog. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); | 1751 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); |
1752 | 1752 |
1753 // Focus manager should be the last one to destruct. | 1753 // Focus manager should be the last one to destruct. |
1754 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); | 1754 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); |
1755 | 1755 |
1756 // Clear window_ so that we don't try to close it again. | 1756 // Clear window_ so that we don't try to close it again. |
1757 window_ = NULL; | 1757 window_ = NULL; |
1758 } | 1758 } |
1759 | 1759 |
1760 } // namespace views | 1760 } // namespace views |
OLD | NEW |