blob: 9d7ebd5554f0209ddde227da18dc6dee424d555a [file] [log] [blame]
[email protected]677b2a02012-06-04 21:54:081// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
oshimaf65398422014-11-18 23:30:425#ifndef COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_
6#define COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_
initial.commit09911bf2008-07-26 23:55:297
Brett Wilson45d6f2d2017-08-23 17:01:248#include "base/containers/circular_deque.h"
avibc5337b2015-12-25 23:16:339#include "base/macros.h"
[email protected]677b2a02012-06-04 21:54:0810
olli.raula36aa8be2015-09-10 11:14:2211namespace base {
[email protected]d3c6c0d72010-12-09 08:15:0412template <typename T> struct DefaultSingletonTraits;
olli.raula36aa8be2015-09-10 11:14:2213}
[email protected]d3c6c0d72010-12-09 08:15:0414
oshima0929be2a2014-11-19 22:21:0315namespace app_modal {
16
avi373e72a2017-05-26 20:33:5217class JavaScriptAppModalDialog;
oshima0929be2a2014-11-19 22:21:0318
avi373e72a2017-05-26 20:33:5219// Keeps a queue of JavaScriptAppModalDialogs, making sure only one app modal
initial.commit09911bf2008-07-26 23:55:2920// dialog is shown at a time.
[email protected]1f460072009-05-28 17:02:0721// This class is a singleton.
initial.commit09911bf2008-07-26 23:55:2922class AppModalDialogQueue {
23 public:
Brett Wilson45d6f2d2017-08-23 17:01:2424 typedef base::circular_deque<JavaScriptAppModalDialog*>::iterator iterator;
[email protected]677b2a02012-06-04 21:54:0825
[email protected]d3c6c0d72010-12-09 08:15:0426 // Returns the singleton instance.
27 static AppModalDialogQueue* GetInstance();
28
[email protected]2e5b90c2011-08-16 21:11:5529 // Adds a modal dialog to the queue. If there are no other dialogs in the
initial.commit09911bf2008-07-26 23:55:2930 // 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]7e2a3992012-05-22 22:57:1933 // activate any other browser windows.
avi373e72a2017-05-26 20:33:5234 // Note: The JavaScriptAppModalDialog |dialog| must be window modal before it
initial.commit09911bf2008-07-26 23:55:2935 // can be added as app modal.
avi373e72a2017-05-26 20:33:5236 void AddDialog(JavaScriptAppModalDialog* dialog);
initial.commit09911bf2008-07-26 23:55:2937
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]1f460072009-05-28 17:02:0742 void ShowNextDialog();
initial.commit09911bf2008-07-26 23:55:2943
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]1f460072009-05-28 17:02:0750 void ActivateModalDialog();
initial.commit09911bf2008-07-26 23:55:2951
[email protected]b6ad1cab2009-01-16 22:41:4252 // Returns true if there is currently an active app modal dialog box.
[email protected]677b2a02012-06-04 21:54:0853 bool HasActiveDialog() const;
[email protected]b6ad1cab2009-01-16 22:41:4254
avi373e72a2017-05-26 20:33:5255 JavaScriptAppModalDialog* active_dialog() { return active_dialog_; }
[email protected]b6ad1cab2009-01-16 22:41:4256
[email protected]2e5b90c2011-08-16 21:11:5557 // Iterators to walk the queue. The queue does not include the currently
58 // active app modal dialog box.
[email protected]677b2a02012-06-04 21:54:0859 iterator begin() { return app_modal_dialog_queue_.begin(); }
60 iterator end() { return app_modal_dialog_queue_.end(); }
[email protected]a1e97f02011-06-30 14:04:3461
initial.commit09911bf2008-07-26 23:55:2962 private:
olli.raula36aa8be2015-09-10 11:14:2263 friend struct base::DefaultSingletonTraits<AppModalDialogQueue>;
[email protected]1f460072009-05-28 17:02:0764
[email protected]2858bbf2010-10-05 23:46:0265 AppModalDialogQueue();
66 ~AppModalDialogQueue();
[email protected]1f460072009-05-28 17:02:0767
initial.commit09911bf2008-07-26 23:55:2968 // Shows |dialog| and notifies the BrowserList that a modal dialog is showing.
avi373e72a2017-05-26 20:33:5269 void ShowModalDialog(JavaScriptAppModalDialog* dialog);
initial.commit09911bf2008-07-26 23:55:2970
[email protected]1e1baa42010-02-18 03:51:5071 // 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
avi373e72a2017-05-26 20:33:5273 // returns nullptr if there are no more dialogs, or all the dialogs in the
74 // queue are not valid.
75 JavaScriptAppModalDialog* GetNextDialog();
[email protected]1e1baa42010-02-18 03:51:5076
[email protected]2e5b90c2011-08-16 21:11:5577 // Contains all app modal dialogs which are waiting to be shown. The currently
78 // active modal dialog is not included.
Brett Wilson45d6f2d2017-08-23 17:01:2479 base::circular_deque<JavaScriptAppModalDialog*> app_modal_dialog_queue_;
[email protected]b6ad1cab2009-01-16 22:41:4280
avi373e72a2017-05-26 20:33:5281 // The currently active app-modal dialog box. nullptr if there is no active
82 // app-modal dialog box.
83 JavaScriptAppModalDialog* active_dialog_;
[email protected]1f460072009-05-28 17:02:0784
[email protected]171ae922010-02-24 02:07:0885 // Stores if |ShowModalDialog()| is currently being called on an app-modal
86 // dialog.
87 bool showing_modal_dialog_;
88
[email protected]1f460072009-05-28 17:02:0789 DISALLOW_COPY_AND_ASSIGN(AppModalDialogQueue);
initial.commit09911bf2008-07-26 23:55:2990};
91
oshima0929be2a2014-11-19 22:21:0392} // namespace app_modal
93
oshimaf65398422014-11-18 23:30:4294#endif // COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_