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

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);
27 SetFocusBehavior(FocusBehavior::ALWAYS); 51 SetFocusBehavior(FocusBehavior::ALWAYS);
52 SetStyle(style_);
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);
37 } 62 }
(...skipping 14 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
62 const SkColor bg_color = GetNativeTheme()->GetSystemColor( 87 const SkColor border_color = GetNativeTheme()->GetSystemColor(
63 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); 88 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
64 set_background(views::Background::CreateSolidBackground(bg_color)); 89 image_view_->SetBorder(views::Border::CreateSolidBorder(
65 90 style_.selection_border_thickness, border_color));
91 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::BOLD));
66 parent_->OnSelectionChanged(); 92 parent_->OnSelectionChanged();
67 } else { 93 } else {
68 set_background(NULL); 94 image_view_->SetBorder(views::Border::NullBorder());
95 label_->SetFontList(label_->font_list().Derive(0, gfx::Font::NORMAL));
69 } 96 }
70 97
71 SchedulePaint(); 98 SchedulePaint();
99 }
100
101 void DesktopMediaSourceView::SetHovered(bool hovered) {
102 if (hovered) {
103 // Use background color to show mouse hover.
104 const SkColor bg_color = GetNativeTheme()->GetSystemColor(
105 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor);
106 set_background(views::Background::CreateSolidBackground(bg_color));
107 } else {
108 set_background(nullptr);
109 }
110
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::SetStyle(DesktopMediaSourceViewStyle style) {
79 image_view_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin, 119 style_ = style;
80 DesktopMediaPickerDialogView::kThumbnailMargin, 120 image_view_->SetBoundsRect(style_.image_rect);
81 DesktopMediaPickerDialogView::kThumbnailWidth, 121 if (selected_) {
82 DesktopMediaPickerDialogView::kThumbnailHeight); 122 const SkColor border_color = GetNativeTheme()->GetSystemColor(
83 label_->SetBounds(DesktopMediaPickerDialogView::kThumbnailMargin, 123 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
84 DesktopMediaPickerDialogView::kThumbnailHeight + 124 image_view_->SetBorder(views::Border::CreateSolidBorder(
85 DesktopMediaPickerDialogView::kThumbnailMargin, 125 style_.selection_border_thickness, border_color));
86 DesktopMediaPickerDialogView::kThumbnailWidth, 126 }
87 DesktopMediaPickerDialogView::kLabelHeight); 127 label_->SetBoundsRect(style_.label_rect);
128 label_->SetHorizontalAlignment(style_.text_alignment);
88 } 129 }
89 130
90 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) { 131 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
91 Views neighbours; 132 Views neighbours;
92 parent()->GetViewsInGroup(group, &neighbours); 133 parent()->GetViewsInGroup(group, &neighbours);
93 if (neighbours.empty()) 134 if (neighbours.empty())
94 return NULL; 135 return nullptr;
95 136
96 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) { 137 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
97 DCHECK_EQ((*i)->GetClassName(), 138 DCHECK_EQ((*i)->GetClassName(),
98 DesktopMediaSourceView::kDesktopMediaSourceViewClassName); 139 DesktopMediaSourceView::kDesktopMediaSourceViewClassName);
99 DesktopMediaSourceView* source_view = 140 DesktopMediaSourceView* source_view =
100 static_cast<DesktopMediaSourceView*>(*i); 141 static_cast<DesktopMediaSourceView*>(*i);
101 if (source_view->selected_) 142 if (source_view->selected_)
102 return source_view; 143 return source_view;
103 } 144 }
104 return NULL; 145 return nullptr;
105 } 146 }
106 147
107 bool DesktopMediaSourceView::IsGroupFocusTraversable() const { 148 bool DesktopMediaSourceView::IsGroupFocusTraversable() const {
108 return false; 149 return false;
109 } 150 }
110 151
111 void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) { 152 void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) {
112 View::OnPaint(canvas); 153 View::OnPaint(canvas);
113 if (HasFocus()) { 154 if (HasFocus()) {
114 gfx::Rect bounds(GetLocalBounds()); 155 gfx::Rect bounds(GetLocalBounds());
115 bounds.Inset(DesktopMediaPickerDialogView::kThumbnailMargin / 2, 156 bounds.Inset(style_.focus_rectangle_inset, style_.focus_rectangle_inset);
116 DesktopMediaPickerDialogView::kThumbnailMargin / 2);
117 canvas->DrawFocusRect(bounds); 157 canvas->DrawFocusRect(bounds);
118 } 158 }
119 } 159 }
120 160
121 void DesktopMediaSourceView::OnFocus() { 161 void DesktopMediaSourceView::OnFocus() {
122 View::OnFocus(); 162 View::OnFocus();
123 SetSelected(true); 163 SetSelected(true);
124 ScrollRectToVisible(gfx::Rect(size())); 164 ScrollRectToVisible(gfx::Rect(size()));
125 // We paint differently when focused. 165 // We paint differently when focused.
126 SchedulePaint(); 166 SchedulePaint();
127 } 167 }
128 168
129 void DesktopMediaSourceView::OnBlur() { 169 void DesktopMediaSourceView::OnBlur() {
130 View::OnBlur(); 170 View::OnBlur();
131 // We paint differently when focused. 171 // We paint differently when focused.
132 SchedulePaint(); 172 SchedulePaint();
133 } 173 }
134 174
135 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) { 175 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) {
136 if (event.GetClickCount() == 1) { 176 if (event.GetClickCount() == 1) {
137 RequestFocus(); 177 RequestFocus();
138 } else if (event.GetClickCount() == 2) { 178 } else if (event.GetClickCount() == 2) {
139 RequestFocus(); 179 RequestFocus();
140 parent_->OnDoubleClick(); 180 parent_->OnDoubleClick();
141 } 181 }
142 return true; 182 return true;
143 } 183 }
144 184
185 void DesktopMediaSourceView::OnMouseEntered(const ui::MouseEvent& event) {
186 SetHovered(true);
187 }
188
189 void DesktopMediaSourceView::OnMouseExited(const ui::MouseEvent& event) {
190 SetHovered(false);
191 }
192
145 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) { 193 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) {
146 if (event->type() == ui::ET_GESTURE_TAP && 194 if (event->type() == ui::ET_GESTURE_TAP &&
147 event->details().tap_count() == 2) { 195 event->details().tap_count() == 2) {
148 RequestFocus(); 196 RequestFocus();
149 parent_->OnDoubleClick(); 197 parent_->OnDoubleClick();
150 event->SetHandled(); 198 event->SetHandled();
151 return; 199 return;
152 } 200 }
153 201
154 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused 202 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused
155 // on the long tap (when the tap gesture starts). 203 // on the long tap (when the tap gesture starts).
156 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { 204 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
157 RequestFocus(); 205 RequestFocus();
158 event->SetHandled(); 206 event->SetHandled();
159 } 207 }
160 } 208 }
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