[Athena] minimum impl to add screen/background and test windows
This sets the standard directory structure for Athena. BUG=362288 Review URL: https://codereview.chromium.org/287163009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271561 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
35
athena/athena.gyp
Normal file
35
athena/athena.gyp
Normal file
@ -0,0 +1,35 @@
|
||||
# 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.
|
||||
|
||||
{
|
||||
'variables': {
|
||||
'chromium_code': 1,
|
||||
},
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'athena_lib',
|
||||
'type': '<(component)',
|
||||
'dependencies': [
|
||||
'../ui/aura/aura.gyp:aura',
|
||||
'../ui/views/views.gyp:views',
|
||||
'../ui/accessibility/accessibility.gyp:ax_gen',
|
||||
'../skia/skia.gyp:skia',
|
||||
],
|
||||
'defines': [
|
||||
'ATHENA_IMPLEMENTATION',
|
||||
],
|
||||
'sources': [
|
||||
# All .cc, .h under athena, except unittests
|
||||
'athena_export.h',
|
||||
'screen/background_controller.h',
|
||||
'screen/background_controller.cc',
|
||||
'screen/public/screen_manager.h',
|
||||
'screen/screen_manager_impl.cc',
|
||||
'wm/public/window_manager.h',
|
||||
'wm/window_manager_impl.cc',
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
32
athena/athena_export.h
Normal file
32
athena/athena_export.h
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.
|
||||
|
||||
#ifndef ATHENA_ATHENA_EXPORT_H_
|
||||
#define ATHENA_ATHENA_EXPORT_H_
|
||||
|
||||
// Defines ATHENA_EXPORT so that functionality implemented by the ATHENA module
|
||||
// can be exported to consumers.
|
||||
|
||||
#if defined(COMPONENT_BUILD)
|
||||
#if defined(WIN32)
|
||||
|
||||
#if defined(ATHENA_IMPLEMENTATION)
|
||||
#define ATHENA_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define ATHENA_EXPORT __declspec(dllimport)
|
||||
#endif // defined(ATHENA_IMPLEMENTATION)
|
||||
|
||||
#else // defined(WIN32)
|
||||
#if defined(ATHENA_IMPLEMENTATION)
|
||||
#define ATHENA_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define ATHENA_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else // defined(COMPONENT_BUILD)
|
||||
#define ATHENA_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // ATHENA_ATHENA_EXPORT_H_
|
@ -1,5 +1,18 @@
|
||||
include_rules = [
|
||||
"+apps/shell/app",
|
||||
"+apps/shell/browser",
|
||||
"+athena/screen/public",
|
||||
"+athena/wm/public",
|
||||
"+content/public/app",
|
||||
"+ui/aura",
|
||||
]
|
||||
|
||||
# TODO(oshima): Remove this.
|
||||
specific_include_rules = {
|
||||
"placeholder\.*": [
|
||||
"+third_party/skia",
|
||||
"+ui/gfx",
|
||||
"+ui/views",
|
||||
],
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,12 @@
|
||||
|
||||
#include "apps/shell/app/shell_main_delegate.h"
|
||||
#include "apps/shell/browser/shell_browser_main_delegate.h"
|
||||
#include "apps/shell/browser/shell_desktop_controller.h"
|
||||
#include "athena/main/placeholder.h"
|
||||
#include "athena/screen/public/screen_manager.h"
|
||||
#include "athena/wm/public/window_manager.h"
|
||||
#include "content/public/app/content_main.h"
|
||||
#include "ui/aura/window_tree_host.h"
|
||||
|
||||
class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
|
||||
public:
|
||||
@ -12,8 +17,20 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
|
||||
virtual ~AthenaBrowserMainDelegate() {}
|
||||
|
||||
// apps::ShellBrowserMainDelegate:
|
||||
virtual void Start(content::BrowserContext* context) OVERRIDE {}
|
||||
virtual void Shutdown() OVERRIDE {}
|
||||
virtual void Start(content::BrowserContext* context) OVERRIDE {
|
||||
athena::ScreenManager::Create(apps::ShellDesktopController::instance()
|
||||
->GetWindowTreeHost()
|
||||
->window());
|
||||
athena::WindowManager::Create();
|
||||
|
||||
SetupBackgroundImage();
|
||||
CreateTestWindows();
|
||||
}
|
||||
|
||||
virtual void Shutdown() OVERRIDE {
|
||||
athena::WindowManager::Shutdown();
|
||||
athena::ScreenManager::Shutdown();
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate);
|
||||
|
@ -11,13 +11,19 @@
|
||||
'target_name': 'athena_main',
|
||||
'type': 'executable',
|
||||
'dependencies': [
|
||||
'../athena.gyp:athena_lib',
|
||||
'../../apps/shell/app_shell.gyp:app_shell_lib',
|
||||
'../../skia/skia.gyp:skia',
|
||||
'../../ui/accessibility/accessibility.gyp:ax_gen',
|
||||
'../../ui/views/views.gyp:views',
|
||||
],
|
||||
'include_dirs': [
|
||||
'../..',
|
||||
],
|
||||
'sources': [
|
||||
'athena_main.cc',
|
||||
'placeholder.cc',
|
||||
'placeholder.h',
|
||||
],
|
||||
},
|
||||
], # targets
|
||||
|
41
athena/main/placeholder.cc
Normal file
41
athena/main/placeholder.cc
Normal file
@ -0,0 +1,41 @@
|
||||
// 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/main/placeholder.h"
|
||||
|
||||
#include "athena/screen/public/screen_manager.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "ui/gfx/canvas.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
#include "ui/views/background.h"
|
||||
#include "ui/views/controls/label.h"
|
||||
#include "ui/views/painter.h"
|
||||
#include "ui/views/widget/widget.h"
|
||||
|
||||
void CreateTestWindows() {
|
||||
views::Widget* test_app_widget = new views::Widget;
|
||||
// Athena doesn't have frame yet.
|
||||
views::Widget::InitParams params(
|
||||
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
|
||||
params.context = athena::ScreenManager::Get()->GetContext();
|
||||
test_app_widget->Init(params);
|
||||
views::Label* label = new views::Label;
|
||||
label->SetText(base::ASCIIToUTF16("AppWindow"));
|
||||
label->set_background(
|
||||
views::Background::CreateSolidBackground(SK_ColorWHITE));
|
||||
test_app_widget->SetContentsView(label);
|
||||
test_app_widget->Show();
|
||||
}
|
||||
|
||||
void SetupBackgroundImage() {
|
||||
gfx::Size size(200, 200);
|
||||
gfx::Canvas canvas(size, 1.0f, true);
|
||||
scoped_ptr<views::Painter> painter(
|
||||
views::Painter::CreateVerticalGradient(SK_ColorBLUE, SK_ColorCYAN));
|
||||
painter->Paint(&canvas, size);
|
||||
athena::ScreenManager::Get()->SetBackgroundImage(
|
||||
gfx::ImageSkia(canvas.ExtractImageRep()));
|
||||
}
|
14
athena/main/placeholder.h
Normal file
14
athena/main/placeholder.h
Normal file
@ -0,0 +1,14 @@
|
||||
// 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.
|
||||
|
||||
#ifndef ATHENA_MAIN_PLACEHOLDER_H_
|
||||
#define ATHENA_MAIN_PLACEHOLDER_H_
|
||||
|
||||
// This is to create a dummy windows until we have a real app / web windows.
|
||||
void CreateTestWindows();
|
||||
|
||||
// Set up a placeholder image to the screen background.
|
||||
void SetupBackgroundImage();
|
||||
|
||||
#endif // ATHENA_MAIN_PLACEHOLDER_H_
|
6
athena/screen/DEPS
Normal file
6
athena/screen/DEPS
Normal file
@ -0,0 +1,6 @@
|
||||
include_rules = [
|
||||
"+ui/aura",
|
||||
"+ui/compositor",
|
||||
"+ui/gfx",
|
||||
"+ui/views",
|
||||
]
|
72
athena/screen/background_controller.cc
Normal file
72
athena/screen/background_controller.cc
Normal file
@ -0,0 +1,72 @@
|
||||
// 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/screen/background_controller.h"
|
||||
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/gfx/canvas.h"
|
||||
#include "ui/gfx/image/image_skia.h"
|
||||
#include "ui/views/view.h"
|
||||
#include "ui/views/widget/widget.h"
|
||||
|
||||
namespace athena {
|
||||
|
||||
class BackgroundView : public views::View {
|
||||
public:
|
||||
BackgroundView() {}
|
||||
virtual ~BackgroundView() {}
|
||||
|
||||
void SetImage(const gfx::ImageSkia& image) {
|
||||
image_ = image;
|
||||
SchedulePaint();
|
||||
}
|
||||
|
||||
// views::View
|
||||
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
|
||||
canvas->DrawImageInt(image_,
|
||||
0,
|
||||
0,
|
||||
image_.width(),
|
||||
image_.height(),
|
||||
0,
|
||||
0,
|
||||
width(),
|
||||
height(),
|
||||
true);
|
||||
}
|
||||
|
||||
private:
|
||||
gfx::ImageSkia image_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BackgroundView);
|
||||
};
|
||||
|
||||
BackgroundController::BackgroundController(aura::Window* container) {
|
||||
// TODO(oshima): Using widget to just draw an image is probably
|
||||
// overkill. Just use WindowDelegate to draw the background and
|
||||
// remove dependency to ui/views.
|
||||
|
||||
views::Widget* background_widget = new views::Widget;
|
||||
views::Widget::InitParams params(
|
||||
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
|
||||
params.parent = container;
|
||||
background_widget->Init(params);
|
||||
background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true);
|
||||
background_view_ = new BackgroundView;
|
||||
background_widget->SetContentsView(background_view_);
|
||||
background_widget->Show();
|
||||
}
|
||||
|
||||
BackgroundController::~BackgroundController() {
|
||||
// background_widget is owned by the container and will be deleted
|
||||
// when the container is deleted.
|
||||
}
|
||||
|
||||
void BackgroundController::SetImage(const gfx::ImageSkia& image) {
|
||||
// TODO(oshima): implement cross fede animation.
|
||||
background_view_->SetImage(image);
|
||||
}
|
||||
|
||||
} // namespace athena
|
36
athena/screen/background_controller.h
Normal file
36
athena/screen/background_controller.h
Normal file
@ -0,0 +1,36 @@
|
||||
// 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.
|
||||
|
||||
#ifndef ATHENA_SCREEN_BACKGROUND_CONTROLLER_H_
|
||||
#define ATHENA_SCREEN_BACKGROUND_CONTROLLER_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
|
||||
namespace aura {
|
||||
class Window;
|
||||
}
|
||||
|
||||
namespace gfx {
|
||||
class ImageSkia;
|
||||
}
|
||||
|
||||
namespace athena {
|
||||
class BackgroundView;
|
||||
|
||||
// Controls background image switching.
|
||||
class BackgroundController {
|
||||
public:
|
||||
explicit BackgroundController(aura::Window* container);
|
||||
~BackgroundController();
|
||||
|
||||
void SetImage(const gfx::ImageSkia& image);
|
||||
|
||||
private:
|
||||
BackgroundView* background_view_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BackgroundController);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ATHENA_SCREEN_BACKGROUND_CONTROLLER_H_
|
4
athena/screen/public/DEPS
Normal file
4
athena/screen/public/DEPS
Normal file
@ -0,0 +1,4 @@
|
||||
include_rules = [
|
||||
"-athena/screen",
|
||||
"+athena/athena_export.h",
|
||||
]
|
44
athena/screen/public/screen_manager.h
Normal file
44
athena/screen/public/screen_manager.h
Normal file
@ -0,0 +1,44 @@
|
||||
// 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.
|
||||
|
||||
#ifndef ATHENA_SCREEN_PUBLIC_SCREEN_MANAGER_H_
|
||||
#define ATHENA_SCREEN_PUBLIC_SCREEN_MANAGER_H_
|
||||
|
||||
#include "athena/athena_export.h"
|
||||
|
||||
namespace aura {
|
||||
class Window;
|
||||
}
|
||||
|
||||
namespace gfx {
|
||||
class ImageSkia;
|
||||
}
|
||||
|
||||
namespace athena {
|
||||
|
||||
// Mananges screen and UI components on the screen such as background,
|
||||
// home card, etc.
|
||||
class ATHENA_EXPORT ScreenManager {
|
||||
public:
|
||||
// Creates, returns and deletes the singleton object of the ScreenManager
|
||||
// implementation.
|
||||
static ScreenManager* Create(aura::Window* root);
|
||||
static ScreenManager* Get();
|
||||
static void Shutdown();
|
||||
|
||||
virtual ~ScreenManager() {}
|
||||
|
||||
// Returns the container window for window on the screen.
|
||||
virtual aura::Window* GetContainerWindow() = 0;
|
||||
|
||||
// Return the context object to be used for widget creation.
|
||||
virtual aura::Window* GetContext() = 0;
|
||||
|
||||
// Sets the background image.
|
||||
virtual void SetBackgroundImage(const gfx::ImageSkia& image) = 0;
|
||||
};
|
||||
|
||||
} // namespace athena
|
||||
|
||||
#endif // ATHENA_SCREEN_PUBLIC_SCREEN_MANAGER_H_
|
158
athena/screen/screen_manager_impl.cc
Normal file
158
athena/screen/screen_manager_impl.cc
Normal file
@ -0,0 +1,158 @@
|
||||
// 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/screen/public/screen_manager.h"
|
||||
|
||||
#include "athena/screen/background_controller.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "ui/aura/client/window_tree_client.h"
|
||||
#include "ui/aura/layout_manager.h"
|
||||
#include "ui/aura/window.h"
|
||||
|
||||
namespace athena {
|
||||
namespace {
|
||||
|
||||
ScreenManager* instance = NULL;
|
||||
|
||||
// TODO(oshima): There seems to be a couple of private implementation which does
|
||||
// the same.
|
||||
// Consider consolidating and reuse it.
|
||||
class FillLayoutManager : public aura::LayoutManager {
|
||||
public:
|
||||
explicit FillLayoutManager(aura::Window* container) : container_(container) {
|
||||
DCHECK(container_);
|
||||
}
|
||||
|
||||
// aura::LayoutManager:
|
||||
virtual void OnWindowResized() OVERRIDE {
|
||||
gfx::Rect full_bounds = gfx::Rect(container_->bounds().size());
|
||||
for (aura::Window::Windows::const_iterator iter =
|
||||
container_->children().begin();
|
||||
iter != container_->children().end();
|
||||
++iter) {
|
||||
SetChildBoundsDirect(*iter, full_bounds);
|
||||
}
|
||||
}
|
||||
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
|
||||
SetChildBoundsDirect(child, (gfx::Rect(container_->bounds().size())));
|
||||
}
|
||||
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
|
||||
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
|
||||
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
|
||||
bool visible) OVERRIDE {}
|
||||
virtual void SetChildBounds(aura::Window* child,
|
||||
const gfx::Rect& requested_bounds) OVERRIDE {
|
||||
// Ignore SetBounds request.
|
||||
}
|
||||
|
||||
private:
|
||||
aura::Window* container_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FillLayoutManager);
|
||||
};
|
||||
|
||||
class AthenaWindowTreeClient : public aura::client::WindowTreeClient {
|
||||
public:
|
||||
explicit AthenaWindowTreeClient(aura::Window* container)
|
||||
: container_(container) {}
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
aura::Window* CreateContainer(aura::Window* parent, const std::string& name) {
|
||||
aura::Window* container = new aura::Window(NULL);
|
||||
container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
|
||||
container->SetName(name);
|
||||
parent->AddChild(container);
|
||||
container->Show();
|
||||
return container;
|
||||
}
|
||||
|
||||
class ScreenManagerImpl : public ScreenManager {
|
||||
public:
|
||||
explicit ScreenManagerImpl(aura::Window* root_window);
|
||||
virtual ~ScreenManagerImpl();
|
||||
|
||||
void Init();
|
||||
|
||||
private:
|
||||
// Screenmanager:
|
||||
virtual aura::Window* GetContainerWindow() OVERRIDE { return container_; }
|
||||
virtual aura::Window* GetContext() OVERRIDE { return root_window_; }
|
||||
virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||
|
||||
aura::Window* root_window_;
|
||||
// A container used for apps/web windows.
|
||||
aura::Window* container_;
|
||||
aura::Window* background_window_;
|
||||
scoped_ptr<BackgroundController> background_controller_;
|
||||
scoped_ptr<aura::client::WindowTreeClient> window_tree_client_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl);
|
||||
};
|
||||
|
||||
void ScreenManagerImpl::Init() {
|
||||
root_window_->SetLayoutManager(new FillLayoutManager(root_window_));
|
||||
background_window_ = CreateContainer(root_window_, "AthenaBackground");
|
||||
background_window_->SetLayoutManager(
|
||||
new FillLayoutManager(background_window_));
|
||||
background_controller_.reset(new BackgroundController(background_window_));
|
||||
container_ = CreateContainer(root_window_, "AthenaContainer");
|
||||
|
||||
window_tree_client_.reset(new AthenaWindowTreeClient(container_));
|
||||
aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get());
|
||||
}
|
||||
|
||||
void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) {
|
||||
background_controller_->SetImage(image);
|
||||
}
|
||||
|
||||
ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window)
|
||||
: root_window_(root_window) {
|
||||
DCHECK(root_window_);
|
||||
DCHECK(!instance);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
ScreenManagerImpl::~ScreenManagerImpl() {
|
||||
aura::client::SetWindowTreeClient(root_window_, NULL);
|
||||
instance = NULL;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
ScreenManager* ScreenManager::Create(aura::Window* root_window) {
|
||||
(new ScreenManagerImpl(root_window))->Init();
|
||||
DCHECK(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
// static
|
||||
ScreenManager* ScreenManager::Get() {
|
||||
DCHECK(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
// static
|
||||
void ScreenManager::Shutdown() {
|
||||
DCHECK(instance);
|
||||
delete instance;
|
||||
DCHECK(!instance);
|
||||
}
|
||||
|
||||
} // namespace athena
|
4
athena/wm/DEPS
Normal file
4
athena/wm/DEPS
Normal file
@ -0,0 +1,4 @@
|
||||
include_rules = [
|
||||
"+athena/screen/public",
|
||||
"+ui/aura",
|
||||
]
|
4
athena/wm/public/DEPS
Normal file
4
athena/wm/public/DEPS
Normal file
@ -0,0 +1,4 @@
|
||||
include_rules = [
|
||||
"-athena/wm",
|
||||
"+athena/athena_export.h",
|
||||
]
|
25
athena/wm/public/window_manager.h
Normal file
25
athena/wm/public/window_manager.h
Normal file
@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
|
||||
#ifndef ATHENA_SCREEN_PUBLIC_WINDOW_MANAGER_H_
|
||||
#define ATHENA_SCREEN_PUBLIC_WINDOW_MANAGER_H_
|
||||
|
||||
#include "athena/athena_export.h"
|
||||
|
||||
namespace athena {
|
||||
|
||||
// Manages the application, web windows.
|
||||
class ATHENA_EXPORT WindowManager {
|
||||
public:
|
||||
// Creates and deletes the singleton object of the WindowManager
|
||||
// implementation.
|
||||
static WindowManager* Create();
|
||||
static void Shutdown();
|
||||
|
||||
virtual ~WindowManager() {}
|
||||
};
|
||||
|
||||
} // namespace athena
|
||||
|
||||
#endif // ATHENA_SCREEN_PUBLIC_WINDOW_MANAGER_H_
|
97
athena/wm/window_manager_impl.cc
Normal file
97
athena/wm/window_manager_impl.cc
Normal file
@ -0,0 +1,97 @@
|
||||
// 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/layout_manager.h"
|
||||
#include "ui/aura/window.h"
|
||||
|
||||
namespace athena {
|
||||
namespace {
|
||||
|
||||
class WindowManagerImpl : public WindowManager {
|
||||
public:
|
||||
WindowManagerImpl();
|
||||
virtual ~WindowManagerImpl();
|
||||
|
||||
void Layout();
|
||||
|
||||
private:
|
||||
aura::Window* container_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl);
|
||||
};
|
||||
|
||||
class WindowManagerImpl* instance = NULL;
|
||||
|
||||
class AthenaContainerLayoutManager : public aura::LayoutManager {
|
||||
public:
|
||||
AthenaContainerLayoutManager() {}
|
||||
virtual ~AthenaContainerLayoutManager() {}
|
||||
|
||||
private:
|
||||
// aura::LayoutManager:
|
||||
virtual void OnWindowResized() OVERRIDE { instance->Layout(); }
|
||||
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
|
||||
instance->Layout();
|
||||
}
|
||||
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
|
||||
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
|
||||
instance->Layout();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager);
|
||||
};
|
||||
|
||||
WindowManagerImpl::WindowManagerImpl()
|
||||
: container_(ScreenManager::Get()->GetContainerWindow()) {
|
||||
container_->SetLayoutManager(new AthenaContainerLayoutManager);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
WindowManagerImpl::~WindowManagerImpl() {
|
||||
instance = NULL;
|
||||
}
|
||||
|
||||
void WindowManagerImpl::Layout() {
|
||||
gfx::Rect bounds = gfx::Rect(container_->bounds().size());
|
||||
// Just make it small a bit so that the background is visible.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
} // 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
|
Reference in New Issue
Block a user