summaryrefslogtreecommitdiff
path: root/athena/screen
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2014-06-03 10:58:34 +0100
committerTorne (Richard Coles) <torne@google.com>2014-06-03 10:58:34 +0100
commitcedac228d2dd51db4b79ea1e72c7f249408ee061 (patch)
treeaa4ff43d7fe316e95d12721ce5e17653a768a0dd /athena/screen
parent6a869ecff032b5bed299d661b078b0555034598b (diff)
downloadchromium_org-cedac228d2dd51db4b79ea1e72c7f249408ee061.tar.gz
Merge from Chromium at DEPS revision 273901
This commit was generated by merge_to_master.py. Change-Id: I45745444894df927ffc1045ab8de88b9e52636a3
Diffstat (limited to 'athena/screen')
-rw-r--r--athena/screen/DEPS6
-rw-r--r--athena/screen/background_controller.cc72
-rw-r--r--athena/screen/background_controller.h36
-rw-r--r--athena/screen/public/DEPS4
-rw-r--r--athena/screen/public/screen_manager.h51
-rw-r--r--athena/screen/screen_manager_impl.cc169
6 files changed, 338 insertions, 0 deletions
diff --git a/athena/screen/DEPS b/athena/screen/DEPS
new file mode 100644
index 0000000000..08856b1c42
--- /dev/null
+++ b/athena/screen/DEPS
@@ -0,0 +1,6 @@
+include_rules = [
+ "+ui/aura",
+ "+ui/compositor",
+ "+ui/gfx",
+ "+ui/views",
+]
diff --git a/athena/screen/background_controller.cc b/athena/screen/background_controller.cc
new file mode 100644
index 0000000000..53cf3e2491
--- /dev/null
+++ b/athena/screen/background_controller.cc
@@ -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
diff --git a/athena/screen/background_controller.h b/athena/screen/background_controller.h
new file mode 100644
index 0000000000..cdc0d358fb
--- /dev/null
+++ b/athena/screen/background_controller.h
@@ -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_
diff --git a/athena/screen/public/DEPS b/athena/screen/public/DEPS
new file mode 100644
index 0000000000..105352506c
--- /dev/null
+++ b/athena/screen/public/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "-athena/screen",
+ "+athena/athena_export.h",
+]
diff --git a/athena/screen/public/screen_manager.h b/athena/screen/public/screen_manager.h
new file mode 100644
index 0000000000..c2914fe88f
--- /dev/null
+++ b/athena/screen/public/screen_manager.h
@@ -0,0 +1,51 @@
+// 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 <string>
+
+#include "athena/athena_export.h"
+
+namespace aura {
+class Window;
+}
+
+namespace gfx {
+class ImageSkia;
+}
+
+namespace athena {
+
+// 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
+ // implementation.
+ static ScreenManager* Create(aura::Window* root);
+ static ScreenManager* Get();
+ static void Shutdown();
+
+ virtual ~ScreenManager() {}
+
+ // 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;
+
+ // Sets the background image.
+ virtual void SetBackgroundImage(const gfx::ImageSkia& image) = 0;
+};
+
+} // namespace athena
+
+#endif // ATHENA_SCREEN_PUBLIC_SCREEN_MANAGER_H_
diff --git a/athena/screen/screen_manager_impl.cc b/athena/screen/screen_manager_impl.cc
new file mode 100644
index 0000000000..ca3101a769
--- /dev/null
+++ b/athena/screen/screen_manager_impl.cc
@@ -0,0 +1,169 @@
+// 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* 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);
+ 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* 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_;
+ 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_ =
+ CreateContainerInternal(root_window_, "AthenaBackground");
+ background_window_->SetLayoutManager(
+ new FillLayoutManager(background_window_));
+ background_controller_.reset(new BackgroundController(background_window_));
+}
+
+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) {
+ 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