| 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 25 matching lines...) Expand all Loading... |
| 503 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { | 502 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { |
| 504 static const size_t kDialogViewWidth = 600; | 503 static const size_t kDialogViewWidth = 600; |
| 505 return gfx::Size(kDialogViewWidth, GetHeightForWidth(kDialogViewWidth)); | 504 return gfx::Size(kDialogViewWidth, GetHeightForWidth(kDialogViewWidth)); |
| 506 } | 505 } |
| 507 | 506 |
| 508 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { | 507 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { |
| 509 return ui::MODAL_TYPE_CHILD; | 508 return ui::MODAL_TYPE_CHILD; |
| 510 } | 509 } |
| 511 | 510 |
| 512 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const { | 511 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const { |
| 513 return l10n_util::GetStringFUTF16( | 512 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_); |
| 514 IDS_DESKTOP_MEDIA_PICKER_TITLE_DEPRECATED, app_name_); | |
| 515 } | 513 } |
| 516 | 514 |
| 517 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled( | 515 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled( |
| 518 ui::DialogButton button) const { | 516 ui::DialogButton button) const { |
| 519 if (button == ui::DIALOG_BUTTON_OK) | 517 if (button == ui::DIALOG_BUTTON_OK) |
| 520 return sources_list_view_->GetSelection() != NULL; | 518 return sources_list_view_->GetSelection() != NULL; |
| 521 return true; | 519 return true; |
| 522 } | 520 } |
| 523 | 521 |
| 524 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() { | 522 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() { |
| 525 return sources_list_view_; | 523 return sources_list_view_; |
| 526 } | 524 } |
| 527 | 525 |
| 528 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel( | 526 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel( |
| 529 ui::DialogButton button) const { | 527 ui::DialogButton button) const { |
| 530 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK | 528 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ? |
| 531 ? IDS_DESKTOP_MEDIA_PICKER_SHARE | 529 IDS_DESKTOP_MEDIA_PICKER_SHARE : IDS_CANCEL); |
| 532 : IDS_CANCEL); | |
| 533 } | 530 } |
| 534 | 531 |
| 535 bool DesktopMediaPickerDialogView::Accept() { | 532 bool DesktopMediaPickerDialogView::Accept() { |
| 536 DesktopMediaSourceView* selection = sources_list_view_->GetSelection(); | 533 DesktopMediaSourceView* selection = sources_list_view_->GetSelection(); |
| 537 | 534 |
| 538 // Ok button should only be enabled when a source is selected. | 535 // Ok button should only be enabled when a source is selected. |
| 539 DCHECK(selection); | 536 DCHECK(selection); |
| 540 DesktopMediaID source = selection->source_id(); | 537 DesktopMediaID source = selection->source_id(); |
| 541 source.audio_share = audio_share_checkbox_ && | 538 source.audio_share = audio_share_checkbox_ && |
| 542 audio_share_checkbox_->enabled() && | 539 audio_share_checkbox_->enabled() && |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 616 |
| 620 DesktopMediaSourceView* | 617 DesktopMediaSourceView* |
| 621 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const { | 618 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const { |
| 622 if (sources_list_view_->child_count() <= index) | 619 if (sources_list_view_->child_count() <= index) |
| 623 return NULL; | 620 return NULL; |
| 624 | 621 |
| 625 return reinterpret_cast<DesktopMediaSourceView*>( | 622 return reinterpret_cast<DesktopMediaSourceView*>( |
| 626 sources_list_view_->child_at(index)); | 623 sources_list_view_->child_at(index)); |
| 627 } | 624 } |
| 628 | 625 |
| 629 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {} | 626 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) { |
| 627 } |
| 630 | 628 |
| 631 DesktopMediaPickerViews::~DesktopMediaPickerViews() { | 629 DesktopMediaPickerViews::~DesktopMediaPickerViews() { |
| 632 if (dialog_) { | 630 if (dialog_) { |
| 633 dialog_->DetachParent(); | 631 dialog_->DetachParent(); |
| 634 dialog_->GetWidget()->Close(); | 632 dialog_->GetWidget()->Close(); |
| 635 } | 633 } |
| 636 } | 634 } |
| 637 | 635 |
| 638 void DesktopMediaPickerViews::Show( | 636 void DesktopMediaPickerViews::Show( |
| 639 content::WebContents* web_contents, | 637 content::WebContents* web_contents, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 655 | 653 |
| 656 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { | 654 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { |
| 657 // 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. |
| 658 dialog_->DetachParent(); | 656 dialog_->DetachParent(); |
| 659 dialog_ = NULL; | 657 dialog_ = NULL; |
| 660 | 658 |
| 661 DCHECK(!callback_.is_null()); | 659 DCHECK(!callback_.is_null()); |
| 662 | 660 |
| 663 // Notify the |callback_| asynchronously because it may need to destroy | 661 // Notify the |callback_| asynchronously because it may need to destroy |
| 664 // DesktopMediaPicker. | 662 // DesktopMediaPicker. |
| 665 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 663 content::BrowserThread::PostTask( |
| 666 base::Bind(callback_, source)); | 664 content::BrowserThread::UI, FROM_HERE, |
| 665 base::Bind(callback_, source)); |
| 667 callback_.Reset(); | 666 callback_.Reset(); |
| 668 } | 667 } |
| 669 | 668 |
| 670 } // namespace deprecated | 669 // static |
| 670 std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
| 671 return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
| 672 } |
| OLD | NEW |