Back to index

lightning-sunbird  0.9+nobinonly
nsPopupSetFrame.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 //
00040 // nsPopupSetFrame
00041 //
00042 
00043 #ifndef nsPopupSetFrame_h__
00044 #define nsPopupSetFrame_h__
00045 
00046 #include "prtypes.h"
00047 #include "nsIAtom.h"
00048 #include "nsCOMPtr.h"
00049 
00050 #include "nsIPopupSetFrame.h"
00051 #include "nsBoxFrame.h"
00052 #include "nsFrameList.h"
00053 #include "nsIMenuParent.h"
00054 #include "nsITimer.h"
00055 #include "nsISupportsArray.h"
00056 
00057 nsresult NS_NewPopupSetFrame(nsIPresShell* aPresShell, nsIFrame** aResult) ;
00058 
00059 struct nsPopupFrameList {
00060   nsPopupFrameList* mNextPopup;  // The next popup in the list.
00061   nsIFrame* mPopupFrame;         // Our popup.
00062   nsIContent* mPopupContent;     // The content element for the <popup> itself.
00063   
00064   nsIContent* mElementContent; // The content that is having something popped up over it <weak>
00065 
00066   PRInt32 mXPos;                // This child's x position
00067   PRInt32 mYPos;                // This child's y position
00068 
00069   nsAutoString mPopupAnchor;        // This child's anchor.
00070   nsAutoString mPopupAlign;         // This child's align.
00071 
00072   nsAutoString mPopupType;
00073   PRPackedBool mCreateHandlerSucceeded;  // Did the create handler succeed?
00074   PRPackedBool mIsOpen;
00075   nsSize mLastPref;
00076 
00077 public:
00078   nsPopupFrameList(nsIContent* aPopupContent, nsPopupFrameList* aNext);
00079   nsPopupFrameList* GetEntry(nsIContent* aPopupContent);
00080   nsPopupFrameList* GetEntryByFrame(nsIFrame* aPopupFrame);
00081 };
00082 
00083 class nsPopupSetFrame : public nsBoxFrame, public nsIPopupSetFrame
00084 {
00085 public:
00086   nsPopupSetFrame(nsIPresShell* aShell);
00087 
00088   NS_DECL_ISUPPORTS
00089   
00090   NS_IMETHOD Init(nsPresContext*  aPresContext,
00091                   nsIContent*      aContent,
00092                   nsIFrame*        aParent,
00093                   nsStyleContext*  aContext,
00094                   nsIFrame*        aPrevInFlow);
00095 
00096     // nsIBox
00097   NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState);
00098 #ifdef DEBUG_LAYOUT
00099   NS_IMETHOD SetDebug(nsBoxLayoutState& aState, PRBool aDebug);
00100 #endif
00101 
00102   // Used to destroy our popup frames.
00103   NS_IMETHOD Destroy(nsPresContext* aPresContext);
00104 
00105   // Reflow methods
00106   virtual void RepositionPopup(nsPopupFrameList* aEntry, nsBoxLayoutState& aState);
00107 
00108   NS_IMETHOD ShowPopup(nsIContent* aElementContent, nsIContent* aPopupContent, 
00109                        PRInt32 aXPos, PRInt32 aYPos, 
00110                        const nsString& aPopupType, const nsString& anAnchorAlignment,
00111                        const nsString& aPopupAlignment);
00112   NS_IMETHOD HidePopup(nsIFrame* aPopup);
00113   NS_IMETHOD DestroyPopup(nsIFrame* aPopup, PRBool aDestroyEntireChain);
00114 
00115   NS_IMETHOD AddPopupFrame(nsIFrame* aPopup);
00116   NS_IMETHOD RemovePopupFrame(nsIFrame* aPopup);
00117   
00118   PRBool OnCreate(PRInt32 aX, PRInt32 aY, nsIContent* aPopupContent);
00119   PRBool OnDestroy(nsIContent* aPopupContent);
00120   PRBool OnCreated(PRInt32 aX, PRInt32 aY, nsIContent* aPopupContent);
00121   static PRBool OnDestroyed(nsPresContext* aPresContext,
00122                             nsIContent* aPopupContent);
00123 
00124   void ActivatePopup(nsPopupFrameList* aEntry, PRBool aActivateFlag);
00125   void OpenPopup(nsPopupFrameList* aEntry, PRBool aOpenFlag);
00126 
00132   static PRBool MayOpenPopup(nsIFrame* aFrame);
00133 
00134 #ifdef DEBUG
00135   NS_IMETHOD GetFrameName(nsAString& aResult) const
00136   {
00137       return MakeFrameName(NS_LITERAL_STRING("PopupSet"), aResult);
00138   }
00139 #endif
00140 
00141 protected:
00142 
00143   void MarkAsGenerated(nsIContent* aPopupContent);
00144   void UpdateDismissalListener(nsIMenuParent* aMenuParent);
00145 
00146 protected:
00147 #ifdef DEBUG_LAYOUT
00148   nsresult SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, PRBool aDebug);
00149 #endif
00150 
00151   nsPopupFrameList* mPopupList;
00152   
00153   nsPresContext* mPresContext; // Our pres context.
00154 
00155 }; // class nsPopupSetFrame
00156 
00157 #endif