OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/common/system/tray/system_tray_controller.h" | |
6 | |
7 #include "ash/common/system/tray/system_tray.h" | |
8 #include "ash/common/system/tray/system_tray_notifier.h" | |
9 #include "ash/common/system/update/tray_update.h" | |
10 #include "ash/common/wm_shell.h" | |
11 #include "ash/common/wm_window.h" | |
12 #include "ash/root_window_controller.h" | |
13 | |
14 namespace ash { | |
15 | |
16 SystemTrayController::SystemTrayController() | |
17 : hour_clock_type_(base::GetHourClockType()) {} | |
18 | |
19 SystemTrayController::~SystemTrayController() {} | |
20 | |
21 void SystemTrayController::ShowSettings() { | |
22 if (system_tray_client_) | |
23 system_tray_client_->ShowSettings(); | |
24 } | |
25 | |
26 void SystemTrayController::ShowDateSettings() { | |
27 if (system_tray_client_) | |
28 system_tray_client_->ShowDateSettings(); | |
29 } | |
30 | |
31 void SystemTrayController::ShowSetTimeDialog() { | |
32 if (system_tray_client_) | |
33 system_tray_client_->ShowSetTimeDialog(); | |
34 } | |
35 | |
36 void SystemTrayController::ShowDisplaySettings() { | |
37 if (system_tray_client_) | |
38 system_tray_client_->ShowDisplaySettings(); | |
39 } | |
40 | |
41 void SystemTrayController::ShowPowerSettings() { | |
42 if (system_tray_client_) | |
43 system_tray_client_->ShowPowerSettings(); | |
44 } | |
45 | |
46 void SystemTrayController::ShowChromeSlow() { | |
47 if (system_tray_client_) | |
48 system_tray_client_->ShowChromeSlow(); | |
49 } | |
50 | |
51 void SystemTrayController::ShowIMESettings() { | |
52 if (system_tray_client_) | |
53 system_tray_client_->ShowIMESettings(); | |
54 } | |
55 | |
56 void SystemTrayController::ShowHelp() { | |
57 if (system_tray_client_) | |
58 system_tray_client_->ShowHelp(); | |
59 } | |
60 | |
61 void SystemTrayController::ShowAccessibilityHelp() { | |
62 if (system_tray_client_) | |
63 system_tray_client_->ShowAccessibilityHelp(); | |
64 } | |
65 | |
66 void SystemTrayController::ShowAccessibilitySettings() { | |
67 if (system_tray_client_) | |
68 system_tray_client_->ShowAccessibilitySettings(); | |
69 } | |
70 | |
71 void SystemTrayController::ShowPaletteHelp() { | |
72 if (system_tray_client_) | |
73 system_tray_client_->ShowPaletteHelp(); | |
74 } | |
75 | |
76 void SystemTrayController::ShowPaletteSettings() { | |
77 if (system_tray_client_) | |
78 system_tray_client_->ShowPaletteSettings(); | |
79 } | |
80 | |
81 void SystemTrayController::ShowPublicAccountInfo() { | |
82 if (system_tray_client_) | |
83 system_tray_client_->ShowPublicAccountInfo(); | |
84 } | |
85 | |
86 void SystemTrayController::ShowNetworkConfigure(const std::string& network_id) { | |
87 if (system_tray_client_) | |
88 system_tray_client_->ShowNetworkConfigure(network_id); | |
89 } | |
90 | |
91 void SystemTrayController::ShowNetworkCreate(const std::string& type) { | |
92 if (system_tray_client_) | |
93 system_tray_client_->ShowNetworkCreate(type); | |
94 } | |
95 | |
96 void SystemTrayController::ShowThirdPartyVpnCreate( | |
97 const std::string& extension_id) { | |
98 if (system_tray_client_) | |
99 system_tray_client_->ShowThirdPartyVpnCreate(extension_id); | |
100 } | |
101 | |
102 void SystemTrayController::ShowNetworkSettings(const std::string& network_id) { | |
103 if (system_tray_client_) | |
104 system_tray_client_->ShowNetworkSettings(network_id); | |
105 } | |
106 | |
107 void SystemTrayController::ShowProxySettings() { | |
108 if (system_tray_client_) | |
109 system_tray_client_->ShowProxySettings(); | |
110 } | |
111 | |
112 void SystemTrayController::SignOut() { | |
113 if (system_tray_client_) | |
114 system_tray_client_->SignOut(); | |
115 } | |
116 | |
117 void SystemTrayController::RequestRestartForUpdate() { | |
118 if (system_tray_client_) | |
119 system_tray_client_->RequestRestartForUpdate(); | |
120 } | |
121 | |
122 void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) { | |
123 bindings_.AddBinding(this, std::move(request)); | |
124 } | |
125 | |
126 void SystemTrayController::SetClient(mojom::SystemTrayClientPtr client) { | |
127 system_tray_client_ = std::move(client); | |
128 } | |
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 | |
164 void SystemTrayController::SetUse24HourClock(bool use_24_hour) { | |
165 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; | |
166 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); | |
167 } | |
168 | |
169 void SystemTrayController::ShowUpdateIcon(mojom::UpdateSeverity severity, | |
170 bool factory_reset_required) { | |
171 // Show the icon on all displays. | |
172 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) { | |
173 ash::SystemTray* tray = root->GetRootWindowController()->GetSystemTray(); | |
174 // External monitors might not have a tray yet. | |
175 if (!tray) | |
176 continue; | |
177 tray->tray_update()->ShowUpdateIcon(severity, factory_reset_required); | |
178 } | |
179 } | |
180 | |
181 } // namespace ash | |
OLD | NEW |