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

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

Issue 501713002: Fix DesktopMediaPickerViews to handle background parent_web_contents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/views/desktop_media_picker_views_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 gfx::NativeWindow parent_window,
msw 2014/08/26 22:16:46 |parent_window| is no longer used, remove it and c
Sergey Ulanov 2014/08/26 22:43:11 Done. I also have pending CL that removes this par
msw 2014/08/26 23:03:16 Nice, thanks.
385 DesktopMediaPickerViews* parent, 386 DesktopMediaPickerViews* parent,
386 const base::string16& app_name, 387 const base::string16& app_name,
387 const base::string16& target_name, 388 const base::string16& target_name,
388 scoped_ptr<DesktopMediaList> media_list) 389 scoped_ptr<DesktopMediaList> media_list)
389 : parent_(parent), 390 : parent_(parent),
390 app_name_(app_name), 391 app_name_(app_name),
391 label_(new views::Label()), 392 label_(new views::Label()),
392 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), 393 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()),
393 list_view_(new DesktopMediaListView(this, media_list.Pass())) { 394 list_view_(new DesktopMediaListView(this, media_list.Pass())) {
394 if (app_name == target_name) { 395 if (app_name == target_name) {
395 label_->SetText( 396 label_->SetText(
396 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); 397 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name));
397 } else { 398 } else {
398 label_->SetText(l10n_util::GetStringFUTF16( 399 label_->SetText(l10n_util::GetStringFUTF16(
399 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); 400 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name));
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 // 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 425 // in its own top-level window, so in that case it needs to be filtered out of
423 // we get this ID differently. 426 // the list of top-level windows available for capture, and to achieve that
427 // the Id is passed to DesktopMediaList.
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
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 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/desktop_media_picker_views_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698