summaryrefslogtreecommitdiffstats
path: root/app/menus/accelerator_gtk.h
blob: ad74b4e8ab70b05851ee2cb7b80b5ca9f973866e (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
// Copyright (c) 2009 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.

#ifndef APP_MENUS_ACCELERATOR_GTK_H_
#define APP_MENUS_ACCELERATOR_GTK_H_

#include <gdk/gdk.h>

#include "app/menus/accelerator.h"
#include "base/keyboard_code_conversion_gtk.h"
#include "base/keyboard_codes_posix.h"

namespace menus {

class AcceleratorGtk : public Accelerator {
 public:
  AcceleratorGtk(base::KeyboardCode key_code,
                 bool shift_pressed, bool ctrl_pressed, bool alt_pressed) {
    key_code_ = key_code;
    modifiers_ = 0;
    if (shift_pressed)
      modifiers_ |= GDK_SHIFT_MASK;
    if (ctrl_pressed)
      modifiers_ |= GDK_CONTROL_MASK;
    if (alt_pressed)
      modifiers_ |= GDK_MOD1_MASK;
  }

  AcceleratorGtk() { }
  virtual ~AcceleratorGtk() { }

  guint GetGdkKeyCode() {
    // The second parameter is false because accelerator keys are expressed in
    // terms of the non-shift-modified key.
    return base::GdkKeyCodeForWindowsKeyCode(GetKeyCode(), false);
  }

  GdkModifierType gdk_modifier_type() {
    return static_cast<GdkModifierType>(modifiers());
  }
};

}

#endif  // APP_MENUS_ACCELERATOR_GTK_H_