From 6b60a8affbc3723859ae8c52dcd2ec20aca8dae1 Mon Sep 17 00:00:00 2001 From: "caillon%returnzero.com" Date: Tue, 10 Dec 2002 23:41:12 +0000 Subject: [PATCH] Bug 181975 - Convert layout to use nsIPrefService, nsIPrefBranch, and friends. r/sr=roc+moz git-svn-id: svn://10.0.0.236/trunk@135068 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsCSSFrameConstructor.cpp | 15 +- mozilla/layout/base/nsCaret.cpp | 1 - mozilla/layout/base/nsPresContext.cpp | 171 +++++++++--------- mozilla/layout/base/nsPresContext.h | 1 - mozilla/layout/base/nsPresShell.cpp | 42 +++-- mozilla/layout/base/public/nsIPresContext.h | 1 - mozilla/layout/base/public/nsPresContext.h | 1 - mozilla/layout/base/src/nsCaret.cpp | 1 - mozilla/layout/base/src/nsPresContext.cpp | 171 +++++++++--------- mozilla/layout/base/src/nsPresContext.h | 5 +- mozilla/layout/generic/nsFrame.cpp | 10 +- mozilla/layout/generic/nsFrameFrame.cpp | 1 - mozilla/layout/generic/nsHTMLReflowState.cpp | 80 ++++++-- mozilla/layout/generic/nsImageFrame.cpp | 13 +- mozilla/layout/generic/nsObjectFrame.cpp | 16 +- .../layout/generic/nsSimplePageSequence.cpp | 35 ++-- mozilla/layout/generic/nsSimplePageSequence.h | 4 +- mozilla/layout/generic/nsTextFrame.cpp | 23 ++- mozilla/layout/generic/nsTextTransformer.cpp | 10 +- mozilla/layout/html/base/src/nsFrame.cpp | 10 +- .../html/base/src/nsHTMLReflowState.cpp | 80 ++++++-- mozilla/layout/html/base/src/nsImageFrame.cpp | 13 +- .../layout/html/base/src/nsObjectFrame.cpp | 16 +- mozilla/layout/html/base/src/nsPresShell.cpp | 42 +++-- .../html/base/src/nsSimplePageSequence.cpp | 35 ++-- .../html/base/src/nsSimplePageSequence.h | 4 +- mozilla/layout/html/base/src/nsTextFrame.cpp | 23 ++- .../html/base/src/nsTextTransformer.cpp | 10 +- .../layout/html/document/src/nsFrameFrame.cpp | 1 - .../html/style/src/nsCSSFrameConstructor.cpp | 15 +- mozilla/layout/svg/base/src/nsSVGGraphic.cpp | 13 +- mozilla/layout/svg/base/src/nsSVGStroke.cpp | 13 +- mozilla/layout/xul/base/src/nsBoxFrame.cpp | 9 +- .../xul/base/src/nsBoxToBlockAdaptor.cpp | 1 - .../layout/xul/base/src/nsContainerBox.cpp | 1 - .../layout/xul/base/src/nsMenuBarListener.cpp | 22 +-- mozilla/layout/xul/base/src/nsMenuFrame.cpp | 10 +- mozilla/layout/xul/base/src/nsSliderFrame.cpp | 16 +- .../layout/xul/base/src/nsTextBoxFrame.cpp | 26 ++- .../xul/base/src/nsXULTooltipListener.cpp | 53 ++++-- .../xul/base/src/nsXULTooltipListener.h | 6 +- 41 files changed, 569 insertions(+), 451 deletions(-) diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 0b643df7bf8..8f8ed7ed399 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -93,7 +93,8 @@ #include "nsIAnonymousContentCreator.h" #include "nsIFrameManager.h" #include "nsIAttributeContent.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsLegendFrame.h" #include "nsIContentIterator.h" #include "nsBoxLayoutState.h" @@ -4231,10 +4232,10 @@ nsCSSFrameConstructor::HasGfxScrollbars() #endif // Get the Prefs if (!mGotGfxPrefs) { - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); - if (pref) { + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { PRBool hasGfxScroll = PR_FALSE; // use a temp since we have a PRPackedBool - pref->GetBoolPref("nglayout.widget.gfxscrollbars", &hasGfxScroll); + prefBranch->GetBoolPref("nglayout.widget.gfxscrollbars", &hasGfxScroll); mHasGfxScrollbars = hasGfxScroll; mGotGfxPrefs = PR_TRUE; } else { @@ -4251,10 +4252,10 @@ PRBool nsCSSFrameConstructor::UseXBLForms() { if (!mGotXBLFormPrefs) { - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); - if (pref) { + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { PRBool useXBLForms = PR_FALSE; // use a temp since we have a PRPackedBool - pref->GetBoolPref("nglayout.debug.enable_xbl_forms", &useXBLForms); + prefBranch->GetBoolPref("nglayout.debug.enable_xbl_forms", &useXBLForms); mUseXBLForms = useXBLForms; mGotXBLFormPrefs = PR_TRUE; } diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index ed1d70c72f8..557c7acc988 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -75,7 +75,6 @@ #ifdef IBMBIDI //-------------------------------IBM BIDI-------------------------------------- // Mamdouh : Modifiaction of the caret to work with Bidi in the LTR and RTL -#include "nsIPref.h" #include "nsLayoutAtoms.h" //------------------------------END OF IBM BIDI-------------------------------- #endif //IBMBIDI diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index d722ff0c360..2aed821beb5 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -37,7 +37,9 @@ #include "nsCOMPtr.h" #include "nsPresContext.h" #include "nsIPresShell.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranchInternal.h" +#include "nsISupportsPrimitives.h" #include "nsILinkHandler.h" #include "nsIDocShellTreeItem.h" #include "nsIStyleSet.h" @@ -95,18 +97,6 @@ MakeColorPref(const char *colstr) return colorref; } -int PR_CALLBACK -nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data) -{ - nsPresContext* presContext = (nsPresContext*)instance_data; - - NS_ASSERTION(nsnull != presContext, "bad instance data"); - if (nsnull != presContext) { - presContext->PreferenceChanged(aPrefName); - } - return 0; // PREF_OK -} - #ifdef IBMBIDI PRBool IsVisualCharset(const nsAutoString& aCharset) @@ -223,23 +213,22 @@ nsPresContext::~nsPresContext() if (mEventManager) mEventManager->SetPresContext(nsnull); // unclear if this is needed, but can't hurt - // Unregister preference callbacks - if (mPrefs) { - 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); + // Unregister preference observers + nsCOMPtr prefInternal(do_QueryInterface(mPrefBranch)); + if (prefInternal) { + prefInternal->RemoveObserver("browser.anchor_color", this); + prefInternal->RemoveObserver("browser.display.", this); + prefInternal->RemoveObserver("browser.underline_anchors", this); + prefInternal->RemoveObserver("browser.visited_color", this); + prefInternal->RemoveObserver("font.", this); + prefInternal->RemoveObserver("image.animation_mode", this); + prefInternal->RemoveObserver("network.image.imageBehavior", this); #ifdef IBMBIDI - mPrefs->UnregisterCallback("bidi.", PrefChangedCallback, (void*)this); + prefInternal->RemoveObserver("bidi.", this); #endif } #ifdef IBMBIDI - if (mBidiUtils) { - delete mBidiUtils; - } + delete mBidiUtils; #endif // IBMBIDI } @@ -262,7 +251,7 @@ static const char* const kGenericFont[] = { void nsPresContext::GetFontPreferences() { - if (!mPrefs || !mLanguage) + if (!mPrefBranch || !mLanguage) return; /* Fetch the font prefs to be used -- see bug 61883 for details. @@ -292,13 +281,12 @@ nsPresContext::GetFontPreferences() 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)); + nsresult rv = mPrefBranch->GetCharPref("font.size.unit", getter_Copies(cvalue)); if (NS_SUCCEEDED(rv)) { if (!PL_strcmp(cvalue.get(), "px")) { unit = eUnit_px; @@ -314,8 +302,9 @@ nsPresContext::GetFontPreferences() // get font.minimum-size.[langGroup] PRInt32 size; - pref.Assign("font.minimum-size."); pref.Append(NS_ConvertUCS2toUTF8(langGroup)); - rv = mPrefs->GetIntPref(pref.get(), &size); + pref.Assign("font.minimum-size."); + pref.Append(NS_ConvertUCS2toUTF8(langGroup)); + rv = mPrefBranch->GetIntPref(pref.get(), &size); if (NS_SUCCEEDED(rv)) { if (unit == eUnit_px) { mMinimumFontSize = NSFloatPixelsToTwips((float)size, p2t); @@ -331,7 +320,7 @@ nsPresContext::GetFontPreferences() generic_dot_langGroup.Assign(kGenericFont[eType]); generic_dot_langGroup.Append(NS_ConvertUCS2toUTF8(langGroup)); - nsFont* font; + nsFont* font = nsnull; switch (eType) { case eDefaultFont_Variable: font = &mDefaultVariableFont; break; case eDefaultFont_Fixed: font = &mDefaultFixedFont; break; @@ -347,14 +336,19 @@ nsPresContext::GetFontPreferences() // 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); + nsCOMPtr prefString; + mPrefBranch->GetComplexValue(pref.get(), + NS_GET_IID(nsISupportsString), + getter_AddRefs(prefString)); + if (prefString) { + prefString->GetData(font->name); } else { - rv = mPrefs->CopyUnicharPref("font.default", getter_Copies(value)); - if (NS_SUCCEEDED(rv)) { - mDefaultVariableFont.name.Assign(value); + mPrefBranch->GetComplexValue("font.default", + NS_GET_IID(nsISupportsString), + getter_AddRefs(prefString)); + if (prefString) { + prefString->GetData(mDefaultVariableFont.name); } } } @@ -381,7 +375,7 @@ nsPresContext::GetFontPreferences() // 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); - rv = mPrefs->GetIntPref(pref.get(), &size); + rv = mPrefBranch->GetIntPref(pref.get(), &size); if (NS_SUCCEEDED(rv) && size > 0) { if (unit == eUnit_px) { font->size = NSFloatPixelsToTwips((float)size, p2t); @@ -394,7 +388,7 @@ nsPresContext::GetFontPreferences() // 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)); + rv = mPrefBranch->GetCharPref(pref.get(), getter_Copies(cvalue)); if (NS_SUCCEEDED(rv)) { font->sizeAdjust = (float)atof(cvalue.get()); } @@ -421,15 +415,15 @@ nsPresContext::GetDocumentColorPreferences() usePrefColors = PR_FALSE; } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_system_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_system_colors", &boolPref))) { usePrefColors = !boolPref; } } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { mDefaultColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.background_color", getter_Copies(colorStr)))) { + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.background_color", getter_Copies(colorStr)))) { mDefaultBackgroundColor = MakeColorPref(colorStr); } } @@ -445,7 +439,7 @@ nsPresContext::GetDocumentColorPreferences() } } - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_document_colors", &boolPref))) { mUseDocumentColors = boolPref; } } @@ -453,13 +447,13 @@ nsPresContext::GetDocumentColorPreferences() void nsPresContext::GetUserPreferences() { - PRInt32 prefInt; + PRInt32 prefInt = 0; - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.base_font_scaler", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.base_font_scaler", &prefInt))) { mFontScaler = prefInt; } - if (NS_SUCCEEDED(mPrefs->GetIntPref("nglayout.widget.mode", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("nglayout.widget.mode", &prefInt))) { mWidgetRenderingMode = (enum nsWidgetRendering)prefInt; // bad cast } @@ -468,78 +462,75 @@ nsPresContext::GetUserPreferences() // * link colors PRBool boolPref; - nsXPIDLCString colorStr; - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.underline_anchors", &boolPref))) { + nsXPIDLCString stringPref; + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.underline_anchors", &boolPref))) { mUnderlineLinks = boolPref; } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.anchor_color", getter_Copies(colorStr)))) { - mLinkColor = MakeColorPref(colorStr); + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.anchor_color", getter_Copies(stringPref)))) { + mLinkColor = MakeColorPref(stringPref); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.visited_color", getter_Copies(colorStr)))) { - mVisitedLinkColor = MakeColorPref(colorStr); + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.visited_color", getter_Copies(stringPref)))) { + mVisitedLinkColor = MakeColorPref(stringPref); } - - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { mUseFocusColors = boolPref; mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mDefaultBackgroundColor; - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_text_color", getter_Copies(colorStr)))) { - mFocusTextColor = MakeColorPref(colorStr); + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.focus_text_color", getter_Copies(stringPref)))) { + mFocusTextColor = MakeColorPref(stringPref); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_background_color", getter_Copies(colorStr)))) { - mFocusBackgroundColor = MakeColorPref(colorStr); + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.focus_background_color", getter_Copies(stringPref)))) { + mFocusBackgroundColor = MakeColorPref(stringPref); } } - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_ring_width", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.focus_ring_width", &prefInt))) { mFocusRingWidth = prefInt; } - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { mFocusRingOnAnything = boolPref; } // * use fonts? - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.use_document_fonts", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.use_document_fonts", &prefInt))) { mUseDocumentFonts = prefInt == 0 ? PR_FALSE : PR_TRUE; } GetFontPreferences(); // * image animation - char* animatePref = 0; - nsresult rv = mPrefs->CopyCharPref("image.animation_mode", &animatePref); - if (NS_SUCCEEDED(rv) && animatePref) { - if (!nsCRT::strcmp(animatePref, "normal")) + nsresult rv = mPrefBranch->GetCharPref("image.animation_mode", getter_Copies(stringPref)); + if (NS_SUCCEEDED(rv)) { + if (stringPref.Equals("normal")) mImageAnimationModePref = imgIContainer::kNormalAnimMode; - else if (!nsCRT::strcmp(animatePref, "none")) + else if (stringPref.Equals("none")) mImageAnimationModePref = imgIContainer::kDontAnimMode; - else if (!nsCRT::strcmp(animatePref, "once")) + else if (stringPref.Equals("once")) mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode; - nsMemory::Free(animatePref); } #ifdef IBMBIDI - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.direction", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.direction", &prefInt))) { SET_BIDI_OPTION_DIRECTION(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.texttype", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.texttype", &prefInt))) { SET_BIDI_OPTION_TEXTTYPE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.controlstextmode", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.controlstextmode", &prefInt))) { SET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.clipboardtextmode", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.clipboardtextmode", &prefInt))) { SET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.numeral", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.numeral", &prefInt))) { SET_BIDI_OPTION_NUMERAL(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.support", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.support", &prefInt))) { SET_BIDI_OPTION_SUPPORT(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.characterset", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.characterset", &prefInt))) { SET_BIDI_OPTION_CHARACTERSET(mBidi, prefInt); } #endif @@ -634,18 +625,19 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) mDeviceContext = dont_QueryInterface(aDeviceContext); mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); - mPrefs = do_GetService(NS_PREF_CONTRACTID); - if (mPrefs) { - // Register callbacks so we're notified when the preferences change - 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); + mPrefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefInternal(do_QueryInterface(mPrefBranch)); + if (prefInternal) { + // Register observers so we're notified when the preferences change + prefInternal->AddObserver("browser.anchor_color", this, PR_FALSE); + prefInternal->AddObserver("browser.display.", this, PR_FALSE); + prefInternal->AddObserver("browser.underline_anchors", this, PR_FALSE); + prefInternal->AddObserver("browser.visited_color", this, PR_FALSE); + prefInternal->AddObserver("font.", this, PR_FALSE); + prefInternal->AddObserver("image.animation_mode", this, PR_FALSE); + prefInternal->AddObserver("network.image.imageBehavior", this, PR_FALSE); #ifdef IBMBIDI - mPrefs->RegisterCallback("bidi.", PrefChangedCallback, (void*)this); + prefInternal->AddObserver("bidi.", this, PR_FALSE); #endif // Initialize our state from the user preferences @@ -751,6 +743,11 @@ nsPresContext::Observe(nsISupports* aSubject, return NS_OK; } + if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { + PreferenceChanged(NS_LossyConvertUCS2toASCII(aData).get()); + return NS_OK; + } + NS_WARNING("unrecognized topic in nsPresContext::Observe"); return NS_ERROR_FAILURE; } diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index 55224b37a4c..31b58d858d3 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -60,7 +60,6 @@ class nsIFrame; class nsIImage; class nsILinkHandler; class nsIPresShell; -class nsIPref; class nsIStyleContext; class nsIAtom; class nsString; diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 32d85633b9f..c22e8fd2d19 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -57,7 +57,8 @@ #include "prinrval.h" #include "nsVoidArray.h" #include "nsHashtable.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIViewObserver.h" #include "nsContainerFrame.h" #include "nsIDeviceContext.h" @@ -197,7 +198,6 @@ static nsresult CtlStyleWatch(PRUint32 aCtlValue, nsIStyleSet *aStyleSet); static NS_DEFINE_CID(kFrameSelectionCID, NS_FRAMESELECTION_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); -static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); #undef NOISY @@ -1694,10 +1694,11 @@ PresShell::Init(nsIDocument* aDocument, gAsyncReflowDuringDocLoad = PR_TRUE; // Get the prefs service - nsCOMPtr prefs(do_GetService(kPrefServiceCID, &result)); - if (NS_SUCCEEDED(result)) { - prefs->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime); - prefs->GetBoolPref("layout.reflow.async.duringDocLoad", &gAsyncReflowDuringDocLoad); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { + prefBranch->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime); + prefBranch->GetBoolPref("layout.reflow.async.duringDocLoad", + &gAsyncReflowDuringDocLoad); } } @@ -1716,16 +1717,19 @@ PresShell::Init(nsIDocument* aDocument, #endif #ifdef MOZ_REFLOW_PERF - // Get the prefs service - nsCOMPtr prefs(do_GetService(kPrefServiceCID, &result)); - if (NS_SUCCEEDED(result)) { - if (mReflowCountMgr != nsnull) { + if (mReflowCountMgr) { + // Get the prefs service + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { PRBool paintFrameCounts = PR_FALSE; PRBool dumpFrameCounts = PR_FALSE; PRBool dumpFrameByFrameCounts = PR_FALSE; - prefs->GetBoolPref("layout.reflow.showframecounts", &paintFrameCounts); - prefs->GetBoolPref("layout.reflow.dumpframecounts", &dumpFrameCounts); - prefs->GetBoolPref("layout.reflow.dumpframebyframecounts", &dumpFrameByFrameCounts); + prefBranch->GetBoolPref("layout.reflow.showframecounts", + &paintFrameCounts); + prefBranch->GetBoolPref("layout.reflow.dumpframecounts", + &dumpFrameCounts); + prefBranch->GetBoolPref("layout.reflow.dumpframebyframecounts", + &dumpFrameByFrameCounts); mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); @@ -2854,9 +2858,9 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) else { // Initialize the timer. PRInt32 delay = PAINTLOCK_EVENT_DELAY; // Use this value if we fail to get the pref value. - nsCOMPtr prefs(do_GetService(kPrefServiceCID)); - if (prefs) - prefs->GetIntPref("nglayout.initialpaint.delay", &delay); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) + prefBranch->GetIntPref("nglayout.initialpaint.delay", &delay); nsCOMPtr ti = do_QueryInterface(mPaintSuppressionTimer); ti->SetIdle(PR_FALSE); @@ -4004,9 +4008,9 @@ PresShell::GoToAnchor(const nsAString& aAnchorName) // Should we select the target? // This action is controlled by a preference: the default is to not select. PRBool selectAnchor = PR_FALSE; - nsCOMPtr prefs(do_GetService(kPrefServiceCID,&rv)); - if (NS_SUCCEEDED(rv) && prefs) { - prefs->GetBoolPref("layout.selectanchor",&selectAnchor); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { + prefBranch->GetBoolPref("layout.selectanchor", &selectAnchor); } // Even if select anchor pref is false, we must still move the caret there. // That way tabbing will start from the new location diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index 55224b37a4c..31b58d858d3 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -60,7 +60,6 @@ class nsIFrame; class nsIImage; class nsILinkHandler; class nsIPresShell; -class nsIPref; class nsIStyleContext; class nsIAtom; class nsString; diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index 55224b37a4c..31b58d858d3 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -60,7 +60,6 @@ class nsIFrame; class nsIImage; class nsILinkHandler; class nsIPresShell; -class nsIPref; class nsIStyleContext; class nsIAtom; class nsString; diff --git a/mozilla/layout/base/src/nsCaret.cpp b/mozilla/layout/base/src/nsCaret.cpp index ed1d70c72f8..557c7acc988 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -75,7 +75,6 @@ #ifdef IBMBIDI //-------------------------------IBM BIDI-------------------------------------- // Mamdouh : Modifiaction of the caret to work with Bidi in the LTR and RTL -#include "nsIPref.h" #include "nsLayoutAtoms.h" //------------------------------END OF IBM BIDI-------------------------------- #endif //IBMBIDI diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index d722ff0c360..2aed821beb5 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -37,7 +37,9 @@ #include "nsCOMPtr.h" #include "nsPresContext.h" #include "nsIPresShell.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranchInternal.h" +#include "nsISupportsPrimitives.h" #include "nsILinkHandler.h" #include "nsIDocShellTreeItem.h" #include "nsIStyleSet.h" @@ -95,18 +97,6 @@ MakeColorPref(const char *colstr) return colorref; } -int PR_CALLBACK -nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data) -{ - nsPresContext* presContext = (nsPresContext*)instance_data; - - NS_ASSERTION(nsnull != presContext, "bad instance data"); - if (nsnull != presContext) { - presContext->PreferenceChanged(aPrefName); - } - return 0; // PREF_OK -} - #ifdef IBMBIDI PRBool IsVisualCharset(const nsAutoString& aCharset) @@ -223,23 +213,22 @@ nsPresContext::~nsPresContext() if (mEventManager) mEventManager->SetPresContext(nsnull); // unclear if this is needed, but can't hurt - // Unregister preference callbacks - if (mPrefs) { - 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); + // Unregister preference observers + nsCOMPtr prefInternal(do_QueryInterface(mPrefBranch)); + if (prefInternal) { + prefInternal->RemoveObserver("browser.anchor_color", this); + prefInternal->RemoveObserver("browser.display.", this); + prefInternal->RemoveObserver("browser.underline_anchors", this); + prefInternal->RemoveObserver("browser.visited_color", this); + prefInternal->RemoveObserver("font.", this); + prefInternal->RemoveObserver("image.animation_mode", this); + prefInternal->RemoveObserver("network.image.imageBehavior", this); #ifdef IBMBIDI - mPrefs->UnregisterCallback("bidi.", PrefChangedCallback, (void*)this); + prefInternal->RemoveObserver("bidi.", this); #endif } #ifdef IBMBIDI - if (mBidiUtils) { - delete mBidiUtils; - } + delete mBidiUtils; #endif // IBMBIDI } @@ -262,7 +251,7 @@ static const char* const kGenericFont[] = { void nsPresContext::GetFontPreferences() { - if (!mPrefs || !mLanguage) + if (!mPrefBranch || !mLanguage) return; /* Fetch the font prefs to be used -- see bug 61883 for details. @@ -292,13 +281,12 @@ nsPresContext::GetFontPreferences() 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)); + nsresult rv = mPrefBranch->GetCharPref("font.size.unit", getter_Copies(cvalue)); if (NS_SUCCEEDED(rv)) { if (!PL_strcmp(cvalue.get(), "px")) { unit = eUnit_px; @@ -314,8 +302,9 @@ nsPresContext::GetFontPreferences() // get font.minimum-size.[langGroup] PRInt32 size; - pref.Assign("font.minimum-size."); pref.Append(NS_ConvertUCS2toUTF8(langGroup)); - rv = mPrefs->GetIntPref(pref.get(), &size); + pref.Assign("font.minimum-size."); + pref.Append(NS_ConvertUCS2toUTF8(langGroup)); + rv = mPrefBranch->GetIntPref(pref.get(), &size); if (NS_SUCCEEDED(rv)) { if (unit == eUnit_px) { mMinimumFontSize = NSFloatPixelsToTwips((float)size, p2t); @@ -331,7 +320,7 @@ nsPresContext::GetFontPreferences() generic_dot_langGroup.Assign(kGenericFont[eType]); generic_dot_langGroup.Append(NS_ConvertUCS2toUTF8(langGroup)); - nsFont* font; + nsFont* font = nsnull; switch (eType) { case eDefaultFont_Variable: font = &mDefaultVariableFont; break; case eDefaultFont_Fixed: font = &mDefaultFixedFont; break; @@ -347,14 +336,19 @@ nsPresContext::GetFontPreferences() // 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); + nsCOMPtr prefString; + mPrefBranch->GetComplexValue(pref.get(), + NS_GET_IID(nsISupportsString), + getter_AddRefs(prefString)); + if (prefString) { + prefString->GetData(font->name); } else { - rv = mPrefs->CopyUnicharPref("font.default", getter_Copies(value)); - if (NS_SUCCEEDED(rv)) { - mDefaultVariableFont.name.Assign(value); + mPrefBranch->GetComplexValue("font.default", + NS_GET_IID(nsISupportsString), + getter_AddRefs(prefString)); + if (prefString) { + prefString->GetData(mDefaultVariableFont.name); } } } @@ -381,7 +375,7 @@ nsPresContext::GetFontPreferences() // 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); - rv = mPrefs->GetIntPref(pref.get(), &size); + rv = mPrefBranch->GetIntPref(pref.get(), &size); if (NS_SUCCEEDED(rv) && size > 0) { if (unit == eUnit_px) { font->size = NSFloatPixelsToTwips((float)size, p2t); @@ -394,7 +388,7 @@ nsPresContext::GetFontPreferences() // 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)); + rv = mPrefBranch->GetCharPref(pref.get(), getter_Copies(cvalue)); if (NS_SUCCEEDED(rv)) { font->sizeAdjust = (float)atof(cvalue.get()); } @@ -421,15 +415,15 @@ nsPresContext::GetDocumentColorPreferences() usePrefColors = PR_FALSE; } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_system_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_system_colors", &boolPref))) { usePrefColors = !boolPref; } } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { mDefaultColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.background_color", getter_Copies(colorStr)))) { + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.background_color", getter_Copies(colorStr)))) { mDefaultBackgroundColor = MakeColorPref(colorStr); } } @@ -445,7 +439,7 @@ nsPresContext::GetDocumentColorPreferences() } } - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_document_colors", &boolPref))) { mUseDocumentColors = boolPref; } } @@ -453,13 +447,13 @@ nsPresContext::GetDocumentColorPreferences() void nsPresContext::GetUserPreferences() { - PRInt32 prefInt; + PRInt32 prefInt = 0; - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.base_font_scaler", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.base_font_scaler", &prefInt))) { mFontScaler = prefInt; } - if (NS_SUCCEEDED(mPrefs->GetIntPref("nglayout.widget.mode", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("nglayout.widget.mode", &prefInt))) { mWidgetRenderingMode = (enum nsWidgetRendering)prefInt; // bad cast } @@ -468,78 +462,75 @@ nsPresContext::GetUserPreferences() // * link colors PRBool boolPref; - nsXPIDLCString colorStr; - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.underline_anchors", &boolPref))) { + nsXPIDLCString stringPref; + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.underline_anchors", &boolPref))) { mUnderlineLinks = boolPref; } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.anchor_color", getter_Copies(colorStr)))) { - mLinkColor = MakeColorPref(colorStr); + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.anchor_color", getter_Copies(stringPref)))) { + mLinkColor = MakeColorPref(stringPref); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.visited_color", getter_Copies(colorStr)))) { - mVisitedLinkColor = MakeColorPref(colorStr); + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.visited_color", getter_Copies(stringPref)))) { + mVisitedLinkColor = MakeColorPref(stringPref); } - - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { mUseFocusColors = boolPref; mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mDefaultBackgroundColor; - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_text_color", getter_Copies(colorStr)))) { - mFocusTextColor = MakeColorPref(colorStr); + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.focus_text_color", getter_Copies(stringPref)))) { + mFocusTextColor = MakeColorPref(stringPref); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_background_color", getter_Copies(colorStr)))) { - mFocusBackgroundColor = MakeColorPref(colorStr); + if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.focus_background_color", getter_Copies(stringPref)))) { + mFocusBackgroundColor = MakeColorPref(stringPref); } } - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_ring_width", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.focus_ring_width", &prefInt))) { mFocusRingWidth = prefInt; } - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { + if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { mFocusRingOnAnything = boolPref; } // * use fonts? - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.use_document_fonts", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.use_document_fonts", &prefInt))) { mUseDocumentFonts = prefInt == 0 ? PR_FALSE : PR_TRUE; } GetFontPreferences(); // * image animation - char* animatePref = 0; - nsresult rv = mPrefs->CopyCharPref("image.animation_mode", &animatePref); - if (NS_SUCCEEDED(rv) && animatePref) { - if (!nsCRT::strcmp(animatePref, "normal")) + nsresult rv = mPrefBranch->GetCharPref("image.animation_mode", getter_Copies(stringPref)); + if (NS_SUCCEEDED(rv)) { + if (stringPref.Equals("normal")) mImageAnimationModePref = imgIContainer::kNormalAnimMode; - else if (!nsCRT::strcmp(animatePref, "none")) + else if (stringPref.Equals("none")) mImageAnimationModePref = imgIContainer::kDontAnimMode; - else if (!nsCRT::strcmp(animatePref, "once")) + else if (stringPref.Equals("once")) mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode; - nsMemory::Free(animatePref); } #ifdef IBMBIDI - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.direction", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.direction", &prefInt))) { SET_BIDI_OPTION_DIRECTION(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.texttype", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.texttype", &prefInt))) { SET_BIDI_OPTION_TEXTTYPE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.controlstextmode", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.controlstextmode", &prefInt))) { SET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.clipboardtextmode", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.clipboardtextmode", &prefInt))) { SET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.numeral", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.numeral", &prefInt))) { SET_BIDI_OPTION_NUMERAL(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.support", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.support", &prefInt))) { SET_BIDI_OPTION_SUPPORT(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.characterset", &prefInt))) { + if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.characterset", &prefInt))) { SET_BIDI_OPTION_CHARACTERSET(mBidi, prefInt); } #endif @@ -634,18 +625,19 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) mDeviceContext = dont_QueryInterface(aDeviceContext); mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); - mPrefs = do_GetService(NS_PREF_CONTRACTID); - if (mPrefs) { - // Register callbacks so we're notified when the preferences change - 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); + mPrefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefInternal(do_QueryInterface(mPrefBranch)); + if (prefInternal) { + // Register observers so we're notified when the preferences change + prefInternal->AddObserver("browser.anchor_color", this, PR_FALSE); + prefInternal->AddObserver("browser.display.", this, PR_FALSE); + prefInternal->AddObserver("browser.underline_anchors", this, PR_FALSE); + prefInternal->AddObserver("browser.visited_color", this, PR_FALSE); + prefInternal->AddObserver("font.", this, PR_FALSE); + prefInternal->AddObserver("image.animation_mode", this, PR_FALSE); + prefInternal->AddObserver("network.image.imageBehavior", this, PR_FALSE); #ifdef IBMBIDI - mPrefs->RegisterCallback("bidi.", PrefChangedCallback, (void*)this); + prefInternal->AddObserver("bidi.", this, PR_FALSE); #endif // Initialize our state from the user preferences @@ -751,6 +743,11 @@ nsPresContext::Observe(nsISupports* aSubject, return NS_OK; } + if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { + PreferenceChanged(NS_LossyConvertUCS2toASCII(aData).get()); + return NS_OK; + } + NS_WARNING("unrecognized topic in nsPresContext::Observe"); return NS_ERROR_FAILURE; } diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index e7067458a6d..ef588fb8910 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -43,7 +43,7 @@ #include "nsFont.h" #include "nsCRT.h" #include "nsCOMPtr.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" #include "nsICharsetConverterManager.h" #include "nsILanguageAtomService.h" #include "nsIURL.h" @@ -206,7 +206,7 @@ protected: // class, please make the ownership explicit (pinkerton, scc). nsIPresShell* mShell; // [WEAK] - nsCOMPtr mPrefs; + nsCOMPtr mPrefBranch; nsRect mVisibleArea; nsCOMPtr mDeviceContext; // could be weak, but better safe than sorry. Cannot reintroduce cycles // since there is no dependency from gfx back to layout. @@ -289,7 +289,6 @@ protected: void SetImgAnimations(nsCOMPtr& aParent, PRUint16 aMode); private: - static int PR_CALLBACK PrefChangedCallback(const char*, void*); void PreferenceChanged(const char* aPrefName); // these are private, use the list in nsFont.h if you want a public list diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 582c6857297..0fd6cc16f01 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -88,7 +88,8 @@ #include "nsIPercentHeightObserver.h" // For triple-click pref -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsISelectionImageService.h" #include "imgIContainer.h" @@ -98,7 +99,6 @@ #include "nsWidgetsCID.h" // for NS_LOOKANDFEEL_CID #include "nsLayoutErrors.h" -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);//for triple click pref static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID); static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); @@ -1527,9 +1527,9 @@ nsFrame::HandleMultiplePress(nsIPresContext* aPresContext, selectPara = PR_TRUE; else if (me->clickCount == 3) { - nsCOMPtr prefsService( do_GetService(kPrefCID, &rv) ); - if (NS_SUCCEEDED(rv) && prefsService) - prefsService->GetBoolPref("browser.triple_click_selects_paragraph", &selectPara); + nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); + if (prefBranch) + prefBranch->GetBoolPref("browser.triple_click_selects_paragraph", &selectPara); } else return NS_OK; diff --git a/mozilla/layout/generic/nsFrameFrame.cpp b/mozilla/layout/generic/nsFrameFrame.cpp index 431ebedb76b..2ef7af1b850 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -68,7 +68,6 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIDocumentLoader.h" -#include "nsIPref.h" #include "nsFrameSetFrame.h" #include "nsIDOMHTMLFrameElement.h" #include "nsIDOMHTMLIFrameElement.h" diff --git a/mozilla/layout/generic/nsHTMLReflowState.cpp b/mozilla/layout/generic/nsHTMLReflowState.cpp index ddd25c9a8aa..7fb5b3fbaef 100644 --- a/mozilla/layout/generic/nsHTMLReflowState.cpp +++ b/mozilla/layout/generic/nsHTMLReflowState.cpp @@ -48,7 +48,10 @@ #include "nsBlockFrame.h" #include "nsLineBox.h" #include "nsImageFrame.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsIPrefBranchInternal.h" +#include "nsIObserver.h" #include "nsIServiceManager.h" #include "nsIPercentHeightObserver.h" #ifdef IBMBIDI @@ -1625,44 +1628,81 @@ nsHTMLReflowState::ComputeContainingBlockRectangle(nsIPresContext* aPre } } -// Prefs callback to pick up changes -static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance) +class BlinkPrefObserver : public nsIObserver { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - PRBool boolPref; - if (NS_SUCCEEDED(prefs->GetBoolPref("browser.blink_allowed", &boolPref))) - sBlinkIsAllowed = boolPref; - } - return 0; /* PREF_OK */ +public: + BlinkPrefObserver(); + virtual ~BlinkPrefObserver(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER +}; + +BlinkPrefObserver::BlinkPrefObserver() +{ + NS_INIT_ISUPPORTS(); +} + +BlinkPrefObserver::~BlinkPrefObserver() +{ +} + +NS_IMPL_ISUPPORTS1(BlinkPrefObserver, nsIObserver) + +NS_IMETHODIMP +BlinkPrefObserver::Observe(nsISupports *aSubject, const char *aTopic, + const PRUnichar *aData) +{ + NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID), + "We only handle pref changes"); + NS_ASSERTION(nsDependentString(aData) == + NS_LITERAL_STRING("browser.blink_allowed"), + "We only handle the blink pref"); + + nsCOMPtr prefBranch(do_QueryInterface(aSubject)); + PRBool boolPrefValue = PR_TRUE; + prefBranch->GetBoolPref("browser.blink_allowed", &boolPrefValue); + sBlinkIsAllowed = boolPrefValue; + + return NS_OK; } // Check to see if |text-decoration: blink| is allowed. The first time -// called, register the callback and then force-load the pref. After that, +// called, register the observer and then force-load the pref. After that, // just use the cached value. -static PRBool BlinkIsAllowed(void) +static +PRBool BlinkIsAllowed() { if (!sPrefIsLoaded) { - // Set up a listener and check the initial value - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - prefs->RegisterCallback("browser.blink_allowed", PrefsChanged, - nsnull); + // Set up an observer and check the initial value + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) { + PRBool boolPrefValue = PR_TRUE; + prefBranch->GetBoolPref("browser.blink_allowed", &boolPrefValue); + sBlinkIsAllowed = boolPrefValue; + + nsCOMPtr observer = new BlinkPrefObserver(); + if (observer) { + nsCOMPtr pbi = do_QueryInterface(prefBranch); + if (pbi) { + pbi->AddObserver("browser.blink_allowed", observer, PR_FALSE); + } + } } - PrefsChanged(nsnull, nsnull); sPrefIsLoaded = PR_TRUE; } + return sBlinkIsAllowed; } static eNormalLineHeightControl GetNormalLineHeightCalcControl(void) { if (sNormalLineHeightControl == eUninitialized) { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); PRInt32 intPref; // browser.display.normal_lineheight_calc_control is not user changable, so // no need to register callback for it. - if (prefs && NS_SUCCEEDED(prefs->GetIntPref( + if (prefBranch && NS_SUCCEEDED(prefBranch->GetIntPref( "browser.display.normal_lineheight_calc_control", &intPref))) sNormalLineHeightControl = NS_STATIC_CAST(eNormalLineHeightControl, intPref); else diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index d5676bf04f6..ab4da5e6da2 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -94,7 +94,8 @@ #include "nsIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsCSSFrameConstructor.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #ifdef DEBUG #undef NOISY_IMAGE_LOADING @@ -2270,21 +2271,21 @@ void nsImageFrame::IconLoad::GetPrefs(nsIPresContext *aPresContext) NS_ASSERTION(aPresContext, "null presContext is not allowed in GetAltModePref"); // NOTE: the presContext could be used to fetch a cached pref if needed, but is not for now - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) { PRBool boolPref; PRInt32 intPref; - if (NS_SUCCEEDED(prefs->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { + if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { mPrefForceInlineAltText = boolPref; } else { mPrefForceInlineAltText = PR_FALSE; } - if (NS_SUCCEEDED(prefs->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { + if (NS_SUCCEEDED(prefBranch->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { mPrefAllImagesBlocked = PR_TRUE; } else { mPrefAllImagesBlocked = PR_FALSE; } - if (NS_SUCCEEDED(prefs->GetBoolPref("browser.display.show_image_placeholders", &boolPref))) { + if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.show_image_placeholders", &boolPref))) { mPrefShowPlaceholders = boolPref; } else { mPrefShowPlaceholders = PR_TRUE; diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index adaa5fd239e..7a85c7373c4 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -114,7 +114,10 @@ #include "jsapi.h" // XXX temporary for Mac double buffering pref -#include "nsIPref.h" +#if defined(XP_MAC) || defined(XP_MACOSX) +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" +#endif // XXX For temporary paint code #include "nsIStyleContext.h" @@ -139,9 +142,6 @@ #include "nsContentCID.h" static NS_DEFINE_CID(kRangeCID, NS_RANGE_CID); -// XXX temporary for Mac double buffering pref -static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); - /* X headers suck */ #ifdef KeyPress #undef KeyPress @@ -797,10 +797,12 @@ nsObjectFrame::CreateWidget(nsIPresContext* aPresContext, // Turn off double buffering on the Mac. This depends on bug 49743 and partially // fixes 32327, 19931 amd 51787 #if defined(XP_MAC) || defined(XP_MACOSX) - nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); PRBool doubleBuffer = PR_FALSE; - prefs ? prefs->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer) : 0; - + if (prefBranch) { + prefBranch->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer); + } + viewMan->AllowDoubleBuffering(doubleBuffer); #endif diff --git a/mozilla/layout/generic/nsSimplePageSequence.cpp b/mozilla/layout/generic/nsSimplePageSequence.cpp index 83ce4f27dfe..cf95132a6ad 100644 --- a/mozilla/layout/generic/nsSimplePageSequence.cpp +++ b/mozilla/layout/generic/nsSimplePageSequence.cpp @@ -54,7 +54,9 @@ #include "nsRegion.h" #include "nsLayoutAtoms.h" -#include "nsIPref.h" // for header/footer gap & ExtraMargin for Print Preview +// for header/footer gap & ExtraMargin for Print Preview +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" // DateTime Includes #include "nsDateTimeFormatCID.h" @@ -216,23 +218,30 @@ nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsIPresContext* aPresContex return rv; } -void nsSimplePageSequenceFrame::GetEdgePaperMarginCoord(nsIPref* aPref, char* aPrefName, nscoord& aCoord) +void +nsSimplePageSequenceFrame::GetEdgePaperMarginCoord(char* aPrefName, + nscoord& aCoord) { - if (NS_SUCCEEDED(mPageData->mPrintOptions->GetPrinterPrefInt(mPageData->mPrintSettings, - NS_ConvertASCIItoUCS2(aPrefName).get(), &aCoord))) { + nsresult rv = mPageData->mPrintOptions-> + GetPrinterPrefInt(mPageData->mPrintSettings, + NS_ConvertASCIItoUCS2(aPrefName).get(), + &aCoord); + + if (NS_SUCCEEDED(rv)) { nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.0); aCoord = PR_MAX(NS_INCHES_TO_TWIPS(float(aCoord)/100.0f), 0); aCoord = PR_MIN(aCoord, inchInTwips); // an inch is still probably excessive } } -void nsSimplePageSequenceFrame::GetEdgePaperMargin(nsIPref* aPref, nsMargin& aMargin) +void +nsSimplePageSequenceFrame::GetEdgePaperMargin(nsMargin& aMargin) { aMargin.SizeTo(0,0,0,0); - GetEdgePaperMarginCoord(aPref, "print_edge_top", aMargin.top); - GetEdgePaperMarginCoord(aPref, "print_edge_left", aMargin.left); - GetEdgePaperMarginCoord(aPref, "print_edge_bottom", aMargin.bottom); - GetEdgePaperMarginCoord(aPref, "print_edge_right", aMargin.right); + GetEdgePaperMarginCoord("print_edge_top", aMargin.top); + GetEdgePaperMarginCoord("print_edge_left", aMargin.left); + GetEdgePaperMarginCoord("print_edge_bottom", aMargin.bottom); + GetEdgePaperMarginCoord("print_edge_right", aMargin.right); } NS_IMETHODIMP @@ -309,12 +318,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, aPresContext->GetPageDim(&pageSize, &adjSize); nscoord extraGap = 0; - nsCOMPtr pref = do_GetService(NS_PREF_CONTRACTID); - if (pref) { - GetEdgePaperMargin(pref, mPageData->mEdgePaperMargin); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) { + GetEdgePaperMargin(mPageData->mEdgePaperMargin); nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10; PRInt32 gapInTwips; - if (NS_SUCCEEDED(pref->GetIntPref("print.print_extra_margin", &gapInTwips))) { + if (NS_SUCCEEDED(prefBranch->GetIntPref("print.print_extra_margin", &gapInTwips))) { gapInTwips = PR_MAX(gapInTwips, 0); gapInTwips = PR_MIN(gapInTwips, extraThreshold); // clamp to 1/10 of the largest dim of the page extraGap = nscoord(gapInTwips); diff --git a/mozilla/layout/generic/nsSimplePageSequence.h b/mozilla/layout/generic/nsSimplePageSequence.h index e6552b374c2..5a160efe046 100644 --- a/mozilla/layout/generic/nsSimplePageSequence.h +++ b/mozilla/layout/generic/nsSimplePageSequence.h @@ -153,8 +153,8 @@ protected: void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly); void SetPageSizes(const nsRect& aRect, const nsMargin& aMarginRect); - void GetEdgePaperMarginCoord(nsIPref* aPref, char* aPrefName, nscoord& aCoord); - void GetEdgePaperMargin(nsIPref* aPref, nsMargin& aMargin); + void GetEdgePaperMarginCoord(char* aPrefName, nscoord& aCoord); + void GetEdgePaperMargin(nsMargin& aMargin); NS_IMETHOD_(nsrefcnt) AddRef(void) {return nsContainerFrame::AddRef();} NS_IMETHOD_(nsrefcnt) Release(void) {return nsContainerFrame::Release();} diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 6fc88fdce51..06fa0b57368 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -82,7 +82,8 @@ #include "nsILineIterator.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIServiceManager.h" #ifdef ACCESSIBILITY #include "nsIAccessible.h" @@ -104,8 +105,6 @@ #include "nsILE.h" #endif /* SUNCTL */ -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); - #ifdef NS_DEBUG #undef NOISY_BLINK #undef DEBUG_WORD_WRAPPING @@ -1362,10 +1361,10 @@ nsTextFrame::nsTextFrame() { // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); - if ( prefService ) { + nsCOMPtr prefBranch ( do_GetService(NS_PREFSERVICE_CONTRACTID) ); + if ( prefBranch ) { PRBool temp = PR_FALSE; - prefService->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); + prefBranch->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); sWordSelectEatSpaceAfter = temp; } sWordSelectPrefInited = PR_TRUE; @@ -2623,12 +2622,12 @@ nsTextFrame::GetPositionSlowly(nsIPresContext* aPresContext, ComputeExtraJustificationSpacing(*aRendContext, ts, paintBuffer.mBuffer, textLength, numSpaces); //IF STYLE SAYS TO SELECT TO END OF FRAME HERE... - nsCOMPtr prefs( do_GetService(kPrefCID, &rv) ); + nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); PRInt32 prefInt = 0; PRBool outofstylehandled = PR_FALSE; - if (NS_SUCCEEDED(rv) && prefs) + if (prefBranch) { - if (NS_SUCCEEDED(prefs->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) { if (aPoint.y < origin.y)//above rectangle { @@ -3506,12 +3505,12 @@ nsTextFrame::GetPosition(nsIPresContext* aCX, GetOffsetFromView(aCX, origin, &view); //IF STYLE SAYS TO SELECT TO END OF FRAME HERE... - nsCOMPtr prefs( do_GetService(kPrefCID, &rv) ); + nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); PRInt32 prefInt = 0; PRBool outofstylehandled = PR_FALSE; - if (NS_SUCCEEDED(rv) && prefs) + if (prefBranch) { - if (NS_SUCCEEDED(prefs->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) { if ((aPoint.y - origin.y) < 0)//above rectangle { diff --git a/mozilla/layout/generic/nsTextTransformer.cpp b/mozilla/layout/generic/nsTextTransformer.cpp index 23d9db35345..c5c498f525c 100644 --- a/mozilla/layout/generic/nsTextTransformer.cpp +++ b/mozilla/layout/generic/nsTextTransformer.cpp @@ -49,7 +49,8 @@ #include "nsUnicharUtils.h" #include "nsICaseConversion.h" #include "prenv.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #ifdef IBMBIDI #include "nsLayoutAtoms.h" #endif @@ -114,10 +115,11 @@ nsTextTransformer::Initialize() // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); - if ( prefService ) { + nsCOMPtr prefBranch = + do_GetService( NS_PREFSERVICE_CONTRACTID ); + if ( prefBranch ) { PRBool temp = PR_FALSE; - prefService->GetBoolPref("layout.word_select.stop_at_punctuation", &temp); + prefBranch->GetBoolPref("layout.word_select.stop_at_punctuation", &temp); sWordSelectStopAtPunctuation = temp; } sWordSelectPrefInited = PR_TRUE; diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index 582c6857297..0fd6cc16f01 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -88,7 +88,8 @@ #include "nsIPercentHeightObserver.h" // For triple-click pref -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsISelectionImageService.h" #include "imgIContainer.h" @@ -98,7 +99,6 @@ #include "nsWidgetsCID.h" // for NS_LOOKANDFEEL_CID #include "nsLayoutErrors.h" -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);//for triple click pref static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID); static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); @@ -1527,9 +1527,9 @@ nsFrame::HandleMultiplePress(nsIPresContext* aPresContext, selectPara = PR_TRUE; else if (me->clickCount == 3) { - nsCOMPtr prefsService( do_GetService(kPrefCID, &rv) ); - if (NS_SUCCEEDED(rv) && prefsService) - prefsService->GetBoolPref("browser.triple_click_selects_paragraph", &selectPara); + nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); + if (prefBranch) + prefBranch->GetBoolPref("browser.triple_click_selects_paragraph", &selectPara); } else return NS_OK; diff --git a/mozilla/layout/html/base/src/nsHTMLReflowState.cpp b/mozilla/layout/html/base/src/nsHTMLReflowState.cpp index ddd25c9a8aa..7fb5b3fbaef 100644 --- a/mozilla/layout/html/base/src/nsHTMLReflowState.cpp +++ b/mozilla/layout/html/base/src/nsHTMLReflowState.cpp @@ -48,7 +48,10 @@ #include "nsBlockFrame.h" #include "nsLineBox.h" #include "nsImageFrame.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsIPrefBranchInternal.h" +#include "nsIObserver.h" #include "nsIServiceManager.h" #include "nsIPercentHeightObserver.h" #ifdef IBMBIDI @@ -1625,44 +1628,81 @@ nsHTMLReflowState::ComputeContainingBlockRectangle(nsIPresContext* aPre } } -// Prefs callback to pick up changes -static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance) +class BlinkPrefObserver : public nsIObserver { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - PRBool boolPref; - if (NS_SUCCEEDED(prefs->GetBoolPref("browser.blink_allowed", &boolPref))) - sBlinkIsAllowed = boolPref; - } - return 0; /* PREF_OK */ +public: + BlinkPrefObserver(); + virtual ~BlinkPrefObserver(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER +}; + +BlinkPrefObserver::BlinkPrefObserver() +{ + NS_INIT_ISUPPORTS(); +} + +BlinkPrefObserver::~BlinkPrefObserver() +{ +} + +NS_IMPL_ISUPPORTS1(BlinkPrefObserver, nsIObserver) + +NS_IMETHODIMP +BlinkPrefObserver::Observe(nsISupports *aSubject, const char *aTopic, + const PRUnichar *aData) +{ + NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID), + "We only handle pref changes"); + NS_ASSERTION(nsDependentString(aData) == + NS_LITERAL_STRING("browser.blink_allowed"), + "We only handle the blink pref"); + + nsCOMPtr prefBranch(do_QueryInterface(aSubject)); + PRBool boolPrefValue = PR_TRUE; + prefBranch->GetBoolPref("browser.blink_allowed", &boolPrefValue); + sBlinkIsAllowed = boolPrefValue; + + return NS_OK; } // Check to see if |text-decoration: blink| is allowed. The first time -// called, register the callback and then force-load the pref. After that, +// called, register the observer and then force-load the pref. After that, // just use the cached value. -static PRBool BlinkIsAllowed(void) +static +PRBool BlinkIsAllowed() { if (!sPrefIsLoaded) { - // Set up a listener and check the initial value - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - prefs->RegisterCallback("browser.blink_allowed", PrefsChanged, - nsnull); + // Set up an observer and check the initial value + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) { + PRBool boolPrefValue = PR_TRUE; + prefBranch->GetBoolPref("browser.blink_allowed", &boolPrefValue); + sBlinkIsAllowed = boolPrefValue; + + nsCOMPtr observer = new BlinkPrefObserver(); + if (observer) { + nsCOMPtr pbi = do_QueryInterface(prefBranch); + if (pbi) { + pbi->AddObserver("browser.blink_allowed", observer, PR_FALSE); + } + } } - PrefsChanged(nsnull, nsnull); sPrefIsLoaded = PR_TRUE; } + return sBlinkIsAllowed; } static eNormalLineHeightControl GetNormalLineHeightCalcControl(void) { if (sNormalLineHeightControl == eUninitialized) { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); PRInt32 intPref; // browser.display.normal_lineheight_calc_control is not user changable, so // no need to register callback for it. - if (prefs && NS_SUCCEEDED(prefs->GetIntPref( + if (prefBranch && NS_SUCCEEDED(prefBranch->GetIntPref( "browser.display.normal_lineheight_calc_control", &intPref))) sNormalLineHeightControl = NS_STATIC_CAST(eNormalLineHeightControl, intPref); else diff --git a/mozilla/layout/html/base/src/nsImageFrame.cpp b/mozilla/layout/html/base/src/nsImageFrame.cpp index d5676bf04f6..ab4da5e6da2 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -94,7 +94,8 @@ #include "nsIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsCSSFrameConstructor.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #ifdef DEBUG #undef NOISY_IMAGE_LOADING @@ -2270,21 +2271,21 @@ void nsImageFrame::IconLoad::GetPrefs(nsIPresContext *aPresContext) NS_ASSERTION(aPresContext, "null presContext is not allowed in GetAltModePref"); // NOTE: the presContext could be used to fetch a cached pref if needed, but is not for now - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) { PRBool boolPref; PRInt32 intPref; - if (NS_SUCCEEDED(prefs->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { + if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { mPrefForceInlineAltText = boolPref; } else { mPrefForceInlineAltText = PR_FALSE; } - if (NS_SUCCEEDED(prefs->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { + if (NS_SUCCEEDED(prefBranch->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { mPrefAllImagesBlocked = PR_TRUE; } else { mPrefAllImagesBlocked = PR_FALSE; } - if (NS_SUCCEEDED(prefs->GetBoolPref("browser.display.show_image_placeholders", &boolPref))) { + if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.show_image_placeholders", &boolPref))) { mPrefShowPlaceholders = boolPref; } else { mPrefShowPlaceholders = PR_TRUE; diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index adaa5fd239e..7a85c7373c4 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -114,7 +114,10 @@ #include "jsapi.h" // XXX temporary for Mac double buffering pref -#include "nsIPref.h" +#if defined(XP_MAC) || defined(XP_MACOSX) +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" +#endif // XXX For temporary paint code #include "nsIStyleContext.h" @@ -139,9 +142,6 @@ #include "nsContentCID.h" static NS_DEFINE_CID(kRangeCID, NS_RANGE_CID); -// XXX temporary for Mac double buffering pref -static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); - /* X headers suck */ #ifdef KeyPress #undef KeyPress @@ -797,10 +797,12 @@ nsObjectFrame::CreateWidget(nsIPresContext* aPresContext, // Turn off double buffering on the Mac. This depends on bug 49743 and partially // fixes 32327, 19931 amd 51787 #if defined(XP_MAC) || defined(XP_MACOSX) - nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); PRBool doubleBuffer = PR_FALSE; - prefs ? prefs->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer) : 0; - + if (prefBranch) { + prefBranch->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer); + } + viewMan->AllowDoubleBuffering(doubleBuffer); #endif diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 32d85633b9f..c22e8fd2d19 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -57,7 +57,8 @@ #include "prinrval.h" #include "nsVoidArray.h" #include "nsHashtable.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIViewObserver.h" #include "nsContainerFrame.h" #include "nsIDeviceContext.h" @@ -197,7 +198,6 @@ static nsresult CtlStyleWatch(PRUint32 aCtlValue, nsIStyleSet *aStyleSet); static NS_DEFINE_CID(kFrameSelectionCID, NS_FRAMESELECTION_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); -static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); #undef NOISY @@ -1694,10 +1694,11 @@ PresShell::Init(nsIDocument* aDocument, gAsyncReflowDuringDocLoad = PR_TRUE; // Get the prefs service - nsCOMPtr prefs(do_GetService(kPrefServiceCID, &result)); - if (NS_SUCCEEDED(result)) { - prefs->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime); - prefs->GetBoolPref("layout.reflow.async.duringDocLoad", &gAsyncReflowDuringDocLoad); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { + prefBranch->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime); + prefBranch->GetBoolPref("layout.reflow.async.duringDocLoad", + &gAsyncReflowDuringDocLoad); } } @@ -1716,16 +1717,19 @@ PresShell::Init(nsIDocument* aDocument, #endif #ifdef MOZ_REFLOW_PERF - // Get the prefs service - nsCOMPtr prefs(do_GetService(kPrefServiceCID, &result)); - if (NS_SUCCEEDED(result)) { - if (mReflowCountMgr != nsnull) { + if (mReflowCountMgr) { + // Get the prefs service + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { PRBool paintFrameCounts = PR_FALSE; PRBool dumpFrameCounts = PR_FALSE; PRBool dumpFrameByFrameCounts = PR_FALSE; - prefs->GetBoolPref("layout.reflow.showframecounts", &paintFrameCounts); - prefs->GetBoolPref("layout.reflow.dumpframecounts", &dumpFrameCounts); - prefs->GetBoolPref("layout.reflow.dumpframebyframecounts", &dumpFrameByFrameCounts); + prefBranch->GetBoolPref("layout.reflow.showframecounts", + &paintFrameCounts); + prefBranch->GetBoolPref("layout.reflow.dumpframecounts", + &dumpFrameCounts); + prefBranch->GetBoolPref("layout.reflow.dumpframebyframecounts", + &dumpFrameByFrameCounts); mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); @@ -2854,9 +2858,9 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) else { // Initialize the timer. PRInt32 delay = PAINTLOCK_EVENT_DELAY; // Use this value if we fail to get the pref value. - nsCOMPtr prefs(do_GetService(kPrefServiceCID)); - if (prefs) - prefs->GetIntPref("nglayout.initialpaint.delay", &delay); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) + prefBranch->GetIntPref("nglayout.initialpaint.delay", &delay); nsCOMPtr ti = do_QueryInterface(mPaintSuppressionTimer); ti->SetIdle(PR_FALSE); @@ -4004,9 +4008,9 @@ PresShell::GoToAnchor(const nsAString& aAnchorName) // Should we select the target? // This action is controlled by a preference: the default is to not select. PRBool selectAnchor = PR_FALSE; - nsCOMPtr prefs(do_GetService(kPrefServiceCID,&rv)); - if (NS_SUCCEEDED(rv) && prefs) { - prefs->GetBoolPref("layout.selectanchor",&selectAnchor); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { + prefBranch->GetBoolPref("layout.selectanchor", &selectAnchor); } // Even if select anchor pref is false, we must still move the caret there. // That way tabbing will start from the new location diff --git a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp index 83ce4f27dfe..cf95132a6ad 100644 --- a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp +++ b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp @@ -54,7 +54,9 @@ #include "nsRegion.h" #include "nsLayoutAtoms.h" -#include "nsIPref.h" // for header/footer gap & ExtraMargin for Print Preview +// for header/footer gap & ExtraMargin for Print Preview +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" // DateTime Includes #include "nsDateTimeFormatCID.h" @@ -216,23 +218,30 @@ nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsIPresContext* aPresContex return rv; } -void nsSimplePageSequenceFrame::GetEdgePaperMarginCoord(nsIPref* aPref, char* aPrefName, nscoord& aCoord) +void +nsSimplePageSequenceFrame::GetEdgePaperMarginCoord(char* aPrefName, + nscoord& aCoord) { - if (NS_SUCCEEDED(mPageData->mPrintOptions->GetPrinterPrefInt(mPageData->mPrintSettings, - NS_ConvertASCIItoUCS2(aPrefName).get(), &aCoord))) { + nsresult rv = mPageData->mPrintOptions-> + GetPrinterPrefInt(mPageData->mPrintSettings, + NS_ConvertASCIItoUCS2(aPrefName).get(), + &aCoord); + + if (NS_SUCCEEDED(rv)) { nscoord inchInTwips = NS_INCHES_TO_TWIPS(1.0); aCoord = PR_MAX(NS_INCHES_TO_TWIPS(float(aCoord)/100.0f), 0); aCoord = PR_MIN(aCoord, inchInTwips); // an inch is still probably excessive } } -void nsSimplePageSequenceFrame::GetEdgePaperMargin(nsIPref* aPref, nsMargin& aMargin) +void +nsSimplePageSequenceFrame::GetEdgePaperMargin(nsMargin& aMargin) { aMargin.SizeTo(0,0,0,0); - GetEdgePaperMarginCoord(aPref, "print_edge_top", aMargin.top); - GetEdgePaperMarginCoord(aPref, "print_edge_left", aMargin.left); - GetEdgePaperMarginCoord(aPref, "print_edge_bottom", aMargin.bottom); - GetEdgePaperMarginCoord(aPref, "print_edge_right", aMargin.right); + GetEdgePaperMarginCoord("print_edge_top", aMargin.top); + GetEdgePaperMarginCoord("print_edge_left", aMargin.left); + GetEdgePaperMarginCoord("print_edge_bottom", aMargin.bottom); + GetEdgePaperMarginCoord("print_edge_right", aMargin.right); } NS_IMETHODIMP @@ -309,12 +318,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, aPresContext->GetPageDim(&pageSize, &adjSize); nscoord extraGap = 0; - nsCOMPtr pref = do_GetService(NS_PREF_CONTRACTID); - if (pref) { - GetEdgePaperMargin(pref, mPageData->mEdgePaperMargin); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) { + GetEdgePaperMargin(mPageData->mEdgePaperMargin); nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10; PRInt32 gapInTwips; - if (NS_SUCCEEDED(pref->GetIntPref("print.print_extra_margin", &gapInTwips))) { + if (NS_SUCCEEDED(prefBranch->GetIntPref("print.print_extra_margin", &gapInTwips))) { gapInTwips = PR_MAX(gapInTwips, 0); gapInTwips = PR_MIN(gapInTwips, extraThreshold); // clamp to 1/10 of the largest dim of the page extraGap = nscoord(gapInTwips); diff --git a/mozilla/layout/html/base/src/nsSimplePageSequence.h b/mozilla/layout/html/base/src/nsSimplePageSequence.h index e6552b374c2..5a160efe046 100644 --- a/mozilla/layout/html/base/src/nsSimplePageSequence.h +++ b/mozilla/layout/html/base/src/nsSimplePageSequence.h @@ -153,8 +153,8 @@ protected: void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly); void SetPageSizes(const nsRect& aRect, const nsMargin& aMarginRect); - void GetEdgePaperMarginCoord(nsIPref* aPref, char* aPrefName, nscoord& aCoord); - void GetEdgePaperMargin(nsIPref* aPref, nsMargin& aMargin); + void GetEdgePaperMarginCoord(char* aPrefName, nscoord& aCoord); + void GetEdgePaperMargin(nsMargin& aMargin); NS_IMETHOD_(nsrefcnt) AddRef(void) {return nsContainerFrame::AddRef();} NS_IMETHOD_(nsrefcnt) Release(void) {return nsContainerFrame::Release();} diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 6fc88fdce51..06fa0b57368 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -82,7 +82,8 @@ #include "nsILineIterator.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIServiceManager.h" #ifdef ACCESSIBILITY #include "nsIAccessible.h" @@ -104,8 +105,6 @@ #include "nsILE.h" #endif /* SUNCTL */ -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); - #ifdef NS_DEBUG #undef NOISY_BLINK #undef DEBUG_WORD_WRAPPING @@ -1362,10 +1361,10 @@ nsTextFrame::nsTextFrame() { // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); - if ( prefService ) { + nsCOMPtr prefBranch ( do_GetService(NS_PREFSERVICE_CONTRACTID) ); + if ( prefBranch ) { PRBool temp = PR_FALSE; - prefService->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); + prefBranch->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); sWordSelectEatSpaceAfter = temp; } sWordSelectPrefInited = PR_TRUE; @@ -2623,12 +2622,12 @@ nsTextFrame::GetPositionSlowly(nsIPresContext* aPresContext, ComputeExtraJustificationSpacing(*aRendContext, ts, paintBuffer.mBuffer, textLength, numSpaces); //IF STYLE SAYS TO SELECT TO END OF FRAME HERE... - nsCOMPtr prefs( do_GetService(kPrefCID, &rv) ); + nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); PRInt32 prefInt = 0; PRBool outofstylehandled = PR_FALSE; - if (NS_SUCCEEDED(rv) && prefs) + if (prefBranch) { - if (NS_SUCCEEDED(prefs->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) { if (aPoint.y < origin.y)//above rectangle { @@ -3506,12 +3505,12 @@ nsTextFrame::GetPosition(nsIPresContext* aCX, GetOffsetFromView(aCX, origin, &view); //IF STYLE SAYS TO SELECT TO END OF FRAME HERE... - nsCOMPtr prefs( do_GetService(kPrefCID, &rv) ); + nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); PRInt32 prefInt = 0; PRBool outofstylehandled = PR_FALSE; - if (NS_SUCCEEDED(rv) && prefs) + if (prefBranch) { - if (NS_SUCCEEDED(prefs->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) { if ((aPoint.y - origin.y) < 0)//above rectangle { diff --git a/mozilla/layout/html/base/src/nsTextTransformer.cpp b/mozilla/layout/html/base/src/nsTextTransformer.cpp index 23d9db35345..c5c498f525c 100644 --- a/mozilla/layout/html/base/src/nsTextTransformer.cpp +++ b/mozilla/layout/html/base/src/nsTextTransformer.cpp @@ -49,7 +49,8 @@ #include "nsUnicharUtils.h" #include "nsICaseConversion.h" #include "prenv.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #ifdef IBMBIDI #include "nsLayoutAtoms.h" #endif @@ -114,10 +115,11 @@ nsTextTransformer::Initialize() // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); - if ( prefService ) { + nsCOMPtr prefBranch = + do_GetService( NS_PREFSERVICE_CONTRACTID ); + if ( prefBranch ) { PRBool temp = PR_FALSE; - prefService->GetBoolPref("layout.word_select.stop_at_punctuation", &temp); + prefBranch->GetBoolPref("layout.word_select.stop_at_punctuation", &temp); sWordSelectStopAtPunctuation = temp; } sWordSelectPrefInited = PR_TRUE; diff --git a/mozilla/layout/html/document/src/nsFrameFrame.cpp b/mozilla/layout/html/document/src/nsFrameFrame.cpp index 431ebedb76b..2ef7af1b850 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -68,7 +68,6 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIDocumentLoader.h" -#include "nsIPref.h" #include "nsFrameSetFrame.h" #include "nsIDOMHTMLFrameElement.h" #include "nsIDOMHTMLIFrameElement.h" diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index 0b643df7bf8..8f8ed7ed399 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -93,7 +93,8 @@ #include "nsIAnonymousContentCreator.h" #include "nsIFrameManager.h" #include "nsIAttributeContent.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsLegendFrame.h" #include "nsIContentIterator.h" #include "nsBoxLayoutState.h" @@ -4231,10 +4232,10 @@ nsCSSFrameConstructor::HasGfxScrollbars() #endif // Get the Prefs if (!mGotGfxPrefs) { - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); - if (pref) { + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { PRBool hasGfxScroll = PR_FALSE; // use a temp since we have a PRPackedBool - pref->GetBoolPref("nglayout.widget.gfxscrollbars", &hasGfxScroll); + prefBranch->GetBoolPref("nglayout.widget.gfxscrollbars", &hasGfxScroll); mHasGfxScrollbars = hasGfxScroll; mGotGfxPrefs = PR_TRUE; } else { @@ -4251,10 +4252,10 @@ PRBool nsCSSFrameConstructor::UseXBLForms() { if (!mGotXBLFormPrefs) { - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); - if (pref) { + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { PRBool useXBLForms = PR_FALSE; // use a temp since we have a PRPackedBool - pref->GetBoolPref("nglayout.debug.enable_xbl_forms", &useXBLForms); + prefBranch->GetBoolPref("nglayout.debug.enable_xbl_forms", &useXBLForms); mUseXBLForms = useXBLForms; mGotXBLFormPrefs = PR_TRUE; } diff --git a/mozilla/layout/svg/base/src/nsSVGGraphic.cpp b/mozilla/layout/svg/base/src/nsSVGGraphic.cpp index 5f5243ebc40..7d0fc208af1 100644 --- a/mozilla/layout/svg/base/src/nsSVGGraphic.cpp +++ b/mozilla/layout/svg/base/src/nsSVGGraphic.cpp @@ -44,7 +44,8 @@ #include "nsASVGGraphicSource.h" #include "nsStyleStruct.h" #include "nsIServiceManager.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "prdtoa.h" nsSVGGraphic::nsSVGGraphic() @@ -239,14 +240,12 @@ double nsSVGGraphic::GetBezierFlatness() double flatness = 0.5; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - if (!prefs) return flatness; + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (!prefBranch) return flatness; - // XXX: wouldn't it be great if nsIPref had a 'GetFloatPref()'-function? - char *valuestr = nsnull; - if (NS_SUCCEEDED(prefs->CopyCharPref("svg.bezier_flatness",&valuestr)) && (valuestr)) { + nsXPIDLCString valuestr; + if (NS_SUCCEEDED(prefBranch->GetCharPref("svg.bezier_flatness", getter_Copies(valuestr)))) { flatness = PR_strtod(valuestr, nsnull); - nsMemory::Free(valuestr); } return flatness; diff --git a/mozilla/layout/svg/base/src/nsSVGStroke.cpp b/mozilla/layout/svg/base/src/nsSVGStroke.cpp index f4c50de69cc..924e39059da 100644 --- a/mozilla/layout/svg/base/src/nsSVGStroke.cpp +++ b/mozilla/layout/svg/base/src/nsSVGStroke.cpp @@ -39,7 +39,8 @@ #include "nsSVGStroke.h" #include "nsCOMPtr.h" #include "nsIServiceManager.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "prdtoa.h" #include "nsMemory.h" #include "nsReadableUtils.h" @@ -141,14 +142,12 @@ double nsSVGStroke::getFlatness() { double flatness = 0.5; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - if (!prefs) return flatness; + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (!prefBranch) return flatness; - // XXX: wouldn't it be great if nsIPref had a 'GetFloatPref()'-function? - char *valuestr = nsnull; - if (NS_SUCCEEDED(prefs->CopyCharPref("svg.stroke_flatness",&valuestr)) && (valuestr)) { + nsXPIDLCString valuestr; + if (NS_SUCCEEDED(prefBranch->GetCharPref("svg.stroke_flatness", getter_Copies(valuestr)))) { flatness = PR_strtod(valuestr, nsnull); - nsMemory::Free(valuestr); } return flatness; } diff --git a/mozilla/layout/xul/base/src/nsBoxFrame.cpp b/mozilla/layout/xul/base/src/nsBoxFrame.cpp index 5ebd8938573..19ba7438062 100644 --- a/mozilla/layout/xul/base/src/nsBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsBoxFrame.cpp @@ -80,7 +80,8 @@ #include "nsIPresShell.h" #include "nsFrameNavigator.h" #include "nsCSSRendering.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsBoxToBlockAdaptor.h" #include "nsIBoxLayout.h" @@ -1440,9 +1441,9 @@ void nsBoxFrame::GetDebugPref(nsIPresContext* aPresContext) { gDebug = PR_FALSE; - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); - if (pref) { - pref->GetBoolPref("xul.debug.box", &gDebug); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { + prefBranch->GetBoolPref("xul.debug.box", &gDebug); } } diff --git a/mozilla/layout/xul/base/src/nsBoxToBlockAdaptor.cpp b/mozilla/layout/xul/base/src/nsBoxToBlockAdaptor.cpp index 7a19e49aba3..4e0dd43a002 100644 --- a/mozilla/layout/xul/base/src/nsBoxToBlockAdaptor.cpp +++ b/mozilla/layout/xul/base/src/nsBoxToBlockAdaptor.cpp @@ -58,7 +58,6 @@ #include "nsIPresShell.h" #include "nsFrameNavigator.h" #include "nsCSSRendering.h" -#include "nsIPref.h" #include "nsIServiceManager.h" #include "nsBoxToBlockAdaptor.h" #include "nsILineIterator.h" diff --git a/mozilla/layout/xul/base/src/nsContainerBox.cpp b/mozilla/layout/xul/base/src/nsContainerBox.cpp index a1ac108575b..49fd9db13ba 100644 --- a/mozilla/layout/xul/base/src/nsContainerBox.cpp +++ b/mozilla/layout/xul/base/src/nsContainerBox.cpp @@ -71,7 +71,6 @@ #include "nsIPresShell.h" #include "nsFrameNavigator.h" #include "nsCSSRendering.h" -#include "nsIPref.h" #include "nsIServiceManager.h" #include "nsContainerBox.h" diff --git a/mozilla/layout/xul/base/src/nsMenuBarListener.cpp b/mozilla/layout/xul/base/src/nsMenuBarListener.cpp index 40e40d4431a..09ef7998cc9 100644 --- a/mozilla/layout/xul/base/src/nsMenuBarListener.cpp +++ b/mozilla/layout/xul/base/src/nsMenuBarListener.cpp @@ -65,7 +65,8 @@ #include "nsIView.h" #include "nsISupportsArray.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" /* * nsMenuBarListener implementation @@ -117,20 +118,17 @@ void nsMenuBarListener::InitAccessKey() #endif // Get the menu access key value from prefs, overriding the default: - nsresult rv; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && prefs) + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { - rv = prefs->GetIntPref("ui.key.menuAccessKey", &mAccessKey); - rv |= prefs->GetBoolPref("ui.key.menuAccessKeyFocuses", - &mAccessKeyFocuses); - } + nsresult rv = prefBranch->GetIntPref("ui.key.menuAccessKey", &mAccessKey); + rv |= prefBranch->GetBoolPref("ui.key.menuAccessKeyFocuses", + &mAccessKeyFocuses); #ifdef DEBUG_akkana - if (NS_FAILED(rv) || !prefs) - { - NS_ASSERTION(PR_FALSE,"Menubar listener couldn't get accel key from prefs!\n"); - } + NS_ASSERTION(NS_SUCCEEDED(rv) && prefBranch, + "Menubar listener couldn't get accel key from prefs!\n"); #endif + } } //////////////////////////////////////////////////////////////////////// diff --git a/mozilla/layout/xul/base/src/nsMenuFrame.cpp b/mozilla/layout/xul/base/src/nsMenuFrame.cpp index 8fd69116919..48aecefeea1 100644 --- a/mozilla/layout/xul/base/src/nsMenuFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuFrame.cpp @@ -76,7 +76,8 @@ #include "nsIXBLService.h" #include "nsCSSFrameConstructor.h" #include "nsIDOMKeyEvent.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIScrollableView.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" @@ -1555,10 +1556,9 @@ nsMenuFrame::BuildAcceleratorText() #endif // Get the accelerator key value from prefs, overriding the default: - nsresult rv; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && prefs) - rv = prefs->GetIntPref("ui.key.accelKey", &accelKey); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) + prefBranch->GetIntPref("ui.key.accelKey", &accelKey); } nsAutoString modifiers; diff --git a/mozilla/layout/xul/base/src/nsSliderFrame.cpp b/mozilla/layout/xul/base/src/nsSliderFrame.cpp index a3b05192cf9..6fdc5009f5a 100644 --- a/mozilla/layout/xul/base/src/nsSliderFrame.cpp +++ b/mozilla/layout/xul/base/src/nsSliderFrame.cpp @@ -74,15 +74,14 @@ #include "nsRepeatService.h" #include "nsBoxLayoutState.h" #include "nsSprocketLayout.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsGUIEvent.h" // Turn this on if you want to debug slider frames. #undef DEBUG_SLIDER -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); - nsresult NS_NewSliderFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame) { @@ -119,13 +118,12 @@ nsSliderFrame::Init(nsIPresContext* aPresContext, { nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); - nsresult rv2; - mMiddlePref=PR_FALSE; + mMiddlePref = PR_FALSE; mSnapMultiplier = 6; - nsCOMPtr pref = do_GetService(kPrefCID, &rv2); - if(NS_SUCCEEDED(rv2)) { - pref->GetBoolPref("middlemouse.scrollbarPosition", &mMiddlePref); - pref->GetIntPref("slider.snapMultiplier", &mSnapMultiplier); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) { + prefBranch->GetBoolPref("middlemouse.scrollbarPosition", &mMiddlePref); + prefBranch->GetIntPref("slider.snapMultiplier", &mSnapMultiplier); } CreateViewForFrame(aPresContext,this,aContext,PR_TRUE); diff --git a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp index 84f9fea4479..4a34e815b9e 100644 --- a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp @@ -58,7 +58,9 @@ #include "nsINameSpaceManager.h" #include "nsBoxLayoutState.h" #include "nsMenuBarListener.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" +#include "nsIPrefLocalizedString.h" #include "nsXPIDLString.h" #include "nsIServiceManager.h" #include "nsIDocument.h" @@ -197,18 +199,22 @@ nsTextBoxFrame::AlwaysAppendAccessKey() { if (!gAccessKeyPrefInitialized) { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); + nsCOMPtr prefBranch = + do_GetService(NS_PREFSERVICE_CONTRACTID); + gAccessKeyPrefInitialized = PR_TRUE; - if (prefs) + if (prefBranch) { - nsXPIDLString prefValue; - nsresult res = prefs->GetLocalizedUnicharPref( - "intl.menuitems.alwaysappendacceskeys", - getter_Copies(prefValue)); - if (NS_SUCCEEDED(res)) + nsCOMPtr prefValue; + prefBranch->GetComplexValue("intl.menuitems.alwaysappendacceskeys", + NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(prefValue)); + if (prefBranch) { - gAlwaysAppendAccessKey = nsDependentString(prefValue).Equals( - NS_LITERAL_STRING("true")); + nsXPIDLString prefString; + prefValue->ToString(getter_Copies(prefString)); + gAlwaysAppendAccessKey = + nsDependentString(prefString).Equals(NS_LITERAL_STRING("true")); } } } diff --git a/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp b/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp index 1e870f46512..00d58b3e9aa 100644 --- a/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp +++ b/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp @@ -46,7 +46,9 @@ #include "nsIPresShell.h" #include "nsIFrame.h" #include "nsIPopupBoxObject.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefBranchInternal.h" +#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsITreeView.h" #include "nsGUIEvent.h" @@ -79,11 +81,10 @@ nsXULTooltipListener::~nsXULTooltipListener() { HideTooltip(); - // unregister the prefs callback - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - if (prefs) { - prefs->UnregisterCallback("browser.chrome.toolbar_tips", - (PrefChangedFunc)sTooltipPrefChanged, (void*)this); + nsCOMPtr prefInternal(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefInternal) { + // Unregister our pref observer + prefInternal->RemoveObserver("browser.chrome.toolbar_tips", this); } } @@ -95,6 +96,7 @@ NS_INTERFACE_MAP_BEGIN(nsXULTooltipListener) NS_INTERFACE_MAP_ENTRY(nsIDOMMouseMotionListener) NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener) NS_INTERFACE_MAP_ENTRY(nsIDOMXULListener) + NS_INTERFACE_MAP_ENTRY(nsIObserver) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMMouseListener) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMouseMotionListener) NS_INTERFACE_MAP_END @@ -236,6 +238,26 @@ nsXULTooltipListener::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } +////////////////////////////////////////////////////////////////////////// +//// nsIObserver + +NS_IMETHODIMP +nsXULTooltipListener::Observe(nsISupports* aSubject, + const char* aTopic, + const PRUnichar* aData) +{ + if (nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { + NS_ERROR("unknown nsIObserver topic!"); + return NS_ERROR_UNEXPECTED; + } + + nsCOMPtr prefBranch(do_QueryInterface(aSubject)); + NS_ASSERTION(prefBranch, "Pref change topic with no pref subject?"); + prefBranch->GetBoolPref("browser.chrome.toolbar_tips", &sShowTooltips); + + return NS_OK; +} + ////////////////////////////////////////////////////////////////////////// //// nsXULTooltipListener @@ -268,13 +290,14 @@ nsXULTooltipListener::Init(nsIContent* aSourceNode, nsIRootBox* aRootBox) // Only the first time, register the callback and get the initial value of the pref if (!prefChangeRegistered) { - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - if (prefs) { + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { // get the initial value of the pref - nsresult rv = prefs->GetBoolPref("browser.chrome.toolbar_tips", &sShowTooltips); + nsresult rv = prefBranch->GetBoolPref("browser.chrome.toolbar_tips", &sShowTooltips); if (NS_SUCCEEDED(rv)) { // register the callback so we get notified of updates - rv = prefs->RegisterCallback("browser.chrome.toolbar_tips", (PrefChangedFunc)sTooltipPrefChanged, nsnull); + nsCOMPtr prefInternal(do_QueryInterface(prefBranch)); + rv = prefInternal->AddObserver("browser.chrome.toolbar_tips", this, PR_FALSE); if (NS_SUCCEEDED(rv)) prefChangeRegistered = PR_TRUE; } @@ -674,16 +697,6 @@ nsXULTooltipListener::sAutoHideCallback(nsITimer *aTimer, void* aListener) self->HideTooltip(); } -int -nsXULTooltipListener::sTooltipPrefChanged(const char* aPref, void* aData) -{ - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - if (prefs) - prefs->GetBoolPref("browser.chrome.toolbar_tips", &sShowTooltips); - - return NS_OK; -} - nsresult nsXULTooltipListener::GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject) { diff --git a/mozilla/layout/xul/base/src/nsXULTooltipListener.h b/mozilla/layout/xul/base/src/nsXULTooltipListener.h index e26d38b9303..c33712aa6be 100644 --- a/mozilla/layout/xul/base/src/nsXULTooltipListener.h +++ b/mozilla/layout/xul/base/src/nsXULTooltipListener.h @@ -43,6 +43,7 @@ #include "nsIDOMKeyListener.h" #include "nsIDOMMouseEvent.h" #include "nsIDOMXULListener.h" +#include "nsIObserver.h" #include "nsIContent.h" #include "nsIDOMElement.h" #include "nsITimer.h" @@ -54,7 +55,8 @@ class nsXULTooltipListener : public nsIDOMMouseListener, public nsIDOMMouseMotionListener, public nsIDOMKeyListener, - public nsIDOMXULListener + public nsIDOMXULListener, + public nsIObserver { public: @@ -94,6 +96,8 @@ public: // nsIDOMEventListener NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); + NS_DECL_NSIOBSERVER + nsresult Init(nsIContent* aSourceNode, nsIRootBox* aRootBox); nsresult SetDefaultTooltip(nsIContent* aDefaultTooltip); nsresult GetDefaultTooltip(nsIContent** aDefaultTooltip);