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 1218653006: Add support code to test the cast system tray item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 5 years, 5 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
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 "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
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
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
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
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
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
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
551 views::View* TrayCast::CreateTrayView(user::LoginStatus status) { 580 views::View* TrayCast::CreateTrayView(user::LoginStatus status) {
552 CHECK(tray_ == nullptr); 581 CHECK(tray_ == nullptr);
553 tray_ = new tray::CastTrayView(this); 582 tray_ = new tray::CastTrayView(this);
554 tray_->SetVisible(is_casting_); 583 tray_->SetVisible(is_casting_);
555 return tray_; 584 return tray_;
556 } 585 }
557 586
558 views::View* TrayCast::CreateDefaultView(user::LoginStatus status) { 587 views::View* TrayCast::CreateDefaultView(user::LoginStatus status) {
559 CHECK(default_ == nullptr); 588 CHECK(default_ == nullptr);
589
560 default_ = new tray::CastDuplexView(this, cast_config_delegate_, 590 default_ = new tray::CastDuplexView(this, cast_config_delegate_,
561 status != user::LOGGED_IN_LOCKED); 591 status != user::LOGGED_IN_LOCKED);
592 default_->set_id(TRAY_VIEW);
593 default_->select_view()->set_id(SELECT_VIEW);
594 default_->cast_view()->set_id(CAST_VIEW);
595
562 UpdatePrimaryView(); 596 UpdatePrimaryView();
563 return default_; 597 return default_;
564 } 598 }
565 599
566 views::View* TrayCast::CreateDetailedView(user::LoginStatus status) { 600 views::View* TrayCast::CreateDetailedView(user::LoginStatus status) {
567 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 601 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
568 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW); 602 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW);
569 CHECK(detailed_ == nullptr); 603 CHECK(detailed_ == nullptr);
570 detailed_ = new tray::CastDetailedView(this, cast_config_delegate_, status); 604 detailed_ = new tray::CastDetailedView(this, cast_config_delegate_, status);
571 return detailed_; 605 return detailed_;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 is_casting_ = started; 662 is_casting_ = started;
629 UpdatePrimaryView(); 663 UpdatePrimaryView();
630 } 664 }
631 665
632 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 666 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
633 if (tray_) 667 if (tray_)
634 tray_->UpdateAlignment(alignment); 668 tray_->UpdateAlignment(alignment);
635 } 669 }
636 670
637 } // namespace ash 671 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698