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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 return new TabModalConfirmDialogViews( | 32 return new TabModalConfirmDialogViews( |
33 delegate, web_contents); | 33 delegate, web_contents); |
34 } | 34 } |
35 | 35 |
36 ////////////////////////////////////////////////////////////////////////////// | 36 ////////////////////////////////////////////////////////////////////////////// |
37 // TabModalConfirmDialogViews, constructor & destructor: | 37 // TabModalConfirmDialogViews, constructor & destructor: |
38 | 38 |
39 TabModalConfirmDialogViews::TabModalConfirmDialogViews( | 39 TabModalConfirmDialogViews::TabModalConfirmDialogViews( |
40 TabModalConfirmDialogDelegate* delegate, | 40 TabModalConfirmDialogDelegate* delegate, |
41 content::WebContents* web_contents) | 41 content::WebContents* web_contents) |
42 : web_contents_(web_contents), | 42 : delegate_(delegate), |
43 delegate_(delegate), | |
44 dialog_(NULL), | 43 dialog_(NULL), |
45 browser_context_(web_contents->GetBrowserContext()) { | 44 browser_context_(web_contents->GetBrowserContext()) { |
46 views::MessageBoxView::InitParams init_params(delegate->GetMessage()); | 45 views::MessageBoxView::InitParams init_params(delegate->GetMessage()); |
47 init_params.inter_row_vertical_spacing = | 46 init_params.inter_row_vertical_spacing = |
48 views::kUnrelatedControlVerticalSpacing; | 47 views::kUnrelatedControlVerticalSpacing; |
49 message_box_view_ = new views::MessageBoxView(init_params); | 48 message_box_view_ = new views::MessageBoxView(init_params); |
50 | 49 |
51 string16 link_text(delegate->GetLinkText()); | 50 string16 link_text(delegate->GetLinkText()); |
52 if (!link_text.empty()) | 51 if (!link_text.empty()) |
53 message_box_view_->SetLink(link_text, this); | 52 message_box_view_->SetLink(link_text, this); |
54 | 53 |
55 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 54 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
56 WebContentsModalDialogManager::FromWebContents(web_contents); | 55 WebContentsModalDialogManager::FromWebContents(web_contents); |
57 dialog_ = CreateWebContentsModalDialogViews( | 56 dialog_ = CreateWebContentsModalDialogViews( |
58 this, | 57 this, |
59 web_contents->GetView()->GetNativeView(), | 58 web_contents->GetView()->GetNativeView(), |
60 web_contents_modal_dialog_manager->delegate()-> | 59 web_contents_modal_dialog_manager->delegate()-> |
61 GetWebContentsModalDialogHost()); | 60 GetWebContentsModalDialogHost()); |
62 web_contents_modal_dialog_manager->ShowDialog(dialog_->GetNativeView()); | 61 web_contents_modal_dialog_manager->ShowDialog(dialog_->GetNativeView()); |
63 delegate_->set_operations_delegate(this); | 62 delegate_->set_close_delegate(this); |
64 } | 63 } |
65 | 64 |
66 TabModalConfirmDialogViews::~TabModalConfirmDialogViews() { | 65 TabModalConfirmDialogViews::~TabModalConfirmDialogViews() { |
67 } | 66 } |
68 | 67 |
69 void TabModalConfirmDialogViews::AcceptTabModalDialog() { | 68 void TabModalConfirmDialogViews::AcceptTabModalDialog() { |
70 GetDialogClientView()->AcceptWindow(); | 69 GetDialogClientView()->AcceptWindow(); |
71 } | 70 } |
72 | 71 |
73 void TabModalConfirmDialogViews::CancelTabModalDialog() { | 72 void TabModalConfirmDialogViews::CancelTabModalDialog() { |
74 GetDialogClientView()->CancelWindow(); | 73 GetDialogClientView()->CancelWindow(); |
75 } | 74 } |
76 | 75 |
77 void TabModalConfirmDialogViews::CloseDialog() { | 76 void TabModalConfirmDialogViews::CloseDialog() { |
78 dialog_->Close(); | 77 dialog_->Close(); |
79 } | 78 } |
80 | 79 |
81 void TabModalConfirmDialogViews::SetPreventCloseOnLoadStart(bool prevent) { | |
82 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | |
83 WebContentsModalDialogManager::FromWebContents(web_contents_); | |
84 web_contents_modal_dialog_manager->SetPreventCloseOnLoadStart( | |
85 dialog_->GetNativeView(), prevent); | |
86 } | |
87 | |
88 ////////////////////////////////////////////////////////////////////////////// | 80 ////////////////////////////////////////////////////////////////////////////// |
89 // TabModalConfirmDialogViews, views::LinkListener implementation: | 81 // TabModalConfirmDialogViews, views::LinkListener implementation: |
90 | 82 |
91 void TabModalConfirmDialogViews::LinkClicked(views::Link* source, | 83 void TabModalConfirmDialogViews::LinkClicked(views::Link* source, |
92 int event_flags) { | 84 int event_flags) { |
93 delegate_->LinkClicked(ui::DispositionFromEventFlags(event_flags)); | 85 delegate_->LinkClicked(ui::DispositionFromEventFlags(event_flags)); |
94 } | 86 } |
95 | 87 |
96 ////////////////////////////////////////////////////////////////////////////// | 88 ////////////////////////////////////////////////////////////////////////////// |
97 // TabModalConfirmDialogViews, views::DialogDelegate implementation: | 89 // TabModalConfirmDialogViews, views::DialogDelegate implementation: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 delete this; | 137 delete this; |
146 } | 138 } |
147 | 139 |
148 ui::ModalType TabModalConfirmDialogViews::GetModalType() const { | 140 ui::ModalType TabModalConfirmDialogViews::GetModalType() const { |
149 #if defined(USE_ASH) | 141 #if defined(USE_ASH) |
150 return ui::MODAL_TYPE_CHILD; | 142 return ui::MODAL_TYPE_CHILD; |
151 #else | 143 #else |
152 return views::WidgetDelegate::GetModalType(); | 144 return views::WidgetDelegate::GetModalType(); |
153 #endif | 145 #endif |
154 } | 146 } |
OLD | NEW |