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

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: Nit Fixes 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
« no previous file with comments | « chrome/browser/ui/views/desktop_capture/desktop_media_source_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const DesktopMediaSourceViewStyle& style) = default;
21
22 DesktopMediaSourceViewStyle::DesktopMediaSourceViewStyle(
23 int columns,
24 const gfx::Size& item_size,
25 const gfx::Rect& label_rect,
26 gfx::HorizontalAlignment text_alignment,
27 const gfx::Rect& image_rect,
28 int selection_border_thickness,
29 int focus_rectangle_inset)
30 : columns(columns),
31 item_size(item_size),
32 label_rect(label_rect),
33 text_alignment(text_alignment),
34 image_rect(image_rect),
35 selection_border_thickness(selection_border_thickness),
36 focus_rectangle_inset(focus_rectangle_inset) {}
37
38 DesktopMediaSourceView::DesktopMediaSourceView(
39 DesktopMediaListView* parent,
40 DesktopMediaID source_id,
41 DesktopMediaSourceViewStyle style)
20 : parent_(parent), 42 : parent_(parent),
21 source_id_(source_id), 43 source_id_(source_id),
44 style_(style),
22 image_view_(new views::ImageView()), 45 image_view_(new views::ImageView()),
23 label_(new views::Label()), 46 label_(new views::Label()),
24 selected_(false) { 47 selected_(false) {
25 AddChildView(image_view_); 48 AddChildView(image_view_);
26 AddChildView(label_); 49 AddChildView(label_);
50 image_view_->set_interactive(false);
51
27 SetFocusBehavior(FocusBehavior::ALWAYS); 52 SetFocusBehavior(FocusBehavior::ALWAYS);
28 } 53 }
29 54
30 DesktopMediaSourceView::~DesktopMediaSourceView() {} 55 DesktopMediaSourceView::~DesktopMediaSourceView() {}
31 56
32 const char* DesktopMediaSourceView::kDesktopMediaSourceViewClassName = 57 const char* DesktopMediaSourceView::kDesktopMediaSourceViewClassName =
33 "DesktopMediaPicker_DesktopMediaSourceView"; 58 "DesktopMediaPicker_DesktopMediaSourceView";
34 59
35 void DesktopMediaSourceView::SetName(const base::string16& name) { 60 void DesktopMediaSourceView::SetName(const base::string16& name) {
36 label_->SetText(name); 61 label_->SetText(name);
(...skipping 15 matching lines...) Expand all
52 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) { 77 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
53 if (*i != this) { 78 if (*i != this) {
54 DCHECK_EQ((*i)->GetClassName(), 79 DCHECK_EQ((*i)->GetClassName(),
55 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); 80 DesktopMediaSourceView::kDesktopMediaSourceViewClassName);
56 DesktopMediaSourceView* source_view = 81 DesktopMediaSourceView* source_view =
57 static_cast<DesktopMediaSourceView*>(*i); 82 static_cast<DesktopMediaSourceView*>(*i);
58 source_view->SetSelected(false); 83 source_view->SetSelected(false);
59 } 84 }
60 } 85 }
61 86
87 const SkColor border_color = GetNativeTheme()->GetSystemColor(
88 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
89 image_view_->SetBorder(views::Border::CreateSolidBorder(
90 style_.selection_border_thickness, border_color));
91 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::BOLD));
92 parent_->OnSelectionChanged();
93 } else {
94 image_view_->SetBorder(views::Border::NullBorder());
95 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL));
96 }
97
98 SchedulePaint();
99 }
100
101 void DesktopMediaSourceView::SetHovered(bool hovered) {
102 if (hovered) {
103 // Use background color to show mouse hover.
62 const SkColor bg_color = GetNativeTheme()->GetSystemColor( 104 const SkColor bg_color = GetNativeTheme()->GetSystemColor(
63 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); 105 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor);
64 set_background(views::Background::CreateSolidBackground(bg_color)); 106 set_background(views::Background::CreateSolidBackground(bg_color));
65
66 parent_->OnSelectionChanged();
67 } else { 107 } else {
68 set_background(NULL); 108 set_background(NULL);
69 } 109 }
70 110
71 SchedulePaint(); 111 SchedulePaint();
72 } 112 }
73 113
74 const char* DesktopMediaSourceView::GetClassName() const { 114 const char* DesktopMediaSourceView::GetClassName() const {
75 return DesktopMediaSourceView::kDesktopMediaSourceViewClassName; 115 return DesktopMediaSourceView::kDesktopMediaSourceViewClassName;
76 } 116 }
77 117
78 void DesktopMediaSourceView::Layout() { 118 void DesktopMediaSourceView::Layout() {
79 image_view_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin, 119 image_view_->SetBoundsRect(style_.image_rect);
80 DesktopMediaPickerDialogView::kThumbnailMargin, 120 if (selected_) {
81 DesktopMediaPickerDialogView::kThumbnailWidth, 121 const SkColor border_color = GetNativeTheme()->GetSystemColor(
82 DesktopMediaPickerDialogView::kThumbnailHeight); 122 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
83 label_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin, 123 image_view_->SetBorder(views::Border::CreateSolidBorder(
84 DesktopMediaPickerDialogView::kThumbnailHeight + 124 style_.selection_border_thickness, border_color));
85 DesktopMediaPickerDialogView::kThumbnailMargin, 125 }
86 DesktopMediaPickerDialogView::kThumbnailWidth, 126 label_->SetBoundsRect(style_.label_rect);
87 DesktopMediaPickerDialogView::kLabelHeight); 127 label_->SetHorizontalAlignment(style_.text_alignment);
88 } 128 }
89 129
90 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { 130 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
91 Views neighbours; 131 Views neighbours;
92 parent()->GetViewsInGroup(group, &neighbours); 132 parent()->GetViewsInGroup(group, &neighbours);
93 if (neighbours.empty()) 133 if (neighbours.empty())
94 return NULL; 134 return NULL;
msw 2016/05/26 20:50:33 nit: nullptr here and elsewhere
qiangchen 2016/05/26 21:38:38 Done.
95 135
96 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) { 136 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
97 DCHECK_EQ((*i)->GetClassName(), 137 DCHECK_EQ((*i)->GetClassName(),
98 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); 138 DesktopMediaSourceView::kDesktopMediaSourceViewClassName);
99 DesktopMediaSourceView* source_view = 139 DesktopMediaSourceView* source_view =
100 static_cast<DesktopMediaSourceView*>(*i); 140 static_cast<DesktopMediaSourceView*>(*i);
101 if (source_view->selected_) 141 if (source_view->selected_)
102 return source_view; 142 return source_view;
103 } 143 }
104 return NULL; 144 return NULL;
105 } 145 }
106 146
107 bool DesktopMediaSourceView::IsGroupFocusTraversable() const { 147 bool DesktopMediaSourceView::IsGroupFocusTraversable() const {
108 return false; 148 return false;
109 } 149 }
110 150
111 void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) { 151 void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) {
112 View::OnPaint(canvas); 152 View::OnPaint(canvas);
113 if (HasFocus()) { 153 if (HasFocus()) {
msw 2016/05/26 20:50:33 I'd be nice to avoid overriding paint and change t
qiangchen 2016/05/26 21:38:38 Acknowledged.
114 gfx::Rect bounds(GetLocalBounds()); 154 gfx::Rect bounds(GetLocalBounds());
115 bounds.Inset(DesktopMediaPickerDialogView::kThumbnailMargin / 2, 155 bounds.Inset(style_.focus_rectangle_inset, style_.focus_rectangle_inset);
116 DesktopMediaPickerDialogView::kThumbnailMargin / 2);
117 canvas->DrawFocusRect(bounds); 156 canvas->DrawFocusRect(bounds);
118 } 157 }
119 } 158 }
120 159
121 void DesktopMediaSourceView::OnFocus() { 160 void DesktopMediaSourceView::OnFocus() {
122 View::OnFocus(); 161 View::OnFocus();
123 SetSelected(true); 162 SetSelected(true);
124 ScrollRectToVisible(gfx::Rect(size())); 163 ScrollRectToVisible(gfx::Rect(size()));
125 // We paint differently when focused. 164 // We paint differently when focused.
126 SchedulePaint(); 165 SchedulePaint();
127 } 166 }
128 167
129 void DesktopMediaSourceView::OnBlur() { 168 void DesktopMediaSourceView::OnBlur() {
130 View::OnBlur(); 169 View::OnBlur();
131 // We paint differently when focused. 170 // We paint differently when focused.
132 SchedulePaint(); 171 SchedulePaint();
133 } 172 }
134 173
135 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) { 174 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) {
136 if (event.GetClickCount() == 1) { 175 if (event.GetClickCount() == 1) {
137 RequestFocus(); 176 RequestFocus();
138 } else if (event.GetClickCount() == 2) { 177 } else if (event.GetClickCount() == 2) {
139 RequestFocus(); 178 RequestFocus();
140 parent_->OnDoubleClick(); 179 parent_->OnDoubleClick();
141 } 180 }
142 return true; 181 return true;
143 } 182 }
144 183
184 void DesktopMediaSourceView::OnMouseEntered(const ui::MouseEvent& event) {
185 SetHovered(true);
186 }
187
188 void DesktopMediaSourceView::OnMouseExited(const ui::MouseEvent& event) {
189 SetHovered(false);
190 }
191
145 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) { 192 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) {
146 if (event->type() == ui::ET_GESTURE_TAP && 193 if (event->type() == ui::ET_GESTURE_TAP &&
147 event->details().tap_count() == 2) { 194 event->details().tap_count() == 2) {
148 RequestFocus(); 195 RequestFocus();
149 parent_->OnDoubleClick(); 196 parent_->OnDoubleClick();
150 event->SetHandled(); 197 event->SetHandled();
151 return; 198 return;
152 } 199 }
153 200
154 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused 201 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused
155 // on the long tap (when the tap gesture starts). 202 // on the long tap (when the tap gesture starts).
156 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { 203 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
157 RequestFocus(); 204 RequestFocus();
158 event->SetHandled(); 205 event->SetHandled();
159 } 206 }
160 } 207 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/desktop_capture/desktop_media_source_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698