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

Side by Side Diff: components/exo/pointer.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/pointer.h ('k') | components/exo/pointer_unittest.cc » ('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/pointer.h" 5 #include "components/exo/pointer.h"
6 6
7 #include "ash/public/cpp/shell_window_ids.h" 7 #include "ash/public/cpp/shell_window_ids.h"
8 #include "components/exo/pointer_delegate.h" 8 #include "components/exo/pointer_delegate.h"
9 #include "components/exo/pointer_stylus_delegate.h" 9 #include "components/exo/pointer_stylus_delegate.h"
10 #include "components/exo/surface.h" 10 #include "components/exo/surface.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 surface_(nullptr), 44 surface_(nullptr),
45 focus_(nullptr), 45 focus_(nullptr),
46 cursor_scale_(1.0f) { 46 cursor_scale_(1.0f) {
47 auto* helper = WMHelper::GetInstance(); 47 auto* helper = WMHelper::GetInstance();
48 helper->AddPreTargetHandler(this); 48 helper->AddPreTargetHandler(this);
49 helper->AddCursorObserver(this); 49 helper->AddCursorObserver(this);
50 } 50 }
51 51
52 Pointer::~Pointer() { 52 Pointer::~Pointer() {
53 delegate_->OnPointerDestroying(this); 53 delegate_->OnPointerDestroying(this);
54 if (stylus_delegate_)
55 stylus_delegate_->OnPointerDestroying(this);
56 if (surface_) 54 if (surface_)
57 surface_->RemoveSurfaceObserver(this); 55 surface_->RemoveSurfaceObserver(this);
58 if (focus_) { 56 if (focus_) {
59 focus_->RemoveSurfaceObserver(this); 57 focus_->RemoveSurfaceObserver(this);
60 focus_->UnregisterCursorProvider(this); 58 focus_->UnregisterCursorProvider(this);
61 } 59 }
62 if (widget_) 60 if (widget_)
63 widget_->CloseNow(); 61 widget_->CloseNow();
64 62
65 auto* helper = WMHelper::GetInstance(); 63 auto* helper = WMHelper::GetInstance();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // Update hotspot and show cursor surface if not already visible. 97 // Update hotspot and show cursor surface if not already visible.
100 hotspot_ = hotspot; 98 hotspot_ = hotspot;
101 if (surface_) { 99 if (surface_) {
102 surface_->window()->SetBounds( 100 surface_->window()->SetBounds(
103 gfx::Rect(gfx::Point() - hotspot_.OffsetFromOrigin(), 101 gfx::Rect(gfx::Point() - hotspot_.OffsetFromOrigin(),
104 surface_->window()->layer()->size())); 102 surface_->window()->layer()->size()));
105 if (!surface_->window()->IsVisible()) 103 if (!surface_->window()->IsVisible())
106 surface_->window()->Show(); 104 surface_->window()->Show();
107 105
108 // Show widget now that cursor has been defined. 106 // Show widget now that cursor has been defined.
109 if (!widget_->IsVisible() && !is_direct_input_) 107 if (!widget_->IsVisible())
110 widget_->Show(); 108 widget_->Show();
111 } 109 }
112 110
113 // Register pointer as cursor provider now that the cursor for |focus_| has 111 // Register pointer as cursor provider now that the cursor for |focus_| has
114 // been defined. 112 // been defined.
115 focus_->RegisterCursorProvider(this); 113 focus_->RegisterCursorProvider(this);
116 114
117 // Update cursor in case the registration of pointer as cursor provider 115 // Update cursor in case the registration of pointer as cursor provider
118 // caused the cursor to change. 116 // caused the cursor to change.
119 aura::client::CursorClient* cursor_client = 117 aura::client::CursorClient* cursor_client =
120 aura::client::GetCursorClient(focus_->window()->GetRootWindow()); 118 aura::client::GetCursorClient(focus_->window()->GetRootWindow());
121 if (cursor_client) 119 if (cursor_client)
122 cursor_client->SetCursor( 120 cursor_client->SetCursor(
123 focus_->window()->GetCursor(gfx::ToFlooredPoint(location_))); 121 focus_->window()->GetCursor(gfx::ToFlooredPoint(location_)));
124 } 122 }
125 123
126 bool Pointer::HasStylusDelegate() const {
127 return !!stylus_delegate_;
128 }
129
130 void Pointer::SetStylusDelegate(PointerStylusDelegate* delegate) {
131 stylus_delegate_ = delegate;
132 }
133
134 //////////////////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////////////////
135 // ui::EventHandler overrides: 125 // ui::EventHandler overrides:
136 126
137 void Pointer::OnMouseEvent(ui::MouseEvent* event) { 127 void Pointer::OnMouseEvent(ui::MouseEvent* event) {
138 Surface* target = GetEffectiveTargetForEvent(event); 128 Surface* target = GetEffectiveTargetForEvent(event);
139 129
140 if (event->flags() & ui::EF_TOUCH_ACCESSIBILITY) 130 if (event->flags() & ui::EF_TOUCH_ACCESSIBILITY)
141 return; 131 return;
142 132
143 auto new_pointer_type = pointer_type_;
144 if ((event->flags() & ui::EF_IS_SYNTHESIZED) == 0) {
145 new_pointer_type = event->pointer_details().pointer_type;
146 if (new_pointer_type == ui::EventPointerType::POINTER_TYPE_UNKNOWN)
147 new_pointer_type = ui::EventPointerType::POINTER_TYPE_MOUSE;
148 }
149
150 // If target is different than the current pointer focus then we need to 133 // If target is different than the current pointer focus then we need to
151 // generate enter and leave events. 134 // generate enter and leave events.
152 if (target != focus_) { 135 if (target != focus_) {
153 // First generate a leave event if we currently have a target in focus. 136 // First generate a leave event if we currently have a target in focus.
154 if (focus_) { 137 if (focus_) {
155 delegate_->OnPointerLeave(focus_); 138 delegate_->OnPointerLeave(focus_);
156 focus_->RemoveSurfaceObserver(this); 139 focus_->RemoveSurfaceObserver(this);
157 // Require SetCursor() to be called and cursor to be re-defined in 140 // Require SetCursor() to be called and cursor to be re-defined in
158 // response to each OnPointerEnter() call. 141 // response to each OnPointerEnter() call.
159 focus_->UnregisterCursorProvider(this); 142 focus_->UnregisterCursorProvider(this);
160 focus_ = nullptr; 143 focus_ = nullptr;
161 } 144 }
162 // Second generate an enter event if focus moved to a new target. 145 // Second generate an enter event if focus moved to a new target.
163 if (target) { 146 if (target) {
164 delegate_->OnPointerEnter(target, event->location_f(), 147 delegate_->OnPointerEnter(target, event->location_f(),
165 event->button_flags()); 148 event->button_flags());
166 location_ = event->location_f(); 149 location_ = event->location_f();
167 if (stylus_delegate_) {
168 stylus_delegate_->OnPointerToolChange(new_pointer_type);
169 pointer_type_ = new_pointer_type;
170 }
171
172 focus_ = target; 150 focus_ = target;
173 focus_->AddSurfaceObserver(this); 151 focus_->AddSurfaceObserver(this);
174 } 152 }
175 delegate_->OnPointerFrame(); 153 delegate_->OnPointerFrame();
176 } 154 }
177 155
178 // Report changes in pointer type.
179 if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) {
180 stylus_delegate_->OnPointerToolChange(new_pointer_type);
181 pointer_type_ = new_pointer_type;
182 }
183
184 if (focus_ && event->IsMouseEvent() && event->type() != ui::ET_MOUSE_EXITED) { 156 if (focus_ && event->IsMouseEvent() && event->type() != ui::ET_MOUSE_EXITED) {
185 bool send_frame = false;
186
187 // Generate motion event if location changed. We need to check location 157 // Generate motion event if location changed. We need to check location
188 // here as mouse movement can generate both "moved" and "entered" events 158 // here as mouse movement can generate both "moved" and "entered" events
189 // but OnPointerMotion should only be called if location changed since 159 // but OnPointerMotion should only be called if location changed since
190 // OnPointerEnter was called. 160 // OnPointerEnter was called.
191 if (!SameLocation(event, location_)) { 161 if (!SameLocation(event, location_)) {
192 location_ = event->location_f(); 162 location_ = event->location_f();
193 delegate_->OnPointerMotion(event->time_stamp(), location_); 163 delegate_->OnPointerMotion(event->time_stamp(), location_);
194 send_frame = true; 164 delegate_->OnPointerFrame();
195 } 165 }
196 if (stylus_delegate_ &&
197 pointer_type_ != ui::EventPointerType::POINTER_TYPE_MOUSE) {
198 constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
199 gfx::Vector2dF new_tilt = gfx::Vector2dF(event->pointer_details().tilt_x,
200 event->pointer_details().tilt_y);
201 if (std::abs(new_tilt.x() - tilt_.x()) > kEpsilon ||
202 std::abs(new_tilt.y() - tilt_.y()) > kEpsilon) {
203 tilt_ = new_tilt;
204 stylus_delegate_->OnPointerTilt(event->time_stamp(), new_tilt);
205 send_frame = true;
206 }
207
208 float new_force = event->pointer_details().force;
209 if (std::abs(new_force - force_) > kEpsilon) {
210 force_ = new_force;
211 stylus_delegate_->OnPointerForce(event->time_stamp(), new_force);
212 send_frame = true;
213 }
214 }
215 if (send_frame)
216 delegate_->OnPointerFrame();
217 } 166 }
218 167
219 switch (event->type()) { 168 switch (event->type()) {
220 case ui::ET_MOUSE_PRESSED: 169 case ui::ET_MOUSE_PRESSED:
221 case ui::ET_MOUSE_RELEASED: 170 case ui::ET_MOUSE_RELEASED:
222 if (focus_) { 171 if (focus_) {
223 delegate_->OnPointerButton(event->time_stamp(), 172 delegate_->OnPointerButton(event->time_stamp(),
224 event->changed_button_flags(), 173 event->changed_button_flags(),
225 event->type() == ui::ET_MOUSE_PRESSED); 174 event->type() == ui::ET_MOUSE_PRESSED);
226 delegate_->OnPointerFrame(); 175 delegate_->OnPointerFrame();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 case ui::ET_MOUSE_DRAGGED: 209 case ui::ET_MOUSE_DRAGGED:
261 case ui::ET_MOUSE_ENTERED: 210 case ui::ET_MOUSE_ENTERED:
262 case ui::ET_MOUSE_EXITED: 211 case ui::ET_MOUSE_EXITED:
263 case ui::ET_MOUSE_CAPTURE_CHANGED: 212 case ui::ET_MOUSE_CAPTURE_CHANGED:
264 break; 213 break;
265 default: 214 default:
266 NOTREACHED(); 215 NOTREACHED();
267 break; 216 break;
268 } 217 }
269 218
270 if ((event->flags() & ui::EF_IS_SYNTHESIZED) == 0)
271 is_direct_input_ = (event->flags() & ui::EF_DIRECT_INPUT) != 0;
272
273 // Update cursor widget to reflect current focus and pointer location. 219 // Update cursor widget to reflect current focus and pointer location.
274 if (focus_ && !is_direct_input_) { 220 if (focus_) {
275 if (!widget_) 221 if (!widget_)
276 CreatePointerWidget(); 222 CreatePointerWidget();
277 223
278 // Update cursor location if mouse event caused it to change. 224 // Update cursor location if mouse event caused it to change.
279 gfx::Point mouse_location = aura::Env::GetInstance()->last_mouse_location(); 225 gfx::Point mouse_location = aura::Env::GetInstance()->last_mouse_location();
280 gfx::Rect bounds = widget_->GetWindowBoundsInScreen(); 226 gfx::Rect bounds = widget_->GetWindowBoundsInScreen();
281 if (mouse_location != bounds.origin()) { 227 if (mouse_location != bounds.origin()) {
282 bounds.set_origin(mouse_location); 228 bounds.set_origin(mouse_location);
283 widget_->SetBounds(bounds); 229 widget_->SetBounds(bounds);
284 } 230 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 319
374 if (ui_scale != cursor_scale_) { 320 if (ui_scale != cursor_scale_) {
375 gfx::Transform transform; 321 gfx::Transform transform;
376 transform.Scale(ui_scale, ui_scale); 322 transform.Scale(ui_scale, ui_scale);
377 widget_->GetNativeWindow()->SetTransform(transform); 323 widget_->GetNativeWindow()->SetTransform(transform);
378 cursor_scale_ = ui_scale; 324 cursor_scale_ = ui_scale;
379 } 325 }
380 } 326 }
381 327
382 } // namespace exo 328 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/pointer.h ('k') | components/exo/pointer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698