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

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

Issue 2562803002: exo: Replace pointer based stylus and replace with touch based stylus (Closed)
Patch Set: updated deps in gn file 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
« no previous file with comments | « components/exo/touch.h ('k') | components/exo/touch_stylus_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 16 matching lines...) Expand all
35 WMHelper::GetInstance()->AddPreTargetHandler(this); 36 WMHelper::GetInstance()->AddPreTargetHandler(this);
36 } 37 }
37 38
38 Touch::~Touch() { 39 Touch::~Touch() {
39 delegate_->OnTouchDestroying(this); 40 delegate_->OnTouchDestroying(this);
40 if (focus_) 41 if (focus_)
41 focus_->RemoveSurfaceObserver(this); 42 focus_->RemoveSurfaceObserver(this);
42 WMHelper::GetInstance()->RemovePreTargetHandler(this); 43 WMHelper::GetInstance()->RemovePreTargetHandler(this);
43 } 44 }
44 45
46 void Touch::SetStylusDelegate(TouchStylusDelegate* delegate) {
47 stylus_delegate_ = delegate;
48 }
49
50 bool Touch::HasStylusDelegate() const {
51 return !!stylus_delegate_;
52 }
53
45 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
46 // ui::EventHandler overrides: 55 // ui::EventHandler overrides:
47 56
48 void Touch::OnTouchEvent(ui::TouchEvent* event) { 57 void Touch::OnTouchEvent(ui::TouchEvent* event) {
49 bool send_details = false; 58 bool send_details = false;
50 59
51 switch (event->type()) { 60 switch (event->type()) {
52 case ui::ET_TOUCH_PRESSED: { 61 case ui::ET_TOUCH_PRESSED: {
53 // Early out if event doesn't contain a valid target for touch device. 62 // Early out if event doesn't contain a valid target for touch device.
54 Surface* target = GetEffectiveTargetForEvent(event); 63 Surface* target = GetEffectiveTargetForEvent(event);
(...skipping 14 matching lines...) Expand all
69 // Convert location to focus surface coordinate space. 78 // Convert location to focus surface coordinate space.
70 DCHECK(focus_); 79 DCHECK(focus_);
71 gfx::Point location = event->location(); 80 gfx::Point location = event->location();
72 aura::Window::ConvertPointToTarget(target->window(), focus_->window(), 81 aura::Window::ConvertPointToTarget(target->window(), focus_->window(),
73 &location); 82 &location);
74 83
75 // Generate a touch down event for the focus surface. Note that this can 84 // Generate a touch down event for the focus surface. Note that this can
76 // be different from the target surface. 85 // be different from the target surface.
77 delegate_->OnTouchDown(focus_, event->time_stamp(), event->touch_id(), 86 delegate_->OnTouchDown(focus_, event->time_stamp(), event->touch_id(),
78 location); 87 location);
88 if (stylus_delegate_ &&
89 event->pointer_details().pointer_type !=
90 ui::EventPointerType::POINTER_TYPE_TOUCH) {
91 stylus_delegate_->OnTouchTool(event->touch_id(),
92 event->pointer_details().pointer_type);
93 }
79 send_details = true; 94 send_details = true;
80 } break; 95 } break;
81 case ui::ET_TOUCH_RELEASED: { 96 case ui::ET_TOUCH_RELEASED: {
82 auto it = FindVectorItem(touch_points_, event->touch_id()); 97 auto it = FindVectorItem(touch_points_, event->touch_id());
83 if (it == touch_points_.end()) 98 if (it == touch_points_.end())
84 return; 99 return;
85 touch_points_.erase(it); 100 touch_points_.erase(it);
86 101
87 // Reset focus surface if this is the last touch point. 102 // Reset focus surface if this is the last touch point.
88 if (touch_points_.empty()) { 103 if (touch_points_.empty()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 delegate_->OnTouchCancel(); 138 delegate_->OnTouchCancel();
124 } break; 139 } break;
125 default: 140 default:
126 NOTREACHED(); 141 NOTREACHED();
127 return; 142 return;
128 } 143 }
129 if (send_details) { 144 if (send_details) {
130 delegate_->OnTouchShape(event->touch_id(), 145 delegate_->OnTouchShape(event->touch_id(),
131 event->pointer_details().radius_x, 146 event->pointer_details().radius_x,
132 event->pointer_details().radius_y); 147 event->pointer_details().radius_y);
148
149 if (stylus_delegate_ &&
150 event->pointer_details().pointer_type !=
151 ui::EventPointerType::POINTER_TYPE_TOUCH) {
152 if (!std::isnan(event->pointer_details().force)) {
153 stylus_delegate_->OnTouchForce(event->time_stamp(), event->touch_id(),
154 event->pointer_details().force);
155 }
156 stylus_delegate_->OnTouchTilt(
157 event->time_stamp(), event->touch_id(),
158 gfx::Vector2dF(event->pointer_details().tilt_x,
159 event->pointer_details().tilt_y));
160 }
133 } 161 }
134 // TODO(denniskempin): Extend ui::TouchEvent to signal end of sequence of 162 // TODO(denniskempin): Extend ui::TouchEvent to signal end of sequence of
135 // touch events to send TouchFrame once after all touches have been updated. 163 // touch events to send TouchFrame once after all touches have been updated.
136 delegate_->OnTouchFrame(); 164 delegate_->OnTouchFrame();
137 } 165 }
138 166
139 //////////////////////////////////////////////////////////////////////////////// 167 ////////////////////////////////////////////////////////////////////////////////
140 // SurfaceObserver overrides: 168 // SurfaceObserver overrides:
141 169
142 void Touch::OnSurfaceDestroying(Surface* surface) { 170 void Touch::OnSurfaceDestroying(Surface* surface) {
(...skipping 13 matching lines...) Expand all
156 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const { 184 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const {
157 Surface* target = 185 Surface* target =
158 Surface::AsSurface(static_cast<aura::Window*>(event->target())); 186 Surface::AsSurface(static_cast<aura::Window*>(event->target()));
159 if (!target) 187 if (!target)
160 return nullptr; 188 return nullptr;
161 189
162 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr; 190 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr;
163 } 191 }
164 192
165 } // namespace exo 193 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/touch.h ('k') | components/exo/touch_stylus_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698