Bug 663041 layout should use mozilla::Preferences r=roc
authorMasayuki Nakano <masayuki@d-toybox.com>
Sun, 12 Jun 2011 11:30:16 +0900
changeset 70931 e37011790a8a929a3dbfbe6b81c8194e57c35bf7
parent 70930 1abe9e62753397f24176e42e1b5ea114b95d44e0
child 70932 098467464a94f73a8d7fc886461ec0504645b9a3
push id20451
push usermasayuki@d-toybox.com
push dateSun, 12 Jun 2011 02:31:08 +0000
treeherdermozilla-central@e37011790a8a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs663041
milestone7.0a1
first release with
nightly linux32
e37011790a8a / 7.0a1 / 20110612030726 / files
nightly linux64
e37011790a8a / 7.0a1 / 20110612030726 / files
nightly mac
e37011790a8a / 7.0a1 / 20110612030726 / files
nightly win32
e37011790a8a / 7.0a1 / 20110612030726 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 663041 layout should use mozilla::Preferences r=roc
layout/generic/nsGfxScrollFrame.cpp
layout/mathml/nsMathMLChar.cpp
layout/style/nsFontFaceLoader.cpp
layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
layout/tools/layout-debug/src/nsLayoutDebuggingTools.h
layout/tools/layout-debug/src/nsRegressionTester.cpp
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -73,17 +73,17 @@
 #include "nsEventDispatcher.h"
 #include "nsContentUtils.h"
 #include "nsLayoutUtils.h"
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
 #endif
 #include "nsBidiUtils.h"
 #include "nsFrameManager.h"
-#include "nsIPrefService.h"
+#include "mozilla/Preferences.h"
 #include "nsILookAndFeel.h"
 #include "mozilla/dom/Element.h"
 #include "FrameLayerBuilder.h"
 #include "nsSMILKeySpline.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
@@ -1404,25 +1404,17 @@ nsGfxScrollFrameInner::AsyncScroll::Init
   double dt = 1.0 / normalization * kCurrentVelocityWeighting;
   double dxy = slope / normalization * kCurrentVelocityWeighting;
   aTimingFunction.Init(dt, dxy, 1 - kStopDecelerationWeighting, 1);
 }
 
 static PRBool
 IsSmoothScrollingEnabled()
 {
-  nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-  if (prefs) {
-    PRBool enabled;
-    nsresult rv = prefs->GetBoolPref(SMOOTH_SCROLL_PREF_NAME, &enabled);
-    if (NS_SUCCEEDED(rv)) {
-      return enabled;
-    }
-  }
-  return PR_FALSE;
+  return Preferences::GetBool(SMOOTH_SCROLL_PREF_NAME, PR_FALSE);
 }
 
 class ScrollFrameActivityTracker : public nsExpirationTracker<nsGfxScrollFrameInner,4> {
 public:
   // Wait for 3-4s between scrolls before we remove our layers.
   // That's 4 generations of 1s each.
   enum { TIMEOUT_MS = 1000 };
   ScrollFrameActivityTracker()
--- a/layout/mathml/nsMathMLChar.cpp
+++ b/layout/mathml/nsMathMLChar.cpp
@@ -44,18 +44,17 @@
 #include "nsPresContext.h"
 #include "nsStyleContext.h"
 #include "nsStyleConsts.h"
 #include "nsString.h"
 #include "nsUnicharUtils.h"
 #include "nsRenderingContext.h"
 #include "gfxPlatform.h"
 
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
+#include "mozilla/Preferences.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIComponentManager.h"
 #include "nsIPersistentProperties2.h"
 #include "nsIServiceManager.h"
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "nsNetUtil.h"
 
@@ -63,16 +62,18 @@
 #include "nsCSSRendering.h"
 #include "prprf.h"         // For PR_snprintf()
 
 #include "nsDisplayList.h"
 
 #include "nsMathMLOperators.h"
 #include "nsMathMLChar.h"
 
+using namespace mozilla;
+
 //#define SHOW_BORDERS 1
 //#define NOISY_SEARCH 1
 
 // -----------------------------------------------------------------------------------
 static const PRUnichar   kSpaceCh   = PRUnichar(' ');
 static const nsGlyphCode kNullGlyph = {0, 0};
 typedef enum {eExtension_base, eExtension_variants, eExtension_parts}
   nsMathfontPrefExtension;
@@ -590,41 +591,24 @@ nsGlyphTableList::GetGlyphTableFor(const
     }
   }
   // Fall back to default Unicode table
   return &mUnicodeTable;
 }
 
 // -----------------------------------------------------------------------------------
 
-// retrieve a pref value set by the user
-static PRBool
-GetPrefValue(nsIPrefBranch* aPrefBranch, const char* aPrefKey, nsString& aPrefValue)
-{
-  aPrefValue.Truncate();
-  if (aPrefBranch) {
-    nsCOMPtr<nsISupportsString> prefString;
-    aPrefBranch->GetComplexValue(aPrefKey,
-                                 NS_GET_IID(nsISupportsString),
-                                 getter_AddRefs(prefString));
-    if (prefString) {
-      prefString->GetData(aPrefValue);
-    }
-  }
-  return !aPrefValue.IsEmpty();
-}
-
 // Lookup the preferences:
 // "font.mathfont-family.\uNNNN.base"     -- fonts for the base size
 // "font.mathfont-family.\uNNNN.variants" -- fonts for larger glyphs
 // "font.mathfont-family.\uNNNN.parts"    -- fonts for partial glyphs
 // Given the char code and mode of stretch, retrieve the preferred extension
 // font families.
 static PRBool
-GetFontExtensionPref(nsIPrefBranch* aPrefBranch, PRUnichar aChar,
+GetFontExtensionPref(PRUnichar aChar,
                      nsMathfontPrefExtension aExtension, nsString& aValue)
 {
   // initialize OUT param
   aValue.Truncate();
 
   // We are going to try two keys because some users specify their pref as 
   // user_pref("font.mathfont-family.\uNNNN.base", "...") rather than
   // user_pref("font.mathfont-family.\\uNNNN.base", "...").
@@ -661,18 +645,21 @@ GetFontExtensionPref(nsIPrefBranch* aPre
   key.Append(extension);
   // .\uNNNN key
   nsCAutoString alternateKey;
   alternateKey.AssignASCII(kMathFontPrefix);
   NS_ConvertUTF16toUTF8 tmp(&aChar, 1);
   alternateKey.Append(tmp);
   alternateKey.Append(extension);
 
-  return GetPrefValue(aPrefBranch, key.get(), aValue) ||
-    GetPrefValue(aPrefBranch, alternateKey.get(), aValue);
+  aValue = Preferences::GetString(key.get());
+  if (aValue.IsEmpty()) {
+    aValue = Preferences::GetString(alternateKey.get());
+  }
+  return !aValue.IsEmpty();
 }
 
 
 static PRBool
 MathFontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)
 {
   if (!gGlyphTableList->AddGlyphTable(aFamily))
     return PR_FALSE; // stop in low-memory situations
@@ -700,17 +687,16 @@ InitGlobals(nsPresContext* aPresContext)
   else
     The gGlyphTableList has been successfully registered as a shutdown observer.
     It will be deleted at shutdown, even if a failure happens below.
   */
 
   nsCAutoString key;
   nsAutoString value;
   nsCOMPtr<nsIPersistentProperties> mathfontProp;
-  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
 
   // Add the math fonts in the gGlyphTableList in order of preference ...
   // Note: we only load font-names at this stage. The actual glyph tables will
   // be loaded lazily (see nsGlyphTable::ElementAt()).
 
   // Load the "mathfont.properties" file
   value.Truncate();
   rv = LoadProperties(value, mathfontProp);
@@ -1446,19 +1432,18 @@ nsMathMLChar::StretchInternal(nsPresCont
   nsStretchDirection direction = nsMathMLOperators::GetStretchyDirection(mData);
 
   // Set default font and get the default bounding metrics
   // mStyleContext is a leaf context used only when stretching happens.
   // For the base size, the default font should come from the parent context
   nsFont font = mStyleContext->GetParent()->GetStyleFont()->mFont;
 
   // Override with specific fonts if applicable for this character
-  nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
   nsAutoString families;
-  if (GetFontExtensionPref(prefBranch, mData[0], eExtension_base, families)) {
+  if (GetFontExtensionPref(mData[0], eExtension_base, families)) {
     font.name = families;
   }
 
   // Don't modify this nsMathMLChar when doing GetMaxWidth()
   PRBool maxWidth = (NS_STRETCH_MAXWIDTH & aStretchHint) != 0;
   if (!maxWidth) {
     // Record the families in case there is no stretch.  But don't bother
     // storing families when they are just those from the StyleContext.
@@ -1563,48 +1548,46 @@ nsMathMLChar::StretchInternal(nsPresCont
   nsAutoString cssFamilies;
 
   if (!done) {
     font = mStyleContext->GetStyleFont()->mFont;
     cssFamilies = font.name;
   }
 
   // See if there are preferred fonts for the variants of this char
-  if (!done && GetFontExtensionPref(prefBranch, mData[0], eExtension_variants,
-                                    families)) {
+  if (!done && GetFontExtensionPref(mData[0], eExtension_variants, families)) {
     font.name = families;
 
     StretchEnumContext enumData(this, aPresContext, aRenderingContext,
                                 aStretchDirection, targetSize, aStretchHint,
                                 aDesiredStretchSize, font.name, glyphFound);
     enumData.mTryParts = PR_FALSE;
 
     done = !font.EnumerateFamilies(StretchEnumContext::EnumCallback, &enumData);
   }
 
   // See if there are preferred fonts for the parts of this char
   if (!done && !largeopOnly
-      && GetFontExtensionPref(prefBranch, mData[0], eExtension_parts,
-                              families)) {
+      && GetFontExtensionPref(mData[0], eExtension_parts, families)) {
     font.name = families;
 
     StretchEnumContext enumData(this, aPresContext, aRenderingContext,
                                 aStretchDirection, targetSize, aStretchHint,
                                 aDesiredStretchSize, font.name, glyphFound);
     enumData.mTryVariants = PR_FALSE;
 
     done = !font.EnumerateFamilies(StretchEnumContext::EnumCallback, &enumData);
   }
 
   if (!done) { // normal case
     // Use the css font-family but add preferred fallback fonts.
     font.name = cssFamilies;
     NS_NAMED_LITERAL_CSTRING(defaultKey, "font.mathfont-family");
-    nsAutoString fallbackFonts;
-    if (GetPrefValue(prefBranch, defaultKey.get(), fallbackFonts)) {
+    nsAdoptingString fallbackFonts = Preferences::GetString(defaultKey.get());
+    if (!fallbackFonts.IsEmpty()) {
       AddFallbackFonts(font.name, fallbackFonts);
     }
 
 #ifdef NOISY_SEARCH
     printf("Searching in "%s" for a glyph of appropriate size for: 0x%04X:%c\n",
            font.name, mData[0], mData[0]&0x00FF);
 #endif
     StretchEnumContext enumData(this, aPresContext, aRenderingContext,
--- a/layout/style/nsFontFaceLoader.cpp
+++ b/layout/style/nsFontFaceLoader.cpp
@@ -49,17 +49,17 @@
 #include "nsError.h"
 #include "nsIFile.h"
 #include "nsILocalFile.h"
 #include "nsIStreamListener.h"
 #include "nsNetUtil.h"
 #include "nsIChannelEventSink.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsContentUtils.h"
-#include "nsIPrefService.h"
+#include "mozilla/Preferences.h"
 
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIDocument.h"
 #include "nsIFrame.h"
 #include "nsIPrincipal.h"
 #include "nsIScriptSecurityManager.h"
 
@@ -70,16 +70,18 @@
 #include "nsContentErrors.h"
 #include "nsCrossSiteListenerProxy.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsIChannelPolicy.h"
 #include "nsChannelPolicy.h"
 
 #include "nsStyleSet.h"
 
+using namespace mozilla;
+
 #ifdef PR_LOGGING
 static PRLogModuleInfo *gFontDownloaderLog = PR_NewLogModule("fontdownloader");
 #endif /* PR_LOGGING */
 
 #define LOG(args) PR_LOG(gFontDownloaderLog, PR_LOG_DEBUG, args)
 #define LOG_ENABLED() PR_LOG_TEST(gFontDownloaderLog, PR_LOG_DEBUG)
 
 
@@ -99,21 +101,18 @@ nsFontFaceLoader::~nsFontFaceLoader()
   if (mFontSet) {
     mFontSet->RemoveLoader(this);
   }
 }
 
 void
 nsFontFaceLoader::StartedLoading(nsIStreamLoader *aStreamLoader)
 {
-  PRInt32 loadTimeout = 3000;
-  nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-  if (prefs) {
-    prefs->GetIntPref("gfx.downloadable_fonts.fallback_delay", &loadTimeout);
-  }
+  PRInt32 loadTimeout =
+    Preferences::GetInt("gfx.downloadable_fonts.fallback_delay", 3000);
   if (loadTimeout > 0) {
     mLoadTimer = do_CreateInstance("@mozilla.org/timer;1");
     if (mLoadTimer) {
       mLoadTimer->InitWithFuncCallback(LoadTimerCallback,
                                        static_cast<void*>(this),
                                        loadTimeout,
                                        nsITimer::TYPE_ONE_SHOT);
     }
--- a/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
+++ b/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
@@ -43,33 +43,32 @@
 #include "nsIDocShellTreeNode.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocumentViewer.h"
 
 #include "nsIServiceManager.h"
 #include "nsIAtom.h"
 #include "nsQuickSort.h"
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
 
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 
 #include "nsIPresShell.h"
 #include "nsIViewManager.h"
 #include "nsIFrame.h"
 
 #include "nsILayoutDebugger.h"
 #include "nsLayoutCID.h"
 static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID);
 
 #include "nsISelectionController.h"
 #include "mozilla/dom/Element.h"
+#include "mozilla/Preferences.h"
 
 using namespace mozilla;
 
 static already_AddRefed<nsIContentViewer>
 doc_viewer(nsIDocShell *aDocShell)
 {
     if (!aDocShell)
         return nsnull;
@@ -146,35 +145,44 @@ nsLayoutDebuggingTools::~nsLayoutDebuggi
 {
 }
 
 NS_IMPL_ISUPPORTS1(nsLayoutDebuggingTools, nsILayoutDebuggingTools)
 
 NS_IMETHODIMP
 nsLayoutDebuggingTools::Init(nsIDOMWindow *aWin)
 {
-    mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (!mPrefs)
+    if (!Preferences::GetService()) {
         return NS_ERROR_UNEXPECTED;
+    }
 
     {
         nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWin);
         if (!window)
             return NS_ERROR_UNEXPECTED;
         mDocShell = window->GetDocShell();
     }
     NS_ENSURE_TRUE(mDocShell, NS_ERROR_UNEXPECTED);
 
-    GetBoolPref("nglayout.debug.paint_flashing", &mPaintFlashing);
-    GetBoolPref("nglayout.debug.paint_dumping", &mPaintDumping);
-    GetBoolPref("nglayout.debug.invalidate_dumping", &mInvalidateDumping);
-    GetBoolPref("nglayout.debug.event_dumping", &mEventDumping);
-    GetBoolPref("nglayout.debug.motion_event_dumping", &mMotionEventDumping);
-    GetBoolPref("nglayout.debug.crossing_event_dumping", &mCrossingEventDumping);
-    GetBoolPref("layout.reflow.showframecounts", &mReflowCounts);
+    mPaintFlashing =
+        Preferences::GetBool("nglayout.debug.paint_flashing", mPaintFlashing);
+    mPaintDumping =
+        Preferences::GetBool("nglayout.debug.paint_dumping", mPaintDumping);
+    mInvalidateDumping =
+        Preferences::GetBool("nglayout.debug.invalidate_dumping", mInvalidateDumping);
+    mEventDumping =
+        Preferences::GetBool("nglayout.debug.event_dumping", mEventDumping);
+    mMotionEventDumping =
+        Preferences::GetBool("nglayout.debug.motion_event_dumping",
+                             mMotionEventDumping);
+    mCrossingEventDumping =
+        Preferences::GetBool("nglayout.debug.crossing_event_dumping",
+                             mCrossingEventDumping);
+    mReflowCounts =
+        Preferences::GetBool("layout.reflow.showframecounts", mReflowCounts);
 
     {
         nsCOMPtr<nsILayoutDebugger> ld = do_GetService(kLayoutDebuggerCID);
         if (ld) {
             ld->GetShowFrameBorders(&mVisualDebugging);
             ld->GetShowEventTargetFrameBorder(&mVisualEventDebugging);
         }
     }
@@ -573,30 +581,19 @@ void nsLayoutDebuggingTools::ForceRefres
     }
 }
 
 nsresult
 nsLayoutDebuggingTools::SetBoolPrefAndRefresh(const char * aPrefName,
                                               PRBool aNewVal)
 {
     NS_ENSURE_TRUE(mDocShell, NS_ERROR_NOT_INITIALIZED);
-    NS_ENSURE_TRUE(mPrefs && aPrefName, NS_OK);
 
-    mPrefs->SetBoolPref(aPrefName, aNewVal);
-    nsCOMPtr<nsIPrefService> prefService = do_QueryInterface(mPrefs);
-    NS_ENSURE_STATE(prefService);
+    nsIPrefService* prefService = Preferences::GetService();
+    NS_ENSURE_TRUE(prefService && aPrefName, NS_OK);
+
+    Preferences::SetBool(aPrefName, aNewVal);
     prefService->SavePrefFile(nsnull);
 
     ForceRefresh();
 
     return NS_OK;
 }
-
-nsresult
-nsLayoutDebuggingTools::GetBoolPref(const char * aPrefName,
-                                    PRBool *aValue)
-{
-    NS_ENSURE_TRUE(mPrefs && aPrefName, NS_OK);
-
-    mPrefs->GetBoolPref(aPrefName, aValue);
-
-    return NS_OK;
-}
--- a/layout/tools/layout-debug/src/nsLayoutDebuggingTools.h
+++ b/layout/tools/layout-debug/src/nsLayoutDebuggingTools.h
@@ -34,17 +34,16 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsILayoutDebuggingTools.h"
 #include "nsIDocShell.h"
 #include "nsCOMPtr.h"
-#include "nsIPrefBranch.h"
 
 class nsLayoutDebuggingTools : public nsILayoutDebuggingTools {
 
 public:
     nsLayoutDebuggingTools();
     virtual ~nsLayoutDebuggingTools();
 
     NS_DECL_ISUPPORTS
@@ -52,17 +51,16 @@ public:
     NS_DECL_NSILAYOUTDEBUGGINGTOOLS
 
 protected:
     void ForceRefresh();
     nsresult GetBoolPref(const char * aPrefName, PRBool *aValue);
     nsresult SetBoolPrefAndRefresh(const char * aPrefName, PRBool aNewValue);
 
     nsCOMPtr<nsIDocShell> mDocShell;
-    nsCOMPtr<nsIPrefBranch> mPrefs;
 
     PRBool mEditorMode;
     PRBool mVisualDebugging;
     PRBool mVisualEventDebugging;
     PRBool mPaintFlashing;
     PRBool mPaintDumping;
     PRBool mInvalidateDumping;
     PRBool mEventDumping;
--- a/layout/tools/layout-debug/src/nsRegressionTester.cpp
+++ b/layout/tools/layout-debug/src/nsRegressionTester.cpp
@@ -56,17 +56,16 @@
 #include "nsIContentViewer.h"
 #include "nsIContentViewerFile.h"
 #include "nsIFrame.h"
 #include "nsStyleStruct.h"
 #include "nsIFrameUtil.h"
 #include "nsLayoutCID.h"
 #include "nsNetUtil.h"
 #include "nsILocalFile.h"
-#include "nsIPrefService.h"
 #include "nsIViewManager.h"
 #include "nsIView.h"
 
 
 
 static NS_DEFINE_CID(kFrameUtilCID, NS_FRAME_UTIL_CID);