This source file includes following definitions.
- BelongsToContainerWithEqualOrGreaterId
- SupportsChildActivation
- IsWindowConsideredVisibleForActivation
- CanActivateWindow
- GetNextActivatableWindow
- GetTopmostWindowToActivateForContainerIndex
- GetTopmostWindowToActivateInContainer
#include "ash/wm/ash_focus_rules.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/window_state.h"
#include "ui/aura/window.h"
namespace ash {
namespace wm {
namespace {
const int kWindowContainerIds[] = {
kShellWindowId_OverlayContainer,
kShellWindowId_LockSystemModalContainer,
kShellWindowId_SettingBubbleContainer,
kShellWindowId_LockScreenContainer,
kShellWindowId_SystemModalContainer,
kShellWindowId_AlwaysOnTopContainer,
kShellWindowId_AppListContainer,
kShellWindowId_DefaultContainer,
kShellWindowId_DockedContainer,
kShellWindowId_PanelContainer,
kShellWindowId_ShelfContainer,
kShellWindowId_StatusContainer, };
bool BelongsToContainerWithEqualOrGreaterId(const aura::Window* window,
int container_id) {
for (; window; window = window->parent()) {
if (window->id() >= container_id)
return true;
}
return false;
}
}
AshFocusRules::AshFocusRules() {
}
AshFocusRules::~AshFocusRules() {
}
bool AshFocusRules::SupportsChildActivation(aura::Window* window) const {
if (window->id() == kShellWindowId_DefaultContainer)
return true;
for (size_t i = 0; i < arraysize(kWindowContainerIds); i++) {
if (window->id() == kWindowContainerIds[i])
return true;
}
return false;
}
bool AshFocusRules::IsWindowConsideredVisibleForActivation(
aura::Window* window) const {
if (BaseFocusRules::IsWindowConsideredVisibleForActivation(window))
return true;
if (wm::GetWindowState(window)->IsMinimized())
return true;
return window->TargetVisibility() &&
(window->parent()->id() == kShellWindowId_DefaultContainer ||
window->parent()->id() == kShellWindowId_LockScreenContainer);
}
bool AshFocusRules::CanActivateWindow(aura::Window* window) const {
if (!window)
return true;
if (!BaseFocusRules::CanActivateWindow(window))
return false;
if (Shell::GetInstance()->IsSystemModalWindowOpen()) {
return BelongsToContainerWithEqualOrGreaterId(
window, kShellWindowId_SystemModalContainer);
}
return true;
}
aura::Window* AshFocusRules::GetNextActivatableWindow(
aura::Window* ignore) const {
DCHECK(ignore);
int starting_container_index = 0;
aura::Window* root = ignore->GetRootWindow();
if (!root)
root = Shell::GetTargetRootWindow();
int container_count = static_cast<int>(arraysize(kWindowContainerIds));
for (int i = 0; ignore && i < container_count; i++) {
aura::Window* container = Shell::GetContainer(root, kWindowContainerIds[i]);
if (container && container->Contains(ignore)) {
starting_container_index = i;
break;
}
}
aura::Window* window = NULL;
for (int i = starting_container_index; !window && i < container_count; i++)
window = GetTopmostWindowToActivateForContainerIndex(i, ignore);
if (!window && starting_container_index > 0) {
for (int i = starting_container_index - 1; !window && i >= 0; i--)
window = GetTopmostWindowToActivateForContainerIndex(i, ignore);
}
return window;
}
aura::Window* AshFocusRules::GetTopmostWindowToActivateForContainerIndex(
int index,
aura::Window* ignore) const {
aura::Window* window = NULL;
aura::Window* root = ignore ? ignore->GetRootWindow() : NULL;
aura::Window::Windows containers = Shell::GetContainersFromAllRootWindows(
kWindowContainerIds[index], root);
for (aura::Window::Windows::const_iterator iter = containers.begin();
iter != containers.end() && !window; ++iter) {
window = GetTopmostWindowToActivateInContainer((*iter), ignore);
}
return window;
}
aura::Window* AshFocusRules::GetTopmostWindowToActivateInContainer(
aura::Window* container,
aura::Window* ignore) const {
for (aura::Window::Windows::const_reverse_iterator i =
container->children().rbegin();
i != container->children().rend();
++i) {
WindowState* window_state = GetWindowState(*i);
if (*i != ignore &&
window_state->CanActivate() &&
!window_state->IsMinimized())
return *i;
}
return NULL;
}
}
}