Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/ui/views/tab_modal_confirm_dialog_views.h" |
| 6 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 7 | #include "base/strings/utf_string_conversions.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 8 | #include "chrome/browser/ui/browser_dialogs.h" |
| 9 | #include "chrome/browser/ui/browser_list.h" |
| 10 | #include "chrome/browser/ui/browser_window.h" |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 11 | #include "chrome/browser/ui/views/constrained_window_views.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 12 | #include "chrome/common/chrome_switches.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 13 | #include "content/public/browser/web_contents.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 14 | #include "ui/base/window_open_disposition.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 15 | #include "ui/views/controls/message_box_view.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 16 | #include "ui/views/layout/layout_constants.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 17 | #include "ui/views/widget/widget.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 18 | #include "ui/views/window/dialog_client_view.h" |
| 19 | |
| 20 | // static |
| 21 | TabModalConfirmDialog* TabModalConfirmDialog::Create( |
| 22 | TabModalConfirmDialogDelegate* delegate, |
| 23 | content::WebContents* web_contents) { |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 24 | return new TabModalConfirmDialogViews(delegate, web_contents); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 27 | ////////////////////////////////////////////////////////////////////////////// |
| 28 | // TabModalConfirmDialogViews, constructor & destructor: |
| 29 | |
| 30 | TabModalConfirmDialogViews::TabModalConfirmDialogViews( |
| 31 | TabModalConfirmDialogDelegate* delegate, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 32 | content::WebContents* web_contents) |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 33 | : delegate_(delegate) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 34 | views::MessageBoxView::InitParams init_params(delegate->GetDialogMessage()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 35 | init_params.inter_row_vertical_spacing = |
| 36 | views::kUnrelatedControlVerticalSpacing; |
| 37 | message_box_view_ = new views::MessageBoxView(init_params); |
| 38 | |
Torne (Richard Coles) | a3f6a49 | 2013-12-18 16:25:09 +0000 | [diff] [blame] | 39 | base::string16 link_text(delegate->GetLinkText()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 40 | if (!link_text.empty()) |
| 41 | message_box_view_->SetLink(link_text, this); |
| 42 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 43 | ShowWebModalDialogViews(this, web_contents); |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 44 | delegate_->set_close_delegate(this); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | TabModalConfirmDialogViews::~TabModalConfirmDialogViews() { |
| 48 | } |
| 49 | |
| 50 | void TabModalConfirmDialogViews::AcceptTabModalDialog() { |
| 51 | GetDialogClientView()->AcceptWindow(); |
| 52 | } |
| 53 | |
| 54 | void TabModalConfirmDialogViews::CancelTabModalDialog() { |
| 55 | GetDialogClientView()->CancelWindow(); |
| 56 | } |
| 57 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 58 | void TabModalConfirmDialogViews::CloseDialog() { |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 59 | GetWidget()->Close(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 62 | ////////////////////////////////////////////////////////////////////////////// |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 63 | // TabModalConfirmDialogViews, views::LinkListener implementation: |
| 64 | |
| 65 | void TabModalConfirmDialogViews::LinkClicked(views::Link* source, |
| 66 | int event_flags) { |
| 67 | delegate_->LinkClicked(ui::DispositionFromEventFlags(event_flags)); |
| 68 | } |
| 69 | |
| 70 | ////////////////////////////////////////////////////////////////////////////// |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 71 | // TabModalConfirmDialogViews, views::DialogDelegate implementation: |
| 72 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 73 | base::string16 TabModalConfirmDialogViews::GetWindowTitle() const { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 74 | return delegate_->GetTitle(); |
| 75 | } |
| 76 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 77 | base::string16 TabModalConfirmDialogViews::GetDialogButtonLabel( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 78 | ui::DialogButton button) const { |
| 79 | if (button == ui::DIALOG_BUTTON_OK) |
| 80 | return delegate_->GetAcceptButtonTitle(); |
| 81 | if (button == ui::DIALOG_BUTTON_CANCEL) |
| 82 | return delegate_->GetCancelButtonTitle(); |
Torne (Richard Coles) | a3f6a49 | 2013-12-18 16:25:09 +0000 | [diff] [blame] | 83 | return base::string16(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 86 | bool TabModalConfirmDialogViews::Cancel() { |
| 87 | delegate_->Cancel(); |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | bool TabModalConfirmDialogViews::Accept() { |
| 92 | delegate_->Accept(); |
| 93 | return true; |
| 94 | } |
| 95 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 96 | bool TabModalConfirmDialogViews::Close() { |
| 97 | delegate_->Close(); |
| 98 | return true; |
| 99 | } |
| 100 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 101 | /////////////////////////////////////////////////////////////////////////////// |
| 102 | // TabModalConfirmDialogViews, views::WidgetDelegate implementation: |
| 103 | |
| 104 | views::View* TabModalConfirmDialogViews::GetContentsView() { |
| 105 | return message_box_view_; |
| 106 | } |
| 107 | |
| 108 | views::Widget* TabModalConfirmDialogViews::GetWidget() { |
| 109 | return message_box_view_->GetWidget(); |
| 110 | } |
| 111 | |
| 112 | const views::Widget* TabModalConfirmDialogViews::GetWidget() const { |
| 113 | return message_box_view_->GetWidget(); |
| 114 | } |
| 115 | |
| 116 | void TabModalConfirmDialogViews::DeleteDelegate() { |
| 117 | delete this; |
| 118 | } |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 119 | |
| 120 | ui::ModalType TabModalConfirmDialogViews::GetModalType() const { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 121 | return ui::MODAL_TYPE_CHILD; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 122 | } |