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

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

Issue 2560633002: exo: Implement v6 of touch protocol including shape and frame event (Closed)
Patch Set: Fixed pen pointer mode conflict after 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
« no previous file with comments | « no previous file | components/exo/touch_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/wm_helper.h" 9 #include "components/exo/wm_helper.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
(...skipping 28 matching lines...) Expand all
39 delegate_->OnTouchDestroying(this); 39 delegate_->OnTouchDestroying(this);
40 if (focus_) 40 if (focus_)
41 focus_->RemoveSurfaceObserver(this); 41 focus_->RemoveSurfaceObserver(this);
42 WMHelper::GetInstance()->RemovePreTargetHandler(this); 42 WMHelper::GetInstance()->RemovePreTargetHandler(this);
43 } 43 }
44 44
45 //////////////////////////////////////////////////////////////////////////////// 45 ////////////////////////////////////////////////////////////////////////////////
46 // ui::EventHandler overrides: 46 // ui::EventHandler overrides:
47 47
48 void Touch::OnTouchEvent(ui::TouchEvent* event) { 48 void Touch::OnTouchEvent(ui::TouchEvent* event) {
49 bool send_details = false;
50
49 switch (event->type()) { 51 switch (event->type()) {
50 case ui::ET_TOUCH_PRESSED: { 52 case ui::ET_TOUCH_PRESSED: {
51 // Early out if event doesn't contain a valid target for touch device. 53 // Early out if event doesn't contain a valid target for touch device.
52 Surface* target = GetEffectiveTargetForEvent(event); 54 Surface* target = GetEffectiveTargetForEvent(event);
53 if (!target) 55 if (!target)
54 return; 56 return;
55 57
56 // If this is the first touch point then target becomes the focus surface 58 // If this is the first touch point then target becomes the focus surface
57 // until all touch points have been released. 59 // until all touch points have been released.
58 if (touch_points_.empty()) { 60 if (touch_points_.empty()) {
59 DCHECK(!focus_); 61 DCHECK(!focus_);
60 focus_ = target; 62 focus_ = target;
61 focus_->AddSurfaceObserver(this); 63 focus_->AddSurfaceObserver(this);
62 } 64 }
63 65
64 DCHECK(!VectorContainsItem(touch_points_, event->touch_id())); 66 DCHECK(!VectorContainsItem(touch_points_, event->touch_id()));
65 touch_points_.push_back(event->touch_id()); 67 touch_points_.push_back(event->touch_id());
66 68
67 // Convert location to focus surface coordinate space. 69 // Convert location to focus surface coordinate space.
68 DCHECK(focus_); 70 DCHECK(focus_);
69 gfx::Point location = event->location(); 71 gfx::Point location = event->location();
70 aura::Window::ConvertPointToTarget(target->window(), focus_->window(), 72 aura::Window::ConvertPointToTarget(target->window(), focus_->window(),
71 &location); 73 &location);
72 74
73 // Generate a touch down event for the focus surface. Note that this can 75 // Generate a touch down event for the focus surface. Note that this can
74 // be different from the target surface. 76 // be different from the target surface.
75 delegate_->OnTouchDown(focus_, event->time_stamp(), event->touch_id(), 77 delegate_->OnTouchDown(focus_, event->time_stamp(), event->touch_id(),
76 location); 78 location);
79 send_details = true;
77 } break; 80 } break;
78 case ui::ET_TOUCH_RELEASED: { 81 case ui::ET_TOUCH_RELEASED: {
79 auto it = FindVectorItem(touch_points_, event->touch_id()); 82 auto it = FindVectorItem(touch_points_, event->touch_id());
80 if (it != touch_points_.end()) { 83 if (it == touch_points_.end())
81 touch_points_.erase(it); 84 return;
85 touch_points_.erase(it);
82 86
83 // Reset focus surface if this is the last touch point. 87 // Reset focus surface if this is the last touch point.
84 if (touch_points_.empty()) { 88 if (touch_points_.empty()) {
85 DCHECK(focus_); 89 DCHECK(focus_);
86 focus_->RemoveSurfaceObserver(this); 90 focus_->RemoveSurfaceObserver(this);
87 focus_ = nullptr; 91 focus_ = nullptr;
88 } 92 }
89 93
90 delegate_->OnTouchUp(event->time_stamp(), event->touch_id()); 94 delegate_->OnTouchUp(event->time_stamp(), event->touch_id());
91 }
92 } break; 95 } break;
93 case ui::ET_TOUCH_MOVED: { 96 case ui::ET_TOUCH_MOVED: {
94 auto it = FindVectorItem(touch_points_, event->touch_id()); 97 auto it = FindVectorItem(touch_points_, event->touch_id());
95 if (it != touch_points_.end()) { 98 if (it == touch_points_.end())
96 DCHECK(focus_); 99 return;
97 // Convert location to focus surface coordinate space.
98 gfx::Point location = event->location();
99 aura::Window::ConvertPointToTarget(
100 static_cast<aura::Window*>(event->target()), focus_->window(),
101 &location);
102 100
103 delegate_->OnTouchMotion(event->time_stamp(), event->touch_id(), 101 DCHECK(focus_);
104 location); 102 // Convert location to focus surface coordinate space.
105 } 103 gfx::Point location = event->location();
104 aura::Window::ConvertPointToTarget(
105 static_cast<aura::Window*>(event->target()), focus_->window(),
106 &location);
107
108 delegate_->OnTouchMotion(event->time_stamp(), event->touch_id(),
109 location);
110 send_details = true;
106 } break; 111 } break;
107 case ui::ET_TOUCH_CANCELLED: { 112 case ui::ET_TOUCH_CANCELLED: {
108 auto it = FindVectorItem(touch_points_, event->touch_id()); 113 auto it = FindVectorItem(touch_points_, event->touch_id());
109 if (it != touch_points_.end()) { 114 if (it == touch_points_.end())
110 DCHECK(focus_); 115 return;
111 focus_->RemoveSurfaceObserver(this);
112 focus_ = nullptr;
113 116
114 // Cancel the full set of touch sequences as soon as one is canceled. 117 DCHECK(focus_);
115 touch_points_.clear(); 118 focus_->RemoveSurfaceObserver(this);
116 delegate_->OnTouchCancel(); 119 focus_ = nullptr;
117 } 120
121 // Cancel the full set of touch sequences as soon as one is canceled.
122 touch_points_.clear();
123 delegate_->OnTouchCancel();
118 } break; 124 } break;
119 default: 125 default:
120 NOTREACHED(); 126 NOTREACHED();
121 break; 127 return;
122 } 128 }
129 if (send_details) {
130 delegate_->OnTouchShape(event->touch_id(),
131 event->pointer_details().radius_x,
132 event->pointer_details().radius_y);
133 }
134 // TODO(denniskempin): Extend ui::TouchEvent to signal end of sequence of
135 // touch events to send TouchFrame once after all touches have been updated.
136 delegate_->OnTouchFrame();
123 } 137 }
124 138
125 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
126 // SurfaceObserver overrides: 140 // SurfaceObserver overrides:
127 141
128 void Touch::OnSurfaceDestroying(Surface* surface) { 142 void Touch::OnSurfaceDestroying(Surface* surface) {
129 DCHECK(surface == focus_); 143 DCHECK(surface == focus_);
130 focus_ = nullptr; 144 focus_ = nullptr;
131 surface->RemoveSurfaceObserver(this); 145 surface->RemoveSurfaceObserver(this);
132 146
133 // Cancel touch sequences. 147 // Cancel touch sequences.
134 DCHECK_NE(touch_points_.size(), 0u); 148 DCHECK_NE(touch_points_.size(), 0u);
135 touch_points_.clear(); 149 touch_points_.clear();
136 delegate_->OnTouchCancel(); 150 delegate_->OnTouchCancel();
137 } 151 }
138 152
139 //////////////////////////////////////////////////////////////////////////////// 153 ////////////////////////////////////////////////////////////////////////////////
140 // Touch, private: 154 // Touch, private:
141 155
142 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const { 156 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const {
143 Surface* target = 157 Surface* target =
144 Surface::AsSurface(static_cast<aura::Window*>(event->target())); 158 Surface::AsSurface(static_cast<aura::Window*>(event->target()));
145 if (!target) 159 if (!target)
146 return nullptr; 160 return nullptr;
147 161
148 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr; 162 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr;
149 } 163 }
150 164
151 } // namespace exo 165 } // namespace exo
OLDNEW
« no previous file with comments | « no previous file | components/exo/touch_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698