Implemented the backend for the following prefs: Override Document colors, Override document fonts, Link and Visited link colors, and Underline links. Provided the ability to disable the preferences as well, so Composer can show changed fonts and colors. These changes are stewing on the trunk for a day or so before making their debut on the branch. b=40340, r=karnaze,pierre a=buster

git-svn-id: svn://10.0.0.236/trunk@80920 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
attinasi%netscape.com
2000-10-11 08:33:01 +00:00
parent 2e3c2cc514
commit c8ab5d1344
17 changed files with 1400 additions and 25 deletions

View File

@@ -35,6 +35,10 @@
#include "nsIPresContext.h"
#include "nsIHTMLAttributes.h"
// MJA: bug 31816
#include "nsIPresShell.h"
#include "nsIDocShellTreeItem.h"
// - END MJA
class nsHTMLFontElement : public nsIDOMHTMLFontElement,
public nsIJSScriptObject,
@@ -218,7 +222,48 @@ MapFontAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
font->mFont.name = familyList;
nsAutoString face;
if (NS_OK == dc->FirstExistingFont(font->mFont, face)) {
// MJA: bug 31816
// if we are not using document fonts, but this is a xul document,
// then we set the chromeOverride bit so we use the document fonts anyway
PRBool chromeOverride = PR_FALSE;
PRBool useDocumentFonts = PR_TRUE;
aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts,useDocumentFonts);
if (!useDocumentFonts) {
// check if the prefs have been disabled for this shell
// - if prefs are disabled then we use the document fonts anyway (yet another override)
PRBool prefsEnabled = PR_TRUE;
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
if (shell) {
shell->ArePrefStyleRulesEnabled(prefsEnabled);
}
if (!prefsEnabled) {
useDocumentFonts = PR_TRUE;
} else {
// see if we are in the chrome, if so, use the document fonts (override the useDocFonts setting)
nsresult result = NS_OK;
nsCOMPtr<nsISupports> container;
result = aPresContext->GetContainer(getter_AddRefs(container));
if (NS_SUCCEEDED(result) && container) {
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
if (NS_SUCCEEDED(result) && docShell){
PRInt32 docShellType;
result = docShell->GetItemType(&docShellType);
if (NS_SUCCEEDED(result)){
if (nsIDocShellTreeItem::typeChrome == docShellType){
chromeOverride = PR_TRUE;
}
}
}
}
}
}
// find the correct font if we are usingDocumentFonts OR we are overriding for XUL
// MJA: bug 31816
if ((chromeOverride || useDocumentFonts) &&
NS_OK == dc->FirstExistingFont(font->mFont, face)) {
if (face.EqualsIgnoreCase("-moz-fixed")) {
font->mFlags |= NS_STYLE_FONT_USE_FIXED;
} else {

View File

@@ -55,6 +55,11 @@
#include "nsIStyleSet.h"
#include "nsISizeOfHandler.h"
// MJA: bug 31816
#include "nsIPresShell.h"
#include "nsIDocShellTreeItem.h"
// - END MJA
// #define DEBUG_REFS
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@@ -1599,7 +1604,48 @@ MapDeclarationFontInto(nsICSSDeclaration* aDeclaration,
font->mFont.name = familyList;
nsAutoString face;
if (NS_OK == dc->FirstExistingFont(font->mFont, face)) {
// MJA: bug 31816
// if we are not using document fonts, but this is a xul document,
// then we set the chromeOverride bit so we use the document fonts anyway
PRBool chromeOverride = PR_FALSE;
PRBool useDocumentFonts = PR_TRUE;
aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts,useDocumentFonts);
if (!useDocumentFonts) {
// check if the prefs have been disabled for this shell
// - if prefs are disabled then we use the document fonts anyway (yet another override)
PRBool prefsEnabled = PR_TRUE;
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
if (shell) {
shell->ArePrefStyleRulesEnabled(prefsEnabled);
}
if (!prefsEnabled) {
useDocumentFonts = PR_TRUE;
} else {
// see if we are in the chrome, if so, use the document fonts (override the useDocFonts setting)
nsresult result = NS_OK;
nsCOMPtr<nsISupports> container;
result = aPresContext->GetContainer(getter_AddRefs(container));
if (NS_SUCCEEDED(result) && container) {
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
if (NS_SUCCEEDED(result) && docShell){
PRInt32 docShellType;
result = docShell->GetItemType(&docShellType);
if (NS_SUCCEEDED(result)){
if (nsIDocShellTreeItem::typeChrome == docShellType){
chromeOverride = PR_TRUE;
}
}
}
}
}
}
// find the correct font if we are usingDocumentFonts OR we are overriding for XUL
// MJA: bug 31816
if ((chromeOverride || useDocumentFonts) &&
(NS_OK == dc->FirstExistingFont(font->mFont, face))) {
if (face.EqualsIgnoreCase("-moz-fixed")) {
font->mFlags |= NS_STYLE_FONT_USE_FIXED;
}

View File

@@ -146,6 +146,26 @@ public:
NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle) = 0;
/** Setup all style rules required to implement preferences
* - used for background/text/link colors and link underlining
* may be extended for any prefs that are implemented via style rules
* - aForceReflow argument is used to force a full reframe to make the rules show
* (only used when the current page needs to reflect changed pref rules)
*
* - initially created for bugs 31816, 20760, 22963
*/
NS_IMETHOD SetPreferenceStyleRules(PRBool aForceReflow) = 0;
/** Allow client to enable and disable the use of the preference style rules,
* by type.
* NOTE: type argument is currently ignored, but is in the API for
* future refinement
*
* - initially created for bugs 31816, 20760, 22963
*/
NS_IMETHOD EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType=0xFF) = 0;
NS_IMETHOD ArePrefStyleRulesEnabled(PRBool& aEnabled) = 0;
/**
* Gather titles of all selectable (alternate and preferred) style sheets
* fills void array with nsString* caller must free strings

View File

@@ -110,6 +110,14 @@ nsPresContext::nsPresContext()
mDefaultColor = NS_RGB(0x00, 0x00, 0x00);
mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
#endif
mUseDocumentColors = PR_TRUE;
mUseDocumentFonts = PR_TRUE;
mLinkColor = NS_RGB(0x33, 0x33, 0xFF);
mVisitedLinkColor = NS_RGB(0x66, 0x00, 0xCC);
mUnderlineLinks = PR_TRUE;
mDefaultBackgroundImageAttachment = NS_STYLE_BG_ATTACHMENT_SCROLL;
mDefaultBackgroundImageRepeat = NS_STYLE_BG_REPEAT_XY;
mDefaultBackgroundImageOffsetX = mDefaultBackgroundImageOffsetY = 0;
@@ -144,6 +152,9 @@ nsPresContext::~nsPresContext()
if (mPrefs) {
mPrefs->UnregisterCallback("font.", PrefChangedCallback, (void*)this);
mPrefs->UnregisterCallback("browser.display.", PrefChangedCallback, (void*)this);
mPrefs->UnregisterCallback("browser.underline_anchors", PrefChangedCallback, (void*)this);
mPrefs->UnregisterCallback("browser.link_color", PrefChangedCallback, (void*)this);
mPrefs->UnregisterCallback("browser.visited_color", PrefChangedCallback, (void*)this);
}
}
@@ -240,16 +251,17 @@ nsPresContext::GetUserPreferences()
mWidgetRenderingMode = (enum nsWidgetRendering)prefInt; // bad cast
}
// * document colors
PRBool usePrefColors = PR_TRUE;
#ifdef _WIN32
PRUint32 colorPref;
PRBool boolPref;
#ifdef _WIN32
// XXX Is Windows the only platform that uses this?
if (NS_OK == mPrefs->GetBoolPref("browser.display.wfe.use_windows_colors", &boolPref)) {
usePrefColors = !boolPref;
}
#endif
if (usePrefColors) {
PRUint32 colorPref;
if (NS_OK == mPrefs->GetColorPrefDWord("browser.display.foreground_color", &colorPref)) {
mDefaultColor = (nscolor)colorPref;
}
@@ -257,13 +269,56 @@ nsPresContext::GetUserPreferences()
mDefaultBackgroundColor = (nscolor)colorPref;
}
}
if (NS_OK == mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref)) {
mUseDocumentColors = boolPref;
}
// * link colors
if (NS_OK == mPrefs->GetBoolPref("browser.underline_anchors", &boolPref)) {
mUnderlineLinks = boolPref;
}
if (NS_OK == mPrefs->GetColorPrefDWord("browser.anchor_color", &colorPref)) {
mLinkColor = (nscolor)colorPref;
}
if (NS_OK == mPrefs->GetColorPrefDWord("browser.visited_color", &colorPref)) {
mVisitedLinkColor = (nscolor)colorPref;
}
// * use fonts?
if (NS_OK == mPrefs->GetIntPref("browser.display.use_document_fonts", &prefInt)) {
mUseDocumentFonts = prefInt == 0 ? PR_FALSE : PR_TRUE;
}
// * direction
if (NS_OK == mPrefs->GetIntPref("browser.display.direction", &prefInt)) {
mDefaultDirection = prefInt;
}
GetFontPreferences();
}
NS_IMETHODIMP
nsPresContext::GetCachedBoolPref(PRUint32 prefType, PRBool &aValue)
{
nsresult rv = NS_ERROR_FAILURE;
switch(prefType) {
case kPresContext_UseDocumentFonts :
aValue = mUseDocumentFonts;
rv = NS_OK;
break;
case kPresContext_UseDocumentColors:
aValue = mUseDocumentColors;
rv = NS_OK;
break;
case kPresContext_UnderlineLinks:
aValue = mUnderlineLinks;
rv = NS_OK;
break;
default :
rv = NS_ERROR_FAILURE;
}
return rv;
}
NS_IMETHODIMP
nsPresContext::RemapStyleAndReflow()
{
@@ -308,6 +363,12 @@ nsPresContext::PreferenceChanged(const char* aPrefName)
{
// Initialize our state from the user preferences
GetUserPreferences();
// update the presShell: tell it to set the preference style rules up
if (mShell) {
mShell->SetPreferenceStyleRules(PR_TRUE);
}
if (mDeviceContext) {
mDeviceContext->FlushFontCache();
RemapStyleAndReflow();
@@ -327,6 +388,9 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext)
// Register callbacks so we're notified when the preferences change
mPrefs->RegisterCallback("font.", PrefChangedCallback, (void*)this);
mPrefs->RegisterCallback("browser.display.", PrefChangedCallback, (void*)this);
mPrefs->RegisterCallback("browser.underline_anchors", PrefChangedCallback, (void*)this);
mPrefs->RegisterCallback("browser.link_color", PrefChangedCallback, (void*)this);
mPrefs->RegisterCallback("browser.visited_color", PrefChangedCallback, (void*)this);
// Initialize our state from the user preferences
GetUserPreferences();
@@ -750,6 +814,28 @@ nsPresContext::GetDefaultBackgroundImageAttachment(PRUint8* aAttachment)
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::GetDefaultLinkColor(nscolor* aColor)
{
NS_PRECONDITION(nsnull != aColor, "null argument");
if (aColor) {
*aColor = mLinkColor;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP
nsPresContext::GetDefaultVisitedLinkColor(nscolor* aColor)
{
NS_PRECONDITION(nsnull != aColor, "null argument");
if (aColor) {
*aColor = mVisitedLinkColor;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP
nsPresContext::SetDefaultColor(nscolor aColor)
{
@@ -793,6 +879,20 @@ nsPresContext::SetDefaultBackgroundImageAttachment(PRUint8 aAttachment)
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::SetDefaultLinkColor(nscolor aColor)
{
mLinkColor = aColor;
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::SetDefaultVisitedLinkColor(nscolor aColor)
{
mVisitedLinkColor = aColor;
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::GetVisibleArea(nsRect& aResult)
{
@@ -1182,6 +1282,7 @@ nsPresContext::GetLanguageSpecificTransformType(
{
NS_ENSURE_ARG_POINTER(aType);
*aType = mLanguageSpecificTransformType;
return NS_OK;
}

View File

@@ -90,6 +90,11 @@ enum nsLanguageSpecificTransformType {
eLanguageSpecificTransformType_Korean
};
// supported values for cached bool types
const PRUint32 kPresContext_UseDocumentColors = 0x01;
const PRUint32 kPresContext_UseDocumentFonts = 0x02;
const PRUint32 kPresContext_UnderlineLinks = 0x03;
// An interface for presentation contexts. Presentation contexts are
// objects that provide an outer context for a presentation shell.
class nsIPresContext : public nsISupports {
@@ -213,6 +218,13 @@ public:
NS_IMETHOD SetDefaultFixedFont(const nsFont& aFont) = 0;
virtual const nsFont& GetDefaultFixedFontDeprecated() = 0;
/** Get a cached boolean pref, by its type
if the type is not supported, then NS_ERROR_FAILURE is returned
and the aValue argument is undfined, otherwise aValue is set
to the value of the boolean pref */
// * - initially created for bugs 31816, 20760, 22963
NS_IMETHOD GetCachedBoolPref(PRUint32 prefType, PRBool &aValue) = 0;
/**
* Access Nav's magic font scaler value
*/
@@ -220,7 +232,7 @@ public:
NS_IMETHOD SetFontScaler(PRInt32 aScaler) = 0;
/**
* Get the defualt colors
* Get the default colors
*/
NS_IMETHOD GetDefaultColor(nscolor* aColor) = 0;
NS_IMETHOD GetDefaultBackgroundColor(nscolor* aColor) = 0;
@@ -228,6 +240,8 @@ public:
NS_IMETHOD GetDefaultBackgroundImageRepeat(PRUint8* aRepeat) = 0;
NS_IMETHOD GetDefaultBackgroundImageOffset(nscoord* aX, nscoord* aY) = 0;
NS_IMETHOD GetDefaultBackgroundImageAttachment(PRUint8* aRepeat) = 0;
NS_IMETHOD GetDefaultLinkColor(nscolor* aColor) = 0;
NS_IMETHOD GetDefaultVisitedLinkColor(nscolor* aColor) = 0;
NS_IMETHOD SetDefaultColor(nscolor aColor) = 0;
NS_IMETHOD SetDefaultBackgroundColor(nscolor aColor) = 0;
@@ -235,6 +249,8 @@ public:
NS_IMETHOD SetDefaultBackgroundImageRepeat(PRUint8 aRepeat) = 0;
NS_IMETHOD SetDefaultBackgroundImageOffset(nscoord aX, nscoord aY) = 0;
NS_IMETHOD SetDefaultBackgroundImageAttachment(PRUint8 aRepeat) = 0;
NS_IMETHOD SetDefaultLinkColor(nscolor aColor) = 0;
NS_IMETHOD SetDefaultVisitedLinkColor(nscolor aColor) = 0;
NS_IMETHOD GetImageGroup(nsIImageGroup** aGroupResult) = 0;

View File

@@ -43,6 +43,8 @@
#include "nsIDocumentObserver.h"
#include "nsIStyleSet.h"
#include "nsICSSStyleSheet.h" // XXX for UA sheet loading hack, can this go away please?
#include "nsIDOMCSSStyleSheet.h" // for Pref-related rule management (bugs 22963,20760,31816)
#include "nsINameSpaceManager.h" // for Pref-related rule management (bugs 22963,20760,31816)
#include "nsIStyleContext.h"
#include "nsIServiceManager.h"
#include "nsFrame.h"
@@ -137,6 +139,25 @@
// SubShell map
#include "nsDST.h"
// supporting bugs 31816, 20760, 22963
// define USE_OVERRIDE to put prefs in as an override stylesheet
// otherwise they go in as a Backstop stylesheets
// - OVERRIDE is better for text and bg colors, but bad for link colors,
// so eventually, we should probably have a backstop and an override and
// put the link colors in the backstop and the text and bg colors in the override,
// but using the backstop stylesheet with !important rules solves 95% of the
// problem and should suffice for RTM
//
// XXX: use backstop stylesheet of link colors and link underline,
// user override stylesheet for forcing background and text colors, post RTM
//
// #define PREFS_USE_OVERRIDE
// convert a color value to a string, in the CSS format #RRGGBB
// * - initially created for bugs 31816, 20760, 22963
static void ColorToString(nscolor aColor, nsAutoString &aString);
// local management of the style watch:
// aCtlValue should be set to all actions desired (bitwise OR'd together)
// aStyleSet cannot be null
@@ -755,6 +776,9 @@ public:
NS_IMETHOD GetActiveAlternateStyleSheet(nsString& aSheetTitle);
NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle);
NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList);
NS_IMETHOD SetPreferenceStyleRules(PRBool aForceRefrlow);
NS_IMETHOD EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType=0xFF);
NS_IMETHOD ArePrefStyleRulesEnabled(PRBool& aEnabled);
NS_IMETHOD SetDisplaySelection(PRInt16 aToggle);
NS_IMETHOD GetDisplaySelection(PRInt16 *aToggle);
@@ -989,6 +1013,15 @@ protected:
PRBool mInVerifyReflow;
#endif
/**
* methods that manage rules that are used to implement the associated preferences
* - initially created for bugs 31816, 20760, 22963
*/
nsresult ClearPreferenceStyleRules(void);
nsresult CreatePreferenceStyleSheet(void);
nsresult SetPrefColorRules(void);
nsresult SetPrefLinkRules(void);
// IMPORTANT: The ownership implicit in the following member variables has been
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
// pointers for weak (ie, non owning) references. If you add any members to this
@@ -999,6 +1032,8 @@ protected:
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsIPresContext> mPresContext;
nsCOMPtr<nsIStyleSet> mStyleSet;
nsICSSStyleSheet* mPrefStyleSheet; // mStyleSet owns it but we maintaina ref, may be null
PRPackedBool mEnablePrefStyleSheet;
nsIViewManager* mViewManager; // [WEAK] docViewer owns it so I don't have to
nsILayoutHistoryState* mHistoryState; // [WEAK] session history owns this
PRUint32 mUpdateCount;
@@ -1189,6 +1224,8 @@ PresShell::PresShell():mStackArena(nsnull),
mSubShellMap = nsnull;
mRCCreatedDuringLoad = 0;
mDummyLayoutRequest = nsnull;
mPrefStyleSheet = nsnull;
mEnablePrefStyleSheet = PR_TRUE;
#ifdef MOZ_REFLOW_PERF
mReflowCountMgr = new ReflowCountMgr();
@@ -1248,6 +1285,9 @@ PresShell::~PresShell()
}
#endif
// release our pref style sheet, if we have one still
ClearPreferenceStyleRules();
// if we allocated any stack memory free it.
FreeDynamicStack();
@@ -1420,6 +1460,9 @@ PresShell::Init(nsIDocument* aDocument,
// cache the drag service so we can check it during reflows
mDragService = do_GetService("@mozilla.org/widget/dragservice;1");
// setup the preference style rules up (no forced reflow)
SetPreferenceStyleRules(PR_FALSE);
return NS_OK;
}
@@ -1609,6 +1652,366 @@ PresShell::ListAlternateStyleSheets(nsStringArray& aTitleList)
return NS_OK;
}
NS_IMETHODIMP
PresShell::EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType/*=0xFF*/)
{
nsresult result = NS_OK;
// capture change in state
PRBool bChanging = (mEnablePrefStyleSheet != aEnable) ? PR_TRUE : PR_FALSE;
// set to desired state
mEnablePrefStyleSheet = aEnable;
#ifdef NS_DEBUG
printf("PrefStyleSheet %s %s\n",
mEnablePrefStyleSheet ? "ENABLED" : "DISABLED",
bChanging ? "(state toggled)" : "(state unchanged)");
#endif
// deal with changing state
if(bChanging){
switch (mEnablePrefStyleSheet){
case PR_TRUE:
// was off, now on, so create the rules
result = SetPreferenceStyleRules(PR_TRUE);
break;
default :
// was on, now off, so clear the rules
result = ClearPreferenceStyleRules();
break;
}
}
return result;
}
NS_IMETHODIMP
PresShell::ArePrefStyleRulesEnabled(PRBool& aEnabled)
{
aEnabled = mEnablePrefStyleSheet;
return NS_OK;
}
NS_IMETHODIMP
PresShell::SetPreferenceStyleRules(PRBool aForceReflow)
{
NS_PRECONDITION(mPresContext, "presContext cannot be null");
if (mPresContext) {
nsresult result = NS_OK;
// zeroth, make sure this feature is enabled
// XXX: may get more granularity later
// (i.e. each pref may be controlled independently)
if (!mEnablePrefStyleSheet) {
#ifdef NS_DEBUG
printf("PrefStyleSheet disabled\n");
#endif
return PR_TRUE;
}
// first, make sure this is not a chrome shell
nsCOMPtr<nsISupports> container;
result = mPresContext->GetContainer(getter_AddRefs(container));
if (NS_SUCCEEDED(result) && container) {
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
if (NS_SUCCEEDED(result) && docShell){
PRInt32 docShellType;
result = docShell->GetItemType(&docShellType);
if (NS_SUCCEEDED(result)){
if (nsIDocShellTreeItem::typeChrome == docShellType){
return NS_OK;
}
}
}
}
if (NS_SUCCEEDED(result)) {
#ifdef NS_DEBUG
printf("Setting Preference Style Rules:\n");
#endif
// if here, we need to create rules for the prefs
// - this includes the background-color, the text-color,
// the link color, the visited link color and the link-underlining
// first clear any exising rules
result = ClearPreferenceStyleRules();
// now do the color rules
if (NS_SUCCEEDED(result)) {
result = SetPrefColorRules();
}
// now the link rules (must come after the color rules, or links will not be correct color!)
// XXX - when there is both an override and backstop pref stylesheet this won't matter,
// as the color rules will be overrides and the links rules will be backstop
if (NS_SUCCEEDED(result)) {
result = SetPrefLinkRules();
}
// update the styleset now that we are done inserting our rules
if (NS_SUCCEEDED(result)) {
if (mStyleSet) {
mStyleSet->NotifyStyleSheetStateChanged(PR_FALSE);
}
}
}
#ifdef NS_DEBUG
printf( "Preference Style Rules set: error=%ld\n", (long)result);
#endif
if (aForceReflow){
#ifdef NS_DEBUG
printf( "*** Forcing reframe! ***\n");
#endif
// this is harsh, but without it the new colors don't appear on the current page
// Fortunately, it only happens when the prefs change, a rare event.
// XXX - determine why the normal PresContext::RemapStyleAndReflow doesn't cut it
ReconstructFrames();
}
return result;
} else {
return NS_ERROR_NULL_POINTER;
}
}
nsresult PresShell::ClearPreferenceStyleRules(void)
{
nsresult result = NS_OK;
if (mPrefStyleSheet) {
NS_ASSERTION(mStyleSet, "null styleset entirely unexpected!");
if (mStyleSet) {
// remove the sheet from the styleset:
// - note that we have to check for success by comparing the count before and after...
#ifdef NS_DEBUG
#ifdef PREFS_USE_OVERRIDE
PRInt32 numBefore = mStyleSet->GetNumberOfOverrideStyleSheets();
#else
PRInt32 numBefore = mStyleSet->GetNumberOfBackstopStyleSheets();
#endif
NS_ASSERTION(numBefore > 0, "no override stylesheets in styleset, but we have one!");
#endif
#ifdef PREFS_USE_OVERRIDE
mStyleSet->RemoveOverrideStyleSheet(mPrefStyleSheet);
#else
mStyleSet->RemoveBackstopStyleSheet(mPrefStyleSheet);
#endif
#ifdef NS_DEBUG
#ifdef PREFS_USE_OVERRIDE
NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfOverrideStyleSheets(),
"Pref stylesheet was not removed");
#else
NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfBackstopStyleSheets(),
"Pref stylesheet was not removed");
#endif
printf("PrefStyleSheet removed\n");
#endif
// clear the sheet pointer: it is strictly historical now
NS_IF_RELEASE(mPrefStyleSheet);
}
}
return result;
}
nsresult PresShell::CreatePreferenceStyleSheet(void)
{
NS_ASSERTION(mPrefStyleSheet==nsnull, "prefStyleSheet already exists");
nsresult result = NS_OK;
result = NS_NewCSSStyleSheet(&mPrefStyleSheet);
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(mPrefStyleSheet, "null but no error");
nsCOMPtr<nsIURI> uri;
result = NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nsnull);
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(uri, "null but no error");
result = mPrefStyleSheet->Init(uri);
if (NS_SUCCEEDED(result)) {
mPrefStyleSheet->SetDefaultNameSpaceID(kNameSpaceID_HTML);
#ifdef PREFS_USE_OVERRIDE
mStyleSet->AppendOverrideStyleSheet(mPrefStyleSheet);
#else
mStyleSet->AppendBackstopStyleSheet(mPrefStyleSheet);
#endif
}
}
} else {
result = NS_ERROR_OUT_OF_MEMORY;
}
#ifdef NS_DEBUG
printf("CreatePrefStyleSheet completed: error=%ld\n",(long)result);
#endif
return result;
}
nsresult PresShell::SetPrefColorRules(void)
{
NS_ASSERTION(mPresContext,"null prescontext not allowed");
if (mPresContext) {
nsresult result = NS_OK;
PRBool useDocColors = PR_TRUE;
// see if we need to create the rules first
if (NS_SUCCEEDED(mPresContext->GetCachedBoolPref(kPresContext_UseDocumentColors, useDocColors))) {
if (!useDocColors) {
#ifdef NS_DEBUG
printf(" - Creating rules for document colors\n");
#endif
// OK, not using document colors, so we have to force the user's colors via style rules
if (!mPrefStyleSheet) {
result = CreatePreferenceStyleSheet();
}
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(mPrefStyleSheet, "prefstylesheet should not be null");
nscolor bgColor;
nscolor textColor;
result = mPresContext->GetDefaultColor(&textColor);
if (NS_SUCCEEDED(result)) {
result = mPresContext->GetDefaultBackgroundColor(&bgColor);
}
if (NS_SUCCEEDED(result)) {
// get the DOM interface to the stylesheet
nsCOMPtr<nsIDOMCSSStyleSheet> sheet(do_QueryInterface(mPrefStyleSheet,&result));
if (NS_SUCCEEDED(result)) {
PRUint32 index = 0;
nsAutoString strRule,strColor;
// create a rule for each color and add it to the style sheet
// - the rules are !important so they override all but author
// important rules (when put into a backstop stylesheet) and
// all (even author important) when put into an override stylesheet
///////////////////////////////////////////////////////////////
// - default color: '* {color:#RRGGBB !important;}'
ColorToString(textColor,strColor);
strRule.Append(NS_LITERAL_STRING("* {color:"));
strRule.Append(strColor);
strRule.Append(NS_LITERAL_STRING(" !important;} "));
///////////////////////////////////////////////////////////////
// - default background color: '* {background-color:#RRGGBB !important;}'
ColorToString(bgColor,strColor);
strRule.Append(NS_LITERAL_STRING("* {background-color:"));
strRule.Append(strColor);
strRule.Append(NS_LITERAL_STRING(" !important;} "));
// now insert the rule
result = sheet->InsertRule(strRule,0,&index);
}
}
}
}
}
return result;
} else {
return NS_ERROR_FAILURE;
}
}
nsresult PresShell::SetPrefLinkRules(void)
{
NS_ASSERTION(mPresContext,"null prescontext not allowed");
if (mPresContext) {
nsresult result = NS_OK;
if (!mPrefStyleSheet) {
result = CreatePreferenceStyleSheet();
}
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(mPrefStyleSheet, "prefstylesheet should not be null");
// get the DOM interface to the stylesheet
nsCOMPtr<nsIDOMCSSStyleSheet> sheet(do_QueryInterface(mPrefStyleSheet,&result));
if (NS_SUCCEEDED(result)) {
#ifdef NS_DEBUG
printf(" - Creating rules for link and visited colors\n");
#endif
// support default link colors:
// this means the link colors need to be overridable,
// which they are if we put them in the backstop stylesheet,
// though if using an override sheet this will cause authors grief still
// In the backstop stylesheet, they are !important to keep the forced-color rules
// from coloring the links too
//
// XXX: do active links and visited links get another color?
// They were red in the html.css rules
nscolor linkColor, visitedColor;
result = mPresContext->GetDefaultLinkColor(&linkColor);
if (NS_SUCCEEDED(result)) {
result = mPresContext->GetDefaultVisitedLinkColor(&visitedColor);
}
if (NS_SUCCEEDED(result)) {
// insert a rule to make links the preferred color
PRUint32 index = 0;
nsAutoString strRule, strColor;
///////////////////////////////////////////////////////////////
// - links: '*:link, *:link:active {color: #RRGGBB !important;}'
ColorToString(linkColor,strColor);
strRule.Append(NS_LITERAL_STRING("*:link, *:link:active {color:"));
strRule.Append(strColor);
strRule.Append(NS_LITERAL_STRING(" !important;} "));
///////////////////////////////////////////////////////////////
// - visited links '*:visited, *:visited:active {color: #RRGGBB !important;}'
ColorToString(visitedColor,strColor);
strRule.Append(NS_LITERAL_STRING("*:visited, *:visited:active {color:"));
strRule.Append(strColor);
strRule.Append(NS_LITERAL_STRING(" !important;} "));
// insert the rules
result = sheet->InsertRule(strRule,0,&index);
}
if (NS_SUCCEEDED(result)) {
PRBool underlineLinks = PR_TRUE;
result = mPresContext->GetCachedBoolPref(kPresContext_UnderlineLinks,underlineLinks);
if (NS_SUCCEEDED(result)) {
// create a rule for underline: on or off
PRUint32 index = 0;
nsAutoString strRule;
if (underlineLinks) {
// create a rule to make underlining happen
// ':link, :visited {text-decoration:[underline|none];}'
// no need for important, we want these to be overridable
// NOTE: these must go in the backstop stylesheet or they cannot be
// overridden by authors
#ifdef NS_DEBUG
printf (" - Creating rules for enabling link underlines\n");
#endif
// make a rule to make text-decoration: underline happen for links
strRule.Append(NS_LITERAL_STRING(":link, :visited {text-decoration:underline;}"));
} else {
#ifdef NS_DEBUG
printf (" - Creating rules for disabling link underlines\n");
#endif
// make a rule to make text-decoration: none happen for links
strRule.Append(NS_LITERAL_STRING(":link, :visited {text-decoration:none;}"));
}
// ...now insert the rule
result = sheet->InsertRule(strRule,0,&index);
}
}
}
}
return result;
} else {
return NS_ERROR_FAILURE;
}
}
NS_IMETHODIMP
PresShell::SetDisplaySelection(PRInt16 aToggle)
{
@@ -5942,3 +6345,27 @@ void ReflowCountMgr::DisplayDiffsInTotals(const char * aStr)
}
#endif // MOZ_REFLOW_PERF
// make a color string like #RRGGBB
void ColorToString(nscolor aColor, nsAutoString &aString)
{
nsAutoString tmp;
aString.SetLength(0);
// #
aString.Append(NS_LITERAL_STRING("#"));
// RR
tmp.AppendInt((PRInt32)NS_GET_R(aColor), 16);
if (tmp.Length() < 2) tmp.AppendInt(0,16);
aString.Append(tmp);
tmp.SetLength(0);
// GG
tmp.AppendInt((PRInt32)NS_GET_G(aColor), 16);
if (tmp.Length() < 2) tmp.AppendInt(0,16);
aString.Append(tmp);
tmp.SetLength(0);
// BB
tmp.AppendInt((PRInt32)NS_GET_B(aColor), 16);
if (tmp.Length() < 2) tmp.AppendInt(0,16);
aString.Append(tmp);
}

View File

@@ -90,6 +90,11 @@ enum nsLanguageSpecificTransformType {
eLanguageSpecificTransformType_Korean
};
// supported values for cached bool types
const PRUint32 kPresContext_UseDocumentColors = 0x01;
const PRUint32 kPresContext_UseDocumentFonts = 0x02;
const PRUint32 kPresContext_UnderlineLinks = 0x03;
// An interface for presentation contexts. Presentation contexts are
// objects that provide an outer context for a presentation shell.
class nsIPresContext : public nsISupports {
@@ -213,6 +218,13 @@ public:
NS_IMETHOD SetDefaultFixedFont(const nsFont& aFont) = 0;
virtual const nsFont& GetDefaultFixedFontDeprecated() = 0;
/** Get a cached boolean pref, by its type
if the type is not supported, then NS_ERROR_FAILURE is returned
and the aValue argument is undfined, otherwise aValue is set
to the value of the boolean pref */
// * - initially created for bugs 31816, 20760, 22963
NS_IMETHOD GetCachedBoolPref(PRUint32 prefType, PRBool &aValue) = 0;
/**
* Access Nav's magic font scaler value
*/
@@ -220,7 +232,7 @@ public:
NS_IMETHOD SetFontScaler(PRInt32 aScaler) = 0;
/**
* Get the defualt colors
* Get the default colors
*/
NS_IMETHOD GetDefaultColor(nscolor* aColor) = 0;
NS_IMETHOD GetDefaultBackgroundColor(nscolor* aColor) = 0;
@@ -228,6 +240,8 @@ public:
NS_IMETHOD GetDefaultBackgroundImageRepeat(PRUint8* aRepeat) = 0;
NS_IMETHOD GetDefaultBackgroundImageOffset(nscoord* aX, nscoord* aY) = 0;
NS_IMETHOD GetDefaultBackgroundImageAttachment(PRUint8* aRepeat) = 0;
NS_IMETHOD GetDefaultLinkColor(nscolor* aColor) = 0;
NS_IMETHOD GetDefaultVisitedLinkColor(nscolor* aColor) = 0;
NS_IMETHOD SetDefaultColor(nscolor aColor) = 0;
NS_IMETHOD SetDefaultBackgroundColor(nscolor aColor) = 0;
@@ -235,6 +249,8 @@ public:
NS_IMETHOD SetDefaultBackgroundImageRepeat(PRUint8 aRepeat) = 0;
NS_IMETHOD SetDefaultBackgroundImageOffset(nscoord aX, nscoord aY) = 0;
NS_IMETHOD SetDefaultBackgroundImageAttachment(PRUint8 aRepeat) = 0;
NS_IMETHOD SetDefaultLinkColor(nscolor aColor) = 0;
NS_IMETHOD SetDefaultVisitedLinkColor(nscolor aColor) = 0;
NS_IMETHOD GetImageGroup(nsIImageGroup** aGroupResult) = 0;

View File

@@ -146,6 +146,26 @@ public:
NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle) = 0;
/** Setup all style rules required to implement preferences
* - used for background/text/link colors and link underlining
* may be extended for any prefs that are implemented via style rules
* - aForceReflow argument is used to force a full reframe to make the rules show
* (only used when the current page needs to reflect changed pref rules)
*
* - initially created for bugs 31816, 20760, 22963
*/
NS_IMETHOD SetPreferenceStyleRules(PRBool aForceReflow) = 0;
/** Allow client to enable and disable the use of the preference style rules,
* by type.
* NOTE: type argument is currently ignored, but is in the API for
* future refinement
*
* - initially created for bugs 31816, 20760, 22963
*/
NS_IMETHOD EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType=0xFF) = 0;
NS_IMETHOD ArePrefStyleRulesEnabled(PRBool& aEnabled) = 0;
/**
* Gather titles of all selectable (alternate and preferred) style sheets
* fills void array with nsString* caller must free strings

View File

@@ -90,6 +90,11 @@ enum nsLanguageSpecificTransformType {
eLanguageSpecificTransformType_Korean
};
// supported values for cached bool types
const PRUint32 kPresContext_UseDocumentColors = 0x01;
const PRUint32 kPresContext_UseDocumentFonts = 0x02;
const PRUint32 kPresContext_UnderlineLinks = 0x03;
// An interface for presentation contexts. Presentation contexts are
// objects that provide an outer context for a presentation shell.
class nsIPresContext : public nsISupports {
@@ -213,6 +218,13 @@ public:
NS_IMETHOD SetDefaultFixedFont(const nsFont& aFont) = 0;
virtual const nsFont& GetDefaultFixedFontDeprecated() = 0;
/** Get a cached boolean pref, by its type
if the type is not supported, then NS_ERROR_FAILURE is returned
and the aValue argument is undfined, otherwise aValue is set
to the value of the boolean pref */
// * - initially created for bugs 31816, 20760, 22963
NS_IMETHOD GetCachedBoolPref(PRUint32 prefType, PRBool &aValue) = 0;
/**
* Access Nav's magic font scaler value
*/
@@ -220,7 +232,7 @@ public:
NS_IMETHOD SetFontScaler(PRInt32 aScaler) = 0;
/**
* Get the defualt colors
* Get the default colors
*/
NS_IMETHOD GetDefaultColor(nscolor* aColor) = 0;
NS_IMETHOD GetDefaultBackgroundColor(nscolor* aColor) = 0;
@@ -228,6 +240,8 @@ public:
NS_IMETHOD GetDefaultBackgroundImageRepeat(PRUint8* aRepeat) = 0;
NS_IMETHOD GetDefaultBackgroundImageOffset(nscoord* aX, nscoord* aY) = 0;
NS_IMETHOD GetDefaultBackgroundImageAttachment(PRUint8* aRepeat) = 0;
NS_IMETHOD GetDefaultLinkColor(nscolor* aColor) = 0;
NS_IMETHOD GetDefaultVisitedLinkColor(nscolor* aColor) = 0;
NS_IMETHOD SetDefaultColor(nscolor aColor) = 0;
NS_IMETHOD SetDefaultBackgroundColor(nscolor aColor) = 0;
@@ -235,6 +249,8 @@ public:
NS_IMETHOD SetDefaultBackgroundImageRepeat(PRUint8 aRepeat) = 0;
NS_IMETHOD SetDefaultBackgroundImageOffset(nscoord aX, nscoord aY) = 0;
NS_IMETHOD SetDefaultBackgroundImageAttachment(PRUint8 aRepeat) = 0;
NS_IMETHOD SetDefaultLinkColor(nscolor aColor) = 0;
NS_IMETHOD SetDefaultVisitedLinkColor(nscolor aColor) = 0;
NS_IMETHOD GetImageGroup(nsIImageGroup** aGroupResult) = 0;

View File

@@ -110,6 +110,14 @@ nsPresContext::nsPresContext()
mDefaultColor = NS_RGB(0x00, 0x00, 0x00);
mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
#endif
mUseDocumentColors = PR_TRUE;
mUseDocumentFonts = PR_TRUE;
mLinkColor = NS_RGB(0x33, 0x33, 0xFF);
mVisitedLinkColor = NS_RGB(0x66, 0x00, 0xCC);
mUnderlineLinks = PR_TRUE;
mDefaultBackgroundImageAttachment = NS_STYLE_BG_ATTACHMENT_SCROLL;
mDefaultBackgroundImageRepeat = NS_STYLE_BG_REPEAT_XY;
mDefaultBackgroundImageOffsetX = mDefaultBackgroundImageOffsetY = 0;
@@ -144,6 +152,9 @@ nsPresContext::~nsPresContext()
if (mPrefs) {
mPrefs->UnregisterCallback("font.", PrefChangedCallback, (void*)this);
mPrefs->UnregisterCallback("browser.display.", PrefChangedCallback, (void*)this);
mPrefs->UnregisterCallback("browser.underline_anchors", PrefChangedCallback, (void*)this);
mPrefs->UnregisterCallback("browser.link_color", PrefChangedCallback, (void*)this);
mPrefs->UnregisterCallback("browser.visited_color", PrefChangedCallback, (void*)this);
}
}
@@ -240,16 +251,17 @@ nsPresContext::GetUserPreferences()
mWidgetRenderingMode = (enum nsWidgetRendering)prefInt; // bad cast
}
// * document colors
PRBool usePrefColors = PR_TRUE;
#ifdef _WIN32
PRUint32 colorPref;
PRBool boolPref;
#ifdef _WIN32
// XXX Is Windows the only platform that uses this?
if (NS_OK == mPrefs->GetBoolPref("browser.display.wfe.use_windows_colors", &boolPref)) {
usePrefColors = !boolPref;
}
#endif
if (usePrefColors) {
PRUint32 colorPref;
if (NS_OK == mPrefs->GetColorPrefDWord("browser.display.foreground_color", &colorPref)) {
mDefaultColor = (nscolor)colorPref;
}
@@ -257,13 +269,56 @@ nsPresContext::GetUserPreferences()
mDefaultBackgroundColor = (nscolor)colorPref;
}
}
if (NS_OK == mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref)) {
mUseDocumentColors = boolPref;
}
// * link colors
if (NS_OK == mPrefs->GetBoolPref("browser.underline_anchors", &boolPref)) {
mUnderlineLinks = boolPref;
}
if (NS_OK == mPrefs->GetColorPrefDWord("browser.anchor_color", &colorPref)) {
mLinkColor = (nscolor)colorPref;
}
if (NS_OK == mPrefs->GetColorPrefDWord("browser.visited_color", &colorPref)) {
mVisitedLinkColor = (nscolor)colorPref;
}
// * use fonts?
if (NS_OK == mPrefs->GetIntPref("browser.display.use_document_fonts", &prefInt)) {
mUseDocumentFonts = prefInt == 0 ? PR_FALSE : PR_TRUE;
}
// * direction
if (NS_OK == mPrefs->GetIntPref("browser.display.direction", &prefInt)) {
mDefaultDirection = prefInt;
}
GetFontPreferences();
}
NS_IMETHODIMP
nsPresContext::GetCachedBoolPref(PRUint32 prefType, PRBool &aValue)
{
nsresult rv = NS_ERROR_FAILURE;
switch(prefType) {
case kPresContext_UseDocumentFonts :
aValue = mUseDocumentFonts;
rv = NS_OK;
break;
case kPresContext_UseDocumentColors:
aValue = mUseDocumentColors;
rv = NS_OK;
break;
case kPresContext_UnderlineLinks:
aValue = mUnderlineLinks;
rv = NS_OK;
break;
default :
rv = NS_ERROR_FAILURE;
}
return rv;
}
NS_IMETHODIMP
nsPresContext::RemapStyleAndReflow()
{
@@ -308,6 +363,12 @@ nsPresContext::PreferenceChanged(const char* aPrefName)
{
// Initialize our state from the user preferences
GetUserPreferences();
// update the presShell: tell it to set the preference style rules up
if (mShell) {
mShell->SetPreferenceStyleRules(PR_TRUE);
}
if (mDeviceContext) {
mDeviceContext->FlushFontCache();
RemapStyleAndReflow();
@@ -327,6 +388,9 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext)
// Register callbacks so we're notified when the preferences change
mPrefs->RegisterCallback("font.", PrefChangedCallback, (void*)this);
mPrefs->RegisterCallback("browser.display.", PrefChangedCallback, (void*)this);
mPrefs->RegisterCallback("browser.underline_anchors", PrefChangedCallback, (void*)this);
mPrefs->RegisterCallback("browser.link_color", PrefChangedCallback, (void*)this);
mPrefs->RegisterCallback("browser.visited_color", PrefChangedCallback, (void*)this);
// Initialize our state from the user preferences
GetUserPreferences();
@@ -750,6 +814,28 @@ nsPresContext::GetDefaultBackgroundImageAttachment(PRUint8* aAttachment)
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::GetDefaultLinkColor(nscolor* aColor)
{
NS_PRECONDITION(nsnull != aColor, "null argument");
if (aColor) {
*aColor = mLinkColor;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP
nsPresContext::GetDefaultVisitedLinkColor(nscolor* aColor)
{
NS_PRECONDITION(nsnull != aColor, "null argument");
if (aColor) {
*aColor = mVisitedLinkColor;
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP
nsPresContext::SetDefaultColor(nscolor aColor)
{
@@ -793,6 +879,20 @@ nsPresContext::SetDefaultBackgroundImageAttachment(PRUint8 aAttachment)
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::SetDefaultLinkColor(nscolor aColor)
{
mLinkColor = aColor;
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::SetDefaultVisitedLinkColor(nscolor aColor)
{
mVisitedLinkColor = aColor;
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::GetVisibleArea(nsRect& aResult)
{
@@ -1182,6 +1282,7 @@ nsPresContext::GetLanguageSpecificTransformType(
{
NS_ENSURE_ARG_POINTER(aType);
*aType = mLanguageSpecificTransformType;
return NS_OK;
}

View File

@@ -97,6 +97,8 @@ public:
NS_IMETHOD GetDefaultFixedFont(nsFont& aResult);
NS_IMETHOD SetDefaultFixedFont(const nsFont& aFont);
virtual const nsFont& GetDefaultFixedFontDeprecated();
NS_IMETHOD GetCachedBoolPref(PRUint32 prefType, PRBool &aValue);
NS_IMETHOD GetFontScaler(PRInt32* aResult);
NS_IMETHOD SetFontScaler(PRInt32 aScaler);
NS_IMETHOD GetDefaultColor(nscolor* aColor);
@@ -105,6 +107,8 @@ public:
NS_IMETHOD GetDefaultBackgroundImageRepeat(PRUint8* aRepeat);
NS_IMETHOD GetDefaultBackgroundImageOffset(nscoord* aX, nscoord* aY);
NS_IMETHOD GetDefaultBackgroundImageAttachment(PRUint8* aRepeat);
NS_IMETHOD GetDefaultLinkColor(nscolor* aColor);
NS_IMETHOD GetDefaultVisitedLinkColor(nscolor* aColor);
NS_IMETHOD SetDefaultColor(nscolor aColor);
NS_IMETHOD SetDefaultBackgroundColor(nscolor aColor);
@@ -112,6 +116,8 @@ public:
NS_IMETHOD SetDefaultBackgroundImageRepeat(PRUint8 aRepeat);
NS_IMETHOD SetDefaultBackgroundImageOffset(nscoord aX, nscoord aY);
NS_IMETHOD SetDefaultBackgroundImageAttachment(PRUint8 aRepeat);
NS_IMETHOD SetDefaultLinkColor(nscolor aColor);
NS_IMETHOD SetDefaultVisitedLinkColor(nscolor aColor);
NS_IMETHOD GetImageGroup(nsIImageGroup** aGroupResult);
NS_IMETHOD StartLoadImage(const nsString& aURL,
@@ -176,8 +182,13 @@ protected:
nsFont mDefaultFont;
nsFont mDefaultFixedFont;
PRInt32 mFontScaler;
nscolor mDefaultColor;
nscolor mDefaultBackgroundColor;
PRPackedBool mUseDocumentFonts; // set in GetUserPrefs
nscolor mDefaultColor; // set in GetUserPrefs
nscolor mDefaultBackgroundColor; // set in GetUserPrefs
PRPackedBool mUseDocumentColors; // set in GetUserPrefs
nscolor mLinkColor; // set in GetUserPrefs
nscolor mVisitedLinkColor; // set in GetUserPrefs
PRPackedBool mUnderlineLinks; // set in GetUserPrefs
nsString mDefaultBackgroundImage;
PRUint8 mDefaultBackgroundImageRepeat;
nscoord mDefaultBackgroundImageOffsetX;
@@ -194,7 +205,7 @@ protected:
PRPackedBool mStopped; // loading stopped
PRPackedBool mStopChrome; // should we stop chrome?
PRUint8 mDefaultDirection;
#ifdef DEBUG
PRBool mInitialized;
#endif

View File

@@ -43,6 +43,8 @@
#include "nsIDocumentObserver.h"
#include "nsIStyleSet.h"
#include "nsICSSStyleSheet.h" // XXX for UA sheet loading hack, can this go away please?
#include "nsIDOMCSSStyleSheet.h" // for Pref-related rule management (bugs 22963,20760,31816)
#include "nsINameSpaceManager.h" // for Pref-related rule management (bugs 22963,20760,31816)
#include "nsIStyleContext.h"
#include "nsIServiceManager.h"
#include "nsFrame.h"
@@ -137,6 +139,25 @@
// SubShell map
#include "nsDST.h"
// supporting bugs 31816, 20760, 22963
// define USE_OVERRIDE to put prefs in as an override stylesheet
// otherwise they go in as a Backstop stylesheets
// - OVERRIDE is better for text and bg colors, but bad for link colors,
// so eventually, we should probably have a backstop and an override and
// put the link colors in the backstop and the text and bg colors in the override,
// but using the backstop stylesheet with !important rules solves 95% of the
// problem and should suffice for RTM
//
// XXX: use backstop stylesheet of link colors and link underline,
// user override stylesheet for forcing background and text colors, post RTM
//
// #define PREFS_USE_OVERRIDE
// convert a color value to a string, in the CSS format #RRGGBB
// * - initially created for bugs 31816, 20760, 22963
static void ColorToString(nscolor aColor, nsAutoString &aString);
// local management of the style watch:
// aCtlValue should be set to all actions desired (bitwise OR'd together)
// aStyleSet cannot be null
@@ -755,6 +776,9 @@ public:
NS_IMETHOD GetActiveAlternateStyleSheet(nsString& aSheetTitle);
NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle);
NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList);
NS_IMETHOD SetPreferenceStyleRules(PRBool aForceRefrlow);
NS_IMETHOD EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType=0xFF);
NS_IMETHOD ArePrefStyleRulesEnabled(PRBool& aEnabled);
NS_IMETHOD SetDisplaySelection(PRInt16 aToggle);
NS_IMETHOD GetDisplaySelection(PRInt16 *aToggle);
@@ -989,6 +1013,15 @@ protected:
PRBool mInVerifyReflow;
#endif
/**
* methods that manage rules that are used to implement the associated preferences
* - initially created for bugs 31816, 20760, 22963
*/
nsresult ClearPreferenceStyleRules(void);
nsresult CreatePreferenceStyleSheet(void);
nsresult SetPrefColorRules(void);
nsresult SetPrefLinkRules(void);
// IMPORTANT: The ownership implicit in the following member variables has been
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
// pointers for weak (ie, non owning) references. If you add any members to this
@@ -999,6 +1032,8 @@ protected:
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsIPresContext> mPresContext;
nsCOMPtr<nsIStyleSet> mStyleSet;
nsICSSStyleSheet* mPrefStyleSheet; // mStyleSet owns it but we maintaina ref, may be null
PRPackedBool mEnablePrefStyleSheet;
nsIViewManager* mViewManager; // [WEAK] docViewer owns it so I don't have to
nsILayoutHistoryState* mHistoryState; // [WEAK] session history owns this
PRUint32 mUpdateCount;
@@ -1189,6 +1224,8 @@ PresShell::PresShell():mStackArena(nsnull),
mSubShellMap = nsnull;
mRCCreatedDuringLoad = 0;
mDummyLayoutRequest = nsnull;
mPrefStyleSheet = nsnull;
mEnablePrefStyleSheet = PR_TRUE;
#ifdef MOZ_REFLOW_PERF
mReflowCountMgr = new ReflowCountMgr();
@@ -1248,6 +1285,9 @@ PresShell::~PresShell()
}
#endif
// release our pref style sheet, if we have one still
ClearPreferenceStyleRules();
// if we allocated any stack memory free it.
FreeDynamicStack();
@@ -1420,6 +1460,9 @@ PresShell::Init(nsIDocument* aDocument,
// cache the drag service so we can check it during reflows
mDragService = do_GetService("@mozilla.org/widget/dragservice;1");
// setup the preference style rules up (no forced reflow)
SetPreferenceStyleRules(PR_FALSE);
return NS_OK;
}
@@ -1609,6 +1652,366 @@ PresShell::ListAlternateStyleSheets(nsStringArray& aTitleList)
return NS_OK;
}
NS_IMETHODIMP
PresShell::EnablePrefStyleRules(PRBool aEnable, PRUint8 aPrefType/*=0xFF*/)
{
nsresult result = NS_OK;
// capture change in state
PRBool bChanging = (mEnablePrefStyleSheet != aEnable) ? PR_TRUE : PR_FALSE;
// set to desired state
mEnablePrefStyleSheet = aEnable;
#ifdef NS_DEBUG
printf("PrefStyleSheet %s %s\n",
mEnablePrefStyleSheet ? "ENABLED" : "DISABLED",
bChanging ? "(state toggled)" : "(state unchanged)");
#endif
// deal with changing state
if(bChanging){
switch (mEnablePrefStyleSheet){
case PR_TRUE:
// was off, now on, so create the rules
result = SetPreferenceStyleRules(PR_TRUE);
break;
default :
// was on, now off, so clear the rules
result = ClearPreferenceStyleRules();
break;
}
}
return result;
}
NS_IMETHODIMP
PresShell::ArePrefStyleRulesEnabled(PRBool& aEnabled)
{
aEnabled = mEnablePrefStyleSheet;
return NS_OK;
}
NS_IMETHODIMP
PresShell::SetPreferenceStyleRules(PRBool aForceReflow)
{
NS_PRECONDITION(mPresContext, "presContext cannot be null");
if (mPresContext) {
nsresult result = NS_OK;
// zeroth, make sure this feature is enabled
// XXX: may get more granularity later
// (i.e. each pref may be controlled independently)
if (!mEnablePrefStyleSheet) {
#ifdef NS_DEBUG
printf("PrefStyleSheet disabled\n");
#endif
return PR_TRUE;
}
// first, make sure this is not a chrome shell
nsCOMPtr<nsISupports> container;
result = mPresContext->GetContainer(getter_AddRefs(container));
if (NS_SUCCEEDED(result) && container) {
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
if (NS_SUCCEEDED(result) && docShell){
PRInt32 docShellType;
result = docShell->GetItemType(&docShellType);
if (NS_SUCCEEDED(result)){
if (nsIDocShellTreeItem::typeChrome == docShellType){
return NS_OK;
}
}
}
}
if (NS_SUCCEEDED(result)) {
#ifdef NS_DEBUG
printf("Setting Preference Style Rules:\n");
#endif
// if here, we need to create rules for the prefs
// - this includes the background-color, the text-color,
// the link color, the visited link color and the link-underlining
// first clear any exising rules
result = ClearPreferenceStyleRules();
// now do the color rules
if (NS_SUCCEEDED(result)) {
result = SetPrefColorRules();
}
// now the link rules (must come after the color rules, or links will not be correct color!)
// XXX - when there is both an override and backstop pref stylesheet this won't matter,
// as the color rules will be overrides and the links rules will be backstop
if (NS_SUCCEEDED(result)) {
result = SetPrefLinkRules();
}
// update the styleset now that we are done inserting our rules
if (NS_SUCCEEDED(result)) {
if (mStyleSet) {
mStyleSet->NotifyStyleSheetStateChanged(PR_FALSE);
}
}
}
#ifdef NS_DEBUG
printf( "Preference Style Rules set: error=%ld\n", (long)result);
#endif
if (aForceReflow){
#ifdef NS_DEBUG
printf( "*** Forcing reframe! ***\n");
#endif
// this is harsh, but without it the new colors don't appear on the current page
// Fortunately, it only happens when the prefs change, a rare event.
// XXX - determine why the normal PresContext::RemapStyleAndReflow doesn't cut it
ReconstructFrames();
}
return result;
} else {
return NS_ERROR_NULL_POINTER;
}
}
nsresult PresShell::ClearPreferenceStyleRules(void)
{
nsresult result = NS_OK;
if (mPrefStyleSheet) {
NS_ASSERTION(mStyleSet, "null styleset entirely unexpected!");
if (mStyleSet) {
// remove the sheet from the styleset:
// - note that we have to check for success by comparing the count before and after...
#ifdef NS_DEBUG
#ifdef PREFS_USE_OVERRIDE
PRInt32 numBefore = mStyleSet->GetNumberOfOverrideStyleSheets();
#else
PRInt32 numBefore = mStyleSet->GetNumberOfBackstopStyleSheets();
#endif
NS_ASSERTION(numBefore > 0, "no override stylesheets in styleset, but we have one!");
#endif
#ifdef PREFS_USE_OVERRIDE
mStyleSet->RemoveOverrideStyleSheet(mPrefStyleSheet);
#else
mStyleSet->RemoveBackstopStyleSheet(mPrefStyleSheet);
#endif
#ifdef NS_DEBUG
#ifdef PREFS_USE_OVERRIDE
NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfOverrideStyleSheets(),
"Pref stylesheet was not removed");
#else
NS_ASSERTION((numBefore - 1) == mStyleSet->GetNumberOfBackstopStyleSheets(),
"Pref stylesheet was not removed");
#endif
printf("PrefStyleSheet removed\n");
#endif
// clear the sheet pointer: it is strictly historical now
NS_IF_RELEASE(mPrefStyleSheet);
}
}
return result;
}
nsresult PresShell::CreatePreferenceStyleSheet(void)
{
NS_ASSERTION(mPrefStyleSheet==nsnull, "prefStyleSheet already exists");
nsresult result = NS_OK;
result = NS_NewCSSStyleSheet(&mPrefStyleSheet);
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(mPrefStyleSheet, "null but no error");
nsCOMPtr<nsIURI> uri;
result = NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nsnull);
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(uri, "null but no error");
result = mPrefStyleSheet->Init(uri);
if (NS_SUCCEEDED(result)) {
mPrefStyleSheet->SetDefaultNameSpaceID(kNameSpaceID_HTML);
#ifdef PREFS_USE_OVERRIDE
mStyleSet->AppendOverrideStyleSheet(mPrefStyleSheet);
#else
mStyleSet->AppendBackstopStyleSheet(mPrefStyleSheet);
#endif
}
}
} else {
result = NS_ERROR_OUT_OF_MEMORY;
}
#ifdef NS_DEBUG
printf("CreatePrefStyleSheet completed: error=%ld\n",(long)result);
#endif
return result;
}
nsresult PresShell::SetPrefColorRules(void)
{
NS_ASSERTION(mPresContext,"null prescontext not allowed");
if (mPresContext) {
nsresult result = NS_OK;
PRBool useDocColors = PR_TRUE;
// see if we need to create the rules first
if (NS_SUCCEEDED(mPresContext->GetCachedBoolPref(kPresContext_UseDocumentColors, useDocColors))) {
if (!useDocColors) {
#ifdef NS_DEBUG
printf(" - Creating rules for document colors\n");
#endif
// OK, not using document colors, so we have to force the user's colors via style rules
if (!mPrefStyleSheet) {
result = CreatePreferenceStyleSheet();
}
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(mPrefStyleSheet, "prefstylesheet should not be null");
nscolor bgColor;
nscolor textColor;
result = mPresContext->GetDefaultColor(&textColor);
if (NS_SUCCEEDED(result)) {
result = mPresContext->GetDefaultBackgroundColor(&bgColor);
}
if (NS_SUCCEEDED(result)) {
// get the DOM interface to the stylesheet
nsCOMPtr<nsIDOMCSSStyleSheet> sheet(do_QueryInterface(mPrefStyleSheet,&result));
if (NS_SUCCEEDED(result)) {
PRUint32 index = 0;
nsAutoString strRule,strColor;
// create a rule for each color and add it to the style sheet
// - the rules are !important so they override all but author
// important rules (when put into a backstop stylesheet) and
// all (even author important) when put into an override stylesheet
///////////////////////////////////////////////////////////////
// - default color: '* {color:#RRGGBB !important;}'
ColorToString(textColor,strColor);
strRule.Append(NS_LITERAL_STRING("* {color:"));
strRule.Append(strColor);
strRule.Append(NS_LITERAL_STRING(" !important;} "));
///////////////////////////////////////////////////////////////
// - default background color: '* {background-color:#RRGGBB !important;}'
ColorToString(bgColor,strColor);
strRule.Append(NS_LITERAL_STRING("* {background-color:"));
strRule.Append(strColor);
strRule.Append(NS_LITERAL_STRING(" !important;} "));
// now insert the rule
result = sheet->InsertRule(strRule,0,&index);
}
}
}
}
}
return result;
} else {
return NS_ERROR_FAILURE;
}
}
nsresult PresShell::SetPrefLinkRules(void)
{
NS_ASSERTION(mPresContext,"null prescontext not allowed");
if (mPresContext) {
nsresult result = NS_OK;
if (!mPrefStyleSheet) {
result = CreatePreferenceStyleSheet();
}
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(mPrefStyleSheet, "prefstylesheet should not be null");
// get the DOM interface to the stylesheet
nsCOMPtr<nsIDOMCSSStyleSheet> sheet(do_QueryInterface(mPrefStyleSheet,&result));
if (NS_SUCCEEDED(result)) {
#ifdef NS_DEBUG
printf(" - Creating rules for link and visited colors\n");
#endif
// support default link colors:
// this means the link colors need to be overridable,
// which they are if we put them in the backstop stylesheet,
// though if using an override sheet this will cause authors grief still
// In the backstop stylesheet, they are !important to keep the forced-color rules
// from coloring the links too
//
// XXX: do active links and visited links get another color?
// They were red in the html.css rules
nscolor linkColor, visitedColor;
result = mPresContext->GetDefaultLinkColor(&linkColor);
if (NS_SUCCEEDED(result)) {
result = mPresContext->GetDefaultVisitedLinkColor(&visitedColor);
}
if (NS_SUCCEEDED(result)) {
// insert a rule to make links the preferred color
PRUint32 index = 0;
nsAutoString strRule, strColor;
///////////////////////////////////////////////////////////////
// - links: '*:link, *:link:active {color: #RRGGBB !important;}'
ColorToString(linkColor,strColor);
strRule.Append(NS_LITERAL_STRING("*:link, *:link:active {color:"));
strRule.Append(strColor);
strRule.Append(NS_LITERAL_STRING(" !important;} "));
///////////////////////////////////////////////////////////////
// - visited links '*:visited, *:visited:active {color: #RRGGBB !important;}'
ColorToString(visitedColor,strColor);
strRule.Append(NS_LITERAL_STRING("*:visited, *:visited:active {color:"));
strRule.Append(strColor);
strRule.Append(NS_LITERAL_STRING(" !important;} "));
// insert the rules
result = sheet->InsertRule(strRule,0,&index);
}
if (NS_SUCCEEDED(result)) {
PRBool underlineLinks = PR_TRUE;
result = mPresContext->GetCachedBoolPref(kPresContext_UnderlineLinks,underlineLinks);
if (NS_SUCCEEDED(result)) {
// create a rule for underline: on or off
PRUint32 index = 0;
nsAutoString strRule;
if (underlineLinks) {
// create a rule to make underlining happen
// ':link, :visited {text-decoration:[underline|none];}'
// no need for important, we want these to be overridable
// NOTE: these must go in the backstop stylesheet or they cannot be
// overridden by authors
#ifdef NS_DEBUG
printf (" - Creating rules for enabling link underlines\n");
#endif
// make a rule to make text-decoration: underline happen for links
strRule.Append(NS_LITERAL_STRING(":link, :visited {text-decoration:underline;}"));
} else {
#ifdef NS_DEBUG
printf (" - Creating rules for disabling link underlines\n");
#endif
// make a rule to make text-decoration: none happen for links
strRule.Append(NS_LITERAL_STRING(":link, :visited {text-decoration:none;}"));
}
// ...now insert the rule
result = sheet->InsertRule(strRule,0,&index);
}
}
}
}
return result;
} else {
return NS_ERROR_FAILURE;
}
}
NS_IMETHODIMP
PresShell::SetDisplaySelection(PRInt16 aToggle)
{
@@ -5942,3 +6345,27 @@ void ReflowCountMgr::DisplayDiffsInTotals(const char * aStr)
}
#endif // MOZ_REFLOW_PERF
// make a color string like #RRGGBB
void ColorToString(nscolor aColor, nsAutoString &aString)
{
nsAutoString tmp;
aString.SetLength(0);
// #
aString.Append(NS_LITERAL_STRING("#"));
// RR
tmp.AppendInt((PRInt32)NS_GET_R(aColor), 16);
if (tmp.Length() < 2) tmp.AppendInt(0,16);
aString.Append(tmp);
tmp.SetLength(0);
// GG
tmp.AppendInt((PRInt32)NS_GET_G(aColor), 16);
if (tmp.Length() < 2) tmp.AppendInt(0,16);
aString.Append(tmp);
tmp.SetLength(0);
// BB
tmp.AppendInt((PRInt32)NS_GET_B(aColor), 16);
if (tmp.Length() < 2) tmp.AppendInt(0,16);
aString.Append(tmp);
}

View File

@@ -35,6 +35,10 @@
#include "nsIPresContext.h"
#include "nsIHTMLAttributes.h"
// MJA: bug 31816
#include "nsIPresShell.h"
#include "nsIDocShellTreeItem.h"
// - END MJA
class nsHTMLFontElement : public nsIDOMHTMLFontElement,
public nsIJSScriptObject,
@@ -218,7 +222,48 @@ MapFontAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
font->mFont.name = familyList;
nsAutoString face;
if (NS_OK == dc->FirstExistingFont(font->mFont, face)) {
// MJA: bug 31816
// if we are not using document fonts, but this is a xul document,
// then we set the chromeOverride bit so we use the document fonts anyway
PRBool chromeOverride = PR_FALSE;
PRBool useDocumentFonts = PR_TRUE;
aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts,useDocumentFonts);
if (!useDocumentFonts) {
// check if the prefs have been disabled for this shell
// - if prefs are disabled then we use the document fonts anyway (yet another override)
PRBool prefsEnabled = PR_TRUE;
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
if (shell) {
shell->ArePrefStyleRulesEnabled(prefsEnabled);
}
if (!prefsEnabled) {
useDocumentFonts = PR_TRUE;
} else {
// see if we are in the chrome, if so, use the document fonts (override the useDocFonts setting)
nsresult result = NS_OK;
nsCOMPtr<nsISupports> container;
result = aPresContext->GetContainer(getter_AddRefs(container));
if (NS_SUCCEEDED(result) && container) {
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
if (NS_SUCCEEDED(result) && docShell){
PRInt32 docShellType;
result = docShell->GetItemType(&docShellType);
if (NS_SUCCEEDED(result)){
if (nsIDocShellTreeItem::typeChrome == docShellType){
chromeOverride = PR_TRUE;
}
}
}
}
}
}
// find the correct font if we are usingDocumentFonts OR we are overriding for XUL
// MJA: bug 31816
if ((chromeOverride || useDocumentFonts) &&
NS_OK == dc->FirstExistingFont(font->mFont, face)) {
if (face.EqualsIgnoreCase("-moz-fixed")) {
font->mFlags |= NS_STYLE_FONT_USE_FIXED;
} else {

View File

@@ -401,15 +401,11 @@ fieldset {
/* links */
:link {
color: blue;
text-decoration: underline;
cursor: pointer;
-moz-user-focus: normal;
}
:visited {
color: purple;
text-decoration: underline;
cursor: pointer;
-moz-user-focus: normal;
}

View File

@@ -55,6 +55,11 @@
#include "nsIStyleSet.h"
#include "nsISizeOfHandler.h"
// MJA: bug 31816
#include "nsIPresShell.h"
#include "nsIDocShellTreeItem.h"
// - END MJA
// #define DEBUG_REFS
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@@ -1599,7 +1604,48 @@ MapDeclarationFontInto(nsICSSDeclaration* aDeclaration,
font->mFont.name = familyList;
nsAutoString face;
if (NS_OK == dc->FirstExistingFont(font->mFont, face)) {
// MJA: bug 31816
// if we are not using document fonts, but this is a xul document,
// then we set the chromeOverride bit so we use the document fonts anyway
PRBool chromeOverride = PR_FALSE;
PRBool useDocumentFonts = PR_TRUE;
aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts,useDocumentFonts);
if (!useDocumentFonts) {
// check if the prefs have been disabled for this shell
// - if prefs are disabled then we use the document fonts anyway (yet another override)
PRBool prefsEnabled = PR_TRUE;
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
if (shell) {
shell->ArePrefStyleRulesEnabled(prefsEnabled);
}
if (!prefsEnabled) {
useDocumentFonts = PR_TRUE;
} else {
// see if we are in the chrome, if so, use the document fonts (override the useDocFonts setting)
nsresult result = NS_OK;
nsCOMPtr<nsISupports> container;
result = aPresContext->GetContainer(getter_AddRefs(container));
if (NS_SUCCEEDED(result) && container) {
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
if (NS_SUCCEEDED(result) && docShell){
PRInt32 docShellType;
result = docShell->GetItemType(&docShellType);
if (NS_SUCCEEDED(result)){
if (nsIDocShellTreeItem::typeChrome == docShellType){
chromeOverride = PR_TRUE;
}
}
}
}
}
}
// find the correct font if we are usingDocumentFonts OR we are overriding for XUL
// MJA: bug 31816
if ((chromeOverride || useDocumentFonts) &&
(NS_OK == dc->FirstExistingFont(font->mFont, face))) {
if (face.EqualsIgnoreCase("-moz-fixed")) {
font->mFlags |= NS_STYLE_FONT_USE_FIXED;
}

View File

@@ -401,15 +401,11 @@ fieldset {
/* links */
:link {
color: blue;
text-decoration: underline;
cursor: pointer;
-moz-user-focus: normal;
}
:visited {
color: purple;
text-decoration: underline;
cursor: pointer;
-moz-user-focus: normal;
}

View File

@@ -55,6 +55,11 @@
#include "nsIStyleSet.h"
#include "nsISizeOfHandler.h"
// MJA: bug 31816
#include "nsIPresShell.h"
#include "nsIDocShellTreeItem.h"
// - END MJA
// #define DEBUG_REFS
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@@ -1599,7 +1604,48 @@ MapDeclarationFontInto(nsICSSDeclaration* aDeclaration,
font->mFont.name = familyList;
nsAutoString face;
if (NS_OK == dc->FirstExistingFont(font->mFont, face)) {
// MJA: bug 31816
// if we are not using document fonts, but this is a xul document,
// then we set the chromeOverride bit so we use the document fonts anyway
PRBool chromeOverride = PR_FALSE;
PRBool useDocumentFonts = PR_TRUE;
aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts,useDocumentFonts);
if (!useDocumentFonts) {
// check if the prefs have been disabled for this shell
// - if prefs are disabled then we use the document fonts anyway (yet another override)
PRBool prefsEnabled = PR_TRUE;
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
if (shell) {
shell->ArePrefStyleRulesEnabled(prefsEnabled);
}
if (!prefsEnabled) {
useDocumentFonts = PR_TRUE;
} else {
// see if we are in the chrome, if so, use the document fonts (override the useDocFonts setting)
nsresult result = NS_OK;
nsCOMPtr<nsISupports> container;
result = aPresContext->GetContainer(getter_AddRefs(container));
if (NS_SUCCEEDED(result) && container) {
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
if (NS_SUCCEEDED(result) && docShell){
PRInt32 docShellType;
result = docShell->GetItemType(&docShellType);
if (NS_SUCCEEDED(result)){
if (nsIDocShellTreeItem::typeChrome == docShellType){
chromeOverride = PR_TRUE;
}
}
}
}
}
}
// find the correct font if we are usingDocumentFonts OR we are overriding for XUL
// MJA: bug 31816
if ((chromeOverride || useDocumentFonts) &&
(NS_OK == dc->FirstExistingFont(font->mFont, face))) {
if (face.EqualsIgnoreCase("-moz-fixed")) {
font->mFlags |= NS_STYLE_FONT_USE_FIXED;
}