Index: athena/task/task_manager_impl.cc |
diff --git a/athena/task/task_manager_impl.cc b/athena/task/task_manager_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..784a2476f20b385d0d617a1a42368ba0a9895505 |
--- /dev/null |
+++ b/athena/task/task_manager_impl.cc |
@@ -0,0 +1,153 @@ |
+// 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/task/public/task_manager.h" |
+ |
+#include "athena/screen/public/screen_manager.h" |
+#include "athena/task/public/task.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "ui/aura/window.h" |
+#include "ui/views/background.h" |
+#include "ui/views/controls/label.h" |
+#include "ui/views/controls/native/native_view_host.h" |
+#include "ui/views/layout/layout_manager.h" |
+#include "ui/views/view.h" |
+#include "ui/views/widget/widget.h" |
+ |
+namespace athena { |
+ |
+namespace { |
+ |
+class TaskWidget : public views::LayoutManager { |
+ public: |
+ explicit TaskWidget(Task* task) |
+ : task_(task), |
+ container_(NULL), |
+ title_(NULL), |
+ host_(NULL), |
+ widget_(NULL) { |
+ container_ = new views::View; |
+ |
+ title_ = new views::Label(); |
+ title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
+ const gfx::FontList& font_list = title_->font_list(); |
+ title_->SetFontList(font_list.Derive(1, gfx::Font::BOLD)); |
+ title_->SetEnabledColor(SK_ColorBLACK); |
+ title_->SetShadowColors(SK_ColorWHITE, SK_ColorWHITE); |
+ title_->set_shadow_blur(.5); |
+ container_->AddChildView(title_); |
+ container_->SetLayoutManager(this); |
+ |
+ host_ = new views::NativeViewHost(); |
+ container_->AddChildView(host_); |
+ |
+ widget_ = new views::Widget; |
+ views::Widget::InitParams params( |
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
+ params.parent = ScreenManager::Get()->GetContext(); |
+ params.delegate = NULL; |
+ params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; |
+ widget_->Init(params); |
+ widget_->SetContentsView(container_); |
+ |
+ host_->Attach(task->GetNativeWindow()); |
+ } |
+ |
+ virtual ~TaskWidget() {} |
+ |
+ void Show() { |
+ Update(); |
+ widget_->Show(); |
+ } |
+ |
+ void Update() { |
+ title_->SetText(base::UTF8ToUTF16(task_->GetTitle())); |
+ title_->set_background(views::Background::CreateSolidBackground( |
+ task_->GetRepresentativeColor())); |
+ } |
+ |
+ private: |
+ // views::LayoutManager: |
+ virtual void Layout(views::View* host) OVERRIDE { |
+ CHECK_EQ(container_, host); |
+ const gfx::Rect& host_bounds = host->bounds(); |
+ const int kTitleHeight = 25; |
+ title_->SetBounds(0, 0, host_bounds.width(), kTitleHeight); |
+ host_->SetBounds(0, kTitleHeight, host_bounds.width(), |
+ host_bounds.height() - kTitleHeight); |
+ } |
+ |
+ virtual gfx::Size GetPreferredSize(const views::View* host) const OVERRIDE { |
+ CHECK_EQ(container_, host); |
+ gfx::Size size; |
+ gfx::Size label_size = title_->GetPreferredSize(); |
+ gfx::Size host_size = host_->GetPreferredSize(); |
+ |
+ size.set_width(std::max(label_size.width(), host_size.width())); |
+ size.set_height(label_size.height() + host_size.height()); |
+ return size; |
+ } |
+ |
+ Task* task_; |
+ views::View* container_; |
+ views::Label* title_; |
+ views::NativeViewHost* host_; |
+ views::Widget* widget_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TaskWidget); |
+}; |
+ |
+class TaskManagerImpl : public TaskManager { |
+ public: |
+ TaskManagerImpl() {} |
+ virtual ~TaskManagerImpl() {} |
+ |
+ // TaskManager: |
+ virtual void AddTask(Task* task) OVERRIDE { |
+ CHECK(task_widgets_.end() == task_widgets_.find(task)); |
+ TaskWidget* container = new TaskWidget(task); |
+ task_widgets_[task] = container; |
+ container->Show(); |
+ } |
+ |
+ virtual void RemoveTask(Task* task) OVERRIDE { |
+ std::map<Task*, TaskWidget*>::iterator find = task_widgets_.find(task); |
+ if (find != task_widgets_.end()) |
+ task_widgets_.erase(task); |
+ } |
+ |
+ virtual void UpdateTask(Task* task) OVERRIDE { |
+ std::map<Task*, TaskWidget*>::iterator find = task_widgets_.find(task); |
+ if (find != task_widgets_.end()) |
+ find->second->Update(); |
+ } |
+ |
+ private: |
+ std::map<Task*, TaskWidget*> task_widgets_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TaskManagerImpl); |
+}; |
+ |
+static TaskManagerImpl* g_instance; |
+ |
+} // namespace |
+ |
+// static |
+TaskManager* TaskManager::Create() { |
+ CHECK(!g_instance); |
+ g_instance = new TaskManagerImpl(); |
+ return g_instance; |
+} |
+ |
+TaskManager* TaskManager::Get() { |
+ return g_instance; |
+} |
+ |
+void TaskManager::Shutdown() { |
+ CHECK(g_instance); |
+ delete g_instance; |
+ g_instance = NULL; |
+} |
+ |
+} // namespace athena |