~michael-sheldon/oxide/fix-1384357

« back to all changes in this revision

Viewing changes to shared/browser/oxide_touch_event_state.h

  • Committer: Chris Coulson
  • Date: 2015-05-14 15:37:57 UTC
  • Revision ID: chris.coulson@canonical.com-20150514153757-k03j3agy5oi2rxt2
Move gesture detection to RWHV, keep MotionEvent tracking on WebView (so that we keep it in sync with incoming touch events), and reset the gesture pipeline when navigating to a new page

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim:expandtab:shiftwidth=2:tabstop=2:
 
2
// Copyright (C) 2014-2015 Canonical Ltd.
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
#ifndef _OXIDE_SHARED_BROWSER_TOUCH_EVENT_STATE_H_
 
19
#define _OXIDE_SHARED_BROWSER_TOUCH_EVENT_STATE_H_
 
20
 
 
21
#include "base/macros.h"
 
22
#include "base/time/time.h"
 
23
#include "ui/events/gesture_detection/motion_event.h"
 
24
 
 
25
#include "shared/common/oxide_id_allocator.h"
 
26
 
 
27
namespace ui {
 
28
class TouchEvent;
 
29
}
 
30
 
 
31
namespace oxide {
 
32
 
 
33
// An implementation of MotionEvent that tracks incoming ui::TouchEvents
 
34
class TouchEventState : public ui::MotionEvent {
 
35
 public:
 
36
  TouchEventState();
 
37
  ~TouchEventState() override;
 
38
 
 
39
  bool Update(const ui::TouchEvent& event);
 
40
 
 
41
 private:
 
42
  static const size_t kMaxTouchPoints = ui::MotionEvent::MAX_TOUCH_POINT_COUNT;
 
43
 
 
44
  struct TouchPoint {
 
45
    TouchPoint();
 
46
 
 
47
    int platform_id;
 
48
    int id;
 
49
    float x;
 
50
    float y;
 
51
    float raw_x;
 
52
    float raw_y;
 
53
    float pressure;
 
54
    bool active;
 
55
  };
 
56
 
 
57
  bool IsTouchIdActive(int id) const;
 
58
  void RemoveInactiveTouchPoints();
 
59
 
 
60
  size_t GetIndexFromPlatformId(int id) const;
 
61
  bool HasPlatformId(int id) const;
 
62
 
 
63
  void AddTouchPoint(const ui::TouchEvent& event);
 
64
  void UpdateTouchPoint(const ui::TouchEvent& event);
 
65
  void UpdateAction(const ui::TouchEvent& event);
 
66
 
 
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;
 
94
 
 
95
  static TouchPoint CreateTouchPointFromEvent(const ui::TouchEvent& event);
 
96
 
 
97
  uint32_t unique_event_id_;
 
98
 
 
99
  size_t pointer_count_;
 
100
  size_t active_touch_point_count_;
 
101
  TouchPoint touch_points_[kMaxTouchPoints];
 
102
 
 
103
  IdAllocator id_allocator_;
 
104
 
 
105
  Action action_;
 
106
  int action_index_;
 
107
 
 
108
  int flags_;
 
109
 
 
110
  base::TimeTicks last_event_time_;
 
111
};
 
112
 
 
113
} // namespace oxide
 
114
 
 
115
#endif // _OXIDE_SHARED_BROWSER_TOUCH_EVENT_STATE_H_