зеркало из https://github.com/mozilla/pjs.git
Sample code only - not part of mozilla. Implement nsIWebBrowserChrome::ShowAsModal() and some other windowing cleanup. r=danm@netscape.com
This commit is contained in:
Родитель
015c3400ee
Коммит
9df84b4e54
|
@ -29,12 +29,13 @@
|
|||
#include "nsIChannel.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIMarkupDocumentViewer.h"
|
||||
#include "nsIDOMHTMLLinkElement.h"
|
||||
#include "nsIDOMHTMLAnchorElement.h"
|
||||
#include "nsIWindowCreator.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
|
||||
#include "CBrowserWindow.h"
|
||||
#include "CBrowserShell.h"
|
||||
|
@ -77,11 +78,12 @@ static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID);
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
CBrowserWindow::CBrowserWindow() :
|
||||
mIsChromeWindow(false),
|
||||
mBrowserShell(NULL), mBrowserChrome(NULL),
|
||||
mURLField(NULL), mStatusBar(NULL), mThrobber(NULL),
|
||||
mBackButton(NULL), mForwardButton(NULL), mStopButton(NULL),
|
||||
mProgressBar(NULL), mBusy(false),
|
||||
mInitialLoadComplete(false), mShowOnInitialLoad(false),
|
||||
mInitialLoadComplete(false), mVisible(false),
|
||||
mSizeToContent(true),
|
||||
mContextMenuContext(nsIContextMenuListener::CONTEXT_NONE)
|
||||
{
|
||||
|
@ -100,13 +102,15 @@ CBrowserWindow::CBrowserWindow(LCommander* inSuperCommander,
|
|||
ConstStringPtr inTitle,
|
||||
SInt16 inProcID,
|
||||
UInt32 inAttributes,
|
||||
WindowPtr inBehind) :
|
||||
WindowPtr inBehind,
|
||||
Boolean inIsChromeWindow) :
|
||||
LWindow(inSuperCommander, inGlobalBounds, inTitle, inProcID, inAttributes, inBehind),
|
||||
mIsChromeWindow(inIsChromeWindow),
|
||||
mBrowserShell(NULL), mBrowserChrome(NULL),
|
||||
mURLField(NULL), mStatusBar(NULL), mThrobber(NULL),
|
||||
mBackButton(NULL), mForwardButton(NULL), mStopButton(NULL),
|
||||
mProgressBar(NULL), mBusy(false),
|
||||
mInitialLoadComplete(false), mShowOnInitialLoad(false),
|
||||
mInitialLoadComplete(false), mVisible(false),
|
||||
mSizeToContent(true),
|
||||
mContextMenuContext(nsIContextMenuListener::CONTEXT_NONE)
|
||||
{
|
||||
|
@ -122,11 +126,12 @@ CBrowserWindow::CBrowserWindow(LCommander* inSuperCommander,
|
|||
|
||||
CBrowserWindow::CBrowserWindow(LStream* inStream) :
|
||||
LWindow(inStream),
|
||||
mIsChromeWindow(false),
|
||||
mBrowserShell(NULL), mBrowserChrome(NULL),
|
||||
mURLField(NULL), mStatusBar(NULL), mThrobber(NULL),
|
||||
mBackButton(NULL), mForwardButton(NULL), mStopButton(NULL),
|
||||
mProgressBar(NULL), mBusy(false),
|
||||
mInitialLoadComplete(false), mShowOnInitialLoad(false),
|
||||
mInitialLoadComplete(false), mVisible(false),
|
||||
mSizeToContent(true),
|
||||
mContextMenuContext(nsIContextMenuListener::CONTEXT_NONE)
|
||||
{
|
||||
|
@ -205,7 +210,8 @@ CBrowserWindow* CBrowserWindow::CreateWindow(PRUint32 chromeFlags, PRInt32 width
|
|||
windowAttrs |= windAttr_CloseBox;
|
||||
}
|
||||
|
||||
theWindow = new CBrowserWindow(LCommander::GetTopCommander(), globalBounds, "\p", windowDefProc, windowAttrs, window_InFront);
|
||||
Boolean isChrome = (chromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME) != 0;
|
||||
theWindow = new CBrowserWindow(LCommander::GetTopCommander(), globalBounds, "\p", windowDefProc, windowAttrs, window_InFront, isChrome);
|
||||
ThrowIfNil_(theWindow);
|
||||
theWindow->SetUserCon(wind_BrowserWindow);
|
||||
|
||||
|
@ -546,14 +552,13 @@ NS_METHOD CBrowserWindow::GetIWebBrowserChrome(nsIWebBrowserChrome **aChrome)
|
|||
|
||||
NS_METHOD CBrowserWindow::SizeToContent()
|
||||
{
|
||||
nsCOMPtr<nsIContentViewer> aContentViewer;
|
||||
mBrowserShell->GetContentViewer(getter_AddRefs(aContentViewer));
|
||||
NS_ENSURE_TRUE(aContentViewer, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(aContentViewer));
|
||||
NS_ENSURE_TRUE(markupViewer, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(markupViewer->SizeToContent(), NS_ERROR_FAILURE);
|
||||
|
||||
return NS_OK;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
rv = mBrowserChrome->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindowInternal(do_QueryInterface(domWindow, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return domWindowInternal->SizeToContent();
|
||||
}
|
||||
|
||||
NS_METHOD CBrowserWindow::Stop()
|
||||
|
@ -635,20 +640,25 @@ NS_METHOD CBrowserWindow::OnStatusNetStop(nsIWebProgress *progress, nsIRequest *
|
|||
if (mStopButton)
|
||||
mStopButton->Disable();
|
||||
|
||||
// If this is our first load, check to see if we need to be sized/shown.
|
||||
if (!mInitialLoadComplete) {
|
||||
if (mSizeToContent) {
|
||||
SizeToContent();
|
||||
mSizeToContent = false;
|
||||
}
|
||||
if (mShowOnInitialLoad) {
|
||||
Show();
|
||||
Select();
|
||||
mShowOnInitialLoad = false;
|
||||
}
|
||||
mInitialLoadComplete = true;
|
||||
}
|
||||
// If this is a chrome window and it's first load, do some things.
|
||||
if (mIsChromeWindow && !mInitialLoadComplete) {
|
||||
|
||||
// If we don't have a title yet, see if we can get one from the DOM
|
||||
LStr255 windowTitle;
|
||||
GetDescriptor(windowTitle);
|
||||
if (!windowTitle.Length())
|
||||
SetTitleFromDOMDocument();
|
||||
|
||||
// If we are being sized intrinsically, do it now
|
||||
if (mSizeToContent)
|
||||
SizeToContent();
|
||||
|
||||
// If we deferred showing ourselves because waiting to be sized, do it now
|
||||
if (mVisible && !IsVisible())
|
||||
Show();
|
||||
|
||||
}
|
||||
mInitialLoadComplete = true;
|
||||
mBusy = false;
|
||||
|
||||
// Inform any other interested parties
|
||||
|
@ -681,22 +691,26 @@ NS_METHOD CBrowserWindow::OnProgressChange(nsIWebProgress *progress, nsIRequest
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD CBrowserWindow::GetVisibility(PRBool *aVisibility)
|
||||
{
|
||||
*aVisibility = mVisible;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD CBrowserWindow::SetVisibility(PRBool aVisibility)
|
||||
{
|
||||
// If we are waiting for content to load in order to size ourself,
|
||||
// defer making ourselves visible until the load completes.
|
||||
|
||||
if (aVisibility) {
|
||||
if (!mSizeToContent || mInitialLoadComplete) {
|
||||
if (mInitialLoadComplete)
|
||||
Show();
|
||||
Select();
|
||||
}
|
||||
else
|
||||
mShowOnInitialLoad = true;
|
||||
}
|
||||
else
|
||||
Hide();
|
||||
|
||||
mVisible = aVisibility;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -761,6 +775,33 @@ NS_METHOD CBrowserWindow::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD CBrowserWindow::SetTitleFromDOMDocument()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
rv = mBrowserChrome->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
rv = domWindow->GetDocument(getter_AddRefs(domDoc));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIDOMElement> domDocElem;
|
||||
rv = domDoc->GetDocumentElement(getter_AddRefs(domDocElem));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString windowTitle;
|
||||
domDocElem->GetAttribute(NS_LITERAL_STRING("title"), windowTitle);
|
||||
if (!windowTitle.IsEmpty()) {
|
||||
Str255 pStr;
|
||||
CPlatformUCSConversion::GetInstance()->UCSToPlatform(windowTitle, pStr);
|
||||
SetDescriptor(pStr);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Window Creator
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -799,8 +840,6 @@ NS_IMETHODIMP CWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent,
|
|||
// but since windows on the Mac don't have parents anyway...
|
||||
try {
|
||||
theWindow = CBrowserWindow::CreateWindow(aChromeFlags, -1, -1);
|
||||
theWindow->SetSizeToContent(false);
|
||||
theWindow->Show();
|
||||
theWindow->GetIWebBrowserChrome(_retval);
|
||||
} catch(...) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
|
@ -84,7 +84,8 @@ public:
|
|||
ConstStringPtr inTitle,
|
||||
SInt16 inProcID,
|
||||
UInt32 inAttributes,
|
||||
WindowPtr inBehind);
|
||||
WindowPtr inBehind,
|
||||
Boolean inIsChromeWindow);
|
||||
CBrowserWindow(LStream* inStream);
|
||||
|
||||
virtual ~CBrowserWindow();
|
||||
|
@ -148,15 +149,23 @@ protected:
|
|||
PRInt32 curSelfProgress, PRInt32 maxSelfProgress,
|
||||
PRInt32 curTotalProgress, PRInt32 maxTotalProgress);
|
||||
|
||||
NS_METHOD GetVisibility(PRBool *aVisibility);
|
||||
NS_METHOD SetVisibility(PRBool aVisibility);
|
||||
|
||||
NS_METHOD OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode);
|
||||
|
||||
NS_METHOD GetIWebBrowserChrome(nsIWebBrowserChrome **aChrome);
|
||||
|
||||
// -----------------------------------
|
||||
// Internal
|
||||
// -----------------------------------
|
||||
|
||||
NS_METHOD SetTitleFromDOMDocument();
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIWidget> mWindow;
|
||||
|
||||
Boolean mIsChromeWindow;
|
||||
CBrowserShell* mBrowserShell;
|
||||
CWebBrowserChrome* mBrowserChrome;
|
||||
LEditText* mURLField;
|
||||
|
@ -165,7 +174,8 @@ protected:
|
|||
LBevelButton *mBackButton, *mForwardButton, *mStopButton;
|
||||
LProgressBar* mProgressBar;
|
||||
Boolean mBusy;
|
||||
Boolean mInitialLoadComplete, mShowOnInitialLoad;
|
||||
Boolean mInitialLoadComplete;
|
||||
Boolean mVisible; // whether we are visible according to Get/SetVisibility
|
||||
Boolean mSizeToContent;
|
||||
|
||||
PRUint32 mContextMenuContext;
|
||||
|
|
|
@ -87,7 +87,8 @@ CWebBrowserPrompter::~CWebBrowserPrompter()
|
|||
//*****************************************************************************
|
||||
|
||||
CWebBrowserChrome::CWebBrowserChrome() :
|
||||
mBrowserWindow(nsnull), mBrowserShell(nsnull), mPreviousBalloonState(false)
|
||||
mBrowserWindow(nsnull), mBrowserShell(nsnull),
|
||||
mPreviousBalloonState(false), mInModalLoop(false)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
@ -226,6 +227,7 @@ NS_IMETHODIMP CWebBrowserChrome::CreateBrowserWindow(PRUint32 chromeMask, PRInt3
|
|||
|
||||
NS_IMETHODIMP CWebBrowserChrome::DestroyBrowserWindow()
|
||||
{
|
||||
mInModalLoop = false;
|
||||
delete mBrowserWindow;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -247,14 +249,35 @@ NS_IMETHODIMP CWebBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
|
|||
|
||||
NS_IMETHODIMP CWebBrowserChrome::ShowAsModal(void)
|
||||
{
|
||||
NS_ERROR("Haven't Implemented this yet");
|
||||
return NS_ERROR_FAILURE;
|
||||
// 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 CWebBrowserChrome::ExitModalEventLoop(nsresult aStatus)
|
||||
{
|
||||
NS_ERROR("Haven't Implemented this yet");
|
||||
return NS_ERROR_FAILURE;
|
||||
mInModalLoop = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
|
@ -353,6 +376,7 @@ NS_IMETHODIMP CWebBrowserChrome::SetDimensions(PRUint32 flags, PRInt32 x, PRInt3
|
|||
}
|
||||
else // setting size
|
||||
{
|
||||
mBrowserWindow->SetSizeToContent(false);
|
||||
if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER)
|
||||
{
|
||||
browserShell = mBrowserWindow->GetBrowserShell();
|
||||
|
@ -441,7 +465,7 @@ NS_IMETHODIMP CWebBrowserChrome::GetVisibility(PRBool *aVisibility)
|
|||
NS_ENSURE_STATE(mBrowserWindow);
|
||||
NS_ENSURE_ARG_POINTER(aVisibility);
|
||||
|
||||
*aVisibility = mBrowserWindow->IsVisible();
|
||||
mBrowserWindow->GetVisibility(aVisibility);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,7 @@ protected:
|
|||
CBrowserShell* mBrowserShell;
|
||||
|
||||
Boolean mPreviousBalloonState; // are balloons on or off?
|
||||
Boolean mInModalLoop;
|
||||
|
||||
nsCOMPtr<nsIPrompt> mPrompter;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче