blob: d7bc12b6a21865bb0b3c2eec612e2ba2141b5415 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2012 The Chromium Authors
[email protected]1d030242012-06-28 18:34:082// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]42341772013-11-13 06:01:595#ifndef UI_AURA_WINDOW_TRACKER_H_
6#define UI_AURA_WINDOW_TRACKER_H_
[email protected]1d030242012-06-28 18:34:087
oshimacabad392015-12-03 17:38:218#include <vector>
[email protected]1d030242012-06-28 18:34:089
Ali Hijazie63cbaf62023-12-20 19:29:3510#include "base/memory/raw_ptr.h"
Scott Violetefbcd062019-04-26 16:52:2011#include "ui/aura/aura_export.h"
[email protected]1d030242012-06-28 18:34:0812#include "ui/aura/window_observer.h"
13
14namespace aura {
15
Scott Violetefbcd062019-04-26 16:52:2016// This class is used to track an ordered list of Windows. When a Window is
17// destroyed it is removed from the list of Windows.
18class AURA_EXPORT WindowTracker : public WindowObserver {
19 public:
20 // A vector is used for tracking the windows (instead of a set) as some places
21 // care about ordering.
Ali Hijazie63cbaf62023-12-20 19:29:3522 using WindowList = std::vector<raw_ptr<Window, VectorExperimental>>;
Scott Violetefbcd062019-04-26 16:52:2023
24 explicit WindowTracker(const WindowList& windows);
25 WindowTracker();
Peter Boströmc8c12352021-09-21 23:37:1526
27 WindowTracker(const WindowTracker&) = delete;
28 WindowTracker& operator=(const WindowTracker&) = delete;
29
Scott Violetefbcd062019-04-26 16:52:2030 ~WindowTracker() override;
31
32 // Returns the set of windows being observed.
33 const WindowList& windows() const { return windows_; }
34
35 // Adds |window| to the set of Windows being tracked.
36 void Add(Window* window);
37
38 void RemoveAll();
39
40 // Removes |window| from the set of windows being tracked.
41 void Remove(Window* window);
42
43 Window* Pop();
44
45 // Returns true if |window| was previously added and has not been removed or
46 // deleted.
47 bool Contains(Window* window) const;
48
49 // WindowObserver overrides:
50 void OnWindowDestroying(Window* window) override;
51
52 private:
53 WindowList windows_;
Scott Violetefbcd062019-04-26 16:52:2054};
[email protected]1d030242012-06-28 18:34:0855
56} // namespace aura
57
[email protected]42341772013-11-13 06:01:5958#endif // UI_AURA_WINDOW_TRACKER_H_