| 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/ui/views/desktop_media_picker_views.h" | 5 #include "chrome/browser/ui/views/desktop_media_picker_views.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/media/combined_desktop_media_list.h" |
| 14 #include "chrome/browser/media/desktop_media_list.h" | 15 #include "chrome/browser/media/desktop_media_list.h" |
| 15 #include "chrome/browser/ui/ash/ash_util.h" | 16 #include "chrome/browser/ui/ash/ash_util.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 18 #include "components/constrained_window/constrained_window_views.h" | 19 #include "components/constrained_window/constrained_window_views.h" |
| 19 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 20 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
| 22 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
| 23 #include "grit/components_strings.h" | 24 #include "grit/components_strings.h" |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 OnSelectionChanged(); | 389 OnSelectionChanged(); |
| 389 OnDoubleClick(); | 390 OnDoubleClick(); |
| 390 } | 391 } |
| 391 | 392 |
| 392 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( | 393 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( |
| 393 content::WebContents* parent_web_contents, | 394 content::WebContents* parent_web_contents, |
| 394 gfx::NativeWindow context, | 395 gfx::NativeWindow context, |
| 395 DesktopMediaPickerViews* parent, | 396 DesktopMediaPickerViews* parent, |
| 396 const base::string16& app_name, | 397 const base::string16& app_name, |
| 397 const base::string16& target_name, | 398 const base::string16& target_name, |
| 398 std::unique_ptr<DesktopMediaList> media_list, | 399 std::unique_ptr<DesktopMediaList> screen_list, |
| 400 std::unique_ptr<DesktopMediaList> window_list, |
| 401 std::unique_ptr<DesktopMediaList> tab_list, |
| 399 bool request_audio) | 402 bool request_audio) |
| 400 : parent_(parent), | 403 : parent_(parent), |
| 401 app_name_(app_name), | 404 app_name_(app_name), |
| 402 description_label_(new views::Label()), | 405 description_label_(new views::Label()), |
| 403 audio_share_checkbox_(nullptr), | 406 audio_share_checkbox_(nullptr), |
| 404 audio_share_checked_(true), | 407 audio_share_checked_(true), |
| 405 sources_scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), | 408 sources_scroll_view_(views::ScrollView::CreateScrollViewWithBorder()) { |
| 406 sources_list_view_( | 409 std::vector<std::unique_ptr<DesktopMediaList>> media_lists; |
| 407 new DesktopMediaListView(this, std::move(media_list))) { | 410 if (screen_list) |
| 411 media_lists.push_back(std::move(screen_list)); |
| 412 if (window_list) |
| 413 media_lists.push_back(std::move(window_list)); |
| 414 if (tab_list) |
| 415 media_lists.push_back(std::move(tab_list)); |
| 416 |
| 417 std::unique_ptr<DesktopMediaList> media_list; |
| 418 if (media_lists.size() > 1) |
| 419 media_list.reset(new CombinedDesktopMediaList(media_lists)); |
| 420 else |
| 421 media_list = std::move(media_lists[0]); |
| 422 |
| 423 DCHECK(media_list != nullptr); |
| 424 sources_list_view_ = new DesktopMediaListView(this, std::move(media_list)); |
| 425 |
| 408 // TODO(estade): we should be getting the inside-border spacing by default as | 426 // TODO(estade): we should be getting the inside-border spacing by default as |
| 409 // a DialogDelegateView subclass, via default BubbleFrameView content margins. | 427 // a DialogDelegateView subclass, via default BubbleFrameView content margins. |
| 410 SetLayoutManager(new views::BoxLayout( | 428 SetLayoutManager(new views::BoxLayout( |
| 411 views::BoxLayout::kVertical, views::kButtonHEdgeMarginNew, | 429 views::BoxLayout::kVertical, views::kButtonHEdgeMarginNew, |
| 412 views::kPanelVertMargin, views::kLabelToControlVerticalSpacing)); | 430 views::kPanelVertMargin, views::kLabelToControlVerticalSpacing)); |
| 413 | 431 |
| 414 if (app_name == target_name) { | 432 if (app_name == target_name) { |
| 415 description_label_->SetText( | 433 description_label_->SetText( |
| 416 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); | 434 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); |
| 417 } else { | 435 } else { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) { | 626 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) { |
| 609 } | 627 } |
| 610 | 628 |
| 611 DesktopMediaPickerViews::~DesktopMediaPickerViews() { | 629 DesktopMediaPickerViews::~DesktopMediaPickerViews() { |
| 612 if (dialog_) { | 630 if (dialog_) { |
| 613 dialog_->DetachParent(); | 631 dialog_->DetachParent(); |
| 614 dialog_->GetWidget()->Close(); | 632 dialog_->GetWidget()->Close(); |
| 615 } | 633 } |
| 616 } | 634 } |
| 617 | 635 |
| 618 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, | 636 void DesktopMediaPickerViews::Show( |
| 619 gfx::NativeWindow context, | 637 content::WebContents* web_contents, |
| 620 gfx::NativeWindow parent, | 638 gfx::NativeWindow context, |
| 621 const base::string16& app_name, | 639 gfx::NativeWindow parent, |
| 622 const base::string16& target_name, | 640 const base::string16& app_name, |
| 623 std::unique_ptr<DesktopMediaList> media_list, | 641 const base::string16& target_name, |
| 624 bool request_audio, | 642 std::unique_ptr<DesktopMediaList> screen_list, |
| 625 const DoneCallback& done_callback) { | 643 std::unique_ptr<DesktopMediaList> window_list, |
| 644 std::unique_ptr<DesktopMediaList> tab_list, |
| 645 bool request_audio, |
| 646 const DoneCallback& done_callback) { |
| 626 callback_ = done_callback; | 647 callback_ = done_callback; |
| 627 dialog_ = new DesktopMediaPickerDialogView( | 648 dialog_ = new DesktopMediaPickerDialogView( |
| 628 web_contents, context, this, app_name, target_name, std::move(media_list), | 649 web_contents, context, this, app_name, target_name, |
| 650 std::move(screen_list), std::move(window_list), std::move(tab_list), |
| 629 request_audio); | 651 request_audio); |
| 630 } | 652 } |
| 631 | 653 |
| 632 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { | 654 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { |
| 633 // Once this method is called the |dialog_| will close and destroy itself. | 655 // Once this method is called the |dialog_| will close and destroy itself. |
| 634 dialog_->DetachParent(); | 656 dialog_->DetachParent(); |
| 635 dialog_ = NULL; | 657 dialog_ = NULL; |
| 636 | 658 |
| 637 DCHECK(!callback_.is_null()); | 659 DCHECK(!callback_.is_null()); |
| 638 | 660 |
| 639 // Notify the |callback_| asynchronously because it may need to destroy | 661 // Notify the |callback_| asynchronously because it may need to destroy |
| 640 // DesktopMediaPicker. | 662 // DesktopMediaPicker. |
| 641 content::BrowserThread::PostTask( | 663 content::BrowserThread::PostTask( |
| 642 content::BrowserThread::UI, FROM_HERE, | 664 content::BrowserThread::UI, FROM_HERE, |
| 643 base::Bind(callback_, source)); | 665 base::Bind(callback_, source)); |
| 644 callback_.Reset(); | 666 callback_.Reset(); |
| 645 } | 667 } |
| 646 | 668 |
| 647 // static | 669 // static |
| 648 std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 670 std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
| 649 return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 671 return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
| 650 } | 672 } |
| OLD | NEW |