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 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 } | 1287 } |
1288 } | 1288 } |
1289 } | 1289 } |
1290 | 1290 |
1291 // Counts accelerator calls. | 1291 // Counts accelerator calls. |
1292 class TestAcceleratorTarget : public AcceleratorTarget { | 1292 class TestAcceleratorTarget : public AcceleratorTarget { |
1293 public: | 1293 public: |
1294 explicit TestAcceleratorTarget(bool process_accelerator) | 1294 explicit TestAcceleratorTarget(bool process_accelerator) |
1295 : accelerator_count_(0), process_accelerator_(process_accelerator) {} | 1295 : accelerator_count_(0), process_accelerator_(process_accelerator) {} |
1296 | 1296 |
1297 virtual bool AcceleratorPressed(const Accelerator& accelerator) { | 1297 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { |
1298 ++accelerator_count_; | 1298 ++accelerator_count_; |
1299 return process_accelerator_; | 1299 return process_accelerator_; |
1300 } | 1300 } |
1301 | 1301 |
1302 int accelerator_count() const { return accelerator_count_; } | 1302 int accelerator_count() const { return accelerator_count_; } |
1303 | 1303 |
1304 private: | 1304 private: |
1305 int accelerator_count_; // number of times that the accelerator is activated | 1305 int accelerator_count_; // number of times that the accelerator is activated |
1306 bool process_accelerator_; // return value of AcceleratorPressed | 1306 bool process_accelerator_; // return value of AcceleratorPressed |
1307 | 1307 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 // Hitting the return key and the escape key. Nothing should happen. | 1394 // Hitting the return key and the escape key. Nothing should happen. |
1395 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); | 1395 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); |
1396 EXPECT_EQ(return_target.accelerator_count(), 2); | 1396 EXPECT_EQ(return_target.accelerator_count(), 2); |
1397 EXPECT_EQ(return_target2.accelerator_count(), 2); | 1397 EXPECT_EQ(return_target2.accelerator_count(), 2); |
1398 EXPECT_EQ(return_target3.accelerator_count(), 2); | 1398 EXPECT_EQ(return_target3.accelerator_count(), 2); |
1399 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); | 1399 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); |
1400 EXPECT_EQ(escape_target.accelerator_count(), 1); | 1400 EXPECT_EQ(escape_target.accelerator_count(), 1); |
1401 } | 1401 } |
1402 | 1402 |
1403 // Unregisters itself when its accelerator is invoked. | 1403 // Unregisters itself when its accelerator is invoked. |
1404 class SelfUnregisteringAcceleratorTarget : public AcceleratorTarget { | 1404 class SelfUnregisteringAcceleratorTarget : public ui::AcceleratorTarget { |
1405 public: | 1405 public: |
1406 SelfUnregisteringAcceleratorTarget(Accelerator accelerator, | 1406 SelfUnregisteringAcceleratorTarget(Accelerator accelerator, |
1407 FocusManager* focus_manager) | 1407 FocusManager* focus_manager) |
1408 : accelerator_(accelerator), | 1408 : accelerator_(accelerator), |
1409 focus_manager_(focus_manager), | 1409 focus_manager_(focus_manager), |
1410 accelerator_count_(0) { | 1410 accelerator_count_(0) { |
1411 } | 1411 } |
1412 | 1412 |
1413 virtual bool AcceleratorPressed(const Accelerator& accelerator) { | 1413 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { |
1414 ++accelerator_count_; | 1414 ++accelerator_count_; |
1415 focus_manager_->UnregisterAccelerator(accelerator, this); | 1415 focus_manager_->UnregisterAccelerator(accelerator, this); |
1416 return true; | 1416 return true; |
1417 } | 1417 } |
1418 | 1418 |
1419 int accelerator_count() const { return accelerator_count_; } | 1419 int accelerator_count() const { return accelerator_count_; } |
1420 | 1420 |
1421 private: | 1421 private: |
1422 Accelerator accelerator_; | 1422 Accelerator accelerator_; |
1423 FocusManager* focus_manager_; | 1423 FocusManager* focus_manager_; |
(...skipping 327 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 |