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

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

Issue 2591553002: Remove non-cros support from ash/common/system. (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "ash/common/system/status_area_widget.h" 5 #include "ash/common/system/status_area_widget.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/shelf/wm_shelf.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"
9 #include "ash/common/system/overview/overview_button_tray.h" 14 #include "ash/common/system/overview/overview_button_tray.h"
10 #include "ash/common/system/status_area_widget_delegate.h" 15 #include "ash/common/system/status_area_widget_delegate.h"
11 #include "ash/common/system/tray/system_tray.h" 16 #include "ash/common/system/tray/system_tray.h"
12 #include "ash/common/system/tray/system_tray_delegate.h" 17 #include "ash/common/system/tray/system_tray_delegate.h"
13 #include "ash/common/system/web_notification/web_notification_tray.h" 18 #include "ash/common/system/web_notification/web_notification_tray.h"
14 #include "ash/common/wm_lookup.h" 19 #include "ash/common/wm_lookup.h"
15 #include "ash/common/wm_root_window_controller.h" 20 #include "ash/common/wm_root_window_controller.h"
16 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
17 #include "ash/common/wm_window.h" 22 #include "ash/common/wm_window.h"
18 #include "ash/public/cpp/shell_window_ids.h" 23 #include "ash/public/cpp/shell_window_ids.h"
19 #include "base/i18n/time_formatting.h" 24 #include "base/i18n/time_formatting.h"
25 #include "ui/display/display.h"
20 #include "ui/native_theme/native_theme_dark_aura.h" 26 #include "ui/native_theme/native_theme_dark_aura.h"
21 27
22 #if defined(OS_CHROMEOS)
23 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h"
24 #include "ash/common/system/chromeos/palette/palette_tray.h"
25 #include "ash/common/system/chromeos/palette/palette_utils.h"
26 #include "ash/common/system/chromeos/session/logout_button_tray.h"
27 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h"
28 #include "ui/display/display.h"
29 #endif
30
31 namespace ash { 28 namespace ash {
32 29
33 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container, 30 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container,
34 WmShelf* wm_shelf) 31 WmShelf* wm_shelf)
35 : status_area_widget_delegate_(new StatusAreaWidgetDelegate), 32 : status_area_widget_delegate_(new StatusAreaWidgetDelegate),
36 overview_button_tray_(nullptr), 33 overview_button_tray_(nullptr),
37 system_tray_(nullptr), 34 system_tray_(nullptr),
38 web_notification_tray_(nullptr), 35 web_notification_tray_(nullptr),
39 #if defined(OS_CHROMEOS)
40 logout_button_tray_(nullptr), 36 logout_button_tray_(nullptr),
41 palette_tray_(nullptr), 37 palette_tray_(nullptr),
42 virtual_keyboard_tray_(nullptr), 38 virtual_keyboard_tray_(nullptr),
43 ime_menu_tray_(nullptr), 39 ime_menu_tray_(nullptr),
44 #endif
45 login_status_(LoginStatus::NOT_LOGGED_IN), 40 login_status_(LoginStatus::NOT_LOGGED_IN),
46 wm_shelf_(wm_shelf) { 41 wm_shelf_(wm_shelf) {
47 views::Widget::InitParams params( 42 views::Widget::InitParams params(
48 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 43 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
49 params.delegate = status_area_widget_delegate_; 44 params.delegate = status_area_widget_delegate_;
50 params.name = "StatusAreaWidget"; 45 params.name = "StatusAreaWidget";
51 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 46 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
52 status_container->GetRootWindowController() 47 status_container->GetRootWindowController()
53 ->ConfigureWidgetInitParamsForContainer( 48 ->ConfigureWidgetInitParamsForContainer(
54 this, status_container->GetShellWindowId(), &params); 49 this, status_container->GetShellWindowId(), &params);
55 Init(params); 50 Init(params);
56 set_focus_on_creation(false); 51 set_focus_on_creation(false);
57 SetContentsView(status_area_widget_delegate_); 52 SetContentsView(status_area_widget_delegate_);
58 } 53 }
59 54
60 StatusAreaWidget::~StatusAreaWidget() {} 55 StatusAreaWidget::~StatusAreaWidget() {}
61 56
62 void StatusAreaWidget::CreateTrayViews() { 57 void StatusAreaWidget::CreateTrayViews() {
63 AddOverviewButtonTray(); 58 AddOverviewButtonTray();
64 AddSystemTray(); 59 AddSystemTray();
65 AddWebNotificationTray(); 60 AddWebNotificationTray();
66 #if defined(OS_CHROMEOS)
67 AddPaletteTray(); 61 AddPaletteTray();
68 AddVirtualKeyboardTray(); 62 AddVirtualKeyboardTray();
69 AddImeMenuTray(); 63 AddImeMenuTray();
70 AddLogoutButtonTray(); 64 AddLogoutButtonTray();
71 #endif
72 65
73 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 66 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
74 DCHECK(delegate); 67 DCHECK(delegate);
75 // Initialize after all trays have been created. 68 // Initialize after all trays have been created.
76 system_tray_->InitializeTrayItems(delegate, web_notification_tray_); 69 system_tray_->InitializeTrayItems(delegate, web_notification_tray_);
77 web_notification_tray_->Initialize(); 70 web_notification_tray_->Initialize();
78 #if defined(OS_CHROMEOS)
79 logout_button_tray_->Initialize(); 71 logout_button_tray_->Initialize();
80 if (palette_tray_) 72 if (palette_tray_)
81 palette_tray_->Initialize(); 73 palette_tray_->Initialize();
82 virtual_keyboard_tray_->Initialize(); 74 virtual_keyboard_tray_->Initialize();
83 ime_menu_tray_->Initialize(); 75 ime_menu_tray_->Initialize();
84 #endif
85 overview_button_tray_->Initialize(); 76 overview_button_tray_->Initialize();
86 SetShelfAlignment(system_tray_->shelf_alignment()); 77 SetShelfAlignment(system_tray_->shelf_alignment());
87 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); 78 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus());
88 } 79 }
89 80
90 void StatusAreaWidget::Shutdown() { 81 void StatusAreaWidget::Shutdown() {
91 system_tray_->Shutdown(); 82 system_tray_->Shutdown();
92 // Destroy the trays early, causing them to be removed from the view 83 // Destroy the trays early, causing them to be removed from the view
93 // hierarchy. Do not used scoped pointers since we don't want to destroy them 84 // hierarchy. Do not used scoped pointers since we don't want to destroy them
94 // in the destructor if Shutdown() is not called (e.g. in tests). 85 // in the destructor if Shutdown() is not called (e.g. in tests).
95 delete web_notification_tray_; 86 delete web_notification_tray_;
96 web_notification_tray_ = nullptr; 87 web_notification_tray_ = nullptr;
97 // Must be destroyed after |web_notification_tray_|. 88 // Must be destroyed after |web_notification_tray_|.
98 delete system_tray_; 89 delete system_tray_;
99 system_tray_ = nullptr; 90 system_tray_ = nullptr;
100 #if defined(OS_CHROMEOS)
101 delete ime_menu_tray_; 91 delete ime_menu_tray_;
102 ime_menu_tray_ = nullptr; 92 ime_menu_tray_ = nullptr;
103 delete virtual_keyboard_tray_; 93 delete virtual_keyboard_tray_;
104 virtual_keyboard_tray_ = nullptr; 94 virtual_keyboard_tray_ = nullptr;
105 delete logout_button_tray_; 95 delete logout_button_tray_;
106 logout_button_tray_ = nullptr; 96 logout_button_tray_ = nullptr;
107 #endif
108 delete overview_button_tray_; 97 delete overview_button_tray_;
109 overview_button_tray_ = nullptr; 98 overview_button_tray_ = nullptr;
110 } 99 }
111 100
112 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { 101 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) {
113 status_area_widget_delegate_->set_alignment(alignment); 102 status_area_widget_delegate_->set_alignment(alignment);
114 if (system_tray_) 103 if (system_tray_)
115 system_tray_->SetShelfAlignment(alignment); 104 system_tray_->SetShelfAlignment(alignment);
116 if (web_notification_tray_) 105 if (web_notification_tray_)
117 web_notification_tray_->SetShelfAlignment(alignment); 106 web_notification_tray_->SetShelfAlignment(alignment);
118 #if defined(OS_CHROMEOS)
119 if (logout_button_tray_) 107 if (logout_button_tray_)
120 logout_button_tray_->SetShelfAlignment(alignment); 108 logout_button_tray_->SetShelfAlignment(alignment);
121 if (virtual_keyboard_tray_) 109 if (virtual_keyboard_tray_)
122 virtual_keyboard_tray_->SetShelfAlignment(alignment); 110 virtual_keyboard_tray_->SetShelfAlignment(alignment);
123 if (ime_menu_tray_) 111 if (ime_menu_tray_)
124 ime_menu_tray_->SetShelfAlignment(alignment); 112 ime_menu_tray_->SetShelfAlignment(alignment);
125 if (palette_tray_) 113 if (palette_tray_)
126 palette_tray_->SetShelfAlignment(alignment); 114 palette_tray_->SetShelfAlignment(alignment);
127 #endif
128 if (overview_button_tray_) 115 if (overview_button_tray_)
129 overview_button_tray_->SetShelfAlignment(alignment); 116 overview_button_tray_->SetShelfAlignment(alignment);
130 status_area_widget_delegate_->UpdateLayout(); 117 status_area_widget_delegate_->UpdateLayout();
131 } 118 }
132 119
133 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { 120 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) {
134 if (login_status_ == login_status) 121 if (login_status_ == login_status)
135 return; 122 return;
136 login_status_ = login_status; 123 login_status_ = login_status;
137 if (system_tray_) 124 if (system_tray_)
138 system_tray_->UpdateAfterLoginStatusChange(login_status); 125 system_tray_->UpdateAfterLoginStatusChange(login_status);
139 if (web_notification_tray_) 126 if (web_notification_tray_)
140 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); 127 web_notification_tray_->UpdateAfterLoginStatusChange(login_status);
141 #if defined(OS_CHROMEOS)
142 if (logout_button_tray_) 128 if (logout_button_tray_)
143 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); 129 logout_button_tray_->UpdateAfterLoginStatusChange(login_status);
144 #endif
145 if (overview_button_tray_) 130 if (overview_button_tray_)
146 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); 131 overview_button_tray_->UpdateAfterLoginStatusChange(login_status);
147 } 132 }
148 133
149 bool StatusAreaWidget::ShouldShowShelf() const { 134 bool StatusAreaWidget::ShouldShowShelf() const {
150 if ((system_tray_ && system_tray_->ShouldShowShelf()) || 135 if ((system_tray_ && system_tray_->ShouldShowShelf()) ||
151 (web_notification_tray_ && 136 (web_notification_tray_ &&
152 web_notification_tray_->ShouldBlockShelfAutoHide())) 137 web_notification_tray_->ShouldBlockShelfAutoHide()))
153 return true; 138 return true;
154 139
155 #if defined(OS_CHROMEOS)
156 if (palette_tray_ && palette_tray_->ShouldBlockShelfAutoHide()) 140 if (palette_tray_ && palette_tray_->ShouldBlockShelfAutoHide())
157 return true; 141 return true;
158 142
159 if (ime_menu_tray_ && ime_menu_tray_->ShouldBlockShelfAutoHide()) 143 if (ime_menu_tray_ && ime_menu_tray_->ShouldBlockShelfAutoHide())
160 return true; 144 return true;
161 #endif
162 145
163 if (!wm_shelf_->IsVisible()) 146 if (!wm_shelf_->IsVisible())
164 return false; 147 return false;
165 148
166 // If the shelf is currently visible, don't hide the shelf if the mouse 149 // If the shelf is currently visible, don't hide the shelf if the mouse
167 // is in any of the notification bubbles. 150 // is in any of the notification bubbles.
168 return (system_tray_ && system_tray_->IsMouseInNotificationBubble()) || 151 return (system_tray_ && system_tray_->IsMouseInNotificationBubble()) ||
169 (web_notification_tray_ && 152 (web_notification_tray_ &&
170 web_notification_tray_->IsMouseInNotificationBubble()); 153 web_notification_tray_->IsMouseInNotificationBubble());
171 } 154 }
172 155
173 bool StatusAreaWidget::IsMessageBubbleShown() const { 156 bool StatusAreaWidget::IsMessageBubbleShown() const {
174 return ((system_tray_ && system_tray_->IsAnyBubbleVisible()) || 157 return ((system_tray_ && system_tray_->IsAnyBubbleVisible()) ||
175 (web_notification_tray_ && 158 (web_notification_tray_ &&
176 web_notification_tray_->IsMessageCenterBubbleVisible())); 159 web_notification_tray_->IsMessageCenterBubbleVisible()));
177 } 160 }
178 161
179 void StatusAreaWidget::SchedulePaint() { 162 void StatusAreaWidget::SchedulePaint() {
180 status_area_widget_delegate_->SchedulePaint(); 163 status_area_widget_delegate_->SchedulePaint();
181 web_notification_tray_->SchedulePaint(); 164 web_notification_tray_->SchedulePaint();
182 system_tray_->SchedulePaint(); 165 system_tray_->SchedulePaint();
183 #if defined(OS_CHROMEOS)
184 virtual_keyboard_tray_->SchedulePaint(); 166 virtual_keyboard_tray_->SchedulePaint();
185 logout_button_tray_->SchedulePaint(); 167 logout_button_tray_->SchedulePaint();
186 ime_menu_tray_->SchedulePaint(); 168 ime_menu_tray_->SchedulePaint();
187 if (palette_tray_) 169 if (palette_tray_)
188 palette_tray_->SchedulePaint(); 170 palette_tray_->SchedulePaint();
189 #endif
190 overview_button_tray_->SchedulePaint(); 171 overview_button_tray_->SchedulePaint();
191 } 172 }
192 173
193 const ui::NativeTheme* StatusAreaWidget::GetNativeTheme() const { 174 const ui::NativeTheme* StatusAreaWidget::GetNativeTheme() const {
194 return MaterialDesignController::IsShelfMaterial() 175 return MaterialDesignController::IsShelfMaterial()
195 ? ui::NativeThemeDarkAura::instance() 176 ? ui::NativeThemeDarkAura::instance()
196 : Widget::GetNativeTheme(); 177 : Widget::GetNativeTheme();
197 } 178 }
198 179
199 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { 180 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) {
200 Widget::OnNativeWidgetActivationChanged(active); 181 Widget::OnNativeWidgetActivationChanged(active);
201 if (active) 182 if (active)
202 status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); 183 status_area_widget_delegate_->SetPaneFocusAndFocusDefault();
203 } 184 }
204 185
205 void StatusAreaWidget::UpdateShelfItemBackground(int alpha) { 186 void StatusAreaWidget::UpdateShelfItemBackground(int alpha) {
206 web_notification_tray_->UpdateShelfItemBackground(alpha); 187 web_notification_tray_->UpdateShelfItemBackground(alpha);
207 system_tray_->UpdateShelfItemBackground(alpha); 188 system_tray_->UpdateShelfItemBackground(alpha);
208 #if defined(OS_CHROMEOS)
209 virtual_keyboard_tray_->UpdateShelfItemBackground(alpha); 189 virtual_keyboard_tray_->UpdateShelfItemBackground(alpha);
210 logout_button_tray_->UpdateShelfItemBackground(alpha); 190 logout_button_tray_->UpdateShelfItemBackground(alpha);
211 ime_menu_tray_->UpdateShelfItemBackground(alpha); 191 ime_menu_tray_->UpdateShelfItemBackground(alpha);
212 if (palette_tray_) 192 if (palette_tray_)
213 palette_tray_->UpdateShelfItemBackground(alpha); 193 palette_tray_->UpdateShelfItemBackground(alpha);
214 #endif
215 overview_button_tray_->UpdateShelfItemBackground(alpha); 194 overview_button_tray_->UpdateShelfItemBackground(alpha);
216 } 195 }
217 196
218 void StatusAreaWidget::AddSystemTray() { 197 void StatusAreaWidget::AddSystemTray() {
219 system_tray_ = new SystemTray(wm_shelf_); 198 system_tray_ = new SystemTray(wm_shelf_);
220 status_area_widget_delegate_->AddTray(system_tray_); 199 status_area_widget_delegate_->AddTray(system_tray_);
221 } 200 }
222 201
223 void StatusAreaWidget::AddWebNotificationTray() { 202 void StatusAreaWidget::AddWebNotificationTray() {
224 DCHECK(system_tray_); 203 DCHECK(system_tray_);
225 web_notification_tray_ = new WebNotificationTray( 204 web_notification_tray_ = new WebNotificationTray(
226 wm_shelf_, WmLookup::Get()->GetWindowForWidget(this), system_tray_); 205 wm_shelf_, WmLookup::Get()->GetWindowForWidget(this), system_tray_);
227 status_area_widget_delegate_->AddTray(web_notification_tray_); 206 status_area_widget_delegate_->AddTray(web_notification_tray_);
228 } 207 }
229 208
230 #if defined(OS_CHROMEOS)
231 void StatusAreaWidget::AddLogoutButtonTray() { 209 void StatusAreaWidget::AddLogoutButtonTray() {
232 logout_button_tray_ = new LogoutButtonTray(wm_shelf_); 210 logout_button_tray_ = new LogoutButtonTray(wm_shelf_);
233 status_area_widget_delegate_->AddTray(logout_button_tray_); 211 status_area_widget_delegate_->AddTray(logout_button_tray_);
234 } 212 }
235 213
236 void StatusAreaWidget::AddPaletteTray() { 214 void StatusAreaWidget::AddPaletteTray() {
237 if (!IsPaletteFeatureEnabled()) 215 if (!IsPaletteFeatureEnabled())
238 return; 216 return;
239 217
240 const display::Display& display = 218 const display::Display& display =
(...skipping 10 matching lines...) Expand all
251 229
252 void StatusAreaWidget::AddVirtualKeyboardTray() { 230 void StatusAreaWidget::AddVirtualKeyboardTray() {
253 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); 231 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_);
254 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); 232 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_);
255 } 233 }
256 234
257 void StatusAreaWidget::AddImeMenuTray() { 235 void StatusAreaWidget::AddImeMenuTray() {
258 ime_menu_tray_ = new ImeMenuTray(wm_shelf_); 236 ime_menu_tray_ = new ImeMenuTray(wm_shelf_);
259 status_area_widget_delegate_->AddTray(ime_menu_tray_); 237 status_area_widget_delegate_->AddTray(ime_menu_tray_);
260 } 238 }
261 #endif
262 239
263 void StatusAreaWidget::AddOverviewButtonTray() { 240 void StatusAreaWidget::AddOverviewButtonTray() {
264 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); 241 overview_button_tray_ = new OverviewButtonTray(wm_shelf_);
265 status_area_widget_delegate_->AddTray(overview_button_tray_); 242 status_area_widget_delegate_->AddTray(overview_button_tray_);
266 } 243 }
267 244
268 } // namespace ash 245 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698