2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
2002-10-16 03:40:38 +04:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nsCOMPtr.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsILinkHandler.h"
|
2001-07-25 10:33:06 +04:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2005-01-20 06:39:09 +03:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIFocusController.h"
|
2004-01-08 01:30:53 +03:00
|
|
|
#include "nsStyleSet.h"
|
2001-08-10 00:22:39 +04:00
|
|
|
#include "nsImageLoader.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIContent.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
1998-09-05 07:52:40 +04:00
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIDocument.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1998-12-02 03:32:20 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-09-10 09:51:08 +04:00
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2000-02-15 07:49:32 +03:00
|
|
|
#include "nsIURIContentListener.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-03-02 10:13:02 +03:00
|
|
|
#include "nsIServiceManager.h"
|
2000-05-16 02:05:45 +04:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-05-22 02:40:10 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2001-05-08 05:40:09 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2002-11-07 03:59:25 +03:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2003-01-09 09:49:07 +03:00
|
|
|
#include "nsCSSRendering.h"
|
2001-05-08 05:40:09 +04:00
|
|
|
#include "prprf.h"
|
2002-02-15 02:31:54 +03:00
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2004-02-27 20:17:37 +03:00
|
|
|
#include "nsEventStateManager.h"
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#endif // IBMBIDI
|
2000-02-15 07:49:32 +03:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// Needed for Start/Stop of Image Animation
|
|
|
|
#include "imgIContainer.h"
|
2003-03-19 06:47:09 +03:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2001-11-14 14:21:54 +03:00
|
|
|
|
2002-09-11 07:03:49 +04:00
|
|
|
//needed for resetting of image service color
|
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsISelectionImageService.h"
|
2001-11-14 14:21:54 +03:00
|
|
|
|
2001-05-08 05:40:09 +04:00
|
|
|
static nscolor
|
|
|
|
MakeColorPref(const char *colstr)
|
|
|
|
{
|
|
|
|
PRUint32 red, green, blue;
|
|
|
|
nscolor colorref;
|
|
|
|
|
|
|
|
// 4.x stored RGB color values as a string rather than as an int,
|
|
|
|
// thus we need to do this conversion
|
|
|
|
PR_sscanf(colstr, "#%02x%02x%02x", &red, &green, &blue);
|
|
|
|
colorref = NS_RGB(red, green, blue);
|
|
|
|
return colorref;
|
|
|
|
}
|
|
|
|
|
2002-12-11 08:11:02 +03:00
|
|
|
int PR_CALLBACK
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data)
|
2002-12-11 08:11:02 +03:00
|
|
|
{
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* presContext = (nsPresContext*)instance_data;
|
2002-12-11 08:11:02 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(nsnull != presContext, "bad instance data");
|
|
|
|
if (nsnull != presContext) {
|
|
|
|
presContext->PreferenceChanged(aPrefName);
|
|
|
|
}
|
|
|
|
return 0; // PREF_OK
|
|
|
|
}
|
|
|
|
|
2005-08-24 03:52:16 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)aClosure;
|
|
|
|
NS_ASSERTION(presContext != nsnull, "bad instance data");
|
|
|
|
if (presContext)
|
|
|
|
presContext->UpdateAfterPreferencesChanged();
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
2004-04-13 04:28:44 +04:00
|
|
|
static PRBool
|
2004-07-29 23:41:39 +04:00
|
|
|
IsVisualCharset(const nsCString& aCharset)
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
if (aCharset.LowerCaseEqualsLiteral("ibm864") // Arabic//ahmed
|
|
|
|
|| aCharset.LowerCaseEqualsLiteral("ibm862") // Hebrew
|
|
|
|
|| aCharset.LowerCaseEqualsLiteral("iso-8859-8") ) { // Hebrew
|
2001-03-09 06:13:03 +03:00
|
|
|
return PR_TRUE; // visual text type
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PR_FALSE; // logical text type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2001-08-10 15:57:42 +04:00
|
|
|
PR_STATIC_CALLBACK(PRBool) destroy_loads(nsHashKey *aKey, void *aData, void* closure)
|
2001-08-10 00:22:39 +04:00
|
|
|
{
|
|
|
|
nsISupports *sup = NS_REINTERPRET_CAST(nsISupports*, aData);
|
|
|
|
nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, sup);
|
|
|
|
loader->Destroy();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-07-29 02:12:45 +04:00
|
|
|
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
2001-02-20 00:50:04 +03:00
|
|
|
#include "nsContentCID.h"
|
2002-09-11 07:03:49 +04:00
|
|
|
static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID);
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 08:06:30 +04:00
|
|
|
// bother initializing members to 0.
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::nsPresContext(nsPresContextType aType)
|
2004-07-29 23:41:39 +04:00
|
|
|
: mType(aType),
|
2005-08-13 15:54:22 +04:00
|
|
|
mTextZoom(1.0),
|
2004-09-05 04:04:04 +04:00
|
|
|
mViewportStyleOverflow(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
|
2004-07-29 23:41:39 +04:00
|
|
|
mCompatibilityMode(eCompatibility_FullStandards),
|
|
|
|
mImageAnimationModePref(imgIContainer::kNormalAnimMode),
|
|
|
|
mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)),
|
2001-09-27 22:34:30 +04:00
|
|
|
mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
2004-07-29 23:41:39 +04:00
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)),
|
2001-09-27 22:34:30 +04:00
|
|
|
mDefaultSerifFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
2004-07-29 23:41:39 +04:00
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)),
|
2001-09-27 22:34:30 +04:00
|
|
|
mDefaultSansSerifFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
2004-07-29 23:41:39 +04:00
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)),
|
2001-09-27 22:34:30 +04:00
|
|
|
mDefaultMonospaceFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
2004-07-29 23:41:39 +04:00
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)),
|
|
|
|
mDefaultCursiveFont("cursive", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)),
|
|
|
|
mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12))
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-08-01 03:15:21 +04:00
|
|
|
// NOTE! nsPresContext::operator new() zeroes out all members, so don't
|
2004-04-30 08:06:30 +04:00
|
|
|
// bother initializing members to 0.
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
mDoScaledTwips = PR_TRUE;
|
2000-09-21 05:20:00 +04:00
|
|
|
|
2002-02-15 17:48:12 +03:00
|
|
|
SetBackgroundImageDraw(PR_TRUE); // always draw the background
|
|
|
|
SetBackgroundColorDraw(PR_TRUE);
|
2001-12-11 08:57:37 +03:00
|
|
|
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
2000-10-11 12:33:01 +04:00
|
|
|
|
|
|
|
mUseDocumentColors = PR_TRUE;
|
|
|
|
mUseDocumentFonts = PR_TRUE;
|
|
|
|
|
2001-09-27 22:34:30 +04:00
|
|
|
// the minimum font-size is unconstrained by default
|
|
|
|
|
2003-10-15 05:56:12 +04:00
|
|
|
mLinkColor = NS_RGB(0x00, 0x00, 0xEE);
|
|
|
|
mActiveLinkColor = NS_RGB(0xEE, 0x00, 0x00);
|
|
|
|
mVisitedLinkColor = NS_RGB(0x55, 0x1A, 0x8B);
|
2000-10-11 12:33:01 +04:00
|
|
|
mUnderlineLinks = PR_TRUE;
|
|
|
|
|
2001-04-10 02:17:11 +04:00
|
|
|
mFocusTextColor = mDefaultColor;
|
2004-02-01 01:41:40 +03:00
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
2001-04-10 02:17:11 +04:00
|
|
|
mFocusRingWidth = 1;
|
|
|
|
|
2000-09-21 02:59:20 +04:00
|
|
|
mLanguageSpecificTransformType = eLanguageSpecificTransformType_Unknown;
|
2004-07-29 23:41:39 +04:00
|
|
|
if (aType == eContext_Galley) {
|
|
|
|
mMedium = nsLayoutAtoms::screen;
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
|
|
|
} else {
|
|
|
|
SetBackgroundImageDraw(PR_FALSE);
|
|
|
|
SetBackgroundColorDraw(PR_FALSE);
|
|
|
|
mImageAnimationMode = imgIContainer::kDontAnimMode;
|
|
|
|
mNeverAnimate = PR_TRUE;
|
|
|
|
mMedium = nsLayoutAtoms::print;
|
|
|
|
mPaginated = PR_TRUE;
|
|
|
|
if (aType == eContext_PrintPreview) {
|
|
|
|
mCanPaginatedScroll = PR_TRUE;
|
|
|
|
mPageDim.SetRect(-1, -1, -1, -1);
|
|
|
|
} else {
|
|
|
|
mPageDim.SetRect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::~nsPresContext()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-08-10 00:22:39 +04:00
|
|
|
mImageLoaders.Enumerate(destroy_loads);
|
|
|
|
|
2003-04-25 02:44:48 +04:00
|
|
|
NS_PRECONDITION(!mShell, "Presshell forgot to clear our mShell pointer");
|
|
|
|
SetShell(nsnull);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2003-06-19 22:16:53 +04:00
|
|
|
if (mEventManager) {
|
1999-04-30 13:04:36 +04:00
|
|
|
mEventManager->SetPresContext(nsnull); // unclear if this is needed, but can't hurt
|
2003-06-19 22:16:53 +04:00
|
|
|
NS_RELEASE(mEventManager);
|
|
|
|
}
|
1998-11-18 08:25:26 +03:00
|
|
|
|
2005-08-24 03:52:16 +04:00
|
|
|
if (mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
mPrefChangedTimer->Cancel();
|
|
|
|
mPrefChangedTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
2002-12-11 08:11:02 +03:00
|
|
|
// Unregister preference callbacks
|
2004-04-30 08:06:30 +04:00
|
|
|
nsContentUtils::UnregisterPrefCallback("font.",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.display.",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.underline_anchors",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.anchor_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.active_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("browser.visited_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::UnregisterPrefCallback("image.animation_mode",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
2004-04-30 07:10:29 +04:00
|
|
|
#ifdef IBMBIDI
|
2004-04-30 08:06:30 +04:00
|
|
|
nsContentUtils::UnregisterPrefCallback("bidi.", PrefChangedCallback, this);
|
|
|
|
|
|
|
|
delete mBidiUtils;
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif // IBMBIDI
|
2003-06-19 22:16:53 +04:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mDeviceContext);
|
2004-01-21 12:35:59 +03:00
|
|
|
NS_IF_RELEASE(mLookAndFeel);
|
2004-06-09 03:53:59 +04:00
|
|
|
NS_IF_RELEASE(mLangGroup);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2005-12-02 15:02:44 +03:00
|
|
|
NS_IMPL_ISUPPORTS1(nsPresContext, nsIObserver)
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-09-27 22:34:30 +04:00
|
|
|
#define MAKE_FONT_PREF_KEY(_pref, _s0, _s1) \
|
|
|
|
_pref.Assign(_s0); \
|
|
|
|
_pref.Append(_s1);
|
|
|
|
|
|
|
|
static const char* const kGenericFont[] = {
|
|
|
|
".variable.",
|
|
|
|
".fixed.",
|
|
|
|
".serif.",
|
|
|
|
".sans-serif.",
|
|
|
|
".monospace.",
|
|
|
|
".cursive.",
|
|
|
|
".fantasy."
|
|
|
|
};
|
|
|
|
|
2000-01-12 19:10:48 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetFontPreferences()
|
2000-01-12 19:10:48 +03:00
|
|
|
{
|
2004-06-09 03:53:59 +04:00
|
|
|
if (!mLangGroup)
|
2001-09-27 22:34:30 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Fetch the font prefs to be used -- see bug 61883 for details.
|
|
|
|
Not all prefs are needed upfront. Some are fallback prefs intended
|
|
|
|
for the GFX font sub-system...
|
|
|
|
|
|
|
|
1) unit : assumed to be the same for all language groups -------------
|
|
|
|
font.size.unit = px | pt XXX could be folded in the size... bug 90440
|
|
|
|
|
|
|
|
2) attributes for generic fonts --------------------------------------
|
|
|
|
font.default = serif | sans-serif - fallback generic font
|
|
|
|
font.name.[generic].[langGroup] = current user' selected font on the pref dialog
|
|
|
|
font.name-list.[generic].[langGroup] = fontname1, fontname2, ... [factory pre-built list]
|
|
|
|
font.size.[generic].[langGroup] = integer - settable by the user
|
|
|
|
font.size-adjust.[generic].[langGroup] = "float" - settable by the user
|
|
|
|
font.minimum-size.[langGroup] = integer - settable by the user
|
|
|
|
*/
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
float p2t = ScaledPixelsToTwips();
|
2001-09-27 22:34:30 +04:00
|
|
|
mDefaultVariableFont.size = NSFloatPixelsToTwips((float)16, p2t);
|
|
|
|
mDefaultFixedFont.size = NSFloatPixelsToTwips((float)13, p2t);
|
|
|
|
|
2004-06-09 03:53:59 +04:00
|
|
|
const char *langGroup;
|
|
|
|
mLangGroup->GetUTF8String(&langGroup);
|
2001-09-27 22:34:30 +04:00
|
|
|
|
|
|
|
nsCAutoString pref;
|
|
|
|
|
|
|
|
// get the current applicable font-size unit
|
|
|
|
enum {eUnit_unknown = -1, eUnit_px, eUnit_pt};
|
|
|
|
PRInt32 unit = eUnit_px;
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
nsAdoptingCString cvalue =
|
|
|
|
nsContentUtils::GetCharPref("font.size.unit");
|
|
|
|
|
|
|
|
if (!cvalue.IsEmpty()) {
|
|
|
|
if (cvalue.Equals("px")) {
|
2001-09-27 22:34:30 +04:00
|
|
|
unit = eUnit_px;
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
else if (cvalue.Equals("pt")) {
|
2001-09-27 22:34:30 +04:00
|
|
|
unit = eUnit_pt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARNING("unexpected font-size unit -- expected: 'px' or 'pt'");
|
|
|
|
unit = eUnit_unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get font.minimum-size.[langGroup]
|
2003-06-24 05:46:50 +04:00
|
|
|
|
|
|
|
pref.Assign("font.minimum-size.");
|
2004-06-09 03:53:59 +04:00
|
|
|
pref.Append(langGroup);
|
2003-06-24 05:46:50 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
PRInt32 size = nsContentUtils::GetIntPref(pref.get());
|
|
|
|
if (size > 0) {
|
2001-09-27 22:34:30 +04:00
|
|
|
if (unit == eUnit_px) {
|
|
|
|
mMinimumFontSize = NSFloatPixelsToTwips((float)size, p2t);
|
|
|
|
}
|
|
|
|
else if (unit == eUnit_pt) {
|
|
|
|
mMinimumFontSize = NSIntPointsToTwips(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get attributes specific to each generic font
|
|
|
|
nsCAutoString generic_dot_langGroup;
|
|
|
|
for (PRInt32 eType = eDefaultFont_Variable; eType < eDefaultFont_COUNT; ++eType) {
|
|
|
|
generic_dot_langGroup.Assign(kGenericFont[eType]);
|
2004-06-09 03:53:59 +04:00
|
|
|
generic_dot_langGroup.Append(langGroup);
|
2001-09-27 22:34:30 +04:00
|
|
|
|
2002-12-11 08:11:02 +03:00
|
|
|
nsFont* font;
|
2001-09-27 22:34:30 +04:00
|
|
|
switch (eType) {
|
|
|
|
case eDefaultFont_Variable: font = &mDefaultVariableFont; break;
|
|
|
|
case eDefaultFont_Fixed: font = &mDefaultFixedFont; break;
|
|
|
|
case eDefaultFont_Serif: font = &mDefaultSerifFont; break;
|
|
|
|
case eDefaultFont_SansSerif: font = &mDefaultSansSerifFont; break;
|
|
|
|
case eDefaultFont_Monospace: font = &mDefaultMonospaceFont; break;
|
|
|
|
case eDefaultFont_Cursive: font = &mDefaultCursiveFont; break;
|
|
|
|
case eDefaultFont_Fantasy: font = &mDefaultFantasyFont; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the default variable font (the other fonts are seen as 'generic' fonts
|
|
|
|
// in GFX and will be queried there when hunting for alternative fonts)
|
|
|
|
if (eType == eDefaultFont_Variable) {
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.name", generic_dot_langGroup);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
nsAdoptingString value =
|
|
|
|
nsContentUtils::GetStringPref(pref.get());
|
|
|
|
if (!value.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
font->name.Assign(value);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else {
|
2005-01-24 02:58:32 +03:00
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.default.", langGroup);
|
|
|
|
value = nsContentUtils::GetStringPref(pref.get());
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
mDefaultVariableFont.name.Assign(value);
|
2001-09-27 22:34:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (eType == eDefaultFont_Monospace) {
|
|
|
|
// This takes care of the confusion whereby people often expect "monospace"
|
|
|
|
// to have the same default font-size as "-moz-fixed" (this tentative
|
|
|
|
// size may be overwritten with the specific value for "monospace" when
|
|
|
|
// "font.size.monospace.[langGroup]" is read -- see below)
|
|
|
|
font->size = mDefaultFixedFont.size;
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else if (eType != eDefaultFont_Fixed) {
|
|
|
|
// all the other generic fonts are initialized with the size of the
|
|
|
|
// variable font, but their specific size can supersede later -- see below
|
|
|
|
font->size = mDefaultVariableFont.size;
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bug 84398: for spec purists, a different font-size only applies to the
|
|
|
|
// .variable. and .fixed. fonts and the other fonts should get |font-size-adjust|.
|
|
|
|
// The problem is that only GfxWin has the support for |font-size-adjust|. So for
|
|
|
|
// parity, we enable the ability to set a different font-size on all platforms.
|
|
|
|
|
|
|
|
// get font.size.[generic].[langGroup]
|
|
|
|
// size=0 means 'Auto', i.e., generic fonts retain the size of the variable font
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.size", generic_dot_langGroup);
|
2004-04-30 08:06:30 +04:00
|
|
|
size = nsContentUtils::GetIntPref(pref.get());
|
|
|
|
if (size > 0) {
|
2001-09-27 22:34:30 +04:00
|
|
|
if (unit == eUnit_px) {
|
|
|
|
font->size = NSFloatPixelsToTwips((float)size, p2t);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else if (unit == eUnit_pt) {
|
|
|
|
font->size = NSIntPointsToTwips(size);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
|
|
|
|
// get font.size-adjust.[generic].[langGroup]
|
|
|
|
// XXX only applicable on GFX ports that handle |font-size-adjust|
|
|
|
|
MAKE_FONT_PREF_KEY(pref, "font.size-adjust", generic_dot_langGroup);
|
2004-04-30 08:06:30 +04:00
|
|
|
cvalue = nsContentUtils::GetCharPref(pref.get());
|
|
|
|
if (!cvalue.IsEmpty()) {
|
2001-09-27 22:34:30 +04:00
|
|
|
font->sizeAdjust = (float)atof(cvalue.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_rbs
|
|
|
|
printf("%s Family-list:%s size:%d sizeAdjust:%.2f\n",
|
2004-04-30 08:06:30 +04:00
|
|
|
generic_dot_langGroup.get(),
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertUTF16toUTF8(font->name).get(), font->size,
|
2003-06-24 05:46:50 +04:00
|
|
|
font->sizeAdjust);
|
2001-09-27 22:34:30 +04:00
|
|
|
#endif
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetDocumentColorPreferences()
|
2001-10-17 03:59:25 +04:00
|
|
|
{
|
2004-06-08 23:34:55 +04:00
|
|
|
PRInt32 useAccessibilityTheme = 0;
|
2001-10-17 03:59:25 +04:00
|
|
|
PRBool usePrefColors = PR_TRUE;
|
2002-11-07 03:59:25 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryReferent(mContainer));
|
2001-10-17 03:59:25 +04:00
|
|
|
if (docShell) {
|
|
|
|
PRInt32 docShellType;
|
|
|
|
docShell->GetItemType(&docShellType);
|
2004-06-08 23:34:55 +04:00
|
|
|
if (nsIDocShellTreeItem::typeChrome == docShellType) {
|
2001-10-17 03:59:25 +04:00
|
|
|
usePrefColors = PR_FALSE;
|
2004-06-08 23:34:55 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLookAndFeel->GetMetric(nsILookAndFeel::eMetric_UseAccessibilityTheme, useAccessibilityTheme);
|
|
|
|
usePrefColors = !useAccessibilityTheme;
|
|
|
|
}
|
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
if (usePrefColors) {
|
2004-04-30 08:06:30 +04:00
|
|
|
usePrefColors =
|
|
|
|
!nsContentUtils::GetBoolPref("browser.display.use_system_colors",
|
|
|
|
PR_FALSE);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
if (usePrefColors) {
|
2004-04-30 08:06:30 +04:00
|
|
|
nsAdoptingCString colorStr =
|
|
|
|
nsContentUtils::GetCharPref("browser.display.foreground_color");
|
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2001-10-17 03:59:25 +04:00
|
|
|
mDefaultColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
colorStr =
|
|
|
|
nsContentUtils::GetCharPref("browser.display.background_color");
|
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor = MakeColorPref(colorStr);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mDefaultColor = NS_RGB(0x00, 0x00, 0x00);
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
2004-01-21 12:35:59 +03:00
|
|
|
mLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowForeground,
|
|
|
|
mDefaultColor);
|
|
|
|
mLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground,
|
2004-02-01 01:41:40 +03:00
|
|
|
mBackgroundColor);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
|
2004-06-08 23:34:55 +04:00
|
|
|
mUseDocumentColors = !useAccessibilityTheme &&
|
2004-04-30 08:06:30 +04:00
|
|
|
nsContentUtils::GetBoolPref("browser.display.use_document_colors",
|
|
|
|
mUseDocumentColors);
|
2001-10-17 03:59:25 +04:00
|
|
|
}
|
|
|
|
|
1998-11-06 19:16:01 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetUserPreferences()
|
1998-11-06 19:16:01 +03:00
|
|
|
{
|
2005-11-09 01:45:49 +03:00
|
|
|
if (!GetPresShell()) {
|
|
|
|
// No presshell means nothing to do here. We'll do this when we
|
|
|
|
// get a presshell.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mFontScaler =
|
|
|
|
nsContentUtils::GetIntPref("browser.display.base_font_scaler",
|
|
|
|
mFontScaler);
|
1998-11-06 19:16:01 +03:00
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * document colors
|
2001-10-17 03:59:25 +04:00
|
|
|
GetDocumentColorPreferences();
|
2001-03-29 11:16:06 +04:00
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * link colors
|
2004-04-30 08:06:30 +04:00
|
|
|
mUnderlineLinks =
|
|
|
|
nsContentUtils::GetBoolPref("browser.underline_anchors", mUnderlineLinks);
|
|
|
|
|
|
|
|
nsAdoptingCString colorStr =
|
|
|
|
nsContentUtils::GetCharPref("browser.anchor_color");
|
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
mLinkColor = MakeColorPref(colorStr);
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
colorStr =
|
|
|
|
nsContentUtils::GetCharPref("browser.active_color");
|
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2003-10-15 05:56:12 +04:00
|
|
|
mActiveLinkColor = MakeColorPref(colorStr);
|
|
|
|
}
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
colorStr = nsContentUtils::GetCharPref("browser.visited_color");
|
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
2002-12-11 08:11:02 +03:00
|
|
|
mVisitedLinkColor = MakeColorPref(colorStr);
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mUseFocusColors =
|
|
|
|
nsContentUtils::GetBoolPref("browser.display.use_focus_colors",
|
|
|
|
mUseFocusColors);
|
2001-04-10 02:17:11 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mFocusTextColor = mDefaultColor;
|
|
|
|
mFocusBackgroundColor = mBackgroundColor;
|
|
|
|
|
|
|
|
colorStr = nsContentUtils::GetCharPref("browser.display.focus_text_color");
|
2001-04-10 02:17:11 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusTextColor = MakeColorPref(colorStr);
|
2001-04-10 02:17:11 +04:00
|
|
|
}
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
colorStr =
|
|
|
|
nsContentUtils::GetCharPref("browser.display.focus_background_color");
|
|
|
|
|
|
|
|
if (!colorStr.IsEmpty()) {
|
|
|
|
mFocusBackgroundColor = MakeColorPref(colorStr);
|
2004-04-30 07:10:29 +04:00
|
|
|
}
|
2004-04-30 03:34:19 +04:00
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mFocusRingWidth =
|
|
|
|
nsContentUtils::GetIntPref("browser.display.focus_ring_width",
|
|
|
|
mFocusRingWidth);
|
|
|
|
|
|
|
|
mFocusRingOnAnything =
|
|
|
|
nsContentUtils::GetBoolPref("browser.display.focus_ring_on_anything",
|
|
|
|
mFocusRingOnAnything);
|
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * use fonts?
|
2004-04-30 08:06:30 +04:00
|
|
|
mUseDocumentFonts =
|
|
|
|
nsContentUtils::GetIntPref("browser.display.use_document_fonts") != 0;
|
|
|
|
|
2004-06-21 14:32:27 +04:00
|
|
|
// * replace backslashes with Yen signs? (bug 245770)
|
|
|
|
mEnableJapaneseTransform =
|
|
|
|
nsContentUtils::GetBoolPref("layout.enable_japanese_specific_transform");
|
|
|
|
|
2000-01-12 19:10:48 +03:00
|
|
|
GetFontPreferences();
|
2001-01-10 02:55:27 +03:00
|
|
|
|
|
|
|
// * image animation
|
2004-04-30 08:06:30 +04:00
|
|
|
const nsAdoptingCString& animatePref =
|
|
|
|
nsContentUtils::GetCharPref("image.animation_mode");
|
|
|
|
if (animatePref.Equals("normal"))
|
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
|
|
|
else if (animatePref.Equals("none"))
|
|
|
|
mImageAnimationModePref = imgIContainer::kDontAnimMode;
|
|
|
|
else if (animatePref.Equals("once"))
|
|
|
|
mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode;
|
2001-11-01 08:49:45 +03:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
2005-11-09 01:45:49 +03:00
|
|
|
PRUint32 bidiOptions = GetBidi();
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
PRInt32 prefInt =
|
|
|
|
nsContentUtils::GetIntPref("bidi.direction",
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_DIRECTION(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_DIRECTION(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
|
|
|
nsContentUtils::GetIntPref("bidi.texttype",
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_TEXTTYPE(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_TEXTTYPE(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
|
|
|
nsContentUtils::GetIntPref("bidi.controlstextmode",
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
|
|
|
nsContentUtils::GetIntPref("bidi.numeral",
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_NUMERAL(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_NUMERAL(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
|
|
|
nsContentUtils::GetIntPref("bidi.support",
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_SUPPORT(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_SUPPORT(bidiOptions, prefInt);
|
2004-04-30 08:06:30 +04:00
|
|
|
|
|
|
|
prefInt =
|
|
|
|
nsContentUtils::GetIntPref("bidi.characterset",
|
2005-11-09 01:45:49 +03:00
|
|
|
GET_BIDI_OPTION_CHARACTERSET(bidiOptions));
|
|
|
|
SET_BIDI_OPTION_CHARACTERSET(bidiOptions, prefInt);
|
|
|
|
|
2005-11-13 12:55:09 +03:00
|
|
|
// We don't need to force reflow: either we are initializing a new
|
|
|
|
// prescontext or we are being called from UpdateAfterPreferencesChanged()
|
|
|
|
// which triggers a reflow anyway.
|
|
|
|
SetBidi(bidiOptions, PR_FALSE);
|
2001-11-01 08:49:45 +03:00
|
|
|
#endif
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 03:18:22 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::ClearStyleDataAndReflow()
|
1998-11-06 19:16:01 +03:00
|
|
|
{
|
1999-09-15 02:16:42 +04:00
|
|
|
if (mShell) {
|
2001-07-25 10:33:06 +04:00
|
|
|
// Clear out all our style data.
|
2004-01-08 01:30:53 +03:00
|
|
|
mShell->StyleSet()->ClearStyleData(this);
|
2001-07-25 10:33:06 +04:00
|
|
|
|
2002-04-29 17:46:29 +04:00
|
|
|
// Force a reflow of the root frame
|
|
|
|
// XXX We really should only do a reflow if a preference that affects
|
|
|
|
// formatting changed, e.g., a font change. If it's just a color change
|
|
|
|
// then we only need to repaint...
|
|
|
|
mShell->StyleChangeReflow();
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
2000-04-03 01:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PreferenceChanged(const char* aPrefName)
|
2000-04-03 01:52:17 +04:00
|
|
|
{
|
2005-08-24 03:52:16 +04:00
|
|
|
// we use a zero-delay timer to coalesce multiple pref updates
|
|
|
|
if (!mPrefChangedTimer)
|
|
|
|
{
|
|
|
|
mPrefChangedTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!mPrefChangedTimer)
|
|
|
|
return;
|
|
|
|
mPrefChangedTimer->InitWithFuncCallback(nsPresContext::PrefChangedUpdateTimerCallback, (void*)this, 0, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::UpdateAfterPreferencesChanged()
|
|
|
|
{
|
|
|
|
mPrefChangedTimer = nsnull;
|
|
|
|
|
2002-11-07 03:59:25 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryReferent(mContainer));
|
2001-07-25 10:33:06 +04:00
|
|
|
if (docShell) {
|
|
|
|
PRInt32 docShellType;
|
|
|
|
docShell->GetItemType(&docShellType);
|
|
|
|
if (nsIDocShellTreeItem::typeChrome == docShellType)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-03 01:52:17 +04:00
|
|
|
// Initialize our state from the user preferences
|
|
|
|
GetUserPreferences();
|
2000-10-11 12:33:01 +04:00
|
|
|
|
|
|
|
// update the presShell: tell it to set the preference style rules up
|
|
|
|
if (mShell) {
|
|
|
|
mShell->SetPreferenceStyleRules(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2004-02-03 01:17:21 +03:00
|
|
|
mDeviceContext->FlushFontCache();
|
2004-07-29 23:41:39 +04:00
|
|
|
ClearStyleDataAndReflow();
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::Init(nsIDeviceContext* aDeviceContext)
|
1998-06-25 08:24:45 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!(mInitialized == PR_TRUE), "attempt to reinit pres context");
|
2004-02-03 01:17:21 +03:00
|
|
|
NS_ENSURE_ARG(aDeviceContext);
|
1998-06-25 08:24:45 +04:00
|
|
|
|
2003-06-19 22:16:53 +04:00
|
|
|
mDeviceContext = aDeviceContext;
|
2004-02-03 01:17:21 +03:00
|
|
|
NS_ADDREF(mDeviceContext);
|
1998-07-31 09:54:59 +04:00
|
|
|
|
2004-01-21 12:35:59 +03:00
|
|
|
// Get the look and feel service here; default colors will be initialized
|
2005-11-09 01:45:49 +03:00
|
|
|
// from calling GetUserPreferences() when we get a presshell.
|
2004-01-21 12:35:59 +03:00
|
|
|
nsresult rv = CallGetService(kLookAndFeelCID, &mLookAndFeel);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("LookAndFeel service must be implemented for this toolkit");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-02-27 20:17:37 +03:00
|
|
|
mEventManager = new nsEventStateManager();
|
|
|
|
if (!mEventManager)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2004-02-27 21:24:36 +03:00
|
|
|
NS_ADDREF(mEventManager);
|
|
|
|
|
2004-04-30 08:06:30 +04:00
|
|
|
mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
// Register callbacks so we're notified when the preferences change
|
|
|
|
nsContentUtils::RegisterPrefCallback("font.",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.display.",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.underline_anchors",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.anchor_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.active_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("browser.visited_color",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
nsContentUtils::RegisterPrefCallback("image.animation_mode",
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::PrefChangedCallback,
|
2004-04-30 08:06:30 +04:00
|
|
|
this);
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
nsContentUtils::RegisterPrefCallback("bidi.", PrefChangedCallback,
|
|
|
|
this);
|
|
|
|
#endif
|
|
|
|
|
2004-02-27 20:17:37 +03:00
|
|
|
rv = mEventManager->Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mEventManager->SetPresContext(this);
|
|
|
|
|
1998-06-25 08:24:45 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mInitialized = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
|
2006-01-21 12:31:45 +03:00
|
|
|
float pixelsToTwips = ScaledPixelsToTwips();
|
2004-11-26 21:40:58 +03:00
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THIN] = NSIntPixelsToTwips(1, pixelsToTwips);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_MEDIUM] = NSIntPixelsToTwips(3, pixelsToTwips);
|
|
|
|
mBorderWidthTable[NS_STYLE_BORDER_WIDTH_THICK] = NSIntPixelsToTwips(5, pixelsToTwips);
|
|
|
|
|
1998-06-25 08:24:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Note: We don't hold a reference on the shell; it has a reference to
|
|
|
|
// us
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetShell(nsIPresShell* aShell)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-04-25 02:44:48 +04:00
|
|
|
if (mShell) {
|
|
|
|
// Remove ourselves as the charset observer from the shell's doc, because
|
|
|
|
// this shell may be going away for good.
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2003-04-25 02:44:48 +04:00
|
|
|
if (doc) {
|
|
|
|
doc->RemoveCharSetObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
mShell = aShell;
|
2003-04-25 02:44:48 +04:00
|
|
|
|
|
|
|
if (mShell) {
|
2005-11-09 01:45:49 +03:00
|
|
|
// Initialize our state from the user preferences, now that we
|
|
|
|
// have a presshell, and hence a document.
|
|
|
|
GetUserPreferences();
|
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
|
|
|
NS_ASSERTION(doc, "expect document here");
|
|
|
|
if (doc) {
|
|
|
|
nsIURI *baseURI = doc->GetBaseURI();
|
|
|
|
|
|
|
|
if (mMedium != nsLayoutAtoms::print && baseURI) {
|
|
|
|
PRBool isChrome = PR_FALSE;
|
|
|
|
PRBool isRes = PR_FALSE;
|
|
|
|
baseURI->SchemeIs("chrome", &isChrome);
|
|
|
|
baseURI->SchemeIs("resource", &isRes);
|
|
|
|
|
|
|
|
if (!isChrome && !isRes)
|
|
|
|
mImageAnimationMode = mImageAnimationModePref;
|
|
|
|
else
|
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
|
|
|
}
|
2001-01-10 02:55:27 +03:00
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
if (mLangService) {
|
|
|
|
doc->AddCharSetObserver(this);
|
2004-08-10 01:19:15 +04:00
|
|
|
UpdateCharSet(doc->GetDocumentCharacterSet());
|
1999-02-12 20:45:58 +03:00
|
|
|
}
|
1998-09-05 07:52:40 +04:00
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 02:59:20 +04:00
|
|
|
void
|
2004-08-10 01:19:15 +04:00
|
|
|
nsPresContext::UpdateCharSet(const nsAFlatCString& aCharSet)
|
2000-09-21 02:59:20 +04:00
|
|
|
{
|
|
|
|
if (mLangService) {
|
2004-06-09 03:53:59 +04:00
|
|
|
NS_IF_RELEASE(mLangGroup);
|
2004-08-10 01:19:15 +04:00
|
|
|
mLangGroup = mLangService->LookupCharSet(aCharSet.get()).get(); // addrefs
|
2004-06-21 14:32:27 +04:00
|
|
|
|
|
|
|
if (mLangGroup == nsLayoutAtoms::Japanese && mEnableJapaneseTransform) {
|
2004-06-09 03:53:59 +04:00
|
|
|
mLanguageSpecificTransformType =
|
2000-09-21 02:59:20 +04:00
|
|
|
eLanguageSpecificTransformType_Japanese;
|
2004-06-09 03:53:59 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLanguageSpecificTransformType =
|
2000-09-21 02:59:20 +04:00
|
|
|
eLanguageSpecificTransformType_None;
|
|
|
|
}
|
2004-06-21 14:32:27 +04:00
|
|
|
// bug 39570: moved from nsLanguageAtomService::LookupCharSet()
|
|
|
|
#if !defined(XP_BEOS)
|
|
|
|
if (mLangGroup == nsLayoutAtoms::Unicode) {
|
|
|
|
NS_RELEASE(mLangGroup);
|
|
|
|
NS_IF_ADDREF(mLangGroup = mLangService->GetLocaleLanguageGroup());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
GetFontPreferences();
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
//ahmed
|
|
|
|
|
2005-11-09 01:45:49 +03:00
|
|
|
switch (GET_BIDI_OPTION_TEXTTYPE(GetBidi())) {
|
2004-08-06 01:38:08 +04:00
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_LOGICAL:
|
|
|
|
SetVisualMode(PR_FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_VISUAL:
|
|
|
|
SetVisualMode(PR_TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IBMBIDI_TEXTTYPE_CHARSET:
|
|
|
|
default:
|
2004-08-10 01:19:15 +04:00
|
|
|
SetVisualMode(IsVisualCharset(aCharSet));
|
2004-08-06 01:38:08 +04:00
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif // IBMBIDI
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
|
|
|
|
2000-06-02 03:12:26 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::Observe(nsISupports* aSubject,
|
2004-07-29 23:41:39 +04:00
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
2000-06-02 03:12:26 +04:00
|
|
|
{
|
2001-10-20 00:52:59 +04:00
|
|
|
if (!nsCRT::strcmp(aTopic, "charset")) {
|
2006-02-03 17:18:39 +03:00
|
|
|
UpdateCharSet(NS_LossyConvertUTF16toASCII(aData));
|
2004-02-03 01:17:21 +03:00
|
|
|
mDeviceContext->FlushFontCache();
|
2004-07-29 23:41:39 +04:00
|
|
|
ClearStyleDataAndReflow();
|
2004-02-03 01:17:21 +03:00
|
|
|
|
2001-10-20 00:52:59 +04:00
|
|
|
return NS_OK;
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_WARNING("unrecognized topic in nsPresContext::Observe");
|
2001-10-20 00:52:59 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-06-02 03:12:26 +04:00
|
|
|
}
|
|
|
|
|
2003-12-25 00:51:50 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetCompatibilityMode(nsCompatibility aMode)
|
1998-07-31 09:54:59 +04:00
|
|
|
{
|
2002-05-24 03:09:31 +04:00
|
|
|
mCompatibilityMode = aMode;
|
|
|
|
|
2003-12-25 00:51:50 +03:00
|
|
|
if (!mShell)
|
|
|
|
return;
|
2000-06-03 01:45:06 +04:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
// enable/disable the QuirkSheet
|
2004-01-08 01:30:53 +03:00
|
|
|
mShell->StyleSet()->
|
|
|
|
EnableQuirkStyleSheet(mCompatibilityMode == eCompatibility_NavQuirks);
|
1998-07-31 09:54:59 +04:00
|
|
|
}
|
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// Helper function for setting Anim Mode on image
|
|
|
|
static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, PRUint16 aMode)
|
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
if (aImgReq) {
|
2001-11-14 14:21:54 +03:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
aImgReq->GetImage(getter_AddRefs(imgCon));
|
|
|
|
if (imgCon) {
|
|
|
|
imgCon->SetAnimationMode(aMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enumeration call back for HashTable
|
|
|
|
PR_STATIC_CALLBACK(PRBool) set_animation_mode(nsHashKey *aKey, void *aData, void* closure)
|
|
|
|
{
|
|
|
|
nsISupports *sup = NS_REINTERPRET_CAST(nsISupports*, aData);
|
|
|
|
nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, sup);
|
2004-02-19 21:56:13 +03:00
|
|
|
imgIRequest* imgReq = loader->GetRequest();
|
2001-11-14 17:44:34 +03:00
|
|
|
SetImgAnimModeOnImgReq(imgReq, (PRUint16)NS_PTR_TO_INT32(closure));
|
2001-11-14 14:21:54 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// IMPORTANT: Assumption is that all images for a Presentation
|
|
|
|
// have the same Animation Mode (pavlov said this was OK)
|
|
|
|
//
|
|
|
|
// Walks content and set the animation mode
|
|
|
|
// this is a way to turn on/off image animations
|
2004-08-01 03:15:21 +04:00
|
|
|
void nsPresContext::SetImgAnimations(nsIContent *aParent, PRUint16 aMode)
|
2001-11-14 14:21:54 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imgContent(do_QueryInterface(aParent));
|
2001-11-14 14:21:54 +03:00
|
|
|
if (imgContent) {
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<imgIRequest> imgReq;
|
|
|
|
imgContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imgReq));
|
|
|
|
SetImgAnimModeOnImgReq(imgReq, aMode);
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
PRUint32 count = aParent->GetChildCount();
|
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
|
|
|
SetImgAnimations(aParent->GetChildAt(i), aMode);
|
2001-11-14 14:21:54 +03:00
|
|
|
}
|
|
|
|
}
|
2000-05-13 05:39:20 +04:00
|
|
|
|
2003-12-26 07:24:11 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetImageAnimationModeInternal(PRUint16 aMode)
|
2000-05-13 05:39:20 +04:00
|
|
|
{
|
2001-11-14 17:03:09 +03:00
|
|
|
NS_ASSERTION(aMode == imgIContainer::kNormalAnimMode ||
|
|
|
|
aMode == imgIContainer::kDontAnimMode ||
|
|
|
|
aMode == imgIContainer::kLoopOnceAnimMode, "Wrong Animation Mode is being set!");
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
// Image animation mode cannot be changed when rendering to a printer.
|
|
|
|
if (mMedium == nsLayoutAtoms::print)
|
|
|
|
return;
|
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// This hash table contains a list of background images
|
|
|
|
// so iterate over it and set the mode
|
2004-04-30 08:11:02 +04:00
|
|
|
mImageLoaders.Enumerate(set_animation_mode, NS_INT32_TO_PTR(aMode));
|
2001-11-14 14:21:54 +03:00
|
|
|
|
|
|
|
// Now walk the content tree and set the animation mode
|
|
|
|
// on all the images
|
|
|
|
if (mShell != nsnull) {
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-11-14 14:21:54 +03:00
|
|
|
if (doc) {
|
2003-10-22 10:09:48 +04:00
|
|
|
nsIContent *rootContent = doc->GetRootContent();
|
2001-11-14 14:21:54 +03:00
|
|
|
if (rootContent) {
|
|
|
|
SetImgAnimations(rootContent, aMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-13 05:39:20 +04:00
|
|
|
mImageAnimationMode = aMode;
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetImageAnimationModeExternal(PRUint16 aMode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-07-29 23:41:39 +04:00
|
|
|
SetImageAnimationModeInternal(aMode);
|
|
|
|
}
|
1998-08-28 00:43:04 +04:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
already_AddRefed<nsIFontMetrics>
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetMetricsForInternal(const nsFont& aFont)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
1999-02-12 20:45:58 +03:00
|
|
|
nsIFontMetrics* metrics = nsnull;
|
2004-06-09 03:53:59 +04:00
|
|
|
mDeviceContext->GetMetricsFor(aFont, mLangGroup, metrics);
|
2004-07-29 23:41:39 +04:00
|
|
|
return metrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIFontMetrics>
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetMetricsForExternal(const nsFont& aFont)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
return GetMetricsForInternal(aFont);
|
1999-02-12 20:45:58 +03:00
|
|
|
}
|
|
|
|
|
2004-02-01 01:41:40 +03:00
|
|
|
const nsFont*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetDefaultFontInternal(PRUint8 aFontID) const
|
1999-02-12 20:45:58 +03:00
|
|
|
{
|
2004-02-01 01:41:40 +03:00
|
|
|
const nsFont *font;
|
2001-09-27 22:34:30 +04:00
|
|
|
switch (aFontID) {
|
|
|
|
// Special (our default variable width font and fixed width font)
|
|
|
|
case kPresContext_DefaultVariableFont_ID:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultVariableFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kPresContext_DefaultFixedFont_ID:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultFixedFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
// CSS
|
|
|
|
case kGenericFont_serif:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultSerifFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_sans_serif:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultSansSerifFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_monospace:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultMonospaceFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_cursive:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultCursiveFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_fantasy:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = &mDefaultFantasyFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
default:
|
2004-02-01 01:41:40 +03:00
|
|
|
font = nsnull;
|
2001-09-27 22:34:30 +04:00
|
|
|
NS_ERROR("invalid arg");
|
|
|
|
break;
|
|
|
|
}
|
2004-02-01 01:41:40 +03:00
|
|
|
return font;
|
1998-07-17 09:41:41 +04:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
const nsFont*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetDefaultFontExternal(PRUint8 aFontID) const
|
2001-11-03 17:59:39 +03:00
|
|
|
{
|
2004-07-29 23:41:39 +04:00
|
|
|
return GetDefaultFontInternal(aFontID);
|
|
|
|
}
|
2001-11-03 17:59:39 +03:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
float
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::TwipsToPixelsForFonts() const
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
2004-02-03 01:17:21 +03:00
|
|
|
float app2dev;
|
2001-11-03 17:59:39 +03:00
|
|
|
#ifdef NS_PRINT_PREVIEW
|
2004-02-03 01:17:21 +03:00
|
|
|
// If an alternative DC is available we want to use
|
|
|
|
// it to get the scaling factor for fonts. Usually, the AltDC
|
|
|
|
// is a printing DC so therefore we need to get the printers
|
|
|
|
// scaling values for calculating the font heights
|
|
|
|
nsCOMPtr<nsIDeviceContext> altDC;
|
|
|
|
mDeviceContext->GetAltDevice(getter_AddRefs(altDC));
|
|
|
|
if (altDC) {
|
2004-02-05 04:57:10 +03:00
|
|
|
app2dev = altDC->AppUnitsToDevUnits();
|
2004-02-03 01:17:21 +03:00
|
|
|
} else {
|
2004-02-05 04:57:10 +03:00
|
|
|
app2dev = mDeviceContext->AppUnitsToDevUnits();
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
2004-02-03 01:17:21 +03:00
|
|
|
#else
|
2004-02-05 04:57:10 +03:00
|
|
|
app2dev = mDeviceContext->AppUnitsToDevUnits();
|
2004-02-03 01:17:21 +03:00
|
|
|
#endif
|
2004-07-29 23:41:39 +04:00
|
|
|
return app2dev;
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
float
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::ScaledPixelsToTwips() const
|
1998-11-14 04:52:27 +03:00
|
|
|
{
|
2004-02-03 01:17:21 +03:00
|
|
|
float scale;
|
|
|
|
float p2t;
|
1998-11-14 04:52:27 +03:00
|
|
|
|
2004-02-05 04:57:10 +03:00
|
|
|
p2t = mDeviceContext->DevUnitsToAppUnits();
|
2004-07-29 23:41:39 +04:00
|
|
|
if (mDoScaledTwips) {
|
|
|
|
mDeviceContext->GetCanonicalPixelScale(scale);
|
|
|
|
scale = p2t * scale;
|
|
|
|
} else {
|
|
|
|
scale = p2t;
|
|
|
|
}
|
2004-02-03 01:17:21 +03:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
return scale;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2005-08-13 15:54:22 +04:00
|
|
|
void
|
|
|
|
nsPresContext::SetTextZoomExternal(float aZoom)
|
|
|
|
{
|
|
|
|
SetTextZoomInternal(aZoom);
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
imgIRequest*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::LoadImage(imgIRequest* aImage, nsIFrame* aTargetFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-08-10 00:22:39 +04:00
|
|
|
// look and see if we have a loader for the target frame.
|
1999-02-12 20:45:58 +03:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
nsVoidKey key(aTargetFrame);
|
|
|
|
nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, mImageLoaders.Get(&key)); // addrefs
|
1998-05-09 07:22:01 +04:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
if (!loader) {
|
2004-02-19 21:56:13 +03:00
|
|
|
loader = new nsImageLoader();
|
|
|
|
if (!loader)
|
2004-07-29 23:41:39 +04:00
|
|
|
return nsnull;
|
2000-02-15 07:49:32 +03:00
|
|
|
|
2004-02-19 21:56:13 +03:00
|
|
|
NS_ADDREF(loader); // new
|
2001-08-10 00:22:39 +04:00
|
|
|
|
|
|
|
loader->Init(aTargetFrame, this);
|
2004-02-19 21:56:13 +03:00
|
|
|
mImageLoaders.Put(&key, loader);
|
1998-11-26 21:10:10 +03:00
|
|
|
}
|
1998-11-23 20:18:34 +03:00
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
loader->Load(aImage);
|
1999-04-14 01:49:28 +04:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
imgIRequest *request = loader->GetRequest();
|
2001-08-10 00:22:39 +04:00
|
|
|
NS_RELEASE(loader);
|
2001-05-22 02:40:10 +04:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
return request;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::StopImagesFor(nsIFrame* aTargetFrame)
|
1998-11-26 21:10:10 +03:00
|
|
|
{
|
2001-08-10 00:22:39 +04:00
|
|
|
nsVoidKey key(aTargetFrame);
|
|
|
|
nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, mImageLoaders.Get(&key)); // addrefs
|
2000-09-22 00:17:04 +04:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
if (loader) {
|
|
|
|
loader->Destroy();
|
|
|
|
NS_RELEASE(loader);
|
1998-11-26 21:10:10 +03:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
mImageLoaders.Remove(&key);
|
1999-04-14 01:49:28 +04:00
|
|
|
}
|
1998-05-09 07:22:01 +04:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetContainer(nsISupports* aHandler)
|
1999-04-30 13:04:36 +04:00
|
|
|
{
|
2002-11-07 03:59:25 +03:00
|
|
|
mContainer = do_GetWeakReference(aHandler);
|
2001-10-17 03:59:25 +04:00
|
|
|
if (mContainer) {
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
already_AddRefed<nsISupports>
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetContainerInternal()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-02-01 13:09:07 +03:00
|
|
|
nsISupports *result;
|
|
|
|
if (mContainer)
|
|
|
|
CallQueryReferent(mContainer.get(), &result);
|
|
|
|
else
|
|
|
|
result = nsnull;
|
2002-11-07 03:59:25 +03:00
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-06-24 01:53:02 +04:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
already_AddRefed<nsISupports>
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetContainerExternal()
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
return GetContainerInternal();
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
2004-04-13 04:28:44 +04:00
|
|
|
PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::BidiEnabledInternal() const
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2004-04-13 04:28:44 +04:00
|
|
|
PRBool bidiEnabled = PR_FALSE;
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsPresContext::GetBidiEnabled");
|
2001-03-09 06:13:03 +03:00
|
|
|
if (mShell) {
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_ASSERTION(doc, "PresShell has no document in nsPresContext::GetBidiEnabled");
|
2001-03-09 06:13:03 +03:00
|
|
|
if (doc) {
|
2004-04-13 04:28:44 +04:00
|
|
|
bidiEnabled = doc->GetBidiEnabled();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
2004-04-13 04:28:44 +04:00
|
|
|
return bidiEnabled;
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::BidiEnabledExternal() const
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
return BidiEnabledInternal();
|
|
|
|
}
|
|
|
|
|
2004-04-13 04:28:44 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetBidiEnabled(PRBool aBidiEnabled) const
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
|
|
|
if (mShell) {
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-03-09 06:13:03 +03:00
|
|
|
if (doc) {
|
2001-05-16 17:40:08 +04:00
|
|
|
doc->SetBidiEnabled(aBidiEnabled);
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
nsBidiPresUtils*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetBidiUtils()
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2004-07-29 23:41:39 +04:00
|
|
|
if (!mBidiUtils)
|
2001-03-09 06:13:03 +03:00
|
|
|
mBidiUtils = new nsBidiPresUtils;
|
2004-07-29 23:41:39 +04:00
|
|
|
|
|
|
|
return mBidiUtils;
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow)
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2005-11-13 12:55:09 +03:00
|
|
|
// Don't do all this stuff unless the options have changed.
|
|
|
|
if (aSource == GetBidi()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!(aForceReflow && (GetBidi() == 0)),
|
|
|
|
"ForceReflow on new prescontext");
|
|
|
|
|
2005-11-09 01:45:49 +03:00
|
|
|
GetDocument()->SetBidiOptions(aSource);
|
|
|
|
if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(aSource)
|
|
|
|
|| IBMBIDI_NUMERAL_HINDI == GET_BIDI_OPTION_NUMERAL(aSource)) {
|
2001-05-16 17:40:08 +04:00
|
|
|
SetBidiEnabled(PR_TRUE);
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
if (IBMBIDI_TEXTTYPE_VISUAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2001-03-09 06:13:03 +03:00
|
|
|
SetVisualMode(PR_TRUE);
|
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
else if (IBMBIDI_TEXTTYPE_LOGICAL == GET_BIDI_OPTION_TEXTTYPE(aSource)) {
|
2001-03-09 06:13:03 +03:00
|
|
|
SetVisualMode(PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
2004-08-10 01:19:15 +04:00
|
|
|
nsIDocument* doc = mShell->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
SetVisualMode(IsVisualCharset(doc->GetDocumentCharacterSet()));
|
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
2005-11-13 12:55:09 +03:00
|
|
|
if (aForceReflow) {
|
2004-07-29 23:41:39 +04:00
|
|
|
ClearStyleDataAndReflow();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
2005-11-09 01:45:49 +03:00
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsPresContext::GetBidi() const
|
|
|
|
{
|
|
|
|
return GetDocument()->GetBidiOptions();
|
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#endif //IBMBIDI
|
2000-03-21 18:51:59 +03:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
nsITheme*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetTheme()
|
2001-12-18 01:51:39 +03:00
|
|
|
{
|
|
|
|
if (!mNoTheme && !mTheme) {
|
|
|
|
mTheme = do_GetService("@mozilla.org/chrome/chrome-native-theme;1");
|
|
|
|
if (!mTheme)
|
|
|
|
mNoTheme = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
return mTheme;
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::ThemeChanged()
|
2001-12-18 01:51:39 +03:00
|
|
|
{
|
|
|
|
// Tell the theme that it changed, so it can flush any handles to stale theme
|
|
|
|
// data.
|
|
|
|
if (mTheme)
|
|
|
|
mTheme->ThemeChanged();
|
|
|
|
|
|
|
|
// Clear all cached nsILookAndFeel colors.
|
|
|
|
if (mLookAndFeel)
|
|
|
|
mLookAndFeel->LookAndFeelChanged();
|
2004-09-17 10:27:01 +04:00
|
|
|
|
|
|
|
// We have to clear style data because the assumption of style rule
|
|
|
|
// immutability has been violated since any style rule that uses
|
|
|
|
// system colors or fonts (and probably -moz-appearance as well) has
|
|
|
|
// changed.
|
|
|
|
nsPresContext::ClearStyleDataAndReflow();
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SysColorChanged()
|
2002-06-04 21:47:54 +04:00
|
|
|
{
|
|
|
|
if (mLookAndFeel) {
|
|
|
|
// Don't use the cached values for the system colors
|
|
|
|
mLookAndFeel->LookAndFeelChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset default background and foreground colors for the document since
|
|
|
|
// they may be using system colors
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
|
|
|
|
// Clear out all of the style data since it may contain RGB values
|
|
|
|
// which originated from system colors.
|
2002-09-11 07:03:49 +04:00
|
|
|
nsCOMPtr<nsISelectionImageService> imageService;
|
|
|
|
nsresult result;
|
|
|
|
imageService = do_GetService(kSelectionImageService, &result);
|
|
|
|
if (NS_SUCCEEDED(result) && imageService)
|
|
|
|
{
|
|
|
|
imageService->Reset();
|
|
|
|
}
|
2002-12-14 19:18:57 +03:00
|
|
|
|
|
|
|
// We need to do a full reflow (and view update) here. Clearing the style
|
|
|
|
// data without reflowing/updating views will lead to incorrect change hints
|
|
|
|
// later, because when generating change hints, any style structs which have
|
|
|
|
// been cleared and not reread are assumed to not be used at all.
|
2004-07-29 23:41:39 +04:00
|
|
|
ClearStyleDataAndReflow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::GetPageDim(nsRect* aActualRect, nsRect* aAdjRect)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
if (mMedium == nsLayoutAtoms::print) {
|
|
|
|
if (aActualRect) {
|
|
|
|
PRInt32 width, height;
|
|
|
|
nsresult rv = mDeviceContext->GetDeviceSurfaceDimensions(width, height);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
aActualRect->SetRect(0, 0, width, height);
|
|
|
|
}
|
|
|
|
if (aAdjRect)
|
|
|
|
*aAdjRect = mPageDim;
|
|
|
|
} else {
|
|
|
|
if (aActualRect)
|
|
|
|
aActualRect->SetRect(0, 0, 0, 0);
|
|
|
|
if (aAdjRect)
|
|
|
|
aAdjRect->SetRect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetPageDim(const nsRect& aPageDim)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
if (mMedium == nsLayoutAtoms::print)
|
|
|
|
mPageDim = aPageDim;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetPaginatedScrolling(PRBool aPaginated)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
if (mType == eContext_PrintPreview)
|
|
|
|
mCanPaginatedScroll = aPaginated;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::SetPrintSettings(nsIPrintSettings *aPrintSettings)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
|
|
|
if (mMedium == nsLayoutAtoms::print)
|
|
|
|
mPrintSettings = aPrintSettings;
|
|
|
|
}
|
|
|
|
|
2005-01-20 06:39:09 +03:00
|
|
|
PRBool
|
|
|
|
nsPresContext::EnsureVisible(PRBool aUnsuppressFocus)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
// Make sure this is the content viewer we belong with
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docV(do_QueryInterface(cv));
|
|
|
|
if (docV) {
|
|
|
|
nsCOMPtr<nsPresContext> currentPresContext;
|
|
|
|
docV->GetPresContext(getter_AddRefs(currentPresContext));
|
|
|
|
if (currentPresContext == this) {
|
|
|
|
// OK, this is us. We want to call Show() on the content viewer. But
|
|
|
|
// first, we need to suppress focus changes; otherwise the focus will
|
|
|
|
// get sent to the wrong place (toplevel window).
|
|
|
|
nsCOMPtr<nsPIDOMWindow> privWindow = do_GetInterface(docShell);
|
|
|
|
// XXXbz privWindow should never really be null!
|
|
|
|
nsIFocusController* fc =
|
|
|
|
privWindow ? privWindow->GetRootFocusController() : nsnull;
|
|
|
|
if (fc) {
|
|
|
|
fc->SetSuppressFocus(PR_TRUE,
|
|
|
|
"nsPresContext::EnsureVisible Suppression");
|
|
|
|
}
|
|
|
|
cv->Show();
|
|
|
|
if (fc && aUnsuppressFocus) {
|
|
|
|
fc->SetSuppressFocus(PR_FALSE,
|
|
|
|
"nsPresContext::EnsureVisible Suppression");
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_NewPresContext(nsPresContext::nsPresContextType aType,
|
|
|
|
nsPresContext** aInstancePtrResult)
|
2004-07-29 23:41:39 +04:00
|
|
|
{
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext *context = new nsPresContext(aType);
|
2004-07-29 23:41:39 +04:00
|
|
|
if (!context)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aInstancePtrResult = context);
|
2004-01-28 03:18:22 +03:00
|
|
|
return NS_OK;
|
2002-06-04 21:47:54 +04:00
|
|
|
}
|
2001-12-18 01:51:39 +03:00
|
|
|
|
2000-04-21 18:59:47 +04:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
2004-07-29 23:41:39 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext::CountReflows(const char * aName,
|
2004-07-29 23:41:39 +04:00
|
|
|
PRUint32 aType, nsIFrame * aFrame)
|
2000-04-21 18:59:47 +04:00
|
|
|
{
|
|
|
|
if (mShell) {
|
2001-02-22 16:58:17 +03:00
|
|
|
mShell->CountReflows(aName, aType, aFrame);
|
2000-04-21 18:59:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|