| 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" |
| 11 #include "ash/system/tray/fixed_sized_image_view.h" | 11 #include "ash/system/tray/fixed_sized_image_view.h" |
| 12 #include "ash/system/tray/fixed_sized_scroll_view.h" | 12 #include "ash/system/tray/fixed_sized_scroll_view.h" |
| 13 #include "ash/system/tray/hover_highlight_view.h" | 13 #include "ash/system/tray/hover_highlight_view.h" |
| 14 #include "ash/system/tray/system_tray.h" | 14 #include "ash/system/tray/system_tray.h" |
| 15 #include "ash/system/tray/system_tray_delegate.h" | 15 #include "ash/system/tray/system_tray_delegate.h" |
| 16 #include "ash/system/tray/system_tray_notifier.h" | 16 #include "ash/system/tray/system_tray_notifier.h" |
| 17 #include "ash/system/tray/throbber_view.h" | 17 #include "ash/system/tray/throbber_view.h" |
| 18 #include "ash/system/tray/tray_constants.h" | 18 #include "ash/system/tray/tray_constants.h" |
| 19 #include "ash/system/tray/tray_details_view.h" | |
| 20 #include "ash/system/tray/tray_item_more.h" | |
| 21 #include "ash/system/tray/tray_item_view.h" | 19 #include "ash/system/tray/tray_item_view.h" |
| 22 #include "ash/system/tray/tray_popup_label_button.h" | |
| 23 #include "base/bind.h" | 20 #include "base/bind.h" |
| 24 #include "grit/ash_resources.h" | 21 #include "grit/ash_resources.h" |
| 25 #include "grit/ash_strings.h" | 22 #include "grit/ash_strings.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 29 #include "ui/views/controls/button/button.h" | |
| 30 #include "ui/views/controls/image_view.h" | 26 #include "ui/views/controls/image_view.h" |
| 31 #include "ui/views/controls/label.h" | 27 #include "ui/views/controls/label.h" |
| 32 #include "ui/views/layout/box_layout.h" | 28 #include "ui/views/layout/box_layout.h" |
| 33 #include "ui/views/layout/fill_layout.h" | 29 #include "ui/views/layout/fill_layout.h" |
| 34 | 30 |
| 35 namespace ash { | 31 namespace ash { |
| 36 | 32 |
| 37 namespace { | 33 namespace { |
| 38 const int kStopButtonRightPadding = 18; | 34 const int kStopButtonRightPadding = 18; |
| 39 } // namespace | 35 } // namespace |
| 40 | 36 |
| 41 namespace tray { | 37 namespace tray { |
| 42 | 38 |
| 43 // This view is displayed in the system tray when the cast extension is active. | |
| 44 // It asks the user if they want to cast the desktop. If they click on the | |
| 45 // chevron, then a detail view will replace this view where the user will | |
| 46 // actually pick the cast receiver. | |
| 47 class CastSelectDefaultView : public TrayItemMore { | |
| 48 public: | |
| 49 CastSelectDefaultView(SystemTrayItem* owner, | |
| 50 CastConfigDelegate* cast_config_delegate, | |
| 51 bool show_more); | |
| 52 ~CastSelectDefaultView() override; | |
| 53 | |
| 54 // Updates the label based on the current set of receivers (if there are or | |
| 55 // are not any available receivers). | |
| 56 void UpdateLabel(); | |
| 57 | |
| 58 private: | |
| 59 void UpdateLabelCallback( | |
| 60 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); | |
| 61 | |
| 62 CastConfigDelegate* cast_config_delegate_; | |
| 63 base::WeakPtrFactory<CastSelectDefaultView> weak_ptr_factory_; | |
| 64 DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView); | |
| 65 }; | |
| 66 | |
| 67 CastSelectDefaultView::CastSelectDefaultView( | 39 CastSelectDefaultView::CastSelectDefaultView( |
| 68 SystemTrayItem* owner, | 40 SystemTrayItem* owner, |
| 69 CastConfigDelegate* cast_config_delegate, | 41 CastConfigDelegate* cast_config_delegate, |
| 70 bool show_more) | 42 bool show_more) |
| 71 : TrayItemMore(owner, show_more), | 43 : TrayItemMore(owner, show_more), |
| 72 cast_config_delegate_(cast_config_delegate), | 44 cast_config_delegate_(cast_config_delegate), |
| 73 weak_ptr_factory_(this) { | 45 weak_ptr_factory_(this) { |
| 74 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 46 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 75 SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia()); | 47 SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia()); |
| 76 | 48 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 99 void CastSelectDefaultView::UpdateLabel() { | 71 void CastSelectDefaultView::UpdateLabel() { |
| 100 if (cast_config_delegate_ == nullptr || | 72 if (cast_config_delegate_ == nullptr || |
| 101 cast_config_delegate_->HasCastExtension() == false) | 73 cast_config_delegate_->HasCastExtension() == false) |
| 102 return; | 74 return; |
| 103 | 75 |
| 104 cast_config_delegate_->GetReceiversAndActivities( | 76 cast_config_delegate_->GetReceiversAndActivities( |
| 105 base::Bind(&CastSelectDefaultView::UpdateLabelCallback, | 77 base::Bind(&CastSelectDefaultView::UpdateLabelCallback, |
| 106 weak_ptr_factory_.GetWeakPtr())); | 78 weak_ptr_factory_.GetWeakPtr())); |
| 107 } | 79 } |
| 108 | 80 |
| 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 | |
| 111 // |CastSelectDefaultView| view inside of the |CastDuplexView|. | |
| 112 class CastCastView : public views::View, public views::ButtonListener { | |
| 113 public: | |
| 114 explicit CastCastView(CastConfigDelegate* cast_config_delegate); | |
| 115 ~CastCastView() override; | |
| 116 | |
| 117 // Updates the label for the stop view to include information about the | |
| 118 // current device that is being casted. | |
| 119 void UpdateLabel(); | |
| 120 | |
| 121 private: | |
| 122 void UpdateLabelCallback( | |
| 123 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); | |
| 124 | |
| 125 // Overridden from views::View. | |
| 126 int GetHeightForWidth(int width) const override; | |
| 127 void Layout() override; | |
| 128 | |
| 129 // Overridden from views::ButtonListener. | |
| 130 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 131 | |
| 132 CastConfigDelegate* cast_config_delegate_; | |
| 133 views::ImageView* icon_; | |
| 134 views::Label* label_; | |
| 135 TrayPopupLabelButton* stop_button_; | |
| 136 base::WeakPtrFactory<CastCastView> weak_ptr_factory_; | |
| 137 | |
| 138 DISALLOW_COPY_AND_ASSIGN(CastCastView); | |
| 139 }; | |
| 140 | |
| 141 CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate) | 81 CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate) |
| 142 : cast_config_delegate_(cast_config_delegate), weak_ptr_factory_(this) { | 82 : cast_config_delegate_(cast_config_delegate), weak_ptr_factory_(this) { |
| 143 // We will initialize the primary tray view which shows a stop button here. | 83 // We will initialize the primary tray view which shows a stop button here. |
| 144 | 84 |
| 145 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 85 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 146 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 86 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 147 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 87 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 148 kTrayPopupPaddingHorizontal, 0, | 88 kTrayPopupPaddingHorizontal, 0, |
| 149 kTrayPopupPaddingBetweenItems)); | 89 kTrayPopupPaddingBetweenItems)); |
| 150 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); | 90 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 139 |
| 200 // Adjust the label's bounds in case it got cut off by |stop_button_|. | 140 // Adjust the label's bounds in case it got cut off by |stop_button_|. |
| 201 if (label_->bounds().Intersects(stop_button_->bounds())) { | 141 if (label_->bounds().Intersects(stop_button_->bounds())) { |
| 202 gfx::Rect label_bounds = label_->bounds(); | 142 gfx::Rect label_bounds = label_->bounds(); |
| 203 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems - | 143 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems - |
| 204 label_->x()); | 144 label_->x()); |
| 205 label_->SetBoundsRect(label_bounds); | 145 label_->SetBoundsRect(label_bounds); |
| 206 } | 146 } |
| 207 } | 147 } |
| 208 | 148 |
| 149 void CastCastView::StopCasting() { |
| 150 cast_config_delegate_->StopCasting(); |
| 151 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 152 ash::UMA_STATUS_AREA_CAST_STOP_CAST); |
| 153 } |
| 154 |
| 209 void CastCastView::UpdateLabel() { | 155 void CastCastView::UpdateLabel() { |
| 210 if (cast_config_delegate_ == nullptr || | 156 if (cast_config_delegate_ == nullptr || |
| 211 cast_config_delegate_->HasCastExtension() == false) | 157 cast_config_delegate_->HasCastExtension() == false) |
| 212 return; | 158 return; |
| 213 | 159 |
| 214 cast_config_delegate_->GetReceiversAndActivities(base::Bind( | 160 cast_config_delegate_->GetReceiversAndActivities(base::Bind( |
| 215 &CastCastView::UpdateLabelCallback, weak_ptr_factory_.GetWeakPtr())); | 161 &CastCastView::UpdateLabelCallback, weak_ptr_factory_.GetWeakPtr())); |
| 216 } | 162 } |
| 217 | 163 |
| 218 void CastCastView::UpdateLabelCallback( | 164 void CastCastView::UpdateLabelCallback( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 238 PreferredSizeChanged(); | 184 PreferredSizeChanged(); |
| 239 Layout(); | 185 Layout(); |
| 240 break; | 186 break; |
| 241 } | 187 } |
| 242 } | 188 } |
| 243 } | 189 } |
| 244 | 190 |
| 245 void CastCastView::ButtonPressed(views::Button* sender, | 191 void CastCastView::ButtonPressed(views::Button* sender, |
| 246 const ui::Event& event) { | 192 const ui::Event& event) { |
| 247 DCHECK(sender == stop_button_); | 193 DCHECK(sender == stop_button_); |
| 248 cast_config_delegate_->StopCasting(); | 194 StopCasting(); |
| 249 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | |
| 250 ash::UMA_STATUS_AREA_CAST_STOP_CAST); | |
| 251 } | 195 } |
| 252 | 196 |
| 253 // 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|) | |
| 255 // is active. | |
| 256 class CastDuplexView : public views::View { | |
| 257 public: | |
| 258 CastDuplexView(SystemTrayItem* owner, | |
| 259 CastConfigDelegate* config_delegate, | |
| 260 bool show_more); | |
| 261 ~CastDuplexView() override; | |
| 262 | |
| 263 // Activate either the casting or select view. | |
| 264 void ActivateCastView(); | |
| 265 void ActivateSelectView(); | |
| 266 | |
| 267 CastSelectDefaultView* select_view() { return select_view_; } | |
| 268 CastCastView* cast_view() { return cast_view_; } | |
| 269 | |
| 270 private: | |
| 271 // Overridden from views::View. | |
| 272 void ChildPreferredSizeChanged(views::View* child) override; | |
| 273 void Layout() override; | |
| 274 | |
| 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_; | |
| 280 CastCastView* cast_view_; | |
| 281 | |
| 282 DISALLOW_COPY_AND_ASSIGN(CastDuplexView); | |
| 283 }; | |
| 284 | |
| 285 CastDuplexView::CastDuplexView(SystemTrayItem* owner, | 197 CastDuplexView::CastDuplexView(SystemTrayItem* owner, |
| 286 CastConfigDelegate* config_delegate, | 198 CastConfigDelegate* config_delegate, |
| 287 bool show_more) { | 199 bool show_more) { |
| 288 select_view_ = new CastSelectDefaultView(owner, config_delegate, show_more); | 200 select_view_ = new CastSelectDefaultView(owner, config_delegate, show_more); |
| 289 cast_view_ = new CastCastView(config_delegate); | 201 cast_view_ = new CastCastView(config_delegate); |
| 290 SetLayoutManager(new views::FillLayout()); | 202 SetLayoutManager(new views::FillLayout()); |
| 291 | 203 |
| 292 ActivateSelectView(); | 204 ActivateSelectView(); |
| 293 } | 205 } |
| 294 | 206 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 break; | 283 break; |
| 372 case ash::SHELF_ALIGNMENT_LEFT: | 284 case ash::SHELF_ALIGNMENT_LEFT: |
| 373 case ash::SHELF_ALIGNMENT_RIGHT: | 285 case ash::SHELF_ALIGNMENT_RIGHT: |
| 374 layout = views::BoxLayout::kVertical; | 286 layout = views::BoxLayout::kVertical; |
| 375 break; | 287 break; |
| 376 } | 288 } |
| 377 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); | 289 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); |
| 378 Layout(); | 290 Layout(); |
| 379 } | 291 } |
| 380 | 292 |
| 381 // 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 | |
| 383 // |CastSelectDefaultView|. | |
| 384 class CastDetailedView : public TrayDetailsView, public ViewClickListener { | |
| 385 public: | |
| 386 CastDetailedView(SystemTrayItem* owner, | |
| 387 CastConfigDelegate* cast_config_delegate, | |
| 388 user::LoginStatus login); | |
| 389 ~CastDetailedView() override; | |
| 390 | |
| 391 private: | |
| 392 void CreateItems(); | |
| 393 | |
| 394 void UpdateReceiverList(); | |
| 395 void UpdateReceiverListCallback( | |
| 396 const CastConfigDelegate::ReceiversAndActivites& | |
| 397 new_receivers_and_activities); | |
| 398 void UpdateReceiverListFromCachedData(); | |
| 399 views::View* AddToReceiverList( | |
| 400 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); | |
| 401 | |
| 402 void AppendSettingsEntries(); | |
| 403 void AppendHeaderEntry(); | |
| 404 | |
| 405 // Overridden from ViewClickListener. | |
| 406 void OnViewClicked(views::View* sender) override; | |
| 407 | |
| 408 CastConfigDelegate* cast_config_delegate_; | |
| 409 user::LoginStatus login_; | |
| 410 views::View* options_ = nullptr; | |
| 411 CastConfigDelegate::ReceiversAndActivites receivers_and_activities_; | |
| 412 // A mapping from the view pointer to the associated activity id | |
| 413 std::map<views::View*, std::string> receiver_activity_map_; | |
| 414 base::WeakPtrFactory<CastDetailedView> weak_ptr_factory_; | |
| 415 | |
| 416 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); | |
| 417 }; | |
| 418 | |
| 419 CastDetailedView::CastDetailedView(SystemTrayItem* owner, | 293 CastDetailedView::CastDetailedView(SystemTrayItem* owner, |
| 420 CastConfigDelegate* cast_config_delegate, | 294 CastConfigDelegate* cast_config_delegate, |
| 421 user::LoginStatus login) | 295 user::LoginStatus login) |
| 422 : TrayDetailsView(owner), | 296 : TrayDetailsView(owner), |
| 423 cast_config_delegate_(cast_config_delegate), | 297 cast_config_delegate_(cast_config_delegate), |
| 424 login_(login), | 298 login_(login), |
| 425 weak_ptr_factory_(this) { | 299 weak_ptr_factory_(this) { |
| 426 CreateItems(); | 300 CreateItems(); |
| 427 UpdateReceiverList(); | 301 UpdateReceiverList(); |
| 428 } | 302 } |
| 429 | 303 |
| 430 CastDetailedView::~CastDetailedView() { | 304 CastDetailedView::~CastDetailedView() { |
| 431 } | 305 } |
| 432 | 306 |
| 307 void CastDetailedView::SimulateViewClickedForTest( |
| 308 const std::string& receiver_id) { |
| 309 for (auto& it : receiver_activity_map_) { |
| 310 if (it.second == receiver_id) { |
| 311 OnViewClicked(it.first); |
| 312 break; |
| 313 } |
| 314 } |
| 315 } |
| 316 |
| 433 void CastDetailedView::CreateItems() { | 317 void CastDetailedView::CreateItems() { |
| 434 CreateScrollableList(); | 318 CreateScrollableList(); |
| 435 AppendSettingsEntries(); | 319 AppendSettingsEntries(); |
| 436 AppendHeaderEntry(); | 320 AppendHeaderEntry(); |
| 437 } | 321 } |
| 438 | 322 |
| 439 void CastDetailedView::UpdateReceiverList() { | 323 void CastDetailedView::UpdateReceiverList() { |
| 440 cast_config_delegate_->GetReceiversAndActivities( | 324 cast_config_delegate_->GetReceiversAndActivities( |
| 441 base::Bind(&CastDetailedView::UpdateReceiverListCallback, | 325 base::Bind(&CastDetailedView::UpdateReceiverListCallback, |
| 442 weak_ptr_factory_.GetWeakPtr())); | 326 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 is_casting_ = started; | 512 is_casting_ = started; |
| 629 UpdatePrimaryView(); | 513 UpdatePrimaryView(); |
| 630 } | 514 } |
| 631 | 515 |
| 632 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 516 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 633 if (tray_) | 517 if (tray_) |
| 634 tray_->UpdateAlignment(alignment); | 518 tray_->UpdateAlignment(alignment); |
| 635 } | 519 } |
| 636 | 520 |
| 637 } // namespace ash | 521 } // namespace ash |
| OLD | NEW |