Back to index

lightning-sunbird  0.9+nobinonly
GeckoContainer.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: Mozilla-sample-code 1.0
00003  *
00004  * Copyright (c) 2002 Netscape Communications Corporation and
00005  * other contributors
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this Mozilla sample software and associated documentation files
00009  * (the "Software"), to deal in the Software without restriction, including
00010  * without limitation the rights to use, copy, modify, merge, publish,
00011  * distribute, sublicense, and/or sell copies of the Software, and to permit
00012  * persons to whom the Software is furnished to do so, subject to the
00013  * following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included
00016  * in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00021  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00023  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00024  * DEALINGS IN THE SOFTWARE.
00025  *
00026  * Contributor(s):
00027  *   Adam Lock <adamlock@netscape.com>
00028  *
00029  * ***** END LICENSE BLOCK ***** */
00030 
00031 #ifndef __WebBrowserChrome__
00032 #define __WebBrowserChrome__
00033 
00034 #include "nsCOMPtr.h"
00035 #include "nsIGenericFactory.h"
00036 #include "nsIWebBrowserChrome.h"
00037 #include "nsIWebBrowserChromeFocus.h"
00038 
00039 #include "nsIContentViewer.h"
00040 #include "nsIContentViewerFile.h"
00041 #include "nsIBaseWindow.h"
00042 #include "nsIEmbeddingSiteWindow2.h"
00043 #include "nsIWebNavigation.h"
00044 #include "nsIWebProgressListener.h"
00045 #include "nsIInterfaceRequestor.h"
00046 #include "nsIInterfaceRequestorUtils.h"
00047 #include "nsIWebBrowser.h"
00048 #include "nsIURIContentListener.h"
00049 #include "nsIObserver.h"
00050 #include "nsWeakReference.h"
00051 #include "nsIContextMenuListener.h"
00052 #include "nsIContextMenuListener2.h"
00053 #include "nsITooltipListener.h"
00054 
00055 class GeckoContainerUI;
00056 
00057 // Define a custom nsIGeckoContainer interface. It means that if we are passed
00058 // some random nsIWebBrowserChrome object we can tell if its one of ours by
00059 // QIing to see if it implements nsIGeckoContainer
00060 
00061 #define NS_IGECKOCONTAINER_IID \
00062     { 0xbf47a2ec, 0x9be0, 0x4f18, { 0x9a, 0xf0, 0x8e, 0x1c, 0x89, 0x2a, 0xa3, 0x1d } }
00063 
00064 class NS_NO_VTABLE nsIGeckoContainer : public nsISupports
00065 {
00066 public:
00067     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IGECKOCONTAINER_IID)
00068 
00069     NS_IMETHOD GetRole(nsACString &aRole) = 0;
00070     NS_IMETHOD GetContainerUI(GeckoContainerUI **pUI) = 0;
00071 };
00072 
00073 #define NS_DECL_NSIGECKOCONTAINER \
00074     NS_IMETHOD GetRole(nsACString &aRole); \
00075     NS_IMETHOD GetContainerUI(GeckoContainerUI **pUI);
00076 
00077 class GeckoContainer   :
00078     public nsIWebBrowserChrome,
00079     public nsIWebBrowserChromeFocus,
00080     public nsIWebProgressListener,
00081     public nsIEmbeddingSiteWindow2,
00082     public nsIInterfaceRequestor,
00083     public nsIObserver,
00084     public nsIContextMenuListener2,
00085     public nsITooltipListener,
00086     public nsIURIContentListener,
00087     public nsIGeckoContainer,
00088     public nsSupportsWeakReference
00089 {
00090 public:
00091     // Supply a container UI callback and optionally a role, e.g. "browser"
00092     // which can be used to modify the behaviour depending on the value
00093     // it contains.
00094     GeckoContainer(GeckoContainerUI *pUI, const char *aRole = NULL);
00095     virtual ~GeckoContainer();
00096 
00097     NS_DECL_ISUPPORTS
00098     NS_DECL_NSIWEBBROWSERCHROME
00099     NS_DECL_NSIWEBBROWSERCHROMEFOCUS
00100     NS_DECL_NSIWEBPROGRESSLISTENER
00101     NS_DECL_NSIEMBEDDINGSITEWINDOW
00102     NS_DECL_NSIEMBEDDINGSITEWINDOW2
00103     NS_DECL_NSIINTERFACEREQUESTOR
00104     NS_DECL_NSIOBSERVER
00105     NS_DECL_NSICONTEXTMENULISTENER2
00106     NS_DECL_NSITOOLTIPLISTENER
00107     NS_DECL_NSIURICONTENTLISTENER
00108     NS_DECL_NSIGECKOCONTAINER
00109 
00110     nsresult CreateBrowser(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, nativeWindow aParent,
00111                            nsIWebBrowser **aBrowser);
00112 
00113     void     SetParent(nsIWebBrowserChrome *aParent)
00114                { mDependentParent = aParent; }
00115    
00116 protected:
00117     nsresult SendHistoryStatusMessage(nsIURI * aURI, char * operation, PRInt32 info1=0, PRUint32 info2=0);
00118 
00119     void ContentFinishedLoading();
00120 
00121     GeckoContainerUI *mUI;
00122     nativeWindow mNativeWindow;
00123     PRUint32     mChromeFlags;
00124     PRBool       mContinueModalLoop;
00125     PRBool       mSizeSet;
00126     PRBool       mIsChromeContainer;
00127     PRBool       mIsURIContentListener;
00128 
00129     nsCString    mRole;
00130     nsCOMPtr<nsIWebBrowser> mWebBrowser;
00131     nsCOMPtr<nsIWebBrowserChrome> mDependentParent; // opener (for dependent windows only)
00132 };
00133 
00134 
00135 class GeckoContainerUI
00136 {
00137 protected:
00138     PRBool mBusy;
00139 
00140 public:
00141     GeckoContainerUI() :
00142         mBusy(PR_FALSE)
00143     {
00144     }
00145     // Called by the window creator when a new browser window is requested
00146     virtual nsresult CreateBrowserWindow(PRUint32 aChromeFlags,
00147          nsIWebBrowserChrome *aParent, nsIWebBrowserChrome **aNewWindow);
00148     // Called when the content wants to be destroyed (e.g. a window.close() happened)
00149     virtual void Destroy();
00150     // Called when the Gecko has been torn down, allowing dangling references to be released
00151     virtual void Destroyed();
00152     // Called when the content wants focus
00153     virtual void SetFocus();
00154     // Called when the content wants focus (e.g. onblur handler)
00155     virtual void KillFocus();
00156     // Called when the status bar text needs to be updated (e.g. progress notifications)
00157     virtual void UpdateStatusBarText(const PRUnichar* aStatusText);
00158     // Called when the current URI has changed. Allows UI to update address bar
00159     virtual void UpdateCurrentURI();
00160     // Called when the browser busy state changes. Allows UI to display an hourglass 
00161     virtual void UpdateBusyState(PRBool aBusy);
00162     // Called when total progress changes
00163     virtual void UpdateProgress(PRInt32 aCurrent, PRInt32 aMax);
00164     virtual void GetResourceStringById(PRInt32 aID, char ** aReturn);
00165     // Called when a context menu event has been detected on the page
00166     virtual void ShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aContextMenuInfo);
00167     // Called when a tooltip should be shown
00168     virtual void ShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText);
00169     // Called when a tooltip should be hidden
00170     virtual void HideTooltip();
00171     // Called when the window should be hidden or shown
00172     virtual void ShowWindow(PRBool aShow);
00173     // Called when the browser area should be resized
00174     virtual void SizeTo(PRInt32 aWidth, PRInt32 aHeight);
00175     virtual void EnableChromeWindow(PRBool aEnabled);
00176     virtual PRUint32 RunEventLoop(PRBool &aRunCondition);
00177 };
00178 
00179 #endif /* __WebBrowserChrome__ */