OLD | NEW |
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/system/status_area_widget.h" | 5 #include "ash/system/status_area_widget.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
9 #include "ash/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/shell_delegate.h" | 11 #include "ash/shell_delegate.h" |
12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
13 #include "ash/system/bluetooth/bluetooth_observer.h" | 13 #include "ash/system/bluetooth/bluetooth_observer.h" |
| 14 #include "ash/system/overview/overview_button_tray.h" |
14 #include "ash/system/session/logout_button_tray.h" | 15 #include "ash/system/session/logout_button_tray.h" |
15 #include "ash/system/status_area_widget_delegate.h" | 16 #include "ash/system/status_area_widget_delegate.h" |
16 #include "ash/system/tray/system_tray.h" | 17 #include "ash/system/tray/system_tray.h" |
17 #include "ash/system/tray/system_tray_delegate.h" | 18 #include "ash/system/tray/system_tray_delegate.h" |
18 #include "ash/system/web_notification/web_notification_tray.h" | 19 #include "ash/system/web_notification/web_notification_tray.h" |
19 #include "ash/wm/window_properties.h" | 20 #include "ash/wm/window_properties.h" |
20 #include "base/i18n/time_formatting.h" | 21 #include "base/i18n/time_formatting.h" |
21 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
22 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
23 | 24 |
24 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
25 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" | 26 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" |
26 #endif | 27 #endif |
27 | 28 |
28 namespace ash { | 29 namespace ash { |
29 | 30 |
30 namespace internal { | 31 namespace internal { |
31 | 32 |
32 const char StatusAreaWidget::kNativeViewName[] = "StatusAreaWidget"; | 33 const char StatusAreaWidget::kNativeViewName[] = "StatusAreaWidget"; |
33 | 34 |
34 StatusAreaWidget::StatusAreaWidget(aura::Window* status_container) | 35 StatusAreaWidget::StatusAreaWidget(aura::Window* status_container) |
35 : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), | 36 : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), |
| 37 overview_button_tray_(NULL), |
36 system_tray_(NULL), | 38 system_tray_(NULL), |
37 web_notification_tray_(NULL), | 39 web_notification_tray_(NULL), |
38 logout_button_tray_(NULL), | 40 logout_button_tray_(NULL), |
39 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
40 virtual_keyboard_tray_(NULL), | 42 virtual_keyboard_tray_(NULL), |
41 #endif | 43 #endif |
42 login_status_(user::LOGGED_IN_NONE) { | 44 login_status_(user::LOGGED_IN_NONE) { |
43 views::Widget::InitParams params( | 45 views::Widget::InitParams params( |
44 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 46 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
45 params.delegate = status_area_widget_delegate_; | 47 params.delegate = status_area_widget_delegate_; |
46 params.parent = status_container; | 48 params.parent = status_container; |
47 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 49 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
48 Init(params); | 50 Init(params); |
49 set_focus_on_creation(false); | 51 set_focus_on_creation(false); |
50 SetContentsView(status_area_widget_delegate_); | 52 SetContentsView(status_area_widget_delegate_); |
51 GetNativeView()->SetName(kNativeViewName); | 53 GetNativeView()->SetName(kNativeViewName); |
52 } | 54 } |
53 | 55 |
54 StatusAreaWidget::~StatusAreaWidget() { | 56 StatusAreaWidget::~StatusAreaWidget() { |
55 } | 57 } |
56 | 58 |
57 void StatusAreaWidget::CreateTrayViews() { | 59 void StatusAreaWidget::CreateTrayViews() { |
| 60 AddOverviewButtonTray(); |
58 AddSystemTray(); | 61 AddSystemTray(); |
59 AddWebNotificationTray(); | 62 AddWebNotificationTray(); |
60 AddLogoutButtonTray(); | 63 AddLogoutButtonTray(); |
61 #if defined(OS_CHROMEOS) | 64 #if defined(OS_CHROMEOS) |
62 AddVirtualKeyboardTray(); | 65 AddVirtualKeyboardTray(); |
63 #endif | 66 #endif |
| 67 |
64 SystemTrayDelegate* delegate = | 68 SystemTrayDelegate* delegate = |
65 ash::Shell::GetInstance()->system_tray_delegate(); | 69 ash::Shell::GetInstance()->system_tray_delegate(); |
66 DCHECK(delegate); | 70 DCHECK(delegate); |
67 // Initialize after all trays have been created. | 71 // Initialize after all trays have been created. |
68 if (system_tray_) | 72 system_tray_->InitializeTrayItems(delegate); |
69 system_tray_->InitializeTrayItems(delegate); | 73 web_notification_tray_->Initialize(); |
70 if (web_notification_tray_) | 74 logout_button_tray_->Initialize(); |
71 web_notification_tray_->Initialize(); | |
72 if (logout_button_tray_) | |
73 logout_button_tray_->Initialize(); | |
74 #if defined(OS_CHROMEOS) | 75 #if defined(OS_CHROMEOS) |
75 if (virtual_keyboard_tray_) | 76 virtual_keyboard_tray_->Initialize(); |
76 virtual_keyboard_tray_->Initialize(); | |
77 #endif | 77 #endif |
| 78 overview_button_tray_->Initialize(); |
78 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); | 79 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); |
79 } | 80 } |
80 | 81 |
81 void StatusAreaWidget::Shutdown() { | 82 void StatusAreaWidget::Shutdown() { |
82 // 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 |
83 // 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 |
84 // 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). |
85 delete logout_button_tray_; | 86 delete logout_button_tray_; |
86 logout_button_tray_ = NULL; | 87 logout_button_tray_ = NULL; |
87 delete web_notification_tray_; | 88 delete web_notification_tray_; |
88 web_notification_tray_ = NULL; | 89 web_notification_tray_ = NULL; |
89 delete system_tray_; | 90 delete system_tray_; |
90 system_tray_ = NULL; | 91 system_tray_ = NULL; |
91 #if defined(OS_CHROMEOS) | 92 #if defined(OS_CHROMEOS) |
92 delete virtual_keyboard_tray_; | 93 delete virtual_keyboard_tray_; |
93 virtual_keyboard_tray_ = NULL; | 94 virtual_keyboard_tray_ = NULL; |
94 #endif | 95 #endif |
| 96 delete overview_button_tray_; |
| 97 overview_button_tray_ = NULL; |
95 } | 98 } |
96 | 99 |
97 bool StatusAreaWidget::ShouldShowShelf() const { | 100 bool StatusAreaWidget::ShouldShowShelf() const { |
98 if ((system_tray_ && system_tray_->ShouldShowShelf()) || | 101 if ((system_tray_ && system_tray_->ShouldShowShelf()) || |
99 (web_notification_tray_ && | 102 (web_notification_tray_ && |
100 web_notification_tray_->ShouldBlockShelfAutoHide())) | 103 web_notification_tray_->ShouldBlockShelfAutoHide())) |
101 return true; | 104 return true; |
102 | 105 |
103 if (!RootWindowController::ForShelf(GetNativeView())->shelf()->IsVisible()) | 106 if (!RootWindowController::ForShelf(GetNativeView())->shelf()->IsVisible()) |
104 return false; | 107 return false; |
105 | 108 |
106 // If the shelf is currently visible, don't hide the shelf if the mouse | 109 // If the shelf is currently visible, don't hide the shelf if the mouse |
107 // is in any of the notification bubbles. | 110 // is in any of the notification bubbles. |
108 return (system_tray_ && system_tray_->IsMouseInNotificationBubble()) || | 111 return (system_tray_ && system_tray_->IsMouseInNotificationBubble()) || |
109 (web_notification_tray_ && | 112 (web_notification_tray_ && |
110 web_notification_tray_->IsMouseInNotificationBubble()); | 113 web_notification_tray_->IsMouseInNotificationBubble()); |
111 } | 114 } |
112 | 115 |
113 bool StatusAreaWidget::IsMessageBubbleShown() const { | 116 bool StatusAreaWidget::IsMessageBubbleShown() const { |
114 return ((system_tray_ && system_tray_->IsAnyBubbleVisible()) || | 117 return ((system_tray_ && system_tray_->IsAnyBubbleVisible()) || |
115 (web_notification_tray_ && | 118 (web_notification_tray_ && |
116 web_notification_tray_->IsMessageCenterBubbleVisible())); | 119 web_notification_tray_->IsMessageCenterBubbleVisible())); |
117 } | 120 } |
118 | 121 |
119 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { | 122 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { |
120 Widget::OnNativeWidgetActivationChanged(active); | 123 Widget::OnNativeWidgetActivationChanged(active); |
(...skipping 16 matching lines...) Expand all Loading... |
137 status_area_widget_delegate_->AddTray(logout_button_tray_); | 140 status_area_widget_delegate_->AddTray(logout_button_tray_); |
138 } | 141 } |
139 | 142 |
140 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
141 void StatusAreaWidget::AddVirtualKeyboardTray() { | 144 void StatusAreaWidget::AddVirtualKeyboardTray() { |
142 virtual_keyboard_tray_ = new VirtualKeyboardTray(this); | 145 virtual_keyboard_tray_ = new VirtualKeyboardTray(this); |
143 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); | 146 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |
144 } | 147 } |
145 #endif | 148 #endif |
146 | 149 |
| 150 void StatusAreaWidget::AddOverviewButtonTray() { |
| 151 overview_button_tray_ = new OverviewButtonTray(this); |
| 152 status_area_widget_delegate_->AddTray(overview_button_tray_); |
| 153 } |
| 154 |
147 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 155 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
148 status_area_widget_delegate_->set_alignment(alignment); | 156 status_area_widget_delegate_->set_alignment(alignment); |
149 if (system_tray_) | 157 if (system_tray_) |
150 system_tray_->SetShelfAlignment(alignment); | 158 system_tray_->SetShelfAlignment(alignment); |
151 if (web_notification_tray_) | 159 if (web_notification_tray_) |
152 web_notification_tray_->SetShelfAlignment(alignment); | 160 web_notification_tray_->SetShelfAlignment(alignment); |
153 if (logout_button_tray_) | 161 if (logout_button_tray_) |
154 logout_button_tray_->SetShelfAlignment(alignment); | 162 logout_button_tray_->SetShelfAlignment(alignment); |
155 #if defined(OS_CHROMEOS) | 163 #if defined(OS_CHROMEOS) |
156 if (virtual_keyboard_tray_) | 164 if (virtual_keyboard_tray_) |
157 virtual_keyboard_tray_->SetShelfAlignment(alignment); | 165 virtual_keyboard_tray_->SetShelfAlignment(alignment); |
158 #endif | 166 #endif |
| 167 if (overview_button_tray_) |
| 168 overview_button_tray_->SetShelfAlignment(alignment); |
159 status_area_widget_delegate_->UpdateLayout(); | 169 status_area_widget_delegate_->UpdateLayout(); |
160 } | 170 } |
161 | 171 |
162 void StatusAreaWidget::SetHideSystemNotifications(bool hide) { | 172 void StatusAreaWidget::SetHideSystemNotifications(bool hide) { |
163 if (system_tray_) | 173 if (system_tray_) |
164 system_tray_->SetHideNotifications(hide); | 174 system_tray_->SetHideNotifications(hide); |
165 } | 175 } |
166 | 176 |
167 void StatusAreaWidget::UpdateAfterLoginStatusChange( | 177 void StatusAreaWidget::UpdateAfterLoginStatusChange( |
168 user::LoginStatus login_status) { | 178 user::LoginStatus login_status) { |
169 if (login_status_ == login_status) | 179 if (login_status_ == login_status) |
170 return; | 180 return; |
171 login_status_ = login_status; | 181 login_status_ = login_status; |
172 if (system_tray_) | 182 if (system_tray_) |
173 system_tray_->UpdateAfterLoginStatusChange(login_status); | 183 system_tray_->UpdateAfterLoginStatusChange(login_status); |
174 if (web_notification_tray_) | 184 if (web_notification_tray_) |
175 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | 185 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |
176 if (logout_button_tray_) | 186 if (logout_button_tray_) |
177 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); | 187 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); |
178 } | 188 } |
179 | 189 |
180 } // namespace internal | 190 } // namespace internal |
181 } // namespace ash | 191 } // namespace ash |
OLD | NEW |