This source file includes following definitions.
- AddTrackedWindows
- AddDraggedWindows
- CompareWindowState
- BuildWindowListInternal
- ignore_window_activations_
- BuildWindowList
- BuildMruWindowList
- SetIgnoreActivations
- SetActiveWindow
- OnWindowActivated
- OnWindowDestroyed
#include "ash/wm/mru_window_tracker.h"
#include <algorithm>
#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/switchable_windows.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace_controller.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 {
void AddTrackedWindows(aura::Window* root,
int container_id,
MruWindowTracker::WindowList* windows) {
aura::Window* container = Shell::GetContainer(root, container_id);
const MruWindowTracker::WindowList& children(container->children());
windows->insert(windows->end(), children.begin(), children.end());
}
void AddDraggedWindows(aura::Window* root,
MruWindowTracker::WindowList* windows) {
aura::Window* container =
Shell::GetContainer(root, kShellWindowId_DockedContainer);
const MruWindowTracker::WindowList& children = container->children();
for (MruWindowTracker::WindowList::const_iterator iter = children.begin();
iter != children.end(); ++iter) {
if (wm::GetWindowState(*iter)->is_dragged())
windows->insert(windows->end(), *iter);
}
}
bool CompareWindowState(aura::Window* w1, aura::Window* w2) {
return ash::wm::IsWindowMinimized(w1) && !ash::wm::IsWindowMinimized(w2);
}
MruWindowTracker::WindowList BuildWindowListInternal(
const std::list<aura::Window*>* mru_windows,
bool top_most_at_end) {
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)
continue;
for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i)
AddTrackedWindows(*iter, kSwitchableWindowContainerIds[i], &windows);
}
for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i)
AddTrackedWindows(active_root, kSwitchableWindowContainerIds[i], &windows);
AddDraggedWindows(active_root, &windows);
MruWindowTracker::WindowList::iterator last =
std::remove_if(
windows.begin(),
windows.end(),
std::not1(std::ptr_fun(ash::wm::CanActivateWindow)));
windows.erase(last, windows.end());
if (mru_windows) {
for (std::list<aura::Window*>::const_reverse_iterator ix =
mru_windows->rbegin();
ix != mru_windows->rend(); ++ix) {
if (!IsSwitchableContainer((*ix)->parent()) ||
!ash::wm::CanActivateWindow(*ix)) {
continue;
}
MruWindowTracker::WindowList::iterator window =
std::find(windows.begin(), windows.end(), *ix);
if (window != windows.end()) {
windows.erase(window);
windows.push_back(*ix);
}
}
}
std::stable_sort(windows.begin(), windows.end(), CompareWindowState);
if (!top_most_at_end)
std::reverse(windows.begin(), windows.end());
return windows;
}
}
MruWindowTracker::MruWindowTracker(
aura::client::ActivationClient* activation_client)
: activation_client_(activation_client),
ignore_window_activations_(false) {
activation_client_->AddObserver(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);
}
MruWindowTracker::WindowList MruWindowTracker::BuildWindowList(
bool top_most_at_end) {
return BuildWindowListInternal(NULL, top_most_at_end);
}
MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() {
return BuildWindowListInternal(&mru_windows_, false);
}
void MruWindowTracker::SetIgnoreActivations(bool ignore) {
ignore_window_activations_ = ignore;
if (!ignore)
SetActiveWindow(wm::GetActiveWindow());
}
void MruWindowTracker::SetActiveWindow(aura::Window* active_window) {
if (!active_window)
return;
std::list<aura::Window*>::iterator iter =
std::find(mru_windows_.begin(), mru_windows_.end(), active_window);
if (iter == mru_windows_.end())
active_window->AddObserver(this);
else
mru_windows_.erase(iter);
CHECK(active_window->layer());
mru_windows_.push_front(active_window);
}
void MruWindowTracker::OnWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) {
if (!ignore_window_activations_)
SetActiveWindow(gained_active);
}
void MruWindowTracker::OnWindowDestroyed(aura::Window* window) {
mru_windows_.remove(window);
window->RemoveObserver(this);
}
}