2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
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.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* 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
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
1998-07-31 09:54:59 +04:00
|
|
|
#include "nsIPref.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsILinkHandler.h"
|
2001-07-25 10:33:06 +04:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIStyleSet.h"
|
1999-09-04 03:35:41 +04:00
|
|
|
#include "nsIFrameManager.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"
|
1998-11-06 19:16:01 +03:00
|
|
|
#include "nsIStyleContext.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-04-25 11:10:48 +04:00
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsIBox.h"
|
2000-05-16 02:05:45 +04:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-05-22 02:40:10 +04:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsNetUtil.h"
|
2001-05-08 05:40:09 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2001-12-18 01:51:39 +03:00
|
|
|
|
2001-05-08 05:40:09 +04:00
|
|
|
#include "prprf.h"
|
2002-02-15 02:31:54 +03:00
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#endif // IBMBIDI
|
2000-02-15 07:49:32 +03:00
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// Needed for Start/Stop of Image Animation
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
|
|
|
#include "nsIImageFrame.h"
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-08-17 05:14:21 +04:00
|
|
|
int PR_CALLBACK
|
|
|
|
nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data)
|
1998-11-06 19:16:01 +03:00
|
|
|
{
|
|
|
|
nsPresContext* presContext = (nsPresContext*)instance_data;
|
|
|
|
|
|
|
|
NS_ASSERTION(nsnull != presContext, "bad instance data");
|
|
|
|
if (nsnull != presContext) {
|
|
|
|
presContext->PreferenceChanged(aPrefName);
|
|
|
|
}
|
|
|
|
return 0; // PREF_OK
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRBool
|
|
|
|
IsVisualCharset(const nsAutoString& aCharset)
|
|
|
|
{
|
|
|
|
if (aCharset.EqualsIgnoreCase("ibm864") // Arabic//ahmed
|
|
|
|
|| aCharset.EqualsIgnoreCase("ibm862") // Hebrew
|
|
|
|
|| aCharset.EqualsIgnoreCase("iso-8859-8") ) { // Hebrew
|
|
|
|
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"
|
|
|
|
static NS_DEFINE_CID(kEventStateManagerCID, NS_EVENTSTATEMANAGER_CID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsPresContext::nsPresContext()
|
2001-09-27 22:34:30 +04:00
|
|
|
: mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)),
|
|
|
|
mDefaultFixedFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(10)),
|
|
|
|
mDefaultSerifFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)),
|
|
|
|
mDefaultSansSerifFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)),
|
|
|
|
mDefaultMonospaceFont("monospace", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
|
|
|
|
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,
|
2001-12-18 01:51:39 +03:00
|
|
|
NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)),
|
|
|
|
mNoTheme(PR_FALSE)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
1999-07-07 05:21:25 +04:00
|
|
|
mCompatibilityMode = eCompatibility_Standard;
|
|
|
|
mCompatibilityLocked = PR_FALSE;
|
1999-09-09 23:43:27 +04:00
|
|
|
mWidgetRenderingMode = eWidgetRendering_Gfx;
|
2001-11-14 17:03:09 +03:00
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
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
|
|
|
|
2000-09-21 05:20:00 +04:00
|
|
|
mStopped = PR_FALSE;
|
|
|
|
mStopChrome = PR_TRUE;
|
2001-08-10 00:22:39 +04:00
|
|
|
|
1999-11-19 10:29:13 +03:00
|
|
|
mShell = nsnull;
|
1998-07-25 05:11:49 +04:00
|
|
|
|
1998-07-17 09:41:41 +04:00
|
|
|
mDefaultColor = NS_RGB(0x00, 0x00, 0x00);
|
|
|
|
mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
2001-01-30 07:41:49 +03:00
|
|
|
nsILookAndFeel* look = nsnull;
|
|
|
|
if (NS_SUCCEEDED(GetLookAndFeel(&look)) && look) {
|
|
|
|
look->GetColor(nsILookAndFeel::eColor_WindowForeground, mDefaultColor);
|
|
|
|
look->GetColor(nsILookAndFeel::eColor_WindowBackground, mDefaultBackgroundColor);
|
|
|
|
NS_RELEASE(look);
|
|
|
|
}
|
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
|
|
|
|
mMinimumFontSize = 0;
|
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
mLinkColor = NS_RGB(0x33, 0x33, 0xFF);
|
|
|
|
mVisitedLinkColor = NS_RGB(0x66, 0x00, 0xCC);
|
|
|
|
mUnderlineLinks = PR_TRUE;
|
|
|
|
|
2001-04-10 02:17:11 +04:00
|
|
|
mUseFocusColors = PR_FALSE;
|
|
|
|
mFocusTextColor = mDefaultColor;
|
|
|
|
mFocusBackgroundColor = mDefaultBackgroundColor;
|
|
|
|
mFocusRingWidth = 1;
|
|
|
|
mFocusRingOnAnything = PR_FALSE;
|
|
|
|
|
1999-06-13 02:31:15 +04:00
|
|
|
mDefaultBackgroundImageAttachment = NS_STYLE_BG_ATTACHMENT_SCROLL;
|
|
|
|
mDefaultBackgroundImageRepeat = NS_STYLE_BG_REPEAT_XY;
|
|
|
|
mDefaultBackgroundImageOffsetX = mDefaultBackgroundImageOffsetY = 0;
|
2000-09-21 02:59:20 +04:00
|
|
|
mLanguageSpecificTransformType = eLanguageSpecificTransformType_Unknown;
|
2001-01-27 17:09:34 +03:00
|
|
|
mIsRenderingOnlySelection = PR_FALSE;
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
mIsVisual = PR_FALSE;
|
|
|
|
mBidiUtils = nsnull;
|
|
|
|
mIsBidiSystem = PR_FALSE;
|
|
|
|
mBidi = 0;
|
|
|
|
#endif // IBMBIDI
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext::~nsPresContext()
|
|
|
|
{
|
2001-08-10 00:22:39 +04:00
|
|
|
mImageLoaders.Enumerate(destroy_loads);
|
|
|
|
|
2000-06-02 03:12:26 +04:00
|
|
|
if (mShell) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
mShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
|
|
|
doc->RemoveCharSetObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
mShell = nsnull;
|
|
|
|
|
1999-04-30 13:04:36 +04:00
|
|
|
if (mEventManager)
|
|
|
|
mEventManager->SetPresContext(nsnull); // unclear if this is needed, but can't hurt
|
1998-11-18 08:25:26 +03:00
|
|
|
|
1998-11-06 19:16:01 +03:00
|
|
|
// Unregister preference callbacks
|
1999-04-30 13:04:36 +04:00
|
|
|
if (mPrefs) {
|
2001-08-17 05:14:21 +04:00
|
|
|
mPrefs->UnregisterCallback("font.", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->UnregisterCallback("browser.display.", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->UnregisterCallback("browser.underline_anchors", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->UnregisterCallback("browser.anchor_color", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->UnregisterCallback("browser.visited_color", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->UnregisterCallback("network.image.imageBehavior", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->UnregisterCallback("image.animation_mode", nsPresContext::PrefChangedCallback, (void*)this);
|
2001-11-01 08:49:45 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
mPrefs->UnregisterCallback("bidi.", PrefChangedCallback, (void*)this);
|
|
|
|
#endif
|
1998-11-13 05:47:33 +03:00
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (mBidiUtils) {
|
|
|
|
delete mBidiUtils;
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-06-02 03:12:26 +04:00
|
|
|
NS_IMPL_ISUPPORTS2(nsPresContext, nsIPresContext, 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
|
|
|
|
nsPresContext::GetFontPreferences()
|
|
|
|
{
|
2001-09-27 22:34:30 +04:00
|
|
|
if (!mPrefs || !mLanguage)
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
float p2t;
|
|
|
|
GetScaledPixelsToTwips(&p2t);
|
|
|
|
mDefaultVariableFont.size = NSFloatPixelsToTwips((float)16, p2t);
|
|
|
|
mDefaultFixedFont.size = NSFloatPixelsToTwips((float)13, p2t);
|
|
|
|
|
|
|
|
nsAutoString langGroup;
|
|
|
|
nsCOMPtr<nsIAtom> langGroupAtom;
|
|
|
|
mLanguage->GetLanguageGroup(getter_AddRefs(langGroupAtom));
|
|
|
|
langGroupAtom->ToString(langGroup);
|
|
|
|
|
|
|
|
nsCAutoString pref;
|
|
|
|
nsXPIDLString value;
|
|
|
|
nsXPIDLCString cvalue;
|
|
|
|
|
|
|
|
// get the current applicable font-size unit
|
|
|
|
enum {eUnit_unknown = -1, eUnit_px, eUnit_pt};
|
|
|
|
PRInt32 unit = eUnit_px;
|
|
|
|
nsresult rv = mPrefs->CopyCharPref("font.size.unit", getter_Copies(cvalue));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (!PL_strcmp(cvalue.get(), "px")) {
|
|
|
|
unit = eUnit_px;
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else if (!PL_strcmp(cvalue.get(), "pt")) {
|
|
|
|
unit = eUnit_pt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARNING("unexpected font-size unit -- expected: 'px' or 'pt'");
|
|
|
|
unit = eUnit_unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get font.minimum-size.[langGroup]
|
|
|
|
PRInt32 size;
|
|
|
|
pref.Assign("font.minimum-size."); pref.Append(NS_ConvertUCS2toUTF8(langGroup));
|
|
|
|
rv = mPrefs->GetIntPref(pref.get(), &size);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
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]);
|
|
|
|
generic_dot_langGroup.Append(NS_ConvertUCS2toUTF8(langGroup));
|
|
|
|
|
|
|
|
nsFont* font;
|
|
|
|
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;
|
|
|
|
default: NS_ERROR("not reached - bogus to silence some compilers"); 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);
|
|
|
|
rv = mPrefs->CopyUnicharPref(pref.get(), getter_Copies(value));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
font->name.Assign(value);
|
2000-01-15 19:30:13 +03:00
|
|
|
}
|
2001-09-27 22:34:30 +04:00
|
|
|
else {
|
|
|
|
rv = mPrefs->CopyUnicharPref("font.default", getter_Copies(value));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mDefaultVariableFont.name.Assign(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
2001-10-27 11:43:56 +04:00
|
|
|
rv = mPrefs->GetIntPref(pref.get(), &size);
|
2001-09-27 22:34:30 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && size > 0) {
|
|
|
|
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);
|
|
|
|
rv = mPrefs->CopyCharPref(pref.get(), getter_Copies(cvalue));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
font->sizeAdjust = (float)atof(cvalue.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_rbs
|
|
|
|
nsCAutoString family(NS_ConvertUCS2toUTF8(font->name));
|
|
|
|
printf("%s Family-list:%s size:%d sizeAdjust:%.2f\n",
|
|
|
|
generic_dot_langGroup.get(), family.get(), font->size, font->sizeAdjust);
|
|
|
|
#endif
|
2000-01-12 19:10:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-17 03:59:25 +04:00
|
|
|
void
|
|
|
|
nsPresContext::GetDocumentColorPreferences()
|
|
|
|
{
|
|
|
|
PRBool usePrefColors = PR_TRUE;
|
|
|
|
PRBool boolPref;
|
|
|
|
nsXPIDLCString colorStr;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(mContainer));
|
|
|
|
if (docShell) {
|
|
|
|
PRInt32 docShellType;
|
|
|
|
docShell->GetItemType(&docShellType);
|
|
|
|
if (nsIDocShellTreeItem::typeChrome == docShellType)
|
|
|
|
usePrefColors = PR_FALSE;
|
|
|
|
}
|
|
|
|
if (usePrefColors) {
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_system_colors", &boolPref))) {
|
|
|
|
usePrefColors = !boolPref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (usePrefColors) {
|
|
|
|
if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) {
|
|
|
|
mDefaultColor = MakeColorPref(colorStr);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.background_color", getter_Copies(colorStr)))) {
|
|
|
|
mDefaultBackgroundColor = MakeColorPref(colorStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Without this here, checking the "use system colors" checkbox
|
|
|
|
// has no affect until the constructor is called again
|
|
|
|
mDefaultColor = NS_RGB(0x00, 0x00, 0x00);
|
|
|
|
mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
|
|
|
|
nsCOMPtr<nsILookAndFeel> look;
|
|
|
|
if (NS_SUCCEEDED(GetLookAndFeel(getter_AddRefs(look))) && look) {
|
|
|
|
look->GetColor(nsILookAndFeel::eColor_WindowForeground, mDefaultColor);
|
|
|
|
look->GetColor(nsILookAndFeel::eColor_WindowBackground, mDefaultBackgroundColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref))) {
|
|
|
|
mUseDocumentColors = boolPref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-06 19:16:01 +03:00
|
|
|
void
|
|
|
|
nsPresContext::GetUserPreferences()
|
|
|
|
{
|
1999-04-03 00:41:58 +04:00
|
|
|
PRInt32 prefInt;
|
1998-11-06 19:16:01 +03:00
|
|
|
|
2001-04-10 02:17:11 +04:00
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.base_font_scaler", &prefInt))) {
|
1998-11-06 19:16:01 +03:00
|
|
|
mFontScaler = prefInt;
|
|
|
|
}
|
|
|
|
|
2001-04-10 02:17:11 +04:00
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("nglayout.compatibility.mode", &prefInt))) {
|
1999-08-08 05:14:50 +04:00
|
|
|
// XXX this should really be a state on the webshell instead of using prefs
|
1999-07-07 05:21:25 +04:00
|
|
|
switch (prefInt) {
|
|
|
|
case 1:
|
|
|
|
mCompatibilityLocked = PR_TRUE;
|
|
|
|
mCompatibilityMode = eCompatibility_Standard;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
mCompatibilityLocked = PR_TRUE;
|
|
|
|
mCompatibilityMode = eCompatibility_NavQuirks;
|
|
|
|
break;
|
|
|
|
case 0: // auto
|
|
|
|
default:
|
|
|
|
mCompatibilityLocked = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mCompatibilityLocked = PR_FALSE; // auto
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
|
|
|
|
2001-04-10 02:17:11 +04:00
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("nglayout.widget.mode", &prefInt))) {
|
1999-03-03 01:43:26 +03:00
|
|
|
mWidgetRenderingMode = (enum nsWidgetRendering)prefInt; // bad cast
|
1999-05-04 01:32:15 +04:00
|
|
|
}
|
1999-03-03 01:43:26 +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
|
2001-10-17 03:59:25 +04:00
|
|
|
PRBool boolPref;
|
|
|
|
nsXPIDLCString colorStr;
|
2001-04-10 02:17:11 +04:00
|
|
|
if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.underline_anchors", &boolPref))) {
|
2000-10-11 12:33:01 +04:00
|
|
|
mUnderlineLinks = boolPref;
|
|
|
|
}
|
2001-05-08 05:40:09 +04:00
|
|
|
if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.anchor_color", getter_Copies(colorStr)))) {
|
|
|
|
mLinkColor = MakeColorPref(colorStr);
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
2001-05-08 05:40:09 +04:00
|
|
|
if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.visited_color", getter_Copies(colorStr)))) {
|
|
|
|
mVisitedLinkColor = MakeColorPref(colorStr);
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
|
|
|
|
2001-04-10 02:17:11 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_focus_colors", &boolPref))) {
|
|
|
|
mUseFocusColors = boolPref;
|
|
|
|
mFocusTextColor = mDefaultColor;
|
|
|
|
mFocusBackgroundColor = mDefaultBackgroundColor;
|
2001-05-08 05:40:09 +04:00
|
|
|
if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_text_color", getter_Copies(colorStr)))) {
|
|
|
|
mFocusTextColor = MakeColorPref(colorStr);
|
2001-04-10 02:17:11 +04:00
|
|
|
}
|
2001-05-08 05:40:09 +04:00
|
|
|
if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_background_color", getter_Copies(colorStr)))) {
|
|
|
|
mFocusBackgroundColor = MakeColorPref(colorStr);
|
2001-04-10 02:17:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_ring_width", &prefInt))) {
|
|
|
|
mFocusRingWidth = prefInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) {
|
|
|
|
mFocusRingOnAnything = boolPref;
|
|
|
|
}
|
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
// * use fonts?
|
2001-04-10 02:17:11 +04:00
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.use_document_fonts", &prefInt))) {
|
2000-10-11 12:33:01 +04:00
|
|
|
mUseDocumentFonts = prefInt == 0 ? PR_FALSE : PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-01-12 19:10:48 +03:00
|
|
|
GetFontPreferences();
|
2001-01-10 02:55:27 +03:00
|
|
|
|
|
|
|
// * image animation
|
|
|
|
char* animatePref = 0;
|
|
|
|
nsresult rv = mPrefs->CopyCharPref("image.animation_mode", &animatePref);
|
|
|
|
if (NS_SUCCEEDED(rv) && animatePref) {
|
|
|
|
if (!nsCRT::strcmp(animatePref, "normal"))
|
2001-11-14 17:03:09 +03:00
|
|
|
mImageAnimationModePref = imgIContainer::kNormalAnimMode;
|
2001-01-10 02:55:27 +03:00
|
|
|
else if (!nsCRT::strcmp(animatePref, "none"))
|
2001-11-14 17:03:09 +03:00
|
|
|
mImageAnimationModePref = imgIContainer::kDontAnimMode;
|
2001-01-10 02:55:27 +03:00
|
|
|
else if (!nsCRT::strcmp(animatePref, "once"))
|
2001-11-14 17:03:09 +03:00
|
|
|
mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode;
|
2001-01-10 02:55:27 +03:00
|
|
|
nsMemory::Free(animatePref);
|
|
|
|
}
|
2001-11-01 08:49:45 +03:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.direction", &prefInt))) {
|
|
|
|
SET_BIDI_OPTION_DIRECTION(mBidi, prefInt);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.texttype", &prefInt))) {
|
|
|
|
SET_BIDI_OPTION_TEXTTYPE(mBidi, prefInt);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.controlstextmode", &prefInt))) {
|
|
|
|
SET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi, prefInt);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.clipboardtextmode", &prefInt))) {
|
|
|
|
SET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi, prefInt);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.numeral", &prefInt))) {
|
|
|
|
SET_BIDI_OPTION_NUMERAL(mBidi, prefInt);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.support", &prefInt))) {
|
|
|
|
SET_BIDI_OPTION_SUPPORT(mBidi, prefInt);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.characterset", &prefInt))) {
|
|
|
|
SET_BIDI_OPTION_CHARACTERSET(mBidi, prefInt);
|
|
|
|
}
|
|
|
|
#endif
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
NS_IMETHODIMP
|
2001-10-31 01:58:00 +03:00
|
|
|
nsPresContext::GetCachedBoolPref(PRUint32 aPrefType, PRBool& aValue)
|
2000-10-11 12:33:01 +04:00
|
|
|
{
|
2001-09-27 22:34:30 +04:00
|
|
|
nsresult rv = NS_OK;
|
2000-10-11 12:33:01 +04:00
|
|
|
|
2001-09-27 22:34:30 +04:00
|
|
|
switch (aPrefType) {
|
2000-10-11 12:33:01 +04:00
|
|
|
case kPresContext_UseDocumentFonts :
|
|
|
|
aValue = mUseDocumentFonts;
|
|
|
|
break;
|
|
|
|
case kPresContext_UseDocumentColors:
|
|
|
|
aValue = mUseDocumentColors;
|
|
|
|
break;
|
|
|
|
case kPresContext_UnderlineLinks:
|
|
|
|
aValue = mUnderlineLinks;
|
|
|
|
break;
|
|
|
|
default :
|
2001-09-27 22:34:30 +04:00
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
NS_ERROR("invalid arg");
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-10-31 01:58:00 +03:00
|
|
|
nsPresContext::GetCachedIntPref(PRUint32 aPrefType, PRInt32& aValue)
|
2001-09-27 22:34:30 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
switch (aPrefType) {
|
|
|
|
case kPresContext_MinimumFontSize:
|
|
|
|
aValue = mMinimumFontSize;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
NS_ERROR("invalid arg");
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-04-03 01:52:17 +04:00
|
|
|
NS_IMETHODIMP
|
2001-07-25 10:33:06 +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.
|
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
mShell->GetStyleSet(getter_AddRefs(set));
|
|
|
|
set->ClearStyleData(this, nsnull, nsnull);
|
|
|
|
|
1999-09-15 02:16:42 +04:00
|
|
|
// Have the root frame's style context remap its style based on the
|
|
|
|
// user preferences
|
|
|
|
nsIFrame* rootFrame;
|
|
|
|
|
|
|
|
mShell->GetRootFrame(&rootFrame);
|
|
|
|
if (rootFrame) {
|
2000-04-25 11:10:48 +04:00
|
|
|
// boxes know how to coelesce style changes. So if our root frame is a box
|
|
|
|
// then tell it to handle it. If its a block we are stuck with a full top to bottom
|
|
|
|
// reflow. -EDV
|
|
|
|
nsIFrame* child = nsnull;
|
|
|
|
rootFrame->FirstChild(this, nsnull, &child);
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIBox> box = do_QueryInterface(child, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && box) {
|
|
|
|
nsBoxLayoutState state(this);
|
|
|
|
box->MarkStyleChange(state);
|
|
|
|
} else {
|
|
|
|
// 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();
|
|
|
|
}
|
1999-09-15 02:16:42 +04:00
|
|
|
}
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
2000-04-03 01:52:17 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPresContext::PreferenceChanged(const char* aPrefName)
|
|
|
|
{
|
2001-07-25 10:33:06 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(mContainer));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-04-03 01:52:17 +04:00
|
|
|
if (mDeviceContext) {
|
|
|
|
mDeviceContext->FlushFontCache();
|
2001-07-25 10:33:06 +04:00
|
|
|
ClearStyleDataAndReflow();
|
2000-04-03 01:52:17 +04:00
|
|
|
}
|
1998-11-06 19:16:01 +03:00
|
|
|
}
|
|
|
|
|
1998-11-26 21:10:10 +03:00
|
|
|
NS_IMETHODIMP
|
2000-03-02 10:13:02 +03:00
|
|
|
nsPresContext::Init(nsIDeviceContext* aDeviceContext)
|
1998-06-25 08:24:45 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!(mInitialized == PR_TRUE), "attempt to reinit pres context");
|
|
|
|
|
1999-04-30 13:04:36 +04:00
|
|
|
mDeviceContext = dont_QueryInterface(aDeviceContext);
|
1998-07-31 09:54:59 +04:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
|
|
|
|
mPrefs = do_GetService(NS_PREF_CONTRACTID);
|
1999-04-30 13:04:36 +04:00
|
|
|
if (mPrefs) {
|
1998-11-06 19:16:01 +03:00
|
|
|
// Register callbacks so we're notified when the preferences change
|
2001-08-17 05:14:21 +04:00
|
|
|
mPrefs->RegisterCallback("font.", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->RegisterCallback("browser.display.", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->RegisterCallback("browser.underline_anchors", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->RegisterCallback("browser.anchor_color", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->RegisterCallback("browser.visited_color", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->RegisterCallback("network.image.imageBehavior", nsPresContext::PrefChangedCallback, (void*)this);
|
|
|
|
mPrefs->RegisterCallback("image.animation_mode", nsPresContext::PrefChangedCallback, (void*)this);
|
2001-11-01 08:49:45 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
mPrefs->RegisterCallback("bidi.", PrefChangedCallback, (void*)this);
|
|
|
|
#endif
|
1998-07-31 09:54:59 +04:00
|
|
|
|
1998-11-06 19:16:01 +03:00
|
|
|
// Initialize our state from the user preferences
|
|
|
|
GetUserPreferences();
|
1998-07-31 09:54:59 +04:00
|
|
|
}
|
|
|
|
|
1998-06-25 08:24:45 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mInitialized = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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
|
1998-11-26 21:10:10 +03:00
|
|
|
NS_IMETHODIMP
|
1998-05-09 07:22:01 +04:00
|
|
|
nsPresContext::SetShell(nsIPresShell* aShell)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
mShell = aShell;
|
1998-09-05 07:52:40 +04:00
|
|
|
if (nsnull != mShell) {
|
1999-02-12 20:45:58 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
if (NS_SUCCEEDED(mShell->GetDocument(getter_AddRefs(doc)))) {
|
1999-02-12 21:41:26 +03:00
|
|
|
NS_ASSERTION(doc, "expect document here");
|
|
|
|
if (doc) {
|
1999-04-30 13:04:36 +04:00
|
|
|
doc->GetBaseURL(*getter_AddRefs(mBaseURL));
|
2001-01-10 02:55:27 +03:00
|
|
|
|
|
|
|
if (mBaseURL) {
|
2001-01-31 04:33:03 +03:00
|
|
|
PRBool isChrome = PR_FALSE;
|
|
|
|
PRBool isRes = PR_FALSE;
|
2001-03-13 05:02:05 +03:00
|
|
|
mBaseURL->SchemeIs("chrome", &isChrome);
|
|
|
|
mBaseURL->SchemeIs("resource", &isRes);
|
2001-01-31 04:33:03 +03:00
|
|
|
|
|
|
|
if (!isChrome && !isRes)
|
2001-01-10 02:55:27 +03:00
|
|
|
mImageAnimationMode = mImageAnimationModePref;
|
|
|
|
else
|
2001-11-14 17:03:09 +03:00
|
|
|
mImageAnimationMode = imgIContainer::kNormalAnimMode;
|
2001-01-10 02:55:27 +03:00
|
|
|
}
|
|
|
|
|
2000-05-06 01:04:36 +04:00
|
|
|
if (mLangService) {
|
1999-12-08 02:27:52 +03:00
|
|
|
nsAutoString charset;
|
2000-06-02 03:12:26 +04:00
|
|
|
doc->AddCharSetObserver(this);
|
1999-12-08 02:27:52 +03:00
|
|
|
doc->GetDocumentCharacterSet(charset);
|
2001-06-30 15:02:25 +04:00
|
|
|
UpdateCharSet(charset.get());
|
1999-12-08 02:27:52 +03:00
|
|
|
}
|
1999-02-12 20:45:58 +03:00
|
|
|
}
|
1998-09-05 07:52:40 +04:00
|
|
|
}
|
|
|
|
}
|
1998-11-26 21:10:10 +03:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetShell(nsIPresShell** aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
*aResult = mShell;
|
1998-05-09 07:22:01 +04:00
|
|
|
NS_IF_ADDREF(mShell);
|
1999-02-12 20:45:58 +03:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 02:59:20 +04:00
|
|
|
void
|
|
|
|
nsPresContext::UpdateCharSet(const PRUnichar* aCharSet)
|
|
|
|
{
|
|
|
|
if (mLangService) {
|
|
|
|
mLangService->LookupCharSet(aCharSet, getter_AddRefs(mLanguage));
|
|
|
|
GetFontPreferences();
|
|
|
|
if (mLanguage) {
|
|
|
|
nsCOMPtr<nsIAtom> langGroupAtom;
|
|
|
|
mLanguage->GetLanguageGroup(getter_AddRefs(langGroupAtom));
|
|
|
|
NS_ASSERTION(langGroupAtom, "non-NULL language group atom expected");
|
|
|
|
if (langGroupAtom.get() == nsLayoutAtoms::Japanese) {
|
|
|
|
mLanguageSpecificTransformType =
|
|
|
|
eLanguageSpecificTransformType_Japanese;
|
|
|
|
}
|
|
|
|
else if (langGroupAtom.get() == nsLayoutAtoms::Korean) {
|
|
|
|
mLanguageSpecificTransformType =
|
|
|
|
eLanguageSpecificTransformType_Korean;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLanguageSpecificTransformType =
|
|
|
|
eLanguageSpecificTransformType_None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
//ahmed
|
|
|
|
mCharset=aCharSet;
|
|
|
|
|
|
|
|
SetVisualMode(IsVisualCharset(mCharset) );
|
|
|
|
#endif // IBMBIDI
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
|
|
|
|
2000-06-02 03:12:26 +04:00
|
|
|
NS_IMETHODIMP
|
2001-10-20 00:52:59 +04:00
|
|
|
nsPresContext::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2000-06-02 03:12:26 +04:00
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
2001-10-20 00:52:59 +04:00
|
|
|
if (!nsCRT::strcmp(aTopic, "charset")) {
|
2000-09-21 02:59:20 +04:00
|
|
|
UpdateCharSet(aData);
|
2001-12-15 02:13:28 +03:00
|
|
|
if (mDeviceContext) {
|
|
|
|
mDeviceContext->FlushFontCache();
|
|
|
|
ClearStyleDataAndReflow();
|
|
|
|
}
|
2001-10-20 00:52:59 +04:00
|
|
|
return NS_OK;
|
2000-09-21 02:59:20 +04:00
|
|
|
}
|
|
|
|
|
2001-10-20 00:52:59 +04:00
|
|
|
NS_WARNING("unrecognized topic in nsPresContext::Observe");
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-06-02 03:12:26 +04:00
|
|
|
}
|
|
|
|
|
1998-07-31 09:54:59 +04:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 20:45:58 +03:00
|
|
|
nsPresContext::GetCompatibilityMode(nsCompatibility* aResult)
|
1998-07-31 09:54:59 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
*aResult = mCompatibilityMode;
|
1998-07-31 09:54:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-03 01:43:26 +03:00
|
|
|
|
1998-07-31 09:54:59 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetCompatibilityMode(nsCompatibility aMode)
|
|
|
|
{
|
1999-07-07 05:21:25 +04:00
|
|
|
if (! mCompatibilityLocked) {
|
|
|
|
mCompatibilityMode = aMode;
|
|
|
|
}
|
2000-06-03 01:45:06 +04:00
|
|
|
|
2000-06-22 00:44:59 +04:00
|
|
|
// enable/disable the QuirkSheet
|
|
|
|
NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsPresContext::SetCompatibilityMode");
|
|
|
|
if (mShell) {
|
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
nsresult rv = mShell->GetStyleSet(getter_AddRefs(set));
|
|
|
|
if (NS_SUCCEEDED(rv) && set) {
|
|
|
|
set->EnableQuirkStyleSheet((mCompatibilityMode != eCompatibility_Standard) ? PR_TRUE : PR_FALSE);
|
|
|
|
}
|
2000-06-03 01:45:06 +04:00
|
|
|
}
|
1998-07-31 09:54:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-03 01:43:26 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetWidgetRenderingMode(nsWidgetRendering* aResult)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-03-03 01:43:26 +03:00
|
|
|
*aResult = mWidgetRenderingMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetWidgetRenderingMode(nsWidgetRendering aMode)
|
|
|
|
{
|
|
|
|
mWidgetRenderingMode = aMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-13 05:39:20 +04:00
|
|
|
NS_IMETHODIMP
|
2001-11-14 17:03:09 +03:00
|
|
|
nsPresContext::GetImageAnimationMode(PRUint16* aModeResult)
|
2000-05-13 05:39:20 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aModeResult, "null out param");
|
2000-05-13 05:39:20 +04:00
|
|
|
*aModeResult = mImageAnimationMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-14 14:21:54 +03:00
|
|
|
// Helper function for setting Anim Mode on image
|
|
|
|
static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, PRUint16 aMode)
|
|
|
|
{
|
|
|
|
if (aImgReq != nsnull) {
|
|
|
|
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);
|
|
|
|
nsCOMPtr<imgIRequest> imgReq;
|
|
|
|
loader->GetRequest(getter_AddRefs(imgReq));
|
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
|
2001-11-14 17:03:09 +03:00
|
|
|
void nsPresContext::SetImgAnimations(nsCOMPtr<nsIContent>& aParent, PRUint16 aMode)
|
2001-11-14 14:21:54 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLImageElement> imgContent(do_QueryInterface(aParent));
|
|
|
|
if (imgContent) {
|
|
|
|
nsIFrame* frame;
|
|
|
|
mShell->GetPrimaryFrameFor(aParent, &frame);
|
|
|
|
if (frame != nsnull) {
|
|
|
|
nsIImageFrame* imgFrame = nsnull;
|
|
|
|
CallQueryInterface(frame, &imgFrame);
|
|
|
|
if (imgFrame != nsnull) {
|
|
|
|
nsCOMPtr<imgIRequest> imgReq;
|
|
|
|
imgFrame->GetImageRequest(getter_AddRefs(imgReq));
|
|
|
|
SetImgAnimModeOnImgReq(imgReq, aMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PRInt32 count;
|
|
|
|
aParent->ChildCount(count);
|
|
|
|
for (PRInt32 i=0;i<count;i++) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
aParent->ChildAt(i, *getter_AddRefs(child));
|
|
|
|
if (child) {
|
|
|
|
SetImgAnimations(child, aMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-05-13 05:39:20 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-11-14 17:03:09 +03:00
|
|
|
nsPresContext::SetImageAnimationMode(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!");
|
|
|
|
|
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
|
|
|
|
mImageLoaders.Enumerate(set_animation_mode, (void*)aMode);
|
|
|
|
|
|
|
|
// Now walk the content tree and set the animation mode
|
|
|
|
// on all the images
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
if (mShell != nsnull) {
|
|
|
|
mShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
doc->GetRootContent(getter_AddRefs(rootContent));
|
|
|
|
if (rootContent) {
|
|
|
|
SetImgAnimations(rootContent, aMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-13 05:39:20 +04:00
|
|
|
mImageAnimationMode = aMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-24 02:23:41 +03:00
|
|
|
/* This function has now been deprecated. It is no longer necesary to
|
2000-08-04 02:30:47 +04:00
|
|
|
* hold on to presContext just to get a nsLookAndFeel. nsLookAndFeel is
|
|
|
|
* now a service provided by ServiceManager.
|
|
|
|
*/
|
1999-09-10 09:51:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aLookAndFeel, "null out param");
|
1999-09-10 09:51:08 +04:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (! mLookAndFeel) {
|
2000-07-29 02:12:45 +04:00
|
|
|
mLookAndFeel = do_GetService(kLookAndFeelCID,&result);
|
1999-09-10 09:51:08 +04:00
|
|
|
}
|
|
|
|
*aLookAndFeel = mLookAndFeel;
|
2000-07-29 02:12:45 +04:00
|
|
|
NS_IF_ADDREF(*aLookAndFeel);
|
1999-09-10 09:51:08 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-09-05 07:52:40 +04:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
nsPresContext::GetBaseURL(nsIURI** aResult)
|
1998-09-05 07:52:40 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
*aResult = mBaseURL;
|
1999-04-30 13:04:36 +04:00
|
|
|
NS_IF_ADDREF(*aResult);
|
1998-09-05 07:52:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-11 18:53:26 +03:00
|
|
|
NS_IMETHODIMP
|
1998-04-14 00:24:54 +04:00
|
|
|
nsPresContext::ResolveStyleContextFor(nsIContent* aContent,
|
1998-11-03 23:20:07 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
1999-02-12 20:45:58 +03:00
|
|
|
PRBool aForceUnique,
|
|
|
|
nsIStyleContext** aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
nsresult rv = mShell->GetStyleSet(getter_AddRefs(set));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-02-12 21:41:26 +03:00
|
|
|
if (set) {
|
1999-02-12 20:45:58 +03:00
|
|
|
result = set->ResolveStyleFor(this, aContent, aParentContext,
|
|
|
|
aForceUnique);
|
|
|
|
if (nsnull == result) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aResult = result;
|
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::ResolveStyleContextForNonElement(
|
|
|
|
nsIStyleContext* aParentContext,
|
|
|
|
PRBool aForceUnique,
|
|
|
|
nsIStyleContext** aResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
|
|
|
|
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
nsresult rv = mShell->GetStyleSet(getter_AddRefs(set));
|
|
|
|
if (NS_SUCCEEDED(rv) && set) {
|
|
|
|
result = set->ResolveStyleForNonElement(this, aParentContext,
|
|
|
|
aForceUnique);
|
|
|
|
if (!result)
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aResult = result;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-11 18:53:26 +03:00
|
|
|
NS_IMETHODIMP
|
1998-11-03 23:20:07 +03:00
|
|
|
nsPresContext::ResolvePseudoStyleContextFor(nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsIStyleContext* aParentContext,
|
1999-02-12 20:45:58 +03:00
|
|
|
PRBool aForceUnique,
|
|
|
|
nsIStyleContext** aResult)
|
2001-02-16 00:24:47 +03:00
|
|
|
{
|
|
|
|
return ResolvePseudoStyleWithComparator(aParentContent, aPseudoTag, aParentContext,
|
|
|
|
aForceUnique, nsnull, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::ResolvePseudoStyleWithComparator(nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsIStyleContext* aParentContext,
|
|
|
|
PRBool aForceUnique,
|
|
|
|
nsICSSPseudoComparator* aComparator,
|
|
|
|
nsIStyleContext** aResult)
|
1998-05-19 01:06:33 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1998-05-19 01:06:33 +04:00
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
nsresult rv = mShell->GetStyleSet(getter_AddRefs(set));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-02-12 21:41:26 +03:00
|
|
|
if (set) {
|
1999-02-12 20:45:58 +03:00
|
|
|
result = set->ResolvePseudoStyleFor(this, aParentContent, aPseudoTag,
|
2001-02-16 00:24:47 +03:00
|
|
|
aParentContext, aForceUnique, aComparator);
|
1999-02-12 20:45:58 +03:00
|
|
|
if (nsnull == result) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aResult = result;
|
|
|
|
return rv;
|
1998-05-19 01:06:33 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
NS_IMETHODIMP
|
1998-11-03 23:20:07 +03:00
|
|
|
nsPresContext::ProbePseudoStyleContextFor(nsIContent* aParentContent,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsIStyleContext* aParentContext,
|
1999-02-12 20:45:58 +03:00
|
|
|
PRBool aForceUnique,
|
|
|
|
nsIStyleContext** aResult)
|
1998-05-19 01:06:33 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1998-05-19 01:06:33 +04:00
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
nsIStyleContext* result = nsnull;
|
|
|
|
nsCOMPtr<nsIStyleSet> set;
|
|
|
|
nsresult rv = mShell->GetStyleSet(getter_AddRefs(set));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-02-12 21:41:26 +03:00
|
|
|
if (set) {
|
1999-02-12 20:45:58 +03:00
|
|
|
result = set->ProbePseudoStyleFor(this, aParentContent, aPseudoTag,
|
|
|
|
aParentContext, aForceUnique);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aResult = result;
|
|
|
|
return rv;
|
1998-05-19 01:06:33 +04:00
|
|
|
}
|
|
|
|
|
1999-09-04 03:35:41 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::ReParentStyleContext(nsIFrame* aFrame,
|
|
|
|
nsIStyleContext* aNewParentContext)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
|
|
|
if (! aFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFrameManager> manager;
|
|
|
|
nsresult rv = mShell->GetFrameManager(getter_AddRefs(manager));
|
|
|
|
if (NS_SUCCEEDED(rv) && manager) {
|
1999-11-24 09:03:41 +03:00
|
|
|
rv = manager->ReParentStyleContext(this, aFrame, aNewParentContext);
|
1999-09-04 03:35:41 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::AllocateFromShell(size_t aSize, void** aResult)
|
|
|
|
{
|
|
|
|
if (mShell)
|
|
|
|
return mShell->AllocateFrame(aSize, aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::FreeToShell(size_t aSize, void* aFreeChunk)
|
|
|
|
{
|
|
|
|
if (mShell)
|
|
|
|
return mShell->FreeFrame(aSize, aFreeChunk);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-04 03:35:41 +04:00
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1998-08-28 00:43:04 +04:00
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
nsIFontMetrics* metrics = nsnull;
|
1999-04-30 13:04:36 +04:00
|
|
|
if (mDeviceContext) {
|
2000-05-06 01:04:36 +04:00
|
|
|
nsCOMPtr<nsIAtom> langGroup;
|
|
|
|
if (mLanguage) {
|
|
|
|
mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
|
|
|
|
}
|
|
|
|
mDeviceContext->GetMetricsFor(aFont, langGroup, metrics);
|
1998-08-28 00:43:04 +04:00
|
|
|
}
|
1999-02-12 20:45:58 +03:00
|
|
|
*aResult = metrics;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-01-10 03:04:35 +03:00
|
|
|
nsPresContext::GetDefaultFont(PRUint8 aFontID, const nsFont** aResult)
|
1999-02-12 20:45:58 +03:00
|
|
|
{
|
2001-09-27 22:34:30 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
switch (aFontID) {
|
|
|
|
// Special (our default variable width font and fixed width font)
|
|
|
|
case kPresContext_DefaultVariableFont_ID:
|
2002-01-10 03:04:35 +03:00
|
|
|
*aResult = &mDefaultVariableFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kPresContext_DefaultFixedFont_ID:
|
2002-01-10 03:04:35 +03:00
|
|
|
*aResult = &mDefaultFixedFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
// CSS
|
|
|
|
case kGenericFont_serif:
|
2002-01-10 03:04:35 +03:00
|
|
|
*aResult = &mDefaultSerifFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_sans_serif:
|
2002-01-10 03:04:35 +03:00
|
|
|
*aResult = &mDefaultSansSerifFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_monospace:
|
2002-01-10 03:04:35 +03:00
|
|
|
*aResult = &mDefaultMonospaceFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_cursive:
|
2002-01-10 03:04:35 +03:00
|
|
|
*aResult = &mDefaultCursiveFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
case kGenericFont_fantasy:
|
2002-01-10 03:04:35 +03:00
|
|
|
*aResult = &mDefaultFantasyFont;
|
2001-09-27 22:34:30 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
NS_ERROR("invalid arg");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-06-13 02:31:15 +04:00
|
|
|
NS_IMETHODIMP
|
2001-10-31 01:58:00 +03:00
|
|
|
nsPresContext::SetDefaultFont(PRUint8 aFontID, const nsFont& aFont)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-09-27 22:34:30 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
switch (aFontID) {
|
|
|
|
// Special (our default variable width font and fixed width font)
|
|
|
|
case kPresContext_DefaultVariableFont_ID:
|
|
|
|
mDefaultVariableFont = aFont;
|
|
|
|
break;
|
|
|
|
case kPresContext_DefaultFixedFont_ID:
|
|
|
|
mDefaultFixedFont = aFont;
|
|
|
|
break;
|
|
|
|
// CSS
|
|
|
|
case kGenericFont_serif:
|
|
|
|
mDefaultSerifFont = aFont;
|
|
|
|
break;
|
|
|
|
case kGenericFont_sans_serif:
|
|
|
|
mDefaultSansSerifFont = aFont;
|
|
|
|
break;
|
|
|
|
case kGenericFont_monospace:
|
|
|
|
mDefaultMonospaceFont = aFont;
|
|
|
|
break;
|
|
|
|
case kGenericFont_cursive:
|
|
|
|
mDefaultCursiveFont = aFont;
|
|
|
|
break;
|
|
|
|
case kGenericFont_fantasy:
|
|
|
|
mDefaultFantasyFont = aFont;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
NS_ERROR("invalid arg");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rv;
|
1998-07-17 09:41:41 +04:00
|
|
|
}
|
|
|
|
|
1998-11-26 21:10:10 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 20:45:58 +03:00
|
|
|
nsPresContext::GetFontScaler(PRInt32* aResult)
|
1998-07-25 05:11:49 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
|
|
|
|
*aResult = mFontScaler;
|
1998-11-26 21:10:10 +03:00
|
|
|
return NS_OK;
|
1998-07-25 05:11:49 +04:00
|
|
|
}
|
|
|
|
|
1998-11-26 21:10:10 +03:00
|
|
|
NS_IMETHODIMP
|
1998-07-25 05:11:49 +04:00
|
|
|
nsPresContext::SetFontScaler(PRInt32 aScaler)
|
|
|
|
{
|
|
|
|
mFontScaler = aScaler;
|
1998-11-26 21:10:10 +03:00
|
|
|
return NS_OK;
|
1998-07-25 05:11:49 +04:00
|
|
|
}
|
|
|
|
|
1998-07-31 09:54:59 +04:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 20:45:58 +03:00
|
|
|
nsPresContext::GetDefaultColor(nscolor* aResult)
|
1998-07-17 09:41:41 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
|
|
|
|
*aResult = mDefaultColor;
|
1998-07-17 09:41:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-31 09:54:59 +04:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 20:45:58 +03:00
|
|
|
nsPresContext::GetDefaultBackgroundColor(nscolor* aResult)
|
1998-07-17 09:41:41 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
|
|
|
|
*aResult = mDefaultBackgroundColor;
|
1998-07-17 09:41:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-13 02:31:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetDefaultBackgroundImage(nsString& aImage)
|
|
|
|
{
|
|
|
|
aImage = mDefaultBackgroundImage;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetDefaultBackgroundImageRepeat(PRUint8* aRepeat)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aRepeat, "null out param");
|
1999-06-13 02:31:15 +04:00
|
|
|
*aRepeat = mDefaultBackgroundImageRepeat;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetDefaultBackgroundImageOffset(nscoord* aX, nscoord* aY)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aX && aY, "null out param");
|
1999-06-13 02:31:15 +04:00
|
|
|
*aX = mDefaultBackgroundImageOffsetX;
|
|
|
|
*aY = mDefaultBackgroundImageOffsetY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetDefaultBackgroundImageAttachment(PRUint8* aAttachment)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aAttachment, "null out param");
|
1999-06-13 02:31:15 +04:00
|
|
|
*aAttachment = mDefaultBackgroundImageAttachment;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetDefaultLinkColor(nscolor* aColor)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aColor, "null out param");
|
|
|
|
*aColor = mLinkColor;
|
|
|
|
return NS_OK;
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetDefaultVisitedLinkColor(nscolor* aColor)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aColor, "null out param");
|
|
|
|
*aColor = mVisitedLinkColor;
|
|
|
|
return NS_OK;
|
2000-10-11 12:33:01 +04:00
|
|
|
}
|
|
|
|
|
2001-04-10 02:17:11 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetFocusRingOnAnything(PRBool& aFocusRingOnAnything)
|
|
|
|
{
|
|
|
|
aFocusRingOnAnything = mFocusRingOnAnything;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetUseFocusColors(PRBool& aUseFocusColors)
|
|
|
|
{
|
|
|
|
aUseFocusColors = mUseFocusColors;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetFocusTextColor(nscolor* aColor)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aColor, "null out param");
|
|
|
|
*aColor = mFocusTextColor;
|
|
|
|
return NS_OK;
|
2001-04-10 02:17:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetFocusBackgroundColor(nscolor* aColor)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aColor, "null out param");
|
|
|
|
*aColor = mFocusBackgroundColor;
|
|
|
|
return NS_OK;
|
2001-04-10 02:17:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetFocusRingWidth(PRUint8 *aFocusRingWidth)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aFocusRingWidth, "null out param");
|
|
|
|
*aFocusRingWidth = mFocusRingWidth;
|
|
|
|
return NS_OK;
|
2001-04-10 02:17:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-31 09:54:59 +04:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 20:45:58 +03:00
|
|
|
nsPresContext::SetDefaultColor(nscolor aColor)
|
1998-07-23 21:57:00 +04:00
|
|
|
{
|
|
|
|
mDefaultColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-31 09:54:59 +04:00
|
|
|
NS_IMETHODIMP
|
1999-02-12 20:45:58 +03:00
|
|
|
nsPresContext::SetDefaultBackgroundColor(nscolor aColor)
|
1998-07-23 21:57:00 +04:00
|
|
|
{
|
|
|
|
mDefaultBackgroundColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-13 02:31:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetDefaultBackgroundImage(const nsString& aImage)
|
|
|
|
{
|
|
|
|
mDefaultBackgroundImage = aImage;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetDefaultBackgroundImageRepeat(PRUint8 aRepeat)
|
|
|
|
{
|
|
|
|
mDefaultBackgroundImageRepeat = aRepeat;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetDefaultBackgroundImageOffset(nscoord aX, nscoord aY)
|
|
|
|
{
|
|
|
|
mDefaultBackgroundImageOffsetX = aX;
|
|
|
|
mDefaultBackgroundImageOffsetY = aY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetDefaultBackgroundImageAttachment(PRUint8 aAttachment)
|
|
|
|
{
|
|
|
|
mDefaultBackgroundImageAttachment = aAttachment;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-10-11 12:33:01 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetDefaultLinkColor(nscolor aColor)
|
|
|
|
{
|
|
|
|
mLinkColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetDefaultVisitedLinkColor(nscolor aColor)
|
|
|
|
{
|
|
|
|
mVisitedLinkColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-26 21:10:10 +03:00
|
|
|
NS_IMETHODIMP
|
1998-05-22 22:36:40 +04:00
|
|
|
nsPresContext::GetVisibleArea(nsRect& aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-22 22:36:40 +04:00
|
|
|
aResult = mVisibleArea;
|
1998-11-26 21:10:10 +03:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-11-26 21:10:10 +03:00
|
|
|
NS_IMETHODIMP
|
1998-05-09 07:22:01 +04:00
|
|
|
nsPresContext::SetVisibleArea(const nsRect& r)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
mVisibleArea = r;
|
1998-11-26 21:10:10 +03:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetPixelsToTwips(float* aResult) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
|
|
|
|
float p2t = 1.0f;
|
1999-04-30 13:04:36 +04:00
|
|
|
if (mDeviceContext) {
|
1998-08-28 02:45:35 +04:00
|
|
|
mDeviceContext->GetDevUnitsToAppUnits(p2t);
|
1998-05-09 07:22:01 +04:00
|
|
|
}
|
1999-02-12 20:45:58 +03:00
|
|
|
*aResult = p2t;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetTwipsToPixels(float* aResult) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
|
|
|
|
float app2dev = 1.0f;
|
1999-04-30 13:04:36 +04:00
|
|
|
if (mDeviceContext) {
|
1998-08-28 02:45:35 +04:00
|
|
|
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
1998-05-09 07:22:01 +04:00
|
|
|
}
|
1999-02-12 20:45:58 +03:00
|
|
|
*aResult = app2dev;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetTwipsToPixelsForFonts(float* aResult) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
float app2dev = 1.0f;
|
|
|
|
if (mDeviceContext) {
|
|
|
|
#ifdef NS_PRINT_PREVIEW
|
|
|
|
// 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) {
|
|
|
|
altDC->GetAppUnitsToDevUnits(app2dev);
|
|
|
|
} else {
|
|
|
|
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
*aResult = app2dev;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetScaledPixelsToTwips(float* aResult) const
|
1998-11-14 04:52:27 +03:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
|
|
|
|
float scale = 1.0f;
|
1999-04-30 13:04:36 +04:00
|
|
|
if (mDeviceContext)
|
1998-11-14 04:52:27 +03:00
|
|
|
{
|
1999-02-12 20:45:58 +03:00
|
|
|
float p2t;
|
1998-11-14 04:52:27 +03:00
|
|
|
mDeviceContext->GetDevUnitsToAppUnits(p2t);
|
|
|
|
mDeviceContext->GetCanonicalPixelScale(scale);
|
1999-02-12 20:45:58 +03:00
|
|
|
scale = p2t * scale;
|
1998-11-14 04:52:27 +03:00
|
|
|
}
|
1999-02-12 20:45:58 +03:00
|
|
|
*aResult = scale;
|
1998-11-14 04:52:27 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetDeviceContext(nsIDeviceContext** aResult) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1999-02-12 20:45:58 +03:00
|
|
|
*aResult = mDeviceContext;
|
1999-04-30 13:04:36 +04:00
|
|
|
NS_IF_ADDREF(*aResult);
|
1999-02-12 20:45:58 +03:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-09-29 21:50:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetImageLoadFlags(nsLoadFlags& aLoadFlags)
|
|
|
|
{
|
|
|
|
aLoadFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-31 09:54:59 +04:00
|
|
|
NS_IMETHODIMP
|
2001-08-10 00:22:39 +04:00
|
|
|
nsPresContext::LoadImage(const nsString& aURL,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
imgIRequest **aRequest)
|
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
|
|
|
|
2002-02-15 02:31:54 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
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
|
|
|
|
2002-02-15 02:31:54 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
rv = mShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
|
|
|
doc->GetBaseURL(*getter_AddRefs(baseURI));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), aURL, baseURI);
|
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
if (!loader) {
|
2002-02-15 02:31:54 +03:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
aTargetFrame->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
// Check with the content-policy things to make sure this load is permitted.
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(content));
|
|
|
|
|
|
|
|
if (!element) // this would seem bad(tm)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (content) {
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
rv = content->GetDocument(*getter_AddRefs(document));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalScript;
|
|
|
|
rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWin(do_QueryInterface(globalScript));
|
|
|
|
|
|
|
|
PRBool shouldLoad = PR_TRUE;
|
|
|
|
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE,
|
|
|
|
uri, element, domWin, &shouldLoad);
|
|
|
|
if (NS_SUCCEEDED(rv) && !shouldLoad)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
nsImageLoader *newLoader = new nsImageLoader();
|
|
|
|
if (!newLoader)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-02-15 07:49:32 +03:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
NS_ADDREF(newLoader); // new
|
1999-02-12 20:45:58 +03:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
nsCOMPtr<nsISupports> sup;
|
|
|
|
newLoader->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(sup));
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
loader = NS_REINTERPRET_CAST(nsImageLoader*, sup.get());
|
|
|
|
|
|
|
|
loader->Init(aTargetFrame, this);
|
|
|
|
|
|
|
|
mImageLoaders.Put(&key, sup);
|
1998-11-26 21:10:10 +03:00
|
|
|
}
|
1998-11-23 20:18:34 +03:00
|
|
|
|
1999-05-07 04:06:03 +04:00
|
|
|
// Allow for a null target frame argument (for precached images)
|
2000-05-13 05:39:20 +04:00
|
|
|
if (aTargetFrame) {
|
1999-05-07 04:06:03 +04:00
|
|
|
// Mark frame as having loaded an image
|
|
|
|
nsFrameState state;
|
|
|
|
aTargetFrame->GetFrameState(&state);
|
|
|
|
state |= NS_FRAME_HAS_LOADED_IMAGES;
|
|
|
|
aTargetFrame->SetFrameState(state);
|
|
|
|
}
|
1999-04-14 01:49:28 +04:00
|
|
|
|
2002-02-15 02:31:54 +03:00
|
|
|
loader->Load(uri);
|
1999-04-14 01:49:28 +04:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
loader->GetRequest(aRequest);
|
2000-05-16 02:05:45 +04:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
NS_RELEASE(loader);
|
2001-05-22 02:40:10 +04:00
|
|
|
|
1998-05-09 07:22:01 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
|
1998-11-26 21:10:10 +03:00
|
|
|
NS_IMETHODIMP
|
2001-08-10 00:22:39 +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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
|
1998-05-09 07:22:01 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetLinkHandler(nsILinkHandler* aHandler)
|
1999-04-30 13:04:36 +04:00
|
|
|
{
|
1998-04-14 00:24:54 +04:00
|
|
|
mLinkHandler = aHandler;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:01 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetLinkHandler(nsILinkHandler** aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1998-04-14 00:24:54 +04:00
|
|
|
*aResult = mLinkHandler;
|
|
|
|
NS_IF_ADDREF(mLinkHandler);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:01 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetContainer(nsISupports* aHandler)
|
1999-04-30 13:04:36 +04:00
|
|
|
{
|
1998-04-14 00:24:54 +04:00
|
|
|
mContainer = aHandler;
|
2001-10-17 03:59:25 +04:00
|
|
|
if (mContainer) {
|
|
|
|
GetDocumentColorPreferences();
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-09 07:22:01 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetContainer(nsISupports** aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
1998-04-14 00:24:54 +04:00
|
|
|
*aResult = mContainer;
|
|
|
|
NS_IF_ADDREF(mContainer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-24 01:53:02 +04:00
|
|
|
|
1998-07-31 09:54:59 +04:00
|
|
|
NS_IMETHODIMP
|
1998-06-24 01:53:02 +04:00
|
|
|
nsPresContext::GetEventStateManager(nsIEventStateManager** aManager)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aManager, "null ptr");
|
|
|
|
if (nsnull == aManager) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1999-04-30 13:52:22 +04:00
|
|
|
if (!mEventManager) {
|
2001-02-20 00:50:04 +03:00
|
|
|
nsresult rv;
|
|
|
|
mEventManager = do_CreateInstance(kEventStateManagerCID,&rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
1998-06-24 01:53:02 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-18 08:25:26 +03:00
|
|
|
//Not refcnted, set null in destructor
|
|
|
|
mEventManager->SetPresContext(this);
|
|
|
|
|
1998-06-24 01:53:02 +04:00
|
|
|
*aManager = mEventManager;
|
1999-04-30 13:04:36 +04:00
|
|
|
NS_IF_ADDREF(*aManager);
|
1998-06-24 01:53:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-21 18:51:59 +03:00
|
|
|
|
2001-03-09 06:13:03 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
//ahmed
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::IsArabicEncoding(PRBool& aResult)
|
|
|
|
{
|
|
|
|
aResult=PR_FALSE;
|
|
|
|
if ( (mCharset.EqualsIgnoreCase("ibm864") )||(mCharset.EqualsIgnoreCase("ibm864i") )||(mCharset.EqualsIgnoreCase("windows-1256") )||(mCharset.EqualsIgnoreCase("iso-8859-6") ))
|
|
|
|
aResult=PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::IsVisRTL(PRBool& aResult)
|
|
|
|
{
|
|
|
|
aResult=PR_FALSE;
|
|
|
|
if ( (mIsVisual)&&(GET_BIDI_OPTION_DIRECTION(mBidi) == IBMBIDI_TEXTDIRECTION_RTL) )
|
|
|
|
aResult=PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-05-16 17:40:08 +04:00
|
|
|
nsPresContext::GetBidiEnabled(PRBool* aBidiEnabled) const
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
2001-05-16 17:40:08 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aBidiEnabled);
|
|
|
|
*aBidiEnabled = PR_FALSE;
|
|
|
|
NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsPresContext::GetBidiEnabled");
|
2001-03-09 06:13:03 +03:00
|
|
|
if (mShell) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
mShell->GetDocument(getter_AddRefs(doc) );
|
2001-05-16 17:40:08 +04:00
|
|
|
NS_ASSERTION(doc, "PresShell has no document in nsPresContext::GetBidiEnabled");
|
2001-03-09 06:13:03 +03:00
|
|
|
if (doc) {
|
2001-05-16 17:40:08 +04:00
|
|
|
doc->GetBidiEnabled(aBidiEnabled);
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-05-16 17:40:08 +04:00
|
|
|
nsPresContext::SetBidiEnabled(PRBool aBidiEnabled) const
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
|
|
|
if (mShell) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
mShell->GetDocument(getter_AddRefs(doc) );
|
|
|
|
if (doc) {
|
2001-05-16 17:40:08 +04:00
|
|
|
doc->SetBidiEnabled(aBidiEnabled);
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetVisualMode(PRBool aIsVisual)
|
|
|
|
{
|
|
|
|
mIsVisual = aIsVisual;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::IsVisualMode(PRBool& aIsVisual) const
|
|
|
|
{
|
|
|
|
aIsVisual = mIsVisual;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetBidiUtils(nsBidiPresUtils** aBidiUtils)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mBidiUtils) {
|
|
|
|
mBidiUtils = new nsBidiPresUtils;
|
|
|
|
if (!mBidiUtils) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aBidiUtils = mBidiUtils;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-04-14 01:54:17 +04:00
|
|
|
NS_IMETHODIMP nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow)
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
|
|
|
mBidi = aSource;
|
|
|
|
if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(mBidi)
|
|
|
|
|| IBMBIDI_NUMERAL_HINDI == GET_BIDI_OPTION_NUMERAL(mBidi)) {
|
2001-05-16 17:40:08 +04:00
|
|
|
SetBidiEnabled(PR_TRUE);
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
if (IBMBIDI_TEXTTYPE_VISUAL == GET_BIDI_OPTION_TEXTTYPE(mBidi)) {
|
|
|
|
SetVisualMode(PR_TRUE);
|
|
|
|
}
|
|
|
|
else if (IBMBIDI_TEXTTYPE_LOGICAL == GET_BIDI_OPTION_TEXTTYPE(mBidi)) {
|
|
|
|
SetVisualMode(PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SetVisualMode(IsVisualCharset(mCharset) );
|
|
|
|
}
|
|
|
|
if (mShell && aForceReflow) {
|
2001-07-25 10:33:06 +04:00
|
|
|
ClearStyleDataAndReflow();
|
2001-03-09 06:13:03 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-14 01:54:17 +04:00
|
|
|
NS_IMETHODIMP nsPresContext::GetBidi(PRUint32* aDest)
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
|
|
|
if (aDest)
|
|
|
|
*aDest = mBidi;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Mohamed 17-1-01
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::SetIsBidiSystem(PRBool aIsBidi)
|
|
|
|
{
|
|
|
|
mIsBidiSystem = aIsBidi;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetIsBidiSystem(PRBool& aResult) const
|
|
|
|
{
|
|
|
|
aResult = mIsBidiSystem;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-06-22 13:56:05 +04:00
|
|
|
nsPresContext::GetBidiCharset(nsAWritableString &aCharSet)
|
2001-03-09 06:13:03 +03:00
|
|
|
{
|
|
|
|
aCharSet = mCharset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
//Mohamed End
|
|
|
|
|
|
|
|
#endif //IBMBIDI
|
2000-03-21 18:51:59 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-06 01:04:36 +04:00
|
|
|
nsPresContext::GetLanguage(nsILanguageAtom** aLanguage)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aLanguage, "null out param");
|
2000-05-06 01:04:36 +04:00
|
|
|
|
|
|
|
*aLanguage = mLanguage;
|
|
|
|
NS_IF_ADDREF(*aLanguage);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-09-21 02:59:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetLanguageSpecificTransformType(
|
|
|
|
nsLanguageSpecificTransformType* aType)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aType, "null out param");
|
2000-09-21 02:59:20 +04:00
|
|
|
*aType = mLanguageSpecificTransformType;
|
2000-10-11 12:33:01 +04:00
|
|
|
|
2000-09-21 02:59:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::IsRenderingOnlySelection(PRBool* aResult)
|
|
|
|
{
|
2001-10-30 09:02:05 +03:00
|
|
|
NS_PRECONDITION(aResult, "null out param");
|
2001-01-27 17:09:34 +03:00
|
|
|
*aResult = mIsRenderingOnlySelection;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::GetTheme(nsITheme** aResult)
|
|
|
|
{
|
|
|
|
if (!mNoTheme && !mTheme) {
|
|
|
|
mTheme = do_GetService("@mozilla.org/chrome/chrome-native-theme;1");
|
|
|
|
if (!mTheme)
|
|
|
|
mNoTheme = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = mTheme;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return mTheme ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::ThemeChanged()
|
|
|
|
{
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
if (!mShell)
|
|
|
|
return NS_OK;
|
|
|
|
|
2001-12-19 05:49:14 +03:00
|
|
|
return mShell->ReconstructStyleData(PR_TRUE);
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-21 18:59:47 +04:00
|
|
|
#ifdef MOZ_REFLOW_PERF
|
|
|
|
NS_IMETHODIMP
|
2001-02-22 16:58:17 +03:00
|
|
|
nsPresContext::CountReflows(const char * aName, 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
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-13 04:47:22 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPresContext::PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIFrame * aFrame, PRUint32 aColor)
|
|
|
|
{
|
|
|
|
if (mShell) {
|
|
|
|
mShell->PaintCount(aName, aRenderingContext, this, aFrame, aColor);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-21 18:59:47 +04:00
|
|
|
#endif
|