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

Side by Side Diff: chrome/browser/ui/views/desktop_media_picker_views.cc

Issue 1962073002: Desktop Capture Picker New UI: Non Mac Structure Change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Unittest Crash 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/desktop_media_picker_views.h"
6
7 #include <stddef.h>
8 #include <utility>
9
10 #include "base/callback.h"
11 #include "base/command_line.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h"
14 #include "chrome/browser/media/combined_desktop_media_list.h"
15 #include "chrome/browser/media/desktop_media_list.h"
16 #include "chrome/browser/ui/ash/ash_util.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/grit/generated_resources.h"
19 #include "components/constrained_window/constrained_window_views.h"
20 #include "components/web_modal/web_contents_modal_dialog_manager.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/web_contents_delegate.h"
24 #include "grit/components_strings.h"
25 #include "ui/aura/window_tree_host.h"
26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/events/event_constants.h"
28 #include "ui/events/keycodes/keyboard_codes.h"
29 #include "ui/gfx/canvas.h"
30 #include "ui/native_theme/native_theme.h"
31 #include "ui/views/background.h"
32 #include "ui/views/bubble/bubble_frame_view.h"
33 #include "ui/views/controls/button/checkbox.h"
34 #include "ui/views/controls/image_view.h"
35 #include "ui/views/controls/label.h"
36 #include "ui/views/controls/scroll_view.h"
37 #include "ui/views/layout/box_layout.h"
38 #include "ui/views/layout/layout_constants.h"
39 #include "ui/views/widget/widget.h"
40 #include "ui/views/window/dialog_client_view.h"
41 #include "ui/wm/core/shadow_types.h"
42
43 using content::DesktopMediaID;
44
45 namespace {
46
47 const int kThumbnailWidth = 160;
48 const int kThumbnailHeight = 100;
49 const int kThumbnailMargin = 10;
50 const int kLabelHeight = 40;
51 const int kListItemWidth = kThumbnailMargin * 2 + kThumbnailWidth;
52 const int kListItemHeight =
53 kThumbnailMargin * 2 + kThumbnailHeight + kLabelHeight;
54 const int kListColumns = 3;
55 const int kTotalListWidth = kListColumns * kListItemWidth;
56
57 const int kDesktopMediaSourceViewGroupId = 1;
58
59 const char kDesktopMediaSourceViewClassName[] =
60 "DesktopMediaPicker_DesktopMediaSourceView";
61
62 DesktopMediaID::Id AcceleratedWidgetToDesktopMediaId(
63 gfx::AcceleratedWidget accelerated_widget) {
64 #if defined(OS_WIN)
65 return reinterpret_cast<DesktopMediaID::Id>(accelerated_widget);
66 #else
67 return static_cast<DesktopMediaID::Id>(accelerated_widget);
68 #endif
69 }
70
71 int GetMediaListViewHeightForRows(size_t rows) {
72 return kListItemHeight * rows;
73 }
74
75 } // namespace
76
77 DesktopMediaSourceView::DesktopMediaSourceView(
78 DesktopMediaListView* parent,
79 DesktopMediaID source_id)
80 : parent_(parent),
81 source_id_(source_id),
82 image_view_(new views::ImageView()),
83 label_(new views::Label()),
84 selected_(false) {
85 AddChildView(image_view_);
86 AddChildView(label_);
87 SetFocusBehavior(FocusBehavior::ALWAYS);
88 }
89
90 DesktopMediaSourceView::~DesktopMediaSourceView() {}
91
92 void DesktopMediaSourceView::SetName(const base::string16& name) {
93 label_->SetText(name);
94 }
95
96 void DesktopMediaSourceView::SetThumbnail(const gfx::ImageSkia& thumbnail) {
97 image_view_->SetImage(thumbnail);
98 }
99
100 void DesktopMediaSourceView::SetSelected(bool selected) {
101 if (selected == selected_)
102 return;
103 selected_ = selected;
104
105 if (selected) {
106 // Unselect all other sources.
107 Views neighbours;
108 parent()->GetViewsInGroup(GetGroup(), &neighbours);
109 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
110 if (*i != this) {
111 DCHECK_EQ((*i)->GetClassName(), kDesktopMediaSourceViewClassName);
112 DesktopMediaSourceView* source_view =
113 static_cast<DesktopMediaSourceView*>(*i);
114 source_view->SetSelected(false);
115 }
116 }
117
118 const SkColor bg_color = GetNativeTheme()->GetSystemColor(
119 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
120 set_background(views::Background::CreateSolidBackground(bg_color));
121
122 parent_->OnSelectionChanged();
123 } else {
124 set_background(NULL);
125 }
126
127 SchedulePaint();
128 }
129
130 const char* DesktopMediaSourceView::GetClassName() const {
131 return kDesktopMediaSourceViewClassName;
132 }
133
134 void DesktopMediaSourceView::Layout() {
135 image_view_->SetBounds(kThumbnailMargin, kThumbnailMargin,
136 kThumbnailWidth, kThumbnailHeight);
137 label_->SetBounds(kThumbnailMargin, kThumbnailHeight + kThumbnailMargin,
138 kThumbnailWidth, kLabelHeight);
139 }
140
141 views::View* DesktopMediaSourceView::GetSelectedViewForGroup(int group) {
142 Views neighbours;
143 parent()->GetViewsInGroup(group, &neighbours);
144 if (neighbours.empty())
145 return NULL;
146
147 for (Views::iterator i(neighbours.begin()); i != neighbours.end(); ++i) {
148 DCHECK_EQ((*i)->GetClassName(), kDesktopMediaSourceViewClassName);
149 DesktopMediaSourceView* source_view =
150 static_cast<DesktopMediaSourceView*>(*i);
151 if (source_view->selected_)
152 return source_view;
153 }
154 return NULL;
155 }
156
157 bool DesktopMediaSourceView::IsGroupFocusTraversable() const {
158 return false;
159 }
160
161 void DesktopMediaSourceView::OnPaint(gfx::Canvas* canvas) {
162 View::OnPaint(canvas);
163 if (HasFocus()) {
164 gfx::Rect bounds(GetLocalBounds());
165 bounds.Inset(kThumbnailMargin / 2, kThumbnailMargin / 2);
166 canvas->DrawFocusRect(bounds);
167 }
168 }
169
170 void DesktopMediaSourceView::OnFocus() {
171 View::OnFocus();
172 SetSelected(true);
173 ScrollRectToVisible(gfx::Rect(size()));
174 // We paint differently when focused.
175 SchedulePaint();
176 }
177
178 void DesktopMediaSourceView::OnBlur() {
179 View::OnBlur();
180 // We paint differently when focused.
181 SchedulePaint();
182 }
183
184 bool DesktopMediaSourceView::OnMousePressed(const ui::MouseEvent& event) {
185 if (event.GetClickCount() == 1) {
186 RequestFocus();
187 } else if (event.GetClickCount() == 2) {
188 RequestFocus();
189 parent_->OnDoubleClick();
190 }
191 return true;
192 }
193
194 void DesktopMediaSourceView::OnGestureEvent(ui::GestureEvent* event) {
195 if (event->type() == ui::ET_GESTURE_TAP &&
196 event->details().tap_count() == 2) {
197 RequestFocus();
198 parent_->OnDoubleClick();
199 event->SetHandled();
200 return;
201 }
202
203 // Detect tap gesture using ET_GESTURE_TAP_DOWN so the view also gets focused
204 // on the long tap (when the tap gesture starts).
205 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
206 RequestFocus();
207 event->SetHandled();
208 }
209 }
210
211 DesktopMediaListView::DesktopMediaListView(
212 DesktopMediaPickerDialogView* parent,
213 std::unique_ptr<DesktopMediaList> media_list)
214 : parent_(parent), media_list_(std::move(media_list)), weak_factory_(this) {
215 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight));
216 SetFocusBehavior(FocusBehavior::ALWAYS);
217 }
218
219 DesktopMediaListView::~DesktopMediaListView() {}
220
221 void DesktopMediaListView::StartUpdating(DesktopMediaID dialog_window_id) {
222 media_list_->SetViewDialogWindowId(dialog_window_id);
223 media_list_->StartUpdating(this);
224 }
225
226 void DesktopMediaListView::OnSelectionChanged() {
227 parent_->OnSelectionChanged();
228 }
229
230 void DesktopMediaListView::OnDoubleClick() {
231 parent_->OnDoubleClick();
232 }
233
234 DesktopMediaSourceView* DesktopMediaListView::GetSelection() {
235 for (int i = 0; i < child_count(); ++i) {
236 DesktopMediaSourceView* source_view =
237 static_cast<DesktopMediaSourceView*>(child_at(i));
238 DCHECK_EQ(source_view->GetClassName(), kDesktopMediaSourceViewClassName);
239 if (source_view->is_selected())
240 return source_view;
241 }
242 return NULL;
243 }
244
245 gfx::Size DesktopMediaListView::GetPreferredSize() const {
246 int total_rows = (child_count() + kListColumns - 1) / kListColumns;
247 return gfx::Size(kTotalListWidth, GetMediaListViewHeightForRows(total_rows));
248 }
249
250 void DesktopMediaListView::Layout() {
251 int x = 0;
252 int y = 0;
253
254 for (int i = 0; i < child_count(); ++i) {
255 if (x + kListItemWidth > kTotalListWidth) {
256 x = 0;
257 y += kListItemHeight;
258 }
259
260 View* source_view = child_at(i);
261 source_view->SetBounds(x, y, kListItemWidth, kListItemHeight);
262
263 x += kListItemWidth;
264 }
265
266 y += kListItemHeight;
267 SetSize(gfx::Size(kTotalListWidth, y));
268 }
269
270 bool DesktopMediaListView::OnKeyPressed(const ui::KeyEvent& event) {
271 int position_increment = 0;
272 switch (event.key_code()) {
273 case ui::VKEY_UP:
274 position_increment = -kListColumns;
275 break;
276 case ui::VKEY_DOWN:
277 position_increment = kListColumns;
278 break;
279 case ui::VKEY_LEFT:
280 position_increment = -1;
281 break;
282 case ui::VKEY_RIGHT:
283 position_increment = 1;
284 break;
285 default:
286 return false;
287 }
288
289 if (position_increment != 0) {
290 DesktopMediaSourceView* selected = GetSelection();
291 DesktopMediaSourceView* new_selected = NULL;
292
293 if (selected) {
294 int index = GetIndexOf(selected);
295 int new_index = index + position_increment;
296 if (new_index >= child_count())
297 new_index = child_count() - 1;
298 else if (new_index < 0)
299 new_index = 0;
300 if (index != new_index) {
301 new_selected =
302 static_cast<DesktopMediaSourceView*>(child_at(new_index));
303 }
304 } else if (has_children()) {
305 new_selected = static_cast<DesktopMediaSourceView*>(child_at(0));
306 }
307
308 if (new_selected) {
309 GetFocusManager()->SetFocusedView(new_selected);
310 }
311
312 return true;
313 }
314
315 return false;
316 }
317
318 void DesktopMediaListView::OnSourceAdded(DesktopMediaList* list, int index) {
319 const DesktopMediaList::Source& source = media_list_->GetSource(index);
320 DesktopMediaSourceView* source_view =
321 new DesktopMediaSourceView(this, source.id);
322 source_view->SetName(source.name);
323 source_view->SetGroup(kDesktopMediaSourceViewGroupId);
324 AddChildViewAt(source_view, index);
325
326 PreferredSizeChanged();
327
328 if (child_count() % kListColumns == 1)
329 parent_->OnMediaListRowsChanged();
330
331 std::string autoselect_source =
332 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
333 switches::kAutoSelectDesktopCaptureSource);
334 if (!autoselect_source.empty() &&
335 base::ASCIIToUTF16(autoselect_source) == source.name) {
336 // Select, then accept and close the dialog when we're done adding sources.
337 source_view->OnFocus();
338 content::BrowserThread::PostTask(
339 content::BrowserThread::UI, FROM_HERE,
340 base::Bind(&DesktopMediaListView::AcceptSelection,
341 weak_factory_.GetWeakPtr()));
342 }
343 }
344
345 void DesktopMediaListView::OnSourceRemoved(DesktopMediaList* list, int index) {
346 DesktopMediaSourceView* view =
347 static_cast<DesktopMediaSourceView*>(child_at(index));
348 DCHECK(view);
349 DCHECK_EQ(view->GetClassName(), kDesktopMediaSourceViewClassName);
350 bool was_selected = view->is_selected();
351 RemoveChildView(view);
352 delete view;
353
354 if (was_selected)
355 OnSelectionChanged();
356
357 PreferredSizeChanged();
358
359 if (child_count() % kListColumns == 0)
360 parent_->OnMediaListRowsChanged();
361 }
362
363 void DesktopMediaListView::OnSourceMoved(DesktopMediaList* list,
364 int old_index,
365 int new_index) {
366 DesktopMediaSourceView* view =
367 static_cast<DesktopMediaSourceView*>(child_at(old_index));
368 ReorderChildView(view, new_index);
369 PreferredSizeChanged();
370 }
371
372 void DesktopMediaListView::OnSourceNameChanged(DesktopMediaList* list,
373 int index) {
374 const DesktopMediaList::Source& source = media_list_->GetSource(index);
375 DesktopMediaSourceView* source_view =
376 static_cast<DesktopMediaSourceView*>(child_at(index));
377 source_view->SetName(source.name);
378 }
379
380 void DesktopMediaListView::OnSourceThumbnailChanged(DesktopMediaList* list,
381 int index) {
382 const DesktopMediaList::Source& source = media_list_->GetSource(index);
383 DesktopMediaSourceView* source_view =
384 static_cast<DesktopMediaSourceView*>(child_at(index));
385 source_view->SetThumbnail(source.thumbnail);
386 }
387
388 void DesktopMediaListView::AcceptSelection() {
389 OnSelectionChanged();
390 OnDoubleClick();
391 }
392
393 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
394 content::WebContents* parent_web_contents,
395 gfx::NativeWindow context,
396 DesktopMediaPickerViews* parent,
397 const base::string16& app_name,
398 const base::string16& target_name,
399 std::unique_ptr<DesktopMediaList> screen_list,
400 std::unique_ptr<DesktopMediaList> window_list,
401 std::unique_ptr<DesktopMediaList> tab_list,
402 bool request_audio)
403 : parent_(parent),
404 app_name_(app_name),
405 description_label_(new views::Label()),
406 audio_share_checkbox_(nullptr),
407 audio_share_checked_(true),
408 sources_scroll_view_(views::ScrollView::CreateScrollViewWithBorder()) {
409 std::vector<std::unique_ptr<DesktopMediaList>> media_lists;
410 if (screen_list)
411 media_lists.push_back(std::move(screen_list));
412 if (window_list)
413 media_lists.push_back(std::move(window_list));
414 if (tab_list)
415 media_lists.push_back(std::move(tab_list));
416
417 std::unique_ptr<DesktopMediaList> media_list;
418 if (media_lists.size() > 1)
419 media_list.reset(new CombinedDesktopMediaList(media_lists));
420 else
421 media_list = std::move(media_lists[0]);
422
423 DCHECK(media_list != nullptr);
424 sources_list_view_ = new DesktopMediaListView(this, std::move(media_list));
425
426 // TODO(estade): we should be getting the inside-border spacing by default as
427 // a DialogDelegateView subclass, via default BubbleFrameView content margins.
428 SetLayoutManager(new views::BoxLayout(
429 views::BoxLayout::kVertical, views::kButtonHEdgeMarginNew,
430 views::kPanelVertMargin, views::kLabelToControlVerticalSpacing));
431
432 if (app_name == target_name) {
433 description_label_->SetText(
434 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name));
435 } else {
436 description_label_->SetText(l10n_util::GetStringFUTF16(
437 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name));
438 }
439 description_label_->SetMultiLine(true);
440 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
441 AddChildView(description_label_);
442
443 sources_scroll_view_->SetContents(sources_list_view_);
444 sources_scroll_view_->ClipHeightTo(GetMediaListViewHeightForRows(1),
445 GetMediaListViewHeightForRows(2));
446 AddChildView(sources_scroll_view_);
447
448 if (request_audio) {
449 audio_share_checkbox_ = new views::Checkbox(
450 l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE));
451 AddChildView(audio_share_checkbox_);
452 audio_share_checkbox_->SetEnabled(false);
453 audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
454 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_NONE));
455 }
456
457 // If |parent_web_contents| is set and it's not a background page then the
458 // picker will be shown modal to the web contents. Otherwise the picker is
459 // shown in a separate window.
460 views::Widget* widget = NULL;
461 bool modal_dialog =
462 parent_web_contents &&
463 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents);
464 if (modal_dialog) {
465 widget = constrained_window::ShowWebModalDialogViews(this,
466 parent_web_contents);
467 } else {
468 widget = DialogDelegate::CreateDialogWidget(this, context, NULL);
469 widget->Show();
470 }
471
472 // If the picker is not modal to the calling web contents then it is displayed
473 // in its own top-level window, so in that case it needs to be filtered out of
474 // the list of top-level windows available for capture, and to achieve that
475 // the Id is passed to DesktopMediaList.
476 DesktopMediaID dialog_window_id;
477 if (!modal_dialog) {
478 dialog_window_id = DesktopMediaID::RegisterAuraWindow(
479 DesktopMediaID::TYPE_WINDOW, widget->GetNativeWindow());
480
481 bool is_ash_window = false;
482 #if defined(USE_ASH)
483 is_ash_window = chrome::IsNativeWindowInAsh(widget->GetNativeWindow());
484 #endif
485
486 // Set native window ID if the windows is outside Ash.
487 if (!is_ash_window) {
488 dialog_window_id.id = AcceleratedWidgetToDesktopMediaId(
489 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
490 }
491 }
492
493 sources_list_view_->StartUpdating(dialog_window_id);
494 }
495
496 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {}
497
498 void DesktopMediaPickerDialogView::DetachParent() {
499 parent_ = NULL;
500 }
501
502 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const {
503 static const size_t kDialogViewWidth = 600;
504 return gfx::Size(kDialogViewWidth, GetHeightForWidth(kDialogViewWidth));
505 }
506
507 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
508 return ui::MODAL_TYPE_CHILD;
509 }
510
511 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const {
512 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_);
513 }
514
515 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled(
516 ui::DialogButton button) const {
517 if (button == ui::DIALOG_BUTTON_OK)
518 return sources_list_view_->GetSelection() != NULL;
519 return true;
520 }
521
522 views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() {
523 return sources_list_view_;
524 }
525
526 base::string16 DesktopMediaPickerDialogView::GetDialogButtonLabel(
527 ui::DialogButton button) const {
528 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ?
529 IDS_DESKTOP_MEDIA_PICKER_SHARE : IDS_CANCEL);
530 }
531
532 bool DesktopMediaPickerDialogView::Accept() {
533 DesktopMediaSourceView* selection = sources_list_view_->GetSelection();
534
535 // Ok button should only be enabled when a source is selected.
536 DCHECK(selection);
537 DesktopMediaID source = selection->source_id();
538 source.audio_share = audio_share_checkbox_ &&
539 audio_share_checkbox_->enabled() &&
540 audio_share_checkbox_->checked();
541
542 // If the media source is an tab, activate it.
543 if (source.type == DesktopMediaID::TYPE_WEB_CONTENTS) {
544 content::WebContents* tab = content::WebContents::FromRenderFrameHost(
545 content::RenderFrameHost::FromID(
546 source.web_contents_id.render_process_id,
547 source.web_contents_id.main_render_frame_id));
548 if (tab)
549 tab->GetDelegate()->ActivateContents(tab);
550 }
551
552 if (parent_)
553 parent_->NotifyDialogResult(source);
554
555 // Return true to close the window.
556 return true;
557 }
558
559 void DesktopMediaPickerDialogView::DeleteDelegate() {
560 // If the dialog is being closed then notify the parent about it.
561 if (parent_)
562 parent_->NotifyDialogResult(DesktopMediaID());
563 delete this;
564 }
565
566 void DesktopMediaPickerDialogView::OnSelectionChanged() {
567 GetDialogClientView()->UpdateDialogButtons();
568
569 // Disable the checkbox if we cannot support audio for the selected source.
570 if (audio_share_checkbox_) {
571 DesktopMediaSourceView* selection = sources_list_view_->GetSelection();
572
573 DesktopMediaID source;
574 if (selection)
575 source = selection->source_id();
576
577 if (source.type == DesktopMediaID::TYPE_SCREEN ||
578 source.type == DesktopMediaID::TYPE_WEB_CONTENTS) {
579 if (!audio_share_checkbox_->enabled()) {
580 audio_share_checkbox_->SetEnabled(true);
581 audio_share_checkbox_->SetChecked(audio_share_checked_);
582 }
583 audio_share_checkbox_->SetTooltipText(base::string16());
584 } else if (source.type == DesktopMediaID::TYPE_WINDOW) {
585 if (audio_share_checkbox_->enabled()) {
586 audio_share_checkbox_->SetEnabled(false);
587 audio_share_checked_ = audio_share_checkbox_->checked();
588 audio_share_checkbox_->SetChecked(false);
589 }
590 audio_share_checkbox_->SetTooltipText(l10n_util::GetStringUTF16(
591 IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_TOOLTIP_WINDOW));
592 } else {
593 NOTREACHED();
594 }
595 }
596 }
597
598 void DesktopMediaPickerDialogView::OnDoubleClick() {
599 // This will call Accept() and close the dialog.
600 GetDialogClientView()->AcceptWindow();
601 }
602
603 void DesktopMediaPickerDialogView::OnMediaListRowsChanged() {
604 gfx::Rect widget_bound = GetWidget()->GetWindowBoundsInScreen();
605
606 int new_height = widget_bound.height() - sources_scroll_view_->height() +
607 sources_scroll_view_->GetPreferredSize().height();
608
609 GetWidget()->CenterWindow(gfx::Size(widget_bound.width(), new_height));
610 }
611
612 DesktopMediaListView* DesktopMediaPickerDialogView::GetMediaListViewForTesting()
613 const {
614 return sources_list_view_;
615 }
616
617 DesktopMediaSourceView*
618 DesktopMediaPickerDialogView::GetMediaSourceViewForTesting(int index) const {
619 if (sources_list_view_->child_count() <= index)
620 return NULL;
621
622 return reinterpret_cast<DesktopMediaSourceView*>(
623 sources_list_view_->child_at(index));
624 }
625
626 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {
627 }
628
629 DesktopMediaPickerViews::~DesktopMediaPickerViews() {
630 if (dialog_) {
631 dialog_->DetachParent();
632 dialog_->GetWidget()->Close();
633 }
634 }
635
636 void DesktopMediaPickerViews::Show(
637 content::WebContents* web_contents,
638 gfx::NativeWindow context,
639 gfx::NativeWindow parent,
640 const base::string16& app_name,
641 const base::string16& target_name,
642 std::unique_ptr<DesktopMediaList> screen_list,
643 std::unique_ptr<DesktopMediaList> window_list,
644 std::unique_ptr<DesktopMediaList> tab_list,
645 bool request_audio,
646 const DoneCallback& done_callback) {
647 callback_ = done_callback;
648 dialog_ = new DesktopMediaPickerDialogView(
649 web_contents, context, this, app_name, target_name,
650 std::move(screen_list), std::move(window_list), std::move(tab_list),
651 request_audio);
652 }
653
654 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) {
655 // Once this method is called the |dialog_| will close and destroy itself.
656 dialog_->DetachParent();
657 dialog_ = NULL;
658
659 DCHECK(!callback_.is_null());
660
661 // Notify the |callback_| asynchronously because it may need to destroy
662 // DesktopMediaPicker.
663 content::BrowserThread::PostTask(
664 content::BrowserThread::UI, FROM_HERE,
665 base::Bind(callback_, source));
666 callback_.Reset();
667 }
668
669 // static
670 std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() {
671 return std::unique_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews());
672 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/desktop_media_picker_views.h ('k') | chrome/browser/ui/views/desktop_media_picker_views_deprecated.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698