Index: ash/system/cast/tray_cast.cc |
diff --git a/ash/system/cast/tray_cast.cc b/ash/system/cast/tray_cast.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c5264cffd187910e31fdb59632754d4a7025d6c3 |
--- /dev/null |
+++ b/ash/system/cast/tray_cast.cc |
@@ -0,0 +1,595 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/system/cast/tray_cast.h" |
+ |
+#include "ash/cast_config_delegate.h" |
+#include "ash/session/session_state_delegate.h" |
+#include "ash/shelf/shelf_types.h" |
+#include "ash/shell.h" |
+#include "ash/system/chromeos/screen_security/screen_tray_item.h" |
+#include "ash/system/tray/fixed_sized_image_view.h" |
+#include "ash/system/tray/fixed_sized_scroll_view.h" |
+#include "ash/system/tray/hover_highlight_view.h" |
+#include "ash/system/tray/system_tray.h" |
+#include "ash/system/tray/system_tray_delegate.h" |
+#include "ash/system/tray/system_tray_notifier.h" |
+#include "ash/system/tray/throbber_view.h" |
+#include "ash/system/tray/tray_constants.h" |
+#include "ash/system/tray/tray_details_view.h" |
+#include "ash/system/tray/tray_item_more.h" |
+#include "ash/system/tray/tray_item_view.h" |
+#include "ash/system/tray/tray_popup_label_button.h" |
+#include "base/bind.h" |
+#include "grit/ash_resources.h" |
+#include "grit/ash_strings.h" |
+#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/gfx/image/image.h" |
+#include "ui/views/controls/button/button.h" |
+#include "ui/views/controls/image_view.h" |
+#include "ui/views/controls/label.h" |
+#include "ui/views/layout/box_layout.h" |
+#include "ui/views/layout/fill_layout.h" |
+ |
+namespace { |
+const int kStopButtonRightPadding = 18; |
+} // namespace |
+ |
+namespace ash { |
+namespace tray { |
+ |
+static void StopCastCallback( |
+ CastConfigDelegate* cast_config, |
+ const CastConfigDelegate::ReceiversAndActivites& receivers_activities) { |
+ for (auto& item : receivers_activities) { |
+ auto activity = item.second.activity; |
achuithb
2015/04/30 00:03:31
Let's spell out the type of activity here
jdufault
2015/04/30 21:51:03
Done.
|
+ if (activity.allow_stop && activity.id.empty() == false) { |
achuithb
2015/04/30 00:03:32
Don't need {} here
jdufault
2015/04/30 21:51:03
Done.
|
+ cast_config->StopCasting(activity.id); |
+ } |
+ } |
+} |
+ |
+static void StopCast() { |
+ auto cast_config = |
achuithb
2015/04/30 00:03:32
Let's spell out the type of cast_config here
jdufault
2015/04/30 21:51:03
Done.
|
+ Shell::GetInstance()->system_tray_delegate()->GetCastConfigDelegate(); |
+ if (cast_config && cast_config->HasCastExtension()) { |
+ cast_config->GetReceiversAndActivities( |
+ base::Bind(&StopCastCallback, cast_config)); |
+ } |
+} |
+ |
+class CastSelectDefaultView : public TrayItemMore { |
achuithb
2015/04/30 00:03:31
Class comment here
jdufault
2015/04/30 21:51:03
Done.
|
+ public: |
+ CastSelectDefaultView(SystemTrayItem* owner, |
+ CastConfigDelegate* cast_config_delegate, |
+ bool show_more); |
+ ~CastSelectDefaultView() override; |
+ |
+ void UpdateLabel(); |
achuithb
2015/04/30 00:03:32
Function comment for all public functions
jdufault
2015/04/30 21:51:04
Done.
|
+ |
+ private: |
+ void UpdateLabelCallback( |
+ const CastConfigDelegate::ReceiversAndActivites& receivers_activities); |
+ |
+ CastConfigDelegate* cast_config_delegate_; |
+ DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView); |
+}; |
+ |
+class CastCastView : public views::View, public views::ButtonListener { |
achuithb
2015/04/30 00:03:32
Class comment
jdufault
2015/04/30 21:51:03
Done.
|
+ public: |
+ CastCastView(CastConfigDelegate* cast_config_delegate); |
achuithb
2015/04/30 00:03:32
explicit
jdufault
2015/04/30 21:51:03
Done.
|
+ ~CastCastView() override; |
+ |
+ void UpdateLabel(); |
achuithb
2015/04/30 00:03:32
Comment
jdufault
2015/04/30 21:51:03
Done.
|
+ |
+ private: |
+ void UpdateLabelCallback( |
+ const CastConfigDelegate::ReceiversAndActivites& receivers_activities); |
+ |
+ // Overridden from views::View. |
+ void Layout() override; |
+ // Overridden from views::ButtonListener |
+ void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
+ |
+ CastConfigDelegate* cast_config_delegate_; |
+ views::ImageView* icon_; |
+ views::View* label_container_; |
+ views::Label* title_; |
+ views::Label* details_; |
+ TrayPopupLabelButton* stop_button_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CastCastView); |
+}; |
+ |
+CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate) |
+ : cast_config_delegate_(cast_config_delegate) { |
+ set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
+ SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
+ kTrayPopupPaddingHorizontal, 0, |
+ kTrayPopupPaddingBetweenItems)); |
+ icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); |
+ icon_->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia()); |
+ AddChildView(icon_); |
+ |
+ label_container_ = new views::View; |
+ label_container_->SetLayoutManager( |
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
+ |
+ title_ = new views::Label; |
+ title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ title_->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); |
+ label_container_->AddChildView(title_); |
+ |
+ details_ = new views::Label; |
+ details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ details_->SetMultiLine(false); |
+ details_->SetEnabledColor(kHeaderTextColorNormal); |
+ label_container_->AddChildView(details_); |
+ |
+ AddChildView(label_container_); |
+ |
+ auto stop_button_text = |
achuithb
2015/04/30 00:03:32
Spell out the type here
jdufault
2015/04/30 21:51:04
Done.
|
+ ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
+ IDS_ASH_STATUS_TRAY_CAST_STOP); |
+ stop_button_ = new TrayPopupLabelButton(this, stop_button_text); |
+ AddChildView(stop_button_); |
+ |
+ UpdateLabel(); |
+} |
+ |
+CastCastView::~CastCastView() { |
+} |
+ |
+void CastCastView::Layout() { |
+ views::View::Layout(); |
+ |
+ // Give the stop button the space it requests. |
+ gfx::Size stop_size = stop_button_->GetPreferredSize(); |
+ gfx::Rect stop_bounds(stop_size); |
+ stop_bounds.set_x(width() - stop_size.width() - kStopButtonRightPadding); |
+ stop_bounds.set_y((height() - stop_size.height()) / 2); |
+ stop_button_->SetBoundsRect(stop_bounds); |
+ |
+ // Adjust the label's bounds in case it got cut off by |stop_button_|. |
+ if (label_container_->bounds().Intersects(stop_button_->bounds())) { |
+ gfx::Rect label_bounds = label_container_->bounds(); |
+ label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems - |
+ label_container_->x()); |
+ label_container_->SetBoundsRect(label_bounds); |
+ } |
+ |
+ // Center the label |
achuithb
2015/04/30 00:03:31
Period at the end of comment.
jdufault
2015/04/30 21:51:04
Done.
|
+ // TODO(jdufault): Why doesn't this happen automatically? |
+ auto extra_height = height() - label_container_->GetPreferredSize().height(); |
+ label_container_->SetY(extra_height / 2); |
+} |
+ |
+void CastCastView::UpdateLabel() { |
+ if (cast_config_delegate_ == nullptr || |
+ cast_config_delegate_->HasCastExtension() == false) |
+ return; |
+ |
+ cast_config_delegate_->GetReceiversAndActivities( |
+ base::Bind(&CastCastView::UpdateLabelCallback, base::Unretained(this))); |
+} |
+ |
+void CastCastView::UpdateLabelCallback( |
+ const CastConfigDelegate::ReceiversAndActivites& receivers_activities) { |
+ for (auto& i : receivers_activities) { |
+ auto receiver = i.second.receiver; |
achuithb
2015/04/30 00:03:32
Spell out the types of receiver and activity here.
jdufault
2015/04/30 21:51:04
Done.
|
+ auto activity = i.second.activity; |
+ if (activity.id.empty() == false) { |
achuithb
2015/04/30 00:03:32
if (!activity.id.empty()) is a more common constru
jdufault
2015/04/30 21:51:03
Done.
|
+ title_->SetText(activity.title); |
+ details_->SetText(l10n_util::GetStringFUTF16( |
+ IDS_ASH_STATUS_TRAY_CAST_ACTIVE_DETAIL, receiver.name)); |
+ |
achuithb
2015/04/30 00:03:32
unnecessary newline.
jdufault
2015/04/30 21:51:03
Done.
|
+ Layout(); |
+ return; |
achuithb
2015/04/30 00:03:32
You don't need this return
jdufault
2015/04/30 21:51:04
Changed to break; it expresses intent that we only
|
+ } |
+ } |
+} |
+ |
+void CastCastView::ButtonPressed(views::Button* sender, |
+ const ui::Event& event) { |
+ DCHECK(sender == stop_button_); |
+ StopCast(); |
+} |
+ |
+class CastDuplexView : public views::View { |
achuithb
2015/04/30 00:03:32
class comment.
jdufault
2015/04/30 21:51:03
Done.
|
+ public: |
+ CastDuplexView(SystemTrayItem* owner, |
+ CastConfigDelegate* config_delegate, |
+ bool show_more); |
+ ~CastDuplexView() override; |
+ |
+ // Activate either the casting or select view. |
+ void ActivateCastView(); |
+ void ActivateSelectView(); |
+ |
+ CastSelectDefaultView* select_view() { return select_view_; } |
+ CastCastView* cast_view() { return cast_view_; } |
+ |
+ // Overridden from views::View. |
achuithb
2015/04/30 00:03:32
Make this private
jdufault
2015/04/30 21:51:04
Done.
|
+ void Layout() override; |
+ |
+ private: |
+ CastSelectDefaultView* select_view_; |
+ CastCastView* cast_view_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CastDuplexView); |
+}; |
+ |
+CastDuplexView::CastDuplexView(SystemTrayItem* owner, |
+ CastConfigDelegate* config_delegate, |
+ bool show_more) { |
+ select_view_ = new CastSelectDefaultView(owner, config_delegate, show_more); |
+ cast_view_ = new CastCastView(config_delegate); |
+ SetLayoutManager(new views::FillLayout()); |
+ AddChildView(select_view_); |
+ AddChildView(cast_view_); |
+ |
+ ActivateSelectView(); |
+} |
+ |
+CastDuplexView::~CastDuplexView() { |
+} |
+ |
+void CastDuplexView::ActivateCastView() { |
+ select_view_->SetVisible(false); |
+ cast_view_->SetVisible(true); |
+ InvalidateLayout(); |
+} |
+ |
+void CastDuplexView::ActivateSelectView() { |
+ select_view_->SetVisible(true); |
+ cast_view_->SetVisible(false); |
+ InvalidateLayout(); |
+} |
+ |
+void CastDuplexView::Layout() { |
+ views::View::Layout(); |
+ |
+ if (select_view_->IsDrawn()) |
+ select_view_->SetBoundsRect(GetContentsBounds()); |
+ if (cast_view_->IsDrawn()) |
+ cast_view_->SetBoundsRect(GetContentsBounds()); |
+} |
+ |
+class CastTrayView : public TrayItemView { |
achuithb
2015/04/30 00:03:32
class comment
jdufault
2015/04/30 21:51:03
Done.
|
+ public: |
+ CastTrayView(SystemTrayItem* tray_item); |
+ ~CastTrayView() override; |
+ void UpdateAlignment(ShelfAlignment alignment); |
achuithb
2015/04/30 00:03:31
Add new line and function comment
jdufault
2015/04/30 21:51:03
Done.
|
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(CastTrayView); |
+}; |
+ |
+CastTrayView::CastTrayView(SystemTrayItem* tray_item) |
+ : TrayItemView(tray_item) { |
+ CreateImageView(); |
+ |
+ auto& rb = ui::ResourceBundle::GetSharedInstance(); |
achuithb
2015/04/30 00:03:32
Spell out type of rb
jdufault
2015/04/30 21:51:03
Removed |rb|, folded into the call
|
+ image_view()->SetImage( |
+ rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_STATUS).ToImageSkia()); |
+} |
+ |
+CastTrayView::~CastTrayView() { |
+} |
+ |
+void CastTrayView::UpdateAlignment(ShelfAlignment alignment) { |
+ // Center the item dependent on the orientation of the shelf. |
+ views::BoxLayout::Orientation layout = views::BoxLayout::kHorizontal; |
+ switch (alignment) { |
+ case ash::SHELF_ALIGNMENT_BOTTOM: |
+ case ash::SHELF_ALIGNMENT_TOP: |
+ layout = views::BoxLayout::kHorizontal; |
+ break; |
+ case ash::SHELF_ALIGNMENT_LEFT: |
+ case ash::SHELF_ALIGNMENT_RIGHT: |
+ layout = views::BoxLayout::kVertical; |
+ break; |
+ } |
+ SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); |
+ Layout(); |
+} |
+ |
+CastSelectDefaultView::CastSelectDefaultView( |
achuithb
2015/04/30 00:03:31
Shouldn't this be right after the class definition
jdufault
2015/04/30 21:51:03
Done.
|
+ SystemTrayItem* owner, |
+ CastConfigDelegate* cast_config_delegate, |
+ bool show_more) |
+ : TrayItemMore(owner, show_more), |
+ cast_config_delegate_(cast_config_delegate) { |
+ auto& rb = ui::ResourceBundle::GetSharedInstance(); |
+ SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia()); |
+ |
+ // We first set a default label before we actually know what the label will |
+ // be, because it could take awhile before UpdateLabel() actually applies |
+ // the correct label. |
+ // TODO(jdufault): What should the default label be? |
+ SetLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_NO_DEVICE)); |
+ UpdateLabel(); |
+} |
+ |
+CastSelectDefaultView::~CastSelectDefaultView() { |
+} |
+ |
+void CastSelectDefaultView::UpdateLabelCallback( |
+ const CastConfigDelegate::ReceiversAndActivites& receivers_activities) { |
+ // The label needs to reflect if there are no cast receivers |
+ const base::string16 label = |
+ ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
+ receivers_activities.empty() ? IDS_ASH_STATUS_TRAY_CAST_NO_DEVICE |
+ : IDS_ASH_STATUS_TRAY_CAST_DESKTOP); |
+ SetLabel(label); |
+ SetAccessibleName(label); |
+ SetVisible(true); |
+} |
+ |
+void CastSelectDefaultView::UpdateLabel() { |
+ if (cast_config_delegate_ == nullptr || |
+ cast_config_delegate_->HasCastExtension() == false) |
+ return; |
+ |
+ cast_config_delegate_->GetReceiversAndActivities(base::Bind( |
+ &CastSelectDefaultView::UpdateLabelCallback, base::Unretained(this))); |
+} |
+ |
+class CastDetailedView : public TrayDetailsView, public ViewClickListener { |
achuithb
2015/04/30 00:03:32
class comment
jdufault
2015/04/30 21:51:03
Done.
|
+ public: |
+ CastDetailedView(SystemTrayItem* owner, |
+ CastConfigDelegate* cast_config_delegate, |
+ user::LoginStatus login); |
+ ~CastDetailedView() override; |
+ |
+ void Update(); |
achuithb
2015/04/30 00:03:32
function comment
jdufault
2015/04/30 21:51:04
Done.
|
+ |
+ private: |
+ void CreateItems(); |
+ void UpdateCastReceiverList(const CastConfigDelegate::ReceiversAndActivites& |
+ new_receivers_and_activities); |
+ void AppendHeaderEntry(); |
+ |
+ void UpdateReceiverScrollList(); |
+ views::View* AddReceiverToList( |
+ const CastConfigDelegate::ReceiverAndActivity& receiverActivity); |
+ |
+ // Add settings entries. |
+ void AppendSettingsEntries(); |
+ // Overridden from ViewClickListener. |
+ void OnViewClicked(views::View* sender) override; |
+ |
+ CastConfigDelegate* cast_config_delegate_; |
+ user::LoginStatus login_; |
+ views::View* options_; |
+ CastConfigDelegate::ReceiversAndActivites receivers_and_activities_; |
+ // A mapping from the view pointer to the associated activity id |
+ std::map<views::View*, std::string> receiver_activity_map_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CastDetailedView); |
+}; |
+ |
+CastDetailedView::CastDetailedView(SystemTrayItem* owner, |
+ CastConfigDelegate* cast_config_delegate, |
+ user::LoginStatus login) |
+ : TrayDetailsView(owner), |
+ cast_config_delegate_(cast_config_delegate), |
+ login_(login), |
+ options_(nullptr) { |
+ CreateItems(); |
+ Update(); |
+} |
+ |
+CastDetailedView::~CastDetailedView() { |
+} |
+ |
+void CastDetailedView::Update() { |
+ cast_config_delegate_->GetReceiversAndActivities(base::Bind( |
+ &CastDetailedView::UpdateCastReceiverList, base::Unretained(this))); |
+} |
+ |
+void CastDetailedView::UpdateCastReceiverList( |
+ const CastConfigDelegate::ReceiversAndActivites& |
+ new_receivers_and_activities) { |
+ // Add/update existing. |
+ for (auto i = new_receivers_and_activities.begin(); |
+ i != new_receivers_and_activities.end(); ++i) { |
+ receivers_and_activities_[i->first] = i->second; |
+ } |
+ // Remove non-existent. |
+ for (auto i = receivers_and_activities_.begin(); |
+ i != receivers_and_activities_.end(); ++i) { |
+ if (new_receivers_and_activities.count(i->first) == 0) |
+ receivers_and_activities_.erase(i->first); |
+ } |
+ |
+ // Update UI. |
+ UpdateReceiverScrollList(); |
+ Layout(); |
+} |
+ |
+void CastDetailedView::CreateItems() { |
+ CreateScrollableList(); |
+ AppendSettingsEntries(); |
+ AppendHeaderEntry(); |
+} |
+ |
+void CastDetailedView::AppendHeaderEntry() { |
+ CreateSpecialRow(IDS_ASH_STATUS_TRAY_CAST, this); |
+} |
+ |
+void CastDetailedView::UpdateReceiverScrollList() { |
+ // Remove all of the existing views |
achuithb
2015/04/30 00:03:32
period at end of comment.
jdufault
2015/04/30 21:51:03
Done.
|
+ receiver_activity_map_.clear(); |
+ scroll_content()->RemoveAllChildViews(true); |
+ |
+ // Add a view for each receiver |
achuithb
2015/04/30 00:03:32
same
jdufault
2015/04/30 21:51:03
Done.
|
+ for (auto& it : receivers_and_activities_) { |
+ const CastConfigDelegate::ReceiverAndActivity& receiver_activity = |
+ it.second; |
+ auto container = AddReceiverToList(receiver_activity); |
achuithb
2015/04/30 00:03:31
spell out type
jdufault
2015/04/30 21:51:03
Done.
|
+ receiver_activity_map_[container] = it.first; |
+ } |
+ |
+ scroll_content()->SizeToPreferredSize(); |
+ static_cast<views::View*>(scroller())->Layout(); |
+} |
+ |
+views::View* CastDetailedView::AddReceiverToList( |
+ const CastConfigDelegate::ReceiverAndActivity& receiverActivity) { |
+ auto container = new HoverHighlightView(this); |
achuithb
2015/04/30 00:03:32
spell out type
jdufault
2015/04/30 21:51:04
It is within the line, clearly HoverHighlightView
|
+ |
+ const gfx::ImageSkia* image = |
+ ui::ResourceBundle::GetSharedInstance() |
+ .GetImageNamed(IDR_AURA_UBER_TRAY_CAST_DEVICE_ICON) |
+ .ToImageSkia(); |
+ auto& name = receiverActivity.receiver.name; |
achuithb
2015/04/30 00:03:32
spell out type
jdufault
2015/04/30 21:51:03
Done.
|
+ container->AddIndentedIconAndLabel(*image, name, false); |
+ |
+ scroll_content()->AddChildView(container); |
+ return container; |
+} |
+ |
+// Add settings entries. |
+void CastDetailedView::AppendSettingsEntries() { |
+ // Settings requires a browser window, hide it for non logged in user. |
+ bool userAddingRunning = Shell::GetInstance() |
achuithb
2015/04/30 00:03:32
const bool
jdufault
2015/04/30 21:51:03
Done.
|
+ ->session_state_delegate() |
+ ->IsInSecondaryLoginScreen(); |
+ |
+ if (login_ == user::LOGGED_IN_NONE || login_ == user::LOGGED_IN_LOCKED || |
+ userAddingRunning) |
+ return; |
+ |
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
+ HoverHighlightView* container = new HoverHighlightView(this); |
+ container->AddLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_OPTIONS), |
+ gfx::ALIGN_LEFT, false /* highlight */); |
+ |
+ AddChildView(container); |
+ options_ = container; |
+} |
+ |
+void CastDetailedView::OnViewClicked(views::View* sender) { |
+ if (sender == footer()->content()) { |
+ TransitionToDefaultView(); |
+ } else if (sender == options_) { |
+ cast_config_delegate_->LaunchCastOptions(); |
+ } else { |
+ // Find the receiver we are going to cast to |
+ auto it = receiver_activity_map_.find(sender); |
+ if (it != receiver_activity_map_.end()) { |
+ // TODO(jdufault): Should this cast the desktop instead of showing a |
+ // popup? |
+ cast_config_delegate_->CastToReceiver(it->second); |
+ // TODO(jdufault): Should we transition to the default view? |
+ } |
+ } |
+} |
+ |
+} // namespace tray |
+ |
+TrayCast::TrayCast(SystemTray* system_tray) |
+ : SystemTrayItem(system_tray), |
+ is_casting_(false), |
+ tray_(nullptr), |
+ default_(nullptr), |
+ detailed_(nullptr), |
+ cast_config_delegate_(ash::Shell::GetInstance() |
+ ->system_tray_delegate() |
+ ->GetCastConfigDelegate()) { |
+ Shell::GetInstance()->AddShellObserver(this); |
+ Shell::GetInstance()->system_tray_notifier()->AddCastObserver(this); |
+} |
+ |
+TrayCast::~TrayCast() { |
+ Shell::GetInstance()->RemoveShellObserver(this); |
+ Shell::GetInstance()->system_tray_notifier()->RemoveCastObserver(this); |
+} |
+ |
+void TrayCast::OnCastRefresh() { |
+ if (default_) { |
+ default_->select_view()->UpdateLabel(); |
+ default_->cast_view()->UpdateLabel(); |
+ } else if (detailed_) |
+ detailed_->Update(); |
+} |
+ |
+views::View* TrayCast::CreateTrayView(user::LoginStatus status) { |
+ CHECK(tray_ == nullptr); |
+ tray_ = new tray::CastTrayView(this); |
+ tray_->SetVisible(is_casting_); |
+ return tray_; |
+} |
+ |
+views::View* TrayCast::CreateDefaultView(user::LoginStatus status) { |
+ CHECK(default_ == nullptr); |
+ default_ = new tray::CastDuplexView(this, cast_config_delegate_, |
+ status != user::LOGGED_IN_LOCKED); |
+ UpdatePrimaryView(); |
+ return default_; |
+} |
+ |
+views::View* TrayCast::CreateDetailedView(user::LoginStatus status) { |
+ Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
+ ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW); |
+ CHECK(detailed_ == nullptr); |
+ detailed_ = new tray::CastDetailedView(this, cast_config_delegate_, status); |
+ return detailed_; |
+} |
+ |
+void TrayCast::DestroyTrayView() { |
+ tray_ = nullptr; |
+} |
+ |
+void TrayCast::DestroyDefaultView() { |
+ default_ = nullptr; |
+} |
+ |
+void TrayCast::DestroyDetailedView() { |
+ detailed_ = nullptr; |
+} |
+ |
+bool TrayCast::HasCastExtension() { |
+ return cast_config_delegate_ != nullptr && |
+ cast_config_delegate_->HasCastExtension(); |
+} |
+ |
+void TrayCast::UpdatePrimaryView() { |
+ if (HasCastExtension() == false) { |
+ if (default_) |
+ default_->SetVisible(false); |
+ if (tray_) { |
+ base::MessageLoopForUI::current()->PostTask( |
+ FROM_HERE, base::Bind(&tray::CastTrayView::SetVisible, |
+ base::Unretained(tray_), false)); |
+ } |
+ } else { |
+ if (default_) { |
+ if (is_casting_ == false) { |
+ default_->ActivateSelectView(); |
+ } else { |
+ default_->ActivateCastView(); |
+ } |
+ } |
+ |
+ if (tray_) { |
+ tray_->SetVisible(is_casting_); |
+ } |
+ } |
+} |
+ |
+void TrayCast::OnCastingSessionStartedOrStopped(bool started) { |
+ is_casting_ = started; |
+ UpdatePrimaryView(); |
+} |
+ |
+void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
+ if (tray_) |
+ tray_->UpdateAlignment(alignment); |
+} |
+ |
+} // namespace ash |