Chromium Code Reviews| 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 |
|
tdanderson
2017/03/22 23:39:55
note: I suggest that your other CL https://chromiu
varkha
2017/03/23 01:22:12
Makes sense. Will wait.
| |
| 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" | 49 #include "ui/views/layout/box_layout.h" |
|
tdanderson
2017/03/22 23:39:55
nit: I think you can delete this now
varkha
2017/03/23 01:22:12
Done.
| |
| 51 #include "ui/views/layout/fill_layout.h" | 50 #include "ui/views/layout/fill_layout.h" |
| 52 #include "ui/views/view.h" | 51 #include "ui/views/view.h" |
| 53 | 52 |
| 54 namespace ash { | 53 namespace ash { |
| 55 | 54 |
| 56 namespace { | 55 namespace { |
| 57 | 56 |
| 58 bool UseMd() { | |
| 59 return MaterialDesignController::IsSystemTrayMenuMaterial(); | |
| 60 } | |
| 61 | |
| 62 // Indicates whether |network| belongs to this VPN provider. | 57 // Indicates whether |network| belongs to this VPN provider. |
| 63 bool VpnProviderMatchesNetwork(const VPNProvider& provider, | 58 bool VpnProviderMatchesNetwork(const VPNProvider& provider, |
| 64 const chromeos::NetworkState& network) { | 59 const chromeos::NetworkState& network) { |
| 65 if (network.type() != shill::kTypeVPN) | 60 if (network.type() != shill::kTypeVPN) |
| 66 return false; | 61 return false; |
| 67 const bool network_uses_third_party_provider = | 62 const bool network_uses_third_party_provider = |
| 68 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; | 63 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; |
| 69 if (!provider.third_party) | 64 if (!provider.third_party) |
| 70 return !network_uses_third_party_provider; | 65 return !network_uses_third_party_provider; |
| 71 return network_uses_third_party_provider && | 66 return network_uses_third_party_provider && |
| 72 network.third_party_vpn_provider_extension_id() == | 67 network.third_party_vpn_provider_extension_id() == |
| 73 provider.extension_id; | 68 provider.extension_id; |
| 74 } | 69 } |
| 75 | 70 |
| 76 // The base class of all list entries, a |HoverHighlightView| with no border. | 71 // The base class of all list entries, a |HoverHighlightView| with no border. |
| 77 class VPNListEntryBase : public HoverHighlightView { | 72 class VPNListEntryBase : public HoverHighlightView { |
| 78 public: | 73 public: |
| 79 // When the user clicks the entry, the |parent|'s OnViewClicked() will be | 74 // When the user clicks the entry, the |parent|'s OnViewClicked() will be |
| 80 // invoked. | 75 // invoked. |
| 81 explicit VPNListEntryBase(VPNListView* parent); | 76 explicit VPNListEntryBase(VPNListView* parent); |
| 82 | 77 |
| 83 private: | 78 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(VPNListEntryBase); | 79 DISALLOW_COPY_AND_ASSIGN(VPNListEntryBase); |
| 85 }; | 80 }; |
| 86 | 81 |
| 87 // A list entry that represents a VPN provider. | 82 // A list entry that represents a VPN provider. |
| 88 class VPNListProviderEntry : public VPNListEntryBase { | 83 class VPNListProviderEntry : public views::ButtonListener, public views::View { |
| 89 public: | 84 public: |
| 90 VPNListProviderEntry(VPNListView* parent, const std::string& name) | 85 VPNListProviderEntry(ViewClickListener* parent, |
| 91 : VPNListEntryBase(parent) { | 86 bool top_item, |
| 92 views::Label* const label = AddLabel( | 87 const std::string& name, |
| 93 base::UTF8ToUTF16(name), gfx::ALIGN_LEFT, false /* highlight */); | 88 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) { | 89 : parent_(parent) { |
| 110 TrayPopupUtils::ConfigureAsStickyHeader(this); | 90 TrayPopupUtils::ConfigureAsStickyHeader(this); |
| 111 SetLayoutManager(new views::FillLayout); | 91 SetLayoutManager(new views::FillLayout); |
| 112 TriView* tri_view = TrayPopupUtils::CreateSubHeaderRowView(); | 92 TriView* tri_view = TrayPopupUtils::CreateSubHeaderRowView(); |
| 113 AddChildView(tri_view); | 93 AddChildView(tri_view); |
| 114 | 94 |
| 115 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | 95 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); |
| 116 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); | 96 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); |
| 117 style.SetupLabel(label); | 97 style.SetupLabel(label); |
| 118 label->SetText(base::ASCIIToUTF16(name)); | 98 label->SetText(base::ASCIIToUTF16(name)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 133 protected: | 113 protected: |
| 134 // views::ButtonListener: | 114 // views::ButtonListener: |
| 135 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 115 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 136 parent_->OnViewClicked(this); | 116 parent_->OnViewClicked(this); |
| 137 } | 117 } |
| 138 | 118 |
| 139 private: | 119 private: |
| 140 // Our parent to handle events. | 120 // Our parent to handle events. |
| 141 ViewClickListener* parent_; | 121 ViewClickListener* parent_; |
| 142 | 122 |
| 143 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntryMd); | 123 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntry); |
| 144 }; | 124 }; |
| 145 | 125 |
| 146 // A list entry that represents a network. If the network is currently | 126 // 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 | 127 // 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 | 128 // network is currently connected, a disconnect button will be shown next to its |
| 149 // name. | 129 // name. |
| 150 class VPNListNetworkEntry : public VPNListEntryBase, | 130 class VPNListNetworkEntry : public VPNListEntryBase, |
| 151 public network_icon::AnimationObserver { | 131 public network_icon::AnimationObserver { |
| 152 public: | 132 public: |
| 153 VPNListNetworkEntry(VPNListView* parent, | 133 VPNListNetworkEntry(VPNListView* parent, |
| 154 const chromeos::NetworkState* network); | 134 const chromeos::NetworkState* network); |
| 155 ~VPNListNetworkEntry() override; | 135 ~VPNListNetworkEntry() override; |
| 156 | 136 |
| 157 // network_icon::AnimationObserver: | 137 // network_icon::AnimationObserver: |
| 158 void NetworkIconChanged() override; | 138 void NetworkIconChanged() override; |
| 159 | 139 |
| 160 private: | 140 private: |
| 161 void UpdateFromNetworkState(const chromeos::NetworkState* network); | 141 void UpdateFromNetworkState(const chromeos::NetworkState* network); |
| 162 void SetupConnectedItemMd(const base::string16& text, | 142 void SetupConnectedItem(const base::string16& text, |
| 163 const gfx::ImageSkia& image); | 143 const gfx::ImageSkia& image); |
| 164 void SetupConnectingItemMd(const base::string16& text, | 144 void SetupConnectingItem(const base::string16& text, |
| 165 const gfx::ImageSkia& image); | 145 const gfx::ImageSkia& image); |
| 166 | 146 |
| 167 const std::string guid_; | 147 const std::string guid_; |
| 168 | 148 |
| 169 views::LabelButton* disconnect_button_ = nullptr; | 149 views::LabelButton* disconnect_button_ = nullptr; |
| 170 | 150 |
| 171 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); | 151 DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); |
| 172 }; | 152 }; |
| 173 | 153 |
| 174 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) | 154 VPNListEntryBase::VPNListEntryBase(VPNListView* parent) |
| 175 : HoverHighlightView(parent) { | 155 : HoverHighlightView(parent) {} |
| 176 if (!UseMd()) | |
| 177 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); | |
| 178 } | |
| 179 | 156 |
| 180 VPNListNetworkEntry::VPNListNetworkEntry(VPNListView* parent, | 157 VPNListNetworkEntry::VPNListNetworkEntry(VPNListView* parent, |
| 181 const chromeos::NetworkState* network) | 158 const chromeos::NetworkState* network) |
| 182 : VPNListEntryBase(parent), guid_(network->guid()) { | 159 : VPNListEntryBase(parent), guid_(network->guid()) { |
| 183 UpdateFromNetworkState(network); | 160 UpdateFromNetworkState(network); |
| 184 } | 161 } |
| 185 | 162 |
| 186 VPNListNetworkEntry::~VPNListNetworkEntry() { | 163 VPNListNetworkEntry::~VPNListNetworkEntry() { |
| 187 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 164 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 188 } | 165 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 204 // This is a transient state where the network has been removed already but | 181 // This is a transient state where the network has been removed already but |
| 205 // the network list in the UI has not been updated yet. | 182 // the network list in the UI has not been updated yet. |
| 206 return; | 183 return; |
| 207 } | 184 } |
| 208 RemoveAllChildViews(true); | 185 RemoveAllChildViews(true); |
| 209 disconnect_button_ = nullptr; | 186 disconnect_button_ = nullptr; |
| 210 | 187 |
| 211 gfx::ImageSkia image = | 188 gfx::ImageSkia image = |
| 212 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); | 189 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); |
| 213 base::string16 label = network_icon::GetLabelForNetwork( | 190 base::string16 label = network_icon::GetLabelForNetwork( |
| 214 network, UseMd() ? network_icon::ICON_TYPE_MENU_LIST | 191 network, network_icon::ICON_TYPE_MENU_LIST); |
| 215 : network_icon::ICON_TYPE_LIST); | |
| 216 if (network->IsConnectedState()) | 192 if (network->IsConnectedState()) |
| 217 SetupConnectedItemMd(label, image); | 193 SetupConnectedItem(label, image); |
| 218 else if (network->IsConnectingState()) | 194 else if (network->IsConnectingState()) |
| 219 SetupConnectingItemMd(label, image); | 195 SetupConnectingItem(label, image); |
| 220 else | 196 else |
| 221 AddIconAndLabel(image, label, false); | 197 AddIconAndLabel(image, label, false); |
| 222 | 198 |
| 223 if (network->IsConnectedState()) { | 199 if (network->IsConnectedState()) { |
| 224 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton( | 200 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton( |
| 225 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)); | 201 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)); |
| 226 tri_view()->AddView(TriView::Container::END, disconnect_button_); | 202 tri_view()->AddView(TriView::Container::END, disconnect_button_); |
| 227 tri_view()->SetContainerVisible(TriView::Container::END, true); | 203 tri_view()->SetContainerVisible(TriView::Container::END, true); |
| 228 tri_view()->SetContainerBorder( | 204 tri_view()->SetContainerBorder( |
| 229 TriView::Container::END, | 205 TriView::Container::END, |
| 230 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); | 206 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); |
| 231 } | 207 } |
| 232 Layout(); | 208 Layout(); |
| 233 } | 209 } |
| 234 | 210 |
| 235 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. | 211 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. |
| 236 void VPNListNetworkEntry::SetupConnectedItemMd(const base::string16& text, | 212 void VPNListNetworkEntry::SetupConnectedItem(const base::string16& text, |
| 237 const gfx::ImageSkia& image) { | 213 const gfx::ImageSkia& image) { |
| 238 AddIconAndLabels( | 214 AddIconAndLabels( |
| 239 image, text, | 215 image, text, |
| 240 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); | 216 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); |
| 241 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); | 217 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); |
| 242 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); | 218 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); |
| 243 style.SetupLabel(sub_text_label()); | 219 style.SetupLabel(sub_text_label()); |
| 244 } | 220 } |
| 245 | 221 |
| 246 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. | 222 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. |
| 247 void VPNListNetworkEntry::SetupConnectingItemMd(const base::string16& text, | 223 void VPNListNetworkEntry::SetupConnectingItem(const base::string16& text, |
| 248 const gfx::ImageSkia& image) { | 224 const gfx::ImageSkia& image) { |
| 249 AddIconAndLabels( | 225 AddIconAndLabels( |
| 250 image, text, | 226 image, text, |
| 251 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); | 227 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); |
| 252 ThrobberView* throbber = new ThrobberView; | 228 ThrobberView* throbber = new ThrobberView; |
| 253 throbber->Start(); | 229 throbber->Start(); |
| 254 AddRightView(throbber); | 230 AddRightView(throbber); |
| 255 } | 231 } |
| 256 | 232 |
| 257 } // namespace | 233 } // namespace |
| 258 | 234 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 284 break; | 260 break; |
| 285 } | 261 } |
| 286 } | 262 } |
| 287 } | 263 } |
| 288 | 264 |
| 289 // Clear the list. | 265 // Clear the list. |
| 290 container()->RemoveAllChildViews(true); | 266 container()->RemoveAllChildViews(true); |
| 291 provider_view_map_.clear(); | 267 provider_view_map_.clear(); |
| 292 network_view_guid_map_.clear(); | 268 network_view_guid_map_.clear(); |
| 293 list_empty_ = true; | 269 list_empty_ = true; |
| 294 if (!UseMd()) { | |
| 295 container()->SetLayoutManager( | |
| 296 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 297 } | |
| 298 | 270 |
| 299 // Get the list of available VPN networks, in shill's priority order. | 271 // Get the list of available VPN networks, in shill's priority order. |
| 300 chromeos::NetworkStateHandler::NetworkStateList networks; | 272 chromeos::NetworkStateHandler::NetworkStateList networks; |
| 301 chromeos::NetworkHandler::Get() | 273 chromeos::NetworkHandler::Get() |
| 302 ->network_state_handler() | 274 ->network_state_handler() |
| 303 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), | 275 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), |
| 304 &networks); | 276 &networks); |
| 305 | 277 |
| 306 // Show all VPN providers and all networks that are currently disconnected. | 278 // Show all VPN providers and all networks that are currently disconnected. |
| 307 AddProvidersAndNetworks(networks); | 279 AddProvidersAndNetworks(networks); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 // Add a visual separator, unless this is the topmost entry in the list. | 361 // Add a visual separator, unless this is the topmost entry in the list. |
| 390 if (!list_empty_) | 362 if (!list_empty_) |
| 391 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); | 363 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); |
| 392 std::string vpn_name = | 364 std::string vpn_name = |
| 393 vpn_provider.third_party | 365 vpn_provider.third_party |
| 394 ? vpn_provider.third_party_provider_name | 366 ? vpn_provider.third_party_provider_name |
| 395 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER); | 367 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER); |
| 396 | 368 |
| 397 // Add a list entry for the VPN provider. | 369 // Add a list entry for the VPN provider. |
| 398 views::View* provider_view = nullptr; | 370 views::View* provider_view = nullptr; |
| 399 if (UseMd()) { | 371 provider_view = new VPNListProviderEntry(this, list_empty_, vpn_name, |
| 400 provider_view = new VPNListProviderEntryMd( | 372 IDS_ASH_STATUS_TRAY_ADD_CONNECTION); |
| 401 this, list_empty_, vpn_name, IDS_ASH_STATUS_TRAY_ADD_CONNECTION); | |
| 402 } else { | |
| 403 provider_view = new VPNListProviderEntry(this, vpn_name); | |
| 404 } | |
| 405 container()->AddChildView(provider_view); | 373 container()->AddChildView(provider_view); |
| 406 provider_view_map_[provider_view] = vpn_provider; | 374 provider_view_map_[provider_view] = vpn_provider; |
| 407 list_empty_ = false; | 375 list_empty_ = false; |
| 408 // Add the networks belonging to this provider, in the priority order returned | 376 // Add the networks belonging to this provider, in the priority order returned |
| 409 // by shill. | 377 // by shill. |
| 410 for (const chromeos::NetworkState* const& network : networks) { | 378 for (const chromeos::NetworkState* const& network : networks) { |
| 411 if (VpnProviderMatchesNetwork(vpn_provider, *network)) | 379 if (VpnProviderMatchesNetwork(vpn_provider, *network)) |
| 412 AddNetwork(network); | 380 AddNetwork(network); |
| 413 } | 381 } |
| 414 } | 382 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 433 } | 401 } |
| 434 } | 402 } |
| 435 | 403 |
| 436 // Add providers without any configured networks, in the order that the | 404 // Add providers without any configured networks, in the order that the |
| 437 // providers were returned by the extensions system. | 405 // providers were returned by the extensions system. |
| 438 for (const VPNProvider& provider : providers) | 406 for (const VPNProvider& provider : providers) |
| 439 AddProviderAndNetworks(provider, networks); | 407 AddProviderAndNetworks(provider, networks); |
| 440 } | 408 } |
| 441 | 409 |
| 442 } // namespace ash | 410 } // namespace ash |
| OLD | NEW |