Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_modifiers_evdev.cc
blobd867b5eef7d03b7204be4e906a8613eacbc7d1ce
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/events/ozone/evdev/event_modifiers_evdev.h"
7 #include <linux/input.h>
9 #include "ui/events/event.h"
11 namespace ui {
13 namespace {
15 static const int kEventFlagFromModifiers[] = {
16 EF_NONE, // EVDEV_MODIFIER_NONE,
17 EF_CAPS_LOCK_DOWN, // EVDEV_MODIFIER_CAPS_LOCK
18 EF_SHIFT_DOWN, // EVDEV_MODIFIER_SHIFT
19 EF_CONTROL_DOWN, // EVDEV_MODIFIER_CONTROL
20 EF_ALT_DOWN, // EVDEV_MODIFIER_ALT
21 EF_LEFT_MOUSE_BUTTON, // EVDEV_MODIFIER_LEFT_MOUSE_BUTTON
22 EF_MIDDLE_MOUSE_BUTTON, // EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON
23 EF_RIGHT_MOUSE_BUTTON, // EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON
24 EF_COMMAND_DOWN, // EVDEV_MODIFIER_COMMAND
25 EF_ALTGR_DOWN, // EVDEV_MODIFIER_ALTGR
28 } // namespace
30 EventModifiersEvdev::EventModifiersEvdev()
31 : modifier_flags_locked_(0), modifier_flags_(0) {
32 memset(modifiers_down_, 0, sizeof(modifiers_down_));
34 EventModifiersEvdev::~EventModifiersEvdev() {}
36 void EventModifiersEvdev::UpdateModifier(unsigned int modifier, bool down) {
37 CHECK_LT(modifier, EVDEV_NUM_MODIFIERS);
39 if (down) {
40 modifiers_down_[modifier]++;
41 } else {
42 // Ignore spurious modifier "up" events. This might happen if the
43 // button is down during startup.
44 if (modifiers_down_[modifier])
45 modifiers_down_[modifier]--;
48 UpdateFlags(modifier);
51 void EventModifiersEvdev::UpdateModifierLock(unsigned int modifier, bool down) {
52 CHECK_LT(modifier, EVDEV_NUM_MODIFIERS);
54 if (down)
55 modifier_flags_locked_ ^= kEventFlagFromModifiers[modifier];
57 // TODO(spang): Synchronize with the CapsLock LED.
59 UpdateFlags(modifier);
62 void EventModifiersEvdev::UpdateFlags(unsigned int modifier) {
63 int mask = kEventFlagFromModifiers[modifier];
64 bool down = modifiers_down_[modifier];
65 bool locked = (modifier_flags_locked_ & mask);
66 if (down != locked)
67 modifier_flags_ |= mask;
68 else
69 modifier_flags_ &= ~mask;
72 int EventModifiersEvdev::GetModifierFlags() { return modifier_flags_; }
74 // static
75 int EventModifiersEvdev::GetEventFlagFromModifier(unsigned int modifier) {
76 return kEventFlagFromModifiers[modifier];
79 } // namespace ui