Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/desktop_capture/desktop_media_source_view.h" | |
| 6 | |
| 7 #include "chrome/browser/media/desktop_media_list.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" | |
| 10 #include "ui/gfx/canvas.h" | |
| 11 #include "ui/native_theme/native_theme.h" | |
| 12 #include "ui/views/background.h" | |
| 13 #include "ui/views/controls/image_view.h" | |
| 14 #include "ui/views/controls/label.h" | |
| 15 | |
| 16 using content::DesktopMediaID; | |
| 17 | |
| 18 DesktopMediaSourceView::DesktopMediaSourceView(DesktopMediaListView* parent, | |
| 19 DesktopMediaID source_id) | |
| 20 : parent_(parent), | |
| 21 source_id_(source_id), | |
| 22 image_view_(new views::ImageView()), | |
| 23 label_(new views::Label()), | |
| 24 selected_(false) { | |
| 25 AddChildView(image_view_); | |
| 26 AddChildView(label_); | |
| 27 SetFocusBehavior(FocusBehavior::ALWAYS); | |
| 28 } | |
| 29 | |
| 30 DesktopMediaSourceView::~DesktopMediaSourceView() {} | |
| 31 | |
| 32 const char* DesktopMediaSourceView::kDesktopMediaSourceViewClassName = | |
| 33 "DesktopMediaPicker_DesktopMediaSourceView"; | |
| 34 | |
| 35 void DesktopMediaSourceView::SetName(const base::string16& name) { | |
| 36 label_->SetText(name); | |
| 37 } | |
| 38 | |
| 39 void DesktopMediaSourceView::SetThumbnail(const gfx::ImageSkia& thumbnail) { | |
| 40 image_view_->SetImage(thumbnail); | |
| 41 } | |
| 42 | |
| 43 void DesktopMediaSourceView::SetSelected(bool selected) { | |
| 44 if (selected == selected_) | |
| 45 return; | |
| 46 selected_ = selected; | |
| 47 | |
| 48 if (selected) { | |
| 49 // Unselect all other sources. | |
| 50 Views neighbours; | |
| 51 parent()->GetViewsInGroup(GetGroup(), &neighbours); | |
| 52 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) { | |
| 53 if (*i != this) { | |
| 54 DCHECK_EQ((*i)->GetClassName(), | |
| 55 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); | |
| 56 DesktopMediaSourceView* source_view = | |
| 57 static_cast<DesktopMediaSourceView*>(*i); | |
| 58 source_view->SetSelected(false); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 const SkColor bg_color = GetNativeTheme()->GetSystemColor( | |
| 63 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | |
| 64 set_background(views::Background::CreateSolidBackground(bg_color)); | |
| 65 | |
| 66 parent_->OnSelectionChanged(); | |
| 67 } else { | |
| 68 set_background(NULL); | |
| 69 } | |
| 70 | |
| 71 SchedulePaint(); | |
| 72 } | |
| 73 | |
| 74 const char* DesktopMediaSourceView::GetClassName() const { | |
| 75 // return nullptr; | |
|
msw
2016/05/16 22:49:25
Remove this
qiangchen
2016/05/16 23:49:42
Done.
Ah, this is my debug code. I am not sure wh
| |
| 76 return DesktopMediaSourceView::kDesktopMediaSourceViewClassName; | |
| 77 } | |
| 78 | |
| 79 void DesktopMediaSourceView::Layout() { | |
| 80 image_view_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin, | |
| 81 DesktopMediaPickerDialogView::kThumbnailMargin, | |
| 82 DesktopMediaPickerDialogView::kThumbnailWidth, | |
| 83 DesktopMediaPickerDialogView::kThumbnailHeight); | |
| 84 label_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin, | |
| 85 DesktopMediaPickerDialogView::kThumbnailHeight + | |
| 86 DesktopMediaPickerDialogView::kThumbnailMargin, | |
| 87 DesktopMediaPickerDialogView::kThumbnailWidth, | |
| 88 DesktopMediaPickerDialogView::kLabelHeight); | |
| 89 } | |
| 90 | |
| 91 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { | |
| 92 Views neighbours; | |
| 93 parent()->GetViewsInGroup(group, &neighbours); | |
| 94 if (neighbours.empty()) | |
| 95 return NULL; | |
| 96 | |
| 97 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) { | |
| 98 DCHECK_EQ((*i)->GetClassName(), | |
| 99 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); | |
| 100 DesktopMediaSourceView* source_view = | |
| 101 static_cast<DesktopMediaSourceView*>(*i); | |
| 102 if (source_view->selected_) | |
| 103 return source_view; | |
| 104 } | |
| 105 return NULL; | |
| 106 } | |
| 107 | |
| 108 bool DesktopMediaSourceView::IsGroupFocusTraversable() const { | |
| 109 return false; | |
| 110 } | |
| 111 | |
| 112 void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) { | |
| 113 View::OnPaint(canvas); | |
| 114 if (HasFocus()) { | |
| 115 gfx::Rect bounds(GetLocalBounds()); | |
| 116 bounds.Inset(DesktopMediaPickerDialogView::kThumbnailMargin / 2, | |
| 117 DesktopMediaPickerDialogView::kThumbnailMargin / 2); | |
| 118 canvas->DrawFocusRect(bounds); | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 void DesktopMediaSourceView::OnFocus() { | |
| 123 View::OnFocus(); | |
| 124 SetSelected(true); | |
| 125 ScrollRectToVisible(gfx::Rect(size())); | |
| 126 // We paint differently when focused. | |
| 127 SchedulePaint(); | |
| 128 } | |
| 129 | |
| 130 void DesktopMediaSourceView::OnBlur() { | |
| 131 View::OnBlur(); | |
| 132 // We paint differently when focused. | |
| 133 SchedulePaint(); | |
| 134 } | |
| 135 | |
| 136 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) { | |
| 137 if (event.GetClickCount() == 1) { | |
| 138 RequestFocus(); | |
| 139 } else if (event.GetClickCount() == 2) { | |
| 140 RequestFocus(); | |
| 141 parent_->OnDoubleClick(); | |
| 142 } | |
| 143 return true; | |
| 144 } | |
| 145 | |
| 146 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) { | |
| 147 if (event->type() == ui::ET_GESTURE_TAP && | |
| 148 event->details().tap_count() == 2) { | |
| 149 RequestFocus(); | |
| 150 parent_->OnDoubleClick(); | |
| 151 event->SetHandled(); | |
| 152 return; | |
| 153 } | |
| 154 | |
| 155 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused | |
| 156 // on the long tap (when the tap gesture starts). | |
| 157 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | |
| 158 RequestFocus(); | |
| 159 event->SetHandled(); | |
| 160 } | |
| 161 } | |
| OLD | NEW |