diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 20:26:47 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 20:26:47 +0000 |
commit | 6377a003e5948a14cf79bf6433e4c89dbc9354e0 (patch) | |
tree | b84cc5488c90e4b3ef85bba3f61a7613a2d4579d /ui/aura_shell/stacking_controller.cc | |
parent | 90c5032fb8beef603812ac47769184ae526abaf8 (diff) | |
download | chromium_src-6377a003e5948a14cf79bf6433e4c89dbc9354e0.zip chromium_src-6377a003e5948a14cf79bf6433e4c89dbc9354e0.tar.gz chromium_src-6377a003e5948a14cf79bf6433e4c89dbc9354e0.tar.bz2 |
Rid the world of TopLevelWindowContainer, and "toplevel" concept from Window entirely.
- Creates StackingController in aura_shell to manage stacking and implement aura::StackingClient.
- Moves DesktopEventFilter to shell, since it's mostly shell-related anyway.
- Move relevant tests to shell, requiring some refactoring to move test utils around.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8505049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109492 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura_shell/stacking_controller.cc')
-rw-r--r-- | ui/aura_shell/stacking_controller.cc | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/ui/aura_shell/stacking_controller.cc b/ui/aura_shell/stacking_controller.cc new file mode 100644 index 0000000..1371c20 --- /dev/null +++ b/ui/aura_shell/stacking_controller.cc @@ -0,0 +1,95 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/aura_shell/stacking_controller.h" + +#include "ui/aura/desktop.h" +#include "ui/aura/window.h" +#include "ui/aura_shell/shell.h" +#include "ui/aura_shell/shell_window_ids.h" + +namespace aura_shell { +namespace internal { +namespace { + +aura::Window* GetContainer(int id) { + return Shell::GetInstance()->GetContainer(id); +} + +// Returns true if children of |window| can be activated. +bool SupportsChildActivation(aura::Window* window) { + return window->id() == kShellWindowId_DefaultContainer || + window->id() == kShellWindowId_AlwaysOnTopContainer; +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// +// StackingController, public: + +StackingController::StackingController() { + aura::Desktop::GetInstance()->SetStackingClient(this); +} + +StackingController::~StackingController() { +} + +// static +aura::Window* StackingController::GetActivatableWindow(aura::Window* window) { + aura::Window* parent = window->parent(); + aura::Window* child = window; + while (parent) { + if (SupportsChildActivation(parent)) + return child; + parent = parent->parent(); + child = child->parent(); + } + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// StackingController, aura::StackingClient implementation: + +void StackingController::AddChildToDefaultParent(aura::Window* window) { + aura::Window* parent = NULL; + switch (window->type()) { + case aura::WINDOW_TYPE_NORMAL: + case aura::WINDOW_TYPE_POPUP: + parent = GetContainer(internal::kShellWindowId_DefaultContainer); + break; + case aura::WINDOW_TYPE_MENU: + case aura::WINDOW_TYPE_TOOLTIP: + parent = GetContainer(internal::kShellWindowId_MenusAndTooltipsContainer); + break; + default: + NOTREACHED() << "Window " << window->id() + << " has unhandled type " << window->type(); + break; + } + parent->AddChild(window); +} + +bool StackingController::CanActivateWindow(aura::Window* window) const { + return window && SupportsChildActivation(window->parent()); +} + +aura::Window* StackingController::GetTopmostWindowToActivate( + aura::Window* ignore) const { + const aura::Window* container = GetContainer(kShellWindowId_DefaultContainer); + for (aura::Window::Windows::const_reverse_iterator i = + container->children().rbegin(); + i != container->children().rend(); + ++i) { + if (*i != ignore && (*i)->CanActivate()) + return *i; + } + return NULL; +} + + +//////////////////////////////////////////////////////////////////////////////// +// StackingController, private: + +} // namespace internal +} // namespace aura_shell |