| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "athena/activity/public/activity_view_manager.h" | 5 #include "athena/activity/public/activity_view_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "athena/activity/activity_widget_delegate.h" |
| 10 #include "athena/activity/public/activity.h" | 11 #include "athena/activity/public/activity.h" |
| 11 #include "athena/activity/public/activity_view_model.h" | 12 #include "athena/activity/public/activity_view_model.h" |
| 12 #include "athena/screen/public/screen_manager.h" | 13 #include "athena/screen/public/screen_manager.h" |
| 13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 14 #include "ui/views/background.h" | |
| 15 #include "ui/views/controls/label.h" | |
| 16 #include "ui/views/layout/layout_manager.h" | |
| 17 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 18 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 19 | 17 |
| 20 namespace athena { | 18 namespace athena { |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 class ActivityWidget : public views::LayoutManager { | 21 class ActivityWidget { |
| 24 public: | 22 public: |
| 25 explicit ActivityWidget(Activity* activity) | 23 explicit ActivityWidget(Activity* activity) |
| 26 : activity_(activity), | 24 : activity_(activity), widget_(NULL) { |
| 27 container_(NULL), | 25 ActivityViewModel* view_model = activity->GetActivityViewModel(); |
| 28 title_(NULL), | |
| 29 content_(NULL), | |
| 30 widget_(NULL) { | |
| 31 container_ = new views::View; | |
| 32 | |
| 33 title_ = new views::Label(); | |
| 34 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
| 35 const gfx::FontList& font_list = title_->font_list(); | |
| 36 title_->SetFontList(font_list.Derive(1, gfx::Font::BOLD)); | |
| 37 title_->SetEnabledColor(SK_ColorBLACK); | |
| 38 container_->AddChildView(title_); | |
| 39 container_->SetLayoutManager(this); | |
| 40 content_ = activity->GetActivityViewModel()->GetContentsView(); | |
| 41 container_->AddChildView(content_); | |
| 42 | |
| 43 widget_ = new views::Widget; | 26 widget_ = new views::Widget; |
| 44 views::Widget::InitParams params( | 27 views::Widget::InitParams params( |
| 45 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 28 view_model->UsesFrame() |
| 29 ? views::Widget::InitParams::TYPE_WINDOW |
| 30 : views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 46 params.context = ScreenManager::Get()->GetContext(); | 31 params.context = ScreenManager::Get()->GetContext(); |
| 47 params.delegate = NULL; | 32 params.delegate = new ActivityWidgetDelegate(view_model); |
| 48 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; | 33 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; |
| 49 widget_->Init(params); | 34 widget_->Init(params); |
| 50 widget_->SetContentsView(container_); | |
| 51 | |
| 52 activity_->GetActivityViewModel()->Init(); | 35 activity_->GetActivityViewModel()->Init(); |
| 53 } | 36 } |
| 54 | 37 |
| 55 virtual ~ActivityWidget() {} | 38 virtual ~ActivityWidget() {} |
| 56 | 39 |
| 57 void Show() { | 40 void Show() { |
| 58 Update(); | 41 Update(); |
| 59 widget_->Show(); | 42 widget_->Show(); |
| 60 } | 43 } |
| 61 | 44 |
| 62 void Update() { | 45 void Update() { |
| 63 title_->SetText(activity_->GetActivityViewModel()->GetTitle()); | 46 widget_->UpdateWindowTitle(); |
| 64 SkColor bgcolor = | |
| 65 activity_->GetActivityViewModel()->GetRepresentativeColor(); | |
| 66 title_->set_background(views::Background::CreateSolidBackground(bgcolor)); | |
| 67 title_->SetBackgroundColor(bgcolor); | |
| 68 } | 47 } |
| 69 | 48 |
| 70 private: | 49 private: |
| 71 // views::LayoutManager: | |
| 72 virtual void Layout(views::View* host) OVERRIDE { | |
| 73 CHECK_EQ(container_, host); | |
| 74 const gfx::Rect& content_bounds = host->bounds(); | |
| 75 const int kTitleHeight = 25; | |
| 76 title_->SetBounds(0, 0, content_bounds.width(), kTitleHeight); | |
| 77 content_->SetBounds(0, | |
| 78 kTitleHeight, | |
| 79 content_bounds.width(), | |
| 80 content_bounds.height() - kTitleHeight); | |
| 81 } | |
| 82 | |
| 83 virtual gfx::Size GetPreferredSize(const views::View* host) const OVERRIDE { | |
| 84 CHECK_EQ(container_, host); | |
| 85 gfx::Size size; | |
| 86 gfx::Size label_size = title_->GetPreferredSize(); | |
| 87 gfx::Size content_size = content_->GetPreferredSize(); | |
| 88 | |
| 89 size.set_width(std::max(label_size.width(), content_size.width())); | |
| 90 size.set_height(label_size.height() + content_size.height()); | |
| 91 return size; | |
| 92 } | |
| 93 | 50 |
| 94 Activity* activity_; | 51 Activity* activity_; |
| 95 views::View* container_; | |
| 96 views::Label* title_; | |
| 97 views::View* content_; | |
| 98 views::Widget* widget_; | 52 views::Widget* widget_; |
| 99 | 53 |
| 100 DISALLOW_COPY_AND_ASSIGN(ActivityWidget); | 54 DISALLOW_COPY_AND_ASSIGN(ActivityWidget); |
| 101 }; | 55 }; |
| 102 | 56 |
| 103 ActivityViewManager* instance = NULL; | 57 ActivityViewManager* instance = NULL; |
| 104 | 58 |
| 105 class ActivityViewManagerImpl : public ActivityViewManager { | 59 class ActivityViewManagerImpl : public ActivityViewManager { |
| 106 public: | 60 public: |
| 107 ActivityViewManagerImpl() { | 61 ActivityViewManagerImpl() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 ActivityViewManager* ActivityViewManager::Get() { | 107 ActivityViewManager* ActivityViewManager::Get() { |
| 154 return instance; | 108 return instance; |
| 155 } | 109 } |
| 156 | 110 |
| 157 void ActivityViewManager::Shutdown() { | 111 void ActivityViewManager::Shutdown() { |
| 158 CHECK(instance); | 112 CHECK(instance); |
| 159 delete instance; | 113 delete instance; |
| 160 } | 114 } |
| 161 | 115 |
| 162 } // namespace athena | 116 } // namespace athena |
| OLD | NEW |