Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/browser/ui/views/desktop_capture/desktop_media_source_view.cc

Issue 2270543003: Display Window Icon In Picker UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unittest crash Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 13 #include "ui/views/background.h"
14 #include "ui/views/border.h" 14 #include "ui/views/border.h"
15 #include "ui/views/controls/image_view.h" 15 #include "ui/views/controls/image_view.h"
16 #include "ui/views/controls/label.h" 16 #include "ui/views/controls/label.h"
17 17
18 using content::DesktopMediaID; 18 using content::DesktopMediaID;
19 19
20 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle( 20 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle(
21 const DesktopMediaSourceViewStyle& style) = default; 21 const DesktopMediaSourceViewStyle& style) = default;
22 22
23 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle( 23 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle(
24 int columns, 24 int columns,
25 const gfx::Size& item_size, 25 const gfx::Size& item_size,
26 const gfx::Rect& icon_rect,
26 const gfx::Rect& label_rect, 27 const gfx::Rect& label_rect,
27 gfx::HorizontalAlignment text_alignment, 28 gfx::HorizontalAlignment text_alignment,
28 const gfx::Rect& image_rect, 29 const gfx::Rect& image_rect,
29 int selection_border_thickness, 30 int selection_border_thickness,
30 int focus_rectangle_inset) 31 int focus_rectangle_inset)
31 : columns(columns), 32 : columns(columns),
32 item_size(item_size), 33 item_size(item_size),
34 icon_rect(icon_rect),
33 label_rect(label_rect), 35 label_rect(label_rect),
34 text_alignment(text_alignment), 36 text_alignment(text_alignment),
35 image_rect(image_rect), 37 image_rect(image_rect),
36 selection_border_thickness(selection_border_thickness), 38 selection_border_thickness(selection_border_thickness),
37 focus_rectangle_inset(focus_rectangle_inset) {} 39 focus_rectangle_inset(focus_rectangle_inset) {}
38 40
39 DesktopMediaSourceView::DesktopMediaSourceView( 41 DesktopMediaSourceView::DesktopMediaSourceView(
40 DesktopMediaListView* parent, 42 DesktopMediaListView* parent,
41 DesktopMediaID source_id, 43 DesktopMediaID source_id,
42 DesktopMediaSourceViewStyle style) 44 DesktopMediaSourceViewStyle style)
43 : parent_(parent), 45 : parent_(parent),
44 source_id_(source_id), 46 source_id_(source_id),
45 style_(style), 47 style_(style),
48 icon_view_(new views::ImageView()),
46 image_view_(new views::ImageView()), 49 image_view_(new views::ImageView()),
47 label_(new views::Label()), 50 label_(new views::Label()),
48 selected_(false) { 51 selected_(false) {
52 AddChildView(icon_view_);
49 AddChildView(image_view_); 53 AddChildView(image_view_);
50 AddChildView(label_); 54 AddChildView(label_);
51 image_view_->set_interactive(false); 55 image_view_->set_interactive(false);
56 icon_view_->set_interactive(false);
msw 2016/08/23 21:37:12 nit: order before image_view_->set_interactive(fal
qiangchen 2016/08/23 23:24:30 Done.
52 SetFocusBehavior(FocusBehavior::ALWAYS); 57 SetFocusBehavior(FocusBehavior::ALWAYS);
53 SetStyle(style_); 58 SetStyle(style_);
54 } 59 }
55 60
56 DesktopMediaSourceView::~DesktopMediaSourceView() {} 61 DesktopMediaSourceView::~DesktopMediaSourceView() {}
57 62
58 const char* DesktopMediaSourceView::kDesktopMediaSourceViewClassName = 63 const char* DesktopMediaSourceView::kDesktopMediaSourceViewClassName =
59 "DesktopMediaPicker_DesktopMediaSourceView"; 64 "DesktopMediaPicker_DesktopMediaSourceView";
60 65
61 void DesktopMediaSourceView::SetName(const base::string16& name) { 66 void DesktopMediaSourceView::SetName(const base::string16& name) {
62 label_->SetText(name); 67 label_->SetText(name);
63 } 68 }
64 69
65 void DesktopMediaSourceView::SetThumbnail(const gfx::ImageSkia& thumbnail) { 70 void DesktopMediaSourceView::SetThumbnail(const gfx::ImageSkia& thumbnail) {
66 image_view_->SetImage(thumbnail); 71 image_view_->SetImage(thumbnail);
67 } 72 }
68 73
74 void DesktopMediaSourceView::SetIcon(const gfx::ImageSkia& icon) {
75 icon_view_->SetImage(icon);
76 }
77
69 void DesktopMediaSourceView::SetSelected(bool selected) { 78 void DesktopMediaSourceView::SetSelected(bool selected) {
70 if (selected == selected_) 79 if (selected == selected_)
71 return; 80 return;
72 selected_ = selected; 81 selected_ = selected;
73 82
74 if (selected) { 83 if (selected) {
75 // Unselect all other sources. 84 // Unselect all other sources.
76 Views neighbours; 85 Views neighbours;
77 parent()->GetViewsInGroup(GetGroup(), &neighbours); 86 parent()->GetViewsInGroup(GetGroup(), &neighbours);
78 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) { 87 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 129
121 void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) { 130 void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) {
122 style_ = style; 131 style_ = style;
123 image_view_->SetBoundsRect(style_.image_rect); 132 image_view_->SetBoundsRect(style_.image_rect);
124 if (selected_) { 133 if (selected_) {
125 const SkColor border_color = GetNativeTheme()->GetSystemColor( 134 const SkColor border_color = GetNativeTheme()->GetSystemColor(
126 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); 135 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
127 image_view_->SetBorder(views::Border::CreateSolidBorder( 136 image_view_->SetBorder(views::Border::CreateSolidBorder(
128 style_.selection_border_thickness, border_color)); 137 style_.selection_border_thickness, border_color));
129 } 138 }
139 icon_view_->SetBoundsRect(style_.icon_rect);
140 icon_view_->SetImageSize(gfx::Size(style_.icon_rect.width(),
msw 2016/08/23 21:37:12 nit: icon_view_->SetImageSize(style_.icon_rect.siz
qiangchen 2016/08/23 23:24:30 Done.
141 style_.icon_rect.height()));
130 label_->SetBoundsRect(style_.label_rect); 142 label_->SetBoundsRect(style_.label_rect);
131 label_->SetHorizontalAlignment(style_.text_alignment); 143 label_->SetHorizontalAlignment(style_.text_alignment);
132 } 144 }
133 145
134 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { 146 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
135 Views neighbours; 147 Views neighbours;
136 parent()->GetViewsInGroup(group, &neighbours); 148 parent()->GetViewsInGroup(group, &neighbours);
137 if (neighbours.empty()) 149 if (neighbours.empty())
138 return nullptr; 150 return nullptr;
139 151
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { 219 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
208 RequestFocus(); 220 RequestFocus();
209 event->SetHandled(); 221 event->SetHandled();
210 } 222 }
211 } 223 }
212 224
213 void DesktopMediaSourceView::GetAccessibleState(ui::AXViewState* state) { 225 void DesktopMediaSourceView::GetAccessibleState(ui::AXViewState* state) {
214 state->role = ui::AX_ROLE_BUTTON; 226 state->role = ui::AX_ROLE_BUTTON;
215 state->name = label_->text(); 227 state->name = label_->text();
216 } 228 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698