| 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/public/activity.h" | 10 #include "athena/activity/public/activity.h" |
| 11 #include "athena/activity/public/activity_view_model.h" | 11 #include "athena/activity/public/activity_view_model.h" |
| 12 #include "athena/screen/public/screen_manager.h" | 12 #include "athena/screen/public/screen_manager.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/views/background.h" | 15 #include "ui/views/background.h" |
| 16 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/controls/native/native_view_host.h" | |
| 18 #include "ui/views/layout/layout_manager.h" | 17 #include "ui/views/layout/layout_manager.h" |
| 19 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 20 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 21 | 20 |
| 22 namespace athena { | 21 namespace athena { |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 class ActivityWidget : public views::LayoutManager { | 24 class ActivityWidget : public views::LayoutManager { |
| 26 public: | 25 public: |
| 27 explicit ActivityWidget(Activity* activity) | 26 explicit ActivityWidget(Activity* activity) |
| 28 : activity_(activity), | 27 : activity_(activity), |
| 29 container_(NULL), | 28 container_(NULL), |
| 30 title_(NULL), | 29 title_(NULL), |
| 31 host_(NULL), | 30 content_(NULL), |
| 32 widget_(NULL) { | 31 widget_(NULL) { |
| 33 container_ = new views::View; | 32 container_ = new views::View; |
| 34 | 33 |
| 35 title_ = new views::Label(); | 34 title_ = new views::Label(); |
| 36 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 35 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 37 const gfx::FontList& font_list = title_->font_list(); | 36 const gfx::FontList& font_list = title_->font_list(); |
| 38 title_->SetFontList(font_list.Derive(1, gfx::Font::BOLD)); | 37 title_->SetFontList(font_list.Derive(1, gfx::Font::BOLD)); |
| 39 title_->SetEnabledColor(SK_ColorBLACK); | 38 title_->SetEnabledColor(SK_ColorBLACK); |
| 40 container_->AddChildView(title_); | 39 container_->AddChildView(title_); |
| 41 container_->SetLayoutManager(this); | 40 container_->SetLayoutManager(this); |
| 42 | 41 content_ = activity->GetActivityViewModel()->GetContentsView(); |
| 43 host_ = new views::NativeViewHost(); | 42 container_->AddChildView(content_); |
| 44 container_->AddChildView(host_); | |
| 45 | 43 |
| 46 widget_ = new views::Widget; | 44 widget_ = new views::Widget; |
| 47 views::Widget::InitParams params( | 45 views::Widget::InitParams params( |
| 48 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 46 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 49 params.context = ScreenManager::Get()->GetContext(); | 47 params.context = ScreenManager::Get()->GetContext(); |
| 50 params.delegate = NULL; | 48 params.delegate = NULL; |
| 51 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; | 49 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; |
| 52 widget_->Init(params); | 50 widget_->Init(params); |
| 53 widget_->SetContentsView(container_); | 51 widget_->SetContentsView(container_); |
| 54 | |
| 55 host_->Attach(activity_->GetActivityViewModel()->GetNativeWindow()); | |
| 56 } | 52 } |
| 57 | 53 |
| 58 virtual ~ActivityWidget() {} | 54 virtual ~ActivityWidget() {} |
| 59 | 55 |
| 60 void Show() { | 56 void Show() { |
| 61 Update(); | 57 Update(); |
| 62 widget_->Show(); | 58 widget_->Show(); |
| 63 } | 59 } |
| 64 | 60 |
| 65 void Update() { | 61 void Update() { |
| 66 title_->SetText( | 62 title_->SetText( |
| 67 base::UTF8ToUTF16(activity_->GetActivityViewModel()->GetTitle())); | 63 base::UTF8ToUTF16(activity_->GetActivityViewModel()->GetTitle())); |
| 68 SkColor bgcolor = | 64 SkColor bgcolor = |
| 69 activity_->GetActivityViewModel()->GetRepresentativeColor(); | 65 activity_->GetActivityViewModel()->GetRepresentativeColor(); |
| 70 title_->set_background(views::Background::CreateSolidBackground(bgcolor)); | 66 title_->set_background(views::Background::CreateSolidBackground(bgcolor)); |
| 71 title_->SetBackgroundColor(bgcolor); | 67 title_->SetBackgroundColor(bgcolor); |
| 72 } | 68 } |
| 73 | 69 |
| 74 private: | 70 private: |
| 75 // views::LayoutManager: | 71 // views::LayoutManager: |
| 76 virtual void Layout(views::View* host) OVERRIDE { | 72 virtual void Layout(views::View* host) OVERRIDE { |
| 77 CHECK_EQ(container_, host); | 73 CHECK_EQ(container_, host); |
| 78 const gfx::Rect& host_bounds = host->bounds(); | 74 const gfx::Rect& content_bounds = host->bounds(); |
| 79 const int kTitleHeight = 25; | 75 const int kTitleHeight = 25; |
| 80 title_->SetBounds(0, 0, host_bounds.width(), kTitleHeight); | 76 title_->SetBounds(0, 0, content_bounds.width(), kTitleHeight); |
| 81 host_->SetBounds(0, | 77 content_->SetBounds(0, |
| 82 kTitleHeight, | 78 kTitleHeight, |
| 83 host_bounds.width(), | 79 content_bounds.width(), |
| 84 host_bounds.height() - kTitleHeight); | 80 content_bounds.height() - kTitleHeight); |
| 85 } | 81 } |
| 86 | 82 |
| 87 virtual gfx::Size GetPreferredSize(const views::View* host) const OVERRIDE { | 83 virtual gfx::Size GetPreferredSize(const views::View* host) const OVERRIDE { |
| 88 CHECK_EQ(container_, host); | 84 CHECK_EQ(container_, host); |
| 89 gfx::Size size; | 85 gfx::Size size; |
| 90 gfx::Size label_size = title_->GetPreferredSize(); | 86 gfx::Size label_size = title_->GetPreferredSize(); |
| 91 gfx::Size host_size = host_->GetPreferredSize(); | 87 gfx::Size content_size = content_->GetPreferredSize(); |
| 92 | 88 |
| 93 size.set_width(std::max(label_size.width(), host_size.width())); | 89 size.set_width(std::max(label_size.width(), content_size.width())); |
| 94 size.set_height(label_size.height() + host_size.height()); | 90 size.set_height(label_size.height() + content_size.height()); |
| 95 return size; | 91 return size; |
| 96 } | 92 } |
| 97 | 93 |
| 98 Activity* activity_; | 94 Activity* activity_; |
| 99 views::View* container_; | 95 views::View* container_; |
| 100 views::Label* title_; | 96 views::Label* title_; |
| 101 views::NativeViewHost* host_; | 97 views::View* content_; |
| 102 views::Widget* widget_; | 98 views::Widget* widget_; |
| 103 | 99 |
| 104 DISALLOW_COPY_AND_ASSIGN(ActivityWidget); | 100 DISALLOW_COPY_AND_ASSIGN(ActivityWidget); |
| 105 }; | 101 }; |
| 106 | 102 |
| 107 ActivityViewManager* instance = NULL; | 103 ActivityViewManager* instance = NULL; |
| 108 | 104 |
| 109 class ActivityViewManagerImpl : public ActivityViewManager { | 105 class ActivityViewManagerImpl : public ActivityViewManager { |
| 110 public: | 106 public: |
| 111 ActivityViewManagerImpl() { | 107 ActivityViewManagerImpl() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 ActivityViewManager* ActivityViewManager::Get() { | 153 ActivityViewManager* ActivityViewManager::Get() { |
| 158 return instance; | 154 return instance; |
| 159 } | 155 } |
| 160 | 156 |
| 161 void ActivityViewManager::Shutdown() { | 157 void ActivityViewManager::Shutdown() { |
| 162 CHECK(instance); | 158 CHECK(instance); |
| 163 delete instance; | 159 delete instance; |
| 164 } | 160 } |
| 165 | 161 |
| 166 } // namespace athena | 162 } // namespace athena |
| OLD | NEW |