OLD | NEW |
---|---|
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_list_view.h" | 5 #include "chrome/browser/ui/views/desktop_capture/desktop_media_list_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/media/desktop_media_list.h" | 9 #include "chrome/browser/media/desktop_media_list.h" |
10 #include "chrome/browser/media/window_icon_util.h" | |
10 #include "chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.h" | 11 #include "chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.h" |
11 #include "chrome/browser/ui/views/desktop_capture/desktop_media_source_view.h" | 12 #include "chrome/browser/ui/views/desktop_capture/desktop_media_source_view.h" |
13 #include "chrome/browser/ui/views/frame/browser_view.h" | |
12 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "extensions/grit/extensions_browser_resources.h" | |
17 #include "grit/theme_resources.h" | |
Lei Zhang
2016/08/30 09:39:34
BTW, we are trying to ever-so-slowly get rid of us
qiangchen
2016/08/30 17:10:45
Acknowledged.
| |
14 #include "ui/accessibility/ax_view_state.h" | 18 #include "ui/accessibility/ax_view_state.h" |
19 #include "ui/aura/window.h" | |
20 #include "ui/base/resource/resource_bundle.h" | |
15 #include "ui/views/focus/focus_manager.h" | 21 #include "ui/views/focus/focus_manager.h" |
16 | 22 |
17 using content::DesktopMediaID; | 23 using content::DesktopMediaID; |
18 | 24 |
19 namespace { | 25 namespace { |
20 | 26 |
21 const int kDesktopMediaSourceViewGroupId = 1; | 27 const int kDesktopMediaSourceViewGroupId = 1; |
22 | 28 |
29 #if defined(USE_ASH) | |
30 // Here we are going to display default app icon for app windows without an | |
31 // icon, and display product logo for chrome browser windows. | |
32 gfx::ImageSkia LoadDefaultIcon(aura::Window* window) { | |
33 BrowserView* browser_view = | |
34 BrowserView::GetBrowserViewForNativeWindow(window); | |
35 Browser* browser = browser_view ? browser_view->browser() : nullptr; | |
36 | |
37 // Apps could be launched in a view other than BrowserView, so we count those | |
38 // windows without Browser association as apps. | |
39 // Technically dev tool is actually a special app, but we would like to | |
40 // display product logo for it, because intuitively it is internal to browser. | |
41 bool is_app = !browser || (browser->is_app() && !browser->is_devtools()); | |
42 int idr = is_app ? IDR_APP_DEFAULT_ICON : IDR_PRODUCT_LOGO_32; | |
43 | |
44 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
45 return *rb.GetImageSkiaNamed(idr); | |
46 } | |
47 #endif | |
Lei Zhang
2016/08/30 09:39:34
extra blank line after would be nice to mirror lin
qiangchen
2016/08/30 17:10:45
Thanks. Will fix it next time I touch this file.
| |
23 } // namespace | 48 } // namespace |
24 | 49 |
25 DesktopMediaListView::DesktopMediaListView( | 50 DesktopMediaListView::DesktopMediaListView( |
26 DesktopMediaPickerDialogView* parent, | 51 DesktopMediaPickerDialogView* parent, |
27 std::unique_ptr<DesktopMediaList> media_list, | 52 std::unique_ptr<DesktopMediaList> media_list, |
28 DesktopMediaSourceViewStyle generic_style, | 53 DesktopMediaSourceViewStyle generic_style, |
29 DesktopMediaSourceViewStyle single_style, | 54 DesktopMediaSourceViewStyle single_style, |
30 const base::string16& accessible_name) | 55 const base::string16& accessible_name) |
31 : parent_(parent), | 56 : parent_(parent), |
32 media_list_(std::move(media_list)), | 57 media_list_(std::move(media_list)), |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 169 |
145 // We are going to have a second item, apply the generic style. | 170 // We are going to have a second item, apply the generic style. |
146 if (child_count() == 1) | 171 if (child_count() == 1) |
147 SetStyle(&generic_style_); | 172 SetStyle(&generic_style_); |
148 | 173 |
149 DesktopMediaSourceView* source_view = | 174 DesktopMediaSourceView* source_view = |
150 new DesktopMediaSourceView(this, source.id, *active_style_); | 175 new DesktopMediaSourceView(this, source.id, *active_style_); |
151 | 176 |
152 source_view->SetName(source.name); | 177 source_view->SetName(source.name); |
153 source_view->SetGroup(kDesktopMediaSourceViewGroupId); | 178 source_view->SetGroup(kDesktopMediaSourceViewGroupId); |
179 if (source.id.type == DesktopMediaID::TYPE_WINDOW) { | |
180 gfx::ImageSkia icon_image = GetWindowIcon(source.id); | |
181 #if defined(USE_ASH) | |
182 // Empty icons are used to represent default icon for aura windows. By | |
183 // detecting this, we load the default icon from resource. | |
184 if (icon_image.isNull()) { | |
185 aura::Window* window = DesktopMediaID::GetAuraWindowById(source.id); | |
186 if (window) | |
187 icon_image = LoadDefaultIcon(window); | |
188 } | |
189 #endif | |
190 source_view->SetIcon(icon_image); | |
191 } | |
154 AddChildViewAt(source_view, index); | 192 AddChildViewAt(source_view, index); |
155 | 193 |
156 if ((child_count() - 1) % active_style_->columns == 0) | 194 if ((child_count() - 1) % active_style_->columns == 0) |
157 parent_->OnMediaListRowsChanged(); | 195 parent_->OnMediaListRowsChanged(); |
158 | 196 |
159 // Auto select the first screen. | 197 // Auto select the first screen. |
160 if (index == 0 && source.id.type == DesktopMediaID::TYPE_SCREEN) | 198 if (index == 0 && source.id.type == DesktopMediaID::TYPE_SCREEN) |
161 source_view->RequestFocus(); | 199 source_view->RequestFocus(); |
162 | 200 |
163 PreferredSizeChanged(); | 201 PreferredSizeChanged(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 DesktopMediaSourceView* source_view = | 278 DesktopMediaSourceView* source_view = |
241 static_cast<DesktopMediaSourceView*>(child_at(i)); | 279 static_cast<DesktopMediaSourceView*>(child_at(i)); |
242 source_view->SetStyle(*active_style_); | 280 source_view->SetStyle(*active_style_); |
243 } | 281 } |
244 } | 282 } |
245 | 283 |
246 void DesktopMediaListView::GetAccessibleState(ui::AXViewState* state) { | 284 void DesktopMediaListView::GetAccessibleState(ui::AXViewState* state) { |
247 state->role = ui::AX_ROLE_GROUP; | 285 state->role = ui::AX_ROLE_GROUP; |
248 state->name = accessible_name_; | 286 state->name = accessible_name_; |
249 } | 287 } |
OLD | NEW |