Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: ash/common/system/chromeos/network/tray_network.cc

Issue 2761313003: Update appearance of Wi-Fi toggle notification. (Closed)
Patch Set: one more rename Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/chromeos/network/tray_network.h" 5 #include "ash/common/system/chromeos/network/tray_network.h"
6 6
7 #include "ash/common/shelf/wm_shelf_util.h" 7 #include "ash/common/shelf/wm_shelf_util.h"
8 #include "ash/common/system/chromeos/network/network_icon.h" 8 #include "ash/common/system/chromeos/network/network_icon.h"
9 #include "ash/common/system/chromeos/network/network_icon_animation.h" 9 #include "ash/common/system/chromeos/network/network_icon_animation.h"
10 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" 10 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h"
11 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h" 11 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h"
12 #include "ash/common/system/chromeos/network/tray_network_state_observer.h" 12 #include "ash/common/system/chromeos/network/tray_network_state_observer.h"
13 #include "ash/common/system/tray/system_tray.h" 13 #include "ash/common/system/tray/system_tray.h"
14 #include "ash/common/system/tray/system_tray_delegate.h" 14 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/system/tray/system_tray_notifier.h" 15 #include "ash/common/system/tray/system_tray_notifier.h"
16 #include "ash/common/system/tray/tray_constants.h" 16 #include "ash/common/system/tray/tray_constants.h"
17 #include "ash/common/system/tray/tray_item_more.h" 17 #include "ash/common/system/tray/tray_item_more.h"
18 #include "ash/common/system/tray/tray_item_view.h" 18 #include "ash/common/system/tray/tray_item_view.h"
19 #include "ash/common/system/tray/tray_popup_item_style.h" 19 #include "ash/common/system/tray/tray_popup_item_style.h"
20 #include "ash/common/system/tray/tray_utils.h" 20 #include "ash/common/system/tray/tray_utils.h"
21 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
22 #include "ash/resources/grit/ash_resources.h"
23 #include "ash/strings/grit/ash_strings.h" 22 #include "ash/strings/grit/ash_strings.h"
24 #include "base/command_line.h" 23 #include "base/command_line.h"
25 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
26 #include "chromeos/network/network_state.h" 25 #include "chromeos/network/network_state.h"
27 #include "chromeos/network/network_state_handler.h" 26 #include "chromeos/network/network_state_handler.h"
28 #include "third_party/cros_system_api/dbus/service_constants.h" 27 #include "third_party/cros_system_api/dbus/service_constants.h"
29 #include "ui/accessibility/ax_node_data.h" 28 #include "ui/accessibility/ax_node_data.h"
30 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/views/controls/image_view.h" 30 #include "ui/views/controls/image_view.h"
33 #include "ui/views/controls/link.h" 31 #include "ui/views/controls/link.h"
34 #include "ui/views/controls/link_listener.h" 32 #include "ui/views/controls/link_listener.h"
35 #include "ui/views/layout/box_layout.h" 33 #include "ui/views/layout/box_layout.h"
36 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
37 35
38 using chromeos::NetworkHandler; 36 using chromeos::NetworkHandler;
39 using chromeos::NetworkState; 37 using chromeos::NetworkState;
40 using chromeos::NetworkStateHandler; 38 using chromeos::NetworkStateHandler;
41 using chromeos::NetworkTypePattern; 39 using chromeos::NetworkTypePattern;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return style; 168 return style;
171 } 169 }
172 170
173 private: 171 private:
174 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); 172 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView);
175 }; 173 };
176 174
177 class NetworkWifiDetailedView : public NetworkDetailedView { 175 class NetworkWifiDetailedView : public NetworkDetailedView {
178 public: 176 public:
179 explicit NetworkWifiDetailedView(SystemTrayItem* owner) 177 explicit NetworkWifiDetailedView(SystemTrayItem* owner)
180 : NetworkDetailedView(owner) { 178 : NetworkDetailedView(owner) {}
181 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 179
182 kTrayPopupPaddingHorizontal, 10, 180 ~NetworkWifiDetailedView() override {}
183 kTrayPopupPaddingBetweenItems)); 181
182 // NetworkDetailedView:
183 void Init() override {
184 constexpr int kVerticalPadding = 10;
185 auto* box_layout = new views::BoxLayout(
186 views::BoxLayout::kHorizontal, kTrayPopupPaddingHorizontal,
187 kVerticalPadding, kTrayPopupPaddingBetweenItems);
188 SetLayoutManager(box_layout);
189
184 image_view_ = new views::ImageView; 190 image_view_ = new views::ImageView;
185 AddChildView(image_view_); 191 AddChildView(image_view_);
186 192
187 label_view_ = new views::Label(); 193 label_view_ = new views::Label();
188 label_view_->SetMultiLine(true);
189 label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 194 label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
190 AddChildView(label_view_); 195 AddChildView(label_view_);
196 box_layout->SetFlexForView(label_view_, 1);
191 197
192 Update(); 198 Update();
193 } 199 }
194 200
195 ~NetworkWifiDetailedView() override {}
196
197 // Overridden from NetworkDetailedView:
198
199 void Init() override {}
200
201 NetworkDetailedView::DetailedViewType GetViewType() const override { 201 NetworkDetailedView::DetailedViewType GetViewType() const override {
202 return NetworkDetailedView::WIFI_VIEW; 202 return NetworkDetailedView::WIFI_VIEW;
203 } 203 }
204 204
205 void Layout() override {
206 // Center both views vertically.
207 views::View::Layout();
208 image_view_->SetY((height() - image_view_->GetPreferredSize().height()) /
209 2);
210 label_view_->SetY((height() - label_view_->GetPreferredSize().height()) /
211 2);
212 }
213
214 void Update() override { 205 void Update() override {
215 bool wifi_enabled = 206 bool wifi_enabled =
216 NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( 207 NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled(
217 NetworkTypePattern::WiFi()); 208 NetworkTypePattern::WiFi());
218 const int image_id = wifi_enabled ? IDR_AURA_UBER_TRAY_WIFI_ENABLED 209 image_view_->SetImage(network_icon::GetImageForWifiChipState(wifi_enabled));
219 : IDR_AURA_UBER_TRAY_WIFI_DISABLED;
220 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
221 image_view_->SetImage(bundle.GetImageNamed(image_id).ToImageSkia());
222 210
223 const int string_id = wifi_enabled 211 const int string_id = wifi_enabled
224 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED 212 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED
225 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; 213 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
226 label_view_->SetText(bundle.GetLocalizedString(string_id)); 214 label_view_->SetText(l10n_util::GetStringUTF16(string_id));
227 label_view_->SizeToFit(
228 kTrayPopupMinWidth - kTrayPopupPaddingHorizontal * 2 -
229 kTrayPopupPaddingBetweenItems - kTrayPopupDetailsIconWidth);
230 } 215 }
231 216
232 private: 217 private:
233 views::ImageView* image_view_; 218 views::ImageView* image_view_ = nullptr;
234 views::Label* label_view_; 219 views::Label* label_view_ = nullptr;
235 220
236 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); 221 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
237 }; 222 };
238 223
239 } // namespace tray 224 } // namespace tray
240 225
241 TrayNetwork::TrayNetwork(SystemTray* system_tray) 226 TrayNetwork::TrayNetwork(SystemTray* system_tray)
242 : SystemTrayItem(system_tray, UMA_NETWORK), 227 : SystemTrayItem(system_tray, UMA_NETWORK),
243 tray_(NULL), 228 tray_(NULL),
244 default_(NULL), 229 default_(NULL),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 WmShell::Get()->RecordUserMetricsAction( 264 WmShell::Get()->RecordUserMetricsAction(
280 UMA_STATUS_AREA_DETAILED_NETWORK_VIEW); 265 UMA_STATUS_AREA_DETAILED_NETWORK_VIEW);
281 if (!chromeos::NetworkHandler::IsInitialized()) 266 if (!chromeos::NetworkHandler::IsInitialized())
282 return NULL; 267 return NULL;
283 if (request_wifi_view_) { 268 if (request_wifi_view_) {
284 detailed_ = new tray::NetworkWifiDetailedView(this); 269 detailed_ = new tray::NetworkWifiDetailedView(this);
285 request_wifi_view_ = false; 270 request_wifi_view_ = false;
286 } else { 271 } else {
287 detailed_ = new tray::NetworkStateListDetailedView( 272 detailed_ = new tray::NetworkStateListDetailedView(
288 this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status); 273 this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status);
289 detailed_->Init();
290 } 274 }
275 detailed_->Init();
291 return detailed_; 276 return detailed_;
292 } 277 }
293 278
294 void TrayNetwork::DestroyTrayView() { 279 void TrayNetwork::DestroyTrayView() {
295 tray_ = NULL; 280 tray_ = NULL;
296 } 281 }
297 282
298 void TrayNetwork::DestroyDefaultView() { 283 void TrayNetwork::DestroyDefaultView() {
299 default_ = NULL; 284 default_ = NULL;
300 } 285 }
301 286
302 void TrayNetwork::DestroyDetailedView() { 287 void TrayNetwork::DestroyDetailedView() {
303 detailed_ = NULL; 288 detailed_ = NULL;
304 } 289 }
305 290
306 void TrayNetwork::RequestToggleWifi() { 291 void TrayNetwork::RequestToggleWifi() {
307 // This will always be triggered by a user action (e.g. keyboard shortcut) 292 // This will always be triggered by a user action (e.g. keyboard shortcut)
308 if (!detailed_ || 293 if (!detailed_ ||
309 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { 294 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) {
310 request_wifi_view_ = true; 295 request_wifi_view_ = true;
311 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 296 ShowDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
312 } 297 }
313 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 298 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
314 bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()); 299 bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi());
315 WmShell::Get()->RecordUserMetricsAction( 300 WmShell::Get()->RecordUserMetricsAction(
316 enabled ? UMA_STATUS_AREA_DISABLE_WIFI : UMA_STATUS_AREA_ENABLE_WIFI); 301 enabled ? UMA_STATUS_AREA_DISABLE_WIFI : UMA_STATUS_AREA_ENABLE_WIFI);
317 handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), !enabled, 302 handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), !enabled,
318 chromeos::network_handler::ErrorCallback()); 303 chromeos::network_handler::ErrorCallback());
319 } 304 }
320 305
321 void TrayNetwork::OnCaptivePortalDetected(const std::string& /* guid */) { 306 void TrayNetwork::OnCaptivePortalDetected(const std::string& /* guid */) {
322 NetworkStateChanged(); 307 NetworkStateChanged();
323 } 308 }
324 309
325 void TrayNetwork::NetworkStateChanged() { 310 void TrayNetwork::NetworkStateChanged() {
326 if (tray_) 311 if (tray_)
327 tray_->UpdateNetworkStateHandlerIcon(); 312 tray_->UpdateNetworkStateHandlerIcon();
328 if (default_) 313 if (default_)
329 default_->Update(); 314 default_->Update();
330 if (detailed_) 315 if (detailed_)
331 detailed_->Update(); 316 detailed_->Update();
332 } 317 }
333 318
334 } // namespace ash 319 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/network_icon.cc ('k') | ash/common/system/chromeos/tray_caps_lock.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698