Back to index

lightning-sunbird  0.9+nobinonly
nsBrowserWindow.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Brian Ryner <bryner@brianryner.com>
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 #ifndef nsBrowserWindow_h___
00039 #define nsBrowserWindow_h___
00040 
00041 // Local Includes
00042 #include "nsWebBrowserChrome.h"
00043 #include "nsThrobber.h"
00044 
00045 // Helper Classes
00046 
00047 // Interfaces Needed
00048 #include "nsIBaseWindow.h"
00049 #include "nsIInterfaceRequestor.h"
00050 #include "nsIFile.h"
00051 #include "nsILocalFile.h"
00052 
00053 #include "nsIWebBrowser.h"
00054 #include "nsIStreamListener.h"
00055 #include "nsIProgressEventSink.h"
00056 #include "nsIDocShell.h"
00057 #include "nsString.h"
00058 #include "nsVoidArray.h"
00059 #include "nsCRT.h"
00060 #include "prtime.h"
00061 
00062 #include "nsIXPBaseWindow.h"
00063 #include "nsPrintSetupDialog.h"
00064 #include "nsTableInspectorDialog.h"
00065 #include "nsImageInspectorDialog.h"
00066 #include "nsITextWidget.h"
00067 
00068 #include "nsIPrintSettings.h"
00069 
00070 class nsILabel;
00071 class nsICheckButton;
00072 class nsIButton;
00073 class nsThrobber;
00074 class nsViewerApp;
00075 class nsIDocumentViewer;
00076 class nsPresContext;
00077 class nsIPresShell;
00078 class nsIContentConnector;
00079 class nsWebCrawler;
00080 class nsIContent;
00081 
00082 #define SAMPLES_BASE_URL "resource:/res/samples"
00083 
00087 class nsBrowserWindow : public nsIBaseWindow,
00088                         public nsIInterfaceRequestor,
00089                         public nsIProgressEventSink
00090 {
00091 friend class nsWebBrowserChrome;
00092 
00093 public:
00094   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00095 
00096   NS_DECL_ISUPPORTS
00097   NS_DECL_NSIBASEWINDOW
00098   NS_DECL_NSIINTERFACEREQUESTOR
00099 
00100 protected:
00101    void DestroyWidget(nsISupports* aWidget);
00102 
00103 public:
00104 
00105   // nsIBrowserWindow
00106   NS_IMETHOD Init(nsIAppShell* aAppShell,
00107                   const nsRect& aBounds,
00108                   PRUint32 aChromeMask,
00109                   PRBool aAllowPlugins = PR_TRUE);
00110                   
00111   // virtual method for platform-specific initialization
00112   NS_IMETHOD InitNativeWindow() { return NS_OK; }
00113   
00114   // nsIBrowserWindow
00115   NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY);
00116   NS_IMETHOD SizeContentTo(PRInt32 aWidth, PRInt32 aHeight);
00117   NS_IMETHOD SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight,
00118                           PRBool aWidthTransient, PRBool aHeightTransient);
00119   NS_IMETHOD GetContentBounds(nsRect& aBounds);
00120   NS_IMETHOD GetWindowBounds(nsRect& aBounds);
00121   NS_IMETHOD SetChrome(PRUint32 aNewChromeMask);
00122   NS_IMETHOD GetChrome(PRUint32& aChromeMaskResult);
00123   NS_IMETHOD SetProgress(PRInt32 aProgress, PRInt32 aProgressMax);
00124   NS_IMETHOD ShowMenuBar(PRBool aShow);
00125   NS_IMETHOD GetDocShell(nsIDocShell*& aResult);
00126   NS_IMETHOD GetContentDocShell(nsIDocShell **aResult);
00127 
00128   // nsIProgressEventSink
00129   NS_DECL_NSIPROGRESSEVENTSINK
00130 
00131   // nsBrowserWindow
00132   void SetWebCrawler(nsWebCrawler* aWebCrawler);
00133   virtual nsresult CreateMenuBar(PRInt32 aWidth) = 0;
00134   virtual nsresult GetMenuBarHeight(PRInt32 * aHeightOut);
00135   virtual nsresult CreateToolBar(PRInt32 aWidth);
00136   virtual nsresult CreateStatusBar(PRInt32 aWidth);
00137   void Layout(PRInt32 aWidth, PRInt32 aHeight);
00138   void Back();
00139   void Forward();
00140   void GoTo(const PRUnichar* aURL);
00141   void StartThrobber();
00142   void StopThrobber();
00143   void LoadThrobberImages();
00144   void DestroyThrobberImages();
00145   virtual nsEventStatus DispatchMenuItem(PRInt32 aID) = 0;
00146   virtual nsresult GetWindow(nsIWidget** aWindow);
00147 
00148   void DoFileOpen();
00149   void DoCopy();
00150   void DoPaste();
00151   void DoJSConsole();
00152   void DoPrefs();
00153   void DoEditorMode(nsIDocShell* aDocShell);
00154   void DoEditorTest(nsIDocShell* aDocShell, PRInt32 aCommandID);
00155   nsIPresShell* GetPresShell();
00156 
00157   void DoFind();
00158   NS_IMETHOD FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound);
00159   NS_IMETHOD ForceRefresh();
00160 
00161   void DoTreeView();
00162   void DoToolbarDemo();
00163 
00164   void ShowPrintPreview(PRInt32 aID);
00165   void DoPrint(void);
00166   void DoTableInspector(void);
00167   void DoImageInspector(void);
00168 
00169 #ifdef NS_DEBUG
00170   void DumpContent(FILE *out = stdout);
00171   void DumpFrames(FILE *out = stdout, nsString *aFilter = nsnull);
00172   void DumpViews(FILE *out = stdout);
00173   void DumpWebShells(FILE *out = stdout);
00174   void DumpStyleSheets(FILE *out = stdout);
00175   void DumpStyleContexts(FILE *out = stdout);
00176   void DumpReflowStats(FILE *out = stdout);
00177   void DisplayReflowStats(PRBool aIsOn);
00178   void ToggleFrameBorders();
00179   void ToggleVisualEventDebugging();
00180   void ToggleBoolPrefAndRefresh(const char * aPrefName);
00181 
00182   void DoDebugSave();
00183   void DoToggleSelection();
00184   void DoDebugRobot();
00185   void DoSiteWalker();
00186   nsEventStatus DispatchDebugMenu(PRInt32 aID);
00187 #endif
00188   void SetBoolPref(const char * aPrefName, PRBool aValue);
00189   void SetStringPref(const char * aPrefName, const nsString& aValue);
00190   void GetStringPref(const char * aPrefName, nsString& aValue);
00191 
00192   nsEventStatus DispatchStyleMenu(PRInt32 aID);
00193   void SetCompatibilityMode(PRUint32 aMode);
00194 
00195   nsEventStatus ProcessDialogEvent(nsGUIEvent *aEvent);
00196 
00197   // Initialize a second view on a different browser windows document
00198   // viewer.
00199   nsresult Init(nsIAppShell* aAppShell,
00200                 const nsRect& aBounds,
00201                 PRUint32 aChromeMask,
00202                 PRBool aAllowPlugins,
00203                 nsIDocumentViewer* aDocViewer,
00204                 nsPresContext* aPresContext);
00205 
00206   void SetApp(nsViewerApp* aApp) {
00207     mApp = aApp;
00208   }
00209 
00210   static void CloseAllWindows();
00211 
00212   void SetShowLoadTimes(PRBool aOn) {
00213     mShowLoadTimes = aOn;
00214   }
00215 
00216   nsViewerApp* mApp;
00217   nsWebCrawler* mWebCrawler;
00218 
00219   PRUint32 mChromeMask;
00220   nsString mTitle;
00221 
00222   nsCOMPtr<nsIWidget> mWindow;
00223   nsCOMPtr<nsIDocShell> mDocShell;
00224   nsCOMPtr<nsIWebBrowser> mWebBrowser;
00225 
00226   nsCOMPtr<nsILocalFile> mOpenFileDirectory;
00227 
00228   PRTime mLoadStartTime;
00229   PRBool mShowLoadTimes;
00230 
00231   // "Toolbar"
00232   nsITextWidget* mLocation;
00233   nsIButton* mBack;
00234   nsIButton* mForward;
00235   nsThrobber* mThrobber;
00236   
00237   // "Status bar"
00238   nsITextWidget* mStatus;
00239 
00240   nsIXPBaseWindow * mXPDialog;
00241   nsIXPBaseWindow * mTableInspectorDialog;
00242   nsIXPBaseWindow * mImageInspectorDialog;
00243   PrintSetupInfo    mPrintSetupInfo;
00244 
00245   nsTableInspectorDialog * mTableInspector;
00246   nsImageInspectorDialog * mImageInspector;
00247 
00248   //for creating more instances
00249   nsIAppShell* mAppShell;
00250   PRBool mAllowPlugins;
00251 
00252   // Global window collection
00253   static nsVoidArray *gBrowsers;
00254   static void AddBrowser(nsBrowserWindow* aBrowser);
00255   static void RemoveBrowser(nsBrowserWindow* aBrowser);
00256   static nsBrowserWindow* FindBrowserFor(nsIWidget* aWidget, PRIntn aWhich);
00257 
00258 protected:
00259   nsIDOMDocument* GetDOMDocument(nsIDocShell *aDocShell);
00260   NS_IMETHOD EnsureWebBrowserChrome();
00261 
00262   nsBrowserWindow();
00263   virtual ~nsBrowserWindow();
00264 
00265   nsWebBrowserChrome*   mWebBrowserChrome;
00266   PRBool mHaveMenuBar;
00267 
00268   nsCOMPtr<nsIPrintSettings> mPrintSettings;
00269 };
00270 
00271 // XXX This is bad; because we can't hang a closure off of the event
00272 // callback we have no way to store our This pointer; therefore we
00273 // have to hunt to find the browswer that events belong too!!!
00274 
00275 // aWhich for FindBrowserFor
00276 #define FIND_WINDOW   0
00277 #define FIND_BACK     1
00278 #define FIND_FORWARD  2
00279 #define FIND_LOCATION 3
00280 
00281 //----------------------------------------------------------------------
00282 
00283 class nsNativeBrowserWindow : public nsBrowserWindow {
00284 public:
00285   nsNativeBrowserWindow();
00286   ~nsNativeBrowserWindow();
00287   
00288   virtual nsresult CreateMenuBar(PRInt32 aWidth);
00289   virtual nsEventStatus DispatchMenuItem(PRInt32 aID);
00290   virtual nsresult GetMenuBarHeight(PRInt32 * aHeightOut);
00291   
00292 protected:
00293          NS_IMETHOD InitNativeWindow();
00294 
00295 };
00296 
00297 #endif /* nsBrowserWindow_h___ */