Back to index

lightning-sunbird  0.9+nobinonly
WebChrome.cpp
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.org 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) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Roy Yokoyama <yokoyama@netscape.com> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * 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 #using <mscorlib.dll>
00040 
00041 #include "DotNETEmbed.h"
00042 #include "WebChrome.h"
00043 
00044 #define NS_WEBBROWSER_CONTRACTID "@mozilla.org/embedding/browser/nsWebBrowser;1"
00045 
00046 #pragma unmanaged
00047 
00048 //*****************************************************************************
00049 // WebBrowserChrome::nsISupports
00050 //*****************************************************************************   
00051 
00052 NS_IMPL_ADDREF(WebBrowserChrome)
00053 NS_IMPL_RELEASE(WebBrowserChrome)
00054 
00055 NS_INTERFACE_MAP_BEGIN(WebBrowserChrome)
00056  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
00057  NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
00058  NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
00059 NS_INTERFACE_MAP_END
00060 
00061 
00062 WebBrowserChrome::WebBrowserChrome()
00063 {
00064   mNativeWindow = nsnull;
00065 }
00066 
00067 WebBrowserChrome::~WebBrowserChrome()
00068 {
00069 }
00070 
00071 /* attribute nativeSiteWindow siteWindow */
00072 NS_IMETHODIMP WebBrowserChrome::GetSiteWindow(void * *aSiteWindow)
00073 {
00074   *aSiteWindow = mNativeWindow;
00075   return NS_OK;
00076 }
00077 
00078 NS_IMETHODIMP WebBrowserChrome::GetTitle(PRUnichar * *aTitle)
00079 {
00080   NS_ENSURE_ARG_POINTER(aTitle);
00081 
00082   *aTitle = nsnull;
00083 
00084   return NS_ERROR_NOT_IMPLEMENTED;
00085 }
00086 NS_IMETHODIMP WebBrowserChrome::SetTitle(const PRUnichar * aTitle)
00087 {
00088   return NS_ERROR_NOT_IMPLEMENTED;
00089 }
00090 
00091 /* attribute boolean visibility; */
00092 NS_IMETHODIMP WebBrowserChrome::GetVisibility(PRBool * aVisibility)
00093 {
00094   NS_ENSURE_ARG_POINTER(aVisibility);
00095   *aVisibility = PR_TRUE;
00096   return NS_OK;
00097 }
00098 
00099 
00100 NS_IMETHODIMP WebBrowserChrome::SetVisibility(PRBool aVisibility)
00101 {
00102   return NS_OK;
00103 }
00104 
00105 /* void setFocus (); */
00106 NS_IMETHODIMP WebBrowserChrome::SetFocus()
00107 {
00108   return NS_OK;
00109 }
00110 
00111 NS_IMETHODIMP WebBrowserChrome::SetDimensions(PRUint32 aFlags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
00112 {
00113   return NS_OK;
00114 }
00115 
00116 NS_IMETHODIMP WebBrowserChrome::GetDimensions(PRUint32 aFlags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
00117 {
00118   if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
00119   {
00120     *x = 0;
00121     *y = 0;
00122   }
00123   if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER ||
00124       aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
00125   {
00126     *cx = 0;
00127     *cy = 0;
00128   }
00129   return NS_OK;
00130 }
00131 
00132 NS_IMETHODIMP WebBrowserChrome::ExitModalEventLoop(nsresult aStatus)
00133 {
00134   return NS_OK;
00135 }
00136 
00137 NS_IMETHODIMP WebBrowserChrome::ShowAsModal(void)
00138 {
00139   return NS_OK;
00140 }
00141 
00142 NS_IMETHODIMP WebBrowserChrome::IsWindowModal(PRBool *_retval)
00143 {
00144   *_retval = PR_FALSE;
00145   return NS_ERROR_NOT_IMPLEMENTED;
00146 }
00147 
00148 
00149 NS_IMETHODIMP WebBrowserChrome::SetStatus(PRUint32 aType, const PRUnichar* aStatus)
00150 {
00151   return NS_OK;
00152 }
00153 
00154 NS_IMETHODIMP WebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
00155 {
00156   NS_ENSURE_ARG_POINTER(aWebBrowser);
00157   *aWebBrowser = mWebBrowser;
00158   NS_IF_ADDREF(*aWebBrowser);
00159   return NS_OK;
00160 }
00161 
00162 NS_IMETHODIMP WebBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
00163 {
00164   mWebBrowser = aWebBrowser;
00165   return NS_OK;
00166 }
00167 
00168 NS_IMETHODIMP WebBrowserChrome::GetChromeFlags(PRUint32* aChromeMask)
00169 {
00170   *aChromeMask = mChromeFlags;
00171   return NS_OK;
00172 }
00173 
00174 NS_IMETHODIMP WebBrowserChrome::SetChromeFlags(PRUint32 aChromeMask)
00175 {
00176   mChromeFlags = aChromeMask;
00177   return NS_OK;
00178 }
00179 
00180 NS_IMETHODIMP WebBrowserChrome::DestroyBrowserWindow(void)
00181 {
00182   return NS_OK;
00183 }
00184 
00185 
00186 NS_IMETHODIMP WebBrowserChrome::SizeBrowserTo(PRInt32 aWidth, PRInt32 aHeight)
00187 {
00188   ::MoveWindow((HWND)mNativeWindow, 0, 0, aWidth, aHeight, TRUE);
00189   return NS_OK;
00190 }
00191 
00192 nsresult WebBrowserChrome::CreateBrowser(HWND hWnd, PRInt32 aX, PRInt32 aY,
00193                                          PRInt32 aCX, PRInt32 aCY,
00194                                          nsIWebBrowser **aBrowser)
00195 {
00196   NS_ENSURE_ARG_POINTER(aBrowser);
00197   *aBrowser = nsnull;
00198 
00199   mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
00200   
00201   if (!mWebBrowser)
00202     return NS_ERROR_FAILURE;
00203 
00204   (void)mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, this));
00205 
00206   nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(mWebBrowser);
00207   dsti->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
00208 
00209   nsCOMPtr<nsIBaseWindow> browserBaseWindow = do_QueryInterface(mWebBrowser);
00210 
00211   mNativeWindow = hWnd;
00212 
00213   if (!mNativeWindow)
00214     return NS_ERROR_FAILURE;
00215 
00216   browserBaseWindow->InitWindow( mNativeWindow,
00217                            nsnull, 
00218                            aX, aY, aCX, aCY);
00219   browserBaseWindow->Create();
00220 
00221 
00222   if (mWebBrowser)
00223   {
00224     *aBrowser = mWebBrowser;
00225     NS_ADDREF(*aBrowser);
00226     return NS_OK;
00227   }
00228   return NS_ERROR_FAILURE;
00229 }
00230