tray_action.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2017 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_TRAY_ACTION_TRAY_ACTION_H_
  5. #define ASH_TRAY_ACTION_TRAY_ACTION_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/public/mojom/tray_action.mojom.h"
  9. #include "base/observer_list.h"
  10. #include "base/scoped_observation.h"
  11. #include "mojo/public/cpp/bindings/pending_receiver.h"
  12. #include "mojo/public/cpp/bindings/pending_remote.h"
  13. #include "mojo/public/cpp/bindings/receiver_set.h"
  14. #include "mojo/public/cpp/bindings/remote.h"
  15. #include "ui/events/devices/device_data_manager.h"
  16. #include "ui/events/devices/input_device_event_observer.h"
  17. namespace ui {
  18. enum class StylusState;
  19. } // namespace ui
  20. namespace ash {
  21. class BacklightsForcedOffSetter;
  22. class LockScreenNoteDisplayStateHandler;
  23. class TrayActionObserver;
  24. // Controller that ash can use to request a predefined set of actions to be
  25. // performed by clients.
  26. // The controller provides an interface to:
  27. // * Send a request to the client to handle an action.
  28. // * Observe the state of support for an action as reported by the current ash
  29. // client.
  30. // Currently, only single action is supported - creating new note on the lock
  31. // screen - Chrome handles this action by launching an app (if any) that is
  32. // registered as a lock screen enabled action handler for the new note action.
  33. class ASH_EXPORT TrayAction : public mojom::TrayAction,
  34. public ui::InputDeviceEventObserver {
  35. public:
  36. explicit TrayAction(BacklightsForcedOffSetter* backlights_forced_off_setter);
  37. TrayAction(const TrayAction&) = delete;
  38. TrayAction& operator=(const TrayAction&) = delete;
  39. ~TrayAction() override;
  40. LockScreenNoteDisplayStateHandler*
  41. lock_screen_note_display_state_handler_for_test() {
  42. return lock_screen_note_display_state_handler_.get();
  43. }
  44. void AddObserver(TrayActionObserver* observer);
  45. void RemoveObserver(TrayActionObserver* observer);
  46. void BindReceiver(mojo::PendingReceiver<mojom::TrayAction> receiver);
  47. // Gets last known handler state for the lock screen note action.
  48. // It will return kNotAvailable if an action handler has not been set using
  49. // |SetClient|.
  50. mojom::TrayActionState GetLockScreenNoteState() const;
  51. // Helper method for determining if lock screen not action is in active state.
  52. bool IsLockScreenNoteActive() const;
  53. // If the client is set, sends it a request to handle the lock screen note
  54. // action.
  55. void RequestNewLockScreenNote(mojom::LockScreenNoteOrigin origin);
  56. // If the client is set, sends a request to close the lock screen note.
  57. void CloseLockScreenNote(mojom::CloseLockScreenNoteReason reason);
  58. // mojom::TrayAction:
  59. void SetClient(mojo::PendingRemote<mojom::TrayActionClient> action_handler,
  60. mojom::TrayActionState lock_screen_note_state) override;
  61. void UpdateLockScreenNoteState(mojom::TrayActionState state) override;
  62. // ui::InputDeviceEventObserver:
  63. void OnStylusStateChanged(ui::StylusState state) override;
  64. void FlushMojoForTesting();
  65. private:
  66. // Notifies the observers that state for the lock screen note action has been
  67. // updated.
  68. void NotifyLockScreenNoteStateChanged();
  69. BacklightsForcedOffSetter* const backlights_forced_off_setter_;
  70. // Last known state for lock screen note action.
  71. mojom::TrayActionState lock_screen_note_state_ =
  72. mojom::TrayActionState::kNotAvailable;
  73. std::unique_ptr<LockScreenNoteDisplayStateHandler>
  74. lock_screen_note_display_state_handler_;
  75. base::ObserverList<TrayActionObserver>::Unchecked observers_;
  76. // Receivers for users of the mojo interface.
  77. mojo::ReceiverSet<mojom::TrayAction> receivers_;
  78. mojo::Remote<mojom::TrayActionClient> tray_action_client_;
  79. base::ScopedObservation<ui::DeviceDataManager, ui::InputDeviceEventObserver>
  80. stylus_observation_{this};
  81. };
  82. } // namespace ash
  83. #endif // ASH_TRAY_ACTION_TRAY_ACTION_H_