OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/views/jsmessage_box_dialog.h" |
| 6 |
| 7 #include "chrome/browser/app_modal_dialog.h" |
| 8 #include "chrome/browser/tab_contents/web_contents.h" |
| 9 #include "chrome/common/l10n_util.h" |
| 10 #include "chrome/common/message_box_flags.h" |
| 11 #include "chrome/views/controls/message_box_view.h" |
| 12 #include "chrome/views/window/window.h" |
| 13 #include "grit/generated_resources.h" |
| 14 |
| 15 JavascriptMessageBoxDialog::JavascriptMessageBoxDialog( |
| 16 AppModalDialog* parent, |
| 17 const std::wstring& message_text, |
| 18 const std::wstring& default_prompt_text, |
| 19 bool display_suppress_checkbox) |
| 20 : parent_(parent), |
| 21 dialog_(NULL), |
| 22 message_box_view_(new MessageBoxView( |
| 23 parent->dialog_flags() | MessageBox::kAutoDetectAlignment, |
| 24 message_text, default_prompt_text)) { |
| 25 DCHECK(message_box_view_); |
| 26 |
| 27 if (display_suppress_checkbox) { |
| 28 message_box_view_->SetCheckBoxLabel( |
| 29 l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION)); |
| 30 } |
| 31 } |
| 32 |
| 33 JavascriptMessageBoxDialog::~JavascriptMessageBoxDialog() { |
| 34 } |
| 35 |
| 36 void JavascriptMessageBoxDialog::ShowModalDialog() { |
| 37 HWND root_hwnd = GetAncestor(web_contents()->GetNativeView(), |
| 38 GA_ROOT); |
| 39 dialog_ = views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this); |
| 40 dialog_->Show(); |
| 41 } |
| 42 |
| 43 void JavascriptMessageBoxDialog::ActivateModalDialog() { |
| 44 // Ensure that the dialog is visible and at the top of the z-order. These |
| 45 // conditions may not be true if the dialog was opened on a different virtual |
| 46 // desktop to the one the browser window is on. |
| 47 dialog_->Show(); |
| 48 dialog_->Activate(); |
| 49 } |
| 50 |
| 51 void JavascriptMessageBoxDialog::CloseModalDialog() { |
| 52 // If the dialog is visible close it. |
| 53 if (dialog_) |
| 54 dialog_->Close(); |
| 55 } |
| 56 |
| 57 ////////////////////////////////////////////////////////////////////////////// |
| 58 // JavascriptMessageBoxDialog, views::DialogDelegate implementation: |
| 59 |
| 60 int JavascriptMessageBoxDialog::GetDialogButtons() const { |
| 61 int dialog_buttons = 0; |
| 62 if (parent_->dialog_flags() & MessageBox::kFlagHasOKButton) |
| 63 dialog_buttons = DIALOGBUTTON_OK; |
| 64 |
| 65 if (parent_->dialog_flags() & MessageBox::kFlagHasCancelButton) |
| 66 dialog_buttons |= DIALOGBUTTON_CANCEL; |
| 67 |
| 68 return dialog_buttons; |
| 69 } |
| 70 |
| 71 std::wstring JavascriptMessageBoxDialog::GetWindowTitle() const { |
| 72 return parent_->title();; |
| 73 } |
| 74 |
| 75 |
| 76 void JavascriptMessageBoxDialog::WindowClosing() { |
| 77 dialog_ = NULL; |
| 78 |
| 79 } |
| 80 |
| 81 void JavascriptMessageBoxDialog::DeleteDelegate() { |
| 82 delete parent_; |
| 83 delete this; |
| 84 } |
| 85 |
| 86 bool JavascriptMessageBoxDialog::Cancel() { |
| 87 parent_->OnCancel(); |
| 88 return true; |
| 89 } |
| 90 |
| 91 bool JavascriptMessageBoxDialog::Accept() { |
| 92 |
| 93 parent_->OnAccept(message_box_view_->GetInputText(), |
| 94 message_box_view_->IsCheckBoxSelected()); |
| 95 return true; |
| 96 } |
| 97 |
| 98 std::wstring JavascriptMessageBoxDialog::GetDialogButtonLabel( |
| 99 DialogButton button) const { |
| 100 if (parent_->is_before_unload_dialog()) { |
| 101 if (button == DialogDelegate::DIALOGBUTTON_OK) { |
| 102 return l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL); |
| 103 } else if (button == DialogDelegate::DIALOGBUTTON_CANCEL) { |
| 104 return l10n_util::GetString( |
| 105 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL); |
| 106 } |
| 107 } |
| 108 return DialogDelegate::GetDialogButtonLabel(button); |
| 109 } |
| 110 |
| 111 /////////////////////////////////////////////////////////////////////////////// |
| 112 // JavascriptMessageBoxDialog, views::WindowDelegate implementation: |
| 113 |
| 114 views::View* JavascriptMessageBoxDialog::GetContentsView() { |
| 115 return message_box_view_; |
| 116 } |
| 117 |
| 118 views::View* JavascriptMessageBoxDialog::GetInitiallyFocusedView() { |
| 119 if (message_box_view_->text_box()) |
| 120 return message_box_view_->text_box(); |
| 121 return views::DialogDelegate::GetInitiallyFocusedView(); |
| 122 } |
OLD | NEW |