| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "content/public/browser/web_contents_delegate.h" | 21 #include "content/public/browser/web_contents_delegate.h" |
| 22 #include "grit/components_strings.h" | 22 #include "grit/components_strings.h" |
| 23 #include "ui/aura/window_tree_host.h" | 23 #include "ui/aura/window_tree_host.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/events/event_constants.h" | 25 #include "ui/events/event_constants.h" |
| 26 #include "ui/events/keycodes/keyboard_codes.h" | 26 #include "ui/events/keycodes/keyboard_codes.h" |
| 27 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 28 #include "ui/native_theme/native_theme.h" | 28 #include "ui/native_theme/native_theme.h" |
| 29 #include "ui/views/background.h" | 29 #include "ui/views/background.h" |
| 30 #include "ui/views/bubble/bubble_frame_view.h" | 30 #include "ui/views/bubble/bubble_frame_view.h" |
| 31 #include "ui/views/controls/button/checkbox.h" |
| 31 #include "ui/views/controls/image_view.h" | 32 #include "ui/views/controls/image_view.h" |
| 32 #include "ui/views/controls/label.h" | 33 #include "ui/views/controls/label.h" |
| 33 #include "ui/views/controls/scroll_view.h" | 34 #include "ui/views/controls/scroll_view.h" |
| 34 #include "ui/views/layout/layout_constants.h" | 35 #include "ui/views/layout/layout_constants.h" |
| 35 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 36 #include "ui/views/window/dialog_client_view.h" | 37 #include "ui/views/window/dialog_client_view.h" |
| 37 #include "ui/wm/core/shadow_types.h" | 38 #include "ui/wm/core/shadow_types.h" |
| 38 | 39 |
| 39 using content::DesktopMediaID; | 40 using content::DesktopMediaID; |
| 40 | 41 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 OnSelectionChanged(); | 382 OnSelectionChanged(); |
| 382 OnDoubleClick(); | 383 OnDoubleClick(); |
| 383 } | 384 } |
| 384 | 385 |
| 385 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( | 386 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( |
| 386 content::WebContents* parent_web_contents, | 387 content::WebContents* parent_web_contents, |
| 387 gfx::NativeWindow context, | 388 gfx::NativeWindow context, |
| 388 DesktopMediaPickerViews* parent, | 389 DesktopMediaPickerViews* parent, |
| 389 const base::string16& app_name, | 390 const base::string16& app_name, |
| 390 const base::string16& target_name, | 391 const base::string16& target_name, |
| 391 scoped_ptr<DesktopMediaList> media_list) | 392 scoped_ptr<DesktopMediaList> media_list, |
| 393 bool request_audio) |
| 392 : parent_(parent), | 394 : parent_(parent), |
| 393 app_name_(app_name), | 395 app_name_(app_name), |
| 394 label_(new views::Label()), | 396 label_(new views::Label()), |
| 397 checkbox_(nullptr), |
| 395 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), | 398 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), |
| 396 list_view_(new DesktopMediaListView(this, std::move(media_list))) { | 399 list_view_(new DesktopMediaListView(this, std::move(media_list))) { |
| 397 if (app_name == target_name) { | 400 if (app_name == target_name) { |
| 398 label_->SetText( | 401 label_->SetText( |
| 399 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); | 402 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); |
| 400 } else { | 403 } else { |
| 401 label_->SetText(l10n_util::GetStringFUTF16( | 404 label_->SetText(l10n_util::GetStringFUTF16( |
| 402 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); | 405 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); |
| 403 } | 406 } |
| 404 label_->SetMultiLine(true); | 407 label_->SetMultiLine(true); |
| 405 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 408 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 406 AddChildView(label_); | 409 AddChildView(label_); |
| 407 | 410 |
| 411 if (request_audio) { |
| 412 checkbox_ = new views::Checkbox( |
| 413 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE)); |
| 414 AddChildView(checkbox_); |
| 415 } |
| 416 |
| 408 scroll_view_->SetContents(list_view_); | 417 scroll_view_->SetContents(list_view_); |
| 409 scroll_view_->ClipHeightTo( | 418 scroll_view_->ClipHeightTo( |
| 410 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); | 419 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); |
| 411 AddChildView(scroll_view_); | 420 AddChildView(scroll_view_); |
| 412 | 421 |
| 413 // If |parent_web_contents| is set and it's not a background page then the | 422 // If |parent_web_contents| is set and it's not a background page then the |
| 414 // picker will be shown modal to the web contents. Otherwise the picker is | 423 // picker will be shown modal to the web contents. Otherwise the picker is |
| 415 // shown in a separate window. | 424 // shown in a separate window. |
| 416 views::Widget* widget = NULL; | 425 views::Widget* widget = NULL; |
| 417 bool modal_dialog = | 426 bool modal_dialog = |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 void DesktopMediaPickerDialogView::DetachParent() { | 463 void DesktopMediaPickerDialogView::DetachParent() { |
| 455 parent_ = NULL; | 464 parent_ = NULL; |
| 456 } | 465 } |
| 457 | 466 |
| 458 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { | 467 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { |
| 459 static const size_t kDialogViewWidth = 600; | 468 static const size_t kDialogViewWidth = 600; |
| 460 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); | 469 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); |
| 461 size_t label_height = | 470 size_t label_height = |
| 462 label_->GetHeightForWidth(kDialogViewWidth - title_insets.height() * 2); | 471 label_->GetHeightForWidth(kDialogViewWidth - title_insets.height() * 2); |
| 463 | 472 |
| 473 size_t checkbox_height = |
| 474 checkbox_ ? checkbox_->GetPreferredSize().height() : 0; |
| 475 |
| 464 return gfx::Size(kDialogViewWidth, | 476 return gfx::Size(kDialogViewWidth, |
| 465 views::kPanelVertMargin * 2 + label_height + | 477 views::kPanelVertMargin * 2 + label_height + |
| 466 views::kPanelVerticalSpacing + | 478 checkbox_height + views::kPanelVerticalSpacing + |
| 467 scroll_view_->GetPreferredSize().height()); | 479 scroll_view_->GetPreferredSize().height()); |
| 468 } | 480 } |
| 469 | 481 |
| 470 void DesktopMediaPickerDialogView::Layout() { | 482 void DesktopMediaPickerDialogView::Layout() { |
| 471 // DialogDelegate uses the bubble style frame. | 483 // DialogDelegate uses the bubble style frame. |
| 472 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); | 484 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); |
| 473 gfx::Rect rect = GetLocalBounds(); | 485 gfx::Rect rect = GetLocalBounds(); |
| 474 | 486 |
| 475 rect.Inset(title_insets.left(), views::kPanelVertMargin); | 487 rect.Inset(title_insets.left(), views::kPanelVertMargin); |
| 476 | 488 |
| 477 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(), | 489 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(), |
| 478 label_->GetHeightForWidth(rect.width())); | 490 label_->GetHeightForWidth(rect.width())); |
| 479 label_->SetBoundsRect(label_rect); | 491 label_->SetBoundsRect(label_rect); |
| 480 | 492 |
| 493 if (checkbox_) { |
| 494 gfx::Rect checkbox_rect( |
| 495 rect.x(), label_rect.bottom() + views::kPanelVertMargin, rect.width(), |
| 496 checkbox_->GetHeightForWidth(rect.width())); |
| 497 checkbox_->SetBoundsRect(checkbox_rect); |
| 498 } |
| 499 |
| 481 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing; | 500 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing; |
| 482 scroll_view_->SetBounds( | 501 scroll_view_->SetBounds( |
| 483 rect.x(), scroll_view_top, | 502 rect.x(), scroll_view_top, |
| 484 rect.width(), rect.height() - scroll_view_top); | 503 rect.width(), rect.height() - scroll_view_top); |
| 485 } | 504 } |
| 486 | 505 |
| 487 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { | 506 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { |
| 488 return ui::MODAL_TYPE_CHILD; | 507 return ui::MODAL_TYPE_CHILD; |
| 489 } | 508 } |
| 490 | 509 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 512 bool DesktopMediaPickerDialogView::Accept() { | 531 bool DesktopMediaPickerDialogView::Accept() { |
| 513 DesktopMediaSourceView* selection = list_view_->GetSelection(); | 532 DesktopMediaSourceView* selection = list_view_->GetSelection(); |
| 514 | 533 |
| 515 // Ok button should only be enabled when a source is selected. | 534 // Ok button should only be enabled when a source is selected. |
| 516 DCHECK(selection); | 535 DCHECK(selection); |
| 517 | 536 |
| 518 DesktopMediaID source; | 537 DesktopMediaID source; |
| 519 if (selection) | 538 if (selection) |
| 520 source = selection->source_id(); | 539 source = selection->source_id(); |
| 521 | 540 |
| 541 if (checkbox_) { |
| 542 source.audio_share = checkbox_->checked(); |
| 543 } |
| 544 |
| 522 if (parent_) | 545 if (parent_) |
| 523 parent_->NotifyDialogResult(source); | 546 parent_->NotifyDialogResult(source); |
| 524 | 547 |
| 525 // Return true to close the window. | 548 // Return true to close the window. |
| 526 return true; | 549 return true; |
| 527 } | 550 } |
| 528 | 551 |
| 529 void DesktopMediaPickerDialogView::DeleteDelegate() { | 552 void DesktopMediaPickerDialogView::DeleteDelegate() { |
| 530 // If the dialog is being closed then notify the parent about it. | 553 // If the dialog is being closed then notify the parent about it. |
| 531 if (parent_) | 554 if (parent_) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 dialog_->GetWidget()->Close(); | 596 dialog_->GetWidget()->Close(); |
| 574 } | 597 } |
| 575 } | 598 } |
| 576 | 599 |
| 577 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, | 600 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, |
| 578 gfx::NativeWindow context, | 601 gfx::NativeWindow context, |
| 579 gfx::NativeWindow parent, | 602 gfx::NativeWindow parent, |
| 580 const base::string16& app_name, | 603 const base::string16& app_name, |
| 581 const base::string16& target_name, | 604 const base::string16& target_name, |
| 582 scoped_ptr<DesktopMediaList> media_list, | 605 scoped_ptr<DesktopMediaList> media_list, |
| 606 bool request_audio, |
| 583 const DoneCallback& done_callback) { | 607 const DoneCallback& done_callback) { |
| 584 callback_ = done_callback; | 608 callback_ = done_callback; |
| 585 dialog_ = | 609 dialog_ = new DesktopMediaPickerDialogView( |
| 586 new DesktopMediaPickerDialogView(web_contents, context, this, app_name, | 610 web_contents, context, this, app_name, target_name, std::move(media_list), |
| 587 target_name, std::move(media_list)); | 611 request_audio); |
| 588 } | 612 } |
| 589 | 613 |
| 590 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { | 614 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { |
| 591 // Once this method is called the |dialog_| will close and destroy itself. | 615 // Once this method is called the |dialog_| will close and destroy itself. |
| 592 dialog_->DetachParent(); | 616 dialog_->DetachParent(); |
| 593 dialog_ = NULL; | 617 dialog_ = NULL; |
| 594 | 618 |
| 595 DCHECK(!callback_.is_null()); | 619 DCHECK(!callback_.is_null()); |
| 596 | 620 |
| 597 // Notify the |callback_| asynchronously because it may need to destroy | 621 // Notify the |callback_| asynchronously because it may need to destroy |
| 598 // DesktopMediaPicker. | 622 // DesktopMediaPicker. |
| 599 content::BrowserThread::PostTask( | 623 content::BrowserThread::PostTask( |
| 600 content::BrowserThread::UI, FROM_HERE, | 624 content::BrowserThread::UI, FROM_HERE, |
| 601 base::Bind(callback_, source)); | 625 base::Bind(callback_, source)); |
| 602 callback_.Reset(); | 626 callback_.Reset(); |
| 603 } | 627 } |
| 604 | 628 |
| 605 // static | 629 // static |
| 606 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 630 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
| 607 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 631 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
| 608 } | 632 } |
| OLD | NEW |