OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_media_picker_views.h" | 5 #include "chrome/browser/ui/views/desktop_media_picker_views.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | |
9 #include "base/strings/utf_string_conversions.h" | |
8 #include "chrome/browser/media/desktop_media_list.h" | 10 #include "chrome/browser/media/desktop_media_list.h" |
9 #include "chrome/browser/ui/ash/ash_util.h" | 11 #include "chrome/browser/ui/ash/ash_util.h" |
10 #include "chrome/browser/ui/views/constrained_window_views.h" | 12 #include "chrome/browser/ui/views/constrained_window_views.h" |
13 #include "chrome/common/chrome_switches.h" | |
11 #include "components/web_modal/popup_manager.h" | 14 #include "components/web_modal/popup_manager.h" |
15 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
12 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
13 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
14 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
15 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/events/event_constants.h" | 20 #include "ui/events/event_constants.h" |
17 #include "ui/events/keycodes/keyboard_codes.h" | 21 #include "ui/events/keycodes/keyboard_codes.h" |
18 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
19 #include "ui/native_theme/native_theme.h" | 23 #include "ui/native_theme/native_theme.h" |
20 #include "ui/views/background.h" | 24 #include "ui/views/background.h" |
21 #include "ui/views/bubble/bubble_frame_view.h" | 25 #include "ui/views/bubble/bubble_frame_view.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
52 return reinterpret_cast<DesktopMediaID::Id>(accelerated_widget); | 56 return reinterpret_cast<DesktopMediaID::Id>(accelerated_widget); |
53 #else | 57 #else |
54 return static_cast<DesktopMediaID::Id>(accelerated_widget); | 58 return static_cast<DesktopMediaID::Id>(accelerated_widget); |
55 #endif | 59 #endif |
56 } | 60 } |
57 | 61 |
58 int GetMediaListViewHeightForRows(size_t rows) { | 62 int GetMediaListViewHeightForRows(size_t rows) { |
59 return kListItemHeight * rows; | 63 return kListItemHeight * rows; |
60 } | 64 } |
61 | 65 |
66 static bool ShouldAutoSelectSource(const DesktopMediaList::Source& source) { | |
Peter Kasting
2014/08/13 17:17:50
Nit: "static" unnecessary (you're already in an an
phoglund_chromium
2014/08/14 13:16:24
Done. Inlining worked out pretty nicely with your
| |
67 std::string desired_source = | |
68 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
69 switches::kAutoSelectDesktopCaptureSource); | |
70 if (desired_source.empty()) | |
71 return false; | |
72 | |
73 return desired_source == base::UTF16ToASCII(source.name); | |
Peter Kasting
2014/08/13 17:17:50
Nit: Shorter:
return !desired_source.empty() &&
phoglund_chromium
2014/08/14 13:16:24
Done.
| |
74 } | |
75 | |
76 class AutoSelectTask: public base::RefCounted<AutoSelectTask> { | |
Peter Kasting
2014/08/13 17:17:50
Does this really need to be refcounted? Seems lik
phoglund_chromium
2014/08/14 13:16:24
Nope, went with jiayl's solution instead.
| |
77 public: | |
78 explicit AutoSelectTask(const base::WeakPtr<DesktopMediaListView>& list_view) | |
79 : list_view_(list_view) {} | |
80 | |
81 void AcceptSelectedSource() { | |
82 if (list_view_) { | |
83 list_view_->OnSelectionChanged(); | |
84 list_view_->OnDoubleClick(); | |
85 } | |
86 } | |
87 | |
88 private: | |
89 friend class base::RefCounted<AutoSelectTask>; | |
90 ~AutoSelectTask() {} | |
91 | |
92 base::WeakPtr<DesktopMediaListView> list_view_; | |
93 }; | |
Peter Kasting
2014/08/13 17:17:50
Nit: DISALLOW_COPY_AND_ASSIGN
phoglund_chromium
2014/08/14 13:16:24
Acknowledged.
| |
94 | |
62 } // namespace | 95 } // namespace |
63 | 96 |
64 DesktopMediaSourceView::DesktopMediaSourceView( | 97 DesktopMediaSourceView::DesktopMediaSourceView( |
65 DesktopMediaListView* parent, | 98 DesktopMediaListView* parent, |
66 DesktopMediaID source_id) | 99 DesktopMediaID source_id) |
67 : parent_(parent), | 100 : parent_(parent), |
68 source_id_(source_id), | 101 source_id_(source_id), |
69 image_view_(new views::ImageView()), | 102 image_view_(new views::ImageView()), |
70 label_(new views::Label()), | 103 label_(new views::Label()), |
71 selected_(false) { | 104 selected_(false) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 225 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
193 RequestFocus(); | 226 RequestFocus(); |
194 event->SetHandled(); | 227 event->SetHandled(); |
195 } | 228 } |
196 } | 229 } |
197 | 230 |
198 DesktopMediaListView::DesktopMediaListView( | 231 DesktopMediaListView::DesktopMediaListView( |
199 DesktopMediaPickerDialogView* parent, | 232 DesktopMediaPickerDialogView* parent, |
200 scoped_ptr<DesktopMediaList> media_list) | 233 scoped_ptr<DesktopMediaList> media_list) |
201 : parent_(parent), | 234 : parent_(parent), |
202 media_list_(media_list.Pass()) { | 235 media_list_(media_list.Pass()), |
236 weak_factory_(this) { | |
203 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight)); | 237 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight)); |
204 } | 238 } |
205 | 239 |
206 DesktopMediaListView::~DesktopMediaListView() {} | 240 DesktopMediaListView::~DesktopMediaListView() {} |
207 | 241 |
208 void DesktopMediaListView::StartUpdating(DesktopMediaID::Id dialog_window_id) { | 242 void DesktopMediaListView::StartUpdating(DesktopMediaID::Id dialog_window_id) { |
209 media_list_->SetViewDialogWindowId(dialog_window_id); | 243 media_list_->SetViewDialogWindowId(dialog_window_id); |
210 media_list_->StartUpdating(this); | 244 media_list_->StartUpdating(this); |
211 } | 245 } |
212 | 246 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 DesktopMediaSourceView* source_view = | 341 DesktopMediaSourceView* source_view = |
308 new DesktopMediaSourceView(this, source.id); | 342 new DesktopMediaSourceView(this, source.id); |
309 source_view->SetName(source.name); | 343 source_view->SetName(source.name); |
310 source_view->SetGroup(kDesktopMediaSourceViewGroupId); | 344 source_view->SetGroup(kDesktopMediaSourceViewGroupId); |
311 AddChildViewAt(source_view, index); | 345 AddChildViewAt(source_view, index); |
312 | 346 |
313 PreferredSizeChanged(); | 347 PreferredSizeChanged(); |
314 | 348 |
315 if (child_count() % kListColumns == 1) | 349 if (child_count() % kListColumns == 1) |
316 parent_->OnMediaListRowsChanged(); | 350 parent_->OnMediaListRowsChanged(); |
351 | |
352 if (ShouldAutoSelectSource(source)) { | |
353 // Focusing on the element will select it. | |
354 source_view->OnFocus(); | |
355 | |
356 // Accept and close the dialog when we're done adding sources. | |
357 scoped_refptr<AutoSelectTask> task( | |
358 new AutoSelectTask(weak_factory_.GetWeakPtr())); | |
359 content::BrowserThread::PostTask( | |
360 content::BrowserThread::UI, FROM_HERE, | |
361 base::Bind(&AutoSelectTask::AcceptSelectedSource, task)); | |
jiayl
2014/08/13 17:32:42
AutoSelectTask is not needed.
You can just do
Pos
phoglund_chromium
2014/08/14 13:16:24
So PostTask is smart enough to check the weak poin
| |
362 } | |
317 } | 363 } |
318 | 364 |
319 void DesktopMediaListView::OnSourceRemoved(int index) { | 365 void DesktopMediaListView::OnSourceRemoved(int index) { |
320 DesktopMediaSourceView* view = | 366 DesktopMediaSourceView* view = |
321 static_cast<DesktopMediaSourceView*>(child_at(index)); | 367 static_cast<DesktopMediaSourceView*>(child_at(index)); |
322 DCHECK(view); | 368 DCHECK(view); |
323 DCHECK_EQ(view->GetClassName(), kDesktopMediaSourceViewClassName); | 369 DCHECK_EQ(view->GetClassName(), kDesktopMediaSourceViewClassName); |
324 bool was_selected = view->is_selected(); | 370 bool was_selected = view->is_selected(); |
325 RemoveChildView(view); | 371 RemoveChildView(view); |
326 delete view; | 372 delete view; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 content::BrowserThread::PostTask( | 617 content::BrowserThread::PostTask( |
572 content::BrowserThread::UI, FROM_HERE, | 618 content::BrowserThread::UI, FROM_HERE, |
573 base::Bind(callback_, source)); | 619 base::Bind(callback_, source)); |
574 callback_.Reset(); | 620 callback_.Reset(); |
575 } | 621 } |
576 | 622 |
577 // static | 623 // static |
578 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 624 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
579 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 625 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
580 } | 626 } |
OLD | NEW |