1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 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_ 7 #pragma once 8 9 #include <queue> 10 11 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 12 13 template <typename T> struct DefaultSingletonTraits; 14 15 // Keeps a queue of AppModalDialogs, making sure only one app modal 16 // dialog is shown at a time. 17 // This class is a singleton. 18 class AppModalDialogQueue { 19 public: 20 // Returns the singleton instance. 21 static AppModalDialogQueue* GetInstance(); 22 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 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 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 29 // activated as well. See browser_list.h for more notes about our somewhat 30 // sloppy app modality. 31 // Note: The AppModalDialog |dialog| must be window modal before it 32 // can be added as app modal. 33 void AddDialog(AppModalDialog* dialog); 34 35 // Removes the current dialog in the queue (the one that is being shown). 36 // Shows the next dialog in the queue, if any is present. This does not 37 // ensure that the currently showing dialog is closed, it just makes it no 38 // longer app modal. 39 void ShowNextDialog(); 40 41 // Activates and shows the current dialog, if the user clicks on one of the 42 // windows disabled by the presence of an app modal dialog. This forces 43 // the window to be visible on the display even if desktop manager software 44 // opened the dialog on another virtual desktop. Assumes there is currently a 45 // dialog being shown. (Call BrowserList::IsShowingAppModalDialog to test 46 // this condition). 47 void ActivateModalDialog(); 48 49 // Returns true if there is currently an active app modal dialog box. HasActiveDialog()50 bool HasActiveDialog() { 51 return active_dialog_ != NULL; 52 } 53 54 // Accessor for |active_dialog_|. active_dialog()55 AppModalDialog* active_dialog() { 56 return active_dialog_; 57 } 58 59 private: 60 friend struct DefaultSingletonTraits<AppModalDialogQueue>; 61 62 AppModalDialogQueue(); 63 ~AppModalDialogQueue(); 64 65 // Shows |dialog| and notifies the BrowserList that a modal dialog is showing. 66 void ShowModalDialog(AppModalDialog* dialog); 67 68 // Returns the next dialog to show. This removes entries from 69 // app_modal_dialog_queue_ until one is valid or the queue is empty. This 70 // returns NULL if there are no more dialogs, or all the dialogs in the queue 71 // are not valid. 72 AppModalDialog* GetNextDialog(); 73 74 // Contains all app modal dialogs which are waiting to be shown, with the 75 // currently modal dialog at the front of the queue. 76 std::queue<AppModalDialog*> app_modal_dialog_queue_; 77 78 // The currently active app-modal dialog box's delegate. NULL if there is no 79 // active app-modal dialog box. 80 AppModalDialog* active_dialog_; 81 82 // Stores if |ShowModalDialog()| is currently being called on an app-modal 83 // dialog. 84 bool showing_modal_dialog_; 85 86 DISALLOW_COPY_AND_ASSIGN(AppModalDialogQueue); 87 }; 88 89 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_QUEUE_H_ 90