| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tab_modal_confirm_dialog_views.h" | 5 #include "chrome/browser/ui/views/tab_modal_confirm_dialog_views.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/browser_dialogs.h" | 8 #include "chrome/browser/ui/browser_dialogs.h" |
| 9 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 11 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "components/web_modal/web_contents_modal_dialog_host.h" | |
| 14 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
| 15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | |
| 16 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 17 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/window_open_disposition.h" | 16 #include "ui/base/window_open_disposition.h" |
| 20 #include "ui/views/controls/message_box_view.h" | 17 #include "ui/views/controls/message_box_view.h" |
| 21 #include "ui/views/layout/layout_constants.h" | 18 #include "ui/views/layout/layout_constants.h" |
| 22 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 23 #include "ui/views/window/dialog_client_view.h" | 20 #include "ui/views/window/dialog_client_view.h" |
| 24 | 21 |
| 25 using web_modal::WebContentsModalDialogManager; | |
| 26 using web_modal::WebContentsModalDialogManagerDelegate; | |
| 27 | |
| 28 // static | 22 // static |
| 29 TabModalConfirmDialog* TabModalConfirmDialog::Create( | 23 TabModalConfirmDialog* TabModalConfirmDialog::Create( |
| 30 TabModalConfirmDialogDelegate* delegate, | 24 TabModalConfirmDialogDelegate* delegate, |
| 31 content::WebContents* web_contents) { | 25 content::WebContents* web_contents) { |
| 32 return new TabModalConfirmDialogViews( | 26 return new TabModalConfirmDialogViews(delegate, web_contents); |
| 33 delegate, web_contents); | |
| 34 } | 27 } |
| 35 | 28 |
| 36 ////////////////////////////////////////////////////////////////////////////// | 29 ////////////////////////////////////////////////////////////////////////////// |
| 37 // TabModalConfirmDialogViews, constructor & destructor: | 30 // TabModalConfirmDialogViews, constructor & destructor: |
| 38 | 31 |
| 39 TabModalConfirmDialogViews::TabModalConfirmDialogViews( | 32 TabModalConfirmDialogViews::TabModalConfirmDialogViews( |
| 40 TabModalConfirmDialogDelegate* delegate, | 33 TabModalConfirmDialogDelegate* delegate, |
| 41 content::WebContents* web_contents) | 34 content::WebContents* web_contents) |
| 42 : delegate_(delegate), | 35 : delegate_(delegate) { |
| 43 dialog_(NULL) { | |
| 44 views::MessageBoxView::InitParams init_params(delegate->GetDialogMessage()); | 36 views::MessageBoxView::InitParams init_params(delegate->GetDialogMessage()); |
| 45 init_params.inter_row_vertical_spacing = | 37 init_params.inter_row_vertical_spacing = |
| 46 views::kUnrelatedControlVerticalSpacing; | 38 views::kUnrelatedControlVerticalSpacing; |
| 47 message_box_view_ = new views::MessageBoxView(init_params); | 39 message_box_view_ = new views::MessageBoxView(init_params); |
| 48 | 40 |
| 49 base::string16 link_text(delegate->GetLinkText()); | 41 base::string16 link_text(delegate->GetLinkText()); |
| 50 if (!link_text.empty()) | 42 if (!link_text.empty()) |
| 51 message_box_view_->SetLink(link_text, this); | 43 message_box_view_->SetLink(link_text, this); |
| 52 | 44 |
| 53 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 45 ShowWebModalDialogViews(this, web_contents); |
| 54 WebContentsModalDialogManager::FromWebContents(web_contents); | |
| 55 WebContentsModalDialogManagerDelegate* modal_delegate = | |
| 56 web_contents_modal_dialog_manager->delegate(); | |
| 57 DCHECK(modal_delegate); | |
| 58 dialog_ = views::Widget::CreateWindowAsFramelessChild( | |
| 59 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | |
| 60 web_contents_modal_dialog_manager->ShowModalDialog( | |
| 61 dialog_->GetNativeView()); | |
| 62 delegate_->set_close_delegate(this); | 46 delegate_->set_close_delegate(this); |
| 63 } | 47 } |
| 64 | 48 |
| 65 TabModalConfirmDialogViews::~TabModalConfirmDialogViews() { | 49 TabModalConfirmDialogViews::~TabModalConfirmDialogViews() { |
| 66 } | 50 } |
| 67 | 51 |
| 68 void TabModalConfirmDialogViews::AcceptTabModalDialog() { | 52 void TabModalConfirmDialogViews::AcceptTabModalDialog() { |
| 69 GetDialogClientView()->AcceptWindow(); | 53 GetDialogClientView()->AcceptWindow(); |
| 70 } | 54 } |
| 71 | 55 |
| 72 void TabModalConfirmDialogViews::CancelTabModalDialog() { | 56 void TabModalConfirmDialogViews::CancelTabModalDialog() { |
| 73 GetDialogClientView()->CancelWindow(); | 57 GetDialogClientView()->CancelWindow(); |
| 74 } | 58 } |
| 75 | 59 |
| 76 void TabModalConfirmDialogViews::CloseDialog() { | 60 void TabModalConfirmDialogViews::CloseDialog() { |
| 77 dialog_->Close(); | 61 GetWidget()->Close(); |
| 78 } | 62 } |
| 79 | 63 |
| 80 ////////////////////////////////////////////////////////////////////////////// | 64 ////////////////////////////////////////////////////////////////////////////// |
| 81 // TabModalConfirmDialogViews, views::LinkListener implementation: | 65 // TabModalConfirmDialogViews, views::LinkListener implementation: |
| 82 | 66 |
| 83 void TabModalConfirmDialogViews::LinkClicked(views::Link* source, | 67 void TabModalConfirmDialogViews::LinkClicked(views::Link* source, |
| 84 int event_flags) { | 68 int event_flags) { |
| 85 delegate_->LinkClicked(ui::DispositionFromEventFlags(event_flags)); | 69 delegate_->LinkClicked(ui::DispositionFromEventFlags(event_flags)); |
| 86 } | 70 } |
| 87 | 71 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 113 |
| 130 const views::Widget* TabModalConfirmDialogViews::GetWidget() const { | 114 const views::Widget* TabModalConfirmDialogViews::GetWidget() const { |
| 131 return message_box_view_->GetWidget(); | 115 return message_box_view_->GetWidget(); |
| 132 } | 116 } |
| 133 | 117 |
| 134 void TabModalConfirmDialogViews::DeleteDelegate() { | 118 void TabModalConfirmDialogViews::DeleteDelegate() { |
| 135 delete this; | 119 delete this; |
| 136 } | 120 } |
| 137 | 121 |
| 138 ui::ModalType TabModalConfirmDialogViews::GetModalType() const { | 122 ui::ModalType TabModalConfirmDialogViews::GetModalType() const { |
| 139 #if defined(USE_ASH) | |
| 140 return ui::MODAL_TYPE_CHILD; | 123 return ui::MODAL_TYPE_CHILD; |
| 141 #else | |
| 142 return views::WidgetDelegate::GetModalType(); | |
| 143 #endif | |
| 144 } | 124 } |
| OLD | NEW |