Commit 3397a04e authored by oshima@chromium.org's avatar oshima@chromium.org

Add initial home card impl.

BUG=362288

Review URL: https://codereview.chromium.org/287253003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272681 0039d316-1c4b-4281-b951-d872f2087c98
parent f7280b45
......@@ -22,8 +22,12 @@
'sources': [
# All .cc, .h under athena, except unittests
'athena_export.h',
'screen/background_controller.h',
'home/home_card_delegate_view.cc',
'home/home_card_delegate_view.h',
'home/home_card_impl.cc',
'home/public/home_card.h',
'screen/background_controller.cc',
'screen/background_controller.h',
'screen/public/screen_manager.h',
'screen/screen_manager_impl.cc',
'wm/public/window_manager.h',
......
include_rules = [
"+athena/screen/public",
"+ui/aura",
"+ui/views",
"+ui/wm/core",
]
// 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/home/home_card_delegate_view.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/widget/widget.h"
namespace athena {
HomeCardDelegateView::HomeCardDelegateView() {
const SkColor kHomeTopColor = 0xDDFFFFFF;
const SkColor kHomeBottomColor = 0xAAEEEEEE;
const SkColor kHomeBorderColor = 0xDDFFFFFF;
set_background(views::Background::CreateVerticalGradientBackground(
kHomeTopColor, kHomeBottomColor));
scoped_ptr<views::Border> border(
views::Border::CreateSolidBorder(5, kHomeBorderColor));
SetBorder(border.Pass());
}
HomeCardDelegateView::~HomeCardDelegateView() {
}
void HomeCardDelegateView::OnMouseEvent(ui::MouseEvent* event) {
// Temp code to test animation.
if (event->type() == ui::ET_MOUSE_PRESSED) {
views::Widget* widget = GetWidget();
if (widget->IsVisible())
widget->Hide();
}
}
void HomeCardDelegateView::DeleteDelegate() {
delete this;
}
views::Widget* HomeCardDelegateView::GetWidget() {
return views::View::GetWidget();
}
const views::Widget* HomeCardDelegateView::GetWidget() const {
return views::View::GetWidget();
}
views::View* HomeCardDelegateView::GetContentsView() {
return this;
}
} // namespace athena
// 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_HOME_HOME_CARD_DELEGATE_VIEW_H_
#define ATHENA_HOME_HOME_CARD_DELEGATE_VIEW_H_
#include "ui/views/view.h"
#include "ui/views/widget/widget_delegate.h"
namespace athena {
class HomeCardDelegateView : public views::WidgetDelegate, public views::View {
public:
HomeCardDelegateView();
virtual ~HomeCardDelegateView();
private:
// views::View
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
// views::WidgetDelegate:
virtual void DeleteDelegate() OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
virtual const views::Widget* GetWidget() const OVERRIDE;
virtual views::View* GetContentsView() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(HomeCardDelegateView);
};
} // namespace athena
#endif // ATHENA_HOME_HOME_CARD_DELEGATE_VIEW_H_
// 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/home/public/home_card.h"
#include "athena/home/home_card_delegate_view.h"
#include "athena/screen/public/screen_manager.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/visibility_controller.h"
#include "ui/wm/core/window_animations.h"
namespace athena {
namespace {
HomeCard* instance = NULL;
class HomeCardLayoutManager : public aura::LayoutManager {
public:
explicit HomeCardLayoutManager(aura::Window* container)
: container_(container) {}
virtual ~HomeCardLayoutManager() {}
private:
// aura::LayoutManager:
virtual void OnWindowResized() OVERRIDE { Layout(); }
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); }
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
Layout();
}
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) OVERRIDE {
Layout();
}
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE {
SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size()));
}
void Layout() {
const int kHomeCardHeight = 50;
const int kHomeCardHorizontalMargin = 50;
if (container_->children().size() < 1)
return;
aura::Window* home_card = container_->children()[0];
if (!home_card->IsVisible())
return;
gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds();
gfx::Rect card_bounds = screen_bounds;
card_bounds.Inset(kHomeCardHorizontalMargin,
screen_bounds.height() - kHomeCardHeight,
kHomeCardHorizontalMargin,
0);
SetChildBoundsDirect(home_card, card_bounds);
}
aura::Window* container_;
DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
};
class HomeCardImpl : public HomeCard {
public:
HomeCardImpl();
virtual ~HomeCardImpl();
void Init();
private:
views::Widget* home_card_widget_;
DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
};
HomeCardImpl::HomeCardImpl() : home_card_widget_(NULL) {
DCHECK(!instance);
instance = this;
}
HomeCardImpl::~HomeCardImpl() {
DCHECK(instance);
home_card_widget_->CloseNow();
instance = NULL;
}
void HomeCardImpl::Init() {
aura::Window* container =
ScreenManager::Get()->CreateContainer("HomeCardContainer");
container->SetLayoutManager(new HomeCardLayoutManager(container));
wm::SetChildWindowVisibilityChangesAnimated(container);
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.delegate = new HomeCardDelegateView();
params.parent = container;
home_card_widget_ = new views::Widget;
home_card_widget_->Init(params);
home_card_widget_->GetNativeView()->SetName("HomeCardWidget");
aura::Window* home_card_window = home_card_widget_->GetNativeView();
wm::SetWindowVisibilityAnimationType(
home_card_window, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
wm::SetWindowVisibilityAnimationTransition(home_card_window,
wm::ANIMATE_BOTH);
home_card_widget_->Show();
}
} // namespace
// static
HomeCard* HomeCard::Create() {
(new HomeCardImpl())->Init();
DCHECK(instance);
return instance;
}
// static
void HomeCard::Shutdown() {
DCHECK(instance);
delete instance;
instance = NULL;
}
} // namespace athena
include_rules = [
"-athena/home",
"+athena/athena_export.h",
]
// 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_HOME_PUBLIC_HOME_CARD_H_
#define ATHENA_HOME_PUBLIC_HOME_CARD_H_
#include "athena/athena_export.h"
namespace athena {
class ATHENA_EXPORT HomeCard {
public:
// Creates and deletes the singleton object of the HomeCard
// implementation.
static HomeCard* Create();
static void Shutdown();
virtual ~HomeCard() {}
};
} // namespace athena
#endif // ATHENA_HOME_PUBLIC_HOME_CARD_H_
include_rules = [
"+apps/shell/app",
"+apps/shell/browser",
"+athena/home/public",
"+athena/screen/public",
"+athena/wm/public",
"+content/public/app",
"+ui/aura",
"+ui/wm/core",
]
# TODO(oshima): Remove this.
......
......@@ -5,11 +5,14 @@
#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/home/public/home_card.h"
#include "athena/main/placeholder.h"
#include "athena/screen/public/screen_manager.h"
#include "athena/wm/public/window_manager.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/app/content_main.h"
#include "ui/aura/window_tree_host.h"
#include "ui/wm/core/visibility_controller.h"
class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
public:
......@@ -18,20 +21,29 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
// apps::ShellBrowserMainDelegate:
virtual void Start(content::BrowserContext* context) OVERRIDE {
athena::ScreenManager::Create(apps::ShellDesktopController::instance()
->GetWindowTreeHost()
->window());
aura::Window* root_window =
apps::ShellDesktopController::instance()->GetWindowTreeHost()->window();
visibility_controller_.reset(new ::wm::VisibilityController);
aura::client::SetVisibilityClient(root_window,
visibility_controller_.get());
athena::ScreenManager::Create(root_window);
athena::WindowManager::Create();
athena::HomeCard::Create();
SetupBackgroundImage();
CreateTestWindows();
}
virtual void Shutdown() OVERRIDE {
athena::HomeCard::Shutdown();
athena::WindowManager::Shutdown();
athena::ScreenManager::Shutdown();
visibility_controller_.reset();
}
scoped_ptr< ::wm::VisibilityController> visibility_controller_;
private:
DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate);
};
......
......@@ -16,6 +16,7 @@
#include "ui/views/widget/widget.h"
void CreateTestWindows() {
const int kAppWindowBackgroundColor = 0xFFDDDDDD;
views::Widget* test_app_widget = new views::Widget;
// Athena doesn't have frame yet.
views::Widget::InitParams params(
......@@ -25,7 +26,7 @@ void CreateTestWindows() {
views::Label* label = new views::Label;
label->SetText(base::ASCIIToUTF16("AppWindow"));
label->set_background(
views::Background::CreateSolidBackground(SK_ColorWHITE));
views::Background::CreateSolidBackground(kAppWindowBackgroundColor));
test_app_widget->SetContentsView(label);
test_app_widget->Show();
}
......
......@@ -5,6 +5,8 @@
#ifndef ATHENA_SCREEN_PUBLIC_SCREEN_MANAGER_H_
#define ATHENA_SCREEN_PUBLIC_SCREEN_MANAGER_H_
#include <string>
#include "athena/athena_export.h"
namespace aura {
......@@ -17,8 +19,9 @@ class ImageSkia;
namespace athena {
// Mananges screen and UI components on the screen such as background,
// home card, etc.
// Mananges basic UI components on the screen such as background, and provide
// API for other UI components, such as window manager, home card, to
// create and manage their windows on the screen.
class ATHENA_EXPORT ScreenManager {
public:
// Creates, returns and deletes the singleton object of the ScreenManager
......@@ -29,8 +32,12 @@ class ATHENA_EXPORT ScreenManager {
virtual ~ScreenManager() {}
// Returns the container window for window on the screen.
virtual aura::Window* GetContainerWindow() = 0;
// Creates the container window that is used when creating a normal
// widget without specific parent.
virtual aura::Window* CreateDefaultContainer(const std::string& name) = 0;
// Creates the container window on the screen.
virtual aura::Window* CreateContainer(const std::string& name) = 0;
// Return the context object to be used for widget creation.
virtual aura::Window* GetContext() = 0;
......
......@@ -73,7 +73,8 @@ class AthenaWindowTreeClient : public aura::client::WindowTreeClient {
DISALLOW_COPY_AND_ASSIGN(AthenaWindowTreeClient);
};
aura::Window* CreateContainer(aura::Window* parent, const std::string& name) {
aura::Window* CreateContainerInternal(aura::Window* parent,
const std::string& name) {
aura::Window* container = new aura::Window(NULL);
container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
container->SetName(name);
......@@ -90,15 +91,16 @@ class ScreenManagerImpl : public ScreenManager {
void Init();
private:
// Screenmanager:
virtual aura::Window* GetContainerWindow() OVERRIDE { return container_; }
// ScreenManager:
virtual aura::Window* CreateDefaultContainer(
const std::string& name) OVERRIDE;
virtual aura::Window* CreateContainer(const std::string& name) OVERRIDE;
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_;
......@@ -107,14 +109,23 @@ class ScreenManagerImpl : public ScreenManager {
void ScreenManagerImpl::Init() {
root_window_->SetLayoutManager(new FillLayoutManager(root_window_));
background_window_ = CreateContainer(root_window_, "AthenaBackground");
background_window_ =
CreateContainerInternal(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::Window* ScreenManagerImpl::CreateDefaultContainer(
const std::string& name) {
aura::Window* container = CreateContainerInternal(root_window_, name);
window_tree_client_.reset(new AthenaWindowTreeClient(container));
aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get());
return container;
}
aura::Window* ScreenManagerImpl::CreateContainer(const std::string& name) {
return CreateContainerInternal(root_window_, name);
}
void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) {
......
......@@ -12,7 +12,7 @@
namespace athena {
namespace {
class WindowManagerImpl : public WindowManager {
class WindowManagerImpl : public WindowManager, public aura::WindowObserver {
public:
WindowManagerImpl();
virtual ~WindowManagerImpl();
......@@ -20,7 +20,13 @@ class WindowManagerImpl : public WindowManager {
void Layout();
private:
aura::Window* container_;
// aura::WindowObserver
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
if (window == container_)
container_.reset();
}
scoped_ptr<aura::Window> container_;
DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl);
};
......@@ -56,16 +62,23 @@ class AthenaContainerLayoutManager : public aura::LayoutManager {
};
WindowManagerImpl::WindowManagerImpl()
: container_(ScreenManager::Get()->GetContainerWindow()) {
: container_(
ScreenManager::Get()->CreateDefaultContainer("MainContainer")) {
container_->SetLayoutManager(new AthenaContainerLayoutManager);
container_->AddObserver(this);
instance = this;
}
WindowManagerImpl::~WindowManagerImpl() {
if (container_)
container_->RemoveObserver(this);
container_.reset();
instance = NULL;
}
void WindowManagerImpl::Layout() {
if (!container_)
return;
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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment