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

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

Issue 2571943002: [ash-md] Adds VPN network status indicators in system menu (Closed)
Patch Set: [ash-md] Adds VPN network status indicators in system menu (separated not closing menu) Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/vpn_list_view.h" 5 #include "ash/common/system/chromeos/network/vpn_list_view.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/common/ash_view_ids.h" 11 #include "ash/common/ash_view_ids.h"
12 #include "ash/common/material_design/material_design_controller.h" 12 #include "ash/common/material_design/material_design_controller.h"
13 #include "ash/common/system/chromeos/network/network_icon.h" 13 #include "ash/common/system/chromeos/network/network_icon.h"
14 #include "ash/common/system/chromeos/network/network_icon_animation.h" 14 #include "ash/common/system/chromeos/network/network_icon_animation.h"
15 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" 15 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h"
16 #include "ash/common/system/chromeos/network/network_list_delegate.h" 16 #include "ash/common/system/chromeos/network/network_list_delegate.h"
17 #include "ash/common/system/chromeos/network/vpn_list.h" 17 #include "ash/common/system/chromeos/network/vpn_list.h"
18 #include "ash/common/system/tray/hover_highlight_view.h" 18 #include "ash/common/system/tray/hover_highlight_view.h"
19 #include "ash/common/system/tray/system_menu_button.h" 19 #include "ash/common/system/tray/system_menu_button.h"
20 #include "ash/common/system/tray/system_tray_controller.h" 20 #include "ash/common/system/tray/system_tray_controller.h"
21 #include "ash/common/system/tray/throbber_view.h"
21 #include "ash/common/system/tray/tray_constants.h" 22 #include "ash/common/system/tray/tray_constants.h"
22 #include "ash/common/system/tray/tray_popup_label_button.h" 23 #include "ash/common/system/tray/tray_popup_label_button.h"
23 #include "ash/common/system/tray/tray_popup_utils.h" 24 #include "ash/common/system/tray/tray_popup_utils.h"
24 #include "ash/common/system/tray/tri_view.h" 25 #include "ash/common/system/tray/tri_view.h"
25 #include "ash/common/wm_shell.h" 26 #include "ash/common/wm_shell.h"
26 #include "ash/resources/vector_icons/vector_icons.h" 27 #include "ash/resources/vector_icons/vector_icons.h"
27 #include "base/bind.h" 28 #include "base/bind.h"
28 #include "base/bind_helpers.h" 29 #include "base/bind_helpers.h"
29 #include "base/logging.h" 30 #include "base/logging.h"
30 #include "base/strings/utf_string_conversions.h" 31 #include "base/strings/utf_string_conversions.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 void OnMouseEntered(const ui::MouseEvent& event) override; 187 void OnMouseEntered(const ui::MouseEvent& event) override;
187 void OnMouseExited(const ui::MouseEvent& event) override; 188 void OnMouseExited(const ui::MouseEvent& event) override;
188 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 189 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
189 190
190 VPNListNetworkEntry* parent_; 191 VPNListNetworkEntry* parent_;
191 192
192 DISALLOW_COPY_AND_ASSIGN(DisconnectButton); 193 DISALLOW_COPY_AND_ASSIGN(DisconnectButton);
193 }; 194 };
194 195
195 void UpdateFromNetworkState(const chromeos::NetworkState* network); 196 void UpdateFromNetworkState(const chromeos::NetworkState* network);
197 void SetupConnectedItemMd(const base::string16& text,
198 const gfx::ImageSkia& image);
199 void SetupConnectingItemMd(const base::string16& text,
200 const gfx::ImageSkia& image);
196 201
197 const std::string service_path_; 202 const std::string service_path_;
198 203
199 views::LabelButton* disconnect_button_ = nullptr; 204 views::LabelButton* disconnect_button_ = nullptr;
200 205
201 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); 206 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry);
202 }; 207 };
203 208
204 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) 209 VPNListEntryBase::VPNListEntryBase(VPNListView* parent)
205 : HoverHighlightView(parent) { 210 : HoverHighlightView(parent) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 if (network && network->IsConnectingState()) 280 if (network && network->IsConnectingState())
276 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 281 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
277 else 282 else
278 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 283 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
279 284
280 if (!network) { 285 if (!network) {
281 // This is a transient state where the network has been removed already but 286 // This is a transient state where the network has been removed already but
282 // the network list in the UI has not been updated yet. 287 // the network list in the UI has not been updated yet.
283 return; 288 return;
284 } 289 }
285
286 RemoveAllChildViews(true); 290 RemoveAllChildViews(true);
287 disconnect_button_ = nullptr; 291 disconnect_button_ = nullptr;
288 292
289 AddIconAndLabel( 293 gfx::ImageSkia image =
290 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST), 294 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST);
291 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST), 295 base::string16 label =
292 IsConnectedOrConnecting(network)); 296 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST);
293 if (IsConnectedOrConnecting(network)) { 297 if (UseMd()) {
294 if (UseMd()) { 298 if (network->IsConnectedState())
299 SetupConnectedItemMd(label, image);
300 else if (network->IsConnectingState())
301 SetupConnectingItemMd(label, image);
302 else
303 AddIconAndLabel(image, label, false);
304
305 if (network->IsConnectedState()) {
295 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton( 306 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton(
296 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)); 307 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT));
297 tri_view()->AddView(TriView::Container::END, disconnect_button_); 308 tri_view()->AddView(TriView::Container::END, disconnect_button_);
298 tri_view()->SetContainerVisible(TriView::Container::END, true); 309 tri_view()->SetContainerVisible(TriView::Container::END, true);
299 tri_view()->SetContainerBorder( 310 tri_view()->SetContainerBorder(
300 TriView::Container::END, 311 TriView::Container::END,
301 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); 312 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin));
302 } else { 313 }
314 } else {
315 AddIconAndLabel(image, label, IsConnectedOrConnecting(network));
316 if (IsConnectedOrConnecting(network)) {
303 disconnect_button_ = new DisconnectButton(this); 317 disconnect_button_ = new DisconnectButton(this);
304 AddChildView(disconnect_button_); 318 AddChildView(disconnect_button_);
305 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 3)); 319 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 3));
320 } else {
321 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
306 } 322 }
307 } else {
308 if (!UseMd())
309 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
310 }
311
312 if (!UseMd()) {
313 // The icon and the disconnect button are always set to their preferred 323 // The icon and the disconnect button are always set to their preferred
314 // size. All remaining space is used for the network name. 324 // size. All remaining space is used for the network name.
315 views::BoxLayout* layout = new views::BoxLayout( 325 views::BoxLayout* layout = new views::BoxLayout(
316 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems); 326 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems);
317 SetLayoutManager(layout); 327 SetLayoutManager(layout);
318 layout->SetDefaultFlex(0); 328 layout->SetDefaultFlex(0);
319 layout->SetFlexForView(text_label(), 1); 329 layout->SetFlexForView(text_label(), 1);
320 } 330 }
321 Layout(); 331 Layout();
322 } 332 }
323 333
334 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc.
335 void VPNListNetworkEntry::SetupConnectedItemMd(const base::string16& text,
336 const gfx::ImageSkia& image) {
337 AddIconAndLabels(
338 image, text,
339 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED));
340 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION);
341 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED);
342 style.SetupLabel(sub_text_label());
343 }
344
345 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc.
346 void VPNListNetworkEntry::SetupConnectingItemMd(const base::string16& text,
347 const gfx::ImageSkia& image) {
348 AddIconAndLabels(
349 image, text,
350 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING));
351 ThrobberView* throbber = new ThrobberView;
352 throbber->Start();
353 AddRightView(throbber);
354 }
355
324 } // namespace 356 } // namespace
325 357
326 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) { 358 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) {
327 WmShell::Get()->vpn_list()->AddObserver(this); 359 WmShell::Get()->vpn_list()->AddObserver(this);
328 } 360 }
329 361
330 VPNListView::~VPNListView() { 362 VPNListView::~VPNListView() {
331 WmShell::Get()->vpn_list()->RemoveObserver(this); 363 WmShell::Get()->vpn_list()->RemoveObserver(this);
332 } 364 }
333 365
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 538 }
507 } 539 }
508 540
509 // Add providers without any configured networks, in the order that the 541 // Add providers without any configured networks, in the order that the
510 // providers were returned by the extensions system. 542 // providers were returned by the extensions system.
511 for (const VPNProvider& provider : providers) 543 for (const VPNProvider& provider : providers)
512 AddProviderAndNetworks(provider, networks); 544 AddProviderAndNetworks(provider, networks);
513 } 545 }
514 546
515 } // namespace ash 547 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698