mru_window_tracker.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright 2013 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_MRU_WINDOW_TRACKER_H_
  5. #define ASH_WM_MRU_WINDOW_TRACKER_H_
  6. #include <vector>
  7. #include "ash/ash_export.h"
  8. #include "ui/aura/window_observer.h"
  9. #include "ui/wm/public/activation_change_observer.h"
  10. namespace ash {
  11. enum DesksMruType {
  12. // The MRU window list will include windows from all active and inactive
  13. // desks.
  14. kAllDesks,
  15. // The MRU window list will exclude windows from the inactive desks.
  16. //
  17. // NOTE: During an on-going desk-switch animation, getting the MRU window list
  18. // for the active desk can be inconsistent, depending on at which stage of the
  19. // animation it is done. If you want the MRU windows in the soon-to-be active
  20. // desk, then wait for the animation to finish.
  21. kActiveDesk,
  22. };
  23. // A predicate that determines whether |window| can be included in the MRU
  24. // window list.
  25. bool CanIncludeWindowInMruList(aura::Window* window);
  26. // Maintains a most recently used list of windows. This is used for window
  27. // cycling using Alt+Tab and overview mode.
  28. class ASH_EXPORT MruWindowTracker : public wm::ActivationChangeObserver,
  29. public aura::WindowObserver {
  30. public:
  31. using WindowList = std::vector<aura::Window*>;
  32. MruWindowTracker();
  33. MruWindowTracker(const MruWindowTracker&) = delete;
  34. MruWindowTracker& operator=(const MruWindowTracker&) = delete;
  35. ~MruWindowTracker() override;
  36. // Returns the set windows in the mru list regardless of whether they can be
  37. // included in the cycler or not.
  38. // |desks_mru_type| determines whether to include or exclude windows from the
  39. // inactive desks.
  40. // TODO(oshima|afakhry): Investigate if we can consolidate BuildXXXList
  41. // methods with parameters.
  42. WindowList BuildAppWindowList(DesksMruType desks_mru_type) const;
  43. // Returns the set of windows which can be cycled through using the tracked
  44. // list of most recently used windows.
  45. // |desks_mru_type| determines whether to include or exclude windows from the
  46. // inactive desks.
  47. WindowList BuildMruWindowList(DesksMruType desks_mru_type) const;
  48. // This does the same thing as the above, but ignores the system modal dialog
  49. // state and hence the returned list could contain more windows if a system
  50. // modal dialog window is present.
  51. // |desks_mru_type| determines whether to include or exclude windows from the
  52. // inactive desks.
  53. WindowList BuildWindowListIgnoreModal(DesksMruType desks_mru_type) const;
  54. // This does the same thing as |BuildMruWindowList()| but with some
  55. // exclusions. This list is used for cycling through by the keyboard via
  56. // alt-tab.
  57. // |desks_mru_type| determines whether to include or exclude windows from the
  58. // inactive desks.
  59. WindowList BuildWindowForCycleList(DesksMruType desks_mru_type) const;
  60. // This does the same thing as |BuildWindowForCycleList()| but includes
  61. // ARC PIP windows if they exist. Entering PIP for Android can consume the
  62. // window (in contrast to Chrome PIP, which creates a new window). To support
  63. // the same interaction as Chrome PIP auto-pip, include the Android PIP window
  64. // in alt-tab. This will let alt tabbing back to the 'original window' restore
  65. // that window from PIP, which matches behaviour for Chrome PIP, where
  66. // alt-tabbing back to the original Chrome tab or app ends auto-PIP.
  67. WindowList BuildWindowForCycleWithPipList(DesksMruType desks_mru_type) const;
  68. // Starts or stops ignoring window activations. If no longer ignoring
  69. // activations the currently active window is moved to the front of the
  70. // MRU window list. Used by WindowCycleList to avoid adding all cycled
  71. // windows to the front of the MRU window list.
  72. void SetIgnoreActivations(bool ignore);
  73. // Called after |window| moved out of its about-to-be-removed desk, to a new
  74. // target desk's container. This causes |window| to be made the least-recently
  75. // used window across all desks.
  76. void OnWindowMovedOutFromRemovingDesk(aura::Window* window);
  77. // Called when a window is moved to another desk or created by a window
  78. // restore feature. This function should be only called by
  79. // `WindowRestoreController`.
  80. void OnWindowAlteredByWindowRestore(aura::Window* window);
  81. const std::vector<aura::Window*>& GetMruWindowsForTesting() {
  82. return mru_windows_;
  83. }
  84. private:
  85. // Updates the `mru_windows_` list to insert/move `active_window` at/to the
  86. // back.
  87. void SetActiveWindow(aura::Window* active_window);
  88. // wm::ActivationChangeObserver:
  89. void OnWindowActivated(ActivationReason reason,
  90. aura::Window* gained_active,
  91. aura::Window* lost_active) override;
  92. // aura::WindowObserver:
  93. void OnWindowDestroyed(aura::Window* window) override;
  94. // List of windows that have been activated in containers that we cycle
  95. // through, sorted such that the most recently used window comes last. Note
  96. // that this ordering differs from the lists returned by the
  97. // `Build*Window*List` functions, which are reversed.
  98. std::vector<aura::Window*> mru_windows_;
  99. bool ignore_window_activations_ = false;
  100. };
  101. } // namespace ash
  102. #endif // ASH_WM_MRU_WINDOW_TRACKER_H_