Chromium Code Reviews| 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()) { | |
|
yoshiki
2016/08/18 08:39:08
nit: no need brackets, since there is only a line
yiyix
2016/08/18 20:01:43
Thanks, i missed it.
| |
| 146 return; | |
| 147 } | |
| 148 | |
| 149 // No separator is required between |system_tray_| and |overview_button_tray_| | |
| 150 // and no separator is required for the right most tray item. | |
| 151 if (tray == overview_button_tray_ || tray == system_tray_) { | |
| 152 tray->SetSeparatorVisibility(false); | |
| 153 return; | |
| 154 } | |
| 155 #if defined(OS_CHROMEOS) | |
| 156 // If |logout_button_tray_| is visible, check if |tray| is visible and to | |
| 157 // the left of |logout_button_tray_|. If it is the case, then no separator | |
| 158 // is required between |tray| and |logout_button_tray_|. If | |
| 159 // |logout_button_tray_| is not visible, then separator should always be | |
| 160 // visible. | |
| 161 tray->SetSeparatorVisibility(!IsNextVisibleTrayToLogout(tray) && | |
| 162 tray != logout_button_tray_); | |
| 163 #else | |
| 164 tray->SetSeparatorVisibility(true); | |
| 165 #endif | |
| 166 } | |
| 167 | |
| 106 bool StatusAreaWidget::ShouldShowShelf() const { | 168 bool StatusAreaWidget::ShouldShowShelf() const { |
| 107 if ((system_tray_ && system_tray_->ShouldShowShelf()) || | 169 if ((system_tray_ && system_tray_->ShouldShowShelf()) || |
| 108 (web_notification_tray_ && | 170 (web_notification_tray_ && |
| 109 web_notification_tray_->ShouldBlockShelfAutoHide())) | 171 web_notification_tray_->ShouldBlockShelfAutoHide())) |
| 110 return true; | 172 return true; |
| 111 | 173 |
| 112 if (!wm_shelf_->IsVisible()) | 174 if (!wm_shelf_->IsVisible()) |
| 113 return false; | 175 return false; |
| 114 | 176 |
| 115 // If the shelf is currently visible, don't hide the shelf if the mouse | 177 // 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 | 243 |
| 182 void StatusAreaWidget::AddVirtualKeyboardTray() { | 244 void StatusAreaWidget::AddVirtualKeyboardTray() { |
| 183 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); | 245 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); |
| 184 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); | 246 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |
| 185 } | 247 } |
| 186 | 248 |
| 187 void StatusAreaWidget::AddImeMenuTray() { | 249 void StatusAreaWidget::AddImeMenuTray() { |
| 188 ime_menu_tray_ = new ImeMenuTray(wm_shelf_); | 250 ime_menu_tray_ = new ImeMenuTray(wm_shelf_); |
| 189 status_area_widget_delegate_->AddTray(ime_menu_tray_); | 251 status_area_widget_delegate_->AddTray(ime_menu_tray_); |
| 190 } | 252 } |
| 253 | |
| 254 bool StatusAreaWidget::IsNextVisibleTrayToLogout(TrayBackgroundView* tray) { | |
|
yoshiki
2016/08/18 08:39:08
Shouldn't we return false immediately if logout_bu
yiyix
2016/08/18 20:01:43
|logout_button_tray_| should not be nullptr. It al
| |
| 255 if (!logout_button_tray_->visible()) | |
| 256 return false; | |
| 257 int logout_button_index = | |
| 258 status_area_widget_delegate_->GetIndexOf(logout_button_tray_); | |
| 259 // Logout button should always exist. | |
| 260 DCHECK_NE(-1, logout_button_index); | |
| 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 |