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