OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/wm/core/nested_accelerator_controller.h" | 5 #include "ui/wm/core/nested_accelerator_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/event_types.h" | 8 #include "base/event_types.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 FROM_HERE, base::MessageLoop::current()->QuitClosure()); | 97 FROM_HERE, base::MessageLoop::current()->QuitClosure()); |
98 } | 98 } |
99 | 99 |
100 class MockNestedAcceleratorDelegate : public NestedAcceleratorDelegate { | 100 class MockNestedAcceleratorDelegate : public NestedAcceleratorDelegate { |
101 public: | 101 public: |
102 MockNestedAcceleratorDelegate() | 102 MockNestedAcceleratorDelegate() |
103 : accelerator_manager_(new ui::AcceleratorManager) {} | 103 : accelerator_manager_(new ui::AcceleratorManager) {} |
104 virtual ~MockNestedAcceleratorDelegate() {} | 104 virtual ~MockNestedAcceleratorDelegate() {} |
105 | 105 |
106 // NestedAcceleratorDelegate: | 106 // NestedAcceleratorDelegate: |
107 virtual bool ShouldProcessEventNow(const ui::KeyEvent& key_event) OVERRIDE { | 107 virtual Result ProcessAccelerator( |
108 return true; | 108 const ui::Accelerator& accelerator) OVERRIDE { |
109 } | 109 return accelerator_manager_->Process(accelerator) ? |
110 virtual bool ProcessEvent(const ui::KeyEvent& key_event) OVERRIDE { | 110 RESULT_PROCESSED : RESULT_NOT_PROCESSED; |
111 const int kModifierMask = | |
112 (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN); | |
113 ui::Accelerator accelerator(key_event.key_code(), | |
114 key_event.flags() & kModifierMask); | |
115 if (key_event.type() == ui::ET_KEY_RELEASED) | |
116 accelerator.set_type(ui::ET_KEY_RELEASED); | |
117 return accelerator_manager_->Process(accelerator); | |
118 } | 111 } |
119 | 112 |
120 void Register(const ui::Accelerator& accelerator, | 113 void Register(const ui::Accelerator& accelerator, |
121 ui::AcceleratorTarget* target) { | 114 ui::AcceleratorTarget* target) { |
122 accelerator_manager_->Register( | 115 accelerator_manager_->Register( |
123 accelerator, ui::AcceleratorManager::kNormalPriority, target); | 116 accelerator, ui::AcceleratorManager::kNormalPriority, target); |
124 } | 117 } |
125 | 118 |
126 private: | 119 private: |
127 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; | 120 scoped_ptr<ui::AcceleratorManager> accelerator_manager_; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 &inner_dispatcher); | 196 &inner_dispatcher); |
204 aura::client::DispatcherRunLoop run_loop( | 197 aura::client::DispatcherRunLoop run_loop( |
205 aura::client::GetDispatcherClient(root_window()), NULL); | 198 aura::client::GetDispatcherClient(root_window()), NULL); |
206 run_loop.Run(); | 199 run_loop.Run(); |
207 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); | 200 EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched()); |
208 EXPECT_EQ(1, target.accelerator_pressed_count()); | 201 EXPECT_EQ(1, target.accelerator_pressed_count()); |
209 } | 202 } |
210 | 203 |
211 } // namespace test | 204 } // namespace test |
212 } // namespace wm | 205 } // namespace wm |
OLD | NEW |