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

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

Issue 2761313003: Update appearance of Wi-Fi toggle notification. (Closed)
Patch Set: 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 auto* box_layout = new views::BoxLayout(views::BoxLayout::kHorizontal,
185 kTrayPopupPaddingHorizontal, 10,
James Cook 2017/03/21 19:57:31 nit: put the magic 10 in a named constant
Evan Stade 2017/03/22 20:33:54 Done.
186 kTrayPopupPaddingBetweenItems);
187 SetLayoutManager(box_layout);
188
184 image_view_ = new views::ImageView; 189 image_view_ = new views::ImageView;
185 AddChildView(image_view_); 190 AddChildView(image_view_);
186 191
187 label_view_ = new views::Label(); 192 label_view_ = new views::Label();
188 label_view_->SetMultiLine(true);
189 label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 193 label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
190 AddChildView(label_view_); 194 AddChildView(label_view_);
195 box_layout->SetFlexForView(label_view_, 1);
191 196
192 Update(); 197 Update();
193 } 198 }
194 199
195 ~NetworkWifiDetailedView() override {}
196
197 // Overridden from NetworkDetailedView:
198
199 void Init() override {}
200
201 NetworkDetailedView::DetailedViewType GetViewType() const override { 200 NetworkDetailedView::DetailedViewType GetViewType() const override {
202 return NetworkDetailedView::WIFI_VIEW; 201 return NetworkDetailedView::WIFI_VIEW;
203 } 202 }
204 203
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 { 204 void Update() override {
215 bool wifi_enabled = 205 bool wifi_enabled =
216 NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( 206 NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled(
217 NetworkTypePattern::WiFi()); 207 NetworkTypePattern::WiFi());
218 const int image_id = wifi_enabled ? IDR_AURA_UBER_TRAY_WIFI_ENABLED 208 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 209
223 const int string_id = wifi_enabled 210 const int string_id = wifi_enabled
224 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED 211 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED
225 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; 212 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
226 label_view_->SetText(bundle.GetLocalizedString(string_id)); 213 label_view_->SetText(l10n_util::GetStringUTF16(string_id));
227 label_view_->SizeToFit(
228 kTrayPopupMinWidth - kTrayPopupPaddingHorizontal * 2 -
229 kTrayPopupPaddingBetweenItems - kTrayPopupDetailsIconWidth);
230 } 214 }
231 215
232 private: 216 private:
233 views::ImageView* image_view_; 217 views::ImageView* image_view_ = nullptr;
234 views::Label* label_view_; 218 views::Label* label_view_ = nullptr;
235 219
236 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); 220 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
237 }; 221 };
238 222
239 } // namespace tray 223 } // namespace tray
240 224
241 TrayNetwork::TrayNetwork(SystemTray* system_tray) 225 TrayNetwork::TrayNetwork(SystemTray* system_tray)
242 : SystemTrayItem(system_tray, UMA_NETWORK), 226 : SystemTrayItem(system_tray, UMA_NETWORK),
243 tray_(NULL), 227 tray_(NULL),
244 default_(NULL), 228 default_(NULL),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 WmShell::Get()->RecordUserMetricsAction( 263 WmShell::Get()->RecordUserMetricsAction(
280 UMA_STATUS_AREA_DETAILED_NETWORK_VIEW); 264 UMA_STATUS_AREA_DETAILED_NETWORK_VIEW);
281 if (!chromeos::NetworkHandler::IsInitialized()) 265 if (!chromeos::NetworkHandler::IsInitialized())
282 return NULL; 266 return NULL;
283 if (request_wifi_view_) { 267 if (request_wifi_view_) {
284 detailed_ = new tray::NetworkWifiDetailedView(this); 268 detailed_ = new tray::NetworkWifiDetailedView(this);
285 request_wifi_view_ = false; 269 request_wifi_view_ = false;
286 } else { 270 } else {
287 detailed_ = new tray::NetworkStateListDetailedView( 271 detailed_ = new tray::NetworkStateListDetailedView(
288 this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status); 272 this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status);
289 detailed_->Init();
290 } 273 }
274 detailed_->Init();
291 return detailed_; 275 return detailed_;
292 } 276 }
293 277
294 void TrayNetwork::DestroyTrayView() { 278 void TrayNetwork::DestroyTrayView() {
295 tray_ = NULL; 279 tray_ = NULL;
296 } 280 }
297 281
298 void TrayNetwork::DestroyDefaultView() { 282 void TrayNetwork::DestroyDefaultView() {
299 default_ = NULL; 283 default_ = NULL;
300 } 284 }
301 285
302 void TrayNetwork::DestroyDetailedView() { 286 void TrayNetwork::DestroyDetailedView() {
303 detailed_ = NULL; 287 detailed_ = NULL;
304 } 288 }
305 289
306 void TrayNetwork::RequestToggleWifi() { 290 void TrayNetwork::RequestToggleWifi() {
307 // This will always be triggered by a user action (e.g. keyboard shortcut) 291 // This will always be triggered by a user action (e.g. keyboard shortcut)
308 if (!detailed_ || 292 if (!detailed_ ||
309 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { 293 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) {
310 request_wifi_view_ = true; 294 request_wifi_view_ = true;
311 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 295 PopUpDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
312 } 296 }
313 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 297 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
314 bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()); 298 bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi());
315 WmShell::Get()->RecordUserMetricsAction( 299 WmShell::Get()->RecordUserMetricsAction(
316 enabled ? UMA_STATUS_AREA_DISABLE_WIFI : UMA_STATUS_AREA_ENABLE_WIFI); 300 enabled ? UMA_STATUS_AREA_DISABLE_WIFI : UMA_STATUS_AREA_ENABLE_WIFI);
317 handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), !enabled, 301 handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), !enabled,
318 chromeos::network_handler::ErrorCallback()); 302 chromeos::network_handler::ErrorCallback());
319 } 303 }
320 304
321 void TrayNetwork::OnCaptivePortalDetected(const std::string& /* guid */) { 305 void TrayNetwork::OnCaptivePortalDetected(const std::string& /* guid */) {
322 NetworkStateChanged(); 306 NetworkStateChanged();
323 } 307 }
324 308
325 void TrayNetwork::NetworkStateChanged() { 309 void TrayNetwork::NetworkStateChanged() {
326 if (tray_) 310 if (tray_)
327 tray_->UpdateNetworkStateHandlerIcon(); 311 tray_->UpdateNetworkStateHandlerIcon();
328 if (default_) 312 if (default_)
329 default_->Update(); 313 default_->Update();
330 if (detailed_) 314 if (detailed_)
331 detailed_->Update(); 315 detailed_->Update();
332 } 316 }
333 317
334 } // namespace ash 318 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698