OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/network_list.h" | 5 #include "ash/system/network/network_list.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <memory> |
8 | 8 |
9 #include "ash/shell.h" | |
10 #include "ash/shell_port.h" | |
9 #include "ash/strings/grit/ash_strings.h" | 11 #include "ash/strings/grit/ash_strings.h" |
10 #include "ash/system/network/network_icon.h" | 12 #include "ash/system/network/network_icon.h" |
11 #include "ash/system/network/network_icon_animation.h" | 13 #include "ash/system/network/network_icon_animation.h" |
12 #include "ash/system/network/network_list_delegate.h" | 14 #include "ash/system/network/network_info.h" |
15 #include "ash/system/network/network_state_list_detailed_view.h" | |
16 #include "ash/system/networking_config_delegate.h" | |
17 #include "ash/system/tray/fixed_sized_image_view.h" | |
18 #include "ash/system/tray/hover_highlight_view.h" | |
13 #include "ash/system/tray/system_menu_button.h" | 19 #include "ash/system/tray/system_menu_button.h" |
20 #include "ash/system/tray/system_tray_controller.h" | |
21 #include "ash/system/tray/system_tray_delegate.h" | |
22 #include "ash/system/tray/throbber_view.h" | |
14 #include "ash/system/tray/tray_constants.h" | 23 #include "ash/system/tray/tray_constants.h" |
15 #include "ash/system/tray/tray_popup_item_style.h" | 24 #include "ash/system/tray/tray_popup_item_style.h" |
16 #include "ash/system/tray/tray_popup_utils.h" | 25 #include "ash/system/tray/tray_popup_utils.h" |
17 #include "ash/system/tray/tri_view.h" | 26 #include "ash/system/tray/tri_view.h" |
18 #include "base/memory/ptr_util.h" | 27 #include "base/memory/ptr_util.h" |
28 #include "base/strings/string16.h" | |
29 #include "base/strings/utf_string_conversions.h" | |
19 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
20 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 31 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
21 #include "chromeos/dbus/power_manager_client.h" | 32 #include "chromeos/dbus/power_manager_client.h" |
22 #include "chromeos/login/login_state.h" | 33 #include "chromeos/login/login_state.h" |
23 #include "chromeos/network/managed_network_configuration_handler.h" | 34 #include "chromeos/network/managed_network_configuration_handler.h" |
24 #include "chromeos/network/network_state.h" | 35 #include "chromeos/network/network_state.h" |
25 #include "chromeos/network/network_state_handler.h" | 36 #include "chromeos/network/network_state_handler.h" |
26 #include "chromeos/network/network_state_handler_observer.h" | 37 #include "chromeos/network/network_state_handler_observer.h" |
27 #include "chromeos/network/proxy/ui_proxy_config_service.h" | 38 #include "chromeos/network/proxy/ui_proxy_config_service.h" |
28 #include "components/device_event_log/device_event_log.h" | 39 #include "components/device_event_log/device_event_log.h" |
40 #include "third_party/skia/include/core/SkColor.h" | |
29 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
31 #include "ui/gfx/color_palette.h" | 43 #include "ui/gfx/color_palette.h" |
32 #include "ui/gfx/font.h" | 44 #include "ui/gfx/font.h" |
45 #include "ui/gfx/image/image_skia.h" | |
33 #include "ui/gfx/paint_vector_icon.h" | 46 #include "ui/gfx/paint_vector_icon.h" |
47 #include "ui/gfx/text_constants.h" | |
34 #include "ui/views/background.h" | 48 #include "ui/views/background.h" |
49 #include "ui/views/border.h" | |
35 #include "ui/views/controls/button/toggle_button.h" | 50 #include "ui/views/controls/button/toggle_button.h" |
36 #include "ui/views/controls/image_view.h" | 51 #include "ui/views/controls/image_view.h" |
37 #include "ui/views/controls/label.h" | 52 #include "ui/views/controls/label.h" |
38 #include "ui/views/controls/separator.h" | 53 #include "ui/views/controls/separator.h" |
39 #include "ui/views/layout/box_layout.h" | 54 #include "ui/views/layout/box_layout.h" |
40 #include "ui/views/layout/fill_layout.h" | 55 #include "ui/views/layout/fill_layout.h" |
41 #include "ui/views/painter.h" | 56 #include "ui/views/painter.h" |
42 #include "ui/views/view.h" | 57 #include "ui/views/view.h" |
43 | 58 |
44 using chromeos::LoginState; | 59 using chromeos::LoginState; |
(...skipping 21 matching lines...) Expand all Loading... | |
66 global_network_config->GetBooleanWithoutPathExpansion( | 81 global_network_config->GetBooleanWithoutPathExpansion( |
67 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, | 82 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, |
68 &policy_prohibites_unmanaged); | 83 &policy_prohibites_unmanaged); |
69 } | 84 } |
70 if (!policy_prohibites_unmanaged) | 85 if (!policy_prohibites_unmanaged) |
71 return false; | 86 return false; |
72 return !managed_configuration_handler->FindPolicyByGuidAndProfile( | 87 return !managed_configuration_handler->FindPolicyByGuidAndProfile( |
73 network->guid(), network->profile_path()); | 88 network->guid(), network->profile_path()); |
74 } | 89 } |
75 | 90 |
91 // TODO(varkha|mohsen): Consolidate with a similar method in tray_bluetooth.cc. | |
tdanderson
2017/04/28 16:36:20
Can you please reference crbug.com/686924 here?
mohsen
2017/04/28 21:51:32
Done.
| |
92 void SetupConnectedItem(HoverHighlightView* container, | |
93 const base::string16& text, | |
94 const gfx::ImageSkia& image) { | |
95 container->AddIconAndLabels( | |
96 image, text, | |
97 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); | |
98 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); | |
99 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); | |
100 style.SetupLabel(container->sub_text_label()); | |
101 } | |
102 | |
103 // TODO(varkha|mohsen): Consolidate with a similar method in tray_bluetooth.cc. | |
104 void SetupConnectingItem(HoverHighlightView* container, | |
105 const base::string16& text, | |
106 const gfx::ImageSkia& image) { | |
107 container->AddIconAndLabels( | |
108 image, text, | |
109 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); | |
110 ThrobberView* throbber = new ThrobberView; | |
111 throbber->Start(); | |
112 container->AddRightView(throbber); | |
113 } | |
114 | |
76 } // namespace | 115 } // namespace |
77 | 116 |
78 // A header row for sections in network detailed view which contains a title and | 117 // A header row for sections in network detailed view which contains a title and |
79 // a toggle button to turn on/off the section. Subclasses are given the | 118 // a toggle button to turn on/off the section. Subclasses are given the |
80 // opportunity to add extra buttons before the toggle button is added. | 119 // opportunity to add extra buttons before the toggle button is added. |
81 class NetworkListView::SectionHeaderRowView : public views::View, | 120 class NetworkListView::SectionHeaderRowView : public views::View, |
82 public views::ButtonListener { | 121 public views::ButtonListener { |
83 public: | 122 public: |
84 explicit SectionHeaderRowView(int title_id) | 123 explicit SectionHeaderRowView(int title_id) |
85 : title_id_(title_id), | 124 : title_id_(title_id), |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 void OnToggleToggled(bool is_on) override { | 242 void OnToggleToggled(bool is_on) override { |
204 // TODO (hansberry): Persist toggle to settings/preferences. | 243 // TODO (hansberry): Persist toggle to settings/preferences. |
205 } | 244 } |
206 | 245 |
207 private: | 246 private: |
208 DISALLOW_COPY_AND_ASSIGN(TetherHeaderRowView); | 247 DISALLOW_COPY_AND_ASSIGN(TetherHeaderRowView); |
209 }; | 248 }; |
210 | 249 |
211 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { | 250 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { |
212 public: | 251 public: |
213 explicit WifiHeaderRowView(NetworkListDelegate* network_list_delegate) | 252 WifiHeaderRowView() |
214 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), | 253 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), |
215 network_list_delegate_(network_list_delegate), | |
216 join_(nullptr) {} | 254 join_(nullptr) {} |
217 | 255 |
218 ~WifiHeaderRowView() override {} | 256 ~WifiHeaderRowView() override {} |
219 | 257 |
220 void SetIsOn(bool enabled) override { | 258 void SetIsOn(bool enabled) override { |
221 join_->SetEnabled(enabled); | 259 join_->SetEnabled(enabled); |
222 SectionHeaderRowView::SetIsOn(enabled); | 260 SectionHeaderRowView::SetIsOn(enabled); |
223 } | 261 } |
224 | 262 |
225 const char* GetClassName() const override { return "WifiHeaderRowView"; } | 263 const char* GetClassName() const override { return "WifiHeaderRowView"; } |
(...skipping 19 matching lines...) Expand all Loading... | |
245 join_ = new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | 283 join_ = new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, |
246 normal_image, disabled_image, | 284 normal_image, disabled_image, |
247 IDS_ASH_STATUS_TRAY_OTHER_WIFI); | 285 IDS_ASH_STATUS_TRAY_OTHER_WIFI); |
248 join_->SetInkDropColor(prominent_color); | 286 join_->SetInkDropColor(prominent_color); |
249 join_->SetEnabled(enabled); | 287 join_->SetEnabled(enabled); |
250 container()->AddView(TriView::Container::END, join_); | 288 container()->AddView(TriView::Container::END, join_); |
251 } | 289 } |
252 | 290 |
253 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 291 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
254 if (sender == join_) { | 292 if (sender == join_) { |
255 network_list_delegate_->OnOtherWifiClicked(); | 293 ShellPort::Get()->RecordUserMetricsAction( |
294 UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED); | |
295 Shell::Get()->system_tray_controller()->ShowNetworkCreate( | |
296 shill::kTypeWifi); | |
256 return; | 297 return; |
257 } | 298 } |
258 SectionHeaderRowView::ButtonPressed(sender, event); | 299 SectionHeaderRowView::ButtonPressed(sender, event); |
259 } | 300 } |
260 | 301 |
261 private: | 302 private: |
262 // Full opacity for badge. | 303 // Full opacity for badge. |
263 static constexpr int kJoinBadgeAlpha = 0xFF; | 304 static constexpr int kJoinBadgeAlpha = 0xFF; |
264 | 305 |
265 // .30 opacity for icon. | 306 // .30 opacity for icon. |
266 static constexpr int kJoinIconAlpha = 0x4D; | 307 static constexpr int kJoinIconAlpha = 0x4D; |
267 | 308 |
268 // .38 opacity for disabled badge. | 309 // .38 opacity for disabled badge. |
269 static constexpr int kDisabledJoinBadgeAlpha = 0x61; | 310 static constexpr int kDisabledJoinBadgeAlpha = 0x61; |
270 | 311 |
271 // .30 * .38 opacity for disabled icon. | 312 // .30 * .38 opacity for disabled icon. |
272 static constexpr int kDisabledJoinIconAlpha = 0x1D; | 313 static constexpr int kDisabledJoinIconAlpha = 0x1D; |
273 | 314 |
274 NetworkListDelegate* network_list_delegate_; | |
275 | |
276 // A button to invoke "Join Wi-Fi network" dialog. | 315 // A button to invoke "Join Wi-Fi network" dialog. |
277 SystemMenuButton* join_; | 316 SystemMenuButton* join_; |
278 | 317 |
279 DISALLOW_COPY_AND_ASSIGN(WifiHeaderRowView); | 318 DISALLOW_COPY_AND_ASSIGN(WifiHeaderRowView); |
280 }; | 319 }; |
281 | 320 |
282 } // namespace | 321 } // namespace |
283 | 322 |
284 // NetworkListView: | 323 // NetworkListView: |
285 | 324 |
286 NetworkListView::NetworkListView(NetworkListDelegate* delegate) | 325 NetworkListView::NetworkListView( |
287 : needs_relayout_(false), | 326 tray::NetworkStateListDetailedView* detailed_view) |
288 delegate_(delegate), | 327 : NetworkListViewBase(detailed_view), |
328 needs_relayout_(false), | |
289 no_wifi_networks_view_(nullptr), | 329 no_wifi_networks_view_(nullptr), |
290 no_cellular_networks_view_(nullptr), | 330 no_cellular_networks_view_(nullptr), |
291 cellular_header_view_(nullptr), | 331 cellular_header_view_(nullptr), |
292 tether_header_view_(nullptr), | 332 tether_header_view_(nullptr), |
293 wifi_header_view_(nullptr), | 333 wifi_header_view_(nullptr), |
294 cellular_separator_view_(nullptr), | 334 cellular_separator_view_(nullptr), |
295 tether_separator_view_(nullptr), | 335 tether_separator_view_(nullptr), |
296 wifi_separator_view_(nullptr), | 336 wifi_separator_view_(nullptr), |
297 connection_warning_(nullptr) { | 337 connection_warning_(nullptr) {} |
298 CHECK(delegate_); | |
299 } | |
300 | 338 |
301 NetworkListView::~NetworkListView() { | 339 NetworkListView::~NetworkListView() { |
302 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 340 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
303 } | 341 } |
304 | 342 |
305 void NetworkListView::Update() { | 343 void NetworkListView::Update() { |
306 CHECK(container()); | 344 CHECK(container()); |
307 | 345 |
308 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 346 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
309 | 347 |
(...skipping 28 matching lines...) Expand all Loading... | |
338 void NetworkListView::UpdateNetworks( | 376 void NetworkListView::UpdateNetworks( |
339 const NetworkStateHandler::NetworkStateList& networks) { | 377 const NetworkStateHandler::NetworkStateList& networks) { |
340 SCOPED_NET_LOG_IF_SLOW(); | 378 SCOPED_NET_LOG_IF_SLOW(); |
341 // |network_list_| contains all the info and is going to be cleared and | 379 // |network_list_| contains all the info and is going to be cleared and |
342 // recreated. Save them to |last_network_info_map_|. | 380 // recreated. Save them to |last_network_info_map_|. |
343 last_network_info_map_.clear(); | 381 last_network_info_map_.clear(); |
344 for (auto& info : network_list_) | 382 for (auto& info : network_list_) |
345 last_network_info_map_[info->guid] = std::move(info); | 383 last_network_info_map_[info->guid] = std::move(info); |
346 | 384 |
347 network_list_.clear(); | 385 network_list_.clear(); |
348 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); | |
349 for (const auto* network : networks) { | 386 for (const auto* network : networks) { |
350 if (!pattern.MatchesType(network->type())) | 387 if (!NetworkTypePattern::NonVirtual().MatchesType(network->type())) |
351 continue; | 388 continue; |
352 | 389 |
353 // Do not add Wi-Fi networks that are associated with a Tether network. | 390 // Do not add Wi-Fi networks that are associated with a Tether network. |
354 if (NetworkTypePattern::WiFi().MatchesType(network->type()) && | 391 if (NetworkTypePattern::WiFi().MatchesType(network->type()) && |
355 !network->tether_guid().empty()) | 392 !network->tether_guid().empty()) |
356 continue; | 393 continue; |
357 | 394 |
358 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->guid())); | 395 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->guid())); |
359 } | 396 } |
360 } | 397 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 return; | 504 return; |
468 | 505 |
469 views::View* selected_view = nullptr; | 506 views::View* selected_view = nullptr; |
470 for (const auto& iter : network_guid_map_) { | 507 for (const auto& iter : network_guid_map_) { |
471 if (iter.second->IsMouseHovered()) { | 508 if (iter.second->IsMouseHovered()) { |
472 selected_view = iter.second; | 509 selected_view = iter.second; |
473 break; | 510 break; |
474 } | 511 } |
475 } | 512 } |
476 container()->SizeToPreferredSize(); | 513 container()->SizeToPreferredSize(); |
477 delegate_->RelayoutScrollList(); | 514 detailed_view()->RelayoutScrollList(); |
478 if (selected_view) | 515 if (selected_view) |
479 container()->ScrollRectToVisible(selected_view->bounds()); | 516 container()->ScrollRectToVisible(selected_view->bounds()); |
480 } | 517 } |
481 | 518 |
482 std::unique_ptr<std::set<std::string>> | 519 std::unique_ptr<std::set<std::string>> |
483 NetworkListView::UpdateNetworkListEntries() { | 520 NetworkListView::UpdateNetworkListEntries() { |
484 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 521 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
485 | 522 |
486 // Keep an index where the next child should be inserted. | 523 // Keep an index where the next child should be inserted. |
487 int index = 0; | 524 int index = 0; |
(...skipping 10 matching lines...) Expand all Loading... | |
498 if (!connection_warning_) | 535 if (!connection_warning_) |
499 connection_warning_ = CreateConnectionWarning(); | 536 connection_warning_ = CreateConnectionWarning(); |
500 PlaceViewAtIndex(connection_warning_, index++); | 537 PlaceViewAtIndex(connection_warning_, index++); |
501 } | 538 } |
502 | 539 |
503 // First add high-priority networks (not Wi-Fi nor cellular). | 540 // First add high-priority networks (not Wi-Fi nor cellular). |
504 std::unique_ptr<std::set<std::string>> new_guids = | 541 std::unique_ptr<std::set<std::string>> new_guids = |
505 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); | 542 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); |
506 index += new_guids->size(); | 543 index += new_guids->size(); |
507 | 544 |
508 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); | 545 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { |
509 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { | 546 index = UpdateSectionHeaderRow( |
510 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | 547 NetworkTypePattern::Cellular(), |
511 index = UpdateSectionHeaderRow( | 548 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, |
512 NetworkTypePattern::Cellular(), | 549 &cellular_header_view_, &cellular_separator_view_); |
513 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, | 550 } |
514 &cellular_header_view_, &cellular_separator_view_); | |
515 } | |
516 | 551 |
517 // Cellular initializing. | 552 // Cellular initializing. |
518 int message_id = network_icon::GetCellularUninitializedMsg(); | 553 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); |
519 if (!message_id && | 554 if (!cellular_message_id && |
520 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && | 555 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && |
521 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { | 556 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { |
522 message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; | 557 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; |
523 } | 558 } |
524 UpdateInfoLabel(message_id, index, &no_cellular_networks_view_); | 559 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); |
525 if (message_id) | 560 if (cellular_message_id) |
526 ++index; | 561 ++index; |
527 | 562 |
528 // Add cellular networks. | 563 // Add cellular networks. |
529 std::unique_ptr<std::set<std::string>> new_cellular_guids = | 564 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
530 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 565 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); |
531 index += new_cellular_guids->size(); | 566 index += new_cellular_guids->size(); |
532 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | 567 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); |
533 } | |
534 | 568 |
535 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing | 569 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing |
536 // it to include Tether. See crbug.com/693647. | 570 // it to include Tether. See crbug.com/693647. |
537 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { | 571 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { |
538 index = UpdateSectionHeaderRow( | 572 index = UpdateSectionHeaderRow( |
539 NetworkTypePattern::Tether(), | 573 NetworkTypePattern::Tether(), |
540 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index, | 574 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index, |
541 &tether_header_view_, &tether_separator_view_); | 575 &tether_header_view_, &tether_separator_view_); |
542 | 576 |
543 // TODO (hansberry): Should a message similar to | 577 // TODO (hansberry): Should a message similar to |
544 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology | 578 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology is |
545 // is enabled but no networks are around? | 579 // enabled but no networks are around? |
546 | 580 |
547 // Add Tether networks. | 581 // Add Tether networks. |
548 std::unique_ptr<std::set<std::string>> new_tether_guids = | 582 std::unique_ptr<std::set<std::string>> new_tether_guids = |
549 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); | 583 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); |
550 index += new_tether_guids->size(); | 584 index += new_tether_guids->size(); |
551 new_guids->insert(new_tether_guids->begin(), new_tether_guids->end()); | 585 new_guids->insert(new_tether_guids->begin(), new_tether_guids->end()); |
552 } | 586 } |
553 | 587 |
554 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { | 588 index = UpdateSectionHeaderRow( |
555 index = UpdateSectionHeaderRow( | 589 NetworkTypePattern::WiFi(), |
556 NetworkTypePattern::WiFi(), | 590 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
557 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 591 &wifi_header_view_, &wifi_separator_view_); |
558 &wifi_header_view_, &wifi_separator_view_); | |
559 | 592 |
560 // "Wifi Enabled / Disabled". | 593 // "Wifi Enabled / Disabled". |
561 int message_id = 0; | 594 int wifi_message_id = 0; |
562 if (network_list_.empty()) { | 595 if (network_list_.empty()) { |
563 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 596 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
564 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED | 597 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
565 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; | 598 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; |
566 } | 599 } |
567 UpdateInfoLabel(message_id, index, &no_wifi_networks_view_); | 600 UpdateInfoLabel(wifi_message_id, index, &no_wifi_networks_view_); |
568 if (message_id) | 601 if (wifi_message_id) |
569 ++index; | 602 ++index; |
570 | 603 |
571 // Add Wi-Fi networks. | 604 // Add Wi-Fi networks. |
572 std::unique_ptr<std::set<std::string>> new_wifi_guids = | 605 std::unique_ptr<std::set<std::string>> new_wifi_guids = |
573 UpdateNetworkChildren(NetworkInfo::Type::WIFI, index); | 606 UpdateNetworkChildren(NetworkInfo::Type::WIFI, index); |
574 index += new_wifi_guids->size(); | 607 index += new_wifi_guids->size(); |
575 new_guids->insert(new_wifi_guids->begin(), new_wifi_guids->end()); | 608 new_guids->insert(new_wifi_guids->begin(), new_wifi_guids->end()); |
576 } | |
577 | 609 |
578 // No networks or other messages (fallback). | 610 // No networks or other messages (fallback). |
579 if (index == 0) { | 611 if (index == 0) { |
580 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, | 612 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, |
581 &no_wifi_networks_view_); | 613 &no_wifi_networks_view_); |
582 } | 614 } |
583 | 615 |
584 return new_guids; | 616 return new_guids; |
585 } | 617 } |
586 | 618 |
619 views::View* NetworkListView::CreateViewForNetwork(const NetworkInfo& info) { | |
620 HoverHighlightView* container = new HoverHighlightView(detailed_view()); | |
621 if (info.connected) | |
622 SetupConnectedItem(container, info.label, info.image); | |
623 else if (info.connecting) | |
624 SetupConnectingItem(container, info.label, info.image); | |
625 else | |
626 container->AddIconAndLabel(info.image, info.label); | |
627 container->SetTooltipText(info.tooltip); | |
628 views::View* controlled_icon = CreateControlledByExtensionView(info); | |
629 if (controlled_icon) | |
630 container->AddChildView(controlled_icon); | |
631 return container; | |
632 } | |
633 | |
634 void NetworkListView::UpdateViewForNetwork(views::View* view, | |
635 const NetworkInfo& info) { | |
636 HoverHighlightView* container = static_cast<HoverHighlightView*>(view); | |
tdanderson
2017/04/28 16:36:20
WDYT of having CreateViewForNetwork() return a Hov
mohsen
2017/04/28 21:51:32
Sure. Done.
| |
637 DCHECK(!container->has_children()); | |
638 if (info.connected) | |
639 SetupConnectedItem(container, info.label, info.image); | |
640 else if (info.connecting) | |
641 SetupConnectingItem(container, info.label, info.image); | |
642 else | |
643 container->AddIconAndLabel(info.image, info.label); | |
644 views::View* controlled_icon = CreateControlledByExtensionView(info); | |
645 container->SetTooltipText(info.tooltip); | |
646 if (controlled_icon) | |
647 view->AddChildView(controlled_icon); | |
648 } | |
649 | |
650 views::View* NetworkListView::CreateControlledByExtensionView( | |
651 const NetworkInfo& info) { | |
652 NetworkingConfigDelegate* networking_config_delegate = | |
653 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate(); | |
654 if (!networking_config_delegate) | |
655 return nullptr; | |
656 std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo> | |
657 extension_info = | |
658 networking_config_delegate->LookUpExtensionForNetwork(info.guid); | |
659 if (!extension_info) | |
660 return nullptr; | |
661 | |
662 // Get the tooltip text. | |
663 base::string16 tooltip_text = l10n_util::GetStringFUTF16( | |
664 IDS_ASH_STATUS_TRAY_EXTENSION_CONTROLLED_WIFI, | |
665 base::UTF8ToUTF16(extension_info->extension_name)); | |
666 | |
667 views::ImageView* controlled_icon = | |
668 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); | |
669 | |
670 controlled_icon->SetImage( | |
671 gfx::CreateVectorIcon(kCaptivePortalIcon, kMenuIconColor)); | |
672 controlled_icon->SetTooltipText(tooltip_text); | |
673 return controlled_icon; | |
674 } | |
675 | |
587 std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren( | 676 std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren( |
588 NetworkInfo::Type type, | 677 NetworkInfo::Type type, |
589 int index) { | 678 int index) { |
590 std::unique_ptr<std::set<std::string>> new_guids(new std::set<std::string>); | 679 std::unique_ptr<std::set<std::string>> new_guids(new std::set<std::string>); |
591 for (const auto& info : network_list_) { | 680 for (const auto& info : network_list_) { |
592 if (info->type != type) | 681 if (info->type != type) |
593 continue; | 682 continue; |
594 UpdateNetworkChild(index++, info.get()); | 683 UpdateNetworkChild(index++, info.get()); |
595 new_guids->insert(info->guid); | 684 new_guids->insert(info->guid); |
596 } | 685 } |
597 return new_guids; | 686 return new_guids; |
598 } | 687 } |
599 | 688 |
600 void NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { | 689 void NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { |
601 views::View* network_view = nullptr; | 690 views::View* network_view = nullptr; |
602 NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid); | 691 NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid); |
603 if (found == network_guid_map_.end()) { | 692 if (found == network_guid_map_.end()) { |
604 network_view = delegate_->CreateViewForNetwork(*info); | 693 network_view = CreateViewForNetwork(*info); |
605 } else { | 694 } else { |
606 network_view = found->second; | 695 network_view = found->second; |
607 if (NeedUpdateViewForNetwork(*info)) { | 696 if (NeedUpdateViewForNetwork(*info)) { |
608 network_view->RemoveAllChildViews(true); | 697 network_view->RemoveAllChildViews(true); |
609 delegate_->UpdateViewForNetwork(network_view, *info); | 698 UpdateViewForNetwork(network_view, *info); |
610 network_view->Layout(); | 699 network_view->Layout(); |
611 network_view->SchedulePaint(); | 700 network_view->SchedulePaint(); |
612 } | 701 } |
613 } | 702 } |
614 PlaceViewAtIndex(network_view, index); | 703 PlaceViewAtIndex(network_view, index); |
615 if (info->disable) | 704 if (info->disable) |
616 network_view->SetEnabled(false); | 705 network_view->SetEnabled(false); |
617 network_map_[network_view] = info->guid; | 706 network_map_[network_view] = info->guid; |
618 network_guid_map_[info->guid] = network_view; | 707 network_guid_map_[info->guid] = network_view; |
619 } | 708 } |
(...skipping 16 matching lines...) Expand all Loading... | |
636 if (!message_id) { | 725 if (!message_id) { |
637 if (label) { | 726 if (label) { |
638 needs_relayout_ = true; | 727 needs_relayout_ = true; |
639 delete label; | 728 delete label; |
640 *label_ptr = nullptr; | 729 *label_ptr = nullptr; |
641 } | 730 } |
642 return; | 731 return; |
643 } | 732 } |
644 base::string16 text = | 733 base::string16 text = |
645 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); | 734 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); |
646 if (!label) | 735 if (!label) { |
647 label = delegate_->CreateInfoLabel(); | 736 label = new views::Label(); |
tdanderson
2017/04/28 16:36:20
Can you add a TODO(mohsen) here saying this should
mohsen
2017/04/28 21:51:32
Done.
| |
737 label->SetBorder(views::CreateEmptyBorder( | |
738 kTrayPopupPaddingBetweenItems, kTrayPopupPaddingHorizontal, | |
739 kTrayPopupPaddingBetweenItems, 0)); | |
740 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
741 label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0)); | |
742 } | |
648 label->SetText(text); | 743 label->SetText(text); |
649 PlaceViewAtIndex(label, insertion_index); | 744 PlaceViewAtIndex(label, insertion_index); |
650 *label_ptr = label; | 745 *label_ptr = label; |
651 } | 746 } |
652 | 747 |
653 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, | 748 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, |
654 bool enabled, | 749 bool enabled, |
655 int child_index, | 750 int child_index, |
656 SectionHeaderRowView** view, | 751 SectionHeaderRowView** view, |
657 views::Separator** separator_view) { | 752 views::Separator** separator_view) { |
658 if (!*view) { | 753 if (!*view) { |
659 if (pattern.Equals(NetworkTypePattern::Cellular())) | 754 if (pattern.Equals(NetworkTypePattern::Cellular())) |
660 *view = new CellularHeaderRowView(); | 755 *view = new CellularHeaderRowView(); |
661 else if (pattern.Equals(NetworkTypePattern::Tether())) | 756 else if (pattern.Equals(NetworkTypePattern::Tether())) |
662 *view = new TetherHeaderRowView(); | 757 *view = new TetherHeaderRowView(); |
663 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 758 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
664 *view = new WifiHeaderRowView(delegate_); | 759 *view = new WifiHeaderRowView(); |
665 else | 760 else |
666 NOTREACHED(); | 761 NOTREACHED(); |
667 (*view)->Init(enabled); | 762 (*view)->Init(enabled); |
668 } | 763 } |
669 // Show or hide a separator above the header. The separator should only be | 764 // Show or hide a separator above the header. The separator should only be |
670 // visible when the header row is not at the top of the list. | 765 // visible when the header row is not at the top of the list. |
671 if (child_index > 0) { | 766 if (child_index > 0) { |
672 if (!*separator_view) | 767 if (!*separator_view) |
673 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); | 768 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); |
674 PlaceViewAtIndex(*separator_view, child_index++); | 769 PlaceViewAtIndex(*separator_view, child_index++); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | 817 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
723 style.SetupLabel(label); | 818 style.SetupLabel(label); |
724 connection_warning->AddView(TriView::Container::CENTER, label); | 819 connection_warning->AddView(TriView::Container::CENTER, label); |
725 | 820 |
726 // Nothing to the right of the text. | 821 // Nothing to the right of the text. |
727 connection_warning->SetContainerVisible(TriView::Container::END, false); | 822 connection_warning->SetContainerVisible(TriView::Container::END, false); |
728 return connection_warning; | 823 return connection_warning; |
729 } | 824 } |
730 | 825 |
731 } // namespace ash | 826 } // namespace ash |
OLD | NEW |