OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/media/desktop_media_picker.h" | 5 #include "chrome/browser/media/desktop_media_picker.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "chrome/browser/media/desktop_media_list.h" | 8 #include "chrome/browser/media/desktop_media_list.h" |
9 #include "chrome/browser/media/desktop_media_list_observer.h" | 9 #include "chrome/browser/media/desktop_media_list_observer.h" |
10 #include "chrome/browser/ui/ash/ash_util.h" | 10 #include "chrome/browser/ui/ash/ash_util.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListView); | 147 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListView); |
148 }; | 148 }; |
149 | 149 |
150 // Dialog view used for DesktopMediaPickerViews. | 150 // Dialog view used for DesktopMediaPickerViews. |
151 class DesktopMediaPickerDialogView : public views::DialogDelegateView { | 151 class DesktopMediaPickerDialogView : public views::DialogDelegateView { |
152 public: | 152 public: |
153 DesktopMediaPickerDialogView(gfx::NativeWindow context, | 153 DesktopMediaPickerDialogView(gfx::NativeWindow context, |
154 gfx::NativeWindow parent_window, | 154 gfx::NativeWindow parent_window, |
155 DesktopMediaPickerViews* parent, | 155 DesktopMediaPickerViews* parent, |
156 const base::string16& app_name, | 156 const base::string16& app_name, |
| 157 const base::string16& target_name, |
157 scoped_ptr<DesktopMediaList> media_list); | 158 scoped_ptr<DesktopMediaList> media_list); |
158 virtual ~DesktopMediaPickerDialogView(); | 159 virtual ~DesktopMediaPickerDialogView(); |
159 | 160 |
160 // Called by parent (DesktopMediaPickerViews) when it's destroyed. | 161 // Called by parent (DesktopMediaPickerViews) when it's destroyed. |
161 void DetachParent(); | 162 void DetachParent(); |
162 | 163 |
163 // Called by DesktopMediaListView. | 164 // Called by DesktopMediaListView. |
164 void OnSelectionChanged(); | 165 void OnSelectionChanged(); |
165 void OnDoubleClick(); | 166 void OnDoubleClick(); |
166 | 167 |
(...skipping 25 matching lines...) Expand all Loading... |
192 public: | 193 public: |
193 DesktopMediaPickerViews(); | 194 DesktopMediaPickerViews(); |
194 virtual ~DesktopMediaPickerViews(); | 195 virtual ~DesktopMediaPickerViews(); |
195 | 196 |
196 void NotifyDialogResult(DesktopMediaID source); | 197 void NotifyDialogResult(DesktopMediaID source); |
197 | 198 |
198 // DesktopMediaPicker overrides. | 199 // DesktopMediaPicker overrides. |
199 virtual void Show(gfx::NativeWindow context, | 200 virtual void Show(gfx::NativeWindow context, |
200 gfx::NativeWindow parent, | 201 gfx::NativeWindow parent, |
201 const base::string16& app_name, | 202 const base::string16& app_name, |
| 203 const base::string16& target_name, |
202 scoped_ptr<DesktopMediaList> media_list, | 204 scoped_ptr<DesktopMediaList> media_list, |
203 const DoneCallback& done_callback) OVERRIDE; | 205 const DoneCallback& done_callback) OVERRIDE; |
204 | 206 |
205 private: | 207 private: |
206 DoneCallback callback_; | 208 DoneCallback callback_; |
207 | 209 |
208 // The |dialog_| is owned by the corresponding views::Widget instance. | 210 // The |dialog_| is owned by the corresponding views::Widget instance. |
209 // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed | 211 // When DesktopMediaPickerViews is destroyed the |dialog_| is destroyed |
210 // asynchronously by closing the widget. | 212 // asynchronously by closing the widget. |
211 DesktopMediaPickerDialogView* dialog_; | 213 DesktopMediaPickerDialogView* dialog_; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 DesktopMediaSourceView* source_view = | 485 DesktopMediaSourceView* source_view = |
484 static_cast<DesktopMediaSourceView*>(child_at(index)); | 486 static_cast<DesktopMediaSourceView*>(child_at(index)); |
485 source_view->SetThumbnail(source.thumbnail); | 487 source_view->SetThumbnail(source.thumbnail); |
486 } | 488 } |
487 | 489 |
488 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( | 490 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( |
489 gfx::NativeWindow context, | 491 gfx::NativeWindow context, |
490 gfx::NativeWindow parent_window, | 492 gfx::NativeWindow parent_window, |
491 DesktopMediaPickerViews* parent, | 493 DesktopMediaPickerViews* parent, |
492 const base::string16& app_name, | 494 const base::string16& app_name, |
| 495 const base::string16& target_name, |
493 scoped_ptr<DesktopMediaList> media_list) | 496 scoped_ptr<DesktopMediaList> media_list) |
494 : parent_(parent), | 497 : parent_(parent), |
495 app_name_(app_name), | 498 app_name_(app_name), |
496 label_(new views::Label()), | 499 label_(new views::Label()), |
497 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), | 500 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), |
498 list_view_(new DesktopMediaListView(this, media_list.Pass())) { | 501 list_view_(new DesktopMediaListView(this, media_list.Pass())) { |
499 label_->SetText( | 502 if (app_name == target_name) { |
500 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name_)); | 503 label_->SetText( |
| 504 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); |
| 505 } else { |
| 506 label_->SetText(l10n_util::GetStringFUTF16( |
| 507 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); |
| 508 } |
501 label_->SetMultiLine(true); | 509 label_->SetMultiLine(true); |
502 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 510 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
503 AddChildView(label_); | 511 AddChildView(label_); |
504 | 512 |
505 scroll_view_->SetContents(list_view_); | 513 scroll_view_->SetContents(list_view_); |
506 AddChildView(scroll_view_); | 514 AddChildView(scroll_view_); |
507 | 515 |
508 DialogDelegate::CreateDialogWidget(this, context, parent_window); | 516 DialogDelegate::CreateDialogWidget(this, context, parent_window); |
509 | 517 |
510 // DesktopMediaList needs to know the ID of the picker window which | 518 // DesktopMediaList needs to know the ID of the picker window which |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 DesktopMediaPickerViews::~DesktopMediaPickerViews() { | 625 DesktopMediaPickerViews::~DesktopMediaPickerViews() { |
618 if (dialog_) { | 626 if (dialog_) { |
619 dialog_->DetachParent(); | 627 dialog_->DetachParent(); |
620 dialog_->GetWidget()->Close(); | 628 dialog_->GetWidget()->Close(); |
621 } | 629 } |
622 } | 630 } |
623 | 631 |
624 void DesktopMediaPickerViews::Show(gfx::NativeWindow context, | 632 void DesktopMediaPickerViews::Show(gfx::NativeWindow context, |
625 gfx::NativeWindow parent, | 633 gfx::NativeWindow parent, |
626 const base::string16& app_name, | 634 const base::string16& app_name, |
| 635 const base::string16& target_name, |
627 scoped_ptr<DesktopMediaList> media_list, | 636 scoped_ptr<DesktopMediaList> media_list, |
628 const DoneCallback& done_callback) { | 637 const DoneCallback& done_callback) { |
629 callback_ = done_callback; | 638 callback_ = done_callback; |
630 dialog_ = new DesktopMediaPickerDialogView( | 639 dialog_ = new DesktopMediaPickerDialogView( |
631 context, parent, this, app_name, media_list.Pass()); | 640 context, parent, this, app_name, target_name, media_list.Pass()); |
632 } | 641 } |
633 | 642 |
634 void DesktopMediaPickerViews::NotifyDialogResult( | 643 void DesktopMediaPickerViews::NotifyDialogResult( |
635 DesktopMediaID source) { | 644 DesktopMediaID source) { |
636 // Once this method is called the |dialog_| will close and destroy itself. | 645 // Once this method is called the |dialog_| will close and destroy itself. |
637 dialog_->DetachParent(); | 646 dialog_->DetachParent(); |
638 dialog_ = NULL; | 647 dialog_ = NULL; |
639 | 648 |
640 DCHECK(!callback_.is_null()); | 649 DCHECK(!callback_.is_null()); |
641 | 650 |
642 // Notify the |callback_| asynchronously because it may need to destroy | 651 // Notify the |callback_| asynchronously because it may need to destroy |
643 // DesktopMediaPicker. | 652 // DesktopMediaPicker. |
644 content::BrowserThread::PostTask( | 653 content::BrowserThread::PostTask( |
645 content::BrowserThread::UI, FROM_HERE, | 654 content::BrowserThread::UI, FROM_HERE, |
646 base::Bind(callback_, source)); | 655 base::Bind(callback_, source)); |
647 callback_.Reset(); | 656 callback_.Reset(); |
648 } | 657 } |
649 | 658 |
650 } // namespace | 659 } // namespace |
651 | 660 |
652 // static | 661 // static |
653 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 662 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
654 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 663 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
655 } | 664 } |
OLD | NEW |