lock_screen_action_background_controller.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_LOCK_SCREEN_ACTION_LOCK_SCREEN_ACTION_BACKGROUND_CONTROLLER_H_
  5. #define ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_ACTION_BACKGROUND_CONTROLLER_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/lock_screen_action/lock_screen_action_background_state.h"
  9. #include "base/callback_forward.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/observer_list.h"
  12. namespace aura {
  13. class Window;
  14. }
  15. namespace ash {
  16. class LockScreenActionBackgroundObserver;
  17. // Base class for managing lock screen action background. The implementation
  18. // should provide methods for showing and hiding background when requested.
  19. // The base class keeps track of the background state, and notifies observers
  20. // when the state changes.
  21. class ASH_EXPORT LockScreenActionBackgroundController {
  22. public:
  23. // Creates a LockScreenActionBackgroundController instance.
  24. static std::unique_ptr<LockScreenActionBackgroundController> Create();
  25. // Method that can be used in tests to change the controller returned by
  26. // |Create| in tests.
  27. // Note: this has to be called before root window controller is initialized
  28. // to have any effect.
  29. using FactoryCallback = base::RepeatingCallback<
  30. std::unique_ptr<LockScreenActionBackgroundController>()>;
  31. static void SetFactoryCallbackForTesting(
  32. FactoryCallback* testing_factory_callback);
  33. LockScreenActionBackgroundController();
  34. LockScreenActionBackgroundController(
  35. const LockScreenActionBackgroundController&) = delete;
  36. LockScreenActionBackgroundController& operator=(
  37. const LockScreenActionBackgroundController&) = delete;
  38. virtual ~LockScreenActionBackgroundController();
  39. // Sets the window the background widget should use as its parent.
  40. void SetParentWindow(aura::Window* parent_window);
  41. void AddObserver(LockScreenActionBackgroundObserver* observer);
  42. void RemoveObserver(LockScreenActionBackgroundObserver* observer);
  43. LockScreenActionBackgroundState state() const { return state_; }
  44. // Returns whether |window| is a background widget window.
  45. virtual bool IsBackgroundWindow(aura::Window* window) const = 0;
  46. // Starts showing background.
  47. //
  48. // Returns whether the background state has changed. On success, the state is
  49. // expected to change to either kShowing, or kShown.
  50. virtual bool ShowBackground() = 0;
  51. // Hides background without an animation.
  52. //
  53. // Returns whether the background state has changed. On success the state is
  54. // expected to change to kHidden.
  55. virtual bool HideBackgroundImmediately() = 0;
  56. // Starts hiding the background. Unlike |HideBackgroundImediatelly|, hiding
  57. // the background may be accompanied with an animation, in which case state
  58. // should be changed to kHiding.
  59. //
  60. // Returns whether the background state has changed. On success, the state is
  61. // expected to change to either kHiding or kHidden.
  62. virtual bool HideBackground() = 0;
  63. protected:
  64. // Method the implementations should use to update the current background
  65. // state and notify observers of background state changes.
  66. void UpdateState(LockScreenActionBackgroundState state);
  67. aura::Window* parent_window_ = nullptr;
  68. private:
  69. LockScreenActionBackgroundState state_ =
  70. LockScreenActionBackgroundState::kHidden;
  71. base::ObserverList<LockScreenActionBackgroundObserver>::Unchecked observers_;
  72. };
  73. } // namespace ash
  74. #endif // ASH_LOCK_SCREEN_ACTION_LOCK_SCREEN_ACTION_BACKGROUND_CONTROLLER_H_