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.
4
5#ifndef UI_EVENTS_DEVICE_DATA_MANAGER_H_
6#define UI_EVENTS_DEVICE_DATA_MANAGER_H_
7
8#include <stdint.h>
9
10#include <vector>
11
12#include "base/macros.h"
13#include "base/memory/scoped_ptr.h"
14#include "base/observer_list.h"
15#include "ui/events/device_hotplug_event_observer.h"
16#include "ui/events/events_base_export.h"
17#include "ui/events/touchscreen_device.h"
18#include "ui/gfx/transform.h"
19
20namespace ui {
21
22class InputDeviceEventObserver;
23
24// Keeps track of device mappings and event transformations.
25class EVENTS_BASE_EXPORT DeviceDataManager : public DeviceHotplugEventObserver {
26 public:
27  virtual ~DeviceDataManager();
28
29  static void CreateInstance();
30  static DeviceDataManager* GetInstance();
31  static bool HasInstance();
32
33  void ClearTouchTransformerRecord();
34  void UpdateTouchInfoForDisplay(int64_t display_id,
35                                 int touch_device_id,
36                                 const gfx::Transform& touch_transformer);
37  void ApplyTouchTransformer(int touch_device_id, float* x, float* y);
38  int64_t GetDisplayForTouchDevice(int touch_device_id) const;
39
40  void UpdateTouchRadiusScale(int touch_device_id, double scale);
41  void ApplyTouchRadiusScale(int touch_device_id, double* radius);
42
43  const std::vector<TouchscreenDevice>& touchscreen_devices() const {
44    return touchscreen_devices_;
45  }
46
47  void AddObserver(InputDeviceEventObserver* observer);
48  void RemoveObserver(InputDeviceEventObserver* observer);
49
50 protected:
51  DeviceDataManager();
52
53  static DeviceDataManager* instance();
54
55  static const int kMaxDeviceNum = 128;
56
57 private:
58  static DeviceDataManager* instance_;
59
60  bool IsTouchDeviceIdValid(int touch_device_id) const;
61
62  // DeviceHotplugEventObserver:
63  virtual void OnTouchscreenDevicesUpdated(
64      const std::vector<TouchscreenDevice>& devices) OVERRIDE;
65
66  double touch_radius_scale_map_[kMaxDeviceNum];
67
68  // Table to keep track of which display id is mapped to which touch device.
69  int64_t touch_device_to_display_map_[kMaxDeviceNum];
70  // Index table to find the TouchTransformer for a touch device.
71  gfx::Transform touch_device_transformer_map_[kMaxDeviceNum];
72
73  std::vector<TouchscreenDevice> touchscreen_devices_;
74
75  ObserverList<InputDeviceEventObserver> observers_;
76
77  DISALLOW_COPY_AND_ASSIGN(DeviceDataManager);
78};
79
80}  // namespace ui
81
82#endif  // UI_EVENTS_DEVICE_DATA_MANAGER_H_
83