| 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/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/shelf/wm_shelf.h" | 8 #include "ash/common/shelf/wm_shelf.h" |
| 8 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 9 #include "ash/common/system/overview/overview_button_tray.h" | 10 #include "ash/common/system/overview/overview_button_tray.h" |
| 10 #include "ash/common/system/status_area_widget_delegate.h" | 11 #include "ash/common/system/status_area_widget_delegate.h" |
| 11 #include "ash/common/system/tray/system_tray.h" | 12 #include "ash/common/system/tray/system_tray.h" |
| 12 #include "ash/common/system/tray/system_tray_delegate.h" | 13 #include "ash/common/system/tray/system_tray_delegate.h" |
| 13 #include "ash/common/system/web_notification/web_notification_tray.h" | 14 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 14 #include "ash/common/wm_lookup.h" | 15 #include "ash/common/wm_lookup.h" |
| 15 #include "ash/common/wm_root_window_controller.h" | 16 #include "ash/common/wm_root_window_controller.h" |
| 16 #include "ash/common/wm_shell.h" | 17 #include "ash/common/wm_shell.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ime_menu_tray_ = nullptr; | 97 ime_menu_tray_ = nullptr; |
| 97 delete virtual_keyboard_tray_; | 98 delete virtual_keyboard_tray_; |
| 98 virtual_keyboard_tray_ = nullptr; | 99 virtual_keyboard_tray_ = nullptr; |
| 99 delete logout_button_tray_; | 100 delete logout_button_tray_; |
| 100 logout_button_tray_ = nullptr; | 101 logout_button_tray_ = nullptr; |
| 101 #endif | 102 #endif |
| 102 delete overview_button_tray_; | 103 delete overview_button_tray_; |
| 103 overview_button_tray_ = nullptr; | 104 overview_button_tray_ = nullptr; |
| 104 } | 105 } |
| 105 | 106 |
| 107 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
| 108 status_area_widget_delegate_->set_alignment(alignment); |
| 109 if (system_tray_) |
| 110 system_tray_->SetShelfAlignment(alignment); |
| 111 if (web_notification_tray_) |
| 112 web_notification_tray_->SetShelfAlignment(alignment); |
| 113 #if defined(OS_CHROMEOS) |
| 114 if (logout_button_tray_) |
| 115 logout_button_tray_->SetShelfAlignment(alignment); |
| 116 if (virtual_keyboard_tray_) |
| 117 virtual_keyboard_tray_->SetShelfAlignment(alignment); |
| 118 if (ime_menu_tray_) |
| 119 ime_menu_tray_->SetShelfAlignment(alignment); |
| 120 if (palette_tray_) |
| 121 palette_tray_->SetShelfAlignment(alignment); |
| 122 #endif |
| 123 if (overview_button_tray_) |
| 124 overview_button_tray_->SetShelfAlignment(alignment); |
| 125 status_area_widget_delegate_->UpdateLayout(); |
| 126 } |
| 127 |
| 128 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { |
| 129 if (login_status_ == login_status) |
| 130 return; |
| 131 login_status_ = login_status; |
| 132 if (system_tray_) |
| 133 system_tray_->UpdateAfterLoginStatusChange(login_status); |
| 134 if (web_notification_tray_) |
| 135 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |
| 136 #if defined(OS_CHROMEOS) |
| 137 if (logout_button_tray_) |
| 138 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 139 #endif |
| 140 if (overview_button_tray_) |
| 141 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 142 } |
| 143 |
| 144 void StatusAreaWidget::OnTrayVisibilityChanged(TrayBackgroundView* tray) { |
| 145 if (!ash::MaterialDesignController::IsShelfMaterial()) |
| 146 return; |
| 147 |
| 148 // No separator is required between |system_tray_| and |overview_button_tray_| |
| 149 // and no separator is required for the right most tray item. |
| 150 if (tray == overview_button_tray_ || tray == system_tray_) { |
| 151 tray->SetSeparatorVisibility(false); |
| 152 return; |
| 153 } |
| 154 #if defined(OS_CHROMEOS) |
| 155 // If |logout_button_tray_| is visible, check if |tray| is visible and to |
| 156 // the left of |logout_button_tray_|. If it is the case, then no separator |
| 157 // is required between |tray| and |logout_button_tray_|. If |
| 158 // |logout_button_tray_| is not visible, then separator should always be |
| 159 // visible. |
| 160 tray->SetSeparatorVisibility(!IsNextVisibleTrayToLogout(tray) && |
| 161 tray != logout_button_tray_); |
| 162 #else |
| 163 tray->SetSeparatorVisibility(true); |
| 164 #endif |
| 165 } |
| 166 |
| 106 bool StatusAreaWidget::ShouldShowShelf() const { | 167 bool StatusAreaWidget::ShouldShowShelf() const { |
| 107 if ((system_tray_ && system_tray_->ShouldShowShelf()) || | 168 if ((system_tray_ && system_tray_->ShouldShowShelf()) || |
| 108 (web_notification_tray_ && | 169 (web_notification_tray_ && |
| 109 web_notification_tray_->ShouldBlockShelfAutoHide())) | 170 web_notification_tray_->ShouldBlockShelfAutoHide())) |
| 110 return true; | 171 return true; |
| 111 | 172 |
| 112 if (!wm_shelf_->IsVisible()) | 173 if (!wm_shelf_->IsVisible()) |
| 113 return false; | 174 return false; |
| 114 | 175 |
| 115 // If the shelf is currently visible, don't hide the shelf if the mouse | 176 // If the shelf is currently visible, don't hide the shelf if the mouse |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 242 |
| 182 void StatusAreaWidget::AddVirtualKeyboardTray() { | 243 void StatusAreaWidget::AddVirtualKeyboardTray() { |
| 183 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); | 244 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); |
| 184 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); | 245 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |
| 185 } | 246 } |
| 186 | 247 |
| 187 void StatusAreaWidget::AddImeMenuTray() { | 248 void StatusAreaWidget::AddImeMenuTray() { |
| 188 ime_menu_tray_ = new ImeMenuTray(wm_shelf_); | 249 ime_menu_tray_ = new ImeMenuTray(wm_shelf_); |
| 189 status_area_widget_delegate_->AddTray(ime_menu_tray_); | 250 status_area_widget_delegate_->AddTray(ime_menu_tray_); |
| 190 } | 251 } |
| 252 |
| 253 bool StatusAreaWidget::IsNextVisibleTrayToLogout( |
| 254 TrayBackgroundView* tray) const { |
| 255 int logout_button_index = |
| 256 status_area_widget_delegate_->GetIndexOf(logout_button_tray_); |
| 257 // Logout button should always exist. |
| 258 DCHECK_NE(-1, logout_button_index); |
| 259 if (!logout_button_tray_->visible()) |
| 260 return false; |
| 261 |
| 262 for (int c = logout_button_index + 1; |
| 263 c < status_area_widget_delegate_->child_count(); c++) { |
| 264 if (status_area_widget_delegate_->child_at(c)->visible()) |
| 265 return tray == status_area_widget_delegate_->child_at(c); |
| 266 } |
| 267 return false; |
| 268 } |
| 191 #endif | 269 #endif |
| 192 | 270 |
| 193 void StatusAreaWidget::AddOverviewButtonTray() { | 271 void StatusAreaWidget::AddOverviewButtonTray() { |
| 194 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); | 272 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); |
| 195 status_area_widget_delegate_->AddTray(overview_button_tray_); | 273 status_area_widget_delegate_->AddTray(overview_button_tray_); |
| 196 } | 274 } |
| 197 | 275 |
| 198 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | |
| 199 status_area_widget_delegate_->set_alignment(alignment); | |
| 200 if (system_tray_) | |
| 201 system_tray_->SetShelfAlignment(alignment); | |
| 202 if (web_notification_tray_) | |
| 203 web_notification_tray_->SetShelfAlignment(alignment); | |
| 204 #if defined(OS_CHROMEOS) | |
| 205 if (logout_button_tray_) | |
| 206 logout_button_tray_->SetShelfAlignment(alignment); | |
| 207 if (virtual_keyboard_tray_) | |
| 208 virtual_keyboard_tray_->SetShelfAlignment(alignment); | |
| 209 if (ime_menu_tray_) | |
| 210 ime_menu_tray_->SetShelfAlignment(alignment); | |
| 211 if (palette_tray_) | |
| 212 palette_tray_->SetShelfAlignment(alignment); | |
| 213 #endif | |
| 214 if (overview_button_tray_) | |
| 215 overview_button_tray_->SetShelfAlignment(alignment); | |
| 216 status_area_widget_delegate_->UpdateLayout(); | |
| 217 } | |
| 218 | |
| 219 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { | |
| 220 if (login_status_ == login_status) | |
| 221 return; | |
| 222 login_status_ = login_status; | |
| 223 if (system_tray_) | |
| 224 system_tray_->UpdateAfterLoginStatusChange(login_status); | |
| 225 if (web_notification_tray_) | |
| 226 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | |
| 227 #if defined(OS_CHROMEOS) | |
| 228 if (logout_button_tray_) | |
| 229 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); | |
| 230 #endif | |
| 231 if (overview_button_tray_) | |
| 232 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); | |
| 233 } | |
| 234 | |
| 235 } // namespace ash | 276 } // namespace ash |
| OLD | NEW |