Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / wm / core / nested_accelerator_dispatcher_win.cc
bloba8defb16074de8441e8da532e35da6bc2384ca2f
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.
5 #include "ui/wm/core/nested_accelerator_dispatcher.h"
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/base/accelerators/accelerator.h"
11 #include "ui/events/event.h"
12 #include "ui/wm/core/accelerator_filter.h"
13 #include "ui/wm/core/nested_accelerator_delegate.h"
15 using base::MessagePumpDispatcher;
17 namespace wm {
19 namespace {
21 bool IsKeyEvent(const MSG& msg) {
22 return msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN ||
23 msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP;
26 } // namespace
28 class NestedAcceleratorDispatcherWin : public NestedAcceleratorDispatcher,
29 public MessagePumpDispatcher {
30 public:
31 NestedAcceleratorDispatcherWin(NestedAcceleratorDelegate* delegate,
32 MessagePumpDispatcher* nested)
33 : NestedAcceleratorDispatcher(delegate), nested_dispatcher_(nested) {}
34 ~NestedAcceleratorDispatcherWin() override {}
36 private:
37 // NestedAcceleratorDispatcher:
38 scoped_ptr<base::RunLoop> CreateRunLoop() override {
39 return make_scoped_ptr(new base::RunLoop(this));
42 // MessagePumpDispatcher:
43 uint32_t Dispatch(const MSG& event) override {
44 if (IsKeyEvent(event)) {
45 ui::Accelerator accelerator((ui::KeyEvent(event)));
47 switch (delegate_->ProcessAccelerator(accelerator)) {
48 case NestedAcceleratorDelegate::RESULT_PROCESS_LATER:
49 return POST_DISPATCH_QUIT_LOOP;
50 case NestedAcceleratorDelegate::RESULT_PROCESSED:
51 return POST_DISPATCH_NONE;
52 case NestedAcceleratorDelegate::RESULT_NOT_PROCESSED:
53 break;
57 return nested_dispatcher_ ? nested_dispatcher_->Dispatch(event)
58 : POST_DISPATCH_PERFORM_DEFAULT;
61 MessagePumpDispatcher* nested_dispatcher_;
63 DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDispatcherWin);
66 scoped_ptr<NestedAcceleratorDispatcher> NestedAcceleratorDispatcher::Create(
67 NestedAcceleratorDelegate* delegate,
68 MessagePumpDispatcher* nested_dispatcher) {
69 return make_scoped_ptr(
70 new NestedAcceleratorDispatcherWin(delegate, nested_dispatcher));
73 } // namespace wm