New files for bug 120026 - rework PPEmbed so its classes are less dependent and more easily reusable. r=adamlock@netscape.com/sr=sfraser@netscape.com

This commit is contained in:
ccarlen%netscape.com 2002-02-01 22:55:18 +00:00
parent c332208943
commit b9c06e75b3
6 changed files with 1099 additions and 0 deletions

View File

@ -0,0 +1,23 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
read 'GIF ' (128) "throbber-anim.gif";

View File

@ -0,0 +1,523 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Local Includes
#include "CBrowserChrome.h"
#include "CBrowserShell.h"
#include "CBrowserMsgDefs.h"
#include "nsIGenericFactory.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsIURI.h"
#include "nsIWebProgress.h"
#include "nsIDocShellTreeItem.h"
#include "nsIRequest.h"
#include "nsIChannel.h"
#include "nsIDOMWindow.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "UMacUnicode.h"
#include "ApplIDs.h"
#include <LStaticText.h>
#include <LCheckBox.h>
#include <LEditText.h>
#include <UModalDialogs.h>
#include <LPushButton.h>
// Interfaces needed to be included
// Defines
// Constants
const PRInt32 kGrowIconSize = 15;
//*****************************************************************************
//*** CBrowserChrome:
//*****************************************************************************
CBrowserChrome::CBrowserChrome(CBrowserShell *aShell,
UInt32 aChromeFlags,
Boolean aIsMainContent) :
mBrowserWindow(nsnull), mBrowserShell(aShell),
mChromeFlags(aChromeFlags), mIsMainContent(aIsMainContent),
mSizeToContent(false),
mInModalLoop(false), mWindowVisible(false),
mInitialLoadComplete(false)
{
NS_INIT_REFCNT();
ThrowIfNil_(mBrowserShell);
mBrowserWindow = LWindow::FetchWindowObject(mBrowserShell->GetMacWindow());
StartListening();
}
CBrowserChrome::~CBrowserChrome()
{
}
void CBrowserChrome::SetBrowserShell(CBrowserShell *aShell)
{
mBrowserShell = aShell;
if (mBrowserShell)
mBrowserWindow = LWindow::FetchWindowObject(mBrowserShell->GetMacWindow());
else
mBrowserWindow = nsnull;
}
//*****************************************************************************
// CBrowserChrome::nsISupports
//*****************************************************************************
NS_IMPL_ISUPPORTS7(CBrowserChrome,
nsIWebBrowserChrome,
nsIInterfaceRequestor,
nsIWebBrowserChromeFocus,
nsIEmbeddingSiteWindow,
nsIContextMenuListener,
nsITooltipListener,
nsISupportsWeakReference);
//*****************************************************************************
// CBrowserChrome::nsIInterfaceRequestor
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::GetInterface(const nsIID &aIID, void** aInstancePtr)
{
if (aIID.Equals(NS_GET_IID(nsIDOMWindow)))
{
nsCOMPtr<nsIWebBrowser> browser;
GetWebBrowser(getter_AddRefs(browser));
if (browser)
return browser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
return NS_ERROR_NOT_INITIALIZED;
}
return QueryInterface(aIID, aInstancePtr);
}
//*****************************************************************************
// CBrowserChrome::nsIWebBrowserChrome
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::SetStatus(PRUint32 statusType, const PRUnichar *status)
{
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
MsgChromeStatusChangeInfo info(mBrowserShell, statusType, status);
mBrowserShell->BroadcastMessage(msg_OnChromeStatusChange, &info);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
{
NS_ENSURE_ARG_POINTER(aWebBrowser);
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
mBrowserShell->GetWebBrowser(aWebBrowser);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
{
NS_ENSURE_ARG(aWebBrowser); // Passing nsnull is NOT OK
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
mBrowserShell->SetWebBrowser(aWebBrowser);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetChromeFlags(PRUint32* aChromeMask)
{
NS_ENSURE_ARG_POINTER(aChromeMask);
*aChromeMask = mChromeFlags;
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetChromeFlags(PRUint32 aChromeMask)
{
// Yuck - our window would have to be rebuilt to do this.
NS_ERROR("Haven't implemented this yet!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CBrowserChrome::DestroyBrowserWindow()
{
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
mInModalLoop = false;
delete mBrowserWindow;
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::IsWindowModal(PRBool *_retval)
{
*_retval = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
{
SDimension16 curSize;
mBrowserShell->GetFrameSize(curSize);
mBrowserWindow->ResizeWindowBy((aCX - curSize.width), (aCY - curSize.height));
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::ShowAsModal(void)
{
// We need this override because StDialogHandler deletes
// its window in its destructor. We don't want that here.
class CChromeDialogHandler : public StDialogHandler
{
public:
CChromeDialogHandler(LWindow* inWindow,
LCommander* inSuper) :
StDialogHandler(inWindow, inSuper)
{ }
virtual ~CChromeDialogHandler()
{ mDialog = nil; }
};
CChromeDialogHandler theHandler(mBrowserWindow, mBrowserWindow->GetSuperCommander());
// Set to false by ExitModalEventLoop or DestroyBrowserWindow
mInModalLoop = true;
while (mInModalLoop)
theHandler.DoDialog();
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::ExitModalEventLoop(nsresult aStatus)
{
mInModalLoop = false;
return NS_OK;
}
//*****************************************************************************
// CBrowserChrome::nsIWebBrowserChromeFocus
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::FocusNextElement()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP CBrowserChrome::FocusPrevElement()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//*****************************************************************************
// CBrowserChrome::nsIEmbeddingSiteWindow
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::SetDimensions(PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_STATE(mBrowserShell);
if ((flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) &&
(flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))
return NS_ERROR_INVALID_ARG;
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
{
mBrowserWindow->MoveWindowTo(x, y);
}
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER)
{
// Don't resize the inner view independently from the window. Keep them in
// proportion by resizing the window and letting that affect the inner view.
SDimension16 curSize;
mBrowserShell->GetFrameSize(curSize);
mBrowserWindow->ResizeWindowBy(cx - curSize.width, cy - curSize.height);
}
else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
{
if (mBrowserWindow->HasAttribute(windAttr_Resizable /*windAttr_SizeBox*/))
cy += 15;
mBrowserWindow->ResizeWindowTo(cx, cy);
}
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetDimensions(PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_STATE(mBrowserShell);
if ((flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) &&
(flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))
return NS_ERROR_INVALID_ARG;
Rect outerBounds;
if ((flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) ||
(flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))
mBrowserWindow->GetGlobalBounds(outerBounds);
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
{
if (x)
*x = outerBounds.left;
if (y)
*y = outerBounds.top;
}
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER)
{
SDimension16 curSize;
mBrowserShell->GetFrameSize(curSize);
if (cx)
*cx = curSize.width;
if (cy)
*cy = curSize.height;
}
else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
{
if (cx)
*cx = outerBounds.right - outerBounds.left;
if (cy)
{
*cy = outerBounds.bottom - outerBounds.top;
if (mBrowserWindow->HasAttribute(windAttr_Resizable /*windAttr_SizeBox*/))
*cy -= 15;
}
}
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetFocus()
{
// We're driving focus through CBrowserShell::BeTarget()
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetVisibility(PRBool *aVisibility)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_ARG_POINTER(aVisibility);
*aVisibility = mWindowVisible;
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetVisibility(PRBool aVisibility)
{
NS_ENSURE_STATE(mBrowserWindow);
if (aVisibility == mWindowVisible)
return NS_OK;
mWindowVisible = aVisibility;
// If we are being told to become visible but we need to wait for
// content to load so that we can size ourselves to it,
// don't actually show it now. That will be done after the
// load completes.
PRBool sizingToContent = mIsMainContent &&
(mChromeFlags & CHROME_OPENAS_CHROME) &&
(mChromeFlags & CHROME_OPENAS_DIALOG);
if (sizingToContent && mWindowVisible && !mInitialLoadComplete)
return NS_OK;
aVisibility ? mBrowserWindow->Show() : mBrowserWindow->Hide();
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetTitle(PRUnichar * *aTitle)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_ARG_POINTER(aTitle);
Str255 pStr;
nsAutoString titleStr;
mBrowserWindow->GetDescriptor(pStr);
CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, titleStr);
*aTitle = ToNewUnicode(titleStr);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::SetTitle(const PRUnichar * aTitle)
{
NS_ENSURE_STATE(mBrowserWindow);
NS_ENSURE_ARG(aTitle);
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(aTitle), pStr);
mBrowserWindow->SetDescriptor(pStr);
return NS_OK;
}
NS_IMETHODIMP CBrowserChrome::GetSiteWindow(void * *aSiteWindow)
{
NS_ENSURE_ARG(aSiteWindow);
NS_ENSURE_STATE(mBrowserWindow);
*aSiteWindow = mBrowserWindow->Compat_GetMacWindow();
return NS_OK;
}
//*****************************************************************************
// CBrowserChrome::nsIContextMenuListener
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
{
nsresult rv;
try
{
rv = mBrowserShell->OnShowContextMenu(aContextFlags, aEvent, aNode);
}
catch (...)
{
rv = NS_ERROR_FAILURE;
}
return rv;
}
//*****************************************************************************
// CBrowserChrome::nsITooltipListener
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText)
{
nsresult rv;
try
{
rv = mBrowserShell->OnShowTooltip(aXCoords, aYCoords, aTipText);
}
catch (...)
{
rv = NS_ERROR_FAILURE;
}
return rv;
}
NS_IMETHODIMP CBrowserChrome::OnHideTooltip()
{
nsresult rv;
try
{
rv = mBrowserShell->OnHideTooltip();
}
catch (...)
{
rv = NS_ERROR_FAILURE;
}
return rv;
}
//*****************************************************************************
// CBrowserChrome::LListener
//*****************************************************************************
void CBrowserChrome::ListenToMessage(MessageT inMessage, void* ioParam)
{
switch (inMessage)
{
case msg_OnNetStopChange:
{
const MsgNetStartInfo *info = reinterpret_cast<MsgNetStartInfo*>(ioParam);
mInitialLoadComplete = true;
// See if we need to size it and show it
if (mIsMainContent &&
(mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME) &&
(mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG))
{
nsCOMPtr<nsIDOMWindow> domWindow;
(void)GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow));
if (domWindow)
domWindow->SizeToContent();
if (mWindowVisible != mBrowserWindow->IsVisible())
mBrowserWindow->Show();
}
// If we are chrome, get the window title from the DOM
if (mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)
{
nsresult rv;
nsCOMPtr<nsIDOMWindow> domWindow;
rv = GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow));
if (NS_FAILED(rv)) return;
nsCOMPtr<nsIDOMDocument> domDoc;
rv = domWindow->GetDocument(getter_AddRefs(domDoc));
if (NS_FAILED(rv)) return;
nsCOMPtr<nsIDOMElement> domDocElem;
rv = domDoc->GetDocumentElement(getter_AddRefs(domDocElem));
if (NS_FAILED(rv)) return;
nsAutoString windowTitle;
domDocElem->GetAttribute(NS_LITERAL_STRING("title"), windowTitle);
if (!windowTitle.IsEmpty()) {
Str255 pStr;
CPlatformUCSConversion::GetInstance()->UCSToPlatform(windowTitle, pStr);
mBrowserWindow->SetDescriptor(pStr);
}
}
}
break;
}
}

View File

@ -0,0 +1,110 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CBrowserChrome__
#define __CBrowserChrome__
#pragma once
// Helper Classes
#include "nsCOMPtr.h"
// Interfaces Needed
#include "nsIWebBrowserChrome.h"
#include "nsIWebBrowserChromeFocus.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIContextMenuListener.h"
#include "nsITooltipListener.h"
#include "nsWeakReference.h"
#include <LListener.h>
// Other
#include "nsIWebBrowser.h"
class CBrowserShell;
class CBrowserChrome : public nsIWebBrowserChrome,
public nsIWebBrowserChromeFocus,
public nsIEmbeddingSiteWindow,
public nsIInterfaceRequestor,
public nsIContextMenuListener,
public nsITooltipListener,
public nsSupportsWeakReference,
public LListener
{
friend class CBrowserShell;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIWEBBROWSERCHROMEFOCUS
NS_DECL_NSIEMBEDDINGSITEWINDOW
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICONTEXTMENULISTENER
NS_DECL_NSITOOLTIPLISTENER
// LListener
virtual void ListenToMessage(MessageT inMessage,
void* ioParam);
protected:
CBrowserChrome(CBrowserShell* aShell,
UInt32 aChromeFlags,
Boolean aIsMainContent);
virtual ~CBrowserChrome();
void SetBrowserShell(CBrowserShell* aShell);
protected:
CBrowserShell *mBrowserShell;
LWindow *mBrowserWindow;
PRUint32 mChromeFlags;
Boolean mIsMainContent;
Boolean mSizeToContent;
Boolean mInModalLoop;
Boolean mWindowVisible;
Boolean mInitialLoadComplete;
};
#endif // __CBrowserChrome__

View File

@ -0,0 +1,139 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CBrowserShellMsgDefs__
#define __CBrowserShellMsgDefs__
#pragma once
// Messages sent by CBrowserShell
#ifndef EMBED_MSG_BASE_ID
#define EMBED_MSG_BASE_ID 1000
#endif
enum {
msg_OnNetStartChange = EMBED_MSG_BASE_ID + 0,
msg_OnNetStopChange = EMBED_MSG_BASE_ID + 1,
msg_OnProgressChange = EMBED_MSG_BASE_ID + 2,
msg_OnLocationChange = EMBED_MSG_BASE_ID + 3,
msg_OnStatusChange = EMBED_MSG_BASE_ID + 4,
msg_OnChromeStatusChange = EMBED_MSG_BASE_ID + 5
};
/**
* CBrowserShell and CBrowserChrome broadcast changes using LBroadcaster::BroadcastMessage()
* A pointer to one of the following types is passed as the ioParam.
*/
// msg_OnNetStartChange
struct MsgNetStartInfo
{
MsgNetStartInfo(CBrowserShell* broadcaster) :
mBroadcaster(broadcaster)
{ }
CBrowserShell *mBroadcaster;
};
// msg_OnNetStopChange
struct MsgNetStopInfo
{
MsgNetStopInfo(CBrowserShell* broadcaster) :
mBroadcaster(broadcaster)
{ }
CBrowserShell *mBroadcaster;
};
// msg_OnProgressChange
struct MsgOnProgressChangeInfo
{
MsgOnProgressChangeInfo(CBrowserShell* broadcaster, PRInt32 curProgress, PRInt32 maxProgress) :
mBroadcaster(broadcaster), mCurProgress(curProgress), mMaxProgress(maxProgress)
{ }
CBrowserShell *mBroadcaster;
PRInt32 mCurProgress, mMaxProgress;
};
// msg_OnLocationChange
struct MsgLocationChangeInfo
{
MsgLocationChangeInfo(CBrowserShell* broadcaster,
const char* urlSpec) :
mBroadcaster(broadcaster), mURLSpec(urlSpec)
{ }
CBrowserShell *mBroadcaster;
const char *mURLSpec;
};
// msg_OnStatusChange
struct MsgStatusChangeInfo
{
MsgStatusChangeInfo(CBrowserShell* broadcaster,
nsresult status, const PRUnichar *message) :
mBroadcaster(broadcaster),
mStatus(status), mMessage(message)
{ }
CBrowserShell *mBroadcaster;
nsresult mStatus;
const PRUnichar *mMessage;
};
// msg_OnChromeStatusChange
// See nsIWebBrowserChrome::SetStatus
struct MsgChromeStatusChangeInfo
{
MsgChromeStatusChangeInfo(CBrowserShell* broadcaster,
PRUint32 statusType,
const PRUnichar* status) :
mBroadcaster(broadcaster),
mStatusType(statusType), mStatus(status)
{ }
CBrowserShell *mBroadcaster;
PRUint32 mStatusType;
const PRUnichar *mStatus;
};
#endif // __CBrowserShellMsgDefs__

View File

@ -0,0 +1,239 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "CWindowCreator.h"
#include "nsIWindowWatcher.h"
#include "nsIServiceManagerUtils.h"
#include "CBrowserShell.h"
#include "CBrowserWindow.h"
#include "ApplIDs.h"
// ---------------------------------------------------------------------------
// CWindowCreator
// ---------------------------------------------------------------------------
NS_IMPL_ISUPPORTS1(CWindowCreator, nsIWindowCreator);
CWindowCreator::CWindowCreator()
{
NS_INIT_ISUPPORTS();
}
CWindowCreator::~CWindowCreator()
{
}
NS_IMETHODIMP CWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent,
PRUint32 aChromeFlags,
nsIWebBrowserChrome **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = 0;
// we're ignoring aParent,
// but since windows on the Mac don't have parents anyway...
try {
LWindow *theWindow = CreateWindowInternal(aChromeFlags, -1, -1);
CBrowserShell *browser = dynamic_cast<CBrowserShell*>(theWindow->FindPaneByID(CBrowserShell::paneID_MainBrowser));
ThrowIfNil_(browser);
browser->GetWebBrowserChrome(_retval);
} catch(...) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
/*
InitializeWindowCreator creates and hands off an object with a callback
to a window creation function. This will be used by Gecko C++ code
(never JS) to create new windows when no previous window is handy
to begin with. This is done in a few exceptional cases, like PSM code.
Failure to set this callback will only disable the ability to create
new windows under these circumstances.
*/
nsresult CWindowCreator::Initialize()
{
// Create a CWindowCreator and give it to the WindowWatcher service
// The WindowWatcher service will own it so we don't keep a ref.
CWindowCreator *windowCreator = new CWindowCreator;
if (!windowCreator) return NS_ERROR_FAILURE;
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!wwatch) return NS_ERROR_FAILURE;
return wwatch->SetWindowCreator(windowCreator);
}
LWindow* CWindowCreator::CreateWindowInternal(PRUint32 inChromeFlags,
PRInt32 width, PRInt32 height)
{
const SInt16 kStatusBarHeight = 16;
LWindow *theWindow;
PRUint32 chromeFlags;
if (inChromeFlags == nsIWebBrowserChrome::CHROME_DEFAULT)
chromeFlags = nsIWebBrowserChrome::CHROME_WINDOW_RESIZE |
nsIWebBrowserChrome::CHROME_WINDOW_CLOSE |
nsIWebBrowserChrome::CHROME_TOOLBAR |
nsIWebBrowserChrome::CHROME_STATUSBAR;
else
chromeFlags = inChromeFlags;
// Bounds - Set to an arbitrary rect - we'll size it after all the subviews are in.
Rect globalBounds;
globalBounds.left = 4;
globalBounds.top = 42;
globalBounds.right = globalBounds.left + 600;
globalBounds.bottom = globalBounds.top + 400;
// ProcID and attributes
short windowDefProc;
UInt32 windowAttrs = (windAttr_Enabled | windAttr_Targetable);
if (chromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG)
{
windowAttrs |= windAttr_Modal;
if (chromeFlags & nsIWebBrowserChrome::CHROME_TITLEBAR)
{
windowDefProc = kWindowMovableModalDialogProc;
windowAttrs |= windAttr_TitleBar;
}
else
windowDefProc = kWindowModalDialogProc;
}
else
{
windowAttrs |= windAttr_Regular;
if (chromeFlags & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE)
{
windowDefProc = kWindowGrowDocumentProc;
windowAttrs |= windAttr_Resizable;
}
else
windowDefProc = kWindowDocumentProc;
if (chromeFlags & nsIWebBrowserChrome::CHROME_WINDOW_CLOSE)
windowAttrs |= windAttr_CloseBox;
}
theWindow = new CBrowserWindow(LCommander::GetTopCommander(), globalBounds, "\p", windowDefProc, windowAttrs, window_InFront);
ThrowIfNil_(theWindow);
SDimension16 windowSize, toolBarSize;
theWindow->GetFrameSize(windowSize);
if (chromeFlags & nsIWebBrowserChrome::CHROME_TOOLBAR)
{
LView::SetDefaultView(theWindow);
LCommander::SetDefaultCommander(theWindow);
LAttachable::SetDefaultAttachable(nil);
LView *toolBarView = static_cast<LView*>(UReanimator::ReadObjects(ResType_PPob, 131));
ThrowIfNil_(toolBarView);
toolBarView->GetFrameSize(toolBarSize);
toolBarView->PlaceInSuperFrameAt(0, 0, false);
toolBarSize.width = windowSize.width;
toolBarView->ResizeFrameTo(toolBarSize.width, toolBarSize.height, false);
}
SPaneInfo aPaneInfo;
SViewInfo aViewInfo;
aPaneInfo.paneID = CBrowserShell::paneID_MainBrowser;
aPaneInfo.width = windowSize.width;
aPaneInfo.height = windowSize.height;
if (chromeFlags & nsIWebBrowserChrome::CHROME_TOOLBAR)
aPaneInfo.height -= toolBarSize.height;
if (chromeFlags & nsIWebBrowserChrome::CHROME_STATUSBAR)
aPaneInfo.height -= kStatusBarHeight - 1;
aPaneInfo.visible = true;
aPaneInfo.enabled = true;
aPaneInfo.bindings.left = true;
aPaneInfo.bindings.top = true;
aPaneInfo.bindings.right = true;
aPaneInfo.bindings.bottom = true;
aPaneInfo.left = 0;
aPaneInfo.top = (chromeFlags & nsIWebBrowserChrome::CHROME_TOOLBAR) ? toolBarSize.height : 0;
aPaneInfo.userCon = 0;
aPaneInfo.superView = theWindow;
aViewInfo.imageSize.width = 0;
aViewInfo.imageSize.height = 0;
aViewInfo.scrollPos.h = aViewInfo.scrollPos.v = 0;
aViewInfo.scrollUnit.h = aViewInfo.scrollUnit.v = 1;
aViewInfo.reconcileOverhang = 0;
CBrowserShell *aShell = new CBrowserShell(aPaneInfo, aViewInfo, chromeFlags, PR_TRUE);
ThrowIfNil_(aShell);
aShell->AddAttachments();
aShell->PutInside(theWindow, false);
if (chromeFlags & nsIWebBrowserChrome::CHROME_STATUSBAR)
{
LView::SetDefaultView(theWindow);
LCommander::SetDefaultCommander(theWindow);
LAttachable::SetDefaultAttachable(nil);
LView *statusView = static_cast<LView*>(UReanimator::ReadObjects(ResType_PPob, 130));
ThrowIfNil_(statusView);
statusView->PlaceInSuperFrameAt(0, windowSize.height - kStatusBarHeight + 1, false);
statusView->ResizeFrameTo(windowSize.width - 15, kStatusBarHeight, false);
}
// Now the window is constructed...
theWindow->FinishCreate();
Rect theBounds;
theWindow->GetGlobalBounds(theBounds);
if (width == -1)
width = theBounds.right - theBounds.left;
if (height == -1)
height = theBounds.bottom - theBounds.top;
theWindow->ResizeWindowTo(width, height);
return theWindow;
}

View File

@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __CWindowCreator__
#define __CWindowCreator__
#include "nsIWindowCreator.h"
#include "nsIWebBrowserChrome.h"
// ---------------------------------------------------------------------------
// CWindowCreator
// ---------------------------------------------------------------------------
class CWindowCreator : public nsIWindowCreator
{
public:
CWindowCreator();
virtual ~CWindowCreator();
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
// Call at startup time.
static nsresult Initialize();
static LWindow* CreateWindowInternal(PRUint32 inChromeFlags,
PRInt32 width, PRInt32 height);
};
#endif // __CWindowCreator__