Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 80772ed | 2011-08-09 21:11:38 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | b50892c5f | 2012-05-13 07:34:14 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_UI_SIMPLE_MESSAGE_BOX_H_ |
| 6 | #define CHROME_BROWSER_UI_SIMPLE_MESSAGE_BOX_H_ |
[email protected] | 80772ed | 2011-08-09 21:11:38 | [diff] [blame] | 7 | |
Jan Wilken Dörrie | ad587c3 | 2021-03-11 14:09:27 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Avi Drissman | 9269d4ed | 2023-01-07 01:38:06 | [diff] [blame] | 10 | #include "base/functional/callback_forward.h" |
[email protected] | 80772ed | 2011-08-09 21:11:38 | [diff] [blame] | 11 | #include "ui/gfx/native_widget_types.h" |
| 12 | |
[email protected] | d3322029 | 2012-07-04 01:41:27 | [diff] [blame] | 13 | namespace chrome { |
[email protected] | 80772ed | 2011-08-09 21:11:38 | [diff] [blame] | 14 | |
[email protected] | 5da155e | 2012-05-26 16:31:16 | [diff] [blame] | 15 | enum MessageBoxResult { |
afakhry | 7c9abe7 | 2016-08-05 17:33:19 | [diff] [blame] | 16 | // User chose NO or CANCEL. If there's a checkbox, then the checkbox was |
| 17 | // unchecked. |
| 18 | MESSAGE_BOX_RESULT_NO = 0, |
| 19 | |
| 20 | // User chose YES or OK. If there's a checkbox, then the checkbox was checked. |
| 21 | MESSAGE_BOX_RESULT_YES = 1, |
Elly Fong-Jones | 165afb9 | 2017-06-29 18:43:28 | [diff] [blame] | 22 | |
| 23 | // Message box was displayed asynchronously and is pending a real result, |
| 24 | // which will be delivered via callback. |
| 25 | MESSAGE_BOX_RESULT_DEFERRED = 2, |
[email protected] | 5da155e | 2012-05-26 16:31:16 | [diff] [blame] | 26 | }; |
| 27 | |
[email protected] | d1f48ef5 | 2012-05-13 19:34:21 | [diff] [blame] | 28 | enum MessageBoxType { |
Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 29 | MESSAGE_BOX_TYPE_WARNING, // Shows an OK button. |
| 30 | MESSAGE_BOX_TYPE_QUESTION, // Shows YES and NO buttons. |
[email protected] | d1f48ef5 | 2012-05-13 19:34:21 | [diff] [blame] | 31 | }; |
| 32 | |
[email protected] | 5da155e | 2012-05-26 16:31:16 | [diff] [blame] | 33 | // Shows a dialog box with the given |title| and |message|. If |parent| is |
| 34 | // non-NULL, the box will be made modal to the |parent|, except on Mac, where it |
[email protected] | 24ced7dc0 | 2013-04-04 08:32:39 | [diff] [blame] | 35 | // is always app-modal. |
[email protected] | 5da155e | 2012-05-26 16:31:16 | [diff] [blame] | 36 | // |
Mihai Sardarescu | ca00b242 | 2018-11-28 10:54:22 | [diff] [blame] | 37 | // If |can_close| is false, then this dialog will not show the close button and |
| 38 | // the dialog will only be dismissed when the user presses the OK button. |
| 39 | // |
[email protected] | 5da155e | 2012-05-26 16:31:16 | [diff] [blame] | 40 | // NOTE: In general, you should avoid this since it's usually poor UI. |
tfarina | 917cff5e | 2015-10-31 01:16:38 | [diff] [blame] | 41 | // We have a variety of other surfaces such as app menu notifications and |
[email protected] | 5da155e | 2012-05-26 16:31:16 | [diff] [blame] | 42 | // infobars; consult the UI leads for a recommendation. |
Mihai Sardarescu | d9faab6a | 2021-11-30 19:03:27 | [diff] [blame] | 43 | MessageBoxResult ShowWarningMessageBox(gfx::NativeWindow parent, |
| 44 | const std::u16string& title, |
| 45 | const std::u16string& message); |
estade | e16f96ed | 2016-03-07 22:57:05 | [diff] [blame] | 46 | |
xiyuan | 2404367 | 2017-06-14 15:17:29 | [diff] [blame] | 47 | // As above, but shows the dialog box asynchronously with a checkbox. |
| 48 | // |callback| will be invoked after the dialog is dismissed. It is invoked with |
| 49 | // true if the checkbox is checked and false otherwise. |
| 50 | void ShowWarningMessageBoxWithCheckbox( |
| 51 | gfx::NativeWindow parent, |
Jan Wilken Dörrie | 3f97e29 | 2021-03-11 18:07:14 | [diff] [blame] | 52 | const std::u16string& title, |
| 53 | const std::u16string& message, |
| 54 | const std::u16string& checkbox_text, |
xiyuan | 2404367 | 2017-06-14 15:17:29 | [diff] [blame] | 55 | base::OnceCallback<void(bool checked)> callback); |
afakhry | 7c9abe7 | 2016-08-05 17:33:19 | [diff] [blame] | 56 | |
estade | e16f96ed | 2016-03-07 22:57:05 | [diff] [blame] | 57 | // As above, but two buttons are displayed and the return value indicates which |
| 58 | // is chosen. |
Collin Baker | 58ae65c | 2021-02-05 21:12:29 | [diff] [blame] | 59 | MessageBoxResult ShowQuestionMessageBoxSync(gfx::NativeWindow parent, |
Jan Wilken Dörrie | 3f97e29 | 2021-03-11 18:07:14 | [diff] [blame] | 60 | const std::u16string& title, |
| 61 | const std::u16string& message); |
Collin Baker | 58ae65c | 2021-02-05 21:12:29 | [diff] [blame] | 62 | |
| 63 | void ShowQuestionMessageBox( |
| 64 | gfx::NativeWindow parent, |
Jan Wilken Dörrie | 3f97e29 | 2021-03-11 18:07:14 | [diff] [blame] | 65 | const std::u16string& title, |
| 66 | const std::u16string& message, |
Collin Baker | 58ae65c | 2021-02-05 21:12:29 | [diff] [blame] | 67 | base::OnceCallback<void(MessageBoxResult)> callback); |
[email protected] | 80772ed | 2011-08-09 21:11:38 | [diff] [blame] | 68 | |
[email protected] | f8ef716 | 2013-11-22 01:56:41 | [diff] [blame] | 69 | // Shows a dialog box with the given |title| and |message|, and with two buttons |
| 70 | // labeled with |yes_text| and |no_text|. If |parent| is non-NULL, the box will |
| 71 | // be made modal to the |parent|. (Aura only.) |
| 72 | // |
| 73 | // NOTE: In general, you should avoid this since it's usually poor UI. |
tfarina | 917cff5e | 2015-10-31 01:16:38 | [diff] [blame] | 74 | // We have a variety of other surfaces such as app menu notifications and |
[email protected] | f8ef716 | 2013-11-22 01:56:41 | [diff] [blame] | 75 | // infobars; consult the UI leads for a recommendation. |
| 76 | MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, |
Jan Wilken Dörrie | 3f97e29 | 2021-03-11 18:07:14 | [diff] [blame] | 77 | const std::u16string& title, |
| 78 | const std::u16string& message, |
| 79 | const std::u16string& yes_text, |
| 80 | const std::u16string& no_text); |
[email protected] | f8ef716 | 2013-11-22 01:56:41 | [diff] [blame] | 81 | |
[email protected] | d3322029 | 2012-07-04 01:41:27 | [diff] [blame] | 82 | } // namespace chrome |
[email protected] | 80772ed | 2011-08-09 21:11:38 | [diff] [blame] | 83 | |
[email protected] | b50892c5f | 2012-05-13 07:34:14 | [diff] [blame] | 84 | #endif // CHROME_BROWSER_UI_SIMPLE_MESSAGE_BOX_H_ |