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