| Index: chrome/browser/ui/views/desktop_capture/desktop_media_source_view.cc
|
| diff --git a/chrome/browser/ui/views/desktop_capture/desktop_media_source_view.cc b/chrome/browser/ui/views/desktop_capture/desktop_media_source_view.cc
|
| index 02c9e68858b2b2eb353ba261867873b97aa7684c..6a55124f77b20e1f7f6fa69b1208871f6b939f52 100644
|
| --- a/chrome/browser/ui/views/desktop_capture/desktop_media_source_view.cc
|
| +++ b/chrome/browser/ui/views/desktop_capture/desktop_media_source_view.cc
|
| @@ -10,21 +10,46 @@
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/native_theme/native_theme.h"
|
| #include "ui/views/background.h"
|
| +#include "ui/views/border.h"
|
| #include "ui/views/controls/image_view.h"
|
| #include "ui/views/controls/label.h"
|
|
|
| using content::DesktopMediaID;
|
|
|
| -DesktopMediaSourceView::DesktopMediaSourceView(DesktopMediaListView* parent,
|
| - DesktopMediaID source_id)
|
| +DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle(
|
| + const DesktopMediaSourceViewStyle& style) = default;
|
| +
|
| +DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle(
|
| + int columns,
|
| + const gfx::Size& item_size,
|
| + const gfx::Rect& label_rect,
|
| + gfx::HorizontalAlignment text_alignment,
|
| + const gfx::Rect& image_rect,
|
| + int selection_border_thickness,
|
| + int focus_rectangle_inset)
|
| + : columns(columns),
|
| + item_size(item_size),
|
| + label_rect(label_rect),
|
| + text_alignment(text_alignment),
|
| + image_rect(image_rect),
|
| + selection_border_thickness(selection_border_thickness),
|
| + focus_rectangle_inset(focus_rectangle_inset) {}
|
| +
|
| +DesktopMediaSourceView::DesktopMediaSourceView(
|
| + DesktopMediaListView* parent,
|
| + DesktopMediaID source_id,
|
| + DesktopMediaSourceViewStyle style)
|
| : parent_(parent),
|
| source_id_(source_id),
|
| + style_(style),
|
| image_view_(new views::ImageView()),
|
| label_(new views::Label()),
|
| selected_(false) {
|
| AddChildView(image_view_);
|
| AddChildView(label_);
|
| + image_view_->set_interactive(false);
|
| SetFocusBehavior(FocusBehavior::ALWAYS);
|
| + SetStyle(style_);
|
| }
|
|
|
| DesktopMediaSourceView::~DesktopMediaSourceView() {}
|
| @@ -59,13 +84,28 @@ void DesktopMediaSourceView::SetSelected(bool selected) {
|
| }
|
| }
|
|
|
| - const SkColor bg_color = GetNativeTheme()->GetSystemColor(
|
| + const SkColor border_color = GetNativeTheme()->GetSystemColor(
|
| ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
|
| - set_background(views::Background::CreateSolidBackground(bg_color));
|
| -
|
| + image_view_->SetBorder(views::Border::CreateSolidBorder(
|
| + style_.selection_border_thickness, border_color));
|
| + label_->SetFontList(label_->font_list().Derive(0, gfx::Font::BOLD));
|
| parent_->OnSelectionChanged();
|
| } else {
|
| - set_background(NULL);
|
| + image_view_->SetBorder(views::Border::NullBorder());
|
| + label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL));
|
| + }
|
| +
|
| + SchedulePaint();
|
| +}
|
| +
|
| +void DesktopMediaSourceView::SetHovered(bool hovered) {
|
| + if (hovered) {
|
| + // Use background color to show mouse hover.
|
| + const SkColor bg_color = GetNativeTheme()->GetSystemColor(
|
| + ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor);
|
| + set_background(views::Background::CreateSolidBackground(bg_color));
|
| + } else {
|
| + set_background(nullptr);
|
| }
|
|
|
| SchedulePaint();
|
| @@ -75,23 +115,24 @@ const char* DesktopMediaSourceView::GetClassName() const {
|
| return DesktopMediaSourceView::kDesktopMediaSourceViewClassName;
|
| }
|
|
|
| -void DesktopMediaSourceView::Layout() {
|
| - image_view_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin,
|
| - DesktopMediaPickerDialogView::kThumbnailMargin,
|
| - DesktopMediaPickerDialogView::kThumbnailWidth,
|
| - DesktopMediaPickerDialogView::kThumbnailHeight);
|
| - label_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin,
|
| - DesktopMediaPickerDialogView::kThumbnailHeight +
|
| - DesktopMediaPickerDialogView::kThumbnailMargin,
|
| - DesktopMediaPickerDialogView::kThumbnailWidth,
|
| - DesktopMediaPickerDialogView::kLabelHeight);
|
| +void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) {
|
| + style_ = style;
|
| + image_view_->SetBoundsRect(style_.image_rect);
|
| + if (selected_) {
|
| + const SkColor border_color = GetNativeTheme()->GetSystemColor(
|
| + ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
|
| + image_view_->SetBorder(views::Border::CreateSolidBorder(
|
| + style_.selection_border_thickness, border_color));
|
| + }
|
| + label_->SetBoundsRect(style_.label_rect);
|
| + label_->SetHorizontalAlignment(style_.text_alignment);
|
| }
|
|
|
| views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
|
| Views neighbours;
|
| parent()->GetViewsInGroup(group, &neighbours);
|
| if (neighbours.empty())
|
| - return NULL;
|
| + return nullptr;
|
|
|
| for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
|
| DCHECK_EQ((*i)->GetClassName(),
|
| @@ -101,7 +142,7 @@ views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
|
| if (source_view->selected_)
|
| return source_view;
|
| }
|
| - return NULL;
|
| + return nullptr;
|
| }
|
|
|
| bool DesktopMediaSourceView::IsGroupFocusTraversable() const {
|
| @@ -112,8 +153,7 @@ void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) {
|
| View::OnPaint(canvas);
|
| if (HasFocus()) {
|
| gfx::Rect bounds(GetLocalBounds());
|
| - bounds.Inset(DesktopMediaPickerDialogView::kThumbnailMargin / 2,
|
| - DesktopMediaPickerDialogView::kThumbnailMargin / 2);
|
| + bounds.Inset(style_.focus_rectangle_inset, style_.focus_rectangle_inset);
|
| canvas->DrawFocusRect(bounds);
|
| }
|
| }
|
| @@ -142,6 +182,14 @@ bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) {
|
| return true;
|
| }
|
|
|
| +void DesktopMediaSourceView::OnMouseEntered(const ui::MouseEvent& event) {
|
| + SetHovered(true);
|
| +}
|
| +
|
| +void DesktopMediaSourceView::OnMouseExited(const ui::MouseEvent& event) {
|
| + SetHovered(false);
|
| +}
|
| +
|
| void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) {
|
| if (event->type() == ui::ET_GESTURE_TAP &&
|
| event->details().tap_count() == 2) {
|
|
|