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_dispatcher.h" | 5 #include "ui/wm/core/nested_accelerator_dispatcher.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_pump_dispatcher.h" | 8 #include "base/message_loop/message_pump_dispatcher.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "ui/base/accelerators/accelerator.h" |
10 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
| 12 #include "ui/wm/core/accelerator_filter.h" |
11 #include "ui/wm/core/nested_accelerator_delegate.h" | 13 #include "ui/wm/core/nested_accelerator_delegate.h" |
12 | 14 |
13 using base::MessagePumpDispatcher; | 15 using base::MessagePumpDispatcher; |
14 | 16 |
15 namespace wm { | 17 namespace wm { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 bool IsKeyEvent(const MSG& msg) { | 21 bool IsKeyEvent(const MSG& msg) { |
20 return msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN || | 22 return msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN || |
(...skipping 13 matching lines...) Expand all Loading... |
34 private: | 36 private: |
35 // NestedAcceleratorDispatcher: | 37 // NestedAcceleratorDispatcher: |
36 virtual scoped_ptr<base::RunLoop> CreateRunLoop() OVERRIDE { | 38 virtual scoped_ptr<base::RunLoop> CreateRunLoop() OVERRIDE { |
37 return scoped_ptr<base::RunLoop>(new base::RunLoop(this)); | 39 return scoped_ptr<base::RunLoop>(new base::RunLoop(this)); |
38 } | 40 } |
39 | 41 |
40 // MessagePumpDispatcher: | 42 // MessagePumpDispatcher: |
41 virtual uint32_t Dispatch(const MSG& event) OVERRIDE { | 43 virtual uint32_t Dispatch(const MSG& event) OVERRIDE { |
42 if (IsKeyEvent(event)) { | 44 if (IsKeyEvent(event)) { |
43 ui::KeyEvent key_event(event, false); | 45 ui::KeyEvent key_event(event, false); |
44 if (!delegate_->ShouldProcessEventNow(key_event)) | 46 ui::Accelerator accelerator = CreateAcceleratorFromKeyEvent(key_event); |
45 return POST_DISPATCH_QUIT_LOOP; | |
46 | 47 |
47 if (delegate_->ProcessEvent(key_event)) | 48 switch (delegate_->ProcessAccelerator(accelerator)) { |
48 return POST_DISPATCH_NONE; | 49 case NestedAcceleratorDelegate::RESULT_PROCESS_LATER: |
| 50 return POST_DISPATCH_QUIT_LOOP; |
| 51 case NestedAcceleratorDelegate::RESULT_PROCESSED: |
| 52 return POST_DISPATCH_NONE; |
| 53 case NestedAcceleratorDelegate::RESULT_NOT_PROCESSED: |
| 54 break; |
| 55 } |
49 } | 56 } |
50 | 57 |
51 return nested_dispatcher_ ? nested_dispatcher_->Dispatch(event) | 58 return nested_dispatcher_ ? nested_dispatcher_->Dispatch(event) |
52 : POST_DISPATCH_PERFORM_DEFAULT; | 59 : POST_DISPATCH_PERFORM_DEFAULT; |
53 } | 60 } |
54 | 61 |
55 MessagePumpDispatcher* nested_dispatcher_; | 62 MessagePumpDispatcher* nested_dispatcher_; |
56 | 63 |
57 DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDispatcherWin); | 64 DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDispatcherWin); |
58 }; | 65 }; |
59 | 66 |
60 scoped_ptr<NestedAcceleratorDispatcher> NestedAcceleratorDispatcher::Create( | 67 scoped_ptr<NestedAcceleratorDispatcher> NestedAcceleratorDispatcher::Create( |
61 NestedAcceleratorDelegate* delegate, | 68 NestedAcceleratorDelegate* delegate, |
62 MessagePumpDispatcher* nested_dispatcher) { | 69 MessagePumpDispatcher* nested_dispatcher) { |
63 return scoped_ptr<NestedAcceleratorDispatcher>( | 70 return scoped_ptr<NestedAcceleratorDispatcher>( |
64 new NestedAcceleratorDispatcherWin(delegate, nested_dispatcher)); | 71 new NestedAcceleratorDispatcherWin(delegate, nested_dispatcher)); |
65 } | 72 } |
66 | 73 |
67 } // namespace wm | 74 } // namespace wm |
OLD | NEW |