Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: components/exo/touch.cc

Issue 2655303004: Add id properties to PointerEvent (Closed)
Patch Set: pointer id Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "components/exo/touch.h" 5 #include "components/exo/touch.h"
6 6
7 #include "components/exo/surface.h" 7 #include "components/exo/surface.h"
8 #include "components/exo/touch_delegate.h" 8 #include "components/exo/touch_delegate.h"
9 #include "components/exo/touch_stylus_delegate.h" 9 #include "components/exo/touch_stylus_delegate.h"
10 #include "components/exo/wm_helper.h" 10 #include "components/exo/wm_helper.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 bool Touch::HasStylusDelegate() const { 61 bool Touch::HasStylusDelegate() const {
62 return !!stylus_delegate_; 62 return !!stylus_delegate_;
63 } 63 }
64 64
65 //////////////////////////////////////////////////////////////////////////////// 65 ////////////////////////////////////////////////////////////////////////////////
66 // ui::EventHandler overrides: 66 // ui::EventHandler overrides:
67 67
68 void Touch::OnTouchEvent(ui::TouchEvent* event) { 68 void Touch::OnTouchEvent(ui::TouchEvent* event) {
69 bool send_details = false; 69 bool send_details = false;
70 70
71 int touch_pointer_id = event->pointer_details().id;
sadrul 2017/02/13 16:47:42 Make this const
lanwei 2017/02/13 21:50:28 Done.
71 switch (event->type()) { 72 switch (event->type()) {
72 case ui::ET_TOUCH_PRESSED: { 73 case ui::ET_TOUCH_PRESSED: {
73 // Early out if event doesn't contain a valid target for touch device. 74 // Early out if event doesn't contain a valid target for touch device.
74 Surface* target = GetEffectiveTargetForEvent(event); 75 Surface* target = GetEffectiveTargetForEvent(event);
75 if (!target) 76 if (!target)
76 return; 77 return;
77 78
78 // If this is the first touch point then target becomes the focus surface 79 // If this is the first touch point then target becomes the focus surface
79 // until all touch points have been released. 80 // until all touch points have been released.
80 if (touch_points_.empty()) { 81 if (touch_points_.empty()) {
81 DCHECK(!focus_); 82 DCHECK(!focus_);
82 focus_ = target; 83 focus_ = target;
83 focus_->AddSurfaceObserver(this); 84 focus_->AddSurfaceObserver(this);
84 } 85 }
85 86
86 DCHECK(!VectorContainsItem(touch_points_, event->touch_id())); 87 DCHECK(!VectorContainsItem(touch_points_, touch_pointer_id));
87 touch_points_.push_back(event->touch_id()); 88 touch_points_.push_back(touch_pointer_id);
88 89
89 // Convert location to focus surface coordinate space. 90 // Convert location to focus surface coordinate space.
90 DCHECK(focus_); 91 DCHECK(focus_);
91 gfx::PointF location = EventLocationInWindow(event, focus_->window()); 92 gfx::PointF location = EventLocationInWindow(event, focus_->window());
92 93
93 // Generate a touch down event for the focus surface. Note that this can 94 // Generate a touch down event for the focus surface. Note that this can
94 // be different from the target surface. 95 // be different from the target surface.
95 delegate_->OnTouchDown(focus_, event->time_stamp(), event->touch_id(), 96 delegate_->OnTouchDown(focus_, event->time_stamp(), touch_pointer_id,
96 location); 97 location);
97 if (stylus_delegate_ && 98 if (stylus_delegate_ &&
98 event->pointer_details().pointer_type != 99 event->pointer_details().pointer_type !=
99 ui::EventPointerType::POINTER_TYPE_TOUCH) { 100 ui::EventPointerType::POINTER_TYPE_TOUCH) {
100 stylus_delegate_->OnTouchTool(event->touch_id(), 101 stylus_delegate_->OnTouchTool(touch_pointer_id,
101 event->pointer_details().pointer_type); 102 event->pointer_details().pointer_type);
102 } 103 }
103 send_details = true; 104 send_details = true;
104 } break; 105 } break;
105 case ui::ET_TOUCH_RELEASED: { 106 case ui::ET_TOUCH_RELEASED: {
106 auto it = FindVectorItem(touch_points_, event->touch_id()); 107 auto it = FindVectorItem(touch_points_, touch_pointer_id);
107 if (it == touch_points_.end()) 108 if (it == touch_points_.end())
108 return; 109 return;
109 touch_points_.erase(it); 110 touch_points_.erase(it);
110 111
111 // Reset focus surface if this is the last touch point. 112 // Reset focus surface if this is the last touch point.
112 if (touch_points_.empty()) { 113 if (touch_points_.empty()) {
113 DCHECK(focus_); 114 DCHECK(focus_);
114 focus_->RemoveSurfaceObserver(this); 115 focus_->RemoveSurfaceObserver(this);
115 focus_ = nullptr; 116 focus_ = nullptr;
116 } 117 }
117 118
118 delegate_->OnTouchUp(event->time_stamp(), event->touch_id()); 119 delegate_->OnTouchUp(event->time_stamp(), touch_pointer_id);
119 } break; 120 } break;
120 case ui::ET_TOUCH_MOVED: { 121 case ui::ET_TOUCH_MOVED: {
121 auto it = FindVectorItem(touch_points_, event->touch_id()); 122 auto it = FindVectorItem(touch_points_, touch_pointer_id);
122 if (it == touch_points_.end()) 123 if (it == touch_points_.end())
123 return; 124 return;
124 125
125 DCHECK(focus_); 126 DCHECK(focus_);
126 // Convert location to focus surface coordinate space. 127 // Convert location to focus surface coordinate space.
127 gfx::PointF location = EventLocationInWindow(event, focus_->window()); 128 gfx::PointF location = EventLocationInWindow(event, focus_->window());
128 delegate_->OnTouchMotion(event->time_stamp(), event->touch_id(), 129 delegate_->OnTouchMotion(event->time_stamp(), touch_pointer_id, location);
129 location);
130 send_details = true; 130 send_details = true;
131 } break; 131 } break;
132 case ui::ET_TOUCH_CANCELLED: { 132 case ui::ET_TOUCH_CANCELLED: {
133 auto it = FindVectorItem(touch_points_, event->touch_id()); 133 auto it = FindVectorItem(touch_points_, touch_pointer_id);
134 if (it == touch_points_.end()) 134 if (it == touch_points_.end())
135 return; 135 return;
136 136
137 DCHECK(focus_); 137 DCHECK(focus_);
138 focus_->RemoveSurfaceObserver(this); 138 focus_->RemoveSurfaceObserver(this);
139 focus_ = nullptr; 139 focus_ = nullptr;
140 140
141 // Cancel the full set of touch sequences as soon as one is canceled. 141 // Cancel the full set of touch sequences as soon as one is canceled.
142 touch_points_.clear(); 142 touch_points_.clear();
143 delegate_->OnTouchCancel(); 143 delegate_->OnTouchCancel();
144 } break; 144 } break;
145 default: 145 default:
146 NOTREACHED(); 146 NOTREACHED();
147 return; 147 return;
148 } 148 }
149 if (send_details) { 149 if (send_details) {
150 delegate_->OnTouchShape(event->touch_id(), 150 delegate_->OnTouchShape(touch_pointer_id, event->pointer_details().radius_x,
151 event->pointer_details().radius_x,
152 event->pointer_details().radius_y); 151 event->pointer_details().radius_y);
153 152
154 if (stylus_delegate_ && 153 if (stylus_delegate_ &&
155 event->pointer_details().pointer_type != 154 event->pointer_details().pointer_type !=
156 ui::EventPointerType::POINTER_TYPE_TOUCH) { 155 ui::EventPointerType::POINTER_TYPE_TOUCH) {
157 if (!std::isnan(event->pointer_details().force)) { 156 if (!std::isnan(event->pointer_details().force)) {
158 stylus_delegate_->OnTouchForce(event->time_stamp(), event->touch_id(), 157 stylus_delegate_->OnTouchForce(event->time_stamp(), touch_pointer_id,
159 event->pointer_details().force); 158 event->pointer_details().force);
160 } 159 }
161 stylus_delegate_->OnTouchTilt( 160 stylus_delegate_->OnTouchTilt(
162 event->time_stamp(), event->touch_id(), 161 event->time_stamp(), touch_pointer_id,
163 gfx::Vector2dF(event->pointer_details().tilt_x, 162 gfx::Vector2dF(event->pointer_details().tilt_x,
164 event->pointer_details().tilt_y)); 163 event->pointer_details().tilt_y));
165 } 164 }
166 } 165 }
167 // TODO(denniskempin): Extend ui::TouchEvent to signal end of sequence of 166 // TODO(denniskempin): Extend ui::TouchEvent to signal end of sequence of
168 // touch events to send TouchFrame once after all touches have been updated. 167 // touch events to send TouchFrame once after all touches have been updated.
169 delegate_->OnTouchFrame(); 168 delegate_->OnTouchFrame();
170 } 169 }
171 170
172 //////////////////////////////////////////////////////////////////////////////// 171 ////////////////////////////////////////////////////////////////////////////////
(...skipping 16 matching lines...) Expand all
189 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const { 188 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const {
190 Surface* target = 189 Surface* target =
191 Surface::AsSurface(static_cast<aura::Window*>(event->target())); 190 Surface::AsSurface(static_cast<aura::Window*>(event->target()));
192 if (!target) 191 if (!target)
193 return nullptr; 192 return nullptr;
194 193
195 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr; 194 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr;
196 } 195 }
197 196
198 } // namespace exo 197 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698