Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(706)

Side by Side Diff: athena/system/system_ui_impl.cc

Issue 863033002: Delete athena/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/system/status_icon_container_view.cc ('k') | athena/system/time_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "athena/system/public/system_ui.h"
6
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"
26
27 namespace athena {
28 namespace {
29
30 SystemUI* instance = nullptr;
31
32 // View which positions the TimeView on the left and the StatusIconView on the
33 // right.
34 class SystemInfoView : public views::View {
35 public:
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_);
41 }
42
43 ~SystemInfoView() override {}
44
45 // views::View:
46 virtual gfx::Size GetPreferredSize() const override {
47 // The view should be as wide as its parent view.
48 return gfx::Size(0,
49 std::max(time_view_->GetPreferredSize().height(),
50 status_icon_view_->GetPreferredSize().height()));
51 }
52
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(),
59 0,
60 status_icon_preferred_size.width(),
61 status_icon_preferred_size.height()));
62 }
63
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
67 // does not change.
68 Layout();
69 }
70
71 private:
72 views::View* time_view_;
73 views::View* status_icon_view_;
74
75 DISALLOW_COPY_AND_ASSIGN(SystemInfoView);
76 };
77
78 class SystemUIImpl : public SystemUI, public WindowManagerObserver {
79 public:
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);
86 }
87
88 ~SystemUIImpl() override {
89 WindowManager::Get()->RemoveObserver(this);
90
91 // Stops file watching now if exists. Waiting until message loop shutdon
92 // leads to FilePathWatcher crash.
93 orientation_controller_->Shutdown();
94 }
95
96 void Init() {
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_));
102
103 shutdown_dialog_.reset(new ShutdownDialog());
104 background_controller_.reset(
105 new BackgroundController(background_container_));
106 }
107
108 private:
109 // SystemUI:
110 void SetBackgroundImage(const gfx::ImageSkia& image) override {
111 background_controller_->SetImage(image);
112 }
113
114 // WindowManagerObserver:
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();
141 }
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
154 scoped_ptr<OrientationController> orientation_controller_;
155 scoped_ptr<ShutdownDialog> shutdown_dialog_;
156 scoped_ptr<BackgroundController> background_controller_;
157
158 // The parent container for the background.
159 aura::Window* background_container_;
160
161 views::Widget* system_info_widget_;
162
163 DISALLOW_COPY_AND_ASSIGN(SystemUIImpl);
164 };
165
166 } // namespace
167
168 // static
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;
173 system_ui->Init();
174 return instance;
175 }
176
177 // static
178 SystemUI* SystemUI::Get() {
179 DCHECK(instance);
180 return instance;
181 }
182
183 // static
184 void SystemUI::Shutdown() {
185 CHECK(instance);
186 delete instance;
187 instance = nullptr;
188 }
189
190 } // namespace athena
OLDNEW
« no previous file with comments | « athena/system/status_icon_container_view.cc ('k') | athena/system/time_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698