OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ASH_LASER_LASER_POINTER_CONTROLLER_H_ |
| 6 #define ASH_LASER_LASER_POINTER_CONTROLLER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "ash/ash_export.h" |
| 11 #include "base/macros.h" |
| 12 #include "ui/aura/window_observer.h" |
| 13 #include "ui/events/event.h" |
| 14 #include "ui/events/event_handler.h" |
| 15 #include "ui/gfx/geometry/point.h" |
| 16 |
| 17 namespace base { |
| 18 class Timer; |
| 19 } |
| 20 |
| 21 namespace ui { |
| 22 class LocatedEvent; |
| 23 class MouseEvent; |
| 24 class TouchEvent; |
| 25 } |
| 26 |
| 27 namespace ash { |
| 28 |
| 29 class LaserPointerView; |
| 30 |
| 31 // Controller for the laser pointer functionality. Enables/disables laser |
| 32 // pointer as well as receives points and passes them off to be rendered. |
| 33 class ASH_EXPORT LaserPointerController : public ui::EventHandler, |
| 34 public aura::WindowObserver { |
| 35 public: |
| 36 LaserPointerController(); |
| 37 ~LaserPointerController() override; |
| 38 |
| 39 // Turns the laser pointer feature on or off. The user still has to press and |
| 40 // drag to see the laser pointer. |
| 41 void SetEnabled(bool enabled); |
| 42 |
| 43 private: |
| 44 friend class LaserPointerControllerTestApi; |
| 45 |
| 46 // ui::EventHandler: |
| 47 void OnMouseEvent(ui::MouseEvent* event) override; |
| 48 |
| 49 // aura::WindowObserver: |
| 50 void OnWindowDestroying(aura::Window* window) override; |
| 51 |
| 52 void StopTimer(); |
| 53 |
| 54 // Helper method to create a new LaserPointerView with a new root window when |
| 55 // the current root window changes because the user is on multiple screens and |
| 56 // switched focus to a different screen. |
| 57 void SwitchTargetRootWindowIfNeeded(); |
| 58 |
| 59 // Timer callback which adds a point where the mouse was last seen. This |
| 60 // allows the trail to fade away when the mouse is stationary. |
| 61 void AddStationaryPoint(); |
| 62 |
| 63 // Timer which will add a new stationary point when the mouse stops moving. |
| 64 // This will remove points that are too old. |
| 65 std::unique_ptr<base::Timer> stationary_timer_; |
| 66 int stationary_timer_repeat_count_ = 0; |
| 67 |
| 68 bool enabled_ = false; |
| 69 |
| 70 // The last seen mouse location in screen coordinates. |
| 71 gfx::Point current_mouse_location_; |
| 72 |
| 73 // |laser_pointer_view_| will only hold an instance when the laser pointer is |
| 74 // enabled and activated (pressed or dragged). |
| 75 std::unique_ptr<LaserPointerView> laser_pointer_view_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(LaserPointerController); |
| 78 }; |
| 79 |
| 80 } // namespace ash |
| 81 |
| 82 #endif // ASH_LASER_LASER_POINTER_CONTROLLER_H_ |
OLD | NEW |