| 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 "ash/accelerators/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/events/event.h" | 10 #include "ui/events/event.h" |
| 11 #include "ui/wm/core/nested_accelerator_delegate.h" |
| 11 | 12 |
| 12 using base::MessagePumpDispatcher; | 13 using base::MessagePumpDispatcher; |
| 13 | 14 |
| 14 namespace ash { | 15 namespace wm { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 bool IsKeyEvent(const MSG& msg) { | 19 bool IsKeyEvent(const MSG& msg) { |
| 19 return msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN || | 20 return msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN || |
| 20 msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP; | 21 msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP; |
| 21 } | 22 } |
| 22 | 23 |
| 23 } // namespace | 24 } // namespace |
| 24 | 25 |
| 25 class AcceleratorDispatcherWin : public AcceleratorDispatcher, | 26 class NestedAcceleratorDispatcherWin : public NestedAcceleratorDispatcher, |
| 26 public MessagePumpDispatcher { | 27 public MessagePumpDispatcher { |
| 27 public: | 28 public: |
| 28 explicit AcceleratorDispatcherWin(MessagePumpDispatcher* nested) | 29 NestedAcceleratorDispatcherWin(NestedAcceleratorDelegate* delegate, |
| 29 : nested_dispatcher_(nested) {} | 30 MessagePumpDispatcher* nested) |
| 30 virtual ~AcceleratorDispatcherWin() {} | 31 : NestedAcceleratorDispatcher(delegate), nested_dispatcher_(nested) {} |
| 32 virtual ~NestedAcceleratorDispatcherWin() {} |
| 31 | 33 |
| 32 private: | 34 private: |
| 33 // AcceleratorDispatcher: | 35 // NestedAcceleratorDispatcher: |
| 34 virtual scoped_ptr<base::RunLoop> CreateRunLoop() OVERRIDE { | 36 virtual scoped_ptr<base::RunLoop> CreateRunLoop() OVERRIDE { |
| 35 return scoped_ptr<base::RunLoop>(new base::RunLoop(this)); | 37 return scoped_ptr<base::RunLoop>(new base::RunLoop(this)); |
| 36 } | 38 } |
| 37 | 39 |
| 38 // MessagePumpDispatcher: | 40 // MessagePumpDispatcher: |
| 39 virtual uint32_t Dispatch(const MSG& event) OVERRIDE { | 41 virtual uint32_t Dispatch(const MSG& event) OVERRIDE { |
| 40 if (IsKeyEvent(event)) { | 42 if (IsKeyEvent(event)) { |
| 41 ui::KeyEvent key_event(event, false); | 43 ui::KeyEvent key_event(event, false); |
| 42 if (MenuClosedForPossibleAccelerator(key_event)) | 44 if (!delegate_->ShouldProcessEventNow(key_event)) |
| 43 return POST_DISPATCH_QUIT_LOOP; | 45 return POST_DISPATCH_QUIT_LOOP; |
| 44 | 46 |
| 45 if (AcceleratorProcessedForKeyEvent(key_event)) | 47 if (delegate_->ProcessEvent(key_event)) |
| 46 return POST_DISPATCH_NONE; | 48 return POST_DISPATCH_NONE; |
| 47 } | 49 } |
| 48 | 50 |
| 49 return nested_dispatcher_ ? nested_dispatcher_->Dispatch(event) | 51 return nested_dispatcher_ ? nested_dispatcher_->Dispatch(event) |
| 50 : POST_DISPATCH_PERFORM_DEFAULT; | 52 : POST_DISPATCH_PERFORM_DEFAULT; |
| 51 } | 53 } |
| 52 | 54 |
| 53 MessagePumpDispatcher* nested_dispatcher_; | 55 MessagePumpDispatcher* nested_dispatcher_; |
| 54 | 56 |
| 55 DISALLOW_COPY_AND_ASSIGN(AcceleratorDispatcherWin); | 57 DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDispatcherWin); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 scoped_ptr<AcceleratorDispatcher> AcceleratorDispatcher::Create( | 60 scoped_ptr<NestedAcceleratorDispatcher> NestedAcceleratorDispatcher::Create( |
| 61 NestedAcceleratorDelegate* delegate, |
| 59 MessagePumpDispatcher* nested_dispatcher) { | 62 MessagePumpDispatcher* nested_dispatcher) { |
| 60 return scoped_ptr<AcceleratorDispatcher>( | 63 return scoped_ptr<NestedAcceleratorDispatcher>( |
| 61 new AcceleratorDispatcherWin(nested_dispatcher)); | 64 new NestedAcceleratorDispatcherWin(delegate, nested_dispatcher)); |
| 62 } | 65 } |
| 63 | 66 |
| 64 } // namespace ash | 67 } // namespace wm |
| OLD | NEW |