OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/wm/window_list_provider_impl.h" | 5 #include "athena/wm/window_list_provider_impl.h" |
6 | 6 |
| 7 #include "athena/wm/public/window_list_provider_observer.h" |
7 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
8 | 9 |
9 namespace athena { | 10 namespace athena { |
10 | 11 |
11 WindowListProviderImpl::WindowListProviderImpl(aura::Window* container) | 12 WindowListProviderImpl::WindowListProviderImpl(aura::Window* container) |
12 : container_(container) { | 13 : container_(container) { |
13 CHECK(container_); | 14 CHECK(container_); |
| 15 container_->AddObserver(this); |
14 } | 16 } |
15 | 17 |
16 WindowListProviderImpl::~WindowListProviderImpl() { | 18 WindowListProviderImpl::~WindowListProviderImpl() { |
| 19 // Remove all remaining window observers. |
| 20 const aura::Window::Windows& container_children = container_->children(); |
| 21 for (aura::Window::Windows::const_iterator iter = container_children.begin(); |
| 22 iter != container_children.end(); |
| 23 ++iter) { |
| 24 if (IsValidWindow(*iter)) |
| 25 (*iter)->RemoveObserver(this); |
| 26 } |
| 27 container_->RemoveObserver(this); |
| 28 } |
| 29 |
| 30 void WindowListProviderImpl::AddObserver(WindowListProviderObserver* observer) { |
| 31 observers_.AddObserver(observer); |
| 32 } |
| 33 |
| 34 void WindowListProviderImpl::RemoveObserver( |
| 35 WindowListProviderObserver* observer) { |
| 36 observers_.RemoveObserver(observer); |
17 } | 37 } |
18 | 38 |
19 aura::Window::Windows WindowListProviderImpl::GetWindowList() const { | 39 aura::Window::Windows WindowListProviderImpl::GetWindowList() const { |
20 aura::Window::Windows list; | 40 aura::Window::Windows list; |
21 const aura::Window::Windows& container_children = container_->children(); | 41 const aura::Window::Windows& container_children = container_->children(); |
22 for (aura::Window::Windows::const_iterator iter = container_children.begin(); | 42 for (aura::Window::Windows::const_iterator iter = container_children.begin(); |
23 iter != container_children.end(); | 43 iter != container_children.end(); |
24 ++iter) { | 44 ++iter) { |
25 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL) | 45 if (IsValidWindow(*iter)) |
26 list.push_back(*iter); | 46 list.push_back(*iter); |
27 } | 47 } |
28 return list; | 48 return list; |
29 } | 49 } |
30 | 50 |
| 51 bool WindowListProviderImpl::IsWindowInList(aura::Window* window) const { |
| 52 return window->parent() == container_ && IsValidWindow(window); |
| 53 } |
| 54 |
| 55 bool WindowListProviderImpl::IsValidWindow(aura::Window* window) const { |
| 56 return window->type() == ui::wm::WINDOW_TYPE_NORMAL; |
| 57 } |
| 58 |
| 59 void WindowListProviderImpl::MoveToFront(aura::Window* window) { |
| 60 DCHECK(IsWindowInList(window)); |
| 61 container_->StackChildAtTop(window); |
| 62 } |
| 63 |
| 64 void WindowListProviderImpl::StackWindowFrontOf( |
| 65 aura::Window* window, |
| 66 aura::Window* reference_window) { |
| 67 DCHECK_NE(window, reference_window); |
| 68 DCHECK(IsWindowInList(window)); |
| 69 DCHECK(IsWindowInList(reference_window)); |
| 70 container_->StackChildAbove(window, reference_window); |
| 71 } |
| 72 |
| 73 void WindowListProviderImpl::StackWindowBehindTo( |
| 74 aura::Window* window, |
| 75 aura::Window* reference_window) { |
| 76 DCHECK_NE(window, reference_window); |
| 77 DCHECK(IsWindowInList(window)); |
| 78 DCHECK(IsWindowInList(reference_window)); |
| 79 container_->StackChildBelow(window, reference_window); |
| 80 } |
| 81 |
| 82 void WindowListProviderImpl::OnWindowAdded(aura::Window* window) { |
| 83 if (!IsValidWindow(window) || window->parent() != container_) |
| 84 return; |
| 85 DCHECK(IsWindowInList(window)); |
| 86 window->AddObserver(this); |
| 87 } |
| 88 |
| 89 void WindowListProviderImpl::OnWillRemoveWindow(aura::Window* window) { |
| 90 if (!IsValidWindow(window) || window->parent() != container_) |
| 91 return; |
| 92 DCHECK(IsWindowInList(window)); |
| 93 window->RemoveObserver(this); |
| 94 } |
| 95 |
| 96 void WindowListProviderImpl::OnWindowStackingChanged(aura::Window* window) { |
| 97 if (window == container_) |
| 98 return; |
| 99 DCHECK(IsWindowInList(window)); |
| 100 // Inform our listeners that the stacking has been changed. |
| 101 FOR_EACH_OBSERVER(WindowListProviderObserver, |
| 102 observers_, |
| 103 OnWindowStackingChanged()); |
| 104 } |
| 105 |
31 } // namespace athena | 106 } // namespace athena |
OLD | NEW |