Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_modifiers_evdev.cc
blob566623d18ec80f8823815f188a376df8d57bcf40
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_BACK_MOUSE_BUTTON, // EVDEV_MODIFIER_BACK_MOUSE_BUTTON
25 EF_FORWARD_MOUSE_BUTTON, // EVDEV_MODIFIER_FORWARD_MOUSE_BUTTON
26 EF_COMMAND_DOWN, // EVDEV_MODIFIER_COMMAND
27 EF_ALTGR_DOWN, // EVDEV_MODIFIER_ALTGR
28 EF_MOD3_DOWN, // EVDEV_MODIFIER_MOD3
31 } // namespace
33 EventModifiersEvdev::EventModifiersEvdev()
34 : modifier_flags_locked_(0), modifier_flags_(0) {
35 memset(modifiers_down_, 0, sizeof(modifiers_down_));
37 EventModifiersEvdev::~EventModifiersEvdev() {}
39 void EventModifiersEvdev::UpdateModifier(unsigned int modifier, bool down) {
40 DCHECK_LT(modifier, EVDEV_NUM_MODIFIERS);
42 if (down) {
43 modifiers_down_[modifier]++;
44 } else {
45 // Ignore spurious modifier "up" events. This might happen if the
46 // button is down during startup.
47 if (modifiers_down_[modifier])
48 modifiers_down_[modifier]--;
51 UpdateFlags(modifier);
54 void EventModifiersEvdev::UpdateModifierLock(unsigned int modifier, bool down) {
55 DCHECK_LT(modifier, EVDEV_NUM_MODIFIERS);
57 if (down)
58 modifier_flags_locked_ ^= kEventFlagFromModifiers[modifier];
60 UpdateFlags(modifier);
63 void EventModifiersEvdev::SetModifierLock(unsigned int modifier, bool locked) {
64 DCHECK_LT(modifier, EVDEV_NUM_MODIFIERS);
66 if (locked)
67 modifier_flags_locked_ |= kEventFlagFromModifiers[modifier];
68 else
69 modifier_flags_locked_ &= ~kEventFlagFromModifiers[modifier];
71 UpdateFlags(modifier);
74 void EventModifiersEvdev::UpdateFlags(unsigned int modifier) {
75 int mask = kEventFlagFromModifiers[modifier];
76 bool down = modifiers_down_[modifier];
77 bool locked = (modifier_flags_locked_ & mask);
78 if (down != locked)
79 modifier_flags_ |= mask;
80 else
81 modifier_flags_ &= ~mask;
84 int EventModifiersEvdev::GetModifierFlags() { return modifier_flags_; }
86 // static
87 int EventModifiersEvdev::GetEventFlagFromModifier(unsigned int modifier) {
88 return kEventFlagFromModifiers[modifier];
91 } // namespace ui