diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 8f8ed7ed399..0b643df7bf8 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -93,8 +93,7 @@ #include "nsIAnonymousContentCreator.h" #include "nsIFrameManager.h" #include "nsIAttributeContent.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #include "nsLegendFrame.h" #include "nsIContentIterator.h" #include "nsBoxLayoutState.h" @@ -4232,10 +4231,10 @@ nsCSSFrameConstructor::HasGfxScrollbars() #endif // Get the Prefs if (!mGotGfxPrefs) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { + nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); + if (pref) { PRBool hasGfxScroll = PR_FALSE; // use a temp since we have a PRPackedBool - prefBranch->GetBoolPref("nglayout.widget.gfxscrollbars", &hasGfxScroll); + pref->GetBoolPref("nglayout.widget.gfxscrollbars", &hasGfxScroll); mHasGfxScrollbars = hasGfxScroll; mGotGfxPrefs = PR_TRUE; } else { @@ -4252,10 +4251,10 @@ PRBool nsCSSFrameConstructor::UseXBLForms() { if (!mGotXBLFormPrefs) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { + nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); + if (pref) { PRBool useXBLForms = PR_FALSE; // use a temp since we have a PRPackedBool - prefBranch->GetBoolPref("nglayout.debug.enable_xbl_forms", &useXBLForms); + pref->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 557c7acc988..ed1d70c72f8 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -75,6 +75,7 @@ #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 2aed821beb5..d722ff0c360 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -37,9 +37,7 @@ #include "nsCOMPtr.h" #include "nsPresContext.h" #include "nsIPresShell.h" -#include "nsIPrefService.h" -#include "nsIPrefBranchInternal.h" -#include "nsISupportsPrimitives.h" +#include "nsIPref.h" #include "nsILinkHandler.h" #include "nsIDocShellTreeItem.h" #include "nsIStyleSet.h" @@ -97,6 +95,18 @@ 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) @@ -213,22 +223,23 @@ nsPresContext::~nsPresContext() if (mEventManager) mEventManager->SetPresContext(nsnull); // unclear if this is needed, but can't hurt - // 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); + // 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); #ifdef IBMBIDI - prefInternal->RemoveObserver("bidi.", this); + mPrefs->UnregisterCallback("bidi.", PrefChangedCallback, (void*)this); #endif } #ifdef IBMBIDI - delete mBidiUtils; + if (mBidiUtils) { + delete mBidiUtils; + } #endif // IBMBIDI } @@ -251,7 +262,7 @@ static const char* const kGenericFont[] = { void nsPresContext::GetFontPreferences() { - if (!mPrefBranch || !mLanguage) + if (!mPrefs || !mLanguage) return; /* Fetch the font prefs to be used -- see bug 61883 for details. @@ -281,12 +292,13 @@ 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 = mPrefBranch->GetCharPref("font.size.unit", getter_Copies(cvalue)); + nsresult rv = mPrefs->CopyCharPref("font.size.unit", getter_Copies(cvalue)); if (NS_SUCCEEDED(rv)) { if (!PL_strcmp(cvalue.get(), "px")) { unit = eUnit_px; @@ -302,9 +314,8 @@ nsPresContext::GetFontPreferences() // get font.minimum-size.[langGroup] PRInt32 size; - pref.Assign("font.minimum-size."); - pref.Append(NS_ConvertUCS2toUTF8(langGroup)); - rv = mPrefBranch->GetIntPref(pref.get(), &size); + pref.Assign("font.minimum-size."); pref.Append(NS_ConvertUCS2toUTF8(langGroup)); + rv = mPrefs->GetIntPref(pref.get(), &size); if (NS_SUCCEEDED(rv)) { if (unit == eUnit_px) { mMinimumFontSize = NSFloatPixelsToTwips((float)size, p2t); @@ -320,7 +331,7 @@ nsPresContext::GetFontPreferences() generic_dot_langGroup.Assign(kGenericFont[eType]); generic_dot_langGroup.Append(NS_ConvertUCS2toUTF8(langGroup)); - nsFont* font = nsnull; + nsFont* font; switch (eType) { case eDefaultFont_Variable: font = &mDefaultVariableFont; break; case eDefaultFont_Fixed: font = &mDefaultFixedFont; break; @@ -336,19 +347,14 @@ 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); - nsCOMPtr prefString; - mPrefBranch->GetComplexValue(pref.get(), - NS_GET_IID(nsISupportsString), - getter_AddRefs(prefString)); - if (prefString) { - prefString->GetData(font->name); + rv = mPrefs->CopyUnicharPref(pref.get(), getter_Copies(value)); + if (NS_SUCCEEDED(rv)) { + font->name.Assign(value); } else { - mPrefBranch->GetComplexValue("font.default", - NS_GET_IID(nsISupportsString), - getter_AddRefs(prefString)); - if (prefString) { - prefString->GetData(mDefaultVariableFont.name); + rv = mPrefs->CopyUnicharPref("font.default", getter_Copies(value)); + if (NS_SUCCEEDED(rv)) { + mDefaultVariableFont.name.Assign(value); } } } @@ -375,7 +381,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 = mPrefBranch->GetIntPref(pref.get(), &size); + rv = mPrefs->GetIntPref(pref.get(), &size); if (NS_SUCCEEDED(rv) && size > 0) { if (unit == eUnit_px) { font->size = NSFloatPixelsToTwips((float)size, p2t); @@ -388,7 +394,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 = mPrefBranch->GetCharPref(pref.get(), getter_Copies(cvalue)); + rv = mPrefs->CopyCharPref(pref.get(), getter_Copies(cvalue)); if (NS_SUCCEEDED(rv)) { font->sizeAdjust = (float)atof(cvalue.get()); } @@ -415,15 +421,15 @@ nsPresContext::GetDocumentColorPreferences() usePrefColors = PR_FALSE; } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_system_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_system_colors", &boolPref))) { usePrefColors = !boolPref; } } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { mDefaultColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.background_color", getter_Copies(colorStr)))) { + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.background_color", getter_Copies(colorStr)))) { mDefaultBackgroundColor = MakeColorPref(colorStr); } } @@ -439,7 +445,7 @@ nsPresContext::GetDocumentColorPreferences() } } - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_document_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref))) { mUseDocumentColors = boolPref; } } @@ -447,13 +453,13 @@ nsPresContext::GetDocumentColorPreferences() void nsPresContext::GetUserPreferences() { - PRInt32 prefInt = 0; + PRInt32 prefInt; - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.base_font_scaler", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.base_font_scaler", &prefInt))) { mFontScaler = prefInt; } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("nglayout.widget.mode", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("nglayout.widget.mode", &prefInt))) { mWidgetRenderingMode = (enum nsWidgetRendering)prefInt; // bad cast } @@ -462,75 +468,78 @@ nsPresContext::GetUserPreferences() // * link colors PRBool boolPref; - nsXPIDLCString stringPref; - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.underline_anchors", &boolPref))) { + nsXPIDLCString colorStr; + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.underline_anchors", &boolPref))) { mUnderlineLinks = boolPref; } - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.anchor_color", getter_Copies(stringPref)))) { - mLinkColor = MakeColorPref(stringPref); + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.anchor_color", getter_Copies(colorStr)))) { + mLinkColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.visited_color", getter_Copies(stringPref)))) { - mVisitedLinkColor = MakeColorPref(stringPref); + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.visited_color", getter_Copies(colorStr)))) { + mVisitedLinkColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { + + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { mUseFocusColors = boolPref; mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mDefaultBackgroundColor; - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.focus_text_color", getter_Copies(stringPref)))) { - mFocusTextColor = MakeColorPref(stringPref); + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_text_color", getter_Copies(colorStr)))) { + mFocusTextColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.focus_background_color", getter_Copies(stringPref)))) { - mFocusBackgroundColor = MakeColorPref(stringPref); + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_background_color", getter_Copies(colorStr)))) { + mFocusBackgroundColor = MakeColorPref(colorStr); } } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.focus_ring_width", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_ring_width", &prefInt))) { mFocusRingWidth = prefInt; } - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { mFocusRingOnAnything = boolPref; } // * use fonts? - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.use_document_fonts", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.use_document_fonts", &prefInt))) { mUseDocumentFonts = prefInt == 0 ? PR_FALSE : PR_TRUE; } GetFontPreferences(); // * image animation - nsresult rv = mPrefBranch->GetCharPref("image.animation_mode", getter_Copies(stringPref)); - if (NS_SUCCEEDED(rv)) { - if (stringPref.Equals("normal")) + char* animatePref = 0; + nsresult rv = mPrefs->CopyCharPref("image.animation_mode", &animatePref); + if (NS_SUCCEEDED(rv) && animatePref) { + if (!nsCRT::strcmp(animatePref, "normal")) mImageAnimationModePref = imgIContainer::kNormalAnimMode; - else if (stringPref.Equals("none")) + else if (!nsCRT::strcmp(animatePref, "none")) mImageAnimationModePref = imgIContainer::kDontAnimMode; - else if (stringPref.Equals("once")) + else if (!nsCRT::strcmp(animatePref, "once")) mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode; + nsMemory::Free(animatePref); } #ifdef IBMBIDI - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.direction", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.direction", &prefInt))) { SET_BIDI_OPTION_DIRECTION(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.texttype", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.texttype", &prefInt))) { SET_BIDI_OPTION_TEXTTYPE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.controlstextmode", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.controlstextmode", &prefInt))) { SET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.clipboardtextmode", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.clipboardtextmode", &prefInt))) { SET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.numeral", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.numeral", &prefInt))) { SET_BIDI_OPTION_NUMERAL(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.support", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.support", &prefInt))) { SET_BIDI_OPTION_SUPPORT(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.characterset", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.characterset", &prefInt))) { SET_BIDI_OPTION_CHARACTERSET(mBidi, prefInt); } #endif @@ -625,19 +634,18 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) mDeviceContext = dont_QueryInterface(aDeviceContext); mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); - 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); + 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); #ifdef IBMBIDI - prefInternal->AddObserver("bidi.", this, PR_FALSE); + mPrefs->RegisterCallback("bidi.", PrefChangedCallback, (void*)this); #endif // Initialize our state from the user preferences @@ -743,11 +751,6 @@ 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 31b58d858d3..55224b37a4c 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -60,6 +60,7 @@ 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 c22e8fd2d19..32d85633b9f 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -57,8 +57,7 @@ #include "prinrval.h" #include "nsVoidArray.h" #include "nsHashtable.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #include "nsIViewObserver.h" #include "nsContainerFrame.h" #include "nsIDeviceContext.h" @@ -198,6 +197,7 @@ 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,11 +1694,10 @@ PresShell::Init(nsIDocument* aDocument, gAsyncReflowDuringDocLoad = PR_TRUE; // Get the prefs service - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime); - prefBranch->GetBoolPref("layout.reflow.async.duringDocLoad", - &gAsyncReflowDuringDocLoad); + nsCOMPtr prefs(do_GetService(kPrefServiceCID, &result)); + if (NS_SUCCEEDED(result)) { + prefs->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime); + prefs->GetBoolPref("layout.reflow.async.duringDocLoad", &gAsyncReflowDuringDocLoad); } } @@ -1717,19 +1716,16 @@ PresShell::Init(nsIDocument* aDocument, #endif #ifdef MOZ_REFLOW_PERF - if (mReflowCountMgr) { - // Get the prefs service - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { + // Get the prefs service + nsCOMPtr prefs(do_GetService(kPrefServiceCID, &result)); + if (NS_SUCCEEDED(result)) { + if (mReflowCountMgr != nsnull) { PRBool paintFrameCounts = PR_FALSE; PRBool dumpFrameCounts = PR_FALSE; PRBool dumpFrameByFrameCounts = PR_FALSE; - prefBranch->GetBoolPref("layout.reflow.showframecounts", - &paintFrameCounts); - prefBranch->GetBoolPref("layout.reflow.dumpframecounts", - &dumpFrameCounts); - prefBranch->GetBoolPref("layout.reflow.dumpframebyframecounts", - &dumpFrameByFrameCounts); + prefs->GetBoolPref("layout.reflow.showframecounts", &paintFrameCounts); + prefs->GetBoolPref("layout.reflow.dumpframecounts", &dumpFrameCounts); + prefs->GetBoolPref("layout.reflow.dumpframebyframecounts", &dumpFrameByFrameCounts); mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); @@ -2858,9 +2854,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 prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) - prefBranch->GetIntPref("nglayout.initialpaint.delay", &delay); + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + if (prefs) + prefs->GetIntPref("nglayout.initialpaint.delay", &delay); nsCOMPtr ti = do_QueryInterface(mPaintSuppressionTimer); ti->SetIdle(PR_FALSE); @@ -4008,9 +4004,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 prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("layout.selectanchor", &selectAnchor); + nsCOMPtr prefs(do_GetService(kPrefServiceCID,&rv)); + if (NS_SUCCEEDED(rv) && prefs) { + prefs->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 31b58d858d3..55224b37a4c 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -60,6 +60,7 @@ 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 31b58d858d3..55224b37a4c 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -60,6 +60,7 @@ 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 557c7acc988..ed1d70c72f8 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -75,6 +75,7 @@ #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 2aed821beb5..d722ff0c360 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -37,9 +37,7 @@ #include "nsCOMPtr.h" #include "nsPresContext.h" #include "nsIPresShell.h" -#include "nsIPrefService.h" -#include "nsIPrefBranchInternal.h" -#include "nsISupportsPrimitives.h" +#include "nsIPref.h" #include "nsILinkHandler.h" #include "nsIDocShellTreeItem.h" #include "nsIStyleSet.h" @@ -97,6 +95,18 @@ 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) @@ -213,22 +223,23 @@ nsPresContext::~nsPresContext() if (mEventManager) mEventManager->SetPresContext(nsnull); // unclear if this is needed, but can't hurt - // 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); + // 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); #ifdef IBMBIDI - prefInternal->RemoveObserver("bidi.", this); + mPrefs->UnregisterCallback("bidi.", PrefChangedCallback, (void*)this); #endif } #ifdef IBMBIDI - delete mBidiUtils; + if (mBidiUtils) { + delete mBidiUtils; + } #endif // IBMBIDI } @@ -251,7 +262,7 @@ static const char* const kGenericFont[] = { void nsPresContext::GetFontPreferences() { - if (!mPrefBranch || !mLanguage) + if (!mPrefs || !mLanguage) return; /* Fetch the font prefs to be used -- see bug 61883 for details. @@ -281,12 +292,13 @@ 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 = mPrefBranch->GetCharPref("font.size.unit", getter_Copies(cvalue)); + nsresult rv = mPrefs->CopyCharPref("font.size.unit", getter_Copies(cvalue)); if (NS_SUCCEEDED(rv)) { if (!PL_strcmp(cvalue.get(), "px")) { unit = eUnit_px; @@ -302,9 +314,8 @@ nsPresContext::GetFontPreferences() // get font.minimum-size.[langGroup] PRInt32 size; - pref.Assign("font.minimum-size."); - pref.Append(NS_ConvertUCS2toUTF8(langGroup)); - rv = mPrefBranch->GetIntPref(pref.get(), &size); + pref.Assign("font.minimum-size."); pref.Append(NS_ConvertUCS2toUTF8(langGroup)); + rv = mPrefs->GetIntPref(pref.get(), &size); if (NS_SUCCEEDED(rv)) { if (unit == eUnit_px) { mMinimumFontSize = NSFloatPixelsToTwips((float)size, p2t); @@ -320,7 +331,7 @@ nsPresContext::GetFontPreferences() generic_dot_langGroup.Assign(kGenericFont[eType]); generic_dot_langGroup.Append(NS_ConvertUCS2toUTF8(langGroup)); - nsFont* font = nsnull; + nsFont* font; switch (eType) { case eDefaultFont_Variable: font = &mDefaultVariableFont; break; case eDefaultFont_Fixed: font = &mDefaultFixedFont; break; @@ -336,19 +347,14 @@ 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); - nsCOMPtr prefString; - mPrefBranch->GetComplexValue(pref.get(), - NS_GET_IID(nsISupportsString), - getter_AddRefs(prefString)); - if (prefString) { - prefString->GetData(font->name); + rv = mPrefs->CopyUnicharPref(pref.get(), getter_Copies(value)); + if (NS_SUCCEEDED(rv)) { + font->name.Assign(value); } else { - mPrefBranch->GetComplexValue("font.default", - NS_GET_IID(nsISupportsString), - getter_AddRefs(prefString)); - if (prefString) { - prefString->GetData(mDefaultVariableFont.name); + rv = mPrefs->CopyUnicharPref("font.default", getter_Copies(value)); + if (NS_SUCCEEDED(rv)) { + mDefaultVariableFont.name.Assign(value); } } } @@ -375,7 +381,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 = mPrefBranch->GetIntPref(pref.get(), &size); + rv = mPrefs->GetIntPref(pref.get(), &size); if (NS_SUCCEEDED(rv) && size > 0) { if (unit == eUnit_px) { font->size = NSFloatPixelsToTwips((float)size, p2t); @@ -388,7 +394,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 = mPrefBranch->GetCharPref(pref.get(), getter_Copies(cvalue)); + rv = mPrefs->CopyCharPref(pref.get(), getter_Copies(cvalue)); if (NS_SUCCEEDED(rv)) { font->sizeAdjust = (float)atof(cvalue.get()); } @@ -415,15 +421,15 @@ nsPresContext::GetDocumentColorPreferences() usePrefColors = PR_FALSE; } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_system_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_system_colors", &boolPref))) { usePrefColors = !boolPref; } } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { mDefaultColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.background_color", getter_Copies(colorStr)))) { + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.background_color", getter_Copies(colorStr)))) { mDefaultBackgroundColor = MakeColorPref(colorStr); } } @@ -439,7 +445,7 @@ nsPresContext::GetDocumentColorPreferences() } } - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_document_colors", &boolPref))) { + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref))) { mUseDocumentColors = boolPref; } } @@ -447,13 +453,13 @@ nsPresContext::GetDocumentColorPreferences() void nsPresContext::GetUserPreferences() { - PRInt32 prefInt = 0; + PRInt32 prefInt; - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.base_font_scaler", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.base_font_scaler", &prefInt))) { mFontScaler = prefInt; } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("nglayout.widget.mode", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("nglayout.widget.mode", &prefInt))) { mWidgetRenderingMode = (enum nsWidgetRendering)prefInt; // bad cast } @@ -462,75 +468,78 @@ nsPresContext::GetUserPreferences() // * link colors PRBool boolPref; - nsXPIDLCString stringPref; - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.underline_anchors", &boolPref))) { + nsXPIDLCString colorStr; + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.underline_anchors", &boolPref))) { mUnderlineLinks = boolPref; } - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.anchor_color", getter_Copies(stringPref)))) { - mLinkColor = MakeColorPref(stringPref); + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.anchor_color", getter_Copies(colorStr)))) { + mLinkColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.visited_color", getter_Copies(stringPref)))) { - mVisitedLinkColor = MakeColorPref(stringPref); + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.visited_color", getter_Copies(colorStr)))) { + mVisitedLinkColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { + + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { mUseFocusColors = boolPref; mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mDefaultBackgroundColor; - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.focus_text_color", getter_Copies(stringPref)))) { - mFocusTextColor = MakeColorPref(stringPref); + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_text_color", getter_Copies(colorStr)))) { + mFocusTextColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefBranch->GetCharPref("browser.display.focus_background_color", getter_Copies(stringPref)))) { - mFocusBackgroundColor = MakeColorPref(stringPref); + if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_background_color", getter_Copies(colorStr)))) { + mFocusBackgroundColor = MakeColorPref(colorStr); } } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.focus_ring_width", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_ring_width", &prefInt))) { mFocusRingWidth = prefInt; } - if (NS_SUCCEEDED(mPrefBranch->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { + if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { mFocusRingOnAnything = boolPref; } // * use fonts? - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("browser.display.use_document_fonts", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.use_document_fonts", &prefInt))) { mUseDocumentFonts = prefInt == 0 ? PR_FALSE : PR_TRUE; } GetFontPreferences(); // * image animation - nsresult rv = mPrefBranch->GetCharPref("image.animation_mode", getter_Copies(stringPref)); - if (NS_SUCCEEDED(rv)) { - if (stringPref.Equals("normal")) + char* animatePref = 0; + nsresult rv = mPrefs->CopyCharPref("image.animation_mode", &animatePref); + if (NS_SUCCEEDED(rv) && animatePref) { + if (!nsCRT::strcmp(animatePref, "normal")) mImageAnimationModePref = imgIContainer::kNormalAnimMode; - else if (stringPref.Equals("none")) + else if (!nsCRT::strcmp(animatePref, "none")) mImageAnimationModePref = imgIContainer::kDontAnimMode; - else if (stringPref.Equals("once")) + else if (!nsCRT::strcmp(animatePref, "once")) mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode; + nsMemory::Free(animatePref); } #ifdef IBMBIDI - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.direction", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.direction", &prefInt))) { SET_BIDI_OPTION_DIRECTION(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.texttype", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.texttype", &prefInt))) { SET_BIDI_OPTION_TEXTTYPE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.controlstextmode", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.controlstextmode", &prefInt))) { SET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.clipboardtextmode", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.clipboardtextmode", &prefInt))) { SET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.numeral", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.numeral", &prefInt))) { SET_BIDI_OPTION_NUMERAL(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.support", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.support", &prefInt))) { SET_BIDI_OPTION_SUPPORT(mBidi, prefInt); } - if (NS_SUCCEEDED(mPrefBranch->GetIntPref("bidi.characterset", &prefInt))) { + if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.characterset", &prefInt))) { SET_BIDI_OPTION_CHARACTERSET(mBidi, prefInt); } #endif @@ -625,19 +634,18 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) mDeviceContext = dont_QueryInterface(aDeviceContext); mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); - 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); + 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); #ifdef IBMBIDI - prefInternal->AddObserver("bidi.", this, PR_FALSE); + mPrefs->RegisterCallback("bidi.", PrefChangedCallback, (void*)this); #endif // Initialize our state from the user preferences @@ -743,11 +751,6 @@ 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 ef588fb8910..e7067458a6d 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 "nsIPrefBranch.h" +#include "nsIPref.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 mPrefBranch; + nsCOMPtr mPrefs; 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,6 +289,7 @@ 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 0aa50ae6c53..eb6959a2066 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -88,8 +88,7 @@ #include "nsIPercentHeightObserver.h" // For triple-click pref -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #include "nsIServiceManager.h" #include "nsISelectionImageService.h" #include "imgIContainer.h" @@ -99,6 +98,7 @@ #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 prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); - if (prefBranch) - prefBranch->GetBoolPref("browser.triple_click_selects_paragraph", &selectPara); + nsCOMPtr prefsService( do_GetService(kPrefCID, &rv) ); + if (NS_SUCCEEDED(rv) && prefsService) + prefsService->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 2ef7af1b850..431ebedb76b 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -68,6 +68,7 @@ #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 7fb5b3fbaef..ddd25c9a8aa 100644 --- a/mozilla/layout/generic/nsHTMLReflowState.cpp +++ b/mozilla/layout/generic/nsHTMLReflowState.cpp @@ -48,10 +48,7 @@ #include "nsBlockFrame.h" #include "nsLineBox.h" #include "nsImageFrame.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" -#include "nsIPrefBranchInternal.h" -#include "nsIObserver.h" +#include "nsIPref.h" #include "nsIServiceManager.h" #include "nsIPercentHeightObserver.h" #ifdef IBMBIDI @@ -1628,81 +1625,44 @@ nsHTMLReflowState::ComputeContainingBlockRectangle(nsIPresContext* aPre } } -class BlinkPrefObserver : public nsIObserver +// Prefs callback to pick up changes +static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance) { -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; + 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 */ } // Check to see if |text-decoration: blink| is allowed. The first time -// called, register the observer and then force-load the pref. After that, +// called, register the callback and then force-load the pref. After that, // just use the cached value. -static -PRBool BlinkIsAllowed() +static PRBool BlinkIsAllowed(void) { if (!sPrefIsLoaded) { - // 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); - } - } + // 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); } + PrefsChanged(nsnull, nsnull); sPrefIsLoaded = PR_TRUE; } - return sBlinkIsAllowed; } static eNormalLineHeightControl GetNormalLineHeightCalcControl(void) { if (sNormalLineHeightControl == eUninitialized) { - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); PRInt32 intPref; // browser.display.normal_lineheight_calc_control is not user changable, so // no need to register callback for it. - if (prefBranch && NS_SUCCEEDED(prefBranch->GetIntPref( + if (prefs && NS_SUCCEEDED(prefs->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 ab4da5e6da2..d5676bf04f6 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -94,8 +94,7 @@ #include "nsIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsCSSFrameConstructor.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #ifdef DEBUG #undef NOISY_IMAGE_LOADING @@ -2271,21 +2270,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 prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefBranch) { + nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); + if (prefs) { PRBool boolPref; PRInt32 intPref; - if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { + if (NS_SUCCEEDED(prefs->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { mPrefForceInlineAltText = boolPref; } else { mPrefForceInlineAltText = PR_FALSE; } - if (NS_SUCCEEDED(prefBranch->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { + if (NS_SUCCEEDED(prefs->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { mPrefAllImagesBlocked = PR_TRUE; } else { mPrefAllImagesBlocked = PR_FALSE; } - if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.show_image_placeholders", &boolPref))) { + if (NS_SUCCEEDED(prefs->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 da5023daa9d..adaa5fd239e 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -114,8 +114,7 @@ #include "jsapi.h" // XXX temporary for Mac double buffering pref -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" // XXX For temporary paint code #include "nsIStyleContext.h" @@ -140,6 +139,9 @@ #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 @@ -795,12 +797,10 @@ 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 prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); PRBool doubleBuffer = PR_FALSE; - if (prefBranch) { - prefBranch->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer); - } - + prefs ? prefs->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer) : 0; + viewMan->AllowDoubleBuffering(doubleBuffer); #endif diff --git a/mozilla/layout/generic/nsSimplePageSequence.cpp b/mozilla/layout/generic/nsSimplePageSequence.cpp index cf95132a6ad..83ce4f27dfe 100644 --- a/mozilla/layout/generic/nsSimplePageSequence.cpp +++ b/mozilla/layout/generic/nsSimplePageSequence.cpp @@ -54,9 +54,7 @@ #include "nsRegion.h" #include "nsLayoutAtoms.h" -// for header/footer gap & ExtraMargin for Print Preview -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" // for header/footer gap & ExtraMargin for Print Preview // DateTime Includes #include "nsDateTimeFormatCID.h" @@ -218,30 +216,23 @@ nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsIPresContext* aPresContex return rv; } -void -nsSimplePageSequenceFrame::GetEdgePaperMarginCoord(char* aPrefName, - nscoord& aCoord) +void nsSimplePageSequenceFrame::GetEdgePaperMarginCoord(nsIPref* aPref, char* aPrefName, nscoord& aCoord) { - nsresult rv = mPageData->mPrintOptions-> - GetPrinterPrefInt(mPageData->mPrintSettings, - NS_ConvertASCIItoUCS2(aPrefName).get(), - &aCoord); - - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(mPageData->mPrintOptions->GetPrinterPrefInt(mPageData->mPrintSettings, + NS_ConvertASCIItoUCS2(aPrefName).get(), &aCoord))) { 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(nsMargin& aMargin) +void nsSimplePageSequenceFrame::GetEdgePaperMargin(nsIPref* aPref, nsMargin& aMargin) { aMargin.SizeTo(0,0,0,0); - GetEdgePaperMarginCoord("print_edge_top", aMargin.top); - GetEdgePaperMarginCoord("print_edge_left", aMargin.left); - GetEdgePaperMarginCoord("print_edge_bottom", aMargin.bottom); - GetEdgePaperMarginCoord("print_edge_right", aMargin.right); + 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); } NS_IMETHODIMP @@ -318,12 +309,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, aPresContext->GetPageDim(&pageSize, &adjSize); nscoord extraGap = 0; - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefBranch) { - GetEdgePaperMargin(mPageData->mEdgePaperMargin); + nsCOMPtr pref = do_GetService(NS_PREF_CONTRACTID); + if (pref) { + GetEdgePaperMargin(pref, mPageData->mEdgePaperMargin); nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10; PRInt32 gapInTwips; - if (NS_SUCCEEDED(prefBranch->GetIntPref("print.print_extra_margin", &gapInTwips))) { + if (NS_SUCCEEDED(pref->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 5a160efe046..e6552b374c2 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(char* aPrefName, nscoord& aCoord); - void GetEdgePaperMargin(nsMargin& aMargin); + void GetEdgePaperMarginCoord(nsIPref* aPref, char* aPrefName, nscoord& aCoord); + void GetEdgePaperMargin(nsIPref* aPref, 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 752b5ff0ec2..b81c3fa61a7 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -83,8 +83,7 @@ #include "nsILineIterator.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #include "nsIServiceManager.h" #ifdef ACCESSIBILITY #include "nsIAccessible.h" @@ -106,6 +105,8 @@ #include "nsILE.h" #endif /* SUNCTL */ +static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); + #ifdef NS_DEBUG #undef NOISY_BLINK #undef DEBUG_WORD_WRAPPING @@ -1364,10 +1365,10 @@ nsTextFrame::nsTextFrame() { // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefBranch ( do_GetService(NS_PREFSERVICE_CONTRACTID) ); - if ( prefBranch ) { + nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); + if ( prefService ) { PRBool temp = PR_FALSE; - prefBranch->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); + prefService->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); sWordSelectEatSpaceAfter = temp; } sWordSelectPrefInited = PR_TRUE; @@ -2640,12 +2641,12 @@ nsTextFrame::GetPositionSlowly(nsIPresContext* aPresContext, ComputeExtraJustificationSpacing(*aRendContext, ts, paintBuffer.mBuffer, textLength, numSpaces); //IF STYLE SAYS TO SELECT TO END OF FRAME HERE... - nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); + nsCOMPtr prefs( do_GetService(kPrefCID, &rv) ); PRInt32 prefInt = 0; PRBool outofstylehandled = PR_FALSE; - if (prefBranch) + if (NS_SUCCEEDED(rv) && prefs) { - if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + if (NS_SUCCEEDED(prefs->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) { if (aPoint.y < origin.y)//above rectangle { @@ -3528,12 +3529,12 @@ nsTextFrame::GetPosition(nsIPresContext* aCX, GetOffsetFromView(aCX, origin, &view); //IF STYLE SAYS TO SELECT TO END OF FRAME HERE... - nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); + nsCOMPtr prefs( do_GetService(kPrefCID, &rv) ); PRInt32 prefInt = 0; PRBool outofstylehandled = PR_FALSE; - if (prefBranch) + if (NS_SUCCEEDED(rv) && prefs) { - if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + if (NS_SUCCEEDED(prefs->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 c5c498f525c..23d9db35345 100644 --- a/mozilla/layout/generic/nsTextTransformer.cpp +++ b/mozilla/layout/generic/nsTextTransformer.cpp @@ -49,8 +49,7 @@ #include "nsUnicharUtils.h" #include "nsICaseConversion.h" #include "prenv.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #ifdef IBMBIDI #include "nsLayoutAtoms.h" #endif @@ -115,11 +114,10 @@ nsTextTransformer::Initialize() // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefBranch = - do_GetService( NS_PREFSERVICE_CONTRACTID ); - if ( prefBranch ) { + nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); + if ( prefService ) { PRBool temp = PR_FALSE; - prefBranch->GetBoolPref("layout.word_select.stop_at_punctuation", &temp); + prefService->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 0aa50ae6c53..eb6959a2066 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -88,8 +88,7 @@ #include "nsIPercentHeightObserver.h" // For triple-click pref -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #include "nsIServiceManager.h" #include "nsISelectionImageService.h" #include "imgIContainer.h" @@ -99,6 +98,7 @@ #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 prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); - if (prefBranch) - prefBranch->GetBoolPref("browser.triple_click_selects_paragraph", &selectPara); + nsCOMPtr prefsService( do_GetService(kPrefCID, &rv) ); + if (NS_SUCCEEDED(rv) && prefsService) + prefsService->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 7fb5b3fbaef..ddd25c9a8aa 100644 --- a/mozilla/layout/html/base/src/nsHTMLReflowState.cpp +++ b/mozilla/layout/html/base/src/nsHTMLReflowState.cpp @@ -48,10 +48,7 @@ #include "nsBlockFrame.h" #include "nsLineBox.h" #include "nsImageFrame.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" -#include "nsIPrefBranchInternal.h" -#include "nsIObserver.h" +#include "nsIPref.h" #include "nsIServiceManager.h" #include "nsIPercentHeightObserver.h" #ifdef IBMBIDI @@ -1628,81 +1625,44 @@ nsHTMLReflowState::ComputeContainingBlockRectangle(nsIPresContext* aPre } } -class BlinkPrefObserver : public nsIObserver +// Prefs callback to pick up changes +static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance) { -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; + 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 */ } // Check to see if |text-decoration: blink| is allowed. The first time -// called, register the observer and then force-load the pref. After that, +// called, register the callback and then force-load the pref. After that, // just use the cached value. -static -PRBool BlinkIsAllowed() +static PRBool BlinkIsAllowed(void) { if (!sPrefIsLoaded) { - // 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); - } - } + // 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); } + PrefsChanged(nsnull, nsnull); sPrefIsLoaded = PR_TRUE; } - return sBlinkIsAllowed; } static eNormalLineHeightControl GetNormalLineHeightCalcControl(void) { if (sNormalLineHeightControl == eUninitialized) { - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); PRInt32 intPref; // browser.display.normal_lineheight_calc_control is not user changable, so // no need to register callback for it. - if (prefBranch && NS_SUCCEEDED(prefBranch->GetIntPref( + if (prefs && NS_SUCCEEDED(prefs->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 ab4da5e6da2..d5676bf04f6 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -94,8 +94,7 @@ #include "nsIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsCSSFrameConstructor.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #ifdef DEBUG #undef NOISY_IMAGE_LOADING @@ -2271,21 +2270,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 prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefBranch) { + nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); + if (prefs) { PRBool boolPref; PRInt32 intPref; - if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { + if (NS_SUCCEEDED(prefs->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { mPrefForceInlineAltText = boolPref; } else { mPrefForceInlineAltText = PR_FALSE; } - if (NS_SUCCEEDED(prefBranch->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { + if (NS_SUCCEEDED(prefs->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { mPrefAllImagesBlocked = PR_TRUE; } else { mPrefAllImagesBlocked = PR_FALSE; } - if (NS_SUCCEEDED(prefBranch->GetBoolPref("browser.display.show_image_placeholders", &boolPref))) { + if (NS_SUCCEEDED(prefs->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 da5023daa9d..adaa5fd239e 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -114,8 +114,7 @@ #include "jsapi.h" // XXX temporary for Mac double buffering pref -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" // XXX For temporary paint code #include "nsIStyleContext.h" @@ -140,6 +139,9 @@ #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 @@ -795,12 +797,10 @@ 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 prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); PRBool doubleBuffer = PR_FALSE; - if (prefBranch) { - prefBranch->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer); - } - + prefs ? prefs->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer) : 0; + viewMan->AllowDoubleBuffering(doubleBuffer); #endif diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index c22e8fd2d19..32d85633b9f 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -57,8 +57,7 @@ #include "prinrval.h" #include "nsVoidArray.h" #include "nsHashtable.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #include "nsIViewObserver.h" #include "nsContainerFrame.h" #include "nsIDeviceContext.h" @@ -198,6 +197,7 @@ 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,11 +1694,10 @@ PresShell::Init(nsIDocument* aDocument, gAsyncReflowDuringDocLoad = PR_TRUE; // Get the prefs service - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime); - prefBranch->GetBoolPref("layout.reflow.async.duringDocLoad", - &gAsyncReflowDuringDocLoad); + nsCOMPtr prefs(do_GetService(kPrefServiceCID, &result)); + if (NS_SUCCEEDED(result)) { + prefs->GetIntPref("layout.reflow.timeslice", &gMaxRCProcessingTime); + prefs->GetBoolPref("layout.reflow.async.duringDocLoad", &gAsyncReflowDuringDocLoad); } } @@ -1717,19 +1716,16 @@ PresShell::Init(nsIDocument* aDocument, #endif #ifdef MOZ_REFLOW_PERF - if (mReflowCountMgr) { - // Get the prefs service - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { + // Get the prefs service + nsCOMPtr prefs(do_GetService(kPrefServiceCID, &result)); + if (NS_SUCCEEDED(result)) { + if (mReflowCountMgr != nsnull) { PRBool paintFrameCounts = PR_FALSE; PRBool dumpFrameCounts = PR_FALSE; PRBool dumpFrameByFrameCounts = PR_FALSE; - prefBranch->GetBoolPref("layout.reflow.showframecounts", - &paintFrameCounts); - prefBranch->GetBoolPref("layout.reflow.dumpframecounts", - &dumpFrameCounts); - prefBranch->GetBoolPref("layout.reflow.dumpframebyframecounts", - &dumpFrameByFrameCounts); + prefs->GetBoolPref("layout.reflow.showframecounts", &paintFrameCounts); + prefs->GetBoolPref("layout.reflow.dumpframecounts", &dumpFrameCounts); + prefs->GetBoolPref("layout.reflow.dumpframebyframecounts", &dumpFrameByFrameCounts); mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); @@ -2858,9 +2854,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 prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) - prefBranch->GetIntPref("nglayout.initialpaint.delay", &delay); + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + if (prefs) + prefs->GetIntPref("nglayout.initialpaint.delay", &delay); nsCOMPtr ti = do_QueryInterface(mPaintSuppressionTimer); ti->SetIdle(PR_FALSE); @@ -4008,9 +4004,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 prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("layout.selectanchor", &selectAnchor); + nsCOMPtr prefs(do_GetService(kPrefServiceCID,&rv)); + if (NS_SUCCEEDED(rv) && prefs) { + prefs->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 cf95132a6ad..83ce4f27dfe 100644 --- a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp +++ b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp @@ -54,9 +54,7 @@ #include "nsRegion.h" #include "nsLayoutAtoms.h" -// for header/footer gap & ExtraMargin for Print Preview -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" // for header/footer gap & ExtraMargin for Print Preview // DateTime Includes #include "nsDateTimeFormatCID.h" @@ -218,30 +216,23 @@ nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsIPresContext* aPresContex return rv; } -void -nsSimplePageSequenceFrame::GetEdgePaperMarginCoord(char* aPrefName, - nscoord& aCoord) +void nsSimplePageSequenceFrame::GetEdgePaperMarginCoord(nsIPref* aPref, char* aPrefName, nscoord& aCoord) { - nsresult rv = mPageData->mPrintOptions-> - GetPrinterPrefInt(mPageData->mPrintSettings, - NS_ConvertASCIItoUCS2(aPrefName).get(), - &aCoord); - - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(mPageData->mPrintOptions->GetPrinterPrefInt(mPageData->mPrintSettings, + NS_ConvertASCIItoUCS2(aPrefName).get(), &aCoord))) { 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(nsMargin& aMargin) +void nsSimplePageSequenceFrame::GetEdgePaperMargin(nsIPref* aPref, nsMargin& aMargin) { aMargin.SizeTo(0,0,0,0); - GetEdgePaperMarginCoord("print_edge_top", aMargin.top); - GetEdgePaperMarginCoord("print_edge_left", aMargin.left); - GetEdgePaperMarginCoord("print_edge_bottom", aMargin.bottom); - GetEdgePaperMarginCoord("print_edge_right", aMargin.right); + 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); } NS_IMETHODIMP @@ -318,12 +309,12 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, aPresContext->GetPageDim(&pageSize, &adjSize); nscoord extraGap = 0; - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefBranch) { - GetEdgePaperMargin(mPageData->mEdgePaperMargin); + nsCOMPtr pref = do_GetService(NS_PREF_CONTRACTID); + if (pref) { + GetEdgePaperMargin(pref, mPageData->mEdgePaperMargin); nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10; PRInt32 gapInTwips; - if (NS_SUCCEEDED(prefBranch->GetIntPref("print.print_extra_margin", &gapInTwips))) { + if (NS_SUCCEEDED(pref->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 5a160efe046..e6552b374c2 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(char* aPrefName, nscoord& aCoord); - void GetEdgePaperMargin(nsMargin& aMargin); + void GetEdgePaperMarginCoord(nsIPref* aPref, char* aPrefName, nscoord& aCoord); + void GetEdgePaperMargin(nsIPref* aPref, 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 752b5ff0ec2..b81c3fa61a7 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -83,8 +83,7 @@ #include "nsILineIterator.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #include "nsIServiceManager.h" #ifdef ACCESSIBILITY #include "nsIAccessible.h" @@ -106,6 +105,8 @@ #include "nsILE.h" #endif /* SUNCTL */ +static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); + #ifdef NS_DEBUG #undef NOISY_BLINK #undef DEBUG_WORD_WRAPPING @@ -1364,10 +1365,10 @@ nsTextFrame::nsTextFrame() { // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefBranch ( do_GetService(NS_PREFSERVICE_CONTRACTID) ); - if ( prefBranch ) { + nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); + if ( prefService ) { PRBool temp = PR_FALSE; - prefBranch->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); + prefService->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); sWordSelectEatSpaceAfter = temp; } sWordSelectPrefInited = PR_TRUE; @@ -2640,12 +2641,12 @@ nsTextFrame::GetPositionSlowly(nsIPresContext* aPresContext, ComputeExtraJustificationSpacing(*aRendContext, ts, paintBuffer.mBuffer, textLength, numSpaces); //IF STYLE SAYS TO SELECT TO END OF FRAME HERE... - nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); + nsCOMPtr prefs( do_GetService(kPrefCID, &rv) ); PRInt32 prefInt = 0; PRBool outofstylehandled = PR_FALSE; - if (prefBranch) + if (NS_SUCCEEDED(rv) && prefs) { - if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + if (NS_SUCCEEDED(prefs->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) { if (aPoint.y < origin.y)//above rectangle { @@ -3528,12 +3529,12 @@ nsTextFrame::GetPosition(nsIPresContext* aCX, GetOffsetFromView(aCX, origin, &view); //IF STYLE SAYS TO SELECT TO END OF FRAME HERE... - nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); + nsCOMPtr prefs( do_GetService(kPrefCID, &rv) ); PRInt32 prefInt = 0; PRBool outofstylehandled = PR_FALSE; - if (prefBranch) + if (NS_SUCCEEDED(rv) && prefs) { - if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + if (NS_SUCCEEDED(prefs->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 c5c498f525c..23d9db35345 100644 --- a/mozilla/layout/html/base/src/nsTextTransformer.cpp +++ b/mozilla/layout/html/base/src/nsTextTransformer.cpp @@ -49,8 +49,7 @@ #include "nsUnicharUtils.h" #include "nsICaseConversion.h" #include "prenv.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #ifdef IBMBIDI #include "nsLayoutAtoms.h" #endif @@ -115,11 +114,10 @@ nsTextTransformer::Initialize() // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefBranch = - do_GetService( NS_PREFSERVICE_CONTRACTID ); - if ( prefBranch ) { + nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); + if ( prefService ) { PRBool temp = PR_FALSE; - prefBranch->GetBoolPref("layout.word_select.stop_at_punctuation", &temp); + prefService->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 2ef7af1b850..431ebedb76b 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -68,6 +68,7 @@ #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 8f8ed7ed399..0b643df7bf8 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -93,8 +93,7 @@ #include "nsIAnonymousContentCreator.h" #include "nsIFrameManager.h" #include "nsIAttributeContent.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsIPref.h" #include "nsLegendFrame.h" #include "nsIContentIterator.h" #include "nsBoxLayoutState.h" @@ -4232,10 +4231,10 @@ nsCSSFrameConstructor::HasGfxScrollbars() #endif // Get the Prefs if (!mGotGfxPrefs) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { + nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); + if (pref) { PRBool hasGfxScroll = PR_FALSE; // use a temp since we have a PRPackedBool - prefBranch->GetBoolPref("nglayout.widget.gfxscrollbars", &hasGfxScroll); + pref->GetBoolPref("nglayout.widget.gfxscrollbars", &hasGfxScroll); mHasGfxScrollbars = hasGfxScroll; mGotGfxPrefs = PR_TRUE; } else { @@ -4252,10 +4251,10 @@ PRBool nsCSSFrameConstructor::UseXBLForms() { if (!mGotXBLFormPrefs) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { + nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); + if (pref) { PRBool useXBLForms = PR_FALSE; // use a temp since we have a PRPackedBool - prefBranch->GetBoolPref("nglayout.debug.enable_xbl_forms", &useXBLForms); + pref->GetBoolPref("nglayout.debug.enable_xbl_forms", &useXBLForms); mUseXBLForms = useXBLForms; mGotXBLFormPrefs = PR_TRUE; }