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

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

Issue 2463163002: Update chromeos system menu buttons for MD. (Closed)
Patch Set: rebase Created 4 years, 1 month 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 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/material_design/material_design_controller.h"
11 #include "ash/common/system/chromeos/network/network_icon.h" 12 #include "ash/common/system/chromeos/network/network_icon.h"
12 #include "ash/common/system/chromeos/network/network_icon_animation.h" 13 #include "ash/common/system/chromeos/network/network_icon_animation.h"
13 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" 14 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h"
14 #include "ash/common/system/chromeos/network/network_list_delegate.h" 15 #include "ash/common/system/chromeos/network/network_list_delegate.h"
15 #include "ash/common/system/chromeos/network/vpn_delegate.h" 16 #include "ash/common/system/chromeos/network/vpn_delegate.h"
16 #include "ash/common/system/tray/hover_highlight_view.h" 17 #include "ash/common/system/tray/hover_highlight_view.h"
17 #include "ash/common/system/tray/system_tray_delegate.h" 18 #include "ash/common/system/tray/system_tray_delegate.h"
18 #include "ash/common/system/tray/tray_constants.h" 19 #include "ash/common/system/tray/tray_constants.h"
19 #include "ash/common/system/tray/tray_popup_label_button.h" 20 #include "ash/common/system/tray/tray_popup_label_button.h"
21 #include "ash/common/system/tray/tray_utils.h"
20 #include "ash/common/wm_shell.h" 22 #include "ash/common/wm_shell.h"
21 #include "base/bind.h" 23 #include "base/bind.h"
22 #include "base/bind_helpers.h" 24 #include "base/bind_helpers.h"
23 #include "base/logging.h" 25 #include "base/logging.h"
24 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
25 #include "base/values.h" 27 #include "base/values.h"
26 #include "chromeos/network/network_connection_handler.h" 28 #include "chromeos/network/network_connection_handler.h"
27 #include "chromeos/network/network_handler.h" 29 #include "chromeos/network/network_handler.h"
28 #include "chromeos/network/network_state.h" 30 #include "chromeos/network/network_state.h"
29 #include "chromeos/network/network_type_pattern.h" 31 #include "chromeos/network/network_type_pattern.h"
30 #include "grit/ash_strings.h" 32 #include "grit/ash_strings.h"
31 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/gfx/geometry/rect.h" 34 #include "ui/gfx/geometry/rect.h"
33 #include "ui/gfx/image/image_skia.h" 35 #include "ui/gfx/image/image_skia.h"
34 #include "ui/gfx/text_constants.h" 36 #include "ui/gfx/text_constants.h"
35 #include "ui/views/border.h" 37 #include "ui/views/border.h"
36 #include "ui/views/controls/button/button.h" 38 #include "ui/views/controls/button/button.h"
37 #include "ui/views/controls/label.h" 39 #include "ui/views/controls/label.h"
38 #include "ui/views/controls/separator.h" 40 #include "ui/views/controls/separator.h"
39 #include "ui/views/layout/box_layout.h" 41 #include "ui/views/layout/box_layout.h"
40 #include "ui/views/view.h" 42 #include "ui/views/view.h"
41 43
42 namespace ash { 44 namespace ash {
43 45
44 namespace { 46 namespace {
45 47
48 bool UseMd() {
49 return MaterialDesignController::IsSystemTrayMenuMaterial();
50 }
51
46 bool IsConnectedOrConnecting(const chromeos::NetworkState* network) { 52 bool IsConnectedOrConnecting(const chromeos::NetworkState* network) {
47 return network->IsConnectedState() || network->IsConnectingState(); 53 return network->IsConnectedState() || network->IsConnectingState();
48 } 54 }
49 55
50 void IgnoreDisconnectError(const std::string& error_name, 56 void IgnoreDisconnectError(const std::string& error_name,
51 std::unique_ptr<base::DictionaryValue> error_data) {} 57 std::unique_ptr<base::DictionaryValue> error_data) {}
52 58
53 // The base class of all list entries, a |HoverHighlightView| with no border. 59 // The base class of all list entries, a |HoverHighlightView| with no border.
54 class VPNListEntryBase : public HoverHighlightView { 60 class VPNListEntryBase : public HoverHighlightView {
55 public: 61 public:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 109
104 VPNListNetworkEntry* parent_; 110 VPNListNetworkEntry* parent_;
105 111
106 DISALLOW_COPY_AND_ASSIGN(DisconnectButton); 112 DISALLOW_COPY_AND_ASSIGN(DisconnectButton);
107 }; 113 };
108 114
109 void UpdateFromNetworkState(const chromeos::NetworkState* network); 115 void UpdateFromNetworkState(const chromeos::NetworkState* network);
110 116
111 const std::string service_path_; 117 const std::string service_path_;
112 118
113 DisconnectButton* disconnect_button_ = nullptr; 119 views::LabelButton* disconnect_button_ = nullptr;
114 120
115 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); 121 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry);
116 }; 122 };
117 123
118 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) 124 VPNListEntryBase::VPNListEntryBase(VPNListView* parent)
119 : HoverHighlightView(parent) { 125 : HoverHighlightView(parent) {
120 SetBorder( 126 SetBorder(
121 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); 127 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
122 } 128 }
123 129
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 ->DisconnectNetwork(service_path_, base::Bind(&base::DoNothing), 165 ->DisconnectNetwork(service_path_, base::Bind(&base::DoNothing),
160 base::Bind(&IgnoreDisconnectError)); 166 base::Bind(&IgnoreDisconnectError));
161 } 167 }
162 168
163 VPNListNetworkEntry::DisconnectButton::DisconnectButton( 169 VPNListNetworkEntry::DisconnectButton::DisconnectButton(
164 VPNListNetworkEntry* parent) 170 VPNListNetworkEntry* parent)
165 : TrayPopupLabelButton( 171 : TrayPopupLabelButton(
166 parent, 172 parent,
167 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)), 173 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)),
168 parent_(parent) { 174 parent_(parent) {
175 DCHECK(!UseMd());
169 DCHECK(parent_); 176 DCHECK(parent_);
170 } 177 }
171 178
172 void VPNListNetworkEntry::DisconnectButton::OnMouseEntered( 179 void VPNListNetworkEntry::DisconnectButton::OnMouseEntered(
173 const ui::MouseEvent& event) { 180 const ui::MouseEvent& event) {
174 TrayPopupLabelButton::OnMouseEntered(event); 181 TrayPopupLabelButton::OnMouseEntered(event);
175 parent_->SetHoverHighlight(false); 182 parent_->SetHoverHighlight(false);
176 } 183 }
177 184
178 void VPNListNetworkEntry::DisconnectButton::OnMouseExited( 185 void VPNListNetworkEntry::DisconnectButton::OnMouseExited(
(...skipping 26 matching lines...) Expand all
205 } 212 }
206 213
207 RemoveAllChildViews(true); 214 RemoveAllChildViews(true);
208 disconnect_button_ = nullptr; 215 disconnect_button_ = nullptr;
209 216
210 AddIconAndLabel( 217 AddIconAndLabel(
211 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST), 218 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST),
212 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST), 219 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST),
213 IsConnectedOrConnecting(network)); 220 IsConnectedOrConnecting(network));
214 if (IsConnectedOrConnecting(network)) { 221 if (IsConnectedOrConnecting(network)) {
215 disconnect_button_ = new DisconnectButton(this); 222 if (UseMd()) {
223 disconnect_button_ = CreateTrayPopupButton(
224 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT));
225 } else {
226 disconnect_button_ = new DisconnectButton(this);
227 }
216 AddChildView(disconnect_button_); 228 AddChildView(disconnect_button_);
217 SetBorder( 229 SetBorder(views::Border::CreateEmptyBorder(
218 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 3)); 230 0, kTrayPopupPaddingHorizontal, 0,
231 UseMd() ? kTrayPopupButtonEndMargin : 3));
219 } else { 232 } else {
220 SetBorder( 233 SetBorder(
221 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); 234 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
222 } 235 }
223 236
224 // The icon and the disconnect button are always set to their preferred size. 237 // The icon and the disconnect button are always set to their preferred size.
225 // All remaining space is used for the network name. 238 // All remaining space is used for the network name.
226 views::BoxLayout* layout = new views::BoxLayout( 239 views::BoxLayout* layout =
227 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems); 240 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, UseMd() ? 0 : 3,
241 kTrayPopupPaddingBetweenItems);
242 if (UseMd())
tdanderson 2016/11/01 22:38:50 nit: if (UseMd()) { ... }
Evan Stade 2016/11/01 23:54:09 Done.
243 layout->set_cross_axis_alignment(
244 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
228 SetLayoutManager(layout); 245 SetLayoutManager(layout);
229 layout->SetDefaultFlex(0); 246 layout->SetDefaultFlex(0);
230 layout->SetFlexForView(text_label(), 1); 247 layout->SetFlexForView(text_label(), 1);
231 Layout(); 248 Layout();
232 } 249 }
233 250
234 } // namespace 251 } // namespace
235 252
236 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) { 253 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) {
237 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this); 254 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 429 }
413 } 430 }
414 431
415 // Add providers without any configured networks, in the order that the 432 // Add providers without any configured networks, in the order that the
416 // providers were returned by the extensions system. 433 // providers were returned by the extensions system.
417 for (const VPNProvider& provider : providers) 434 for (const VPNProvider& provider : providers)
418 AddProviderAndNetworks(provider.key, provider.name, networks); 435 AddProviderAndNetworks(provider.key, provider.name, networks);
419 } 436 }
420 437
421 } // namespace ash 438 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698