Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / tab_modal_confirm_dialog_views.cc
blobd0bbd9b1c33669bdbfb8536ccdb26d2d0a87fbb1
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/browser/ui/tab_modal_confirm_dialog_delegate.h"
12 #include "chrome/browser/ui/views/constrained_window_views.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "components/web_modal/web_contents_modal_dialog_host.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager.h"
16 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
17 #include "content/public/browser/web_contents.h"
18 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/window_open_disposition.h"
21 #include "ui/views/controls/message_box_view.h"
22 #include "ui/views/layout/layout_constants.h"
23 #include "ui/views/widget/widget.h"
24 #include "ui/views/window/dialog_client_view.h"
26 using web_modal::WebContentsModalDialogManager;
27 using web_modal::WebContentsModalDialogManagerDelegate;
29 // static
30 TabModalConfirmDialog* TabModalConfirmDialog::Create(
31 TabModalConfirmDialogDelegate* delegate,
32 content::WebContents* web_contents) {
33 return new TabModalConfirmDialogViews(
34 delegate, web_contents);
37 //////////////////////////////////////////////////////////////////////////////
38 // TabModalConfirmDialogViews, constructor & destructor:
40 TabModalConfirmDialogViews::TabModalConfirmDialogViews(
41 TabModalConfirmDialogDelegate* delegate,
42 content::WebContents* web_contents)
43 : delegate_(delegate),
44 dialog_(NULL),
45 browser_context_(web_contents->GetBrowserContext()) {
46 views::MessageBoxView::InitParams init_params(delegate->GetMessage());
47 init_params.inter_row_vertical_spacing =
48 views::kUnrelatedControlVerticalSpacing;
49 message_box_view_ = new views::MessageBoxView(init_params);
51 base::string16 link_text(delegate->GetLinkText());
52 if (!link_text.empty())
53 message_box_view_->SetLink(link_text, this);
55 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
56 WebContentsModalDialogManager::FromWebContents(web_contents);
57 WebContentsModalDialogManagerDelegate* modal_delegate =
58 web_contents_modal_dialog_manager->delegate();
59 DCHECK(modal_delegate);
60 dialog_ = views::Widget::CreateWindowAsFramelessChild(
61 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView());
62 web_contents_modal_dialog_manager->ShowDialog(dialog_->GetNativeView());
63 delegate_->set_close_delegate(this);
66 TabModalConfirmDialogViews::~TabModalConfirmDialogViews() {
69 void TabModalConfirmDialogViews::AcceptTabModalDialog() {
70 GetDialogClientView()->AcceptWindow();
73 void TabModalConfirmDialogViews::CancelTabModalDialog() {
74 GetDialogClientView()->CancelWindow();
77 void TabModalConfirmDialogViews::CloseDialog() {
78 dialog_->Close();
81 //////////////////////////////////////////////////////////////////////////////
82 // TabModalConfirmDialogViews, views::LinkListener implementation:
84 void TabModalConfirmDialogViews::LinkClicked(views::Link* source,
85 int event_flags) {
86 delegate_->LinkClicked(ui::DispositionFromEventFlags(event_flags));
89 //////////////////////////////////////////////////////////////////////////////
90 // TabModalConfirmDialogViews, views::DialogDelegate implementation:
92 base::string16 TabModalConfirmDialogViews::GetWindowTitle() const {
93 return delegate_->GetTitle();
96 base::string16 TabModalConfirmDialogViews::GetDialogButtonLabel(
97 ui::DialogButton button) const {
98 if (button == ui::DIALOG_BUTTON_OK)
99 return delegate_->GetAcceptButtonTitle();
100 if (button == ui::DIALOG_BUTTON_CANCEL)
101 return delegate_->GetCancelButtonTitle();
102 return base::string16();
105 bool TabModalConfirmDialogViews::Cancel() {
106 delegate_->Cancel();
107 return true;
110 bool TabModalConfirmDialogViews::Accept() {
111 delegate_->Accept();
112 return true;
115 bool TabModalConfirmDialogViews::Close() {
116 delegate_->Close();
117 return true;
120 ///////////////////////////////////////////////////////////////////////////////
121 // TabModalConfirmDialogViews, views::WidgetDelegate implementation:
123 views::View* TabModalConfirmDialogViews::GetContentsView() {
124 return message_box_view_;
127 // TODO(wittman): Remove this override once we move to the new style frame view
128 // on all dialogs.
129 views::NonClientFrameView* TabModalConfirmDialogViews::CreateNonClientFrameView(
130 views::Widget* widget) {
131 return CreateConstrainedStyleNonClientFrameView(widget, browser_context_);
134 views::Widget* TabModalConfirmDialogViews::GetWidget() {
135 return message_box_view_->GetWidget();
138 const views::Widget* TabModalConfirmDialogViews::GetWidget() const {
139 return message_box_view_->GetWidget();
142 void TabModalConfirmDialogViews::DeleteDelegate() {
143 delete this;
146 ui::ModalType TabModalConfirmDialogViews::GetModalType() const {
147 #if defined(USE_ASH)
148 return ui::MODAL_TYPE_CHILD;
149 #else
150 return views::WidgetDelegate::GetModalType();
151 #endif