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

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

Issue 2562803002: exo: Replace pointer based stylus and replace with touch based stylus (Closed)
Patch Set: rebase Created 4 years 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/wm_helper.h" 10 #include "components/exo/wm_helper.h"
10 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
11 #include "ui/events/event.h" 12 #include "ui/events/event.h"
12 13
13 namespace exo { 14 namespace exo {
14 namespace { 15 namespace {
15 16
16 // Helper function that returns an iterator to the first item in |vector| 17 // Helper function that returns an iterator to the first item in |vector|
17 // with |value|. 18 // with |value|.
18 template <typename T, typename U> 19 template <typename T, typename U>
19 typename T::iterator FindVectorItem(T& vector, U value) { 20 typename T::iterator FindVectorItem(T& vector, U value) {
20 return std::find(vector.begin(), vector.end(), value); 21 return std::find(vector.begin(), vector.end(), value);
21 } 22 }
22 23
23 // Helper function that returns true if |vector| contains an item with |value|. 24 // Helper function that returns true if |vector| contains an item with |value|.
24 template <typename T, typename U> 25 template <typename T, typename U>
25 bool VectorContainsItem(T& vector, U value) { 26 bool VectorContainsItem(T& vector, U value) {
26 return FindVectorItem(vector, value) != vector.end(); 27 return FindVectorItem(vector, value) != vector.end();
27 } 28 }
28 29
29 } // namespace 30 } // namespace
30 31
31 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
32 // Touch, public: 33 // Touch, public:
33 34
34 Touch::Touch(TouchDelegate* delegate) : delegate_(delegate) { 35 Touch::Touch(TouchDelegate* delegate)
36 : delegate_(delegate), stylus_delegate_(nullptr) {
reveman 2016/12/08 23:17:14 nit: unnecessary
denniskempin 2016/12/15 21:16:49 Done.
35 WMHelper::GetInstance()->AddPreTargetHandler(this); 37 WMHelper::GetInstance()->AddPreTargetHandler(this);
36 } 38 }
37 39
38 Touch::~Touch() { 40 Touch::~Touch() {
39 delegate_->OnTouchDestroying(this); 41 delegate_->OnTouchDestroying(this);
40 if (focus_) 42 if (focus_)
41 focus_->RemoveSurfaceObserver(this); 43 focus_->RemoveSurfaceObserver(this);
42 WMHelper::GetInstance()->RemovePreTargetHandler(this); 44 WMHelper::GetInstance()->RemovePreTargetHandler(this);
43 } 45 }
44 46
47 void Touch::SetStylusDelegate(TouchStylusDelegate* delegate) {
48 stylus_delegate_ = delegate;
49 }
50
45 //////////////////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////////////////
46 // ui::EventHandler overrides: 52 // ui::EventHandler overrides:
47 53
48 void Touch::OnTouchEvent(ui::TouchEvent* event) { 54 void Touch::OnTouchEvent(ui::TouchEvent* event) {
49 bool send_details = false; 55 bool send_details = false;
50 56
51 switch (event->type()) { 57 switch (event->type()) {
52 case ui::ET_TOUCH_PRESSED: { 58 case ui::ET_TOUCH_PRESSED: {
53 // Early out if event doesn't contain a valid target for touch device. 59 // Early out if event doesn't contain a valid target for touch device.
54 Surface* target = GetEffectiveTargetForEvent(event); 60 Surface* target = GetEffectiveTargetForEvent(event);
(...skipping 14 matching lines...) Expand all
69 // Convert location to focus surface coordinate space. 75 // Convert location to focus surface coordinate space.
70 DCHECK(focus_); 76 DCHECK(focus_);
71 gfx::Point location = event->location(); 77 gfx::Point location = event->location();
72 aura::Window::ConvertPointToTarget(target->window(), focus_->window(), 78 aura::Window::ConvertPointToTarget(target->window(), focus_->window(),
73 &location); 79 &location);
74 80
75 // Generate a touch down event for the focus surface. Note that this can 81 // Generate a touch down event for the focus surface. Note that this can
76 // be different from the target surface. 82 // be different from the target surface.
77 delegate_->OnTouchDown(focus_, event->time_stamp(), event->touch_id(), 83 delegate_->OnTouchDown(focus_, event->time_stamp(), event->touch_id(),
78 location); 84 location);
85 if (stylus_delegate_ &&
86 event->pointer_details().pointer_type !=
87 ui::EventPointerType::POINTER_TYPE_TOUCH) {
88 stylus_delegate_->OnTouchTool(event->touch_id(),
89 event->pointer_details().pointer_type);
90 }
79 send_details = true; 91 send_details = true;
80 } break; 92 } break;
81 case ui::ET_TOUCH_RELEASED: { 93 case ui::ET_TOUCH_RELEASED: {
82 auto it = FindVectorItem(touch_points_, event->touch_id()); 94 auto it = FindVectorItem(touch_points_, event->touch_id());
83 if (it == touch_points_.end()) 95 if (it == touch_points_.end())
84 return; 96 return;
85 touch_points_.erase(it); 97 touch_points_.erase(it);
86 98
87 // Reset focus surface if this is the last touch point. 99 // Reset focus surface if this is the last touch point.
88 if (touch_points_.empty()) { 100 if (touch_points_.empty()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 delegate_->OnTouchCancel(); 135 delegate_->OnTouchCancel();
124 } break; 136 } break;
125 default: 137 default:
126 NOTREACHED(); 138 NOTREACHED();
127 return; 139 return;
128 } 140 }
129 if (send_details) { 141 if (send_details) {
130 delegate_->OnTouchShape(event->touch_id(), 142 delegate_->OnTouchShape(event->touch_id(),
131 event->pointer_details().radius_x, 143 event->pointer_details().radius_x,
132 event->pointer_details().radius_y); 144 event->pointer_details().radius_y);
145
146 if (stylus_delegate_ &&
147 event->pointer_details().pointer_type !=
148 ui::EventPointerType::POINTER_TYPE_TOUCH) {
149 if (!std::isnan(event->pointer_details().force)) {
150 stylus_delegate_->OnTouchForce(event->time_stamp(), event->touch_id(),
151 event->pointer_details().force);
152 }
153 stylus_delegate_->OnTouchTilt(
154 event->time_stamp(), event->touch_id(),
155 gfx::Vector2dF(event->pointer_details().tilt_x,
156 event->pointer_details().tilt_y));
157 }
133 } 158 }
134 // TODO(denniskempin): Extend ui::TouchEvent to signal end of sequence of 159 // TODO(denniskempin): Extend ui::TouchEvent to signal end of sequence of
135 // touch events to send TouchFrame once after all touches have been updated. 160 // touch events to send TouchFrame once after all touches have been updated.
136 delegate_->OnTouchFrame(); 161 delegate_->OnTouchFrame();
137 } 162 }
138 163
139 //////////////////////////////////////////////////////////////////////////////// 164 ////////////////////////////////////////////////////////////////////////////////
140 // SurfaceObserver overrides: 165 // SurfaceObserver overrides:
141 166
142 void Touch::OnSurfaceDestroying(Surface* surface) { 167 void Touch::OnSurfaceDestroying(Surface* surface) {
(...skipping 13 matching lines...) Expand all
156 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const { 181 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const {
157 Surface* target = 182 Surface* target =
158 Surface::AsSurface(static_cast<aura::Window*>(event->target())); 183 Surface::AsSurface(static_cast<aura::Window*>(event->target()));
159 if (!target) 184 if (!target)
160 return nullptr; 185 return nullptr;
161 186
162 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr; 187 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr;
163 } 188 }
164 189
165 } // namespace exo 190 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698