| 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" | 8 #include "base/command_line.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/media/desktop_media_list.h" | 10 #include "chrome/browser/media/desktop_media_list.h" |
| 11 #include "chrome/browser/ui/ash/ash_util.h" | 11 #include "chrome/browser/ui/ash/ash_util.h" |
| 12 #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" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/web_modal/popup_manager.h" | 15 #include "components/web_modal/popup_manager.h" |
| 16 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 16 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/web_contents_delegate.h" |
| 18 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/events/event_constants.h" | 21 #include "ui/events/event_constants.h" |
| 21 #include "ui/events/keycodes/keyboard_codes.h" | 22 #include "ui/events/keycodes/keyboard_codes.h" |
| 22 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 23 #include "ui/native_theme/native_theme.h" | 24 #include "ui/native_theme/native_theme.h" |
| 24 #include "ui/views/background.h" | 25 #include "ui/views/background.h" |
| 25 #include "ui/views/bubble/bubble_frame_view.h" | 26 #include "ui/views/bubble/bubble_frame_view.h" |
| 26 #include "ui/views/controls/image_view.h" | 27 #include "ui/views/controls/image_view.h" |
| 27 #include "ui/views/controls/label.h" | 28 #include "ui/views/controls/label.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 375 } |
| 375 | 376 |
| 376 void DesktopMediaListView::AcceptSelection() { | 377 void DesktopMediaListView::AcceptSelection() { |
| 377 OnSelectionChanged(); | 378 OnSelectionChanged(); |
| 378 OnDoubleClick(); | 379 OnDoubleClick(); |
| 379 } | 380 } |
| 380 | 381 |
| 381 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( | 382 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( |
| 382 content::WebContents* parent_web_contents, | 383 content::WebContents* parent_web_contents, |
| 383 gfx::NativeWindow context, | 384 gfx::NativeWindow context, |
| 384 gfx::NativeWindow parent_window, | |
| 385 DesktopMediaPickerViews* parent, | 385 DesktopMediaPickerViews* parent, |
| 386 const base::string16& app_name, | 386 const base::string16& app_name, |
| 387 const base::string16& target_name, | 387 const base::string16& target_name, |
| 388 scoped_ptr<DesktopMediaList> media_list) | 388 scoped_ptr<DesktopMediaList> media_list) |
| 389 : parent_(parent), | 389 : parent_(parent), |
| 390 app_name_(app_name), | 390 app_name_(app_name), |
| 391 label_(new views::Label()), | 391 label_(new views::Label()), |
| 392 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), | 392 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), |
| 393 list_view_(new DesktopMediaListView(this, media_list.Pass())) { | 393 list_view_(new DesktopMediaListView(this, media_list.Pass())) { |
| 394 if (app_name == target_name) { | 394 if (app_name == target_name) { |
| 395 label_->SetText( | 395 label_->SetText( |
| 396 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); | 396 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); |
| 397 } else { | 397 } else { |
| 398 label_->SetText(l10n_util::GetStringFUTF16( | 398 label_->SetText(l10n_util::GetStringFUTF16( |
| 399 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); | 399 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); |
| 400 } | 400 } |
| 401 label_->SetMultiLine(true); | 401 label_->SetMultiLine(true); |
| 402 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 402 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 403 AddChildView(label_); | 403 AddChildView(label_); |
| 404 | 404 |
| 405 scroll_view_->SetContents(list_view_); | 405 scroll_view_->SetContents(list_view_); |
| 406 scroll_view_->ClipHeightTo( | 406 scroll_view_->ClipHeightTo( |
| 407 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); | 407 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); |
| 408 AddChildView(scroll_view_); | 408 AddChildView(scroll_view_); |
| 409 | 409 |
| 410 // If |parent_web_contents| is set, the picker will be shown modal to the | 410 // If |parent_web_contents| is set and it's not a background page then the |
| 411 // web contents. Otherwise, a new dialog widget inside |parent_window| will be | 411 // picker will be shown modal to the web contents. Otherwise the picker is |
| 412 // created for the picker. Note that |parent_window| may also be NULL if | 412 // shown in a separate window. |
| 413 // parent web contents is not set. In this case the picker will be parented | |
| 414 // by a root window. | |
| 415 views::Widget* widget = NULL; | 413 views::Widget* widget = NULL; |
| 416 if (parent_web_contents) | 414 bool modal_dialog = |
| 415 parent_web_contents && |
| 416 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents); |
| 417 if (modal_dialog) { |
| 417 widget = CreateWebModalDialogViews(this, parent_web_contents); | 418 widget = CreateWebModalDialogViews(this, parent_web_contents); |
| 418 else | 419 } else { |
| 419 widget = DialogDelegate::CreateDialogWidget(this, context, parent_window); | 420 widget = DialogDelegate::CreateDialogWidget(this, context, NULL); |
| 421 } |
| 420 | 422 |
| 421 // DesktopMediaList needs to know the ID of the picker window which | 423 // If the picker is not modal to the calling web contents then it is displayed |
| 422 // matches the ID it gets from the OS. Depending on the OS and configuration | 424 // in its own top-level window, so in that case it needs to be filtered out of |
| 423 // we get this ID differently. | 425 // the list of top-level windows available for capture, and to achieve that |
| 426 // the Id is passed to DesktopMediaList. |
| 424 DesktopMediaID::Id dialog_window_id = 0; | 427 DesktopMediaID::Id dialog_window_id = 0; |
| 425 | 428 if (!modal_dialog) { |
| 426 // If there is |parent_window| or |parent_web_contents|, the picker window | |
| 427 // is embedded in the parent and does not have its own native window id, so we | |
| 428 // do not filter in that case. | |
| 429 if (!parent_window && !parent_web_contents) { | |
| 430 #if defined(USE_ASH) | 429 #if defined(USE_ASH) |
| 431 if (chrome::IsNativeWindowInAsh(widget->GetNativeWindow())) { | 430 if (chrome::IsNativeWindowInAsh(widget->GetNativeWindow())) { |
| 432 dialog_window_id = | 431 dialog_window_id = |
| 433 DesktopMediaID::RegisterAuraWindow(widget->GetNativeWindow()).id; | 432 DesktopMediaID::RegisterAuraWindow(widget->GetNativeWindow()).id; |
| 434 DCHECK_NE(dialog_window_id, 0); | 433 DCHECK_NE(dialog_window_id, 0); |
| 435 } | 434 } |
| 436 #endif | 435 #endif |
| 437 | 436 |
| 438 if (dialog_window_id == 0) { | 437 if (dialog_window_id == 0) { |
| 439 dialog_window_id = AcceleratedWidgetToDesktopMediaId( | 438 dialog_window_id = AcceleratedWidgetToDesktopMediaId( |
| 440 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); | 439 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); |
| 441 } | 440 } |
| 442 } | 441 } |
| 443 | 442 |
| 444 list_view_->StartUpdating(dialog_window_id); | 443 list_view_->StartUpdating(dialog_window_id); |
| 445 | 444 |
| 446 if (parent_web_contents) { | 445 if (modal_dialog) { |
| 447 web_modal::PopupManager* popup_manager = | 446 web_modal::PopupManager* popup_manager = |
| 448 web_modal::PopupManager::FromWebContents(parent_web_contents); | 447 web_modal::PopupManager::FromWebContents(parent_web_contents); |
| 449 popup_manager->ShowModalDialog(GetWidget()->GetNativeView(), | 448 popup_manager->ShowModalDialog(GetWidget()->GetNativeView(), |
| 450 parent_web_contents); | 449 parent_web_contents); |
| 451 } else { | 450 } else { |
| 452 widget->Show(); | 451 widget->Show(); |
| 453 } | 452 } |
| 454 } | 453 } |
| 455 | 454 |
| 456 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} | 455 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 570 |
| 572 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, | 571 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, |
| 573 gfx::NativeWindow context, | 572 gfx::NativeWindow context, |
| 574 gfx::NativeWindow parent, | 573 gfx::NativeWindow parent, |
| 575 const base::string16& app_name, | 574 const base::string16& app_name, |
| 576 const base::string16& target_name, | 575 const base::string16& target_name, |
| 577 scoped_ptr<DesktopMediaList> media_list, | 576 scoped_ptr<DesktopMediaList> media_list, |
| 578 const DoneCallback& done_callback) { | 577 const DoneCallback& done_callback) { |
| 579 callback_ = done_callback; | 578 callback_ = done_callback; |
| 580 dialog_ = new DesktopMediaPickerDialogView( | 579 dialog_ = new DesktopMediaPickerDialogView( |
| 581 web_contents, context, parent, this, app_name, target_name, | 580 web_contents, context, this, app_name, target_name, media_list.Pass()); |
| 582 media_list.Pass()); | |
| 583 } | 581 } |
| 584 | 582 |
| 585 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { | 583 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) { |
| 586 // Once this method is called the |dialog_| will close and destroy itself. | 584 // Once this method is called the |dialog_| will close and destroy itself. |
| 587 dialog_->DetachParent(); | 585 dialog_->DetachParent(); |
| 588 dialog_ = NULL; | 586 dialog_ = NULL; |
| 589 | 587 |
| 590 DCHECK(!callback_.is_null()); | 588 DCHECK(!callback_.is_null()); |
| 591 | 589 |
| 592 // Notify the |callback_| asynchronously because it may need to destroy | 590 // Notify the |callback_| asynchronously because it may need to destroy |
| 593 // DesktopMediaPicker. | 591 // DesktopMediaPicker. |
| 594 content::BrowserThread::PostTask( | 592 content::BrowserThread::PostTask( |
| 595 content::BrowserThread::UI, FROM_HERE, | 593 content::BrowserThread::UI, FROM_HERE, |
| 596 base::Bind(callback_, source)); | 594 base::Bind(callback_, source)); |
| 597 callback_.Reset(); | 595 callback_.Reset(); |
| 598 } | 596 } |
| 599 | 597 |
| 600 // static | 598 // static |
| 601 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 599 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
| 602 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 600 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
| 603 } | 601 } |
| OLD | NEW |