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