| Index: athena/wm/window_manager_impl.cc
|
| diff --git a/athena/wm/window_manager_impl.cc b/athena/wm/window_manager_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d1e2b155bcd9b0722f67b7a0ce5523fb99b7a20f
|
| --- /dev/null
|
| +++ b/athena/wm/window_manager_impl.cc
|
| @@ -0,0 +1,132 @@
|
| +// Copyright 2014 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 "athena/wm/public/window_manager.h"
|
| +
|
| +#include "athena/screen/public/screen_manager.h"
|
| +#include "base/logging.h"
|
| +#include "ui/aura/client/window_tree_client.h"
|
| +#include "ui/aura/layout_manager.h"
|
| +#include "ui/aura/window.h"
|
| +
|
| +namespace athena {
|
| +namespace {
|
| +
|
| +class WindowManagerImpl : public WindowManager {
|
| + public:
|
| + WindowManagerImpl();
|
| + virtual ~WindowManagerImpl();
|
| +
|
| + void OnWindowAdded(aura::Window* window);
|
| + void OnWindowRemoved(aura::Window* window);
|
| + void Layout();
|
| +
|
| + private:
|
| + aura::Window* container_;
|
| + scoped_ptr<aura::client::WindowTreeClient> window_tree_client_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl);
|
| +};
|
| +
|
| +class WindowManagerImpl* instance = NULL;
|
| +
|
| +class AthenaContainerLayoutManager : public aura::LayoutManager {
|
| + public:
|
| + AthenaContainerLayoutManager() {}
|
| +
|
| + // aura::LayoutManager:
|
| + virtual void OnWindowResized() OVERRIDE { instance->Layout(); }
|
| + virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
|
| + instance->OnWindowAdded(child);
|
| + }
|
| + virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
|
| + virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
|
| + instance->OnWindowRemoved(child);
|
| + }
|
| + virtual void OnChildWindowVisibilityChanged(aura::Window* child,
|
| + bool visible) OVERRIDE {
|
| + instance->Layout();
|
| + }
|
| + virtual void SetChildBounds(aura::Window* child,
|
| + const gfx::Rect& requested_bounds) OVERRIDE {
|
| + if (!requested_bounds.IsEmpty())
|
| + SetChildBoundsDirect(child, requested_bounds);
|
| + }
|
| +
|
| + private:
|
| + WindowManager* window_manager_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager);
|
| +};
|
| +
|
| +class AthenaWindowTreeClient : public aura::client::WindowTreeClient {
|
| + public:
|
| + AthenaWindowTreeClient(aura::Window* container) : container_(container) {
|
| + container_->SetLayoutManager(new AthenaContainerLayoutManager);
|
| + }
|
| +
|
| + private:
|
| + virtual ~AthenaWindowTreeClient() {}
|
| +
|
| + // aura::client::WindowTreeClient:
|
| + virtual aura::Window* GetDefaultParent(aura::Window* context,
|
| + aura::Window* window,
|
| + const gfx::Rect& bounds) OVERRIDE {
|
| + return container_;
|
| + }
|
| +
|
| + aura::Window* container_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AthenaWindowTreeClient);
|
| +};
|
| +
|
| +WindowManagerImpl::WindowManagerImpl()
|
| + : container_(ScreenManager::Get()->GetContainerWindow()),
|
| + window_tree_client_(new AthenaWindowTreeClient(container_)) {
|
| + instance = this;
|
| + aura::client::SetWindowTreeClient(
|
| + ScreenManager::Get()->GetContainerWindow(), window_tree_client_.get());
|
| +}
|
| +
|
| +WindowManagerImpl::~WindowManagerImpl() {
|
| + instance = NULL;
|
| + aura::client::SetWindowTreeClient(
|
| + ScreenManager::Get()->GetContainerWindow(), NULL);
|
| +}
|
| +
|
| +void WindowManagerImpl::Layout() {
|
| + gfx::Rect bounds = gfx::Rect(container_->bounds().size());
|
| + bounds.Inset(10, 10, 10, 10);
|
| + const aura::Window::Windows& children = container_->children();
|
| + for (aura::Window::Windows::const_iterator iter = children.begin();
|
| + iter != children.end();
|
| + ++iter) {
|
| + (*iter)->SetBounds(bounds);
|
| + }
|
| +}
|
| +
|
| +void WindowManagerImpl::OnWindowAdded(aura::Window* child) {
|
| +}
|
| +
|
| +void WindowManagerImpl::OnWindowRemoved(aura::Window* child) {
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +WindowManager* WindowManager::Create() {
|
| + DCHECK(!instance);
|
| + new WindowManagerImpl;
|
| + DCHECK(instance);
|
| + return instance;
|
| +}
|
| +
|
| +// static
|
| +void WindowManager::Shutdown() {
|
| + DCHECK(instance);
|
| + delete instance;
|
| + DCHECK(!instance);
|
| +}
|
| +
|
| +} // namespace athena
|
|
|