overlay_event_filter.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2012 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 ASH_WM_OVERLAY_EVENT_FILTER_H_
  5. #define ASH_WM_OVERLAY_EVENT_FILTER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/session/session_observer.h"
  8. #include "base/compiler_specific.h"
  9. #include "ui/aura/window.h"
  10. #include "ui/events/event_handler.h"
  11. namespace ash {
  12. // EventFilter for the "overlay window", which intercepts events before they are
  13. // processed by the usual path (e.g. the partial screenshot UI, the keyboard
  14. // overlay). It does nothing the first time, but works when |Activate()| is
  15. // called. The main task of this event filter is just to stop propagation
  16. // of any key events during activation, and also signal cancellation when keys
  17. // for canceling are pressed.
  18. class ASH_EXPORT OverlayEventFilter : public ui::EventHandler,
  19. public SessionObserver {
  20. public:
  21. // Windows that need to receive events from OverlayEventFilter implement this.
  22. class ASH_EXPORT Delegate {
  23. public:
  24. // Invoked when OverlayEventFilter needs to stop handling events.
  25. virtual void Cancel() = 0;
  26. // Returns true if the overlay should be canceled in response to |event|.
  27. virtual bool IsCancelingKeyEvent(ui::KeyEvent* event) = 0;
  28. // Returns the window that needs to receive events. NULL if no window needs
  29. // to receive key events from OverlayEventFilter.
  30. virtual aura::Window* GetWindow() = 0;
  31. };
  32. OverlayEventFilter();
  33. OverlayEventFilter(const OverlayEventFilter&) = delete;
  34. OverlayEventFilter& operator=(const OverlayEventFilter&) = delete;
  35. ~OverlayEventFilter() override;
  36. // Starts the filtering of events. It also notifies the specified
  37. // |delegate| when a key event means cancel (like Esc). It holds the
  38. // pointer to the specified |delegate| until Deactivate() is called, but
  39. // does not take ownership.
  40. void Activate(Delegate* delegate);
  41. // Ends the filtering of events.
  42. void Deactivate(Delegate* delegate);
  43. // Cancels the partial screenshot UI. Do nothing if it's not activated.
  44. void Cancel();
  45. // Returns true if it's currently active.
  46. bool IsActive();
  47. // ui::EventHandler overrides:
  48. void OnKeyEvent(ui::KeyEvent* event) override;
  49. // SessionObserver overrides:
  50. void OnLoginStatusChanged(LoginStatus status) override;
  51. void OnChromeTerminating() override;
  52. void OnLockStateChanged(bool locked) override;
  53. private:
  54. Delegate* delegate_ = nullptr;
  55. ScopedSessionObserver scoped_session_observer_;
  56. };
  57. } // namespace ash
  58. #endif // ASH_WM_OVERLAY_EVENT_FILTER_H_