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