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 #ifndef CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_QUEUE_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_QUEUE_H_ |
6 #define CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_QUEUE_H_ | 6 #define CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_QUEUE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 | 10 |
11 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 11 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
12 | 12 |
13 template <typename T> struct DefaultSingletonTraits; | 13 template <typename T> struct DefaultSingletonTraits; |
14 | 14 |
15 // Keeps a queue of AppModalDialogs, making sure only one app modal | 15 // Keeps a queue of AppModalDialogs, making sure only one app modal |
16 // dialog is shown at a time. | 16 // dialog is shown at a time. |
17 // This class is a singleton. | 17 // This class is a singleton. |
18 class AppModalDialogQueue { | 18 class AppModalDialogQueue { |
19 public: | 19 public: |
20 // Returns the singleton instance. | 20 // Returns the singleton instance. |
21 static AppModalDialogQueue* GetInstance(); | 21 static AppModalDialogQueue* GetInstance(); |
22 | 22 |
23 // Adds a modal dialog to the queue, if there are no other dialogs in the | 23 // Adds a modal dialog to the queue. If there are no other dialogs in the |
24 // queue, the dialog will be shown immediately. Once it is shown, the | 24 // queue, the dialog will be shown immediately. Once it is shown, the |
25 // most recently active browser window (or whichever is currently active) | 25 // most recently active browser window (or whichever is currently active) |
26 // will be app modal, meaning it will be activated if the user tries to | 26 // will be app modal, meaning it will be activated if the user tries to |
27 // activate any other browser windows. So the dialog being shown should | 27 // activate any other browser windows. So the dialog being shown should |
28 // assure it is the child of BrowserList::GetLastActive() so that it is | 28 // assure it is the child of BrowserList::GetLastActive() so that it is |
29 // activated as well. See browser_list.h for more notes about our somewhat | 29 // activated as well. See browser_list.h for more notes about our somewhat |
30 // sloppy app modality. | 30 // sloppy app modality. |
31 // Note: The AppModalDialog |dialog| must be window modal before it | 31 // Note: The AppModalDialog |dialog| must be window modal before it |
32 // can be added as app modal. | 32 // can be added as app modal. |
33 void AddDialog(AppModalDialog* dialog); | 33 void AddDialog(AppModalDialog* dialog); |
(...skipping 15 matching lines...) Expand all Loading... |
49 // Returns true if there is currently an active app modal dialog box. | 49 // Returns true if there is currently an active app modal dialog box. |
50 bool HasActiveDialog() { | 50 bool HasActiveDialog() { |
51 return active_dialog_ != NULL; | 51 return active_dialog_ != NULL; |
52 } | 52 } |
53 | 53 |
54 // Accessor for |active_dialog_|. | 54 // Accessor for |active_dialog_|. |
55 AppModalDialog* active_dialog() { | 55 AppModalDialog* active_dialog() { |
56 return active_dialog_; | 56 return active_dialog_; |
57 } | 57 } |
58 | 58 |
59 // Iterators to walk the queue. | 59 // Iterators to walk the queue. The queue does not include the currently |
| 60 // active app modal dialog box. |
60 typedef std::deque<AppModalDialog*>::iterator iterator; | 61 typedef std::deque<AppModalDialog*>::iterator iterator; |
61 iterator begin() { | 62 iterator begin() { |
62 return app_modal_dialog_queue_.begin(); | 63 return app_modal_dialog_queue_.begin(); |
63 } | 64 } |
64 | 65 |
65 iterator end() { | 66 iterator end() { |
66 return app_modal_dialog_queue_.end(); | 67 return app_modal_dialog_queue_.end(); |
67 } | 68 } |
68 | 69 |
69 private: | 70 private: |
70 friend struct DefaultSingletonTraits<AppModalDialogQueue>; | 71 friend struct DefaultSingletonTraits<AppModalDialogQueue>; |
71 | 72 |
72 AppModalDialogQueue(); | 73 AppModalDialogQueue(); |
73 ~AppModalDialogQueue(); | 74 ~AppModalDialogQueue(); |
74 | 75 |
75 // Shows |dialog| and notifies the BrowserList that a modal dialog is showing. | 76 // Shows |dialog| and notifies the BrowserList that a modal dialog is showing. |
76 void ShowModalDialog(AppModalDialog* dialog); | 77 void ShowModalDialog(AppModalDialog* dialog); |
77 | 78 |
78 // Returns the next dialog to show. This removes entries from | 79 // Returns the next dialog to show. This removes entries from |
79 // app_modal_dialog_queue_ until one is valid or the queue is empty. This | 80 // app_modal_dialog_queue_ until one is valid or the queue is empty. This |
80 // returns NULL if there are no more dialogs, or all the dialogs in the queue | 81 // returns NULL if there are no more dialogs, or all the dialogs in the queue |
81 // are not valid. | 82 // are not valid. |
82 AppModalDialog* GetNextDialog(); | 83 AppModalDialog* GetNextDialog(); |
83 | 84 |
84 // Contains all app modal dialogs which are waiting to be shown, with the | 85 // Contains all app modal dialogs which are waiting to be shown. The currently |
85 // currently modal dialog at the front of the queue. | 86 // active modal dialog is not included. |
86 std::deque<AppModalDialog*> app_modal_dialog_queue_; | 87 std::deque<AppModalDialog*> app_modal_dialog_queue_; |
87 | 88 |
88 // The currently active app-modal dialog box's delegate. NULL if there is no | 89 // The currently active app-modal dialog box's delegate. NULL if there is no |
89 // active app-modal dialog box. | 90 // active app-modal dialog box. |
90 AppModalDialog* active_dialog_; | 91 AppModalDialog* active_dialog_; |
91 | 92 |
92 // Stores if |ShowModalDialog()| is currently being called on an app-modal | 93 // Stores if |ShowModalDialog()| is currently being called on an app-modal |
93 // dialog. | 94 // dialog. |
94 bool showing_modal_dialog_; | 95 bool showing_modal_dialog_; |
95 | 96 |
96 DISALLOW_COPY_AND_ASSIGN(AppModalDialogQueue); | 97 DISALLOW_COPY_AND_ASSIGN(AppModalDialogQueue); |
97 }; | 98 }; |
98 | 99 |
99 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_QUEUE_H_ | 100 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_QUEUE_H_ |
OLD | NEW |