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

Side by Side Diff: ash/common/system/status_area_widget.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 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 | « ash/common/system/status_area_widget.h ('k') | ash/common/system/status_area_widget_delegate.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 (c) 2012 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 "ash/common/system/status_area_widget.h"
6
7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/shelf/wm_shelf.h"
9 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h"
10 #include "ash/common/system/chromeos/palette/palette_tray.h"
11 #include "ash/common/system/chromeos/palette/palette_utils.h"
12 #include "ash/common/system/chromeos/session/logout_button_tray.h"
13 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h"
14 #include "ash/common/system/overview/overview_button_tray.h"
15 #include "ash/common/system/status_area_widget_delegate.h"
16 #include "ash/common/system/tray/system_tray.h"
17 #include "ash/common/system/tray/system_tray_delegate.h"
18 #include "ash/common/system/web_notification/web_notification_tray.h"
19 #include "ash/common/wm_shell.h"
20 #include "ash/common/wm_window.h"
21 #include "ash/public/cpp/shell_window_ids.h"
22 #include "ash/root_window_controller.h"
23 #include "base/i18n/time_formatting.h"
24 #include "ui/display/display.h"
25 #include "ui/native_theme/native_theme_dark_aura.h"
26
27 namespace ash {
28
29 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container,
30 WmShelf* wm_shelf)
31 : status_area_widget_delegate_(new StatusAreaWidgetDelegate),
32 overview_button_tray_(nullptr),
33 system_tray_(nullptr),
34 web_notification_tray_(nullptr),
35 logout_button_tray_(nullptr),
36 palette_tray_(nullptr),
37 virtual_keyboard_tray_(nullptr),
38 ime_menu_tray_(nullptr),
39 login_status_(LoginStatus::NOT_LOGGED_IN),
40 wm_shelf_(wm_shelf) {
41 views::Widget::InitParams params(
42 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
43 params.delegate = status_area_widget_delegate_;
44 params.name = "StatusAreaWidget";
45 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
46 status_container->GetRootWindowController()
47 ->ConfigureWidgetInitParamsForContainer(
48 this, status_container->GetShellWindowId(), &params);
49 Init(params);
50 set_focus_on_creation(false);
51 SetContentsView(status_area_widget_delegate_);
52 }
53
54 StatusAreaWidget::~StatusAreaWidget() {}
55
56 void StatusAreaWidget::CreateTrayViews() {
57 AddOverviewButtonTray();
58 AddSystemTray();
59 AddWebNotificationTray();
60 AddPaletteTray();
61 AddVirtualKeyboardTray();
62 AddImeMenuTray();
63 AddLogoutButtonTray();
64
65 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
66 DCHECK(delegate);
67 // Initialize after all trays have been created.
68 system_tray_->InitializeTrayItems(delegate, web_notification_tray_);
69 web_notification_tray_->Initialize();
70 logout_button_tray_->Initialize();
71 if (palette_tray_)
72 palette_tray_->Initialize();
73 virtual_keyboard_tray_->Initialize();
74 ime_menu_tray_->Initialize();
75 overview_button_tray_->Initialize();
76 SetShelfAlignment(system_tray_->shelf_alignment());
77 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus());
78 }
79
80 void StatusAreaWidget::Shutdown() {
81 system_tray_->Shutdown();
82 // Destroy the trays early, causing them to be removed from the view
83 // hierarchy. Do not used scoped pointers since we don't want to destroy them
84 // in the destructor if Shutdown() is not called (e.g. in tests).
85 delete web_notification_tray_;
86 web_notification_tray_ = nullptr;
87 // Must be destroyed after |web_notification_tray_|.
88 delete system_tray_;
89 system_tray_ = nullptr;
90 delete ime_menu_tray_;
91 ime_menu_tray_ = nullptr;
92 delete virtual_keyboard_tray_;
93 virtual_keyboard_tray_ = nullptr;
94 delete logout_button_tray_;
95 logout_button_tray_ = nullptr;
96 delete overview_button_tray_;
97 overview_button_tray_ = nullptr;
98 }
99
100 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) {
101 status_area_widget_delegate_->set_alignment(alignment);
102 if (system_tray_)
103 system_tray_->SetShelfAlignment(alignment);
104 if (web_notification_tray_)
105 web_notification_tray_->SetShelfAlignment(alignment);
106 if (logout_button_tray_)
107 logout_button_tray_->SetShelfAlignment(alignment);
108 if (virtual_keyboard_tray_)
109 virtual_keyboard_tray_->SetShelfAlignment(alignment);
110 if (ime_menu_tray_)
111 ime_menu_tray_->SetShelfAlignment(alignment);
112 if (palette_tray_)
113 palette_tray_->SetShelfAlignment(alignment);
114 if (overview_button_tray_)
115 overview_button_tray_->SetShelfAlignment(alignment);
116 status_area_widget_delegate_->UpdateLayout();
117 }
118
119 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) {
120 if (login_status_ == login_status)
121 return;
122 login_status_ = login_status;
123 if (system_tray_)
124 system_tray_->UpdateAfterLoginStatusChange(login_status);
125 if (web_notification_tray_)
126 web_notification_tray_->UpdateAfterLoginStatusChange(login_status);
127 if (logout_button_tray_)
128 logout_button_tray_->UpdateAfterLoginStatusChange(login_status);
129 if (overview_button_tray_)
130 overview_button_tray_->UpdateAfterLoginStatusChange(login_status);
131 }
132
133 bool StatusAreaWidget::ShouldShowShelf() const {
134 if ((system_tray_ && system_tray_->ShouldShowShelf()) ||
135 (web_notification_tray_ &&
136 web_notification_tray_->ShouldBlockShelfAutoHide()))
137 return true;
138
139 if (palette_tray_ && palette_tray_->ShouldBlockShelfAutoHide())
140 return true;
141
142 if (ime_menu_tray_ && ime_menu_tray_->ShouldBlockShelfAutoHide())
143 return true;
144
145 return false;
146 }
147
148 bool StatusAreaWidget::IsMessageBubbleShown() const {
149 return ((system_tray_ && system_tray_->IsSystemBubbleVisible()) ||
150 (web_notification_tray_ &&
151 web_notification_tray_->IsMessageCenterBubbleVisible()));
152 }
153
154 void StatusAreaWidget::SchedulePaint() {
155 status_area_widget_delegate_->SchedulePaint();
156 web_notification_tray_->SchedulePaint();
157 system_tray_->SchedulePaint();
158 virtual_keyboard_tray_->SchedulePaint();
159 logout_button_tray_->SchedulePaint();
160 ime_menu_tray_->SchedulePaint();
161 if (palette_tray_)
162 palette_tray_->SchedulePaint();
163 overview_button_tray_->SchedulePaint();
164 }
165
166 const ui::NativeTheme* StatusAreaWidget::GetNativeTheme() const {
167 return MaterialDesignController::IsShelfMaterial()
168 ? ui::NativeThemeDarkAura::instance()
169 : Widget::GetNativeTheme();
170 }
171
172 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) {
173 Widget::OnNativeWidgetActivationChanged(active);
174 if (active)
175 status_area_widget_delegate_->SetPaneFocusAndFocusDefault();
176 }
177
178 void StatusAreaWidget::UpdateShelfItemBackground(SkColor color) {
179 web_notification_tray_->UpdateShelfItemBackground(color);
180 system_tray_->UpdateShelfItemBackground(color);
181 virtual_keyboard_tray_->UpdateShelfItemBackground(color);
182 logout_button_tray_->UpdateShelfItemBackground(color);
183 ime_menu_tray_->UpdateShelfItemBackground(color);
184 if (palette_tray_)
185 palette_tray_->UpdateShelfItemBackground(color);
186 overview_button_tray_->UpdateShelfItemBackground(color);
187 }
188
189 void StatusAreaWidget::AddSystemTray() {
190 system_tray_ = new SystemTray(wm_shelf_);
191 status_area_widget_delegate_->AddTray(system_tray_);
192 }
193
194 void StatusAreaWidget::AddWebNotificationTray() {
195 DCHECK(system_tray_);
196 web_notification_tray_ = new WebNotificationTray(
197 wm_shelf_, WmWindow::Get(this->GetNativeWindow()), system_tray_);
198 status_area_widget_delegate_->AddTray(web_notification_tray_);
199 }
200
201 void StatusAreaWidget::AddLogoutButtonTray() {
202 logout_button_tray_ = new LogoutButtonTray(wm_shelf_);
203 status_area_widget_delegate_->AddTray(logout_button_tray_);
204 }
205
206 void StatusAreaWidget::AddPaletteTray() {
207 const display::Display& display =
208 WmWindow::Get(this->GetNativeWindow())->GetDisplayNearestWindow();
209
210 // Create the palette only on the internal display, where the stylus is
211 // available. We also create a palette on every display if requested from the
212 // command line.
213 if (display.IsInternal() || palette_utils::IsPaletteEnabledOnEveryDisplay()) {
214 palette_tray_ = new PaletteTray(wm_shelf_);
215 status_area_widget_delegate_->AddTray(palette_tray_);
216 }
217 }
218
219 void StatusAreaWidget::AddVirtualKeyboardTray() {
220 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_);
221 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_);
222 }
223
224 void StatusAreaWidget::AddImeMenuTray() {
225 ime_menu_tray_ = new ImeMenuTray(wm_shelf_);
226 status_area_widget_delegate_->AddTray(ime_menu_tray_);
227 }
228
229 void StatusAreaWidget::AddOverviewButtonTray() {
230 overview_button_tray_ = new OverviewButtonTray(wm_shelf_);
231 status_area_widget_delegate_->AddTray(overview_button_tray_);
232 }
233
234 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/status_area_widget.h ('k') | ash/common/system/status_area_widget_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698