NaCl docs: add sanitizers to GSoC ideas
[chromium-blink-merge.git] / chrome / browser / ui / views / tab_modal_confirm_dialog_views.cc
blob2dc88569b1e8ec2887bc7df51a77ceacd2729425
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.
5 #include "chrome/browser/ui/views/tab_modal_confirm_dialog_views.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser_dialogs.h"
9 #include "chrome/browser/ui/browser_list.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "components/constrained_window/constrained_window_views.h"
13 #include "content/public/browser/web_contents.h"
14 #include "ui/base/window_open_disposition.h"
15 #include "ui/views/controls/message_box_view.h"
16 #include "ui/views/layout/layout_constants.h"
17 #include "ui/views/widget/widget.h"
18 #include "ui/views/window/dialog_client_view.h"
20 // static
21 TabModalConfirmDialog* TabModalConfirmDialog::Create(
22 TabModalConfirmDialogDelegate* delegate,
23 content::WebContents* web_contents) {
24 return new TabModalConfirmDialogViews(delegate, web_contents);
27 //////////////////////////////////////////////////////////////////////////////
28 // TabModalConfirmDialogViews, constructor & destructor:
30 TabModalConfirmDialogViews::TabModalConfirmDialogViews(
31 TabModalConfirmDialogDelegate* delegate,
32 content::WebContents* web_contents)
33 : delegate_(delegate) {
34 views::MessageBoxView::InitParams init_params(delegate->GetDialogMessage());
35 init_params.inter_row_vertical_spacing =
36 views::kUnrelatedControlVerticalSpacing;
37 message_box_view_ = new views::MessageBoxView(init_params);
39 base::string16 link_text(delegate->GetLinkText());
40 if (!link_text.empty())
41 message_box_view_->SetLink(link_text, this);
43 constrained_window::ShowWebModalDialogViews(this, web_contents);
44 delegate_->set_close_delegate(this);
47 TabModalConfirmDialogViews::~TabModalConfirmDialogViews() {
50 void TabModalConfirmDialogViews::AcceptTabModalDialog() {
51 GetDialogClientView()->AcceptWindow();
54 void TabModalConfirmDialogViews::CancelTabModalDialog() {
55 GetDialogClientView()->CancelWindow();
58 void TabModalConfirmDialogViews::CloseDialog() {
59 GetWidget()->Close();
62 //////////////////////////////////////////////////////////////////////////////
63 // TabModalConfirmDialogViews, views::LinkListener implementation:
65 void TabModalConfirmDialogViews::LinkClicked(views::Link* source,
66 int event_flags) {
67 delegate_->LinkClicked(ui::DispositionFromEventFlags(event_flags));
70 //////////////////////////////////////////////////////////////////////////////
71 // TabModalConfirmDialogViews, views::DialogDelegate implementation:
73 base::string16 TabModalConfirmDialogViews::GetWindowTitle() const {
74 return delegate_->GetTitle();
77 base::string16 TabModalConfirmDialogViews::GetDialogButtonLabel(
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();
83 return base::string16();
86 bool TabModalConfirmDialogViews::Cancel() {
87 delegate_->Cancel();
88 return true;
91 bool TabModalConfirmDialogViews::Accept() {
92 delegate_->Accept();
93 return true;
96 bool TabModalConfirmDialogViews::Close() {
97 delegate_->Close();
98 return true;
101 ///////////////////////////////////////////////////////////////////////////////
102 // TabModalConfirmDialogViews, views::WidgetDelegate implementation:
104 views::View* TabModalConfirmDialogViews::GetContentsView() {
105 return message_box_view_;
108 views::Widget* TabModalConfirmDialogViews::GetWidget() {
109 return message_box_view_->GetWidget();
112 const views::Widget* TabModalConfirmDialogViews::GetWidget() const {
113 return message_box_view_->GetWidget();
116 void TabModalConfirmDialogViews::DeleteDelegate() {
117 delete this;
120 ui::ModalType TabModalConfirmDialogViews::GetModalType() const {
121 return ui::MODAL_TYPE_CHILD;