Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: ash/system/cast/tray_cast.cc

Issue 1118613003: Add UI for cast system tray integration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
(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 {
37 const int kStopButtonRightPadding = 18;
38 } // namespace
39
40 namespace ash {
41 namespace tray {
42
43 static void StopCastCallback(
44 CastConfigDelegate* cast_config,
45 const CastConfigDelegate::ReceiversAndActivites& receivers_activities) {
46 for (auto& item : receivers_activities) {
47 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.
48 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.
49 cast_config->StopCasting(activity.id);
50 }
51 }
52 }
53
54 static void StopCast() {
55 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.
56 Shell::GetInstance()->system_tray_delegate()->GetCastConfigDelegate();
57 if (cast_config && cast_config->HasCastExtension()) {
58 cast_config->GetReceiversAndActivities(
59 base::Bind(&StopCastCallback, cast_config));
60 }
61 }
62
63 class CastSelectDefaultView : public TrayItemMore {
achuithb 2015/04/30 00:03:31 Class comment here
jdufault 2015/04/30 21:51:03 Done.
64 public:
65 CastSelectDefaultView(SystemTrayItem* owner,
66 CastConfigDelegate* cast_config_delegate,
67 bool show_more);
68 ~CastSelectDefaultView() override;
69
70 void UpdateLabel();
achuithb 2015/04/30 00:03:32 Function comment for all public functions
jdufault 2015/04/30 21:51:04 Done.
71
72 private:
73 void UpdateLabelCallback(
74 const CastConfigDelegate::ReceiversAndActivites& receivers_activities);
75
76 CastConfigDelegate* cast_config_delegate_;
77 DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView);
78 };
79
80 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.
81 public:
82 CastCastView(CastConfigDelegate* cast_config_delegate);
achuithb 2015/04/30 00:03:32 explicit
jdufault 2015/04/30 21:51:03 Done.
83 ~CastCastView() override;
84
85 void UpdateLabel();
achuithb 2015/04/30 00:03:32 Comment
jdufault 2015/04/30 21:51:03 Done.
86
87 private:
88 void UpdateLabelCallback(
89 const CastConfigDelegate::ReceiversAndActivites& receivers_activities);
90
91 // Overridden from views::View.
92 void Layout() override;
93 // Overridden from views::ButtonListener
94 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
95
96 CastConfigDelegate* cast_config_delegate_;
97 views::ImageView* icon_;
98 views::View* label_container_;
99 views::Label* title_;
100 views::Label* details_;
101 TrayPopupLabelButton* stop_button_;
102
103 DISALLOW_COPY_AND_ASSIGN(CastCastView);
104 };
105
106 CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate)
107 : cast_config_delegate_(cast_config_delegate) {
108 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
109 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
110 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
111 kTrayPopupPaddingHorizontal, 0,
112 kTrayPopupPaddingBetweenItems));
113 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight);
114 icon_->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia());
115 AddChildView(icon_);
116
117 label_container_ = new views::View;
118 label_container_->SetLayoutManager(
119 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
120
121 title_ = new views::Label;
122 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
123 title_->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont));
124 label_container_->AddChildView(title_);
125
126 details_ = new views::Label;
127 details_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
128 details_->SetMultiLine(false);
129 details_->SetEnabledColor(kHeaderTextColorNormal);
130 label_container_->AddChildView(details_);
131
132 AddChildView(label_container_);
133
134 auto stop_button_text =
achuithb 2015/04/30 00:03:32 Spell out the type here
jdufault 2015/04/30 21:51:04 Done.
135 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
136 IDS_ASH_STATUS_TRAY_CAST_STOP);
137 stop_button_ = new TrayPopupLabelButton(this, stop_button_text);
138 AddChildView(stop_button_);
139
140 UpdateLabel();
141 }
142
143 CastCastView::~CastCastView() {
144 }
145
146 void CastCastView::Layout() {
147 views::View::Layout();
148
149 // Give the stop button the space it requests.
150 gfx::Size stop_size = stop_button_->GetPreferredSize();
151 gfx::Rect stop_bounds(stop_size);
152 stop_bounds.set_x(width() - stop_size.width() - kStopButtonRightPadding);
153 stop_bounds.set_y((height() - stop_size.height()) / 2);
154 stop_button_->SetBoundsRect(stop_bounds);
155
156 // Adjust the label's bounds in case it got cut off by |stop_button_|.
157 if (label_container_->bounds().Intersects(stop_button_->bounds())) {
158 gfx::Rect label_bounds = label_container_->bounds();
159 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems -
160 label_container_->x());
161 label_container_->SetBoundsRect(label_bounds);
162 }
163
164 // Center the label
achuithb 2015/04/30 00:03:31 Period at the end of comment.
jdufault 2015/04/30 21:51:04 Done.
165 // TODO(jdufault): Why doesn't this happen automatically?
166 auto extra_height = height() - label_container_->GetPreferredSize().height();
167 label_container_->SetY(extra_height / 2);
168 }
169
170 void CastCastView::UpdateLabel() {
171 if (cast_config_delegate_ == nullptr ||
172 cast_config_delegate_->HasCastExtension() == false)
173 return;
174
175 cast_config_delegate_->GetReceiversAndActivities(
176 base::Bind(&CastCastView::UpdateLabelCallback, base::Unretained(this)));
177 }
178
179 void CastCastView::UpdateLabelCallback(
180 const CastConfigDelegate::ReceiversAndActivites& receivers_activities) {
181 for (auto& i : receivers_activities) {
182 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.
183 auto activity = i.second.activity;
184 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.
185 title_->SetText(activity.title);
186 details_->SetText(l10n_util::GetStringFUTF16(
187 IDS_ASH_STATUS_TRAY_CAST_ACTIVE_DETAIL, receiver.name));
188
achuithb 2015/04/30 00:03:32 unnecessary newline.
jdufault 2015/04/30 21:51:03 Done.
189 Layout();
190 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
191 }
192 }
193 }
194
195 void CastCastView::ButtonPressed(views::Button* sender,
196 const ui::Event& event) {
197 DCHECK(sender == stop_button_);
198 StopCast();
199 }
200
201 class CastDuplexView : public views::View {
achuithb 2015/04/30 00:03:32 class comment.
jdufault 2015/04/30 21:51:03 Done.
202 public:
203 CastDuplexView(SystemTrayItem* owner,
204 CastConfigDelegate* config_delegate,
205 bool show_more);
206 ~CastDuplexView() override;
207
208 // Activate either the casting or select view.
209 void ActivateCastView();
210 void ActivateSelectView();
211
212 CastSelectDefaultView* select_view() { return select_view_; }
213 CastCastView* cast_view() { return cast_view_; }
214
215 // Overridden from views::View.
achuithb 2015/04/30 00:03:32 Make this private
jdufault 2015/04/30 21:51:04 Done.
216 void Layout() override;
217
218 private:
219 CastSelectDefaultView* select_view_;
220 CastCastView* cast_view_;
221
222 DISALLOW_COPY_AND_ASSIGN(CastDuplexView);
223 };
224
225 CastDuplexView::CastDuplexView(SystemTrayItem* owner,
226 CastConfigDelegate* config_delegate,
227 bool show_more) {
228 select_view_ = new CastSelectDefaultView(owner, config_delegate, show_more);
229 cast_view_ = new CastCastView(config_delegate);
230 SetLayoutManager(new views::FillLayout());
231 AddChildView(select_view_);
232 AddChildView(cast_view_);
233
234 ActivateSelectView();
235 }
236
237 CastDuplexView::~CastDuplexView() {
238 }
239
240 void CastDuplexView::ActivateCastView() {
241 select_view_->SetVisible(false);
242 cast_view_->SetVisible(true);
243 InvalidateLayout();
244 }
245
246 void CastDuplexView::ActivateSelectView() {
247 select_view_->SetVisible(true);
248 cast_view_->SetVisible(false);
249 InvalidateLayout();
250 }
251
252 void CastDuplexView::Layout() {
253 views::View::Layout();
254
255 if (select_view_->IsDrawn())
256 select_view_->SetBoundsRect(GetContentsBounds());
257 if (cast_view_->IsDrawn())
258 cast_view_->SetBoundsRect(GetContentsBounds());
259 }
260
261 class CastTrayView : public TrayItemView {
achuithb 2015/04/30 00:03:32 class comment
jdufault 2015/04/30 21:51:03 Done.
262 public:
263 CastTrayView(SystemTrayItem* tray_item);
264 ~CastTrayView() override;
265 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.
266
267 private:
268 DISALLOW_COPY_AND_ASSIGN(CastTrayView);
269 };
270
271 CastTrayView::CastTrayView(SystemTrayItem* tray_item)
272 : TrayItemView(tray_item) {
273 CreateImageView();
274
275 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
276 image_view()->SetImage(
277 rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_STATUS).ToImageSkia());
278 }
279
280 CastTrayView::~CastTrayView() {
281 }
282
283 void CastTrayView::UpdateAlignment(ShelfAlignment alignment) {
284 // Center the item dependent on the orientation of the shelf.
285 views::BoxLayout::Orientation layout = views::BoxLayout::kHorizontal;
286 switch (alignment) {
287 case ash::SHELF_ALIGNMENT_BOTTOM:
288 case ash::SHELF_ALIGNMENT_TOP:
289 layout = views::BoxLayout::kHorizontal;
290 break;
291 case ash::SHELF_ALIGNMENT_LEFT:
292 case ash::SHELF_ALIGNMENT_RIGHT:
293 layout = views::BoxLayout::kVertical;
294 break;
295 }
296 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
297 Layout();
298 }
299
300 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.
301 SystemTrayItem* owner,
302 CastConfigDelegate* cast_config_delegate,
303 bool show_more)
304 : TrayItemMore(owner, show_more),
305 cast_config_delegate_(cast_config_delegate) {
306 auto& rb = ui::ResourceBundle::GetSharedInstance();
307 SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia());
308
309 // We first set a default label before we actually know what the label will
310 // be, because it could take awhile before UpdateLabel() actually applies
311 // the correct label.
312 // TODO(jdufault): What should the default label be?
313 SetLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_NO_DEVICE));
314 UpdateLabel();
315 }
316
317 CastSelectDefaultView::~CastSelectDefaultView() {
318 }
319
320 void CastSelectDefaultView::UpdateLabelCallback(
321 const CastConfigDelegate::ReceiversAndActivites& receivers_activities) {
322 // The label needs to reflect if there are no cast receivers
323 const base::string16 label =
324 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
325 receivers_activities.empty() ? IDS_ASH_STATUS_TRAY_CAST_NO_DEVICE
326 : IDS_ASH_STATUS_TRAY_CAST_DESKTOP);
327 SetLabel(label);
328 SetAccessibleName(label);
329 SetVisible(true);
330 }
331
332 void CastSelectDefaultView::UpdateLabel() {
333 if (cast_config_delegate_ == nullptr ||
334 cast_config_delegate_->HasCastExtension() == false)
335 return;
336
337 cast_config_delegate_->GetReceiversAndActivities(base::Bind(
338 &CastSelectDefaultView::UpdateLabelCallback, base::Unretained(this)));
339 }
340
341 class CastDetailedView : public TrayDetailsView, public ViewClickListener {
achuithb 2015/04/30 00:03:32 class comment
jdufault 2015/04/30 21:51:03 Done.
342 public:
343 CastDetailedView(SystemTrayItem* owner,
344 CastConfigDelegate* cast_config_delegate,
345 user::LoginStatus login);
346 ~CastDetailedView() override;
347
348 void Update();
achuithb 2015/04/30 00:03:32 function comment
jdufault 2015/04/30 21:51:04 Done.
349
350 private:
351 void CreateItems();
352 void UpdateCastReceiverList(const CastConfigDelegate::ReceiversAndActivites&
353 new_receivers_and_activities);
354 void AppendHeaderEntry();
355
356 void UpdateReceiverScrollList();
357 views::View* AddReceiverToList(
358 const CastConfigDelegate::ReceiverAndActivity& receiverActivity);
359
360 // Add settings entries.
361 void AppendSettingsEntries();
362 // Overridden from ViewClickListener.
363 void OnViewClicked(views::View* sender) override;
364
365 CastConfigDelegate* cast_config_delegate_;
366 user::LoginStatus login_;
367 views::View* options_;
368 CastConfigDelegate::ReceiversAndActivites receivers_and_activities_;
369 // A mapping from the view pointer to the associated activity id
370 std::map<views::View*, std::string> receiver_activity_map_;
371
372 DISALLOW_COPY_AND_ASSIGN(CastDetailedView);
373 };
374
375 CastDetailedView::CastDetailedView(SystemTrayItem* owner,
376 CastConfigDelegate* cast_config_delegate,
377 user::LoginStatus login)
378 : TrayDetailsView(owner),
379 cast_config_delegate_(cast_config_delegate),
380 login_(login),
381 options_(nullptr) {
382 CreateItems();
383 Update();
384 }
385
386 CastDetailedView::~CastDetailedView() {
387 }
388
389 void CastDetailedView::Update() {
390 cast_config_delegate_->GetReceiversAndActivities(base::Bind(
391 &CastDetailedView::UpdateCastReceiverList, base::Unretained(this)));
392 }
393
394 void CastDetailedView::UpdateCastReceiverList(
395 const CastConfigDelegate::ReceiversAndActivites&
396 new_receivers_and_activities) {
397 // Add/update existing.
398 for (auto i = new_receivers_and_activities.begin();
399 i != new_receivers_and_activities.end(); ++i) {
400 receivers_and_activities_[i->first] = i->second;
401 }
402 // Remove non-existent.
403 for (auto i = receivers_and_activities_.begin();
404 i != receivers_and_activities_.end(); ++i) {
405 if (new_receivers_and_activities.count(i->first) == 0)
406 receivers_and_activities_.erase(i->first);
407 }
408
409 // Update UI.
410 UpdateReceiverScrollList();
411 Layout();
412 }
413
414 void CastDetailedView::CreateItems() {
415 CreateScrollableList();
416 AppendSettingsEntries();
417 AppendHeaderEntry();
418 }
419
420 void CastDetailedView::AppendHeaderEntry() {
421 CreateSpecialRow(IDS_ASH_STATUS_TRAY_CAST, this);
422 }
423
424 void CastDetailedView::UpdateReceiverScrollList() {
425 // 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.
426 receiver_activity_map_.clear();
427 scroll_content()->RemoveAllChildViews(true);
428
429 // Add a view for each receiver
achuithb 2015/04/30 00:03:32 same
jdufault 2015/04/30 21:51:03 Done.
430 for (auto& it : receivers_and_activities_) {
431 const CastConfigDelegate::ReceiverAndActivity& receiver_activity =
432 it.second;
433 auto container = AddReceiverToList(receiver_activity);
achuithb 2015/04/30 00:03:31 spell out type
jdufault 2015/04/30 21:51:03 Done.
434 receiver_activity_map_[container] = it.first;
435 }
436
437 scroll_content()->SizeToPreferredSize();
438 static_cast<views::View*>(scroller())->Layout();
439 }
440
441 views::View* CastDetailedView::AddReceiverToList(
442 const CastConfigDelegate::ReceiverAndActivity& receiverActivity) {
443 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
444
445 const gfx::ImageSkia* image =
446 ui::ResourceBundle::GetSharedInstance()
447 .GetImageNamed(IDR_AURA_UBER_TRAY_CAST_DEVICE_ICON)
448 .ToImageSkia();
449 auto& name = receiverActivity.receiver.name;
achuithb 2015/04/30 00:03:32 spell out type
jdufault 2015/04/30 21:51:03 Done.
450 container->AddIndentedIconAndLabel(*image, name, false);
451
452 scroll_content()->AddChildView(container);
453 return container;
454 }
455
456 // Add settings entries.
457 void CastDetailedView::AppendSettingsEntries() {
458 // Settings requires a browser window, hide it for non logged in user.
459 bool userAddingRunning = Shell::GetInstance()
achuithb 2015/04/30 00:03:32 const bool
jdufault 2015/04/30 21:51:03 Done.
460 ->session_state_delegate()
461 ->IsInSecondaryLoginScreen();
462
463 if (login_ == user::LOGGED_IN_NONE || login_ == user::LOGGED_IN_LOCKED ||
464 userAddingRunning)
465 return;
466
467 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
468 HoverHighlightView* container = new HoverHighlightView(this);
469 container->AddLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_OPTIONS),
470 gfx::ALIGN_LEFT, false /* highlight */);
471
472 AddChildView(container);
473 options_ = container;
474 }
475
476 void CastDetailedView::OnViewClicked(views::View* sender) {
477 if (sender == footer()->content()) {
478 TransitionToDefaultView();
479 } else if (sender == options_) {
480 cast_config_delegate_->LaunchCastOptions();
481 } else {
482 // Find the receiver we are going to cast to
483 auto it = receiver_activity_map_.find(sender);
484 if (it != receiver_activity_map_.end()) {
485 // TODO(jdufault): Should this cast the desktop instead of showing a
486 // popup?
487 cast_config_delegate_->CastToReceiver(it->second);
488 // TODO(jdufault): Should we transition to the default view?
489 }
490 }
491 }
492
493 } // namespace tray
494
495 TrayCast::TrayCast(SystemTray* system_tray)
496 : SystemTrayItem(system_tray),
497 is_casting_(false),
498 tray_(nullptr),
499 default_(nullptr),
500 detailed_(nullptr),
501 cast_config_delegate_(ash::Shell::GetInstance()
502 ->system_tray_delegate()
503 ->GetCastConfigDelegate()) {
504 Shell::GetInstance()->AddShellObserver(this);
505 Shell::GetInstance()->system_tray_notifier()->AddCastObserver(this);
506 }
507
508 TrayCast::~TrayCast() {
509 Shell::GetInstance()->RemoveShellObserver(this);
510 Shell::GetInstance()->system_tray_notifier()->RemoveCastObserver(this);
511 }
512
513 void TrayCast::OnCastRefresh() {
514 if (default_) {
515 default_->select_view()->UpdateLabel();
516 default_->cast_view()->UpdateLabel();
517 } else if (detailed_)
518 detailed_->Update();
519 }
520
521 views::View* TrayCast::CreateTrayView(user::LoginStatus status) {
522 CHECK(tray_ == nullptr);
523 tray_ = new tray::CastTrayView(this);
524 tray_->SetVisible(is_casting_);
525 return tray_;
526 }
527
528 views::View* TrayCast::CreateDefaultView(user::LoginStatus status) {
529 CHECK(default_ == nullptr);
530 default_ = new tray::CastDuplexView(this, cast_config_delegate_,
531 status != user::LOGGED_IN_LOCKED);
532 UpdatePrimaryView();
533 return default_;
534 }
535
536 views::View* TrayCast::CreateDetailedView(user::LoginStatus status) {
537 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
538 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW);
539 CHECK(detailed_ == nullptr);
540 detailed_ = new tray::CastDetailedView(this, cast_config_delegate_, status);
541 return detailed_;
542 }
543
544 void TrayCast::DestroyTrayView() {
545 tray_ = nullptr;
546 }
547
548 void TrayCast::DestroyDefaultView() {
549 default_ = nullptr;
550 }
551
552 void TrayCast::DestroyDetailedView() {
553 detailed_ = nullptr;
554 }
555
556 bool TrayCast::HasCastExtension() {
557 return cast_config_delegate_ != nullptr &&
558 cast_config_delegate_->HasCastExtension();
559 }
560
561 void TrayCast::UpdatePrimaryView() {
562 if (HasCastExtension() == false) {
563 if (default_)
564 default_->SetVisible(false);
565 if (tray_) {
566 base::MessageLoopForUI::current()->PostTask(
567 FROM_HERE, base::Bind(&tray::CastTrayView::SetVisible,
568 base::Unretained(tray_), false));
569 }
570 } else {
571 if (default_) {
572 if (is_casting_ == false) {
573 default_->ActivateSelectView();
574 } else {
575 default_->ActivateCastView();
576 }
577 }
578
579 if (tray_) {
580 tray_->SetVisible(is_casting_);
581 }
582 }
583 }
584
585 void TrayCast::OnCastingSessionStartedOrStopped(bool started) {
586 is_casting_ = started;
587 UpdatePrimaryView();
588 }
589
590 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
591 if (tray_)
592 tray_->UpdateAlignment(alignment);
593 }
594
595 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698