Back to index

lightning-sunbird  0.9+nobinonly
nsIFocusController.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  * vim: set ts=3 sw=2 et tw=80:
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is the Mozilla browser.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications, Inc.
00021  * Portions created by the Initial Developer are Copyright (C) 1999
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   David W. Hyatt <hyatt@netscape.com> (Original Author)
00026  *   Dan Rosen <dr@netscape.com>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either of the GNU General Public License Version 2 or later (the "GPL"),
00030  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #ifndef nsIFocusController_h__
00043 #define nsIFocusController_h__
00044 
00045 #include "nsISupports.h"
00046 #include "nsCOMPtr.h"
00047 
00048 class nsIDOMElement;
00049 class nsIDOMNode;
00050 class nsIDOMWindowInternal;
00051 class nsIController;
00052 class nsIControllers;
00053 class nsAString;
00054 
00055 // {AC71F479-17E1-4ee0-8EFD-0ECF2AA2F827}
00056 #define NS_IFOCUSCONTROLLER_IID \
00057 { 0xac71f479, 0x17e1, 0x4ee0, { 0x8e, 0xfd, 0xe, 0xcf, 0x2a, 0xa2, 0xf8, 0x27 } }
00058 
00059 class nsIFocusController : public nsISupports {
00060 public:
00061   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFOCUSCONTROLLER_IID)
00062 
00063   NS_IMETHOD GetFocusedElement(nsIDOMElement** aResult)=0;
00064   NS_IMETHOD SetFocusedElement(nsIDOMElement* aElement)=0;
00065 
00066   NS_IMETHOD GetFocusedWindow(nsIDOMWindowInternal** aResult)=0;
00067   NS_IMETHOD SetFocusedWindow(nsIDOMWindowInternal* aResult)=0;
00068 
00069   NS_IMETHOD GetSuppressFocus(PRBool* aSuppressFlag)=0;
00070   NS_IMETHOD SetSuppressFocus(PRBool aSuppressFlag, const char* aReason)=0;
00071 
00072   NS_IMETHOD GetSuppressFocusScroll(PRBool* aSuppressFlag)=0;
00073   NS_IMETHOD SetSuppressFocusScroll(PRBool aSuppressFlag)=0;
00074   
00075   NS_IMETHOD GetActive(PRBool* aActive)=0;
00076   NS_IMETHOD SetActive(PRBool aActive)=0;
00077 
00078   NS_IMETHOD GetPopupNode(nsIDOMNode** aNode)=0;
00079   NS_IMETHOD SetPopupNode(nsIDOMNode* aNode)=0;
00080 
00081   NS_IMETHOD GetControllerForCommand(const char * aCommand, nsIController** aResult)=0;
00082   NS_IMETHOD GetControllers(nsIControllers** aResult)=0;
00083 
00084   NS_IMETHOD MoveFocus(PRBool aForward, nsIDOMElement* aElt)=0;
00085   NS_IMETHOD RewindFocusState()=0;
00086 
00087   NS_IMETHOD ResetElementFocus() = 0;
00088 };
00089 
00090 // {884e474a-bb6b-4cbf-89ea-47e0ec1f67c3}
00091 #define NS_IFOCUSCONTROLLER_MOZILLA_1_8_BRANCH_IID \
00092 { 0x884e474a, 0xbb6b, 0x4cbf, { 0x89, 0xea, 0x47, 0xe0, 0xec, 0x1f, 0x67, 0xc3 } }
00093 
00094 class nsIFocusController_MOZILLA_1_8_BRANCH : public nsIFocusController
00095 {
00096 public:
00097   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFOCUSCONTROLLER_MOZILLA_1_8_BRANCH_IID)
00098 
00099   NS_IMETHOD GetPopupEvent(nsIDOMEvent** aEvent)=0;
00100   NS_IMETHOD SetPopupEvent(nsIDOMEvent* aEvent)=0;
00101 };
00102 
00103 class nsFocusSuppressor {
00104 public:
00105   ~nsFocusSuppressor()
00106   {
00107     Unsuppress();
00108   }
00109 
00110   // Note: We assume that aReason outlives the instance of this class.
00111   void Suppress(nsIFocusController *aController, const char *aReason)
00112   {
00113     Unsuppress();
00114 
00115     mController = aController;
00116     mReason = aReason;
00117     if (aController) {
00118       mController->SetSuppressFocus(PR_TRUE, mReason);
00119     }
00120   }
00121 
00122   void Unsuppress()
00123   {
00124     if (mController) {
00125       mController->SetSuppressFocus(PR_FALSE, mReason);
00126       mController = nsnull;
00127       mReason = nsnull;
00128     }
00129   }
00130 
00131   PRBool Suppressing()
00132   {
00133     return mController != nsnull;
00134   }
00135 
00136 private:
00137   nsCOMPtr<nsIFocusController> mController;
00138   const char *mReason;
00139 };
00140 
00141 #endif // nsIFocusController_h__