| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (*i != this) { | 87 if (*i != this) { |
| 89 DCHECK_EQ((*i)->GetClassName(), | 88 DCHECK_EQ((*i)->GetClassName(), |
| 90 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); | 89 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); |
| 91 DesktopMediaSourceView* source_view = | 90 DesktopMediaSourceView* source_view = |
| 92 static_cast<DesktopMediaSourceView*>(*i); | 91 static_cast<DesktopMediaSourceView*>(*i); |
| 93 source_view->SetSelected(false); | 92 source_view->SetSelected(false); |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 | 95 |
| 97 const SkColor border_color = GetNativeTheme()->GetSystemColor( | 96 const SkColor border_color = GetNativeTheme()->GetSystemColor( |
| 98 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | 97 ui::NativeTheme::kColorId_FocusedBorderColor); |
| 99 image_view_->SetBorder(views::Border::CreateSolidBorder( | 98 image_view_->SetBorder(views::Border::CreateSolidBorder( |
| 100 style_.selection_border_thickness, border_color)); | 99 style_.selection_border_thickness, border_color)); |
| 101 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL, | 100 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL, |
| 102 gfx::Font::Weight::BOLD)); | 101 gfx::Font::Weight::BOLD)); |
| 103 parent_->OnSelectionChanged(); | 102 parent_->OnSelectionChanged(); |
| 104 } else { | 103 } else { |
| 105 image_view_->SetBorder(views::Border::NullBorder()); | 104 image_view_->SetBorder(views::Border::NullBorder()); |
| 106 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL, | 105 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL, |
| 107 gfx::Font::Weight::NORMAL)); | 106 gfx::Font::Weight::NORMAL)); |
| 108 } | 107 } |
| 109 | 108 |
| 110 SchedulePaint(); | 109 SchedulePaint(); |
| 111 } | 110 } |
| 112 | 111 |
| 113 void DesktopMediaSourceView::SetHovered(bool hovered) { | |
| 114 if (hovered) { | |
| 115 // Use background color to show mouse hover. | |
| 116 const SkColor bg_color = GetNativeTheme()->GetSystemColor( | |
| 117 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); | |
| 118 set_background(views::Background::CreateSolidBackground(bg_color)); | |
| 119 } else { | |
| 120 set_background(nullptr); | |
| 121 } | |
| 122 | |
| 123 SchedulePaint(); | |
| 124 } | |
| 125 | |
| 126 const char* DesktopMediaSourceView::GetClassName() const { | 112 const char* DesktopMediaSourceView::GetClassName() const { |
| 127 return DesktopMediaSourceView::kDesktopMediaSourceViewClassName; | 113 return DesktopMediaSourceView::kDesktopMediaSourceViewClassName; |
| 128 } | 114 } |
| 129 | 115 |
| 130 void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) { | 116 void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) { |
| 131 style_ = style; | 117 style_ = style; |
| 132 image_view_->SetBoundsRect(style_.image_rect); | 118 image_view_->SetBoundsRect(style_.image_rect); |
| 133 if (selected_) { | 119 if (selected_) { |
| 134 const SkColor border_color = GetNativeTheme()->GetSystemColor( | 120 const SkColor border_color = GetNativeTheme()->GetSystemColor( |
| 135 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | 121 ui::NativeTheme::kColorId_FocusedBorderColor); |
| 136 image_view_->SetBorder(views::Border::CreateSolidBorder( | 122 image_view_->SetBorder(views::Border::CreateSolidBorder( |
| 137 style_.selection_border_thickness, border_color)); | 123 style_.selection_border_thickness, border_color)); |
| 138 } | 124 } |
| 139 icon_view_->SetBoundsRect(style_.icon_rect); | 125 icon_view_->SetBoundsRect(style_.icon_rect); |
| 140 icon_view_->SetImageSize(style_.icon_rect.size()); | 126 icon_view_->SetImageSize(style_.icon_rect.size()); |
| 141 label_->SetBoundsRect(style_.label_rect); | 127 label_->SetBoundsRect(style_.label_rect); |
| 142 label_->SetHorizontalAlignment(style_.text_alignment); | 128 label_->SetHorizontalAlignment(style_.text_alignment); |
| 143 } | 129 } |
| 144 | 130 |
| 145 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { | 131 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) { | 175 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) { |
| 190 if (event.GetClickCount() == 1) { | 176 if (event.GetClickCount() == 1) { |
| 191 RequestFocus(); | 177 RequestFocus(); |
| 192 } else if (event.GetClickCount() == 2) { | 178 } else if (event.GetClickCount() == 2) { |
| 193 RequestFocus(); | 179 RequestFocus(); |
| 194 parent_->OnDoubleClick(); | 180 parent_->OnDoubleClick(); |
| 195 } | 181 } |
| 196 return true; | 182 return true; |
| 197 } | 183 } |
| 198 | 184 |
| 199 void DesktopMediaSourceView::OnMouseEntered(const ui::MouseEvent& event) { | |
| 200 SetHovered(true); | |
| 201 } | |
| 202 | |
| 203 void DesktopMediaSourceView::OnMouseExited(const ui::MouseEvent& event) { | |
| 204 SetHovered(false); | |
| 205 } | |
| 206 | |
| 207 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) { | 185 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) { |
| 208 if (event->type() == ui::ET_GESTURE_TAP && | 186 if (event->type() == ui::ET_GESTURE_TAP && |
| 209 event->details().tap_count() == 2) { | 187 event->details().tap_count() == 2) { |
| 210 RequestFocus(); | 188 RequestFocus(); |
| 211 parent_->OnDoubleClick(); | 189 parent_->OnDoubleClick(); |
| 212 event->SetHandled(); | 190 event->SetHandled(); |
| 213 return; | 191 return; |
| 214 } | 192 } |
| 215 | 193 |
| 216 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused | 194 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused |
| 217 // on the long tap (when the tap gesture starts). | 195 // on the long tap (when the tap gesture starts). |
| 218 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 196 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 219 RequestFocus(); | 197 RequestFocus(); |
| 220 event->SetHandled(); | 198 event->SetHandled(); |
| 221 } | 199 } |
| 222 } | 200 } |
| 223 | 201 |
| 224 void DesktopMediaSourceView::GetAccessibleState(ui::AXViewState* state) { | 202 void DesktopMediaSourceView::GetAccessibleState(ui::AXViewState* state) { |
| 225 state->role = ui::AX_ROLE_BUTTON; | 203 state->role = ui::AX_ROLE_BUTTON; |
| 226 state->name = label_->text(); | 204 state->name = label_->text(); |
| 227 } | 205 } |
| OLD | NEW |