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