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

Side by Side Diff: components/exo/pointer.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/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 void Pointer::SetStylusDelegate(PointerStylusDelegate* delegate) {
127 stylus_delegate_ = delegate;
128 }
129
130 //////////////////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////////////////
131 // ui::EventHandler overrides: 125 // ui::EventHandler overrides:
132 126
133 void Pointer::OnMouseEvent(ui::MouseEvent* event) { 127 void Pointer::OnMouseEvent(ui::MouseEvent* event) {
134 Surface* target = GetEffectiveTargetForEvent(event); 128 Surface* target = GetEffectiveTargetForEvent(event);
135 129
136 if (event->flags() & ui::EF_TOUCH_ACCESSIBILITY) 130 if (event->flags() & ui::EF_TOUCH_ACCESSIBILITY)
137 return; 131 return;
138 132
139 auto new_pointer_type = pointer_type_;
140 if ((event->flags() & ui::EF_IS_SYNTHESIZED) == 0) {
141 new_pointer_type = event->pointer_details().pointer_type;
142 if (new_pointer_type == ui::EventPointerType::POINTER_TYPE_UNKNOWN)
143 new_pointer_type = ui::EventPointerType::POINTER_TYPE_MOUSE;
144 }
145
146 // 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
147 // generate enter and leave events. 134 // generate enter and leave events.
148 if (target != focus_) { 135 if (target != focus_) {
149 // 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.
150 if (focus_) { 137 if (focus_) {
151 delegate_->OnPointerLeave(focus_); 138 delegate_->OnPointerLeave(focus_);
152 focus_->RemoveSurfaceObserver(this); 139 focus_->RemoveSurfaceObserver(this);
153 // 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
154 // response to each OnPointerEnter() call. 141 // response to each OnPointerEnter() call.
155 focus_->UnregisterCursorProvider(this); 142 focus_->UnregisterCursorProvider(this);
156 focus_ = nullptr; 143 focus_ = nullptr;
157 } 144 }
158 // 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.
159 if (target) { 146 if (target) {
160 delegate_->OnPointerEnter(target, event->location_f(), 147 delegate_->OnPointerEnter(target, event->location_f(),
161 event->button_flags()); 148 event->button_flags());
162 location_ = event->location_f(); 149 location_ = event->location_f();
163 if (stylus_delegate_) {
164 stylus_delegate_->OnPointerToolChange(new_pointer_type);
165 pointer_type_ = new_pointer_type;
166 }
167
168 focus_ = target; 150 focus_ = target;
169 focus_->AddSurfaceObserver(this); 151 focus_->AddSurfaceObserver(this);
170 } 152 }
171 delegate_->OnPointerFrame(); 153 delegate_->OnPointerFrame();
172 } 154 }
173 155
174 // Report changes in pointer type.
175 if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) {
176 stylus_delegate_->OnPointerToolChange(new_pointer_type);
177 pointer_type_ = new_pointer_type;
178 }
179
180 if (focus_ && event->IsMouseEvent() && event->type() != ui::ET_MOUSE_EXITED) { 156 if (focus_ && event->IsMouseEvent() && event->type() != ui::ET_MOUSE_EXITED) {
181 bool send_frame = false;
182
183 // Generate motion event if location changed. We need to check location 157 // Generate motion event if location changed. We need to check location
184 // here as mouse movement can generate both "moved" and "entered" events 158 // here as mouse movement can generate both "moved" and "entered" events
185 // but OnPointerMotion should only be called if location changed since 159 // but OnPointerMotion should only be called if location changed since
186 // OnPointerEnter was called. 160 // OnPointerEnter was called.
187 if (!SameLocation(event, location_)) { 161 if (!SameLocation(event, location_)) {
188 location_ = event->location_f(); 162 location_ = event->location_f();
189 delegate_->OnPointerMotion(event->time_stamp(), location_); 163 delegate_->OnPointerMotion(event->time_stamp(), location_);
190 send_frame = true; 164 delegate_->OnPointerFrame();
191 } 165 }
192 if (stylus_delegate_ &&
193 pointer_type_ != ui::EventPointerType::POINTER_TYPE_MOUSE) {
194 constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
195 gfx::Vector2dF new_tilt = gfx::Vector2dF(event->pointer_details().tilt_x,
196 event->pointer_details().tilt_y);
197 if (std::abs(new_tilt.x() - tilt_.x()) > kEpsilon ||
198 std::abs(new_tilt.y() - tilt_.y()) > kEpsilon) {
199 tilt_ = new_tilt;
200 stylus_delegate_->OnPointerTilt(event->time_stamp(), new_tilt);
201 send_frame = true;
202 }
203
204 float new_force = event->pointer_details().force;
205 if (std::abs(new_force - force_) > kEpsilon) {
206 force_ = new_force;
207 stylus_delegate_->OnPointerForce(event->time_stamp(), new_force);
208 send_frame = true;
209 }
210 }
211 if (send_frame)
212 delegate_->OnPointerFrame();
213 } 166 }
214 167
215 switch (event->type()) { 168 switch (event->type()) {
216 case ui::ET_MOUSE_PRESSED: 169 case ui::ET_MOUSE_PRESSED:
217 case ui::ET_MOUSE_RELEASED: 170 case ui::ET_MOUSE_RELEASED:
218 if (focus_) { 171 if (focus_) {
219 delegate_->OnPointerButton(event->time_stamp(), 172 delegate_->OnPointerButton(event->time_stamp(),
220 event->changed_button_flags(), 173 event->changed_button_flags(),
221 event->type() == ui::ET_MOUSE_PRESSED); 174 event->type() == ui::ET_MOUSE_PRESSED);
222 delegate_->OnPointerFrame(); 175 delegate_->OnPointerFrame();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 case ui::ET_MOUSE_DRAGGED: 209 case ui::ET_MOUSE_DRAGGED:
257 case ui::ET_MOUSE_ENTERED: 210 case ui::ET_MOUSE_ENTERED:
258 case ui::ET_MOUSE_EXITED: 211 case ui::ET_MOUSE_EXITED:
259 case ui::ET_MOUSE_CAPTURE_CHANGED: 212 case ui::ET_MOUSE_CAPTURE_CHANGED:
260 break; 213 break;
261 default: 214 default:
262 NOTREACHED(); 215 NOTREACHED();
263 break; 216 break;
264 } 217 }
265 218
266 if ((event->flags() & ui::EF_IS_SYNTHESIZED) == 0)
267 is_direct_input_ = (event->flags() & ui::EF_DIRECT_INPUT) != 0;
268
269 // Update cursor widget to reflect current focus and pointer location. 219 // Update cursor widget to reflect current focus and pointer location.
270 if (focus_ && !is_direct_input_) { 220 if (focus_) {
271 if (!widget_) 221 if (!widget_)
272 CreatePointerWidget(); 222 CreatePointerWidget();
273 223
274 // Update cursor location if mouse event caused it to change. 224 // Update cursor location if mouse event caused it to change.
275 gfx::Point mouse_location = aura::Env::GetInstance()->last_mouse_location(); 225 gfx::Point mouse_location = aura::Env::GetInstance()->last_mouse_location();
276 gfx::Rect bounds = widget_->GetWindowBoundsInScreen(); 226 gfx::Rect bounds = widget_->GetWindowBoundsInScreen();
277 if (mouse_location != bounds.origin()) { 227 if (mouse_location != bounds.origin()) {
278 bounds.set_origin(mouse_location); 228 bounds.set_origin(mouse_location);
279 widget_->SetBounds(bounds); 229 widget_->SetBounds(bounds);
280 } 230 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 319
370 if (ui_scale != cursor_scale_) { 320 if (ui_scale != cursor_scale_) {
371 gfx::Transform transform; 321 gfx::Transform transform;
372 transform.Scale(ui_scale, ui_scale); 322 transform.Scale(ui_scale, ui_scale);
373 widget_->GetNativeWindow()->SetTransform(transform); 323 widget_->GetNativeWindow()->SetTransform(transform);
374 cursor_scale_ = ui_scale; 324 cursor_scale_ = ui_scale;
375 } 325 }
376 } 326 }
377 327
378 } // namespace exo 328 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698