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

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

Powered by Google App Engine
This is Rietveld 408576698