Home | History | Annotate | Download | only in evdev
      1 // Copyright 2013 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.
      4 
      5 #ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
      6 #define UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
      7 
      8 #include <bitset>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "ui/events/event_constants.h"
     12 #include "ui/events/events_export.h"
     13 #include "ui/events/ozone/event_converter_ozone.h"
     14 
     15 namespace ui {
     16 
     17 class TouchEvent;
     18 
     19 class EVENTS_EXPORT TouchEventConverterEvdev : public EventConverterOzone {
     20  public:
     21   enum {
     22     MAX_FINGERS = 11
     23   };
     24   TouchEventConverterEvdev(int fd, int id);
     25   virtual ~TouchEventConverterEvdev();
     26 
     27  private:
     28   friend class MockTouchEventConverterEvdev;
     29 
     30   // Unsafe part of initialization.
     31   void Init();
     32 
     33   // Overidden from base::MessagePumpLibevent::Watcher.
     34   virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
     35   virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
     36 
     37   // Pressure values.
     38   int pressure_min_;
     39   int pressure_max_;  // Used to normalize pressure values.
     40 
     41   // Touch scaling.
     42   float x_scale_;
     43   float y_scale_;
     44 
     45   // Maximum coordinate-values allowed for the events.
     46   int x_max_;
     47   int y_max_;
     48 
     49   // Touch point currently being updated from the /dev/input/event* stream.
     50   int current_slot_;
     51 
     52   // File descriptor for the /dev/input/event* instance.
     53   int fd_;
     54 
     55   // Number corresponding to * in the source evdev device: /dev/input/event*
     56   int id_;
     57 
     58   // Bit field tracking which in-progress touch points have been modified
     59   // without a syn event.
     60   std::bitset<MAX_FINGERS> altered_slots_;
     61 
     62   struct InProgressEvents {
     63     int x_;
     64     int y_;
     65     int id_;  // Device reported "unique" touch point id; -1 means not active
     66     int finger_;  // "Finger" id starting from 0; -1 means not active
     67 
     68     EventType type_;
     69     int major_;
     70     float pressure_;
     71   };
     72 
     73   // In-progress touch points.
     74   InProgressEvents events_[MAX_FINGERS];
     75 
     76   DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdev);
     77 };
     78 
     79 }  // namespace ui
     80 
     81 #endif  // UI_EVENTS_OZONE_EVDEV_TOUCH_EVENT_CONVERTER_EVDEV_H_
     82 
     83