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" |
19 #include "ui/views/view.h" | 22 #include "ui/views/view.h" |
| 23 #include "ui/views/widget/widget.h" |
| 24 #include "ui/wm/core/visibility_controller.h" |
| 25 #include "ui/wm/core/window_animations.h" |
20 | 26 |
21 namespace athena { | 27 namespace athena { |
22 namespace { | 28 namespace { |
23 | 29 |
24 SystemUI* instance = nullptr; | 30 SystemUI* instance = nullptr; |
25 | 31 |
26 // View which positions the TimeView on the left and the StatusIconView on the | 32 // View which positions the TimeView on the left and the StatusIconView on the |
27 // right. | 33 // right. |
28 class SystemInfoView : public views::View { | 34 class SystemInfoView : public views::View { |
29 public: | 35 public: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 Layout(); | 68 Layout(); |
63 } | 69 } |
64 | 70 |
65 private: | 71 private: |
66 views::View* time_view_; | 72 views::View* time_view_; |
67 views::View* status_icon_view_; | 73 views::View* status_icon_view_; |
68 | 74 |
69 DISALLOW_COPY_AND_ASSIGN(SystemInfoView); | 75 DISALLOW_COPY_AND_ASSIGN(SystemInfoView); |
70 }; | 76 }; |
71 | 77 |
72 class SystemUIImpl : public SystemUI { | 78 class SystemUIImpl : public SystemUI, public WindowManagerObserver { |
73 public: | 79 public: |
74 SystemUIImpl(scoped_refptr<base::TaskRunner> blocking_task_runner) | 80 SystemUIImpl(scoped_refptr<base::TaskRunner> blocking_task_runner) |
75 : orientation_controller_(new OrientationController()), | 81 : orientation_controller_(new OrientationController()), |
76 background_container_(nullptr) { | 82 background_container_(nullptr), |
| 83 system_info_widget_(nullptr) { |
77 orientation_controller_->InitWith(blocking_task_runner); | 84 orientation_controller_->InitWith(blocking_task_runner); |
| 85 WindowManager::Get()->AddObserver(this); |
78 } | 86 } |
79 | 87 |
80 ~SystemUIImpl() override { | 88 ~SystemUIImpl() override { |
| 89 WindowManager::Get()->RemoveObserver(this); |
| 90 |
81 // Stops file watching now if exists. Waiting until message loop shutdon | 91 // Stops file watching now if exists. Waiting until message loop shutdon |
82 // leads to FilePathWatcher crash. | 92 // leads to FilePathWatcher crash. |
83 orientation_controller_->Shutdown(); | 93 orientation_controller_->Shutdown(); |
84 } | 94 } |
85 | 95 |
86 void Init() { | 96 void Init() { |
87 ScreenManager* screen_manager = ScreenManager::Get(); | 97 ScreenManager* screen_manager = ScreenManager::Get(); |
88 background_container_ = screen_manager->CreateContainer( | 98 background_container_ = screen_manager->CreateContainer( |
89 ScreenManager::ContainerParams("AthenaBackground", CP_BACKGROUND)); | 99 ScreenManager::ContainerParams("AthenaBackground", CP_BACKGROUND)); |
90 background_container_->SetLayoutManager( | 100 background_container_->SetLayoutManager( |
91 new FillLayoutManager(background_container_)); | 101 new FillLayoutManager(background_container_)); |
92 | 102 |
93 shutdown_dialog_.reset(new ShutdownDialog()); | 103 shutdown_dialog_.reset(new ShutdownDialog()); |
94 background_controller_.reset( | 104 background_controller_.reset( |
95 new BackgroundController(background_container_)); | 105 new BackgroundController(background_container_)); |
96 } | 106 } |
97 | 107 |
98 private: | 108 private: |
99 // SystemUI: | 109 // SystemUI: |
100 virtual void SetBackgroundImage(const gfx::ImageSkia& image) override { | 110 void SetBackgroundImage(const gfx::ImageSkia& image) override { |
101 background_controller_->SetImage(image); | 111 background_controller_->SetImage(image); |
102 } | 112 } |
103 | 113 |
104 virtual views::View* CreateSystemInfoView(ColorScheme color_scheme) override { | 114 // WindowManagerObserver: |
105 return new SystemInfoView(color_scheme); | 115 void OnOverviewModeEnter() override { |
| 116 DCHECK(!system_info_widget_); |
| 117 |
| 118 ScreenManager* screen_manager = ScreenManager::Get(); |
| 119 aura::Window* container = screen_manager->CreateContainer( |
| 120 ScreenManager::ContainerParams("SystemInfo", CP_SYSTEM_INFO)); |
| 121 wm::SetChildWindowVisibilityChangesAnimated(container); |
| 122 |
| 123 system_info_widget_ = new views::Widget(); |
| 124 views::Widget::InitParams widget_params( |
| 125 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 126 widget_params.parent = container; |
| 127 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 128 widget_params.bounds = |
| 129 gfx::Rect(0, 0, container->bounds().width(), kSystemUIHeight); |
| 130 system_info_widget_->Init(widget_params); |
| 131 system_info_widget_->SetContentsView( |
| 132 new SystemInfoView(SystemUI::COLOR_SCHEME_LIGHT)); |
| 133 |
| 134 wm::SetWindowVisibilityAnimationType( |
| 135 system_info_widget_->GetNativeWindow(), |
| 136 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); |
| 137 wm::SetWindowVisibilityAnimationVerticalPosition( |
| 138 system_info_widget_->GetNativeWindow(), -kSystemUIHeight); |
| 139 |
| 140 system_info_widget_->Show(); |
106 } | 141 } |
107 | 142 |
| 143 void OnOverviewModeExit() override { |
| 144 // Deleting the container deletes its child windows which deletes |
| 145 // |system_info_widget_|. |
| 146 delete system_info_widget_->GetNativeWindow()->parent(); |
| 147 system_info_widget_ = nullptr; |
| 148 } |
| 149 |
| 150 void OnSplitViewModeEnter() override {} |
| 151 |
| 152 void OnSplitViewModeExit() override {} |
| 153 |
108 scoped_ptr<OrientationController> orientation_controller_; | 154 scoped_ptr<OrientationController> orientation_controller_; |
109 scoped_ptr<ShutdownDialog> shutdown_dialog_; | 155 scoped_ptr<ShutdownDialog> shutdown_dialog_; |
110 scoped_ptr<BackgroundController> background_controller_; | 156 scoped_ptr<BackgroundController> background_controller_; |
111 | 157 |
112 // The parent container for the background. | 158 // The parent container for the background. |
113 aura::Window* background_container_; | 159 aura::Window* background_container_; |
114 | 160 |
115 // The parent container used by system modal dialogs. | 161 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 | 162 |
122 DISALLOW_COPY_AND_ASSIGN(SystemUIImpl); | 163 DISALLOW_COPY_AND_ASSIGN(SystemUIImpl); |
123 }; | 164 }; |
124 | 165 |
125 } // namespace | 166 } // namespace |
126 | 167 |
127 // static | 168 // static |
128 SystemUI* SystemUI::Create( | 169 SystemUI* SystemUI::Create( |
129 scoped_refptr<base::TaskRunner> blocking_task_runner) { | 170 scoped_refptr<base::TaskRunner> blocking_task_runner) { |
130 SystemUIImpl* system_ui = new SystemUIImpl(blocking_task_runner); | 171 SystemUIImpl* system_ui = new SystemUIImpl(blocking_task_runner); |
131 instance = system_ui; | 172 instance = system_ui; |
132 system_ui->Init(); | 173 system_ui->Init(); |
133 return instance; | 174 return instance; |
134 } | 175 } |
135 | 176 |
136 // static | 177 // static |
137 SystemUI* SystemUI::Get() { | 178 SystemUI* SystemUI::Get() { |
138 DCHECK(instance); | 179 DCHECK(instance); |
139 return instance; | 180 return instance; |
140 } | 181 } |
141 | 182 |
142 // static | 183 // static |
143 void SystemUI::Shutdown() { | 184 void SystemUI::Shutdown() { |
144 CHECK(instance); | 185 CHECK(instance); |
145 delete instance; | 186 delete instance; |
146 instance = nullptr; | 187 instance = nullptr; |
147 } | 188 } |
148 | 189 |
149 } // namespace athena | 190 } // namespace athena |
OLD | NEW |