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