Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: chrome/browser/ui/views/desktop_media_picker_views.cc

Issue 1644073002: Desktop Share Audio User Permission (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: UI Layout Fix Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 description_label_(new views::Label()),
395 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), 397 audio_share_checkbox_(nullptr),
396 list_view_(new DesktopMediaListView(this, std::move(media_list))) { 398 sources_scroll_view_(views::ScrollView::CreateScrollViewWithBorder()),
399 sources_list_view_(
400 new DesktopMediaListView(this, std::move(media_list))) {
397 if (app_name == target_name) { 401 if (app_name == target_name) {
398 label_->SetText( 402 description_label_->SetText(
399 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); 403 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name));
400 } else { 404 } else {
401 label_->SetText(l10n_util::GetStringFUTF16( 405 description_label_->SetText(l10n_util::GetStringFUTF16(
402 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); 406 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name));
403 } 407 }
404 label_->SetMultiLine(true); 408 description_label_->SetMultiLine(true);
405 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 409 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
406 AddChildView(label_); 410 AddChildView(description_label_);
407 411
408 scroll_view_->SetContents(list_view_); 412 if (request_audio) {
409 scroll_view_->ClipHeightTo( 413 audio_share_checkbox_ = new views::Checkbox(
410 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); 414 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE));
411 AddChildView(scroll_view_); 415 AddChildView(audio_share_checkbox_);
416 audio_share_checkbox_->SetEnabled(false);
417 audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
418 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_NONE));
419 }
420
421 sources_scroll_view_->SetContents(sources_list_view_);
422 sources_scroll_view_->ClipHeightTo(GetMediaListViewHeightForRows(1),
423 GetMediaListViewHeightForRows(2));
424 AddChildView(sources_scroll_view_);
412 425
413 // If |parent_web_contents| is set and it's not a background page then the 426 // 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 427 // picker will be shown modal to the web contents. Otherwise the picker is
415 // shown in a separate window. 428 // shown in a separate window.
416 views::Widget* widget = NULL; 429 views::Widget* widget = NULL;
417 bool modal_dialog = 430 bool modal_dialog =
418 parent_web_contents && 431 parent_web_contents &&
419 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents); 432 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents);
420 if (modal_dialog) { 433 if (modal_dialog) {
421 widget = constrained_window::ShowWebModalDialogViews(this, 434 widget = constrained_window::ShowWebModalDialogViews(this,
(...skipping 17 matching lines...) Expand all
439 is_ash_window = chrome::IsNativeWindowInAsh(widget->GetNativeWindow()); 452 is_ash_window = chrome::IsNativeWindowInAsh(widget->GetNativeWindow());
440 #endif 453 #endif
441 454
442 // Set native window ID if the windows is outside Ash. 455 // Set native window ID if the windows is outside Ash.
443 if (!is_ash_window) { 456 if (!is_ash_window) {
444 dialog_window_id.id = AcceleratedWidgetToDesktopMediaId( 457 dialog_window_id.id = AcceleratedWidgetToDesktopMediaId(
445 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); 458 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
446 } 459 }
447 } 460 }
448 461
449 list_view_->StartUpdating(dialog_window_id); 462 sources_list_view_->StartUpdating(dialog_window_id);
450 } 463 }
451 464
452 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} 465 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {}
453 466
454 void DesktopMediaPickerDialogView::DetachParent() { 467 void DesktopMediaPickerDialogView::DetachParent() {
455 parent_ = NULL; 468 parent_ = NULL;
456 } 469 }
457 470
458 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { 471 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const {
459 static const size_t kDialogViewWidth = 600; 472 static const size_t kDialogViewWidth = 600;
473
460 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); 474 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets();
461 size_t label_height = 475
462 label_->GetHeightForWidth(kDialogViewWidth - title_insets.height() * 2); 476 const size_t kInnerWidth = kDialogViewWidth - title_insets.height() * 2;
477
478 size_t label_height = description_label_->GetHeightForWidth(kInnerWidth);
479
480 size_t checkbox_height_with_padding =
481 audio_share_checkbox_
482 ? audio_share_checkbox_->GetHeightForWidth(kInnerWidth) +
483 views::kPanelVertMargin
484 : 0;
463 485
464 return gfx::Size(kDialogViewWidth, 486 return gfx::Size(kDialogViewWidth,
465 views::kPanelVertMargin * 2 + label_height + 487 views::kPanelVertMargin * 2 + label_height +
488 checkbox_height_with_padding +
466 views::kPanelVerticalSpacing + 489 views::kPanelVerticalSpacing +
467 scroll_view_->GetPreferredSize().height()); 490 sources_scroll_view_->GetPreferredSize().height());
468 } 491 }
469 492
470 void DesktopMediaPickerDialogView::Layout() { 493 void DesktopMediaPickerDialogView::Layout() {
471 // DialogDelegate uses the bubble style frame. 494 // DialogDelegate uses the bubble style frame.
472 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); 495 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets();
473 gfx::Rect rect = GetLocalBounds(); 496 gfx::Rect rect = GetLocalBounds();
474 497
475 rect.Inset(title_insets.left(), views::kPanelVertMargin); 498 rect.Inset(title_insets.left(), views::kPanelVertMargin);
476 499
477 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(), 500 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(),
478 label_->GetHeightForWidth(rect.width())); 501 description_label_->GetHeightForWidth(rect.width()));
479 label_->SetBoundsRect(label_rect); 502 description_label_->SetBoundsRect(label_rect);
503
504 int checkbox_height = 0;
505 int checkbox_height_with_padding = 0;
506 if (audio_share_checkbox_) {
507 checkbox_height = audio_share_checkbox_->GetHeightForWidth(rect.width());
508 checkbox_height_with_padding = checkbox_height + views::kPanelVertMargin;
509 }
480 510
481 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing; 511 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing;
482 scroll_view_->SetBounds( 512 int scroll_view_height =
483 rect.x(), scroll_view_top, 513 rect.height() - scroll_view_top - checkbox_height_with_padding;
484 rect.width(), rect.height() - scroll_view_top); 514 gfx::Rect scroll_view_rect(rect.x(), scroll_view_top, rect.width(),
515 scroll_view_height);
516 sources_scroll_view_->SetBoundsRect(scroll_view_rect);
517
518 if (audio_share_checkbox_) {
519 gfx::Rect checkbox_rect(rect.x(),
520 scroll_view_rect.bottom() + views::kPanelVertMargin,
521 rect.width(), checkbox_height);
522 audio_share_checkbox_->SetBoundsRect(checkbox_rect);
523 }
485 } 524 }
486 525
487 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { 526 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
488 return ui::MODAL_TYPE_CHILD; 527 return ui::MODAL_TYPE_CHILD;
489 } 528 }
490 529
491 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const { 530 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const {
492 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_); 531 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_);
493 } 532 }
494 533
495 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled( 534 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled(
496 ui::DialogButton button) const { 535 ui::DialogButton button) const {
497 if (button == ui::DIALOG_BUTTON_OK) 536 if (button == ui::DIALOG_BUTTON_OK)
498 return list_view_->GetSelection() != NULL; 537 return sources_list_view_->GetSelection() != NULL;
499 return true; 538 return true;
500 } 539 }
501 540
502 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() { 541 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() {
503 return list_view_; 542 return sources_list_view_;
504 } 543 }
505 544
506 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel( 545 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel(
507 ui::DialogButton button) const { 546 ui::DialogButton button) const {
508 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ? 547 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ?
509 IDS_DESKTOP_MEDIA_PICKER_SHARE : IDS_CANCEL); 548 IDS_DESKTOP_MEDIA_PICKER_SHARE : IDS_CANCEL);
510 } 549 }
511 550
512 bool DesktopMediaPickerDialogView::Accept() { 551 bool DesktopMediaPickerDialogView::Accept() {
513 DesktopMediaSourceView* selection = list_view_->GetSelection(); 552 DesktopMediaSourceView* selection = sources_list_view_->GetSelection();
514 553
515 // Ok button should only be enabled when a source is selected. 554 // Ok button should only be enabled when a source is selected.
516 DCHECK(selection); 555 DCHECK(selection);
517 556
518 DesktopMediaID source; 557 DesktopMediaID source;
519 if (selection) 558 if (selection)
520 source = selection->source_id(); 559 source = selection->source_id();
521 560
561 if (audio_share_checkbox_) {
562 source.audio_share =
msw 2016/02/03 19:34:19 nit: remove conditional above and include it in th
qiangchen 2016/02/03 23:45:10 Done.
563 audio_share_checkbox_->enabled() && audio_share_checkbox_->checked();
564 }
565
522 if (parent_) 566 if (parent_)
523 parent_->NotifyDialogResult(source); 567 parent_->NotifyDialogResult(source);
524 568
525 // Return true to close the window. 569 // Return true to close the window.
526 return true; 570 return true;
527 } 571 }
528 572
529 void DesktopMediaPickerDialogView::DeleteDelegate() { 573 void DesktopMediaPickerDialogView::DeleteDelegate() {
530 // If the dialog is being closed then notify the parent about it. 574 // If the dialog is being closed then notify the parent about it.
531 if (parent_) 575 if (parent_)
532 parent_->NotifyDialogResult(DesktopMediaID()); 576 parent_->NotifyDialogResult(DesktopMediaID());
533 delete this; 577 delete this;
534 } 578 }
535 579
536 void DesktopMediaPickerDialogView::OnSelectionChanged() { 580 void DesktopMediaPickerDialogView::OnSelectionChanged() {
537 GetDialogClientView()->UpdateDialogButtons(); 581 GetDialogClientView()->UpdateDialogButtons();
582
583 // Disable the checkbox if we cannot support audio for the selected source.
584 if (audio_share_checkbox_) {
585 DesktopMediaSourceView* selection = sources_list_view_->GetSelection();
586
587 DesktopMediaID source;
588 if (selection)
589 source = selection->source_id();
590
591 if (source.type == DesktopMediaID::TYPE_SCREEN) {
592 audio_share_checkbox_->SetEnabled(true);
593 audio_share_checkbox_->SetTooltipText(base::string16());
594 } else if (source.type == DesktopMediaID::TYPE_WINDOW) {
595 audio_share_checkbox_->SetEnabled(false);
596 audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
597 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_WINDOW));
598 } else {
599 NOTREACHED();
600 }
601 }
538 } 602 }
539 603
540 void DesktopMediaPickerDialogView::OnDoubleClick() { 604 void DesktopMediaPickerDialogView::OnDoubleClick() {
541 // This will call Accept() and close the dialog. 605 // This will call Accept() and close the dialog.
542 GetDialogClientView()->AcceptWindow(); 606 GetDialogClientView()->AcceptWindow();
543 } 607 }
544 608
545 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() { 609 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() {
546 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen(); 610 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen();
547 611
548 int new_height = widget_bound.height() - scroll_view_->height() + 612 int new_height = widget_bound.height() - sources_scroll_view_->height() +
549 scroll_view_->GetPreferredSize().height(); 613 sources_scroll_view_->GetPreferredSize().height();
550 614
551 GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height)); 615 GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height));
552 } 616 }
553 617
554 DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting() 618 DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting()
555 const { 619 const {
556 return list_view_; 620 return sources_list_view_;
557 } 621 }
558 622
559 DesktopMediaSourceView* 623 DesktopMediaSourceView*
560 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const { 624 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const {
561 if (list_view_->child_count() <= index) 625 if (sources_list_view_->child_count() <= index)
562 return NULL; 626 return NULL;
563 627
564 return reinterpret_cast<DesktopMediaSourceView*>(list_view_->child_at(index)); 628 return reinterpret_cast<DesktopMediaSourceView*>(
629 sources_list_view_->child_at(index));
565 } 630 }
566 631
567 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) { 632 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {
568 } 633 }
569 634
570 DesktopMediaPickerViews::~DesktopMediaPickerViews() { 635 DesktopMediaPickerViews::~DesktopMediaPickerViews() {
571 if (dialog_) { 636 if (dialog_) {
572 dialog_->DetachParent(); 637 dialog_->DetachParent();
573 dialog_->GetWidget()->Close(); 638 dialog_->GetWidget()->Close();
574 } 639 }
575 } 640 }
576 641
577 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, 642 void DesktopMediaPickerViews::Show(content::WebContents* web_contents,
578 gfx::NativeWindow context, 643 gfx::NativeWindow context,
579 gfx::NativeWindow parent, 644 gfx::NativeWindow parent,
580 const base::string16& app_name, 645 const base::string16& app_name,
581 const base::string16& target_name, 646 const base::string16& target_name,
582 scoped_ptr<DesktopMediaList> media_list, 647 scoped_ptr<DesktopMediaList> media_list,
648 bool request_audio,
583 const DoneCallback& done_callback) { 649 const DoneCallback& done_callback) {
584 callback_ = done_callback; 650 callback_ = done_callback;
585 dialog_ = 651 dialog_ = new DesktopMediaPickerDialogView(
586 new DesktopMediaPickerDialogView(web_contents, context, this, app_name, 652 web_contents, context, this, app_name, target_name, std::move(media_list),
587 target_name, std::move(media_list)); 653 request_audio);
588 } 654 }
589 655
590 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { 656 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) {
591 // 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.
592 dialog_->DetachParent(); 658 dialog_->DetachParent();
593 dialog_ = NULL; 659 dialog_ = NULL;
594 660
595 DCHECK(!callback_.is_null()); 661 DCHECK(!callback_.is_null());
596 662
597 // Notify the |callback_| asynchronously because it may need to destroy 663 // Notify the |callback_| asynchronously because it may need to destroy
598 // DesktopMediaPicker. 664 // DesktopMediaPicker.
599 content::BrowserThread::PostTask( 665 content::BrowserThread::PostTask(
600 content::BrowserThread::UI, FROM_HERE, 666 content::BrowserThread::UI, FROM_HERE,
601 base::Bind(callback_, source)); 667 base::Bind(callback_, source));
602 callback_.Reset(); 668 callback_.Reset();
603 } 669 }
604 670
605 // static 671 // static
606 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { 672 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() {
607 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); 673 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews());
608 } 674 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/desktop_media_picker_views.h ('k') | chrome/browser/ui/views/desktop_media_picker_views_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698