system_modal_container_layout_manager.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_
  5. #define ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_
  6. #include <memory>
  7. #include <set>
  8. #include <vector>
  9. #include "ash/ash_export.h"
  10. #include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
  11. #include "ash/shelf/shelf.h"
  12. #include "ash/shelf/shelf_observer.h"
  13. #include "ash/wm/wm_default_layout_manager.h"
  14. #include "base/scoped_observation.h"
  15. #include "ui/aura/window_observer.h"
  16. namespace gfx {
  17. class Rect;
  18. }
  19. namespace ash {
  20. class WindowDimmer;
  21. // LayoutManager for the modal window container.
  22. // System modal windows which are centered on the screen will be kept centered
  23. // when the container size changes.
  24. class ASH_EXPORT SystemModalContainerLayoutManager
  25. : public WmDefaultLayoutManager,
  26. public ShelfObserver,
  27. public aura::WindowObserver,
  28. public KeyboardControllerObserver {
  29. public:
  30. explicit SystemModalContainerLayoutManager(aura::Window* container);
  31. SystemModalContainerLayoutManager(const SystemModalContainerLayoutManager&) =
  32. delete;
  33. SystemModalContainerLayoutManager& operator=(
  34. const SystemModalContainerLayoutManager&) = delete;
  35. ~SystemModalContainerLayoutManager() override;
  36. bool has_window_dimmer() const { return window_dimmer_ != nullptr; }
  37. // Overridden from WmDefaultLayoutManager:
  38. void OnChildWindowVisibilityChanged(aura::Window* child,
  39. bool visible) override;
  40. void OnWindowResized() override;
  41. void OnWindowAddedToLayout(aura::Window* child) override;
  42. void OnWillRemoveWindowFromLayout(aura::Window* child) override;
  43. void SetChildBounds(aura::Window* child,
  44. const gfx::Rect& requested_bounds) override;
  45. // Overridden from aura::WindowObserver:
  46. void OnWindowPropertyChanged(aura::Window* window,
  47. const void* key,
  48. intptr_t old) override;
  49. // Overridden from KeyboardControllerObserver:
  50. void OnKeyboardOccludedBoundsChanged(const gfx::Rect& new_bounds) override;
  51. // True if the window is either contained by the top most modal window,
  52. // or contained by its transient children.
  53. bool IsPartOfActiveModalWindow(aura::Window* window);
  54. // Activates next modal window if any. Returns false if there
  55. // are no more modal windows in this layout manager.
  56. bool ActivateNextModalWindow();
  57. // Creates modal background window, which is a partially-opaque
  58. // fullscreen window. If there is already a modal background window,
  59. // it will bring it the top.
  60. void CreateModalBackground();
  61. void DestroyModalBackground();
  62. // Is the |window| modal background?
  63. static bool IsModalBackground(aura::Window* window);
  64. // ShelfObserver:
  65. void WillChangeVisibilityState(ShelfVisibilityState new_state) override;
  66. private:
  67. void AddModalWindow(aura::Window* window);
  68. // Removes |window| from |modal_windows_|. Returns true if |window| was in
  69. // |modal_windows_|.
  70. bool RemoveModalWindow(aura::Window* window);
  71. // Called when a modal window is removed. It will activate another modal
  72. // window if any, or remove modal screens on all displays.
  73. void OnModalWindowRemoved(aura::Window* removed);
  74. // Reposition the dialogs to become visible after the work area changes.
  75. void PositionDialogsAfterWorkAreaResize();
  76. // Get the usable bounds rectangle for enclosed dialogs.
  77. gfx::Rect GetUsableDialogArea() const;
  78. // Gets the new bounds for a |window| to use which are either centered (if the
  79. // window was previously centered) or fitted to the screen.
  80. gfx::Rect GetCenteredAndOrFittedBounds(const aura::Window* window);
  81. // Returns true if |bounds| is considered centered.
  82. bool IsBoundsCentered(const gfx::Rect& window_bounds) const;
  83. aura::Window* modal_window() {
  84. return !modal_windows_.empty() ? modal_windows_.back() : nullptr;
  85. }
  86. // The container that owns the layout manager.
  87. aura::Window* container_;
  88. // WindowDimmer used to dim windows behind the modal window(s) being shown in
  89. // |container_|.
  90. std::unique_ptr<WindowDimmer> window_dimmer_;
  91. // A stack of modal windows. Only the topmost can receive events.
  92. std::vector<aura::Window*> modal_windows_;
  93. // Windows contained in this set are centered. Windows are automatically
  94. // added to this based on IsBoundsCentered().
  95. std::set<const aura::Window*> windows_to_center_;
  96. // A shelf observer to update position of modals when work area is updated.
  97. base::ScopedObservation<Shelf, ShelfObserver> shelf_observation_{this};
  98. };
  99. } // namespace ash
  100. #endif // ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_