summaryrefslogtreecommitdiffstats
path: root/ash/accelerators/accelerator_dispatcher_linux.cc
blob: 8403480f192077e960eb452ba1b9af0c0c85a54a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/accelerators/accelerator_dispatcher.h"

#include <X11/Xlib.h>

// Xlib defines RootWindow
#ifdef RootWindow
#undef RootWindow
#endif

#include "ash/accelerators/accelerator_controller.h"
#include "ash/shell.h"
#include "ui/aura/env.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/events.h"

namespace ash {

namespace {

const int kModifierMask = (ui::EF_SHIFT_DOWN |
                           ui::EF_CONTROL_DOWN |
                           ui::EF_ALT_DOWN);
}  // namespace

base::MessagePumpDispatcher::DispatchStatus AcceleratorDispatcher::Dispatch(
    XEvent* xev) {
  if (!associated_window_)
    return EVENT_QUIT;
  if (!ui::IsNoopEvent(xev) && !associated_window_->CanReceiveEvents())
    return aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev);

  if (xev->type == KeyPress) {
    ash::AcceleratorController* accelerator_controller =
        ash::Shell::GetInstance()->accelerator_controller();
    ui::Accelerator accelerator(ui::KeyboardCodeFromNative(xev),
                                ui::EventFlagsFromNative(xev) & kModifierMask);
    if (accelerator_controller && accelerator_controller->Process(accelerator))
      return EVENT_PROCESSED;
  }
  return nested_dispatcher_->Dispatch(xev);
}

}  // namespace ash