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

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

Issue 319013002: Reland Fix Views web-modal dialog widget creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert MediaGalleriesScanResultDialogViews::AcceptDialogForTesting. Created 6 years, 6 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
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/media/desktop_media_picker.h" 5 #include "chrome/browser/media/desktop_media_picker.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/media/desktop_media_list_observer.h" 9 #include "chrome/browser/media/desktop_media_list_observer.h"
10 #include "chrome/browser/ui/ash/ash_util.h" 10 #include "chrome/browser/ui/ash/ash_util.h"
11 #include "components/web_modal/web_contents_modal_dialog_host.h" 11 #include "chrome/browser/ui/views/constrained_window_views.h"
12 #include "components/web_modal/web_contents_modal_dialog_manager.h" 12 #include "components/web_modal/web_contents_modal_dialog_manager.h"
13 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
14 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
15 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
16 #include "ui/aura/window_tree_host.h" 15 #include "ui/aura/window_tree_host.h"
17 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.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/controls/image_view.h" 21 #include "ui/views/controls/image_view.h"
23 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
24 #include "ui/views/controls/scroll_view.h" 23 #include "ui/views/controls/scroll_view.h"
25 #include "ui/views/layout/box_layout.h" 24 #include "ui/views/layout/box_layout.h"
26 #include "ui/views/layout/layout_constants.h" 25 #include "ui/views/layout/layout_constants.h"
27 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
28 #include "ui/views/window/dialog_client_view.h" 27 #include "ui/views/window/dialog_client_view.h"
29 #include "ui/views/window/dialog_delegate.h" 28 #include "ui/views/window/dialog_delegate.h"
30 #include "ui/wm/core/shadow_types.h" 29 #include "ui/wm/core/shadow_types.h"
31 30
32 using content::DesktopMediaID; 31 using content::DesktopMediaID;
33 using web_modal::WebContentsModalDialogManager;
34 using web_modal::WebContentsModalDialogManagerDelegate;
35 32
36 namespace { 33 namespace {
37 34
38 const int kThumbnailWidth = 160; 35 const int kThumbnailWidth = 160;
39 const int kThumbnailHeight = 100; 36 const int kThumbnailHeight = 100;
40 const int kThumbnailMargin = 10; 37 const int kThumbnailMargin = 10;
41 const int kLabelHeight = 40; 38 const int kLabelHeight = 40;
42 const int kListItemWidth = kThumbnailMargin * 2 + kThumbnailWidth; 39 const int kListItemWidth = kThumbnailMargin * 2 + kThumbnailWidth;
43 const int kListItemHeight = 40 const int kListItemHeight =
44 kThumbnailMargin * 2 + kThumbnailHeight + kLabelHeight; 41 kThumbnailMargin * 2 + kThumbnailHeight + kLabelHeight;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 163
167 // Called by DesktopMediaListView. 164 // Called by DesktopMediaListView.
168 void OnSelectionChanged(); 165 void OnSelectionChanged();
169 void OnDoubleClick(); 166 void OnDoubleClick();
170 167
171 // views::View overrides. 168 // views::View overrides.
172 virtual gfx::Size GetPreferredSize() const OVERRIDE; 169 virtual gfx::Size GetPreferredSize() const OVERRIDE;
173 virtual void Layout() OVERRIDE; 170 virtual void Layout() OVERRIDE;
174 171
175 // views::DialogDelegateView overrides. 172 // views::DialogDelegateView overrides.
173 virtual ui::ModalType GetModalType() const OVERRIDE;
176 virtual base::string16 GetWindowTitle() const OVERRIDE; 174 virtual base::string16 GetWindowTitle() const OVERRIDE;
177 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; 175 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
178 virtual base::string16 GetDialogButtonLabel( 176 virtual base::string16 GetDialogButtonLabel(
179 ui::DialogButton button) const OVERRIDE; 177 ui::DialogButton button) const OVERRIDE;
180 virtual bool Accept() OVERRIDE; 178 virtual bool Accept() OVERRIDE;
181 virtual void DeleteDelegate() OVERRIDE; 179 virtual void DeleteDelegate() OVERRIDE;
182 180
183 private: 181 private:
184 DesktopMediaPickerViews* parent_; 182 DesktopMediaPickerViews* parent_;
185 base::string16 app_name_; 183 base::string16 app_name_;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 AddChildView(label_); 514 AddChildView(label_);
517 515
518 scroll_view_->SetContents(list_view_); 516 scroll_view_->SetContents(list_view_);
519 AddChildView(scroll_view_); 517 AddChildView(scroll_view_);
520 518
521 // If |parent_web_contents| is set, the picker will be shown modal to the 519 // If |parent_web_contents| is set, the picker will be shown modal to the
522 // web contents. Otherwise, a new dialog widget inside |parent_window| will be 520 // web contents. Otherwise, a new dialog widget inside |parent_window| will be
523 // created for the picker. Note that |parent_window| may also be NULL if 521 // created for the picker. Note that |parent_window| may also be NULL if
524 // parent web contents is not set. In this case the picker will be parented 522 // parent web contents is not set. In this case the picker will be parented
525 // by a root window. 523 // by a root window.
526 WebContentsModalDialogManager* web_contents_modal_dialog_manager = NULL; 524 views::Widget* widget = NULL;
527 if (parent_web_contents) { 525 if (parent_web_contents)
528 web_contents_modal_dialog_manager = 526 widget = CreateWebModalDialogViews(this, parent_web_contents);
529 WebContentsModalDialogManager::FromWebContents(parent_web_contents); 527 else
530 DCHECK(web_contents_modal_dialog_manager); 528 widget = DialogDelegate::CreateDialogWidget(this, context, parent_window);
531 WebContentsModalDialogManagerDelegate* delegate =
532 web_contents_modal_dialog_manager->delegate();
533 DCHECK(delegate);
534 views::Widget::CreateWindowAsFramelessChild(
535 this,
536 delegate->GetWebContentsModalDialogHost()->GetHostView());
537 } else {
538 DialogDelegate::CreateDialogWidget(this, context, parent_window);
539 }
540 529
541 // DesktopMediaList needs to know the ID of the picker window which 530 // DesktopMediaList needs to know the ID of the picker window which
542 // matches the ID it gets from the OS. Depending on the OS and configuration 531 // matches the ID it gets from the OS. Depending on the OS and configuration
543 // we get this ID differently. 532 // we get this ID differently.
544 content::DesktopMediaID::Id dialog_window_id = 0; 533 content::DesktopMediaID::Id dialog_window_id = 0;
545
546 #if defined(USE_ASH) 534 #if defined(USE_ASH)
547 if (chrome::IsNativeWindowInAsh(GetWidget()->GetNativeWindow())) { 535 if (chrome::IsNativeWindowInAsh(widget->GetNativeWindow())) {
548 dialog_window_id = content::DesktopMediaID::RegisterAuraWindow( 536 dialog_window_id = content::DesktopMediaID::RegisterAuraWindow(
549 GetWidget()->GetNativeWindow()).id; 537 widget->GetNativeWindow()).id;
550 } else 538 DCHECK_NE(dialog_window_id, 0);
539 }
551 #endif 540 #endif
552 { 541 if (dialog_window_id == 0) {
553 dialog_window_id = AcceleratedWidgetToDesktopMediaId( 542 dialog_window_id = AcceleratedWidgetToDesktopMediaId(
554 GetWidget()->GetNativeWindow()->GetHost()-> 543 widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
555 GetAcceleratedWidget());
556 } 544 }
557 545
558 list_view_->StartUpdating(dialog_window_id); 546 list_view_->StartUpdating(dialog_window_id);
559 547
560 if (parent_web_contents) { 548 if (parent_web_contents) {
561 web_contents_modal_dialog_manager->ShowModalDialog( 549 web_modal::WebContentsModalDialogManager* manager =
562 GetWidget()->GetNativeView()); 550 web_modal::WebContentsModalDialogManager::FromWebContents(
551 parent_web_contents);
552 manager->ShowModalDialog(widget->GetNativeView());
563 } else { 553 } else {
564 GetWidget()->Show(); 554 widget->Show();
565 } 555 }
566 } 556 }
567 557
568 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {} 558 DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {}
569 559
570 void DesktopMediaPickerDialogView::DetachParent() { 560 void DesktopMediaPickerDialogView::DetachParent() {
571 parent_ = NULL; 561 parent_ = NULL;
572 } 562 }
573 563
574 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { 564 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const {
575 return gfx::Size(600, 500); 565 return gfx::Size(600, 500);
576 } 566 }
577 567
578 void DesktopMediaPickerDialogView::Layout() { 568 void DesktopMediaPickerDialogView::Layout() {
579 gfx::Rect rect = GetLocalBounds(); 569 gfx::Rect rect = GetLocalBounds();
580 rect.Inset(views::kPanelHorizMargin, views::kPanelVertMargin); 570 rect.Inset(views::kPanelHorizMargin, views::kPanelVertMargin);
581 571
582 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(), 572 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(),
583 label_->GetHeightForWidth(rect.width())); 573 label_->GetHeightForWidth(rect.width()));
584 label_->SetBoundsRect(label_rect); 574 label_->SetBoundsRect(label_rect);
585 575
586 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing; 576 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing;
587 scroll_view_->SetBounds( 577 scroll_view_->SetBounds(
588 rect.x(), scroll_view_top, 578 rect.x(), scroll_view_top,
589 rect.width(), rect.height() - scroll_view_top); 579 rect.width(), rect.height() - scroll_view_top);
590 } 580 }
591 581
582 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
583 return ui::MODAL_TYPE_CHILD;
584 }
585
592 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const { 586 base::string16 DesktopMediaPickerDialogView::GetWindowTitle() const {
593 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_); 587 return l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TITLE, app_name_);
594 } 588 }
595 589
596 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled( 590 bool DesktopMediaPickerDialogView::IsDialogButtonEnabled(
597 ui::DialogButton button) const { 591 ui::DialogButton button) const {
598 if (button == ui::DIALOG_BUTTON_OK) 592 if (button == ui::DIALOG_BUTTON_OK)
599 return list_view_->GetSelection() != NULL; 593 return list_view_->GetSelection() != NULL;
600 return true; 594 return true;
601 } 595 }
(...skipping 30 matching lines...) Expand all
632 626
633 void DesktopMediaPickerDialogView::OnSelectionChanged() { 627 void DesktopMediaPickerDialogView::OnSelectionChanged() {
634 GetDialogClientView()->UpdateDialogButtons(); 628 GetDialogClientView()->UpdateDialogButtons();
635 } 629 }
636 630
637 void DesktopMediaPickerDialogView::OnDoubleClick() { 631 void DesktopMediaPickerDialogView::OnDoubleClick() {
638 // This will call Accept() and close the dialog. 632 // This will call Accept() and close the dialog.
639 GetDialogClientView()->AcceptWindow(); 633 GetDialogClientView()->AcceptWindow();
640 } 634 }
641 635
642 DesktopMediaPickerViews::DesktopMediaPickerViews() 636 DesktopMediaPickerViews::DesktopMediaPickerViews() : dialog_(NULL) {
643 : dialog_(NULL) {
644 } 637 }
645 638
646 DesktopMediaPickerViews::~DesktopMediaPickerViews() { 639 DesktopMediaPickerViews::~DesktopMediaPickerViews() {
647 if (dialog_) { 640 if (dialog_) {
648 dialog_->DetachParent(); 641 dialog_->DetachParent();
649 dialog_->GetWidget()->Close(); 642 dialog_->GetWidget()->Close();
650 } 643 }
651 } 644 }
652 645
653 void DesktopMediaPickerViews::Show(content::WebContents* web_contents, 646 void DesktopMediaPickerViews::Show(content::WebContents* web_contents,
654 gfx::NativeWindow context, 647 gfx::NativeWindow context,
655 gfx::NativeWindow parent, 648 gfx::NativeWindow parent,
656 const base::string16& app_name, 649 const base::string16& app_name,
657 const base::string16& target_name, 650 const base::string16& target_name,
658 scoped_ptr<DesktopMediaList> media_list, 651 scoped_ptr<DesktopMediaList> media_list,
659 const DoneCallback& done_callback) { 652 const DoneCallback& done_callback) {
660 callback_ = done_callback; 653 callback_ = done_callback;
661 dialog_ = new DesktopMediaPickerDialogView( 654 dialog_ = new DesktopMediaPickerDialogView(
662 web_contents, context, parent, this, app_name, target_name, 655 web_contents, context, parent, this, app_name, target_name,
663 media_list.Pass()); 656 media_list.Pass());
664 } 657 }
665 658
666 void DesktopMediaPickerViews::NotifyDialogResult( 659 void DesktopMediaPickerViews::NotifyDialogResult(DesktopMediaID source) {
667 DesktopMediaID source) {
668 // Once this method is called the |dialog_| will close and destroy itself. 660 // Once this method is called the |dialog_| will close and destroy itself.
669 dialog_->DetachParent(); 661 dialog_->DetachParent();
670 dialog_ = NULL; 662 dialog_ = NULL;
671 663
672 DCHECK(!callback_.is_null()); 664 DCHECK(!callback_.is_null());
673 665
674 // Notify the |callback_| asynchronously because it may need to destroy 666 // Notify the |callback_| asynchronously because it may need to destroy
675 // DesktopMediaPicker. 667 // DesktopMediaPicker.
676 content::BrowserThread::PostTask( 668 content::BrowserThread::PostTask(
677 content::BrowserThread::UI, FROM_HERE, 669 content::BrowserThread::UI, FROM_HERE,
678 base::Bind(callback_, source)); 670 base::Bind(callback_, source));
679 callback_.Reset(); 671 callback_.Reset();
680 } 672 }
681 673
682 } // namespace 674 } // namespace
683 675
684 // static 676 // static
685 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { 677 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() {
686 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); 678 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews());
687 } 679 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698