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

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

Issue 2589583002: [ash-md] Adds VPN network status indicators in system menu (Closed)
Patch Set: 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_delegate.h" 17 #include "ash/common/system/chromeos/network/vpn_delegate.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_delegate.h" 20 #include "ash/common/system/tray/system_tray_delegate.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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 void OnMouseEntered(const ui::MouseEvent& event) override; 172 void OnMouseEntered(const ui::MouseEvent& event) override;
172 void OnMouseExited(const ui::MouseEvent& event) override; 173 void OnMouseExited(const ui::MouseEvent& event) override;
173 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 174 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
174 175
175 VPNListNetworkEntry* parent_; 176 VPNListNetworkEntry* parent_;
176 177
177 DISALLOW_COPY_AND_ASSIGN(DisconnectButton); 178 DISALLOW_COPY_AND_ASSIGN(DisconnectButton);
178 }; 179 };
179 180
180 void UpdateFromNetworkState(const chromeos::NetworkState* network); 181 void UpdateFromNetworkState(const chromeos::NetworkState* network);
182 void SetupConnectedItemMd(const base::string16& text,
183 const gfx::ImageSkia& image);
184 void SetupConnectingItemMd(const base::string16& text,
185 const gfx::ImageSkia& image);
181 186
182 const std::string service_path_; 187 const std::string service_path_;
183 188
184 views::LabelButton* disconnect_button_ = nullptr; 189 views::LabelButton* disconnect_button_ = nullptr;
185 190
186 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); 191 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry);
187 }; 192 };
188 193
189 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) 194 VPNListEntryBase::VPNListEntryBase(VPNListView* parent)
190 : HoverHighlightView(parent) { 195 : HoverHighlightView(parent) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if (network && network->IsConnectingState()) 265 if (network && network->IsConnectingState())
261 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 266 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
262 else 267 else
263 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 268 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
264 269
265 if (!network) { 270 if (!network) {
266 // This is a transient state where the network has been removed already but 271 // This is a transient state where the network has been removed already but
267 // the network list in the UI has not been updated yet. 272 // the network list in the UI has not been updated yet.
268 return; 273 return;
269 } 274 }
270
271 RemoveAllChildViews(true); 275 RemoveAllChildViews(true);
272 disconnect_button_ = nullptr; 276 disconnect_button_ = nullptr;
273 277
274 AddIconAndLabel( 278 gfx::ImageSkia image =
275 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST), 279 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST);
276 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST), 280 base::string16 label =
277 IsConnectedOrConnecting(network)); 281 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST);
278 if (IsConnectedOrConnecting(network)) { 282 if (UseMd()) {
279 if (UseMd()) { 283 if (network->IsConnectedState())
284 SetupConnectedItemMd(label, image);
285 else if (network->IsConnectingState())
286 SetupConnectingItemMd(label, image);
287 else
288 AddIconAndLabel(image, label, false);
289
290 if (network->IsConnectedState()) {
280 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton( 291 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton(
281 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)); 292 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT));
282 tri_view()->AddView(TriView::Container::END, disconnect_button_); 293 tri_view()->AddView(TriView::Container::END, disconnect_button_);
283 tri_view()->SetContainerVisible(TriView::Container::END, true); 294 tri_view()->SetContainerVisible(TriView::Container::END, true);
284 tri_view()->SetContainerBorder( 295 tri_view()->SetContainerBorder(
285 TriView::Container::END, 296 TriView::Container::END,
286 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); 297 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin));
287 } else { 298 }
299 } else {
300 AddIconAndLabel(image, label, IsConnectedOrConnecting(network));
301 if (IsConnectedOrConnecting(network)) {
288 disconnect_button_ = new DisconnectButton(this); 302 disconnect_button_ = new DisconnectButton(this);
289 AddChildView(disconnect_button_); 303 AddChildView(disconnect_button_);
290 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 3)); 304 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 3));
305 } else {
306 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
291 } 307 }
292 } else {
293 if (!UseMd())
294 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
295 }
296
297 if (!UseMd()) {
298 // The icon and the disconnect button are always set to their preferred 308 // The icon and the disconnect button are always set to their preferred
299 // size. All remaining space is used for the network name. 309 // size. All remaining space is used for the network name.
300 views::BoxLayout* layout = new views::BoxLayout( 310 views::BoxLayout* layout = new views::BoxLayout(
301 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems); 311 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems);
302 SetLayoutManager(layout); 312 SetLayoutManager(layout);
303 layout->SetDefaultFlex(0); 313 layout->SetDefaultFlex(0);
304 layout->SetFlexForView(text_label(), 1); 314 layout->SetFlexForView(text_label(), 1);
305 } 315 }
306 Layout(); 316 Layout();
307 } 317 }
308 318
319 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc.
320 void VPNListNetworkEntry::SetupConnectedItemMd(const base::string16& text,
321 const gfx::ImageSkia& image) {
322 AddIconAndLabels(
323 image, text,
324 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED));
325 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION);
326 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED);
327 style.SetupLabel(sub_text_label());
328 }
329
330 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc.
331 void VPNListNetworkEntry::SetupConnectingItemMd(const base::string16& text,
332 const gfx::ImageSkia& image) {
333 AddIconAndLabels(
334 image, text,
335 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING));
336 ThrobberView* throbber = new ThrobberView;
337 throbber->Start();
338 AddRightView(throbber);
339 }
340
309 } // namespace 341 } // namespace
310 342
311 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) { 343 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) {
312 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this); 344 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this);
313 } 345 }
314 346
315 VPNListView::~VPNListView() { 347 VPNListView::~VPNListView() {
316 // We need the check as on shell destruction, the delegate is destroyed first. 348 // We need the check as on shell destruction, the delegate is destroyed first.
317 SystemTrayDelegate* const system_tray_delegate = 349 SystemTrayDelegate* const system_tray_delegate =
318 WmShell::Get()->system_tray_delegate(); 350 WmShell::Get()->system_tray_delegate();
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 } 523 }
492 } 524 }
493 525
494 // Add providers without any configured networks, in the order that the 526 // Add providers without any configured networks, in the order that the
495 // providers were returned by the extensions system. 527 // providers were returned by the extensions system.
496 for (const VPNProvider& provider : providers) 528 for (const VPNProvider& provider : providers)
497 AddProviderAndNetworks(provider.key, provider.name, networks); 529 AddProviderAndNetworks(provider.key, provider.name, networks);
498 } 530 }
499 531
500 } // namespace ash 532 } // 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