Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: chrome/browser/views/jsmessage_box_dialog.cc

Issue 560030: Refactored out JS specific part of modal dialog stack into its own class, exp... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/jsmessage_box_dialog.h" 5 #include "chrome/browser/views/jsmessage_box_dialog.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/message_box_flags.h" 8 #include "app/message_box_flags.h"
9 #include "base/keyboard_codes.h" 9 #include "base/keyboard_codes.h"
10 #include "chrome/browser/app_modal_dialog.h" 10 #include "chrome/browser/app_modal_dialog.h"
11 #include "chrome/browser/tab_contents/tab_contents.h" 11 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "grit/generated_resources.h" 12 #include "grit/generated_resources.h"
13 #include "views/controls/message_box_view.h" 13 #include "views/controls/message_box_view.h"
14 #include "views/window/window.h" 14 #include "views/window/window.h"
15 15
16 JavascriptMessageBoxDialog::JavascriptMessageBoxDialog( 16 JavaScriptMessageBoxDialog::JavaScriptMessageBoxDialog(
17 AppModalDialog* parent, 17 JavaScriptAppModalDialog* parent,
18 const std::wstring& message_text, 18 const std::wstring& message_text,
19 const std::wstring& default_prompt_text, 19 const std::wstring& default_prompt_text,
20 bool display_suppress_checkbox) 20 bool display_suppress_checkbox)
21 : parent_(parent), 21 : parent_(parent),
22 dialog_(NULL),
23 message_box_view_(new MessageBoxView( 22 message_box_view_(new MessageBoxView(
24 parent->dialog_flags() | MessageBoxFlags::kAutoDetectAlignment, 23 parent->dialog_flags() | MessageBoxFlags::kAutoDetectAlignment,
25 message_text, default_prompt_text)) { 24 message_text, default_prompt_text)) {
26 DCHECK(message_box_view_); 25 DCHECK(message_box_view_);
27 26
28 message_box_view_->AddAccelerator( 27 message_box_view_->AddAccelerator(
29 views::Accelerator(base::VKEY_C, false, true, false)); 28 views::Accelerator(base::VKEY_C, false, true, false));
30 if (display_suppress_checkbox) { 29 if (display_suppress_checkbox) {
31 message_box_view_->SetCheckBoxLabel( 30 message_box_view_->SetCheckBoxLabel(
32 l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION)); 31 l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION));
33 } 32 }
34 } 33 }
35 34
36 JavascriptMessageBoxDialog::~JavascriptMessageBoxDialog() { 35 JavaScriptMessageBoxDialog::~JavaScriptMessageBoxDialog() {
37 } 36 }
38 37
39 void JavascriptMessageBoxDialog::ShowModalDialog() { 38 gfx::NativeWindow JavaScriptMessageBoxDialog::GetDialogRootWindow() {
40 gfx::NativeWindow root_hwnd = client()->GetMessageBoxRootWindow(); 39 return client()->GetMessageBoxRootWindow();
41 // GetMessageBoxRootWindow() will be NULL if there's no selected tab (e.g.,
42 // during shutdown), in which case we simply skip showing this dialog.
43 if (!root_hwnd) {
44 Cancel();
45 } else {
46 dialog_ = views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this);
47 dialog_->Show();
48 }
49 }
50
51 void JavascriptMessageBoxDialog::ActivateModalDialog() {
52 // Ensure that the dialog is visible and at the top of the z-order. These
53 // conditions may not be true if the dialog was opened on a different virtual
54 // desktop to the one the browser window is on.
55 dialog_->Show();
56 dialog_->Activate();
57 }
58
59 void JavascriptMessageBoxDialog::CloseModalDialog() {
60 // If the dialog is visible close it.
61 if (dialog_)
62 dialog_->Close();
63 } 40 }
64 41
65 ////////////////////////////////////////////////////////////////////////////// 42 //////////////////////////////////////////////////////////////////////////////
66 // JavascriptMessageBoxDialog, views::DialogDelegate implementation: 43 // JavaScriptMessageBoxDialog, views::DialogDelegate implementation:
67 44
68 int JavascriptMessageBoxDialog::GetDialogButtons() const { 45 int JavaScriptMessageBoxDialog::GetDialogButtons() const {
69 int dialog_buttons = 0; 46 int dialog_buttons = 0;
70 if (parent_->dialog_flags() & MessageBoxFlags::kFlagHasOKButton) 47 if (parent_->dialog_flags() & MessageBoxFlags::kFlagHasOKButton)
71 dialog_buttons = MessageBoxFlags::DIALOGBUTTON_OK; 48 dialog_buttons = MessageBoxFlags::DIALOGBUTTON_OK;
72 49
73 if (parent_->dialog_flags() & MessageBoxFlags::kFlagHasCancelButton) 50 if (parent_->dialog_flags() & MessageBoxFlags::kFlagHasCancelButton)
74 dialog_buttons |= MessageBoxFlags::DIALOGBUTTON_CANCEL; 51 dialog_buttons |= MessageBoxFlags::DIALOGBUTTON_CANCEL;
75 52
76 return dialog_buttons; 53 return dialog_buttons;
77 } 54 }
78 55
79 std::wstring JavascriptMessageBoxDialog::GetWindowTitle() const { 56 std::wstring JavaScriptMessageBoxDialog::GetWindowTitle() const {
80 return parent_->title(); 57 return parent_->title();
81 } 58 }
82 59
83 60
84 void JavascriptMessageBoxDialog::WindowClosing() { 61 void JavaScriptMessageBoxDialog::WindowClosing() {
85 dialog_ = NULL; 62 dialog_ = NULL;
86 } 63 }
87 64
88 void JavascriptMessageBoxDialog::DeleteDelegate() { 65 void JavaScriptMessageBoxDialog::DeleteDelegate() {
89 delete parent_; 66 delete parent_;
90 delete this; 67 delete this;
91 } 68 }
92 69
93 bool JavascriptMessageBoxDialog::Cancel() { 70 bool JavaScriptMessageBoxDialog::Cancel() {
94 parent_->OnCancel(); 71 parent_->OnCancel();
95 return true; 72 return true;
96 } 73 }
97 74
98 bool JavascriptMessageBoxDialog::Accept() { 75 bool JavaScriptMessageBoxDialog::Accept() {
99 parent_->OnAccept(message_box_view_->GetInputText(), 76 parent_->OnAccept(message_box_view_->GetInputText(),
100 message_box_view_->IsCheckBoxSelected()); 77 message_box_view_->IsCheckBoxSelected());
101 return true; 78 return true;
102 } 79 }
103 80
104 void JavascriptMessageBoxDialog::OnClose() { 81 void JavaScriptMessageBoxDialog::OnClose() {
105 parent_->OnClose(); 82 parent_->OnClose();
106 } 83 }
107 84
108 std::wstring JavascriptMessageBoxDialog::GetDialogButtonLabel( 85 std::wstring JavaScriptMessageBoxDialog::GetDialogButtonLabel(
109 MessageBoxFlags::DialogButton button) const { 86 MessageBoxFlags::DialogButton button) const {
110 if (parent_->is_before_unload_dialog()) { 87 if (parent_->is_before_unload_dialog()) {
111 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { 88 if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
112 return l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL); 89 return l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL);
113 } else if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) { 90 } else if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) {
114 return l10n_util::GetString( 91 return l10n_util::GetString(
115 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL); 92 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
116 } 93 }
117 } 94 }
118 return DialogDelegate::GetDialogButtonLabel(button); 95 return DialogDelegate::GetDialogButtonLabel(button);
119 } 96 }
120 97
121 /////////////////////////////////////////////////////////////////////////////// 98 ///////////////////////////////////////////////////////////////////////////////
122 // JavascriptMessageBoxDialog, views::WindowDelegate implementation: 99 // JavaScriptMessageBoxDialog, views::WindowDelegate implementation:
123 100
124 views::View* JavascriptMessageBoxDialog::GetContentsView() { 101 views::View* JavaScriptMessageBoxDialog::GetContentsView() {
125 return message_box_view_; 102 return message_box_view_;
126 } 103 }
127 104
128 views::View* JavascriptMessageBoxDialog::GetInitiallyFocusedView() { 105 views::View* JavaScriptMessageBoxDialog::GetInitiallyFocusedView() {
129 if (message_box_view_->text_box()) 106 if (message_box_view_->text_box())
130 return message_box_view_->text_box(); 107 return message_box_view_->text_box();
131 return views::DialogDelegate::GetInitiallyFocusedView(); 108 return views::DialogDelegate::GetInitiallyFocusedView();
132 } 109 }
OLDNEW
« no previous file with comments | « chrome/browser/views/jsmessage_box_dialog.h ('k') | chrome/browser/views/modal_dialog_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698