| OLD | NEW |
| 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/system/network/tray_network.h" | 5 #include "ash/system/network/tray_network.h" |
| 6 | 6 |
| 7 #include "ash/shelf/wm_shelf_util.h" | 7 #include "ash/shelf/wm_shelf_util.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_port.h" | 9 #include "ash/shell_port.h" |
| 10 #include "ash/strings/grit/ash_strings.h" | 10 #include "ash/strings/grit/ash_strings.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ash/system/tray/tray_item_view.h" | 21 #include "ash/system/tray/tray_item_view.h" |
| 22 #include "ash/system/tray/tray_popup_item_style.h" | 22 #include "ash/system/tray/tray_popup_item_style.h" |
| 23 #include "ash/system/tray/tray_utils.h" | 23 #include "ash/system/tray/tray_utils.h" |
| 24 #include "base/command_line.h" | 24 #include "base/command_line.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "chromeos/network/network_state.h" | 26 #include "chromeos/network/network_state.h" |
| 27 #include "chromeos/network/network_state_handler.h" | 27 #include "chromeos/network/network_state_handler.h" |
| 28 #include "third_party/cros_system_api/dbus/service_constants.h" | 28 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 29 #include "ui/accessibility/ax_node_data.h" | 29 #include "ui/accessibility/ax_node_data.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/gfx/image/image_skia_operations.h" |
| 31 #include "ui/views/controls/image_view.h" | 32 #include "ui/views/controls/image_view.h" |
| 32 #include "ui/views/controls/link.h" | 33 #include "ui/views/controls/link.h" |
| 33 #include "ui/views/controls/link_listener.h" | 34 #include "ui/views/controls/link_listener.h" |
| 34 #include "ui/views/layout/box_layout.h" | 35 #include "ui/views/layout/box_layout.h" |
| 35 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 36 | 37 |
| 37 using chromeos::NetworkHandler; | 38 using chromeos::NetworkHandler; |
| 38 using chromeos::NetworkState; | 39 using chromeos::NetworkState; |
| 39 using chromeos::NetworkStateHandler; | 40 using chromeos::NetworkStateHandler; |
| 40 using chromeos::NetworkTypePattern; | 41 using chromeos::NetworkTypePattern; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 135 } |
| 135 | 136 |
| 136 ~NetworkDefaultView() override { | 137 ~NetworkDefaultView() override { |
| 137 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 138 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 138 } | 139 } |
| 139 | 140 |
| 140 void Update() { | 141 void Update() { |
| 141 gfx::ImageSkia image; | 142 gfx::ImageSkia image; |
| 142 base::string16 label; | 143 base::string16 label; |
| 143 bool animating = false; | 144 bool animating = false; |
| 144 // TODO(bruthig): Update the image to use the proper color. See | |
| 145 // https://crbug.com/632027. | |
| 146 network_icon::GetDefaultNetworkImageAndLabel( | 145 network_icon::GetDefaultNetworkImageAndLabel( |
| 147 network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label, &animating); | 146 network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label, &animating); |
| 147 // We use the inactive icon alpha only if there is no active network and |
| 148 // wifi is disabled. |
| 149 if (!IsActive() && |
| 150 !NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( |
| 151 NetworkTypePattern::WiFi())) { |
| 152 image = gfx::ImageSkiaOperations::CreateTransparentImage( |
| 153 image, TrayPopupItemStyle::kInactiveIconAlpha); |
| 154 } |
| 155 |
| 148 if (animating) | 156 if (animating) |
| 149 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 157 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 150 else | 158 else |
| 151 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 159 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 152 SetImage(image); | 160 SetImage(image); |
| 153 SetLabel(label); | 161 SetLabel(label); |
| 154 SetAccessibleName(label); | 162 SetAccessibleName(label); |
| 155 UpdateStyle(); | 163 UpdateStyle(); |
| 156 } | 164 } |
| 157 | 165 |
| 158 // network_icon::AnimationObserver | 166 // network_icon::AnimationObserver |
| 159 void NetworkIconChanged() override { Update(); } | 167 void NetworkIconChanged() override { Update(); } |
| 160 | 168 |
| 161 protected: | 169 protected: |
| 162 // TrayItemMore: | 170 // TrayItemMore: |
| 163 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override { | 171 std::unique_ptr<TrayPopupItemStyle> HandleCreateStyle() const override { |
| 164 std::unique_ptr<TrayPopupItemStyle> style = | 172 std::unique_ptr<TrayPopupItemStyle> style = |
| 165 TrayItemMore::HandleCreateStyle(); | 173 TrayItemMore::HandleCreateStyle(); |
| 166 style->set_color_style(GetConnectedNetwork() != nullptr | 174 style->set_color_style(IsActive() |
| 167 ? TrayPopupItemStyle::ColorStyle::ACTIVE | 175 ? TrayPopupItemStyle::ColorStyle::ACTIVE |
| 168 : TrayPopupItemStyle::ColorStyle::INACTIVE); | 176 : TrayPopupItemStyle::ColorStyle::INACTIVE); |
| 169 return style; | 177 return style; |
| 170 } | 178 } |
| 171 | 179 |
| 180 // Determines whether to use the ACTIVE or INACTIVE text style. |
| 181 bool IsActive() const { return GetConnectedNetwork() != nullptr; } |
| 182 |
| 172 private: | 183 private: |
| 173 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); | 184 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); |
| 174 }; | 185 }; |
| 175 | 186 |
| 176 class NetworkWifiDetailedView : public NetworkDetailedView { | 187 class NetworkWifiDetailedView : public NetworkDetailedView { |
| 177 public: | 188 public: |
| 178 explicit NetworkWifiDetailedView(SystemTrayItem* owner) | 189 explicit NetworkWifiDetailedView(SystemTrayItem* owner) |
| 179 : NetworkDetailedView(owner) {} | 190 : NetworkDetailedView(owner) {} |
| 180 | 191 |
| 181 ~NetworkWifiDetailedView() override {} | 192 ~NetworkWifiDetailedView() override {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 197 box_layout->SetFlexForView(label_view_, 1); | 208 box_layout->SetFlexForView(label_view_, 1); |
| 198 | 209 |
| 199 Update(); | 210 Update(); |
| 200 } | 211 } |
| 201 | 212 |
| 202 NetworkDetailedView::DetailedViewType GetViewType() const override { | 213 NetworkDetailedView::DetailedViewType GetViewType() const override { |
| 203 return NetworkDetailedView::WIFI_VIEW; | 214 return NetworkDetailedView::WIFI_VIEW; |
| 204 } | 215 } |
| 205 | 216 |
| 206 void Update() override { | 217 void Update() override { |
| 207 bool wifi_enabled = | 218 const bool wifi_enabled = |
| 208 NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( | 219 NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( |
| 209 NetworkTypePattern::WiFi()); | 220 NetworkTypePattern::WiFi()); |
| 210 image_view_->SetImage( | 221 image_view_->SetImage( |
| 211 network_icon::GetBasicImageForWiFiNetwork(wifi_enabled)); | 222 network_icon::GetImageForWiFiEnabledState(wifi_enabled)); |
| 212 | 223 |
| 213 const int string_id = wifi_enabled | 224 const int string_id = wifi_enabled |
| 214 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED | 225 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
| 215 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; | 226 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; |
| 216 label_view_->SetText(l10n_util::GetStringUTF16(string_id)); | 227 label_view_->SetText(l10n_util::GetStringUTF16(string_id)); |
| 217 } | 228 } |
| 218 | 229 |
| 219 private: | 230 private: |
| 220 views::ImageView* image_view_ = nullptr; | 231 views::ImageView* image_view_ = nullptr; |
| 221 views::Label* label_view_ = nullptr; | 232 views::Label* label_view_ = nullptr; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 void TrayNetwork::NetworkStateChanged() { | 323 void TrayNetwork::NetworkStateChanged() { |
| 313 if (tray_) | 324 if (tray_) |
| 314 tray_->UpdateNetworkStateHandlerIcon(); | 325 tray_->UpdateNetworkStateHandlerIcon(); |
| 315 if (default_) | 326 if (default_) |
| 316 default_->Update(); | 327 default_->Update(); |
| 317 if (detailed_) | 328 if (detailed_) |
| 318 detailed_->Update(); | 329 detailed_->Update(); |
| 319 } | 330 } |
| 320 | 331 |
| 321 } // namespace ash | 332 } // namespace ash |
| OLD | NEW |