touch.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_EXO_TOUCH_H_
  5. #define COMPONENTS_EXO_TOUCH_H_
  6. #include "base/containers/flat_map.h"
  7. #include "components/exo/surface_observer.h"
  8. #include "ui/events/event_handler.h"
  9. #include "ui/gfx/geometry/point_f.h"
  10. namespace ui {
  11. class LocatedEvent;
  12. class TouchEvent;
  13. }
  14. namespace exo {
  15. class Seat;
  16. class TouchDelegate;
  17. class TouchStylusDelegate;
  18. // This class implements a client touch device that represents one or more
  19. // touch devices.
  20. class Touch : public ui::EventHandler, public SurfaceObserver {
  21. public:
  22. Touch(TouchDelegate* delegate, Seat* seat);
  23. Touch(const Touch&) = delete;
  24. Touch& operator=(const Touch&) = delete;
  25. ~Touch() override;
  26. TouchDelegate* delegate() const { return delegate_; }
  27. // Set delegate for stylus events.
  28. void SetStylusDelegate(TouchStylusDelegate* delegate);
  29. bool HasStylusDelegate() const;
  30. // Overridden from ui::EventHandler:
  31. void OnTouchEvent(ui::TouchEvent* event) override;
  32. // Overridden from SurfaceObserver:
  33. void OnSurfaceDestroying(Surface* surface) override;
  34. private:
  35. // Returns the effective target for |event|.
  36. Surface* GetEffectiveTargetForEvent(ui::LocatedEvent* event) const;
  37. // Cancels touches on all the surfaces.
  38. void CancelAllTouches();
  39. // The delegate instance that all events are dispatched to.
  40. TouchDelegate* const delegate_;
  41. Seat* const seat_;
  42. // The delegate instance that all stylus related events are dispatched to.
  43. TouchStylusDelegate* stylus_delegate_ = nullptr;
  44. // Map of touch points to its focus surface.
  45. base::flat_map<int, Surface*> touch_points_surface_map_;
  46. // Map of a touched surface to the count of touch pointers on that surface.
  47. base::flat_map<Surface*, int> surface_touch_count_map_;
  48. };
  49. } // namespace exo
  50. #endif // COMPONENTS_EXO_TOUCH_H_