| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/simple_message_box_views.h" | 5 #include "chrome/browser/ui/views/simple_message_box_views.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/simple_message_box.h" | 9 #include "chrome/browser/simple_message_box.h" |
| 10 #include "chrome/browser/ui/dialog_style.h" | 10 #include "chrome/browser/ui/dialog_style.h" |
| 11 #include "chrome/browser/ui/views/window.h" | 11 #include "chrome/browser/ui/views/window.h" |
| 12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/message_box_flags.h" | |
| 15 #include "ui/views/controls/message_box_view.h" | 14 #include "ui/views/controls/message_box_view.h" |
| 16 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 17 | 16 |
| 18 #if defined(USE_AURA) | 17 #if defined(USE_AURA) |
| 19 #include "ui/views/focus/accelerator_handler.h" | 18 #include "ui/views/focus/accelerator_handler.h" |
| 20 #endif | 19 #endif |
| 21 | 20 |
| 22 namespace browser { | 21 namespace browser { |
| 23 | 22 |
| 24 void ShowErrorBox(gfx::NativeWindow parent, | 23 void ShowErrorBox(gfx::NativeWindow parent, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 | 34 |
| 36 } // namespace browser | 35 } // namespace browser |
| 37 | 36 |
| 38 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
| 39 // SimpleMessageBoxViews, public: | 38 // SimpleMessageBoxViews, public: |
| 40 | 39 |
| 41 // static | 40 // static |
| 42 void SimpleMessageBoxViews::ShowErrorBox(gfx::NativeWindow parent_window, | 41 void SimpleMessageBoxViews::ShowErrorBox(gfx::NativeWindow parent_window, |
| 43 const string16& title, | 42 const string16& title, |
| 44 const string16& message) { | 43 const string16& message) { |
| 45 int dialog_flags = ui::MessageBoxFlags::kFlagHasMessage | | |
| 46 ui::MessageBoxFlags::kFlagHasOKButton; | |
| 47 | |
| 48 // This is a reference counted object so it is given an initial increment | 44 // This is a reference counted object so it is given an initial increment |
| 49 // in the constructor with a corresponding decrement in DeleteDelegate(). | 45 // in the constructor with a corresponding decrement in DeleteDelegate(). |
| 50 new SimpleMessageBoxViews(parent_window, dialog_flags, title, message); | 46 new SimpleMessageBoxViews(parent_window, DIALOG_ERROR, title, message); |
| 51 } | 47 } |
| 52 | 48 |
| 53 bool SimpleMessageBoxViews::ShowYesNoBox(gfx::NativeWindow parent_window, | 49 bool SimpleMessageBoxViews::ShowYesNoBox(gfx::NativeWindow parent_window, |
| 54 const string16& title, | 50 const string16& title, |
| 55 const string16& message) { | 51 const string16& message) { |
| 56 int dialog_flags = ui::MessageBoxFlags::kIsConfirmMessageBox; | |
| 57 | |
| 58 // This is a reference counted object so it is given an initial increment | 52 // This is a reference counted object so it is given an initial increment |
| 59 // in the constructor plus an extra one below to ensure the dialog persists | 53 // in the constructor plus an extra one below to ensure the dialog persists |
| 60 // until we retrieve the user response.. | 54 // until we retrieve the user response.. |
| 61 scoped_refptr<SimpleMessageBoxViews> dialog = | 55 scoped_refptr<SimpleMessageBoxViews> dialog = |
| 62 new SimpleMessageBoxViews(parent_window, dialog_flags, title, message); | 56 new SimpleMessageBoxViews(parent_window, DIALOG_YES_NO, title, message); |
| 63 | 57 |
| 64 // Make sure Chrome doesn't attempt to shut down with the dialog up. | 58 // Make sure Chrome doesn't attempt to shut down with the dialog up. |
| 65 g_browser_process->AddRefModule(); | 59 g_browser_process->AddRefModule(); |
| 66 | 60 |
| 67 bool old_state = MessageLoopForUI::current()->NestableTasksAllowed(); | 61 bool old_state = MessageLoopForUI::current()->NestableTasksAllowed(); |
| 68 MessageLoopForUI::current()->SetNestableTasksAllowed(true); | 62 MessageLoopForUI::current()->SetNestableTasksAllowed(true); |
| 69 MessageLoopForUI::current()->RunWithDispatcher(dialog); | 63 MessageLoopForUI::current()->RunWithDispatcher(dialog); |
| 70 MessageLoopForUI::current()->SetNestableTasksAllowed(old_state); | 64 MessageLoopForUI::current()->SetNestableTasksAllowed(old_state); |
| 71 | 65 |
| 72 g_browser_process->ReleaseModule(); | 66 g_browser_process->ReleaseModule(); |
| 73 | 67 |
| 74 return dialog->Accepted(); | 68 return dialog->Accepted(); |
| 75 } | 69 } |
| 76 | 70 |
| 77 bool SimpleMessageBoxViews::Cancel() { | 71 bool SimpleMessageBoxViews::Cancel() { |
| 78 disposition_ = DISPOSITION_CANCEL; | 72 disposition_ = DISPOSITION_CANCEL; |
| 79 return true; | 73 return true; |
| 80 } | 74 } |
| 81 | 75 |
| 82 bool SimpleMessageBoxViews::Accept() { | 76 bool SimpleMessageBoxViews::Accept() { |
| 83 disposition_ = DISPOSITION_OK; | 77 disposition_ = DISPOSITION_OK; |
| 84 return true; | 78 return true; |
| 85 } | 79 } |
| 86 | 80 |
| 87 int SimpleMessageBoxViews::GetDialogButtons() const { | 81 int SimpleMessageBoxViews::GetDialogButtons() const { |
| 88 // NOTE: It seems unsafe to assume that the flags for OK/cancel will always | 82 if (type_ == DIALOG_ERROR) |
| 89 // have the same value as the button ids. | 83 return ui::DIALOG_BUTTON_OK; |
| 90 int dialog_buttons = ui::DIALOG_BUTTON_NONE; | 84 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
| 91 if (dialog_flags_ & ui::MessageBoxFlags::kFlagHasOKButton) | |
| 92 dialog_buttons = ui::DIALOG_BUTTON_OK; | |
| 93 | |
| 94 if (dialog_flags_ & ui::MessageBoxFlags::kFlagHasCancelButton) | |
| 95 dialog_buttons |= ui::DIALOG_BUTTON_CANCEL; | |
| 96 | |
| 97 return dialog_buttons; | |
| 98 } | 85 } |
| 99 | 86 |
| 100 string16 SimpleMessageBoxViews::GetDialogButtonLabel( | 87 string16 SimpleMessageBoxViews::GetDialogButtonLabel( |
| 101 ui::DialogButton button) const { | 88 ui::DialogButton button) const { |
| 102 return button == ui::DIALOG_BUTTON_OK ? l10n_util::GetStringUTF16(IDS_OK) | 89 return button == ui::DIALOG_BUTTON_OK ? l10n_util::GetStringUTF16(IDS_OK) |
| 103 : l10n_util::GetStringUTF16(IDS_CLOSE); | 90 : l10n_util::GetStringUTF16(IDS_CLOSE); |
| 104 } | 91 } |
| 105 | 92 |
| 106 bool SimpleMessageBoxViews::ShouldShowWindowTitle() const { | 93 bool SimpleMessageBoxViews::ShouldShowWindowTitle() const { |
| 107 return true; | 94 return true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 128 } | 115 } |
| 129 | 116 |
| 130 const views::Widget* SimpleMessageBoxViews::GetWidget() const { | 117 const views::Widget* SimpleMessageBoxViews::GetWidget() const { |
| 131 return message_box_view_->GetWidget(); | 118 return message_box_view_->GetWidget(); |
| 132 } | 119 } |
| 133 | 120 |
| 134 //////////////////////////////////////////////////////////////////////////////// | 121 //////////////////////////////////////////////////////////////////////////////// |
| 135 // SimpleMessageBoxViews, private: | 122 // SimpleMessageBoxViews, private: |
| 136 | 123 |
| 137 SimpleMessageBoxViews::SimpleMessageBoxViews(gfx::NativeWindow parent_window, | 124 SimpleMessageBoxViews::SimpleMessageBoxViews(gfx::NativeWindow parent_window, |
| 138 int dialog_flags, | 125 DialogType type, |
| 139 const string16& title, | 126 const string16& title, |
| 140 const string16& message) | 127 const string16& message) |
| 141 : dialog_flags_(dialog_flags), | 128 : type_(type), |
| 142 disposition_(DISPOSITION_UNKNOWN) { | 129 disposition_(DISPOSITION_UNKNOWN) { |
| 143 message_box_title_ = title; | 130 message_box_title_ = title; |
| 144 message_box_view_ = new views::MessageBoxView(dialog_flags, | 131 message_box_view_ = new views::MessageBoxView( |
| 145 message, | 132 views::MessageBoxView::NO_OPTIONS, |
| 146 string16()); | 133 message, |
| 134 string16()); |
| 147 browser::CreateViewsWindow(parent_window, this, STYLE_GENERIC)->Show(); | 135 browser::CreateViewsWindow(parent_window, this, STYLE_GENERIC)->Show(); |
| 148 | 136 |
| 149 // Add reference to be released in DeleteDelegate(). | 137 // Add reference to be released in DeleteDelegate(). |
| 150 AddRef(); | 138 AddRef(); |
| 151 } | 139 } |
| 152 | 140 |
| 153 SimpleMessageBoxViews::~SimpleMessageBoxViews() { | 141 SimpleMessageBoxViews::~SimpleMessageBoxViews() { |
| 154 } | 142 } |
| 155 | 143 |
| 156 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 168 if (disposition_ == DISPOSITION_UNKNOWN) | 156 if (disposition_ == DISPOSITION_UNKNOWN) |
| 169 return base::MessagePumpDispatcher::EVENT_PROCESSED; | 157 return base::MessagePumpDispatcher::EVENT_PROCESSED; |
| 170 return base::MessagePumpDispatcher::EVENT_QUIT; | 158 return base::MessagePumpDispatcher::EVENT_QUIT; |
| 171 } | 159 } |
| 172 #else | 160 #else |
| 173 bool SimpleMessageBoxViews::Dispatch(GdkEvent* event) { | 161 bool SimpleMessageBoxViews::Dispatch(GdkEvent* event) { |
| 174 gtk_main_do_event(event); | 162 gtk_main_do_event(event); |
| 175 return disposition_ == DISPOSITION_UNKNOWN; | 163 return disposition_ == DISPOSITION_UNKNOWN; |
| 176 } | 164 } |
| 177 #endif | 165 #endif |
| OLD | NEW |