screen_pinning_controller.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright 2016 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_SCREEN_PINNING_CONTROLLER_H_
  5. #define ASH_WM_SCREEN_PINNING_CONTROLLER_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "ash/ash_export.h"
  9. #include "ash/display/window_tree_host_manager.h"
  10. namespace aura {
  11. class Window;
  12. }
  13. namespace ash {
  14. class WindowDimmer;
  15. template <typename UserData>
  16. class WindowUserData;
  17. // Supports "screen pinning" for ARC++ apps. From the Android docs:
  18. // "Lets you temporarily restrict users from leaving your task or being
  19. // interrupted by notifications. This could be used, for example, if you are
  20. // developing an education app to support high stakes assessment requirements on
  21. // Android, or a single-purpose or kiosk application."
  22. // https://developer.android.com/about/versions/android-5.0.html#ScreenPinning
  23. // See also ArcKioskAppLauncher::CheckAndPinWindow().
  24. class ASH_EXPORT ScreenPinningController
  25. : public WindowTreeHostManager::Observer,
  26. aura::WindowObserver {
  27. public:
  28. ScreenPinningController();
  29. ScreenPinningController(const ScreenPinningController&) = delete;
  30. ScreenPinningController& operator=(const ScreenPinningController&) = delete;
  31. ~ScreenPinningController() override;
  32. // Sets a pinned window. It is not allowed to call this when there already
  33. // is a pinned window.
  34. void SetPinnedWindow(aura::Window* pinned_window);
  35. // Returns true if in pinned mode, otherwise false.
  36. bool IsPinned() const;
  37. // Returns the pinned window if in pinned mode, or nullptr.
  38. aura::Window* pinned_window() const { return pinned_window_; }
  39. // Called when a new window is added to the container which has the pinned
  40. // window.
  41. void OnWindowAddedToPinnedContainer(aura::Window* new_window);
  42. // Called when a window will be removed from the container which has the
  43. // pinned window.
  44. void OnWillRemoveWindowFromPinnedContainer(aura::Window* window);
  45. // Called when a window stacking is changed in the container which has the
  46. // pinned window.
  47. void OnPinnedContainerWindowStackingChanged(aura::Window* window);
  48. // Called when a new window is added to a system modal container.
  49. void OnWindowAddedToSystemModalContainer(aura::Window* new_window);
  50. // Called when a window will be removed from a system modal container.
  51. void OnWillRemoveWindowFromSystemModalContainer(aura::Window* window);
  52. // Called when a window stacking is changed in a system modal container.
  53. void OnSystemModalContainerWindowStackingChanged(aura::Window* window);
  54. private:
  55. class PinnedContainerWindowObserver;
  56. class PinnedContainerChildWindowObserver;
  57. class SystemModalContainerWindowObserver;
  58. class SystemModalContainerChildWindowObserver;
  59. // Keeps the pinned window on top of the siblings.
  60. void KeepPinnedWindowOnTop();
  61. // Keeps the dim window at bottom of the container.
  62. void KeepDimWindowAtBottom(aura::Window* container);
  63. // Creates a WindowDimmer for |container| and places it in |window_dimmers_|.
  64. // Returns the window from WindowDimmer.
  65. aura::Window* CreateWindowDimmer(aura::Window* container);
  66. // Resets internal states when |pinned_window_| exits pinning state, or
  67. // disappears.
  68. void ResetWindowPinningState();
  69. // WindowTreeHostManager::Observer:
  70. void OnDisplayConfigurationChanged() override;
  71. // aura::WindowObserver:
  72. void OnWindowDestroying(aura::Window* window) override;
  73. // Pinned window should be on top in the parent window.
  74. aura::Window* pinned_window_ = nullptr;
  75. // Owns the WindowDimmers. There is one WindowDimmer for the parent of
  76. // |pinned_window_| and one for each display other than the display
  77. // |pinned_window_| is on.
  78. std::unique_ptr<WindowUserData<WindowDimmer>> window_dimmers_;
  79. // Set true only when restacking done by this controller.
  80. bool in_restacking_ = false;
  81. // Window observers to translate events for the window to this controller.
  82. std::unique_ptr<PinnedContainerWindowObserver>
  83. pinned_container_window_observer_;
  84. std::unique_ptr<PinnedContainerChildWindowObserver>
  85. pinned_container_child_window_observer_;
  86. std::unique_ptr<SystemModalContainerWindowObserver>
  87. system_modal_container_window_observer_;
  88. std::unique_ptr<SystemModalContainerChildWindowObserver>
  89. system_modal_container_child_window_observer_;
  90. };
  91. } // namespace ash
  92. #endif // ASH_WM_SCREEN_PINNING_CONTROLLER_H_