Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/cast/tray_cast.h" | |
| 6 | |
| 7 #include "ash/cast_config_delegate.h" | |
| 8 #include "ash/session/session_state_delegate.h" | |
| 9 #include "ash/shelf/shelf_types.h" | |
| 10 #include "ash/shell.h" | |
| 11 #include "ash/system/chromeos/screen_security/screen_tray_item.h" | |
| 12 #include "ash/system/tray/fixed_sized_image_view.h" | |
| 13 #include "ash/system/tray/fixed_sized_scroll_view.h" | |
| 14 #include "ash/system/tray/hover_highlight_view.h" | |
| 15 #include "ash/system/tray/system_tray.h" | |
| 16 #include "ash/system/tray/system_tray_delegate.h" | |
| 17 #include "ash/system/tray/system_tray_notifier.h" | |
| 18 #include "ash/system/tray/throbber_view.h" | |
| 19 #include "ash/system/tray/tray_constants.h" | |
| 20 #include "ash/system/tray/tray_details_view.h" | |
| 21 #include "ash/system/tray/tray_item_more.h" | |
| 22 #include "ash/system/tray/tray_item_view.h" | |
| 23 #include "ash/system/tray/tray_popup_label_button.h" | |
| 24 #include "base/bind.h" | |
| 25 #include "grit/ash_resources.h" | |
| 26 #include "grit/ash_strings.h" | |
| 27 #include "ui/base/l10n/l10n_util.h" | |
| 28 #include "ui/base/resource/resource_bundle.h" | |
| 29 #include "ui/gfx/image/image.h" | |
| 30 #include "ui/views/controls/button/button.h" | |
| 31 #include "ui/views/controls/image_view.h" | |
| 32 #include "ui/views/controls/label.h" | |
| 33 #include "ui/views/layout/box_layout.h" | |
| 34 #include "ui/views/layout/fill_layout.h" | |
| 35 | |
| 36 namespace ash { | |
| 37 | |
| 38 namespace { | |
| 39 const int kStopButtonRightPadding = 18; | |
| 40 | |
| 41 // Callback helper for StopCast(). | |
| 42 void StopCastCallback( | |
| 43 CastConfigDelegate* cast_config, | |
| 44 const CastConfigDelegate::ReceiversAndActivites& receivers_activities) { | |
| 45 for (auto& item : receivers_activities) { | |
| 46 CastConfigDelegate::Activity activity = item.second.activity; | |
| 47 if (activity.allow_stop && activity.id.empty() == false) | |
| 48 cast_config->StopCasting(activity.id); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 // Invoking this function will cause the device to stop casting. | |
|
achuithb
2015/05/06 21:28:15
Maybe
// Stops currently casting device.
jdufault
2015/05/06 22:26:16
Done.
| |
| 53 void StopCast() { | |
| 54 CastConfigDelegate* cast_config = | |
| 55 Shell::GetInstance()->system_tray_delegate()->GetCastConfigDelegate(); | |
| 56 if (cast_config && cast_config->HasCastExtension()) { | |
| 57 cast_config->GetReceiversAndActivities( | |
| 58 base::Bind(&StopCastCallback, cast_config)); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 } // namespace | |
| 63 | |
| 64 namespace tray { | |
| 65 | |
| 66 // This view is displayed in the system tray when the cast extension is active. | |
| 67 // It asks the user if they want to cast the desktop. If they click on the | |
| 68 // chevron, then a detail view will replace this view where the user will | |
| 69 // actually pick the cast receiver. | |
| 70 class CastSelectDefaultView : public TrayItemMore { | |
| 71 public: | |
| 72 CastSelectDefaultView(SystemTrayItem* owner, | |
| 73 CastConfigDelegate* cast_config_delegate, | |
| 74 bool show_more); | |
| 75 ~CastSelectDefaultView() override; | |
| 76 | |
| 77 // Updates the label based on the current set of receivers (if there are or | |
| 78 // are not any available receivers). | |
| 79 void UpdateLabel(); | |
| 80 | |
| 81 private: | |
| 82 void UpdateLabelCallback( | |
| 83 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); | |
| 84 | |
| 85 CastConfigDelegate* cast_config_delegate_; | |
| 86 DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView); | |
| 87 }; | |
| 88 | |
| 89 CastSelectDefaultView::CastSelectDefaultView( | |
| 90 SystemTrayItem* owner, | |
| 91 CastConfigDelegate* cast_config_delegate, | |
| 92 bool show_more) | |
| 93 : TrayItemMore(owner, show_more), | |
| 94 cast_config_delegate_(cast_config_delegate) { | |
| 95 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 96 SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia()); | |
| 97 | |
| 98 // We first set a default label before we actually know what the label will | |
| 99 // be, because it could take awhile before UpdateLabel() actually applies | |
| 100 // the correct label. | |
| 101 SetLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_NO_DEVICE)); | |
| 102 UpdateLabel(); | |
| 103 } | |
| 104 | |
| 105 CastSelectDefaultView::~CastSelectDefaultView() { | |
| 106 } | |
| 107 | |
| 108 void CastSelectDefaultView::UpdateLabelCallback( | |
| 109 const CastConfigDelegate::ReceiversAndActivites& receivers_activities) { | |
| 110 // The label needs to reflect if there are no cast receivers | |
| 111 const base::string16 label = | |
| 112 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | |
| 113 receivers_activities.empty() ? IDS_ASH_STATUS_TRAY_CAST_NO_DEVICE | |
| 114 : IDS_ASH_STATUS_TRAY_CAST_DESKTOP); | |
| 115 SetLabel(label); | |
| 116 SetAccessibleName(label); | |
| 117 SetVisible(true); | |
| 118 } | |
| 119 | |
| 120 void CastSelectDefaultView::UpdateLabel() { | |
| 121 if (cast_config_delegate_ == nullptr || | |
| 122 cast_config_delegate_->HasCastExtension() == false) | |
| 123 return; | |
| 124 | |
| 125 cast_config_delegate_->GetReceiversAndActivities(base::Bind( | |
| 126 &CastSelectDefaultView::UpdateLabelCallback, base::Unretained(this))); | |
| 127 } | |
| 128 | |
| 129 // This view is displayed when the screen is actively being casted; it allows | |
| 130 // the user to easily stop casting. It fully replaces the | |
| 131 // |CastSelectDefaultView| view inside of the |CastDuplexView|. | |
| 132 class CastCastView : public views::View, public views::ButtonListener { | |
| 133 public: | |
| 134 explicit CastCastView(CastConfigDelegate* cast_config_delegate); | |
| 135 ~CastCastView() override; | |
| 136 | |
| 137 // Updates the label for the stop view to include information about the | |
| 138 // current device that is being casted. | |
| 139 void UpdateLabel(); | |
| 140 | |
| 141 private: | |
| 142 void UpdateLabelCallback( | |
| 143 const CastConfigDelegate::ReceiversAndActivites& receivers_activities); | |
| 144 | |
| 145 // Overridden from views::View. | |
| 146 void Layout() override; | |
| 147 // Overridden from views::ButtonListener | |
| 148 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 149 | |
| 150 CastConfigDelegate* cast_config_delegate_; | |
| 151 views::ImageView* icon_; | |
| 152 views::View* label_container_; | |
| 153 views::Label* title_; | |
| 154 views::Label* details_; | |
| 155 TrayPopupLabelButton* stop_button_; | |
| 156 | |
| 157 DISALLOW_COPY_AND_ASSIGN(CastCastView); | |
| 158 }; | |
| 159 | |
| 160 CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate) | |
| 161 : cast_config_delegate_(cast_config_delegate) { | |
| 162 // We will initialize the primary tray view which shows a stop button here. | |
| 163 | |
| 164 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | |
| 165 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 166 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | |
| 167 kTrayPopupPaddingHorizontal, 0, | |
| 168 kTrayPopupPaddingBetweenItems)); | |
| 169 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); | |
| 170 icon_->SetImage( | |
| 171 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia()); | |
| 172 AddChildView(icon_); | |
| 173 | |
| 174 // The view has two labels, one above the other. The top label (|title_|) | |
| 175 // specifies that we are, say, "Casting desktop". The bottom label | |
| 176 // (|details_|) specifies where we are casting to, ie, "SomeRandom cast" | |
| 177 label_container_ = new views::View; | |
| 178 label_container_->SetLayoutManager( | |
| 179 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 180 | |
| 181 title_ = new views::Label; | |
| 182 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 183 title_->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); | |
| 184 label_container_->AddChildView(title_); | |
| 185 | |
| 186 details_ = new views::Label; | |
| 187 details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 188 details_->SetMultiLine(false); | |
| 189 details_->SetEnabledColor(kHeaderTextColorNormal); | |
| 190 label_container_->AddChildView(details_); | |
| 191 | |
| 192 AddChildView(label_container_); | |
| 193 | |
| 194 // Add the stop bottom on the far-right. We customize how this stop button is | |
| 195 // displayed inside of |Layout()|. | |
| 196 base::string16 stop_button_text = | |
| 197 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | |
| 198 IDS_ASH_STATUS_TRAY_CAST_STOP); | |
| 199 stop_button_ = new TrayPopupLabelButton(this, stop_button_text); | |
| 200 AddChildView(stop_button_); | |
| 201 | |
| 202 UpdateLabel(); | |
| 203 } | |
| 204 | |
| 205 CastCastView::~CastCastView() { | |
| 206 } | |
| 207 | |
| 208 void CastCastView::Layout() { | |
| 209 views::View::Layout(); | |
| 210 | |
| 211 // Give the stop button the space it requests. | |
| 212 gfx::Size stop_size = stop_button_->GetPreferredSize(); | |
| 213 gfx::Rect stop_bounds(stop_size); | |
| 214 stop_bounds.set_x(width() - stop_size.width() - kStopButtonRightPadding); | |
| 215 stop_bounds.set_y((height() - stop_size.height()) / 2); | |
| 216 stop_button_->SetBoundsRect(stop_bounds); | |
| 217 | |
| 218 // Adjust the label's bounds in case it got cut off by |stop_button_|. | |
| 219 if (label_container_->bounds().Intersects(stop_button_->bounds())) { | |
| 220 gfx::Rect label_bounds = label_container_->bounds(); | |
| 221 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems - | |
| 222 label_container_->x()); | |
| 223 label_container_->SetBoundsRect(label_bounds); | |
| 224 } | |
| 225 | |
| 226 // Center the label. | |
| 227 // TODO(jdufault): Why doesn't this happen automatically? | |
| 228 const int extra_height = | |
| 229 height() - label_container_->GetPreferredSize().height(); | |
| 230 label_container_->SetY(extra_height / 2); | |
| 231 } | |
| 232 | |
| 233 void CastCastView::UpdateLabel() { | |
| 234 if (cast_config_delegate_ == nullptr || | |
| 235 cast_config_delegate_->HasCastExtension() == false) | |
| 236 return; | |
| 237 | |
| 238 cast_config_delegate_->GetReceiversAndActivities( | |
| 239 base::Bind(&CastCastView::UpdateLabelCallback, base::Unretained(this))); | |
| 240 } | |
| 241 | |
| 242 void CastCastView::UpdateLabelCallback( | |
| 243 const CastConfigDelegate::ReceiversAndActivites& receivers_activities) { | |
| 244 for (auto& i : receivers_activities) { | |
| 245 const CastConfigDelegate::Receiver receiver = i.second.receiver; | |
| 246 const CastConfigDelegate::Activity activity = i.second.activity; | |
| 247 if (!activity.id.empty()) { | |
| 248 // We want to display different labels inside of the title depending on | |
| 249 // what we are actually casting - either the desktop, a tab, or a fallback | |
| 250 // that catches everything else (ie, an extension tab). | |
| 251 if (activity.tab_id == CastConfigDelegate::Activity::TabId::DESKTOP) { | |
| 252 title_->SetText( | |
| 253 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_CAST_CAST_DESKTOP)); | |
| 254 } else if (activity.tab_id >= 0) { | |
| 255 title_->SetText(l10n_util::GetStringFUTF16( | |
| 256 IDS_ASH_STATUS_TRAY_CAST_CAST_TAB, activity.title)); | |
| 257 } else { | |
| 258 // We will fallback to whatever the extension provides us | |
| 259 title_->SetText(activity.title); | |
| 260 } | |
| 261 | |
| 262 details_->SetText(receiver.name); | |
| 263 Layout(); | |
| 264 break; | |
| 265 } | |
| 266 } | |
| 267 } | |
| 268 | |
| 269 void CastCastView::ButtonPressed(views::Button* sender, | |
| 270 const ui::Event& event) { | |
| 271 DCHECK(sender == stop_button_); | |
| 272 StopCast(); | |
| 273 } | |
| 274 | |
| 275 // This view by itself does very little. It acts as a front-end for managing | |
| 276 // which of the two child views (|CastSelectDefaultView| and |CastCastView|) | |
| 277 // is active. | |
| 278 class CastDuplexView : public views::View { | |
| 279 public: | |
| 280 CastDuplexView(SystemTrayItem* owner, | |
| 281 CastConfigDelegate* config_delegate, | |
| 282 bool show_more); | |
| 283 ~CastDuplexView() override; | |
| 284 | |
| 285 // Activate either the casting or select view. | |
| 286 void ActivateCastView(); | |
| 287 void ActivateSelectView(); | |
| 288 | |
| 289 CastSelectDefaultView* select_view() { return select_view_; } | |
| 290 CastCastView* cast_view() { return cast_view_; } | |
| 291 | |
| 292 private: | |
| 293 // Overridden from views::View. | |
| 294 void Layout() override; | |
| 295 | |
| 296 CastSelectDefaultView* select_view_; | |
| 297 CastCastView* cast_view_; | |
| 298 | |
| 299 DISALLOW_COPY_AND_ASSIGN(CastDuplexView); | |
| 300 }; | |
| 301 | |
| 302 CastDuplexView::CastDuplexView(SystemTrayItem* owner, | |
| 303 CastConfigDelegate* config_delegate, | |
| 304 bool show_more) { | |
| 305 select_view_ = new CastSelectDefaultView(owner, config_delegate, show_more); | |
| 306 cast_view_ = new CastCastView(config_delegate); | |
| 307 SetLayoutManager(new views::FillLayout()); | |
| 308 AddChildView(select_view_); | |
| 309 AddChildView(cast_view_); | |
| 310 | |
| 311 ActivateSelectView(); | |
| 312 } | |
| 313 | |
| 314 CastDuplexView::~CastDuplexView() { | |
| 315 } | |
| 316 | |
| 317 void CastDuplexView::ActivateCastView() { | |
| 318 select_view_->SetVisible(false); | |
| 319 cast_view_->SetVisible(true); | |
| 320 InvalidateLayout(); | |
| 321 } | |
| 322 | |
| 323 void CastDuplexView::ActivateSelectView() { | |
| 324 select_view_->SetVisible(true); | |
| 325 cast_view_->SetVisible(false); | |
| 326 InvalidateLayout(); | |
| 327 } | |
| 328 | |
| 329 void CastDuplexView::Layout() { | |
| 330 views::View::Layout(); | |
| 331 | |
| 332 if (select_view_->IsDrawn()) | |
| 333 select_view_->SetBoundsRect(GetContentsBounds()); | |
| 334 if (cast_view_->IsDrawn()) | |
| 335 cast_view_->SetBoundsRect(GetContentsBounds()); | |
| 336 } | |
| 337 | |
| 338 // Exposes an icon in the tray. |TrayCast| manages the visiblity of this. | |
| 339 class CastTrayView : public TrayItemView { | |
| 340 public: | |
| 341 CastTrayView(SystemTrayItem* tray_item); | |
| 342 ~CastTrayView() override; | |
| 343 | |
| 344 // Called when the tray alignment changes so that the icon can recenter | |
| 345 // itself. | |
| 346 void UpdateAlignment(ShelfAlignment alignment); | |
| 347 | |
| 348 private: | |
| 349 DISALLOW_COPY_AND_ASSIGN(CastTrayView); | |
| 350 }; | |
| 351 | |
| 352 CastTrayView::CastTrayView(SystemTrayItem* tray_item) | |
| 353 : TrayItemView(tray_item) { | |
| 354 CreateImageView(); | |
| 355 | |
| 356 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | |
| 357 .GetImageNamed(IDR_AURA_UBER_TRAY_CAST_STATUS) | |
| 358 .ToImageSkia()); | |
| 359 } | |
| 360 | |
| 361 CastTrayView::~CastTrayView() { | |
| 362 } | |
| 363 | |
| 364 void CastTrayView::UpdateAlignment(ShelfAlignment alignment) { | |
| 365 // Center the item dependent on the orientation of the shelf. | |
| 366 views::BoxLayout::Orientation layout = views::BoxLayout::kHorizontal; | |
| 367 switch (alignment) { | |
| 368 case ash::SHELF_ALIGNMENT_BOTTOM: | |
| 369 case ash::SHELF_ALIGNMENT_TOP: | |
| 370 layout = views::BoxLayout::kHorizontal; | |
| 371 break; | |
| 372 case ash::SHELF_ALIGNMENT_LEFT: | |
| 373 case ash::SHELF_ALIGNMENT_RIGHT: | |
| 374 layout = views::BoxLayout::kVertical; | |
| 375 break; | |
| 376 } | |
| 377 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); | |
| 378 Layout(); | |
| 379 } | |
| 380 | |
| 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_; | |
| 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 | |
| 415 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); | |
| 416 }; | |
| 417 | |
| 418 CastDetailedView::CastDetailedView(SystemTrayItem* owner, | |
| 419 CastConfigDelegate* cast_config_delegate, | |
| 420 user::LoginStatus login) | |
| 421 : TrayDetailsView(owner), | |
| 422 cast_config_delegate_(cast_config_delegate), | |
| 423 login_(login), | |
| 424 options_(nullptr) { | |
| 425 CreateItems(); | |
| 426 UpdateReceiverList(); | |
| 427 } | |
| 428 | |
| 429 CastDetailedView::~CastDetailedView() { | |
| 430 } | |
| 431 | |
| 432 void CastDetailedView::CreateItems() { | |
| 433 CreateScrollableList(); | |
| 434 AppendSettingsEntries(); | |
| 435 AppendHeaderEntry(); | |
| 436 } | |
| 437 | |
| 438 void CastDetailedView::UpdateReceiverList() { | |
| 439 cast_config_delegate_->GetReceiversAndActivities(base::Bind( | |
| 440 &CastDetailedView::UpdateReceiverListCallback, base::Unretained(this))); | |
| 441 } | |
| 442 | |
| 443 void CastDetailedView::UpdateReceiverListCallback( | |
| 444 const CastConfigDelegate::ReceiversAndActivites& | |
| 445 new_receivers_and_activities) { | |
| 446 // Add/update existing. | |
| 447 for (auto i = new_receivers_and_activities.begin(); | |
| 448 i != new_receivers_and_activities.end(); ++i) { | |
| 449 receivers_and_activities_[i->first] = i->second; | |
| 450 } | |
| 451 // Remove non-existent. | |
| 452 for (auto i = receivers_and_activities_.begin(); | |
| 453 i != receivers_and_activities_.end(); ++i) { | |
| 454 if (new_receivers_and_activities.count(i->first) == 0) | |
| 455 receivers_and_activities_.erase(i->first); | |
| 456 } | |
| 457 | |
| 458 // Update UI. | |
| 459 UpdateReceiverListFromCachedData(); | |
| 460 Layout(); | |
| 461 } | |
| 462 | |
| 463 void CastDetailedView::UpdateReceiverListFromCachedData() { | |
| 464 // Remove all of the existing views. | |
| 465 receiver_activity_map_.clear(); | |
| 466 scroll_content()->RemoveAllChildViews(true); | |
| 467 | |
| 468 // Add a view for each receiver. | |
| 469 for (auto& it : receivers_and_activities_) { | |
| 470 const CastConfigDelegate::ReceiverAndActivity& receiver_activity = | |
| 471 it.second; | |
| 472 views::View* container = AddToReceiverList(receiver_activity); | |
| 473 receiver_activity_map_[container] = it.first; | |
| 474 } | |
| 475 | |
| 476 scroll_content()->SizeToPreferredSize(); | |
| 477 static_cast<views::View*>(scroller())->Layout(); | |
| 478 } | |
| 479 | |
| 480 views::View* CastDetailedView::AddToReceiverList( | |
| 481 const CastConfigDelegate::ReceiverAndActivity& receiverActivity) { | |
| 482 auto container = new HoverHighlightView(this); | |
|
jennyz
2015/05/12 21:10:21
nit: Prefer using explicit type HoverHighlightView
achuithb
2015/05/12 21:13:39
+1
jdufault
2015/05/14 19:47:11
Done.
| |
| 483 | |
| 484 const gfx::ImageSkia* image = | |
| 485 ui::ResourceBundle::GetSharedInstance() | |
| 486 .GetImageNamed(IDR_AURA_UBER_TRAY_CAST_DEVICE_ICON) | |
| 487 .ToImageSkia(); | |
| 488 const base::string16& name = receiverActivity.receiver.name; | |
| 489 container->AddIndentedIconAndLabel(*image, name, false); | |
| 490 | |
| 491 scroll_content()->AddChildView(container); | |
| 492 return container; | |
| 493 } | |
| 494 | |
| 495 void CastDetailedView::AppendSettingsEntries() { | |
| 496 // Settings requires a browser window, hide it for non logged in user. | |
| 497 const bool userAddingRunning = Shell::GetInstance() | |
| 498 ->session_state_delegate() | |
| 499 ->IsInSecondaryLoginScreen(); | |
| 500 | |
| 501 if (login_ == user::LOGGED_IN_NONE || login_ == user::LOGGED_IN_LOCKED || | |
| 502 userAddingRunning) | |
| 503 return; | |
| 504 | |
| 505 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 506 HoverHighlightView* container = new HoverHighlightView(this); | |
| 507 container->AddLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_OPTIONS), | |
| 508 gfx::ALIGN_LEFT, false /* highlight */); | |
| 509 | |
| 510 AddChildView(container); | |
| 511 options_ = container; | |
| 512 } | |
| 513 | |
| 514 void CastDetailedView::AppendHeaderEntry() { | |
| 515 CreateSpecialRow(IDS_ASH_STATUS_TRAY_CAST, this); | |
| 516 } | |
| 517 | |
| 518 void CastDetailedView::OnViewClicked(views::View* sender) { | |
| 519 if (sender == footer()->content()) { | |
| 520 TransitionToDefaultView(); | |
| 521 } else if (sender == options_) { | |
| 522 cast_config_delegate_->LaunchCastOptions(); | |
| 523 } else { | |
| 524 // Find the receiver we are going to cast to | |
| 525 auto it = receiver_activity_map_.find(sender); | |
| 526 if (it != receiver_activity_map_.end()) { | |
| 527 cast_config_delegate_->CastToReceiver(it->second); | |
| 528 } | |
| 529 } | |
| 530 } | |
| 531 | |
| 532 } // namespace tray | |
| 533 | |
| 534 TrayCast::TrayCast(SystemTray* system_tray) | |
| 535 : SystemTrayItem(system_tray), | |
| 536 cast_config_delegate_(ash::Shell::GetInstance() | |
| 537 ->system_tray_delegate() | |
| 538 ->GetCastConfigDelegate()) { | |
| 539 Shell::GetInstance()->AddShellObserver(this); | |
| 540 } | |
| 541 | |
| 542 TrayCast::~TrayCast() { | |
| 543 Shell::GetInstance()->RemoveShellObserver(this); | |
| 544 } | |
| 545 | |
| 546 views::View* TrayCast::CreateTrayView(user::LoginStatus status) { | |
| 547 CHECK(tray_ == nullptr); | |
| 548 tray_ = new tray::CastTrayView(this); | |
| 549 tray_->SetVisible(is_casting_); | |
| 550 return tray_; | |
| 551 } | |
| 552 | |
| 553 views::View* TrayCast::CreateDefaultView(user::LoginStatus status) { | |
| 554 CHECK(default_ == nullptr); | |
| 555 default_ = new tray::CastDuplexView(this, cast_config_delegate_, | |
| 556 status != user::LOGGED_IN_LOCKED); | |
| 557 UpdatePrimaryView(); | |
| 558 return default_; | |
| 559 } | |
| 560 | |
| 561 views::View* TrayCast::CreateDetailedView(user::LoginStatus status) { | |
| 562 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | |
| 563 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW); | |
| 564 CHECK(detailed_ == nullptr); | |
| 565 detailed_ = new tray::CastDetailedView(this, cast_config_delegate_, status); | |
| 566 return detailed_; | |
| 567 } | |
| 568 | |
| 569 void TrayCast::DestroyTrayView() { | |
| 570 tray_ = nullptr; | |
| 571 } | |
| 572 | |
| 573 void TrayCast::DestroyDefaultView() { | |
| 574 default_ = nullptr; | |
| 575 } | |
| 576 | |
| 577 void TrayCast::DestroyDetailedView() { | |
| 578 detailed_ = nullptr; | |
| 579 } | |
| 580 | |
| 581 bool TrayCast::HasCastExtension() { | |
| 582 return cast_config_delegate_ != nullptr && | |
| 583 cast_config_delegate_->HasCastExtension(); | |
| 584 } | |
| 585 | |
| 586 void TrayCast::UpdatePrimaryView() { | |
| 587 if (HasCastExtension() == false) { | |
| 588 if (default_) | |
| 589 default_->SetVisible(false); | |
| 590 if (tray_) { | |
| 591 base::MessageLoopForUI::current()->PostTask( | |
| 592 FROM_HERE, base::Bind(&tray::CastTrayView::SetVisible, | |
| 593 base::Unretained(tray_), false)); | |
| 594 } | |
| 595 } else { | |
| 596 if (default_) { | |
| 597 if (is_casting_ == false) { | |
|
jennyz
2015/05/12 21:10:21
nit, only one line in bracket, don't need "{...}".
achuithb
2015/05/12 21:13:39
Thanks for pointing this out - I glossed over it.
jdufault
2015/05/14 19:47:11
Done.
| |
| 598 default_->ActivateSelectView(); | |
| 599 } else { | |
| 600 default_->ActivateCastView(); | |
| 601 } | |
| 602 } | |
| 603 | |
| 604 if (tray_) { | |
|
jennyz
2015/05/12 21:10:21
ditto.
jdufault
2015/05/14 19:47:11
Done.
| |
| 605 tray_->SetVisible(is_casting_); | |
| 606 } | |
| 607 } | |
| 608 } | |
| 609 | |
| 610 void TrayCast::OnCastingSessionStartedOrStopped(bool started) { | |
| 611 is_casting_ = started; | |
| 612 UpdatePrimaryView(); | |
| 613 } | |
| 614 | |
| 615 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | |
| 616 if (tray_) | |
| 617 tray_->UpdateAlignment(alignment); | |
| 618 } | |
| 619 | |
| 620 } // namespace ash | |
| OLD | NEW |