Chromium Code Reviews| Index: chrome/browser/ui/views/desktop_capture/desktop_media_list_view.cc |
| diff --git a/chrome/browser/ui/views/desktop_capture/desktop_media_list_view.cc b/chrome/browser/ui/views/desktop_capture/desktop_media_list_view.cc |
| index fe6f58e401224b8387566890b39c5867381e173c..2903087856421b69acfd9fdbb5bedd546a4c6787 100644 |
| --- a/chrome/browser/ui/views/desktop_capture/desktop_media_list_view.cc |
| +++ b/chrome/browser/ui/views/desktop_capture/desktop_media_list_view.cc |
| @@ -23,11 +23,34 @@ const int kDesktopMediaSourceViewGroupId = 1; |
| DesktopMediaListView::DesktopMediaListView( |
| DesktopMediaPickerDialogView* parent, |
| - std::unique_ptr<DesktopMediaList> media_list) |
| - : parent_(parent), media_list_(std::move(media_list)), weak_factory_(this) { |
| - media_list_->SetThumbnailSize( |
| - gfx::Size(DesktopMediaPickerDialogView::kThumbnailWidth, |
| - DesktopMediaPickerDialogView::kThumbnailHeight)); |
| + std::unique_ptr<DesktopMediaList> media_list, |
| + DesktopMediaSourceViewStyle generic_style) |
| + : parent_(parent), |
| + media_list_(std::move(media_list)), |
| + single_style_(generic_style), |
| + generic_style_(generic_style), |
| + use_single_style_(false), |
| + active_style_(&generic_style_), |
| + weak_factory_(this) { |
| + SwitchStyle(&generic_style_); |
| + |
| + SetFocusBehavior(FocusBehavior::ALWAYS); |
| +} |
| + |
| +DesktopMediaListView::DesktopMediaListView( |
| + DesktopMediaPickerDialogView* parent, |
| + std::unique_ptr<DesktopMediaList> media_list, |
| + DesktopMediaSourceViewStyle generic_style, |
| + DesktopMediaSourceViewStyle single_style) |
| + : parent_(parent), |
| + media_list_(std::move(media_list)), |
| + single_style_(single_style), |
| + generic_style_(generic_style), |
| + use_single_style_(true), |
| + active_style_(&single_style_), |
| + weak_factory_(this) { |
| + SwitchStyle(&single_style_); |
| + |
| SetFocusBehavior(FocusBehavior::ALWAYS); |
| } |
| @@ -60,10 +83,9 @@ DesktopMediaSourceView* DesktopMediaListView::GetSelection() { |
| gfx::Size DesktopMediaListView::GetPreferredSize() const { |
| int total_rows = |
| - (child_count() + DesktopMediaPickerDialogView::kListColumns - 1) / |
| - DesktopMediaPickerDialogView::kListColumns; |
| - return gfx::Size(DesktopMediaPickerDialogView::kTotalListWidth, |
| - DesktopMediaPickerDialogView::kListItemHeight * total_rows); |
| + (child_count() + active_style_->columns - 1) / active_style_->columns; |
| + return gfx::Size(active_style_->columns * active_style_->item_size.width(), |
| + total_rows * active_style_->item_size.height()); |
| } |
| void DesktopMediaListView::Layout() { |
| @@ -71,30 +93,29 @@ void DesktopMediaListView::Layout() { |
| int y = 0; |
| for (int i = 0; i < child_count(); ++i) { |
| - if (x + DesktopMediaPickerDialogView::kListItemWidth > |
| - DesktopMediaPickerDialogView::kTotalListWidth) { |
| + if (i > 0 && i % active_style_->columns == 0) { |
| x = 0; |
| - y += DesktopMediaPickerDialogView::kListItemHeight; |
| + y += active_style_->item_size.height(); |
| } |
| - View* source_view = child_at(i); |
| - source_view->SetBounds(x, y, DesktopMediaPickerDialogView::kListItemWidth, |
| - DesktopMediaPickerDialogView::kListItemHeight); |
| + child_at(i)->SetBounds(x, y, active_style_->item_size.width(), |
| + active_style_->item_size.height()); |
| - x += DesktopMediaPickerDialogView::kListItemWidth; |
| + x += active_style_->item_size.width(); |
| } |
| - y += DesktopMediaPickerDialogView::kListItemHeight; |
| + SetSize(gfx::Size(active_style_->columns * active_style_->item_size.width(), |
| + y + active_style_->item_size.height())); |
| } |
| bool DesktopMediaListView::OnKeyPressed(const ui::KeyEvent& event) { |
| int position_increment = 0; |
| switch (event.key_code()) { |
| case ui::VKEY_UP: |
| - position_increment = -DesktopMediaPickerDialogView::kListColumns; |
| + position_increment = -active_style_->columns; |
| break; |
| case ui::VKEY_DOWN: |
| - position_increment = DesktopMediaPickerDialogView::kListColumns; |
| + position_increment = active_style_->columns; |
| break; |
| case ui::VKEY_LEFT: |
| position_increment = -1; |
| @@ -137,21 +158,28 @@ bool DesktopMediaListView::OnKeyPressed(const ui::KeyEvent& event) { |
| void DesktopMediaListView::OnSourceAdded(DesktopMediaList* list, int index) { |
| const DesktopMediaList::Source& source = media_list_->GetSource(index); |
| + |
| + // We are going to have a second item, apply the generic style. |
| + if (use_single_style_ && child_count() == 1) { |
|
msw
2016/05/24 18:54:25
nit: remove curly braces (hopefully this can just
qiangchen
2016/05/25 16:24:08
Done.
|
| + SwitchStyle(&generic_style_); |
| + } |
| + |
| DesktopMediaSourceView* source_view = |
| - new DesktopMediaSourceView(this, source.id); |
| + new DesktopMediaSourceView(this, source.id, *active_style_); |
| + |
| source_view->SetName(source.name); |
| source_view->SetGroup(kDesktopMediaSourceViewGroupId); |
| AddChildViewAt(source_view, index); |
| - PreferredSizeChanged(); |
| - |
| - if (child_count() % DesktopMediaPickerDialogView::kListColumns == 1) |
| + if ((child_count() - 1) % active_style_->columns == 0) |
| parent_->OnMediaListRowsChanged(); |
| // Auto select the first screen. |
| if (index == 0 && source.id.type == DesktopMediaID::TYPE_SCREEN) |
| source_view->RequestFocus(); |
| + PreferredSizeChanged(); |
| + |
| std::string autoselect_source = |
| base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| switches::kAutoSelectDesktopCaptureSource); |
| @@ -172,6 +200,7 @@ void DesktopMediaListView::OnSourceRemoved(DesktopMediaList* list, int index) { |
| DCHECK(view); |
| DCHECK_EQ(view->GetClassName(), |
| DesktopMediaSourceView::kDesktopMediaSourceViewClassName); |
| + |
| bool was_selected = view->is_selected(); |
| RemoveChildView(view); |
| delete view; |
| @@ -179,10 +208,14 @@ void DesktopMediaListView::OnSourceRemoved(DesktopMediaList* list, int index) { |
| if (was_selected) |
| OnSelectionChanged(); |
| - PreferredSizeChanged(); |
| - |
| - if (child_count() % DesktopMediaPickerDialogView::kListColumns == 0) |
| + if (child_count() % active_style_->columns == 0) |
| parent_->OnMediaListRowsChanged(); |
| + |
| + // Apply single-item styling when the second source is removed. |
| + if (use_single_style_ && child_count() == 1) |
| + SwitchStyle(&single_style_); |
| + |
| + PreferredSizeChanged(); |
| } |
| void DesktopMediaListView::OnSourceMoved(DesktopMediaList* list, |
| @@ -214,3 +247,16 @@ void DesktopMediaListView::AcceptSelection() { |
| OnSelectionChanged(); |
| OnDoubleClick(); |
| } |
| + |
| +void DesktopMediaListView::SwitchStyle(DesktopMediaSourceViewStyle* style) { |
| + active_style_ = style; |
| + media_list_->SetThumbnailSize(gfx::Size( |
| + style->image_rect.width() - 2 * style->selection_border_thickness, |
| + style->image_rect.height() - 2 * style->selection_border_thickness)); |
| + |
| + for (int i = 0; i < child_count(); i++) { |
| + DesktopMediaSourceView* source_view = |
| + static_cast<DesktopMediaSourceView*>(child_at(i)); |
| + source_view->set_style(*active_style_); |
| + } |
| +} |