cast_touch_event_gate.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2018 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 CHROMECAST_GRAPHICS_CAST_TOUCH_EVENT_GATE_H_
  5. #define CHROMECAST_GRAPHICS_CAST_TOUCH_EVENT_GATE_H_
  6. #include "base/containers/flat_set.h"
  7. #include "ui/events/event_rewriter.h"
  8. namespace aura {
  9. class Window;
  10. } // namespace aura
  11. namespace chromecast {
  12. class CastTouchActivityObserver;
  13. // An event rewriter whose purpose is to discard events (when enabled). This
  14. // class is meant to be installed as the first rewriter in the chain, to handle
  15. // scenarios where all input needs to be disabled, such as when the device
  16. // screen is turned off. Instances of CastTouchActivityObserver can be
  17. // registered to receive notifications of gated events.
  18. class CastTouchEventGate : public ui::EventRewriter {
  19. public:
  20. explicit CastTouchEventGate(aura::Window* root_window);
  21. ~CastTouchEventGate() override;
  22. void SetEnabled(bool enabled);
  23. void AddObserver(CastTouchActivityObserver* observer);
  24. void RemoveObserver(CastTouchActivityObserver* observer);
  25. // ui::EventRewriter implementation.
  26. ui::EventDispatchDetails RewriteEvent(
  27. const ui::Event& event,
  28. const Continuation continuation) override;
  29. private:
  30. bool enabled_ = false;
  31. aura::Window* root_window_;
  32. base::flat_set<CastTouchActivityObserver*> observers_;
  33. };
  34. } // namespace chromecast
  35. #endif // CHROMECAST_GRAPHICS_CAST_TOUCH_EVENT_GATE_H_