Chromium Code Reviews| Index: ash/wm/mru_window_tracker.cc |
| diff --git a/ash/wm/mru_window_tracker.cc b/ash/wm/mru_window_tracker.cc |
| index 165159b5ce583e9f798533e834fd10ae1cf174bd..30a40f6f3b7e251edad8ca3ba55342c20fe7bb18 100644 |
| --- a/ash/wm/mru_window_tracker.cc |
| +++ b/ash/wm/mru_window_tracker.cc |
| @@ -6,42 +6,40 @@ |
| #include <algorithm> |
| -#include "ash/aura/wm_window_aura.h" |
| #include "ash/common/shell_window_ids.h" |
| +#include "ash/common/wm/focus_rules.h" |
| #include "ash/common/wm/switchable_windows.h" |
| #include "ash/common/wm/window_state.h" |
| -#include "ash/session/session_state_delegate.h" |
| -#include "ash/shell.h" |
| -#include "ash/wm/ash_focus_rules.h" |
| -#include "ash/wm/window_util.h" |
| -#include "ash/wm/workspace_controller.h" |
| +#include "ash/common/wm_shell.h" |
| +#include "ash/common/wm_window.h" |
| #include "base/bind.h" |
| -#include "ui/aura/window_event_dispatcher.h" |
| -#include "ui/events/event.h" |
| -#include "ui/events/event_handler.h" |
| -#include "ui/wm/public/activation_client.h" |
| namespace ash { |
| namespace { |
| -typedef base::Callback<bool(aura::Window*)> CanActivateWindowPredicate; |
| +using CanActivateWindowPredicate = base::Callback<bool(WmWindow*)>; |
| + |
| +bool CallCanActivate(WmWindow* window) { |
| + return window->CanActivate(); |
| +} |
| // Adds the windows that can be cycled through for the specified window id to |
| // |windows|. |
| -void AddTrackedWindows(aura::Window* root, |
| +void AddTrackedWindows(WmWindow* root, |
| int container_id, |
| MruWindowTracker::WindowList* windows) { |
| - aura::Window* container = Shell::GetContainer(root, container_id); |
| - const MruWindowTracker::WindowList& children(container->children()); |
| + WmWindow* container = root->GetChildByShellWindowId(container_id); |
| + const MruWindowTracker::WindowList children(container->GetChildren()); |
| windows->insert(windows->end(), children.begin(), children.end()); |
| } |
| // Returns whether |w1| should be considered less recently used than |w2|. This |
| // is used for a stable sort to move minimized windows to the LRU end of the |
| // list. |
| -bool CompareWindowState(aura::Window* w1, aura::Window* w2) { |
| - return ash::wm::IsWindowMinimized(w1) && !ash::wm::IsWindowMinimized(w2); |
| +bool CompareWindowState(WmWindow* w1, WmWindow* w2) { |
| + return w1->GetWindowState()->IsMinimized() && |
| + !w2->GetWindowState()->IsMinimized(); |
| } |
| // Returns a list of windows ordered by their stacking order. |
| @@ -49,18 +47,15 @@ bool CompareWindowState(aura::Window* w1, aura::Window* w2) { |
| // It uses the given |should_include_window_predicate| to determine whether to |
| // include a window in the returned list or not. |
| MruWindowTracker::WindowList BuildWindowListInternal( |
| - const std::list<aura::Window*>* mru_windows, |
| + const std::list<WmWindow*>* mru_windows, |
| const CanActivateWindowPredicate& should_include_window_predicate) { |
| MruWindowTracker::WindowList windows; |
| - aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| - |
| - aura::Window* active_root = Shell::GetTargetRootWindow(); |
| - for (aura::Window::Windows::const_iterator iter = root_windows.begin(); |
| - iter != root_windows.end(); ++iter) { |
| - if (*iter == active_root) |
| + WmWindow* active_root = WmShell::Get()->GetRootWindowForNewWindows(); |
| + for (WmWindow* window : WmShell::Get()->GetAllRootWindows()) { |
|
James Cook
2016/06/07 01:21:05
Hooray for nice ranged for loops!
|
| + if (window == active_root) |
| continue; |
| for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) |
| - AddTrackedWindows(*iter, wm::kSwitchableWindowContainerIds[i], &windows); |
| + AddTrackedWindows(window, wm::kSwitchableWindowContainerIds[i], &windows); |
| } |
| // Add windows in the active root windows last so that the topmost window |
| @@ -70,7 +65,7 @@ MruWindowTracker::WindowList BuildWindowListInternal( |
| &windows); |
| // Removes unfocusable windows. |
| - std::vector<aura::Window*>::iterator itr = windows.begin(); |
| + std::vector<WmWindow*>::iterator itr = windows.begin(); |
| while (itr != windows.end()) { |
| if (!should_include_window_predicate.Run(*itr)) |
| itr = windows.erase(itr); |
| @@ -82,12 +77,10 @@ MruWindowTracker::WindowList BuildWindowListInternal( |
| if (mru_windows) { |
| // Iterate through the list backwards, so that we can move each window to |
| // the front of the windows list as we find them. |
| - for (std::list<aura::Window*>::const_reverse_iterator ix = |
| - mru_windows->rbegin(); |
| - ix != mru_windows->rend(); ++ix) { |
| + for (auto ix = mru_windows->rbegin(); ix != mru_windows->rend(); ++ix) { |
| // Exclude windows in non-switchable containers and those which cannot |
| // be activated. |
| - if (!wm::IsSwitchableContainer(WmWindowAura::Get((*ix)->parent())) || |
| + if (!wm::IsSwitchableContainer((*ix)->GetParent()) || |
| !should_include_window_predicate.Run(*ix)) { |
| continue; |
| } |
| @@ -115,35 +108,24 @@ MruWindowTracker::WindowList BuildWindowListInternal( |
| ////////////////////////////////////////////////////////////////////////////// |
| // MruWindowTracker, public: |
| -MruWindowTracker::MruWindowTracker( |
| - aura::client::ActivationClient* activation_client, |
| - ash::wm::AshFocusRules* focus_rules) |
| - : activation_client_(activation_client), |
| - focus_rules_(focus_rules), |
| - ignore_window_activations_(false) { |
| - activation_client_->AddObserver(this); |
| +MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) { |
| + WmShell::Get()->AddActivationObserver(this); |
| } |
| MruWindowTracker::~MruWindowTracker() { |
| - for (std::list<aura::Window*>::iterator iter = mru_windows_.begin(); |
| - iter != mru_windows_.end(); ++iter) { |
| - (*iter)->RemoveObserver(this); |
| - } |
| - |
| - activation_client_->RemoveObserver(this); |
| + WmShell::Get()->RemoveActivationObserver(this); |
| + for (WmWindow* window : mru_windows_) |
| + window->RemoveObserver(this); |
| } |
| MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() const { |
| - return BuildWindowListInternal(&mru_windows_, |
| - base::Bind(&ash::wm::CanActivateWindow)); |
| + return BuildWindowListInternal(&mru_windows_, base::Bind(&CallCanActivate)); |
| } |
| MruWindowTracker::WindowList |
| MruWindowTracker::BuildWindowListIgnoreModal() const { |
| - return BuildWindowListInternal( |
| - NULL, |
| - base::Bind(&MruWindowTracker::IsWindowConsideredActivateable, |
| - base::Unretained(this))); |
| + return BuildWindowListInternal(nullptr, |
| + base::Bind(&IsWindowConsideredActivatable)); |
| } |
| void MruWindowTracker::SetIgnoreActivations(bool ignore) { |
| @@ -152,39 +134,33 @@ void MruWindowTracker::SetIgnoreActivations(bool ignore) { |
| // If no longer ignoring window activations, move currently active window |
| // to front. |
| if (!ignore) |
| - SetActiveWindow(wm::GetActiveWindow()); |
| + SetActiveWindow(WmShell::Get()->GetActiveWindow()); |
| } |
| ////////////////////////////////////////////////////////////////////////////// |
| // MruWindowTracker, private: |
| -void MruWindowTracker::SetActiveWindow(aura::Window* active_window) { |
| +void MruWindowTracker::SetActiveWindow(WmWindow* active_window) { |
| if (!active_window) |
| return; |
| - std::list<aura::Window*>::iterator iter = |
| + std::list<WmWindow*>::iterator iter = |
| std::find(mru_windows_.begin(), mru_windows_.end(), active_window); |
| // Observe all newly tracked windows. |
| if (iter == mru_windows_.end()) |
| active_window->AddObserver(this); |
| else |
| mru_windows_.erase(iter); |
| - // TODO(flackr): Remove this check if this doesn't fire for a while. This |
| - // should verify that all tracked windows start with a layer, see |
| - // http://crbug.com/291354. |
| - CHECK(active_window->layer()); |
| mru_windows_.push_front(active_window); |
| } |
| -void MruWindowTracker::OnWindowActivated( |
| - aura::client::ActivationChangeObserver::ActivationReason reason, |
| - aura::Window* gained_active, |
| - aura::Window* lost_active) { |
| +void MruWindowTracker::OnWindowActivated(WmWindow* gained_active, |
| + WmWindow* lost_active) { |
| if (!ignore_window_activations_) |
| SetActiveWindow(gained_active); |
| } |
| -void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { |
| +void MruWindowTracker::OnWindowDestroyed(WmWindow* window) { |
| // It's possible for OnWindowActivated() to be called after |
| // OnWindowDestroying(). This means we need to override OnWindowDestroyed() |
| // else we may end up with a deleted window in |mru_windows_|. |
| @@ -192,9 +168,4 @@ void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { |
| window->RemoveObserver(this); |
| } |
| -bool MruWindowTracker::IsWindowConsideredActivateable( |
| - aura::Window* window) const { |
| - return focus_rules_->IsWindowConsideredActivatable(window); |
| -} |
| - |
| } // namespace ash |