This source file includes following definitions.
- GetFocusedWindow
- IsWindowConsideredVisibleForActivation
- IsToplevelWindow
- CanActivateWindow
- CanFocusWindow
- GetToplevelWindow
- GetActivatableWindow
- GetFocusableWindow
- GetNextActivatableWindow
#include "ui/wm/core/base_focus_rules.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/wm/core/window_modality_controller.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/public/activation_delegate.h"
namespace wm {
namespace {
aura::Window* GetFocusedWindow(aura::Window* context) {
aura::client::FocusClient* focus_client =
aura::client::GetFocusClient(context);
return focus_client ? focus_client->GetFocusedWindow() : NULL;
}
}
BaseFocusRules::BaseFocusRules() {
}
BaseFocusRules::~BaseFocusRules() {
}
bool BaseFocusRules::IsWindowConsideredVisibleForActivation(
aura::Window* window) const {
return window->IsVisible();
}
bool BaseFocusRules::IsToplevelWindow(aura::Window* window) const {
if (!window->GetRootWindow())
return false;
return SupportsChildActivation(window->parent());
}
bool BaseFocusRules::CanActivateWindow(aura::Window* window) const {
if (!window)
return true;
if (!IsToplevelWindow(window))
return false;
if (!IsWindowConsideredVisibleForActivation(window))
return false;
if (aura::client::GetActivationDelegate(window) &&
!aura::client::GetActivationDelegate(window)->ShouldActivate()) {
return false;
}
if (!window->CanFocus())
return false;
return !GetModalTransient(window);
}
bool BaseFocusRules::CanFocusWindow(aura::Window* window) const {
if (!window)
return true;
aura::Window* activatable = GetActivatableWindow(window);
if (!activatable || !activatable->Contains(window))
return false;
return window->CanFocus();
}
aura::Window* BaseFocusRules::GetToplevelWindow(aura::Window* window) const {
aura::Window* parent = window->parent();
aura::Window* child = window;
while (parent) {
if (IsToplevelWindow(child))
return child;
parent = parent->parent();
child = child->parent();
}
return NULL;
}
aura::Window* BaseFocusRules::GetActivatableWindow(aura::Window* window) const {
aura::Window* parent = window->parent();
aura::Window* child = window;
while (parent) {
if (CanActivateWindow(child))
return child;
aura::Window* modal_transient = GetModalTransient(child);
if (modal_transient)
return GetActivatableWindow(modal_transient);
if (wm::GetTransientParent(child)) {
aura::Window* parent_modal_transient =
GetModalTransient(wm::GetTransientParent(child));
if (parent_modal_transient == child)
return child;
return GetActivatableWindow(wm::GetTransientParent(child));
}
parent = parent->parent();
child = child->parent();
}
return NULL;
}
aura::Window* BaseFocusRules::GetFocusableWindow(aura::Window* window) const {
if (CanFocusWindow(window))
return window;
aura::Window* activatable = GetActivatableWindow(window);
if (!activatable) {
aura::Window* toplevel = GetToplevelWindow(window);
if (toplevel)
activatable = GetNextActivatableWindow(toplevel);
if (!activatable)
return NULL;
}
if (!activatable->Contains(window)) {
aura::Window* focused = GetFocusedWindow(activatable);
return activatable->Contains(focused) ? focused : activatable;
}
while (window && !CanFocusWindow(window))
window = window->parent();
return window;
}
aura::Window* BaseFocusRules::GetNextActivatableWindow(
aura::Window* ignore) const {
DCHECK(ignore);
if (!ignore->parent())
return NULL;
const aura::Window::Windows& siblings = ignore->parent()->children();
DCHECK(!siblings.empty());
for (aura::Window::Windows::const_reverse_iterator rit = siblings.rbegin();
rit != siblings.rend();
++rit) {
aura::Window* cur = *rit;
if (cur == ignore)
continue;
if (CanActivateWindow(cur))
return cur;
}
return NULL;
}
}