OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/aura/window_tracker.h" | 5 #include "ui/aura/window_tracker.h" |
6 | 6 |
7 #include "ui/aura/window.h" | 7 #include "ui/aura/window.h" |
8 | 8 |
9 namespace aura { | 9 namespace aura { |
10 | 10 |
11 WindowTracker::WindowTracker() { | 11 WindowTracker::WindowTracker() { |
12 } | 12 } |
13 | 13 |
| 14 WindowTracker::WindowTracker(const WindowList& windows) { |
| 15 // |windows| may contain dups, so call Add() instead of insert(). |
| 16 for (auto iter = windows.begin(); iter != windows.end(); iter++) |
| 17 Add(*iter); |
| 18 } |
| 19 |
14 WindowTracker::~WindowTracker() { | 20 WindowTracker::~WindowTracker() { |
15 for (Windows::iterator i = windows_.begin(); i != windows_.end(); ++i) | 21 while (has_windows()) |
16 (*i)->RemoveObserver(this); | 22 Pop()->RemoveObserver(this); |
17 } | 23 } |
18 | 24 |
19 void WindowTracker::Add(Window* window) { | 25 void WindowTracker::Add(Window* window) { |
20 if (windows_.count(window)) | 26 if (Contains(window)) |
21 return; | 27 return; |
22 | 28 |
23 window->AddObserver(this); | 29 window->AddObserver(this); |
24 windows_.insert(window); | 30 windows_.push_back(window); |
25 } | 31 } |
26 | 32 |
27 void WindowTracker::Remove(Window* window) { | 33 void WindowTracker::Remove(Window* window) { |
28 if (windows_.count(window)) { | 34 auto iter = std::find(windows_.begin(), windows_.end(), window); |
29 windows_.erase(window); | 35 if (iter != windows_.end()) { |
| 36 windows_.erase(iter); |
30 window->RemoveObserver(this); | 37 window->RemoveObserver(this); |
31 } | 38 } |
32 } | 39 } |
33 | 40 |
34 bool WindowTracker::Contains(Window* window) { | 41 bool WindowTracker::Contains(Window* window) { |
35 return windows_.count(window) > 0; | 42 return std::find(windows_.begin(), windows_.end(), window) != windows_.end(); |
| 43 } |
| 44 |
| 45 aura::Window* WindowTracker::Pop() { |
| 46 DCHECK(!windows_.empty()); |
| 47 aura::Window* window = *windows_.begin(); |
| 48 Remove(window); |
| 49 return window; |
36 } | 50 } |
37 | 51 |
38 void WindowTracker::OnWindowDestroying(Window* window) { | 52 void WindowTracker::OnWindowDestroying(Window* window) { |
39 DCHECK_GT(windows_.count(window), 0u); | 53 DCHECK(Contains(window)); |
40 Remove(window); | 54 Remove(window); |
41 } | 55 } |
42 | 56 |
43 } // namespace aura | 57 } // namespace aura |
OLD | NEW |