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

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

Issue 2342793005: [ash-md] Adds Wi-Fi header row to system tray network detailed view (Closed)
Patch Set: [ash-md] Materializes system tray network detailed view (nits) Created 4 years, 2 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_info.cc ('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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "chromeos/dbus/dbus_thread_manager.h" 10 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return !managed_configuration_handler->FindPolicyByGuidAndProfile( 58 return !managed_configuration_handler->FindPolicyByGuidAndProfile(
59 network->guid(), network->profile_path()); 59 network->guid(), network->profile_path());
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 // NetworkListView: 64 // NetworkListView:
65 65
66 NetworkListView::NetworkListView(NetworkListDelegate* delegate) 66 NetworkListView::NetworkListView(NetworkListDelegate* delegate)
67 : delegate_(delegate), 67 : delegate_(delegate),
68 no_wifi_networks_view_(NULL), 68 no_wifi_networks_view_(nullptr),
69 no_cellular_networks_view_(NULL) { 69 no_cellular_networks_view_(nullptr) {
70 CHECK(delegate_); 70 CHECK(delegate_);
71 } 71 }
72 72
73 NetworkListView::~NetworkListView() { 73 NetworkListView::~NetworkListView() {
74 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 74 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
75 } 75 }
76 76
77 void NetworkListView::Update() { 77 void NetworkListView::Update() {
78 CHECK(container_); 78 CHECK(container());
79 NetworkStateHandler::NetworkStateList network_list; 79 NetworkStateHandler::NetworkStateList network_list;
80 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 80 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
81 handler->GetVisibleNetworkList(&network_list); 81 handler->GetVisibleNetworkList(&network_list);
82 UpdateNetworks(network_list); 82 UpdateNetworks(network_list);
83 UpdateNetworkIcons(); 83 UpdateNetworkIcons();
84 UpdateNetworkListInternal(); 84 UpdateNetworkListInternal();
85 } 85 }
86 86
87 bool NetworkListView::IsNetworkEntry(views::View* view, 87 bool NetworkListView::IsNetworkEntry(views::View* view,
88 std::string* service_path) const { 88 std::string* service_path) const {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 bool prohibited_by_policy = IsProhibitedByPolicy(network); 125 bool prohibited_by_policy = IsProhibitedByPolicy(network);
126 info->image = 126 info->image =
127 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); 127 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST);
128 info->label = 128 info->label =
129 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST); 129 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST);
130 info->highlight = 130 info->highlight =
131 network->IsConnectedState() || network->IsConnectingState(); 131 network->IsConnectedState() || network->IsConnectingState();
132 info->disable = 132 info->disable =
133 (network->activation_state() == shill::kActivationStateActivating) || 133 (network->activation_state() == shill::kActivationStateActivating) ||
134 prohibited_by_policy; 134 prohibited_by_policy;
135 info->is_wifi = network->Matches(NetworkTypePattern::WiFi());
135 if (prohibited_by_policy) { 136 if (prohibited_by_policy) {
136 info->tooltip = 137 info->tooltip =
137 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); 138 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED);
138 } 139 }
139 if (!animating && network->IsConnectingState()) 140 if (!animating && network->IsConnectingState())
140 animating = true; 141 animating = true;
141 } 142 }
142 if (animating) 143 if (animating)
143 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 144 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
144 else 145 else
145 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 146 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
146 } 147 }
147 148
148 void NetworkListView::UpdateNetworkListInternal() { 149 void NetworkListView::UpdateNetworkListInternal() {
149 SCOPED_NET_LOG_IF_SLOW(); 150 SCOPED_NET_LOG_IF_SLOW();
150 // Get the updated list entries 151 // Get the updated list entries
151 network_map_.clear(); 152 network_map_.clear();
152 std::set<std::string> new_service_paths; 153 std::set<std::string> new_service_paths;
153 bool needs_relayout = UpdateNetworkListEntries(&new_service_paths); 154 bool needs_relayout = UpdateNetworkListEntries(&new_service_paths);
154 155
155 // Remove old children 156 // Remove old children
156 std::set<std::string> remove_service_paths; 157 std::set<std::string> remove_service_paths;
157 for (ServicePathMap::const_iterator it = service_path_map_.begin(); 158 for (ServicePathMap::const_iterator it = service_path_map_.begin();
158 it != service_path_map_.end(); 159 it != service_path_map_.end();
159 ++it) { 160 ++it) {
160 if (new_service_paths.find(it->first) == new_service_paths.end()) { 161 if (new_service_paths.find(it->first) == new_service_paths.end()) {
161 remove_service_paths.insert(it->first); 162 remove_service_paths.insert(it->first);
162 network_map_.erase(it->second); 163 network_map_.erase(it->second);
163 container_->RemoveChildView(it->second); 164 delete it->second;
164 needs_relayout = true; 165 needs_relayout = true;
165 } 166 }
166 } 167 }
167 168
168 for (std::set<std::string>::const_iterator remove_it = 169 for (std::set<std::string>::const_iterator remove_it =
169 remove_service_paths.begin(); 170 remove_service_paths.begin();
170 remove_it != remove_service_paths.end(); 171 remove_it != remove_service_paths.end();
171 ++remove_it) { 172 ++remove_it) {
172 service_path_map_.erase(*remove_it); 173 service_path_map_.erase(*remove_it);
173 } 174 }
174 175
175 if (needs_relayout) 176 if (needs_relayout)
176 HandleRelayout(); 177 HandleRelayout();
177 } 178 }
178 179
179 void NetworkListView::HandleRelayout() { 180 void NetworkListView::HandleRelayout() {
180 views::View* selected_view = NULL; 181 views::View* selected_view = nullptr;
181 for (auto& iter : service_path_map_) { 182 for (auto& iter : service_path_map_) {
182 if (delegate_->IsViewHovered(iter.second)) { 183 if (delegate_->IsViewHovered(iter.second)) {
183 selected_view = iter.second; 184 selected_view = iter.second;
184 break; 185 break;
185 } 186 }
186 } 187 }
187 container_->SizeToPreferredSize(); 188 container()->SizeToPreferredSize();
188 delegate_->RelayoutScrollList(); 189 delegate_->RelayoutScrollList();
189 if (selected_view) 190 if (selected_view)
190 container_->ScrollRectToVisible(selected_view->bounds()); 191 container()->ScrollRectToVisible(selected_view->bounds());
191 } 192 }
192 193
193 bool NetworkListView::UpdateNetworkListEntries( 194 bool NetworkListView::UpdateNetworkListEntries(
194 std::set<std::string>* new_service_paths) { 195 std::set<std::string>* new_service_paths) {
195 bool needs_relayout = false; 196 bool needs_relayout = false;
196 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 197 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
197 198
198 // Insert child views 199 // Insert child views
199 int index = 0; 200 int index = 0;
200 201
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 continue; 257 continue;
257 needs_relayout |= UpdateNetworkChild(index++, info.get()); 258 needs_relayout |= UpdateNetworkChild(index++, info.get());
258 new_service_paths->insert(info->service_path); 259 new_service_paths->insert(info->service_path);
259 } 260 }
260 *child_index = index; 261 *child_index = index;
261 return needs_relayout; 262 return needs_relayout;
262 } 263 }
263 264
264 bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { 265 bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) {
265 bool needs_relayout = false; 266 bool needs_relayout = false;
266 views::View* container = NULL; 267 views::View* network_view = nullptr;
267 ServicePathMap::const_iterator found = 268 ServicePathMap::const_iterator found =
268 service_path_map_.find(info->service_path); 269 service_path_map_.find(info->service_path);
269 if (found == service_path_map_.end()) { 270 if (found == service_path_map_.end()) {
270 container = delegate_->CreateViewForNetwork(*info); 271 network_view = delegate_->CreateViewForNetwork(*info);
271 container_->AddChildViewAt(container, index); 272 container()->AddChildViewAt(network_view, index);
272 needs_relayout = true; 273 needs_relayout = true;
273 } else { 274 } else {
274 container = found->second; 275 network_view = found->second;
275 container->RemoveAllChildViews(true); 276 network_view->RemoveAllChildViews(true);
276 delegate_->UpdateViewForNetwork(container, *info); 277 delegate_->UpdateViewForNetwork(network_view, *info);
277 container->Layout(); 278 network_view->Layout();
278 container->SchedulePaint(); 279 network_view->SchedulePaint();
279 needs_relayout = PlaceViewAtIndex(container, index); 280 needs_relayout = PlaceViewAtIndex(network_view, index);
280 } 281 }
281 if (info->disable) 282 if (info->disable)
282 container->SetEnabled(false); 283 network_view->SetEnabled(false);
283 network_map_[container] = info->service_path; 284 network_map_[network_view] = info->service_path;
284 service_path_map_[info->service_path] = container; 285 service_path_map_[info->service_path] = network_view;
285 return needs_relayout; 286 return needs_relayout;
286 } 287 }
287 288
288 bool NetworkListView::PlaceViewAtIndex(views::View* view, int index) { 289 bool NetworkListView::PlaceViewAtIndex(views::View* view, int index) {
289 if (container_->child_at(index) == view) 290 if (container()->child_at(index) == view)
290 return false; 291 return false;
291 container_->ReorderChildView(view, index); 292 container()->ReorderChildView(view, index);
292 return true; 293 return true;
293 } 294 }
294 295
295 bool NetworkListView::UpdateInfoLabel(int message_id, 296 bool NetworkListView::UpdateInfoLabel(int message_id,
296 int index, 297 int index,
297 views::Label** label) { 298 views::Label** label) {
298 CHECK(label); 299 CHECK(label);
299 bool needs_relayout = false; 300 bool needs_relayout = false;
300 if (message_id) { 301 if (message_id) {
301 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 302 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
302 base::string16 text = rb.GetLocalizedString(message_id); 303 base::string16 text = rb.GetLocalizedString(message_id);
303 if (!*label) { 304 if (!*label) {
304 *label = delegate_->CreateInfoLabel(); 305 *label = delegate_->CreateInfoLabel();
305 (*label)->SetText(text); 306 (*label)->SetText(text);
306 container_->AddChildViewAt(*label, index); 307 container()->AddChildViewAt(*label, index);
307 needs_relayout = true; 308 needs_relayout = true;
308 } else { 309 } else {
309 (*label)->SetText(text); 310 (*label)->SetText(text);
310 needs_relayout = PlaceViewAtIndex(*label, index); 311 needs_relayout = PlaceViewAtIndex(*label, index);
311 } 312 }
312 } else if (*label) { 313 } else if (*label) {
313 container_->RemoveChildView(*label);
314 delete *label; 314 delete *label;
315 *label = NULL; 315 *label = nullptr;
316 needs_relayout = true; 316 needs_relayout = true;
317 } 317 }
318 return needs_relayout; 318 return needs_relayout;
319 } 319 }
320 320
321 void NetworkListView::NetworkIconChanged() { 321 void NetworkListView::NetworkIconChanged() {
322 Update(); 322 Update();
323 } 323 }
324 324
325 } // namespace ui 325 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/network/network_info.cc ('k') | ui/chromeos/network/network_list_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698