OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_CHROMEOS_NETWORK_NETWORK_LIST_MD_H_ | |
6 #define UI_CHROMEOS_NETWORK_NETWORK_LIST_MD_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <set> | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "base/macros.h" | |
15 #include "chromeos/network/network_state_handler.h" | |
16 #include "ui/chromeos/network/network_icon_animation_observer.h" | |
17 #include "ui/chromeos/network/network_list_view_base.h" | |
18 #include "ui/chromeos/ui_chromeos_export.h" | |
19 #include "ui/gfx/image/image_skia.h" | |
20 #include "ui/views/controls/button/button.h" | |
21 | |
22 namespace views { | |
23 class Label; | |
24 class View; | |
25 } | |
26 | |
27 namespace ui { | |
28 | |
29 struct NetworkInfo; | |
30 class NetworkListDelegate; | |
31 | |
32 // A list of available networks of a given type. This class is used for all | |
33 // network types except VPNs. For VPNs, see the |VPNList| class. | |
34 class UI_CHROMEOS_EXPORT NetworkListViewMd | |
35 : public NetworkListViewBase, | |
36 public network_icon::AnimationObserver, | |
37 public views::ButtonListener { | |
38 public: | |
39 explicit NetworkListViewMd(NetworkListDelegate* delegate); | |
40 ~NetworkListViewMd() override; | |
41 | |
42 // NetworkListViewBase: | |
43 void Update() override; | |
44 bool IsNetworkEntry(views::View* view, | |
45 std::string* service_path) const override; | |
46 | |
47 private: | |
48 class WifiHeaderRowView; | |
49 | |
50 // Clears |network_list_| and adds to it |networks| that match |delegate_|'s | |
51 // network type pattern. | |
52 void UpdateNetworks( | |
53 const chromeos::NetworkStateHandler::NetworkStateList& networks); | |
54 | |
55 // Updates |network_list_| entries and sets |this| to observe network icon | |
56 // animations when any of the networks are in connecting state. | |
57 void UpdateNetworkIcons(); | |
58 | |
59 // Orders entries in |network_list_| such that higher priority network types | |
60 // are at the top of the list. | |
61 void OrderNetworks(); | |
62 | |
63 // Refreshes a list of child views, updates |network_map_| and | |
64 // |service_path_map_| and performs layout making sure selected view if any is | |
65 // scrolled into view. | |
66 void UpdateNetworkListInternal(); | |
67 | |
68 // Adds new or updates existing child views including header row and messages. | |
69 // Returns a set of service paths for the added network connections. | |
70 std::unique_ptr<std::set<std::string>> UpdateNetworkListEntries(); | |
71 | |
72 // Adds or updates child views representing the network connections when | |
73 // |is_wifi| is matching the attribute of a network connection starting at | |
74 // |child_index|. Returns a set of service paths for the added network | |
75 // connections. | |
76 std::unique_ptr<std::set<std::string>> UpdateNetworkChildren(bool is_wifi, | |
77 int child_index); | |
78 void UpdateNetworkChild(int index, const NetworkInfo* info); | |
79 | |
80 // Reorders children of |container()| as necessary placing |view| at |index|. | |
81 void PlaceViewAtIndex(views::View* view, int index); | |
82 | |
83 // Creates a Label with text specified by |message_id| and adds it to | |
84 // |container()| if necessary or updates the text and reorders the | |
85 // |container()| placing the label at |insertion_index|. When |message_id| is | |
86 // zero removes the |*label_ptr| from the |container()| and destroys it. | |
87 // |label_ptr| is an in / out parameter and is only modified if the Label is | |
88 // created or destroyed. | |
89 void UpdateInfoLabel(int message_id, | |
90 int insertion_index, | |
91 views::Label** label_ptr); | |
92 | |
93 // Creates a Wi-Fi header row |view| and adds it to |container()| if necessary | |
94 // and reorders the |container()| placing the |view| at |child_index|. | |
95 void UpdateWifiHeaderRow(bool enabled, | |
96 int child_index, | |
97 WifiHeaderRowView** view); | |
98 | |
99 // network_icon::AnimationObserver: | |
100 void NetworkIconChanged() override; | |
101 | |
102 // views::ButtonListener: | |
103 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
104 | |
105 bool needs_relayout_; | |
106 NetworkListDelegate* delegate_; | |
107 | |
108 views::Label* no_wifi_networks_view_; | |
109 views::Label* no_cellular_networks_view_; | |
110 WifiHeaderRowView* wifi_header_view_; | |
111 | |
112 // An owned list of network info. | |
113 std::vector<std::unique_ptr<NetworkInfo>> network_list_; | |
114 | |
115 using NetworkMap = std::map<views::View*, std::string>; | |
116 NetworkMap network_map_; | |
117 | |
118 // A map of network service paths to their view. | |
119 typedef std::map<std::string, views::View*> ServicePathMap; | |
120 ServicePathMap service_path_map_; | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(NetworkListViewMd); | |
123 }; | |
124 | |
125 } // namespace ui | |
126 | |
127 #endif // UI_CHROMEOS_NETWORK_NETWORK_LIST_MD_H_ | |
OLD | NEW |