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 "chrome/browser/media/combined_desktop_media_list.h" |
| 6 |
| 7 CombinedDesktopMediaList::CombinedDesktopMediaList( |
| 8 scoped_ptr<DesktopMediaList> list1, |
| 9 scoped_ptr<DesktopMediaList> list2) |
| 10 : list1_(std::move(list1)), list2_(std::move(list2)) {} |
| 11 |
| 12 CombinedDesktopMediaList::~CombinedDesktopMediaList() {} |
| 13 |
| 14 void CombinedDesktopMediaList::SetUpdatePeriod(base::TimeDelta period) { |
| 15 list1_->SetUpdatePeriod(period); |
| 16 list2_->SetUpdatePeriod(period); |
| 17 } |
| 18 |
| 19 void CombinedDesktopMediaList::SetThumbnailSize( |
| 20 const gfx::Size& thumbnail_size) { |
| 21 list1_->SetThumbnailSize(thumbnail_size); |
| 22 list2_->SetThumbnailSize(thumbnail_size); |
| 23 } |
| 24 |
| 25 void CombinedDesktopMediaList::SetViewDialogWindowId( |
| 26 content::DesktopMediaID dialog_id) { |
| 27 list1_->SetViewDialogWindowId(dialog_id); |
| 28 list2_->SetViewDialogWindowId(dialog_id); |
| 29 } |
| 30 |
| 31 void CombinedDesktopMediaList::StartUpdating( |
| 32 DesktopMediaListObserver* observer) { |
| 33 observer_ = observer; |
| 34 list1_->StartUpdating(this); |
| 35 list2_->StartUpdating(this); |
| 36 } |
| 37 |
| 38 int CombinedDesktopMediaList::GetSourceCount() const { |
| 39 return list1_->GetSourceCount() + list2_->GetSourceCount(); |
| 40 } |
| 41 |
| 42 const DesktopMediaList::Source& CombinedDesktopMediaList::GetSource( |
| 43 int index) const { |
| 44 int list1_count = list1_->GetSourceCount(); |
| 45 return (index < list1_count) ? list1_->GetSource(index) |
| 46 : list2_->GetSource(index - list1_count); |
| 47 } |
| 48 |
| 49 void CombinedDesktopMediaList::OnSourceAdded(DesktopMediaList* list, |
| 50 int index) { |
| 51 observer_->OnSourceAdded(this, (list == list1_.get()) |
| 52 ? index |
| 53 : (index + list1_->GetSourceCount())); |
| 54 } |
| 55 |
| 56 void CombinedDesktopMediaList::OnSourceRemoved(DesktopMediaList* list, |
| 57 int index) { |
| 58 observer_->OnSourceRemoved(this, (list == list1_.get()) |
| 59 ? index |
| 60 : (index + list1_->GetSourceCount())); |
| 61 } |
| 62 |
| 63 void CombinedDesktopMediaList::OnSourceMoved(DesktopMediaList* list, |
| 64 int old_index, |
| 65 int new_index) { |
| 66 if (list == list1_.get()) { |
| 67 observer_->OnSourceMoved(this, old_index, new_index); |
| 68 } else { |
| 69 int list1_count = list1_->GetSourceCount(); |
| 70 observer_->OnSourceMoved(this, list1_count + old_index, |
| 71 list1_count + new_index); |
| 72 } |
| 73 } |
| 74 |
| 75 void CombinedDesktopMediaList::OnSourceNameChanged(DesktopMediaList* list, |
| 76 int index) { |
| 77 observer_->OnSourceNameChanged( |
| 78 this, |
| 79 (list == list1_.get()) ? index : (index + list1_->GetSourceCount())); |
| 80 } |
| 81 |
| 82 void CombinedDesktopMediaList::OnSourceThumbnailChanged(DesktopMediaList* list, |
| 83 int index) { |
| 84 observer_->OnSourceThumbnailChanged( |
| 85 this, |
| 86 (list == list1_.get()) ? index : (index + list1_->GetSourceCount())); |
| 87 } |
OLD | NEW |