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/chromeos/virtual_keyboard/virtual_keyboard_tray.h" |
14 #include "ash/system/logout_button/logout_button_tray.h" | 15 #include "ash/system/logout_button/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 namespace ash { | 25 namespace ash { |
25 | 26 |
26 namespace internal { | 27 namespace internal { |
27 | 28 |
28 const char StatusAreaWidget::kNativeViewName[] = "StatusAreaWidget"; | 29 const char StatusAreaWidget::kNativeViewName[] = "StatusAreaWidget"; |
29 | 30 |
30 StatusAreaWidget::StatusAreaWidget(aura::Window* status_container) | 31 StatusAreaWidget::StatusAreaWidget(aura::Window* status_container) |
31 : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), | 32 : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), |
32 system_tray_(NULL), | 33 system_tray_(NULL), |
33 web_notification_tray_(NULL), | 34 web_notification_tray_(NULL), |
34 logout_button_tray_(NULL), | 35 logout_button_tray_(NULL), |
| 36 virtual_keyboard_tray_(NULL), |
35 login_status_(user::LOGGED_IN_NONE) { | 37 login_status_(user::LOGGED_IN_NONE) { |
36 views::Widget::InitParams params( | 38 views::Widget::InitParams params( |
37 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 39 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
38 params.delegate = status_area_widget_delegate_; | 40 params.delegate = status_area_widget_delegate_; |
39 params.parent = status_container; | 41 params.parent = status_container; |
40 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 42 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
41 Init(params); | 43 Init(params); |
42 set_focus_on_creation(false); | 44 set_focus_on_creation(false); |
43 SetContentsView(status_area_widget_delegate_); | 45 SetContentsView(status_area_widget_delegate_); |
44 GetNativeView()->SetName(kNativeViewName); | 46 GetNativeView()->SetName(kNativeViewName); |
45 } | 47 } |
46 | 48 |
47 StatusAreaWidget::~StatusAreaWidget() { | 49 StatusAreaWidget::~StatusAreaWidget() { |
48 } | 50 } |
49 | 51 |
50 void StatusAreaWidget::CreateTrayViews() { | 52 void StatusAreaWidget::CreateTrayViews() { |
51 AddSystemTray(); | 53 AddSystemTray(); |
52 AddWebNotificationTray(); | 54 AddWebNotificationTray(); |
53 AddLogoutButtonTray(); | 55 AddLogoutButtonTray(); |
| 56 AddVirtualKeyboardTray(); |
54 SystemTrayDelegate* delegate = | 57 SystemTrayDelegate* delegate = |
55 ash::Shell::GetInstance()->system_tray_delegate(); | 58 ash::Shell::GetInstance()->system_tray_delegate(); |
56 DCHECK(delegate); | 59 DCHECK(delegate); |
57 // Initialize after all trays have been created. | 60 // Initialize after all trays have been created. |
58 if (system_tray_) | 61 if (system_tray_) |
59 system_tray_->InitializeTrayItems(delegate); | 62 system_tray_->InitializeTrayItems(delegate); |
60 if (web_notification_tray_) | 63 if (web_notification_tray_) |
61 web_notification_tray_->Initialize(); | 64 web_notification_tray_->Initialize(); |
62 if (logout_button_tray_) | 65 if (logout_button_tray_) |
63 logout_button_tray_->Initialize(); | 66 logout_button_tray_->Initialize(); |
| 67 if (virtual_keyboard_tray_) |
| 68 virtual_keyboard_tray_->Initialize(); |
64 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); | 69 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); |
65 } | 70 } |
66 | 71 |
67 void StatusAreaWidget::Shutdown() { | 72 void StatusAreaWidget::Shutdown() { |
68 // Destroy the trays early, causing them to be removed from the view | 73 // Destroy the trays early, causing them to be removed from the view |
69 // hierarchy. Do not used scoped pointers since we don't want to destroy them | 74 // hierarchy. Do not used scoped pointers since we don't want to destroy them |
70 // in the destructor if Shutdown() is not called (e.g. in tests). | 75 // in the destructor if Shutdown() is not called (e.g. in tests). |
71 delete logout_button_tray_; | 76 delete logout_button_tray_; |
72 logout_button_tray_ = NULL; | 77 logout_button_tray_ = NULL; |
73 delete web_notification_tray_; | 78 delete web_notification_tray_; |
74 web_notification_tray_ = NULL; | 79 web_notification_tray_ = NULL; |
75 delete system_tray_; | 80 delete system_tray_; |
76 system_tray_ = NULL; | 81 system_tray_ = NULL; |
| 82 delete virtual_keyboard_tray_; |
| 83 virtual_keyboard_tray_ = NULL; |
77 } | 84 } |
78 | 85 |
79 bool StatusAreaWidget::ShouldShowShelf() const { | 86 bool StatusAreaWidget::ShouldShowShelf() const { |
80 if ((system_tray_ && system_tray_->ShouldShowShelf()) || | 87 if ((system_tray_ && system_tray_->ShouldShowShelf()) || |
81 (web_notification_tray_ && | 88 (web_notification_tray_ && |
82 web_notification_tray_->ShouldBlockShelfAutoHide())) | 89 web_notification_tray_->ShouldBlockShelfAutoHide())) |
83 return true; | 90 return true; |
84 | 91 |
85 if (!RootWindowController::ForShelf(GetNativeView())->shelf()->IsVisible()) | 92 if (!RootWindowController::ForShelf(GetNativeView())->shelf()->IsVisible()) |
86 return false; | 93 return false; |
(...skipping 25 matching lines...) Expand all Loading... |
112 void StatusAreaWidget::AddWebNotificationTray() { | 119 void StatusAreaWidget::AddWebNotificationTray() { |
113 web_notification_tray_ = new WebNotificationTray(this); | 120 web_notification_tray_ = new WebNotificationTray(this); |
114 status_area_widget_delegate_->AddTray(web_notification_tray_); | 121 status_area_widget_delegate_->AddTray(web_notification_tray_); |
115 } | 122 } |
116 | 123 |
117 void StatusAreaWidget::AddLogoutButtonTray() { | 124 void StatusAreaWidget::AddLogoutButtonTray() { |
118 logout_button_tray_ = new LogoutButtonTray(this); | 125 logout_button_tray_ = new LogoutButtonTray(this); |
119 status_area_widget_delegate_->AddTray(logout_button_tray_); | 126 status_area_widget_delegate_->AddTray(logout_button_tray_); |
120 } | 127 } |
121 | 128 |
| 129 void StatusAreaWidget::AddVirtualKeyboardTray() { |
| 130 virtual_keyboard_tray_ = new VirtualKeyboardTray(this); |
| 131 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |
| 132 } |
| 133 |
122 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 134 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
123 status_area_widget_delegate_->set_alignment(alignment); | 135 status_area_widget_delegate_->set_alignment(alignment); |
124 if (system_tray_) | 136 if (system_tray_) |
125 system_tray_->SetShelfAlignment(alignment); | 137 system_tray_->SetShelfAlignment(alignment); |
126 if (web_notification_tray_) | 138 if (web_notification_tray_) |
127 web_notification_tray_->SetShelfAlignment(alignment); | 139 web_notification_tray_->SetShelfAlignment(alignment); |
128 if (logout_button_tray_) | 140 if (logout_button_tray_) |
129 logout_button_tray_->SetShelfAlignment(alignment); | 141 logout_button_tray_->SetShelfAlignment(alignment); |
| 142 if (virtual_keyboard_tray_) |
| 143 virtual_keyboard_tray_->SetShelfAlignment(alignment); |
130 status_area_widget_delegate_->UpdateLayout(); | 144 status_area_widget_delegate_->UpdateLayout(); |
131 } | 145 } |
132 | 146 |
133 void StatusAreaWidget::SetHideSystemNotifications(bool hide) { | 147 void StatusAreaWidget::SetHideSystemNotifications(bool hide) { |
134 if (system_tray_) | 148 if (system_tray_) |
135 system_tray_->SetHideNotifications(hide); | 149 system_tray_->SetHideNotifications(hide); |
136 } | 150 } |
137 | 151 |
138 void StatusAreaWidget::UpdateAfterLoginStatusChange( | 152 void StatusAreaWidget::UpdateAfterLoginStatusChange( |
139 user::LoginStatus login_status) { | 153 user::LoginStatus login_status) { |
140 if (login_status_ == login_status) | 154 if (login_status_ == login_status) |
141 return; | 155 return; |
142 login_status_ = login_status; | 156 login_status_ = login_status; |
143 if (system_tray_) | 157 if (system_tray_) |
144 system_tray_->UpdateAfterLoginStatusChange(login_status); | 158 system_tray_->UpdateAfterLoginStatusChange(login_status); |
145 if (web_notification_tray_) | 159 if (web_notification_tray_) |
146 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | 160 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |
147 if (logout_button_tray_) | 161 if (logout_button_tray_) |
148 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); | 162 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); |
149 } | 163 } |
150 | 164 |
151 } // namespace internal | 165 } // namespace internal |
152 } // namespace ash | 166 } // namespace ash |
OLD | NEW |