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

Unified 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: Fix Compiler Issue Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/desktop_media_picker_views.cc
diff --git a/chrome/browser/ui/views/desktop_media_picker_views.cc b/chrome/browser/ui/views/desktop_media_picker_views.cc
index 2614f56088103a2849e8d0ee12042d020ab0c801..aec60d0721f58b9672891adc8c26b1448815b842 100644
--- a/chrome/browser/ui/views/desktop_media_picker_views.cc
+++ b/chrome/browser/ui/views/desktop_media_picker_views.cc
@@ -28,6 +28,7 @@
#include "ui/native_theme/native_theme.h"
#include "ui/views/background.h"
#include "ui/views/bubble/bubble_frame_view.h"
+#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/scroll_view.h"
@@ -388,10 +389,12 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
DesktopMediaPickerViews* parent,
const base::string16& app_name,
const base::string16& target_name,
- scoped_ptr<DesktopMediaList> media_list)
+ scoped_ptr<DesktopMediaList> media_list,
+ bool request_audio)
: parent_(parent),
app_name_(app_name),
label_(new views::Label()),
+ checkbox_(nullptr),
scroll_view_(views::ScrollView::CreateScrollViewWithBorder()),
list_view_(new DesktopMediaListView(this, std::move(media_list))) {
if (app_name == target_name) {
@@ -405,6 +408,15 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(label_);
+ if (request_audio) {
+ checkbox_ = new views::Checkbox(
+ l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE));
+ AddChildView(checkbox_);
+ checkbox_->SetEnabled(false);
+ checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
+ IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_NONE));
+ }
+
scroll_view_->SetContents(list_view_);
scroll_view_->ClipHeightTo(
GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2));
@@ -461,9 +473,12 @@ gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const {
size_t label_height =
label_->GetHeightForWidth(kDialogViewWidth - title_insets.height() * 2);
+ size_t checkbox_height =
+ 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.
+
return gfx::Size(kDialogViewWidth,
views::kPanelVertMargin * 2 + label_height +
- views::kPanelVerticalSpacing +
+ checkbox_height + views::kPanelVerticalSpacing +
scroll_view_->GetPreferredSize().height());
}
@@ -479,9 +494,19 @@ void DesktopMediaPickerDialogView::Layout() {
label_->SetBoundsRect(label_rect);
int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing;
- scroll_view_->SetBounds(
- rect.x(), scroll_view_top,
- rect.width(), rect.height() - scroll_view_top);
+ int scroll_view_height =
+ rect.height() - scroll_view_top -
+ (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.
+ gfx::Rect scroll_view_rect(rect.x(), scroll_view_top, rect.width(),
+ scroll_view_height);
+ scroll_view_->SetBoundsRect(scroll_view_rect);
+
+ if (checkbox_) {
+ gfx::Rect checkbox_rect(
+ rect.x(), scroll_view_rect.bottom() + views::kPanelVertMargin,
+ 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.
+ checkbox_->SetBoundsRect(checkbox_rect);
+ }
}
ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
@@ -519,6 +544,10 @@ bool DesktopMediaPickerDialogView::Accept() {
if (selection)
source = selection->source_id();
+ 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
+ source.audio_share = checkbox_->enabled() && checkbox_->checked();
+ }
+
if (parent_)
parent_->NotifyDialogResult(source);
@@ -535,6 +564,26 @@ void DesktopMediaPickerDialogView::DeleteDelegate() {
void DesktopMediaPickerDialogView::OnSelectionChanged() {
GetDialogClientView()->UpdateDialogButtons();
+
+ // 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.
+ if (checkbox_) {
+ DesktopMediaSourceView* selection = list_view_->GetSelection();
+
+ DesktopMediaID source;
+ if (selection)
+ source = selection->source_id();
+
+ if (source.type == DesktopMediaID::TYPE_SCREEN) {
+ checkbox_->SetEnabled(true);
+ 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.
+ } else if (source.type == DesktopMediaID::TYPE_WINDOW) {
+ checkbox_->SetEnabled(false);
+ checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
+ IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_WINDOW));
+ } else {
+ NOTREACHED();
+ }
+ }
}
void DesktopMediaPickerDialogView::OnDoubleClick() {
@@ -580,11 +629,12 @@ void DesktopMediaPickerViews::Show(content::WebContents* web_contents,
const base::string16& app_name,
const base::string16& target_name,
scoped_ptr<DesktopMediaList> media_list,
+ bool request_audio,
const DoneCallback& done_callback) {
callback_ = done_callback;
- dialog_ =
- new DesktopMediaPickerDialogView(web_contents, context, this, app_name,
- target_name, std::move(media_list));
+ dialog_ = new DesktopMediaPickerDialogView(
+ web_contents, context, this, app_name, target_name, std::move(media_list),
+ request_audio);
}
void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) {

Powered by Google App Engine
This is Rietveld 408576698