Chromium Code Reviews| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 } | 401 } |
| 401 label_->SetMultiLine(true); | 402 label_->SetMultiLine(true); |
| 402 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 403 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 403 AddChildView(label_); | 404 AddChildView(label_); |
| 404 | 405 |
| 405 scroll_view_->SetContents(list_view_); | 406 scroll_view_->SetContents(list_view_); |
| 406 scroll_view_->ClipHeightTo( | 407 scroll_view_->ClipHeightTo( |
| 407 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); | 408 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); |
| 408 AddChildView(scroll_view_); | 409 AddChildView(scroll_view_); |
| 409 | 410 |
| 410 // If |parent_web_contents| is set, the picker will be shown modal to the | 411 // 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 | 412 // 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 | 413 // 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; | 414 views::Widget* widget = NULL; |
| 416 if (parent_web_contents) | 415 bool modal_dialog = |
| 416 parent_web_contents && | |
| 417 !parent_web_contents->GetDelegate()->IsNeverVisible(parent_web_contents); | |
| 418 if (modal_dialog) { | |
| 417 widget = CreateWebModalDialogViews(this, parent_web_contents); | 419 widget = CreateWebModalDialogViews(this, parent_web_contents); |
| 418 else | 420 } else { |
| 419 widget = DialogDelegate::CreateDialogWidget(this, context, parent_window); | 421 widget = DialogDelegate::CreateDialogWidget(this, context, NULL); |
| 422 } | |
| 420 | 423 |
| 421 // DesktopMediaList needs to know the ID of the picker window which | 424 // DesktopMediaList needs to know the ID of the picker window so it can filter |
| 422 // matches the ID it gets from the OS. Depending on the OS and configuration | 425 // the picker window from the list of available sources. Filtering is not |
|
Wez
2014/08/25 21:32:02
nit: ID -> Id
nit: ... so it can be filtered from
Sergey Ulanov
2014/08/25 22:03:52
Done.
| |
| 423 // we get this ID differently. | 426 // necessary when the picker is shown as a modal dialog, because in that case |
| 427 // it's embedded in the parent window. | |
|
Wez
2014/08/25 21:32:02
I think it'd be clearer to express *why* we need t
Sergey Ulanov
2014/08/25 22:03:52
Done.
| |
| 424 DesktopMediaID::Id dialog_window_id = 0; | 428 DesktopMediaID::Id dialog_window_id = 0; |
| 425 | 429 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) | 430 #if defined(USE_ASH) |
| 431 if (chrome::IsNativeWindowInAsh(widget->GetNativeWindow())) { | 431 if (chrome::IsNativeWindowInAsh(widget->GetNativeWindow())) { |
| 432 dialog_window_id = | 432 dialog_window_id = |
| 433 DesktopMediaID::RegisterAuraWindow(widget->GetNativeWindow()).id; | 433 DesktopMediaID::RegisterAuraWindow(widget->GetNativeWindow()).id; |
| 434 DCHECK_NE(dialog_window_id, 0); | 434 DCHECK_NE(dialog_window_id, 0); |
| 435 } | 435 } |
| 436 #endif | 436 #endif |
| 437 | 437 |
| 438 if (dialog_window_id == 0) { | 438 if (dialog_window_id == 0) { |
| 439 dialog_window_id = AcceleratedWidgetToDesktopMediaId( | 439 dialog_window_id = AcceleratedWidgetToDesktopMediaId( |
| 440 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); | 440 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget()); |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 list_view_->StartUpdating(dialog_window_id); | 444 list_view_->StartUpdating(dialog_window_id); |
| 445 | 445 |
| 446 if (parent_web_contents) { | 446 if (modal_dialog) { |
| 447 web_modal::PopupManager* popup_manager = | 447 web_modal::PopupManager* popup_manager = |
| 448 web_modal::PopupManager::FromWebContents(parent_web_contents); | 448 web_modal::PopupManager::FromWebContents(parent_web_contents); |
| 449 popup_manager->ShowModalDialog(GetWidget()->GetNativeView(), | 449 popup_manager->ShowModalDialog(GetWidget()->GetNativeView(), |
| 450 parent_web_contents); | 450 parent_web_contents); |
| 451 } else { | 451 } else { |
| 452 widget->Show(); | 452 widget->Show(); |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 | 455 |
| 456 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} | 456 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 content::BrowserThread::PostTask( | 594 content::BrowserThread::PostTask( |
| 595 content::BrowserThread::UI, FROM_HERE, | 595 content::BrowserThread::UI, FROM_HERE, |
| 596 base::Bind(callback_, source)); | 596 base::Bind(callback_, source)); |
| 597 callback_.Reset(); | 597 callback_.Reset(); |
| 598 } | 598 } |
| 599 | 599 |
| 600 // static | 600 // static |
| 601 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 601 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
| 602 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 602 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
| 603 } | 603 } |
| OLD | NEW |