| OLD | NEW |
| 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" | |
| 13 #include "ash/common/system/chromeos/network/network_icon.h" | 12 #include "ash/common/system/chromeos/network/network_icon.h" |
| 14 #include "ash/common/system/chromeos/network/network_icon_animation.h" | 13 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
| 15 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" | 14 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" |
| 16 #include "ash/common/system/chromeos/network/network_list_delegate.h" | 15 #include "ash/common/system/chromeos/network/network_list_delegate.h" |
| 17 #include "ash/common/system/chromeos/network/vpn_list.h" | 16 #include "ash/common/system/chromeos/network/vpn_list.h" |
| 18 #include "ash/common/system/tray/hover_highlight_view.h" | 17 #include "ash/common/system/tray/hover_highlight_view.h" |
| 19 #include "ash/common/system/tray/system_menu_button.h" | 18 #include "ash/common/system/tray/system_menu_button.h" |
| 20 #include "ash/common/system/tray/system_tray_controller.h" | 19 #include "ash/common/system/tray/system_tray_controller.h" |
| 21 #include "ash/common/system/tray/throbber_view.h" | 20 #include "ash/common/system/tray/throbber_view.h" |
| 22 #include "ash/common/system/tray/tray_constants.h" | 21 #include "ash/common/system/tray/tray_constants.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/gfx/geometry/rect.h" | 40 #include "ui/gfx/geometry/rect.h" |
| 42 #include "ui/gfx/image/image_skia.h" | 41 #include "ui/gfx/image/image_skia.h" |
| 43 #include "ui/gfx/paint_vector_icon.h" | 42 #include "ui/gfx/paint_vector_icon.h" |
| 44 #include "ui/gfx/text_constants.h" | 43 #include "ui/gfx/text_constants.h" |
| 45 #include "ui/views/border.h" | 44 #include "ui/views/border.h" |
| 46 #include "ui/views/controls/button/button.h" | 45 #include "ui/views/controls/button/button.h" |
| 47 #include "ui/views/controls/button/label_button.h" | 46 #include "ui/views/controls/button/label_button.h" |
| 48 #include "ui/views/controls/label.h" | 47 #include "ui/views/controls/label.h" |
| 49 #include "ui/views/controls/separator.h" | 48 #include "ui/views/controls/separator.h" |
| 50 #include "ui/views/layout/box_layout.h" | |
| 51 #include "ui/views/layout/fill_layout.h" | 49 #include "ui/views/layout/fill_layout.h" |
| 52 #include "ui/views/view.h" | 50 #include "ui/views/view.h" |
| 53 | 51 |
| 54 namespace ash { | 52 namespace ash { |
| 55 | 53 |
| 56 namespace { | 54 namespace { |
| 57 | 55 |
| 58 bool UseMd() { | |
| 59 return MaterialDesignController::IsSystemTrayMenuMaterial(); | |
| 60 } | |
| 61 | |
| 62 // Indicates whether |network| belongs to this VPN provider. | 56 // Indicates whether |network| belongs to this VPN provider. |
| 63 bool VpnProviderMatchesNetwork(const VPNProvider& provider, | 57 bool VpnProviderMatchesNetwork(const VPNProvider& provider, |
| 64 const chromeos::NetworkState& network) { | 58 const chromeos::NetworkState& network) { |
| 65 if (network.type() != shill::kTypeVPN) | 59 if (network.type() != shill::kTypeVPN) |
| 66 return false; | 60 return false; |
| 67 const bool network_uses_third_party_provider = | 61 const bool network_uses_third_party_provider = |
| 68 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; | 62 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; |
| 69 if (!provider.third_party) | 63 if (!provider.third_party) |
| 70 return !network_uses_third_party_provider; | 64 return !network_uses_third_party_provider; |
| 71 return network_uses_third_party_provider && | 65 return network_uses_third_party_provider && |
| 72 network.third_party_vpn_provider_extension_id() == | 66 network.third_party_vpn_provider_extension_id() == |
| 73 provider.extension_id; | 67 provider.extension_id; |
| 74 } | 68 } |
| 75 | 69 |
| 76 // The base class of all list entries, a |HoverHighlightView| with no border. | 70 // The base class of all list entries, a |HoverHighlightView| with no border. |
| 77 class VPNListEntryBase : public HoverHighlightView { | 71 class VPNListEntryBase : public HoverHighlightView { |
| 78 public: | 72 public: |
| 79 // When the user clicks the entry, the |parent|'s OnViewClicked() will be | 73 // When the user clicks the entry, the |parent|'s OnViewClicked() will be |
| 80 // invoked. | 74 // invoked. |
| 81 explicit VPNListEntryBase(VPNListView* parent); | 75 explicit VPNListEntryBase(VPNListView* parent); |
| 82 | 76 |
| 83 private: | 77 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(VPNListEntryBase); | 78 DISALLOW_COPY_AND_ASSIGN(VPNListEntryBase); |
| 85 }; | 79 }; |
| 86 | 80 |
| 87 // A list entry that represents a VPN provider. | 81 // A list entry that represents a VPN provider. |
| 88 class VPNListProviderEntry : public VPNListEntryBase { | 82 class VPNListProviderEntry : public views::ButtonListener, public views::View { |
| 89 public: | 83 public: |
| 90 VPNListProviderEntry(VPNListView* parent, const std::string& name) | 84 VPNListProviderEntry(ViewClickListener* parent, |
| 91 : VPNListEntryBase(parent) { | 85 bool top_item, |
| 92 views::Label* const label = AddLabel( | 86 const std::string& name, |
| 93 base::UTF8ToUTF16(name), gfx::ALIGN_LEFT, false /* highlight */); | 87 int button_accessible_name_id) |
| 94 label->SetBorder(views::CreateEmptyBorder(5, 0, 5, 0)); | |
| 95 } | |
| 96 | |
| 97 private: | |
| 98 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntry); | |
| 99 }; | |
| 100 | |
| 101 // A list entry that represents a VPN provider with Material Design. | |
| 102 class VPNListProviderEntryMd : public views::ButtonListener, | |
| 103 public views::View { | |
| 104 public: | |
| 105 VPNListProviderEntryMd(ViewClickListener* parent, | |
| 106 bool top_item, | |
| 107 const std::string& name, | |
| 108 int button_accessible_name_id) | |
| 109 : parent_(parent) { | 88 : parent_(parent) { |
| 110 TrayPopupUtils::ConfigureAsStickyHeader(this); | 89 TrayPopupUtils::ConfigureAsStickyHeader(this); |
| 111 SetLayoutManager(new views::FillLayout); | 90 SetLayoutManager(new views::FillLayout); |
| 112 TriView* tri_view = TrayPopupUtils::CreateSubHeaderRowView(); | 91 TriView* tri_view = TrayPopupUtils::CreateSubHeaderRowView(); |
| 113 AddChildView(tri_view); | 92 AddChildView(tri_view); |
| 114 | 93 |
| 115 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | 94 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); |
| 116 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); | 95 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); |
| 117 style.SetupLabel(label); | 96 style.SetupLabel(label); |
| 118 label->SetText(base::ASCIIToUTF16(name)); | 97 label->SetText(base::ASCIIToUTF16(name)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 133 protected: | 112 protected: |
| 134 // views::ButtonListener: | 113 // views::ButtonListener: |
| 135 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 114 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 136 parent_->OnViewClicked(this); | 115 parent_->OnViewClicked(this); |
| 137 } | 116 } |
| 138 | 117 |
| 139 private: | 118 private: |
| 140 // Our parent to handle events. | 119 // Our parent to handle events. |
| 141 ViewClickListener* parent_; | 120 ViewClickListener* parent_; |
| 142 | 121 |
| 143 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntryMd); | 122 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntry); |
| 144 }; | 123 }; |
| 145 | 124 |
| 146 // A list entry that represents a network. If the network is currently | 125 // A list entry that represents a network. If the network is currently |
| 147 // connecting, the icon shown by this list entry will be animated. If the | 126 // connecting, the icon shown by this list entry will be animated. If the |
| 148 // network is currently connected, a disconnect button will be shown next to its | 127 // network is currently connected, a disconnect button will be shown next to its |
| 149 // name. | 128 // name. |
| 150 class VPNListNetworkEntry : public VPNListEntryBase, | 129 class VPNListNetworkEntry : public VPNListEntryBase, |
| 151 public network_icon::AnimationObserver { | 130 public network_icon::AnimationObserver { |
| 152 public: | 131 public: |
| 153 VPNListNetworkEntry(VPNListView* parent, | 132 VPNListNetworkEntry(VPNListView* parent, |
| 154 const chromeos::NetworkState* network); | 133 const chromeos::NetworkState* network); |
| 155 ~VPNListNetworkEntry() override; | 134 ~VPNListNetworkEntry() override; |
| 156 | 135 |
| 157 // network_icon::AnimationObserver: | 136 // network_icon::AnimationObserver: |
| 158 void NetworkIconChanged() override; | 137 void NetworkIconChanged() override; |
| 159 | 138 |
| 160 // views::ButtonListener: | 139 // views::ButtonListener: |
| 161 void ButtonPressed(Button* sender, const ui::Event& event) override; | 140 void ButtonPressed(Button* sender, const ui::Event& event) override; |
| 162 | 141 |
| 163 private: | 142 private: |
| 164 void UpdateFromNetworkState(const chromeos::NetworkState* network); | 143 void UpdateFromNetworkState(const chromeos::NetworkState* network); |
| 165 void SetupConnectedItemMd(const base::string16& text, | 144 void SetupConnectedItem(const base::string16& text, |
| 166 const gfx::ImageSkia& image); | 145 const gfx::ImageSkia& image); |
| 167 void SetupConnectingItemMd(const base::string16& text, | 146 void SetupConnectingItem(const base::string16& text, |
| 168 const gfx::ImageSkia& image); | 147 const gfx::ImageSkia& image); |
| 169 | 148 |
| 170 const std::string guid_; | 149 const std::string guid_; |
| 171 | 150 |
| 172 views::LabelButton* disconnect_button_ = nullptr; | 151 views::LabelButton* disconnect_button_ = nullptr; |
| 173 | 152 |
| 174 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); | 153 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); |
| 175 }; | 154 }; |
| 176 | 155 |
| 177 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) | 156 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) |
| 178 : HoverHighlightView(parent) { | 157 : HoverHighlightView(parent) {} |
| 179 if (!UseMd()) | |
| 180 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); | |
| 181 } | |
| 182 | 158 |
| 183 VPNListNetworkEntry::VPNListNetworkEntry(VPNListView* parent, | 159 VPNListNetworkEntry::VPNListNetworkEntry(VPNListView* parent, |
| 184 const chromeos::NetworkState* network) | 160 const chromeos::NetworkState* network) |
| 185 : VPNListEntryBase(parent), guid_(network->guid()) { | 161 : VPNListEntryBase(parent), guid_(network->guid()) { |
| 186 UpdateFromNetworkState(network); | 162 UpdateFromNetworkState(network); |
| 187 } | 163 } |
| 188 | 164 |
| 189 VPNListNetworkEntry::~VPNListNetworkEntry() { | 165 VPNListNetworkEntry::~VPNListNetworkEntry() { |
| 190 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 166 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 191 } | 167 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 217 // This is a transient state where the network has been removed already but | 193 // This is a transient state where the network has been removed already but |
| 218 // the network list in the UI has not been updated yet. | 194 // the network list in the UI has not been updated yet. |
| 219 return; | 195 return; |
| 220 } | 196 } |
| 221 RemoveAllChildViews(true); | 197 RemoveAllChildViews(true); |
| 222 disconnect_button_ = nullptr; | 198 disconnect_button_ = nullptr; |
| 223 | 199 |
| 224 gfx::ImageSkia image = | 200 gfx::ImageSkia image = |
| 225 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); | 201 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); |
| 226 base::string16 label = network_icon::GetLabelForNetwork( | 202 base::string16 label = network_icon::GetLabelForNetwork( |
| 227 network, UseMd() ? network_icon::ICON_TYPE_MENU_LIST | 203 network, network_icon::ICON_TYPE_MENU_LIST); |
| 228 : network_icon::ICON_TYPE_LIST); | |
| 229 if (network->IsConnectedState()) | 204 if (network->IsConnectedState()) |
| 230 SetupConnectedItemMd(label, image); | 205 SetupConnectedItem(label, image); |
| 231 else if (network->IsConnectingState()) | 206 else if (network->IsConnectingState()) |
| 232 SetupConnectingItemMd(label, image); | 207 SetupConnectingItem(label, image); |
| 233 else | 208 else |
| 234 AddIconAndLabel(image, label, false); | 209 AddIconAndLabel(image, label, false); |
| 235 | 210 |
| 236 if (network->IsConnectedState()) { | 211 if (network->IsConnectedState()) { |
| 237 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton( | 212 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton( |
| 238 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)); | 213 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)); |
| 239 tri_view()->AddView(TriView::Container::END, disconnect_button_); | 214 tri_view()->AddView(TriView::Container::END, disconnect_button_); |
| 240 tri_view()->SetContainerVisible(TriView::Container::END, true); | 215 tri_view()->SetContainerVisible(TriView::Container::END, true); |
| 241 tri_view()->SetContainerBorder( | 216 tri_view()->SetContainerBorder( |
| 242 TriView::Container::END, | 217 TriView::Container::END, |
| 243 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); | 218 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); |
| 244 } | 219 } |
| 245 Layout(); | 220 Layout(); |
| 246 } | 221 } |
| 247 | 222 |
| 248 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. | 223 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. |
| 249 void VPNListNetworkEntry::SetupConnectedItemMd(const base::string16& text, | 224 void VPNListNetworkEntry::SetupConnectedItem(const base::string16& text, |
| 250 const gfx::ImageSkia& image) { | 225 const gfx::ImageSkia& image) { |
| 251 AddIconAndLabels( | 226 AddIconAndLabels( |
| 252 image, text, | 227 image, text, |
| 253 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); | 228 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); |
| 254 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); | 229 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); |
| 255 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); | 230 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); |
| 256 style.SetupLabel(sub_text_label()); | 231 style.SetupLabel(sub_text_label()); |
| 257 } | 232 } |
| 258 | 233 |
| 259 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. | 234 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. |
| 260 void VPNListNetworkEntry::SetupConnectingItemMd(const base::string16& text, | 235 void VPNListNetworkEntry::SetupConnectingItem(const base::string16& text, |
| 261 const gfx::ImageSkia& image) { | 236 const gfx::ImageSkia& image) { |
| 262 AddIconAndLabels( | 237 AddIconAndLabels( |
| 263 image, text, | 238 image, text, |
| 264 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); | 239 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); |
| 265 ThrobberView* throbber = new ThrobberView; | 240 ThrobberView* throbber = new ThrobberView; |
| 266 throbber->Start(); | 241 throbber->Start(); |
| 267 AddRightView(throbber); | 242 AddRightView(throbber); |
| 268 } | 243 } |
| 269 | 244 |
| 270 } // namespace | 245 } // namespace |
| 271 | 246 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 297 break; | 272 break; |
| 298 } | 273 } |
| 299 } | 274 } |
| 300 } | 275 } |
| 301 | 276 |
| 302 // Clear the list. | 277 // Clear the list. |
| 303 container()->RemoveAllChildViews(true); | 278 container()->RemoveAllChildViews(true); |
| 304 provider_view_map_.clear(); | 279 provider_view_map_.clear(); |
| 305 network_view_guid_map_.clear(); | 280 network_view_guid_map_.clear(); |
| 306 list_empty_ = true; | 281 list_empty_ = true; |
| 307 if (!UseMd()) { | |
| 308 container()->SetLayoutManager( | |
| 309 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 310 } | |
| 311 | 282 |
| 312 // Get the list of available VPN networks, in shill's priority order. | 283 // Get the list of available VPN networks, in shill's priority order. |
| 313 chromeos::NetworkStateHandler::NetworkStateList networks; | 284 chromeos::NetworkStateHandler::NetworkStateList networks; |
| 314 chromeos::NetworkHandler::Get() | 285 chromeos::NetworkHandler::Get() |
| 315 ->network_state_handler() | 286 ->network_state_handler() |
| 316 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), | 287 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), |
| 317 &networks); | 288 &networks); |
| 318 | 289 |
| 319 // Show all VPN providers and all networks that are currently disconnected. | 290 // Show all VPN providers and all networks that are currently disconnected. |
| 320 AddProvidersAndNetworks(networks); | 291 AddProvidersAndNetworks(networks); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // Add a visual separator, unless this is the topmost entry in the list. | 373 // Add a visual separator, unless this is the topmost entry in the list. |
| 403 if (!list_empty_) | 374 if (!list_empty_) |
| 404 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); | 375 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); |
| 405 std::string vpn_name = | 376 std::string vpn_name = |
| 406 vpn_provider.third_party | 377 vpn_provider.third_party |
| 407 ? vpn_provider.third_party_provider_name | 378 ? vpn_provider.third_party_provider_name |
| 408 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER); | 379 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER); |
| 409 | 380 |
| 410 // Add a list entry for the VPN provider. | 381 // Add a list entry for the VPN provider. |
| 411 views::View* provider_view = nullptr; | 382 views::View* provider_view = nullptr; |
| 412 if (UseMd()) { | 383 provider_view = new VPNListProviderEntry(this, list_empty_, vpn_name, |
| 413 provider_view = new VPNListProviderEntryMd( | 384 IDS_ASH_STATUS_TRAY_ADD_CONNECTION); |
| 414 this, list_empty_, vpn_name, IDS_ASH_STATUS_TRAY_ADD_CONNECTION); | |
| 415 } else { | |
| 416 provider_view = new VPNListProviderEntry(this, vpn_name); | |
| 417 } | |
| 418 container()->AddChildView(provider_view); | 385 container()->AddChildView(provider_view); |
| 419 provider_view_map_[provider_view] = vpn_provider; | 386 provider_view_map_[provider_view] = vpn_provider; |
| 420 list_empty_ = false; | 387 list_empty_ = false; |
| 421 // Add the networks belonging to this provider, in the priority order returned | 388 // Add the networks belonging to this provider, in the priority order returned |
| 422 // by shill. | 389 // by shill. |
| 423 for (const chromeos::NetworkState* const& network : networks) { | 390 for (const chromeos::NetworkState* const& network : networks) { |
| 424 if (VpnProviderMatchesNetwork(vpn_provider, *network)) | 391 if (VpnProviderMatchesNetwork(vpn_provider, *network)) |
| 425 AddNetwork(network); | 392 AddNetwork(network); |
| 426 } | 393 } |
| 427 } | 394 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 446 } | 413 } |
| 447 } | 414 } |
| 448 | 415 |
| 449 // Add providers without any configured networks, in the order that the | 416 // Add providers without any configured networks, in the order that the |
| 450 // providers were returned by the extensions system. | 417 // providers were returned by the extensions system. |
| 451 for (const VPNProvider& provider : providers) | 418 for (const VPNProvider& provider : providers) |
| 452 AddProviderAndNetworks(provider, networks); | 419 AddProviderAndNetworks(provider, networks); |
| 453 } | 420 } |
| 454 | 421 |
| 455 } // namespace ash | 422 } // namespace ash |
| OLD | NEW |