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 "chrome/browser/media/desktop_media_list.h" | 8 #include "chrome/browser/media/desktop_media_list.h" |
9 #include "chrome/browser/ui/ash/ash_util.h" | 9 #include "chrome/browser/ui/ash/ash_util.h" |
10 #include "chrome/browser/ui/views/constrained_window_views.h" | 10 #include "chrome/browser/ui/views/constrained_window_views.h" |
11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
12 #include "components/web_modal/popup_manager.h" | 12 #include "components/web_modal/popup_manager.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/web_contents_delegate.h" |
14 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/events/event_constants.h" | 17 #include "ui/events/event_constants.h" |
17 #include "ui/events/keycodes/keyboard_codes.h" | 18 #include "ui/events/keycodes/keyboard_codes.h" |
18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
19 #include "ui/native_theme/native_theme.h" | 20 #include "ui/native_theme/native_theme.h" |
20 #include "ui/views/background.h" | 21 #include "ui/views/background.h" |
21 #include "ui/views/bubble/bubble_frame_view.h" | 22 #include "ui/views/bubble/bubble_frame_view.h" |
22 #include "ui/views/controls/image_view.h" | 23 #include "ui/views/controls/image_view.h" |
23 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 void DesktopMediaListView::OnSourceThumbnailChanged(int index) { | 352 void DesktopMediaListView::OnSourceThumbnailChanged(int index) { |
352 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 353 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
353 DesktopMediaSourceView* source_view = | 354 DesktopMediaSourceView* source_view = |
354 static_cast<DesktopMediaSourceView*>(child_at(index)); | 355 static_cast<DesktopMediaSourceView*>(child_at(index)); |
355 source_view->SetThumbnail(source.thumbnail); | 356 source_view->SetThumbnail(source.thumbnail); |
356 } | 357 } |
357 | 358 |
358 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( | 359 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( |
359 content::WebContents* parent_web_contents, | 360 content::WebContents* parent_web_contents, |
360 gfx::NativeWindow context, | 361 gfx::NativeWindow context, |
361 gfx::NativeWindow parent_window, | |
362 DesktopMediaPickerViews* parent, | 362 DesktopMediaPickerViews* parent, |
363 const base::string16& app_name, | 363 const base::string16& app_name, |
364 const base::string16& target_name, | 364 const base::string16& target_name, |
365 scoped_ptr<DesktopMediaList> media_list) | 365 scoped_ptr<DesktopMediaList> media_list) |
366 : parent_(parent), | 366 : parent_(parent), |
367 app_name_(app_name), | 367 app_name_(app_name), |
368 label_(new views::Label()), | 368 label_(new views::Label()), |
369 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), | 369 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), |
370 list_view_(new DesktopMediaListView(this, media_list.Pass())) { | 370 list_view_(new DesktopMediaListView(this, media_list.Pass())) { |
371 if (app_name == target_name) { | 371 if (app_name == target_name) { |
372 label_->SetText( | 372 label_->SetText( |
373 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); | 373 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); |
374 } else { | 374 } else { |
375 label_->SetText(l10n_util::GetStringFUTF16( | 375 label_->SetText(l10n_util::GetStringFUTF16( |
376 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); | 376 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); |
377 } | 377 } |
378 label_->SetMultiLine(true); | 378 label_->SetMultiLine(true); |
379 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 379 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
380 AddChildView(label_); | 380 AddChildView(label_); |
381 | 381 |
382 scroll_view_->SetContents(list_view_); | 382 scroll_view_->SetContents(list_view_); |
383 scroll_view_->ClipHeightTo( | 383 scroll_view_->ClipHeightTo( |
384 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); | 384 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); |
385 AddChildView(scroll_view_); | 385 AddChildView(scroll_view_); |
386 | 386 |
387 // If |parent_web_contents| is set, the picker will be shown modal to the | 387 // If |parent_web_contents| is set and it's not a background page then the |
388 // web contents. Otherwise, a new dialog widget inside |parent_window| will be | 388 // picker will be shown modal to the web contents. Otherwise the picker is |
389 // created for the picker. Note that |parent_window| may also be NULL if | 389 // shown in a separate window. |
390 // parent web contents is not set. In this case the picker will be parented | |
391 // by a root window. | |
392 views::Widget* widget = NULL; | 390 views::Widget* widget = NULL; |
393 if (parent_web_contents) | 391 bool modal_dialog = |
| 392 parent_web_contents && |
| 393 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents); |
| 394 if (modal_dialog) { |
394 widget = CreateWebModalDialogViews(this, parent_web_contents); | 395 widget = CreateWebModalDialogViews(this, parent_web_contents); |
395 else | 396 } else { |
396 widget = DialogDelegate::CreateDialogWidget(this, context, parent_window); | 397 widget = DialogDelegate::CreateDialogWidget(this, context, NULL); |
| 398 } |
397 | 399 |
398 // DesktopMediaList needs to know the ID of the picker window which | 400 // If the picker is not modal to the calling web contents then it is displayed |
399 // matches the ID it gets from the OS. Depending on the OS and configuration | 401 // in its own top-level window, so in that case it needs to be filtered out of |
400 // we get this ID differently. | 402 // the list of top-level windows available for capture, and to achieve that |
| 403 // the Id is passed to DesktopMediaList. |
401 DesktopMediaID::Id dialog_window_id = 0; | 404 DesktopMediaID::Id dialog_window_id = 0; |
402 | 405 if (!modal_dialog) { |
403 // If there is |parent_window| or |parent_web_contents|, the picker window | |
404 // is embedded in the parent and does not have its own native window id, so we | |
405 // do not filter in that case. | |
406 if (!parent_window && !parent_web_contents) { | |
407 #if defined(USE_ASH) | 406 #if defined(USE_ASH) |
408 if (chrome::IsNativeWindowInAsh(widget->GetNativeWindow())) { | 407 if (chrome::IsNativeWindowInAsh(widget->GetNativeWindow())) { |
409 dialog_window_id = | 408 dialog_window_id = |
410 DesktopMediaID::RegisterAuraWindow(widget->GetNativeWindow()).id; | 409 DesktopMediaID::RegisterAuraWindow(widget->GetNativeWindow()).id; |
411 DCHECK_NE(dialog_window_id, 0); | 410 DCHECK_NE(dialog_window_id, 0); |
412 } | 411 } |
413 #endif | 412 #endif |
414 | 413 |
415 if (dialog_window_id == 0) { | 414 if (dialog_window_id == 0) { |
416 dialog_window_id = AcceleratedWidgetToDesktopMediaId( | 415 dialog_window_id = AcceleratedWidgetToDesktopMediaId( |
417 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); | 416 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); |
418 } | 417 } |
419 } | 418 } |
420 | 419 |
421 list_view_->StartUpdating(dialog_window_id); | 420 list_view_->StartUpdating(dialog_window_id); |
422 | 421 |
423 if (parent_web_contents) { | 422 if (modal_dialog) { |
424 web_modal::PopupManager* popup_manager = | 423 web_modal::PopupManager* popup_manager = |
425 web_modal::PopupManager::FromWebContents(parent_web_contents); | 424 web_modal::PopupManager::FromWebContents(parent_web_contents); |
426 popup_manager->ShowModalDialog(GetWidget()->GetNativeView(), | 425 popup_manager->ShowModalDialog(GetWidget()->GetNativeView(), |
427 parent_web_contents); | 426 parent_web_contents); |
428 } else { | 427 } else { |
429 widget->Show(); | 428 widget->Show(); |
430 } | 429 } |
431 } | 430 } |
432 | 431 |
433 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} | 432 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 547 |
549 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, | 548 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, |
550 gfx::NativeWindow context, | 549 gfx::NativeWindow context, |
551 gfx::NativeWindow parent, | 550 gfx::NativeWindow parent, |
552 const base::string16& app_name, | 551 const base::string16& app_name, |
553 const base::string16& target_name, | 552 const base::string16& target_name, |
554 scoped_ptr<DesktopMediaList> media_list, | 553 scoped_ptr<DesktopMediaList> media_list, |
555 const DoneCallback& done_callback) { | 554 const DoneCallback& done_callback) { |
556 callback_ = done_callback; | 555 callback_ = done_callback; |
557 dialog_ = new DesktopMediaPickerDialogView( | 556 dialog_ = new DesktopMediaPickerDialogView( |
558 web_contents, context, parent, this, app_name, target_name, | 557 web_contents, context, this, app_name, target_name, media_list.Pass()); |
559 media_list.Pass()); | |
560 } | 558 } |
561 | 559 |
562 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { | 560 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { |
563 // Once this method is called the |dialog_| will close and destroy itself. | 561 // Once this method is called the |dialog_| will close and destroy itself. |
564 dialog_->DetachParent(); | 562 dialog_->DetachParent(); |
565 dialog_ = NULL; | 563 dialog_ = NULL; |
566 | 564 |
567 DCHECK(!callback_.is_null()); | 565 DCHECK(!callback_.is_null()); |
568 | 566 |
569 // Notify the |callback_| asynchronously because it may need to destroy | 567 // Notify the |callback_| asynchronously because it may need to destroy |
570 // DesktopMediaPicker. | 568 // DesktopMediaPicker. |
571 content::BrowserThread::PostTask( | 569 content::BrowserThread::PostTask( |
572 content::BrowserThread::UI, FROM_HERE, | 570 content::BrowserThread::UI, FROM_HERE, |
573 base::Bind(callback_, source)); | 571 base::Bind(callback_, source)); |
574 callback_.Reset(); | 572 callback_.Reset(); |
575 } | 573 } |
576 | 574 |
577 // static | 575 // static |
578 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 576 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
579 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 577 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
580 } | 578 } |
OLD | NEW |