1998-04-13 20:24:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
1998-07-31 05:54:59 +00:00
|
|
|
#include "nsIPref.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIStyleSet.h"
|
1998-05-11 22:56:58 +00:00
|
|
|
#include "nsFrameImageLoader.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIImageGroup.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
1998-06-23 21:53:02 +00:00
|
|
|
#include "nsEventStateManager.h"
|
1998-09-05 03:52:40 +00:00
|
|
|
#include "nsIURL.h"
|
1998-10-01 21:44:16 +00:00
|
|
|
#include "nsIURLGroup.h"
|
1998-09-05 03:52:40 +00:00
|
|
|
#include "nsIDocument.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-05-12 01:30:15 +00:00
|
|
|
#define NOISY_IMAGES
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
static NS_DEFINE_IID(kIPresContextIID, NS_IPRESCONTEXT_IID);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
nsPresContext::nsPresContext()
|
|
|
|
: mVisibleArea(0, 0, 0, 0),
|
|
|
|
mDefaultFont("Times", NS_FONT_STYLE_NORMAL,
|
|
|
|
NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL,
|
|
|
|
0,
|
1998-07-31 23:34:45 +00:00
|
|
|
NSIntPointsToTwips(12)),
|
1998-07-17 05:41:41 +00:00
|
|
|
mDefaultFixedFont("Courier", NS_FONT_STYLE_NORMAL,
|
|
|
|
NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL,
|
|
|
|
0,
|
1998-07-31 23:34:45 +00:00
|
|
|
NSIntPointsToTwips(10))
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
mShell = nsnull;
|
|
|
|
mDeviceContext = nsnull;
|
1998-07-31 05:54:59 +00:00
|
|
|
mPrefs = nsnull;
|
1998-04-13 20:24:54 +00:00
|
|
|
mImageGroup = nsnull;
|
|
|
|
mLinkHandler = nsnull;
|
|
|
|
mContainer = nsnull;
|
1998-06-23 21:53:02 +00:00
|
|
|
mEventManager = nsnull;
|
1998-06-25 04:24:45 +00:00
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
mFontScaler = 0;
|
|
|
|
|
|
|
|
mCompatibilityMode = eCompatibility_NavQuirks;
|
1998-09-05 03:52:40 +00:00
|
|
|
mBaseURL = nsnull;
|
1998-07-25 01:11:49 +00:00
|
|
|
|
1998-07-17 05:41:41 +00:00
|
|
|
mDefaultColor = NS_RGB(0x00, 0x00, 0x00);
|
|
|
|
mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
|
|
|
|
1998-06-25 04:24:45 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mInitialized = PR_FALSE;
|
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext::~nsPresContext()
|
|
|
|
{
|
|
|
|
mShell = nsnull;
|
|
|
|
|
|
|
|
// XXX there is a race between an async notify and this code because
|
|
|
|
// the presentation shell code deletes the frame tree first and then
|
|
|
|
// deletes us. We need an "Deactivation" hook for this code too
|
|
|
|
|
|
|
|
// Release all the image loaders
|
|
|
|
PRInt32 n = mImageLoaders.Count();
|
|
|
|
for (PRInt32 i = 0; i < n; i++) {
|
1998-05-11 22:56:58 +00:00
|
|
|
nsIFrameImageLoader* loader;
|
|
|
|
loader = (nsIFrameImageLoader*) mImageLoaders.ElementAt(i);
|
|
|
|
NS_RELEASE(loader);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mImageGroup) {
|
1998-08-18 01:43:35 +00:00
|
|
|
// Interrupt any loading images. This also stops all looping
|
|
|
|
// image animations.
|
|
|
|
mImageGroup->Interrupt();
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_RELEASE(mImageGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mLinkHandler);
|
|
|
|
NS_IF_RELEASE(mContainer);
|
1998-06-23 21:53:02 +00:00
|
|
|
NS_IF_RELEASE(mEventManager);
|
1998-06-25 04:24:45 +00:00
|
|
|
NS_IF_RELEASE(mDeviceContext);
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IF_RELEASE(mPrefs);
|
1998-09-05 03:52:40 +00:00
|
|
|
NS_IF_RELEASE(mBaseURL);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
nsrefcnt
|
|
|
|
nsPresContext::AddRef(void)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
return ++mRefCnt;
|
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
nsrefcnt
|
|
|
|
nsPresContext::Release(void)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != mRefCnt, "bad refcnt");
|
|
|
|
if (--mRefCnt == 0) {
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_QUERY_INTERFACE(nsPresContext, kIPresContextIID);
|
|
|
|
|
1998-06-25 04:24:45 +00:00
|
|
|
nsresult
|
1998-07-31 05:54:59 +00:00
|
|
|
nsPresContext::Init(nsIDeviceContext* aDeviceContext, nsIPref* aPrefs)
|
1998-06-25 04:24:45 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!(mInitialized == PR_TRUE), "attempt to reinit pres context");
|
|
|
|
|
|
|
|
mDeviceContext = aDeviceContext;
|
|
|
|
NS_IF_ADDREF(mDeviceContext);
|
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
mPrefs = aPrefs;
|
|
|
|
NS_IF_ADDREF(mPrefs);
|
|
|
|
|
|
|
|
if (nsnull != mPrefs) { // initialize pres context state from preferences
|
|
|
|
int32 prefInt;
|
|
|
|
char prefChar[512];
|
|
|
|
int charSize = sizeof(prefChar);
|
|
|
|
|
|
|
|
if (NS_OK == mPrefs->GetIntPref("browser.base_font_scaler", &prefInt)) {
|
|
|
|
mFontScaler = prefInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX these font prefs strings don't take font encoding into account
|
|
|
|
if (NS_OK == mPrefs->GetCharPref("intl.font2.win.prop_font", &(prefChar[0]), &charSize)) {
|
|
|
|
mDefaultFont.name = prefChar;
|
|
|
|
}
|
|
|
|
if (NS_OK == mPrefs->GetIntPref("intl.font2.win.prop_size", &prefInt)) {
|
1998-07-31 23:34:45 +00:00
|
|
|
mDefaultFont.size = NSIntPointsToTwips(prefInt);
|
1998-07-31 05:54:59 +00:00
|
|
|
}
|
|
|
|
if (NS_OK == mPrefs->GetCharPref("intl.font2.win.fixed_font", &(prefChar[0]), &charSize)) {
|
|
|
|
mDefaultFixedFont.name = prefChar;
|
|
|
|
}
|
|
|
|
if (NS_OK == mPrefs->GetIntPref("intl.font2.win.fixed_size", &prefInt)) {
|
1998-07-31 23:34:45 +00:00
|
|
|
mDefaultFixedFont.size = NSIntPointsToTwips(prefInt);
|
1998-07-31 05:54:59 +00:00
|
|
|
}
|
1998-09-23 23:02:02 +00:00
|
|
|
if (NS_OK == mPrefs->GetIntPref("nglayout.compatibility.mode", &prefInt)) {
|
|
|
|
mCompatibilityMode = (enum nsCompatibility)prefInt; // bad cast
|
|
|
|
}
|
1998-07-31 05:54:59 +00:00
|
|
|
}
|
|
|
|
|
1998-06-25 04:24:45 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mInitialized = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// Note: We don't hold a reference on the shell; it has a reference to
|
|
|
|
// us
|
1998-05-09 03:22:01 +00:00
|
|
|
void
|
|
|
|
nsPresContext::SetShell(nsIPresShell* aShell)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-09-05 03:52:40 +00:00
|
|
|
NS_IF_RELEASE(mBaseURL);
|
1998-04-13 20:24:54 +00:00
|
|
|
mShell = aShell;
|
1998-09-05 03:52:40 +00:00
|
|
|
if (nsnull != mShell) {
|
|
|
|
nsIDocument* doc = mShell->GetDocument();
|
|
|
|
NS_ASSERTION(nsnull != doc, "expect document here");
|
|
|
|
if (nsnull != doc) {
|
|
|
|
mBaseURL = doc->GetDocumentURL();
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
nsIPresShell*
|
|
|
|
nsPresContext::GetShell()
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-09 03:22:01 +00:00
|
|
|
NS_IF_ADDREF(mShell);
|
1998-04-13 20:24:54 +00:00
|
|
|
return mShell;
|
|
|
|
}
|
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetPrefs(nsIPref*& aPrefs)
|
|
|
|
{
|
|
|
|
aPrefs = mPrefs;
|
|
|
|
NS_IF_ADDREF(aPrefs);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetCompatibilityMode(nsCompatibility& aMode)
|
|
|
|
{
|
|
|
|
aMode = mCompatibilityMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetCompatibilityMode(nsCompatibility aMode)
|
|
|
|
{
|
|
|
|
mCompatibilityMode = aMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-05 03:52:40 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetBaseURL(nsIURL*& aURL)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mBaseURL);
|
|
|
|
aURL = mBaseURL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIStyleContext*
|
|
|
|
nsPresContext::ResolveStyleContextFor(nsIContent* aContent,
|
1998-06-05 06:00:55 +00:00
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
PRBool aForceUnique)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
|
|
|
|
nsIStyleSet* set = mShell->GetStyleSet();
|
|
|
|
if (nsnull != set) {
|
1998-06-05 06:00:55 +00:00
|
|
|
result = set->ResolveStyleFor(this, aContent, aParentFrame, aForceUnique);
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_RELEASE(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-05-18 21:06:33 +00:00
|
|
|
nsIStyleContext*
|
|
|
|
nsPresContext::ResolvePseudoStyleContextFor(nsIAtom* aPseudoTag,
|
1998-06-05 06:00:55 +00:00
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
PRBool aForceUnique)
|
1998-05-18 21:06:33 +00:00
|
|
|
{
|
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
|
|
|
|
nsIStyleSet* set = mShell->GetStyleSet();
|
|
|
|
if (nsnull != set) {
|
1998-06-05 06:00:55 +00:00
|
|
|
result = set->ResolvePseudoStyleFor(this, aPseudoTag, aParentFrame, aForceUnique);
|
1998-05-18 21:06:33 +00:00
|
|
|
NS_RELEASE(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIStyleContext*
|
|
|
|
nsPresContext::ProbePseudoStyleContextFor(nsIAtom* aPseudoTag,
|
1998-06-05 06:00:55 +00:00
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
PRBool aForceUnique)
|
1998-05-18 21:06:33 +00:00
|
|
|
{
|
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
|
|
|
|
nsIStyleSet* set = mShell->GetStyleSet();
|
|
|
|
if (nsnull != set) {
|
1998-06-05 06:00:55 +00:00
|
|
|
result = set->ProbePseudoStyleFor(this, aPseudoTag, aParentFrame, aForceUnique);
|
1998-05-18 21:06:33 +00:00
|
|
|
NS_RELEASE(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
nsIFontMetrics*
|
|
|
|
nsPresContext::GetMetricsFor(const nsFont& aFont)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-08-27 20:43:04 +00:00
|
|
|
if (nsnull != mDeviceContext) {
|
|
|
|
nsIFontMetrics* metrics;
|
|
|
|
|
|
|
|
mDeviceContext->GetMetricsFor(aFont, metrics);
|
1998-08-27 20:45:56 +00:00
|
|
|
return metrics;
|
1998-08-27 20:43:04 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
const nsFont&
|
|
|
|
nsPresContext::GetDefaultFont(void)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
return mDefaultFont;
|
|
|
|
}
|
|
|
|
|
1998-07-17 05:41:41 +00:00
|
|
|
const nsFont&
|
|
|
|
nsPresContext::GetDefaultFixedFont(void)
|
|
|
|
{
|
|
|
|
return mDefaultFixedFont;
|
|
|
|
}
|
|
|
|
|
1998-07-25 01:11:49 +00:00
|
|
|
PRInt32
|
|
|
|
nsPresContext::GetFontScaler(void)
|
|
|
|
{
|
|
|
|
return mFontScaler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::SetFontScaler(PRInt32 aScaler)
|
|
|
|
{
|
|
|
|
mFontScaler = aScaler;
|
|
|
|
}
|
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-17 05:41:41 +00:00
|
|
|
nsPresContext::GetDefaultColor(nscolor& aColor)
|
|
|
|
{
|
|
|
|
aColor = mDefaultColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IMETHODIMP
|
1998-07-17 05:41:41 +00:00
|
|
|
nsPresContext::GetDefaultBackgroundColor(nscolor& aColor)
|
|
|
|
{
|
|
|
|
aColor = mDefaultBackgroundColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetDefaultColor(const nscolor& aColor)
|
1998-07-23 17:57:00 +00:00
|
|
|
{
|
|
|
|
mDefaultColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetDefaultBackgroundColor(const nscolor& aColor)
|
1998-07-23 17:57:00 +00:00
|
|
|
{
|
|
|
|
mDefaultBackgroundColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-22 18:36:40 +00:00
|
|
|
void
|
|
|
|
nsPresContext::GetVisibleArea(nsRect& aResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-22 18:36:40 +00:00
|
|
|
aResult = mVisibleArea;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
void
|
|
|
|
nsPresContext::SetVisibleArea(const nsRect& r)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
mVisibleArea = r;
|
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
float
|
|
|
|
nsPresContext::GetPixelsToTwips() const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-09 03:22:01 +00:00
|
|
|
if (nsnull != mDeviceContext) {
|
1998-08-27 22:45:35 +00:00
|
|
|
float p2t;
|
|
|
|
mDeviceContext->GetDevUnitsToAppUnits(p2t);
|
|
|
|
return p2t;
|
1998-05-09 03:22:01 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
float
|
|
|
|
nsPresContext::GetTwipsToPixels() const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-09 03:22:01 +00:00
|
|
|
if (nsnull != mDeviceContext) {
|
1998-08-27 22:45:35 +00:00
|
|
|
float app2dev;
|
|
|
|
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
|
|
|
return app2dev;
|
1998-05-09 03:22:01 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
nsIDeviceContext*
|
|
|
|
nsPresContext::GetDeviceContext() const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mDeviceContext);
|
|
|
|
return mDeviceContext;
|
|
|
|
}
|
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IMETHODIMP
|
1998-05-11 22:56:58 +00:00
|
|
|
nsPresContext::GetImageGroup(nsIImageGroup*& aGroupResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
if (nsnull == mImageGroup) {
|
1998-05-09 03:22:01 +00:00
|
|
|
// Create image group
|
1998-05-11 22:56:58 +00:00
|
|
|
nsresult rv = NS_NewImageGroup(&mImageGroup);
|
1998-05-09 03:22:01 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-10-01 21:44:16 +00:00
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
// Initialize the image group
|
1998-10-01 21:44:16 +00:00
|
|
|
nsIURLGroup* urlGroup = mBaseURL->GetURLGroup();
|
|
|
|
rv = mImageGroup->Init(mDeviceContext, urlGroup);
|
|
|
|
NS_IF_RELEASE(urlGroup);
|
1998-05-09 03:22:01 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-05-11 22:56:58 +00:00
|
|
|
aGroupResult = mImageGroup;
|
|
|
|
NS_IF_ADDREF(mImageGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::StartLoadImage(const nsString& aURL,
|
|
|
|
const nscolor* aBackgroundColor,
|
|
|
|
nsIFrame* aTargetFrame,
|
1998-09-26 18:36:59 +00:00
|
|
|
nsFrameImageLoaderCB aCallBack,
|
1998-07-31 05:54:59 +00:00
|
|
|
PRBool aNeedSizeUpdate,
|
|
|
|
nsIFrameImageLoader*& aLoaderResult)
|
1998-05-11 22:56:58 +00:00
|
|
|
{
|
|
|
|
aLoaderResult = nsnull;
|
1998-07-31 05:54:59 +00:00
|
|
|
|
1998-05-11 22:56:58 +00:00
|
|
|
// Lookup image request in our loaders array. Note that we need
|
|
|
|
// to get a loader that is observing the same image and that has
|
|
|
|
// the same value for aNeedSizeUpdate.
|
1998-05-09 03:22:01 +00:00
|
|
|
PRInt32 i, n = mImageLoaders.Count();
|
1998-05-11 22:56:58 +00:00
|
|
|
nsIFrameImageLoader* loader;
|
|
|
|
nsAutoString loaderURL;
|
1998-05-09 03:22:01 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
1998-05-11 22:56:58 +00:00
|
|
|
loader = (nsIFrameImageLoader*) mImageLoaders.ElementAt(i);
|
|
|
|
nsIFrame* targetFrame;
|
|
|
|
loader->GetTargetFrame(targetFrame);
|
|
|
|
if (targetFrame == aTargetFrame) {
|
|
|
|
loader->GetURL(loaderURL);
|
|
|
|
// XXX case doesn't matter for all of the url so using Equals
|
|
|
|
// isn't quite right
|
|
|
|
if (aURL.Equals(loaderURL)) {
|
|
|
|
// Make sure the size update flags are the same, if not keep looking
|
|
|
|
PRIntn status;
|
|
|
|
loader->GetImageLoadStatus(status);
|
|
|
|
PRBool wantSize = 0 != (status & NS_IMAGE_LOAD_STATUS_SIZE_REQUESTED);
|
|
|
|
if (aNeedSizeUpdate == wantSize) {
|
|
|
|
NS_ADDREF(loader);
|
|
|
|
aLoaderResult = loader;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create image group if needed
|
|
|
|
nsresult rv;
|
|
|
|
if (nsnull == mImageGroup) {
|
|
|
|
nsIImageGroup* group;
|
|
|
|
rv = GetImageGroup(group);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-23 18:40:18 +00:00
|
|
|
NS_RELEASE(group);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
// We haven't seen that image before. Create a new loader and
|
|
|
|
// start it going.
|
1998-05-11 22:56:58 +00:00
|
|
|
rv = NS_NewFrameImageLoader(&loader);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-08-19 18:07:27 +00:00
|
|
|
mImageLoaders.AppendElement(loader);
|
1998-06-02 22:05:45 +00:00
|
|
|
|
1998-07-16 04:34:59 +00:00
|
|
|
rv = loader->Init(this, mImageGroup, aURL, aBackgroundColor, aTargetFrame,
|
1998-09-26 18:36:59 +00:00
|
|
|
aCallBack, aNeedSizeUpdate);
|
1998-06-02 22:05:45 +00:00
|
|
|
if (NS_OK != rv) {
|
1998-08-19 18:07:27 +00:00
|
|
|
mImageLoaders.RemoveElement(loader);
|
1998-08-18 01:43:35 +00:00
|
|
|
NS_RELEASE(loader);
|
1998-06-02 22:05:45 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-08-18 01:43:35 +00:00
|
|
|
// Return the loader
|
|
|
|
NS_ADDREF(loader);
|
1998-05-11 22:56:58 +00:00
|
|
|
aLoaderResult = loader;
|
1998-05-09 03:22:01 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IMETHODIMP
|
1998-05-09 03:22:01 +00:00
|
|
|
nsPresContext::StopLoadImage(nsIFrame* aForFrame)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-11 22:56:58 +00:00
|
|
|
nsIFrameImageLoader* loader;
|
1998-05-09 03:22:01 +00:00
|
|
|
PRInt32 i, n = mImageLoaders.Count();
|
|
|
|
for (i = 0; i < n;) {
|
1998-05-11 22:56:58 +00:00
|
|
|
loader = (nsIFrameImageLoader*) mImageLoaders.ElementAt(i);
|
|
|
|
nsIFrame* loaderFrame;
|
|
|
|
loader->GetTargetFrame(loaderFrame);
|
|
|
|
if (loaderFrame == aForFrame) {
|
1998-05-12 01:30:15 +00:00
|
|
|
loader->StopImageLoad();
|
1998-05-11 22:56:58 +00:00
|
|
|
NS_RELEASE(loader);
|
|
|
|
mImageLoaders.RemoveElementAt(i);
|
|
|
|
n--;
|
|
|
|
continue;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
1998-05-09 03:22:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetLinkHandler(nsILinkHandler* aHandler)
|
1998-04-16 21:51:16 +00:00
|
|
|
{ // XXX should probably be a WEAK reference
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_IF_RELEASE(mLinkHandler);
|
|
|
|
mLinkHandler = aHandler;
|
|
|
|
NS_IF_ADDREF(aHandler);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetLinkHandler(nsILinkHandler** aResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mLinkHandler;
|
|
|
|
NS_IF_ADDREF(mLinkHandler);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetContainer(nsISupports* aHandler)
|
1998-04-16 21:51:16 +00:00
|
|
|
{ // XXX should most likely be a WEAK reference
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_IF_RELEASE(mContainer);
|
|
|
|
mContainer = aHandler;
|
|
|
|
NS_IF_ADDREF(aHandler);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-09 03:22:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetContainer(nsISupports** aResult)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mContainer;
|
|
|
|
NS_IF_ADDREF(mContainer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-23 21:53:02 +00:00
|
|
|
|
1998-07-31 05:54:59 +00:00
|
|
|
NS_IMETHODIMP
|
1998-06-23 21:53:02 +00:00
|
|
|
nsPresContext::GetEventStateManager(nsIEventStateManager** aManager)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aManager, "null ptr");
|
|
|
|
if (nsnull == aManager) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull == mEventManager) {
|
|
|
|
nsresult rv = NS_NewEventStateManager(&mEventManager);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aManager = mEventManager;
|
|
|
|
NS_IF_ADDREF(mEventManager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-10 19:32:14 +00:00
|
|
|
|