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
3 // found in the LICENSE file.
5 #include "athena/activity/public/activity_view_manager.h"
10 #include "athena/activity/activity_widget_delegate.h"
11 #include "athena/activity/public/activity.h"
12 #include "athena/activity/public/activity_manager.h"
13 #include "athena/activity/public/activity_view_model.h"
14 #include "athena/screen/public/screen_manager.h"
15 #include "ui/aura/window.h"
16 #include "ui/views/view.h"
17 #include "ui/views/widget/widget.h"
18 #include "ui/views/widget/widget_observer.h"
23 typedef std::map
<Activity
*, views::Widget
*> ActivityWidgetMap
;
25 views::Widget
* CreateWidget(Activity
* activity
) {
26 ActivityViewModel
* view_model
= activity
->GetActivityViewModel();
27 views::Widget
* widget
= new views::Widget
;
28 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
29 params
.delegate
= new ActivityWidgetDelegate(view_model
);
30 params
.activatable
= views::Widget::InitParams::ACTIVATABLE_YES
;
32 activity
->GetActivityViewModel()->Init();
36 ActivityViewManager
* instance
= NULL
;
38 class ActivityViewManagerImpl
: public ActivityViewManager
,
39 public views::WidgetObserver
{
41 ActivityViewManagerImpl() {
46 virtual ~ActivityViewManagerImpl() {
47 CHECK_EQ(this, instance
);
51 // ActivityViewManager:
52 virtual void AddActivity(Activity
* activity
) OVERRIDE
{
53 CHECK(activity_widgets_
.end() == activity_widgets_
.find(activity
));
54 views::Widget
* container
= CreateWidget(activity
);
55 container
->AddObserver(this);
56 activity_widgets_
[activity
] = container
;
57 container
->UpdateWindowTitle();
59 container
->Activate();
62 virtual void RemoveActivity(Activity
* activity
) OVERRIDE
{
63 ActivityWidgetMap::iterator find
= activity_widgets_
.find(activity
);
64 if (find
!= activity_widgets_
.end()) {
65 views::Widget
* widget
= find
->second
;
66 widget
->RemoveObserver(this);
68 activity_widgets_
.erase(activity
);
72 virtual void UpdateActivity(Activity
* activity
) OVERRIDE
{
73 ActivityWidgetMap::iterator find
= activity_widgets_
.find(activity
);
74 if (find
!= activity_widgets_
.end())
75 find
->second
->UpdateWindowTitle();
78 // views::WidgetObserver:
79 virtual void OnWidgetDestroying(views::Widget
* widget
) OVERRIDE
{
80 for (ActivityWidgetMap::iterator iter
= activity_widgets_
.begin();
81 iter
!= activity_widgets_
.end();
83 if (iter
->second
== widget
) {
91 ActivityWidgetMap activity_widgets_
;
93 DISALLOW_COPY_AND_ASSIGN(ActivityViewManagerImpl
);
99 ActivityViewManager
* ActivityViewManager::Create() {
100 new ActivityViewManagerImpl();
105 ActivityViewManager
* ActivityViewManager::Get() {
109 void ActivityViewManager::Shutdown() {
114 } // namespace athena