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/system/public/system_ui.h"
7 #include "athena/screen/public/screen_manager.h"
8 #include "athena/system/background_controller.h"
9 #include "athena/system/orientation_controller.h"
10 #include "athena/system/shutdown_dialog.h"
11 #include "athena/system/status_icon_container_view.h"
12 #include "athena/system/time_view.h"
13 #include "athena/util/athena_constants.h"
14 #include "athena/util/container_priorities.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"
18 #include "base/logging.h"
19 #include "base/memory/ref_counted.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "ui/aura/window.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"
30 SystemUI
* instance
= nullptr;
32 // View which positions the TimeView on the left and the StatusIconView on the
34 class SystemInfoView
: public views::View
{
36 SystemInfoView(SystemUI::ColorScheme color_scheme
)
37 : time_view_(new TimeView(color_scheme
)),
38 status_icon_view_(new StatusIconContainerView(color_scheme
)) {
39 AddChildView(time_view_
);
40 AddChildView(status_icon_view_
);
43 ~SystemInfoView() override
{}
46 virtual gfx::Size
GetPreferredSize() const override
{
47 // The view should be as wide as its parent view.
49 std::max(time_view_
->GetPreferredSize().height(),
50 status_icon_view_
->GetPreferredSize().height()));
53 virtual void Layout() override
{
54 time_view_
->SetBoundsRect(gfx::Rect(time_view_
->GetPreferredSize()));
55 gfx::Size status_icon_preferred_size
=
56 status_icon_view_
->GetPreferredSize();
57 status_icon_view_
->SetBoundsRect(
58 gfx::Rect(width() - status_icon_preferred_size
.width(),
60 status_icon_preferred_size
.width(),
61 status_icon_preferred_size
.height()));
64 virtual void ChildPreferredSizeChanged(views::View
* child
) override
{
65 // Relayout to take into account changes in |status_icon_view_|'s width.
66 // Assume that |time_view_|'s and |status_icon_view_|'s preferred height
72 views::View
* time_view_
;
73 views::View
* status_icon_view_
;
75 DISALLOW_COPY_AND_ASSIGN(SystemInfoView
);
78 class SystemUIImpl
: public SystemUI
, public WindowManagerObserver
{
80 SystemUIImpl(scoped_refptr
<base::TaskRunner
> blocking_task_runner
)
81 : orientation_controller_(new OrientationController()),
82 background_container_(nullptr),
83 system_info_widget_(nullptr) {
84 orientation_controller_
->InitWith(blocking_task_runner
);
85 WindowManager::Get()->AddObserver(this);
88 ~SystemUIImpl() override
{
89 WindowManager::Get()->RemoveObserver(this);
91 // Stops file watching now if exists. Waiting until message loop shutdon
92 // leads to FilePathWatcher crash.
93 orientation_controller_
->Shutdown();
97 ScreenManager
* screen_manager
= ScreenManager::Get();
98 background_container_
= screen_manager
->CreateContainer(
99 ScreenManager::ContainerParams("AthenaBackground", CP_BACKGROUND
));
100 background_container_
->SetLayoutManager(
101 new FillLayoutManager(background_container_
));
103 shutdown_dialog_
.reset(new ShutdownDialog());
104 background_controller_
.reset(
105 new BackgroundController(background_container_
));
110 void SetBackgroundImage(const gfx::ImageSkia
& image
) override
{
111 background_controller_
->SetImage(image
);
114 // WindowManagerObserver:
115 void OnOverviewModeEnter() override
{
116 DCHECK(!system_info_widget_
);
118 ScreenManager
* screen_manager
= ScreenManager::Get();
119 aura::Window
* container
= screen_manager
->CreateContainer(
120 ScreenManager::ContainerParams("SystemInfo", CP_SYSTEM_INFO
));
121 wm::SetChildWindowVisibilityChangesAnimated(container
);
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
));
134 wm::SetWindowVisibilityAnimationType(
135 system_info_widget_
->GetNativeWindow(),
136 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL
);
137 wm::SetWindowVisibilityAnimationVerticalPosition(
138 system_info_widget_
->GetNativeWindow(), -kSystemUIHeight
);
140 system_info_widget_
->Show();
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;
150 void OnSplitViewModeEnter() override
{}
152 void OnSplitViewModeExit() override
{}
154 scoped_ptr
<OrientationController
> orientation_controller_
;
155 scoped_ptr
<ShutdownDialog
> shutdown_dialog_
;
156 scoped_ptr
<BackgroundController
> background_controller_
;
158 // The parent container for the background.
159 aura::Window
* background_container_
;
161 views::Widget
* system_info_widget_
;
163 DISALLOW_COPY_AND_ASSIGN(SystemUIImpl
);
169 SystemUI
* SystemUI::Create(
170 scoped_refptr
<base::TaskRunner
> blocking_task_runner
) {
171 SystemUIImpl
* system_ui
= new SystemUIImpl(blocking_task_runner
);
172 instance
= system_ui
;
178 SystemUI
* SystemUI::Get() {
184 void SystemUI::Shutdown() {
190 } // namespace athena