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/system/public/system_ui.h" | 5 #include "athena/system/public/system_ui.h" |
6 | 6 |
7 #include "athena/screen/public/screen_manager.h" | 7 #include "athena/screen/public/screen_manager.h" |
8 #include "athena/system/background_controller.h" | 8 #include "athena/system/background_controller.h" |
9 #include "athena/system/orientation_controller.h" | 9 #include "athena/system/orientation_controller.h" |
10 #include "athena/system/shutdown_dialog.h" | 10 #include "athena/system/shutdown_dialog.h" |
11 #include "athena/system/status_icon_container_view.h" | 11 #include "athena/system/status_icon_container_view.h" |
12 #include "athena/system/time_view.h" | 12 #include "athena/system/time_view.h" |
13 #include "athena/util/athena_constants.h" | |
13 #include "athena/util/container_priorities.h" | 14 #include "athena/util/container_priorities.h" |
14 #include "athena/util/fill_layout_manager.h" | 15 #include "athena/util/fill_layout_manager.h" |
16 #include "athena/wm/public/window_manager.h" | |
17 #include "athena/wm/public/window_manager_observer.h" | |
15 #include "base/logging.h" | 18 #include "base/logging.h" |
16 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
18 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
22 #include "ui/compositor/closure_animation_observer.h" | |
23 #include "ui/compositor/layer.h" | |
24 #include "ui/compositor/scoped_layer_animation_settings.h" | |
25 #include "ui/gfx/animation/tween.h" | |
26 #include "ui/gfx/transform.h" | |
19 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
28 #include "ui/views/widget/widget.h" | |
20 | 29 |
21 namespace athena { | 30 namespace athena { |
22 namespace { | 31 namespace { |
23 | 32 |
24 SystemUI* instance = nullptr; | 33 SystemUI* instance = nullptr; |
25 | 34 |
35 void ClearSystemInfo(views::Widget* widget) { | |
36 aura::Window* container = widget->GetNativeWindow()->parent(); | |
37 container->Hide(); | |
38 container->parent()->RemoveChild(container); | |
39 delete container; | |
40 } | |
41 | |
26 // View which positions the TimeView on the left and the StatusIconView on the | 42 // View which positions the TimeView on the left and the StatusIconView on the |
27 // right. | 43 // right. |
28 class SystemInfoView : public views::View { | 44 class SystemInfoView : public views::View { |
29 public: | 45 public: |
30 SystemInfoView(SystemUI::ColorScheme color_scheme) | 46 SystemInfoView(SystemUI::ColorScheme color_scheme) |
31 : time_view_(new TimeView(color_scheme)), | 47 : time_view_(new TimeView(color_scheme)), |
32 status_icon_view_(new StatusIconContainerView(color_scheme)) { | 48 status_icon_view_(new StatusIconContainerView(color_scheme)) { |
33 AddChildView(time_view_); | 49 AddChildView(time_view_); |
34 AddChildView(status_icon_view_); | 50 AddChildView(status_icon_view_); |
35 } | 51 } |
(...skipping 26 matching lines...) Expand all Loading... | |
62 Layout(); | 78 Layout(); |
63 } | 79 } |
64 | 80 |
65 private: | 81 private: |
66 views::View* time_view_; | 82 views::View* time_view_; |
67 views::View* status_icon_view_; | 83 views::View* status_icon_view_; |
68 | 84 |
69 DISALLOW_COPY_AND_ASSIGN(SystemInfoView); | 85 DISALLOW_COPY_AND_ASSIGN(SystemInfoView); |
70 }; | 86 }; |
71 | 87 |
72 class SystemUIImpl : public SystemUI { | 88 class SystemUIImpl : public SystemUI, public WindowManagerObserver { |
73 public: | 89 public: |
74 SystemUIImpl(scoped_refptr<base::TaskRunner> blocking_task_runner) | 90 SystemUIImpl(scoped_refptr<base::TaskRunner> blocking_task_runner) |
75 : orientation_controller_(new OrientationController()), | 91 : orientation_controller_(new OrientationController()), |
76 background_container_(nullptr) { | 92 background_container_(nullptr), |
93 system_info_widget_(nullptr) { | |
77 orientation_controller_->InitWith(blocking_task_runner); | 94 orientation_controller_->InitWith(blocking_task_runner); |
95 WindowManager::Get()->AddObserver(this); | |
78 } | 96 } |
79 | 97 |
80 ~SystemUIImpl() override { | 98 ~SystemUIImpl() override { |
99 WindowManager::Get()->RemoveObserver(this); | |
100 | |
81 // Stops file watching now if exists. Waiting until message loop shutdon | 101 // Stops file watching now if exists. Waiting until message loop shutdon |
82 // leads to FilePathWatcher crash. | 102 // leads to FilePathWatcher crash. |
83 orientation_controller_->Shutdown(); | 103 orientation_controller_->Shutdown(); |
84 } | 104 } |
85 | 105 |
86 void Init() { | 106 void Init() { |
87 ScreenManager* screen_manager = ScreenManager::Get(); | 107 ScreenManager* screen_manager = ScreenManager::Get(); |
88 background_container_ = screen_manager->CreateContainer( | 108 background_container_ = screen_manager->CreateContainer( |
89 ScreenManager::ContainerParams("AthenaBackground", CP_BACKGROUND)); | 109 ScreenManager::ContainerParams("AthenaBackground", CP_BACKGROUND)); |
90 background_container_->SetLayoutManager( | 110 background_container_->SetLayoutManager( |
91 new FillLayoutManager(background_container_)); | 111 new FillLayoutManager(background_container_)); |
92 | 112 |
93 shutdown_dialog_.reset(new ShutdownDialog()); | 113 shutdown_dialog_.reset(new ShutdownDialog()); |
94 background_controller_.reset( | 114 background_controller_.reset( |
95 new BackgroundController(background_container_)); | 115 new BackgroundController(background_container_)); |
96 } | 116 } |
97 | 117 |
98 private: | 118 private: |
99 // SystemUI: | 119 // SystemUI: |
100 virtual void SetBackgroundImage(const gfx::ImageSkia& image) override { | 120 void SetBackgroundImage(const gfx::ImageSkia& image) override { |
101 background_controller_->SetImage(image); | 121 background_controller_->SetImage(image); |
102 } | 122 } |
103 | 123 |
104 virtual views::View* CreateSystemInfoView(ColorScheme color_scheme) override { | 124 // WindowManagerObserver: |
105 return new SystemInfoView(color_scheme); | 125 void OnOverviewModeEnter() override { |
126 DCHECK(!system_info_widget_); | |
127 | |
128 ScreenManager* screen_manager = ScreenManager::Get(); | |
129 aura::Window* container = screen_manager->CreateContainer( | |
130 ScreenManager::ContainerParams("SystemInfo", CP_SYSTEM_INFO)); | |
131 | |
132 system_info_widget_ = new views::Widget(); | |
133 views::Widget::InitParams widget_params( | |
134 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
135 widget_params.parent = container; | |
136 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
137 widget_params.bounds = | |
138 gfx::Rect(0, 0, container->bounds().width(), kSystemUIHeight); | |
139 system_info_widget_->Init(widget_params); | |
140 system_info_widget_->SetContentsView( | |
141 new SystemInfoView(SystemUI::COLOR_SCHEME_LIGHT)); | |
142 system_info_widget_->Show(); | |
143 | |
144 gfx::Transform transform; | |
145 transform.Translate(0, SkMScalar(-kSystemUIHeight)); | |
146 system_info_widget_->GetLayer()->SetTransform(transform); | |
147 | |
148 { | |
149 ui::ScopedLayerAnimationSettings settings( | |
150 system_info_widget_->GetLayer()->GetAnimator()); | |
151 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
152 system_info_widget_->GetLayer()->SetTransform(gfx::Transform()); | |
153 } | |
106 } | 154 } |
107 | 155 |
156 void OnOverviewModeExit() override { | |
157 ui::ScopedLayerAnimationSettings settings( | |
158 system_info_widget_->GetLayer()->GetAnimator()); | |
159 settings.SetTweenType(gfx::Tween::EASE_IN); | |
160 gfx::Transform transform; | |
161 transform.Translate(0, SkIntToMScalar(-kSystemUIHeight)); | |
162 system_info_widget_->GetLayer()->SetTransform(transform); | |
163 settings.AddObserver(new ui::ClosureAnimationObserver( | |
164 base::Bind(&ClearSystemInfo, system_info_widget_))); | |
oshima
2014/11/12 20:35:03
It's probably better to use ScopedHidingAnimatinoS
Jun Mukai
2014/11/12 21:39:58
Removed the the code around here and replaced by u
| |
165 system_info_widget_ = nullptr; | |
166 } | |
167 | |
168 void OnSplitViewModeEnter() override {} | |
169 | |
170 void OnSplitViewModeExit() override {} | |
171 | |
108 scoped_ptr<OrientationController> orientation_controller_; | 172 scoped_ptr<OrientationController> orientation_controller_; |
109 scoped_ptr<ShutdownDialog> shutdown_dialog_; | 173 scoped_ptr<ShutdownDialog> shutdown_dialog_; |
110 scoped_ptr<BackgroundController> background_controller_; | 174 scoped_ptr<BackgroundController> background_controller_; |
111 | 175 |
112 // The parent container for the background. | 176 // The parent container for the background. |
113 aura::Window* background_container_; | 177 aura::Window* background_container_; |
114 | 178 |
115 // The parent container used by system modal dialogs. | 179 views::Widget* system_info_widget_; |
116 aura::Window* system_modal_container_; | |
117 | |
118 // The parent container used by system modal dialogs when the login screen is | |
119 // visible. | |
120 aura::Window* login_screen_system_modal_container_; | |
121 | 180 |
122 DISALLOW_COPY_AND_ASSIGN(SystemUIImpl); | 181 DISALLOW_COPY_AND_ASSIGN(SystemUIImpl); |
123 }; | 182 }; |
124 | 183 |
125 } // namespace | 184 } // namespace |
126 | 185 |
127 // static | 186 // static |
128 SystemUI* SystemUI::Create( | 187 SystemUI* SystemUI::Create( |
129 scoped_refptr<base::TaskRunner> blocking_task_runner) { | 188 scoped_refptr<base::TaskRunner> blocking_task_runner) { |
130 SystemUIImpl* system_ui = new SystemUIImpl(blocking_task_runner); | 189 SystemUIImpl* system_ui = new SystemUIImpl(blocking_task_runner); |
131 instance = system_ui; | 190 instance = system_ui; |
132 system_ui->Init(); | 191 system_ui->Init(); |
133 return instance; | 192 return instance; |
134 } | 193 } |
135 | 194 |
136 // static | 195 // static |
137 SystemUI* SystemUI::Get() { | 196 SystemUI* SystemUI::Get() { |
138 DCHECK(instance); | 197 DCHECK(instance); |
139 return instance; | 198 return instance; |
140 } | 199 } |
141 | 200 |
142 // static | 201 // static |
143 void SystemUI::Shutdown() { | 202 void SystemUI::Shutdown() { |
144 CHECK(instance); | 203 CHECK(instance); |
145 delete instance; | 204 delete instance; |
146 instance = nullptr; | 205 instance = nullptr; |
147 } | 206 } |
148 | 207 |
149 } // namespace athena | 208 } // namespace athena |
OLD | NEW |