OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_ | 5 #ifndef COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_ |
6 #define COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_ | 6 #define COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 template <typename T> struct DefaultSingletonTraits; | 13 template <typename T> struct DefaultSingletonTraits; |
14 } | 14 } |
15 | 15 |
16 namespace app_modal { | 16 namespace app_modal { |
17 | 17 |
18 class AppModalDialog; | 18 class JavaScriptAppModalDialog; |
19 | 19 |
20 // Keeps a queue of AppModalDialogs, making sure only one app modal | 20 // Keeps a queue of JavaScriptAppModalDialogs, making sure only one app modal |
21 // dialog is shown at a time. | 21 // dialog is shown at a time. |
22 // This class is a singleton. | 22 // This class is a singleton. |
23 class AppModalDialogQueue { | 23 class AppModalDialogQueue { |
24 public: | 24 public: |
25 typedef std::deque<AppModalDialog*>::iterator iterator; | 25 typedef std::deque<JavaScriptAppModalDialog*>::iterator iterator; |
26 | 26 |
27 // Returns the singleton instance. | 27 // Returns the singleton instance. |
28 static AppModalDialogQueue* GetInstance(); | 28 static AppModalDialogQueue* GetInstance(); |
29 | 29 |
30 // Adds a modal dialog to the queue. If there are no other dialogs in the | 30 // Adds a modal dialog to the queue. If there are no other dialogs in the |
31 // queue, the dialog will be shown immediately. Once it is shown, the | 31 // queue, the dialog will be shown immediately. Once it is shown, the |
32 // most recently active browser window (or whichever is currently active) | 32 // most recently active browser window (or whichever is currently active) |
33 // will be app modal, meaning it will be activated if the user tries to | 33 // will be app modal, meaning it will be activated if the user tries to |
34 // activate any other browser windows. | 34 // activate any other browser windows. |
35 // Note: The AppModalDialog |dialog| must be window modal before it | 35 // Note: The JavaScriptAppModalDialog |dialog| must be window modal before it |
36 // can be added as app modal. | 36 // can be added as app modal. |
37 void AddDialog(AppModalDialog* dialog); | 37 void AddDialog(JavaScriptAppModalDialog* dialog); |
38 | 38 |
39 // Removes the current dialog in the queue (the one that is being shown). | 39 // Removes the current dialog in the queue (the one that is being shown). |
40 // Shows the next dialog in the queue, if any is present. This does not | 40 // Shows the next dialog in the queue, if any is present. This does not |
41 // ensure that the currently showing dialog is closed, it just makes it no | 41 // ensure that the currently showing dialog is closed, it just makes it no |
42 // longer app modal. | 42 // longer app modal. |
43 void ShowNextDialog(); | 43 void ShowNextDialog(); |
44 | 44 |
45 // Activates and shows the current dialog, if the user clicks on one of the | 45 // Activates and shows the current dialog, if the user clicks on one of the |
46 // windows disabled by the presence of an app modal dialog. This forces | 46 // windows disabled by the presence of an app modal dialog. This forces |
47 // the window to be visible on the display even if desktop manager software | 47 // the window to be visible on the display even if desktop manager software |
48 // opened the dialog on another virtual desktop. Assumes there is currently a | 48 // opened the dialog on another virtual desktop. Assumes there is currently a |
49 // dialog being shown. (Call BrowserList::IsShowingAppModalDialog to test | 49 // dialog being shown. (Call BrowserList::IsShowingAppModalDialog to test |
50 // this condition). | 50 // this condition). |
51 void ActivateModalDialog(); | 51 void ActivateModalDialog(); |
52 | 52 |
53 // Returns true if there is currently an active app modal dialog box. | 53 // Returns true if there is currently an active app modal dialog box. |
54 bool HasActiveDialog() const; | 54 bool HasActiveDialog() const; |
55 | 55 |
56 AppModalDialog* active_dialog() { return active_dialog_; } | 56 JavaScriptAppModalDialog* active_dialog() { return active_dialog_; } |
57 | 57 |
58 // Iterators to walk the queue. The queue does not include the currently | 58 // Iterators to walk the queue. The queue does not include the currently |
59 // active app modal dialog box. | 59 // active app modal dialog box. |
60 iterator begin() { return app_modal_dialog_queue_.begin(); } | 60 iterator begin() { return app_modal_dialog_queue_.begin(); } |
61 iterator end() { return app_modal_dialog_queue_.end(); } | 61 iterator end() { return app_modal_dialog_queue_.end(); } |
62 | 62 |
63 private: | 63 private: |
64 friend struct base::DefaultSingletonTraits<AppModalDialogQueue>; | 64 friend struct base::DefaultSingletonTraits<AppModalDialogQueue>; |
65 | 65 |
66 AppModalDialogQueue(); | 66 AppModalDialogQueue(); |
67 ~AppModalDialogQueue(); | 67 ~AppModalDialogQueue(); |
68 | 68 |
69 // Shows |dialog| and notifies the BrowserList that a modal dialog is showing. | 69 // Shows |dialog| and notifies the BrowserList that a modal dialog is showing. |
70 void ShowModalDialog(AppModalDialog* dialog); | 70 void ShowModalDialog(JavaScriptAppModalDialog* dialog); |
71 | 71 |
72 // Returns the next dialog to show. This removes entries from | 72 // Returns the next dialog to show. This removes entries from |
73 // app_modal_dialog_queue_ until one is valid or the queue is empty. This | 73 // app_modal_dialog_queue_ until one is valid or the queue is empty. This |
74 // returns NULL if there are no more dialogs, or all the dialogs in the queue | 74 // returns nullptr if there are no more dialogs, or all the dialogs in the |
75 // are not valid. | 75 // queue are not valid. |
76 AppModalDialog* GetNextDialog(); | 76 JavaScriptAppModalDialog* GetNextDialog(); |
77 | 77 |
78 // Contains all app modal dialogs which are waiting to be shown. The currently | 78 // Contains all app modal dialogs which are waiting to be shown. The currently |
79 // active modal dialog is not included. | 79 // active modal dialog is not included. |
80 std::deque<AppModalDialog*> app_modal_dialog_queue_; | 80 std::deque<JavaScriptAppModalDialog*> app_modal_dialog_queue_; |
81 | 81 |
82 // The currently active app-modal dialog box's delegate. NULL if there is no | 82 // The currently active app-modal dialog box. nullptr if there is no active |
83 // active app-modal dialog box. | 83 // app-modal dialog box. |
84 AppModalDialog* active_dialog_; | 84 JavaScriptAppModalDialog* active_dialog_; |
85 | 85 |
86 // Stores if |ShowModalDialog()| is currently being called on an app-modal | 86 // Stores if |ShowModalDialog()| is currently being called on an app-modal |
87 // dialog. | 87 // dialog. |
88 bool showing_modal_dialog_; | 88 bool showing_modal_dialog_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(AppModalDialogQueue); | 90 DISALLOW_COPY_AND_ASSIGN(AppModalDialogQueue); |
91 }; | 91 }; |
92 | 92 |
93 } // namespace app_modal | 93 } // namespace app_modal |
94 | 94 |
95 #endif // COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_ | 95 #endif // COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_QUEUE_H_ |
OLD | NEW |