| 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 046e6fd178209557c48d786b08af38380bcc3a85..f9a12ca6485503c25c15c2109bd6304e25aacd60 100644
|
| --- a/chrome/browser/ui/views/desktop_media_picker_views.cc
|
| +++ b/chrome/browser/ui/views/desktop_media_picker_views.cc
|
| @@ -31,6 +31,8 @@
|
| #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"
|
| +#include "ui/views/controls/button/label_button_border.h"
|
| #include "ui/views/controls/image_view.h"
|
| #include "ui/views/controls/label.h"
|
| #include "ui/views/controls/scroll_view.h"
|
| @@ -59,6 +61,10 @@ const int kDesktopMediaSourceViewGroupId = 1;
|
| const char kDesktopMediaSourceViewClassName[] =
|
| "DesktopMediaPicker_DesktopMediaSourceView";
|
|
|
| +const SkColor kActiveButtonColor = 0xFF4444FF;
|
| +const SkColor kActiveBorderColor = 0xFF8888FF;
|
| +const SkColor kInactiveButtonColor = 0xFF000000;
|
| +
|
| DesktopMediaID::Id AcceleratedWidgetToDesktopMediaId(
|
| gfx::AcceleratedWidget accelerated_widget) {
|
| #if defined(OS_WIN)
|
| @@ -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;
|
| 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));
|
| }
|
|
|
| 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) {
|
| + source_view->OnFocus();
|
| + }
|
| +
|
| std::string autoselect_source =
|
| base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
|
| switches::kAutoSelectDesktopCaptureSource);
|
| @@ -404,30 +416,48 @@ 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));
|
| + current_index_(0) {
|
| + int index = 0;
|
| + if (screen_list) {
|
| + source_types_.push_back(DesktopMediaID::TYPE_SCREEN);
|
| + scroll_views_.push_back(views::ScrollView::CreateScrollViewWithBorder());
|
| + list_views_.push_back(
|
| + new DesktopMediaListView(this, std::move(screen_list)));
|
| +
|
| + views::LabelButton* button = new views::LabelButton(
|
| + this,
|
| + l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_SCREEN));
|
| + button->set_tag(index);
|
| + source_type_buttons_.push_back(button);
|
| + index++;
|
| + }
|
| +
|
| + 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)));
|
| + views::LabelButton* button = new views::LabelButton(
|
| + this,
|
| + l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_WINDOW));
|
| + button->set_tag(index);
|
| + source_type_buttons_.push_back(button);
|
| + index++;
|
| + }
|
| +
|
| + 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)));
|
| + views::LabelButton* button = new views::LabelButton(
|
| + this,
|
| + l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_TAB));
|
| + button->set_tag(index);
|
| + source_type_buttons_.push_back(button);
|
| + index++;
|
| + }
|
| +
|
| + DCHECK(index > 0);
|
|
|
| if (app_name == target_name) {
|
| description_label_->SetText(
|
| @@ -440,20 +470,31 @@ 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_);
|
| + std::vector<gfx::Font> font =
|
| + source_type_buttons_[0]->GetFontList().GetFonts();
|
| + font[0] = gfx::Font(font[0].GetFontName(), 16);
|
| + for (auto& button : source_type_buttons_) {
|
| + button->SetFontList(gfx::FontList(font));
|
| + button->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER);
|
| + AddChildView(button);
|
| + }
|
| +
|
| + 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(scroll_views_[i]);
|
| + }
|
|
|
| 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));
|
| }
|
|
|
| + SwitchSourceType(0);
|
| +
|
| // 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.
|
| @@ -490,18 +531,165 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
|
| }
|
| }
|
|
|
| - sources_list_view_->StartUpdating(dialog_window_id);
|
| + for (auto& list_view : list_views_) {
|
| + list_view->StartUpdating(dialog_window_id);
|
| + }
|
| }
|
|
|
| DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {}
|
|
|
| +void DesktopMediaPickerDialogView::ButtonPressed(views::Button* sender,
|
| + const ui::Event& event) {
|
| + const int index = static_cast<views::LabelButton*>(sender)->tag();
|
| + SwitchSourceType(index);
|
| +
|
| + // Repaint the buttons.
|
| + for (auto& button : source_type_buttons_) {
|
| + button->SchedulePaint();
|
| + }
|
| + GetDialogClientView()->UpdateDialogButtons();
|
| +}
|
| +
|
| +void DesktopMediaPickerDialogView::SwitchSourceType(int index) {
|
| + current_index_ = index;
|
| +
|
| + // Set the border of source type buttons
|
| + for (size_t i = 0; i < source_type_buttons_.size(); i++) {
|
| + if (static_cast<int>(i) == index) {
|
| + source_type_buttons_[i]->SetBorder(views::Border::CreateSolidSidedBorder(
|
| + 0, 0, 4, 0, kActiveBorderColor));
|
| + source_type_buttons_[i]->SetEnabledTextColors(kActiveButtonColor);
|
| + scroll_views_[i]->SetVisible(true);
|
| + } else {
|
| + source_type_buttons_[i]->SetBorder(views::Border::NullBorder());
|
| + source_type_buttons_[i]->SetEnabledTextColors(kInactiveButtonColor);
|
| + scroll_views_[i]->SetVisible(false);
|
| + }
|
| + }
|
| +
|
| + // Set whether the checkbox is visible based on the source type
|
| + 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++;
|
| + }
|
| +
|
| + int button_height = 0;
|
| + for (size_t i = 0; i < source_type_buttons_.size(); i++) {
|
| + const int height = source_type_buttons_[i]->GetHeightForWidth(kInnerWidth);
|
| + if (height > button_height)
|
| + button_height = height;
|
| + }
|
| +
|
| + int scroll_view_height =
|
| + scroll_views_[current_index_]->GetPreferredSize().height();
|
| + related_spacing_num++;
|
| +
|
| + return gfx::Size(
|
| + kDialogViewWidth,
|
| + views::kPanelVertMargin * 2 + label_height + checkbox_height +
|
| + scroll_view_height + button_height +
|
| + views::kRelatedControlVerticalSpacing * related_spacing_num +
|
| + views::kUnrelatedControlVerticalSpacing * unrelated_spacing_num);
|
| +}
|
| +
|
| +void DesktopMediaPickerDialogView::Layout() {
|
| + // DialogDelegate uses the bubble style frame.
|
| + gfx::Rect rect = GetLocalBounds();
|
| +
|
| + // |left|, |top|, |right|, |bottom| describes the available area.
|
| + rect.Inset(views::kPanelHorizMargin * 2, views::kPanelVertMargin);
|
| + int left = rect.x();
|
| + int top = rect.y();
|
| + int right = rect.x() + rect.width();
|
| + int bottom = rect.y() + rect.height();
|
| +
|
| + // Put on Label
|
| + 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 Group button
|
| + std::vector<int> buttons_width;
|
| + int total_ideal_width = 0;
|
| + for (auto& button : source_type_buttons_) {
|
| + const int width = button->GetPreferredSize().width() + 16;
|
| + buttons_width.push_back(width);
|
| + total_ideal_width += width;
|
| + }
|
| +
|
| + int button_height = 0;
|
| + int button_left = left;
|
| + for (size_t i = 0; i < buttons_width.size(); i++) {
|
| + if (right - left < total_ideal_width)
|
| + buttons_width[i] = (right - left) * buttons_width[i] / total_ideal_width;
|
| + const int height =
|
| + source_type_buttons_[i]->GetHeightForWidth(buttons_width[i]) + 8;
|
| + if (height > button_height)
|
| + button_height = height;
|
| + }
|
| +
|
| + for (size_t i = 0; i < buttons_width.size(); i++) {
|
| + gfx::Rect button_rect(button_left, top, buttons_width[i], button_height);
|
| + button_left += buttons_width[i];
|
| + source_type_buttons_[i]->SetBoundsRect(button_rect);
|
| + }
|
| +
|
| + top += button_height;
|
| +
|
| + // Put on Checkbox
|
| + int checkbox_height = 0;
|
| + if (audio_share_checkbox_) {
|
| + 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 scroll_view_height = bottom - top - views::kRelatedControlVerticalSpacing;
|
| + gfx::Rect scroll_view_rect(
|
| + 0, top, right - left + views::kPanelHorizMargin * 4, scroll_view_height);
|
| +
|
| + for (size_t i = 0; i < scroll_views_.size(); i++)
|
| + scroll_views_[i]->SetBoundsRect(scroll_view_rect);
|
| }
|
|
|
| ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
|
| @@ -514,13 +702,14 @@ base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const {
|
|
|
| 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) {
|
| + return list_views_[current_index_]->GetSelection() != NULL;
|
| + }
|
| return true;
|
| }
|
|
|
| views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() {
|
| - return sources_list_view_;
|
| + return list_views_[0];
|
| }
|
|
|
| base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel(
|
| @@ -529,14 +718,19 @@ base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel(
|
| 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_[current_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 +759,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,24 +769,38 @@ 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() -
|
| + scroll_views_[current_index_]->height() +
|
| + scroll_views_[current_index_]->GetPreferredSize().height();
|
|
|
| GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height));
|
| }
|
|
|
| DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting()
|
| const {
|
| - return sources_list_view_;
|
| + return list_views_[current_index_];
|
| }
|
|
|
| DesktopMediaSourceView*
|
| DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const {
|
| - if (sources_list_view_->child_count() <= index)
|
| + if (list_views_[current_index_]->child_count() <= index)
|
| return NULL;
|
|
|
| return reinterpret_cast<DesktopMediaSourceView*>(
|
| - sources_list_view_->child_at(index));
|
| + list_views_[current_index_]->child_at(index));
|
| +}
|
| +
|
| +views::LabelButton* DesktopMediaPickerDialogView::GetSourceTypeButtonForTesting(
|
| + DesktopMediaID::Type source_type) const {
|
| + for (size_t i = 0; i < source_types_.size(); i++) {
|
| + if (source_types_[i] == source_type)
|
| + return source_type_buttons_[i];
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| +views::Checkbox* DesktopMediaPickerDialogView::GetCheckboxForTesting() const {
|
| + return audio_share_checkbox_;
|
| }
|
|
|
| DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {
|
|
|