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

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

Issue 2365523002: Materialized the font/icon color for some default rows in the system menu. (Closed)
Patch Set: Applied TrayPopupItemStyle to Network, SMS, Tracing, OS Update. Created 4 years, 3 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_vpn.h" 5 #include "ash/common/system/chromeos/network/tray_vpn.h"
6 6
7 #include "ash/common/session/session_state_delegate.h" 7 #include "ash/common/session/session_state_delegate.h"
8 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h" 8 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h"
9 #include "ash/common/system/chromeos/network/vpn_delegate.h" 9 #include "ash/common/system/chromeos/network/vpn_delegate.h"
10 #include "ash/common/system/tray/system_tray.h" 10 #include "ash/common/system/tray/system_tray.h"
11 #include "ash/common/system/tray/system_tray_delegate.h" 11 #include "ash/common/system/tray/system_tray_delegate.h"
12 #include "ash/common/system/tray/tray_constants.h" 12 #include "ash/common/system/tray/tray_constants.h"
13 #include "ash/common/system/tray/tray_item_more.h" 13 #include "ash/common/system/tray/tray_item_more.h"
14 #include "ash/common/system/tray/tray_popup_item_style.h"
14 #include "ash/common/system/tray/tray_popup_label_button.h" 15 #include "ash/common/system/tray/tray_popup_label_button.h"
15 #include "ash/common/wm_shell.h" 16 #include "ash/common/wm_shell.h"
16 #include "chromeos/network/network_state.h" 17 #include "chromeos/network/network_state.h"
17 #include "chromeos/network/network_state_handler.h" 18 #include "chromeos/network/network_state_handler.h"
18 #include "grit/ash_strings.h" 19 #include "grit/ash_strings.h"
19 #include "grit/ui_chromeos_strings.h" 20 #include "grit/ui_chromeos_strings.h"
20 #include "third_party/cros_system_api/dbus/service_constants.h" 21 #include "third_party/cros_system_api/dbus/service_constants.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/chromeos/network/network_icon.h" 23 #include "ui/chromeos/network/network_icon.h"
23 #include "ui/chromeos/network/network_icon_animation.h" 24 #include "ui/chromeos/network/network_icon_animation.h"
24 #include "ui/chromeos/network/network_icon_animation_observer.h" 25 #include "ui/chromeos/network/network_icon_animation_observer.h"
25 26
26 using chromeos::NetworkHandler; 27 using chromeos::NetworkHandler;
27 using chromeos::NetworkState; 28 using chromeos::NetworkState;
28 using chromeos::NetworkStateHandler; 29 using chromeos::NetworkStateHandler;
29 using chromeos::NetworkTypePattern; 30 using chromeos::NetworkTypePattern;
30 31
31 namespace ash { 32 namespace ash {
32 namespace tray { 33 namespace tray {
33 34
34 class VpnDefaultView : public TrayItemMore, 35 class VpnDefaultView : public TrayItemMore,
35 public ui::network_icon::AnimationObserver { 36 public ui::network_icon::AnimationObserver {
36 public: 37 public:
37 VpnDefaultView(SystemTrayItem* owner, bool show_more) 38 VpnDefaultView(SystemTrayItem* owner, bool show_more)
38 : TrayItemMore(owner, show_more) { 39 : TrayItemMore(owner, show_more) {}
39 Update();
40 }
41 40
42 ~VpnDefaultView() override { 41 ~VpnDefaultView() override {
43 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 42 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
44 } 43 }
45 44
46 static bool ShouldShow() { 45 static bool ShouldShow() {
47 // Show the VPN entry in the ash tray bubble if at least one third-party VPN 46 // Show the VPN entry in the ash tray bubble if at least one third-party VPN
48 // provider is installed. 47 // provider is installed.
49 if (WmShell::Get() 48 if (WmShell::Get()
50 ->system_tray_delegate() 49 ->system_tray_delegate()
(...skipping 21 matching lines...) Expand all
72 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( 71 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(
73 this); 72 this);
74 SetImage(image); 73 SetImage(image);
75 SetLabel(label); 74 SetLabel(label);
76 SetAccessibleName(label); 75 SetAccessibleName(label);
77 } 76 }
78 77
79 // ui::network_icon::AnimationObserver 78 // ui::network_icon::AnimationObserver
80 void NetworkIconChanged() override { Update(); } 79 void NetworkIconChanged() override { Update(); }
81 80
81 protected:
82 // TrayItemMore:
83 std::unique_ptr<TrayPopupItemStyle> CreateStyle() const override {
84 std::unique_ptr<TrayPopupItemStyle> style =
85 base::MakeUnique<TrayPopupItemStyle>(
86 GetNativeTheme(),
87 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL);
88 style->set_color_style(
89 !IsVpnEnabled()
90 ? TrayPopupItemStyle::ColorStyle::DISABLED
91 : IsVpnConnected() ? TrayPopupItemStyle::ColorStyle::ACTIVE
92 : TrayPopupItemStyle::ColorStyle::INACTIVE);
93 return style;
94 }
95
96 void UpdateStyle() override {
97 TrayItemMore::UpdateStyle();
98 Update();
99 }
100
82 private: 101 private:
102 bool IsVpnEnabled() const {
103 NetworkStateHandler* handler =
104 NetworkHandler::Get()->network_state_handler();
105 return handler->FirstNetworkByType(NetworkTypePattern::VPN());
106 }
107
108 bool IsVpnConnected() const {
109 NetworkStateHandler* handler =
110 NetworkHandler::Get()->network_state_handler();
111 const NetworkState* vpn =
112 handler->FirstNetworkByType(NetworkTypePattern::VPN());
113 return IsVpnEnabled() &&
114 (vpn->IsConnectedState() || vpn->IsConnectingState());
115 }
116
83 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, 117 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image,
84 base::string16* label, 118 base::string16* label,
85 bool* animating) { 119 bool* animating) {
120 // TODO(bruthig): Update the image to use the proper color. See
121 // https://crbug.com/632147.
86 NetworkStateHandler* handler = 122 NetworkStateHandler* handler =
87 NetworkHandler::Get()->network_state_handler(); 123 NetworkHandler::Get()->network_state_handler();
88 const NetworkState* vpn = 124 const NetworkState* vpn =
89 handler->FirstNetworkByType(NetworkTypePattern::VPN()); 125 handler->FirstNetworkByType(NetworkTypePattern::VPN());
90 *image = ui::network_icon::GetVpnImage(); 126 *image = ui::network_icon::GetVpnImage();
91 if (!vpn || (!vpn->IsConnectedState() && !vpn->IsConnectingState())) { 127 if (!IsVpnConnected()) {
tdanderson 2016/09/22 20:44:16 Thanks for the cleanup.
92 if (label) { 128 if (label) {
93 *label = 129 *label =
94 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); 130 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED);
95 } 131 }
96 *animating = false; 132 *animating = false;
97 return; 133 return;
98 } 134 }
99 *animating = vpn->IsConnectingState(); 135 *animating = vpn->IsConnectingState();
100 if (label) { 136 if (label) {
101 *label = ui::network_icon::GetLabelForNetwork( 137 *label = ui::network_icon::GetLabelForNetwork(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {} 202 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {}
167 203
168 void TrayVPN::NetworkStateChanged() { 204 void TrayVPN::NetworkStateChanged() {
169 if (default_) 205 if (default_)
170 default_->Update(); 206 default_->Update();
171 if (detailed_) 207 if (detailed_)
172 detailed_->Update(); 208 detailed_->Update();
173 } 209 }
174 210
175 } // namespace ash 211 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698