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

Unified Diff: chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.cc

Issue 1932413002: Desktop Capture Picker New UI: Non Mac Structure Change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: File name change Created 4 years, 8 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_capture/desktop_media_picker_views.cc
diff --git a/chrome/browser/ui/views/desktop_media_picker_views.cc b/chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.cc
similarity index 70%
copy from chrome/browser/ui/views/desktop_media_picker_views.cc
copy to chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.cc
index 046e6fd178209557c48d786b08af38380bcc3a85..094c814269426e3a490c5ee9b2f67c9d5ea4d7f3 100644
--- a/chrome/browser/ui/views/desktop_media_picker_views.cc
+++ b/chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/views/desktop_media_picker_views.h"
+#include "chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.h"
#include <stddef.h>
#include <utility>
@@ -14,13 +14,17 @@
#include "chrome/browser/media/combined_desktop_media_list.h"
#include "chrome/browser/media/desktop_media_list.h"
#include "chrome/browser/ui/ash/ash_util.h"
+#include "chrome/browser/ui/views/desktop_media_picker_views_deprecated.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
+#include "chrome/grit/google_chrome_strings.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents_delegate.h"
+#include "extensions/common/switches.h"
#include "grit/components_strings.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/l10n/l10n_util.h"
@@ -31,9 +35,12 @@
#include "ui/views/background.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/checkbox.h"
+#include "ui/views/controls/button/label_button.h"
msw 2016/05/02 23:49:57 Remove this.
qiangchen 2016/05/05 22:17:54 Done.
+#include "ui/views/controls/button/label_button_border.h"
msw 2016/05/02 23:49:58 Remove this.
qiangchen 2016/05/05 22:17:53 Done.
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/scroll_view.h"
+#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/layout_constants.h"
#include "ui/views/widget/widget.h"
@@ -74,14 +81,13 @@ int GetMediaListViewHeightForRows(size_t rows) {
} // namespace
-DesktopMediaSourceView::DesktopMediaSourceView(
- DesktopMediaListView* parent,
- DesktopMediaID source_id)
+DesktopMediaSourceView::DesktopMediaSourceView(DesktopMediaListView* parent,
+ DesktopMediaID source_id)
: parent_(parent),
source_id_(source_id),
image_view_(new views::ImageView()),
label_(new views::Label()),
- selected_(false) {
+ selected_(false) {
AddChildView(image_view_);
AddChildView(label_);
SetFocusable(true);
@@ -132,8 +138,8 @@ const char* DesktopMediaSourceView::GetClassName() const {
}
void DesktopMediaSourceView::Layout() {
- image_view_->SetBounds(kThumbnailMargin, kThumbnailMargin,
- kThumbnailWidth, kThumbnailHeight);
+ image_view_->SetBounds(kThumbnailMargin, kThumbnailMargin, kThumbnailWidth,
+ kThumbnailHeight);
label_->SetBounds(kThumbnailMargin, kThumbnailHeight + kThumbnailMargin,
kThumbnailWidth, kLabelHeight);
}
@@ -244,16 +250,17 @@ DesktopMediaSourceView* DesktopMediaListView::GetSelection() {
gfx::Size DesktopMediaListView::GetPreferredSize() const {
int total_rows = (child_count() + kListColumns - 1) / kListColumns;
- return gfx::Size(kTotalListWidth, GetMediaListViewHeightForRows(total_rows));
+ return gfx::Size(kTotalListWidth + views::kPanelHorizMargin * 4,
+ GetMediaListViewHeightForRows(total_rows));
}
void DesktopMediaListView::Layout() {
- int x = 0;
+ int x = views::kPanelHorizMargin * 2;
msw 2016/05/02 23:49:58 Why add a new margin? How did you come up with thi
qiangchen 2016/05/05 22:17:53 Changed it back. My original change makes the tab
int y = 0;
for (int i = 0; i < child_count(); ++i) {
- if (x + kListItemWidth > kTotalListWidth) {
- x = 0;
+ if (x + kListItemWidth > kTotalListWidth + views::kPanelHorizMargin * 2) {
+ x = views::kPanelHorizMargin * 2;
y += kListItemHeight;
}
@@ -264,7 +271,7 @@ void DesktopMediaListView::Layout() {
}
y += kListItemHeight;
- SetSize(gfx::Size(kTotalListWidth, y));
+ SetSize(gfx::Size(kTotalListWidth + views::kPanelHorizMargin * 2, y));
msw 2016/05/02 23:49:58 Shouldn't this be *4? I'm not sure it makes sense
qiangchen 2016/05/05 22:17:53 You are right, no need to SetSize here.
}
bool DesktopMediaListView::OnKeyPressed(const ui::KeyEvent& event) {
@@ -328,6 +335,11 @@ void DesktopMediaListView::OnSourceAdded(DesktopMediaList* list, int index) {
if (child_count() % kListColumns == 1)
parent_->OnMediaListRowsChanged();
+ // Auto select the first screen.
+ if (index == 0 && source.id.type == DesktopMediaID::TYPE_SCREEN) {
msw 2016/05/02 23:49:57 nit: remove curlies
qiangchen 2016/05/05 22:17:53 Done.
+ source_view->OnFocus();
msw 2016/05/02 23:49:57 This should probably call RequestFocus instead (di
qiangchen 2016/05/05 22:17:53 Done.
+ }
+
std::string autoselect_source =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kAutoSelectDesktopCaptureSource);
@@ -404,30 +416,41 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
app_name_(app_name),
description_label_(new views::Label()),
audio_share_checkbox_(nullptr),
- audio_share_checked_(true),
- sources_scroll_view_(views::ScrollView::CreateScrollViewWithBorder()) {
- std::vector<std::unique_ptr<DesktopMediaList>> media_lists;
- if (screen_list)
- media_lists.push_back(std::move(screen_list));
- if (window_list)
- media_lists.push_back(std::move(window_list));
- if (tab_list)
- media_lists.push_back(std::move(tab_list));
-
- std::unique_ptr<DesktopMediaList> media_list;
- if (media_lists.size() > 1)
- media_list.reset(new CombinedDesktopMediaList(media_lists));
- else
- media_list = std::move(media_lists[0]);
-
- DCHECK(media_list != nullptr);
- sources_list_view_ = new DesktopMediaListView(this, std::move(media_list));
-
- // TODO(estade): we should be getting the inside-border spacing by default as
- // a DialogDelegateView subclass, via default BubbleFrameView content margins.
- SetLayoutManager(new views::BoxLayout(
- views::BoxLayout::kVertical, views::kButtonHEdgeMarginNew,
- views::kPanelVertMargin, views::kLabelToControlVerticalSpacing));
+ pane_(new views::TabbedPane()) {
+ if (screen_list) {
+ source_types_.push_back(DesktopMediaID::TYPE_SCREEN);
+ scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
msw 2016/05/02 23:49:57 |scroll_views_| isn't accessed beyond this ctor's
qiangchen 2016/05/05 22:17:53 Done.
+ list_views_.push_back(
+ new DesktopMediaListView(this, std::move(screen_list)));
+
+ pane_->AddTab(
+ l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_SCREEN),
+ scroll_views_.back());
+ pane_->set_listener(this);
+ }
+
+ if (window_list) {
+ source_types_.push_back(DesktopMediaID::TYPE_WINDOW);
+ scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
+ list_views_.push_back(
+ new DesktopMediaListView(this, std::move(window_list)));
+
+ pane_->AddTab(
+ l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_WINDOW),
+ scroll_views_.back());
+ pane_->set_listener(this);
+ }
+
+ if (tab_list) {
+ source_types_.push_back(DesktopMediaID::TYPE_WEB_CONTENTS);
+ scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
+ list_views_.push_back(new DesktopMediaListView(this, std::move(tab_list)));
+
+ pane_->AddTab(
+ l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_TAB),
+ scroll_views_.back());
+ pane_->set_listener(this);
+ }
if (app_name == target_name) {
description_label_->SetText(
@@ -440,20 +463,23 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(description_label_);
- sources_scroll_view_->SetContents(sources_list_view_);
- sources_scroll_view_->ClipHeightTo(GetMediaListViewHeightForRows(1),
- GetMediaListViewHeightForRows(2));
- AddChildView(sources_scroll_view_);
+ for (size_t i = 0; i < source_types_.size(); i++) {
+ scroll_views_[i]->SetContents(list_views_[i]);
+ scroll_views_[i]->ClipHeightTo(GetMediaListViewHeightForRows(1),
+ GetMediaListViewHeightForRows(2));
+ }
+ AddChildView(pane_);
if (request_audio) {
audio_share_checkbox_ = new views::Checkbox(
l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE));
+ audio_share_checkbox_->SetChecked(true);
AddChildView(audio_share_checkbox_);
- audio_share_checkbox_->SetEnabled(false);
- audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
- IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_NONE));
}
+ // Focus on the first non-null media_list
msw 2016/05/02 23:49:58 nit: add a trailing period.
qiangchen 2016/05/05 22:17:53 Done.
+ SwitchSourceType(0);
msw 2016/05/02 23:49:57 Should this call TabSelectedAt instead (to also Up
qiangchen 2016/05/05 22:17:53 No. This is the constructor function, if we call T
+
// If |parent_web_contents| is set and it's not a background page then the
// picker will be shown modal to the web contents. Otherwise the picker is
// shown in a separate window.
@@ -462,8 +488,8 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
parent_web_contents &&
!parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents);
if (modal_dialog) {
- widget = constrained_window::ShowWebModalDialogViews(this,
- parent_web_contents);
+ widget =
+ constrained_window::ShowWebModalDialogViews(this, parent_web_contents);
} else {
widget = DialogDelegate::CreateDialogWidget(this, context, NULL);
widget->Show();
@@ -490,18 +516,105 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
}
}
- sources_list_view_->StartUpdating(dialog_window_id);
+ for (auto& list_view : list_views_) {
msw 2016/05/02 23:49:57 nit: remove curlies
qiangchen 2016/05/05 22:17:53 Done.
+ list_view->StartUpdating(dialog_window_id);
+ }
}
DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {}
+void DesktopMediaPickerDialogView::TabSelectedAt(int index) {
+ SwitchSourceType(index);
+ GetDialogClientView()->UpdateDialogButtons();
+}
+
+void DesktopMediaPickerDialogView::SwitchSourceType(int index) {
+ // Set whether the checkbox is visible based on the source type
msw 2016/05/02 23:49:58 nit: add a trailing period.
qiangchen 2016/05/05 22:17:53 Done.
+ if (audio_share_checkbox_) {
+ switch (source_types_[index]) {
+ case DesktopMediaID::TYPE_SCREEN:
+#if defined(USE_CRAS) || defined(OS_WIN)
+ audio_share_checkbox_->SetVisible(true);
+#else
+ audio_share_checkbox_->SetVisible(false);
+#endif
+ break;
+ case DesktopMediaID::TYPE_WINDOW:
+ audio_share_checkbox_->SetVisible(false);
+ break;
+ case DesktopMediaID::TYPE_WEB_CONTENTS:
+ audio_share_checkbox_->SetVisible(true);
+ break;
+ case DesktopMediaID::TYPE_NONE:
+ NOTREACHED();
+ break;
+ }
+ }
+}
+
void DesktopMediaPickerDialogView::DetachParent() {
parent_ = NULL;
}
gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const {
static const size_t kDialogViewWidth = 600;
- return gfx::Size(kDialogViewWidth, GetHeightForWidth(kDialogViewWidth));
+ const size_t kInnerWidth = kDialogViewWidth - views::kPanelHorizMargin * 4;
+
+ int related_spacing_num = 0;
+ int unrelated_spacing_num = 0;
+
+ size_t label_height = description_label_->GetHeightForWidth(kInnerWidth);
+ unrelated_spacing_num++;
+
+ size_t checkbox_height = 0;
+ if (audio_share_checkbox_) {
+ checkbox_height = audio_share_checkbox_->GetHeightForWidth(kInnerWidth);
+ related_spacing_num++;
+ }
+
+ size_t pane_height = pane_->GetHeightForWidth(kInnerWidth);
+ related_spacing_num++;
+
+ return gfx::Size(
+ kDialogViewWidth,
+ views::kPanelVertMargin * 2 + label_height + checkbox_height +
+ pane_height +
+ views::kRelatedControlVerticalSpacing * related_spacing_num +
+ views::kUnrelatedControlVerticalSpacing * unrelated_spacing_num);
+}
+
+void DesktopMediaPickerDialogView::Layout() {
msw 2016/05/02 23:49:58 Can you use BoxLayout instead of doing manual layo
qiangchen 2016/05/05 22:17:53 Done.
+ // DialogDelegate uses the bubble style frame.
msw 2016/05/02 23:49:58 What is the purpose of this comment? All dialogs u
qiangchen 2016/05/05 22:17:53 N/A This is copied from old code.
+ gfx::Rect rect = GetLocalBounds();
+
+ // |left|, |top|, |right|, |bottom| describes the available area.
+ rect.Inset(views::kPanelHorizMargin * 2, views::kPanelVertMargin);
msw 2016/05/02 23:49:57 Perhaps giving the view an empty border (or overri
qiangchen 2016/05/05 22:17:53 N/A
+ int left = rect.x();
+ int top = rect.y();
+ int right = rect.x() + rect.width();
+ int bottom = rect.y() + rect.height();
+
+ // Put on Label
msw 2016/05/02 23:49:58 These comments don't have any value; remove them (
qiangchen 2016/05/05 22:17:53 Done.
+ gfx::Rect label_rect(left, top, right - left,
+ description_label_->GetHeightForWidth(right - left));
+ description_label_->SetBoundsRect(label_rect);
+ top += label_rect.height() + views::kUnrelatedControlVerticalSpacing;
+
+ // Put on Checkbox
+ int checkbox_height = 0;
msw 2016/05/02 23:49:57 You should make this checkbox the dialog's 'extra'
qiangchen 2016/05/05 22:17:53 Done.
+ if (audio_share_checkbox_) {
msw 2016/05/02 23:49:58 Should this also check for the checkbox visibility
qiangchen 2016/05/05 22:17:53 N/A after accepting previous comment.
+ checkbox_height = audio_share_checkbox_->GetHeightForWidth(right - left);
+ bottom -= checkbox_height;
+ gfx::Rect checkbox_rect(left, bottom, right - left, checkbox_height);
+ audio_share_checkbox_->SetBoundsRect(checkbox_rect);
+ }
+
+ // Put on scroll view
+ int pane_height = bottom - top - views::kRelatedControlVerticalSpacing;
+ gfx::Rect pane_rect(0, top, right - left + views::kPanelHorizMargin * 4,
+ pane_height);
+
+ pane_->SetBoundsRect(pane_rect);
}
ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
@@ -509,34 +622,41 @@ ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
}
base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const {
- return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_);
+ return l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE);
}
bool DesktopMediaPickerDialogView::IsDialogButtonEnabled(
ui::DialogButton button) const {
- if (button == ui::DIALOG_BUTTON_OK)
- return sources_list_view_->GetSelection() != NULL;
+ if (button == ui::DIALOG_BUTTON_OK) {
msw 2016/05/02 23:49:57 nit: remove curlies
qiangchen 2016/05/05 22:17:54 Done.
+ return list_views_[pane_->selected_tab_index()]->GetSelection() != NULL;
+ }
return true;
}
views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() {
- return sources_list_view_;
+ return list_views_[0];
}
base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel(
ui::DialogButton button) const {
- return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ?
- IDS_DESKTOP_MEDIA_PICKER_SHARE : IDS_CANCEL);
+ return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK
+ ? IDS_DESKTOP_MEDIA_PICKER_SHARE
+ : IDS_CANCEL);
+}
+
+bool DesktopMediaPickerDialogView::ShouldDefaultButtonBeBlue() const {
+ return true;
}
bool DesktopMediaPickerDialogView::Accept() {
- DesktopMediaSourceView* selection = sources_list_view_->GetSelection();
+ DesktopMediaSourceView* selection =
+ list_views_[pane_->selected_tab_index()]->GetSelection();
// Ok button should only be enabled when a source is selected.
DCHECK(selection);
DesktopMediaID source = selection->source_id();
source.audio_share = audio_share_checkbox_ &&
- audio_share_checkbox_->enabled() &&
+ audio_share_checkbox_->visible() &&
audio_share_checkbox_->checked();
// If the media source is an tab, activate it.
@@ -565,34 +685,6 @@ void DesktopMediaPickerDialogView::DeleteDelegate() {
void DesktopMediaPickerDialogView::OnSelectionChanged() {
GetDialogClientView()->UpdateDialogButtons();
-
- // Disable the checkbox if we cannot support audio for the selected source.
- if (audio_share_checkbox_) {
- DesktopMediaSourceView* selection = sources_list_view_->GetSelection();
-
- DesktopMediaID source;
- if (selection)
- source = selection->source_id();
-
- if (source.type == DesktopMediaID::TYPE_SCREEN ||
- source.type == DesktopMediaID::TYPE_WEB_CONTENTS) {
- if (!audio_share_checkbox_->enabled()) {
- audio_share_checkbox_->SetEnabled(true);
- audio_share_checkbox_->SetChecked(audio_share_checked_);
- }
- audio_share_checkbox_->SetTooltipText(base::string16());
- } else if (source.type == DesktopMediaID::TYPE_WINDOW) {
- if (audio_share_checkbox_->enabled()) {
- audio_share_checkbox_->SetEnabled(false);
- audio_share_checked_ = audio_share_checkbox_->checked();
- audio_share_checkbox_->SetChecked(false);
- }
- audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
- IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_WINDOW));
- } else {
- NOTREACHED();
- }
- }
}
void DesktopMediaPickerDialogView::OnDoubleClick() {
@@ -603,29 +695,45 @@ void DesktopMediaPickerDialogView::OnDoubleClick() {
void DesktopMediaPickerDialogView::OnMediaListRowsChanged() {
gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen();
- int new_height = widget_bound.height() - sources_scroll_view_->height() +
- sources_scroll_view_->GetPreferredSize().height();
+ int new_height = widget_bound.height() - pane_->height() +
+ pane_->GetPreferredSize().height();
GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height));
}
DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting()
const {
- return sources_list_view_;
+ return list_views_[pane_->selected_tab_index()];
}
DesktopMediaSourceView*
DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const {
- if (sources_list_view_->child_count() <= index)
+ if (list_views_[pane_->selected_tab_index()]->child_count() <= index)
return NULL;
return reinterpret_cast<DesktopMediaSourceView*>(
- sources_list_view_->child_at(index));
+ list_views_[pane_->selected_tab_index()]->child_at(index));
}
-DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {
+views::Checkbox* DesktopMediaPickerDialogView::GetCheckboxForTesting() const {
+ return audio_share_checkbox_;
}
+int DesktopMediaPickerDialogView::GetIndexOfSourceTypeForTesting(
+ DesktopMediaID::Type source_type) const {
+ for (size_t i = 0; i < source_types_.size(); i++) {
+ if (source_types_[i] == source_type)
+ return i;
+ }
+ return -1;
+}
+
+views::TabbedPane* DesktopMediaPickerDialogView::GetPaneForTesting() const {
+ return pane_;
+}
+
+DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {}
+
DesktopMediaPickerViews::~DesktopMediaPickerViews() {
if (dialog_) {
dialog_->DetachParent();
@@ -660,13 +768,17 @@ void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) {
// Notify the |callback_| asynchronously because it may need to destroy
// DesktopMediaPicker.
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE,
- base::Bind(callback_, source));
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ base::Bind(callback_, source));
callback_.Reset();
}
// static
std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() {
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ extensions::switches::kDisableDesktopCapturePickerNewUI)) {
+ return std::unique_ptr<DesktopMediaPicker>(
+ new deprecated::DesktopMediaPickerViews());
+ }
return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews());
}

Powered by Google App Engine
This is Rietveld 408576698