[email protected] | 677b2a0 | 2012-06-04 21:54:08 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 5 | #ifndef COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_ |
6 | #define COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_ | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
Brett Wilson | 45d6f2d | 2017-08-23 17:01:24 | [diff] [blame] | 8 | #include "base/containers/circular_deque.h" |
avi | bc5337b | 2015-12-25 23:16:33 | [diff] [blame] | 9 | #include "base/macros.h" |
[email protected] | 677b2a0 | 2012-06-04 21:54:08 | [diff] [blame] | 10 | |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 11 | namespace base { |
[email protected] | d3c6c0d7 | 2010-12-09 08:15:04 | [diff] [blame] | 12 | template <typename T> struct DefaultSingletonTraits; |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 13 | } |
[email protected] | d3c6c0d7 | 2010-12-09 08:15:04 | [diff] [blame] | 14 | |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 15 | namespace app_modal { |
16 | |||||
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 17 | class JavaScriptAppModalDialog; |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 18 | |
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 19 | // Keeps a queue of JavaScriptAppModalDialogs, making sure only one app modal |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | // dialog is shown at a time. |
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 21 | // This class is a singleton. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | class AppModalDialogQueue { |
23 | public: | ||||
Brett Wilson | 45d6f2d | 2017-08-23 17:01:24 | [diff] [blame] | 24 | typedef base::circular_deque<JavaScriptAppModalDialog*>::iterator iterator; |
[email protected] | 677b2a0 | 2012-06-04 21:54:08 | [diff] [blame] | 25 | |
[email protected] | d3c6c0d7 | 2010-12-09 08:15:04 | [diff] [blame] | 26 | // Returns the singleton instance. |
27 | static AppModalDialogQueue* GetInstance(); | ||||
28 | |||||
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 29 | // Adds a modal dialog to the queue. If there are no other dialogs in the |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | // queue, the dialog will be shown immediately. Once it is shown, the |
31 | // most recently active browser window (or whichever is currently active) | ||||
32 | // will be app modal, meaning it will be activated if the user tries to | ||||
[email protected] | 7e2a399 | 2012-05-22 22:57:19 | [diff] [blame] | 33 | // activate any other browser windows. |
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 34 | // Note: The JavaScriptAppModalDialog |dialog| must be window modal before it |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 35 | // can be added as app modal. |
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 36 | void AddDialog(JavaScriptAppModalDialog* dialog); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 37 | |
38 | // Removes the current dialog in the queue (the one that is being shown). | ||||
39 | // Shows the next dialog in the queue, if any is present. This does not | ||||
40 | // ensure that the currently showing dialog is closed, it just makes it no | ||||
41 | // longer app modal. | ||||
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 42 | void ShowNextDialog(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 43 | |
44 | // Activates and shows the current dialog, if the user clicks on one of the | ||||
45 | // windows disabled by the presence of an app modal dialog. This forces | ||||
46 | // the window to be visible on the display even if desktop manager software | ||||
47 | // opened the dialog on another virtual desktop. Assumes there is currently a | ||||
48 | // dialog being shown. (Call BrowserList::IsShowingAppModalDialog to test | ||||
49 | // this condition). | ||||
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 50 | void ActivateModalDialog(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 51 | |
[email protected] | b6ad1cab | 2009-01-16 22:41:42 | [diff] [blame] | 52 | // Returns true if there is currently an active app modal dialog box. |
[email protected] | 677b2a0 | 2012-06-04 21:54:08 | [diff] [blame] | 53 | bool HasActiveDialog() const; |
[email protected] | b6ad1cab | 2009-01-16 22:41:42 | [diff] [blame] | 54 | |
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 55 | JavaScriptAppModalDialog* active_dialog() { return active_dialog_; } |
[email protected] | b6ad1cab | 2009-01-16 22:41:42 | [diff] [blame] | 56 | |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 57 | // Iterators to walk the queue. The queue does not include the currently |
58 | // active app modal dialog box. | ||||
[email protected] | 677b2a0 | 2012-06-04 21:54:08 | [diff] [blame] | 59 | iterator begin() { return app_modal_dialog_queue_.begin(); } |
60 | iterator end() { return app_modal_dialog_queue_.end(); } | ||||
[email protected] | a1e97f0 | 2011-06-30 14:04:34 | [diff] [blame] | 61 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 62 | private: |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 63 | friend struct base::DefaultSingletonTraits<AppModalDialogQueue>; |
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 64 | |
[email protected] | 2858bbf | 2010-10-05 23:46:02 | [diff] [blame] | 65 | AppModalDialogQueue(); |
66 | ~AppModalDialogQueue(); | ||||
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 67 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | // Shows |dialog| and notifies the BrowserList that a modal dialog is showing. |
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 69 | void ShowModalDialog(JavaScriptAppModalDialog* dialog); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 70 | |
[email protected] | 1e1baa4 | 2010-02-18 03:51:50 | [diff] [blame] | 71 | // Returns the next dialog to show. This removes entries from |
72 | // app_modal_dialog_queue_ until one is valid or the queue is empty. This | ||||
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 73 | // returns nullptr if there are no more dialogs, or all the dialogs in the |
74 | // queue are not valid. | ||||
75 | JavaScriptAppModalDialog* GetNextDialog(); | ||||
[email protected] | 1e1baa4 | 2010-02-18 03:51:50 | [diff] [blame] | 76 | |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 77 | // Contains all app modal dialogs which are waiting to be shown. The currently |
78 | // active modal dialog is not included. | ||||
Brett Wilson | 45d6f2d | 2017-08-23 17:01:24 | [diff] [blame] | 79 | base::circular_deque<JavaScriptAppModalDialog*> app_modal_dialog_queue_; |
[email protected] | b6ad1cab | 2009-01-16 22:41:42 | [diff] [blame] | 80 | |
avi | 373e72a | 2017-05-26 20:33:52 | [diff] [blame] | 81 | // The currently active app-modal dialog box. nullptr if there is no active |
82 | // app-modal dialog box. | ||||
83 | JavaScriptAppModalDialog* active_dialog_; | ||||
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 84 | |
[email protected] | 171ae92 | 2010-02-24 02:07:08 | [diff] [blame] | 85 | // Stores if |ShowModalDialog()| is currently being called on an app-modal |
86 | // dialog. | ||||
87 | bool showing_modal_dialog_; | ||||
88 | |||||
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 89 | DISALLOW_COPY_AND_ASSIGN(AppModalDialogQueue); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 90 | }; |
91 | |||||
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 92 | } // namespace app_modal |
93 | |||||
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 94 | #endif // COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_ |