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); |
261 ~CastDuplexView() override; | 267 ~CastDuplexView() override; |
262 | 268 |
263 // Activate either the casting or select view. | 269 // Activate either the casting or select view. |
264 void ActivateCastView(); | 270 void ActivateCastView(); |
265 void ActivateSelectView(); | 271 void ActivateSelectView(); |
266 | 272 |
267 CastSelectDefaultView* select_view() { return select_view_; } | 273 CastSelectDefaultView* select_view() { return select_view_; } |
268 CastCastView* cast_view() { return cast_view_; } | 274 CastCastView* cast_view() { return cast_view_; } |
269 | 275 |
276 // Only one of |select_view_| or |cast_view_| will be displayed at any given | |
277 // time. This will return the view is being displayed. | |
278 views::View* ActiveChildView(); | |
279 | |
270 private: | 280 private: |
271 // Overridden from views::View. | 281 // Overridden from views::View. |
272 void ChildPreferredSizeChanged(views::View* child) override; | 282 void ChildPreferredSizeChanged(views::View* child) override; |
273 void Layout() override; | 283 void Layout() override; |
274 | 284 |
275 // Only one of |select_view_| or |cast_view_| will be displayed at any given | |
276 // time. This will return the view is being displayed. | |
277 views::View* ActiveChildView(); | |
278 | |
279 CastSelectDefaultView* select_view_; | 285 CastSelectDefaultView* select_view_; |
280 CastCastView* cast_view_; | 286 CastCastView* cast_view_; |
281 | 287 |
282 DISALLOW_COPY_AND_ASSIGN(CastDuplexView); | 288 DISALLOW_COPY_AND_ASSIGN(CastDuplexView); |
283 }; | 289 }; |
284 | 290 |
285 CastDuplexView::CastDuplexView(SystemTrayItem* owner, | 291 CastDuplexView::CastDuplexView(SystemTrayItem* owner, |
286 CastConfigDelegate* config_delegate, | 292 CastConfigDelegate* config_delegate, |
287 bool show_more) { | 293 bool show_more) { |
288 select_view_ = new CastSelectDefaultView(owner, config_delegate, show_more); | 294 select_view_ = new CastSelectDefaultView(owner, config_delegate, show_more); |
(...skipping 92 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 void SimulateViewClickedForTest(const std::string& id); | |
achuithb
2015/07/14 18:06:39
I think it's worthwhile to add a function comment
jdufault
2015/07/15 17:35:01
Done.
| |
398 | |
391 private: | 399 private: |
392 void CreateItems(); | 400 void CreateItems(); |
393 | 401 |
394 void UpdateReceiverList(); | 402 void UpdateReceiverList(); |
395 void UpdateReceiverListCallback( | 403 void UpdateReceiverListCallback( |
396 const CastConfigDelegate::ReceiversAndActivites& | 404 const CastConfigDelegate::ReceiversAndActivites& |
397 new_receivers_and_activities); | 405 new_receivers_and_activities); |
398 void UpdateReceiverListFromCachedData(); | 406 void UpdateReceiverListFromCachedData(); |
399 views::View* AddToReceiverList( | 407 views::View* AddToReceiverList( |
400 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); | 408 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); |
(...skipping 22 matching lines...) Expand all Loading... | |
423 cast_config_delegate_(cast_config_delegate), | 431 cast_config_delegate_(cast_config_delegate), |
424 login_(login), | 432 login_(login), |
425 weak_ptr_factory_(this) { | 433 weak_ptr_factory_(this) { |
426 CreateItems(); | 434 CreateItems(); |
427 UpdateReceiverList(); | 435 UpdateReceiverList(); |
428 } | 436 } |
429 | 437 |
430 CastDetailedView::~CastDetailedView() { | 438 CastDetailedView::~CastDetailedView() { |
431 } | 439 } |
432 | 440 |
441 void CastDetailedView::SimulateViewClickedForTest(const std::string& id) { | |
442 for (auto& it : receiver_activity_map_) { | |
443 if (it.second == id) { | |
444 OnViewClicked(it.first); | |
445 break; | |
446 } | |
447 } | |
448 } | |
449 | |
433 void CastDetailedView::CreateItems() { | 450 void CastDetailedView::CreateItems() { |
434 CreateScrollableList(); | 451 CreateScrollableList(); |
435 AppendSettingsEntries(); | 452 AppendSettingsEntries(); |
436 AppendHeaderEntry(); | 453 AppendHeaderEntry(); |
437 } | 454 } |
438 | 455 |
439 void CastDetailedView::UpdateReceiverList() { | 456 void CastDetailedView::UpdateReceiverList() { |
440 cast_config_delegate_->GetReceiversAndActivities( | 457 cast_config_delegate_->GetReceiversAndActivities( |
441 base::Bind(&CastDetailedView::UpdateReceiverListCallback, | 458 base::Bind(&CastDetailedView::UpdateReceiverListCallback, |
442 weak_ptr_factory_.GetWeakPtr())); | 459 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 ->system_tray_delegate() | 558 ->system_tray_delegate() |
542 ->GetCastConfigDelegate()), | 559 ->GetCastConfigDelegate()), |
543 weak_ptr_factory_(this) { | 560 weak_ptr_factory_(this) { |
544 Shell::GetInstance()->AddShellObserver(this); | 561 Shell::GetInstance()->AddShellObserver(this); |
545 } | 562 } |
546 | 563 |
547 TrayCast::~TrayCast() { | 564 TrayCast::~TrayCast() { |
548 Shell::GetInstance()->RemoveShellObserver(this); | 565 Shell::GetInstance()->RemoveShellObserver(this); |
549 } | 566 } |
550 | 567 |
568 bool TrayCast::IsTrayInitializedForTest() const { | |
569 return default_ != nullptr; | |
570 } | |
571 | |
572 bool TrayCast::IsTrayVisibleForTest() const { | |
573 return default_ != nullptr && default_->IsDrawn(); | |
574 } | |
575 | |
576 bool TrayCast::IsTrayCastViewVisibleForTest() const { | |
577 return default_ != nullptr && | |
578 default_->ActiveChildView() == default_->cast_view(); | |
579 } | |
580 | |
581 bool TrayCast::IsTraySelectViewVisibleForTest() const { | |
582 return default_ != nullptr && | |
583 default_->ActiveChildView() == default_->select_view(); | |
584 } | |
585 | |
586 void TrayCast::StartCastForTest(const std::string& id) { | |
587 if (detailed_ != nullptr) | |
588 detailed_->SimulateViewClickedForTest(id); | |
589 } | |
590 | |
591 void TrayCast::StopCastForTest() { | |
592 default_->cast_view()->StopCasting(); | |
593 } | |
594 | |
551 views::View* TrayCast::CreateTrayView(user::LoginStatus status) { | 595 views::View* TrayCast::CreateTrayView(user::LoginStatus status) { |
552 CHECK(tray_ == nullptr); | 596 CHECK(tray_ == nullptr); |
553 tray_ = new tray::CastTrayView(this); | 597 tray_ = new tray::CastTrayView(this); |
554 tray_->SetVisible(is_casting_); | 598 tray_->SetVisible(is_casting_); |
555 return tray_; | 599 return tray_; |
556 } | 600 } |
557 | 601 |
558 views::View* TrayCast::CreateDefaultView(user::LoginStatus status) { | 602 views::View* TrayCast::CreateDefaultView(user::LoginStatus status) { |
559 CHECK(default_ == nullptr); | 603 CHECK(default_ == nullptr); |
560 default_ = new tray::CastDuplexView(this, cast_config_delegate_, | 604 default_ = new tray::CastDuplexView(this, cast_config_delegate_, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 is_casting_ = started; | 672 is_casting_ = started; |
629 UpdatePrimaryView(); | 673 UpdatePrimaryView(); |
630 } | 674 } |
631 | 675 |
632 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 676 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
633 if (tray_) | 677 if (tray_) |
634 tray_->UpdateAlignment(alignment); | 678 tray_->UpdateAlignment(alignment); |
635 } | 679 } |
636 | 680 |
637 } // namespace ash | 681 } // namespace ash |
OLD | NEW |