This source file includes following definitions.
- GetNumberOfManagedWindows
- WindowStateDestroyed
- OnOverviewModeStarted
- OnOverviewModeEnded
- OnWindowDestroying
- OnWindowAdded
- OnWindowBoundsChanged
- OnDisplayBoundsChanged
- OnDisplayAdded
- OnDisplayRemoved
- MaximizeAllWindows
- RestoreAllWindows
- MaximizeAndTrackWindow
- ForgetWindow
- ShouldHandleWindow
- AddWindowCreationObservers
- RemoveWindowCreationObservers
- DisplayConfigurationChanged
- IsContainerWindow
- EnableBackdropBehindTopWindowOnEachDisplay
#include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/maximize_mode/maximize_mode_window_state.h"
#include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/workspace_controller.h"
#include "ui/aura/window.h"
#include "ui/gfx/screen.h"
namespace ash {
MaximizeModeWindowManager::~MaximizeModeWindowManager() {
Shell::GetInstance()->RemoveShellObserver(this);
Shell::GetScreen()->RemoveObserver(this);
EnableBackdropBehindTopWindowOnEachDisplay(false);
RemoveWindowCreationObservers();
RestoreAllWindows();
Shell::GetInstance()->OnMaximizeModeEnded();
}
int MaximizeModeWindowManager::GetNumberOfManagedWindows() {
return window_state_map_.size();
}
void MaximizeModeWindowManager::WindowStateDestroyed(aura::Window* window) {
DCHECK(!window->HasObserver(this));
WindowToState::iterator it = window_state_map_.find(window);
DCHECK(it != window_state_map_.end());
window_state_map_.erase(it);
}
void MaximizeModeWindowManager::OnOverviewModeStarted() {
if (backdrops_hidden_)
return;
EnableBackdropBehindTopWindowOnEachDisplay(false);
backdrops_hidden_ = true;
}
void MaximizeModeWindowManager::OnOverviewModeEnded() {
if (!backdrops_hidden_)
return;
backdrops_hidden_ = false;
EnableBackdropBehindTopWindowOnEachDisplay(true);
}
void MaximizeModeWindowManager::OnWindowDestroying(aura::Window* window) {
if (!IsContainerWindow(window))
ForgetWindow(window);
}
void MaximizeModeWindowManager::OnWindowAdded(
aura::Window* window) {
if (IsContainerWindow(window->parent()) &&
window_state_map_.find(window) == window_state_map_.end())
MaximizeAndTrackWindow(window);
}
void MaximizeModeWindowManager::OnWindowBoundsChanged(
aura::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
if (!IsContainerWindow(window))
return;
for (WindowToState::iterator it = window_state_map_.begin();
it != window_state_map_.end();
++it) {
it->second->UpdateWindowPosition(wm::GetWindowState(it->first), false);
}
}
void MaximizeModeWindowManager::OnDisplayBoundsChanged(
const gfx::Display& display) {
}
void MaximizeModeWindowManager::OnDisplayAdded(const gfx::Display& display) {
DisplayConfigurationChanged();
}
void MaximizeModeWindowManager::OnDisplayRemoved(const gfx::Display& display) {
DisplayConfigurationChanged();
}
MaximizeModeWindowManager::MaximizeModeWindowManager()
: backdrops_hidden_(false) {
WindowSelectorController* controller =
Shell::GetInstance()->window_selector_controller();
if (controller && controller->IsSelecting())
controller->OnSelectionCanceled();
MaximizeAllWindows();
AddWindowCreationObservers();
EnableBackdropBehindTopWindowOnEachDisplay(true);
Shell::GetInstance()->OnMaximizeModeStarted();
Shell::GetScreen()->AddObserver(this);
Shell::GetInstance()->AddShellObserver(this);
}
void MaximizeModeWindowManager::MaximizeAllWindows() {
MruWindowTracker::WindowList windows =
MruWindowTracker::BuildWindowList(false);
for (MruWindowTracker::WindowList::iterator window = windows.begin();
window != windows.end(); ++window) {
MaximizeAndTrackWindow(*window);
}
}
void MaximizeModeWindowManager::RestoreAllWindows() {
while (window_state_map_.size())
ForgetWindow(window_state_map_.begin()->first);
}
void MaximizeModeWindowManager::MaximizeAndTrackWindow(
aura::Window* window) {
if (!ShouldHandleWindow(window))
return;
DCHECK(window_state_map_.find(window) == window_state_map_.end());
window->AddObserver(this);
window_state_map_[window] = new MaximizeModeWindowState(window, this);
}
void MaximizeModeWindowManager::ForgetWindow(aura::Window* window) {
WindowToState::iterator it = window_state_map_.find(window);
DCHECK(it != window_state_map_.end());
window->RemoveObserver(this);
it->second->LeaveMaximizeMode(wm::GetWindowState(it->first));
DCHECK(window_state_map_.find(window) == window_state_map_.end());
}
bool MaximizeModeWindowManager::ShouldHandleWindow(aura::Window* window) {
DCHECK(window);
return window->type() == ui::wm::WINDOW_TYPE_NORMAL;
}
void MaximizeModeWindowManager::AddWindowCreationObservers() {
DCHECK(observed_container_windows_.empty());
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
for (aura::Window::Windows::const_iterator iter = root_windows.begin();
iter != root_windows.end(); ++iter) {
aura::Window* container =
Shell::GetContainer(*iter, kShellWindowId_DefaultContainer);
DCHECK(observed_container_windows_.find(container) ==
observed_container_windows_.end());
container->AddObserver(this);
observed_container_windows_.insert(container);
}
}
void MaximizeModeWindowManager::RemoveWindowCreationObservers() {
for (std::set<aura::Window*>::iterator iter =
observed_container_windows_.begin();
iter != observed_container_windows_.end(); ++iter) {
(*iter)->RemoveObserver(this);
}
observed_container_windows_.clear();
}
void MaximizeModeWindowManager::DisplayConfigurationChanged() {
EnableBackdropBehindTopWindowOnEachDisplay(false);
RemoveWindowCreationObservers();
AddWindowCreationObservers();
EnableBackdropBehindTopWindowOnEachDisplay(true);
}
bool MaximizeModeWindowManager::IsContainerWindow(aura::Window* window) {
return observed_container_windows_.find(window) !=
observed_container_windows_.end();
}
void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay(
bool enable) {
if (backdrops_hidden_)
return;
Shell::RootWindowControllerList controllers =
Shell::GetAllRootWindowControllers();
for (Shell::RootWindowControllerList::iterator iter = controllers.begin();
iter != controllers.end(); ++iter) {
RootWindowController* controller = *iter;
aura::Window* container = Shell::GetContainer(
controller->root_window(), kShellWindowId_DefaultContainer);
controller->workspace_controller()->SetMaximizeBackdropDelegate(
scoped_ptr<WorkspaceLayoutManagerDelegate>(
enable ? new WorkspaceBackdropDelegate(container) : NULL));
}
}
}