| 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 "desktop_media_picker_views_deprecated.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/combined_desktop_media_list.h" |
| 15 #include "chrome/browser/media/desktop_media_list.h" | 15 #include "chrome/browser/media/desktop_media_list.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return static_cast<DesktopMediaID::Id>(accelerated_widget); | 67 return static_cast<DesktopMediaID::Id>(accelerated_widget); |
| 68 #endif | 68 #endif |
| 69 } | 69 } |
| 70 | 70 |
| 71 int GetMediaListViewHeightForRows(size_t rows) { | 71 int GetMediaListViewHeightForRows(size_t rows) { |
| 72 return kListItemHeight * rows; | 72 return kListItemHeight * rows; |
| 73 } | 73 } |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 namespace deprecated { | 77 DesktopMediaSourceView::DesktopMediaSourceView( |
| 78 | 78 DesktopMediaListView* parent, |
| 79 DesktopMediaSourceView::DesktopMediaSourceView(DesktopMediaListView* parent, | 79 DesktopMediaID source_id) |
| 80 DesktopMediaID source_id) | |
| 81 : parent_(parent), | 80 : parent_(parent), |
| 82 source_id_(source_id), | 81 source_id_(source_id), |
| 83 image_view_(new views::ImageView()), | 82 image_view_(new views::ImageView()), |
| 84 label_(new views::Label()), | 83 label_(new views::Label()), |
| 85 selected_(false) { | 84 selected_(false) { |
| 86 AddChildView(image_view_); | 85 AddChildView(image_view_); |
| 87 AddChildView(label_); | 86 AddChildView(label_); |
| 88 SetFocusBehavior(FocusBehavior::ALWAYS); | 87 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 89 } | 88 } |
| 90 | 89 |
| 91 DesktopMediaSourceView::~DesktopMediaSourceView() {} | 90 DesktopMediaSourceView::~DesktopMediaSourceView() {} |
| 92 | 91 |
| 93 void DesktopMediaSourceView::SetName(const base::string16& name) { | 92 void DesktopMediaSourceView::SetName(const base::string16& name) { |
| 94 label_->SetText(name); | 93 label_->SetText(name); |
| 95 } | 94 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 126 } | 125 } |
| 127 | 126 |
| 128 SchedulePaint(); | 127 SchedulePaint(); |
| 129 } | 128 } |
| 130 | 129 |
| 131 const char* DesktopMediaSourceView::GetClassName() const { | 130 const char* DesktopMediaSourceView::GetClassName() const { |
| 132 return kDesktopMediaSourceViewClassName; | 131 return kDesktopMediaSourceViewClassName; |
| 133 } | 132 } |
| 134 | 133 |
| 135 void DesktopMediaSourceView::Layout() { | 134 void DesktopMediaSourceView::Layout() { |
| 136 image_view_->SetBounds(kThumbnailMargin, kThumbnailMargin, kThumbnailWidth, | 135 image_view_->SetBounds(kThumbnailMargin, kThumbnailMargin, |
| 137 kThumbnailHeight); | 136 kThumbnailWidth, kThumbnailHeight); |
| 138 label_->SetBounds(kThumbnailMargin, kThumbnailHeight + kThumbnailMargin, | 137 label_->SetBounds(kThumbnailMargin, kThumbnailHeight + kThumbnailMargin, |
| 139 kThumbnailWidth, kLabelHeight); | 138 kThumbnailWidth, kLabelHeight); |
| 140 } | 139 } |
| 141 | 140 |
| 142 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { | 141 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { |
| 143 Views neighbours; | 142 Views neighbours; |
| 144 parent()->GetViewsInGroup(group, &neighbours); | 143 parent()->GetViewsInGroup(group, &neighbours); |
| 145 if (neighbours.empty()) | 144 if (neighbours.empty()) |
| 146 return NULL; | 145 return NULL; |
| 147 | 146 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 455 } |
| 457 | 456 |
| 458 // If |parent_web_contents| is set and it's not a background page then the | 457 // If |parent_web_contents| is set and it's not a background page then the |
| 459 // picker will be shown modal to the web contents. Otherwise the picker is | 458 // picker will be shown modal to the web contents. Otherwise the picker is |
| 460 // shown in a separate window. | 459 // shown in a separate window. |
| 461 views::Widget* widget = NULL; | 460 views::Widget* widget = NULL; |
| 462 bool modal_dialog = | 461 bool modal_dialog = |
| 463 parent_web_contents && | 462 parent_web_contents && |
| 464 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents); | 463 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents); |
| 465 if (modal_dialog) { | 464 if (modal_dialog) { |
| 466 widget = | 465 widget = constrained_window::ShowWebModalDialogViews(this, |
| 467 constrained_window::ShowWebModalDialogViews(this, parent_web_contents); | 466 parent_web_contents); |
| 468 } else { | 467 } else { |
| 469 widget = DialogDelegate::CreateDialogWidget(this, context, NULL); | 468 widget = DialogDelegate::CreateDialogWidget(this, context, NULL); |
| 470 widget->Show(); | 469 widget->Show(); |
| 471 } | 470 } |
| 472 | 471 |
| 473 // If the picker is not modal to the calling web contents then it is displayed | 472 // If the picker is not modal to the calling web contents then it is displayed |
| 474 // in its own top-level window, so in that case it needs to be filtered out of | 473 // in its own top-level window, so in that case it needs to be filtered out of |
| 475 // the list of top-level windows available for capture, and to achieve that | 474 // the list of top-level windows available for capture, and to achieve that |
| 476 // the Id is passed to DesktopMediaList. | 475 // the Id is passed to DesktopMediaList. |
| 477 DesktopMediaID dialog_window_id; | 476 DesktopMediaID dialog_window_id; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 return sources_list_view_->GetSelection() != NULL; | 518 return sources_list_view_->GetSelection() != NULL; |
| 520 return true; | 519 return true; |
| 521 } | 520 } |
| 522 | 521 |
| 523 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() { | 522 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() { |
| 524 return sources_list_view_; | 523 return sources_list_view_; |
| 525 } | 524 } |
| 526 | 525 |
| 527 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel( | 526 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel( |
| 528 ui::DialogButton button) const { | 527 ui::DialogButton button) const { |
| 529 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK | 528 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ? |
| 530 ? IDS_DESKTOP_MEDIA_PICKER_SHARE | 529 IDS_DESKTOP_MEDIA_PICKER_SHARE : IDS_CANCEL); |
| 531 : IDS_CANCEL); | |
| 532 } | 530 } |
| 533 | 531 |
| 534 bool DesktopMediaPickerDialogView::Accept() { | 532 bool DesktopMediaPickerDialogView::Accept() { |
| 535 DesktopMediaSourceView* selection = sources_list_view_->GetSelection(); | 533 DesktopMediaSourceView* selection = sources_list_view_->GetSelection(); |
| 536 | 534 |
| 537 // Ok button should only be enabled when a source is selected. | 535 // Ok button should only be enabled when a source is selected. |
| 538 DCHECK(selection); | 536 DCHECK(selection); |
| 539 DesktopMediaID source = selection->source_id(); | 537 DesktopMediaID source = selection->source_id(); |
| 540 source.audio_share = audio_share_checkbox_ && | 538 source.audio_share = audio_share_checkbox_ && |
| 541 audio_share_checkbox_->enabled() && | 539 audio_share_checkbox_->enabled() && |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 | 616 |
| 619 DesktopMediaSourceView* | 617 DesktopMediaSourceView* |
| 620 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const { | 618 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const { |
| 621 if (sources_list_view_->child_count() <= index) | 619 if (sources_list_view_->child_count() <= index) |
| 622 return NULL; | 620 return NULL; |
| 623 | 621 |
| 624 return reinterpret_cast<DesktopMediaSourceView*>( | 622 return reinterpret_cast<DesktopMediaSourceView*>( |
| 625 sources_list_view_->child_at(index)); | 623 sources_list_view_->child_at(index)); |
| 626 } | 624 } |
| 627 | 625 |
| 628 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {} | 626 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) { |
| 627 } |
| 629 | 628 |
| 630 DesktopMediaPickerViews::~DesktopMediaPickerViews() { | 629 DesktopMediaPickerViews::~DesktopMediaPickerViews() { |
| 631 if (dialog_) { | 630 if (dialog_) { |
| 632 dialog_->DetachParent(); | 631 dialog_->DetachParent(); |
| 633 dialog_->GetWidget()->Close(); | 632 dialog_->GetWidget()->Close(); |
| 634 } | 633 } |
| 635 } | 634 } |
| 636 | 635 |
| 637 void DesktopMediaPickerViews::Show( | 636 void DesktopMediaPickerViews::Show( |
| 638 content::WebContents* web_contents, | 637 content::WebContents* web_contents, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 654 | 653 |
| 655 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { | 654 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { |
| 656 // 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. |
| 657 dialog_->DetachParent(); | 656 dialog_->DetachParent(); |
| 658 dialog_ = NULL; | 657 dialog_ = NULL; |
| 659 | 658 |
| 660 DCHECK(!callback_.is_null()); | 659 DCHECK(!callback_.is_null()); |
| 661 | 660 |
| 662 // Notify the |callback_| asynchronously because it may need to destroy | 661 // Notify the |callback_| asynchronously because it may need to destroy |
| 663 // DesktopMediaPicker. | 662 // DesktopMediaPicker. |
| 664 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 663 content::BrowserThread::PostTask( |
| 665 base::Bind(callback_, source)); | 664 content::BrowserThread::UI, FROM_HERE, |
| 665 base::Bind(callback_, source)); |
| 666 callback_.Reset(); | 666 callback_.Reset(); |
| 667 } | 667 } |
| 668 | 668 |
| 669 } // namespace deprecated | 669 // static |
| 670 std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
| 671 return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
| 672 } |
| OLD | NEW |