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" | |
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(OS_CHROMEOS) | |
30 // As aura framework uses empty icon to represent default icon, it relies on | |
31 // the caller to handle the case. | |
32 // Here we are going to display default app icon for app windows without an | |
33 // icon, and display product logo for chrome browser windows. | |
34 gfx::ImageSkia LoadDefaultIcon(aura::Window* window) { | |
35 BrowserView* browser_view = | |
36 BrowserView::GetBrowserViewForNativeWindow(window); | |
37 Browser* browser = browser_view ? browser_view->browser() : nullptr; | |
38 | |
39 // Apps could be launched in a view other than BrowserView, so we count those | |
40 // windows without Browser association as apps. | |
41 // Technically dev tool is actually a special app, but we would like to | |
42 // display product logo for it, because intuitively it is internal to browser. | |
43 bool is_app = browser ? browser->is_app() && !browser->is_devtools() : true; | |
44 int idr = is_app ? IDR_APP_DEFAULT_ICON : IDR_PRODUCT_LOGO_32; | |
45 | |
46 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
47 return *rb.GetImageSkiaNamed(idr); | |
48 } | |
49 #endif | |
23 } // namespace | 50 } // namespace |
24 | 51 |
25 DesktopMediaListView::DesktopMediaListView( | 52 DesktopMediaListView::DesktopMediaListView( |
26 DesktopMediaPickerDialogView* parent, | 53 DesktopMediaPickerDialogView* parent, |
27 std::unique_ptr<DesktopMediaList> media_list, | 54 std::unique_ptr<DesktopMediaList> media_list, |
28 DesktopMediaSourceViewStyle generic_style, | 55 DesktopMediaSourceViewStyle generic_style, |
29 DesktopMediaSourceViewStyle single_style, | 56 DesktopMediaSourceViewStyle single_style, |
30 const base::string16& accessible_name) | 57 const base::string16& accessible_name) |
31 : parent_(parent), | 58 : parent_(parent), |
32 media_list_(std::move(media_list)), | 59 media_list_(std::move(media_list)), |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 171 |
145 // We are going to have a second item, apply the generic style. | 172 // We are going to have a second item, apply the generic style. |
146 if (child_count() == 1) | 173 if (child_count() == 1) |
147 SetStyle(&generic_style_); | 174 SetStyle(&generic_style_); |
148 | 175 |
149 DesktopMediaSourceView* source_view = | 176 DesktopMediaSourceView* source_view = |
150 new DesktopMediaSourceView(this, source.id, *active_style_); | 177 new DesktopMediaSourceView(this, source.id, *active_style_); |
151 | 178 |
152 source_view->SetName(source.name); | 179 source_view->SetName(source.name); |
153 source_view->SetGroup(kDesktopMediaSourceViewGroupId); | 180 source_view->SetGroup(kDesktopMediaSourceViewGroupId); |
181 if (source.id.type == DesktopMediaID::TYPE_WINDOW) { | |
182 gfx::ImageSkia icon_image = GetWindowIcon(source.id); | |
183 #if defined(OS_CHROMEOS) | |
184 if (icon_image.isNull()) { | |
185 aura::Window* window = DesktopMediaID::GetAuraWindowById(source.id); | |
186 if (window) icon_image = LoadDefaultIcon(window); | |
Daniel Erat
2016/08/25 23:39:58
please see the style guide. the body should be on
qiangchen
2016/08/25 23:54:19
Done.
| |
187 } | |
188 #endif | |
189 source_view->SetIcon(icon_image); | |
190 } | |
154 AddChildViewAt(source_view, index); | 191 AddChildViewAt(source_view, index); |
155 | 192 |
156 if ((child_count() - 1) % active_style_->columns == 0) | 193 if ((child_count() - 1) % active_style_->columns == 0) |
157 parent_->OnMediaListRowsChanged(); | 194 parent_->OnMediaListRowsChanged(); |
158 | 195 |
159 // Auto select the first screen. | 196 // Auto select the first screen. |
160 if (index == 0 && source.id.type == DesktopMediaID::TYPE_SCREEN) | 197 if (index == 0 && source.id.type == DesktopMediaID::TYPE_SCREEN) |
161 source_view->RequestFocus(); | 198 source_view->RequestFocus(); |
162 | 199 |
163 PreferredSizeChanged(); | 200 PreferredSizeChanged(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 DesktopMediaSourceView* source_view = | 277 DesktopMediaSourceView* source_view = |
241 static_cast<DesktopMediaSourceView*>(child_at(i)); | 278 static_cast<DesktopMediaSourceView*>(child_at(i)); |
242 source_view->SetStyle(*active_style_); | 279 source_view->SetStyle(*active_style_); |
243 } | 280 } |
244 } | 281 } |
245 | 282 |
246 void DesktopMediaListView::GetAccessibleState(ui::AXViewState* state) { | 283 void DesktopMediaListView::GetAccessibleState(ui::AXViewState* state) { |
247 state->role = ui::AX_ROLE_GROUP; | 284 state->role = ui::AX_ROLE_GROUP; |
248 state->name = accessible_name_; | 285 state->name = accessible_name_; |
249 } | 286 } |
OLD | NEW |