| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/tray/system_tray_controller.h" | 5 #include "ash/common/system/tray/system_tray_controller.h" |
| 6 | 6 |
| 7 #include "ash/common/system/tray/system_tray.h" | 7 #include "ash/common/system/tray/system_tray.h" |
| 8 #include "ash/common/system/tray/system_tray_notifier.h" | 8 #include "ash/common/system/tray/system_tray_notifier.h" |
| 9 #include "ash/common/system/update/tray_update.h" | 9 #include "ash/common/system/update/tray_update.h" |
| 10 #include "ash/common/wm_root_window_controller.h" | 10 #include "ash/common/wm_root_window_controller.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 | 121 |
| 122 void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) { | 122 void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) { |
| 123 bindings_.AddBinding(this, std::move(request)); | 123 bindings_.AddBinding(this, std::move(request)); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void SystemTrayController::SetClient(mojom::SystemTrayClientPtr client) { | 126 void SystemTrayController::SetClient(mojom::SystemTrayClientPtr client) { |
| 127 system_tray_client_ = std::move(client); | 127 system_tray_client_ = std::move(client); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void SystemTrayController::SetPrimaryTrayEnabled(bool enabled) { |
| 131 ash::SystemTray* tray = |
| 132 WmShell::Get()->GetPrimaryRootWindowController()->GetSystemTray(); |
| 133 if (!tray) |
| 134 return; |
| 135 |
| 136 // We disable the UI to prevent user from interacting with UI elements, |
| 137 // particularly with the system tray menu. However, in case if the system tray |
| 138 // bubble is opened at this point, it remains opened and interactive even |
| 139 // after SystemTray::SetEnabled(false) call, which can be dangerous |
| 140 // (http://crbug.com/497080). Close the menu to fix it. Calling |
| 141 // SystemTray::SetEnabled(false) guarantees, that the menu will not be opened |
| 142 // until the UI is enabled again. |
| 143 if (!enabled && tray->HasSystemBubble()) |
| 144 tray->CloseSystemBubble(); |
| 145 |
| 146 tray->SetEnabled(enabled); |
| 147 } |
| 148 |
| 149 void SystemTrayController::SetPrimaryTrayVisible(bool visible) { |
| 150 ash::SystemTray* tray = |
| 151 WmShell::Get()->GetPrimaryRootWindowController()->GetSystemTray(); |
| 152 if (!tray) |
| 153 return; |
| 154 |
| 155 tray->SetVisible(visible); |
| 156 tray->GetWidget()->SetOpacity(visible ? 1.f : 0.f); |
| 157 if (visible) { |
| 158 tray->GetWidget()->Show(); |
| 159 } else { |
| 160 tray->GetWidget()->Hide(); |
| 161 } |
| 162 } |
| 163 |
| 130 void SystemTrayController::SetUse24HourClock(bool use_24_hour) { | 164 void SystemTrayController::SetUse24HourClock(bool use_24_hour) { |
| 131 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; | 165 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; |
| 132 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); | 166 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); |
| 133 } | 167 } |
| 134 | 168 |
| 135 void SystemTrayController::ShowUpdateIcon(mojom::UpdateSeverity severity, | 169 void SystemTrayController::ShowUpdateIcon(mojom::UpdateSeverity severity, |
| 136 bool factory_reset_required) { | 170 bool factory_reset_required) { |
| 137 // Show the icon on all displays. | 171 // Show the icon on all displays. |
| 138 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { | 172 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { |
| 139 ash::SystemTray* tray = root->GetRootWindowController()->GetSystemTray(); | 173 ash::SystemTray* tray = root->GetRootWindowController()->GetSystemTray(); |
| 140 // External monitors might not have a tray yet. | 174 // External monitors might not have a tray yet. |
| 141 if (!tray) | 175 if (!tray) |
| 142 continue; | 176 continue; |
| 143 tray->tray_update()->ShowUpdateIcon(severity, factory_reset_required); | 177 tray->tray_update()->ShowUpdateIcon(severity, factory_reset_required); |
| 144 } | 178 } |
| 145 } | 179 } |
| 146 | 180 |
| 147 } // namespace ash | 181 } // namespace ash |
| OLD | NEW |