Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: ui/chromeos/network/network_list.cc

Issue 980943005: Add ash UI for third-party VPNs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_2_407541_434711_remove_combined_name
Patch Set: Updated after latest round of UI reviews. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/chromeos/network/network_list.h ('k') | ui/chromeos/network/network_list_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/chromeos/network/network_list.h" 5 #include "ui/chromeos/network/network_list.h"
6 6
7 #include "chromeos/dbus/dbus_thread_manager.h" 7 #include "chromeos/dbus/dbus_thread_manager.h"
8 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" 8 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
9 #include "chromeos/dbus/power_manager_client.h" 9 #include "chromeos/dbus/power_manager_client.h"
10 #include "chromeos/network/network_state.h" 10 #include "chromeos/network/network_state.h"
(...skipping 13 matching lines...) Expand all
24 using chromeos::NetworkHandler; 24 using chromeos::NetworkHandler;
25 using chromeos::NetworkStateHandler; 25 using chromeos::NetworkStateHandler;
26 using chromeos::NetworkTypePattern; 26 using chromeos::NetworkTypePattern;
27 27
28 namespace ui { 28 namespace ui {
29 29
30 // NetworkListView: 30 // NetworkListView:
31 31
32 NetworkListView::NetworkListView(NetworkListDelegate* delegate) 32 NetworkListView::NetworkListView(NetworkListDelegate* delegate)
33 : delegate_(delegate), 33 : delegate_(delegate),
34 content_(NULL),
35 scanning_view_(NULL), 34 scanning_view_(NULL),
36 no_wifi_networks_view_(NULL), 35 no_wifi_networks_view_(NULL),
37 no_cellular_networks_view_(NULL) { 36 no_cellular_networks_view_(NULL) {
38 CHECK(delegate); 37 CHECK(delegate_);
39 } 38 }
40 39
41 NetworkListView::~NetworkListView() { 40 NetworkListView::~NetworkListView() {
42 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 41 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
43 } 42 }
44 43
45 void NetworkListView::UpdateNetworkList() { 44 void NetworkListView::Update() {
46 CHECK(content_); 45 CHECK(container_);
47 NetworkStateHandler::NetworkStateList network_list; 46 NetworkStateHandler::NetworkStateList network_list;
48 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 47 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
49 handler->GetVisibleNetworkList(&network_list); 48 handler->GetVisibleNetworkList(&network_list);
50 UpdateNetworks(network_list); 49 UpdateNetworks(network_list);
51 UpdateNetworkIcons(); 50 UpdateNetworkIcons();
52 UpdateNetworkListInternal(); 51 UpdateNetworkListInternal();
53 } 52 }
54 53
55 bool NetworkListView::IsViewInList(views::View* view, 54 bool NetworkListView::IsNetworkEntry(views::View* view,
56 std::string* service_path) const { 55 std::string* service_path) const {
57 std::map<views::View*, std::string>::const_iterator found = 56 std::map<views::View*, std::string>::const_iterator found =
58 network_map_.find(view); 57 network_map_.find(view);
59 if (found == network_map_.end()) 58 if (found == network_map_.end())
60 return false; 59 return false;
61 *service_path = found->second; 60 *service_path = found->second;
62 return true; 61 return true;
63 } 62 }
64 63
65 void NetworkListView::UpdateNetworks( 64 void NetworkListView::UpdateNetworks(
66 const NetworkStateHandler::NetworkStateList& networks) { 65 const NetworkStateHandler::NetworkStateList& networks) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 bool needs_relayout = UpdateNetworkListEntries(&new_service_paths); 115 bool needs_relayout = UpdateNetworkListEntries(&new_service_paths);
117 116
118 // Remove old children 117 // Remove old children
119 std::set<std::string> remove_service_paths; 118 std::set<std::string> remove_service_paths;
120 for (ServicePathMap::const_iterator it = service_path_map_.begin(); 119 for (ServicePathMap::const_iterator it = service_path_map_.begin();
121 it != service_path_map_.end(); 120 it != service_path_map_.end();
122 ++it) { 121 ++it) {
123 if (new_service_paths.find(it->first) == new_service_paths.end()) { 122 if (new_service_paths.find(it->first) == new_service_paths.end()) {
124 remove_service_paths.insert(it->first); 123 remove_service_paths.insert(it->first);
125 network_map_.erase(it->second); 124 network_map_.erase(it->second);
126 content_->RemoveChildView(it->second); 125 container_->RemoveChildView(it->second);
127 needs_relayout = true; 126 needs_relayout = true;
128 } 127 }
129 } 128 }
130 129
131 for (std::set<std::string>::const_iterator remove_it = 130 for (std::set<std::string>::const_iterator remove_it =
132 remove_service_paths.begin(); 131 remove_service_paths.begin();
133 remove_it != remove_service_paths.end(); 132 remove_it != remove_service_paths.end();
134 ++remove_it) { 133 ++remove_it) {
135 service_path_map_.erase(*remove_it); 134 service_path_map_.erase(*remove_it);
136 } 135 }
137 136
138 if (needs_relayout) 137 if (needs_relayout)
139 HandleRelayout(); 138 HandleRelayout();
140 } 139 }
141 140
142 void NetworkListView::HandleRelayout() { 141 void NetworkListView::HandleRelayout() {
143 views::View* selected_view = NULL; 142 views::View* selected_view = NULL;
144 for (auto& iter : service_path_map_) { 143 for (auto& iter : service_path_map_) {
145 if (delegate_->IsViewHovered(iter.second)) { 144 if (delegate_->IsViewHovered(iter.second)) {
146 selected_view = iter.second; 145 selected_view = iter.second;
147 break; 146 break;
148 } 147 }
149 } 148 }
150 content_->SizeToPreferredSize(); 149 container_->SizeToPreferredSize();
151 delegate_->RelayoutScrollList(); 150 delegate_->RelayoutScrollList();
152 if (selected_view) 151 if (selected_view)
153 content_->ScrollRectToVisible(selected_view->bounds()); 152 container_->ScrollRectToVisible(selected_view->bounds());
154 } 153 }
155 154
156 bool NetworkListView::UpdateNetworkListEntries( 155 bool NetworkListView::UpdateNetworkListEntries(
157 std::set<std::string>* new_service_paths) { 156 std::set<std::string>* new_service_paths) {
158 bool needs_relayout = false; 157 bool needs_relayout = false;
159 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 158 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
160 159
161 // Insert child views 160 // Insert child views
162 int index = 0; 161 int index = 0;
163 162
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (message_id) 201 if (message_id)
203 ++index; 202 ++index;
204 } 203 }
205 204
206 // Un-highlighted networks 205 // Un-highlighted networks
207 needs_relayout |= UpdateNetworkChildren(new_service_paths, &index, 206 needs_relayout |= UpdateNetworkChildren(new_service_paths, &index,
208 false /* not highlighted */); 207 false /* not highlighted */);
209 208
210 // No networks or other messages (fallback) 209 // No networks or other messages (fallback)
211 if (index == 0) { 210 if (index == 0) {
212 int message_id = 0; 211 needs_relayout |= UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index,
213 if (pattern.Equals(NetworkTypePattern::VPN())) 212 &scanning_view_);
214 message_id = IDS_ASH_STATUS_TRAY_NETWORK_NO_VPN;
215 else
216 message_id = IDS_ASH_STATUS_TRAY_NO_NETWORKS;
217 needs_relayout |= UpdateInfoLabel(message_id, index, &scanning_view_);
218 } 213 }
219 214
220 return needs_relayout; 215 return needs_relayout;
221 } 216 }
222 217
223 bool NetworkListView::UpdateNetworkChildren( 218 bool NetworkListView::UpdateNetworkChildren(
224 std::set<std::string>* new_service_paths, 219 std::set<std::string>* new_service_paths,
225 int* child_index, 220 int* child_index,
226 bool highlighted) { 221 bool highlighted) {
227 bool needs_relayout = false; 222 bool needs_relayout = false;
228 int index = *child_index; 223 int index = *child_index;
229 for (auto& info : network_list_) { 224 for (auto& info : network_list_) {
230 if (info->highlight != highlighted) 225 if (info->highlight != highlighted)
231 continue; 226 continue;
232 needs_relayout |= UpdateNetworkChild(index++, info); 227 needs_relayout |= UpdateNetworkChild(index++, info);
233 new_service_paths->insert(info->service_path); 228 new_service_paths->insert(info->service_path);
234 } 229 }
235 *child_index = index; 230 *child_index = index;
236 return needs_relayout; 231 return needs_relayout;
237 } 232 }
238 233
239 bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { 234 bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) {
240 bool needs_relayout = false; 235 bool needs_relayout = false;
241 views::View* container = NULL; 236 views::View* container = NULL;
242 ServicePathMap::const_iterator found = 237 ServicePathMap::const_iterator found =
243 service_path_map_.find(info->service_path); 238 service_path_map_.find(info->service_path);
244 if (found == service_path_map_.end()) { 239 if (found == service_path_map_.end()) {
245 container = delegate_->CreateViewForNetwork(*info); 240 container = delegate_->CreateViewForNetwork(*info);
246 content_->AddChildViewAt(container, index); 241 container_->AddChildViewAt(container, index);
247 needs_relayout = true; 242 needs_relayout = true;
248 } else { 243 } else {
249 container = found->second; 244 container = found->second;
250 container->RemoveAllChildViews(true); 245 container->RemoveAllChildViews(true);
251 delegate_->UpdateViewForNetwork(container, *info); 246 delegate_->UpdateViewForNetwork(container, *info);
252 container->Layout(); 247 container->Layout();
253 container->SchedulePaint(); 248 container->SchedulePaint();
254 needs_relayout = PlaceViewAtIndex(container, index); 249 needs_relayout = PlaceViewAtIndex(container, index);
255 } 250 }
256 if (info->disable) 251 if (info->disable)
257 container->SetEnabled(false); 252 container->SetEnabled(false);
258 network_map_[container] = info->service_path; 253 network_map_[container] = info->service_path;
259 service_path_map_[info->service_path] = container; 254 service_path_map_[info->service_path] = container;
260 return needs_relayout; 255 return needs_relayout;
261 } 256 }
262 257
263 bool NetworkListView::PlaceViewAtIndex(views::View* view, int index) { 258 bool NetworkListView::PlaceViewAtIndex(views::View* view, int index) {
264 if (content_->child_at(index) == view) 259 if (container_->child_at(index) == view)
265 return false; 260 return false;
266 content_->ReorderChildView(view, index); 261 container_->ReorderChildView(view, index);
267 return true; 262 return true;
268 } 263 }
269 264
270 bool NetworkListView::UpdateInfoLabel(int message_id, 265 bool NetworkListView::UpdateInfoLabel(int message_id,
271 int index, 266 int index,
272 views::Label** label) { 267 views::Label** label) {
273 CHECK(label); 268 CHECK(label);
274 bool needs_relayout = false; 269 bool needs_relayout = false;
275 if (message_id) { 270 if (message_id) {
276 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 271 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
277 base::string16 text = rb.GetLocalizedString(message_id); 272 base::string16 text = rb.GetLocalizedString(message_id);
278 if (!*label) { 273 if (!*label) {
279 *label = delegate_->CreateInfoLabel(); 274 *label = delegate_->CreateInfoLabel();
280 (*label)->SetText(text); 275 (*label)->SetText(text);
281 content_->AddChildViewAt(*label, index); 276 container_->AddChildViewAt(*label, index);
282 needs_relayout = true; 277 needs_relayout = true;
283 } else { 278 } else {
284 (*label)->SetText(text); 279 (*label)->SetText(text);
285 needs_relayout = PlaceViewAtIndex(*label, index); 280 needs_relayout = PlaceViewAtIndex(*label, index);
286 } 281 }
287 } else if (*label) { 282 } else if (*label) {
288 content_->RemoveChildView(*label); 283 container_->RemoveChildView(*label);
289 delete *label; 284 delete *label;
290 *label = NULL; 285 *label = NULL;
291 needs_relayout = true; 286 needs_relayout = true;
292 } 287 }
293 return needs_relayout; 288 return needs_relayout;
294 } 289 }
295 290
296 void NetworkListView::NetworkIconChanged() { 291 void NetworkListView::NetworkIconChanged() {
297 UpdateNetworkList(); 292 Update();
298 } 293 }
299 294
300 } // namespace ui 295 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/network/network_list.h ('k') | ui/chromeos/network/network_list_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698