| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "athena/athena_export.h" |
| 9 #include "athena/wm/public/window_list_provider_observer.h" | 10 #include "athena/wm/public/window_list_provider_observer.h" |
| 10 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_property.h" |
| 13 #include "ui/wm/core/transient_window_manager.h" |
| 14 #include "ui/wm/core/window_util.h" |
| 15 |
| 16 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(ATHENA_EXPORT, bool); |
| 11 | 17 |
| 12 namespace athena { | 18 namespace athena { |
| 19 namespace { |
| 20 |
| 21 // Used to keep track of which window should be managed. This is necessary |
| 22 // as the necessary informatino used in IsValidWindow (transient parent |
| 23 // for example) may not available during destruction. |
| 24 DEFINE_WINDOW_PROPERTY_KEY(bool, kManagedKey, false); |
| 25 |
| 26 } // namespace |
| 13 | 27 |
| 14 WindowListProviderImpl::WindowListProviderImpl(aura::Window* container) | 28 WindowListProviderImpl::WindowListProviderImpl(aura::Window* container) |
| 15 : container_(container) { | 29 : container_(container) { |
| 16 CHECK(container_); | 30 CHECK(container_); |
| 17 container_->AddObserver(this); | 31 container_->AddObserver(this); |
| 18 RecreateWindowList(); | 32 RecreateWindowList(); |
| 19 std::for_each(window_list_.begin(), window_list_.end(), | 33 for (auto* window : window_list_) |
| 20 std::bind2nd(std::mem_fun(&aura::Window::AddObserver), | 34 window->AddObserver(this); |
| 21 this)); | |
| 22 } | 35 } |
| 23 | 36 |
| 24 WindowListProviderImpl::~WindowListProviderImpl() { | 37 WindowListProviderImpl::~WindowListProviderImpl() { |
| 25 // Remove all remaining window observers. | 38 // Remove all remaining window observers. |
| 26 for (aura::Window::Windows::const_iterator iter = window_list_.begin(); | 39 for (auto* window : window_list_) { |
| 27 iter != window_list_.end(); | 40 CHECK(window->GetProperty(kManagedKey)); |
| 28 ++iter) { | 41 window->RemoveObserver(this); |
| 29 CHECK(IsValidWindow(*iter)); | |
| 30 (*iter)->RemoveObserver(this); | |
| 31 } | 42 } |
| 32 container_->RemoveObserver(this); | 43 container_->RemoveObserver(this); |
| 33 } | 44 } |
| 34 | 45 |
| 35 void WindowListProviderImpl::RecreateWindowList() { | 46 bool WindowListProviderImpl::IsValidWindow(aura::Window* window) const { |
| 36 window_list_.clear(); | 47 if (wm::GetTransientParent(window)) |
| 37 const aura::Window::Windows& container_children = container_->children(); | 48 return false; |
| 38 for (aura::Window::Windows::const_iterator iter = container_children.begin(); | 49 |
| 39 iter != container_children.end(); | 50 // TODO(oshima): crbug.com/413912. |
| 40 ++iter) { | 51 return window->type() == ui::wm::WINDOW_TYPE_NORMAL || |
| 41 if (IsValidWindow(*iter)) | 52 window->type() == ui::wm::WINDOW_TYPE_PANEL; |
| 42 window_list_.push_back(*iter); | |
| 43 } | |
| 44 } | 53 } |
| 45 | 54 |
| 46 void WindowListProviderImpl::AddObserver(WindowListProviderObserver* observer) { | 55 void WindowListProviderImpl::AddObserver(WindowListProviderObserver* observer) { |
| 47 observers_.AddObserver(observer); | 56 observers_.AddObserver(observer); |
| 48 } | 57 } |
| 49 | 58 |
| 50 void WindowListProviderImpl::RemoveObserver( | 59 void WindowListProviderImpl::RemoveObserver( |
| 51 WindowListProviderObserver* observer) { | 60 WindowListProviderObserver* observer) { |
| 52 observers_.RemoveObserver(observer); | 61 observers_.RemoveObserver(observer); |
| 53 } | 62 } |
| 54 | 63 |
| 55 const aura::Window::Windows& WindowListProviderImpl::GetWindowList() const { | 64 const aura::Window::Windows& WindowListProviderImpl::GetWindowList() const { |
| 56 return window_list_; | 65 return window_list_; |
| 57 } | 66 } |
| 58 | 67 |
| 59 bool WindowListProviderImpl::IsWindowInList(aura::Window* window) const { | 68 bool WindowListProviderImpl::IsWindowInList(aura::Window* window) const { |
| 69 // TODO(oshima): Use kManagedKey specify which windows are managed. |
| 60 return window->parent() == container_ && IsValidWindow(window); | 70 return window->parent() == container_ && IsValidWindow(window); |
| 61 } | 71 } |
| 62 | 72 |
| 63 bool WindowListProviderImpl::IsValidWindow(aura::Window* window) const { | |
| 64 // TODO(oshima): crbug.com/413912 | |
| 65 return window->type() == ui::wm::WINDOW_TYPE_NORMAL || | |
| 66 window->type() == ui::wm::WINDOW_TYPE_PANEL; | |
| 67 } | |
| 68 | |
| 69 void WindowListProviderImpl::StackWindowFrontOf( | 73 void WindowListProviderImpl::StackWindowFrontOf( |
| 70 aura::Window* window, | 74 aura::Window* window, |
| 71 aura::Window* reference_window) { | 75 aura::Window* reference_window) { |
| 72 DCHECK_NE(window, reference_window); | 76 DCHECK_NE(window, reference_window); |
| 73 DCHECK(IsWindowInList(window)); | 77 DCHECK(IsWindowInList(window)); |
| 74 DCHECK(IsWindowInList(reference_window)); | 78 DCHECK(IsWindowInList(reference_window)); |
| 75 container_->StackChildAbove(window, reference_window); | 79 container_->StackChildAbove(window, reference_window); |
| 76 } | 80 } |
| 77 | 81 |
| 78 void WindowListProviderImpl::StackWindowBehindTo( | 82 void WindowListProviderImpl::StackWindowBehindTo( |
| 79 aura::Window* window, | 83 aura::Window* window, |
| 80 aura::Window* reference_window) { | 84 aura::Window* reference_window) { |
| 81 DCHECK_NE(window, reference_window); | 85 DCHECK_NE(window, reference_window); |
| 82 DCHECK(IsWindowInList(window)); | 86 DCHECK(IsWindowInList(window)); |
| 83 DCHECK(IsWindowInList(reference_window)); | 87 DCHECK(IsWindowInList(reference_window)); |
| 84 container_->StackChildBelow(window, reference_window); | 88 container_->StackChildBelow(window, reference_window); |
| 85 } | 89 } |
| 86 | 90 |
| 91 void WindowListProviderImpl::RecreateWindowList() { |
| 92 window_list_.clear(); |
| 93 for (auto* window : container_->children()) { |
| 94 if (window->GetProperty(kManagedKey)) |
| 95 window_list_.push_back(window); |
| 96 } |
| 97 } |
| 98 |
| 87 void WindowListProviderImpl::OnWindowAdded(aura::Window* window) { | 99 void WindowListProviderImpl::OnWindowAdded(aura::Window* window) { |
| 88 if (!IsValidWindow(window) || window->parent() != container_) | 100 if (!IsValidWindow(window) || window->parent() != container_) |
| 89 return; | 101 return; |
| 102 |
| 103 window->SetProperty(kManagedKey, true); |
| 90 RecreateWindowList(); | 104 RecreateWindowList(); |
| 91 DCHECK(IsWindowInList(window)); | 105 DCHECK(IsWindowInList(window)); |
| 92 window->AddObserver(this); | 106 window->AddObserver(this); |
| 93 } | 107 } |
| 94 | 108 |
| 95 void WindowListProviderImpl::OnWillRemoveWindow(aura::Window* window) { | 109 void WindowListProviderImpl::OnWillRemoveWindow(aura::Window* window) { |
| 96 if (!IsValidWindow(window) || window->parent() != container_) | 110 if (!window->GetProperty(kManagedKey)) |
| 97 return; | 111 return; |
| 98 DCHECK(IsWindowInList(window)); | 112 DCHECK(IsWindowInList(window)); |
| 99 aura::Window::Windows::iterator find = std::find(window_list_.begin(), | 113 aura::Window::Windows::iterator find = std::find(window_list_.begin(), |
| 100 window_list_.end(), | 114 window_list_.end(), |
| 101 window); | 115 window); |
| 102 CHECK(find != window_list_.end()); | 116 CHECK(find != window_list_.end()); |
| 103 int index = find - window_list_.begin(); | 117 int index = find - window_list_.begin(); |
| 104 window_list_.erase(find); | 118 window_list_.erase(find); |
| 105 window->RemoveObserver(this); | 119 window->RemoveObserver(this); |
| 106 FOR_EACH_OBSERVER( | 120 FOR_EACH_OBSERVER( |
| 107 WindowListProviderObserver, observers_, OnWindowRemoved(window, index)); | 121 WindowListProviderObserver, observers_, OnWindowRemoved(window, index)); |
| 108 } | 122 } |
| 109 | 123 |
| 110 void WindowListProviderImpl::OnWindowStackingChanged(aura::Window* window) { | 124 void WindowListProviderImpl::OnWindowStackingChanged(aura::Window* window) { |
| 111 if (window == container_) | 125 if (window == container_) |
| 112 return; | 126 return; |
| 113 DCHECK(IsWindowInList(window)); | 127 DCHECK(IsWindowInList(window)); |
| 114 RecreateWindowList(); | 128 RecreateWindowList(); |
| 115 // Inform our listeners that the stacking has been changed. | 129 // Inform our listeners that the stacking has been changed. |
| 116 FOR_EACH_OBSERVER(WindowListProviderObserver, | 130 FOR_EACH_OBSERVER(WindowListProviderObserver, |
| 117 observers_, | 131 observers_, |
| 118 OnWindowStackingChanged()); | 132 OnWindowStackingChanged()); |
| 119 } | 133 } |
| 120 | 134 |
| 121 } // namespace athena | 135 } // namespace athena |
| OLD | NEW |