OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "ui/events/gestures/motion_event_aura.h" | 8 #include "ui/events/gestures/motion_event_aura.h" |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 MotionEventAura::MotionEventAura() { | 65 MotionEventAura::MotionEventAura() { |
66 set_action_index(-1); | 66 set_action_index(-1); |
67 } | 67 } |
68 | 68 |
69 MotionEventAura::~MotionEventAura() { | 69 MotionEventAura::~MotionEventAura() { |
70 } | 70 } |
71 | 71 |
72 void MotionEventAura::OnTouch(const TouchEvent& touch) { | 72 bool MotionEventAura::OnTouch(const TouchEvent& touch) { |
| 73 int index = FindPointerIndexOfId(touch.touch_id()); |
| 74 bool pointer_id_is_active = index != -1; |
| 75 |
| 76 if (touch.type() == ET_TOUCH_PRESSED && pointer_id_is_active) { |
| 77 // Ignore touch press events if we already believe the pointer is down. |
| 78 |
| 79 // TODO(tdresser): this should return false (or NOTREACHED()); |
| 80 // however, there is at least one case where we need to allow a |
| 81 // touch press from a currently used touch id. See |
| 82 // crbug.com/446852 for details. |
| 83 } else if (touch.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) { |
| 84 // We could have an active touch stream transfered to us, resulting in touch |
| 85 // move or touch up events without associated touch down events. Ignore |
| 86 // them. |
| 87 return false; |
| 88 } |
| 89 |
| 90 if (touch.type() == ET_TOUCH_MOVED && touch.x() == GetX(index) && |
| 91 touch.y() == GetY(index)) { |
| 92 return false; |
| 93 } |
| 94 |
73 switch (touch.type()) { | 95 switch (touch.type()) { |
74 case ET_TOUCH_PRESSED: | 96 case ET_TOUCH_PRESSED: |
75 AddTouch(touch); | 97 AddTouch(touch); |
76 break; | 98 break; |
77 case ET_TOUCH_RELEASED: | 99 case ET_TOUCH_RELEASED: |
78 case ET_TOUCH_CANCELLED: | 100 case ET_TOUCH_CANCELLED: |
79 // Removing these touch points needs to be postponed until after the | 101 // Removing these touch points needs to be postponed until after the |
80 // MotionEvent has been dispatched. This cleanup occurs in | 102 // MotionEvent has been dispatched. This cleanup occurs in |
81 // CleanupRemovedTouchPoints. | 103 // CleanupRemovedTouchPoints. |
82 UpdateTouch(touch); | 104 UpdateTouch(touch); |
83 break; | 105 break; |
84 case ET_TOUCH_MOVED: | 106 case ET_TOUCH_MOVED: |
85 UpdateTouch(touch); | 107 UpdateTouch(touch); |
86 break; | 108 break; |
87 default: | 109 default: |
88 NOTREACHED(); | 110 NOTREACHED(); |
89 break; | 111 return false; |
90 } | 112 } |
91 | 113 |
92 UpdateCachedAction(touch); | 114 UpdateCachedAction(touch); |
93 set_flags(touch.flags()); | 115 set_flags(touch.flags()); |
94 set_event_time(touch.time_stamp() + base::TimeTicks()); | 116 set_event_time(touch.time_stamp() + base::TimeTicks()); |
| 117 return true; |
95 } | 118 } |
96 | 119 |
97 int MotionEventAura::GetId() const { | 120 int MotionEventAura::GetId() const { |
98 return GetPointerId(0); | 121 return GetPointerId(0); |
99 } | 122 } |
100 | 123 |
101 void MotionEventAura::CleanupRemovedTouchPoints(const TouchEvent& event) { | 124 void MotionEventAura::CleanupRemovedTouchPoints(const TouchEvent& event) { |
102 if (event.type() != ET_TOUCH_RELEASED && | 125 if (event.type() != ET_TOUCH_RELEASED && |
103 event.type() != ET_TOUCH_CANCELLED) { | 126 event.type() != ET_TOUCH_CANCELLED) { |
104 return; | 127 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 183 } |
161 | 184 |
162 int MotionEventAura::GetIndexFromId(int id) const { | 185 int MotionEventAura::GetIndexFromId(int id) const { |
163 int index = FindPointerIndexOfId(id); | 186 int index = FindPointerIndexOfId(id); |
164 DCHECK_GE(index, 0); | 187 DCHECK_GE(index, 0); |
165 DCHECK_LT(index, static_cast<int>(GetPointerCount())); | 188 DCHECK_LT(index, static_cast<int>(GetPointerCount())); |
166 return index; | 189 return index; |
167 } | 190 } |
168 | 191 |
169 } // namespace ui | 192 } // namespace ui |
OLD | NEW |