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

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

Issue 1990053002: Desktop Capture Picker New UI: Non Mac Appearance Change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/native_theme/native_theme.h" 11 #include "ui/native_theme/native_theme.h"
12 #include "ui/views/background.h" 12 #include "ui/views/background.h"
13 #include "ui/views/border.h"
13 #include "ui/views/controls/image_view.h" 14 #include "ui/views/controls/image_view.h"
14 #include "ui/views/controls/label.h" 15 #include "ui/views/controls/label.h"
15 16
16 using content::DesktopMediaID; 17 using content::DesktopMediaID;
17 18
18 DesktopMediaSourceView::DesktopMediaSourceView(DesktopMediaListView* parent, 19 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle()
19 DesktopMediaID source_id) 20 : columns(0),
21 text_alignment(gfx::HorizontalAlignment::ALIGN_CENTER),
22 selection_border_thickness(0),
23 paint_inset_horizontal(0),
24 paint_inset_vertical(0) {}
25
26 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle(
27 const DesktopMediaSourceViewStyle& style) {
28 columns = style.columns;
29 item_size = style.item_size;
30 image_position = style.image_position;
31 selection_border_thickness = style.selection_border_thickness;
32 label_position = style.label_position;
33 text_alignment = style.text_alignment;
34 paint_inset_horizontal = style.paint_inset_horizontal;
35 paint_inset_vertical = style.paint_inset_vertical;
36 }
37
38 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle(
39 int columns,
40 const gfx::Size& item_size,
41 const gfx::Rect& label_position,
42 gfx::HorizontalAlignment text_alignment,
43 const gfx::Rect& image_position,
44 int selection_border_thickness,
45 int paint_inset_horizontal,
46 int paint_inset_vertical)
47 : columns(columns),
48 item_size(item_size),
49 label_position(label_position),
50 text_alignment(text_alignment),
51 image_position(image_position),
52 selection_border_thickness(selection_border_thickness),
53 paint_inset_horizontal(paint_inset_horizontal),
54 paint_inset_vertical(paint_inset_vertical) {}
55
56 DesktopMediaSourceView::DesktopMediaSourceView(
57 DesktopMediaListView* parent,
58 DesktopMediaID source_id,
59 DesktopMediaSourceViewStyle style)
20 : parent_(parent), 60 : parent_(parent),
21 source_id_(source_id), 61 source_id_(source_id),
62 style_(style),
22 image_view_(new views::ImageView()), 63 image_view_(new views::ImageView()),
23 label_(new views::Label()), 64 label_(new views::Label()),
24 selected_(false) { 65 selected_(false) {
25 AddChildView(image_view_); 66 AddChildView(image_view_);
26 AddChildView(label_); 67 AddChildView(label_);
68 image_view_->set_interactive(false);
69
27 SetFocusBehavior(FocusBehavior::ALWAYS); 70 SetFocusBehavior(FocusBehavior::ALWAYS);
28 } 71 }
29 72
30 DesktopMediaSourceView::~DesktopMediaSourceView() {} 73 DesktopMediaSourceView::~DesktopMediaSourceView() {}
31 74
75
msw 2016/05/20 23:26:37 nit: remove
qiangchen 2016/05/24 00:03:37 Done.
32 const char* DesktopMediaSourceView::kDesktopMediaSourceViewClassName = 76 const char* DesktopMediaSourceView::kDesktopMediaSourceViewClassName =
33 "DesktopMediaPicker_DesktopMediaSourceView"; 77 "DesktopMediaPicker_DesktopMediaSourceView";
34 78
79 void DesktopMediaSourceView::SetStyle(DesktopMediaSourceViewStyle style) {
msw 2016/05/20 23:26:37 nit: make this a simple accessor, defined in the h
qiangchen 2016/05/24 00:03:37 Done.
80 style_ = style;
81 }
82
35 void DesktopMediaSourceView::SetName(const base::string16& name) { 83 void DesktopMediaSourceView::SetName(const base::string16& name) {
36 label_->SetText(name); 84 label_->SetText(name);
37 } 85 }
38 86
39 void DesktopMediaSourceView::SetThumbnail(const gfx::ImageSkia& thumbnail) { 87 void DesktopMediaSourceView::SetThumbnail(const gfx::ImageSkia& thumbnail) {
40 image_view_->SetImage(thumbnail); 88 image_view_->SetImage(thumbnail);
41 } 89 }
42 90
43 void DesktopMediaSourceView::SetSelected(bool selected) { 91 void DesktopMediaSourceView::SetSelected(bool selected) {
44 if (selected == selected_) 92 if (selected == selected_)
45 return; 93 return;
46 selected_ = selected; 94 selected_ = selected;
47 95
48 if (selected) { 96 if (selected) {
49 // Unselect all other sources. 97 // Unselect all other sources.
50 Views neighbours; 98 Views neighbours;
51 parent()->GetViewsInGroup(GetGroup(), &neighbours); 99 parent()->GetViewsInGroup(GetGroup(), &neighbours);
52 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) { 100 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
53 if (*i != this) { 101 if (*i != this) {
54 DCHECK_EQ((*i)->GetClassName(), 102 DCHECK_EQ((*i)->GetClassName(),
55 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); 103 DesktopMediaSourceView::kDesktopMediaSourceViewClassName);
56 DesktopMediaSourceView* source_view = 104 DesktopMediaSourceView* source_view =
57 static_cast<DesktopMediaSourceView*>(*i); 105 static_cast<DesktopMediaSourceView*>(*i);
58 source_view->SetSelected(false); 106 source_view->SetSelected(false);
59 } 107 }
60 } 108 }
61 109
62 const SkColor bg_color = GetNativeTheme()->GetSystemColor( 110 const SkColor border_color = GetNativeTheme()->GetSystemColor(
63 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); 111 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
112 image_view_->SetBorder(views::Border::CreateSolidBorder(
113 style_.selection_border_thickness, border_color));
114 gfx::Font font =
115 label_->font_list().GetPrimaryFont().Derive(0, gfx::Font::BOLD);
116 label_->SetFontList(gfx::FontList(font));
msw 2016/05/20 23:26:37 nit: label_->SetFontList(label_->font_list().Deriv
qiangchen 2016/05/24 00:03:37 Done.
117 parent_->OnSelectionChanged();
118 } else {
119 image_view_->SetBorder(views::Border::NullBorder());
120 gfx::Font font =
121 label_->font_list().GetPrimaryFont().Derive(0, gfx::Font::NORMAL);
122 label_->SetFontList(gfx::FontList(font));
msw 2016/05/20 23:26:37 nit: label_->SetFontList(label_->font_list().Deriv
qiangchen 2016/05/24 00:03:37 Done.
123 }
124
125 SchedulePaint();
126 }
127
128 void DesktopMediaSourceView::SetHovered(bool hovered) {
129 if (hovered == hovered_)
msw 2016/05/20 23:26:37 nit: tracking hovered_ to early return here probab
qiangchen 2016/05/24 00:03:37 Done.
130 return;
131
132 hovered_ = hovered;
133
134 if (hovered) {
135 // Make the background a little darker.
136 const SkColor bg_color = 0x44000000;
msw 2016/05/20 23:26:37 Use kColorId_HoverMenuItemBackgroundColor
qiangchen 2016/05/24 00:03:37 Done. But I found HoverMenuButtonColor looks bett
msw 2016/05/24 18:54:25 Please post pictures of each, it seems odd to mix
qiangchen 2016/05/25 16:24:08 I'll set color for the scroll_view's background to
64 set_background(views::Background::CreateSolidBackground(bg_color)); 137 set_background(views::Background::CreateSolidBackground(bg_color));
65
66 parent_->OnSelectionChanged();
67 } else { 138 } else {
68 set_background(NULL); 139 set_background(NULL);
69 } 140 }
70 141
71 SchedulePaint(); 142 SchedulePaint();
72 } 143 }
73 144
74 const char* DesktopMediaSourceView::GetClassName() const { 145 const char* DesktopMediaSourceView::GetClassName() const {
75 return DesktopMediaSourceView::kDesktopMediaSourceViewClassName; 146 return DesktopMediaSourceView::kDesktopMediaSourceViewClassName;
76 } 147 }
77 148
78 void DesktopMediaSourceView::Layout() { 149 void DesktopMediaSourceView::Layout() {
79 image_view_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin, 150 image_view_->SetBoundsRect(style_.image_position);
80 DesktopMediaPickerDialogView::kThumbnailMargin, 151 label_->SetBoundsRect(style_.label_position);
81 DesktopMediaPickerDialogView::kThumbnailWidth, 152 label_->SetHorizontalAlignment(style_.text_alignment);
82 DesktopMediaPickerDialogView::kThumbnailHeight);
83 label_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin,
84 DesktopMediaPickerDialogView::kThumbnailHeight +
85 DesktopMediaPickerDialogView::kThumbnailMargin,
86 DesktopMediaPickerDialogView::kThumbnailWidth,
87 DesktopMediaPickerDialogView::kLabelHeight);
88 } 153 }
89 154
90 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { 155 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
91 Views neighbours; 156 Views neighbours;
92 parent()->GetViewsInGroup(group, &neighbours); 157 parent()->GetViewsInGroup(group, &neighbours);
93 if (neighbours.empty()) 158 if (neighbours.empty())
94 return NULL; 159 return NULL;
95 160
96 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) { 161 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
97 DCHECK_EQ((*i)->GetClassName(), 162 DCHECK_EQ((*i)->GetClassName(),
98 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); 163 DesktopMediaSourceView::kDesktopMediaSourceViewClassName);
99 DesktopMediaSourceView* source_view = 164 DesktopMediaSourceView* source_view =
100 static_cast<DesktopMediaSourceView*>(*i); 165 static_cast<DesktopMediaSourceView*>(*i);
101 if (source_view->selected_) 166 if (source_view->selected_)
102 return source_view; 167 return source_view;
103 } 168 }
104 return NULL; 169 return NULL;
105 } 170 }
106 171
107 bool DesktopMediaSourceView::IsGroupFocusTraversable() const { 172 bool DesktopMediaSourceView::IsGroupFocusTraversable() const {
108 return false; 173 return false;
109 } 174 }
110 175
111 void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) { 176 void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) {
112 View::OnPaint(canvas); 177 View::OnPaint(canvas);
113 if (HasFocus()) { 178 if (HasFocus()) {
114 gfx::Rect bounds(GetLocalBounds()); 179 gfx::Rect bounds(GetLocalBounds());
115 bounds.Inset(DesktopMediaPickerDialogView::kThumbnailMargin / 2, 180 bounds.Inset(style_.paint_inset_horizontal, style_.paint_inset_vertical);
116 DesktopMediaPickerDialogView::kThumbnailMargin / 2);
117 canvas->DrawFocusRect(bounds); 181 canvas->DrawFocusRect(bounds);
118 } 182 }
119 } 183 }
120 184
121 void DesktopMediaSourceView::OnFocus() { 185 void DesktopMediaSourceView::OnFocus() {
122 View::OnFocus(); 186 View::OnFocus();
123 SetSelected(true); 187 SetSelected(true);
124 ScrollRectToVisible(gfx::Rect(size())); 188 ScrollRectToVisible(gfx::Rect(size()));
125 // We paint differently when focused. 189 // We paint differently when focused.
126 SchedulePaint(); 190 SchedulePaint();
127 } 191 }
128 192
129 void DesktopMediaSourceView::OnBlur() { 193 void DesktopMediaSourceView::OnBlur() {
130 View::OnBlur(); 194 View::OnBlur();
131 // We paint differently when focused. 195 // We paint differently when focused.
132 SchedulePaint(); 196 SchedulePaint();
133 } 197 }
134 198
135 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) { 199 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) {
136 if (event.GetClickCount() == 1) { 200 if (event.GetClickCount() == 1) {
137 RequestFocus(); 201 RequestFocus();
138 } else if (event.GetClickCount() == 2) { 202 } else if (event.GetClickCount() == 2) {
139 RequestFocus(); 203 RequestFocus();
140 parent_->OnDoubleClick(); 204 parent_->OnDoubleClick();
141 } 205 }
142 return true; 206 return true;
143 } 207 }
144 208
209 void DesktopMediaSourceView::OnMouseEntered(const ui::MouseEvent& event) {
210 SetHovered(true);
211 }
212
213 void DesktopMediaSourceView::OnMouseExited(const ui::MouseEvent& event) {
214 SetHovered(false);
215 }
216
145 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) { 217 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) {
146 if (event->type() == ui::ET_GESTURE_TAP && 218 if (event->type() == ui::ET_GESTURE_TAP &&
147 event->details().tap_count() == 2) { 219 event->details().tap_count() == 2) {
148 RequestFocus(); 220 RequestFocus();
149 parent_->OnDoubleClick(); 221 parent_->OnDoubleClick();
150 event->SetHandled(); 222 event->SetHandled();
151 return; 223 return;
152 } 224 }
153 225
154 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused 226 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused
155 // on the long tap (when the tap gesture starts). 227 // on the long tap (when the tap gesture starts).
156 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { 228 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
157 RequestFocus(); 229 RequestFocus();
158 event->SetHandled(); 230 event->SetHandled();
159 } 231 }
160 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698