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

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

Issue 2289223002: Make TrayDetailsView a ViewClickListener and ButtonListener (Closed)
Patch Set: fix test Created 4 years, 3 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 | « no previous file | ash/common/system/chromeos/audio/audio_detailed_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/common/system/cast/tray_cast.h" 5 #include "ash/common/system/cast/tray_cast.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shelf/shelf_types.h" 9 #include "ash/common/shelf/shelf_types.h"
10 #include "ash/common/shelf/wm_shelf_util.h" 10 #include "ash/common/shelf/wm_shelf_util.h"
11 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h" 11 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h"
12 #include "ash/common/system/tray/fixed_sized_image_view.h" 12 #include "ash/common/system/tray/fixed_sized_image_view.h"
13 #include "ash/common/system/tray/fixed_sized_scroll_view.h" 13 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
14 #include "ash/common/system/tray/hover_highlight_view.h" 14 #include "ash/common/system/tray/hover_highlight_view.h"
15 #include "ash/common/system/tray/system_tray.h" 15 #include "ash/common/system/tray/system_tray.h"
16 #include "ash/common/system/tray/system_tray_delegate.h" 16 #include "ash/common/system/tray/system_tray_delegate.h"
17 #include "ash/common/system/tray/throbber_view.h" 17 #include "ash/common/system/tray/throbber_view.h"
18 #include "ash/common/system/tray/tray_constants.h" 18 #include "ash/common/system/tray/tray_constants.h"
19 #include "ash/common/system/tray/tray_details_view.h" 19 #include "ash/common/system/tray/tray_details_view.h"
20 #include "ash/common/system/tray/tray_item_more.h" 20 #include "ash/common/system/tray/tray_item_more.h"
21 #include "ash/common/system/tray/tray_item_view.h" 21 #include "ash/common/system/tray/tray_item_view.h"
22 #include "ash/common/system/tray/tray_popup_label_button.h" 22 #include "ash/common/system/tray/tray_popup_label_button.h"
23 #include "ash/common/system/tray/view_click_listener.h"
24 #include "ash/common/wm_shell.h" 23 #include "ash/common/wm_shell.h"
25 #include "base/bind.h" 24 #include "base/bind.h"
26 #include "grit/ash_resources.h" 25 #include "grit/ash_resources.h"
27 #include "grit/ash_strings.h" 26 #include "grit/ash_strings.h"
28 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/gfx/image/image.h" 29 #include "ui/gfx/image/image.h"
31 #include "ui/gfx/paint_vector_icon.h" 30 #include "ui/gfx/paint_vector_icon.h"
32 #include "ui/gfx/text_elider.h" 31 #include "ui/gfx/text_elider.h"
33 #include "ui/gfx/vector_icons_public.h" 32 #include "ui/gfx/vector_icons_public.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment) 377 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment)
379 ? views::BoxLayout::kHorizontal 378 ? views::BoxLayout::kHorizontal
380 : views::BoxLayout::kVertical; 379 : views::BoxLayout::kVertical;
381 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); 380 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
382 Layout(); 381 Layout();
383 } 382 }
384 383
385 // This view displays a list of cast receivers that can be clicked on and casted 384 // This view displays a list of cast receivers that can be clicked on and casted
386 // to. It is activated by clicking on the chevron inside of 385 // to. It is activated by clicking on the chevron inside of
387 // |CastSelectDefaultView|. 386 // |CastSelectDefaultView|.
388 class CastDetailedView : public TrayDetailsView, public ViewClickListener { 387 class CastDetailedView : public TrayDetailsView {
389 public: 388 public:
390 CastDetailedView(SystemTrayItem* owner, 389 CastDetailedView(SystemTrayItem* owner,
391 LoginStatus login, 390 LoginStatus login,
392 const CastConfigDelegate::ReceiversAndActivities& 391 const CastConfigDelegate::ReceiversAndActivities&
393 receivers_and_activities); 392 receivers_and_activities);
394 ~CastDetailedView() override; 393 ~CastDetailedView() override;
395 394
396 // Makes the detail view think the view associated with the given receiver_id 395 // Makes the detail view think the view associated with the given receiver_id
397 // was clicked. This will start a cast. 396 // was clicked. This will start a cast.
398 void SimulateViewClickedForTest(const std::string& receiver_id); 397 void SimulateViewClickedForTest(const std::string& receiver_id);
399 398
400 // Updates the list of available receivers. 399 // Updates the list of available receivers.
401 void UpdateReceiverList(const CastConfigDelegate::ReceiversAndActivities& 400 void UpdateReceiverList(const CastConfigDelegate::ReceiversAndActivities&
402 new_receivers_and_activities); 401 new_receivers_and_activities);
403 402
404 private: 403 private:
405 void CreateItems(); 404 void CreateItems();
406 405
407 void UpdateReceiverListFromCachedData(); 406 void UpdateReceiverListFromCachedData();
408 views::View* AddToReceiverList( 407 views::View* AddToReceiverList(
409 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); 408 const CastConfigDelegate::ReceiverAndActivity& receiverActivity);
410 409
411 void AppendSettingsEntries(); 410 void AppendSettingsEntries();
412 void AppendHeaderEntry();
413 411
414 // Overridden from ViewClickListener. 412 // TrayDetailsView:
415 void OnViewClicked(views::View* sender) override; 413 void HandleViewClicked(views::View* view) override;
416 414
417 LoginStatus login_; 415 LoginStatus login_;
418 views::View* options_ = nullptr; 416 views::View* options_ = nullptr;
419 // A mapping from the receiver id to the receiver/activity data. 417 // A mapping from the receiver id to the receiver/activity data.
420 std::map<std::string, CastConfigDelegate::ReceiverAndActivity> 418 std::map<std::string, CastConfigDelegate::ReceiverAndActivity>
421 receivers_and_activities_; 419 receivers_and_activities_;
422 // A mapping from the view pointer to the associated activity id. 420 // A mapping from the view pointer to the associated activity id.
423 std::map<views::View*, std::string> receiver_activity_map_; 421 std::map<views::View*, std::string> receiver_activity_map_;
424 422
425 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); 423 DISALLOW_COPY_AND_ASSIGN(CastDetailedView);
426 }; 424 };
427 425
428 CastDetailedView::CastDetailedView( 426 CastDetailedView::CastDetailedView(
429 SystemTrayItem* owner, 427 SystemTrayItem* owner,
430 LoginStatus login, 428 LoginStatus login,
431 const CastConfigDelegate::ReceiversAndActivities& receivers_and_activities) 429 const CastConfigDelegate::ReceiversAndActivities& receivers_and_activities)
432 : TrayDetailsView(owner), login_(login) { 430 : TrayDetailsView(owner), login_(login) {
433 CreateItems(); 431 CreateItems();
434 UpdateReceiverList(receivers_and_activities); 432 UpdateReceiverList(receivers_and_activities);
435 } 433 }
436 434
437 CastDetailedView::~CastDetailedView() {} 435 CastDetailedView::~CastDetailedView() {}
438 436
439 void CastDetailedView::SimulateViewClickedForTest( 437 void CastDetailedView::SimulateViewClickedForTest(
440 const std::string& receiver_id) { 438 const std::string& receiver_id) {
441 for (auto& it : receiver_activity_map_) { 439 for (auto& it : receiver_activity_map_) {
442 if (it.second == receiver_id) { 440 if (it.second == receiver_id) {
443 OnViewClicked(it.first); 441 HandleViewClicked(it.first);
444 break; 442 break;
445 } 443 }
446 } 444 }
447 } 445 }
448 446
449 void CastDetailedView::CreateItems() { 447 void CastDetailedView::CreateItems() {
450 CreateScrollableList(); 448 CreateScrollableList();
451 if (GetCastConfigDelegate()->HasOptions()) 449 if (GetCastConfigDelegate()->HasOptions())
452 AppendSettingsEntries(); 450 AppendSettingsEntries();
453 AppendHeaderEntry(); 451 CreateTitleRow(IDS_ASH_STATUS_TRAY_CAST);
454 } 452 }
455 453
456 void CastDetailedView::UpdateReceiverList( 454 void CastDetailedView::UpdateReceiverList(
457 const CastConfigDelegate::ReceiversAndActivities& 455 const CastConfigDelegate::ReceiversAndActivities&
458 new_receivers_and_activities) { 456 new_receivers_and_activities) {
459 // Add/update existing. 457 // Add/update existing.
460 for (auto i = new_receivers_and_activities.begin(); 458 for (auto i = new_receivers_and_activities.begin();
461 i != new_receivers_and_activities.end(); ++i) { 459 i != new_receivers_and_activities.end(); ++i) {
462 receivers_and_activities_[i->receiver.id] = *i; 460 receivers_and_activities_[i->receiver.id] = *i;
463 } 461 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 524
527 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 525 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
528 HoverHighlightView* container = new HoverHighlightView(this); 526 HoverHighlightView* container = new HoverHighlightView(this);
529 container->AddLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_OPTIONS), 527 container->AddLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_OPTIONS),
530 gfx::ALIGN_LEFT, false /* highlight */); 528 gfx::ALIGN_LEFT, false /* highlight */);
531 529
532 AddChildView(container); 530 AddChildView(container);
533 options_ = container; 531 options_ = container;
534 } 532 }
535 533
536 void CastDetailedView::AppendHeaderEntry() { 534 void CastDetailedView::HandleViewClicked(views::View* view) {
537 CreateSpecialRow(IDS_ASH_STATUS_TRAY_CAST, this); 535 if (view == options_) {
538 } 536 GetCastConfigDelegate()->LaunchCastOptions();
537 return;
538 }
539 539
540 void CastDetailedView::OnViewClicked(views::View* sender) { 540 // Find the receiver we are going to cast to.
541 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); 541 auto it = receiver_activity_map_.find(view);
542 542 if (it != receiver_activity_map_.end()) {
543 if (sender == footer()->content()) { 543 GetCastConfigDelegate()->CastToReceiver(it->second);
544 TransitionToDefaultView(); 544 WmShell::Get()->RecordUserMetricsAction(
545 } else if (sender == options_) { 545 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST);
546 cast_config_delegate->LaunchCastOptions();
547 } else {
548 // Find the receiver we are going to cast to
549 auto it = receiver_activity_map_.find(sender);
550 if (it != receiver_activity_map_.end()) {
551 cast_config_delegate->CastToReceiver(it->second);
552 WmShell::Get()->RecordUserMetricsAction(
553 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST);
554 }
555 } 546 }
556 } 547 }
557 548
558 } // namespace tray 549 } // namespace tray
559 550
560 TrayCast::TrayCast(SystemTray* system_tray) 551 TrayCast::TrayCast(SystemTray* system_tray)
561 : SystemTrayItem(system_tray, UMA_CAST) { 552 : SystemTrayItem(system_tray, UMA_CAST) {
562 WmShell::Get()->AddShellObserver(this); 553 WmShell::Get()->AddShellObserver(this);
563 } 554 }
564 555
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 is_casting_ = started; 678 is_casting_ = started;
688 UpdatePrimaryView(); 679 UpdatePrimaryView();
689 } 680 }
690 681
691 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 682 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
692 if (tray_) 683 if (tray_)
693 tray_->UpdateAlignment(alignment); 684 tray_->UpdateAlignment(alignment);
694 } 685 }
695 686
696 } // namespace ash 687 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/common/system/chromeos/audio/audio_detailed_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698