| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/desktop_capture/desktop_media_source_view.h" | 5 #include "chrome/browser/ui/views/desktop_capture/desktop_media_source_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/media/desktop_media_list.h" | 7 #include "chrome/browser/media/desktop_media_list.h" |
| 8 #include "chrome/browser/ui/views/desktop_capture/desktop_media_list_view.h" | 8 #include "chrome/browser/ui/views/desktop_capture/desktop_media_list_view.h" |
| 9 #include "chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.h" | 9 #include "chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.h" |
| 10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/native_theme/native_theme.h" | 12 #include "ui/native_theme/native_theme.h" |
| 13 #include "ui/views/background.h" | |
| 14 #include "ui/views/border.h" | 13 #include "ui/views/border.h" |
| 15 #include "ui/views/controls/image_view.h" | 14 #include "ui/views/controls/image_view.h" |
| 16 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 17 | 16 |
| 18 using content::DesktopMediaID; | 17 using content::DesktopMediaID; |
| 19 | 18 |
| 20 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle( | 19 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle( |
| 21 const DesktopMediaSourceViewStyle& style) = default; | 20 const DesktopMediaSourceViewStyle& style) = default; |
| 22 | 21 |
| 23 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle( | 22 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 if (*i != this) { | 78 if (*i != this) { |
| 80 DCHECK_EQ((*i)->GetClassName(), | 79 DCHECK_EQ((*i)->GetClassName(), |
| 81 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); | 80 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); |
| 82 DesktopMediaSourceView* source_view = | 81 DesktopMediaSourceView* source_view = |
| 83 static_cast<DesktopMediaSourceView*>(*i); | 82 static_cast<DesktopMediaSourceView*>(*i); |
| 84 source_view->SetSelected(false); | 83 source_view->SetSelected(false); |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 | 86 |
| 88 const SkColor border_color = GetNativeTheme()->GetSystemColor( | 87 const SkColor border_color = GetNativeTheme()->GetSystemColor( |
| 89 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | 88 ui::NativeTheme::kColorId_FocusedBorderColor); |
| 90 image_view_->SetBorder(views::Border::CreateSolidBorder( | 89 image_view_->SetBorder(views::Border::CreateSolidBorder( |
| 91 style_.selection_border_thickness, border_color)); | 90 style_.selection_border_thickness, border_color)); |
| 92 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL, | 91 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL, |
| 93 gfx::Font::Weight::BOLD)); | 92 gfx::Font::Weight::BOLD)); |
| 94 parent_->OnSelectionChanged(); | 93 parent_->OnSelectionChanged(); |
| 95 } else { | 94 } else { |
| 96 image_view_->SetBorder(views::Border::NullBorder()); | 95 image_view_->SetBorder(views::Border::NullBorder()); |
| 97 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL, | 96 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL, |
| 98 gfx::Font::Weight::NORMAL)); | 97 gfx::Font::Weight::NORMAL)); |
| 99 } | 98 } |
| 100 | 99 |
| 101 SchedulePaint(); | 100 SchedulePaint(); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void DesktopMediaSourceView::SetHovered(bool hovered) { | |
| 105 if (hovered) { | |
| 106 // Use background color to show mouse hover. | |
| 107 const SkColor bg_color = GetNativeTheme()->GetSystemColor( | |
| 108 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); | |
| 109 set_background(views::Background::CreateSolidBackground(bg_color)); | |
| 110 } else { | |
| 111 set_background(nullptr); | |
| 112 } | |
| 113 | |
| 114 SchedulePaint(); | |
| 115 } | |
| 116 | |
| 117 const char* DesktopMediaSourceView::GetClassName() const { | 103 const char* DesktopMediaSourceView::GetClassName() const { |
| 118 return DesktopMediaSourceView::kDesktopMediaSourceViewClassName; | 104 return DesktopMediaSourceView::kDesktopMediaSourceViewClassName; |
| 119 } | 105 } |
| 120 | 106 |
| 121 void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) { | 107 void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) { |
| 122 style_ = style; | 108 style_ = style; |
| 123 image_view_->SetBoundsRect(style_.image_rect); | 109 image_view_->SetBoundsRect(style_.image_rect); |
| 124 if (selected_) { | 110 if (selected_) { |
| 125 const SkColor border_color = GetNativeTheme()->GetSystemColor( | 111 const SkColor border_color = GetNativeTheme()->GetSystemColor( |
| 126 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | 112 ui::NativeTheme::kColorId_FocusedBorderColor); |
| 127 image_view_->SetBorder(views::Border::CreateSolidBorder( | 113 image_view_->SetBorder(views::Border::CreateSolidBorder( |
| 128 style_.selection_border_thickness, border_color)); | 114 style_.selection_border_thickness, border_color)); |
| 129 } | 115 } |
| 130 label_->SetBoundsRect(style_.label_rect); | 116 label_->SetBoundsRect(style_.label_rect); |
| 131 label_->SetHorizontalAlignment(style_.text_alignment); | 117 label_->SetHorizontalAlignment(style_.text_alignment); |
| 132 } | 118 } |
| 133 | 119 |
| 134 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { | 120 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { |
| 135 Views neighbours; | 121 Views neighbours; |
| 136 parent()->GetViewsInGroup(group, &neighbours); | 122 parent()->GetViewsInGroup(group, &neighbours); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) { | 164 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) { |
| 179 if (event.GetClickCount() == 1) { | 165 if (event.GetClickCount() == 1) { |
| 180 RequestFocus(); | 166 RequestFocus(); |
| 181 } else if (event.GetClickCount() == 2) { | 167 } else if (event.GetClickCount() == 2) { |
| 182 RequestFocus(); | 168 RequestFocus(); |
| 183 parent_->OnDoubleClick(); | 169 parent_->OnDoubleClick(); |
| 184 } | 170 } |
| 185 return true; | 171 return true; |
| 186 } | 172 } |
| 187 | 173 |
| 188 void DesktopMediaSourceView::OnMouseEntered(const ui::MouseEvent& event) { | |
| 189 SetHovered(true); | |
| 190 } | |
| 191 | |
| 192 void DesktopMediaSourceView::OnMouseExited(const ui::MouseEvent& event) { | |
| 193 SetHovered(false); | |
| 194 } | |
| 195 | |
| 196 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) { | 174 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) { |
| 197 if (event->type() == ui::ET_GESTURE_TAP && | 175 if (event->type() == ui::ET_GESTURE_TAP && |
| 198 event->details().tap_count() == 2) { | 176 event->details().tap_count() == 2) { |
| 199 RequestFocus(); | 177 RequestFocus(); |
| 200 parent_->OnDoubleClick(); | 178 parent_->OnDoubleClick(); |
| 201 event->SetHandled(); | 179 event->SetHandled(); |
| 202 return; | 180 return; |
| 203 } | 181 } |
| 204 | 182 |
| 205 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused | 183 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused |
| 206 // on the long tap (when the tap gesture starts). | 184 // on the long tap (when the tap gesture starts). |
| 207 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 185 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 208 RequestFocus(); | 186 RequestFocus(); |
| 209 event->SetHandled(); | 187 event->SetHandled(); |
| 210 } | 188 } |
| 211 } | 189 } |
| 212 | 190 |
| 213 void DesktopMediaSourceView::GetAccessibleState(ui::AXViewState* state) { | 191 void DesktopMediaSourceView::GetAccessibleState(ui::AXViewState* state) { |
| 214 state->role = ui::AX_ROLE_BUTTON; | 192 state->role = ui::AX_ROLE_BUTTON; |
| 215 state->name = label_->text(); | 193 state->name = label_->text(); |
| 216 } | 194 } |
| OLD | NEW |