Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / gestures / motion_event_aura.h
blob6f94ddbf2e8e4f3c3003ab8d7c8f358c18f2a7a6
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 #ifndef UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_H_
6 #define UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_H_
8 #include <map>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "ui/events/event.h"
13 #include "ui/events/events_export.h"
14 #include "ui/events/gesture_detection/motion_event.h"
16 namespace ui {
18 // Implementation of MotionEvent which takes a stream of ui::TouchEvents.
19 class EVENTS_EXPORT MotionEventAura : public MotionEvent {
20 public:
21 MotionEventAura();
22 virtual ~MotionEventAura();
24 void OnTouch(const TouchEvent& touch);
26 // MotionEvent implementation.
27 virtual int GetId() const OVERRIDE;
28 virtual Action GetAction() const OVERRIDE;
29 virtual int GetActionIndex() const OVERRIDE;
30 virtual size_t GetPointerCount() const OVERRIDE;
31 virtual int GetPointerId(size_t pointer_index) const OVERRIDE;
32 virtual float GetX(size_t pointer_index) const OVERRIDE;
33 virtual float GetY(size_t pointer_index) const OVERRIDE;
34 virtual float GetRawX(size_t pointer_index) const OVERRIDE;
35 virtual float GetRawY(size_t pointer_index) const OVERRIDE;
36 virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE;
37 virtual float GetPressure(size_t pointer_index) const OVERRIDE;
38 virtual ToolType GetToolType(size_t pointer_index) const OVERRIDE;
39 virtual int GetButtonState() const OVERRIDE;
40 virtual base::TimeTicks GetEventTime() const OVERRIDE;
42 virtual scoped_ptr<MotionEvent> Clone() const OVERRIDE;
43 virtual scoped_ptr<MotionEvent> Cancel() const OVERRIDE;
45 int GetSourceDeviceId(size_t pointer_index) const;
47 // We can't cleanup removed touch points immediately upon receipt of a
48 // TouchCancel or TouchRelease, as the MotionEvent needs to be able to report
49 // information about those touch events. Once the MotionEvent has been
50 // processed, we call CleanupRemovedTouchPoints to do the required
51 // book-keeping.
52 void CleanupRemovedTouchPoints(const TouchEvent& event);
54 private:
55 struct PointData {
56 PointData();
57 float x;
58 float y;
59 float raw_x;
60 float raw_y;
61 int touch_id;
62 float pressure;
63 int source_device_id;
64 float major_radius;
67 MotionEventAura(
68 size_t pointer_count,
69 const base::TimeTicks& last_touch_time,
70 Action cached_action,
71 int cached_action_index,
72 const PointData (&active_touches)[MotionEvent::MAX_TOUCH_POINT_COUNT]);
74 static PointData GetPointDataFromTouchEvent(const TouchEvent& touch);
75 void AddTouch(const TouchEvent& touch);
76 void UpdateTouch(const TouchEvent& touch);
77 void UpdateCachedAction(const TouchEvent& touch);
78 size_t GetIndexFromId(int id) const;
80 size_t pointer_count_;
81 base::TimeTicks last_touch_time_;
82 Action cached_action_;
83 // The index of the touch responsible for last ACTION_POINTER_DOWN or
84 // ACTION_POINTER_UP. -1 if no such action has occurred.
85 int cached_action_index_;
87 // We want constant time indexing by pointer_index, and fast indexing by id.
88 PointData active_touches_[MotionEvent::MAX_TOUCH_POINT_COUNT];
90 DISALLOW_COPY_AND_ASSIGN(MotionEventAura);
93 } // namespace ui
95 #endif // UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_H_