Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: athena/screen/screen_manager_impl.cc

Issue 287163009: [Athena] minimum impl to add screen/background and test windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: athena/screen/screen_manager_impl.cc
diff --git a/athena/screen/screen_manager_impl.cc b/athena/screen/screen_manager_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6add3de90d2fd41482a622831fd60f8dffb0f82f
--- /dev/null
+++ b/athena/screen/screen_manager_impl.cc
@@ -0,0 +1,127 @@
+// 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/layout_manager.h"
+#include "ui/aura/window.h"
+
+namespace athena {
+namespace {
+
+class FillLayoutManager : public aura::LayoutManager {
+ public:
+ 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_;
+};
+
+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);
+ virtual ~ScreenManagerImpl();
+
+ virtual aura::Window* GetContainerWindow() OVERRIDE { return container_; }
+ virtual aura::Window* GetContext() OVERRIDE { return root_window_; }
+ virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE;
+
+ void Init();
+
+ private:
+ aura::Window* root_window_;
+ aura::Window* container_;
+ aura::Window* background_window_;
+
+ scoped_ptr<BackgroundController> background_controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl);
+};
+
+void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) {
+ background_controller_->SetImage(image);
+}
+
+void ScreenManagerImpl::Init() {
+ root_window_->SetLayoutManager(new FillLayoutManager(root_window_));
+ background_window_ = CreateContainer(root_window_, "background");
+ background_window_->SetLayoutManager(
+ new FillLayoutManager(background_window_));
+ background_controller_.reset(new BackgroundController(background_window_));
+ container_ = CreateContainer(root_window_, "container");
+}
+
+ScreenManagerImpl* instance = NULL;
+
+ScreenManagerImpl::ScreenManagerImpl(aura::Window* root)
+ : root_window_(root) {
+ DCHECK(root_window_);
+ DCHECK(!instance);
+ instance = this;
+}
+
+ScreenManagerImpl::~ScreenManagerImpl() {
+ instance = NULL;
+}
+
+} // namespace
+
+// static
+ScreenManager* ScreenManager::Get() {
+ DCHECK(instance);
+ return instance;
+}
+
+// static
+ScreenManager* ScreenManager::Create(aura::Window* root) {
+ new ScreenManagerImpl(root);
+ instance->Init();
+ return instance;
+}
+
+// static
+void ScreenManager::Shutdown() {
+ DCHECK(instance);
+ delete instance;
+ DCHECK(!instance);
+}
+
+} // namespace athena

Powered by Google App Engine
This is Rietveld 408576698