Chromium Code Reviews| 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 checkbox_->SetEnabled(false); | |
| 416 checkbox_->SetTooltipText(l10n_util::GetStringUTF16( | |
| 417 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_NONE)); | |
| 418 } | |
| 419 | |
| 408 scroll_view_->SetContents(list_view_); | 420 scroll_view_->SetContents(list_view_); |
| 409 scroll_view_->ClipHeightTo( | 421 scroll_view_->ClipHeightTo( |
| 410 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); | 422 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); |
| 411 AddChildView(scroll_view_); | 423 AddChildView(scroll_view_); |
| 412 | 424 |
| 413 // If |parent_web_contents| is set and it's not a background page then the | 425 // 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 | 426 // picker will be shown modal to the web contents. Otherwise the picker is |
| 415 // shown in a separate window. | 427 // shown in a separate window. |
| 416 views::Widget* widget = NULL; | 428 views::Widget* widget = NULL; |
| 417 bool modal_dialog = | 429 bool modal_dialog = |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 list_view_->StartUpdating(dialog_window_id); | 461 list_view_->StartUpdating(dialog_window_id); |
| 450 } | 462 } |
| 451 | 463 |
| 452 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} | 464 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} |
| 453 | 465 |
| 454 void DesktopMediaPickerDialogView::DetachParent() { | 466 void DesktopMediaPickerDialogView::DetachParent() { |
| 455 parent_ = NULL; | 467 parent_ = NULL; |
| 456 } | 468 } |
| 457 | 469 |
| 458 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { | 470 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { |
| 459 static const size_t kDialogViewWidth = 600; | 471 static const size_t kDialogViewWidth = 600; |
|
msw
2016/02/03 18:21:55
You should ensure that the checkbox preferred widt
qiangchen
2016/02/03 19:19:02
Changed to GetHeightForWidth
| |
| 460 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); | 472 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); |
| 461 size_t label_height = | 473 size_t label_height = |
| 462 label_->GetHeightForWidth(kDialogViewWidth - title_insets.height() * 2); | 474 label_->GetHeightForWidth(kDialogViewWidth - title_insets.height() * 2); |
| 463 | 475 |
| 476 size_t checkbox_height = | |
| 477 checkbox_ ? checkbox_->GetPreferredSize().height() : 0; | |
|
msw
2016/02/03 18:21:55
You need to add an additional views::kPanelVertMar
qiangchen
2016/02/03 19:19:02
Done.
| |
| 478 | |
| 464 return gfx::Size(kDialogViewWidth, | 479 return gfx::Size(kDialogViewWidth, |
| 465 views::kPanelVertMargin * 2 + label_height + | 480 views::kPanelVertMargin * 2 + label_height + |
| 466 views::kPanelVerticalSpacing + | 481 checkbox_height + views::kPanelVerticalSpacing + |
| 467 scroll_view_->GetPreferredSize().height()); | 482 scroll_view_->GetPreferredSize().height()); |
| 468 } | 483 } |
| 469 | 484 |
| 470 void DesktopMediaPickerDialogView::Layout() { | 485 void DesktopMediaPickerDialogView::Layout() { |
| 471 // DialogDelegate uses the bubble style frame. | 486 // DialogDelegate uses the bubble style frame. |
| 472 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); | 487 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); |
| 473 gfx::Rect rect = GetLocalBounds(); | 488 gfx::Rect rect = GetLocalBounds(); |
| 474 | 489 |
| 475 rect.Inset(title_insets.left(), views::kPanelVertMargin); | 490 rect.Inset(title_insets.left(), views::kPanelVertMargin); |
| 476 | 491 |
| 477 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(), | 492 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(), |
| 478 label_->GetHeightForWidth(rect.width())); | 493 label_->GetHeightForWidth(rect.width())); |
| 479 label_->SetBoundsRect(label_rect); | 494 label_->SetBoundsRect(label_rect); |
| 480 | 495 |
| 481 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing; | 496 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing; |
| 482 scroll_view_->SetBounds( | 497 int scroll_view_height = |
| 483 rect.x(), scroll_view_top, | 498 rect.height() - scroll_view_top - |
| 484 rect.width(), rect.height() - scroll_view_top); | 499 (checkbox_ ? checkbox_->GetPreferredSize().height() : 0); |
|
msw
2016/02/03 18:21:55
Ditto: You need to add an additional views::kPanel
qiangchen
2016/02/03 19:19:01
Done.
| |
| 500 gfx::Rect scroll_view_rect(rect.x(), scroll_view_top, rect.width(), | |
| 501 scroll_view_height); | |
| 502 scroll_view_->SetBoundsRect(scroll_view_rect); | |
| 503 | |
| 504 if (checkbox_) { | |
| 505 gfx::Rect checkbox_rect( | |
| 506 rect.x(), scroll_view_rect.bottom() + views::kPanelVertMargin, | |
| 507 rect.width(), checkbox_->GetHeightForWidth(rect.width())); | |
|
msw
2016/02/03 18:21:55
Using GetHeightForWidth here, but GetPreferredSize
qiangchen
2016/02/03 19:19:01
Done.
| |
| 508 checkbox_->SetBoundsRect(checkbox_rect); | |
| 509 } | |
| 485 } | 510 } |
| 486 | 511 |
| 487 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { | 512 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { |
| 488 return ui::MODAL_TYPE_CHILD; | 513 return ui::MODAL_TYPE_CHILD; |
| 489 } | 514 } |
| 490 | 515 |
| 491 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const { | 516 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const { |
| 492 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_); | 517 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_); |
| 493 } | 518 } |
| 494 | 519 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 512 bool DesktopMediaPickerDialogView::Accept() { | 537 bool DesktopMediaPickerDialogView::Accept() { |
| 513 DesktopMediaSourceView* selection = list_view_->GetSelection(); | 538 DesktopMediaSourceView* selection = list_view_->GetSelection(); |
| 514 | 539 |
| 515 // Ok button should only be enabled when a source is selected. | 540 // Ok button should only be enabled when a source is selected. |
| 516 DCHECK(selection); | 541 DCHECK(selection); |
| 517 | 542 |
| 518 DesktopMediaID source; | 543 DesktopMediaID source; |
| 519 if (selection) | 544 if (selection) |
| 520 source = selection->source_id(); | 545 source = selection->source_id(); |
| 521 | 546 |
| 547 if (checkbox_) { | |
|
msw
2016/02/03 18:21:55
nit: remove curly braces
qiangchen
2016/02/03 19:19:01
N/A now, as variable name change make it multiple
| |
| 548 source.audio_share = checkbox_->enabled() && checkbox_->checked(); | |
| 549 } | |
| 550 | |
| 522 if (parent_) | 551 if (parent_) |
| 523 parent_->NotifyDialogResult(source); | 552 parent_->NotifyDialogResult(source); |
| 524 | 553 |
| 525 // Return true to close the window. | 554 // Return true to close the window. |
| 526 return true; | 555 return true; |
| 527 } | 556 } |
| 528 | 557 |
| 529 void DesktopMediaPickerDialogView::DeleteDelegate() { | 558 void DesktopMediaPickerDialogView::DeleteDelegate() { |
| 530 // If the dialog is being closed then notify the parent about it. | 559 // If the dialog is being closed then notify the parent about it. |
| 531 if (parent_) | 560 if (parent_) |
| 532 parent_->NotifyDialogResult(DesktopMediaID()); | 561 parent_->NotifyDialogResult(DesktopMediaID()); |
| 533 delete this; | 562 delete this; |
| 534 } | 563 } |
| 535 | 564 |
| 536 void DesktopMediaPickerDialogView::OnSelectionChanged() { | 565 void DesktopMediaPickerDialogView::OnSelectionChanged() { |
| 537 GetDialogClientView()->UpdateDialogButtons(); | 566 GetDialogClientView()->UpdateDialogButtons(); |
| 567 | |
| 568 // Disable the checkbox if we cannot support audio for the selected source | |
|
msw
2016/02/03 18:21:55
nit: trailing period
qiangchen
2016/02/03 19:19:01
Done.
| |
| 569 if (checkbox_) { | |
| 570 DesktopMediaSourceView* selection = list_view_->GetSelection(); | |
| 571 | |
| 572 DesktopMediaID source; | |
| 573 if (selection) | |
| 574 source = selection->source_id(); | |
| 575 | |
| 576 if (source.type == DesktopMediaID::TYPE_SCREEN) { | |
| 577 checkbox_->SetEnabled(true); | |
| 578 checkbox_->SetTooltipText(base::UTF8ToUTF16("")); | |
|
msw
2016/02/03 18:21:55
Use base::string16() here instead of base::UTF8ToU
qiangchen
2016/02/03 19:19:01
Done.
| |
| 579 } else if (source.type == DesktopMediaID::TYPE_WINDOW) { | |
| 580 checkbox_->SetEnabled(false); | |
| 581 checkbox_->SetTooltipText(l10n_util::GetStringUTF16( | |
| 582 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_WINDOW)); | |
| 583 } else { | |
| 584 NOTREACHED(); | |
| 585 } | |
| 586 } | |
| 538 } | 587 } |
| 539 | 588 |
| 540 void DesktopMediaPickerDialogView::OnDoubleClick() { | 589 void DesktopMediaPickerDialogView::OnDoubleClick() { |
| 541 // This will call Accept() and close the dialog. | 590 // This will call Accept() and close the dialog. |
| 542 GetDialogClientView()->AcceptWindow(); | 591 GetDialogClientView()->AcceptWindow(); |
| 543 } | 592 } |
| 544 | 593 |
| 545 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() { | 594 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() { |
| 546 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen(); | 595 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen(); |
| 547 | 596 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 573 dialog_->GetWidget()->Close(); | 622 dialog_->GetWidget()->Close(); |
| 574 } | 623 } |
| 575 } | 624 } |
| 576 | 625 |
| 577 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, | 626 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, |
| 578 gfx::NativeWindow context, | 627 gfx::NativeWindow context, |
| 579 gfx::NativeWindow parent, | 628 gfx::NativeWindow parent, |
| 580 const base::string16& app_name, | 629 const base::string16& app_name, |
| 581 const base::string16& target_name, | 630 const base::string16& target_name, |
| 582 scoped_ptr<DesktopMediaList> media_list, | 631 scoped_ptr<DesktopMediaList> media_list, |
| 632 bool request_audio, | |
| 583 const DoneCallback& done_callback) { | 633 const DoneCallback& done_callback) { |
| 584 callback_ = done_callback; | 634 callback_ = done_callback; |
| 585 dialog_ = | 635 dialog_ = new DesktopMediaPickerDialogView( |
| 586 new DesktopMediaPickerDialogView(web_contents, context, this, app_name, | 636 web_contents, context, this, app_name, target_name, std::move(media_list), |
| 587 target_name, std::move(media_list)); | 637 request_audio); |
| 588 } | 638 } |
| 589 | 639 |
| 590 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { | 640 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { |
| 591 // Once this method is called the |dialog_| will close and destroy itself. | 641 // Once this method is called the |dialog_| will close and destroy itself. |
| 592 dialog_->DetachParent(); | 642 dialog_->DetachParent(); |
| 593 dialog_ = NULL; | 643 dialog_ = NULL; |
| 594 | 644 |
| 595 DCHECK(!callback_.is_null()); | 645 DCHECK(!callback_.is_null()); |
| 596 | 646 |
| 597 // Notify the |callback_| asynchronously because it may need to destroy | 647 // Notify the |callback_| asynchronously because it may need to destroy |
| 598 // DesktopMediaPicker. | 648 // DesktopMediaPicker. |
| 599 content::BrowserThread::PostTask( | 649 content::BrowserThread::PostTask( |
| 600 content::BrowserThread::UI, FROM_HERE, | 650 content::BrowserThread::UI, FROM_HERE, |
| 601 base::Bind(callback_, source)); | 651 base::Bind(callback_, source)); |
| 602 callback_.Reset(); | 652 callback_.Reset(); |
| 603 } | 653 } |
| 604 | 654 |
| 605 // static | 655 // static |
| 606 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 656 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
| 607 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 657 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
| 608 } | 658 } |
| OLD | NEW |