1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
// Copyright (C) 2014-2015 Canonical Ltd.
4
// This library is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU Lesser General Public
6
// License as published by the Free Software Foundation; either
7
// version 2.1 of the License, or (at your option) any later version.
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// Lesser General Public License for more details.
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this library; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#ifndef _OXIDE_SHARED_BROWSER_TOUCH_EVENT_STATE_H_
19
#define _OXIDE_SHARED_BROWSER_TOUCH_EVENT_STATE_H_
21
#include "base/macros.h"
22
#include "base/time/time.h"
23
#include "ui/events/gesture_detection/motion_event.h"
25
#include "shared/common/oxide_id_allocator.h"
33
// An implementation of MotionEvent that tracks incoming ui::TouchEvents
34
class TouchEventState : public ui::MotionEvent {
37
~TouchEventState() override;
39
bool Update(const ui::TouchEvent& event);
42
static const size_t kMaxTouchPoints = ui::MotionEvent::MAX_TOUCH_POINT_COUNT;
57
bool IsTouchIdActive(int id) const;
58
void RemoveInactiveTouchPoints();
60
size_t GetIndexFromPlatformId(int id) const;
61
bool HasPlatformId(int id) const;
63
void AddTouchPoint(const ui::TouchEvent& event);
64
void UpdateTouchPoint(const ui::TouchEvent& event);
65
void UpdateAction(const ui::TouchEvent& event);
67
// ui::MotionEvent implementation
68
uint32_t GetUniqueEventId() const override;
69
Action GetAction() const override;
70
int GetActionIndex() const override;
71
size_t GetPointerCount() const override;
72
int GetPointerId(size_t pointer_index) const override;
73
float GetX(size_t pointer_index) const override;
74
float GetY(size_t pointer_index) const override;
75
float GetRawX(size_t pointer_index) const override;
76
float GetRawY(size_t pointer_index) const override;
77
float GetTouchMajor(size_t pointer_index) const override;
78
float GetTouchMinor(size_t pointer_index) const override;
79
float GetOrientation(size_t pointer_index) const override;
80
float GetPressure(size_t pointer_index) const override;
81
base::TimeTicks GetEventTime() const override;
82
size_t GetHistorySize() const override;
83
base::TimeTicks GetHistoricalEventTime(
84
size_t historical_index) const override;
85
float GetHistoricalTouchMajor(size_t pointer_index,
86
size_t historical_index) const override;
87
float GetHistoricalX(size_t pointer_index,
88
size_t historical_index) const override;
89
float GetHistoricalY(size_t pointer_index,
90
size_t historical_index) const override;
91
ToolType GetToolType(size_t pointer_index) const override;
92
int GetButtonState() const override;
93
int GetFlags() const override;
95
static TouchPoint CreateTouchPointFromEvent(const ui::TouchEvent& event);
97
uint32_t unique_event_id_;
99
size_t pointer_count_;
100
size_t active_touch_point_count_;
101
TouchPoint touch_points_[kMaxTouchPoints];
103
IdAllocator id_allocator_;
110
base::TimeTicks last_event_time_;
115
#endif // _OXIDE_SHARED_BROWSER_TOUCH_EVENT_STATE_H_