| 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/system/cast/tray_cast.h" | 5 #include "ash/system/cast/tray_cast.h" |
| 6 | 6 |
| 7 #include "ash/session/session_state_delegate.h" | 7 #include "ash/session/session_state_delegate.h" |
| 8 #include "ash/shelf/shelf_types.h" | 8 #include "ash/shelf/shelf_types.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/system/chromeos/screen_security/screen_tray_item.h" | 10 #include "ash/system/chromeos/screen_security/screen_tray_item.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 // This view is displayed when the screen is actively being casted; it allows | 109 // This view is displayed when the screen is actively being casted; it allows |
| 110 // the user to easily stop casting. It fully replaces the | 110 // the user to easily stop casting. It fully replaces the |
| 111 // |CastSelectDefaultView| view inside of the |CastDuplexView|. | 111 // |CastSelectDefaultView| view inside of the |CastDuplexView|. |
| 112 class CastCastView : public views::View, public views::ButtonListener { | 112 class CastCastView : public views::View, public views::ButtonListener { |
| 113 public: | 113 public: |
| 114 explicit CastCastView(CastConfigDelegate* cast_config_delegate); | 114 explicit CastCastView(CastConfigDelegate* cast_config_delegate); |
| 115 ~CastCastView() override; | 115 ~CastCastView() override; |
| 116 | 116 |
| 117 void StopCasting(); |
| 118 |
| 117 // Updates the label for the stop view to include information about the | 119 // Updates the label for the stop view to include information about the |
| 118 // current device that is being casted. | 120 // current device that is being casted. |
| 119 void UpdateLabel(); | 121 void UpdateLabel(); |
| 120 | 122 |
| 121 private: | 123 private: |
| 122 void UpdateLabelCallback( | 124 void UpdateLabelCallback( |
| 123 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); | 125 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); |
| 124 | 126 |
| 125 // Overridden from views::View. | 127 // Overridden from views::View. |
| 126 int GetHeightForWidth(int width) const override; | 128 int GetHeightForWidth(int width) const override; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 201 |
| 200 // Adjust the label's bounds in case it got cut off by |stop_button_|. | 202 // Adjust the label's bounds in case it got cut off by |stop_button_|. |
| 201 if (label_->bounds().Intersects(stop_button_->bounds())) { | 203 if (label_->bounds().Intersects(stop_button_->bounds())) { |
| 202 gfx::Rect label_bounds = label_->bounds(); | 204 gfx::Rect label_bounds = label_->bounds(); |
| 203 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems - | 205 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems - |
| 204 label_->x()); | 206 label_->x()); |
| 205 label_->SetBoundsRect(label_bounds); | 207 label_->SetBoundsRect(label_bounds); |
| 206 } | 208 } |
| 207 } | 209 } |
| 208 | 210 |
| 211 void CastCastView::StopCasting() { |
| 212 cast_config_delegate_->StopCasting(); |
| 213 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 214 ash::UMA_STATUS_AREA_CAST_STOP_CAST); |
| 215 } |
| 216 |
| 209 void CastCastView::UpdateLabel() { | 217 void CastCastView::UpdateLabel() { |
| 210 if (cast_config_delegate_ == nullptr || | 218 if (cast_config_delegate_ == nullptr || |
| 211 cast_config_delegate_->HasCastExtension() == false) | 219 cast_config_delegate_->HasCastExtension() == false) |
| 212 return; | 220 return; |
| 213 | 221 |
| 214 cast_config_delegate_->GetReceiversAndActivities(base::Bind( | 222 cast_config_delegate_->GetReceiversAndActivities(base::Bind( |
| 215 &CastCastView::UpdateLabelCallback, weak_ptr_factory_.GetWeakPtr())); | 223 &CastCastView::UpdateLabelCallback, weak_ptr_factory_.GetWeakPtr())); |
| 216 } | 224 } |
| 217 | 225 |
| 218 void CastCastView::UpdateLabelCallback( | 226 void CastCastView::UpdateLabelCallback( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 238 PreferredSizeChanged(); | 246 PreferredSizeChanged(); |
| 239 Layout(); | 247 Layout(); |
| 240 break; | 248 break; |
| 241 } | 249 } |
| 242 } | 250 } |
| 243 } | 251 } |
| 244 | 252 |
| 245 void CastCastView::ButtonPressed(views::Button* sender, | 253 void CastCastView::ButtonPressed(views::Button* sender, |
| 246 const ui::Event& event) { | 254 const ui::Event& event) { |
| 247 DCHECK(sender == stop_button_); | 255 DCHECK(sender == stop_button_); |
| 248 cast_config_delegate_->StopCasting(); | 256 StopCasting(); |
| 249 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | |
| 250 ash::UMA_STATUS_AREA_CAST_STOP_CAST); | |
| 251 } | 257 } |
| 252 | 258 |
| 253 // This view by itself does very little. It acts as a front-end for managing | 259 // This view by itself does very little. It acts as a front-end for managing |
| 254 // which of the two child views (|CastSelectDefaultView| and |CastCastView|) | 260 // which of the two child views (|CastSelectDefaultView| and |CastCastView|) |
| 255 // is active. | 261 // is active. |
| 256 class CastDuplexView : public views::View { | 262 class CastDuplexView : public views::View { |
| 257 public: | 263 public: |
| 258 CastDuplexView(SystemTrayItem* owner, | 264 CastDuplexView(SystemTrayItem* owner, |
| 259 CastConfigDelegate* config_delegate, | 265 CastConfigDelegate* config_delegate, |
| 260 bool show_more); | 266 bool show_more); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 // This view displays a list of cast receivers that can be clicked on and casted | 387 // This view displays a list of cast receivers that can be clicked on and casted |
| 382 // to. It is activated by clicking on the chevron inside of | 388 // to. It is activated by clicking on the chevron inside of |
| 383 // |CastSelectDefaultView|. | 389 // |CastSelectDefaultView|. |
| 384 class CastDetailedView : public TrayDetailsView, public ViewClickListener { | 390 class CastDetailedView : public TrayDetailsView, public ViewClickListener { |
| 385 public: | 391 public: |
| 386 CastDetailedView(SystemTrayItem* owner, | 392 CastDetailedView(SystemTrayItem* owner, |
| 387 CastConfigDelegate* cast_config_delegate, | 393 CastConfigDelegate* cast_config_delegate, |
| 388 user::LoginStatus login); | 394 user::LoginStatus login); |
| 389 ~CastDetailedView() override; | 395 ~CastDetailedView() override; |
| 390 | 396 |
| 397 // Makes the detail view think the view associated with the given receiver_id |
| 398 // was clicked. This will start a cast. |
| 399 void SimulateViewClickedForTest(const std::string& receiver_id); |
| 400 |
| 391 private: | 401 private: |
| 392 void CreateItems(); | 402 void CreateItems(); |
| 393 | 403 |
| 394 void UpdateReceiverList(); | 404 void UpdateReceiverList(); |
| 395 void UpdateReceiverListCallback( | 405 void UpdateReceiverListCallback( |
| 396 const CastConfigDelegate::ReceiversAndActivites& | 406 const CastConfigDelegate::ReceiversAndActivites& |
| 397 new_receivers_and_activities); | 407 new_receivers_and_activities); |
| 398 void UpdateReceiverListFromCachedData(); | 408 void UpdateReceiverListFromCachedData(); |
| 399 views::View* AddToReceiverList( | 409 views::View* AddToReceiverList( |
| 400 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); | 410 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 423 cast_config_delegate_(cast_config_delegate), | 433 cast_config_delegate_(cast_config_delegate), |
| 424 login_(login), | 434 login_(login), |
| 425 weak_ptr_factory_(this) { | 435 weak_ptr_factory_(this) { |
| 426 CreateItems(); | 436 CreateItems(); |
| 427 UpdateReceiverList(); | 437 UpdateReceiverList(); |
| 428 } | 438 } |
| 429 | 439 |
| 430 CastDetailedView::~CastDetailedView() { | 440 CastDetailedView::~CastDetailedView() { |
| 431 } | 441 } |
| 432 | 442 |
| 443 void CastDetailedView::SimulateViewClickedForTest( |
| 444 const std::string& receiver_id) { |
| 445 for (auto& it : receiver_activity_map_) { |
| 446 if (it.second == receiver_id) { |
| 447 OnViewClicked(it.first); |
| 448 break; |
| 449 } |
| 450 } |
| 451 } |
| 452 |
| 433 void CastDetailedView::CreateItems() { | 453 void CastDetailedView::CreateItems() { |
| 434 CreateScrollableList(); | 454 CreateScrollableList(); |
| 435 AppendSettingsEntries(); | 455 AppendSettingsEntries(); |
| 436 AppendHeaderEntry(); | 456 AppendHeaderEntry(); |
| 437 } | 457 } |
| 438 | 458 |
| 439 void CastDetailedView::UpdateReceiverList() { | 459 void CastDetailedView::UpdateReceiverList() { |
| 440 cast_config_delegate_->GetReceiversAndActivities( | 460 cast_config_delegate_->GetReceiversAndActivities( |
| 441 base::Bind(&CastDetailedView::UpdateReceiverListCallback, | 461 base::Bind(&CastDetailedView::UpdateReceiverListCallback, |
| 442 weak_ptr_factory_.GetWeakPtr())); | 462 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 ->system_tray_delegate() | 561 ->system_tray_delegate() |
| 542 ->GetCastConfigDelegate()), | 562 ->GetCastConfigDelegate()), |
| 543 weak_ptr_factory_(this) { | 563 weak_ptr_factory_(this) { |
| 544 Shell::GetInstance()->AddShellObserver(this); | 564 Shell::GetInstance()->AddShellObserver(this); |
| 545 } | 565 } |
| 546 | 566 |
| 547 TrayCast::~TrayCast() { | 567 TrayCast::~TrayCast() { |
| 548 Shell::GetInstance()->RemoveShellObserver(this); | 568 Shell::GetInstance()->RemoveShellObserver(this); |
| 549 } | 569 } |
| 550 | 570 |
| 571 void TrayCast::StartCastForTest(const std::string& receiver_id) { |
| 572 if (detailed_ != nullptr) |
| 573 detailed_->SimulateViewClickedForTest(receiver_id); |
| 574 } |
| 575 |
| 576 void TrayCast::StopCastForTest() { |
| 577 default_->cast_view()->StopCasting(); |
| 578 } |
| 579 |
| 580 views::View* TrayCast::default_view() { |
| 581 return default_; |
| 582 } |
| 583 |
| 551 views::View* TrayCast::CreateTrayView(user::LoginStatus status) { | 584 views::View* TrayCast::CreateTrayView(user::LoginStatus status) { |
| 552 CHECK(tray_ == nullptr); | 585 CHECK(tray_ == nullptr); |
| 553 tray_ = new tray::CastTrayView(this); | 586 tray_ = new tray::CastTrayView(this); |
| 554 tray_->SetVisible(is_casting_); | 587 tray_->SetVisible(is_casting_); |
| 555 return tray_; | 588 return tray_; |
| 556 } | 589 } |
| 557 | 590 |
| 558 views::View* TrayCast::CreateDefaultView(user::LoginStatus status) { | 591 views::View* TrayCast::CreateDefaultView(user::LoginStatus status) { |
| 559 CHECK(default_ == nullptr); | 592 CHECK(default_ == nullptr); |
| 593 |
| 560 default_ = new tray::CastDuplexView(this, cast_config_delegate_, | 594 default_ = new tray::CastDuplexView(this, cast_config_delegate_, |
| 561 status != user::LOGGED_IN_LOCKED); | 595 status != user::LOGGED_IN_LOCKED); |
| 596 default_->set_id(TRAY_VIEW); |
| 597 default_->select_view()->set_id(SELECT_VIEW); |
| 598 default_->cast_view()->set_id(CAST_VIEW); |
| 599 |
| 562 UpdatePrimaryView(); | 600 UpdatePrimaryView(); |
| 563 return default_; | 601 return default_; |
| 564 } | 602 } |
| 565 | 603 |
| 566 views::View* TrayCast::CreateDetailedView(user::LoginStatus status) { | 604 views::View* TrayCast::CreateDetailedView(user::LoginStatus status) { |
| 567 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 605 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 568 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW); | 606 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW); |
| 569 CHECK(detailed_ == nullptr); | 607 CHECK(detailed_ == nullptr); |
| 570 detailed_ = new tray::CastDetailedView(this, cast_config_delegate_, status); | 608 detailed_ = new tray::CastDetailedView(this, cast_config_delegate_, status); |
| 571 return detailed_; | 609 return detailed_; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 is_casting_ = started; | 666 is_casting_ = started; |
| 629 UpdatePrimaryView(); | 667 UpdatePrimaryView(); |
| 630 } | 668 } |
| 631 | 669 |
| 632 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 670 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 633 if (tray_) | 671 if (tray_) |
| 634 tray_->UpdateAlignment(alignment); | 672 tray_->UpdateAlignment(alignment); |
| 635 } | 673 } |
| 636 | 674 |
| 637 } // namespace ash | 675 } // namespace ash |
| OLD | NEW |