15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef UI_EVENTS_OZONE_EVDEV_EVENT_MODIFIERS_EVDEV_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define UI_EVENTS_OZONE_EVDEV_EVENT_MODIFIERS_EVDEV_H_
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/basictypes.h"
9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace ui {
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)enum {
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_NONE,
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_CAPS_LOCK,
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_SHIFT,
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_CONTROL,
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_ALT,
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_LEFT_MOUSE_BUTTON,
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON,
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON,
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_COMMAND,
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_MODIFIER_ALTGR,
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EVDEV_NUM_MODIFIERS
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Modifier key state for Evdev.
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Chrome relies on the underlying OS to interpret modifier keys such as Shift,
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Ctrl, and Alt. The Linux input subsystem does not assign any special meaning
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// to these keys, so this work must happen at a higher layer (normally X11 or
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// the console driver). When using evdev directly, we must do it ourselves.
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The modifier state is shared between all input devices connected to the
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// system. This is to support actions such as Shift-Clicking that use multiple
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// devices.
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Normally a modifier is set if any of the keys or buttons assigned to it are
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// currently pressed. However some keys toggle a persistent "lock" for the
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// modifier instead, such as CapsLock. If a modifier is "locked" then its state
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// is inverted until it is unlocked.
42cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class EVENTS_OZONE_EVDEV_EXPORT EventModifiersEvdev {
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EventModifiersEvdev();
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ~EventModifiersEvdev();
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Record key press or release for regular modifier key (shift, alt, etc).
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void UpdateModifier(unsigned int modifier, bool down);
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Record key press or release for locking modifier key (caps lock).
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void UpdateModifierLock(unsigned int modifier, bool down);
521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Return current flags to use for incoming events.
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  int GetModifierFlags();
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Return the mask for the specified modifier.
570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  static int GetEventFlagFromModifier(unsigned int modifier);
580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Count of keys pressed for each modifier.
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  int modifiers_down_[EVDEV_NUM_MODIFIERS];
621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Mask of modifier flags currently "locked".
641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  int modifier_flags_locked_;
651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Mask of modifier flags currently active (nonzero keys pressed xor locked).
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  int modifier_flags_;
681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Update modifier_flags_ from modifiers_down_ and modifier_flags_locked_.
701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void UpdateFlags(unsigned int modifier);
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(EventModifiersEvdev);
731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namspace ui
761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // UI_EVENTS_OZONE_EVDEV_EVENT_MODIFIERS_EVDEV_H_
78