| 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/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_observer.h" |
| 14 #include "ash/common/system/chromeos/network/network_list_delegate.h" |
| 11 #include "ash/common/system/chromeos/network/vpn_delegate.h" | 15 #include "ash/common/system/chromeos/network/vpn_delegate.h" |
| 12 #include "ash/common/system/tray/hover_highlight_view.h" | 16 #include "ash/common/system/tray/hover_highlight_view.h" |
| 13 #include "ash/common/system/tray/system_tray_delegate.h" | 17 #include "ash/common/system/tray/system_tray_delegate.h" |
| 14 #include "ash/common/system/tray/tray_constants.h" | 18 #include "ash/common/system/tray/tray_constants.h" |
| 15 #include "ash/common/system/tray/tray_popup_label_button.h" | 19 #include "ash/common/system/tray/tray_popup_label_button.h" |
| 16 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
| 17 #include "base/bind.h" | 21 #include "base/bind.h" |
| 18 #include "base/bind_helpers.h" | 22 #include "base/bind_helpers.h" |
| 19 #include "base/logging.h" | 23 #include "base/logging.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/values.h" | 25 #include "base/values.h" |
| 22 #include "chromeos/network/network_connection_handler.h" | 26 #include "chromeos/network/network_connection_handler.h" |
| 23 #include "chromeos/network/network_handler.h" | 27 #include "chromeos/network/network_handler.h" |
| 24 #include "chromeos/network/network_state.h" | 28 #include "chromeos/network/network_state.h" |
| 25 #include "chromeos/network/network_type_pattern.h" | 29 #include "chromeos/network/network_type_pattern.h" |
| 26 #include "grit/ash_strings.h" | 30 #include "grit/ash_strings.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/chromeos/network/network_icon.h" | |
| 29 #include "ui/chromeos/network/network_icon_animation.h" | |
| 30 #include "ui/chromeos/network/network_icon_animation_observer.h" | |
| 31 #include "ui/chromeos/network/network_list_delegate.h" | |
| 32 #include "ui/gfx/geometry/rect.h" | 32 #include "ui/gfx/geometry/rect.h" |
| 33 #include "ui/gfx/image/image_skia.h" | 33 #include "ui/gfx/image/image_skia.h" |
| 34 #include "ui/gfx/text_constants.h" | 34 #include "ui/gfx/text_constants.h" |
| 35 #include "ui/views/border.h" | 35 #include "ui/views/border.h" |
| 36 #include "ui/views/controls/button/button.h" | 36 #include "ui/views/controls/button/button.h" |
| 37 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
| 38 #include "ui/views/controls/separator.h" | 38 #include "ui/views/controls/separator.h" |
| 39 #include "ui/views/layout/box_layout.h" | 39 #include "ui/views/layout/box_layout.h" |
| 40 #include "ui/views/view.h" | 40 #include "ui/views/view.h" |
| 41 | 41 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntry); | 70 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntry); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // A list entry that represents a network. If the network is currently | 73 // A list entry that represents a network. If the network is currently |
| 74 // connecting, the icon shown by this list entry will be animated. If the | 74 // connecting, the icon shown by this list entry will be animated. If the |
| 75 // network is currently connected, a disconnect button will be shown next to its | 75 // network is currently connected, a disconnect button will be shown next to its |
| 76 // name. | 76 // name. |
| 77 class VPNListNetworkEntry : public VPNListEntryBase, | 77 class VPNListNetworkEntry : public VPNListEntryBase, |
| 78 public ui::network_icon::AnimationObserver, | 78 public network_icon::AnimationObserver, |
| 79 public views::ButtonListener { | 79 public views::ButtonListener { |
| 80 public: | 80 public: |
| 81 VPNListNetworkEntry(VPNListView* parent, | 81 VPNListNetworkEntry(VPNListView* parent, |
| 82 const chromeos::NetworkState* network); | 82 const chromeos::NetworkState* network); |
| 83 ~VPNListNetworkEntry() override; | 83 ~VPNListNetworkEntry() override; |
| 84 | 84 |
| 85 // ui::network_icon::AnimationObserver: | 85 // network_icon::AnimationObserver: |
| 86 void NetworkIconChanged() override; | 86 void NetworkIconChanged() override; |
| 87 | 87 |
| 88 // views::ButtonListener: | 88 // views::ButtonListener: |
| 89 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 89 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 // A disconnect button that will be shown if the network is currently | 92 // A disconnect button that will be shown if the network is currently |
| 93 // connected. Updates the list entry's hover state as the mouse enters/exits | 93 // connected. Updates the list entry's hover state as the mouse enters/exits |
| 94 // the button. | 94 // the button. |
| 95 class DisconnectButton : public TrayPopupLabelButton { | 95 class DisconnectButton : public TrayPopupLabelButton { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 label->SetBorder(views::Border::CreateEmptyBorder(5, 0, 5, 0)); | 130 label->SetBorder(views::Border::CreateEmptyBorder(5, 0, 5, 0)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 VPNListNetworkEntry::VPNListNetworkEntry(VPNListView* parent, | 133 VPNListNetworkEntry::VPNListNetworkEntry(VPNListView* parent, |
| 134 const chromeos::NetworkState* network) | 134 const chromeos::NetworkState* network) |
| 135 : VPNListEntryBase(parent), service_path_(network->path()) { | 135 : VPNListEntryBase(parent), service_path_(network->path()) { |
| 136 UpdateFromNetworkState(network); | 136 UpdateFromNetworkState(network); |
| 137 } | 137 } |
| 138 | 138 |
| 139 VPNListNetworkEntry::~VPNListNetworkEntry() { | 139 VPNListNetworkEntry::~VPNListNetworkEntry() { |
| 140 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 140 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void VPNListNetworkEntry::NetworkIconChanged() { | 143 void VPNListNetworkEntry::NetworkIconChanged() { |
| 144 UpdateFromNetworkState( | 144 UpdateFromNetworkState( |
| 145 chromeos::NetworkHandler::Get()->network_state_handler()->GetNetworkState( | 145 chromeos::NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
| 146 service_path_)); | 146 service_path_)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void VPNListNetworkEntry::ButtonPressed(views::Button* sender, | 149 void VPNListNetworkEntry::ButtonPressed(views::Button* sender, |
| 150 const ui::Event& event) { | 150 const ui::Event& event) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 TrayPopupLabelButton::OnBoundsChanged(previous_bounds); | 183 TrayPopupLabelButton::OnBoundsChanged(previous_bounds); |
| 184 if (IsMouseHovered()) { | 184 if (IsMouseHovered()) { |
| 185 SetState(STATE_HOVERED); | 185 SetState(STATE_HOVERED); |
| 186 parent_->SetHoverHighlight(false); | 186 parent_->SetHoverHighlight(false); |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 void VPNListNetworkEntry::UpdateFromNetworkState( | 190 void VPNListNetworkEntry::UpdateFromNetworkState( |
| 191 const chromeos::NetworkState* network) { | 191 const chromeos::NetworkState* network) { |
| 192 if (network && network->IsConnectingState()) | 192 if (network && network->IsConnectingState()) |
| 193 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 193 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 194 else | 194 else |
| 195 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 195 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 196 | 196 |
| 197 if (!network) { | 197 if (!network) { |
| 198 // This is a transient state where the network has been removed already but | 198 // This is a transient state where the network has been removed already but |
| 199 // the network list in the UI has not been updated yet. | 199 // the network list in the UI has not been updated yet. |
| 200 return; | 200 return; |
| 201 } | 201 } |
| 202 | 202 |
| 203 RemoveAllChildViews(true); | 203 RemoveAllChildViews(true); |
| 204 disconnect_button_ = nullptr; | 204 disconnect_button_ = nullptr; |
| 205 | 205 |
| 206 AddIconAndLabel(ui::network_icon::GetImageForNetwork( | 206 AddIconAndLabel( |
| 207 network, ui::network_icon::ICON_TYPE_LIST), | 207 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST), |
| 208 ui::network_icon::GetLabelForNetwork( | 208 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST), |
| 209 network, ui::network_icon::ICON_TYPE_LIST), | 209 IsConnectedOrConnecting(network)); |
| 210 IsConnectedOrConnecting(network)); | |
| 211 if (IsConnectedOrConnecting(network)) { | 210 if (IsConnectedOrConnecting(network)) { |
| 212 disconnect_button_ = new DisconnectButton(this); | 211 disconnect_button_ = new DisconnectButton(this); |
| 213 AddChildView(disconnect_button_); | 212 AddChildView(disconnect_button_); |
| 214 SetBorder( | 213 SetBorder( |
| 215 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 3)); | 214 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 3)); |
| 216 } else { | 215 } else { |
| 217 SetBorder( | 216 SetBorder( |
| 218 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); | 217 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); |
| 219 } | 218 } |
| 220 | 219 |
| 221 // The icon and the disconnect button are always set to their preferred size. | 220 // The icon and the disconnect button are always set to their preferred size. |
| 222 // All remaining space is used for the network name. | 221 // All remaining space is used for the network name. |
| 223 views::BoxLayout* layout = new views::BoxLayout( | 222 views::BoxLayout* layout = new views::BoxLayout( |
| 224 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems); | 223 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems); |
| 225 SetLayoutManager(layout); | 224 SetLayoutManager(layout); |
| 226 layout->SetDefaultFlex(0); | 225 layout->SetDefaultFlex(0); |
| 227 layout->SetFlexForView(text_label(), 1); | 226 layout->SetFlexForView(text_label(), 1); |
| 228 Layout(); | 227 Layout(); |
| 229 } | 228 } |
| 230 | 229 |
| 231 } // namespace | 230 } // namespace |
| 232 | 231 |
| 233 VPNListView::VPNListView(ui::NetworkListDelegate* delegate) | 232 VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) { |
| 234 : delegate_(delegate) { | |
| 235 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this); | 233 WmShell::Get()->system_tray_delegate()->GetVPNDelegate()->AddObserver(this); |
| 236 } | 234 } |
| 237 | 235 |
| 238 VPNListView::~VPNListView() { | 236 VPNListView::~VPNListView() { |
| 239 // We need the check as on shell destruction, the delegate is destroyed first. | 237 // We need the check as on shell destruction, the delegate is destroyed first. |
| 240 SystemTrayDelegate* const system_tray_delegate = | 238 SystemTrayDelegate* const system_tray_delegate = |
| 241 WmShell::Get()->system_tray_delegate(); | 239 WmShell::Get()->system_tray_delegate(); |
| 242 if (system_tray_delegate) { | 240 if (system_tray_delegate) { |
| 243 VPNDelegate* const vpn_delegate = system_tray_delegate->GetVPNDelegate(); | 241 VPNDelegate* const vpn_delegate = system_tray_delegate->GetVPNDelegate(); |
| 244 if (vpn_delegate) | 242 if (vpn_delegate) |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 408 } |
| 411 } | 409 } |
| 412 | 410 |
| 413 // Add providers without any configured networks, in the order that the | 411 // Add providers without any configured networks, in the order that the |
| 414 // providers were returned by the extensions system. | 412 // providers were returned by the extensions system. |
| 415 for (const VPNProvider& provider : providers) | 413 for (const VPNProvider& provider : providers) |
| 416 AddProviderAndNetworks(provider.key, provider.name, networks); | 414 AddProviderAndNetworks(provider.key, provider.name, networks); |
| 417 } | 415 } |
| 418 | 416 |
| 419 } // namespace ash | 417 } // namespace ash |
| OLD | NEW |