OLD | NEW |
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/common/shell_window_ids.h" | 7 #include "ash/common/shell_window_ids.h" |
8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
9 #include "components/exo/pointer_delegate.h" | 9 #include "components/exo/pointer_delegate.h" |
10 #include "components/exo/pointer_stylus_delegate.h" | 10 #include "components/exo/pointer_stylus_delegate.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 delegate_->OnPointerFrame(); | 165 delegate_->OnPointerFrame(); |
166 } | 166 } |
167 | 167 |
168 // Report changes in pointer type. | 168 // Report changes in pointer type. |
169 if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) { | 169 if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) { |
170 stylus_delegate_->OnPointerToolChange(new_pointer_type); | 170 stylus_delegate_->OnPointerToolChange(new_pointer_type); |
171 pointer_type_ = new_pointer_type; | 171 pointer_type_ = new_pointer_type; |
172 } | 172 } |
173 | 173 |
| 174 if (focus_ && event->IsMouseEvent() && event->type() != ui::ET_MOUSE_EXITED) { |
| 175 bool send_frame = false; |
| 176 |
| 177 // Generate motion event if location changed. We need to check location |
| 178 // here as mouse movement can generate both "moved" and "entered" events |
| 179 // but OnPointerMotion should only be called if location changed since |
| 180 // OnPointerEnter was called. |
| 181 if (!SameLocation(event, location_)) { |
| 182 location_ = event->location_f(); |
| 183 delegate_->OnPointerMotion(event->time_stamp(), location_); |
| 184 send_frame = true; |
| 185 } |
| 186 if (stylus_delegate_ && |
| 187 pointer_type_ != ui::EventPointerType::POINTER_TYPE_MOUSE) { |
| 188 constexpr float kEpsilon = std::numeric_limits<float>::epsilon(); |
| 189 gfx::Vector2dF new_tilt = gfx::Vector2dF(event->pointer_details().tilt_x, |
| 190 event->pointer_details().tilt_y); |
| 191 if (std::abs(new_tilt.x() - tilt_.x()) > kEpsilon || |
| 192 std::abs(new_tilt.y() - tilt_.y()) > kEpsilon) { |
| 193 tilt_ = new_tilt; |
| 194 stylus_delegate_->OnPointerTilt(event->time_stamp(), new_tilt); |
| 195 send_frame = true; |
| 196 } |
| 197 |
| 198 float new_force = event->pointer_details().force; |
| 199 if (std::abs(new_force - force_) > kEpsilon) { |
| 200 force_ = new_force; |
| 201 stylus_delegate_->OnPointerForce(event->time_stamp(), new_force); |
| 202 send_frame = true; |
| 203 } |
| 204 } |
| 205 if (send_frame) |
| 206 delegate_->OnPointerFrame(); |
| 207 } |
| 208 |
174 switch (event->type()) { | 209 switch (event->type()) { |
175 case ui::ET_MOUSE_PRESSED: | 210 case ui::ET_MOUSE_PRESSED: |
176 case ui::ET_MOUSE_RELEASED: | 211 case ui::ET_MOUSE_RELEASED: |
177 if (focus_) { | 212 if (focus_) { |
178 delegate_->OnPointerButton(event->time_stamp(), | 213 delegate_->OnPointerButton(event->time_stamp(), |
179 event->changed_button_flags(), | 214 event->changed_button_flags(), |
180 event->type() == ui::ET_MOUSE_PRESSED); | 215 event->type() == ui::ET_MOUSE_PRESSED); |
181 delegate_->OnPointerFrame(); | 216 delegate_->OnPointerFrame(); |
182 } | 217 } |
183 break; | 218 break; |
184 case ui::ET_MOUSE_MOVED: | |
185 case ui::ET_MOUSE_DRAGGED: | |
186 if (focus_) { | |
187 bool send_frame = false; | |
188 // Generate motion event if location changed. We need to check location | |
189 // here as mouse movement can generate both "moved" and "entered" events | |
190 // but OnPointerMotion should only be called if location changed since | |
191 // OnPointerEnter was called. | |
192 if (!SameLocation(event, location_)) { | |
193 location_ = event->location_f(); | |
194 delegate_->OnPointerMotion(event->time_stamp(), location_); | |
195 send_frame = true; | |
196 } | |
197 if (stylus_delegate_ && | |
198 pointer_type_ != ui::EventPointerType::POINTER_TYPE_MOUSE) { | |
199 constexpr float kEpsilon = std::numeric_limits<float>::epsilon(); | |
200 gfx::Vector2dF new_tilt = gfx::Vector2dF( | |
201 event->pointer_details().tilt_x, event->pointer_details().tilt_y); | |
202 if (std::abs(new_tilt.x() - tilt_.x()) > kEpsilon || | |
203 std::abs(new_tilt.y() - tilt_.y()) > kEpsilon) { | |
204 tilt_ = new_tilt; | |
205 stylus_delegate_->OnPointerTilt(event->time_stamp(), new_tilt); | |
206 send_frame = true; | |
207 } | |
208 | |
209 float new_force = event->pointer_details().force; | |
210 if (std::abs(new_force - force_) > kEpsilon) { | |
211 force_ = new_force; | |
212 stylus_delegate_->OnPointerForce(event->time_stamp(), new_force); | |
213 send_frame = true; | |
214 } | |
215 } | |
216 if (send_frame) | |
217 delegate_->OnPointerFrame(); | |
218 } | |
219 break; | |
220 case ui::ET_SCROLL: | 219 case ui::ET_SCROLL: |
221 if (focus_) { | 220 if (focus_) { |
222 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event); | 221 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event); |
223 delegate_->OnPointerScroll( | 222 delegate_->OnPointerScroll( |
224 event->time_stamp(), | 223 event->time_stamp(), |
225 gfx::Vector2dF(scroll_event->x_offset(), scroll_event->y_offset()), | 224 gfx::Vector2dF(scroll_event->x_offset(), scroll_event->y_offset()), |
226 false); | 225 false); |
227 delegate_->OnPointerFrame(); | 226 delegate_->OnPointerFrame(); |
228 } | 227 } |
229 break; | 228 break; |
(...skipping 10 matching lines...) Expand all Loading... |
240 delegate_->OnPointerScrollStop(event->time_stamp()); | 239 delegate_->OnPointerScrollStop(event->time_stamp()); |
241 delegate_->OnPointerFrame(); | 240 delegate_->OnPointerFrame(); |
242 } | 241 } |
243 break; | 242 break; |
244 case ui::ET_SCROLL_FLING_CANCEL: | 243 case ui::ET_SCROLL_FLING_CANCEL: |
245 if (focus_) { | 244 if (focus_) { |
246 delegate_->OnPointerScrollCancel(event->time_stamp()); | 245 delegate_->OnPointerScrollCancel(event->time_stamp()); |
247 delegate_->OnPointerFrame(); | 246 delegate_->OnPointerFrame(); |
248 } | 247 } |
249 break; | 248 break; |
| 249 case ui::ET_MOUSE_MOVED: |
| 250 case ui::ET_MOUSE_DRAGGED: |
250 case ui::ET_MOUSE_ENTERED: | 251 case ui::ET_MOUSE_ENTERED: |
251 case ui::ET_MOUSE_EXITED: | 252 case ui::ET_MOUSE_EXITED: |
252 case ui::ET_MOUSE_CAPTURE_CHANGED: | 253 case ui::ET_MOUSE_CAPTURE_CHANGED: |
253 break; | 254 break; |
254 default: | 255 default: |
255 NOTREACHED(); | 256 NOTREACHED(); |
256 break; | 257 break; |
257 } | 258 } |
258 | 259 |
259 if ((event->flags() & ui::EF_IS_SYNTHESIZED) == 0) | 260 if ((event->flags() & ui::EF_IS_SYNTHESIZED) == 0) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 363 |
363 if (ui_scale != cursor_scale_) { | 364 if (ui_scale != cursor_scale_) { |
364 gfx::Transform transform; | 365 gfx::Transform transform; |
365 transform.Scale(ui_scale, ui_scale); | 366 transform.Scale(ui_scale, ui_scale); |
366 widget_->GetNativeWindow()->SetTransform(transform); | 367 widget_->GetNativeWindow()->SetTransform(transform); |
367 cursor_scale_ = ui_scale; | 368 cursor_scale_ = ui_scale; |
368 } | 369 } |
369 } | 370 } |
370 | 371 |
371 } // namespace exo | 372 } // namespace exo |
OLD | NEW |