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

Side by Side Diff: ash/system/cast/tray_cast.cc

Issue 2831023003: Refactor AddScrollListItem() in system menu detailed views (Closed)
Patch Set: Rebased Created 3 years, 7 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 | « ash/system/bluetooth/tray_bluetooth.cc ('k') | ash/system/ime_menu/ime_list_view.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/cast/tray_cast.h" 5 #include "ash/system/cast/tray_cast.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 void SimulateViewClickedForTest(const std::string& receiver_id); 308 void SimulateViewClickedForTest(const std::string& receiver_id);
309 309
310 // Updates the list of available receivers. 310 // Updates the list of available receivers.
311 void UpdateReceiverList( 311 void UpdateReceiverList(
312 const std::vector<mojom::SinkAndRoutePtr>& sinks_routes); 312 const std::vector<mojom::SinkAndRoutePtr>& sinks_routes);
313 313
314 private: 314 private:
315 void CreateItems(); 315 void CreateItems();
316 316
317 void UpdateReceiverListFromCachedData(); 317 void UpdateReceiverListFromCachedData();
318 views::View* AddToReceiverList(const mojom::SinkAndRoutePtr& sink_route);
319 318
320 // TrayDetailsView: 319 // TrayDetailsView:
321 void HandleViewClicked(views::View* view) override; 320 void HandleViewClicked(views::View* view) override;
322 321
323 // A mapping from the receiver id to the receiver/activity data. 322 // A mapping from the receiver id to the receiver/activity data.
324 std::map<std::string, ash::mojom::SinkAndRoutePtr> sinks_and_routes_; 323 std::map<std::string, ash::mojom::SinkAndRoutePtr> sinks_and_routes_;
325 // A mapping from the view pointer to the associated activity id. 324 // A mapping from the view pointer to the associated activity id.
326 std::map<views::View*, ash::mojom::CastSinkPtr> view_to_sink_map_; 325 std::map<views::View*, ash::mojom::CastSinkPtr> view_to_sink_map_;
327 326
328 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); 327 DISALLOW_COPY_AND_ASSIGN(CastDetailedView);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 380 }
382 381
383 void CastDetailedView::UpdateReceiverListFromCachedData() { 382 void CastDetailedView::UpdateReceiverListFromCachedData() {
384 // Remove all of the existing views. 383 // Remove all of the existing views.
385 view_to_sink_map_.clear(); 384 view_to_sink_map_.clear();
386 scroll_content()->RemoveAllChildViews(true); 385 scroll_content()->RemoveAllChildViews(true);
387 386
388 // Add a view for each receiver. 387 // Add a view for each receiver.
389 for (auto& it : sinks_and_routes_) { 388 for (auto& it : sinks_and_routes_) {
390 const ash::mojom::SinkAndRoutePtr& sink_route = it.second; 389 const ash::mojom::SinkAndRoutePtr& sink_route = it.second;
391 views::View* container = AddToReceiverList(sink_route); 390 const base::string16 name = base::UTF8ToUTF16(sink_route->sink->name);
391 views::View* container = AddScrollListItem(kSystemMenuCastDeviceIcon, name);
392 view_to_sink_map_[container] = sink_route->sink.Clone(); 392 view_to_sink_map_[container] = sink_route->sink.Clone();
393 } 393 }
394 394
395 scroll_content()->SizeToPreferredSize(); 395 scroll_content()->SizeToPreferredSize();
396 scroller()->Layout(); 396 scroller()->Layout();
397 } 397 }
398 398
399 views::View* CastDetailedView::AddToReceiverList(
400 const ash::mojom::SinkAndRoutePtr& sink_route) {
401 const gfx::ImageSkia image =
402 gfx::CreateVectorIcon(kSystemMenuCastDeviceIcon, kMenuIconColor);
403
404 HoverHighlightView* container = new HoverHighlightView(this);
405 container->AddIconAndLabel(image, base::UTF8ToUTF16(sink_route->sink->name));
406
407 scroll_content()->AddChildView(container);
408 return container;
409 }
410
411 void CastDetailedView::HandleViewClicked(views::View* view) { 399 void CastDetailedView::HandleViewClicked(views::View* view) {
412 // Find the receiver we are going to cast to. 400 // Find the receiver we are going to cast to.
413 auto it = view_to_sink_map_.find(view); 401 auto it = view_to_sink_map_.find(view);
414 if (it != view_to_sink_map_.end()) { 402 if (it != view_to_sink_map_.end()) {
415 Shell::Get()->cast_config()->CastToSink(it->second.Clone()); 403 Shell::Get()->cast_config()->CastToSink(it->second.Clone());
416 ShellPort::Get()->RecordUserMetricsAction( 404 ShellPort::Get()->RecordUserMetricsAction(
417 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST); 405 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST);
418 } 406 }
419 } 407 }
420 408
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 516
529 return false; 517 return false;
530 } 518 }
531 519
532 void TrayCast::OnCastingSessionStartedOrStopped(bool started) { 520 void TrayCast::OnCastingSessionStartedOrStopped(bool started) {
533 is_mirror_casting_ = started; 521 is_mirror_casting_ = started;
534 UpdatePrimaryView(); 522 UpdatePrimaryView();
535 } 523 }
536 524
537 } // namespace ash 525 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/bluetooth/tray_bluetooth.cc ('k') | ash/system/ime_menu/ime_list_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698